home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 January / macformat46.iso / Shareware Plus / Developers / Library / Grant's CGI Framework / Grant's CGI Framework / Project Files / MyHandlers.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-20  |  7.2 KB  |  316 lines

  1. /*****
  2.  *
  3.  *    MyHandlers.c
  4.  *
  5.  *    Optional custom functions to handle special events. Includes:
  6.  *        document opening, startup and quitting
  7.  *
  8.  *    Modify these functions if you need to add to the standard support
  9.  *    built into the framework.
  10.  *
  11.  *    The function prototypes are contained in the relevent headers.
  12.  *    For example, AEHandlers.h contains the prototype for CustomOpenDocument
  13.  *
  14.  *    This is a support file for "Grant's CGI Framework".
  15.  *    Please see the license agreement that accompanies the distribution package
  16.  *    for licensing details.
  17.  *
  18.  *    Copyright ©1995,1996 by Grant Neufeld
  19.  *    grant@acm.com
  20.  *    http://arpp.carleton.ca/cgi/framework/
  21.  *
  22.  *****/
  23.  
  24. #include "MyConfiguration.h"
  25.  
  26. #if kCompileWithDragNDrop
  27. #include <Drag.h>
  28. #endif
  29.  
  30. #include "AEHandlers.h"
  31. #include "CGI.h"
  32. #include "CustomHandlers.h"
  33. #include "DebugUtil.h"
  34. #include "EventUtil.h"
  35. #include "ListSTAR.h"
  36. #include "ProcessUtil.h"
  37. #include "Quit.h"
  38. #include "Startup.h"
  39. #include "WindowInt.h"
  40.  
  41.  
  42. /***  FUNCTIONS  ***/
  43.  
  44. /* The application is expected to open the given document, if possible */
  45. OSErr
  46. CustomOpenDocument ( FSSpec *theFile )
  47. {
  48.     OSErr    theErr;
  49.     
  50.     my_assert ( theFile != NULL, "\pCustomOpenDocument: theFile ptr is NULL" );
  51.     
  52.     theErr = noErr;
  53.     
  54.     return theErr;
  55. } /* CustomOpenDocument */
  56.  
  57.  
  58. /**  WINDOWS  **/
  59. #pragma mark -
  60.  
  61. #pragma segment Utilities
  62. /* Close any custom application windows */
  63. #if kCompileWithApplicationWindows
  64. OSErr
  65. CustomCloseWindow ( WindowPtr theWindow )
  66. {
  67.     OSErr    theErr;
  68.     
  69.     theErr = noErr;
  70.     
  71.     return theErr;
  72. } /* CustomCloseWindow */
  73. #endif
  74.  
  75.  
  76. /* If activate is true, restore theWindow's selections.
  77.     If activate is false, hide, or reduce to outline, theWindow's selections.
  78.     If theWindow has a grow box in the bottom right corner,
  79.     you should invalidate the growrect */
  80. #if kCompileWithApplicationWindows
  81. void
  82. CustomActivateWindow ( WindowPtr theWindow, Boolean activate )
  83. {
  84.     
  85. } /* CustomActivateWindow */
  86. #endif
  87.  
  88.  
  89. /* Draw contents of window on an update event */
  90. #if kCompileWithApplicationWindows
  91. void
  92. CustomUpdateWindow ( WindowPtr theWindow )
  93. {
  94.     
  95. } /* CustomUpdateWindow */
  96. #endif
  97.  
  98.  
  99. /* Support a click in a window.
  100.     If the click is on a dragable item, set onDragItem to true. */
  101. #if kCompileWithApplicationWindows
  102. void
  103. CustomClickInWindow ( WindowPtr theWindow, Point thePoint, Boolean *onDragItem )
  104. {
  105.     
  106. } /* CustomClickInWindow */
  107. #endif
  108.  
  109.  
  110. /* Grow the window */
  111. #if kCompileWithApplicationWindows
  112. void
  113. CustomGrowWindow ( WindowPtr theWindow, Point thePoint )
  114. {
  115.     /* this call is in here by default. You can replace it with your own custom
  116.         handler if you want */
  117.     WindowGrowHandler ( theWindow, thePoint );
  118. } /* CustomGrowWindow */
  119. #endif
  120.  
  121.  
  122. /* Handle Idle time tasks for a window. */
  123. #if kCompileWithApplicationWindows
  124. void
  125. CustomWindowIdle ( WindowPtr theWindow )
  126. {
  127.     
  128. } /* CustomWindowIdle */
  129. #endif
  130.  
  131.  
  132. /* If you add windows that allow for text entry or you accept non-command-key
  133.     keyboard input, you need to support this function. */
  134. #if kCompileWithKeyboardEvents
  135. void
  136. CustomKeyPress ( EventRecord *theEvent )
  137. {
  138.     
  139. } /* CustomKeyPress */
  140. #endif
  141.  
  142.  
  143. /*  */
  144. #if kCompileWithDragNDrop
  145. OSErr
  146. CustomDoStartDrag ( EventRecord *theEvent, WindowPtr theWindow )
  147. {
  148.     OSErr            theErr;
  149.     GrafPtr            savePort;
  150.     DragReference    theDrag;
  151.     RgnHandle        dragRegion;
  152.     
  153.     GetPort ( &savePort );
  154.     SetPort ( (GrafPtr)theWindow );
  155.     
  156.     theErr = NewDrag ( &theDrag );
  157.     
  158.     if ( theErr == noErr )
  159.     {
  160.         dragRegion = NewRgn ();
  161.         
  162.         /* ••• You need to call a function that sets up the drag values such as:
  163.             theErr = customSetupDrag ( theWindow, theDrag, dragRegion, theEvent->where ); */
  164.     }
  165.     else
  166.     {
  167.         theDrag = nil;
  168.     }
  169.     
  170.     SetPort ( savePort );
  171.     
  172.     theErr = TrackDrag ( theDrag, theEvent, dragRegion );
  173.     
  174.     if ( dragRegion != CustomOpenDocument )
  175.     {
  176.         DisposeRgn ( dragRegion );
  177.     }
  178.     
  179.     if ( theDrag != nil )
  180.     {
  181.         DisposeDrag ( theDrag );
  182.     }
  183.         
  184.     return theErr;
  185. } /* CustomDoStartDrag */
  186. #endif
  187.  
  188.  
  189. /* This will be called if you have a dialog window (that is either modeless or
  190.     moveable-modal) that receives a mouseDown */
  191. #if kCompileWithApplicationWindows
  192. void
  193. CustomDialogMouseDown ( EventRecord *theEvent, DialogPtr theDialog, short itemHit )
  194. {
  195.     
  196. } /* CustomDialogMouseDown */
  197. #endif
  198.  
  199.  
  200. /**  OTHER TASKS  **/
  201. #pragma mark -
  202.  
  203. /* The prototype for this function is in "ProcessUtil.h" */
  204. #if kCompileWithPeriodicTask
  205. void
  206. CustomPeriodicTask ( void )
  207. {
  208.     //•••WARNING: THIS DOESN'T EXECUTE EXCEPT WHEN COMPILING AS WEBSTAR PLUG-IN.
  209.     //    THIS WILL BE FIXED IN A FUTURE VERSION
  210.     
  211. } /* CustomPeriodicTask */
  212. #endif
  213.  
  214.  
  215.  
  216. /* The prototype for this function is in "ProcessUtil.h" */
  217. #if kCompileWithDeferredTask
  218. void
  219. CustomDeferredTask ( void )
  220. {
  221.     //•••WARNING: THIS DOESN'T EXECUTE IF COMPILING AS WEBSTAR PLUG-IN.
  222.     //    THIS WILL BE FIXED IN A FUTURE VERSION
  223.     
  224. } /* CustomDeferredTask */
  225. #endif
  226.  
  227.  
  228. /**  STARTUP / SHUTDOWN  **/
  229. #pragma mark -
  230.  
  231. #pragma segment Startup
  232. /* Put any of the initialization you need done, here.
  233.     This function will be called once:
  234.         for CGIs: in-between the startup sequence and the main event loop
  235.         for plug-ins: as part of the WSAPI_Init event
  236.     Return noErr / WSAPI_I_NoErr if the initialization was successful,
  237.     otherwise return an error value.
  238.     
  239.     If compiling as a normal CGI:
  240.         Add things like installing additional AppleEvent handlers in this function.
  241.         commandPtr is not available (WSAPI only).
  242.         An error result will cause the application to quit.
  243.     
  244.     If compiling as a WSAPI plug-in:
  245.         Do not make any interface calls or other calls that cannot be handled by
  246.         the WSAPI unless you wrap those calls in
  247.             #if !(kCompilingForWSAPI)
  248.             ...
  249.             #endif
  250.         Do not call ProcessGiveTime unless you want to modify the function
  251.         'WSAPI_Dispatch' in "CGI.c" to not change the resource file reference,
  252.         in which case you will be responsible for setting the resource ref
  253.         if you need to access resources in your own (and not the server's)
  254.         resource fork.
  255.         commandPtr is available. See WSAPI documentation for details.
  256.         An error result will cause the plug-in to not be loaded by the server.
  257.         Any memory allocation or deallocation must be done using direct WSAPI
  258.         calls */
  259. SInt32
  260. CustomStartup (
  261.     #if kCompilingForWSAPI
  262.         WSAPI_CommandPBPtr commandPtr
  263.     #else
  264.         void
  265.     #endif
  266.     )
  267. {
  268.     #if kCompilingForWSAPI
  269.     /* remove or comment-out this line if you use commandPtr */
  270.     #pragma unused(commandPtr)
  271.     #endif
  272.     
  273.     SInt32    theErr;
  274.     
  275.     /* these really have not difference - since both constants equal zero */
  276.     #if kCompilingForWSAPI
  277.     theErr = WSAPI_I_NoErr;
  278.     #else
  279.     theErr = noErr;
  280.     #endif
  281.     
  282.     return theErr;
  283. } /* CustomStartup */
  284.  
  285.  
  286. #pragma segment Main
  287. /* This function is called at quitting time. Put any cleanup you need to do in it.
  288.     Return true if you are successful.
  289.     Return false if you are unable to quit for some reason (this generally only
  290.     applies when the user cancels).
  291.     allowUserInteract specifies whether you can make user interface calls.
  292.     However, CGIs generally should not rely on any user interface calls, so don't
  293.     depend on them. */
  294. Boolean
  295. CustomQuit ( Boolean allowUserInteract )
  296. {
  297.     /* remove or comment-out the following line if you use the allowUserInteract param */
  298.     #pragma unused(allowUserInteract)
  299.     
  300.     return true;
  301. } /* CustomQuit */
  302.  
  303.  
  304. #pragma segment Main
  305. /* this function is called if some sort of emergency has arisen.
  306.     What you're basically being asked to do is release any memory,
  307.     resources, files, etc. that you can. */
  308. void
  309. CustomEmergencyHandler ( void )
  310. {
  311.     
  312. } /* CustomEmergencyHandler */
  313.  
  314.  
  315. /*****  EOF  *****/
  316.