home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / MT2ToolKit 1.0b1 / Trivial / MainLoop.Trivial next >
Encoding:
Text File  |  1995-09-26  |  2.9 KB  |  133 lines  |  [TEXT/MPS ]

  1.  
  2. {%% Generation option: -l}
  3.  
  4.   PROCEDURE DoOSEvent(event: EventRecord; VAR cursorRgn: RgnHandle);
  5.   {Handling operating-system events}
  6.  
  7.     VAR
  8.       window: windowPtr;
  9.       activate: boolean;
  10.  
  11.     BEGIN
  12.       window:=FrontWindow;
  13.       CASE BSR(event.message,24) OF
  14.        mouseMovedMessage:
  15.        
  16.                {%% >> Adjust cursor <<}; 
  17.                 
  18.         suspendResumeMessage:
  19.           BEGIN
  20.             activate:=(BAnd(event.message,resumeFlag)<>0);
  21.             
  22.            {%% >> activate appl. window <<};
  23.            
  24.           END;
  25.         OTHERWISE;
  26.       END;
  27.     END; {DoOSEvent}
  28.  
  29. PROCEDURE DoMouseDown (event: EventRecord; var quit : Boolean);
  30.     VAR
  31.      part         : integer;
  32.      aWindow     : WindowPtr;
  33.      
  34.     BEGIN
  35.       part:=FindWindow(event.where,aWindow);
  36.       CASE part OF
  37. {%%*}    
  38.         InSysWindow:     SystemClick(event,aWindow);
  39.         
  40.         inDrag:         {%% >> <<};
  41.         inGoAway:         {%% >> <<};
  42.         inGrow:          {%% >> <<};
  43.         
  44.         inZoomIn, 
  45.         inZoomOut:         {%% >> handle mouse down in zoombox region <<};
  46.         
  47.         inContent:        {%% >> <<};
  48.       END; {case part of}
  49.     END; {DoMouseDown}
  50.  
  51.   PROCEDURE MainLoop;
  52.  
  53.     CONST
  54.       kReturnKey = $0D;
  55.       kEnterKey = $03;
  56.       kEscKey = 27;
  57.       
  58.  
  59.     VAR
  60.       key: Char;
  61.       quit,gotEvent,activate : Boolean;
  62.       event: EventRecord;
  63.       cursorRgn: RgnHandle;
  64.  
  65.     BEGIN
  66.       cursorRgn:=NewRgn;
  67.       quit:=false;
  68.       REPEAT
  69.         gotEvent:=WaitNextEvent(everyEvent,event,15,cursorRgn);
  70.         IF gotEvent
  71.           THEN
  72.             CASE event.what OF
  73.               osEvt: DoOSEvent(event,cursorRgn);
  74.               activateEvt: 
  75.                 BEGIN
  76.                   activate:=BAnd(event.modifiers,activeFlag)<>0;
  77.                           {%% >> <<}
  78.                 END;
  79.                 
  80.               updateEvt:     {%% >> <<};
  81.               mouseUp:         {%% >> <<};
  82.  
  83.               mouseDown: DoMouseDown (event,quit);
  84.  
  85.               keyDown,autoKey:
  86.                 BEGIN
  87.                   key:=chr(BAnd(event.message,charCodeMask));
  88.                   IF (BAnd(event.modifiers,cmdKey)<>0)
  89.                     THEN {command key down}
  90.                      {%% >> <<}
  91.                     ELSE IF key IN [chr(kReturnKey),chr(kEnterKey)]
  92.                       THEN {return or enter keys were pressed}
  93.                          {%% >> <<}
  94.                       ELSE IF (key=chr(kEscKey))
  95.                         THEN {esc key was pressed}
  96.                           BEGIN
  97.                            {%% >> <<}
  98.                           END
  99.                          ELSE 
  100.                           {%% >> <<};
  101.                  END;
  102.               diskEvt:              {%% >> <<};
  103.               nullEvent:         {%% >> <<};
  104.             END; {case}
  105.       UNTIL quit;
  106.       DisposeRgn(cursorRgn);
  107.     END; {MainLoop}
  108.  
  109.   PROCEDURE Init;
  110.     BEGIN
  111.       MaxApplZone;
  112.       MoreMasters;
  113.       MoreMasters;
  114.       MoreMasters;
  115.       MoreMasters;
  116.       MoreMasters;
  117.       MoreMasters;
  118.       
  119.       InitGraf(@thePort);
  120.       {InitFonts;}                     {%%?}
  121. {%%(}
  122.       {TEInit;}                        {%%?}
  123.       InitCursor;                     {%%?}
  124.       
  125.       {%% >> add another initialization here <<}
  126.     END; {Init}
  127.     
  128. BEGIN {program body}
  129.  Init;
  130.  MainLoop;
  131. END.
  132.  
  133.