home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-02 | 12.3 KB | 433 lines | [TEXT/KAHL] |
- /****
- * CNeoBenchPane.c
- *
- * Pane methods for a typical application.
- *
- * Copyright © 1990 Symantec Corporation. All rights reserved.
- *
- ****/
-
- #include "NeoTypes.h"
- #include "CNeoBenchPane.h"
- #include "CIntegerText.h"
- #include "CRawText.h"
- #include "CNeoBenchDoc.h"
-
- /**
- * Constants that define the locations of the panes that get created
- * And also their spacing.
- **/
-
- #define H_TOTAL 153 // Vert and Hor positions of top Total
- #define V_TOTAL 67 // Editable textbox
-
- #define H_STAT_START 236 // Vert and Hor position of top left
- #define V_STAT_START 67 // Static text array
-
- #define V_LINE_POSN 82 // Where the lines are drawn for the
- // first item.
-
- #define TOT_SOFAR_DIST 83 // Horiz distance from Total to "So Far" text
-
- #define H_DIST 85 // Horiz distance between Stat text panes
- #define V_DIST 30 // Vertical distance between text panes.
-
- #define TOT_WID 75 // Width of Total Edit text boxes
- #define TOT_HGT 16 // Height of the Total EditText box
-
- #define STAT_WID 78 // Width of Static text area
- #define STAT_HGT 21 // Height of Static Text area
-
- #define STOP_WID 85 // Width of stop button
- #define STOP_HGT 25 // Height of stop button
- #define STOP_TOP 225 // Top position
- #define STOP_LFT 275 // Left position
-
- #define GO_WID 85 // Width of Go button
- #define GO_HGT 25 // Height of Go button
- #define GO_TOP 225 // Top position
- #define GO_LFT 400 // Left position
-
- #define LEFT_STAT 13 // Left most position of Stat Text
-
- #define STAT_HDR_TOP 42 // Top vert position of the Stat Text titles
- #define PHASE_NAME_WID 130 // Width of Phase names
-
- #define GO_RES_ID 129 // Res ID of Go button
- #define STOP_RES_ID 128 // Res ID of Stop button
-
- #define REC_H 189 // Where "Records" gets drawn
- #define REC_V 25 // Vert posn
-
- #define TIME_H 360 // Where Time gets printed.
- #define TIME_V 25 // Vert posn same as above
-
- // Statically declared entities
-
- static long default_vals[5] = { 25000, 25000, 25000, 25000, 25000 };
- static long default_maxs[5] = { 1000000, 1000000, 1000000, 1000000, 1000000 };
-
-
- static Str255 Txts = "\p00";
- static Str255 PhaseNames[] = { "\pInsert", "\pLocate Randomly",
- "\pLocate Serially", "\pChange", "\pDelete"
- };
- static Str255 ColNames[] = { "\pTotal", "\pSo Far", "\pPer Record", "\pTotal"
- };
-
- void CNeoBenchPane::INeoBenchPane(CView *anEnclosure, CBureaucrat *aSupervisor,
- short aWidth, short aHeight,
- short aHEncl, short aVEncl,
- SizingOption aHSizing, SizingOption aVSizing)
- {
- short index, j;
- short hpos, vpos;
- long value;
- Str255 someText;
-
- CPane::IPane(anEnclosure, aSupervisor, aWidth, aHeight,
- aHEncl, aVEncl, aHSizing, aVSizing);
-
- SetWantsClicks(TRUE); // Want to respond to clicks.
-
- // -----------------------------------------------------------
- // Make the Stat Text Column names going across
- // -----------------------------------------------------------
-
- vpos = STAT_HDR_TOP; // Init the vert position
- hpos = H_TOTAL; // And the Horiz position
-
- for (index = kMinCol; index <= kMaxCol; index++) {
- NeoFailNil(NeoStatsAcross[index] = new CRawText);
- NeoStatsAcross[index]->IRawText(this, this, ColNames[index], hpos, vpos,
- STAT_WID, STAT_HGT,
- systemFont, normal, 12, teJustCenter);
- hpos += H_DIST;
- }
-
- // -----------------------------------------------------------
- // Make the Stat Text Phase names going down
- // -----------------------------------------------------------
- vpos = V_TOTAL;
- hpos = LEFT_STAT;
-
- for (index = kMinPhase; index <= kMaxPhase; index++) {
- NeoFailNil(NeoPhaseNames[index] = new CRawText);
- NeoPhaseNames[index]->IRawText(this, this, PhaseNames[index],
- hpos, vpos,
- PHASE_NAME_WID, STAT_HGT,
- systemFont, normal, 12, teJustLeft);
-
- vpos += V_DIST;
- }
-
- // -----------------------------------------------------------
- // Make the Editable Text boxes going down
- // -----------------------------------------------------------
- vpos = V_TOTAL;
- hpos = H_TOTAL;
-
- for (index = kMinPhase; index <= kMaxPhase; index++) {
- NeoEditTexts[index] = new CIntegerText(this, this, TOT_WID, TOT_HGT, hpos, vpos,
- aHSizing, aVSizing, /* TOT_WID -2 */ -1, FALSE, FALSE,
- MAXLONG, 0, default_maxs[index], default_vals[index], TRUE);
- NeoFailNil(NeoEditTexts[index]);
- value = default_vals[index];
- NeoEditTexts[index]->SetIntValue(value);
- vpos += V_DIST;
- }
-
- // -----------------------------------------------------------
- // Make the Stat Text boxes going down and across
- // -----------------------------------------------------------
- vpos = V_STAT_START;
-
- for (index = kMinPhase; index <= kMaxPhase; index++) {
- hpos = H_STAT_START;
- for (j = kSoFar; j <= kMaxCol; j++) {
- switch (j) {
- case kSoFar:
- NeoFailNil(NeoRawTexts[index][j] = new CRawText);
- break;
-
- case kPerRecord:
- case kTotal:
- NeoFailNil(NeoRawTexts[index][j] = new CTimeText);
- break;
- }
- ((CTimeText *)NeoRawTexts[index][j])->ITimeText(this, this,
- Txts, hpos, vpos, STAT_WID, STAT_HGT, systemFont,
- normal, 12, teJustRight);
- hpos += H_DIST;
- }
- vpos += V_DIST;
- }
- // -----------------------------------------------------------
- // Create the Stop button, and disable it.
- // -----------------------------------------------------------
- NeoStopButton = new CButton(STOP_RES_ID, this, this);
- NeoStopButton->SetClickCmd(cmdSTOP);
- NeoStopButton->Deactivate();
-
- // -----------------------------------------------------------
- // Create the Go button and disable it.
- // -----------------------------------------------------------
- NeoGoButton = new CButton(GO_RES_ID, this, this);
- NeoGoButton->SetClickCmd(cmdGO);
- NeoGoButton->Activate();
-
- //------------------------------------------------------------
- // Now put in the default max value
- //------------------------------------------------------------
- for (index = kMinPhase; index <= kMaxPhase; index++) {
- maxValue[index] = default_maxs[index];
- minValue[index] = 0;
- }
-
- ClearStatPanes();
- }
-
- /***
- * Draw
- *
- * In this method, you draw whatever you need to display in
- * your pane. The area parameter gives the portion of the
- * pane that needs to be redrawn. Area is in frame coordinates.
- *
- ***/
-
- void CNeoBenchPane::Draw(Rect *area)
-
- {
- short row, col;
- short hpos, vpos;
- Rect hiliteRect;
-
- // MoveTo(5, 50);
- // Line(150, 0);
-
- // Draw the lines under each of the numbered stat text boxes
- PenSize(1, 1);
- vpos = V_LINE_POSN;
-
- for (row=0; row < 5; row++) {
- hpos = H_STAT_START;
-
- for (col = 0; col < 3; col++) {
- MoveTo(hpos, vpos);
- Line(STAT_WID, 0);
- hpos += H_DIST;
- }
- vpos += V_DIST;
- }
-
- // Draw the "Records" and the lines.
- MoveTo(REC_H, REC_V);
- Line(0, 16); // Draw line DOWN
- MoveTo(REC_H, REC_V);
- Line(16, 0); // Draw line across
- TextSize(9);
- TextFont(geneva);
- MoveTo(REC_H + 23, REC_V + 3);
- DrawString("\pRecords"); // Draw the string
- MoveTo(REC_H + 64, REC_V);
- Line(16, 0);
- Line(0, 16);
-
- // Draw the "Time" and the lines
- MoveTo(TIME_H, TIME_V);
- Line(0, 16);
- MoveTo(TIME_H, TIME_V);
- Line(24, 0);
- MoveTo(TIME_H + 31, TIME_V + 3);
- DrawString("\pTime");
- MoveTo(TIME_H + 59, TIME_V);
- Line(24, 0);
- Line(0, 16);
-
- // Hilite the appropriate button
- if (((CNeoBenchDoc *)itsSupervisor)->getState() == kStop) {
- SetRect(&hiliteRect, GO_LFT, GO_TOP,
- GO_LFT + GO_WID, GO_TOP + GO_HGT);
- } else {
- SetRect(&hiliteRect, STOP_LFT, STOP_TOP,
- STOP_LFT + STOP_WID, STOP_TOP + STOP_HGT);
- }
- PenSize(2, 2);
- InsetRect(&hiliteRect, -3, -3);
- FrameRoundRect(&hiliteRect, 16, 16);
- }
-
-
- /***
- * DoClick
- *
- * The mouse went down in the pane.
- * In this method you do whatever is appropriate for your
- * application. HitPt is given in frame coordinates. The other
- * parameters, modiferKeys and when, are taken from the event
- * record.
- *
- * If you want to implement mouse tracking, this is the method
- * to do it in. You need to create a subclass of CMouseTask and
- * pass it in a TrackMouse() message to the pane.
- *
- ***/
-
- void CNeoBenchPane::DoClick(Point hitPt, short modifierKeys, long when)
-
- {
- /* what happens when the mouse goes down */
- }
-
-
- /***
- * HitSamePart
- *
- * Test whether pointA and pointB are in the same part.
- * "The same part" means different things for different applications.
- * In the default method, "the same part" means "in the same pane."
- * If you want a different behavior, override this method. For instance,
- * two points might be in the same part if they're within n pixels
- * of each other.
- *
- * PointA and pointB are both in frame coordinates.
- *
- ***/
-
- Boolean CNeoBenchPane::HitSamePart(Point pointA, Point pointB)
-
- {
- return inherited::HitSamePart(pointA, pointB);
- }
-
-
- /***
- * AdjustCursor
- *
- * If you want the cursor to have a different shape in your pane,
- * do it in this method. If you want a different cursor for different
- * parts of the same pane, you'll need to change the mouseRgn like this:
- * 1. Create a region for the "special area" of your pane.
- * 2. Convert this region to global coordinates
- * 3. Set the mouseRgn to the intersection of this region
- * and the original mouseRgn: SectRgn(mouseRgn, myRgn, mouseRgn);
- *
- * The default method just sets the cursor to the arrow. If this is fine
- * for you, don't override this method.
- *
- ***/
-
- void CNeoBenchPane::AdjustCursor(Point where, RgnHandle mouseRgn)
-
- {
- inherited::AdjustCursor(where, mouseRgn);
- }
-
- /********************************************************************
- For a particular index, get the total number converted from the
- TextBox string, and compare it with the limits, and if out of
- limits, adjust them to be back within the given limits.
- ********************************************************************/
- long CNeoBenchPane::GetTotalNum(short index)
- {
- long theNumber;
-
- if (index < kMinPhase || index > kMaxPhase)
- return 0;
-
- theNumber = NeoEditTexts[index]->GetIntValue();
- if (theNumber > maxValue[index]) {
- NeoEditTexts[index]->SetIntValue(maxValue[index]);
- theNumber = maxValue[index];
- }
- if (theNumber < minValue[index]) {
- NeoEditTexts[index]->SetIntValue(minValue[index]);
- theNumber = minValue[index];
-
- }
- return(theNumber);
- }
-
- /*******************************************************************
- ClearStatPanes - Clears out the Stat text panes containing the
- numbers calculated from the run. Sets the numbers to Zero
- in preparation for the run.
- *******************************************************************/
- void CNeoBenchPane::ClearStatPanes(void)
- {
- short row, col;
-
- for (row = kMinPhase; row <= kMaxPhase; row++) {
- for (col = kSoFar; col <= kMaxCol; col++) {
- NeoRawTexts[row][col]->PutValue(0);
- NeoRawTexts[row][col]->Refresh();
- }
- }
- }
-
- /*******************************************************************
- UpdateCol - Given an index into the phase array ( 0 - 4), and
- an index into the row (0 - 2), we put the value into the
- static text area of the dialog box.
- *******************************************************************/
- void CNeoBenchPane::UpdateCol(short aPhase, short aRow, long aValue)
- {
- // Do error bounds checking, because it spits and sparksten
- // if these arrays are out of bounds.
-
- if (aPhase > kMaxPhase || aPhase < kMinPhase || aRow > kMaxCol || aRow < kMinCol)
- return;
-
- NeoRawTexts[aPhase][aRow]->PutValue(aValue);
- }
-
-
- #define CR 0x24
- /*******************************************************************
-
- *******************************************************************/
- void CNeoBenchPane::DoKeyDown(
- char theChar, /* The associated character */
- Byte keyCode, /* Code for the associated key */
- EventRecord *macEvent) /* Key down event record */
- {
- /* Pass it on to the supervisor */
- if (keyCode == CR) {
- if (((CNeoBenchDoc *)itsSupervisor)->getState() == kStop) {
- DoCommand(cmdGO);
- } else {
- DoCommand(cmdSTOP);
- }
- }
- inherited::DoKeyDown(theChar, keyCode, macEvent);
- }
-
- /*******************************************************************
-
- *******************************************************************/
- void CNeoBenchPane::DoCommand(
- long theCommand) /* Command number */
- {
- switch(theCommand) {
- case cmdSTOP: // We change the button state here
- // but our supervisor has to do more
- ((CNeoBenchDoc *)itsSupervisor)->setState(kStop);
- NeoStopButton->Deactivate();
- NeoGoButton->Activate();
- Refresh();
- break;
-
- case cmdGO:
- ((CNeoBenchDoc *)itsSupervisor)->setState(kStart);
- NeoGoButton->Deactivate();
- NeoStopButton->Activate();
- Refresh();
- break;
- }
- /* Pass it on to the supervisor */
- inherited::DoCommand(theCommand);
- }
-
-
-