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 / chap05pascal_demo / Controls1Pascal.p next >
Text File  |  1999-04-05  |  14KB  |  612 lines

  1. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
  2. // Controls1Pascal.p
  3. // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
  4. // 
  5. // This program opens a zoomDocProc window containing:
  6. //
  7. // •    A pop-up menu.
  8. //
  9. // •    Three radio buttons.
  10. //
  11. // •    Two checkboxes.
  12. //
  13. // •    One button.
  14. //
  15. // •    Vertical and horizontal scroll bars.
  16. //
  17. // The pop-up menu, radio buttons, checkboxes, and button work correctly except that the
  18. // control values are not used for any specific purpose.
  19. //
  20. // The scroll bars are moved and resized when the user resizes or zooms the window;
  21. // however, no action is taken when the scroll box is moved or the scroll arrows or gray
  22. // areas are clicked.
  23. //
  24. // The program utilizes the following resources:
  25. //
  26. // •    An 'MBAR' resource, and 'MENU' resources for Apple, File, Edit menus and a
  27. //        pop-up menu (preload, non-purgeable).  
  28. //
  29. // •    A 'WIND' resource (purgeable) (initially not visible).  
  30. //
  31. // •    'CNTL' resources for the pop-up menu, radio buttons, checkboxes, button and
  32. //            scroll bars (preload, purgeable) (initially visible).  
  33. //
  34. // •    A 'SIZE' resource with the acceptSuspendResumeEvents and doesActivateOnFGSwitch
  35. //            flags set.      
  36. //
  37. // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }
  38.  
  39. program Controls1Pascal(input, output);
  40.  
  41. { ………………………………………………………………………………………………………………… include the following Universal Interfaces }
  42.  
  43. uses
  44.  
  45.     Windows, Menus, Events, Types, Memory, Quickdraw, QuickdrawText, Fonts, Processes,
  46.     TextUtils, Controls, OSUtils, TextEdit, Dialogs, ToolUtils, Devices, Segload, Sound;
  47.  
  48. { ………………………………………………………………………………………………………………………………………………… define the following constants }
  49.  
  50. const
  51.  
  52.  rMenubar = 128;
  53.  rNewWindow = 128;
  54.  
  55.  mApple = 128;
  56.       iAbout = 1;
  57.  mFile = 129;
  58.       iQuit = 11;
  59.  mEdit = 130;
  60.  
  61.  cTimeZone = 128;
  62.       pSydney = 1;
  63.       pNewYork = 2;
  64.       pLondon = 3;
  65.       pRome = 4;
  66.       
  67.  cRed = 129;
  68.  cWhite = 130;
  69.  cBlue = 131;
  70.  cShowgrid = 132;
  71.  cShowrulers = 133;
  72.  cButton = 134;
  73.  cVScrollbar = 135;
  74.  cHScrollbar = 136;
  75.  
  76.  kMaxLong = $7FFFFFFF;
  77.  
  78. { ………………………………………………………………………………………………………………………………………………………………………………… user-defined types }
  79.  
  80. type 
  81.  
  82. DocRec = record
  83.         popupControlHdl: ControlHandle;
  84.         redHdl: ControlHandle;
  85.         whiteHdl: ControlHandle;
  86.         blueHdl: ControlHandle;
  87.         showGridHdl: ControlHandle;
  88.         showRulersHdl: ControlHandle;
  89.         okButtonHdl: ControlHandle;
  90.         vScrollbarHdl: ControlHandle;
  91.         hScrollbarHdl: ControlHandle;
  92.         end;
  93.  
  94. DocRecPointer = ^DocRec;
  95. DocRecHandle = ^DocRecPointer;
  96.  
  97. { ……………………………………………………………………………………………………………………………………………………………………………………… global variables }
  98.  
  99. var
  100.  
  101. gDone : boolean;
  102. gInBackground : boolean;
  103. menubarHdl : Handle;
  104. menuHdl : MenuHandle;
  105. myWindowPtr: WindowPtr;
  106. docRecHdl : DocRecHandle;
  107. eventRec : EventRecord;
  108.  
  109.  
  110. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoInitManagers }
  111.  
  112. procedure DoInitManagers;
  113.  
  114.     begin
  115.     MaxApplZone;
  116.     MoreMasters;
  117.  
  118.     InitGraf(@qd.thePort);
  119.     InitFonts;
  120.     InitWindows;
  121.     InitMenus;
  122.     TEInit;
  123.     InitDialogs(nil);
  124.  
  125.     InitCursor;    
  126.     FlushEvents(everyEvent, 0);
  127.     end;
  128.         {of procedure DoInitManagers}
  129.  
  130. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMenuChoice }
  131.  
  132. procedure DoMenuChoice(menuChoice : longint);
  133.  
  134.     var
  135.     menuID, menuItem : integer;
  136.     itemName : string;
  137.     daDriverRefNum : integer;
  138.     
  139.     begin
  140.     menuID := HiWord(menuChoice);
  141.     menuItem := LoWord(menuChoice);
  142.  
  143.     if (menuID = 0) then
  144.         Exit(DoMenuChoice);
  145.  
  146.     case (menuID) of
  147.  
  148.         mApple:
  149.             begin
  150.             if (menuItem = iAbout) 
  151.                 then     SysBeep(10)
  152.                 else    begin
  153.                         GetMenuItemText(GetMenuHandle(mApple), menuItem, itemName);
  154.                         daDriverRefNum := OpenDeskAcc(itemName);
  155.                         end;
  156.             end;
  157.  
  158.         mFile:
  159.             begin
  160.             if (menuItem = iQuit) then
  161.                 gDone := true;
  162.             end;
  163.         
  164.         end;
  165.             {of case statement}
  166.  
  167.     HiliteMenu(0);
  168.     end;
  169.         {of procedure DoMenuChoice}
  170.  
  171. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoPopupMenuChoice }
  172.  
  173. procedure DoPopupMenuChoice(controlValue : integer);
  174.  
  175.     begin
  176.     case (controlValue) of
  177.  
  178.         pSydney:
  179.             begin
  180.             { Action as appropriate.}
  181.             end;
  182.  
  183.         pNewYork:
  184.             begin
  185.             { Action as appropriate.}
  186.             end;
  187.  
  188.         pLondon:
  189.             begin
  190.             { Action as appropriate.}
  191.             end;
  192.  
  193.         pRome:
  194.             begin
  195.             { Action as appropriate.}
  196.             end;
  197.         end;
  198.             {of case statement}
  199.  
  200.     SysBeep(10);
  201.     end;
  202.         {of procedure DoPopupMenuChoice}
  203.  
  204. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoControls }
  205.  
  206. procedure DoControls(controlHdl : ControlHandle; docRecHdl : DocRecHandle);
  207.  
  208.     begin
  209.     if ((controlHdl = docRecHdl^^.redHdl) or (controlHdl = docRecHdl^^.whiteHdl) or
  210.              (controlHdl = docRecHdl^^.blueHdl)) 
  211.               
  212.         then    begin
  213.             SetControlValue(docRecHdl^^.redHdl, 0);
  214.             SetControlValue(docRecHdl^^.whiteHdl, 0);
  215.             SetControlValue(docRecHdl^^.blueHdl, 0);
  216.             SetControlValue(controlHdl, 1);
  217.             end
  218.         
  219.     else    if((controlHdl = docRecHdl^^.showGridHdl) or 
  220.                     (controlHdl = docRecHdl^^.showRulersHdl))
  221.                         
  222.         then    begin
  223.             if (GetControlValue(controlHdl) = 1)
  224.                 then SetControlValue(controlHdl, 0)
  225.             else SetControlValue(controlHdl, 1);
  226.             end
  227.                             
  228.     else     if ((controlHdl = docRecHdl^^.vScrollbarHdl) or 
  229.                         (controlHdl = docRecHdl^^.hScrollbarHdl))
  230.         then    {Do scroll bars handling.}
  231.                                 
  232.     else    {Must be button.  Do button handling.};
  233.  
  234.     SysBeep(10);
  235.     end;    
  236.         {of procedure DoControls}
  237.  
  238. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoInContent }
  239.  
  240. procedure DoInContent(eventRec : EventRecord; myWindowPtr : WindowPtr);
  241.  
  242.     var
  243.     controlHdl : ControlHandle;
  244.     controlValue : integer;
  245.     docRecHdl : DocRecHandle;
  246.     ignored : integer;
  247.     
  248.     begin
  249.     GlobalToLocal(eventRec.where);
  250.  
  251.     if (FindControl(eventRec.where, myWindowPtr, controlHdl) <> 0) then
  252.         begin
  253.         docRecHdl := DocRecHandle(GetWRefCon(myWindowPtr));
  254.         if (controlHdl = docRecHdl^^.popupControlHdl)
  255.             then    begin
  256.                 ignored := TrackControl(controlHdl, eventRec.where, ControlActionUPP(-1));
  257.                 controlValue := GetControlValue(controlHdl);
  258.                 DoPopupMenuChoice(controlValue);
  259.                 end
  260.                     
  261.             else    if (TrackControl(controlHdl, eventRec.where, nil) <> 0) then
  262.                         DoControls(controlHdl, docRecHdl);
  263.         end;
  264.     end;
  265.         {of procedure DoInContent}
  266.                 
  267. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoAdjustScrollBars }
  268.  
  269. procedure DoAdjustScrollBars(myWindowPtr : WindowPtr);
  270.  
  271.     var
  272.     winRect : Rect;
  273.     docRecHdl : DocRecHandle;
  274.     
  275.     begin
  276.     docRecHdl := DocRecHandle(GetWRefCon(myWindowPtr));
  277.  
  278.     winRect := myWindowPtr^.portRect;
  279.  
  280.     HideControl(docRecHdl^^.vScrollbarHdl);
  281.     HideControl(docRecHdl^^.hScrollbarHdl);
  282.  
  283.     MoveControl(docRecHdl^^.vScrollbarHdl, winRect.right - 15, winRect.top - 1);
  284.     MoveControl(docRecHdl^^.hScrollbarHdl, winRect.left -1, winRect.bottom -15);
  285.  
  286.     SizeControl(docRecHdl^^.vScrollbarHdl, 16, winRect.bottom - 13);
  287.     SizeControl(docRecHdl^^.hScrollbarHdl, winRect.right - 13, 16);
  288.  
  289.     ShowControl(docRecHdl^^.vScrollbarHdl);
  290.     ShowControl(docRecHdl^^.hScrollbarHdl);
  291.  
  292.     DrawGrowIcon(myWindowPtr);
  293.     end;
  294.         {of procedure DoAdjustScrollBars}
  295.  
  296. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoEraseGrowIcon }
  297.  
  298. procedure DoEraseGrowIcon(myWindowPtr : WindowPtr);
  299.  
  300.     var
  301.     growBoxRect : Rect;
  302.     
  303.     begin
  304.     SetPort(myWindowPtr);
  305.  
  306.     growBoxRect := myWindowPtr^.portRect;
  307.     growBoxRect.left := growBoxRect.right - 15;
  308.     growBoxRect.top := growBoxRect.bottom - 15;
  309.     EraseRect(growBoxRect);
  310.     end;
  311.         {of procedure DoEraseGrowIcon}
  312.             
  313. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMouseDown }
  314.  
  315. procedure DoMouseDown(eventRec : EventRecord);
  316.  
  317.     var
  318.     myWindowPtr : WindowPtr;
  319.     partCode : integer;
  320.     growRect : Rect;
  321.     newSize : longint;
  322.     
  323.     begin
  324.     partCode := FindWindow(eventRec.where, myWindowPtr);
  325.     
  326.     case (partCode) of
  327.  
  328.         inMenuBar:
  329.             begin
  330.             DoMenuChoice(MenuSelect(eventRec.where));
  331.             end;
  332.  
  333.         inSysWindow:
  334.             begin
  335.             SystemClick(eventRec, myWindowPtr);
  336.             end;
  337.  
  338.         inContent:
  339.             begin
  340.             if (myWindowPtr <> FrontWindow)
  341.                 then    SelectWindow(myWindowPtr)
  342.                 else    DoInContent(eventRec, myWindowPtr);
  343.             end;
  344.  
  345.         inDrag:
  346.             begin
  347.             DragWindow(myWindowPtr, eventRec.where, qd.screenBits.bounds);
  348.             end;
  349.  
  350.         inGoAway:
  351.             begin
  352.             if (TrackGoAway(myWindowPtr,eventRec.where)) then
  353.                 gDone := true;
  354.             end;
  355.  
  356.         inGrow:
  357.             begin
  358.             growRect := qd.screenBits.bounds;
  359.             growRect.top := 200; 
  360.             growRect.left := 275;
  361.             newSize := GrowWindow(myWindowPtr, eventRec.where, growRect);
  362.             if (newSize <> 0) then
  363.                 begin
  364.                 DoEraseGrowIcon(myWindowPtr);
  365.                 SizeWindow(myWindowPtr, LoWord(newSize), HiWord(newSize), true);
  366.                 DoAdjustScrollBars(myWindowPtr);
  367.                 end;
  368.             end;
  369.  
  370.         inZoomIn, inZoomOut:
  371.             begin
  372.             if (TrackBox(myWindowPtr, eventRec.where, partCode)) then
  373.                 begin
  374.                 SetPort(myWindowPtr);
  375.                 EraseRect(myWindowPtr^.portRect);
  376.                 ZoomWindow(myWindowPtr, partCode, false);
  377.                 InvalRect(myWindowPtr^.portRect);
  378.                 DoAdjustScrollBars(myWindowPtr);
  379.                 end;
  380.             end;
  381.         end;
  382.             {of case statement}
  383.     end;
  384.         {of procedure DoMouseDown}
  385.             
  386. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoUpdate }
  387.  
  388. procedure DoUpdate(eventRec : EventRecord);
  389.  
  390.     var
  391.     myWindowPtr : WindowPtr;
  392.  
  393.     begin
  394.     myWindowPtr := WindowPtr(eventRec.message);
  395.  
  396.     BeginUpdate(myWindowPtr);
  397.  
  398.     if not (EmptyRgn(myWindowPtr^.visRgn)) then
  399.         begin
  400.         SetPort(myWindowPtr);
  401.         UpdateControls(myWindowPtr, myWindowPtr^.visRgn);
  402.         DrawGrowIcon(myWindowPtr);
  403.         end;
  404.  
  405.     EndUpdate(myWindowPtr);
  406.     end;
  407.         {of procedure DoUpdate}
  408.  
  409. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoActivateWindow }
  410.  
  411. procedure DoActivateWindow(myWindowPtr : WindowPtr; becomingActive : boolean);
  412.  
  413.     var
  414.     docRecHdl : DocRecHandle;
  415.     hiliteState : integer;
  416.     
  417.     begin
  418.     docRecHdl := DocRecHandle(GetWRefCon(myWindowPtr));
  419.  
  420.     if (becomingActive) 
  421.         then hiliteState := 0
  422.         else hiliteState := 255;
  423.  
  424.     HiliteControl(docRecHdl^^.popupControlHdl, hiliteState);
  425.     HiliteControl(docRecHdl^^.redHdl,    hiliteState);
  426.     HiliteControl(docRecHdl^^.whiteHdl, hiliteState);
  427.     HiliteControl(docRecHdl^^.blueHdl, hiliteState);
  428.     HiliteControl(docRecHdl^^.showGridHdl, hiliteState);
  429.     HiliteControl(docRecHdl^^.showRulersHdl, hiliteState);
  430.     HiliteControl(docRecHdl^^.okButtonHdl, hiliteState);
  431.     HiliteControl(docRecHdl^^.vScrollbarHdl, hiliteState);
  432.     HiliteControl(docRecHdl^^.hScrollbarHdl, hiliteState);
  433.     end;
  434.         {of procedure DoActivateWindow}
  435.  
  436. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoActivate }
  437.  
  438. procedure DoActivate(eventRec : EventRecord);
  439.  
  440.     var
  441.     myWindowPtr : WindowPtr;
  442.     becomingActive : boolean;
  443.  
  444.     begin
  445.     myWindowPtr := WindowPtr(eventRec.message);
  446.  
  447.     becomingActive := (BAnd(eventRec.modifiers, activeFlag) <> 0);
  448.  
  449.     DoActivateWindow(myWindowPtr, becomingActive);
  450.     end;
  451.         {of procedure DoActivate}
  452.  
  453. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoOSEvent }
  454.  
  455. procedure DoOSEvent(eventRec : EventRecord);
  456.  
  457.     begin
  458.     case BAnd(BSR(eventRec.message, 24), $000000FF) of
  459.  
  460.         suspendResumeMessage:
  461.             begin
  462.             DrawGrowIcon(FrontWindow);
  463.             gInBackground := boolean(BAnd(eventRec.message, resumeFlag));
  464.             DoActivateWindow(FrontWindow, gInBackground);
  465.             end;
  466.                 
  467.         mouseMovedMessage:
  468.             begin
  469.             end;
  470.         
  471.         end;
  472.             {of case statement}
  473.     end;
  474.         {of procedure DoOSEvent}
  475.  
  476. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoEvents }
  477.  
  478. procedure DoEvents(eventRec : EventRecord);
  479.  
  480.     begin
  481.     case (eventRec.what) of
  482.         mouseDown:
  483.             begin
  484.             DoMouseDown(eventRec);
  485.             end;
  486.  
  487.         updateEvt:
  488.             begin
  489.             DoUpdate(eventRec);
  490.             end;
  491.  
  492.         activateEvt:
  493.             begin
  494.             DoActivate(eventRec);
  495.             end;
  496.  
  497.         osEvt:
  498.             begin
  499.             DoOSEvent(eventRec);
  500.             HiliteMenu(0);
  501.             end;
  502.         end;
  503.             {of case statement}
  504.     end;
  505.         {of procedure DoEvents}
  506.             
  507. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoGetControls }
  508.  
  509. procedure DoGetControls(myWindowPtr : WindowPtr);
  510.  
  511.     var
  512.     docRecHdl : DocRecHandle;
  513.  
  514.     begin
  515.     docRecHdl := DocRecHandle(GetWRefCon(myWindowPtr));
  516.  
  517.     with docRecHdl^^ do
  518.         begin
  519.         popupControlHdl := GetNewControl(cTimeZone, myWindowPtr);
  520.         if (popupControlHdl = nil) then
  521.             ExitToShell;
  522.         
  523.         redHdl := GetNewControl(cRed, myWindowPtr);
  524.         if (popupControlHdl = nil) then
  525.             ExitToShell;
  526.         
  527.         whiteHdl := GetNewControl(cWhite, myWindowPtr);
  528.         if (popupControlHdl = nil) then
  529.             ExitToShell;
  530.         
  531.         blueHdl := GetNewControl(cBlue, myWindowPtr);
  532.         if (popupControlHdl = nil) then
  533.             ExitToShell;
  534.         
  535.         showGridHdl := GetNewControl(cShowgrid, myWindowPtr);
  536.         if (popupControlHdl = nil) then
  537.             ExitToShell;
  538.         
  539.         showRulersHdl := GetNewControl(cShowrulers, myWindowPtr);
  540.         if (popupControlHdl = nil) then
  541.             ExitToShell;
  542.         
  543.         okButtonHdl := GetNewControl(cButton, myWindowPtr);
  544.         if (popupControlHdl = nil) then
  545.             ExitToShell;
  546.         
  547.         vScrollbarHdl := GetNewControl(cVScrollbar, myWindowPtr);
  548.         if (popupControlHdl = nil) then
  549.             ExitToShell;
  550.         
  551.         hScrollbarHdl := GetNewControl(cHScrollbar, myWindowPtr);
  552.         if (popupControlHdl = nil) then
  553.             ExitToShell;
  554.         end;
  555.             {of with statement}
  556.  
  557.     end;
  558.         {of procedure DoGetControls}
  559.  
  560. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ start of main program }
  561.  
  562. begin
  563.  
  564.     { …………………………………………………………………………………………………………………………………………………………………… initialize managers }
  565.  
  566.     DoInitManagers;
  567.  
  568.     { …………………………………………………………………………………………………………………………………………………… set up menu bar and menus }
  569.     
  570.     menubarHdl := GetNewMBar(rMenubar);
  571.     if (menubarHdl = nil) then
  572.         ExitToShell;
  573.     SetMenuBar(menubarHdl);
  574.     DrawMenuBar;
  575.  
  576.     menuHdl := GetMenuHandle(mApple);
  577.     if (menuHdl = nil) 
  578.         then ExitToShell
  579.         else AppendResMenu(menuHdl,'DRVR');
  580.  
  581.     { …………………………………………………………………………………………………………………………………………………………………………………… open a window }
  582.  
  583.     myWindowPtr := GetNewWindow(rNewWindow, nil, WindowPtr(-1));
  584.     if (myWindowPtr = nil) then
  585.         ExitToShell;
  586.     SetPort(myWindowPtr);
  587.     
  588.     { ………………… get block for document record, assign handle to window record refCon field }
  589.  
  590.     docRecHdl := DocRecHandle(NewHandle(sizeof(DocRec)));
  591.     if (docRecHdl = nil) then
  592.         ExitToShell;
  593.  
  594.     SetWRefCon(myWindowPtr, longint(docRecHdl));
  595.  
  596.     { …………………………………………………………………………………………………………………………………………… get controls and show window }
  597.         
  598.     DoGetControls(myWindowPtr);
  599.     DoAdjustScrollBars(myWindowPtr);
  600.     ShowWindow(myWindowPtr);
  601.  
  602.     { ……………………………………………………………………………………………………………………………………………………………………………… enter eventLoop }
  603.  
  604.     gDone := false;
  605.  
  606.     while not (gDone) do
  607.         if (WaitNextEvent(everyEvent, eventRec, kMaxLong, nil)) then
  608.             DoEvents(eventRec);
  609.  
  610. end.
  611.     
  612. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }