home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / progrmng / transklc.sit / Skel.c.bin / Skel.c
Encoding:
C/C++ Source or Header  |  1989-01-29  |  4.5 KB  |  220 lines  |  [TEXT/KAHL]

  1. /*
  2.     TransSkel demonstration:  Traditional Skel
  3.  
  4.     This program mimics the original Skel application:  one sizable,
  5.     dragable, non-closable dark gray window, an "About" alert and two
  6.     dialogs.  Desk accessories supported.
  7.  
  8.     The project should include this file, TransSkel.c (or a project
  9.     built from TransSkel.c), and MacTraps.
  10.  
  11.     21 Apr 1988    Paul DuBois
  12.     29 Jan 1989 Conversion for TransSkel 2.0.  Integer should be a
  13.                 typedef for compiler 2-byte integer type.
  14. */
  15.  
  16. # include    <DialogMgr.h>    /* includes WindowMgr, QuickDraw, etc. */
  17. # include    <MenuMgr.h>
  18. # include    <ToolboxUtil.h>
  19.  
  20. # define    nil    (0L)
  21.  
  22. typedef    int    Integer;
  23.  
  24. /*
  25.     Resource numbers
  26. */
  27.  
  28. # define    fileMenuRes    2        /* File menu */
  29. # define    aboutAlrt    1000    /* About box */
  30. # define    theWindRes    260        /* window */
  31. # define    reportDlog    257        /* message dialog box */
  32. # define    aboutStr    1        /* message strings */
  33. # define    rattleStr    2
  34. # define    frightStr    3
  35.  
  36.  
  37.  
  38. /* file menu item numbers */
  39.  
  40. typedef enum {
  41.     rattle = 1,
  42.     frighten,
  43.     /* --- */
  44.     quit = 4
  45. } fileItems;
  46.  
  47.  
  48. WindowPtr    theWind;
  49.  
  50. /*
  51.     Menu handles.  There isn't any apple menu here, since TransSkel will
  52.     be told to handle it itself.
  53. */
  54.  
  55. MenuHandle    fileMenu;
  56.  
  57.  
  58. /* -------------------------------------------------------------------- */
  59. /*                        Menu handling procedures                        */
  60. /* -------------------------------------------------------------------- */
  61.  
  62.  
  63. /*
  64.     Read a string resource and put into the Alert/Dialog paramtext
  65.     values
  66. */
  67.  
  68. SetParamText (strNum)
  69. Integer    strNum;
  70. {
  71. StringHandle    h;
  72.  
  73.     h = GetString (strNum);
  74.     HLock (h);
  75.     ParamText (*h, "\p", "\p", "\p");
  76.     HUnlock (h);
  77. }
  78.  
  79.  
  80. /*
  81.     Handle selection of "About Skelâ•”" item from Apple menu
  82. */
  83.  
  84. DoAbout ()
  85. {
  86. StringHandle    h;
  87.  
  88.     SetParamText (aboutStr);
  89.     (void) Alert (aboutAlrt, nil);
  90. }
  91.  
  92.  
  93. /*
  94.     Put up a dialog box with a message and an OK button.  The message
  95.     is stored in the 'STR ' resource whose number is passed as strNum.
  96. */
  97.  
  98. Report (strNum)
  99. Integer    strNum;
  100. {
  101. DialogPtr    theDialog;
  102. Integer        itemHit;
  103.  
  104.     SetParamText (strNum);
  105.     theDialog = GetNewDialog (reportDlog, nil, -1L);
  106.     ModalDialog (nil, &itemHit);
  107.     DisposDialog (theDialog);
  108. }
  109.  
  110.  
  111. /*
  112.     Process selection from File menu.
  113.     
  114.     Rattle, Frighten    A dialog box with message
  115.     Quit    Request a halt by calling SkelHalt().  This makes SkelMain
  116.             return.
  117. */
  118.  
  119. DoFileMenu (item)
  120. Integer    item;
  121. {
  122.  
  123.     switch (item)
  124.     {
  125.         case rattle:    Report (rattleStr); break;
  126.         case frighten:    Report (frightStr); break;
  127.         case quit:        SkelWhoa (); break;    /* request halt */
  128.     }
  129. }
  130.  
  131.  
  132. /*
  133.     Initialize menus.  Tell TransSkel to process the Apple menu
  134.     automatically, and associate the proper procedures with the
  135.     File and Edit menus.
  136. */
  137.  
  138. SetUpMenus ()
  139. {
  140.  
  141.     SkelApple ("\pAbout Skelâ•”", DoAbout);
  142.     fileMenu = GetMenu (fileMenuRes);
  143.     (void) SkelMenu (fileMenu, DoFileMenu, nil, true);
  144. }
  145.  
  146.  
  147. /* -------------------------------------------------------------------- */
  148. /*                    Window handling procedures                            */
  149. /* -------------------------------------------------------------------- */
  150.  
  151.  
  152. WindActivate (active)
  153. Boolean    active;
  154. {
  155.  
  156.     DrawGrowIcon (theWind);    /* make grow box reflect new window state */
  157. }
  158.  
  159.  
  160. /*
  161.     On update event, can ignore the resizing information, since the whole
  162.     window is always redrawn in terms of the current size, anyway.
  163.     Content area is dark gray except scroll bar areas, which are white.
  164.     Draw grow box as well.
  165. */
  166.  
  167. WindUpdate (resized)
  168. Boolean    resized;
  169. {
  170. Rect    r;
  171.  
  172.     r = theWind->portRect;        /* paint window dark gray */
  173.     r.bottom -= 15;                /* don't bother painting the */
  174.     r.right -= 15;                /* scroll bar areas */
  175.     FillRect (&r, dkGray);
  176.     r = theWind->portRect;        /* paint scroll bar areas white */
  177.     r.left = r.right - 15;
  178.     FillRect (&r, white);
  179.     r = theWind->portRect;
  180.     r.top = r.bottom - 15;
  181.     FillRect (&r, white);
  182.     DrawGrowIcon (theWind);
  183. }
  184.  
  185.  
  186. WindHalt () { DisposeWindow (theWind); }
  187.  
  188.  
  189. /*
  190.     Read window from resource file and install handler for it.  Mouse
  191.     and key clicks are ignored.  There is no close proc since the window
  192.     doesn't have a close box.  There is no idle proc since nothing is
  193.     done while the window is in front (all the things that are done are
  194.     handled by TransSkel).
  195. */
  196.  
  197. WindInit ()
  198. {
  199.  
  200.     theWind = GetNewWindow (theWindRes, nil, -1L);
  201.     (void) SkelWindow (theWind, nil, nil, WindUpdate, WindActivate, nil,
  202.                     WindHalt, nil, false);
  203. }
  204.  
  205.  
  206. /* -------------------------------------------------------------------- */
  207. /*                                    Main                                */
  208. /* -------------------------------------------------------------------- */
  209.  
  210.  
  211. main ()
  212. {
  213.  
  214.     SkelInit (6, nil);            /* initialize */
  215.     SetUpMenus ();                /* install menu handlers */
  216.     WindInit();                    /* install window handler */
  217.     SkelMain ();                /* loop 'til Quit selected */
  218.     SkelClobber ();                /* clean up */
  219. }
  220.