home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / TransSkel / Demos / C Demos / MultiSkel / MultiSkel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-21  |  4.3 KB  |  212 lines  |  [TEXT/KAHL]

  1. /*
  2.  * Should add menu hook routine to dim Close item when no windows are active.
  3.  *
  4.  * MultiSkel - TransSkel multiple-window demonstration main module
  5.  *
  6.  * This module performs setup and termination operations, installs
  7.  * the window and menu handlers, and processes menu item selections.
  8.  *
  9.  * There are four window handlers in this demonstration.  The code
  10.  * for each handler is in its own module.
  11.  *
  12.  * Help Window        Scrollable non-editable text window
  13.  * Edit Window        Non-scrollable editable text window
  14.  * Zoom Window        Non-manipulable graphics display window
  15.  * Region Window    Manipulable graphics display window
  16.  *
  17.  * 21 Apr 88 Paul DuBois
  18.  * 29 Jan 89 Version 1.01
  19.  * - Conversion for TransSkel 2.0.
  20.  * 12 Jan 91 Version 1.02
  21.  * - Conversion for TransSkel 3.00.
  22.  * 05 Jun 93 Version 1.03
  23.  * - Conversion for THINK C 6.0.
  24.  * 15 Feb 94
  25.  * - Numerous minor revisions.
  26.  * 21 Feb 94
  27.  * - Updated for TransSkel 3.11.
  28.  */
  29.  
  30. # include    "TransSkel.h"
  31.  
  32. # include    "MultiSkel.h"
  33.  
  34.  
  35. /* File menu item numbers */
  36.  
  37. typedef enum {
  38.     open = 1,
  39.     close,
  40.     /* --- */
  41.     quit = 4
  42. } fileItems;
  43.  
  44.  
  45. WindowPtr    helpWind;
  46. WindowPtr    editWind;
  47. WindowPtr    zoomWind;
  48. WindowPtr    rgnWind;
  49.  
  50.  
  51. /*
  52.  * Menu handles.  There isn't any Apple menu here, since TransSkel will
  53.  * be told to handle it itself.
  54.  */
  55.  
  56. static MenuHandle    fileMenu;
  57. MenuHandle            editMenu;
  58.  
  59. static RgnHandle    oldClip;
  60.  
  61.  
  62. /*
  63.  * Miscellaneous routines
  64.  * These take care of drawing the grow box and the line along
  65.  * the right edge of the window, and of setting and resetting the clip
  66.  * region to disallow drawing in that right edge by the other drawing
  67.  * routines.
  68.  */
  69.  
  70.  
  71. void
  72. DrawGrowBox (WindowPtr wind)
  73. {
  74. Rect        r;
  75. RgnHandle    oldClip;
  76.  
  77.     r = wind->portRect;
  78.     r.left = r.right - 15;        /* draw only along right edge */
  79.     oldClip = NewRgn ();
  80.     GetClip (oldClip);
  81.     ClipRect (&r);
  82.     DrawGrowIcon (wind);
  83.     SetClip (oldClip);
  84.     DisposeRgn (oldClip);
  85. }
  86.  
  87.  
  88. void
  89. SetWindClip (WindowPtr wind)
  90. {
  91. Rect        r;
  92.  
  93.     r = wind->portRect;
  94.     r.right -= 15;        /* don't draw along right edge */
  95.     oldClip = NewRgn ();
  96.     GetClip (oldClip);
  97.     ClipRect (&r);
  98. }
  99.  
  100.  
  101. void
  102. ResetWindClip (void)
  103. {
  104.     SetClip (oldClip);
  105.     DisposeRgn (oldClip);
  106. }
  107.  
  108.  
  109. /*
  110.  * Show a window if it's not visible.  Select the window FIRST, then
  111.  * show it, so that it comes up in front.  Otherwise it will be drawn
  112.  * in back then brought to the front, which is ugly.
  113.  *
  114.  * The test for visibility must be done carefully:  the window manager
  115.  * stores 255 and 0 for true and false, not real boolean values.
  116.  */
  117.  
  118. static void
  119. MyShowWindow (WindowPtr wind)
  120. {
  121.  
  122.     if (((WindowPeek) wind)->visible == false)
  123.     {
  124.         SelectWindow (wind);
  125.         ShowWindow (wind);
  126.     }
  127. }
  128.  
  129.  
  130. /*
  131.  * Handle selection of About MultiSkel... item from Apple menu
  132.  */
  133.  
  134. static pascal void
  135. DoAppleMenu (short item)
  136. {
  137.     (void) SkelAlert (aboutAlrtRes, SkelDlogFilter (nil, true),
  138.                                         skelPositionOnParentDevice);
  139.     SkelRmveDlogFilter ();
  140. }
  141.  
  142.  
  143. /*
  144.  * Process selection from File menu.
  145.  *
  146.  * Open        Make all four windows visible
  147.  * Close    Hide the frontmost window.  If it belongs to a desk accessory,
  148.  *            close the accessory.
  149.  * Quit        Request a halt by calling SkelHalt().  This makes SkelMain
  150.  *            return.
  151.  */
  152.  
  153. static pascal void
  154. DoFileMenu (short item)
  155. {
  156.     switch (item)
  157.     {
  158.         case open:
  159.             MyShowWindow (rgnWind);
  160.             MyShowWindow (zoomWind);
  161.             MyShowWindow (editWind);
  162.             MyShowWindow (helpWind);
  163.             break;
  164.  
  165.         case close:
  166.             SkelClose (FrontWindow ());
  167.             break;
  168.  
  169.         case quit:
  170.             SkelStopEventLoop ();        /* request halt */
  171.             break;
  172.     }
  173. }
  174.  
  175.  
  176. /*
  177.  * Initialize menus.  Tell TransSkel to process the Apple menu automatically,
  178.  * and associate the proper procedures with the File and Edit menus.
  179.  * The Edit menu is enabled only when the Edit is frontmost.
  180.  *
  181.  * \311 = ellipsis character
  182.  */
  183.  
  184. static void
  185. SetUpMenus (void)
  186. {
  187.     SkelApple ((StringPtr) "\pAbout MultiSkel\311", DoAppleMenu);
  188.     fileMenu = GetMenu (fileMenuRes);
  189.     (void) SkelMenu (fileMenu, DoFileMenu, nil, false, false);
  190.     editMenu = GetMenu (editMenuRes);
  191.     (void) SkelMenu (editMenu, EditWindEditMenu, nil, false, true);
  192. }
  193.  
  194.  
  195. int
  196. main (void)
  197. {
  198. long    f, b;
  199.  
  200.     SkelInit ((SkelInitParamsPtr) nil);
  201.     SkelGetWaitTimes (&f, &b);
  202.     b = f;
  203.     SkelSetWaitTimes (f, b);
  204.     SetUpMenus ();            /* install menu handlers */
  205.     RgnWindInit ();            /* install window handlers  */
  206.     ZoomWindInit ();
  207.     EditWindInit ();
  208.     HelpWindInit ();
  209.     SkelEventLoop ();        /* process events */
  210.     SkelCleanup ();            /* throw away windows and menus */
  211. }
  212.