home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Tools - Objects / MacApp / MacApp 2.0 CD Release / MacApp 2.0 (Many Libraries) / Examples / CPlusExamples / DemoDialogs / UDemoDialogs.cp < prev    next >
Encoding:
Text File  |  1990-03-27  |  49.1 KB  |  1,667 lines  |  [TEXT/MPS ]

  1. // Copyright © 1989-1990 by Apple Computer, Inc.  All rights reserved. 
  2.  
  3.  
  4. #ifndef __UDEMODIALOGS__
  5. #include "UDemoDialogs.h"
  6. #endif
  7.  
  8. extern "C" int strncmp (const char *s1, const char *s2, int n);
  9. extern "C" char* memcpy(void*, void*, int);
  10. #define pstrcpy(p,q) memcpy(p, q, q[0]+1)                    // added for translation: Pascal strcpy
  11.  
  12. // Constants
  13. const short kNoOfLines        = 10000;
  14. const short kMaxScrollBar    = 1000;
  15. const short kTestIcon        = 1000;
  16. const short kTestAlert        = 1000;
  17. const short kTestPopup        = 235;
  18. const short kBaudPopup        = 236;
  19. const short kParityPopup    = 237;
  20. const short kTestPicture    = 1000;
  21. const short kTestStatic     = 1000;
  22. const short kMaxPlaces        = 13;
  23.  
  24. // Constants for Command Items
  25. const short cFirstItem        = 1001;
  26. const short cProcedureViews = 1001;
  27. const short cTemplateViews    = 1002;
  28. const short cMonthlyDialog    = 1003;
  29. const short cSaveDialog     = 1004;
  30. const short cMarkDialog     = 1005;
  31. const short cPageSetupDialog    = 1006;
  32. const short cHomeBrewControls    = 1007;
  33. const short cTabbingTest    = 1008;
  34. const short cCalculator     = 1009;
  35. const short cScrollingTest    = 1011;
  36. const short cFormatDialog    = 1012;
  37. const short cModelessMarkDialog    = 1013;
  38. const short cLastItem        = 1013;
  39. const short cPopupExample    = 1100;
  40.  
  41. const short mUpArrow        = 100;
  42. const short mDownArrow        = 101;
  43. const short mTemperatureChanged        = 102;
  44.  
  45.  
  46. struct FondRecord {
  47.     FamRec familyStuff;
  48.     short noOfFonts;
  49.     struct {
  50.         short size;
  51.         short style;
  52.         short resID;
  53.     } fontStuff[1000];    // not 1001!
  54. };
  55. typedef FondRecord *FondPointer, **FondHandle;
  56.  
  57. static void MakeProcedureViews(CmdNumber aCmdNumber);
  58. static void MakeTemplateViews(CmdNumber aCmdNumber, TTestApplication *aTestApp);
  59. static void MakeScrollingTest(CmdNumber aCmdNumber);
  60. static void MakeMonthlyDialog(CmdNumber aCmdNumber);
  61. static void MakeSaveDialog(CmdNumber aCmdNumber);
  62. static void MakeMarkDialog(CmdNumber aCmdNumber);
  63. static void MakeFormatDialog(CmdNumber aCmdNumber);
  64. static void MakePageSetupDialog(CmdNumber aCmdNumber);
  65. static void MakeHomeBrewControls(CmdNumber aCmdNumber);
  66. static void MakeTabTest(CmdNumber aCmdNumber);
  67. static void MakeCalculator(CmdNumber aCmdNumber);
  68. static void MakeModelessMarkDialog(CmdNumber aCmdNumber);
  69. //--------------------------------------------------------------------------------------------------
  70.  
  71.  
  72. long gMonthlyValues[13];    // this should be [12] since we index relative to 0 ???
  73. IDType gMonthIDs[13];
  74.  
  75. //********************************************************************************************
  76. //    T T e s t A p p l i c a t i o n
  77. //********************************************************************************************
  78. //--------------------------------------------------------------------------------------------------
  79. #pragma segment AInit
  80.  
  81. pascal void 
  82. TTestApplication::ITestApplication(OSType itsMainFileType)
  83. {
  84.     Ptr                 monthIDs;
  85.     TMonthlyDialog *aMonthlyDialog;
  86.     TArrowsControl *anArrowsControl;
  87.     TTemperatureCluster *aTemperatureCluster;
  88.     TTemperatureConversionCluster *aTemperatureConversionCluster;
  89.     THomeBrewDialog *anHomeBrewDialog;
  90.     TSlider *aSlider;
  91.     TPageSetupDialog *aPageSetupDialog;
  92.     TRadioIcon *aRadioIcon;
  93.     TSumStaticText *aSumStaticText;
  94.     TCalcDialog *aCalcDialog;
  95.     TNumbersView *aNumbersView;
  96.     TFontListView *aFontListView;
  97.     TSizeListView *aSizeListView;
  98.     TModelessMarkDialog *aModelessMarkDialog;
  99.     TScrollBar *aScrollBar;
  100.  
  101.  
  102.     IApplication(itsMainFileType);
  103.     fLaunchWithNewDocument = FALSE;        // Suppress the creation of a new document at launch
  104.  
  105.     monthIDs = "jan feb mar apr may jun jul aug sep oct nov dec ";
  106.     BlockMove(monthIDs, (Ptr) gMonthIDs, sizeof(gMonthIDs));
  107.  
  108.     for (short i = 0 ; i < 12 ; i++) {
  109.         gMonthlyValues[i] = (i+1) * 100;
  110.     }
  111.     if (gDeadStripSuppression) { // Hack so linker won't dead strip our custom view descendants
  112.         aMonthlyDialog = new TMonthlyDialog;
  113.         anArrowsControl = new TArrowsControl;
  114.         aTemperatureCluster = new TTemperatureCluster;
  115.         aTemperatureConversionCluster = new TTemperatureConversionCluster;
  116.         aSlider = new TSlider;
  117.         anHomeBrewDialog = new THomeBrewDialog;
  118.         aFontListView = new TFontListView;
  119.         aSizeListView = new TSizeListView;
  120.         aRadioIcon = new TRadioIcon;
  121.         aPageSetupDialog = new TPageSetupDialog;
  122.         aSumStaticText = new TSumStaticText;
  123.         aCalcDialog = new TCalcDialog;
  124.         aNumbersView = new TNumbersView;
  125.         aModelessMarkDialog = new TModelessMarkDialog;
  126.         aScrollBar = new TScrollBar;
  127.     }
  128. }    
  129.  
  130. /*--------------------------------------------------------------------------------------------------*/
  131. #pragma segment ASelCommand
  132.  
  133. pascal TCommand *
  134. TTestApplication::DoMenuCommand(CmdNumber aCmdNumber)
  135. {
  136.     TCommand *returnVal = NULL;
  137.  
  138.     switch (aCmdNumber) {
  139.         case cProcedureViews:
  140.             MakeProcedureViews(aCmdNumber);
  141.             break;
  142.         case cTemplateViews:
  143.             MakeTemplateViews(aCmdNumber, this);
  144.             break;
  145.         case cScrollingTest:
  146.             MakeScrollingTest(aCmdNumber);
  147.             break;
  148.         case cMonthlyDialog:
  149.             MakeMonthlyDialog(aCmdNumber);
  150.             break;
  151.         case cSaveDialog:
  152.             MakeSaveDialog(aCmdNumber);
  153.             break;
  154.         case cMarkDialog:
  155.             MakeMarkDialog(aCmdNumber);
  156.             break;
  157.         case cModelessMarkDialog:
  158.             MakeModelessMarkDialog(aCmdNumber);
  159.             break;
  160.         case cFormatDialog:
  161.             MakeFormatDialog(aCmdNumber);
  162.             break;
  163.         case cPageSetupDialog:
  164.             MakePageSetupDialog(aCmdNumber);
  165.             break;
  166.         case cHomeBrewControls:
  167.             MakeHomeBrewControls(aCmdNumber);
  168.             break;
  169.         case cTabbingTest:
  170.             MakeTabTest(aCmdNumber);
  171.             break;
  172.         case cCalculator:
  173.             MakeCalculator(aCmdNumber);
  174.             break;
  175.         default:
  176.             returnVal = inherited::DoMenuCommand(aCmdNumber);
  177.             break;
  178.     }
  179.     return returnVal;
  180. }
  181.  
  182.  /*--------------------------------------------------------------------------------------------------*/
  183.  
  184. static void MakeProcedureViews(CmdNumber aCmdNumber)
  185. {
  186.     RGBColor aColor;
  187.     VPoint itsLocation;
  188.     VPoint itsSize;
  189.     TextStyle ts;
  190.     TWindow *aWindow;
  191.     TDialogView *aDialogView;
  192.     TCluster *aCluster;
  193.     TRadio *aRadio[8];
  194.     TButton *aButton;
  195.     TIcon *anIcon;
  196.     TCheckBox *aCheckBox;
  197.     TPopup *aPopup;
  198.     TPicture *aPicture;
  199.     TStaticText *aStaticText;
  200.     TEditText *anEditText;
  201.     Str255 s;
  202.  
  203.     aDialogView = new TDialogView;
  204.     FailNIL(aDialogView);
  205.     SetVPt(&itsSize, 480, 900);
  206.     aDialogView->IDialogView(NULL, NULL, &gZeroVPt, &itsSize, sizeFixed,
  207.                             sizeFixed, kNoIdentifier, kNoIdentifier);
  208.     aDialogView->ParamTxt("\p^0", "\pPARAM0");
  209.     aDialogView->ParamTxt("\p^1", "\pPARAM1");
  210.  
  211.     aWindow = NewSimpleWindow(aCmdNumber, TRUE, TRUE, NULL, aDialogView);
  212.     aWindow->fFreeOnClosing = TRUE;
  213.     aWindow->fMustStagger = TRUE;
  214.     aWindow->fMustForceOnScreen = TRUE;
  215.     aWindow->SimpleStagger(kStdStaggerAmount, kStdStaggerAmount, 
  216.                           &gStdStaggerCount);
  217.  
  218.     aStaticText = new TStaticText;
  219.     FailNIL(aStaticText);
  220.     SetVPt(&itsLocation, 50, 100);
  221.     SetVPt(&itsSize, 300, 150);
  222.     aStaticText->IStaticText(aDialogView, &itsLocation, &itsSize, sizeVariable,
  223.                             sizeVariable, kTestStatic, 1);
  224.     SetRGBColor(&aColor, 0, 0, 0xFFFF);
  225.     SetTextStyle(&ts, applFont, italic, 12, &aColor);
  226.     aStaticText->InstallTextStyle(&ts, kDontRedraw);
  227.     aStaticText->SetJustification(teJustCenter, kRedraw);
  228.  
  229.     aCluster = new TCluster;
  230.     FailNIL(aCluster);
  231.     SetVPt(&itsLocation, 100, 340);
  232.     SetVPt(&itsSize, 150, 190);
  233.     aCluster->ICluster(aDialogView, &itsLocation, &itsSize, sizeVariable,
  234.                       sizeVariable, kNoResource, 0);
  235.     aCluster->SetLabel("\pA Cluster!", kRedraw);
  236.  
  237.     SetVPt(&itsSize, 130, 20);
  238.     for (short i = 0 ; i <= 7 ; i++) {
  239.         aRadio[i] = new TRadio;
  240.         FailNIL(aRadio[i]);
  241.         SetVPt(&itsLocation, 10, (i + 1) * 20);
  242.         aRadio[i]->IRadio(aCluster, &itsLocation, &itsSize, sizeVariable, sizeVariable, (StringPtr) "\p", i == 0);
  243.         SetTextStyle(&ts, systemFont, Style((1 << i)/2), 12, &gRGBBlack);
  244.         aRadio[i]->InstallTextStyle(&ts, kDontRedraw);
  245.         switch (i) {
  246.             case 0:
  247.                 aRadio[i]->SetText("\pPlain", kRedraw);
  248.                 break;
  249.             case 1:
  250.                 aRadio[i]->SetText("\pBold", kRedraw);
  251.                 break;
  252.             case 2:
  253.                 aRadio[i]->SetText("\pItalic", kRedraw);
  254.                 break;
  255.             case 3:
  256.                 aRadio[i]->SetText("\pUnderline", kRedraw);
  257.                 break;
  258.             case 4:
  259.                 aRadio[i]->SetText("\pOutline", kRedraw);
  260.                 break;
  261.             case 5:
  262.                 aRadio[i]->SetText("\pShadow", kRedraw);
  263.                 break;
  264.             case 6:
  265.                 aRadio[i]->SetText("\pCondense", kRedraw);
  266.                 break;
  267.             case 7:
  268.                 aRadio[i]->SetText("\pExtend", kRedraw);
  269.                 break;
  270.         }
  271.     }
  272.  
  273.     aCheckBox = new TCheckBox;
  274.     FailNIL(aCheckBox);
  275.     SetVPt(&itsLocation, 100, 540);
  276.     SetVPt(&itsSize, 100, 20);
  277.     aCheckBox->ICheckBox(aDialogView, &itsLocation, &itsSize, sizeFixed, sizeFixed,
  278.                         "\pCheck Box", FALSE);
  279.     SetTextStyle(&ts, applFont, NULL, 12, &gRGBBlack);
  280.     aCheckBox->InstallTextStyle(&ts, kRedraw);
  281.     
  282.     aButton = new TButton;
  283.     FailNIL(aButton);
  284.     SetVPt(&itsLocation, 270, 540);
  285.     SetVPt(&itsSize, 100, 28);
  286.     aButton->IButton(aDialogView, &itsLocation, &itsSize, sizeVariable, sizeVariable,
  287.                     "\pPush Button");
  288.     SetTextStyle(&ts, applFont, NULL, 10, &gRGBBlack);
  289.     aButton->InstallTextStyle(&ts, kDontRedraw);
  290.     aButton->fAdornment = adnRRect;
  291.     SetPt(&aButton->fPenSize, 3, 3);
  292.     aButton->Inset(4, 4, kRedraw);
  293.     
  294.     anIcon = new TIcon;
  295.     FailNIL(anIcon);
  296.     SetVPt(&itsLocation, 130, 570);
  297.     SetVPt(&itsSize, 35, 35);
  298.     anIcon->IIcon(aDialogView, &itsLocation, &itsSize, sizeFixed, sizeFixed,
  299.                  kTestIcon, kPreferColor);
  300.     anIcon->fAdornment = kFrame | adnShadow;
  301.     anIcon->ViewEnable(TRUE, kDontRedraw);
  302.     anIcon->Inset(1, 1, kDontRedraw);
  303.  
  304.     if (gConfiguration.hasHierarchicalMenus) {
  305.         aPopup = new TPopup;
  306.         FailNIL(aPopup);
  307.         SetVPt(&itsLocation, 290, 589);
  308.         SetVPt(&itsSize, 120, 22);
  309.         aPopup->IPopup(aDialogView, &itsLocation, &itsSize, sizeVariable,
  310.                       sizeVariable, kTestPopup, 2, 50);
  311.  
  312.         aPopup = new TPopup;
  313.         FailNIL(aPopup);
  314.         SetVPt(&itsLocation, 290, 624);
  315.         SetVPt(&itsSize, 120, 22);
  316.         aPopup->IPopup(aDialogView, &itsLocation, &itsSize, sizeVariable,
  317.                       sizeVariable, kBaudPopup, 1, 50);
  318.  
  319.         aPopup = new TPopup;
  320.         FailNIL(aPopup);
  321.         SetVPt(&itsLocation, 290, 659);
  322.         SetVPt(&itsSize, 120, 22);
  323.         aPopup->IPopup(aDialogView, &itsLocation, &itsSize, sizeVariable,
  324.                       sizeVariable, kParityPopup, 1, 50);
  325.     }
  326.  
  327.     aPicture = new TPicture;
  328.     FailNIL(aPicture);
  329.     SetVPt(&itsLocation, 100, 660);
  330.     SetVPt(&itsSize, 0x18C - 0xF0 + 16, 0x12C - 0x8F + 16);
  331.     aPicture->IPicture(aDialogView, &itsLocation, &itsSize, sizeVariable,
  332.                       sizeVariable, kTestPicture);
  333.     SetPt(&aPicture->fPenSize, 2, 2);
  334.     aPicture->fAdornment = adnRRect | adnShadow;
  335.     aPicture->ViewEnable(TRUE, kDontRedraw);
  336.     aPicture->Inset(8, 8, kDontRedraw);
  337.     
  338.     aStaticText = new TStaticText;
  339.     FailNIL(aStaticText);
  340.     SetVPt(&itsLocation, 20, 620);
  341.     SetVPt(&itsSize, 100, 20);
  342.     aStaticText->IStaticText(aDialogView, &itsLocation, &itsSize, sizeVariable,
  343.                             sizeVariable, kTestStatic, 2);
  344.     SetRGBColor(&aColor, 0xFFFF, 0, 0);
  345.     aStaticText->InstallColor(&aColor, kRedraw);
  346.     
  347.     anEditText = new TEditText;
  348.     FailNIL(anEditText);
  349.     SetVPt(&itsLocation, 140, 620);
  350.     SetVPt(&itsSize, 100, 22);
  351.     anEditText->IEditText(aDialogView, &itsLocation, &itsSize, 255);
  352.     SetTextStyle(&ts, applFont, 0, 12, &gRGBBlack);
  353.     anEditText->InstallTextStyle(&ts, kDontRedraw);
  354.     anEditText->SetJustification(teJustRight, kDontRedraw);
  355.     anEditText->SetText("\pEditText", kRedraw);
  356.     
  357. //    aDialogView->DoSelectEditText(anEditText, TRUE);
  358.     aWindow->Open();
  359. }
  360.  
  361.  /*--------------------------------------------------------------------------------------------------*/
  362.  
  363. static void MakeTemplateViews(CmdNumber aCmdNumber, TTestApplication *aTestApp)
  364. {
  365.     TWindow *aWindow;
  366.     TDialogView *aDialogView;
  367.     TPopup *aPopup;
  368.  
  369.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  370.     FailNIL(aWindow);
  371.     aDialogView = (TDialogView *) aWindow->FindSubView('DLOG');
  372.     if (gConfiguration.hasHierarchicalMenus)
  373.         aPopup = (TPopup *) (aTestApp->DoCreateViews(NULL, aDialogView, cPopupExample,
  374.                                       &gZeroVPt));
  375.     aDialogView->ParamTxt("\p^0", "\pPARAM0");
  376.     aDialogView->ParamTxt("\p^1", "\pPARAM1");
  377.     aWindow->Open();
  378. }
  379.  /*--------------------------------------------------------------------------------------------------*/
  380.  
  381. static void MakeScrollingTest(CmdNumber aCmdNumber)
  382. {
  383.     TWindow *aWindow;
  384.     Point minSize;
  385.  
  386.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  387.     FailNIL(aWindow);
  388.     SetPt(&minSize, 315, 260);
  389.     aWindow->SetResizeLimits(minSize, *((Point *) &aWindow->fResizeLimits.bottom));
  390.     aWindow->Open();
  391. }
  392.  
  393.  /*--------------------------------------------------------------------------------------------------*/
  394.  
  395. static void MakeMonthlyDialog(CmdNumber aCmdNumber)
  396. {
  397.     TWindow *aWindow;
  398.     TMonthlyDialog *aMonthlyDialog;
  399.  
  400.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  401.     FailNIL(aWindow);
  402.     aMonthlyDialog = (TMonthlyDialog *) aWindow->FindSubView('DLOG');
  403.     if (aMonthlyDialog != NULL)
  404.         aMonthlyDialog->StuffValues();
  405.     aWindow->Open();
  406. }
  407.  /*--------------------------------------------------------------------------------------------------*/
  408.  
  409. static void MakeSaveDialog(CmdNumber aCmdNumber)
  410. {
  411.     TWindow *aWindow;
  412.     IDType dismisser;
  413.  
  414.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  415.     FailNIL(aWindow);
  416.     dismisser = ((TDialogView *) aWindow->FindSubView('DLOG'))->PoseModally();
  417.  
  418.     #if qDebug
  419.         if (dismisser == 'yes ')
  420.             printf("The user said yes.\n");
  421.         else if (dismisser == 'no  ')
  422.             printf("The user said no.\n");
  423.         else if (dismisser == 'cncl')
  424.             printf("The user cancelled the dialog.\n");
  425.         else
  426.         printf("I don't know how the user responded.\n");
  427.     #endif qDebug
  428.     aWindow->Close();
  429. }
  430.  
  431.  /*--------------------------------------------------------------------------------------------------*/
  432.  
  433. static void MakeMarkDialog(CmdNumber aCmdNumber)
  434. {
  435.     TWindow *aWindow;
  436.     IDType dismisser;
  437.     Str255 theMark;
  438.  
  439.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  440.     FailNIL(aWindow);
  441.  
  442.     dismisser = ((TDialogView *) aWindow->FindSubView('DLOG'))->PoseModally();
  443.     #if qDebug
  444.         if (dismisser == 'ok  ') {
  445.             ((TEditText *) aWindow->FindSubView('mark'))->GetText((StringPtr) &theMark);
  446.             if (theMark[0] == 0)
  447.                 printf("No mark specified.\n");
  448.             else
  449.                 printf("The mark is ‘%P’.\n", &theMark);
  450.         } else
  451.             printf("The dialog was cancelled.\n");
  452.     #endif
  453.     aWindow->Close();
  454. }
  455.  
  456. /*--------------------------------------------------------------------------------------------------*/
  457.  
  458. static void MakeModelessMarkDialog(CmdNumber aCmdNumber)
  459. {
  460.     TWindow *aWindow;
  461.  
  462.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  463.     FailNIL(aWindow);
  464.     aWindow->Open();
  465. }
  466.  
  467. static void MakeFormatDialog(CmdNumber aCmdNumber)
  468. {
  469.     TWindow *aWindow;
  470.     TDialogView *theDialog;
  471.     IDType dismisser;
  472.     TSizeListView *theSizeListView;
  473.     TFontListView *theFontListView;
  474.  
  475.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  476.     FailNIL(aWindow);
  477.     theDialog = (TDialogView *) aWindow->FindSubView('DLOG');
  478.  
  479.     theSizeListView = (TSizeListView *) theDialog->FindSubView('slst');
  480.     theSizeListView->InitSizeList();
  481.  
  482.     theFontListView = (TFontListView *) theDialog->FindSubView('flst');
  483.     theFontListView->InitFontList();
  484.  
  485.     dismisser = theDialog->PoseModally();
  486.     #if qDebug
  487.         if( dismisser != 'ok  ')
  488.             printf("The dialog was cancelled.\n");
  489.     #endif
  490.     aWindow->Close();
  491. }
  492.  
  493.  
  494.  /*--------------------------------------------------------------------------------------------------*/
  495.  
  496. static void MakePageSetupDialog(CmdNumber aCmdNumber)
  497. {
  498.     TWindow *aWindow;
  499.     TPageSetupDialog *theDialog;
  500.     IDType dismisser;
  501.     VHSelect orientation;
  502.  
  503.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  504.     FailNIL(aWindow);
  505.     theDialog = (TPageSetupDialog *) aWindow->FindSubView('DLOG');
  506.     theDialog->GetOrientation(&orientation);
  507.     ((TRadioIcon *) theDialog->FindSubView('vert'))->HiliteState(orientation == v, kDontRedraw);
  508.     ((TRadioIcon *) theDialog->FindSubView('horz'))->HiliteState(orientation == h, kDontRedraw);
  509.  
  510.     dismisser = theDialog->PoseModally();
  511.     #if qDebug
  512.         if (dismisser == 'ok  ') {
  513.         } else
  514.             printf("The dialog was cancelled.\n");
  515.     #endif
  516.     aWindow->Close();
  517. }
  518.  
  519.  /*--------------------------------------------------------------------------------------------------*/
  520.  
  521. static void MakeHomeBrewControls(CmdNumber aCmdNumber)
  522. {
  523.     TWindow *aWindow;
  524.  
  525.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  526.     FailNIL(aWindow);
  527.     aWindow->Open();
  528. }
  529.  
  530.  /*--------------------------------------------------------------------------------------------------*/
  531.  
  532. static void MakeTabTest(CmdNumber aCmdNumber)
  533. {
  534.     TWindow *aWindow;
  535.  
  536.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  537.     FailNIL(aWindow);
  538.     aWindow->Open();
  539. }
  540.  
  541.  /*--------------------------------------------------------------------------------------------------*/
  542.  
  543. static void MakeCalculator(CmdNumber aCmdNumber)
  544. {
  545.     TWindow *aWindow;
  546.     TCalcDialog *aCalcDialog;
  547.  
  548.     aWindow = NewTemplateWindow(aCmdNumber, NULL);
  549.     FailNIL(aWindow);
  550.     aCalcDialog = (TCalcDialog *) aWindow->FindSubView('DLOG');
  551.     aCalcDialog->ClearSum();
  552.     aWindow->Open();
  553. }
  554.  
  555. /*--------------------------------------------------------------------------------------------------*/
  556. #pragma segment ARes
  557.  
  558. pascal void TTestApplication::DoSetupMenus()
  559. {
  560.     inherited::DoSetupMenus();
  561.     
  562.     for (short i = cFirstItem; i<=cLastItem; i++)
  563.         Enable(i, TRUE);    
  564. }
  565.  
  566.  /*--------------------------------------------------------------------------------------------------*/
  567. #pragma segment AFields
  568.  
  569. pascal void 
  570. TTestApplication::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  571.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  572. {
  573.     (*DoToField)("\pTTestApplication", NULL, bClass, DoToField_StaticLink);
  574.     TApplication::Fields(DoToField, DoToField_StaticLink);
  575. }
  576.  
  577. //********************************************************************************************
  578. //    T N u m b e r s V i e w 
  579. //*******************************************************************************************
  580. //--------------------------------------------------------------------------------------------------
  581. #pragma segment ARes
  582.  
  583. pascal void TNumbersView::Draw(Rect *area)
  584. {
  585.     VRect viewRect;
  586.     long i, firstLine, lastLine;
  587.     VPoint vPt;
  588.     Point pt;
  589.     Str255 s;
  590.  
  591.     QDToViewRect(area, &viewRect);
  592.     viewRect.right = viewRect.right - 1;
  593.     viewRect.bottom = viewRect.bottom - 1;
  594.     firstLine = (viewRect.top / 16) + 1;
  595.     lastLine = (viewRect.bottom / 16) + 1;
  596.     SetPortTextStyle(&gSystemStyle);
  597.     for (i = firstLine; i<=lastLine; i++) {
  598.         SetVPt(&vPt, 0, i * 16);
  599.         pt = ViewToQDPt(&vPt);
  600.         MoveTo(pt.h, pt.v);
  601.         NumToString(i, s);
  602.         DrawString(s);
  603.     }
  604.  
  605.     inherited::Draw(area);
  606. }
  607.  
  608.  /*--------------------------------------------------------------------------------------------------*/
  609. #pragma segment AFields
  610.  
  611. pascal void 
  612. TNumbersView::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  613.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  614. {
  615.     (*DoToField)("\pTNumbersView", NULL, bClass, DoToField_StaticLink);
  616.     TView::Fields(DoToField, DoToField_StaticLink);
  617. }
  618.  
  619. //********************************************************************************************
  620. //    T M o n t h l y D i a l o g 
  621. //*******************************************************************************************
  622. //--------------------------------------------------------------------------------------------------
  623. #pragma segment AClose
  624.  
  625. pascal void 
  626. TMonthlyDialog::DismissDialog(IDType dismisser)
  627. {
  628.     for (short i = 0; i<12; i++)
  629.         gMonthlyValues[i] = ((TNumberText *) FindSubView(gMonthIDs[i]))->GetValue();
  630.  
  631.     inherited::DismissDialog(dismisser);
  632. }
  633.  
  634. /*--------------------------------------------------------------------------------------------------*/
  635. #pragma segment ARes
  636.  
  637. pascal TCommand *
  638. TMonthlyDialog::DoKeyCommand(short ch, short aKeyCode, EventInfo *info)
  639. {
  640.  
  641.     /* If option-tab is pressed, deselect the current edit text and 
  642.        leave nothing selected. This is for test purposes only.    
  643.        It is not part of the Macintosh user interface. */
  644.  
  645.     if ((ch == chTab) && (info->theOptionKey)) {
  646.         DoSelectEditText(NULL, FALSE);
  647.         return (NULL);
  648.     } else
  649.         return (inherited::DoKeyCommand(ch, aKeyCode, info));
  650. }
  651.  
  652. /*--------------------------------------------------------------------------------------------------*/
  653. #pragma segment ARes
  654.  
  655. pascal void
  656. TMonthlyDialog::StuffValues()
  657. {
  658.     for (short i = 0; i<12; i++)
  659.         ((TNumberText *) FindSubView(gMonthIDs[i]))->SetValue(gMonthlyValues[i], kDontRedraw);
  660. }
  661.  
  662.  /*--------------------------------------------------------------------------------------------------*/
  663. #pragma segment AFields
  664.  
  665. pascal void 
  666. TMonthlyDialog::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  667.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  668. {
  669.     (*DoToField)("\pTMonthlyDialog", NULL, bClass, DoToField_StaticLink);
  670.     TDialogView::Fields(DoToField, DoToField_StaticLink);
  671. }
  672.  
  673. //**************************************************************************************************
  674. //  T M o d e l e s s M a r k D i a l o g                                                           
  675. //**************************************************************************************************
  676. //--------------------------------------------------------------------------------------------------
  677. #pragma segment ARes
  678.  
  679. pascal void 
  680. TModelessMarkDialog::DoChoice (TView *origView, short itsChoice)
  681. {
  682.     Str255    theMark;
  683.  
  684.     switch (itsChoice) {
  685.         case mDefaultKey:            // This handles when user presses the 'return' key
  686.         case mCancelKey:            // This handles when user presses the 'esc' key
  687.         case mButtonHit:            // This handles clicking in 'OK' or 'Cancel' buttons
  688.             if (origView->fIdentifier == fDefaultItem) {
  689.                 ((TEditText *) FindSubView('mark'))->GetText((StringPtr) &theMark);
  690.                 ((TWindow *)GetWindow())->Close();
  691.                 #if qDebug
  692.                 printf("The mark is ‘%P’\n", &theMark);
  693.                 #endif
  694.             } else if (origView->fIdentifier == fCancelItem)
  695.                 ((TWindow *)GetWindow())->Close();
  696.             break;
  697.     }
  698. }
  699.  
  700.  /*--------------------------------------------------------------------------------------------------*/
  701. #pragma segment AFields
  702.  
  703. pascal void 
  704. TModelessMarkDialog::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  705.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  706. {
  707.     (*DoToField)("\pTModelessMarkDialog", NULL, bClass, DoToField_StaticLink);
  708.     TDialogView::Fields(DoToField, DoToField_StaticLink);
  709. }
  710.  
  711. //********************************************************************************************
  712. //    T F o n t L i s t V i e w
  713. //********************************************************************************************
  714. //--------------------------------------------------------------------------------------------------
  715. #pragma segment AOpen
  716.  
  717. short FondAfter(StringPtr fontName, short noOfFonds)
  718. // Find the FOND whose name follows fontName alphabetically, and return its id and name
  719. {
  720.     Handle theFondResource;
  721.     short lastID = 0;
  722.     short thisID;
  723.     ResType itsType;
  724.     Boolean foundFOND = FALSE;
  725.     Str255 lastName;
  726.     Str255 thisName;
  727.  
  728.     pstrcpy((char *) lastName, "\p~~~~~~~~");
  729.     for (short index = 1; index < noOfFonds; index++) {
  730.         theFondResource = GetIndResource('FOND', index);
  731.         GetResInfo(theFondResource, &thisID, &itsType, thisName);
  732.         if ((CompareStrings((StringPtr) &thisName, fontName) == 1) && (CompareStrings((StringPtr) &thisName, (StringPtr) &lastName) == -1)) {
  733.             lastID = thisID;
  734.             pstrcpy(lastName, thisName);
  735.             foundFOND = TRUE;
  736.         }
  737.     }
  738.     if (foundFOND)
  739.         pstrcpy(fontName, lastName);
  740.     else                                             // Skip duplicate FOND names
  741.         pstrcpy(fontName, "\p");
  742.     
  743.     return lastID;
  744. }
  745.  
  746. //--------------------------------------------------------------------------------------------------
  747. #pragma segment AOpen
  748.  
  749. pascal void
  750. TFontListView::InitFontList()
  751. {
  752.     FontListPtr    pFondIDs;
  753.     short        noOfFonds;
  754.     Str255        aString;
  755.     short        fondID;
  756.  
  757.     fFontList = (FontListPtr) NULL;
  758.     noOfFonds = CountResources('FOND');
  759.     if (noOfFonds > kMaxFonds)
  760.         noOfFonds = kMaxFonds;
  761.     pFondIDs = (FontListPtr) NewPermPtr(noOfFonds * sizeof(short));    // array of shorts
  762.     FailNIL(pFondIDs);
  763.     
  764.     pstrcpy(aString, "\p ");
  765.     for (short i = 0; i<=noOfFonds; i++) {                // put each FOND's id in the list… 
  766.         fondID = FondAfter(aString, noOfFonds);            // …in alphabetical order
  767.         (*pFondIDs)[i] = fondID;
  768.         if (Length(aString) == 0) {                        // finished early
  769.             noOfFonds = i;
  770.             break;                                        // break from a for loop
  771.         }
  772.     }
  773.     
  774.     fFontList = pFondIDs;
  775.     InsRowLast(noOfFonds, 16);
  776.  
  777.     SelectItem(1, kDontExtend, kHighlight, kSelect);
  778. }
  779.  
  780. //--------------------------------------------------------------------------------------------------
  781. #pragma segment AClose
  782.  
  783. pascal void
  784. TFontListView::Free()
  785. {
  786.     DisposeIfPtr(fFontList);
  787.     fFontList = (FontListPtr) NULL;
  788.     
  789.     inherited::Free();
  790. }
  791.  
  792. //--------------------------------------------------------------------------------------------------
  793. #pragma segment ARes
  794.  
  795. pascal void
  796. TFontListView::GetItemText(short anItem, StringPtr aString)
  797. {
  798.     Handle theFondResource;
  799.     short itsID;
  800.     ResType itsType;
  801.  
  802.     itsID = (*fFontList)[anItem-1];
  803.     theFondResource = GetResource('FOND', itsID);
  804.     GetResInfo(theFondResource, &itsID, &itsType, aString);
  805. }
  806.  
  807. /*--------------------------------------------------------------------------------------------------*/
  808. #pragma segment ARes
  809.  
  810. pascal void
  811. TFontListView::SelectItem(short anItem, Boolean extendSelection, Boolean highlight,
  812.                             Boolean select)
  813. {
  814.     TView *aView;
  815.  
  816.     inherited::SelectItem(anItem, extendSelection, highlight, select);
  817.  
  818.     if (select) {
  819.         aView = ((TView *) GetWindow())->FindSubView('slst');
  820.         FailNIL(aView);
  821.         ((TSizeListView *) aView)->InstallFontFamily((*fFontList)[anItem-1]);
  822.     }
  823. }
  824.  
  825.  /*--------------------------------------------------------------------------------------------------*/
  826. #pragma segment AFields
  827.  
  828. pascal void 
  829. TFontListView::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  830.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  831. {
  832.     (*DoToField)("\pTFontListView", NULL, bClass, DoToField_StaticLink);
  833.       (*DoToField)("\pfFontList", (Ptr) &fFontList, bPointer, DoToField_StaticLink);
  834.     TTextListView::Fields(DoToField, DoToField_StaticLink);
  835. }
  836.  
  837. //********************************************************************************************
  838. //    T S i z e L i s t V i e w
  839. //********************************************************************************************
  840. /*--------------------------------------------------------------------------------------------------*/
  841. #pragma segment ARes
  842.  
  843. pascal void TSizeListView::InitSizeList()
  844. {
  845.     fSelection = 0;
  846.     fSelectedSize = 9;
  847.     fFondIndex = 0;
  848. }
  849.  
  850. //--------------------------------------------------------------------------------------------------
  851. #pragma segment ARes
  852.  
  853. pascal void
  854. TSizeListView::GetItemText(short anItem, StringPtr aString)
  855. {
  856.     short noOfSizes;
  857.     FondHandle theFond;
  858.  
  859.     theFond = (FondHandle) GetResource('FOND', fFondIndex);
  860.     noOfSizes = 0;
  861.     for (short i = 0; i <= theFond[0]->noOfFonts; i++) {
  862.         if (theFond[0]->fontStuff[i].style == 0 )
  863.             noOfSizes = noOfSizes + 1;
  864.         if (noOfSizes == anItem ) {
  865.             NumToString(theFond[0]->fontStuff[i].size, aString);
  866.             return;
  867.         }
  868.     }
  869.     pstrcpy(aString, "\p");                                        // set it to the empty string
  870. }
  871.  
  872. /*--------------------------------------------------------------------------------------------------*/
  873. #pragma segment AOpen
  874.  
  875. pascal void
  876. TSizeListView::InstallFontFamily(short theFondIndex)
  877. {
  878.     FondHandle theFond;
  879.     short noOfSizes;
  880.     short sizeToSelect;
  881.  
  882.     theFond = (FondHandle) GetResource('FOND', theFondIndex);
  883.     noOfSizes = 0;
  884.     sizeToSelect = 0;
  885.     for (short i = 0; i <= theFond[0]->noOfFonts; i++)
  886.         if (theFond[0]->fontStuff[i].style == 0) {
  887.             noOfSizes = noOfSizes + 1;
  888.             if (theFond[0]->fontStuff[i].size == fSelectedSize)
  889.                 sizeToSelect = noOfSizes;
  890.         }
  891.     fFondIndex = theFondIndex;
  892.     SetNumberOfItems(noOfSizes);
  893.     SelectItem(sizeToSelect, kDontExtend, kDontHighlight, kSelect);
  894.     ForceRedraw();
  895. }
  896.  
  897. /*--------------------------------------------------------------------------------------------------*/
  898. #pragma segment ARes
  899.  
  900. pascal void
  901. TSizeListView::SelectItem(short anItem, Boolean extendSelection, Boolean highlight,
  902.                             Boolean select)
  903. {
  904.     Str255 aString;
  905.     TNumberText *theSizeView;
  906.     long fontSize;
  907.  
  908.     inherited::SelectItem(anItem, extendSelection, highlight, select);
  909.  
  910.     if ( select && (anItem != 0) ) {
  911.         GetItemText(anItem, aString);
  912.         theSizeView = (TNumberText *) (((TView *) GetWindow())->FindSubView('size'));
  913.         theSizeView->SetText((StringPtr) &aString, kRedraw);
  914.         theSizeView->SetSelection(0, SHRT_MAX, kRedraw);
  915.         StringToNum(aString, &fontSize);
  916.         fSelectedSize = fontSize;
  917.     }
  918. }
  919.  
  920. /*--------------------------------------------------------------------------------------------------*/
  921. #pragma segment ARes
  922.  
  923. pascal void
  924. TSizeListView::SetNumberOfItems(short aNumber)
  925. {
  926.     SelectItem(0, kDontExtend, kHighlight, kSelect);
  927.  
  928.     if ( fNumOfRows > aNumber )
  929.         DelItemFirst(fNumOfRows - aNumber);
  930.     else if ( fNumOfRows < aNumber )
  931.         InsItemFirst(aNumber - fNumOfRows);
  932. }
  933.  
  934.  /*--------------------------------------------------------------------------------------------------*/
  935. #pragma segment AFields
  936.  
  937. pascal void 
  938. TSizeListView::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  939.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  940. {
  941.     (*DoToField)("\pTSizeListView", NULL, bClass, DoToField_StaticLink);
  942.       (*DoToField)("\pfSelection", (Ptr) &fSelection, bInteger, DoToField_StaticLink);
  943.       (*DoToField)("\pfSelectedSize", (Ptr) &fSelectedSize, bInteger, DoToField_StaticLink);
  944.     (*DoToField)("\pfFondIndex", (Ptr) &fFondIndex, bInteger, DoToField_StaticLink);
  945.     TTextListView::Fields(DoToField, DoToField_StaticLink);
  946. }
  947.  
  948. //********************************************************************************************
  949. //    T P a g e S e t u p D i a l o g
  950. //********************************************************************************************
  951. //--------------------------------------------------------------------------------------------------
  952. #pragma segment AOpen
  953.  
  954. TPageSetupDialog::TPageSetupDialog()
  955. {
  956.     fOrientation = v;
  957. }
  958.  
  959. //--------------------------------------------------------------------------------------------------
  960. #pragma segment ARes
  961.  
  962. pascal void
  963. TPageSetupDialog::DoChoice(TView *origView, short itsChoice)
  964. {
  965.     
  966.     VHSelect newOrientation;
  967.     TCheckBox *tallAdjCheckBox;
  968.  
  969.     switch (itsChoice) {
  970.         case mIconHit:
  971.             if (origView->fIdentifier == 'vert')
  972.                 newOrientation = v;
  973.             else
  974.                 newOrientation = h;
  975.             if (newOrientation != fOrientation) {
  976.                 ((TRadioIcon *) FindSubView('vert'))->HiliteState(newOrientation == v, kRedraw);
  977.                 ((TRadioIcon *) FindSubView('horz'))->HiliteState(newOrientation == h, kRedraw);
  978.                 tallAdjCheckBox = (TCheckBox *) FindSubView('tall');
  979.                 tallAdjCheckBox->DimState(newOrientation == h, kRedraw);
  980.                 tallAdjCheckBox->SetState(FALSE, kRedraw);
  981.                 fOrientation = newOrientation;
  982.             }
  983.             break;
  984.             
  985.         default:
  986.             inherited::DoChoice(origView, itsChoice);
  987.     }
  988. }
  989.  
  990. /*--------------------------------------------------------------------------------------------------*/
  991. #pragma segment ARes
  992.  
  993. pascal void
  994. TPageSetupDialog::GetOrientation(VHSelect *theOrientation)
  995. {
  996.     *theOrientation = fOrientation;
  997. }
  998.  
  999. /*--------------------------------------------------------------------------------------------------*/
  1000. #pragma segment AFields
  1001.  
  1002. pascal void 
  1003. TPageSetupDialog::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1004.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1005. {
  1006.     (*DoToField)("\pTPageSetupDialog", NULL, bClass, DoToField_StaticLink);
  1007.       (*DoToField)("\pfOrientation", (Ptr) &fOrientation, bVHSelect, DoToField_StaticLink);
  1008.     TDialogView::Fields(DoToField, DoToField_StaticLink);
  1009. }
  1010.  
  1011. //********************************************************************************************
  1012. //    T R a d i o I c o n
  1013. //********************************************************************************************
  1014. //--------------------------------------------------------------------------------------------------
  1015. #pragma segment ADoCommand
  1016.  
  1017. pascal void
  1018. TRadioIcon::TrackMouse(TrackPhase aTrackPhase, VPoint *, 
  1019.                         VPoint *, VPoint *,
  1020.                         Boolean )
  1021. {
  1022.     if (aTrackPhase == trackPress)
  1023.         DoChoice(this, mIconHit);
  1024. }
  1025.  
  1026.  /*--------------------------------------------------------------------------------------------------*/
  1027. #pragma segment AFields
  1028.  
  1029. pascal void 
  1030. TRadioIcon::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1031.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1032. {
  1033.     (*DoToField)("\pTRadioIcon", NULL, bClass, DoToField_StaticLink);
  1034.     TIcon::Fields(DoToField, DoToField_StaticLink);
  1035. }
  1036.  
  1037. //********************************************************************************************
  1038. //    T H o m e B r e w D i a l o g
  1039. //********************************************************************************************
  1040. /*--------------------------------------------------------------------------------------------------*/
  1041. #pragma segment ARes
  1042.  
  1043. pascal Boolean
  1044. THomeBrewDialog::DoSetCursor(Point , RgnHandle )
  1045. // localPoint & cursorRgn removed from declaration so CFront won't complain that it isn't used
  1046. {    
  1047.     CursHandle theCursor;
  1048.  
  1049.     theCursor = GetCursor(crossCursor);
  1050.     SetCursor(*theCursor);
  1051.     return TRUE;
  1052. }
  1053.  
  1054. /*--------------------------------------------------------------------------------------------------*/
  1055. #pragma segment ARes
  1056.  
  1057. pascal TView *
  1058. THomeBrewDialog::HandleCursor(VPoint *theMouse, RgnHandle cursorRgn)
  1059. {
  1060.     if (Focus() && DoSetCursor(ViewToQDPt(theMouse), cursorRgn))
  1061.         return this;
  1062.     else
  1063.         return (TView *) NULL;
  1064. }
  1065.  
  1066.  /*--------------------------------------------------------------------------------------------------*/
  1067. #pragma segment AFields
  1068.  
  1069. pascal void 
  1070. THomeBrewDialog::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1071.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1072. {
  1073.     (*DoToField)("\pTHomeBrewDialog", NULL, bClass, DoToField_StaticLink);
  1074.     TDialogView::Fields(DoToField, DoToField_StaticLink);
  1075. }
  1076.  
  1077. //********************************************************************************************
  1078. //    T A r r o w s C o n t r o l
  1079. //********************************************************************************************
  1080. //--------------------------------------------------------------------------------------------------
  1081. #pragma segment AOpen
  1082.  
  1083. pascal void
  1084. TArrowsControl::IRes(TDocument *itsDocument, TView *itsSuperView, Ptr *itsParams)
  1085. {
  1086.     inherited::IRes(itsDocument, itsSuperView, itsParams);
  1087.     fLastChange = 0;
  1088. }
  1089.  
  1090. /*--------------------------------------------------------------------------------------------------*/
  1091. #pragma segment AClose
  1092.  
  1093. pascal void
  1094. TArrowsControl::TrackMouse(TrackPhase aTrackPhase, VPoint *, 
  1095.                           VPoint *, VPoint *nextPoint, 
  1096.                           Boolean )
  1097. // anchorPoint, previousPoint, & mouseDidMove removed from declaration so CFront won't
  1098. // complain that they aren't used
  1099. {
  1100.     if (TickCount() >= fLastChange + 5) {
  1101.         fLastChange = TickCount();
  1102.         if (aTrackPhase == trackPress)
  1103.             fLastChange = fLastChange + 10;
  1104.  
  1105.         if (ContainsMouse(nextPoint))
  1106.             if (nextPoint->v <= fSize.v / 2)
  1107.                 DoChoice(this, mUpArrow);
  1108.             else
  1109.                 DoChoice(this, mDownArrow);
  1110.     }
  1111. }
  1112.  
  1113.  /*--------------------------------------------------------------------------------------------------*/
  1114. #pragma segment AFields
  1115.  
  1116. pascal void 
  1117. TArrowsControl::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1118.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1119. {
  1120.     (*DoToField)("\pTArrowsControl", NULL, bClass, DoToField_StaticLink);
  1121.     (*DoToField)("\pfLastChange", (Ptr) &fLastChange, bLongInt, DoToField_StaticLink);
  1122.     TPicture::Fields(DoToField, DoToField_StaticLink);
  1123. }
  1124.  
  1125. //******************************************************************************************
  1126. //  TTemperatureCluster
  1127. //******************************************************************************************
  1128. //--------------------------------------------------------------------------------------------------
  1129. #pragma segment ARes
  1130.  
  1131. pascal void
  1132. TTemperatureCluster::DoChoice(TView *, short itsChoice)
  1133. // origView removed from declaration so CFront won't complain that it isn't used
  1134. {
  1135.     TNumberText *theNumberText;
  1136.     long theNumber;
  1137.  
  1138.     switch (itsChoice) {
  1139.         case mUpArrow:
  1140.         case mDownArrow:
  1141.             theNumberText = (TNumberText *) FindSubView('Numb');
  1142.             theNumber = theNumberText->GetValue();
  1143.             if (itsChoice == mUpArrow)
  1144.                 theNumber++;
  1145.             else
  1146.                 theNumber--;
  1147.             theNumberText->SetValue(theNumber, kRedraw);
  1148.             // fall thru
  1149.         default:
  1150.             inherited::DoChoice(this,mTemperatureChanged);
  1151.             break;
  1152.     }
  1153. }
  1154.  
  1155. //--------------------------------------------------------------------------------------------------
  1156.  
  1157. #pragma segment ARes
  1158.  
  1159. pascal long
  1160. TTemperatureCluster::GetValue()
  1161. {
  1162.     TNumberText *numberText;
  1163.  
  1164.     numberText = (TNumberText *) FindSubView('Numb');
  1165.     return numberText->GetValue();
  1166. }
  1167.  
  1168. //--------------------------------------------------------------------------------------------------
  1169. #pragma segment ARes
  1170.  
  1171. pascal void
  1172. TTemperatureCluster::SetValue(long newValue, Boolean redraw)
  1173. {
  1174.     TNumberText *numberText;
  1175.  
  1176.     numberText = (TNumberText *) FindSubView('Numb');
  1177.     numberText->SetValue(newValue,redraw);
  1178. }
  1179.  
  1180.  /*--------------------------------------------------------------------------------------------------*/
  1181. #pragma segment AFields
  1182.  
  1183. pascal void 
  1184. TTemperatureCluster::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1185.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1186. {
  1187.     (*DoToField)("\pTTemperatureCluster", NULL, bClass, DoToField_StaticLink);
  1188.     TCluster::Fields(DoToField, DoToField_StaticLink);
  1189. }
  1190.  
  1191. //******************************************************************************************
  1192. //  TTemperatureConversionCluster
  1193. //******************************************************************************************
  1194. //--------------------------------------------------------------------------------------------------
  1195. #pragma segment ARes
  1196.  
  1197. pascal void
  1198. TTemperatureConversionCluster::DoChoice(TView *origView, short itsChoice)
  1199. {
  1200.     TTemperatureCluster *Celsius;
  1201.     TTemperatureCluster *Fahrenheit;
  1202.  
  1203.     if (itsChoice == mTemperatureChanged) {
  1204.         Celsius = (TTemperatureCluster *) FindSubView('Cels');
  1205.         FailNIL(Celsius);
  1206.         Fahrenheit = (TTemperatureCluster *) FindSubView('Fahr');
  1207.         FailNIL(Fahrenheit);
  1208.         if (origView == Celsius)
  1209.             Fahrenheit->SetValue(Celsius->GetValue()*1.8+32,kRedraw);
  1210.         else {
  1211.             if (origView == Fahrenheit)
  1212.                 Celsius->SetValue((Fahrenheit->GetValue()-32)/1.8,kRedraw);
  1213.         }
  1214.     }
  1215.     else
  1216.         inherited::DoChoice(this,mTemperatureChanged);
  1217. }
  1218.  
  1219.  /*--------------------------------------------------------------------------------------------------*/
  1220. #pragma segment AFields
  1221.  
  1222. pascal void 
  1223. TTemperatureConversionCluster::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1224.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1225. {
  1226.     (*DoToField)("\pTTemperatureConversionCluster", NULL, bClass, DoToField_StaticLink);
  1227.     TCluster::Fields(DoToField, DoToField_StaticLink);
  1228. }
  1229.  
  1230. //********************************************************************************************
  1231. //    T S l i d e r
  1232. //********************************************************************************************
  1233. //--------------------------------------------------------------------------------------------------
  1234. #pragma segment AOpen
  1235.  
  1236. pascal void 
  1237. TSlider::IRes(TDocument *, TView *itsSuperView, Ptr *itsParams)
  1238. // itsDocument removed from declaration so CFront won't complain that it isn't used
  1239. {
  1240.     PicHandle knobPicture;
  1241.     Rect knobRect;
  1242.     Rect *tmpR;
  1243.  
  1244.     inherited::IRes(NULL, itsSuperView, itsParams);
  1245.     knobPicture = GetPicture(1002);
  1246.     fKnobPicture = knobPicture;
  1247.     
  1248.     tmpR = &knobPicture[0]->picFrame;
  1249.     SetPt(((Point *) &knobRect.top), fSize.h - (tmpR->right - tmpR->left), fSize.v - 16);
  1250.     knobRect.right = knobRect.left + tmpR->right - tmpR->left;
  1251.     knobRect.bottom = knobRect.top + tmpR->bottom - tmpR->top;
  1252.  
  1253.     fMaxTop = knobRect.top;
  1254.     fMinTop = knobRect.top - 84;
  1255.     fKnobRect = knobRect;
  1256.     fValue = 0;
  1257. }
  1258.  
  1259. /*--------------------------------------------------------------------------------------------------*/
  1260. #pragma segment ARes
  1261.  
  1262. pascal Boolean
  1263. TSlider::ContainsMouse(VPoint *theMouse)
  1264. {
  1265.     Rect knobRect;
  1266.  
  1267.     GetKnobRect(&knobRect);
  1268.     return PtInRect(VPtToPt(theMouse), &knobRect);
  1269. }
  1270.  
  1271. /*--------------------------------------------------------------------------------------------------*/
  1272. #pragma segment ARes
  1273.  
  1274. pascal void
  1275. TSlider::Draw(Rect *area)
  1276.  
  1277. {
  1278.     inherited::Draw(area);                                /* This draws everything but the knob */
  1279.     DrawKnob();
  1280. }
  1281.  
  1282. /*--------------------------------------------------------------------------------------------------*/
  1283. #pragma segment ARes
  1284.  
  1285. pascal void
  1286. TSlider::DrawKnob()
  1287. {
  1288.     Rect knobRect;
  1289.  
  1290.     GetKnobRect(&knobRect);
  1291.     LoadResource(Handle(fKnobPicture));                 /* In case it was purged from memory */
  1292.     DrawPicture(fKnobPicture, &knobRect);
  1293. }
  1294.  
  1295. /*--------------------------------------------------------------------------------------------------*/
  1296. #pragma segment ARes
  1297.  
  1298. pascal void
  1299. TSlider::GetKnobRect(Rect *knobRect)
  1300. {
  1301.     *knobRect = fKnobRect;
  1302.     OffsetRect(knobRect, 0, -(fValue * 12));
  1303. }
  1304.  
  1305. /*--------------------------------------------------------------------------------------------------*/
  1306. #pragma segment ARes
  1307.  
  1308. pascal void
  1309. TSlider::TrackMouse(TrackPhase aTrackPhase, VPoint *anchorPoint, VPoint *previousPoint,
  1310.                     VPoint *nextPoint, Boolean )
  1311. // mouseDidMove removed from declaration so CFront won't complain that it isn't used
  1312. {
  1313.     Rect oldRect;
  1314.     Rect newRect;
  1315.     Rect difference;
  1316.     RgnHandle savedClip;
  1317.     short base;
  1318.     short offset;
  1319.  
  1320.     GetKnobRect(&oldRect);
  1321.     newRect = oldRect;
  1322.  
  1323.     /* Compute rectangle of knob's current position */
  1324.     offset = Min(Max(previousPoint->v - anchorPoint->v, fMinTop - newRect.top), 
  1325.                  fMaxTop - newRect.top);
  1326.     OffsetRect(&oldRect, 0, offset);
  1327.  
  1328.     /* Compute rectangle of knob's new position */
  1329.     offset = Min(Max(nextPoint->v - anchorPoint->v, fMinTop - newRect.top), 
  1330.                  fMaxTop - newRect.top);
  1331.     OffsetRect(&newRect, 0, offset);
  1332.  
  1333.     /* If the mouse was release, pin the knob to a value and set slider's value */
  1334.     if (aTrackPhase == trackRelease) {
  1335.         base = fSize.v - 16 - newRect.top;
  1336.         offset = base - ((base + 6) / 12 * 12);
  1337.         OffsetRect(&newRect, 0, offset);
  1338.         fValue = (fSize.v - 16 - newRect.top) / 12;
  1339.     }
  1340.  
  1341.     /* To redraw minimal amount, compute difference between old and new positions */
  1342.     difference = oldRect;
  1343.     if (oldRect.top > newRect.top)
  1344.         difference.top = Max(oldRect.top, newRect.bottom);
  1345.     else
  1346.         difference.bottom = Min(oldRect.bottom, newRect.top);
  1347.  
  1348.     savedClip = NewRgn();
  1349.     FailNIL(savedClip);
  1350.     GetClip(savedClip);
  1351.  
  1352.     ClipRect(&difference);
  1353.     inherited::Draw(&difference);
  1354.  
  1355.     SetClip(savedClip);
  1356.     DisposeRgn(savedClip);
  1357.     DrawPicture(fKnobPicture, &newRect);
  1358. }
  1359.  
  1360.  /*--------------------------------------------------------------------------------------------------*/
  1361. #pragma segment AFields
  1362.  
  1363. pascal void 
  1364. TSlider::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1365.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1366. {
  1367.     (*DoToField)("\pTSlider", NULL, bClass, DoToField_StaticLink);
  1368.     (*DoToField)("\pfValue", (Ptr) &fValue, bInteger, DoToField_StaticLink);
  1369.     (*DoToField)("\pfKnobPicture", (Ptr) &fKnobPicture, bHandle, DoToField_StaticLink);
  1370.     (*DoToField)("\pfKnobRect", (Ptr) &fKnobRect, bRect, DoToField_StaticLink);
  1371.     (*DoToField)("\pfMinTop", (Ptr) &fMinTop, bInteger, DoToField_StaticLink);
  1372.     (*DoToField)("\pfMaxTop", (Ptr) &fMaxTop, bInteger, DoToField_StaticLink);
  1373.     TPicture::Fields(DoToField, DoToField_StaticLink);
  1374. }
  1375.  
  1376. //********************************************************************************************
  1377. //    T S u m S t a t i c T e x t
  1378. //********************************************************************************************
  1379. #pragma segment ARes
  1380.  
  1381. pascal void
  1382. TSumStaticText::Draw(Rect *area)
  1383. {
  1384.     Rect theRect;
  1385.  
  1386.     /* Make sure the gray background gets completely erased */
  1387.     GetQDExtent(&theRect);
  1388.     InsetRect(&theRect, fPenSize.h, fPenSize.v);
  1389.     EraseRect(&theRect);
  1390.     inherited::Draw(area);
  1391. }
  1392.  
  1393.  /*--------------------------------------------------------------------------------------------------*/
  1394. #pragma segment AFields
  1395.  
  1396. pascal void 
  1397. TSumStaticText::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1398.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1399. {
  1400.     (*DoToField)("\pTSumStaticText", NULL, bClass, DoToField_StaticLink);
  1401.     TStaticText::Fields(DoToField, DoToField_StaticLink);
  1402. }
  1403.  
  1404. //********************************************************************************************
  1405. //    T C a l c D i a l o g
  1406. //********************************************************************************************
  1407. //--------------------------------------------------------------------------------------------------
  1408. #pragma segment ARes
  1409.  
  1410. pascal void
  1411. TCalcDialog::DoChoice(TView *origView, short itsChoice)
  1412. {
  1413.     IDType origID;
  1414.  
  1415.     origID = origView->fIdentifier;
  1416.     switch (itsChoice) {
  1417.         case mOKHit:                                         /*??? Should be mControlHit*/
  1418.             switch (origID & 0xFF) {
  1419.                 case 'C':
  1420.                     ClearSum();
  1421.                     break;
  1422.                 case '=':
  1423.                 case 'E':
  1424.                     TotalSum(noOperator);
  1425.                     break;
  1426.                 case '/':
  1427.                     TotalSum(divOperator);
  1428.                     break;
  1429.                 case '*':
  1430.                     TotalSum(mulOperator);
  1431.                     break;
  1432.                 case '-':
  1433.                     TotalSum(subOperator);
  1434.                     break;
  1435.                 case '+':
  1436.                     TotalSum(addOperator);
  1437.                     break;
  1438.                 default:
  1439.                     NewDigit(origID & 0xFF);
  1440.                     break;
  1441.             }
  1442.             break;
  1443.             
  1444.         default:
  1445.             inherited::DoChoice(origView, itsChoice);
  1446.             break;
  1447.     }
  1448. }
  1449.  
  1450. /*--------------------------------------------------------------------------------------------------*/
  1451. #pragma segment ARes
  1452.  
  1453. pascal TCommand *
  1454. TCalcDialog::DoKeyCommand(short ch, short aKeyCode, EventInfo *)
  1455. // info removed from declaration so CFront won't complain that it isn't used
  1456. {
  1457.     Boolean foundIt;
  1458.     long whoCares;
  1459.     IDType theID;
  1460.     TView *theView;
  1461.  
  1462.     foundIt = TRUE;
  1463.     if (aKeyCode == 0x47)                             /* Clear key */
  1464.         theID = 'keyC';
  1465.     else if ((ch == chEnter) || (ch == chReturn))
  1466.         theID = 'keyE';
  1467.     else
  1468.         switch (ch) {
  1469.             case '0':
  1470.             case '1':
  1471.             case '2':
  1472.             case '3':
  1473.             case '4':
  1474.             case '5':
  1475.             case '6':
  1476.             case '7':
  1477.             case '8':
  1478.             case '9':
  1479.             case '.':
  1480.             case '+':
  1481.             case '-':
  1482.             case '*':
  1483.             case '/':
  1484.             case '=':
  1485.                 theID = 'key ' | ch;
  1486.                 break;
  1487.             default:
  1488.                 foundIt = FALSE;
  1489.                 SysBeep(1);
  1490.                 break;
  1491.         }
  1492.         
  1493.     if (foundIt) {
  1494.         theView = FindSubView(theID);
  1495.         if (theView->Focus()) {
  1496.             ((TControl *) theView)->Hilite();
  1497.             Delay(5, &whoCares);
  1498.             ((TControl *) theView)->Hilite();
  1499.         }
  1500.         DoChoice(theView, mOKHit);                        /*??? mButtonHit? */
  1501.     }
  1502.     return NULL;
  1503. }
  1504.  
  1505. /*--------------------------------------------------------------------------------------------------*/
  1506. #pragma segment ARes
  1507.  
  1508. pascal void TCalcDialog::ClearSum()
  1509. {
  1510.     fArgument = 0.0;
  1511.     fSum = 0.0;
  1512.     fOperator = noOperator;
  1513.     fDecimalPoint = FALSE;
  1514.     fRestart = TRUE;
  1515.     ((TStaticText *) FindSubView('SUMM'))->SetText("\p0", kRedraw);
  1516. }
  1517.  
  1518. /*--------------------------------------------------------------------------------------------------*/
  1519. #pragma segment ARes
  1520.  
  1521. pascal void TCalcDialog::FetchValue(long double *aValue)
  1522. {
  1523.     Str255 theStr;
  1524.  
  1525.     ((TStaticText *) FindSubView('SUMM'))->GetText((StringPtr) theStr);
  1526.     p2cstr((StringPtr) theStr);
  1527.     sscanf((char *) theStr, "%Lf", aValue);
  1528. }
  1529.  
  1530. /*--------------------------------------------------------------------------------------------------*/
  1531.  
  1532. static pascal short POS(StringPtr subStr, StringPtr theStr)
  1533. {
  1534.     short lSub = Length(subStr);
  1535.     short lStr = Length(theStr);
  1536.     char * p;
  1537.     
  1538.     if (theStr == NULL || subStr == NULL || (lSub > lStr)) return 0;
  1539.     
  1540.     p = (char *) &theStr[1];
  1541.     for (short index = 1; index <= 1 + (lStr - lSub); index++)
  1542.     {
  1543.         if (strncmp((char *) &subStr[1], p++, lSub))
  1544.             return index;
  1545.     }
  1546.     return 0;
  1547. }
  1548.  
  1549. static pascal void Truncate(StringPtr theStr)
  1550. {
  1551.     char theChar;
  1552.  
  1553.     if (Length(theStr) > 1) {
  1554.         theChar = theStr[Length(theStr)];
  1555.         if ( (theChar == '0') || (theChar == '.') )
  1556.             theStr[0] -= 1;
  1557.         if ( theChar == '0' )
  1558.             Truncate(theStr);
  1559.     }
  1560. }
  1561.  
  1562. pascal void TCalcDialog::SetValue()
  1563. {
  1564.     short thePos = 0;
  1565.     Str255 theStr;
  1566.     long double aExtended;
  1567.     int *decpt = NULL;
  1568.     int *sign = NULL;
  1569.  
  1570.     aExtended = fSum;
  1571.     sprintf((char *) theStr, "%Lf", aExtended);
  1572.     c2pstr((char *) theStr);
  1573.     thePos = POS("\p.", theStr);
  1574.     if (thePos != 0)
  1575.         Truncate(theStr);
  1576.     if ((thePos > kMaxPlaces) || 
  1577.             ((thePos != 0) && (POS("\p000000", theStr) == thePos + 1))) {
  1578.         aExtended = fSum;
  1579.         sprintf((char *) theStr, "%.2g", aExtended);
  1580.         c2pstr((char *) theStr);
  1581.     }
  1582.     if (Length(theStr) > kMaxPlaces)
  1583.         theStr[0] = kMaxPlaces;
  1584.     
  1585.     ((TStaticText *) FindSubView('SUMM'))->SetText((StringPtr) &theStr, kRedraw);
  1586. }
  1587.  
  1588. /*--------------------------------------------------------------------------------------------------*/
  1589. #pragma segment ARes
  1590.  
  1591. pascal void 
  1592. TCalcDialog::TotalSum(CalcOperator newOperator)
  1593. {
  1594.     long double aValue;
  1595.     
  1596.     FetchValue(&aValue);
  1597.     fArgument = aValue;
  1598.     switch (fOperator) {
  1599.         case noOperator:
  1600.             fSum = fArgument;
  1601.             break;
  1602.         case divOperator:
  1603.             fSum = fSum / fArgument;
  1604.             break;
  1605.         case mulOperator:
  1606.             fSum = fSum * fArgument;
  1607.             break;
  1608.         case subOperator:
  1609.             fSum = fSum - fArgument;
  1610.             break;
  1611.         case addOperator:
  1612.             fSum = fSum + fArgument;
  1613.             break;
  1614.     }
  1615.     SetValue();
  1616.     fRestart = TRUE;
  1617.     fArgument = fSum;
  1618.     fOperator = newOperator;
  1619. }
  1620.  
  1621. /*--------------------------------------------------------------------------------------------------*/
  1622. #pragma segment ARes
  1623.  
  1624. static void SetIt(TStaticText *theText, StringPtr theStr, short theNumber)
  1625. {
  1626.     theStr[Length(theStr) + 1] = theNumber;
  1627.     theStr[0] += 1;
  1628.     theText->SetText(theStr, kRedraw);
  1629. }
  1630.  
  1631. pascal void 
  1632. TCalcDialog::NewDigit(short theNumber)
  1633. {
  1634.     TStaticText *theText;
  1635.     Str255 theStr;
  1636.  
  1637.     theText = (TStaticText *) FindSubView('SUMM');
  1638.     if (fRestart)
  1639.         pstrcpy(theStr, "\p");
  1640.     else
  1641.         theText->GetText((StringPtr) &theStr);
  1642.         
  1643.     if (Length(theStr) < kMaxPlaces) {
  1644.         fRestart = FALSE;
  1645.         if ((theNumber == '.') && !fDecimalPoint)
  1646.             fDecimalPoint = TRUE;
  1647.         SetIt(theText, theStr, theNumber);
  1648.     }
  1649. }
  1650.  
  1651.  
  1652.  /*--------------------------------------------------------------------------------------------------*/
  1653. #pragma segment AFields
  1654.  
  1655. pascal void 
  1656. TCalcDialog::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, 
  1657.     short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
  1658. {
  1659.     (*DoToField)("\pTCalcDialog", NULL, bClass, DoToField_StaticLink);
  1660.       (*DoToField)("\pfSum", (Ptr) &fSum, bExtended, DoToField_StaticLink);
  1661.       (*DoToField)("\pfArgument", (Ptr) &fArgument, bExtended, DoToField_StaticLink);
  1662.     (*DoToField)("\pfOperator", (Ptr) &fOperator, bInteger, DoToField_StaticLink);
  1663.     (*DoToField)("\pfDecimalPoint", (Ptr) &fDecimalPoint, bBoolean, DoToField_StaticLink);
  1664.     (*DoToField)("\pfRestart", (Ptr) &fRestart, bBoolean, DoToField_StaticLink);
  1665.     TPicture::Fields(DoToField, DoToField_StaticLink);
  1666. }
  1667.