home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / AESample.sit / AESample / sources / sample.subs.c < prev   
Text File  |  1996-06-22  |  9KB  |  355 lines

  1. /*
  2.  *--------------------------------------------------------------
  3.  * sample.subs.c
  4.  *--------------------------------------------------------------
  5.  */
  6. #include <Gestalt.h>
  7.  
  8. #include "sample.h"
  9. #include "sample.subs.h"
  10. #include "sample.dlog.h"
  11. #include "sample.alrt.h"
  12. #include "custom.wind.h"
  13.  
  14. /*
  15.  *--------------------------------------------------------------
  16.  * globals
  17.  *--------------------------------------------------------------
  18.  */
  19. Cursor    gWaitCursor;
  20.  
  21. /*
  22.  *--------------------------------------------------------------
  23.  * GestaltChecks
  24.  *--------------------------------------------------------------
  25.  *    this sample just checks System Version but
  26.  *    you should check other materials whatever you need
  27.  *--------------------------------------------------------------
  28.  */
  29. Boolean GestaltChecks(void)
  30. {
  31.     long    gestaltAnswer;
  32.     OSErr    result;
  33.  
  34.     result = Gestalt(gestaltVersion, &gestaltAnswer);
  35.     if (result != noErr) {
  36.         return (false);
  37.     }
  38.     result = Gestalt(gestaltSystemVersion, &gestaltAnswer);
  39.     if ((result != noErr) || (gestaltAnswer < 0x0700)) {
  40.         return (false);
  41.     }    
  42.     return (true);
  43. }
  44. /*
  45.  *--------------------------------------------------------------
  46.  * SetUpPreferences
  47.  *--------------------------------------------------------------
  48.  *    load data from the preferences file or
  49.  *    initialize preferences in here
  50.  *--------------------------------------------------------------
  51.  */
  52. Boolean SetUpPreferences(void)
  53. {
  54.     /*
  55.         setup prefs here
  56.     */
  57.     return (true);
  58. }
  59. /*
  60.  *--------------------------------------------------------------
  61.  * SetUpMyCursors
  62.  *--------------------------------------------------------------
  63.  *    load cursor data in here
  64.  *--------------------------------------------------------------
  65.  */
  66. Boolean SetUpMyCursors(void)
  67. {
  68.     gWaitCursor  = **GetCursor(watchCursor);
  69.     SetCursor(&gWaitCursor);
  70.     return (true);
  71. }
  72. /*
  73.  *--------------------------------------------------------------
  74.  * SetUpMyWindows
  75.  *--------------------------------------------------------------
  76.  *    setup windows
  77.  *--------------------------------------------------------------
  78.  */
  79. Boolean SetUpMyWindows(void)
  80. {
  81.     if (!SetUpMyMainWindow()) return (false);
  82.     /*
  83.         setup other windows in here
  84.     */
  85.     return (true);
  86. }
  87. /*
  88.  *--------------------------------------------------------------
  89.  * AdjustMyCursor
  90.  *--------------------------------------------------------------
  91.  *    change cursor status according to current conditions
  92.  *--------------------------------------------------------------
  93.  */
  94. void AdjustMyCursor(void)
  95. {
  96.     /*
  97.         this is just a CW.
  98.         implement such as TEIdle here
  99.     */
  100.     if (gNowBackGround == false) {
  101.         InitCursor();
  102.     }
  103. }
  104. /*
  105.  *--------------------------------------------------------------
  106.  * DoUpdate
  107.  *--------------------------------------------------------------
  108.  *    handle update event here
  109.  *--------------------------------------------------------------
  110.  */
  111. void DoUpdate(EventRecord *theEvent)
  112. {
  113.     WindowRef    aWindow = (WindowRef)theEvent->message;
  114.  
  115.     if (aWindow != nil) {
  116.         BeginUpdate(aWindow);
  117.  
  118.         /*
  119.             handle update event; draw window or so.
  120.         */
  121.         if (aWindow == gMainWindow) {
  122.             DrawMyMainWindow();
  123.         }
  124.         EndUpdate(aWindow);
  125.     }
  126. }
  127. /*
  128.  *--------------------------------------------------------------
  129.  * DoActivate
  130.  *--------------------------------------------------------------
  131.  *    handle activate event here
  132.  *--------------------------------------------------------------
  133.  */
  134. void DoActivate(EventRecord *theEvent)
  135. {
  136.     WindowRef    aWindow = (WindowRef)theEvent->message;
  137.     GrafPtr        savePort;
  138.  
  139.     GetPort(&savePort);
  140.     SetPortWindowPort(aWindow);
  141.     /*
  142.         handle activate event.
  143.     */
  144.     SetPort(savePort);
  145. }
  146. /*
  147.  *--------------------------------------------------------------
  148.  * DoContent
  149.  *--------------------------------------------------------------
  150.  *    handle window events here
  151.  *--------------------------------------------------------------
  152.  */
  153. void DoContent(WindowRef theWindow, Point where)
  154. {
  155.     if (FrontWindow() != theWindow){
  156.          SelectWindow(theWindow);
  157.     } else {
  158.         if (theWindow == gMainWindow) {
  159.             DoMyMainWindow(where);
  160.         }
  161.         /*
  162.             handle other window events
  163.         */
  164.     }
  165. }
  166. /*
  167.  *--------------------------------------------------------------
  168.  * DoGrow
  169.  *--------------------------------------------------------------
  170.  *    handle grow window here
  171.  *--------------------------------------------------------------
  172.  */
  173. void DoGrow(WindowRef theWindow, Point where)
  174. {
  175.     GrafPtr    savedPort;
  176.     Rect    maxRect, sizeLimits;
  177.     long    newSize;
  178.  
  179.     GetPort(&savedPort);
  180.     SetPortWindowPort(theWindow);
  181.  
  182.     maxRect = (**GetGrayRgn()).rgnBBox;
  183.     sizeLimits.top = 128;    /* minimum height */
  184.     sizeLimits.left = maxRect.bottom - maxRect.top;    /* maximum height */
  185.     sizeLimits.bottom = 128;    /* minimum width */
  186.     sizeLimits.right = maxRect.right - maxRect.left;    /* maximum width */
  187.  
  188.     newSize = GrowWindow(theWindow, where, &sizeLimits);
  189.     if (newSize != 0) {
  190.         short    newHigh = HiWord(newSize);
  191.         short    newWide = LoWord(newSize);
  192.     /*
  193.         adjust controls in the window
  194.     */
  195.     }
  196.     SetPort(savedPort);
  197. }
  198. /*
  199.  *--------------------------------------------------------------
  200.  * DoDrag
  201.  *--------------------------------------------------------------
  202.  *    handle grow window here
  203.  *--------------------------------------------------------------
  204.  */
  205. void DoDrag(WindowRef theWindow, Point where)
  206. {
  207.     Rect    maxRect;
  208.  
  209.     maxRect = (**GetGrayRgn()).rgnBBox;
  210.     InsetRect(&maxRect, 8, 8);    // have mergines
  211.  
  212.     DragWindow(theWindow, where, &maxRect);
  213.     /*
  214.         remember window position if needed
  215.     */
  216. }
  217. /*
  218.  *--------------------------------------------------------------
  219.  * DoGoAway
  220.  *--------------------------------------------------------------
  221.  *    handle grow window here
  222.  *--------------------------------------------------------------
  223.  */
  224. void DoGoAway(WindowRef theWindow, Point where)
  225. {
  226.     if (TrackGoAway(theWindow, where)) {
  227.         /*
  228.             hide or dispose the window
  229.         */
  230.         if (theWindow == gMainWindow) gForever = false;
  231.         else
  232.         if (theWindow == gViewDialog) HideWindow(gViewDialog);
  233.     }
  234. }
  235. /*
  236.  *--------------------------------------------------------------
  237.  * DoZoom
  238.  *--------------------------------------------------------------
  239.  *    handle zoom window here
  240.  *--------------------------------------------------------------
  241.  */
  242. void DoZoom(WindowRef theWindow, Point where, const short zoom)
  243. {
  244.     if (TrackBox(theWindow, where, zoom)) {
  245.         if (theWindow == gMainWindow) {
  246.             ZoomMyMainWindow(zoom);
  247.         } else {
  248.             ZoomWindow(theWindow, zoom, false);
  249.         }
  250.         /*
  251.             adjust controls in the window
  252.         */
  253.     }
  254. }
  255. /*
  256.  *--------------------------------------------------------------
  257.  *    DoOSEvent
  258.  *--------------------------------------------------------------
  259.  *    suspend and resule event handling
  260.  *--------------------------------------------------------------
  261.  */
  262. void DoOSEvent(EventRecord *theEvent)
  263. {
  264.     short    messageKind = (theEvent->message >> 24) & 0xff;
  265.     short    messageFlag = theEvent->message & 0xff;
  266.  
  267.     if (messageKind == suspendResumeMessage) {
  268.         if (messageFlag & resumeFlag) {
  269.             gNowBackGround = false;
  270.             if (messageFlag & convertClipboardFlag) {
  271.                 DoConvertScrap(kClipboardToPrivate);
  272.             }
  273.             DoResume(theEvent);
  274.         } else {
  275.             gNowBackGround = true;
  276.             DoConvertScrap(kPrivateToClipboard);
  277.             DoSuspend(theEvent);
  278.         }
  279.         /* redraw dialog button frame */
  280.         if (IsWindowVisible(GetDialogWindow(gViewDialog))) {
  281.             FrameBoldButton(gViewDialog, ok);
  282.         }
  283.     }
  284. }
  285. /*
  286.  *--------------------------------------------------------------
  287.  * DoResume
  288.  *--------------------------------------------------------------
  289.  *    handle resume event
  290.  *--------------------------------------------------------------
  291.  */
  292. void DoResume(EventRecord *theEvent)
  293. {
  294. #pragma unused (theEvent) /* remove this when you implement real handler */
  295. }
  296. /*
  297.  *--------------------------------------------------------------
  298.  * DoSuspend
  299.  *--------------------------------------------------------------
  300.  *    handle suspend event
  301.  *--------------------------------------------------------------
  302.  */
  303. void DoSuspend(EventRecord *theEvent)
  304. {
  305. #pragma unused (theEvent) /* remove this when you implement real handler */
  306. }
  307. /*
  308.  *--------------------------------------------------------------
  309.  * DoConvertScrap
  310.  *--------------------------------------------------------------
  311.  *    exchange data between private scrap and system scrap
  312.  *--------------------------------------------------------------
  313.  */
  314. void DoConvertScrap(Boolean toScrap)
  315. {
  316.     if (toScrap == true) {
  317.         /*
  318.             copy local buffer to clipboard
  319.         */
  320.     } else {
  321.         /*
  322.             copy clipboard to local buffer
  323.         */
  324.     }
  325. }
  326. /*
  327.  *--------------------------------------------------------------
  328.  * DoMountDisk
  329.  *--------------------------------------------------------------
  330.  *    disk mount check
  331.  *--------------------------------------------------------------
  332.  */
  333. void DoMountDisk(EventRecord *theEvent)
  334. {
  335.     Point    warnPos = {64, 64};
  336.     long    diskMessage = theEvent->message;
  337.  
  338.     if (HiWord(diskMessage) != noErr) {
  339.         DIBadMount(warnPos, diskMessage);
  340.     }
  341. }
  342. /*
  343.  *--------------------------------------------------------------
  344.  * SaveMyPreferences
  345.  *--------------------------------------------------------------
  346.  *    save preference data to preference file
  347.  *--------------------------------------------------------------
  348.  */
  349. void SaveMyPreferences(void)
  350. {
  351.     /*
  352.         store prefernces data in your preferences file
  353.     */
  354. }
  355.