home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / macintosh-pascal / macintoshp-1.2-demos.sit.hqx / chap23pascal_demo / chap06pascal_demoPPC / DialogsAndAlertsPascalPPC.p < prev    next >
Text File  |  1997-01-07  |  33KB  |  1,367 lines

  1. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
  2. // DialogsAndAlertsPascalPPC.p
  3. // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
  4. // 
  5. // This program:
  6. //
  7. // •    Opens a window for the purposes of displaying text and for proving correct window
  8. //        updating and activation/deactivation in the presence of alert and dialog boxes.
  9. //
  10. // •    Allows the user to invoke a demonstration alert, a modal dialog box, a movable
  11. //        modal dialog box and a modeless dialog box via the Demonstration menu.
  12. //
  13. // The modal dialog box contains three checkboxes.
  14. //
  15. // The movable modal dialog box contains three radio buttons.
  16. //
  17. // The modeless dialog box contains an icon and an editable text item.  The editable text
  18. // item is supported by the Edit menu Cut, Copy, Paste and Clear commands.
  19. //
  20. // An application-defined event filter function is used for the alert box and modal
  21. // dialog box.
  22. //
  23. // An application-defined function is used to draw the bold outline around the default
  24. // button in the modal, movable modal and modeless dialog boxes.
  25. //
  26. // The program utilizes the following resources:
  27. //
  28. // •    An 'MBAR' resource, and 'MENU' resources for Apple, File, Demonstration and Help
  29. //        menus (preload, non-purgeable).
  30. //
  31. // •    A 'WIND' resource (purgeable) (initially visible).
  32. //
  33. // •    An 'ALRT' resource (purgeable).
  34. //
  35. // •    'DLOG' resources (purgeable) (initially not visible) and associated 'DITL' 
  36. //        resources (purgeable).
  37. //
  38. // •    'dctb' resources (purgeable) to force the Dialog Manager to create colour graphics
  39. //        ports for the movable modal and modeless dialog boxes. 
  40. //
  41. // •    A 'cicn' resource (purgeable).
  42. //
  43. // •    A 'SIZE' resource with the acceptSuspendResumeEvents and doesActivateOnFGSwitch
  44. //        flags set.
  45. //
  46. // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }
  47.  
  48. program DialogsAndAlertsPascal(input, output);
  49.  
  50. { ………………………………………………………………………………………………………………… include the following Universal Interfaces }
  51.  
  52. uses
  53.  
  54.     Controls, Windows, Menus, Quickdraw, Fonts, Events, OSUtils, Processes, TextUtils, Dialogs, 
  55.     TextEdit, QuickdrawText, Types, Memory, Palettes, ToolUtils, Devices, LowMem, SegLoad;
  56.  
  57. { ………………………………………………………………………………………………………………………………………………… define the following constants }
  58.  
  59. const
  60.  
  61. mApple = 128;
  62.     iAbout = 1;
  63. mFile = 129;
  64.     iClose = 4;
  65.     iQuit = 11;
  66. mEdit = 130;
  67.      iCut = 3;
  68.      iCopy = 4;
  69.      iPaste = 5;
  70.      iClear = 6;
  71. mDemonstration = 131;
  72.      iAlert = 1;
  73.      iModal = 2;
  74.      iMovable = 3;
  75.      iModeless = 4;
  76. rMenubar = 128;
  77. rNewWindow = 128;
  78. rAlert = 128;
  79.      iOK = 1;
  80.      iCancel = 2;
  81.      iUserItem = 3;
  82. rModal = 129;
  83.     iGridSnap = 4;
  84.      iShowGrid = 5;
  85.      iShowRulers = 6;
  86. rMovable = 130;
  87.      iCharcoal = 4;
  88.      iOilPaint = 5;
  89.      iWaterColour = 6;
  90. rModeless = 131;
  91.      iSearch = 1;
  92.      iEditText = 4;
  93.  
  94. kMovableModal = 1;
  95. kModeless = 2;
  96.  
  97. kReturn = $0D;
  98. kEnter = $03;
  99. kEscape     = $1B;
  100. kPeriod = $2E;
  101.  
  102. kMaxLong = $7FFFFFFF;
  103.  
  104. { ………………………………………………………………………………………………………………………………………………………………………………… user-defined types }
  105.  
  106. type
  107.  
  108. DocRec = record
  109.     vScrollbarHdl, hScrollbarHdl : ControlHandle;
  110.     end;
  111.     
  112. DocRecPointer = ^DocRec;
  113. DocRecHandle = ^DocRecPointer;
  114.  
  115. { ……………………………………………………………………………………………………………………………………………………………………………………… global variables }
  116.  
  117. var
  118.  
  119. gWindowPtr : WindowPtr;
  120. gSleepTime : longint;
  121. gDone : boolean;
  122. gInBackground : boolean;
  123. gGridSnap : integer;
  124. gShowGrid : integer;
  125. gShowRule : integer;    
  126. gBrushType : integer;
  127. gOldBrushType : integer;
  128. gModelessDlgPtr : DialogRef;
  129.  
  130. menubarHdl : Handle;
  131. menuHdl : MenuHandle;
  132. docRecHdl : DocRecHandle;    
  133.  
  134. eventFilterRD : ModalFilterUPP;                                            { For PowerPC }
  135. drawDefaultButtonOutlineRD : UserItemUPP;                                  { For PowerPC }
  136.  
  137. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoInitManagers }
  138.  
  139. procedure DoInitManagers;
  140.  
  141.     begin
  142.     MaxApplZone;
  143.     MoreMasters;
  144.  
  145.     InitGraf(@qd.thePort);
  146.     InitFonts;
  147.     InitWindows;
  148.     InitMenus;
  149.     TEInit;
  150.     InitDialogs(nil);
  151.  
  152.     InitCursor;    
  153.     FlushEvents(everyEvent, 0);
  154.     end;
  155.         {of procedure DoInitManagers}
  156.  
  157. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoIdle }
  158.  
  159. procedure DoIdle(var eventRec : EventRecord);
  160.  
  161.     var
  162.     myWindowPtr : WindowPtr;
  163.     dialogType : integer;
  164.     itemHit : integer;
  165.     ignored : boolean;
  166.     
  167.     begin
  168.     myWindowPtr := FrontWindow;
  169.     if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
  170.         begin
  171.         dialogType := WindowPeek(myWindowPtr)^.refCon;
  172.     
  173.         if (dialogType = kModeless) then
  174.             ignored := DialogSelect(eventRec, DialogPtr(myWindowPtr), itemHit);
  175.         end;
  176.     end;
  177.         {of procedure DoIdle}
  178.  
  179. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoAdjustMenus }
  180.  
  181. procedure DoAdjustMenus;
  182.  
  183.     var
  184.     myWindowPtr : WindowPtr;
  185.     dialogType : integer;
  186.     menuHdl : MenuHandle;
  187.  
  188.     begin
  189.     myWindowPtr := FrontWindow;
  190.     
  191.     if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then 
  192.         begin
  193.         dialogType := WindowPeek(myWindowPtr)^.refCon;
  194.  
  195.         case (dialogType) of
  196.  
  197.             kMovableModal:
  198.                 begin
  199.                 menuHdl := GetMenuHandle(mFile);
  200.                 DisableItem(menuHdl, 0);
  201.                 menuHdl := GetMenuHandle(mEdit);
  202.                 DisableItem(menuHdl, 0);        
  203.                 menuHdl := GetMenuHandle(mDemonstration);
  204.                 DisableItem(menuHdl, 0);        
  205.                 EnableItem(menuHdl, 4);
  206.                 end;
  207.  
  208.             kModeless:
  209.                 begin
  210.                 menuHdl := GetMenuHandle(mFile);
  211.                 EnableItem(menuHdl, 0);
  212.                 EnableItem(menuHdl, 4);
  213.                 menuHdl := GetMenuHandle(mEdit);
  214.                 EnableItem(menuHdl, 0);        
  215.                 menuHdl := GetMenuHandle(mDemonstration);
  216.                 EnableItem(menuHdl, 0);        
  217.                 DisableItem(menuHdl, 4);
  218.                 end;
  219.             end;
  220.                 {of case statement}
  221.     end
  222.     
  223.     else if (WindowPeek(myWindowPtr)^.windowKind = userKind) then 
  224.         begin
  225.         menuHdl := GetMenuHandle(mFile);
  226.         EnableItem(menuHdl, 0);
  227.         DisableItem(menuHdl, 4);
  228.         menuHdl := GetMenuHandle(mEdit);
  229.         DisableItem(menuHdl, 0);
  230.         menuHdl := GetMenuHandle(mDemonstration);
  231.         EnableItem(menuHdl, 0);        
  232.         EnableItem(menuHdl, 4);
  233.         end;
  234.  
  235.     DrawMenuBar;
  236.     end;
  237.         {of procedure DoAdjustMenus}
  238.  
  239. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoKeyDownMovableModal }
  240.  
  241. procedure DoKeyDownMovableModal(var eventRec : EventRecord);
  242.  
  243.     var
  244.     myWindowPtr : WindowPtr;
  245.     charCode : char;
  246.     itemType : integer;
  247.     itemHandle : Handle;
  248.     itemRect : Rect;
  249.     finalTicks : longint;
  250.  
  251.     begin
  252.     myWindowPtr := FrontWindow;
  253.     charCode := chr(BAnd(eventRec.message, charCodeMask));
  254.  
  255.     if ((charCode = char(kReturn)) or (charCode = char(kEnter))) then 
  256.         begin
  257.         GetDialogItem(DialogRef(myWindowPtr), iOK, itemType, itemHandle, itemRect);
  258.         HiliteControl(ControlHandle(itemHandle), kControlButtonPart);
  259.         Delay(8, finalTicks);
  260.         HiliteControl(ControlHandle(itemHandle), 0);
  261.         DisposeDialog(DialogRef(myWindowPtr));
  262.         end
  263.                 
  264.     else if ((charCode = char(kEscape)) or ((BAnd(eventRec.modifiers, cmdKey) <> 0) 
  265.                  and (charCode = char(kPeriod)))) then
  266.         begin
  267.         GetDialogItem(DialogRef(myWindowPtr), iCancel, itemType, itemHandle, itemRect);
  268.         HiliteControl(ControlHandle(itemHandle), kControlButtonPart);
  269.         Delay(8, finalTicks);
  270.         HiliteControl(ControlHandle(itemHandle), 0);
  271.         gBrushType := gOldBrushType;
  272.         DisposeDialog(DialogRef(myWindowPtr));            
  273.         end;
  274.                 
  275.     end;
  276.         {of procedure DoKeyDownDocument}
  277.         
  278. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoItemHitModeless }
  279.  
  280. procedure DoItemHitModeless(myDialogRef : DialogRef);
  281.  
  282.     var
  283.     oldPort : WindowPtr;
  284.     printRect, itemRect : Rect;
  285.     itemType : integer;
  286.     itemHdl : Handle;
  287.     itemString : string;
  288.  
  289.     begin
  290.     GetPort(oldPort);
  291.     SetPort(gWindowPtr);
  292.  
  293.     SetRect(printRect, 15, 13, 369, 36);
  294.  
  295.     PenMode(patBic);
  296.     PaintRect(printRect);    
  297.  
  298.     GetDialogItem(myDialogRef, iEditText, itemType, itemHdl, itemRect);
  299.     GetDialogItemText(itemHdl, itemString);
  300.     MoveTo(20, 29);
  301.     DrawString('Search string:  ');
  302.     DrawString(itemString);
  303.     
  304.     PenNormal;
  305.     SetPort(oldPort);
  306.     end;
  307.         {of procedure DoItemHitModeless}
  308.  
  309. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoKeyDownModeless }
  310.  
  311. procedure DoKeyDownModeless(var eventRec : EventRecord);
  312.  
  313.     var
  314.     myWindowPtr : WindowPtr;
  315.     charCode : char;
  316.     itemType : integer;
  317.     itemHandle : Handle;
  318.     itemRect : Rect;
  319.     finalTicks : longint;
  320.     theDialogRef : DialogRef;    
  321.     itemHit : integer;
  322.     ignored : boolean;
  323.  
  324.     begin
  325.     myWindowPtr := FrontWindow;
  326.     charCode := chr(BAnd(eventRec.message, charCodeMask));
  327.  
  328.     if ((charCode = char(kReturn)) or (charCode = char(kEnter)))then 
  329.         begin
  330.         GetDialogItem(DialogRef(myWindowPtr), iSearch, itemType, itemHandle, itemRect);
  331.         HiliteControl(ControlHandle(itemHandle), kControlButtonPart);
  332.         Delay(8, finalTicks);
  333.         HiliteControl(ControlHandle(itemHandle), 0);
  334.         DoItemHitModeless(DialogRef(myWindowPtr));
  335.         end
  336.                 
  337.     else begin
  338.         theDialogRef := DialogRef(myWindowPtr);
  339.         ignored := DialogSelect(eventRec, theDialogRef, itemHit);
  340.         end;
  341.         
  342.     end;
  343.         {of procedure DoKeyDownModeless}
  344.  
  345. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoUpdateDocument }
  346.  
  347. procedure DoUpdateDocument(var eventRec : EventRecord);
  348.  
  349.     var
  350.     myWindowPtr : WindowPtr;
  351.     paintRect : Rect;
  352.     fillPattern : Pattern;
  353.  
  354.     begin
  355.     myWindowPtr := WindowPtr(eventRec.message);
  356.  
  357.     BeginUpdate(myWindowPtr);
  358.  
  359.     if not (EmptyRgn(myWindowPtr^.visRgn)) then
  360.         begin
  361.         SetPort(myWindowPtr);
  362.  
  363.         EraseRgn(myWindowPtr^.visRgn);
  364.  
  365.         paintRect := myWindowPtr^.portRect;
  366.         paintRect.right := paintRect.right - 15;
  367.         paintRect.bottom := paintRect.bottom - 15;
  368.         GetIndPattern(fillPattern, 0, 16);
  369.         FillRect(paintRect, fillPattern);
  370.  
  371.         DrawGrowIcon(myWindowPtr);
  372.         end;    
  373.  
  374.     EndUpdate(myWindowPtr);
  375.     end;
  376.         {of procedure DoUpdateDocument}
  377.  
  378. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoUpdateMovableOrModeless }
  379.  
  380. procedure DoUpdateMovableOrModeless(var eventRec : EventRecord);
  381.  
  382.     var
  383.     myWindowPtr : WindowPtr;
  384.  
  385.     begin
  386.     myWindowPtr := WindowPtr(eventRec.message);
  387.  
  388.     BeginUpdate(myWindowPtr);
  389.     UpdateDialog(myWindowPtr, myWindowPtr^.visRgn);
  390.     EndUpdate(myWindowPtr);
  391.     end;
  392.         {of procedure DoUpdateMovableOrModeless}
  393.  
  394. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoActivateDocument }
  395.  
  396. procedure DoActivateDocument(myWindowPtr : WindowPtr; becomingActive : boolean);
  397.  
  398.     begin
  399.     if (becomingActive) then
  400.         DoAdjustMenus;
  401.  
  402.     DrawGrowIcon(myWindowPtr);
  403.     end;
  404.         {of procedure DoActivateDocument}
  405.  
  406. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DrawDefaultButtonOutline }
  407.  
  408. procedure DrawDefaultButtonOutline(myDialogRef : DialogRef; theItem : integer);
  409.  
  410.     var
  411.     oldPort : WindowPtr;
  412.     oldPenState : PenState;
  413.     itemType : integer;
  414.     itemHandle : Handle;
  415.     itemRect : Rect;
  416.     colGrafPtr : CGrafPtr;
  417.     isColour : boolean;
  418.     buttonOval : SInt8;
  419.     backColour : RGBColor;
  420.     foreSaveColour : RGBColor;
  421.     newForeColour : RGBColor;
  422.     newGray : boolean;
  423.     targetDevice : GDHandle;
  424.  
  425.     begin
  426.     GetPort(oldPort);
  427.     GetPenState(oldPenState);
  428.  
  429.     GetDialogItem(myDialogRef, iOK, itemType, itemHandle, itemRect);
  430.     SetPort(ControlHandle(itemHandle)^^.contrlOwner);
  431.     InsetRect(itemRect, -4, -4);
  432.  
  433.     colGrafPtr := CGrafPtr(ControlHandle(itemHandle)^^.contrlOwner);
  434.  
  435.     if (BAnd(BSR(colGrafPtr^.portVersion, 14), $00000003) <> 0)
  436.         then isColour := true
  437.         else isColour := false;
  438.  
  439.     buttonOval := trunc((itemRect.bottom - itemRect.top) / 2) + 2;
  440.  
  441.     if (ControlHandle(itemHandle)^^.contrlHilite = 255) 
  442.         then begin
  443.         newGray := false;
  444.  
  445.         if (isColour) then
  446.             begin
  447.             GetBackColor(backColour);
  448.             GetForeColor(foreSaveColour);
  449.             newForeColour := foreSaveColour;
  450.             targetDevice := GetMainDevice;
  451.             newGray := GetGray(targetDevice, backColour, newForeColour);
  452.             end;
  453.  
  454.         if (newGray)
  455.             then RGBForeColor(newForeColour)
  456.             else PenPat(qd.gray);
  457.  
  458.         PenSize(3, 3);
  459.         FrameRoundRect(itemRect, buttonOval, buttonOval);
  460.  
  461.         if (isColour) then
  462.             RGBForeColor(foreSaveColour);
  463.         end
  464.                 
  465.     else begin
  466.         PenPat(qd.black);
  467.         PenSize(3, 3);
  468.         FrameRoundRect(itemRect, buttonOval, buttonOval);
  469.         end;
  470.  
  471.     SetPenState(oldPenState);
  472.     SetPort(oldPort);
  473.     end;
  474.         {of procedure DrawDefaultButtonOutline}
  475.  
  476. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoActivateMovableModal }
  477.  
  478. procedure DoActivateMovableModal(myWindowPtr : WindowPtr; becomingActive : boolean);
  479.  
  480.     var
  481.     a, itemType : integer;
  482.     itemHdl : Handle;
  483.     itemRect : Rect;
  484.  
  485.     begin
  486.     if (becomingActive)
  487.         then begin
  488.         for a := iOK to iWaterColour do
  489.             begin
  490.             if (a <> iUserItem) then
  491.                 begin
  492.                 GetDialogItem(DialogRef(myWindowPtr), a, itemType, itemHdl, itemRect);
  493.                 HiliteControl(ControlHandle(itemHdl), 0);
  494.                 end;
  495.             end;
  496.         DrawDefaultButtonOutline(DialogRef(myWindowPtr), iOK);
  497.         DoAdjustMenus;
  498.         end
  499.                 
  500.         else begin
  501.         for a := iOK to iWaterColour do
  502.             begin
  503.             if (a <> iUserItem) then
  504.                 begin
  505.                 GetDialogItem(DialogRef(myWindowPtr), a, itemType, itemHdl, itemRect);
  506.                 HiliteControl(ControlHandle(itemHdl), 255);
  507.                 end;
  508.             end;
  509.         DrawDefaultButtonOutline(DialogRef(myWindowPtr), iOK);
  510.         end;
  511.     end;
  512.         {of procedure DoActivateMovableModal}
  513.         
  514. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoActivateModeless }
  515.  
  516. procedure DoActivateModeless(myWindowPtr : WindowPtr; becomingActive : boolean);
  517.  
  518.     var
  519.     itemType : integer;
  520.     itemHdl : Handle;
  521.     itemRect : Rect;
  522.  
  523.     begin
  524.     if (becomingActive)
  525.         then begin
  526.         GetDialogItem(DialogRef(myWindowPtr), iSearch, itemType, itemHdl, itemRect);
  527.         HiliteControl(ControlHandle(itemHdl), 0);
  528.  
  529.         DrawDefaultButtonOutline(DialogRef(myWindowPtr), iSearch);
  530.         SelectDialogItemText(DialogRef(myWindowPtr), iEditText, 0, 32767);
  531.         gSleepTime := LMGetCaretTime;
  532.         DoAdjustMenus;
  533.         end
  534.                 
  535.         else begin
  536.         GetDialogItem(DialogRef(myWindowPtr), iSearch, itemType, itemHdl, itemRect);
  537.         HiliteControl(ControlHandle(itemHdl), 255);
  538.         
  539.         DrawDefaultButtonOutline(DialogRef(myWindowPtr), iSearch);
  540.         SelectDialogItemText(DialogRef(myWindowPtr), iEditText, 0, 0);
  541.         gSleepTime := kMaxLong;    
  542.         end;
  543.     end;
  544.         {of procedure DoActivateModeless}
  545.         
  546. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoActivate }
  547.  
  548. procedure DoActivate(var eventRec : EventRecord);
  549.  
  550.     var
  551.     myWindowPtr : WindowPtr;
  552.     dialogType : integer;
  553.     becomingActive : boolean;
  554.  
  555.     begin
  556.     myWindowPtr := WindowPtr(eventRec.message);
  557.     becomingActive := BAnd(eventRec.modifiers, activeFlag) = activeFlag;
  558.  
  559.     if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
  560.         begin
  561.         dialogType := WindowPeek(myWindowPtr)^.refCon;
  562.  
  563.         if (dialogType = kMovableModal)    then
  564.             DoActivateMovableModal(myWindowPtr, becomingActive)
  565.         else if (dialogType = kModeless) then
  566.             DoActivateModeless(myWindowPtr, becomingActive);
  567.         end
  568.         
  569.     else if (WindowPeek(myWindowPtr)^.windowKind = userKind) then
  570.         DoActivateDocument(myWindowPtr, becomingActive);
  571.         
  572.     end;
  573.         {of procedure DoActivate}
  574.         
  575. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoOSEvent }
  576.  
  577. procedure DoOSEvent(var eventRec : EventRecord);
  578.  
  579.     var
  580.     dialogType : integer;
  581.     myWindowPtr : WindowPtr;
  582.     
  583.     begin
  584.     myWindowPtr := FrontWindow;
  585.  
  586.     case BAnd(BSR(eventRec.message, 24), $000000FF) of
  587.  
  588.         suspendResumeMessage:
  589.             begin
  590.             gInBackground := BAnd(eventRec.message, resumeFlag) = 0;
  591.             
  592.             if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
  593.                 begin
  594.                 dialogType := WindowPeek(myWindowPtr)^.refCon;
  595.                 
  596.                 if (dialogType = kMovableModal) then
  597.                     DoActivateMovableModal(myWindowPtr, not(gInBackground))
  598.                 else if (dialogType = kModeless) then
  599.                     DoActivateModeless(myWindowPtr, not(gInBackground));
  600.                 end
  601.                 
  602.             else if (WindowPeek(myWindowPtr)^.windowKind = userKind) then
  603.                 DoActivateDocument(myWindowPtr, not(gInBackground));
  604.             end;
  605.  
  606.         mouseMovedMessage:
  607.             begin
  608.             end;
  609.         
  610.         end;
  611.             {of outer case statement}
  612.     end;
  613.         {of procedure DoOSEvent}
  614.         
  615. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoUpdate }
  616.  
  617. procedure DoUpdate(var eventRec : EventRecord);
  618.  
  619.     var
  620.     myWindowPtr : WindowPtr;
  621.     dialogType : integer;
  622.     
  623.     begin
  624.     myWindowPtr := WindowPtr(eventRec.message);
  625.     
  626.     if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
  627.         begin
  628.         dialogType := WindowPeek(myWindowPtr)^.refCon;
  629.         
  630.         if ((dialogType = kMovableModal) or (dialogType = kModeless)) then
  631.             DoUpdateMovableOrModeless(eventRec);
  632.         end
  633.         
  634.     else if (WindowPeek(myWindowPtr)^.windowKind = userKind) then
  635.         DoUpdateDocument(eventRec);
  636.         
  637.     end;
  638.         {of procedure DoUpdate}
  639.  
  640. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoHideModeless }
  641.  
  642. procedure DoHideModeless;
  643.  
  644.     var
  645.     myWindowPtr : WindowPtr;
  646.     dialogType : integer;
  647.  
  648.     begin
  649.     myWindowPtr := FrontWindow;
  650.  
  651.     if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
  652.         begin
  653.         dialogType := WindowPeek(myWindowPtr)^.refCon;
  654.  
  655.         if (dialogType = kModeless) then
  656.             begin
  657.             HideWindow(myWindowPtr);
  658.             InvalRgn(gWindowPtr^.visRgn);
  659.             gSleepTime := kMaxLong;
  660.             end;
  661.         end;
  662.     end;
  663.         {of procedure DoHideModeless}
  664.         
  665. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoEditMenu }
  666.  
  667. procedure DoEditMenu(menuItem : integer);
  668.  
  669.     var
  670.     myWindowPtr : WindowPtr;
  671.     dialogType : integer;
  672.     
  673.     begin
  674.     myWindowPtr := FrontWindow;
  675.     
  676.     if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
  677.         begin
  678.         dialogType := WindowPeek(myWindowPtr)^.refCon;
  679.  
  680.         if (dialogType = kModeless) then
  681.             case (menuItem) of
  682.  
  683.                 iCut:
  684.                     begin
  685.                     DialogCut(DialogRef(myWindowPtr));
  686.                     end;
  687.  
  688.                 iCopy:
  689.                     begin
  690.                     DialogCopy(DialogRef(myWindowPtr));
  691.                     end;
  692.  
  693.                 iPaste:
  694.                     begin
  695.                     DialogPaste(DialogRef(myWindowPtr));
  696.                     end;
  697.  
  698.                 iClear:
  699.                     begin
  700.                     DialogDelete(DialogRef(myWindowPtr));
  701.                     end;
  702.                 end;
  703.                     {of case statement}
  704.         end;
  705.     end;
  706.         {of procedure DoEditMenu}
  707.         
  708. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ EventFilter }
  709.  
  710. function EventFilter(myDialogRef : DialogRef; eventRec : EventRecord;
  711.                                               var itemHit : integer) : boolean;
  712.  
  713.     var
  714.     charCode : char;
  715.     itemType : integer;
  716.     itemHandle : Handle;
  717.     itemRect : Rect;
  718.     finalTicks : longint;
  719.     handledEvent : boolean;
  720.  
  721.     begin
  722.     handledEvent := false;
  723.  
  724.     if ((eventRec.what = updateEvt) and (WindowPtr(eventRec.message) <> myDialogRef))
  725.         then DoUpdate(eventRec)
  726.         else begin
  727.             case (eventRec.what) of
  728.  
  729.                 keyDown, autoKey:
  730.                     begin
  731.                     charCode := chr(BAnd(eventRec.message, charCodeMask));
  732.                     if ((charCode = char(kReturn)) or (charCode = char(kEnter))) then
  733.                         begin
  734.                         GetDialogItem(myDialogRef, iOK, itemType, itemHandle, itemRect);
  735.                         HiliteControl(ControlHandle(itemHandle), kControlButtonPart);
  736.                         Delay(8, finalTicks);
  737.                         HiliteControl(ControlHandle(itemHandle), 0);
  738.                         handledEvent := true;
  739.                         itemHit := iOK;
  740.                         end;
  741.                     if ((charCode = char(kEscape)) or ((BAnd(eventRec.modifiers, cmdKey) <> 0) 
  742.                             and (charCode = char(kPeriod)))) then
  743.                         begin
  744.                         GetDialogItem(myDialogRef, iCancel, itemType, itemHandle, itemRect);
  745.                         HiliteControl(ControlHandle(itemHandle), kControlButtonPart);
  746.                         Delay(8, finalTicks);
  747.                         HiliteControl(ControlHandle(itemHandle),0);
  748.                         handledEvent := true;
  749.                         itemHit := iCancel;
  750.                         end;
  751.                             
  752.                     {Other keyboard equivalents handled here.}
  753.                     end;
  754.  
  755.                 {Disk-inserted and other events handled here.}
  756.                 end;
  757.                     {of case statement}
  758.         end;
  759.  
  760.     EventFilter := handledEvent;
  761.     end;
  762.         {of procedure EventFilter}
  763.  
  764. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoModalDialog }
  765.  
  766. function DoModalDialog : boolean;
  767.  
  768.     var
  769.     modalDlgPtr : DialogRef;
  770.     itemType, itemHit : integer;
  771.     itemHdl : Handle;
  772.     itemRect : Rect;
  773.     
  774.     begin
  775.     
  776.     modalDlgPtr := GetNewDialog(rModal, nil, WindowPtr(-1));
  777.     if (modalDlgPtr = nil) then
  778.         begin
  779.         DoModalDialog := false;
  780.         Exit(DoModalDialog);
  781.         end;
  782.  
  783.     GetDialogItem(modalDlgPtr, iUserItem, itemType, itemHdl, itemRect);
  784.     SetDialogItem(modalDlgPtr, iUserItem, itemType, Handle(drawDefaultButtonOutlineRD),
  785.                   itemRect);                                                 { For PowerPC }
  786.  
  787.     GetDialogItem(modalDlgPtr, iGridSnap, itemType, itemHdl, itemRect);
  788.     SetControlValue(ControlHandle(itemHdl), gGridSnap);
  789.  
  790.     GetDialogItem(modalDlgPtr, iShowGrid, itemType, itemHdl, itemRect);
  791.     SetControlValue(ControlHandle(itemHdl), gShowGrid);
  792.  
  793.     GetDialogItem(modalDlgPtr, iShowRulers, itemType, itemHdl, itemRect);
  794.     SetControlValue(ControlHandle(itemHdl), gShowRule);
  795.  
  796.     ShowWindow(modalDlgPtr);
  797.  
  798.     repeat
  799.         ModalDialog(eventFilterRD, itemHit);                                   { For PowerPC }
  800.         GetDialogItem(modalDlgPtr, itemHit, itemType, itemHdl, itemRect);
  801.         if (GetControlValue(ControlHandle(itemHdl)) = 1) 
  802.             then SetControlValue(ControlHandle(itemHdl), 0)
  803.             else if (GetControlValue(ControlHandle(itemHdl)) = 0) then
  804.                 SetControlValue(ControlHandle(itemHdl), 1);
  805.         
  806.     until ((itemHit = iOK) or (itemHit = iCancel));
  807.  
  808.     if (itemHit = iOK) then
  809.         begin
  810.         GetDialogItem(modalDlgPtr, iGridSnap, itemType, itemHdl, itemRect);
  811.         gGridSnap := GetControlValue(ControlHandle(itemHdl));
  812.  
  813.         GetDialogItem(modalDlgPtr, iShowGrid, itemType, itemHdl, itemRect);
  814.         gShowGrid := GetControlValue(ControlHandle(itemHdl));
  815.  
  816.         GetDialogItem(modalDlgPtr, iShowRulers, itemType, itemHdl, itemRect);
  817.         gShowRule := GetControlValue(ControlHandle(itemHdl));                
  818.         end;
  819.  
  820.     DisposeDialog(modalDlgPtr);
  821.  
  822.     DoModalDialog := true;
  823.     end;
  824.         {of function DoModalDialog}
  825.  
  826. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMovableModalDialog }
  827.  
  828. function DoMovableModalDialog : boolean;
  829.  
  830.     var
  831.     modalDlgPtr : DialogRef;
  832.     itemType : integer;
  833.     itemHdl : Handle;
  834.     itemRect : Rect;
  835.     
  836.     begin
  837.     modalDlgPtr := GetNewDialog(rMovable, nil, WindowPtr(-1));
  838.     
  839.     if (modalDlgPtr = nil) then
  840.         begin
  841.         DoMovableModalDialog := false;
  842.         Exit(DoMovableModalDialog);
  843.         end;
  844.  
  845.     SetWRefCon(modalDlgPtr, longint(kMovableModal));
  846.  
  847.     GetDialogItem(modalDlgPtr, iUserItem, itemType, itemHdl, itemRect);
  848.     
  849.     SetDialogItem(modalDlgPtr, iUserItem, itemType, Handle(drawDefaultButtonOutlineRD),
  850.                 itemRect);                                                 { For PowerPC }
  851.  
  852.     GetDialogItem(modalDlgPtr, gBrushType, itemType, itemHdl, itemRect);
  853.     SetControlValue(ControlHandle(itemHdl),1);
  854.  
  855.     ShowWindow(modalDlgPtr);
  856.  
  857.     gOldBrushType := gBrushType;
  858.  
  859.     DoMovableModalDialog := true;
  860.     end;
  861.         {of function DoMovableModalDialog}
  862.         
  863. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoModelessDialog }
  864.  
  865. function DoModelessDialog : boolean;
  866.  
  867.     var
  868.     itemType : integer;
  869.     itemHdl : Handle;
  870.     itemRect : Rect;
  871.     
  872.     begin
  873.     if (gModelessDlgPtr = nil) 
  874.         then begin
  875.         gModelessDlgPtr := GetNewDialog(rModeless, nil, WindowPtr(-1));
  876.         if (gModelessDlgPtr = nil) then
  877.             begin
  878.             DoModelessDialog := false;
  879.             Exit(DoModelessDialog);
  880.             end;
  881.  
  882.         SetWRefCon(gModelessDlgPtr, longint(kModeless));
  883.  
  884.         GetDialogItem(gModelessDlgPtr, iUserItem, itemType, itemHdl, itemRect);
  885.         SetDialogItem(gModelessDlgPtr, iUserItem, itemType, 
  886.                    Handle(drawDefaultButtonOutlineRD), itemRect);              { For PowerPC }
  887.  
  888.         ShowWindow(gModelessDlgPtr);
  889.         SelectDialogItemText(gModelessDlgPtr, iEditText, 0, 32767);
  890.         end
  891.                 
  892.         else begin
  893.         ShowWindow(gModelessDlgPtr);
  894.         SelectWindow(gModelessDlgPtr);
  895.         end;
  896.  
  897.     DoModelessDialog := true;
  898.     end;
  899.         {of function DoModelessDialog}
  900.         
  901. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoDemonstrationMenu }
  902.  
  903. procedure DoDemonstrationMenu(menuItem : integer);
  904.  
  905.     var
  906.     myWindowPtr : WindowPtr;
  907.     theRect : Rect;
  908.     ignored : integer;
  909.     
  910.     begin
  911.     case (menuItem) of
  912.  
  913.     iAlert: begin
  914.         myWindowPtr := FrontWindow;
  915.         if (GetAlertStage > 0) then
  916.             begin
  917.             if (myWindowPtr <> nil) then
  918.                 begin
  919.                 if (WindowPeek(myWindowPtr)^.windowKind <> dialogKind) then
  920.                     begin
  921.                     SetRect(theRect, myWindowPtr^.portRect.right - 15,
  922.                         myWindowPtr^.portRect.bottom - 15, myWindowPtr^.portRect.right, 
  923.                         myWindowPtr^.portRect.bottom);
  924.                     InvalRect(theRect);
  925.                     DoActivateDocument(myWindowPtr, false);
  926.                     end
  927.                 else if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
  928.                     begin
  929.                     DoActivateModeless(myWindowPtr, false);
  930.                     end;
  931.                 end;
  932.             end;
  933.             ignored := NoteAlert(rAlert, eventFilterRD);                         { For PowerPC }
  934.         end;
  935.  
  936.     iModal: begin
  937.         myWindowPtr := FrontWindow;
  938.         if (myWindowPtr <> nil) then
  939.             begin 
  940.             if (WindowPeek(myWindowPtr)^.windowKind <> dialogKind) then
  941.                 begin
  942.                 SetRect(theRect, myWindowPtr^.portRect.right - 15,
  943.                     myWindowPtr^.portRect.bottom - 15, myWindowPtr^.portRect.right, 
  944.                     myWindowPtr^.portRect.bottom);
  945.                 InvalRect(theRect);
  946.                 DoActivateDocument(myWindowPtr, false);
  947.                 end
  948.             else if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
  949.                 begin
  950.                 DoActivateModeless(myWindowPtr, false);
  951.                 end;
  952.             end;
  953.             
  954.         if not (DoModalDialog) then
  955.             begin
  956.             SysBeep(10);
  957.             ExitToShell;
  958.             end;
  959.         end;
  960.  
  961.     iMovable: begin
  962.         if not (DoMovableModalDialog) then
  963.             begin
  964.             SysBeep(10);
  965.             ExitToShell;
  966.             end;
  967.         end;
  968.  
  969.     iModeless: begin
  970.         if not (DoModelessDialog) then
  971.             begin
  972.             SysBeep(10);
  973.             ExitToShell;
  974.             end;
  975.         end;
  976.     end;
  977.         {of case statement}
  978.         
  979.     end;
  980.         {of procedure DoDemonstrationMenu}
  981.         
  982. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMenuChoice }
  983.  
  984. procedure DoMenuChoice(menuChoice : longint);
  985.  
  986.     var
  987.     menuID, menuItem : integer;
  988.     itemName : string;
  989.     daDriverRefNum : integer;
  990.  
  991.     begin
  992.     menuID := HiWord(menuChoice);
  993.     menuItem := LoWord(menuChoice);
  994.  
  995.     if (menuID = 0) then
  996.         Exit(DoMenuChoice);
  997.  
  998.     case (menuID) of
  999.  
  1000.         mApple:
  1001.             begin
  1002.             if (menuItem = iAbout)
  1003.                 then SysBeep(10)
  1004.                 else begin
  1005.                     GetMenuItemText(GetMenuHandle(mApple), menuItem, itemName);
  1006.                     daDriverRefNum := OpenDeskAcc(itemName);
  1007.                     end;
  1008.             end;
  1009.  
  1010.         mFile:
  1011.             begin
  1012.             if (menuItem = iQuit)
  1013.                 then gDone := true
  1014.                 else if (menuItem = iClose) then
  1015.                         DoHideModeless;
  1016.             end;
  1017.  
  1018.         mEdit:
  1019.             begin
  1020.             DoEditMenu(menuItem);
  1021.             end;
  1022.  
  1023.         mDemonstration:
  1024.             begin
  1025.             DoDemonstrationMenu(menuItem);
  1026.             end;
  1027.         end;
  1028.             {of case statement}
  1029.  
  1030.     HiliteMenu(0);
  1031.     end;
  1032.         {of procedure DoMenuChoice}
  1033.  
  1034. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoKeyDownDocument }
  1035.  
  1036. procedure DoKeyDownDocument(var eventRec : EventRecord);
  1037.  
  1038.     var
  1039.     charCode : char;
  1040.  
  1041.     begin
  1042.     charCode := chr(BAnd(eventRec.message, charCodeMask));
  1043.  
  1044.     if (BAnd(eventRec.modifiers, cmdKey) <> 0) then
  1045.         begin
  1046.         DoAdjustMenus;
  1047.         DoMenuChoice(MenuKey(charCode));
  1048.         end;
  1049.     end;
  1050.         {of procedure DoKeyDownDocument}
  1051.  
  1052. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoKeyDown }
  1053.  
  1054. procedure DoKeyDown(var eventRec : EventRecord);
  1055.  
  1056.     var
  1057.     myWindowPtr : WindowPtr;
  1058.     dialogType : integer;
  1059.     
  1060.     begin
  1061.     myWindowPtr := FrontWindow;
  1062.     
  1063.     if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
  1064.         begin
  1065.         dialogType := WindowPeek(myWindowPtr)^.refCon;
  1066.  
  1067.         case (dialogType) of
  1068.  
  1069.             kMovableModal:
  1070.                 begin
  1071.                 DoKeyDownMovableModal(eventRec);
  1072.                 end;
  1073.  
  1074.             kModeless:
  1075.                 begin
  1076.                 DoKeyDownModeless(eventRec);
  1077.                 end;
  1078.             end;
  1079.                 {of case statement}
  1080.         end
  1081.     
  1082.     else if (WindowPeek(myWindowPtr)^.windowKind = userKind) then
  1083.         DoKeyDownDocument(eventRec);
  1084.         
  1085.     end;
  1086.         {of procedure DoKeyDown}
  1087.  
  1088. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoItemHitMovableModal }
  1089.  
  1090. procedure DoItemHitMovableModal(myDialogRef : DialogRef; itemHit : integer);
  1091.  
  1092.     var
  1093.     a, itemType : integer;
  1094.     itemHdl : Handle;
  1095.     itemRect : Rect;
  1096.     
  1097.     begin
  1098.     if ((itemHit = iCharcoal) or (itemHit = iOilPaint) or (itemHit = iWaterColour)) 
  1099.         then begin
  1100.         for a := iCharcoal to iWaterColour do
  1101.             begin
  1102.             GetDialogItem(myDialogRef, a, itemType, itemHdl, itemRect);
  1103.             SetControlValue(ControlHandle(itemHdl), 0);
  1104.             end;
  1105.  
  1106.         GetDialogItem(myDialogRef, itemHit, itemType, itemHdl, itemRect);
  1107.         SetControlValue(ControlHandle(itemHdl), 1);
  1108.         gBrushType := itemHit;
  1109.         end
  1110.                 
  1111.     else begin
  1112.         if ((itemHit = iOK) or (itemHit = iCancel)) then
  1113.             begin
  1114.             if (itemHit = iCancel) then
  1115.                 gBrushType := gOldBrushType;
  1116.             DisposeDialog(myDialogRef);
  1117.             end;
  1118.         end;
  1119.     end;
  1120.         {of procedure DoItemHitMovableModal}
  1121.         
  1122. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ InvalidateScrollBarArea }
  1123.  
  1124. procedure InvalidateScrollBarArea(myWindowPtr : WindowPtr);
  1125.  
  1126.     var
  1127.     tempRect : Rect;
  1128.  
  1129.     begin
  1130.     SetPort(myWindowPtr);
  1131.  
  1132.     tempRect := myWindowPtr^.portRect;
  1133.     tempRect.left := tempRect.right - 15;
  1134.     InvalRect(tempRect);
  1135.  
  1136.     tempRect := myWindowPtr^.portRect;
  1137.     tempRect.top := tempRect.bottom - 15;
  1138.     InvalRect(tempRect);
  1139.     end;
  1140.         {of procedure InvalidateScrollBarArea}
  1141.  
  1142. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoInContent }
  1143.  
  1144. procedure DoInContent(var eventRec : EventRecord);
  1145.  
  1146.     var
  1147.     myWindowPtr : WindowPtr;
  1148.     dialogType : integer;
  1149.     myDialogRef : DialogRef;
  1150.     itemHit : integer;
  1151.     
  1152.     begin
  1153.     myWindowPtr := FrontWindow;
  1154.  
  1155.     if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
  1156.         begin
  1157.         dialogType := WindowPeek(myWindowPtr)^.refCon;
  1158.     
  1159.         if (dialogType = kMovableModal) then
  1160.             begin
  1161.             if (DialogSelect(eventRec, myDialogRef, itemHit)) then
  1162.                 DoItemHitMovableModal(myDialogRef, itemHit);
  1163.             end
  1164.             
  1165.         else if (dialogType = kModeless) then
  1166.             begin
  1167.             if (DialogSelect(eventRec, myDialogRef, itemHit)) then
  1168.                 DoItemHitModeless(myDialogRef);
  1169.             end;
  1170.         end
  1171.         
  1172.     else if (WindowPeek(myWindowPtr)^.windowKind = userKind) then
  1173.         begin
  1174.         { Handle clicks in document content region here.}
  1175.         end;
  1176.     end;
  1177.         {of procedure DoInContent}
  1178.         
  1179. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMouseDown }
  1180.  
  1181. procedure DoMouseDown(eventRec : EventRecord);
  1182.  
  1183.     var
  1184.     myWindowPtr : WindowPtr;
  1185.     partCode : integer;
  1186.     growRect : Rect;
  1187.     newSize : longint;
  1188.     
  1189.     begin
  1190.     partCode := FindWindow(eventRec.where, myWindowPtr);
  1191.  
  1192.     case (partCode) of
  1193.  
  1194.         inMenuBar:
  1195.             begin
  1196.             DoAdjustMenus;
  1197.             DoMenuChoice(MenuSelect(eventRec.where));
  1198.             end;
  1199.  
  1200.         inSysWindow:
  1201.             begin
  1202.             SystemClick(eventRec, myWindowPtr);
  1203.             end;
  1204.  
  1205.         inContent:
  1206.             begin
  1207.             if (myWindowPtr <> FrontWindow)
  1208.                 then begin
  1209.                 if (WindowPeek(FrontWindow)^.refCon = kMovableModal)
  1210.                     then SysBeep(10)
  1211.                     else SelectWindow(myWindowPtr);
  1212.                 end
  1213.                             
  1214.                 else DoInContent(eventRec);
  1215.             end;
  1216.  
  1217.         inDrag:
  1218.             begin
  1219.             if ((WindowPeek(FrontWindow)^.refCon = kMovableModal) and 
  1220.                  (WindowPeek(myWindowPtr)^.refCon <> kMovableModal)) then
  1221.                 begin
  1222.                 SysBeep(10);
  1223.                 Exit(DoMouseDown);
  1224.                 end;
  1225.             DragWindow(myWindowPtr, eventRec.where, qd.screenBits.bounds);
  1226.             end;
  1227.  
  1228.         inGoAway:
  1229.             begin
  1230.             if (TrackGoAway(myWindowPtr, eventRec.where)) then
  1231.                 DoHideModeless;
  1232.             end;
  1233.  
  1234.         inGrow:
  1235.             begin
  1236.             growRect := qd.screenBits.bounds;
  1237.             growRect.top := 80; 
  1238.             growRect.left := 160;
  1239.             newSize := GrowWindow(myWindowPtr, eventRec.where, growRect);
  1240.             if (newSize <> 0) then
  1241.                 begin
  1242.                 InvalidateScrollBarArea(myWindowPtr);
  1243.                 SizeWindow(myWindowPtr, LoWord(newSize), HiWord(newSize), true);
  1244.                 InvalidateScrollBarArea(myWindowPtr);
  1245.                 end;
  1246.             end;
  1247.  
  1248.         end;
  1249.             {of case statement}
  1250.     end;
  1251.         {of procedure DoMouseDown}
  1252.         
  1253. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoEvents }
  1254.  
  1255. procedure DoEvents(eventRec : EventRecord);
  1256.  
  1257.     begin
  1258.     case (eventRec.what) of
  1259.  
  1260.         mouseDown:
  1261.             begin
  1262.             DoMouseDown(eventRec);
  1263.             end;
  1264.  
  1265.         keyDown, autoKey:
  1266.             begin
  1267.             DoKeyDown(eventRec);
  1268.             end;
  1269.  
  1270.         updateEvt:
  1271.             begin
  1272.             DoUpdate(eventRec);
  1273.             end;
  1274.  
  1275.         activateEvt:
  1276.             begin
  1277.             DoActivate(eventRec);
  1278.             end;
  1279.  
  1280.         osEvt:
  1281.             begin
  1282.             DoOSEvent(eventRec);
  1283.             HiliteMenu(0);
  1284.             end;
  1285.         end;
  1286.             {of case statement}
  1287.     end;
  1288.         {of procedure DoEvents}
  1289.         
  1290. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ EventLoop }
  1291.  
  1292. procedure EventLoop;
  1293.  
  1294.     var
  1295.     eventRec : EventRecord;
  1296.     gotEvent : Boolean;        
  1297.     
  1298.     begin
  1299.     gSleepTime := kMaxLong;    
  1300.  
  1301.     gDone := false;
  1302.     
  1303.     while not (gDone) do
  1304.         begin
  1305.         gotEvent := WaitNextEvent(everyEvent, eventRec, gSleepTime, nil);
  1306.  
  1307.         if (gotEvent)
  1308.             then DoEvents(eventRec)
  1309.             else DoIdle(eventRec);
  1310.         end;
  1311.     end;
  1312.         {of procedure EventLoop}
  1313.  
  1314.  
  1315. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ start of main program }
  1316.  
  1317. begin
  1318.  
  1319.     gGridSnap := 0;
  1320.     gShowGrid := 0;
  1321.     gShowRule := 0;    
  1322.     gBrushType := iCharcoal;
  1323.     gOldBrushType := iCharcoal;
  1324.     gModelessDlgPtr    := nil;
  1325.  
  1326.     { …………………………………………………………………………………………………………………………………………………………………… initialize managers }
  1327.  
  1328.     DoInitManagers;
  1329.  
  1330.     { ………………………………………………………………………………………………………………………………………………… create routine descriptors }
  1331.  
  1332.     eventFilterRD := NewModalFilterProc(ProcPtr(@EventFilter));               { For PowerPC }
  1333.     drawDefaultButtonOutlineRD := NewUserItemProc(ProcPtr(@DrawDefaultButtonOutline));
  1334.     
  1335.     { …………………………………………………………………………………………………………………………………………………… set up menu bar and menus }
  1336.  
  1337.     menubarHdl := GetNewMBar(rMenubar);
  1338.     if (menubarHdl = nil) then
  1339.         ExitToShell;
  1340.     SetMenuBar(menubarHdl);
  1341.     DrawMenuBar;
  1342.  
  1343.     menuHdl := GetMenuHandle(mApple);
  1344.     if (menuHdl = nil)
  1345.         then ExitToShell
  1346.         else AppendResMenu(menuHdl,'DRVR');
  1347.  
  1348.     { ………………………………………………………………………………………………………………………………………………………………………………………… open window }
  1349.  
  1350.     gWindowPtr := GetNewWindow(rNewWindow, nil, WindowPtr(-1));
  1351.     if (gWindowPtr = nil) then
  1352.         ExitToShell;
  1353.     
  1354.     docRecHdl := DocRecHandle(NewHandle(sizeof(DocRec)));
  1355.     if (docRecHdl = nil) then
  1356.         ExitToShell;
  1357.  
  1358.     SetWRefCon(gWindowPtr, longint(docRecHdl));
  1359.  
  1360.     { ……………………………………………………………………………………………………………………………………………………………………………… enter eventLoop }
  1361.     
  1362.     EventLoop;
  1363.  
  1364. end.
  1365.     
  1366. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }
  1367.