home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 15 / develop 15 code / Floating Windows / Sample / Source / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-17  |  4.4 KB  |  173 lines  |  [TEXT/MPS ]

  1. /*    MPW C Application skeleton by Dean Yu    */
  2. /*    Initialisation routines                    */
  3.  
  4. #include <Types.h>
  5. #include <AppleEvents.h>
  6. #include <Dialogs.h>
  7. #include <Fonts.h>
  8. #include <GestaltEqu.h>
  9. #include <Menus.h>
  10. #include <Quickdraw.h>
  11. #include <ToolUtils.h>
  12. #include <Traps.h>
  13. #include <Windows.h>
  14.  
  15. #include "globals.h"
  16. #include "appleEventHandlers.h"
  17. #include "eventHandler.h"
  18. #include "menuDispatch.h"
  19. #include "trapAvail.h"
  20. #include "WindowExtensions.h"
  21.  
  22. /*    Private routine prototypes */
  23.  
  24. static void InitStuff(void);
  25. static void SetUpMenus(void);
  26. static void SetUpWindows(void);
  27. static void SetupRecordingFloater(void);
  28. static void SetupToolsFloater(void);
  29. static void SetUpLimits(void);
  30. static void SetUpAppleEvents(void);
  31.  
  32. extern void _DataInit();
  33.  
  34. void main()
  35. {
  36.     UnloadSeg((Ptr) _DataInit);
  37.  
  38.     MaxApplZone();
  39.  
  40.     InitStuff();
  41.     EventLoop();
  42. }
  43.  
  44. void InitStuff()
  45. {
  46.     EventRecord    firstEvent;
  47.     OSErr        gestaltError;
  48.     long        gestaltResponse;
  49.     
  50.     InitGraf((Ptr) &qd.thePort);
  51.     InitFonts();
  52.     InitWindows();
  53.     InitMenus();
  54.     InitDialogs(nil);
  55.     InitCursor();
  56.     
  57.     if (!TrapAvailable(_Gestalt))                                            /* Look for _Gestalt */
  58.         FatalErrorAlert(kSystemVersionTooOld);
  59.     
  60.     WaitNextEvent(everyEvent, &firstEvent, 60, nil);
  61.     FlushEvents(everyEvent, 0);
  62.     
  63.     /*    Check to see if certain features are implemented */
  64.     
  65.     gestaltError = Gestalt(gestaltAppleEventsAttr, &gestaltResponse);        /* Check for AppleEvents™ */
  66.     if (!gestaltError)
  67.         {
  68.             if ((gestaltResponse & (1 << gestaltAppleEventsPresent)) == 0)
  69.                 FatalErrorAlert(kNoAppleEvents);
  70.         }
  71.     else
  72.         FatalErrorAlert(kGestaltError);
  73.     
  74.     gestaltError = Gestalt(gestaltPPCToolboxAttr, &gestaltResponse);        /* Check for PPC Toolbox */
  75.     if (gestaltError)
  76.         FatalErrorAlert(kGestaltError);
  77.     
  78.     SetUpMenus();
  79.     SetUpWindows();
  80.     SetUpLimits();
  81.     SetUpAppleEvents();
  82. }
  83.  
  84.  
  85. /*    Get the menu bar from resource fork.  Fill  menu with DAs.  Draw it */
  86.  
  87. void SetUpMenus()
  88. {
  89.     Handle    theMenu;
  90.     
  91.     theMenu = GetNewMBar(rMbarID);
  92.     SetMenuBar(theMenu);
  93.     DisposHandle(theMenu);
  94.     AddResMenu(GetMHandle(rAppleMenuID),'DRVR');
  95.     DisableItem(GetMHandle(rEditMenuID), 0);
  96.     CheckItem(GetMHandle(rFloatersMenuID), kRecordingItem, true);
  97.     CheckItem(GetMHandle(rFloatersMenuID), kToolsItem, true);
  98.     DrawMenuBar();
  99. }
  100.  
  101. /*
  102.     Set up any windows needed by the application
  103. */
  104.  
  105. void SetUpWindows()
  106. {
  107.     SetupRecordingFloater();
  108.     SetupToolsFloater();
  109.     
  110.     gActivateEventHandler = NewActivateHandlerProc(&ActivateEventHandler);
  111. }
  112.  
  113. void SetupRecordingFloater()
  114. {
  115.     Rect        theRect;
  116.     PicHandle    recordingControlsPicture;
  117.     OSErr        error;
  118.     
  119.     recordingControlsPicture = (PicHandle) GetPicture(128);
  120.     theRect = (**recordingControlsPicture).picFrame;
  121.     OffsetRect(&theRect, 70, 70);
  122.     
  123.     gRecordingFloaterActivateHandler = NewActivateHandlerProc(&RecordingFloaterActivateHandler);
  124.     error = NewWindowReference(&gRecordingFloater, &theRect, "\pRecord", true, kHasPaletteTitlebarMask,
  125.                                 (WindowRef) -1, 0, gRecordingFloaterActivateHandler);
  126.     SetWindowPic((WindowPtr) gRecordingFloater, recordingControlsPicture);
  127. }
  128.  
  129. void SetupToolsFloater()
  130. {
  131.     Rect        theRect;
  132.     PicHandle    toolsPicture;
  133.     OSErr        error;
  134.     
  135.     toolsPicture = (PicHandle) GetPicture(130);
  136.     theRect = (**toolsPicture).picFrame;
  137.     OffsetRect(&theRect, 170, 100);
  138.     
  139.     gToolsFloaterActivateHandler = NewActivateHandlerProc(&ToolsFloaterActivateHandler);
  140.     error = NewWindowReference(&gToolsFloater, &theRect, "\pTools", true, kHasPaletteTitlebarMask,
  141.                                 (WindowRef) -1, 0, gToolsFloaterActivateHandler);
  142.     SetWindowPic((WindowPtr) gToolsFloater, toolsPicture);
  143. }
  144.  
  145. /*
  146.     Set up areas for the screen in which windows can be dragged and sized.
  147. */
  148.  
  149. void SetUpLimits()
  150. {
  151.     RgnHandle    deskTop;
  152.     
  153.     deskTop = GetGrayRgn();
  154.     gDragArea = (**deskTop).rgnBBox;
  155.     SetRect(&gGrowBounds, 48, 48,
  156.             ((gDragArea.right) - (gDragArea.left)),((gDragArea.bottom) - (gDragArea.top)));
  157. }
  158.  
  159. /*    Set up the AppleEvent dispatch table */
  160.  
  161. void SetUpAppleEvents()
  162. {
  163.     OSErr    installAppleEventError;
  164.     
  165.     installAppleEventError = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, (AEEventHandlerUPP) &OAPPHandler, 0, false);
  166.     installAppleEventError = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, (AEEventHandlerUPP) &ODOCHandler, 0, false);
  167.     installAppleEventError = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, (AEEventHandlerUPP) &PDOCHandler, 0, false);
  168.     installAppleEventError = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, (AEEventHandlerUPP) &QUITHandler, 0, false);
  169.  
  170.     if (installAppleEventError)
  171.         FatalErrorAlert(kAEInstallError);
  172. }
  173.