home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Snippets / PNL Libraries / MyCursors.p < prev    next >
Encoding:
Text File  |  1997-01-17  |  4.4 KB  |  194 lines  |  [TEXT/CWIE]

  1. unit MyCursors;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Types, Lists, Dialogs, StandardFile, QuickDraw;
  7.  
  8.     procedure StartupCursors;
  9.     procedure CursorSet (c: Cursor);
  10.     procedure CursorSetArrow;
  11.     procedure CursorSetIBeam;
  12.     procedure CursorSetCross;
  13.     procedure CursorSetPlus;
  14.     procedure CursorSetWatch;
  15.     procedure CursorSetProcessing (processing: boolean);
  16.     procedure CursorStandardGetFile(fileFilter:FileFilterUPP;numTypes:integer;typeList:SFTypeList;var reply:StandardFileReply);
  17.     procedure CursorStandardPutFile(prompt:Str255;defaultName:Str255;var reply:StandardFileReply);
  18.     procedure SetEnableCursorTask( enable: boolean );
  19.     
  20. implementation
  21.  
  22.     uses
  23.         Processes, GestaltEqu, ToolUtils, LowMem, Events, 
  24.         MyTypes, MyTimeManager, MySystemGlobals, MyStartup;
  25.  
  26.     const
  27.         watch_delay_time = 1800; { ms }
  28.         cursor_task_time = 200; { ms }
  29.  
  30. {$ifc do_debug}
  31.     var
  32.         startup_check: integer;
  33. {$endc}
  34.  
  35.     var
  36.         state: (S_Leave, S_Waiting, S_Watch);
  37.         ibeam, cross, plus, watch: Cursor;
  38.         current_cursor: Cursor;
  39.         xtm: XTMTask;
  40.         gCursorTaskProc:UniversalProcPtr;
  41.         watch_time:longint;
  42.         last_processing:Boolean;
  43.         cursor_enabled: boolean;
  44.         
  45.     procedure UpdateCursor;
  46.     begin
  47.         if in_foreground then begin
  48.             if state = S_Watch then begin
  49.                 SetCursor(watch);
  50.             end else begin
  51.                 SetCursor(current_cursor);
  52.             end;
  53.         end;
  54.     end;
  55.  
  56.     procedure CursorTask (xtm: XTMTaskPtr);
  57.     begin
  58.         AssertDidStartup( startup_check );
  59.         if (state = S_Waiting) & (LMGetTicks > watch_time) then begin
  60.             state := S_Watch;
  61.             UpdateCursor;
  62.         end;
  63.         XPrimeTime(xtm, gCursorTaskProc, cursor_task_time);
  64.     end;
  65.  
  66.     procedure CursorSet (c: Cursor);
  67.     begin
  68.         current_cursor := c;
  69.         UpdateCursor;
  70.     end;
  71.  
  72.     procedure CursorSetArrow;
  73.     begin
  74.         CursorSet(GetQDGlobals^.arrow);
  75.     end;
  76.  
  77.     procedure CursorSetIBeam;
  78.     begin
  79.         CursorSet(ibeam);
  80.     end;
  81.  
  82.     procedure CursorSetCross;
  83.     begin
  84.         CursorSet(cross);
  85.     end;
  86.  
  87.     procedure CursorSetPlus;
  88.     begin
  89.         CursorSet(plus);
  90.     end;
  91.  
  92.     procedure CursorSetWatch;
  93.     begin
  94.         CursorSet(watch);
  95.     end;
  96.  
  97.     procedure CursorSetProcessing (processing: boolean);
  98.     begin
  99.         if processing <> last_processing then begin
  100.             if processing then begin
  101.                 watch_time := TickCount + watch_delay_time;
  102.                 state := S_Waiting;
  103.             end else begin
  104.                 state := S_Leave;
  105.             end;
  106.             last_processing := processing;
  107.         end;
  108.         UpdateCursor;
  109.     end;
  110.  
  111.     function CursorAlert (alertID: integer; filterProc: ModalFilterUPP): integer;
  112.     begin
  113.         CursorSetArrow;
  114.         CursorSetProcessing(false);
  115.         CursorAlert := Alert(alertID, filterProc);
  116.     end;
  117.  
  118.     function CursorCautionAlert (alertID: integer; filterProc: ModalFilterUPP): integer;
  119.     begin
  120.         CursorSetArrow;
  121.         CursorSetProcessing(false);
  122.         CursorCautionAlert := CautionAlert(alertID, filterProc);
  123.     end;
  124.  
  125.     function CursorNoteAlert (alertID: integer; filterProc: ModalFilterUPP): integer;
  126.     begin
  127.         CursorSetArrow;
  128.         CursorSetProcessing(false);
  129.         CursorNoteAlert := NoteAlert(alertID, filterProc);
  130.     end;
  131.  
  132.     function CursorStopAlert (alertID: integer; filterProc: ModalFilterUPP): integer;
  133.     begin
  134.         CursorSetArrow;
  135.         CursorSetProcessing(false);
  136.         CursorStopAlert := StopAlert(alertID, filterProc);
  137.     end;
  138.  
  139.     procedure CursorStandardGetFile(fileFilter:FileFilterUPP;numTypes:integer;typeList:SFTypeList;var reply:StandardFileReply);
  140.     begin
  141.         CursorSetArrow;
  142.         CursorSetProcessing(false);
  143.         StandardGetFile(fileFilter,numTypes,@typeList,reply);
  144.     end;
  145.  
  146.     procedure CursorStandardPutFile(prompt:Str255;defaultName:Str255;var reply:StandardFileReply);
  147.     begin
  148.         CursorSetArrow;
  149.         CursorSetProcessing(false);
  150.         StandardPutFile(prompt,defaultName,reply);
  151.     end;
  152.     
  153.     procedure SetEnableCursorTask( enable: boolean );
  154.     begin
  155.         if cursor_enabled <> enable then begin
  156.             cursor_enabled := enable;
  157.             if enable then begin
  158.                 XInsertTime(@xtm);
  159.                 XPrimeTime(@xtm, gCursorTaskProc, cursor_task_time);
  160.             end else begin
  161.                 XRemoveTime(@xtm);
  162.             end;
  163.         end;
  164.     end;
  165.     
  166.     function InitCursors(var msg: integer): OSStatus;
  167.     begin
  168. {$unused(msg)}
  169.         DidStartup( startup_check );
  170.         gCursorTaskProc:=NewXTimerProc(@CursorTask);
  171.         state := S_Leave;
  172.         ibeam := GetCursor(iBeamCursor)^^;
  173.         cross := GetCursor(crossCursor)^^;
  174.         plus := GetCursor(plusCursor)^^;
  175.         watch := GetCursor(watchCursor)^^;
  176.         current_cursor := GetQDGlobals^.arrow;
  177.         last_processing := false;
  178.         cursor_enabled := false;
  179.         SetEnableCursorTask( true );
  180.         InitCursors := noErr;
  181.     end;
  182.  
  183.     procedure FinishCursors;
  184.     begin
  185.         SetEnableCursorTask( false );
  186.     end;
  187.  
  188.     procedure StartupCursors;
  189.     begin
  190.         StartupTimeManager;
  191.         SetStartup(InitCursors, nil, 0, FinishCursors);
  192.     end;
  193.     
  194. end.