home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / progrmng / transklc.sit / TransSkel.c.bin / TransSkel.c
Encoding:
C/C++ Source or Header  |  1989-02-09  |  36.2 KB  |  1,500 lines  |  [TEXT/KAHL]

  1. /*
  2.     TransSkel version 2.01 - Transportable application skeleton
  3.     
  4.     TransSkel is public domain and was originally written by:
  5.  
  6.                 Paul DuBois
  7.                 Wisconsin Regional Primate Research Center
  8.                 1220 Capital Court
  9.                 Madison WI  53715-1299  USA
  10.  
  11.     UUCP:        {allegra,uunet}!uwvax!rhesus!dubois
  12.     Internet:    dubois@primate.wisc.edu
  13.             
  14.     Additional changes were made by
  15.         
  16.                 Owen Hartnett
  17.                 OHM Software Company
  18.                 163 Richard Drive
  19.                 Tiverton, RI 02878  USA
  20.             
  21.     UUCP:        {allegra,uunet}!brunix!omh    
  22.     Internet:    omh@cs.brown.edu
  23.     CSNET:        omh@cs.brown.edu.CSNET         
  24.  
  25.     Owen is also responsible for the port to Lightspeed Pascal.
  26.     
  27.     This version of TransSkel written for LightspeedC.  LightspeedC is a
  28.     trademark of:
  29.             THINK Technologies, Inc
  30.             420 Bedford Street  Suite 350
  31.             Lexington, MA  02173  USA
  32.  
  33.     Change history is in TSHistory.c
  34. */
  35.  
  36.  
  37. /*
  38.     The following symbol controls support for dialogs.
  39.     "#define    supportDialogs" enables support.
  40.     "#undef        supportDialogs" disables support.
  41. */
  42.  
  43. # define    supportDialogs
  44.  
  45.  
  46. # ifdef        supportDialogs
  47. #    include    <DialogMgr.h>
  48. # else
  49. #    include    <WindowMgr.h>
  50. # endif
  51.  
  52. # include    <EventMgr.h>
  53. # include    <MenuMgr.h>
  54.  
  55.  
  56. /*
  57.     Integer and Longint should be typedef'd to the 2-byte and 4-byte
  58.     integer types for the compiler being used.  These are int and long
  59.     for LightspeedC.
  60. */
  61.  
  62. typedef int        Integer;
  63. typedef long    Longint;
  64.  
  65.  
  66. # define    nil            0L
  67. # define    mBarHeight    20    /* menu bar height.  All window sizing
  68.                                code takes this into account */
  69.  
  70.  
  71. /*
  72.     New(TypeName) returns handle to new object, for any TypeName.
  73.     If there is insufficient memory, the result is nil.
  74. */
  75.  
  76. # define    New(x)    (x **) NewHandle ((Size) sizeof (x))
  77.  
  78.  
  79.  
  80. /*
  81.     Window and Menu handler types, constants, variables.
  82.  
  83.     whList and mhList are the lists of window and menu handlers.
  84.     whClobOnRmve and mhClobOnRmve are true if the handler disposal proc
  85.     is to be called when a handler is removed.  They are temporarily set
  86.     false when handlers are installed for windows or menus that already
  87.     have handlers - the old handler is removed WITHOUT calling the
  88.     disposal proc.
  89.  
  90.     Default lower limits on window sizing of 80 pixels both directions is
  91.     sufficient to allow text windows room to draw a grow box and scroll
  92.     bars without having the thumb and arrows overlap.  These values may
  93.     be changed if such a constraint is undesirable with SkelGrowBounds.
  94.     Default upper limits are for the Macintosh, not the Lisa, but are set
  95.     per machine in SkelInit.
  96. */
  97.  
  98. typedef struct WHandler    WHandler;
  99.  
  100. struct WHandler
  101. {
  102.     WindowPtr    whWind;            /* window/dialog to be handled  */
  103.     ProcPtr        whClobber;        /* data structure disposal proc */
  104.     ProcPtr        whMouse;        /* mouse-click handler proc     */
  105.     ProcPtr        whKey;            /* key-click handler proc       */
  106.     ProcPtr        whUpdate;        /* update handler proc          */
  107.     ProcPtr        whActivate;        /* activate event handler proc  */
  108.     ProcPtr        whClose;        /* close "event" handler proc   */
  109.     ProcPtr        whIdle;            /* main loop proc               */
  110. # ifdef    supportDialogs
  111.     ProcPtr        whEvent;        /* event proc                   */
  112. # endif
  113.     Rect        whGrow;            /* limits on window sizing      */
  114.     Boolean        whSized;        /* true = window was resized    */
  115.     Boolean        whFrontOnly;    /* true = idle only when active */
  116.     WHandler    **whNext;        /* next window handler          */
  117. };
  118.  
  119. static WHandler    **whList = nil;
  120. static Boolean    whClobOnRmve = true;
  121. static Rect        growRect = { 80, 80, 512, 342 - mBarHeight };
  122.  
  123. typedef struct MHandler    MHandler;
  124.  
  125. struct MHandler
  126. {
  127.     Integer        mhID;            /* menu id                     */
  128.     ProcPtr        mhSelect;        /* item selection handler proc */
  129.     ProcPtr        mhClobber;        /* menu disposal handler proc  */
  130.     MHandler    **mhNext;        /* next menu handler           */
  131. };
  132.  
  133.  
  134. static MHandler    **mhList = nil;            /* list of menu handlers */
  135. static Boolean    mhClobOnRmve = true;
  136.  
  137.  
  138. /*
  139.     Variables for default Apple menu handler.  appleID is set to 1 if
  140.     SkelApple is called and is the id of the Apple menu, appleAboutProc
  141.     is the procedure to execute if there is an About... item and it's
  142.     chosen from the Apple menu.  If doAbout is true, then the menu
  143.     contains the About... item, otherwise it's just desk accessories.
  144. */
  145.  
  146. static MenuHandle    appleMenu;
  147. static Integer        appleID = 0;
  148. static ProcPtr        appleAboutProc = nil;
  149. static Boolean        doAbout = false;
  150.  
  151.  
  152. /*
  153.     Miscellaneous
  154.  
  155.     screenPort points to the window manager port.
  156.  
  157.     doneFlag determines when SkelMain returns.  It is set by calling
  158.     SkelWhoa(), which is how the host requests a halt.
  159.  
  160.     pBkgnd points to a background procedure, to be run during event
  161.     processing.  Set it with SkelBackground.  If nil, there's no
  162.     procedure.
  163.  
  164.     pEvent points to an event-inspecting hook, to be run whenever an
  165.     event occurs.  Set it with SkelEventHook.  If nil, there's no
  166.     procedure.
  167.  
  168.     eventMask controls the event types requested in the GetNextEvent
  169.     call in SkelMain.
  170.  
  171.     diskInitPt is the location at which the disk initialization dialog
  172.     appears, if an uninitialized disk is inserted.
  173. */
  174.  
  175. static GrafPtr    screenPort;
  176. static Integer    doneFlag = false;
  177. static ProcPtr    pBkgnd = nil;
  178. static Boolean    (*pEvent)() = nil;
  179. static Integer    eventMask = everyEvent;
  180. static Point    diskInitPt = { /* v = */ 120, /* h = */ 100 };
  181.  
  182. static WindowPtr    oldWindow = nil;     
  183. static WHandler        **oldWDHandler = nil;
  184.     
  185.  
  186. # ifdef    supportDialogs
  187.  
  188. /*
  189.     dlogEventMask specifies events that are passed to dialogs.
  190.     Others are ignored.  Standard mask passes, mousedown, keydown,
  191.     autokey, update, activate and null events.  Null events are
  192.     controlled by bit 0 (always forced on).
  193. */
  194.  
  195. static Integer    dlogEventMask = 0x16b;
  196.  
  197. # endif
  198.  
  199.  
  200. /* -------------------------------------------------------------------- */
  201. /*                        Internal (private) Routines                        */
  202. /* -------------------------------------------------------------------- */
  203.  
  204.  
  205. /*
  206.     Get handler associated with user or dialog window.
  207.     Return nil if window doesn't belong to any known handler.
  208.     This routine is absolutely fundamental to TransSkel.
  209. */
  210.  
  211.  
  212. static WHandler **GetWDHandler (theWind)
  213. WindowPtr    theWind;
  214. {
  215. register WHandler    **h;
  216.  
  217.     if (theWind == oldWindow) 
  218.         return(oldWDHandler);        /* return handler of cached window */
  219.  
  220.     for (h = whList; h != nil; h = (**h).whNext)
  221.     {
  222.         if ((**h).whWind == theWind)
  223.         {
  224.             oldWindow = theWind;    /* set cached window and handler */
  225.             oldWDHandler = h;
  226.             return (h);
  227.         }
  228.     }
  229.     return (nil);
  230. }
  231.  
  232.  
  233. /*
  234.     Get handler associated with user window.
  235.     Return nil if window doesn't belong to any known handler.
  236.     The order of the two tests is critical:  theWind might be nil.
  237. */
  238.  
  239. static WHandler **GetWHandler (theWind)
  240. WindowPtr    theWind;
  241. {
  242. register WHandler    **h;
  243.  
  244.     if ((h = GetWDHandler (theWind)) != nil
  245.         && ((WindowPeek) theWind)->windowKind != dialogKind)
  246.     {
  247.             return (h);
  248.     }
  249.     return (nil);
  250. }
  251.  
  252.  
  253. # ifdef    supportDialogs
  254.  
  255. /*
  256.     Get handler associated with dialog window.
  257.     Return nil if window doesn't belong to any known handler.
  258.     The order of the two tests is critical:  theDialog might be nil.
  259. */
  260.  
  261. static WHandler **GetDHandler (theDialog)
  262. DialogPtr    theDialog;
  263. {
  264. register WHandler    **h;
  265.  
  266.     if ((h = GetWDHandler (theDialog)) != nil
  267.         && ((WindowPeek) theDialog)->windowKind == dialogKind)
  268.     {
  269.             return (h);
  270.     }
  271.     return (nil);
  272. }
  273.  
  274. # endif
  275.  
  276.  
  277. /*
  278.     General menu-handler.  Just passes selection to the handler's
  279.     select routine.  If the select routine is nil, selecting items from
  280.     the menu is a nop.
  281. */
  282.  
  283. static DoMenuCommand (command)
  284. Longint        command;
  285. {
  286. register Integer    menu;
  287. register Integer    item;
  288. register MHandler    **mh;
  289. register ProcPtr    p;
  290.  
  291.     menu = HiWord (command);
  292.     item = LoWord (command);
  293.     for (mh = mhList; mh != nil; mh = (**mh).mhNext)
  294.     {
  295.         if ((menu == (**mh).mhID) && ((p = (**mh).mhSelect) != nil))
  296.         {
  297.             (*p) (item);
  298.             break;
  299.         }
  300.     }
  301.     HiliteMenu (0);        /* command done, turn off menu hiliting */
  302. }
  303.  
  304.  
  305. /*
  306.     Apple menu handler
  307.     
  308.     DoAppleItem:  If the first item was chosen, and there's an "About..."
  309.     item, call the procedure associated with it (if not nil).  If there
  310.     is no "About..." item or the item was not the first one, then open
  311.     the associated desk accessory.  The port is saved and restored
  312.     because OpenDeskAcc does not always preserve it correctly.
  313.     
  314.     DoAppleClobber disposes of the Apple menu.
  315. */
  316.  
  317.  
  318. static DoAppleItem (item)
  319. Integer    item;
  320. {
  321. GrafPtr    curPort;
  322. Str255    str;
  323. Handle    h;
  324.  
  325.     if (doAbout && item == 1)
  326.     {
  327.         if (appleAboutProc != nil)
  328.             (*appleAboutProc) ();
  329.     }
  330.     else
  331.     {
  332.         GetPort (&curPort);
  333.         GetItem (appleMenu, item, str);        /* get DA name */
  334.         SetResLoad (false);
  335.         h = GetNamedResource ('DRVR', str);
  336.         SetResLoad (true);
  337.         if (h != nil)
  338.         {
  339.             ResrvMem (SizeResource (h) + 0x1000);
  340.             (void) OpenDeskAcc (str);            /* open it */
  341.         }
  342.         SetPort (curPort);
  343.     }
  344. }
  345.  
  346. static DoAppleClobber () { DisposeMenu (appleMenu); }
  347.  
  348.  
  349. /* -------------------------------------------------------------------- */
  350. /*                        Window-handler routing routines                    */
  351. /*                                                                        */
  352. /*    See manual for discussion of port-setting behavior.  In general,    */
  353. /*    the current port is made to associate with the active window.        */
  354. /*    This is done in DoActivate for non-dialog windows, in DoDialog        */
  355. /*    for dialog windows.                                                    */
  356. /* -------------------------------------------------------------------- */
  357.  
  358.  
  359. /*
  360.     Pass local mouse coordinates, click time, and the modifiers flag
  361.     word to the handler.  Should not be necessary to set the port, as
  362.     the click is passed to the active window's handler.
  363. */
  364.  
  365. static DoMouse (h, theEvent)
  366. WHandler    **h;
  367. EventRecord    *theEvent;
  368. {
  369. register ProcPtr    p;
  370. Point                thePt;
  371.  
  372.     if (h != nil)
  373.     {
  374.         if ((p = (**h).whMouse) != nil)
  375.         {
  376.             thePt = theEvent->where;    /* make local copy */
  377.             GlobalToLocal (&thePt);
  378.             (*p) (thePt, theEvent->when, theEvent->modifiers);
  379.         }
  380.     }
  381. }
  382.  
  383.  
  384. /*
  385.     Pass the character and the modifiers flag word to the handler.
  386.     Should not be necessary to set the port, as the click is passed
  387.     to the active window's handler.
  388. */
  389.  
  390. static DoKey (h, ch, mods)
  391. WHandler    **h;
  392. char        ch;
  393. Integer        mods;
  394. {
  395. register ProcPtr    p;
  396.  
  397.     if (h != nil)
  398.     {
  399.         if ((p = (**h).whKey) != nil)
  400.             (*p) (ch, mods);
  401.     }
  402. }
  403.  
  404.  
  405. /*
  406.     Call the window updating procedure, passing to it an indicator whether
  407.     the window has been resized or not.  Then clear the flag, assuming
  408.     the update proc took whatever action was necessary to respond to
  409.     resizing.
  410.  
  411.     If the handler doesn't have any update proc, the Begin/EndUpdate
  412.     stuff is still done, to clear the update region.  Otherwise the
  413.     Window Manager will keep generating update events for the window,
  414.     stalling updates of other windows.
  415.  
  416.     Make sure to save and restore the port, as it's not always the
  417.     active window that is updated.
  418. */
  419.  
  420. static DoUpdate (h)
  421. WHandler    **h;
  422. {
  423. register WHandler    **rh;
  424. register ProcPtr    p;
  425. register GrafPtr    updPort;
  426. GrafPtr                tmpPort;
  427.  
  428.     if ((rh = h) != nil)
  429.     {
  430.         GetPort (&tmpPort);
  431.         SetPort (updPort = (**rh).whWind);
  432.         BeginUpdate (updPort);
  433.         if ((p = (**rh).whUpdate) != nil)
  434.         {
  435.             (*p) ((**rh).whSized);
  436.             (**rh).whSized = false;
  437.         }
  438.         EndUpdate (updPort);
  439.         SetPort (tmpPort);
  440.     }
  441. }
  442.  
  443.  
  444. /*
  445.     Pass activate/deactivate notification to handler.  On activate,
  446.     set the port to the window coming active.  Normally this is done by
  447.     the user clicking in a window.
  448.  
  449.     *** BUT ***
  450.     Under certain conditions, a deactivate may be generated for a window
  451.     that has not had the port set to it by a preceding activate.  If an
  452.     application puts up window A, then window B in front of A, then
  453.     starts processing events, the first events will be a deactivate for A
  454.     and an activate for B.  Since it therefore can't be assumed the port
  455.     was set to A by an activate, the port needs to be set for deactivates
  456.     as well.
  457.  
  458.     This matters not a whit for the more usual cases that occur.  If a
  459.     deactivate for one window is followed by an activate for another, the
  460.     port will still be switched properly to the newly active window.  If
  461.     no activate follows the deactivate, the deactivated window is the last
  462.     one, and it doesn't matter what the port ends up set to, anyway.
  463. */
  464.  
  465. static DoActivate (h, active)
  466. WHandler    **h;
  467. Boolean        active;
  468. {
  469. register ProcPtr    p;
  470.  
  471.     if (h != nil)
  472.     {
  473.         SetPort ((**h).whWind);
  474.         if ((p = (**h).whActivate) != nil)
  475.             (*p) (active);
  476.     }
  477. }
  478.  
  479.  
  480. /*
  481.     Execute a window handler's close box proc.  The close proc for
  482.     handlers for temp windows that want to remove themselves when the
  483.     window is closed can call SkelRmveWind to dispose of the window
  484.     and remove the handler from the window handler list.  Thus, windows
  485.     may be dynamically created and destroyed without filling up the
  486.     handler list with a bunch of invalid handlers.
  487.     
  488.     If the handler doesn't have a close proc, just hide the window.
  489.     The host should provide some way of reopening the window (perhaps
  490.     a menu selection).  Otherwise the window will be lost from user
  491.     control if it is hidden, since it won't receive user-initiated
  492.     events.
  493.  
  494.     This is called both for regular and dialog windows.
  495.  
  496.     Since the close box of only the active window may be clicked, it
  497.     is not necessary to set the port.
  498. */
  499.  
  500. static DoClose (h)
  501. WHandler    **h;
  502. {
  503. register WHandler    **rh;
  504. register ProcPtr    p;
  505.  
  506.     if ((rh = h) != nil)
  507.     {
  508.         if ((p = (**rh).whClose) != nil)
  509.             (*p) ();
  510.         else
  511.             HideWindow ((**rh).whWind);
  512.     }
  513. }
  514.  
  515.  
  516. /*
  517.     Execute a window handler's clobber proc.  This is called both
  518.     for regular and dialog windows.
  519.  
  520.     Must save, set and restore port, since any window (not just active
  521.     one) may be clobbered at any time.
  522.  
  523.     Don't need to check whether handler is nil, as in other handler
  524.     procedures, since this is only called by SkelRmveWind with a
  525.     known-valid handler.
  526. */
  527.  
  528. static DoClobber (h)
  529. WHandler    **h;
  530. {
  531. register ProcPtr    p;
  532. GrafPtr                tmpPort;
  533.  
  534.     GetPort (&tmpPort);
  535.     SetPort ((**h).whWind);
  536.     if ((p = (**h).whClobber) != nil)
  537.         (*p) ();
  538.     SetPort (tmpPort);
  539. }
  540.  
  541.  
  542. # ifdef    supportDialogs
  543.  
  544. /* -------------------------------------------------------------------- */
  545. /*                            Dialog-handling routines                    */
  546. /* -------------------------------------------------------------------- */
  547.  
  548.  
  549. /*
  550.     Handle event if it's for a (modeless) dialog.  The event must be one
  551.     of those that is passed to dialogs according to dlogEventMask.
  552.     This mask can be set so that disk-inserts, for instance, don't
  553.     get eaten up.
  554.  
  555.     Examine event and set port if dialog window is coming active (for
  556.     normal windows, DoActivate sets the port; there's no such thing
  557.     for dialogs, so it's done here.)  When this is done, the trio
  558.     of GetPort/SetPort/SetPort calls commented out below doesn't appear
  559.     to be necessary any longer.  If you want to be cautious, it doesn't
  560.     hurt to uncomment them...
  561. */
  562.  
  563. static DoDialog (theEvent)
  564. register EventRecord    *theEvent;
  565. {
  566. register WHandler    **dh;
  567. DialogPtr            theDialog;
  568. register Integer    what;
  569. Integer                item;
  570. GrafPtr                tmpPort;
  571. WindowPeek            w;
  572.  
  573. /*
  574.     handle command keys before they get to IsDialogEvent
  575. */
  576.  
  577.     what = theEvent->what;
  578.     if((what == keyDown || what == autoKey) && (theEvent->modifiers & cmdKey))
  579.     {
  580.            DoMenuCommand (MenuKey (theEvent->message & charCodeMask));
  581.            return (true);
  582.     }
  583.     
  584.     if (((1 << what) & dlogEventMask) && IsDialogEvent (theEvent))
  585.     {
  586.         /* ugly programming award semi-finalist follows */
  587.         if (theEvent->what == activateEvt            /* if activate */
  588.             && (theEvent->modifiers & activeFlag)    /* and coming active */
  589.             && (w=(WindowPeek) theEvent->message)->windowKind
  590.                     == dialogKind)
  591.         {
  592.             SetPort ((GrafPtr) w);
  593.         }
  594.         if (DialogSelect (theEvent, &theDialog, &item)
  595.            && (dh = GetDHandler (theDialog)) != nil
  596.            && (**dh).whEvent != nil)
  597.         {
  598.             /*GetPort (&tmpPort);*/
  599.             /*SetPort (theDialog);*/
  600.             (*(**dh).whEvent) (item, theEvent);
  601.             /*SetPort (tmpPort);*/
  602.         }
  603.         return (true);
  604.     }
  605.     return (false);
  606. }
  607.  
  608. # endif
  609.  
  610.  
  611. /* -------------------------------------------------------------------- */
  612. /*                            Event-handling routines                        */
  613. /* -------------------------------------------------------------------- */
  614.  
  615.  
  616. /*
  617.     Have either zoomed a window or sized it manually.  Invalidate
  618.     it to force an update and set the 'resized' flag in the window
  619.     handler true.  The port is assumed to be set to the port that changed
  620.     size.
  621. */
  622.  
  623. static TriggerUpdate (h, grownPort)
  624. WHandler    **h;
  625. GrafPtr        grownPort;
  626. {
  627.     InvalRect (&grownPort->portRect);
  628.     if (h != nil)
  629.         (**h).whSized = true;
  630. }
  631.  
  632.  
  633. /*
  634.     Size a window.  If the window has a handler, use the grow limits
  635.     in the handler record, otherwise use the defaults.
  636.  
  637.     The portRect is invalidated to force an update event.  The handler's
  638.     update procedure should check the parameter passed to it to check
  639.     whether the window has changed size, if it needs to adjust itself to
  640.     the new size.  THIS IS A CONVENTION.  Update procs must notice grow
  641.     "events", there is no procedure specifically for such events.
  642.     
  643.     The clipping rectangle is not reset.  If the host application
  644.     keeps the clipping set equal to the portRect or something similar,
  645.     then it will have to arrange to treat window growing with more
  646.     care.
  647.  
  648.     Since the grow region of only the active window may be clicked,
  649.     it should not be necessary to set the port.
  650. */
  651.  
  652. static DoGrow (h, growPort, startPt)
  653. WHandler    **h;
  654. GrafPtr        growPort;
  655. Point        startPt;
  656. {
  657. Rect                r;
  658. register Longint    growRes;
  659.  
  660.     if (h != nil)
  661.         r = (**h).whGrow;
  662.     else
  663.         r = growRect;    /* use default */
  664.  
  665.     /* grow result non-zero if size change    */
  666.  
  667.     if (growRes = GrowWindow (growPort, startPt, &r))
  668.     {
  669.         SizeWindow (growPort, LoWord (growRes), HiWord (growRes), false);
  670.         TriggerUpdate (h, growPort);
  671.     }
  672. }
  673.  
  674.  
  675. /*
  676.     Zoom the current window.  Very similar to DoGrow
  677.  
  678.     Since the zoombox of only the active window may be clicked,
  679.     it should not be necessary to set the port.
  680. */
  681.  
  682. static DoZoom (h, zoomPort, partCode)
  683. register WHandler    **h;
  684. GrafPtr                zoomPort;
  685. short                partCode;
  686. {
  687.     ZoomWindow (zoomPort, partCode, 0);
  688.     TriggerUpdate (h, zoomPort);
  689. }
  690.  
  691.  
  692. /*
  693.     General event handler
  694. */
  695.  
  696. static DoEvent (theEvent)
  697. register EventRecord    *theEvent;
  698.  
  699. {
  700. Point                evtPt;
  701. GrafPtr                evtPort;
  702. register Integer    evtPart;
  703. register char        evtChar;
  704. register Integer    evtMods;
  705. register Longint    evtMsge;
  706. register WHandler    **h;
  707. Rect                r;
  708.  
  709. # ifdef    supportDialogs
  710.  
  711.     if(DoDialog (theEvent))
  712.         return;
  713.  
  714. # endif
  715.  
  716.     evtPt = theEvent->where;
  717.     evtMods = theEvent->modifiers;
  718.     evtMsge = theEvent->message;
  719.  
  720.     switch (theEvent->what)
  721.     {
  722.  
  723.         /*case nullEvent:
  724.             break;*/
  725. /*
  726.     Mouse click.  Get the window that the click occurred in, and the
  727.     part of the window.  GetWDHandler is called here, not GetWHandler, since
  728.     we need the handler for a window which might turn out to be a dialog
  729.     window, e.g., if the click is in a close box.
  730. */
  731.         case mouseDown:
  732.         {
  733.             evtPart = FindWindow (evtPt, &evtPort);
  734.             h = GetWDHandler (evtPort);
  735.  
  736.             switch (evtPart)
  737.             {
  738. /*
  739.     Click in a desk accessory window.  Pass back to the system.
  740. */
  741.                 case inSysWindow:
  742.                 {
  743.                     SystemClick (theEvent, evtPort);
  744.                     break;
  745.                 }
  746. /*
  747.     Click in menu bar.  Track the mouse and execute selected command,
  748.     if any.
  749. */
  750.                 case inMenuBar:
  751.                 {
  752.                     DoMenuCommand (MenuSelect (evtPt));
  753.                     break;
  754.                 }
  755. /*
  756.     Click in grow box.  Resize window.
  757. */
  758.                 case inGrow:
  759.                 {
  760.                     DoGrow (h, evtPort, evtPt);
  761.                     break;
  762.                 }
  763. /*
  764.     Click in title bar.  Drag the window around.  Leave at least
  765.     4 pixels visible in both directions.
  766.     Bug fix:  The window is selected first to make sure it's at least
  767.     activated (unless the command key is down-see Inside Macintosh).
  768.     DragWindow seems to call StillDown first, so that clicks in drag
  769.     regions while machine is busy don't otherwise bring window to front if
  770.     the mouse is already up by the time DragWindow is called.
  771. */
  772.                 case inDrag:
  773.                 {
  774.                     if (evtPort != FrontWindow () && (evtMods & cmdKey) == 0)
  775.                         SelectWindow (evtPort);
  776.                     r = screenPort->portRect;
  777.                     r.top += mBarHeight;            /* skip down past menu bar */
  778.                     InsetRect (&r, 4, 4);
  779.                     DragWindow (evtPort, evtPt, &r);
  780.                     break;
  781.                 }
  782. /*
  783.     Click in close box.  Call the close proc if the window has one.
  784. */
  785.                 case inGoAway:
  786.                 {
  787.                     if (TrackGoAway (evtPort, evtPt))
  788.                         DoClose (h);
  789.                     break;
  790.                 }
  791.  
  792. /*
  793.     Click in zoom box.  Track the click and then zoom the window if
  794.     necessary
  795. */
  796.                 case inZoomIn:
  797.                 case inZoomOut:
  798.                 {
  799.                     if (TrackBox (evtPort, evtPt, evtPart))
  800.                         DoZoom (h, evtPort, evtPart);
  801.                     break;
  802.                 }
  803. /*
  804.     Click in content region.  If the window wasn't frontmost (active),
  805.     just select it, otherwise pass the click to the window's mouse
  806.     click handler.
  807. */
  808.                 case inContent:
  809.                 {
  810.                     if (evtPort != FrontWindow ())
  811.                         SelectWindow (evtPort);
  812.                     else
  813.                         DoMouse (h, theEvent);
  814.                     break;
  815.                 }
  816.  
  817.             }
  818.             break;    /* mouseDown */
  819.         }
  820. /*
  821.     Key event.  If the command key was down, process as menu item
  822.     selection, otherwise pass the character and the modifiers flags
  823.     to the active window's key handler.
  824.  
  825.     If dialogs are supported, there's no check for command-key
  826.     equivalents, since that would have been checked in DoDialog.
  827. */
  828.         case keyDown:
  829.         case autoKey:
  830.         {
  831.             evtChar = evtMsge & charCodeMask;
  832.  
  833. # ifndef    supportDialogs
  834.  
  835.             if (evtMods & cmdKey)        /* try menu equivalent */
  836.             {
  837.                 DoMenuCommand (MenuKey (evtChar));
  838.                 break;
  839.             }
  840.  
  841. # endif
  842.  
  843.             DoKey (GetWHandler (FrontWindow ()), evtChar, evtMods);
  844.             break;
  845.         }
  846. /*
  847.     Update a window.
  848. */
  849.         case updateEvt:
  850.         {
  851.             DoUpdate (GetWHandler ((WindowPtr) evtMsge));
  852.             break;
  853.         }
  854. /*
  855.     Activate or deactivate a window.
  856. */
  857.         case activateEvt:
  858.         {
  859.             DoActivate (GetWHandler ((WindowPtr) evtMsge),
  860.                         ((evtMods & activeFlag) != 0));
  861.             break;
  862.         }
  863. /*
  864.     handle inserts of uninitialized disks
  865. */
  866.         case diskEvt:
  867.         {
  868.             if (HiWord (evtMsge) != noErr)
  869.             {
  870.                 DILoad ();
  871.                 (void) DIBadMount (diskInitPt, evtMsge);
  872.                 DIUnload ();
  873.             }
  874.             break;
  875.         }
  876.     }
  877. }
  878.  
  879.  
  880. /* -------------------------------------------------------------------- */
  881. /*                        Interface (public) Routines                        */
  882. /* -------------------------------------------------------------------- */
  883.  
  884.  
  885. /*
  886.     Initialize the various Macintosh Managers.
  887.     Set default upper limits on window sizing.
  888.     FlushEvents does NOT toss disk insert events, so that disks
  889.     inserted while the application is starting up don't result
  890.     in dead drives.
  891.  
  892.     noMasters is the number of times to call MoreMasters.  gzProc is
  893.     the address of a grow zone procedure to call if memory allocation
  894.     problems occur.  Pass nil if none to be used.
  895. */
  896.  
  897. SkelInit (noMasters, gzProc)
  898. int        noMasters;
  899. ProcPtr    gzProc;
  900. {
  901.     while (noMasters-- > 0)
  902.         MoreMasters ();
  903.  
  904.     if (gzProc != nil)
  905.         SetGrowZone (gzProc);
  906.  
  907.     MaxApplZone ();
  908.     FlushEvents (everyEvent - diskMask, 0 );
  909.     InitGraf (&thePort);
  910.     InitFonts ();
  911.     InitWindows ();
  912.     InitMenus ();
  913.     TEInit ();
  914.     InitDialogs (nil);        /* no restart proc */
  915.     InitCursor ();
  916. /*
  917.     Set upper limits of window sizing to machine screen size.  Allow
  918.     for the menu bar.
  919. */
  920.     GetWMgrPort (&screenPort);
  921.     growRect.right = screenPort->portRect.right;
  922.     growRect.bottom = screenPort->portRect.bottom - mBarHeight;
  923. }
  924.  
  925.  
  926. /*
  927.     Main loop.
  928.  
  929.     Task care of DA's with SystemTask.
  930.     Run background task if there is one.
  931.     If there is an event, check for an event hook.  If there isn't
  932.     one defined, or if there is but it returns false, call the
  933.     general event handler.  (Hook returns true if TransSkel should
  934.     ignore the event.)
  935.     If no event, call the "no-event" handler for the front window and for
  936.     any other windows with idle procedures that are always supposed
  937.     to run.  This is done in such a way that it is safe for idle procs
  938.     to remove the handler for their own window if they want (unlikely,
  939.     but...)  This loop doesn't check whether the window is really
  940.     a dialog window or not, but it doesn't have to, because such
  941.     things always have a nil idle proc.
  942.     
  943.     doneFlag is reset upon exit.  This allows SkelMain to be called
  944.     repeatedly, or recursively.
  945.  
  946.     Null events are examined (in SkelMain) and passed to the event
  947.     handler.  This is necessary to make sure, if dialogs are supported,
  948.     that DialogSelect gets called repeatedly, or the caret won't blink
  949.     if a dialog has any editText items.
  950.  
  951.     Null events are not passed to any event-inspecting hook that may
  952.     be installed.
  953. */
  954.  
  955. SkelMain ()
  956. {
  957. EventRecord            theEvent;
  958. register WHandler    **wh, **wh2;
  959. register WindowPtr    w;
  960. Boolean                haveEvent;
  961. GrafPtr                tmpPort;
  962. register ProcPtr    p;
  963.  
  964.     while (!doneFlag)
  965.     {    
  966.         SystemTask ();
  967.         if (pBkgnd != nil)
  968.             (*pBkgnd) ();
  969.  
  970. /*
  971.     Now watch carefully.  GetNextEvent calls SystemEvent to handle some
  972.     DA events, and returns false if the event was handled.  However, in
  973.     such cases the event record will still have the event that occurred,
  974.     *not* a null event, as you might reasonably expect.  So it's not
  975.     enough to look at haveEvent.
  976.  
  977.     Previous versions figured (wrongly) that haveEvent==false meant a null
  978.     event had occurred, and passed it through to DoEvent and DoDialog, so
  979.     that caret-blinking in dialog TextEdit items would occur.  But cmd-key
  980.     equivalents while DA windows were in front, in particular, allowed
  981.     already-processed DA events to get into DoEvent (because haveEvent
  982.     was false), and they got handled twice because when the event record
  983.     was examined, lo and behold, it had a cmd-key event!  So now this
  984.     logic is used:
  985.  
  986.     If have a real event, and there's no event hook or there is but it
  987.     doesn't handle the event, OR if the "non-event" is a true nullEvent,
  988.     then process it.
  989. */
  990.             
  991.         haveEvent = GetNextEvent (eventMask, &theEvent);
  992.  
  993.         if ((haveEvent && (pEvent == nil || (*pEvent)(&theEvent) == false))
  994.                 || theEvent.what == nullEvent)
  995.             DoEvent(&theEvent);
  996.  
  997. /*
  998.     Run applicable idle procs.  Make sure to save and restore the port,
  999.     since idle procs for the non-active window may be run.
  1000. */
  1001.  
  1002.         if (!haveEvent)
  1003.         {
  1004.             GetPort (&tmpPort);
  1005.             for (wh = whList; wh != nil; wh = wh2)
  1006.             {
  1007.                 wh2 = (**wh).whNext;
  1008.                 w = (**wh).whWind;
  1009.                 if ( (w == FrontWindow () || !(**wh).whFrontOnly ) )
  1010.                 {
  1011.                     SystemTask ();
  1012.                     if ((p = (**wh).whIdle) != nil)
  1013.                     {
  1014.                         SetPort (w);
  1015.                         (*p) ();
  1016.                     }
  1017.                 }
  1018.             }
  1019.             SetPort (tmpPort);
  1020.         }
  1021.     }
  1022.     doneFlag = false;
  1023. }
  1024.  
  1025.  
  1026. /*
  1027.     Tell SkelMain to stop
  1028. */
  1029.  
  1030. SkelWhoa () { doneFlag = true; }
  1031.  
  1032.  
  1033. /*
  1034.     Clobber all the menu, window and dialog handlers
  1035. */
  1036.  
  1037. SkelClobber ()
  1038. {
  1039.     while (whList != nil)
  1040.         SkelRmveWind ((**whList).whWind);
  1041.  
  1042.     while (mhList != nil)
  1043.         SkelRmveMenu (GetMHandle((**mhList).mhID));
  1044. }
  1045.  
  1046.  
  1047. /* -------------------------------------------------------------------- */
  1048. /*                        Menu-handler interface routines                    */
  1049. /* -------------------------------------------------------------------- */
  1050.  
  1051.  
  1052. /*
  1053.     Install handler for a menu.  Remove any previous handler for it.
  1054.     Pass the following parameters:
  1055.  
  1056.     theMenu    Handle to the menu to be handled.  Must be created by host.
  1057.     pSelect    Proc that handles selection of items from menu.  If this is
  1058.             nil, the menu is installed, but nothing happens when items
  1059.             are selected from it.
  1060.     pClobber Proc for disposal of handler's data structures.  Usually
  1061.             nil for menus that remain in menu bar until program
  1062.             termination.
  1063.     
  1064.     The menu is installed, and also drawn in the menu bar if drawBar true.
  1065.     
  1066.     Return 0 if no handler could be allocated, non-zero if successful.
  1067. */
  1068.  
  1069. SkelMenu (theMenu, pSelect, pClobber, drawBar)
  1070. MenuHandle    theMenu;
  1071. ProcPtr        pSelect;
  1072. ProcPtr        pClobber;
  1073. Boolean        drawBar;
  1074. {
  1075. register MHandler    **mh;
  1076.  
  1077.     mhClobOnRmve = false;
  1078.     SkelRmveMenu (theMenu);
  1079.     mhClobOnRmve = true;
  1080.  
  1081.     if ((mh = New (MHandler)) != nil)
  1082.     {
  1083.         (**mh).mhNext = mhList;
  1084.         mhList = mh;
  1085.         (**mh).mhID = (**theMenu).menuID;    /* get menu id number */
  1086.         (**mh).mhSelect = pSelect;            /* install selection handler */
  1087.         (**mh).mhClobber = pClobber;        /* install disposal handler */
  1088.         InsertMenu (theMenu, 0);            /* put menu at end of menu bar */
  1089.     }
  1090.     if (drawBar)
  1091.         DrawMenuBar ();
  1092.     return (mh != nil);
  1093. }
  1094.  
  1095.  
  1096. /*
  1097.     Remove a menu handler.  This calls the handler's disposal routine
  1098.     and then takes the handler out of the handler list and disposes
  1099.     of it.
  1100.  
  1101.     Note that the menu MUST be deleted from the menu bar before calling
  1102.     the clobber proc, because the menu bar will end up filled with
  1103.     garbage if the menu was allocated with NewMenu (see discussion of
  1104.     DisposeMenu in Menu Manager section of Inside Macintosh).
  1105. */
  1106.  
  1107. SkelRmveMenu (theMenu)
  1108. MenuHandle    theMenu;
  1109. {
  1110. register Integer    mID;
  1111. register MHandler    **h, **h2;
  1112. register ProcPtr    p;
  1113.  
  1114.     mID = (**theMenu).menuID;
  1115.     if (mhList != nil)                /* if list empty, ignore */
  1116.     {
  1117.         if ((**mhList).mhID == mID)    /* is it the first element? */
  1118.         {
  1119.             h2 = mhList;
  1120.             mhList = (**mhList).mhNext;
  1121.         }
  1122.         else
  1123.         {
  1124.             for (h = mhList; h != nil; h = h2)
  1125.             {
  1126.                 h2 = (**h).mhNext;
  1127.                 if (h2 == nil)
  1128.                     return;                        /* menu not in list! */
  1129.                 if ((**h2).mhID == mID)            /* found it */
  1130.                 {
  1131.                     (**h).mhNext = (**h2).mhNext;
  1132.                     break;
  1133.                 }
  1134.             }
  1135.         }
  1136.         DeleteMenu (mID);
  1137.         DrawMenuBar ();
  1138.         if (mhClobOnRmve && (p = (**h2).mhClobber) != nil)
  1139.             (*p) (theMenu);                /* call disposal routine */
  1140.         DisposHandle (h2);                /* get rid of handler record */
  1141.     }
  1142. }
  1143.  
  1144.  
  1145. /*
  1146.     Install a handler for the Apple menu.
  1147.     
  1148.     SkelApple is called if TransSkel is supposed to handle the apple
  1149.     menu itself.  aboutTitle is the title of the first item.  If nil,
  1150.     then only desk accessories are put into the menu.  If not nil, then
  1151.     the title is entered as the first item, followed by a gray line,
  1152.     then the desk accessories.
  1153.  
  1154.     SkelApple does not cause the menubar to be drawn, so if the Apple
  1155.     menu is the only menu, DrawMenuBar must be called afterward.
  1156.  
  1157.     No value is returned, unlike SkelMenu.  It is assumed that SkelApple
  1158.     will be called so early in the application that the call the SkelMenu
  1159.     is virtually certain to succeed.  If it doesn't, there's probably
  1160.     little hope for the application anyway.
  1161. */
  1162.  
  1163. SkelApple (aboutTitle, aboutProc)
  1164. StringPtr    aboutTitle;
  1165. ProcPtr        aboutProc;
  1166. {
  1167.     appleID = 1;
  1168.     appleMenu = NewMenu (appleID, "\p\024");    /* 024 = apple character */
  1169.     if (aboutTitle != nil)
  1170.     {
  1171.         doAbout = true;
  1172.         AppendMenu (appleMenu, aboutTitle);    /* add About... item title */
  1173.         AppendMenu (appleMenu, "\p(-");        /* add gray line */
  1174.         appleAboutProc = aboutProc;
  1175.     }
  1176.     AddResMenu (appleMenu, 'DRVR');        /* add desk accessories */
  1177.     (void) SkelMenu (appleMenu, DoAppleItem, DoAppleClobber, false);
  1178. }
  1179.  
  1180.  
  1181. /* -------------------------------------------------------------------- */
  1182. /*                    Window-handler interface routines                    */
  1183. /* -------------------------------------------------------------------- */
  1184.  
  1185.  
  1186. /*
  1187.     Install handler for a window and set current port to it.  Remove
  1188.     any previous handler for it.  Pass the following parameters:
  1189.  
  1190.     theWind    Pointer to the window to be handled.  Must be created by host.
  1191.     pMouse    Proc to handle mouse clicks in window.  The proc will be
  1192.             passed the point (in local coordinates), the time of the
  1193.             click, and the modifier flags word.
  1194.     pKey    Proc to handle key clicks in window.  The proc will be passed
  1195.             the character and the modifier flags word.
  1196.     pUpdate    Proc for updating window.  TransSkel brackets calls to update
  1197.             procs with calls to BeginUpdate and EndUpdate, so the visRgn
  1198.             is set up correctly.  A flag is passed indicating whether the
  1199.             window was resized or not.  BY CONVENTION, the entire portRect
  1200.             is invalidated when the window is resized.  That way, the
  1201.             handler's update proc can redraw the entire content region
  1202.             without interference from BeginUpdate/EndUpdate.  The flag
  1203.             is set to false after the update proc is called; the
  1204.             assumption is made that it will notice the resizing and
  1205.             respond appropriately.
  1206.     pActivate Proc to execute when window is activated or deactivated.
  1207.             A boolean is passed to it which is true if the window is
  1208.             coming active, false if it's going inactive.
  1209.     pClose    Proc to execute when mouse clicked in close box.  Useful
  1210.             mainly to temp window handlers that want to know when to
  1211.             self-destruct (with SkelRmveWind).
  1212.     pClobber Proc for disposal of handler's data structures
  1213.     pIdle    Proc to execute when no events are pending.
  1214.     frontOnly True if pIdle should execute on no events only when
  1215.             theWind is frontmost, false if executes all the time.  Note
  1216.             that if it always goes, everything else may be slowed down!
  1217.  
  1218.     If a particular procedure is not needed (e.g., key events are
  1219.     not processed by a handler), pass nil in place of the appropriate
  1220.     procedure address.
  1221.     
  1222.     Return zero if no handler could be allocated, non-zero if successful.
  1223.     If zero is returned, the port will not have changed.
  1224. */
  1225.  
  1226. SkelWindow (theWind, pMouse, pKey, pUpdate, pActivate, pClose,
  1227.                 pClobber, pIdle, frontOnly)
  1228.  
  1229. WindowPtr    theWind;
  1230. ProcPtr        pMouse, pKey, pUpdate, pActivate, pClose, pClobber, pIdle;
  1231. Boolean        frontOnly;
  1232. {
  1233. register WHandler    **hHand, *hPtr;
  1234.  
  1235.     whClobOnRmve = false;
  1236.     SkelRmveWind (theWind);
  1237.     whClobOnRmve = true;
  1238.  
  1239. /*
  1240.     Get new handler, attach to list of handlers.  It is attached to the
  1241.     beginning of the list, which is simpler; the order is presumably
  1242.     irrelevant to the host, anyway.
  1243. */
  1244.  
  1245.     if ((hHand = New (WHandler)) != nil)
  1246.     {
  1247.         (**hHand).whNext = whList;
  1248.         whList = hHand;
  1249.  
  1250. /*
  1251.     Fill in handler fields
  1252. */
  1253.  
  1254.         hPtr = *hHand;
  1255.         hPtr->whWind = theWind;
  1256.         hPtr->whMouse = pMouse;
  1257.         hPtr->whKey = pKey;
  1258.         hPtr->whUpdate = pUpdate;
  1259.         hPtr->whActivate = pActivate;
  1260.         hPtr->whClose = pClose;
  1261.         hPtr->whClobber = pClobber;
  1262.         hPtr->whIdle = pIdle;
  1263.         hPtr->whFrontOnly = frontOnly;
  1264.         hPtr->whSized = false;
  1265.         hPtr->whGrow = growRect;
  1266.         SetPort (theWind);
  1267.     }
  1268.     return (hHand != nil);
  1269. }
  1270.  
  1271.  
  1272. /*
  1273.     Remove a window handler.  This calls the handler's disposal routine
  1274.     and then takes the handler out of the handler list and disposes
  1275.     of it.
  1276.  
  1277.     SkelRmveWind is also called by SkelRmveDlog.
  1278.  
  1279.     Note that if the window cache variable is set to the window whose
  1280.     handler is being clobbered, the variable must be zeroed.
  1281. */
  1282.  
  1283. SkelRmveWind (theWind)
  1284. WindowPtr    theWind;
  1285. {
  1286. register WHandler    **h, **h2;
  1287.  
  1288.     if (theWind == oldWindow)
  1289.         oldWindow = nil;
  1290.  
  1291.     if (whList != nil)        /* if list empty, ignore */
  1292.     {
  1293.         if ((**whList).whWind == theWind)    /* is it the first element? */
  1294.         {
  1295.             h2 = whList;
  1296.             whList = (**whList).whNext;
  1297.         }
  1298.         else
  1299.         {
  1300.             for (h = whList; h != nil; h = h2)
  1301.             {
  1302.                 h2 = (**h).whNext;
  1303.                 if (h2 == nil)
  1304.                     return;                        /* theWind not in list! */
  1305.                 if ((**h2).whWind == theWind)    /* found it */
  1306.                 {
  1307.                     (**h).whNext = (**h2).whNext;
  1308.                     break;
  1309.                 }
  1310.             }
  1311.         }
  1312.         if (whClobOnRmve)
  1313.             DoClobber (h2);        /* call disposal routine */
  1314.         DisposHandle (h2);        /* get rid of handler record */
  1315.     }
  1316. }
  1317.  
  1318.  
  1319. # ifdef    supportDialogs
  1320.  
  1321. /* -------------------------------------------------------------------- */
  1322. /*                    Dialog-handler interface routines                    */
  1323. /* -------------------------------------------------------------------- */
  1324.  
  1325.  
  1326. /*
  1327.     Install a handler for a modeless dialog window and set the port
  1328.     to it.  Remove any previous handler for it. SkelDialog calls
  1329.     SkelWindow as a subsidiary to install a window handler, then sets
  1330.     the event procedure on return.
  1331.  
  1332.     Pass the following parameters:
  1333.  
  1334.     theDialog    Pointer to the dialog to be handled.  Must be created
  1335.             by host.
  1336.     pEvent    Event-handling proc for dialog events.
  1337.     pClose    Proc to execute when mouse clicked in close box.  Useful
  1338.             mainly to dialog handlers that want to know when to
  1339.             self-destruct (with SkelRmveDlog).
  1340.     pClobber Proc for disposal of handler's data structures
  1341.  
  1342.     If a particular procedure is not needed, pass nil in place of
  1343.     the appropriate procedure address.
  1344.     
  1345.     Return zero if no handler could be allocated, non-zero if successful.
  1346.     If zero is returned, the port will not have changed.
  1347. */
  1348.  
  1349. SkelDialog (theDialog, pEvent, pClose, pClobber)
  1350. DialogPtr    theDialog;
  1351. ProcPtr        pEvent;
  1352. ProcPtr        pClose;
  1353. ProcPtr        pClobber;
  1354. {
  1355. int        swOk;
  1356.  
  1357.     if (SkelWindow (theDialog, nil, nil, nil, nil, pClose, pClobber, nil, false))
  1358.     {
  1359.         (**GetWDHandler (theDialog)).whEvent = pEvent;
  1360.         return (1);
  1361.     }
  1362.     return (0);
  1363. }
  1364.  
  1365.  
  1366. /*
  1367.     Remove a dialog and its handler
  1368. */
  1369.  
  1370. SkelRmveDlog (theDialog)
  1371. DialogPtr    theDialog;
  1372. {
  1373.     SkelRmveWind (theDialog);
  1374. }
  1375.  
  1376. # endif
  1377.  
  1378.  
  1379. /* -------------------------------------------------------------------- */
  1380. /*                    Miscellaneous interface routines                    */
  1381. /* -------------------------------------------------------------------- */
  1382.  
  1383.  
  1384. /*
  1385.     Override the default sizing limits for a window, or, if theWind
  1386.     is nil, reset the default limits used by SkelWindow.
  1387. */
  1388.  
  1389. SkelGrowBounds (theWind, hLo, vLo, hHi, vHi)
  1390. WindowPtr    theWind;
  1391. Integer            hLo, vLo, hHi, vHi;
  1392. {
  1393. register WHandler    **h;
  1394. Rect                r;
  1395.  
  1396.     if (theWind == nil)
  1397.         SetRect (&growRect, hLo, vLo, hHi, vHi);
  1398.     else if ((h = GetWHandler (theWind)) != nil)
  1399.     {
  1400.         SetRect (&r, hLo, vLo, hHi, vHi);
  1401.         (**h).whGrow = r;
  1402.     }
  1403. }
  1404.  
  1405.  
  1406. /*
  1407.     Set the event mask.
  1408. */
  1409.  
  1410. SkelEventMask (mask)
  1411. Integer        mask;
  1412. {
  1413.     eventMask = mask;
  1414. }
  1415.  
  1416.  
  1417. /*
  1418.     Return the event mask.
  1419. */
  1420.  
  1421. SkelGetEventMask (mask)
  1422. Integer        *mask;
  1423. {
  1424.     *mask = eventMask;
  1425. }
  1426.  
  1427.  
  1428. /*
  1429.     Install a background task.  If p is nil, the current task is
  1430.     disabled.
  1431. */
  1432.  
  1433. SkelBackground (p)
  1434. ProcPtr    p;
  1435. {
  1436.     pBkgnd = p;
  1437. }
  1438.  
  1439.  
  1440. /*
  1441.     Return the current background task.  Return nil if none.
  1442. */
  1443.  
  1444. SkelGetBackground (p)
  1445. ProcPtr    *p;
  1446. {
  1447.     *p = pBkgnd;
  1448. }
  1449.  
  1450.  
  1451. /*
  1452.     Install an event-inspecting hook.  If p is nil, the hook is
  1453.     disabled.
  1454. */
  1455.  
  1456. SkelEventHook (p)
  1457. Boolean    (*p)();
  1458. {
  1459.     pEvent = p;
  1460. }
  1461.  
  1462.  
  1463. /*
  1464.     Return the current event-inspecting hook.  Return nil if none.
  1465. */
  1466.  
  1467. SkelGetEventHook (p)
  1468. Boolean    (**p)();
  1469. {
  1470.     *p = pEvent;
  1471. }
  1472.  
  1473.  
  1474. # ifdef    supportDialogs
  1475.  
  1476. /*
  1477.     Set the mask for event types that will be passed to dialogs.
  1478.     Bit 1 is always set, so that null events will be examined.
  1479.     (If this is not done, the caret does not blink in editText items.)
  1480. */
  1481.  
  1482. SkelDlogMask (mask)
  1483. Integer        mask;
  1484. {
  1485.     dlogEventMask = mask | 1;
  1486. }
  1487.  
  1488.  
  1489. /*
  1490.     Return the current dialog event mask.
  1491. */
  1492.  
  1493. SkelGetDlogMask (mask)
  1494. Integer        *mask;
  1495. {
  1496.     *mask = dlogEventMask;
  1497. }
  1498.  
  1499. # endif
  1500.