home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / Programming / MSTPChart / About.c next >
Encoding:
C/C++ Source or Header  |  1993-05-26  |  5.0 KB  |  148 lines  |  [TEXT/KAHL]

  1. #include    "MST_Defines.h"
  2. #include    "MST_Externs.h"
  3. #include    "MST_Prototypes.h"
  4.  
  5.  
  6. /*_____________________________________________________________________________
  7.                         Close_AboutMST()- close our About Box window
  8. _____________________________________________________________________________*/
  9.  
  10. void    Close_AboutMST()
  11. {
  12. /*
  13.  •        Since we have no data associated with our About Box window to save, closing
  14.  •        our about box is short and simple. First check to make sure an About Box
  15.  •        exists. If our program has a flaw in its algorithm somewhere and put us
  16.  •        at this point by mistake, we don't want to call DisposDialog() on a NIL
  17.  •        pointer. The result would be a crash. Then we call DisposDialog() to
  18.  •        destroy the window and free up its memory. The operating system will take
  19.  •        care of generating the appropriate update and activate events, not only
  20.  •        for us, but for programs in the background as well. So don't worry about
  21.  •        other windows at this point...a properly structured program will handle
  22.  •        it all automatically using events. Lastly, we set our pointer to NIL,
  23.  •        indicating there is no current About Box. 
  24.  */
  25.  
  26.     if    (AboutMSTDlog==NIL)    return;
  27.     DisposDialog    (AboutMSTDlog);
  28.     AboutMSTDlog    =    NIL;
  29. }
  30.  
  31.  
  32. /*_____________________________________________________________________________
  33.                         Open_AboutMST()- create & display our About Box window
  34. _____________________________________________________________________________*/
  35.  
  36.  
  37. void    Open_AboutMST()
  38. {
  39.     
  40. /*
  41. •        Here we create and display our About Box. First we check to see if it
  42. •        is already open. If so, we make it the active window (bringing it
  43. •        to the front of all the other windows of our application) by calling
  44. •        SelectWindow(). Otherwise, we create it from our template numbered
  45. •        ResID_AboutMST stored in our resource fork. The third parameter
  46. •        for GetNewDialog (e.g., -1 typecast to a WindowPtr) tells the
  47. •        window manager to place the window in front of all other windows
  48. •        belonging to our application. Then we make it visible (don't
  49. •        rely on the "initially visible" bit being set in the dialog template).
  50. •        Note the really cool thing is that we don't explicitly have to draw
  51. •        the contents of the window. Just sit back and let the operating system
  52. •        generate an update event, which it will because this is a new window.
  53. •        Your update routine will handle the rest.
  54. */
  55.  
  56.     if    (AboutMSTDlog!=NIL)    {    SelectWindow    (AboutMSTDlog);    return;    }
  57.  
  58.     AboutMSTDlog = GetNewDialog    (ResID_AboutMST, NIL, (WindowPtr)-1);
  59.     ShowWindow        (AboutMSTDlog);    
  60. }
  61.  
  62.  
  63. /*_____________________________________________________________________________
  64.                         Update_AboutMST()- Draw our About Box window
  65. _____________________________________________________________________________*/
  66.  
  67.  
  68. void    UpDate_AboutMST()
  69. {
  70.     GDHandle    saveDevice;
  71.     CGrafPtr    saveCGrafPtr;
  72.     int            loop1;
  73.     
  74.     if    (AboutMSTDlog==NIL)    return;        /*Make sure the about box exists*/
  75.     
  76. /*
  77. •        Now save the current Grafport and set the current port to our About Box.
  78. */
  79.     GetGWorld    (&saveCGrafPtr,&saveDevice);
  80.     SetGWorld    ((CGrafPtr)AboutMSTDlog,saveDevice);
  81.     
  82. /*
  83. •        Now we begin updating. You MUST call BeginUpdate() just before
  84. •        and EndUpdate() just after doing your drawing. These two calls
  85. •        restrict your drawing to just that portion of the window that
  86. •        needs updating, and resets the window's update region to empty,
  87. •        thus clearing the window's update event.
  88. •        Note: Dialogs, which are merely windows with a little more data added
  89. •        to their struct, actually have their own routines for handling
  90. •        updates, activate events, etc. Which ones are available depends
  91. •        upon the type of dialog (alert, modal, or modeless). Here we treat
  92. •        dialogs just like windows, except for the call to DrawDialog() for
  93. •        the About Box. DrawDialog() simply draws all the dialog items (see
  94. •        the DITL resources) for the dialog, such as static text and buttons.
  95. */
  96.  
  97.     BeginUpdate(AboutMSTDlog);
  98.     DrawDialog(AboutMSTDlog);        /*Draw the static text in the DITL resource*/
  99.  
  100. /*
  101. •        Now draw the little dotted line around the text
  102. */
  103.     for    (loop1=13;loop1<=AboutMSTDlog->portRect.right-13;loop1+=2)
  104.     {
  105.         MoveTo    (loop1,AboutMSTDlog->portRect.top+13);
  106.         Line    (0,0);
  107.         
  108.         MoveTo    (loop1,AboutMSTDlog->portRect.bottom-13);
  109.         Line    (0,0);
  110.     }
  111.     for    (loop1=13;loop1<=AboutMSTDlog->portRect.bottom-13;loop1+=2)
  112.     {
  113.         MoveTo    (AboutMSTDlog->portRect.left+13,    loop1);
  114.         Line    (0,0);
  115.         
  116.         MoveTo    (AboutMSTDlog->portRect.right-13,    loop1);
  117.         Line    (0,0);
  118.     }
  119.  
  120. /*
  121. •        Now finish up by balancing with a call to EndUpdate(), and restore
  122. •        Quickdraw's pointer to the current Grafport to whatever it was
  123. •        before you updated.
  124. */
  125.  
  126.     EndUpdate(AboutMSTDlog);
  127.     SetGWorld    (saveCGrafPtr,saveDevice);
  128. }
  129.  
  130.  
  131. /*_____________________________________________________________________________
  132.                         Do_AboutMST()- handle events directed to the About Box
  133. _____________________________________________________________________________*/
  134.  
  135.  
  136. void    Do_AboutMST    (EventRecord *thisEvent)
  137.  
  138. /*
  139. •        This is just a stub of a function to demonstrate where
  140. •        you could add code to handle mouseclicks, keydowns, or other
  141. •        events directed to the About Box window.
  142. */
  143.  
  144. {
  145. }
  146.