home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / NeoIntroTCL3.0 folder / TCL / NeoBench / Source / CNeoBenchPane.cp < prev    next >
Encoding:
Text File  |  1994-09-02  |  12.3 KB  |  433 lines  |  [TEXT/KAHL]

  1. /****
  2.  * CNeoBenchPane.c
  3.  *
  4.  *    Pane methods for a typical application.
  5.  *
  6.  *  Copyright © 1990 Symantec Corporation.  All rights reserved.
  7.  *
  8.  ****/
  9.  
  10. #include "NeoTypes.h"
  11. #include "CNeoBenchPane.h"
  12. #include "CIntegerText.h"
  13. #include "CRawText.h"
  14. #include "CNeoBenchDoc.h"
  15.  
  16. /**
  17.  * Constants that define the locations of the panes that get created
  18.  * And also their spacing.
  19.  **/
  20.  
  21. #define    H_TOTAL            153    // Vert and Hor positions of top Total
  22. #define    V_TOTAL            67  // Editable textbox
  23.  
  24. #define H_STAT_START    236    // Vert and Hor position of top left
  25. #define V_STAT_START    67    // Static text array
  26.  
  27. #define    V_LINE_POSN        82    // Where the lines are drawn for the
  28.                             // first item.
  29.  
  30. #define TOT_SOFAR_DIST  83    // Horiz distance from Total to "So Far" text
  31.  
  32. #define H_DIST            85    // Horiz distance between Stat text panes
  33. #define V_DIST            30    // Vertical distance between text panes.
  34.  
  35. #define TOT_WID            75    // Width of Total Edit text boxes
  36. #define TOT_HGT            16    // Height of the Total EditText box
  37.  
  38. #define STAT_WID        78    // Width of Static text area
  39. #define STAT_HGT        21    // Height of Static Text area
  40.  
  41. #define STOP_WID        85    // Width of stop button
  42. #define STOP_HGT        25    // Height of stop button
  43. #define STOP_TOP        225 // Top position
  44. #define STOP_LFT        275    // Left position
  45.  
  46. #define GO_WID            85    // Width of Go button
  47. #define GO_HGT            25    // Height of Go button
  48. #define GO_TOP            225 // Top position
  49. #define GO_LFT            400 // Left position
  50.  
  51. #define LEFT_STAT        13    // Left most position of Stat Text
  52.  
  53. #define STAT_HDR_TOP    42    // Top vert position of the Stat Text titles
  54. #define PHASE_NAME_WID  130 // Width of Phase names
  55.  
  56. #define GO_RES_ID         129 // Res ID of Go button
  57. #define STOP_RES_ID        128    // Res ID of Stop button
  58.  
  59. #define REC_H            189 // Where "Records" gets drawn
  60. #define REC_V            25    // Vert posn
  61.  
  62. #define TIME_H            360 // Where Time gets printed.
  63. #define TIME_V            25    // Vert posn same as above
  64.  
  65. // Statically declared entities
  66.  
  67. static long default_vals[5] = { 25000, 25000, 25000, 25000, 25000 };
  68. static long default_maxs[5] = { 1000000, 1000000, 1000000, 1000000, 1000000 };
  69.  
  70.  
  71. static Str255 Txts = "\p00";
  72. static Str255 PhaseNames[] = { "\pInsert", "\pLocate Randomly",
  73.                                 "\pLocate Serially", "\pChange", "\pDelete"
  74.                                 };
  75. static Str255 ColNames[] = { "\pTotal", "\pSo Far", "\pPer Record", "\pTotal"
  76.                             };
  77.  
  78. void CNeoBenchPane::INeoBenchPane(CView *anEnclosure, CBureaucrat *aSupervisor,
  79.                             short aWidth, short aHeight,
  80.                             short aHEncl, short aVEncl,
  81.                             SizingOption aHSizing, SizingOption aVSizing)
  82. {
  83.     short    index, j;
  84.     short   hpos, vpos;
  85.     long    value;
  86.     Str255  someText;
  87.  
  88.     CPane::IPane(anEnclosure, aSupervisor, aWidth, aHeight,
  89.                             aHEncl, aVEncl, aHSizing, aVSizing);
  90.  
  91.     SetWantsClicks(TRUE);   // Want to respond to clicks.
  92.  
  93.     // -----------------------------------------------------------
  94.     // Make the Stat Text Column names going across
  95.     // -----------------------------------------------------------
  96.  
  97.     vpos = STAT_HDR_TOP;        // Init the vert position
  98.     hpos = H_TOTAL;                // And the Horiz position
  99.  
  100.     for (index = kMinCol; index <= kMaxCol; index++) {
  101.         NeoFailNil(NeoStatsAcross[index] = new CRawText);
  102.         NeoStatsAcross[index]->IRawText(this, this, ColNames[index], hpos, vpos,
  103.                             STAT_WID, STAT_HGT,
  104.                             systemFont, normal, 12, teJustCenter);
  105.         hpos += H_DIST;
  106.     }
  107.  
  108.     // -----------------------------------------------------------
  109.     // Make the Stat Text Phase names going down
  110.     // -----------------------------------------------------------
  111.     vpos = V_TOTAL;
  112.     hpos = LEFT_STAT;
  113.  
  114.     for (index = kMinPhase; index <= kMaxPhase; index++) {
  115.         NeoFailNil(NeoPhaseNames[index] = new CRawText);
  116.         NeoPhaseNames[index]->IRawText(this, this, PhaseNames[index],
  117.                             hpos, vpos,
  118.                             PHASE_NAME_WID, STAT_HGT,
  119.                             systemFont, normal, 12, teJustLeft);
  120.  
  121.         vpos += V_DIST;
  122.     }
  123.  
  124.     // -----------------------------------------------------------
  125.     // Make the Editable Text boxes going down
  126.     // -----------------------------------------------------------
  127.     vpos = V_TOTAL;
  128.     hpos = H_TOTAL;
  129.  
  130.     for (index = kMinPhase; index <= kMaxPhase; index++) {
  131.         NeoEditTexts[index] = new CIntegerText(this, this, TOT_WID, TOT_HGT, hpos, vpos,
  132.                             aHSizing, aVSizing, /* TOT_WID -2 */ -1, FALSE, FALSE,
  133.                             MAXLONG, 0, default_maxs[index], default_vals[index], TRUE);
  134.         NeoFailNil(NeoEditTexts[index]);
  135.         value = default_vals[index];
  136.         NeoEditTexts[index]->SetIntValue(value);
  137.         vpos += V_DIST;
  138.     }
  139.  
  140.     // -----------------------------------------------------------
  141.     // Make the Stat Text boxes going down and across
  142.     // -----------------------------------------------------------
  143.     vpos = V_STAT_START;
  144.  
  145.     for (index = kMinPhase; index <= kMaxPhase; index++) {
  146.         hpos = H_STAT_START;
  147.         for (j = kSoFar; j <= kMaxCol; j++) {
  148.             switch (j) {
  149.             case kSoFar:
  150.                 NeoFailNil(NeoRawTexts[index][j] = new CRawText);
  151.                 break;
  152.  
  153.             case kPerRecord:
  154.             case kTotal:
  155.                 NeoFailNil(NeoRawTexts[index][j] = new CTimeText);
  156.                 break;
  157.             }
  158.             ((CTimeText *)NeoRawTexts[index][j])->ITimeText(this, this,
  159.                 Txts, hpos, vpos, STAT_WID, STAT_HGT, systemFont,
  160.                 normal, 12, teJustRight);
  161.             hpos += H_DIST;
  162.         }
  163.         vpos += V_DIST;
  164.     }
  165.     // -----------------------------------------------------------
  166.     // Create the Stop button,  and disable it.
  167.     // -----------------------------------------------------------
  168.     NeoStopButton = new CButton(STOP_RES_ID, this, this);
  169.     NeoStopButton->SetClickCmd(cmdSTOP);
  170.     NeoStopButton->Deactivate();
  171.  
  172.     // -----------------------------------------------------------
  173.     // Create the Go button and disable it.
  174.     // -----------------------------------------------------------
  175.     NeoGoButton = new CButton(GO_RES_ID, this, this);
  176.     NeoGoButton->SetClickCmd(cmdGO);
  177.     NeoGoButton->Activate();
  178.  
  179.     //------------------------------------------------------------
  180.     // Now put in the default max value
  181.     //------------------------------------------------------------
  182.     for (index = kMinPhase; index <= kMaxPhase; index++) {
  183.         maxValue[index] = default_maxs[index];
  184.         minValue[index] = 0;
  185.     }
  186.  
  187.     ClearStatPanes();
  188. }
  189.  
  190. /***
  191.  * Draw
  192.  *
  193.  *    In this method, you draw whatever you need to display in
  194.  *    your pane. The area parameter gives the portion of the
  195.  *    pane that needs to be redrawn. Area is in frame coordinates.
  196.  *
  197.  ***/
  198.  
  199. void CNeoBenchPane::Draw(Rect *area)
  200.  
  201. {
  202.     short    row, col;
  203.     short    hpos, vpos;
  204.     Rect    hiliteRect;
  205.  
  206.     // MoveTo(5, 50);
  207.     // Line(150, 0);
  208.  
  209.     // Draw the lines under each of the numbered stat text boxes
  210.     PenSize(1, 1);
  211.     vpos = V_LINE_POSN;
  212.  
  213.     for (row=0; row < 5; row++) {
  214.         hpos = H_STAT_START;
  215.  
  216.         for (col = 0; col < 3; col++) {
  217.             MoveTo(hpos, vpos);
  218.             Line(STAT_WID, 0);
  219.             hpos += H_DIST;
  220.         }
  221.         vpos += V_DIST;
  222.     }
  223.  
  224.     // Draw the "Records" and the lines.
  225.     MoveTo(REC_H, REC_V);
  226.     Line(0, 16);                // Draw line DOWN
  227.     MoveTo(REC_H, REC_V);
  228.     Line(16, 0);                    // Draw line across
  229.     TextSize(9);
  230.     TextFont(geneva);
  231.     MoveTo(REC_H + 23, REC_V + 3);
  232.     DrawString("\pRecords");    // Draw the string
  233.     MoveTo(REC_H + 64, REC_V);
  234.     Line(16, 0);
  235.     Line(0, 16);
  236.  
  237.     // Draw the "Time" and the lines
  238.     MoveTo(TIME_H, TIME_V);
  239.     Line(0, 16);
  240.     MoveTo(TIME_H, TIME_V);
  241.     Line(24, 0);
  242.     MoveTo(TIME_H + 31, TIME_V + 3);
  243.     DrawString("\pTime");
  244.     MoveTo(TIME_H + 59, TIME_V);
  245.     Line(24, 0);
  246.     Line(0, 16);
  247.  
  248.     // Hilite the appropriate button
  249.     if (((CNeoBenchDoc *)itsSupervisor)->getState() == kStop) {
  250.         SetRect(&hiliteRect, GO_LFT, GO_TOP,
  251.                                 GO_LFT + GO_WID, GO_TOP + GO_HGT);
  252.     } else {
  253.         SetRect(&hiliteRect, STOP_LFT, STOP_TOP,
  254.                                 STOP_LFT + STOP_WID, STOP_TOP + STOP_HGT);
  255.     }
  256.     PenSize(2, 2);
  257.     InsetRect(&hiliteRect, -3, -3);
  258.     FrameRoundRect(&hiliteRect, 16, 16);
  259. }
  260.  
  261.  
  262. /***
  263.  * DoClick
  264.  *
  265.  *    The mouse went down in the pane.
  266.  *    In this method you do whatever is appropriate for your
  267.  *    application. HitPt is given in frame coordinates. The other
  268.  *    parameters, modiferKeys and when, are taken from the event
  269.  *    record.
  270.  *
  271.  *    If you want to implement mouse tracking, this is the method
  272.  *    to do it in. You need to create a subclass of CMouseTask and
  273.  *    pass it in a TrackMouse() message to the pane.
  274.  *
  275.  ***/
  276.  
  277. void CNeoBenchPane::DoClick(Point hitPt, short modifierKeys, long when)
  278.  
  279. {
  280.     /* what happens when the mouse goes down */
  281. }
  282.  
  283.  
  284. /***
  285.  * HitSamePart
  286.  *
  287.  *    Test whether pointA and pointB are in the same part.
  288.  *    "The same part" means different things for different applications.
  289.  *    In the default method, "the same part" means "in the same pane."
  290.  *    If you want a different behavior, override this method. For instance,
  291.  *    two points might be in the same part if they're within n pixels
  292.  *  of each other.
  293.  *
  294.  *    PointA and pointB are both in frame coordinates.
  295.  *
  296.  ***/
  297.  
  298. Boolean        CNeoBenchPane::HitSamePart(Point pointA, Point pointB)
  299.  
  300. {
  301.     return inherited::HitSamePart(pointA, pointB);
  302. }
  303.  
  304.  
  305. /***
  306.  * AdjustCursor
  307.  *
  308.  *    If you want the cursor to have a different shape in your pane,
  309.  *    do it in this method. If you want a different cursor for different
  310.  *    parts of the same pane, you'll need to change the mouseRgn like this:
  311.  *        1. Create a region for the "special area" of your pane.
  312.  *        2. Convert this region to global coordinates
  313.  *        3. Set the mouseRgn to the intersection of this region
  314.  *            and the original mouseRgn: SectRgn(mouseRgn, myRgn, mouseRgn);
  315.  *
  316.  *    The default method just sets the cursor to the arrow. If this is fine
  317.  *    for you, don't override this method.
  318.  *
  319.  ***/
  320.  
  321. void CNeoBenchPane::AdjustCursor(Point where, RgnHandle mouseRgn)
  322.  
  323. {
  324.     inherited::AdjustCursor(where, mouseRgn);
  325. }
  326.  
  327. /********************************************************************
  328.   For a particular index,   get the total number converted from the
  329.   TextBox string,  and compare it with the limits,  and if out of
  330.   limits,  adjust them to be back within the given limits.
  331. ********************************************************************/
  332. long    CNeoBenchPane::GetTotalNum(short index)
  333. {
  334.     long    theNumber;
  335.  
  336.     if (index < kMinPhase || index > kMaxPhase)
  337.         return 0;
  338.  
  339.     theNumber = NeoEditTexts[index]->GetIntValue();
  340.     if (theNumber > maxValue[index]) {
  341.         NeoEditTexts[index]->SetIntValue(maxValue[index]);
  342.         theNumber = maxValue[index];
  343.     }
  344.     if (theNumber < minValue[index]) {
  345.         NeoEditTexts[index]->SetIntValue(minValue[index]);
  346.         theNumber = minValue[index];
  347.  
  348.     }
  349.     return(theNumber);
  350. }
  351.  
  352. /*******************************************************************
  353.   ClearStatPanes - Clears out the Stat text panes containing the
  354.   numbers calculated from the run.   Sets the numbers to Zero
  355.   in preparation for the run.
  356. *******************************************************************/
  357. void    CNeoBenchPane::ClearStatPanes(void)
  358. {
  359.     short    row, col;
  360.  
  361.     for (row = kMinPhase; row <= kMaxPhase; row++) {
  362.         for (col = kSoFar; col <= kMaxCol; col++) {
  363.             NeoRawTexts[row][col]->PutValue(0);
  364.             NeoRawTexts[row][col]->Refresh();
  365.         }
  366.     }
  367. }
  368.  
  369. /*******************************************************************
  370.   UpdateCol - Given an index into the phase array ( 0 - 4),  and
  371.   an index into the row (0 - 2),  we put the value into the
  372.   static text area of the dialog box.
  373. *******************************************************************/
  374. void    CNeoBenchPane::UpdateCol(short aPhase, short aRow, long aValue)
  375. {
  376.     // Do error bounds checking,  because it spits and sparksten
  377.     // if these arrays are out of bounds.
  378.  
  379.     if (aPhase > kMaxPhase || aPhase < kMinPhase || aRow > kMaxCol || aRow < kMinCol)
  380.         return;
  381.  
  382.     NeoRawTexts[aPhase][aRow]->PutValue(aValue);
  383. }
  384.  
  385.  
  386. #define CR 0x24
  387. /*******************************************************************
  388.  
  389. *******************************************************************/
  390. void    CNeoBenchPane::DoKeyDown(
  391.     char            theChar,            /* The associated character            */
  392.     Byte            keyCode,            /* Code for the associated key        */
  393.     EventRecord        *macEvent)            /* Key down event record            */
  394. {
  395.                                         /* Pass it on to the supervisor        */
  396.     if (keyCode == CR) {
  397.         if (((CNeoBenchDoc *)itsSupervisor)->getState() == kStop) {
  398.             DoCommand(cmdGO);
  399.         } else {
  400.             DoCommand(cmdSTOP);
  401.         }
  402.     }
  403.     inherited::DoKeyDown(theChar, keyCode, macEvent);
  404. }
  405.  
  406. /*******************************************************************
  407.  
  408. *******************************************************************/
  409. void    CNeoBenchPane::DoCommand(
  410.     long        theCommand)                /* Command number                    */
  411. {
  412.     switch(theCommand) {
  413.         case    cmdSTOP:            // We change the button state here
  414.                                     // but our supervisor has to do more
  415.                 ((CNeoBenchDoc *)itsSupervisor)->setState(kStop);
  416.                 NeoStopButton->Deactivate();
  417.                 NeoGoButton->Activate();
  418.                 Refresh();
  419.                 break;
  420.  
  421.         case    cmdGO:
  422.                 ((CNeoBenchDoc *)itsSupervisor)->setState(kStart);
  423.                 NeoGoButton->Deactivate();
  424.                 NeoStopButton->Activate();
  425.                 Refresh();
  426.                 break;
  427.     }
  428.                                         /* Pass it on to the supervisor        */
  429.     inherited::DoCommand(theCommand);
  430. }
  431.  
  432.  
  433.