home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / MacApp / MacApp 3.0a2 / Libraries / UDialog.cp < prev    next >
Encoding:
Text File  |  1991-05-01  |  95.5 KB  |  3,705 lines  |  [TEXT/MPS ]

  1. // UDDialog.cp 
  2. // Copyright © 1988-1991 Apple Computer Inc. All rights reserved.
  3.  
  4.  
  5. #ifndef __UDIALOG__
  6. #include <UDialog.h>
  7. #endif
  8.  
  9. #ifndef __STDIO__
  10. #include <Stdio.h>
  11. #endif
  12.  
  13. #ifndef __UGEOMETRY__
  14. #include <UGeometry.h>
  15. #endif
  16.  
  17. #ifndef __STRINGS__
  18. #include <Strings.h>
  19. #endif
  20.  
  21. #ifndef __SANE__
  22. #include <Sane.h>
  23. #endif
  24.  
  25. #ifndef __TOOLUTILS__
  26. #include <ToolUtils.h>
  27. #endif
  28.  
  29. #ifndef __PACKAGES__
  30. #include <Packages.h>
  31. #endif
  32.  
  33. #ifndef __RESOURCES__
  34. #include <Resources.h>
  35. #endif
  36.  
  37. #ifndef __UASSOCIATION__
  38. #include <UAssociation.h>
  39. #endif
  40.  
  41. #ifndef __UAPPLICATION__
  42. #include <UApplication.h>
  43. #endif
  44.  
  45. #ifndef __UWINDOW__
  46. #include <UWindow.h>
  47. #endif
  48.  
  49. #ifndef __USCROLLER__
  50. #include <UScroller.h>
  51. #endif
  52.  
  53. #ifndef __UMACAPPUTILITIES__
  54. #include <UMacAppUtilities.h>
  55. #endif
  56.  
  57. #ifndef __UERRORMGR__
  58. #include <UErrorMgr.h>
  59. #endif
  60.  
  61. #ifndef __UMACAPPGLOBALS__
  62. #include <UMacAppGlobals.h>
  63. #endif
  64.  
  65. #ifndef __UPOPUP__
  66. #include <UPopUp.h>
  67. #endif
  68.  
  69. #ifndef __UADORNERS__
  70. #include <UAdorners.h>
  71. #endif
  72.  
  73. #ifndef __UITERATOR__
  74. #include <UIterator.h>
  75. #endif
  76.  
  77. #ifndef __UVIEWSERVER__
  78. #include <UViewServer.h>
  79. #endif
  80.  
  81. TAssociation* gParamTxt;                        // Used for text substitution 
  82. TFloatingTEManager* gFloatingTEManager;            // The floating TEView used with edit text fields. 
  83.  
  84. //--------------------------------------------------------------------------------------------------
  85. #pragma segment DlgInit
  86.  
  87. pascal void InitUDialog(void)
  88. {
  89.     if (qTemplateViews)
  90.     {
  91.         // So the linker doesn't dead strip these 
  92.         DontDeadStrip(TDialogView);
  93.         DontDeadStrip(TControl);
  94.         DontDeadStrip(TButton);
  95.         DontDeadStrip(TCheckBox);
  96.         DontDeadStrip(TRadio);
  97.         DontDeadStrip(TCluster);
  98.         DontDeadStrip(TIcon);
  99.         DontDeadStrip(TPicture);
  100.         DontDeadStrip(TPopup);
  101.         DontDeadStrip(TStaticText);
  102.         DontDeadStrip(TEditText);
  103.         DontDeadStrip(TNumberText);
  104.         DontDeadStrip(TPattern);
  105.  
  106.         RegisterStdType("TDialogView", kStdDialogView);
  107.         RegisterStdType("TControl", kStdControl);
  108.         RegisterStdType("TButton", kStdButton);
  109.         RegisterStdType("TCheckBox", kStdCheckBox);
  110.         RegisterStdType("TRadio", kStdRadio);
  111.         RegisterStdType("TCluster", kStdCluster);
  112.         RegisterStdType("TIcon", kStdIcon);
  113.         RegisterStdType("TPicture", kStdPicture);
  114.         RegisterStdType("TPopup", kStdPopup);
  115.         RegisterStdType("TStaticText", kStdStaticText);
  116.         RegisterStdType("TEditText", kStdEditText);
  117.         RegisterStdType("TNumberText", kStdNumberText);
  118.         RegisterStdType("TPattern", kStdPattern);
  119.     }
  120.  
  121.     gFloatingTEManager = new TFloatingTEManager;
  122.     gFloatingTEManager->IObject();
  123.  
  124.     /*!!! Create the dictionary for the global text substitution mechanism. 
  125.       This should move out of UDialog soon */
  126.  
  127.     gParamTxt = new TAssociation;
  128.     gParamTxt->IAssociation();
  129.  
  130.     gUDialogInitialized = TRUE;
  131. }
  132.  
  133.  
  134. //--------------------------------------------------------------------------------------------------
  135. #pragma segment DlgRes
  136. pascal TDialogTEView* AquireFloatingTEView()
  137. {
  138.     if (gFloatingTEManager)
  139.         return (gFloatingTEManager->AquireFloatingTE());
  140.     else
  141.         return NULL;
  142. }
  143.  
  144. //--------------------------------------------------------------------------------------------------
  145. #pragma segment DlgRes
  146. pascal void ReleaseFloatingTEView(TDialogTEView* aDialogTEView)
  147. {
  148.     if (gFloatingTEManager)
  149.         gFloatingTEManager->ReleaseFloatingTE(aDialogTEView);
  150. }
  151.  
  152. //--------------------------------------------------------------------------------------------------
  153. #pragma segment DlgRes
  154.  
  155. pascal void MAParamText(const Str255& keyStr,
  156.                         const Str255& valueStr)
  157.  
  158. {
  159.     gParamTxt->InsertEntry(keyStr, valueStr);
  160. }
  161.  
  162. //--------------------------------------------------------------------------------------------------
  163. #pragma segment DlgRes
  164.  
  165. pascal void MAReplaceText(Str255& theText)
  166. {
  167.     CArrayIterator iter(gParamTxt->fEntries);
  168.     
  169.     for (ArrayIndex i = iter.FirstIndex(); iter.More(); i = iter.NextIndex())
  170.     {
  171.         TEntry* anEntry = (TEntry*)gParamTxt->fEntries->At(i);
  172.         short index;
  173.         
  174.         while (index = theText.Pos(**(anEntry->fKey)))
  175.         {
  176.             theText.Delete(index, (**(anEntry->fKey)).Length());
  177.             if (theText.Length() + (**(anEntry->fValue)).Length() < sizeof(Str255))
  178.                 theText.Insert(**(anEntry->fValue), index);
  179.         }
  180.     }
  181. }
  182.  
  183. //--------------------------------------------------------------------------------------------------
  184. #pragma segment DlgOpen
  185.  
  186. pascal void TDialogView::Initialize(void)        // override 
  187. {
  188.     inherited::Initialize();
  189.  
  190. #if qDebug
  191.     if (!gUDialogInitialized)
  192.     {
  193.         ProgramBreak("InitUDialog must be called before creating a Dialog View.");
  194.         Failure(noErr, 0);
  195.     }
  196. #endif
  197.  
  198.     fDefaultItem = kNoIdentifier;
  199.     fCancelItem = kNoIdentifier;
  200.     fDismisser = kNoIdentifier;
  201. }
  202.  
  203. //--------------------------------------------------------------------------------------------------
  204. #pragma segment DlgOpen
  205.  
  206. pascal void TDialogView::IDialogView(TDocument* itsDocument,
  207.                                      TView* itsSuperView,
  208.                                      const VPoint& itsLocation,
  209.                                      const VPoint& itsSize,
  210.                                      SizeDeterminer itsHSizeDet,
  211.                                      SizeDeterminer itsVSizeDet,
  212.                                      IDType itsDefItemID,
  213.                                      IDType itsCancelItemID)
  214.  
  215. {
  216. #if qDebug
  217.     if (!gUDialogInitialized)
  218.     {
  219.         ProgramBreak("InitUDialog must be called before creating a Dialog View.");
  220.         Failure(noErr, 0);
  221.     }
  222. #endif
  223.  
  224.     this->IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  225.  
  226.     fDefaultItem = itsDefItemID;
  227.     fCancelItem = itsCancelItemID;
  228.  
  229. }
  230.  
  231. //--------------------------------------------------------------------------------------------------
  232. #pragma segment DlgOpen
  233.  
  234. pascal void TDialogView::IRes(TDocument* itsDocument,
  235.                               TView* itsSuperView,
  236.                               Ptr& itsParams)    // override 
  237.  
  238. {
  239. #if qDebug
  240.     if (!gUDialogInitialized)
  241.     {
  242.         ProgramBreak("InitUDialog must be called before creating a Dialog View.");
  243.         Failure(noErr, 0);
  244.     }
  245. #endif
  246.  
  247.     inherited::IRes(itsDocument, itsSuperView, itsParams);
  248.  
  249.     DialogViewTemplate& templateData = *((DialogViewTemplate *) itsParams);
  250.     fDefaultItem = templateData.defaultItem;
  251.     fCancelItem = templateData.cancelItem;
  252.  
  253.     OffsetPtr(itsParams, sizeof(DialogViewTemplate));
  254. }
  255.  
  256. //--------------------------------------------------------------------------------------------------
  257. #pragma segment DlgRes
  258.  
  259. pascal TObject* TDialogView::Clone(void)        // override 
  260.  
  261. {
  262.     TDialogView * aClonedDialogView;
  263.  
  264.  
  265.     aClonedDialogView = (TDialogView *)(inherited::Clone());
  266.  
  267.  
  268.     return aClonedDialogView;
  269. }
  270.  
  271. //--------------------------------------------------------------------------------------------------
  272. #pragma segment MAWriteRes
  273.  
  274. pascal void TDialogView::WRes(ViewRsrcHandle theResource,
  275.                               Ptr& itsParams)    // override 
  276. {
  277.     inherited::WRes(theResource, itsParams);
  278.  
  279.     DialogViewTemplate& templateData = *((DialogViewTemplate *) (ExpandPtr((Handle)theResource, itsParams, sizeof(DialogViewTemplate))));
  280.  
  281.     templateData.defaultItem = fDefaultItem;
  282.     templateData.cancelItem = fCancelItem;
  283. }
  284.  
  285. //--------------------------------------------------------------------------------------------------
  286. #pragma segment MAWriteRes
  287.  
  288. pascal void TDialogView::WriteRes(ViewRsrcHandle theResource,
  289.                                   Ptr& itsParams)// override 
  290.  
  291. {
  292.     gWResSignature = 'dlog';
  293.     gWResType = "TDialogView";
  294.     this->WRes(theResource, itsParams);
  295. }
  296.  
  297. //--------------------------------------------------------------------------------------------------
  298. #pragma segment DlgClose
  299.  
  300. pascal void TDialogView::Free(void)                // override 
  301.  
  302. {
  303.  
  304.     inherited::Free();
  305.  
  306. }
  307.  
  308. //--------------------------------------------------------------------------------------------------
  309. #pragma segment DlgRes
  310.  
  311. pascal Boolean TDialogView::CanDismiss(IDType dismissing)
  312. {
  313.     TView * dismissingView;
  314.     Boolean successful;
  315.  
  316.     // First, make sure the view initiating the the dismissal, if any, is enabled. 
  317.  
  318.     if (((long)dismissing) != ((long)kNoIdentifier))
  319.         dismissingView = this->FindSubView(dismissing);
  320.     else
  321.         dismissingView = NULL;                    // no dismissing view 
  322.  
  323.     // Thanks Tommi GESSL 
  324.     successful = (dismissingView == NULL) || (dismissingView->IsEnabled());
  325.  
  326.     if (successful)                                /* test only we haven´t failed */
  327.     {
  328.         /* Now, if we're not cancelling, make sure the current edit text is valid and
  329.           return false if it isn't.*/
  330.  
  331.         if (((long)fCancelItem == (long)kNoIdentifier) || (dismissing != fCancelItem))
  332.         {
  333.             this->DoSelectEditText(NULL, False);// Attempt to deselect current edit text 
  334.             return (this->GetCurrentEditText() == NULL);// Successful only if it was deselected 
  335.         }
  336.         else
  337.             return (successful);
  338.     }
  339.     else
  340.         return FALSE;
  341. }
  342.  
  343. //--------------------------------------------------------------------------------------------------
  344. #pragma segment DlgClose
  345.  
  346. pascal void TDialogView::Close(void)            // override 
  347.  
  348. {
  349.     if (((long)fDismisser) == ((long)kNoIdentifier))
  350.         this->DismissDialog(kNoIdentifier);
  351.  
  352.     inherited::Close();
  353. }
  354.  
  355. //--------------------------------------------------------------------------------------------------
  356. #pragma segment DlgRes
  357.  
  358. pascal Boolean TDialogView::DeselectCurrentEditText(void)
  359. {
  360.     TEditText * currentEditText;
  361.     Boolean result = TRUE;
  362.  
  363.     currentEditText = this->GetCurrentEditText();
  364.     if ((currentEditText) && (currentEditText->fTEView))
  365.     {
  366.         result = (currentEditText->fTEView->WillingToResignTarget() == kValidValue);
  367.         this->BeTarget();
  368.     }
  369.     return result;
  370. }
  371.  
  372. //--------------------------------------------------------------------------------------------------
  373. #pragma segment DlgClose
  374.  
  375. pascal void TDialogView::DismissDialog(IDType dismisser)
  376.  
  377. {
  378.     TWindow * itsWindow;
  379.  
  380.  
  381.     itsWindow = this->GetWindow();
  382.     if (!itsWindow->IsDismissed())
  383.         if (this->CanDismiss(dismisser))
  384.         {
  385.             itsWindow->Dismiss();
  386.             fDismisser = dismisser;
  387.         }
  388.         else
  389.             Failure(noErr, 0);                    // Silent failure 
  390. }
  391.  
  392. //--------------------------------------------------------------------------------------------------
  393. #pragma segment DlgRes
  394.  
  395. pascal void TDialogView::DoEvent(EvtNumber eventNumber,
  396.                                  TEvtHandler* source,
  397.                                  TEvent* event)// override 
  398.  
  399. {
  400.     switch (eventNumber)
  401.     {
  402.         case mEditTextHit:
  403. #if qDebug
  404.             if (source && !source->IsMemberClass(GetClassIDFromName("TEditText")))
  405.                 ProgramBreak("Got mEditTextHit on non-TEditText view.");
  406. #endif
  407.  
  408.             //!!!RCR
  409. #if FALSE
  410.             else
  411.                 this->DoSelectEditText((TEditText *)source, False);
  412. #endif
  413.  
  414.             break;
  415.         default:
  416.             if (source && source->IsMemberClass(GetClassIDFromName("TControl")) && ((TControl *)source)->fDismissesDialog)
  417.                 this->DismissDialog(((TView *)source)->fIdentifier);
  418.             else
  419.                 inherited::DoEvent(eventNumber, source, event);
  420.             break;
  421.     }
  422. }
  423.  
  424. //--------------------------------------------------------------------------------------------------
  425. #pragma segment DlgRes
  426.  
  427. pascal void TDialogView::DoCommandKey(TToolboxEvent* event)// override 
  428.  
  429. {
  430.     TView * cancelView;
  431.  
  432.  
  433.     //!!! this needs internationalization 
  434.     if (this->IsEnabled() && event->fCharacter == '.' && ((long)fCancelItem != (long)kNoIdentifier))
  435.     {
  436.         cancelView = this->FindSubView(fCancelItem);
  437.         if (cancelView)
  438.         {
  439.             if (cancelView->IsMemberClass(GetClassIDFromName("TControl")))
  440.                 cancelView->HandleEvent(((TControl *)cancelView)->fDefChoice, this, NULL);
  441.             else
  442.                 cancelView->HandleEvent(mCancelKey, this, NULL);
  443.         }
  444.         else
  445.             this->HandleEvent(mCancelKey, this, NULL);
  446.     }
  447.     else
  448.         inherited::DoCommandKey(event);
  449. }
  450.  
  451. //--------------------------------------------------------------------------------------------------
  452. #pragma segment DlgRes
  453.  
  454. pascal void TDialogView::DoKeyCommand(TToolboxEvent* event)// override 
  455. {
  456.     TView * defaultView;
  457.     TView * cancelView;
  458.  
  459.  
  460.     // If we get this far, nobody's handled the Tab, Enter, or Return keys, so we will  
  461.     if (this->IsEnabled())
  462.     {
  463.         switch (event->fCharacter)
  464.         {
  465.             case chEscape:
  466.                 if (event->fKeyCode == kClearVirtualCode)// esc double for two different keys! 
  467.                     inherited::DoKeyCommand(event);
  468.                 else if (((long)fCancelItem) != ((long)kNoIdentifier))
  469.                 {
  470.                     cancelView = this->FindSubView(fCancelItem);
  471.                     if (cancelView)
  472.                     {
  473.                         if (cancelView->IsMemberClass(GetClassIDFromName("TControl")))
  474.                             cancelView->HandleEvent(((TControl *)cancelView)->fDefChoice, this, NULL);
  475.                         else
  476.                             cancelView->HandleEvent(mCancelKey, this, NULL);
  477.                     }
  478.                     else
  479.                         this->HandleEvent(mCancelKey, this, NULL);
  480.                 }
  481.                 else
  482.                     inherited::DoKeyCommand(event);
  483.                 break;
  484.             case chEnter:
  485.             case chReturn:
  486.                 if ((long)fDefaultItem != (long)kNoIdentifier)
  487.                 {
  488.                     defaultView = this->FindSubView(fDefaultItem);
  489.                     if (defaultView)
  490.                     {
  491.                         if (defaultView->IsMemberClass(GetClassIDFromName("TControl")))
  492.                             defaultView->HandleEvent(((TControl *)defaultView)->fDefChoice, this, NULL);
  493.                         else
  494.                             defaultView->HandleEvent(mDefaultKey, this, NULL);
  495.                     }
  496.                     else
  497.                         this->HandleEvent(mDefaultKey, this, NULL);
  498.                 }
  499.                 else
  500.                     inherited::DoKeyCommand(event);
  501.                 break;
  502.             default:
  503.                 inherited::DoKeyCommand(event);
  504.                 break;
  505.         }
  506.     }
  507.     else
  508.         inherited::DoKeyCommand(event);
  509. }
  510.  
  511. //--------------------------------------------------------------------------------------------------
  512. #pragma segment DlgRes
  513.  
  514. pascal void TDialogView::DoSelectEditText(TEditText* theEditText,
  515.                                           Boolean selectChars)
  516. {
  517.  
  518.     if (theEditText != this->GetCurrentEditText())// If we're not editing this view… 
  519.     {
  520.         if (theEditText == NULL)
  521.             this->BeTarget();                    // Set the window's target to self 
  522.         else
  523.         {
  524.             if (theEditText->IsEnabled())
  525.                 theEditText->StartEdit(selectChars);
  526. #if qDebug
  527.             else
  528.                 ProgramBreak("Attempt to select a disabled edit text view");
  529. #endif
  530.         }
  531.     }
  532.     else if (selectChars && (theEditText))// Make sure all the chars are selected. 
  533.         theEditText->SetSelection(0, MAXINT, kRedraw);
  534. }
  535.  
  536. //--------------------------------------------------------------------------------------------------
  537. #pragma segment DlgRes
  538.  
  539. class CCheckSubView
  540. {
  541.     const void*& fStaticLink;
  542.     const DoToEditTextType& fDoToEditText;
  543. public:
  544.     // Constructor
  545.     CCheckSubView(const DoToEditTextType DoToEditText,
  546.                   void* staticLink) :
  547.         fDoToEditText(DoToEditText),
  548.         fStaticLink(staticLink)
  549.     {}
  550.  
  551.     pascal void CheckSubView(TView* theSubView);
  552. };
  553.  
  554. #pragma segment DlgRes
  555.  
  556. pascal void CCheckSubView::CheckSubView(TView* theSubView)
  557. {
  558.     if (theSubView && theSubView->IsMemberClass(GetClassIDFromName("TEditText")))
  559.         fDoToEditText((TEditText *)theSubView, fStaticLink);
  560.     else
  561.     {
  562.         CCheckSubView aCCheckSubView(fDoToEditText, fStaticLink);
  563.  
  564.         theSubView->EachSubView((DoToViewType) & CCheckSubView::CheckSubView, &aCCheckSubView);
  565.     }
  566. }
  567.  
  568. #pragma segment DlgRes
  569.  
  570. pascal void TDialogView::EachEditText(DoToEditTextType DoToEditText,
  571.                                       void* staticLink)
  572. {
  573.     CCheckSubView aCCheckSubView(DoToEditText, staticLink);
  574.  
  575.     this->EachSubView((DoToViewType) & CCheckSubView::CheckSubView, &aCCheckSubView);
  576. }
  577.  
  578. //--------------------------------------------------------------------------------------------------
  579. #pragma segment DlgRes
  580. pascal TEditText* TDialogView::GetCurrentEditText(void)
  581. {
  582.     TEvtHandler * currentTarget;
  583.     TWindow * myWindow;
  584.     TEditText * result;
  585.  
  586.     //!!!RCR Needs work
  587.     result = NULL;
  588.     myWindow = this->GetWindow();
  589.     if (myWindow)
  590.         currentTarget = myWindow->GetTarget();
  591.     else
  592.         currentTarget = NULL;
  593.     if ((currentTarget) && currentTarget->IsMemberClass(GetClassIDFromName("TDialogTEView")))
  594.         result = ((TDialogTEView *)currentTarget)->fEditText;
  595.     return result;
  596. }
  597.  
  598.  
  599. //--------------------------------------------------------------------------------------------------
  600. #pragma segment DlgRes
  601.  
  602. pascal TView* TDialogView::GetDialogView(void)    // override 
  603. {
  604.     return this;
  605. }
  606.  
  607. //--------------------------------------------------------------------------------------------------
  608. #pragma segment MAOpen
  609.  
  610. pascal void TDialogView::DoOpen(void)
  611. {
  612. }
  613.  
  614. //--------------------------------------------------------------------------------------------------
  615. #pragma segment MAOpen
  616.  
  617. pascal void TDialogView::Open(void)                // override 
  618.  
  619. {
  620.     fDismisser = kNoIdentifier;
  621.     this->DoOpen();
  622.     inherited::Open();
  623. }
  624.  
  625. //--------------------------------------------------------------------------------------------------
  626. #pragma segment DlgRes
  627.  
  628. pascal IDType TDialogView::PoseModally(void)
  629. {
  630.     TWindow * itsWindow;
  631.  
  632.     itsWindow = this->GetWindow();
  633.     if (itsWindow)
  634.     {
  635.         itsWindow->PoseModally();
  636.         return fDismisser;
  637.     }
  638.     else
  639.         return kNoIdentifier;
  640. }
  641.  
  642. //--------------------------------------------------------------------------------------------------
  643. #pragma segment DlgRes
  644.  
  645. pascal void TDialogView::SelectEditText(IDType itsIdentifier,
  646.                                         Boolean selectChars)
  647. {
  648.     TView * aSubView;
  649.  
  650.     aSubView = this->FindSubView(itsIdentifier);
  651.     if ((aSubView) && aSubView->IsMemberClass(GetClassIDFromName("TEditText")))
  652.         this->DoSelectEditText((TEditText *)aSubView, selectChars);
  653. }
  654.  
  655. //--------------------------------------------------------------------------------------------------
  656. #pragma segment DlgFields
  657.  
  658. pascal void TDialogView::Fields(TObject* obj)    // override 
  659. {
  660.     obj->DoToField("TDialogView", NULL, bClass);
  661.     obj->DoToField("fDefaultItem", &fDefaultItem, bIDType);
  662.     obj->DoToField("fCancelItem", &fCancelItem, bIDType);
  663.     obj->DoToField("fDismisser", &fDismisser, bIDType);
  664.  
  665.     inherited::Fields(obj);
  666. }
  667.  
  668. //--------------------------------------------------------------------------------------------------
  669. #pragma segment DlgOpen
  670.  
  671. pascal void TButton::Initialize(void)            // override 
  672. {
  673.  
  674.     inherited::Initialize();
  675.  
  676.     fDefChoice = mButtonHit;
  677. }
  678.  
  679. //--------------------------------------------------------------------------------------------------
  680. #pragma segment DlgOpen
  681.  
  682. pascal void TButton::IButton(TView* itsSuperView,
  683.                              const VPoint& itsLocation,
  684.                              const VPoint& itsSize,
  685.                              SizeDeterminer itsHSizeDet,
  686.                              SizeDeterminer itsVSizeDet,
  687.                              const Str255& itsLabel)
  688. {
  689.     this->ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 0, ((pushButProc) | useWFont));
  690. }
  691.  
  692. //--------------------------------------------------------------------------------------------------
  693. #pragma segment DlgOpen
  694.  
  695. pascal void TButton::IRes(TDocument* ,
  696.                           TView* itsSuperView,
  697.                           Ptr& itsParams)        // override 
  698.  
  699. {
  700.     VRect itsArea;
  701.  
  702.     inherited::IRes(NULL, itsSuperView, itsParams);
  703.  
  704.     this->ControlArea(itsArea);
  705.     this->CreateCMgrControl(itsArea, ((ButtonTemplatePtr)itsParams)->itsLabel, 0, 0, 0, ((pushButProc) | useWFont));
  706.  
  707.     OffsetPtrWStr(itsParams, sizeof(ButtonTemplate));
  708. }
  709.  
  710. //--------------------------------------------------------------------------------------------------
  711. #pragma segment DlgRes
  712.  
  713. pascal TObject* TButton::Clone(void)            // override 
  714. {
  715.     TButton * aClonedButton;
  716.  
  717.  
  718.     aClonedButton = (TButton *)(inherited::Clone());
  719.  
  720.     return aClonedButton;
  721. }
  722.  
  723. //--------------------------------------------------------------------------------------------------
  724. #pragma segment MAWriteRes
  725.  
  726. pascal void TButton::WRes(ViewRsrcHandle theResource,
  727.                           Ptr& itsParams)        // override 
  728. {
  729.     Str255 theLabel;
  730.  
  731.     inherited::WRes(theResource, itsParams);
  732.  
  733.     this->GetText(theLabel);
  734.  
  735.     ButtonTemplate& templateData = *((ButtonTemplate *) ExpandPtrWStr((Handle)theResource, itsParams, sizeof(ButtonTemplate), theLabel.Length()));
  736.  
  737.     // templateData.itsLabel = theLabel; 
  738.     CopyStr255(theLabel, PRStr(templateData.itsLabel));
  739. }
  740.  
  741. //--------------------------------------------------------------------------------------------------
  742. #pragma segment MAWriteRes
  743.  
  744. pascal void TButton::WriteRes(ViewRsrcHandle theResource,
  745.                               Ptr& itsParams)    // override 
  746.  
  747. {
  748.     gWResSignature = 'butn';
  749.     gWResType = "TButton";
  750.     this->WRes(theResource, itsParams);
  751. }
  752.  
  753. //--------------------------------------------------------------------------------------------------
  754. #pragma segment DlgRes
  755.  
  756. pascal void TButton::DoEvent(EvtNumber eventNumber,
  757.                                  TEvtHandler* source,
  758.                                  TEvent* event)    // override 
  759.  
  760. {
  761.     if ((eventNumber == mButtonHit) && (source != this) && this->IsEnabled())
  762.         this->Flash();
  763.     inherited::DoEvent(eventNumber, this, event); // note source change
  764. }
  765.  
  766. //--------------------------------------------------------------------------------------------------
  767. #pragma segment DlgFields
  768.  
  769. pascal void TButton::Fields(TObject* obj)        // override 
  770. {
  771.     obj->DoToField("TButton", NULL, bClass);
  772.  
  773.     inherited::Fields(obj);
  774. }
  775.  
  776. //--------------------------------------------------------------------------------------------------
  777. #pragma segment DlgOpen
  778.  
  779. pascal void TCheckBox::Initialize(void)            // override 
  780. {
  781.     inherited::Initialize();
  782.  
  783.     fDefChoice = mCheckBoxHit;
  784. }
  785.  
  786. //--------------------------------------------------------------------------------------------------
  787. #pragma segment DlgOpen
  788.  
  789. pascal void TCheckBox::ICheckBox(TView* itsSuperView,
  790.                                  const VPoint& itsLocation,
  791.                                  const VPoint& itsSize,
  792.                                  SizeDeterminer itsHSizeDet,
  793.                                  SizeDeterminer itsVSizeDet,
  794.                                  const Str255& itsLabel,
  795.                                  Boolean isTurnedOn)
  796.  
  797. {
  798.     this->ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 1, ((checkBoxProc) | useWFont));
  799.     this->SetState(isTurnedOn, kDontRedraw);
  800. }
  801.  
  802. //--------------------------------------------------------------------------------------------------
  803. #pragma segment DlgOpen
  804.  
  805. pascal void TCheckBox::IRes(TDocument*            /* itsDocument */,
  806.                             TView* itsSuperView,
  807.                             Ptr& itsParams)        // override 
  808.  
  809. {
  810.     VRect itsArea;
  811.  
  812.     inherited::IRes(NULL, itsSuperView, itsParams);
  813.  
  814.     this->ControlArea(itsArea);
  815.     this->CreateCMgrControl(itsArea, ((CheckBoxTemplatePtr)itsParams)->itsLabel, ((CheckBoxTemplatePtr)itsParams)->isOn, 0, 1, ((checkBoxProc) | useWFont));
  816.  
  817.     OffsetPtrWStr(itsParams, sizeof(CheckBoxTemplate));
  818. }
  819.  
  820. //--------------------------------------------------------------------------------------------------
  821. #pragma segment DlgRes
  822.  
  823. pascal TObject* TCheckBox::Clone(void)            // override 
  824. {
  825.     TCheckBox * aClonedCheckBox;
  826.  
  827.     aClonedCheckBox = (TCheckBox *)(inherited::Clone());
  828.  
  829.     return aClonedCheckBox;
  830. }
  831.  
  832. //--------------------------------------------------------------------------------------------------
  833. #pragma segment MAWriteRes
  834.  
  835. pascal void TCheckBox::WRes(ViewRsrcHandle theResource,
  836.                             Ptr& itsParams)        // override 
  837. {
  838.     Str255 theLabel;
  839.  
  840.     inherited::WRes(theResource, itsParams);
  841.  
  842.     this->GetText(theLabel);
  843.  
  844.     CheckBoxTemplate& templateData = *((CheckBoxTemplate *) ExpandPtrWStr((Handle)theResource, itsParams, sizeof(CheckBoxTemplate), theLabel.Length()));
  845.  
  846.     templateData.isOn = this->IsOn();
  847.     // templateData.itsLabel = theLabel; 
  848.     CopyStr255(theLabel, PRStr(templateData.itsLabel));
  849. }
  850.  
  851. //--------------------------------------------------------------------------------------------------
  852. #pragma segment MAWriteRes
  853.  
  854. pascal void TCheckBox::WriteRes(ViewRsrcHandle theResource,
  855.                                 Ptr& itsParams)    // override 
  856. {
  857.     gWResSignature = 'chkb';
  858.     gWResType = "TCheckBox";
  859.     this->WRes(theResource, itsParams);
  860. }
  861.  
  862. //--------------------------------------------------------------------------------------------------
  863. #pragma segment DlgRes
  864.  
  865. pascal void TCheckBox::DoEvent(EvtNumber eventNumber,
  866.                                    TEvtHandler*, // source
  867.                                    TEvent* event)// override 
  868.  
  869. {
  870.     if (eventNumber == mCheckBoxHit)
  871.         this->Toggle(kRedraw);
  872.     inherited::DoEvent(eventNumber, this, event);
  873. }
  874.  
  875. //--------------------------------------------------------------------------------------------------
  876. #pragma segment DlgRes
  877.  
  878. pascal Boolean TCheckBox::IsOn(void)
  879. {
  880.     return (this->GetLongVal() != 0);
  881. }
  882.  
  883. //--------------------------------------------------------------------------------------------------
  884. #pragma segment DlgRes
  885.  
  886. pascal void TCheckBox::SetState(Boolean state,
  887.                                 Boolean redraw)
  888. {
  889.     this->SetLongVal((long)state, redraw);
  890. }
  891.  
  892. //--------------------------------------------------------------------------------------------------
  893. #pragma segment DlgRes
  894.  
  895. pascal void TCheckBox::Toggle(Boolean redraw)
  896.  
  897. {
  898.     this->SetLongVal((long)(!this->IsOn()), redraw);
  899. }
  900.  
  901. //--------------------------------------------------------------------------------------------------
  902. #pragma segment DlgRes
  903.  
  904. pascal void TCheckBox::ToggleIf(Boolean matchState,
  905.                                 Boolean redraw)
  906. {
  907.     if (this->IsOn() == matchState)
  908.         this->SetLongVal((long)(!this->IsOn()), redraw);
  909. }
  910.  
  911. //--------------------------------------------------------------------------------------------------
  912. #pragma segment DlgFields
  913.  
  914. pascal void TCheckBox::Fields(TObject* obj)        // override 
  915. {
  916.     obj->DoToField("TCheckBox", NULL, bClass);
  917.  
  918.     inherited::Fields(obj);
  919. }
  920.  
  921. //--------------------------------------------------------------------------------------------------
  922. #pragma segment DlgOpen
  923.  
  924. pascal void TRadio::Initialize(void)            // override 
  925. {
  926.     inherited::Initialize();
  927.  
  928.     fDefChoice = mRadioHit;
  929. }
  930.  
  931. //--------------------------------------------------------------------------------------------------
  932. #pragma segment DlgOpen
  933.  
  934. pascal void TRadio::IRadio(TView* itsSuperView,
  935.                            const VPoint& itsLocation,
  936.                            const VPoint& itsSize,
  937.                            SizeDeterminer itsHSizeDet,
  938.                            SizeDeterminer itsVSizeDet,
  939.                            const Str255& itsLabel,
  940.                            Boolean isTurnedOn)
  941.  
  942. {
  943.     this->ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 1, ((radioButProc) | useWFont));
  944.     this->SetState(isTurnedOn, kDontRedraw);
  945. }
  946.  
  947. //--------------------------------------------------------------------------------------------------
  948. #pragma segment DlgOpen
  949.  
  950. pascal void TRadio::IRes(TDocument* ,
  951.                          TView* itsSuperView,
  952.                          Ptr& itsParams)        // override 
  953.  
  954. {
  955.     VRect itsArea;
  956.  
  957.     inherited::IRes(NULL, itsSuperView, itsParams);
  958.  
  959.     this->ControlArea(itsArea);
  960.     this->CreateCMgrControl(itsArea, ((RadioTemplatePtr)itsParams)->itsLabel, ((RadioTemplatePtr)itsParams)->isOn, 0, 1, (radioButProc | useWFont));
  961.     OffsetPtrWStr(itsParams, sizeof(RadioTemplate));
  962. }
  963.  
  964. //--------------------------------------------------------------------------------------------------
  965. #pragma segment DlgRes
  966.  
  967. pascal TObject* TRadio::Clone(void)                // override 
  968. {
  969.     TRadio * aClonedRadio;
  970.  
  971.     aClonedRadio = (TRadio *)(inherited::Clone());
  972.  
  973.     return aClonedRadio;
  974. }
  975.  
  976. //--------------------------------------------------------------------------------------------------
  977. #pragma segment MAWriteRes
  978.  
  979. pascal void TRadio::WRes(ViewRsrcHandle theResource,
  980.                          Ptr& itsParams)        // override 
  981.  
  982. {
  983.     Str255 theLabel;
  984.  
  985.     inherited::WRes(theResource, itsParams);
  986.  
  987.     this->GetText(theLabel);
  988.  
  989.     RadioTemplate& templateData = *((RadioTemplate *) ExpandPtrWStr((Handle)theResource, itsParams, sizeof(RadioTemplate), theLabel.Length()));
  990.  
  991.     templateData.isOn = this->IsOn();
  992.     // templateData.itsLabel = theLabel; 
  993.     CopyStr255(theLabel, PRStr(templateData.itsLabel));
  994. }
  995.  
  996. //--------------------------------------------------------------------------------------------------
  997. #pragma segment MAWriteRes
  998.  
  999. pascal void TRadio::WriteRes(ViewRsrcHandle theResource,
  1000.                              Ptr& itsParams)    // override 
  1001. {
  1002.     gWResSignature = 'radb';
  1003.     gWResType = "TRadio";
  1004.     this->WRes(theResource, itsParams);
  1005. }
  1006.  
  1007. //--------------------------------------------------------------------------------------------------
  1008. #pragma segment DlgRes
  1009.  
  1010. pascal void TRadio::DoEvent(EvtNumber eventNumber,
  1011.                                 TEvtHandler*,     // source
  1012.                                 TEvent* event)    // override 
  1013.  
  1014. {
  1015.     if ((eventNumber == mRadioHit) &&!this->IsOn())
  1016.         this->Toggle(kRedraw);
  1017.     inherited::DoEvent(eventNumber, this, event);
  1018. }
  1019.  
  1020. //--------------------------------------------------------------------------------------------------
  1021. #pragma segment DlgRes
  1022.  
  1023. pascal Boolean TRadio::IsOn(void)
  1024. {
  1025.     return (this->GetLongVal() != 0);
  1026. }
  1027.  
  1028. //--------------------------------------------------------------------------------------------------
  1029. #pragma segment DlgRes
  1030.  
  1031. pascal void TRadio::SetState(Boolean state,
  1032.                              Boolean redraw)
  1033. {
  1034.     this->SetLongVal((long)(state), redraw);
  1035. }
  1036.  
  1037. //--------------------------------------------------------------------------------------------------
  1038. #pragma segment DlgRes
  1039.  
  1040. pascal void TRadio::Toggle(Boolean redraw)
  1041. {
  1042.     this->SetLongVal((long)(!this->IsOn()), redraw);
  1043. }
  1044.  
  1045. //--------------------------------------------------------------------------------------------------
  1046. #pragma segment DlgRes
  1047.  
  1048. pascal void TRadio::ToggleIf(Boolean matchState,
  1049.                              Boolean redraw)
  1050. {
  1051.     if (this->IsOn() == matchState)
  1052.         this->SetLongVal((long)(!this->IsOn()), redraw);
  1053. }
  1054.  
  1055. //--------------------------------------------------------------------------------------------------
  1056. #pragma segment DlgFields
  1057.  
  1058. pascal void TRadio::Fields(TObject* obj)        // override 
  1059. {
  1060.     obj->DoToField("TRadio", NULL, bClass);
  1061.  
  1062.     inherited::Fields(obj);
  1063. }
  1064.  
  1065. //--------------------------------------------------------------------------------------------------
  1066. #pragma segment DlgOpen
  1067.  
  1068. pascal void TCluster::Initialize(void)            // override 
  1069.  
  1070. {
  1071.     inherited::Initialize();
  1072.  
  1073.     fDataHandle = NULL;
  1074.     fRsrcID = kNoResource;
  1075.     fIndex = 0;                                    // ??? Is there a constant for this 
  1076.  
  1077.     fDefChoice = mClusterHit;
  1078. }
  1079.  
  1080. //--------------------------------------------------------------------------------------------------
  1081. #pragma segment DlgOpen
  1082.  
  1083. pascal void TCluster::ICluster(TView* itsSuperView,
  1084.                                const VPoint& itsLocation,
  1085.                                const VPoint& itsSize,
  1086.                                SizeDeterminer itsHSizeDet,
  1087.                                SizeDeterminer itsVSizeDet,
  1088.                                short itsRsrcID,
  1089.                                short itsIndex)
  1090.  
  1091.  
  1092. {
  1093.     Str255 aString;
  1094.     FailInfo fi;
  1095.  
  1096.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  1097.     fRsrcID = itsRsrcID;
  1098.     fIndex = itsIndex;
  1099.     if (fRsrcID != kNoResource)
  1100.     {
  1101.         if (fi.Try())
  1102.         {
  1103.             GetIndString(aString, fRsrcID, fIndex);
  1104.             FailResError();
  1105.             fi.Success();
  1106.         }
  1107.         else    // Recover
  1108.         {
  1109.             this->Free();
  1110.             fi.ReSignal();
  1111.         }
  1112.  
  1113.         this->SetLabel(aString, kDontRedraw);
  1114.     }
  1115.     this->SetEnable(False);                        // Default is not to enable hit testing 
  1116. }
  1117.  
  1118. //--------------------------------------------------------------------------------------------------
  1119. #pragma segment DlgOpen
  1120.  
  1121. pascal void TCluster::IRes(TDocument* ,
  1122.                            TView* itsSuperView,
  1123.                            Ptr& itsParams)        // override 
  1124.  
  1125. {
  1126.     inherited::IRes(NULL, itsSuperView, itsParams);
  1127.  
  1128.     this->SetLabel(((ClusterTemplatePtr)itsParams)->itsLabel, kDontRedraw);
  1129.  
  1130.     OffsetPtrWStr(itsParams, sizeof(ClusterTemplate));
  1131. }
  1132.  
  1133. //--------------------------------------------------------------------------------------------------
  1134. #pragma segment DlgRes
  1135.  
  1136. pascal TObject* TCluster::Clone(void)            // override 
  1137. {
  1138.     TCluster * aClonedCluster;
  1139.     Str255 theLabel;
  1140.  
  1141.  
  1142.     aClonedCluster = (TCluster *)(inherited::Clone());
  1143.  
  1144.     aClonedCluster->fDataHandle = NULL;
  1145.     this->GetLabel(theLabel);
  1146.     aClonedCluster->SetLabel(theLabel, kDontRedraw);
  1147.  
  1148.     return aClonedCluster;
  1149. }
  1150.  
  1151. //--------------------------------------------------------------------------------------------------
  1152. #pragma segment MAWriteRes
  1153.  
  1154. pascal void TCluster::WRes(ViewRsrcHandle theResource,
  1155.                            Ptr& itsParams)        // override 
  1156.  
  1157. {
  1158.     Str255 theLabel;
  1159.  
  1160.     inherited::WRes(theResource, itsParams);
  1161.  
  1162.     this->GetLabel(theLabel);
  1163.  
  1164.     ClusterTemplate& templateData = *((ClusterTemplate *) ExpandPtrWStr((Handle)theResource, itsParams, sizeof(ClusterTemplate), theLabel.Length()));
  1165.  
  1166.     // templateData.itsLabel = theLabel; 
  1167.     CopyStr255(theLabel, PRStr(templateData.itsLabel));
  1168. }
  1169.  
  1170. //--------------------------------------------------------------------------------------------------
  1171. #pragma segment MAWriteRes
  1172.  
  1173. pascal void TCluster::WriteRes(ViewRsrcHandle theResource,
  1174.                                Ptr& itsParams)    // override 
  1175.  
  1176. {
  1177.     gWResSignature = 'clus';
  1178.     gWResType = "TCluster";
  1179.     this->WRes(theResource, itsParams);
  1180. }
  1181.  
  1182. //--------------------------------------------------------------------------------------------------
  1183. #pragma segment DlgClose
  1184.  
  1185. pascal void TCluster::Free(void)                // override 
  1186. {
  1187.     this->ReleaseLabel();
  1188.     inherited::Free();
  1189. }
  1190.  
  1191. //--------------------------------------------------------------------------------------------------
  1192. #pragma segment DlgRes
  1193.  
  1194. pascal void TCluster::DoEvent(EvtNumber eventNumber,
  1195.                                   TEvtHandler* source,
  1196.                                   TEvent* event)// override 
  1197. {
  1198.     // If we got this far, a radio's changed state. Only worry about it if it's our subview!
  1199.     if ((eventNumber == mRadioHit) && (((TView *)source)->fSuperView == this))
  1200.     {
  1201.         CSubViewIterator iter(this);
  1202.         
  1203.         for (TView* theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  1204.             // If the subview is a TRadio, and it's not the calling radio… 
  1205.             if (theSubView->IsMemberClass(GetClassIDFromName("TRadio")) && (theSubView != source))
  1206.                 ((TRadio *)theSubView)->SetState(False, kRedraw);    // …set it off and redraw it 
  1207.     }
  1208.     
  1209.     inherited::DoEvent(eventNumber, source, event);
  1210. }
  1211.  
  1212. //--------------------------------------------------------------------------------------------------
  1213. #pragma segment DlgRes
  1214.  
  1215. pascal void TCluster::Draw(const VRect& area)    // override 
  1216. {
  1217.     short theFontHeight;
  1218.     VCoordinate theFrameTop;
  1219.     VRect theFrame;
  1220.     Rect theQDFrame;
  1221.     RGBColor oldColor;
  1222.     TextStyle aTextStyle;
  1223.     FontInfo theFontInfo;
  1224.  
  1225.     if (fDataHandle)
  1226.     {
  1227.         PenNormal();                            // Normalcy in most things 
  1228.  
  1229.         PenSize(fPenSize.h, fPenSize.v);        // PenSize(2, 2); 
  1230.  
  1231.         GetIfColor(oldColor);                    // Save the original pen color 
  1232.         aTextStyle = fTextStyle;
  1233.         GetTextStyleFontInfo(aTextStyle, theFontInfo, theFontHeight);
  1234.         this->ControlArea(theFrame);            // Get the control's extent 
  1235.         theFrameTop = theFrame.top + ((theFontHeight) >> 1);
  1236.  
  1237.         theFrame.Inset(VPoint(fPenSize.v + 1, fPenSize.h + 1));    // Inset the frame a little.
  1238.  
  1239.         theFrame.top = theFrameTop;                // Bump top so it cuts label in half 
  1240.  
  1241.         this->ViewToQDRect(theFrame, theQDFrame);
  1242.         FrameRect(theQDFrame);                    // Draw the frame 
  1243.         this->DrawLabel(area);                    // Draw the label 
  1244.  
  1245.         SetIfColor(oldColor);
  1246.     }
  1247.     inherited::Draw(area);                        // Let parents have a chance to draw too 
  1248. }
  1249.  
  1250. //--------------------------------------------------------------------------------------------------
  1251. #pragma segment DlgRes
  1252.  
  1253. pascal void TCluster::DrawLabel(const VRect& /* area */)
  1254. {
  1255.     TextStyle aTextStyle;
  1256.     Str255 theText;
  1257.     Rect labelQDRect;
  1258.     VRect dstRect;
  1259.     FontInfo theFontInfo;
  1260.  
  1261.  
  1262.     aTextStyle = fTextStyle;
  1263.     SetPortTextStyle(aTextStyle);                // Install the object's TextStyle 
  1264.  
  1265.     this->GetLabel(theText);                    // retrieve the label 
  1266.  
  1267.     MAReplaceText(theText);
  1268.  
  1269.     VRect labelRect(0, 16, MAGetFontInfo(theFontInfo), StringWidth(theText) + 8 + 16);
  1270.     if ((labelRect & dstRect).Valid())
  1271.     {
  1272.         this->ViewToQDRect(labelRect, labelQDRect);
  1273.         MATextBox((Ptr)(((long) & theText) + 1), theText.Length(), labelQDRect, teCenter, kNoAutoWrap, NULL, kEraseFirst, kNoSpaceForCaret);
  1274.     }
  1275. }
  1276.  
  1277. //--------------------------------------------------------------------------------------------------
  1278. #pragma segment DlgNonRes
  1279.  
  1280. pascal void TCluster::GetLabel(Str255& theLabel)
  1281. {
  1282.     if (fDataHandle)
  1283.         CopyStr255((**((String255Handle)fDataHandle)), (Ptr) & theLabel);
  1284.     else
  1285.         theLabel = "";
  1286. }
  1287.  
  1288. //--------------------------------------------------------------------------------------------------
  1289. #pragma segment DlgNonRes
  1290.  
  1291. pascal void TCluster::ReleaseLabel(void)
  1292. {
  1293.     fDataHandle = (StringHandle)DisposeIfHandle((Handle)fDataHandle);
  1294.  
  1295.     fRsrcID = kNoResource;
  1296. }
  1297.  
  1298. //--------------------------------------------------------------------------------------------------
  1299. #pragma segment DlgRes
  1300.  
  1301. pascal Boolean FindRadio(TView* aView,
  1302.                          void*                    /* staticLink */)
  1303. {
  1304.     return (aView && aView->IsMemberClass(GetClassIDFromName("TRadio")) && ((TRadio *)aView)->IsOn());
  1305. }
  1306.  
  1307.  
  1308. pascal IDType TCluster::ReportCurrent(void)
  1309. {
  1310.     TView * rView;
  1311.  
  1312.     rView = this->FirstSubViewThat(FindRadio, this);
  1313.     if (rView)
  1314.         return (rView->fIdentifier);
  1315.     else
  1316.         return kNoIdentifier;
  1317. }
  1318.  
  1319. //--------------------------------------------------------------------------------------------------
  1320. #pragma segment DlgNonRes
  1321.  
  1322. pascal void TCluster::SetLabel(const Str255& theLabel,
  1323.                                Boolean redraw)
  1324.  
  1325. {
  1326.     this->ReleaseLabel();
  1327.     if (!theLabel.IsEmpty())
  1328.     {
  1329.         fDataHandle = NewString(theLabel);
  1330.         if (MemError() != noErr)
  1331.             fDataHandle = NULL;
  1332.     }
  1333.     if (redraw)
  1334.         this->ForceRedraw();
  1335. }
  1336.  
  1337. //--------------------------------------------------------------------------------------------------
  1338. #pragma segment DlgFields
  1339.  
  1340. pascal void TCluster::Fields(TObject* obj)        // override 
  1341. {
  1342.     Str255 aString;
  1343.  
  1344.     obj->DoToField("TCluster", NULL, bClass);
  1345.     obj->DoToField("fRsrcID", &fRsrcID, bInteger);
  1346.     obj->DoToField("fIndex", &fIndex, bInteger);
  1347.     obj->DoToField("fDataHandle", &fDataHandle, bHandle);
  1348.     if (fDataHandle)
  1349.     {
  1350.         aString = (**((String255Handle)fDataHandle));
  1351.         obj->DoToField("**fDataHandle", &aString, bString);
  1352.     }
  1353.  
  1354.     inherited::Fields(obj);
  1355. }
  1356.  
  1357. //--------------------------------------------------------------------------------------------------
  1358. #pragma segment DlgOpen
  1359.  
  1360. pascal void TIcon::Initialize(void)                // override 
  1361.  
  1362. {
  1363.     inherited::Initialize();
  1364.  
  1365.     fDataHandle = NULL;
  1366.     fIsColor = kPreferColor;
  1367.     fPreferColor = kPreferColor;
  1368.     fRsrcID = kNoResource;
  1369.  
  1370.     fDefChoice = mIconHit;
  1371. }
  1372.  
  1373. //--------------------------------------------------------------------------------------------------
  1374. #pragma segment DlgOpen
  1375.  
  1376. pascal void TIcon::IIcon(TView* itsSuperView,
  1377.                          const VPoint& itsLocation,
  1378.                          const VPoint& itsSize,
  1379.                          SizeDeterminer itsHSizeDet,
  1380.                          SizeDeterminer itsVSizeDet,
  1381.                          short itsRsrcID,
  1382.                          Boolean preferColor)
  1383.  
  1384. {
  1385.     FailInfo fi;
  1386.     Handle itsRsrcHandle;
  1387.     SignedByte savedState;
  1388.  
  1389.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  1390.     fPreferColor = preferColor;
  1391.     fIsColor = preferColor;
  1392.     fRsrcID = itsRsrcID;
  1393.     if (fRsrcID != kNoResource)
  1394.     {
  1395.         if (fi.Try())
  1396.         {
  1397.             if ((fPreferColor) && (qNeedsColorQD || gConfiguration.hasColorQD))
  1398.             {
  1399.                 // make the 'cicn' resource non-purgeable, so the Toolbox doesn't die 
  1400.                 itsRsrcHandle = GetResource('cicn', fRsrcID);
  1401.                 if (itsRsrcHandle)
  1402.                 {
  1403.                     savedState = HGetState(itsRsrcHandle);
  1404.                     HNoPurge(itsRsrcHandle);
  1405.                 }
  1406.  
  1407.                 fDataHandle = (Handle)GetCIcon(fRsrcID);
  1408.  
  1409.                 // restore the state of the 'cicn' resource 
  1410.                 if (itsRsrcHandle)
  1411.                     HSetState(itsRsrcHandle, savedState);
  1412.             }
  1413.             if (fDataHandle == NULL)
  1414.             {
  1415.                 fDataHandle = GetIcon(fRsrcID);
  1416.                 if (fDataHandle)
  1417.                     fIsColor =!kPreferColor;    // Either can't or won't 
  1418.             }
  1419.             FailNILResource(fDataHandle);        // was FailResError();
  1420.             fi.Success();
  1421.         }
  1422.         else    // Recover
  1423.         {
  1424.             this->Free();
  1425.             fi.ReSignal();
  1426.         }
  1427.     }
  1428.     this->SetEnable(False);                        // Default is to not enable hit testing     }
  1429. }
  1430.  
  1431. //--------------------------------------------------------------------------------------------------
  1432. #pragma segment DlgOpen
  1433.  
  1434. pascal void TIcon::IRes(TDocument* ,
  1435.                         TView* itsSuperView,
  1436.                         Ptr& itsParams)            // override 
  1437. {
  1438.     FailInfo fi;
  1439.     Handle itsRsrcHandle;
  1440.     SignedByte savedState;
  1441.  
  1442.     fDataHandle = NULL;
  1443.     inherited::IRes(NULL, itsSuperView, itsParams);
  1444.  
  1445.     IconTemplate& templateData = *((IconTemplate *) itsParams);
  1446.  
  1447.     fPreferColor = templateData.preferColor;
  1448.     fIsColor = templateData.preferColor;
  1449.     fRsrcID = templateData.rsrcID;
  1450.  
  1451.     if (fRsrcID != kNoResource)
  1452.     {
  1453.         if (fi.Try())
  1454.         {
  1455.             if ((fPreferColor) && (qNeedsColorQD || gConfiguration.hasColorQD))
  1456.             {
  1457.                 // make the 'cicn' resource non-purgeable, so the Toolbox doesn't die 
  1458.                 itsRsrcHandle = GetResource('cicn', fRsrcID);
  1459.                 if (itsRsrcHandle)
  1460.                 {
  1461.                     savedState = HGetState(itsRsrcHandle);
  1462.                     HNoPurge(itsRsrcHandle);
  1463.                 }
  1464.  
  1465.                 fDataHandle = (Handle)GetCIcon(fRsrcID);
  1466.  
  1467.                 // restore the state of the 'cicn' resource 
  1468.                 if (itsRsrcHandle)
  1469.                     HSetState(itsRsrcHandle, savedState);
  1470.             }
  1471.             if (fDataHandle == NULL)
  1472.             {
  1473.                 fDataHandle = GetIcon(fRsrcID);
  1474.                 if (fDataHandle)
  1475.                     fIsColor =!kPreferColor;    // Either can't or won't 
  1476.             }
  1477.             // Don't die because resource not found - just return NULL handle 
  1478.             FailNILResource(fDataHandle);        // was FailResError();
  1479.             fi.Success();
  1480.         }
  1481.         else    // Recover
  1482.         {
  1483.             this->Free();
  1484.             fi.ReSignal();
  1485.         }
  1486.     }
  1487.  
  1488.     OffsetPtr(itsParams, sizeof(IconTemplate));
  1489. }
  1490.  
  1491. //--------------------------------------------------------------------------------------------------
  1492. #pragma segment DlgRes
  1493.  
  1494. pascal TObject* TIcon::Clone(void)                // override 
  1495. {
  1496.     TIcon * aClonedIcon;
  1497.     Handle aHandle;
  1498.     OSErr err;
  1499.     Handle itsRsrcHandle;
  1500.     SignedByte savedState;
  1501.  
  1502.  
  1503.     aClonedIcon = (TIcon *)(inherited::Clone());
  1504.     aClonedIcon->fDataHandle = NULL;
  1505.  
  1506.     if (fDataHandle)
  1507.     {
  1508.         if (fIsColor)
  1509.         {
  1510.             // make the 'cicn' resource non-purgeable, so the Toolbox doesn't die 
  1511.             itsRsrcHandle = GetResource('cicn', fRsrcID);
  1512.             if (itsRsrcHandle)
  1513.             {
  1514.                 savedState = HGetState(itsRsrcHandle);
  1515.                 HNoPurge(itsRsrcHandle);
  1516.             }
  1517.  
  1518.             aClonedIcon->fDataHandle = (Handle)GetCIcon(fRsrcID);
  1519.  
  1520.             // restore the state of the 'cicn' resource 
  1521.             if (itsRsrcHandle)
  1522.                 HSetState(itsRsrcHandle, savedState);
  1523.         }
  1524.         else
  1525.         {
  1526.             aHandle = fDataHandle;
  1527.             err = HandToHand(aHandle);
  1528.             if (err != noErr)
  1529.                 FailNIL(aHandle);
  1530.             aClonedIcon->fDataHandle = aHandle;
  1531.         }
  1532.     }
  1533.     return aClonedIcon;
  1534. }
  1535.  
  1536. //--------------------------------------------------------------------------------------------------
  1537. #pragma segment MAWriteRes
  1538.  
  1539. pascal void TIcon::WRes(ViewRsrcHandle theResource,
  1540.                         Ptr& itsParams)            // override 
  1541. {
  1542.     inherited::WRes(theResource, itsParams);
  1543.  
  1544.     IconTemplate& templateData = *((IconTemplate *) ExpandPtr((Handle)theResource, itsParams, sizeof(IconTemplate)));
  1545.  
  1546.     templateData.preferColor = fPreferColor;
  1547. #if qDebugMsg
  1548.     if (fRsrcID == kNoResource)
  1549.         fprintf(stderr, "Tried to write TIcon with no resource ID.\n");
  1550. #endif
  1551.  
  1552.     templateData.rsrcID = fRsrcID;
  1553. }
  1554.  
  1555. //--------------------------------------------------------------------------------------------------
  1556. #pragma segment MAWriteRes
  1557.  
  1558. pascal void TIcon::WriteRes(ViewRsrcHandle theResource,
  1559.                             Ptr& itsParams)        // override 
  1560. {
  1561.     gWResSignature = 'icon';
  1562.     gWResType = "TIcon";
  1563.     this->WRes(theResource, itsParams);
  1564. }
  1565.  
  1566. //--------------------------------------------------------------------------------------------------
  1567. #pragma segment DlgClose
  1568.  
  1569. pascal void TIcon::Free(void)                    // override 
  1570. {
  1571.     this->ReleaseIcon();
  1572.  
  1573.     inherited::Free();
  1574. }
  1575.  
  1576. //--------------------------------------------------------------------------------------------------
  1577. #pragma segment DlgRes
  1578.  
  1579. pascal void TIcon::Draw(const VRect& area)        // override 
  1580. {
  1581.     SignedByte oldState;
  1582.     VRect theRect;
  1583.     Rect theQDRect;
  1584.     PixMap aPixMap;
  1585.     BitMapPtr aBitMapPtr;
  1586.     Rect srcRect;
  1587.  
  1588.  
  1589.     if (fDataHandle)
  1590.     {
  1591.         if (IsAResource(fDataHandle))
  1592.             LoadResource(fDataHandle);
  1593.         if (*fDataHandle)                // If there's room for the icon… 
  1594.         {
  1595.             PenNormal();                        // NECESSARY? 
  1596.             this->ControlArea(theRect);
  1597.             this->ViewToQDRect(theRect, theQDRect);
  1598.             oldState = HGetState(fDataHandle);
  1599.             HNoPurge(fDataHandle);
  1600.             HLock(fDataHandle);
  1601.  
  1602.             if (fIsColor)
  1603.             {
  1604.  
  1605.                 // We can't use PlotCIcon here because it can't be written to a picture 
  1606.                 // and when WriteToDeskScrap is called, the icon is plotted on the 
  1607.                 // desktop rather than in the picture.  So instead, pick apart the color 
  1608.                 // icon handle and use copybits, ignoring the mask. 
  1609.  
  1610.                 aPixMap = (**((CIconHandle)fDataHandle)).iconPMap;
  1611.                 HLock((**((CIconHandle)fDataHandle)).iconData);
  1612.                 aPixMap.baseAddr = *((**((CIconHandle)fDataHandle)).iconData);
  1613.                 srcRect = aPixMap.bounds;
  1614.                 aBitMapPtr = (BitMapPtr) & aPixMap;
  1615.                 CopyBits((*aBitMapPtr), qd.thePort->portBits, srcRect, theQDRect, srcCopy, NULL);
  1616.                 HUnlock((**((CIconHandle)fDataHandle)).iconData);
  1617.             }
  1618.             else
  1619.                 PlotIcon(theQDRect, fDataHandle);
  1620.  
  1621.             HSetState(fDataHandle, oldState);
  1622.         }
  1623.     }
  1624.  
  1625.     inherited::Draw(area);
  1626. }
  1627.  
  1628. //--------------------------------------------------------------------------------------------------
  1629. #pragma segment DlgNonRes
  1630.  
  1631. pascal void TIcon::ReleaseIcon(void)
  1632. {
  1633.     fRsrcID = kNoResource;
  1634.     if (fDataHandle)
  1635.     {
  1636.         if (fIsColor)
  1637.             DisposCIcon((CIconHandle)fDataHandle);
  1638.         else
  1639.             HPurge(fDataHandle);
  1640.         fDataHandle = NULL;
  1641.     }
  1642. }
  1643.  
  1644. //--------------------------------------------------------------------------------------------------
  1645. #pragma segment DlgNonRes
  1646.  
  1647. pascal void TIcon::SetIcon(Handle theIcon,
  1648.                            Boolean redraw)
  1649. {
  1650.     short theID;
  1651.     ResType theType;
  1652.     Str255 name;
  1653.  
  1654.  
  1655.     this->ReleaseIcon();
  1656.     if (GetHandleSize(theIcon) != 128)
  1657.         fPreferColor = TRUE;
  1658.     else
  1659.         fPreferColor = FALSE;
  1660.     fDataHandle = theIcon;
  1661.  
  1662.     // get the rsrc id 
  1663.     GetResInfo(theIcon, theID, theType, name);
  1664.     if (ResError() == noErr)
  1665.         fRsrcID = theID;
  1666.  
  1667.     if (redraw)
  1668.         this->ForceRedraw();
  1669. }
  1670.  
  1671. //--------------------------------------------------------------------------------------------------
  1672. #pragma segment DlgFields
  1673.  
  1674. pascal void TIcon::Fields(TObject* obj)            // override 
  1675. {
  1676.     obj->DoToField("TIcon", NULL, bClass);
  1677.     obj->DoToField("fPreferColor", &fPreferColor, bBoolean);
  1678.     obj->DoToField("fIsColor", &fIsColor, bBoolean);
  1679.     obj->DoToField("fRsrcID", &fRsrcID, bInteger);
  1680.     obj->DoToField("fDataHandle", &fDataHandle, bHandle);
  1681.  
  1682.     inherited::Fields(obj);
  1683. }
  1684.  
  1685. //--------------------------------------------------------------------------------------------------
  1686. #pragma segment DlgOpen
  1687.  
  1688. pascal void TSmallIcon::Initialize(void)        // override 
  1689. {
  1690.     inherited::Initialize();
  1691.     fDataHandle = NULL;
  1692.     fRsrcID = kNoResource;
  1693.     fDefChoice = mSmallIconHit;
  1694. }
  1695.  
  1696. //--------------------------------------------------------------------------------------------------
  1697. #pragma segment DlgOpen
  1698.  
  1699. pascal void TSmallIcon::ISmallIcon(TView* itsSuperView,
  1700.                                    const VPoint& itsLocation,
  1701.                                    const VPoint& itsSize,
  1702.                                    SizeDeterminer itsHSizeDet,
  1703.                                    SizeDeterminer itsVSizeDet,
  1704.                                    short itsRsrcID)
  1705. {
  1706.     FailInfo fi;
  1707.  
  1708.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  1709.     fRsrcID = itsRsrcID;
  1710.     if (fRsrcID != kNoResource)
  1711.     {
  1712.         if (fi.Try())
  1713.         {
  1714.             fDataHandle = GetResource('SICN', fRsrcID);
  1715.             FailNILResource(fDataHandle);        // was FailResError();
  1716.             fi.Success();
  1717.         }
  1718.         else    // Recover
  1719.         {
  1720.             this->Free();
  1721.             fi.ReSignal();
  1722.         }
  1723.     }
  1724.     this->SetEnable(False);                        // Default is to not enable hit testing 
  1725. }
  1726.  
  1727. //--------------------------------------------------------------------------------------------------
  1728. #pragma segment DlgOpen
  1729.  
  1730. pascal void TSmallIcon::IRes(TDocument* ,
  1731.                              TView* itsSuperView,
  1732.                              Ptr& itsParams)    // override 
  1733. {
  1734.     const short kReadOnlySICN = 256;            // resource ID of small slashed pencil icon 
  1735.     FailInfo fi;
  1736.  
  1737.     inherited::IRes(NULL, itsSuperView, itsParams);
  1738.  
  1739.     //  fRsrcID = ((SmallIconTemplatePtr) itsParams)->rsrcID; 
  1740.     fRsrcID = kReadOnlySICN;                    // !!! change when templates are updated
  1741.     if (fRsrcID != kNoResource)
  1742.     {
  1743.         if (fi.Try())
  1744.         {
  1745.             fDataHandle = GetResource('SICN', fRsrcID);
  1746.             FailNILResource(fDataHandle);        // was FailResError();
  1747.             fi.Success();
  1748.         }
  1749.         else    // Recover
  1750.         {
  1751.             this->Free();
  1752.             fi.ReSignal();
  1753.         }
  1754.     }
  1755.  
  1756.     //  OffsetPtr(itsParams, sizeof(SmallIconTemplate));    
  1757. }
  1758.  
  1759. //--------------------------------------------------------------------------------------------------
  1760. #pragma segment DlgRes
  1761.  
  1762. pascal TObject* TSmallIcon::Clone(void)            // override 
  1763. {
  1764.     TSmallIcon * aClonedSmallIcon;
  1765.     Handle aHandle;
  1766.     OSErr err;
  1767.  
  1768.  
  1769.     aClonedSmallIcon = (TSmallIcon *)(inherited::Clone());
  1770.  
  1771.     aHandle = aClonedSmallIcon->fDataHandle;
  1772.     if (aHandle)
  1773.     {
  1774.         err = HandToHand(aHandle);
  1775.         if (err != noErr)
  1776.             FailNIL(aHandle);
  1777.         aClonedSmallIcon->fDataHandle = aHandle;
  1778.     }
  1779.  
  1780.     return aClonedSmallIcon;
  1781. }
  1782.  
  1783. //--------------------------------------------------------------------------------------------------
  1784. #pragma segment MAWriteRes
  1785.  
  1786. pascal void TSmallIcon::WRes(ViewRsrcHandle theResource,
  1787.                              Ptr& itsParams)    // override 
  1788. {
  1789.     inherited::WRes(theResource, itsParams);
  1790.  
  1791.     SmallIconTemplate& templateData = *((SmallIconTemplate *) ExpandPtr((Handle)theResource, itsParams, sizeof(SmallIconTemplate)));
  1792.  
  1793. #if qDebugMsg
  1794.     if (fRsrcID == kNoResource)
  1795.         fprintf(stderr, "Tried to write TSmallIcon with no resource ID.\n");
  1796. #endif
  1797.  
  1798.     templateData.rsrcID = fRsrcID;
  1799. }
  1800.  
  1801. //--------------------------------------------------------------------------------------------------
  1802. #pragma segment MAWriteRes
  1803.  
  1804. pascal void TSmallIcon::WriteRes(ViewRsrcHandle theResource,
  1805.                                  Ptr& itsParams)// override 
  1806. {
  1807.     gWResSignature = 'SICN';
  1808.     gWResType = "TSmallIcon";
  1809.     this->WRes(theResource, itsParams);
  1810. }
  1811.  
  1812. //--------------------------------------------------------------------------------------------------
  1813. #pragma segment DlgRes
  1814.  
  1815. pascal void TSmallIcon::Draw(const VRect& area)    // override 
  1816. {
  1817.     SignedByte oldState;
  1818.     VRect theRect;
  1819.     Rect theQDRect;
  1820.     BitMap srcBits;
  1821.     GrafPtr port;
  1822.  
  1823.  
  1824. #if qDebug
  1825.     this->AssumeFocused();
  1826. #endif
  1827.  
  1828.     if (fDataHandle)
  1829.     {
  1830.         if (IsAResource(fDataHandle))
  1831.             LoadResource(fDataHandle);
  1832.         if (*fDataHandle)                // If there's room for the small icon… 
  1833.         {
  1834.             this->ControlArea(theRect);
  1835.             this->ViewToQDRect(theRect, theQDRect);
  1836.             oldState = HGetState(fDataHandle);
  1837.             HNoPurge(fDataHandle);
  1838.             // construct a source BitMap 
  1839.             srcBits.baseAddr = (*fDataHandle);
  1840.             srcBits.rowBytes = 2;
  1841.             SetRect(srcBits.bounds, 0, 0, 16, 16);
  1842.  
  1843.             GetPort(port);
  1844.             CopyBits(srcBits, port->portBits, srcBits.bounds, theQDRect, srcCopy, NULL);
  1845.             HSetState(fDataHandle, oldState);
  1846.         }
  1847.     }
  1848.  
  1849.     inherited::Draw(area);
  1850. }
  1851.  
  1852. //--------------------------------------------------------------------------------------------------
  1853. #pragma segment DlgNonRes
  1854.  
  1855. pascal void TSmallIcon::ReleaseSmallIcon(void)
  1856. {
  1857.     fRsrcID = kNoResource;
  1858.     if (fDataHandle)
  1859.         HPurge(fDataHandle);
  1860.     fDataHandle = NULL;
  1861. }
  1862.  
  1863. //--------------------------------------------------------------------------------------------------
  1864. #pragma segment DlgNonRes
  1865.  
  1866. pascal void TSmallIcon::SetSmallIcon(short theSmallIcon,
  1867.                                      Boolean redraw)
  1868. {
  1869.     FailInfo fi;
  1870.  
  1871.     this->ReleaseSmallIcon();
  1872.     if (fi.Try())
  1873.     {
  1874.         fDataHandle = GetResource('SICN', theSmallIcon);
  1875.         FailResError();
  1876.         fi.Success();
  1877.     }
  1878.     else    // Recover
  1879.     {
  1880.         this->Free();
  1881.         fi.ReSignal();
  1882.     }
  1883.     fRsrcID = theSmallIcon;
  1884.     if (redraw)
  1885.         this->ForceRedraw();
  1886. }
  1887.  
  1888. //--------------------------------------------------------------------------------------------------
  1889. #pragma segment DlgFields
  1890.  
  1891. pascal void TSmallIcon::Fields(TObject* obj)    // override 
  1892. {
  1893.     obj->DoToField("TSmallIcon", NULL, bClass);
  1894.     obj->DoToField("fRsrcID", &fRsrcID, bInteger);
  1895.     obj->DoToField("fDataHandle", &fDataHandle, bHandle);
  1896.  
  1897.     inherited::Fields(obj);
  1898. }
  1899.  
  1900. //--------------------------------------------------------------------------------------------------
  1901. #pragma segment DlgOpen
  1902.  
  1903. pascal void TPattern::Initialize(void)            // override 
  1904. {
  1905.     inherited::Initialize();
  1906.  
  1907.     fDataHandle = NULL;
  1908.     fPreferColor = kPreferColor;
  1909.     fIsColor = kPreferColor;
  1910.     fRsrcID = kNoResource;
  1911.  
  1912.     fDefChoice = mPatternHit;
  1913. }
  1914.  
  1915. //--------------------------------------------------------------------------------------------------
  1916. #pragma segment DlgOpen
  1917.  
  1918. pascal void TPattern::IPattern(TView* itsSuperView,
  1919.                                const VPoint& itsLocation,
  1920.                                const VPoint& itsSize,
  1921.                                SizeDeterminer itsHSizeDet,
  1922.                                SizeDeterminer itsVSizeDet,
  1923.                                short itsRsrcID,
  1924.                                Boolean preferColor)
  1925. {
  1926.     FailInfo fi;
  1927.  
  1928.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  1929.     fPreferColor = preferColor;
  1930.     fIsColor = preferColor;
  1931.     fRsrcID = itsRsrcID;
  1932.     if (fRsrcID != kNoResource)
  1933.     {
  1934.         if (fi.Try())
  1935.         {
  1936.             if ((fPreferColor) && (qNeedsColorQD || gConfiguration.hasColorQD))
  1937.                 fDataHandle = (Handle)GetPixPat(fRsrcID);
  1938.             if (fDataHandle == NULL)
  1939.             {
  1940.                 fDataHandle = (Handle)GetPattern(fRsrcID);
  1941.                 if (fDataHandle)
  1942.                     fIsColor =!kPreferColor;    // Either can't or won't 
  1943.             }
  1944.             FailNILResource(fDataHandle);        // was FailResError();
  1945.             fi.Success();
  1946.         }
  1947.         else    // Recover
  1948.         {
  1949.             this->Free();
  1950.             fi.ReSignal();
  1951.         }
  1952.     }
  1953.     this->SetEnable(False);                        // Default is to not enable hit testing 
  1954. }
  1955.  
  1956. //--------------------------------------------------------------------------------------------------
  1957. #pragma segment DlgOpen
  1958.  
  1959. pascal void TPattern::IRes(TDocument* ,
  1960.                            TView* itsSuperView,
  1961.                            Ptr& itsParams)        // override 
  1962. {
  1963.     FailInfo fi;
  1964.  
  1965.     inherited::IRes(NULL, itsSuperView, itsParams);
  1966.  
  1967.     PatternTemplate& templateData = *((PatternTemplate *) itsParams);
  1968.     fPreferColor = templateData.preferColor;
  1969.     fIsColor = templateData.preferColor;
  1970.     fRsrcID = templateData.rsrcID;
  1971.  
  1972.     if (fRsrcID != kNoResource)
  1973.     {
  1974.         if (fi.Try())
  1975.         {
  1976.             if ((fPreferColor) && (qNeedsColorQD || gConfiguration.hasColorQD))
  1977.                 fDataHandle = (Handle)GetPixPat(fRsrcID);
  1978.             if (fDataHandle == NULL)
  1979.             {
  1980.                 fDataHandle = (Handle)GetPattern(fRsrcID);
  1981.                 if (fDataHandle)
  1982.                     fIsColor =!kPreferColor;    // Either can't or won't 
  1983.             }
  1984.             FailNILResource(fDataHandle);        // was FailResError();
  1985.             fi.Success();
  1986.         }
  1987.         else    // Recover
  1988.         {
  1989.             this->Free();
  1990.             fi.ReSignal();
  1991.         }
  1992.     }
  1993.  
  1994.     OffsetPtr(itsParams, sizeof(PatternTemplate));
  1995. }
  1996.  
  1997. //--------------------------------------------------------------------------------------------------
  1998. #pragma segment DlgRes
  1999.  
  2000. pascal TObject* TPattern::Clone(void)            // override 
  2001. {
  2002.     TPattern * aClonedPattern;
  2003.     FailInfo fi;
  2004.     Handle aHandle;
  2005.     OSErr err;
  2006.     
  2007.     VOLATILE(aClonedPattern);
  2008.  
  2009.     aClonedPattern = (TPattern *)(inherited::Clone());
  2010.  
  2011.     if (fDataHandle)
  2012.     {
  2013.         if (fi.Try())
  2014.         {
  2015.             if (fIsColor)
  2016.                 aClonedPattern->fDataHandle = (Handle)GetPixPat(fRsrcID);
  2017.             else
  2018.             {
  2019.                 aHandle = fDataHandle;
  2020.                 err = HandToHand(aHandle);
  2021.                 aClonedPattern->fDataHandle = aHandle;
  2022.             }
  2023.             FailNIL(aClonedPattern->fDataHandle);
  2024.             fi.Success();
  2025.         }
  2026.         else    // Recover
  2027.         {
  2028.             aClonedPattern->Free();
  2029.             fi.ReSignal();
  2030.         }
  2031.     }
  2032.  
  2033.     return aClonedPattern;
  2034. }
  2035.  
  2036. //--------------------------------------------------------------------------------------------------
  2037. #pragma segment MAWriteRes
  2038.  
  2039. pascal void TPattern::WRes(ViewRsrcHandle theResource,
  2040.                            Ptr& itsParams)        // override 
  2041. {
  2042.     inherited::WRes(theResource, itsParams);
  2043.  
  2044.     PatternTemplate& templateData = *((PatternTemplate *) ExpandPtr((Handle)theResource, itsParams, sizeof(PatternTemplate)));
  2045.  
  2046.     templateData.preferColor = fPreferColor;
  2047. #if qDebugMsg
  2048.     if (fRsrcID == kNoResource)
  2049.         fprintf(stderr, "Tried to write TPattern with no resource ID.\n");
  2050. #endif
  2051.  
  2052.     templateData.rsrcID = fRsrcID;
  2053. }
  2054.  
  2055. //--------------------------------------------------------------------------------------------------
  2056. #pragma segment MAWriteRes
  2057.  
  2058. pascal void TPattern::WriteRes(ViewRsrcHandle theResource,
  2059.                                Ptr& itsParams)    // override 
  2060. {
  2061.     gWResSignature = 'patn';
  2062.     gWResType = "TPattern";
  2063.     this->WRes(theResource, itsParams);
  2064. }
  2065.  
  2066. //--------------------------------------------------------------------------------------------------
  2067. #pragma segment DlgClose
  2068.  
  2069. pascal void TPattern::Free(void)                // override 
  2070. {
  2071.     this->ReleasePattern();
  2072.  
  2073.     inherited::Free();
  2074. }
  2075.  
  2076. //--------------------------------------------------------------------------------------------------
  2077. #pragma segment DlgRes
  2078.  
  2079. pascal void TPattern::Draw(const VRect& area)    // override 
  2080. {
  2081.     Boolean wasLocked;
  2082.     VRect theRect;
  2083.     Rect theQDRect;
  2084.  
  2085.     if (fDataHandle)
  2086.     {
  2087.         if (IsAResource(fDataHandle) &&!fIsColor)// Pixpat handles != resource handles 
  2088.             LoadResource(fDataHandle);
  2089.         if (*fDataHandle)                // If there's room for the pattern… 
  2090.         {
  2091.             PenNormal();                        // NECESSARY? 
  2092.             this->ControlArea(theRect);
  2093.             this->ViewToQDRect(theRect, theQDRect);
  2094.             wasLocked = IsHandleLocked(fDataHandle);// Remember current lock state 
  2095.             if (!wasLocked)
  2096.                 HLock(fDataHandle);                // Because FillRect may move memory 
  2097.             if (fIsColor)
  2098.                 FillCRect(theQDRect, (PixPatHandle)fDataHandle);
  2099.             else
  2100.                 FillRect(theQDRect, *((PatHandle)fDataHandle));
  2101.             if (!wasLocked)
  2102.                 HUnlock(fDataHandle);            // restore handle's unlocked state 
  2103.         }
  2104.     }
  2105.  
  2106.     inherited::Draw(area);
  2107. }
  2108.  
  2109. //--------------------------------------------------------------------------------------------------
  2110. #pragma segment DlgNonRes
  2111.  
  2112. pascal void TPattern::ReleasePattern(void)
  2113. {
  2114.     fRsrcID = kNoResource;
  2115.     if (fDataHandle)
  2116.     {
  2117.         if (fIsColor)
  2118.             DisposPixPat((PixPatHandle)fDataHandle);
  2119.         else
  2120.             HPurge(fDataHandle);
  2121.         fDataHandle = NULL;
  2122.     }
  2123. }
  2124.  
  2125. //--------------------------------------------------------------------------------------------------
  2126. #pragma segment DlgNonRes
  2127.  
  2128. pascal void TPattern::SetPattern(Handle thePattern,
  2129.                                  Boolean redraw)
  2130. {
  2131.     short theID;
  2132.     ResType theType;
  2133.     Str255 name;
  2134.  
  2135.     this->ReleasePattern();
  2136.     fDataHandle = thePattern;
  2137.  
  2138.     // get the rsrc id for non-color patterns (color pattern handles aren't resource handles) 
  2139.     if (!fIsColor)
  2140.     {
  2141.         GetResInfo(thePattern, theID, theType, name);
  2142.         if (ResError() == noErr)
  2143.             fRsrcID = theID;
  2144.     }
  2145.  
  2146.     if (redraw)
  2147.         this->ForceRedraw();
  2148. }
  2149.  
  2150. //--------------------------------------------------------------------------------------------------
  2151. #pragma segment DlgFields
  2152.  
  2153. pascal void TPattern::Fields(TObject* obj)        // override 
  2154. {
  2155.     obj->DoToField("TPattern", NULL, bClass);
  2156.     obj->DoToField("fPreferColor", &fPreferColor, bBoolean);
  2157.     obj->DoToField("fIsColor", &fIsColor, bBoolean);
  2158.     obj->DoToField("fRsrcID", &fRsrcID, bInteger);
  2159.     obj->DoToField("fDataHandle", &fDataHandle, bHandle);
  2160.  
  2161.     inherited::Fields(obj);
  2162. }
  2163.  
  2164. //--------------------------------------------------------------------------------------------------
  2165. #pragma segment DlgOpen
  2166.  
  2167. pascal void TPicture::Initialize(void)            // override 
  2168. {
  2169.     inherited::Initialize();
  2170.  
  2171.     fDataHandle = NULL;
  2172.     fRsrcID = kNoResource;
  2173.  
  2174.     fDefChoice = mPictureHit;
  2175. }
  2176.  
  2177. //--------------------------------------------------------------------------------------------------
  2178. #pragma segment DlgOpen
  2179.  
  2180. pascal void TPicture::IPicture(TView* itsSuperView,
  2181.                                const VPoint& itsLocation,
  2182.                                const VPoint& itsSize,
  2183.                                SizeDeterminer itsHSizeDet,
  2184.                                SizeDeterminer itsVSizeDet,
  2185.                                short itsRsrcID)
  2186. {
  2187.     FailInfo fi;
  2188.  
  2189.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  2190.     fRsrcID = itsRsrcID;
  2191.     if (fRsrcID != kNoResource)
  2192.     {
  2193.         if (fi.Try())
  2194.         {
  2195.             fDataHandle = GetPicture(fRsrcID);
  2196.             FailNILResource((Handle)fDataHandle);        // was FailResError();
  2197.             fi.Success();
  2198.         }
  2199.         else    // Recover
  2200.         {
  2201.             this->Free();
  2202.             fi.ReSignal();
  2203.         }
  2204.     }
  2205.     this->SetEnable(False);                        // Default is to not enable hit testing 
  2206. }
  2207.  
  2208. //--------------------------------------------------------------------------------------------------
  2209. #pragma segment DlgOpen
  2210.  
  2211. pascal void TPicture::IRes(TDocument* ,
  2212.                            TView* itsSuperView,
  2213.                            Ptr& itsParams)        // override 
  2214. {
  2215.     FailInfo fi;
  2216.  
  2217.     fDataHandle = NULL;
  2218.     inherited::IRes(NULL, itsSuperView, itsParams);
  2219.  
  2220.     fRsrcID = ((PictureTemplatePtr)itsParams)->rsrcID;
  2221.     if (fRsrcID != kNoResource)
  2222.     {
  2223.         if (fi.Try())
  2224.         {
  2225.             fDataHandle = GetPicture(fRsrcID);
  2226.             FailNILResource((Handle)fDataHandle);        // was FailResError();
  2227.             fi.Success();
  2228.         }
  2229.         else    // Recover
  2230.         {
  2231.             this->Free();
  2232.             fi.ReSignal();
  2233.         }
  2234.     }
  2235.  
  2236.     OffsetPtr(itsParams, sizeof(PictureTemplate));
  2237. }
  2238.  
  2239. //--------------------------------------------------------------------------------------------------
  2240. #pragma segment DlgRes
  2241.  
  2242. pascal TObject* TPicture::Clone(void)            // override 
  2243. {
  2244.     TPicture * aClonedPicture;
  2245.     FailInfo fi;
  2246.  
  2247.     VOLATILE(aClonedPicture);
  2248.  
  2249.     aClonedPicture = (TPicture *)(inherited::Clone());
  2250.  
  2251.     if (fDataHandle)
  2252.     {
  2253.         aClonedPicture->fDataHandle = NULL;
  2254.         if (fi.Try())
  2255.         {
  2256.             aClonedPicture->fDataHandle = GetPicture(fRsrcID);
  2257.             FailResError();
  2258.             fi.Success();
  2259.         }
  2260.         else    // Recover
  2261.         {
  2262.             aClonedPicture->Free();
  2263.             fi.ReSignal();
  2264.         }
  2265.     }
  2266.  
  2267.     return aClonedPicture;
  2268. }
  2269.  
  2270. //--------------------------------------------------------------------------------------------------
  2271. #pragma segment MAWriteRes
  2272.  
  2273. pascal void TPicture::WRes(ViewRsrcHandle theResource,
  2274.                            Ptr& itsParams)        // override 
  2275. {
  2276.     inherited::WRes(theResource, itsParams);
  2277.  
  2278.     PictureTemplate& templateData = *((PictureTemplate *) ExpandPtr((Handle)theResource, itsParams, sizeof(PictureTemplate)));
  2279.  
  2280. #if qDebugMsg
  2281.     if (fRsrcID == kNoResource)
  2282.         fprintf(stderr, "Tried to write TPicture with no resource ID.\n");
  2283. #endif
  2284.  
  2285.     templateData.rsrcID = fRsrcID;
  2286. }
  2287.  
  2288. //--------------------------------------------------------------------------------------------------
  2289. #pragma segment MAWriteRes
  2290.  
  2291. pascal void TPicture::WriteRes(ViewRsrcHandle theResource,
  2292.                                Ptr& itsParams)    // override 
  2293. {
  2294.     gWResSignature = 'pict';
  2295.     gWResType = "TPicture";
  2296.     this->WRes(theResource, itsParams);
  2297. }
  2298.  
  2299. //--------------------------------------------------------------------------------------------------
  2300. #pragma segment DlgClose
  2301.  
  2302. pascal void TPicture::Free(void)                // override 
  2303. {
  2304.     this->ReleasePicture();
  2305.  
  2306.     inherited::Free();
  2307. }
  2308.  
  2309. //--------------------------------------------------------------------------------------------------
  2310. #pragma segment DlgRes
  2311.  
  2312. pascal void TPicture::Draw(const VRect& area)    // override 
  2313. {
  2314.     SignedByte oldState;
  2315.     VRect theRect;
  2316.     Rect theQDRect;
  2317.  
  2318.  
  2319.     if (fDataHandle)
  2320.     {
  2321.         if (IsAResource((Handle)fDataHandle))
  2322.             LoadResource((Handle)fDataHandle);
  2323.         if (*fDataHandle)                // If there's room for the picture… 
  2324.         {
  2325.             this->ControlArea(theRect);
  2326.             this->ViewToQDRect(theRect, theQDRect);
  2327.             oldState = HGetState((Handle)fDataHandle);
  2328.             HNoPurge((Handle)fDataHandle);
  2329.             PenNormal();                        // ??? NECESSARY ??? 
  2330.             DrawPicture(fDataHandle, theQDRect);
  2331.             HSetState((Handle)fDataHandle, oldState);
  2332.         }
  2333.     }
  2334.     inherited::Draw(area);
  2335. }
  2336.  
  2337. //--------------------------------------------------------------------------------------------------
  2338. #pragma segment DlgNonRes
  2339.  
  2340. pascal void TPicture::ReleasePicture(void)
  2341. {
  2342.     fRsrcID = kNoResource;
  2343.     if (fDataHandle)
  2344.     {
  2345.         HPurge((Handle)fDataHandle);
  2346.         fDataHandle = NULL;
  2347.     }
  2348. }
  2349.  
  2350. //--------------------------------------------------------------------------------------------------
  2351. #pragma segment DlgNonRes
  2352.  
  2353. pascal void TPicture::SetPicture(PicHandle thePicture,
  2354.                                  Boolean redraw)
  2355. {
  2356.     short theID;
  2357.     ResType theType;
  2358.     Str255 name;
  2359.  
  2360.     this->ReleasePicture();
  2361.     fDataHandle = thePicture;
  2362.  
  2363.     // get the rsrc id 
  2364.     GetResInfo((Handle)thePicture, theID, theType, name);
  2365.     if (ResError() == noErr)
  2366.         fRsrcID = theID;
  2367.  
  2368.     if (redraw)
  2369.         this->ForceRedraw();
  2370. }
  2371.  
  2372. //--------------------------------------------------------------------------------------------------
  2373. #pragma segment DlgFields
  2374.  
  2375. pascal void TPicture::Fields(TObject* obj)        // override 
  2376. {
  2377.     obj->DoToField("TPicture", NULL, bClass);
  2378.     obj->DoToField("fRsrcID", &fRsrcID, bInteger);
  2379.     obj->DoToField("fDataHandle", &fDataHandle, bHandle);
  2380.  
  2381.     inherited::Fields(obj);
  2382. }
  2383.  
  2384. //--------------------------------------------------------------------------------------------------
  2385. #pragma segment TEOpen
  2386.  
  2387. pascal void TDialogTEView::Initialize(void)        // override 
  2388. {
  2389.     inherited::Initialize();
  2390.  
  2391.     fEditText = NULL;                            /* We don't own this reference but we don't
  2392.                                                   want an invalid one either */
  2393.     fScroller = NULL;
  2394. }
  2395.  
  2396. //--------------------------------------------------------------------------------------------------
  2397. #pragma segment TEOpen
  2398.  
  2399. pascal void TDialogTEView::IDialogTEView(TDocument* itsDocument,
  2400.                                          TView* itsSuperView,
  2401.                                          const VPoint& itsLocation,
  2402.                                          const VPoint& itsSize,
  2403.                                          SizeDeterminer itsHDeterminer,
  2404.                                          SizeDeterminer itsVDeterminer,
  2405.                                          const VRect& itsInset,
  2406.                                          const TextStyle& itsTextStyle,
  2407.                                          short itsJustification,
  2408.                                          Boolean itsStyleType,
  2409.                                          Boolean itsAutoWrap)
  2410.  
  2411. {
  2412.     FailInfo fi;
  2413.     TScroller * aScroller;
  2414.     VOLATILE(aScroller);
  2415.  
  2416.     this->ITEView(itsDocument, itsSuperView, itsLocation, itsSize, itsHDeterminer, itsVDeterminer, itsInset, itsTextStyle, itsJustification, itsStyleType, itsAutoWrap);
  2417.     
  2418.     if (fi.Try())
  2419.     {
  2420.         aScroller = new TScroller;
  2421.         aScroller->IScroller(NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeRelSuperView, gZeroVPt, !kWantHScrollBar, !kWantVScrollBar);
  2422.         aScroller->AddSubView(this);
  2423.     }
  2424.     else    // Recover
  2425.     {
  2426.         aScroller = (TScroller *)FreeIfObject(aScroller);
  2427.         this->Free();
  2428.         fi.ReSignal();
  2429.     }
  2430.     fScroller = aScroller;
  2431. }
  2432.  
  2433. //--------------------------------------------------------------------------------------------------
  2434. #pragma segment TEOpen
  2435.  
  2436. pascal void TDialogTEView::IRes(TDocument* itsDocument,
  2437.                                 TView* itsSuperView,
  2438.                                 Ptr& itsParams)    // override 
  2439.  
  2440. {
  2441.     FailInfo fi;
  2442.     TScroller * aScroller;
  2443.     VOLATILE(aScroller);
  2444.  
  2445.     inherited::IRes(itsDocument, itsSuperView, itsParams);
  2446.  
  2447.     if (fi.Try())
  2448.     {
  2449.         aScroller = new TScroller;
  2450.         aScroller->IScroller(NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeRelSuperView, gZeroVPt, !kWantHScrollBar, !kWantVScrollBar);
  2451.         aScroller->AddSubView(this);
  2452.     }
  2453.     else    // Recover
  2454.     {
  2455.         aScroller = (TScroller *)FreeIfObject(aScroller);
  2456.         this->Free();
  2457.         fi.ReSignal();
  2458.     }
  2459.     fScroller = aScroller;
  2460. }
  2461.  
  2462. //--------------------------------------------------------------------------------------------------
  2463. #pragma segment DlgRes
  2464.  
  2465. pascal TObject* TDialogTEView::Clone(void)        // override 
  2466. {
  2467.     TDialogTEView * aClonedDialogTEView;
  2468.  
  2469.     aClonedDialogTEView = (TDialogTEView *)(inherited::Clone());
  2470.  
  2471.     aClonedDialogTEView->fEditText = NULL;        // no current edittext 
  2472.  
  2473.     if (aClonedDialogTEView->fScroller)
  2474.         aClonedDialogTEView->fScroller = (TScroller *)(aClonedDialogTEView->fScroller->Clone());
  2475.  
  2476.     return aClonedDialogTEView;
  2477. }
  2478.  
  2479. //--------------------------------------------------------------------------------------------------
  2480. #pragma segment TEClose
  2481.  
  2482. pascal void TDialogTEView::Free(void)            // override 
  2483. {
  2484.     if (fScroller)
  2485.     {
  2486.         fScroller->RemoveSubView(this);
  2487.         fScroller = (TScroller *)FreeIfObject(fScroller);
  2488.     }
  2489.  
  2490.     inherited::Free();
  2491. }
  2492.  
  2493. //--------------------------------------------------------------------------------------------------
  2494. #pragma segment DlgFields
  2495.  
  2496. pascal void TDialogTEView::Fields(TObject* obj)    // override 
  2497. {
  2498.     obj->DoToField("TDialogTEView", NULL, bClass);
  2499.     obj->DoToField("fEditText", &fEditText, bObject);
  2500.     obj->DoToField("fScroller", &fScroller, bObject);
  2501.  
  2502.     inherited::Fields(obj);
  2503. }
  2504.  
  2505. //--------------------------------------------------------------------------------------------------
  2506. #pragma segment DlgRes
  2507.  
  2508. pascal void TDialogTEView::BecameWindowTarget(void)    // override 
  2509. {
  2510.     inherited::BecameWindowTarget();
  2511. }
  2512.  
  2513. //--------------------------------------------------------------------------------------------------
  2514. #pragma segment DlgRes
  2515.  
  2516. pascal void TDialogTEView::BecameApplicationTarget(void)    // override 
  2517. {
  2518.     inherited::BecameApplicationTarget();
  2519. }
  2520.  
  2521. //--------------------------------------------------------------------------------------------------
  2522. #pragma segment DlgNonRes
  2523.  
  2524. pascal void TDialogTEView::InstallEditText(TEditText* theEditText,
  2525.                                            Boolean selectChars)
  2526.  
  2527. {
  2528.     Str255 theText;
  2529.     TextStyle aTextStyle;
  2530.     VRect theControlArea;
  2531.     VRect validExtent;
  2532.     Boolean hadPendingUpdate;
  2533.  
  2534.     if (fEditText)
  2535.     {
  2536.         fEditText->RemoveSubView(fScroller);
  2537.         fEditText = NULL;
  2538.     }
  2539.  
  2540.     if (theEditText)
  2541.     {
  2542.         fControlChars = theEditText->fControlChars;
  2543.         fMaxChars = theEditText->fMaxChars;
  2544.         fInset = gZeroVRect;
  2545.         hadPendingUpdate = theEditText->HasPendingUpdate();
  2546.  
  2547.         this->SetJustification(theEditText->fJust, kDontRedraw);
  2548.         this->ChangeWrap(theEditText->fAutoWrap, kDontRedraw);
  2549.  
  2550.         aTextStyle = theEditText->fTextStyle;
  2551.         this->SetOneStyle(0, 0, doAll, aTextStyle, kDontRedraw);
  2552.  
  2553.         theEditText->ControlArea(theControlArea);
  2554.  
  2555.         theEditText->AddSubView(fScroller);        // my scroller 
  2556.  
  2557.         if (fAutoWrap)
  2558.             fSizeDeterminer[hSel] = sizeSuperView;
  2559.         else
  2560.             fSizeDeterminer[hSel] = sizeVariable;/* Let the width vary with the number of
  2561.                                                   characters */
  2562.  
  2563.         fSuperView->Resize(VPoint(theControlArea.Length(vSel),theControlArea.Length(hSel)), kDontInvalidate);
  2564.         fSuperView->Locate(theControlArea[topLeft], kDontInvalidate);
  2565.  
  2566.         theEditText->GetText(theText);
  2567.         this->SetText(theText);
  2568.         this->RecalcText();
  2569.         this->SynchView(kDontRedraw);
  2570.         this->AdjustSize();
  2571.  
  2572.         // Make the scroller's thinking match the display that the user already sees 
  2573.         fScroller->fTranslation.h = 0;
  2574.         switch (GetActualJustification(fJustification))
  2575.         {
  2576.             case teFlushDefault:
  2577.             case teFlushLeft:
  2578.                 fScroller->fTranslation.v = 0;
  2579.                 break;
  2580.             case teFlushRight:                    /* Right brain thinkers… left brain thinkers?? */
  2581.                 ((TScroller *)fSuperView)->fTranslation.h = fScroller->fMaxTranslation.h;
  2582.                 break;
  2583.             case teCenter:
  2584.                 fScroller->fTranslation.h = fScroller->fMaxTranslation.h / 2;
  2585.                 break;
  2586.         }
  2587.         theEditText->InvalidateFocus();
  2588.         theEditText->UpdateCoordinates();
  2589.  
  2590.         if (selectChars)
  2591.             SetSelect(0, MAXINT, fHTE);
  2592.         else
  2593.             SetSelect(0, 0, fHTE);                // Caller will set the selection. 
  2594.  
  2595.         this->BeInScroller(fScroller);
  2596.  
  2597.         // Make my enable and my scroller's enable match my new superview 
  2598.         this->SetEnable(theEditText->IsEnabled());
  2599.         fScroller->SetEnable(theEditText->IsEnabled());
  2600.  
  2601.         // Revalidate my extent to eliminate the flicker created by resizing the scrollers 
  2602.         //!!! RCR && SRF Revisit this
  2603. #if FALSE
  2604.         if (!hadPendingUpdate)
  2605.         {
  2606.             this->GetExtent(validExtent);
  2607.             this->ValidateVRect(validExtent);
  2608.         }
  2609. #endif
  2610.  
  2611.     }
  2612.  
  2613.     fEditText = theEditText;
  2614. }
  2615.  
  2616. //--------------------------------------------------------------------------------------------------
  2617. #pragma segment DlgRes
  2618.  
  2619. pascal void TDialogTEView::ResignedWindowTarget(void)    // override 
  2620. {
  2621.     inherited::ResignedWindowTarget();
  2622.  
  2623.     /* If we're deselecting a field and it's been scrolled, invalidate it
  2624.       so that it is redrawn correctly.*/
  2625.     if (fScroller->fTranslation.v != 0)
  2626.         this->ForceRedraw();
  2627.     else
  2628.     {
  2629.         switch (GetActualJustification(fJustification))
  2630.         {
  2631.             case teFlushDefault:
  2632.             case teFlushLeft:
  2633.                 if (fScroller->fTranslation.h != 0)
  2634.                     this->ForceRedraw();
  2635.                 break;
  2636.             case teFlushRight:
  2637.                 if (fScroller->fTranslation.h != fScroller->fMaxTranslation.h)
  2638.                     this->ForceRedraw();
  2639.                 break;
  2640.             case teCenter:
  2641.                 if (fScroller->fTranslation.h != (fScroller->fMaxTranslation.h / 2))
  2642.                     this->ForceRedraw();
  2643.                 break;
  2644.         }
  2645.     }
  2646.  
  2647.     if (fEditText)
  2648.         fEditText->StopEdit();
  2649.  
  2650. }
  2651.  
  2652. //--------------------------------------------------------------------------------------------------
  2653. #pragma segment DlgRes
  2654.  
  2655. pascal void TDialogTEView::ResignedApplicationTarget(void)    // override 
  2656. {
  2657.     inherited::ResignedApplicationTarget();
  2658. }
  2659.  
  2660. //--------------------------------------------------------------------------------------------------
  2661. #pragma segment DlgRes
  2662.  
  2663. pascal void TDialogTEView::TargetValidationFailed(long reason)// override 
  2664. {
  2665.     if (fEditText)
  2666.         fEditText->TargetValidationFailed(reason);
  2667. }
  2668.  
  2669. //--------------------------------------------------------------------------------------------------
  2670. #pragma segment DlgRes
  2671.  
  2672. pascal long TDialogTEView::WillingToResignTarget(void)// override 
  2673. {
  2674.     TCommand * lastCommand;
  2675.     long result;
  2676.  
  2677.     result = 0;
  2678.  
  2679.     if (fEditText)
  2680.     {
  2681.         lastCommand = this->GetLastCommand();
  2682.         if ((lastCommand) && (lastCommand->fView == this))
  2683.             this->CommitLastCommand();
  2684.  
  2685.         result = fEditText->Validate();
  2686.     }
  2687.     return result;
  2688. }
  2689.  
  2690. //--------------------------------------------------------------------------------------------------
  2691. #pragma segment DlgNonRes
  2692.  
  2693. pascal void TDialogTEView::ComputeSize(VPoint& newSize)// override 
  2694. {
  2695.     inherited::ComputeSize(newSize);
  2696.  
  2697.     if (!fAutoWrap)
  2698.         switch (fSizeDeterminer[hSel])
  2699.         {
  2700.             case sizeVariable:
  2701.                 /* TTEView already computed the variable size, bump it up to at leat the scroller's
  2702.                   size so that the cursor is claimed for the EditText and the user can click anywhere. */
  2703.                 if (!fStyleType)
  2704.                     newSize.h = Max(fScroller->fSize.h, newSize.h);
  2705.                 break;
  2706.         }
  2707. }
  2708.  
  2709. //--------------------------------------------------------------------------------------------------
  2710. #pragma segment DlgOpen
  2711.  
  2712. pascal void TStaticText::Initialize(void)        // override 
  2713. {
  2714.     inherited::Initialize();
  2715.  
  2716.     fDataHandle = NULL;
  2717.     fRsrcID = kNoResource;
  2718.     fIndex = 0;
  2719.     fJust = teFlushDefault;                        // Default to system justification 
  2720.     fAutoWrap = TRUE;                            // Default to compatibility with 2.0 
  2721.  
  2722.     fDefChoice = mStaticTextHit;
  2723. }
  2724.  
  2725. //--------------------------------------------------------------------------------------------------
  2726. #pragma segment DlgOpen
  2727.  
  2728. pascal void TStaticText::IStaticText(TView* itsSuperView,
  2729.                                      const VPoint& itsLocation,
  2730.                                      const VPoint& itsSize,
  2731.                                      SizeDeterminer itsHSizeDet,
  2732.                                      SizeDeterminer itsVSizeDet,
  2733.                                      short itsRsrcID,
  2734.                                      short itsIndex)
  2735. {
  2736.     Str255 aString;
  2737.     FailInfo fi;
  2738.  
  2739.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  2740.     fRsrcID = itsRsrcID;
  2741.     fIndex = itsIndex;
  2742.  
  2743.     //fJust = teFlushDefault;
  2744.     //fAutoWrap = TRUE;
  2745.  
  2746.     if (fRsrcID != kNoResource)
  2747.     {
  2748.         if (fi.Try())
  2749.         {
  2750.             GetIndString(aString, fRsrcID, fIndex);
  2751.             FailResError();
  2752.             fi.Success();
  2753.         }
  2754.         else    // Recover
  2755.         {
  2756.             this->Free();
  2757.             fi.ReSignal();
  2758.         }
  2759.         this->SetText(aString, kDontRedraw);
  2760.     }
  2761.     this->SetEnable(False);                        // Default is to not enable hit testing 
  2762. }
  2763.  
  2764. //--------------------------------------------------------------------------------------------------
  2765. #pragma segment DlgOpen
  2766.  
  2767. pascal void TStaticText::IRes(TDocument* ,
  2768.                               TView* itsSuperView,
  2769.                               Ptr& itsParams)    // override 
  2770. {
  2771.     inherited::IRes(NULL, itsSuperView, itsParams);
  2772.  
  2773.     //fAutoWrap = TRUE;
  2774.     //fDefChoice = mStaticTextHit;
  2775.  
  2776.     StaticTextTemplate& templateData = *((StaticTextTemplate *) itsParams);
  2777.  
  2778.     fJust = templateData.just;
  2779.     this->SetText(templateData.data, kDontRedraw);
  2780.  
  2781.     OffsetPtrWStr(itsParams, sizeof(StaticTextTemplate));
  2782. }
  2783.  
  2784. //--------------------------------------------------------------------------------------------------
  2785. #pragma segment DlgRes
  2786.  
  2787. pascal TObject* TStaticText::Clone(void)        // override 
  2788. {
  2789.     TStaticText * aClonedStaticText;
  2790.     StringHandle newString;
  2791.  
  2792.     aClonedStaticText = (TStaticText *)(inherited::Clone());
  2793.  
  2794.     newString = aClonedStaticText->fDataHandle;
  2795.     if (newString)
  2796.         FailOSErr(HandToHand((Handle&)newString));
  2797.     aClonedStaticText->fDataHandle = newString;
  2798.  
  2799.     return aClonedStaticText;
  2800. }
  2801.  
  2802. //--------------------------------------------------------------------------------------------------
  2803. #pragma segment MAWriteRes
  2804.  
  2805. pascal void TStaticText::WRes(ViewRsrcHandle theResource,
  2806.                               Ptr& itsParams)    // override 
  2807. {
  2808.     Str255 theText;
  2809.  
  2810.     inherited::WRes(theResource, itsParams);
  2811.  
  2812.     this->GetText(theText);
  2813.  
  2814.     StaticTextTemplate& templateData = *((StaticTextTemplate *) ExpandPtrWStr((Handle)theResource, itsParams, sizeof(StaticTextTemplate), theText.Length()));
  2815.  
  2816.     templateData.just = fJust;
  2817.     // templateData.data = theText; 
  2818.     CopyStr255(theText, PRStr(templateData.data));
  2819. }
  2820.  
  2821. //--------------------------------------------------------------------------------------------------
  2822. #pragma segment MAWriteRes
  2823.  
  2824. pascal void TStaticText::WriteRes(ViewRsrcHandle theResource,
  2825.                                   Ptr& itsParams)// override 
  2826. {
  2827.     gWResSignature = 'stat';
  2828.     gWResType = "TStaticText";
  2829.     this->WRes(theResource, itsParams);
  2830. }
  2831.  
  2832. //--------------------------------------------------------------------------------------------------
  2833. #pragma segment DlgClose
  2834.  
  2835. pascal void TStaticText::Free(void)                // override 
  2836. {
  2837.     this->ReleaseText();
  2838.  
  2839.     inherited::Free();
  2840. }
  2841.  
  2842. //--------------------------------------------------------------------------------------------------
  2843. #pragma segment DlgRes
  2844.  
  2845. pascal void TStaticText::ChangeWrap(Boolean newAutoWrap,
  2846.                                     Boolean redraw)
  2847. {
  2848.     fAutoWrap = newAutoWrap;
  2849.     if (redraw)
  2850.         this->ForceRedraw();
  2851. }
  2852.  
  2853. //--------------------------------------------------------------------------------------------------
  2854. #pragma segment DlgRes
  2855.  
  2856. pascal void TStaticText::DoSubstitution(Str255& theText)
  2857.  
  2858. {
  2859.     MAReplaceText(theText);
  2860. }
  2861.  
  2862. //--------------------------------------------------------------------------------------------------
  2863. #pragma segment DlgRes
  2864.  
  2865. pascal void TStaticText::Draw(const VRect& area)// override 
  2866. {
  2867.     VRect theRect;
  2868.     RGBColor oldColor;
  2869.     Str255 theText;
  2870.     TextStyle aTextStyle;
  2871.  
  2872.     if (fDataHandle)
  2873.     {
  2874.         this->GetText(theText);
  2875.         this->DoSubstitution(theText);            // Make the substitution if desired 
  2876.         this->ControlArea(theRect);
  2877.         PenNormal();                            // ??? NECESSARY ??? 
  2878.         GetIfColor(oldColor);
  2879.         aTextStyle = fTextStyle;
  2880.         SetPortTextStyle(aTextStyle);
  2881.         this->ImageText((Ptr)(((long) & theText) + 1), theText.Length(), theRect, fJust);
  2882.         SetIfColor(oldColor);
  2883.     }
  2884.     inherited::Draw(area);
  2885. }
  2886.  
  2887. //--------------------------------------------------------------------------------------------------
  2888. #pragma segment DlgRes
  2889.  
  2890. pascal void TStaticText::GetText(Str255& theText)
  2891. {
  2892.     if (fDataHandle)
  2893.         CopyStr255((**((String255Handle)fDataHandle)), (Ptr)&theText);
  2894.     else
  2895.         theText = "";
  2896. }
  2897.  
  2898. //--------------------------------------------------------------------------------------------------
  2899. #pragma segment DlgRes
  2900.  
  2901. pascal void TStaticText::ImageText(Ptr text,
  2902.                                    long Length,
  2903.                                    const VRect& box,
  2904.                                    short just)
  2905. {
  2906.     Rect qdBox;
  2907.  
  2908.     this->ViewToQDRect(box, qdBox);
  2909.     MATextBox(text, Length, qdBox, just, fAutoWrap, NULL, kNoEraseFirst, kSpaceForCaret);
  2910. }
  2911.  
  2912. //--------------------------------------------------------------------------------------------------
  2913. #pragma segment DlgNonRes
  2914.  
  2915. pascal void TStaticText::ReleaseText(void)
  2916. {
  2917.     fDataHandle = (StringHandle)DisposeIfHandle((Handle)fDataHandle);
  2918.  
  2919.     fRsrcID = kNoResource;
  2920. }
  2921.  
  2922. //--------------------------------------------------------------------------------------------------
  2923. #pragma segment DlgNonRes
  2924.  
  2925. pascal void TStaticText::SetJustification(short theJust,
  2926.                                           Boolean redraw)
  2927. {
  2928.     fJust = theJust;
  2929.     if (redraw)
  2930.         this->ForceRedraw();
  2931. }
  2932.  
  2933. //--------------------------------------------------------------------------------------------------
  2934. #pragma segment DlgNonRes
  2935.  
  2936. pascal void TStaticText::SetText(const Str255& theText,
  2937.                                  Boolean redraw)
  2938. {
  2939.     VRect area;
  2940.     Rect qdArea;
  2941.  
  2942.  
  2943.     if ((fDataHandle == NULL) || (theText != (**((String255Handle)fDataHandle))))
  2944.     {
  2945.         this->ReleaseText();
  2946.         fDataHandle = NewString(theText);
  2947.         if (MemError() != noErr)
  2948.             fDataHandle = NULL;
  2949.         if (redraw && this->IsDrawable())
  2950.         {
  2951.             this->ControlArea(area);
  2952.             this->ViewToQDRect(area, qdArea);
  2953.             EraseRect(qdArea);
  2954.             this->Draw(area);
  2955.         }
  2956.     }
  2957. }
  2958.  
  2959. //--------------------------------------------------------------------------------------------------
  2960. #pragma segment DlgFields
  2961.  
  2962. pascal void TStaticText::Fields(TObject* obj)    // override 
  2963. {
  2964.     Str255 aString;
  2965.  
  2966.     obj->DoToField("TStaticText", NULL, bClass);
  2967.     obj->DoToField("fRsrcID", &fRsrcID, bInteger);
  2968.     obj->DoToField("fIndex", &fIndex, bInteger);
  2969.     obj->DoToField("fDataHandle", &fDataHandle, bHandle);
  2970.     if (fDataHandle)
  2971.     {
  2972.         aString = (**((String255Handle)fDataHandle));
  2973.         obj->DoToField("(**fDataHandle)", &aString, bString);
  2974.     }
  2975.     obj->DoToField("fJust", &fJust, bInteger);
  2976.     obj->DoToField("fAutoWrap", &fAutoWrap, bBoolean);
  2977.  
  2978.     inherited::Fields(obj);
  2979. }
  2980.  
  2981. //--------------------------------------------------------------------------------------------------
  2982. #pragma segment DlgOpen
  2983.  
  2984. pascal void TEditText::Initialize(void)            // override 
  2985. {
  2986.     inherited::Initialize();
  2987.  
  2988.     fTEView = NULL;
  2989.     fMaxChars = 255;                            // Is there a constant? 
  2990.  
  2991.     fControlChars = ASSETELEM(chLeft) | ASSETELEM(chRight) | ASSETELEM(chUp) | ASSETELEM(chDown) | ASSETELEM(chBackspace);
  2992.     fTextStyle = gSystemStyle;
  2993.     fPenSize = Point(1,1);                        // …and a thin frame 
  2994.     this->SetAdornment(kFrame, kDontRedraw);
  2995.     fAutoWrap = False;                            /* Default to compatibility with 2.0 Never
  2996.                                                   the twain shall meet.*/
  2997.     fDefChoice = mEditTextHit;
  2998. }
  2999.  
  3000. //--------------------------------------------------------------------------------------------------
  3001. #pragma segment DlgOpen
  3002.  
  3003. pascal void TEditText::IEditText(TView* itsSuperView,
  3004.                                  const VPoint& itsLocation,
  3005.                                  const VPoint& itsSize,
  3006.                                  short itsMaxChars)
  3007. {
  3008.     this->IStaticText(itsSuperView, itsLocation, itsSize, sizeFixed, sizeFixed, kNoResource, 0);
  3009.  
  3010.     fAutoWrap = False;                            /* Default to compatibility with 2.0 Never
  3011.                                                   the twain shall meet.*/
  3012.     fMaxChars = itsMaxChars;
  3013.     fTextStyle = gSystemStyle;
  3014.     this->Inset(3, 3, kDontRedraw);                // Default is a little, teeny inset… 
  3015.     fPenSize = Point(1,1);                        // …and a thin frame 
  3016.     this->SetAdornment(kFrame, kDontRedraw);
  3017.     this->SetEnable(TRUE);
  3018.     fDefChoice = mEditTextHit;
  3019. }
  3020.  
  3021. //--------------------------------------------------------------------------------------------------
  3022. #pragma segment DlgOpen
  3023.  
  3024. pascal void TEditText::IRes(TDocument* ,
  3025.                             TView* itsSuperView,
  3026.                             Ptr& itsParams)        // override 
  3027. {
  3028.     inherited::IRes(NULL, itsSuperView, itsParams);
  3029.  
  3030.     fAutoWrap = False;                            /* Default to compatibility with 2.0 Never
  3031.                                                   the twain shall meet.*/
  3032.     EditTextTemplate& templateData = *((EditTextTemplate *) itsParams);
  3033.  
  3034.     fMaxChars = templateData.maxChars;
  3035.     fControlChars = templateData.controlChars;
  3036.  
  3037.     fDefChoice = mEditTextHit;
  3038.  
  3039.     OffsetPtr(itsParams, sizeof(EditTextTemplate));
  3040. }
  3041.  
  3042. //--------------------------------------------------------------------------------------------------
  3043. #pragma segment DlgRes
  3044.  
  3045. pascal TObject* TEditText::Clone(void)            // override 
  3046. {
  3047.     TEditText * aClonedEditText;
  3048.  
  3049.     aClonedEditText = (TEditText *)(inherited::Clone());
  3050.  
  3051.     aClonedEditText->fTEView = NULL;
  3052.  
  3053.     return aClonedEditText;
  3054. }
  3055.  
  3056. //--------------------------------------------------------------------------------------------------
  3057. #pragma segment DlgClose
  3058.  
  3059. pascal void TEditText::Free(void)                // override 
  3060.  
  3061. {
  3062.     this->RemoveFloatingTEView();
  3063.     inherited::Free();
  3064. }
  3065.  
  3066. //--------------------------------------------------------------------------------------------------
  3067. #pragma segment MAWriteRes
  3068.  
  3069. pascal void TEditText::WRes(ViewRsrcHandle theResource,
  3070.                             Ptr& itsParams)        // override 
  3071. {
  3072.     inherited::WRes(theResource, itsParams);
  3073.  
  3074.     EditTextTemplate& templateData = *((EditTextTemplate *) ExpandPtr((Handle)theResource, itsParams, sizeof(EditTextTemplate)));
  3075.  
  3076.     templateData.maxChars = fMaxChars;
  3077.     templateData.controlChars = fControlChars;
  3078. }
  3079.  
  3080. //--------------------------------------------------------------------------------------------------
  3081. #pragma segment MAWriteRes
  3082.  
  3083. pascal void TEditText::WriteRes(ViewRsrcHandle theResource,
  3084.                                 Ptr& itsParams)    // override 
  3085. {
  3086.     gWResSignature = 'edit';
  3087.     gWResType = "TEditText";
  3088.     this->WRes(theResource, itsParams);
  3089. }
  3090.  
  3091. //--------------------------------------------------------------------------------------------------
  3092. #pragma segment DlgRes
  3093.  
  3094. pascal void TEditText::BecameWindowTarget(void)        // override 
  3095. {
  3096.     this->StartEdit(TRUE);
  3097.  
  3098.     inherited::BecameWindowTarget();
  3099. }
  3100.  
  3101. //--------------------------------------------------------------------------------------------------
  3102. #pragma segment DlgRes
  3103.  
  3104. pascal void TEditText::BecameApplicationTarget(void)        // override 
  3105. {
  3106. /*
  3107.     if (fTEView)
  3108.         fTEView->BecomeApplicationTarget();
  3109.     else 
  3110.         this->StartEdit(TRUE);
  3111. */
  3112.     inherited::BecameApplicationTarget();
  3113. }
  3114.  
  3115. //--------------------------------------------------------------------------------------------------
  3116. #pragma segment DlgNonRes
  3117.  
  3118. pascal void TEditText::TargetValidationFailed(long reason)
  3119. {
  3120.     Str255 aString;
  3121.  
  3122.     if (reason != kValidValue)
  3123.     {
  3124.         if (reason != kErrorHandled)            // go ahead and post an alert 
  3125.         {
  3126.             if ((reason < 1) || (reason > kNoOfDefaultReasons))
  3127.                 reason = kInvalidValue;
  3128.  
  3129.             GetIndString(aString, (short)kInvalidValueReasons, (short)reason);//!!! Note casting
  3130.             ParamText(aString, "", "", "");
  3131.             StdAlert(phInvalidValue);
  3132.         }
  3133.         aString = (**((String255Handle)fDataHandle));// Restart with previous value 
  3134.         this->RestartEdit(aString);
  3135.     }
  3136. }
  3137.  
  3138. //--------------------------------------------------------------------------------------------------
  3139. #pragma segment DlgRes
  3140.  
  3141. pascal void TEditText::ChangeWrap(Boolean newAutoWrap,
  3142.                                   Boolean redraw)// override 
  3143. {
  3144.     inherited::ChangeWrap(newAutoWrap, redraw);
  3145.     if (fTEView)
  3146.         fTEView->ChangeWrap(newAutoWrap, redraw);
  3147. }
  3148.  
  3149. //--------------------------------------------------------------------------------------------------
  3150. #pragma segment DlgRes
  3151.  
  3152. pascal Boolean TEditText::Deselect(void)
  3153. {
  3154.     long validateResult;
  3155.     TCommand * lastCommand;
  3156.     Boolean result;
  3157.  
  3158.  
  3159.     result = TRUE;
  3160.  
  3161.     /* Commit the last command to prevent undo from applying to the wrong edit text,
  3162.       and to ensure that all changes are made before validating. */
  3163.     if (fTEView)
  3164.     {
  3165.         lastCommand = fTEView->GetLastCommand();
  3166.         if ((lastCommand) && (lastCommand->fView == fTEView))
  3167.             fTEView->CommitLastCommand();
  3168.     }
  3169.  
  3170.     validateResult = this->Validate();
  3171.     if (validateResult == kValidValue)
  3172.         this->StopEdit();
  3173.     else
  3174.     {
  3175.         this->TargetValidationFailed(validateResult);
  3176.         result = FALSE;
  3177.     }
  3178.     return result;
  3179. }
  3180.  
  3181. //--------------------------------------------------------------------------------------------------
  3182. #pragma segment DlgRes
  3183.  
  3184. pascal void TEditText::DoSubstitution(Str255& theText)// override 
  3185. {
  3186.     // Default action is for editable text items is not to do any substitions 
  3187. }
  3188.  
  3189. //--------------------------------------------------------------------------------------------------
  3190. #pragma segment DlgFields
  3191.  
  3192. pascal void TEditText::Fields(TObject* obj)        // override 
  3193. {
  3194.     obj->DoToField("TEditText", NULL, bClass);
  3195.     obj->DoToField("fMaxChars", &fMaxChars, bInteger);
  3196.     obj->DoToField("fTEView", &fTEView, bObject);
  3197.     obj->DoToField("fControlChars", &fControlChars, bHexLongInt);
  3198.  
  3199.     inherited::Fields(obj);
  3200. }
  3201.  
  3202. //--------------------------------------------------------------------------------------------------
  3203. #pragma segment DlgRes
  3204.  
  3205. pascal void TEditText::GetText(Str255& theText)    // override 
  3206. {
  3207.     Handle theChars;
  3208.     short numberOfChars;
  3209.  
  3210.  
  3211.     if (fTEView == NULL)
  3212.         inherited::GetText(theText);
  3213.     else
  3214.     {
  3215.         theChars = fTEView->ExtractText();
  3216.         numberOfChars = (short)Min(255, GetHandleSize(theChars));//!!! Note cast
  3217.         theText[0] = ((char)(numberOfChars));
  3218.         BlockMove((Ptr)(*theChars), (Ptr)(((long) & theText) + 1), numberOfChars);
  3219.     }
  3220. }
  3221.  
  3222. //--------------------------------------------------------------------------------------------------
  3223. #pragma segment DlgRes
  3224.  
  3225. pascal void TEditText::ImageText(Ptr text,
  3226.                                  long Length,
  3227.                                  const VRect& box,
  3228.                                  short just)    // override 
  3229. {
  3230.     Rect qdBox;
  3231.  
  3232.     if (Length >= 0)
  3233.     {
  3234.         this->ViewToQDRect(box, qdBox);
  3235.         MATextBox(text, Length, qdBox, just, fAutoWrap, NULL, kNoEraseFirst, kSpaceForCaret);
  3236.     }
  3237. }
  3238.  
  3239. //--------------------------------------------------------------------------------------------------
  3240. #pragma segment DlgRes
  3241.  
  3242. pascal void TEditText::InstallFloatingTEView(Boolean selectChars)
  3243. {
  3244.     TDialogTEView * aFloatingTEView;
  3245.  
  3246.     if (fTEView == NULL)
  3247.     {
  3248.         aFloatingTEView = AquireFloatingTEView();
  3249.         if (aFloatingTEView == NULL)
  3250.         {
  3251. #if qDebug
  3252.             ProgramBreak("###the aquired TEView is nil.");
  3253. #endif
  3254.  
  3255.             //!!!            exit(InstallFloatingTEView);
  3256.         }
  3257.         aFloatingTEView->InstallEditText(this, selectChars);
  3258.         fTEView = aFloatingTEView;
  3259.     }
  3260.  
  3261.     // since the floating TE view handles dim/hilite drawing - these adorners are removed 
  3262.     if (fDimmed)
  3263.         this->DeleteAdorner(gDimAdorner, kDontRedraw);
  3264.     if (fHilite)
  3265.         this->DeleteAdorner(gHiliteAdorner, kDontRedraw);
  3266. }
  3267.  
  3268. //--------------------------------------------------------------------------------------------------
  3269. #pragma segment DlgRes
  3270. pascal void TEditText::MakeVisible(void)
  3271. {
  3272.     VRect myExtent;
  3273.     VPoint minToSee;
  3274.  
  3275.     this->GetExtent(myExtent);
  3276.     myExtent.Inset(VPoint(-10, -10));
  3277.     minToSee.h = Min(fSize.h + 10, kMaxCoord);
  3278.     minToSee.v = Min(fSize.v + 10, kMaxCoord);
  3279.  
  3280.     this->RevealRect(myExtent, minToSee, kVisible);
  3281. }
  3282.  
  3283. //--------------------------------------------------------------------------------------------------
  3284. #pragma segment DlgRes
  3285.  
  3286. pascal void TEditText::RemoveFloatingTEView(void)
  3287. {
  3288.     if (fTEView)
  3289.     {
  3290.         fTEView->InstallEditText(NULL, False);
  3291.         /*!!!*/
  3292.         ReleaseFloatingTEView(fTEView);
  3293.         fTEView = NULL;
  3294.     }
  3295.  
  3296.     // since the floating TE view handles dim/hilite drawing - these adorners were removed 
  3297.     if (fDimmed)
  3298.         this->AddAdorner(gDimAdorner, kLowestAdornPriority - 10, kDontRedraw);
  3299.     if (fHilite)
  3300.         this->AddAdorner(gHiliteAdorner, kLowestAdornPriority - 5, kDontRedraw);
  3301. }
  3302.  
  3303. //--------------------------------------------------------------------------------------------------
  3304. #pragma segment DlgNonRes
  3305.  
  3306. pascal void TEditText::RestartEdit(const Str255& restartText)
  3307. {
  3308.     Rect area;
  3309.  
  3310.     if (fTEView->Focus())                        // First, attempt to focus the TEView 
  3311.     {
  3312.         ClipRect(gZeroRect);                    /* Prevent TE from mucking up the hilite with
  3313.                                                   a stinking insertion point */
  3314.  
  3315.         //!!!RCR this->InstallSelection(TRUE, False);    
  3316.         fTEView->SetActive(FALSE);                // Deactivate the selection 
  3317.         this->SetText(restartText, kDontRedraw);// Set the text to previous value 
  3318.         this->SetSelection(0, MAXINT, kDontRedraw);// Select all characters 
  3319.  
  3320.         //!!!RCR this->InstallSelection(False, TRUE);    */        /* Activate the selection 
  3321.         fTEView->SetActive(TRUE);
  3322.  
  3323.         this->InvalidateFocus();                // Make sure we re-focus 
  3324.         fTEView->ForceRedraw();
  3325.     }
  3326.     else
  3327.         this->SetText(restartText, kDontRedraw);// Just set the text if we can't focus 
  3328. }
  3329.  
  3330. //--------------------------------------------------------------------------------------------------
  3331. #pragma segment DlgNonRes
  3332.  
  3333. pascal void TEditText::SetJustification(short theJust,
  3334.                                         Boolean redraw)
  3335. {
  3336.     if (fTEView)
  3337.         fTEView->SetJustification(theJust, redraw);
  3338.     inherited::SetJustification(theJust, redraw);
  3339. }
  3340.  
  3341. //--------------------------------------------------------------------------------------------------
  3342. #pragma segment DlgRes
  3343.  
  3344. pascal void TEditText::SetSelection(short selStart,
  3345.                                     short selEnd,
  3346.                                     Boolean redraw)
  3347. {
  3348.     if (fTEView)
  3349.     {
  3350.         if (redraw && fTEView->IsDrawable())
  3351.             TESetSelect(selStart, selEnd, fTEView->fHTE);
  3352.         else
  3353.             SetSelect(selStart, selEnd, fTEView->fHTE);
  3354.     }
  3355. }
  3356.  
  3357. //--------------------------------------------------------------------------------------------------
  3358. #pragma segment DlgNonRes
  3359.  
  3360. pascal void TEditText::SetText(const Str255& theText,
  3361.                                Boolean redraw)    // override 
  3362. {
  3363.     Str255 currentText;
  3364.     VRect area;
  3365.     Rect qdArea;
  3366.  
  3367.     if (fTEView)
  3368.     {
  3369.         this->GetText(currentText);
  3370.         if (currentText != theText)
  3371.         {
  3372.             fTEView->SetText(theText);
  3373.             fTEView->RecalcText();
  3374.             fTEView->SynchView(kDontRedraw);
  3375.             if (redraw && this->IsDrawable())
  3376.             {
  3377.                 this->ControlArea(area);
  3378.                 this->ViewToQDRect(area, qdArea);
  3379.                 EraseRect(qdArea);
  3380.                 this->DrawContents();
  3381.             }
  3382.         }
  3383.     }
  3384.     else
  3385.         inherited::SetText(theText, redraw);
  3386. }
  3387.  
  3388. //--------------------------------------------------------------------------------------------------
  3389. #pragma segment DlgRes
  3390.  
  3391. pascal void TEditText::ResignedWindowTarget(void)        // override 
  3392. {
  3393.     inherited::ResignedWindowTarget();
  3394. }
  3395.  
  3396. //--------------------------------------------------------------------------------------------------
  3397. #pragma segment DlgRes
  3398.  
  3399. pascal void TEditText::ResignedApplicationTarget(void)        // override 
  3400. {
  3401. /*
  3402.     if (fTEView)
  3403.         fTEView->ResignedApplicationTarget();
  3404. */
  3405.     inherited::ResignedApplicationTarget();
  3406. }
  3407.  
  3408.  
  3409.  
  3410. //--------------------------------------------------------------------------------------------------
  3411. #pragma segment DlgNonRes
  3412.  
  3413. pascal void TEditText::StartEdit(Boolean selectChars)
  3414. {
  3415.     this->InstallFloatingTEView(selectChars);
  3416.     this->SetTarget(fTEView);
  3417.  
  3418.     this->MakeVisible();
  3419. }
  3420.  
  3421. //--------------------------------------------------------------------------------------------------
  3422. #pragma segment DlgNonRes
  3423.  
  3424. pascal void TEditText::StopEdit(void)
  3425. {
  3426.     Str255 aString;
  3427.  
  3428.     if (fTEView)
  3429.     {
  3430.         this->GetText(aString);                    /* Must get the text before removing
  3431.                                                   the floating TEView */
  3432.         // fTEView->InstallSelection(TRUE, FALSE); 
  3433.         this->RemoveFloatingTEView();
  3434.         this->SetText(aString, kDontRedraw);
  3435.     }
  3436. }
  3437.  
  3438. //--------------------------------------------------------------------------------------------------
  3439. #pragma segment DlgRes
  3440.  
  3441. pascal long TEditText::Validate(void)
  3442. {
  3443.     long validateResult;
  3444.  
  3445.     validateResult = inherited::Validate();
  3446.     if ((validateResult == kValidValue) && (fTEView) && (GetHandleSize(fTEView->fText) > fMaxChars))
  3447.         validateResult = kTooManyCharacters;
  3448.     return validateResult;
  3449. }
  3450.  
  3451. //--------------------------------------------------------------------------------------------------
  3452. #pragma segment DlgRes
  3453. pascal Boolean TEditText::WantToBecomeTarget(void)// override 
  3454. {
  3455.     return ((fTEView == NULL) && this->IsEnabled())/* && this.IsActive*/;
  3456. }
  3457.  
  3458. //--------------------------------------------------------------------------------------------------
  3459. #pragma segment DlgRes
  3460.  
  3461. pascal long TEditText::WillingToResignTarget(void)// override 
  3462. {
  3463.     return inherited::WillingToResignTarget();
  3464. }
  3465.  
  3466. //--------------------------------------------------------------------------------------------------
  3467. #pragma segment DlgOpen
  3468.  
  3469. pascal void TNumberText::Initialize(void)        // override 
  3470. {
  3471.     inherited::Initialize();
  3472.  
  3473.     fMaximum = MAXLONGINT;
  3474.     fMinimum = 0;
  3475. }
  3476.  
  3477. //--------------------------------------------------------------------------------------------------
  3478. #pragma segment DlgOpen
  3479.  
  3480. pascal void TNumberText::INumberText(TView* itsSuperView,
  3481.                                      const VPoint& itsLocation,
  3482.                                      const VPoint& itsSize,
  3483.                                      long itsValue,
  3484.                                      long itsMinimum,
  3485.                                      long itsMaximum)
  3486. {
  3487.     this->IEditText(itsSuperView, itsLocation, itsSize, 255);
  3488. #if qDebugMsg
  3489.     if (itsMinimum > itsMaximum)
  3490.         fprintf(stderr, "Minimum value specified is greater than maximum for TNumberText.\n");
  3491. #endif
  3492.  
  3493.     fMinimum = itsMinimum;
  3494.     fMaximum = itsMaximum;
  3495.  
  3496.     this->SetValue(itsValue, kDontRedraw);
  3497. }
  3498.  
  3499. //--------------------------------------------------------------------------------------------------
  3500. #pragma segment DlgOpen
  3501.  
  3502. pascal void TNumberText::IRes(TDocument* ,
  3503.                               TView* itsSuperView,
  3504.                               Ptr& itsParams)    // override 
  3505. {
  3506.     inherited::IRes(NULL, itsSuperView, itsParams);
  3507.  
  3508.     NumberTextTemplate& templateData = *((NumberTextTemplate *) itsParams);
  3509.  
  3510. #if qDebugMsg
  3511.     if (templateData.minimum > templateData.maximum)
  3512.         fprintf(stderr, "Minimum value specified is greater than maximum for TNumberText.\n");
  3513. #endif
  3514.  
  3515.     fMinimum = templateData.minimum;
  3516.     fMaximum = templateData.maximum;
  3517.  
  3518.     this->SetValue(templateData.value, kDontRedraw);
  3519.  
  3520.     OffsetPtr(itsParams, sizeof(NumberTextTemplate));
  3521. }
  3522.  
  3523. //--------------------------------------------------------------------------------------------------
  3524. #pragma segment MAWriteRes
  3525.  
  3526. pascal void TNumberText::WRes(ViewRsrcHandle theResource,
  3527.                               Ptr& itsParams)    // override 
  3528.  
  3529. {
  3530.     inherited::WRes(theResource, itsParams);
  3531.  
  3532.     NumberTextTemplate& templateData = *((NumberTextTemplate *) ExpandPtr((Handle)theResource, itsParams, sizeof(NumberTextTemplate)));
  3533.  
  3534.     templateData.value = this->GetValue();
  3535.     templateData.minimum = fMinimum;
  3536.     templateData.maximum = fMaximum;
  3537. }
  3538.  
  3539. //--------------------------------------------------------------------------------------------------
  3540. #pragma segment MAWriteRes
  3541.  
  3542. pascal void TNumberText::WriteRes(ViewRsrcHandle theResource,
  3543.                                   Ptr& itsParams)// override 
  3544. {
  3545.     gWResSignature = 'nmbr';
  3546.     gWResType = "TNumberText";
  3547.     this->WRes(theResource, itsParams);
  3548. }
  3549.  
  3550. //--------------------------------------------------------------------------------------------------
  3551. #pragma segment DlgRes
  3552.  
  3553. pascal long TNumberText::GetValue(void)
  3554. {
  3555.     Str255 aString;
  3556.     long theValue;
  3557.  
  3558.     this->GetText(aString);
  3559.     StringToNum(aString, theValue);
  3560.     return theValue;
  3561. }
  3562.  
  3563. //--------------------------------------------------------------------------------------------------
  3564. #pragma segment DlgNonRes
  3565.  
  3566. pascal void TNumberText::SetValue(long newValue,
  3567.                                   Boolean redraw)
  3568. {
  3569.     Str255 aString;
  3570.  
  3571.     newValue = Max(fMinimum, Min(fMaximum, newValue));
  3572.     NumToString(newValue, aString);
  3573.     this->SetText(aString, redraw);
  3574. }
  3575.  
  3576. //--------------------------------------------------------------------------------------------------
  3577. #pragma segment DlgNonRes
  3578.  
  3579. pascal long TNumberText::Validate(void)            // override 
  3580. {
  3581.     Str255 theString;
  3582.     decimal decRec;
  3583.     extended extValue;
  3584.     short validPrefix = 0;
  3585.     long result;
  3586.  
  3587.  
  3588.     result = kValidValue;
  3589.  
  3590.     //!!! This really begs for a fRequired field to test when the string is left empty 
  3591.     // Then we would inform the user that an empty string is not a valid option. 
  3592.     // Also a fDefault field is necessary. GetValue would return fDefault rather 
  3593.     // than 0 when the string is empty.    For now (2.0) we will not validate an empty
  3594.     // string and assume that if the user wants a value they will override. 
  3595.  
  3596.     this->GetText(theString);
  3597.     if (!theString.IsEmpty())
  3598.     {
  3599.         short index = 0;
  3600.         short itsLength = theString.Length();
  3601.         p2cstr(&theString);                                // Note: p2cstr!
  3602.         str2dec((const char *) &theString, index, decRec, validPrefix);
  3603.         if (validPrefix && (++index > itsLength) && (decRec.exp >= 0))
  3604.         {
  3605.             extValue = dec2num(decRec);
  3606.             if (extValue < fMinimum)
  3607.                 result = kValueTooSmall;
  3608.             else if (extValue > fMaximum)
  3609.                 result = kValueTooLarge;
  3610.         }
  3611.         else
  3612.             result = kNonNumericCharacters;
  3613.     }
  3614.     return result;
  3615. }
  3616.  
  3617. //--------------------------------------------------------------------------------------------------
  3618. #pragma segment DlgFields
  3619.  
  3620. pascal void TNumberText::Fields(TObject* obj)    // override 
  3621. {
  3622.     obj->DoToField("TNumberText", NULL, bClass);
  3623.     obj->DoToField("fMinimum", &fMinimum, bLongInt);
  3624.     obj->DoToField("fMaximum", &fMaximum, bLongInt);
  3625.  
  3626.     inherited::Fields(obj);
  3627. }
  3628.  
  3629. //--------------------------------------------------------------------------------------------------
  3630. #pragma segment DlgInit
  3631.  
  3632. pascal void TFloatingTEManager::Initialize(void)// override 
  3633. {
  3634.     inherited::Initialize();
  3635.     fCache = NULL;
  3636. }
  3637.  
  3638. //--------------------------------------------------------------------------------------------------
  3639. #pragma segment DlgClose
  3640. pascal void TFloatingTEManager::Free(void)        // override 
  3641. {
  3642.     if (fCache)
  3643.         fCache = (TDialogTEView *)(FreeIfObject(fCache));
  3644.     inherited::Free();
  3645. }
  3646.  
  3647. //--------------------------------------------------------------------------------------------------
  3648. #pragma segment DlgFields
  3649. pascal void TFloatingTEManager::Fields(TObject* obj)// override 
  3650. {
  3651.     obj->DoToField("TFloatingTEManager", NULL, bClass);
  3652.     obj->DoToField("fCache", &fCache, bObject);
  3653.  
  3654.     inherited::Fields(obj);
  3655. }
  3656.  
  3657. //--------------------------------------------------------------------------------------------------
  3658. #pragma segment DlgRes
  3659. pascal TDialogTEView* TFloatingTEManager::AquireFloatingTE(void)
  3660. {
  3661.     TDialogTEView * result;
  3662.  
  3663.     if (fCache)                            // Got one in the cache!  
  3664.     {
  3665.         result = fCache;
  3666.         fCache = NULL;                            // Cache is now empty 
  3667.     }
  3668.     else
  3669.         result = this->MakeDialogTEView();
  3670.     return result;
  3671. }
  3672.  
  3673. //--------------------------------------------------------------------------------------------------
  3674. #pragma segment DlgRes
  3675.  
  3676. pascal TDialogTEView* TFloatingTEManager::MakeDialogTEView(void)
  3677. {
  3678.     TDialogTEView * aDialogTEView = NULL;
  3679.  
  3680.     if (qTemplateViews && (gApplication))
  3681.         aDialogTEView = (TDialogTEView *)(gViewServer->DoCreateViews(NULL, NULL, kDialogTEViewID, gZeroVPt));
  3682.     else
  3683.     {
  3684.         aDialogTEView = new TDialogTEView;
  3685.         aDialogTEView->IDialogTEView(NULL, NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeVariable, gZeroVRect, gSystemStyle, teFlushDefault, kWithoutStyle, False);
  3686.  
  3687.     }
  3688.     aDialogTEView->fMinAhead = 1;                /* Don't _jump_ the view ahead when
  3689.                                                   autoscrolling for scrollselectionintoview
  3690.                                                 */
  3691.     return aDialogTEView;
  3692. }
  3693.  
  3694. //--------------------------------------------------------------------------------------------------
  3695. #pragma segment DlgRes
  3696. pascal void TFloatingTEManager::ReleaseFloatingTE(TDialogTEView* aDialogTEView)
  3697. {
  3698.     if (fCache == NULL)
  3699.         fCache = aDialogTEView;
  3700.     else
  3701.         aDialogTEView->Free();
  3702. }
  3703.  
  3704.  
  3705.