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 / chap22pascal_demo / UMain.p < prev    next >
Text File  |  1997-01-05  |  5KB  |  248 lines

  1. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
  2. // UMain.p
  3. // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }
  4.  
  5. unit UMain;
  6.  
  7.  
  8.  
  9. interface
  10.  
  11. { ………………………………………………………………………………………………………………… include the following Universal Interfaces }
  12.  
  13. uses
  14.  
  15.     Windows, Fonts, Menus, TextEdit, Dialogs, SegLoad, ToolUtils, Devices, GestaltEqu, 
  16.     Resources, Sound, Notification, Icons, Processes, ColorPicker, Traps, LowMem, 
  17.  
  18. { ……………………………………………………………………………………………………………………… include the following user-defined units }
  19.  
  20.     UDemos;
  21.  
  22. { ………………………………………………………………………………………………………………………………………………… define the following constants }
  23.  
  24. const
  25.  
  26. mApple = 128;
  27.  iAbout = 1;
  28. mFile = 129;
  29.  iQuit = 11;
  30. mDemonstration = 131;
  31.  iCommandPeriod = 1;
  32.  iNotification = 2;
  33.  iColourPicker = 3;
  34.  iTrapAvailable = 4;
  35.  iMultiMonitors = 5;
  36.  
  37. rMenubar = 128;
  38. rWindow = 128;
  39. rAlert = 128;
  40. rDialog = 129;
  41.  iUserItem = 1;
  42. rIconFamily = 128;
  43. rBarkSound = 8192;
  44. rString = 128;
  45.  
  46. { ……………………………………………………………………………………………………………………………………………………………………………………… global variables }
  47.  
  48. var
  49.  
  50. gColorQuickDraw : boolean;
  51. gDone : boolean;
  52. gWindowPtr : WindowPtr;
  53. gProcessSerNum : ProcessSerialNumber;
  54. gMultiMonitorsDrawDemo : boolean;
  55.  
  56.     procedure DoInitManagers;
  57.     procedure DoEvents(theEvent : EventRecord);
  58.     procedure DoMouseDown(theEvent : EventRecord);
  59.     procedure  DoMenuChoice(menuChoice : longint);
  60.     procedure UnloadSegments;
  61.  
  62.  
  63.  
  64. implementation
  65.  
  66. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoInitManagers }
  67.  
  68. procedure DoInitManagers;
  69.  
  70.     begin
  71.     MaxApplZone;
  72.     MoreMasters;
  73.  
  74.     InitGraf(@qd.thePort);
  75.     InitFonts;
  76.     InitWindows;
  77.     InitMenus;
  78.     TEInit;
  79.     InitDialogs(nil);
  80.  
  81.     InitCursor;    
  82.     FlushEvents(everyEvent, 0);
  83.     end;
  84.         {of procedure DoInitManagers}
  85.  
  86. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoEvents }
  87.  
  88. procedure DoEvents(theEvent : EventRecord);
  89.  
  90.     var
  91.     theWindowPtr : WindowPtr;
  92.     userData : longint;
  93.  
  94.     begin
  95.     case (theEvent.what) of
  96.  
  97.         mouseDown: begin
  98.             DoMouseDown(theEvent);
  99.             end;
  100.  
  101.         updateEvt: begin
  102.             theWindowPtr := WindowPtr(theEvent.message);
  103.  
  104.             BeginUpdate(theWindowPtr);
  105.             if (gMultiMonitorsDrawDemo = true) then
  106.                 begin
  107.                 userData := longint(theWindowPtr);
  108.                 DeviceLoop(theWindowPtr^.visRgn, DeviceLoopDrawingUPP(@DoDeviceLoopDraw), 
  109.                             userData, 0);
  110.                 end;
  111.             EndUpdate(theWindowPtr);
  112.             end;
  113.  
  114.         osEvt: begin
  115.             DoOSEvent(theEvent);
  116.             HiliteMenu(0);
  117.             end;
  118.         end;
  119.             {of case statement}
  120.     end;
  121.         {of procedure DoInitManagers}
  122.  
  123. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMouseDown }
  124.  
  125. procedure DoMouseDown(theEvent : EventRecord);
  126.  
  127.     var
  128.     partCode : integer;
  129.     theWindowPtr : WindowPtr;
  130.  
  131.     begin
  132.     partCode := FindWindow(theEvent.where, theWindowPtr);
  133.  
  134.     case (partCode) of
  135.  
  136.         inMenuBar: begin
  137.             DoMenuChoice(MenuSelect(theEvent.where));
  138.             end;
  139.  
  140.         inSysWindow: begin
  141.             SystemClick(theEvent, theWindowPtr);
  142.             end;
  143.  
  144.         inContent: begin
  145.             if (theWindowPtr <> FrontWindow) then
  146.                 SelectWindow(theWindowPtr);
  147.             end;
  148.  
  149.         inDrag: begin
  150.             DragWindow(theWindowPtr, theEvent.where, qd.screenBits.bounds);
  151.             end;
  152.         
  153.         inZoomIn, inZoomOut: begin
  154.             if (TrackBox(theWindowPtr, theEvent.where, partCode)) then
  155.                 DoZoomWindowMultiMonitors(theWindowPtr, partCode);
  156.             end;
  157.         end;
  158.             {of case statement}
  159.     end;
  160.         {of procedure DoInitManagers}
  161.  
  162. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMenuChoice }
  163.  
  164. procedure DoMenuChoice(menuChoice : longint);
  165.  
  166.     var
  167.     menuID, menuItem : integer;
  168.     itemName : string;
  169.     daDriverRefNum : integer;
  170.  
  171.     begin
  172.     menuID := HiWord(menuChoice);
  173.     menuItem := LoWord(menuChoice);
  174.  
  175.     if (menuID = 0) then
  176.         Exit(DoMenuChoice);
  177.  
  178.     case (menuID) of
  179.  
  180.         mApple: begin
  181.             if (menuItem = iAbout) then
  182.                 SysBeep(10)
  183.             else begin
  184.                 GetMenuItemText(GetMenuHandle(mApple), menuItem, itemName);
  185.                 daDriverRefNum := OpenDeskAcc(itemName);
  186.                 end;
  187.             end;
  188.  
  189.         mFile: begin
  190.             if (menuItem = iQuit) then
  191.                 gDone := true;
  192.             end;
  193.  
  194.         mDemonstration: begin
  195.             gMultiMonitorsDrawDemo := false;
  196.             case (menuItem) of
  197.             
  198.                 iCommandPeriod: begin
  199.                     DoCommandPeriodAndStatusBar;
  200.                     end;
  201.  
  202.                 iNotification: begin
  203.                     EraseRect(gWindowPtr^.portRect);
  204.                     DoSetUpNotification;
  205.                     end;
  206.  
  207.                 iColourPicker: begin
  208.                     DoColourPicker;
  209.                     end;
  210.  
  211.                 iTrapAvailable: begin
  212.                     EraseRect(gWindowPtr^.portRect);
  213.                     MoveTo(150, 110);
  214.                     if (DoCheckSlotVInstallAvailable) then
  215.                         DrawString('Trap is available')
  216.                     else
  217.                         DrawString('Trap is not available');
  218.                     end;
  219.                     
  220.                 iMultiMonitors: begin
  221.                     EraseRect(gWindowPtr^.portRect);
  222.                     gMultiMonitorsDrawDemo := true;
  223.                     InvalRect(gWindowPtr^.portRect);
  224.                     end;
  225.                 end;
  226.                     {of case statement}
  227.             end;
  228.         end;
  229.             {of case statement}
  230.             
  231.     HiliteMenu(0);
  232.     end;
  233.         {of procedure DoMenuChoice}
  234.  
  235. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ UnloadSegments }
  236.  
  237. procedure UnloadSegments;
  238.  
  239.     begin
  240.     UnloadSeg(@DemosSegment);
  241.     end;
  242.         {of procedure UnloadSegments}
  243.  
  244. end.
  245.     {of unit UMain}
  246.     
  247. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }
  248.