home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Tool Chest / Dev.CD Feb 97 TC.toast / Sample Code / QuickTime / JPEG Sample / Source / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-22  |  3.8 KB  |  176 lines  |  [TEXT/MPCC]

  1. /*************************************************************************************
  2. #
  3. #        init.c
  4. #
  5. #        basic initialization code.
  6. #
  7. #        Author(s):     Michael Marinkovich & Guillermo Ortiz
  8. #                    Apple Developer Technical Support
  9. #                    marink@apple.com
  10. #
  11. #        Modification History: 
  12. #
  13. #            4/3/96        MWM     Initial coding                     
  14. #
  15. #        Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved
  16. #
  17. #
  18. #        You may incorporate this sample code into your applications without
  19. #        restriction, though the sample code has been provided "AS IS" and the
  20. #        responsibility for its operation is 100% yours.  However, what you are
  21. #        not permitted to do is to redistribute the source as "DSC Sample Code"
  22. #        after having made changes. If you're going to re-distribute the source,
  23. #        we require that you make it clear in the source that the code was
  24. #        descended from Apple Sample Code, but that you've made changes.
  25. #
  26. *************************************************************************************/
  27.  
  28. #include <AppleEvents.h>
  29. #include <Displays.h>
  30. #include <Events.h>
  31. #include <Fonts.h>
  32. #include <Gestalt.h>
  33. #include <Menus.h>
  34. #include <OSUtils.h>
  35.  
  36. #include "App.h"
  37. #include "Proto.h"
  38.  
  39.  
  40. //----------------------------------------------------------------------
  41. //
  42. //    Globals - 
  43. //
  44. //----------------------------------------------------------------------
  45.  
  46. extern Boolean             gHasDMTwo;
  47. extern Boolean             gHasDrag;
  48. extern Boolean            gInBackground;
  49. extern short            gWindCount;
  50.  
  51.  
  52. //----------------------------------------------------------------------
  53. //
  54. //    Initialize - the main entry point for the initialization
  55. //
  56. //
  57. //----------------------------------------------------------------------
  58.  
  59. OSErr Initialize(void)
  60. {
  61.     OSErr        err = noErr;
  62.     
  63.     
  64.     ToolBoxInit();
  65.     CheckEnvironment();
  66.     err = InitApp();
  67.     
  68.     return err;
  69. }
  70.  
  71.  
  72. //----------------------------------------------------------------------
  73. //
  74. //    ToolBoxInit - initialization all the needed managers
  75. //
  76. //
  77. //----------------------------------------------------------------------
  78.  
  79. void ToolBoxInit(void)
  80. {
  81.  
  82.     InitGraf(&qd.thePort);
  83.     InitFonts();
  84.     InitWindows();
  85.     InitMenus();
  86.     TEInit();
  87.     InitDialogs(nil);
  88.     InitCursor();
  89.         
  90.     FlushEvents(everyEvent, 0);
  91.  
  92. }
  93.  
  94.  
  95. //----------------------------------------------------------------------
  96. //
  97. //    CheckEnvironment - make sure we can run with current sys and managers.
  98. //                       Also initialize globals - have drag & drop
  99. //                      
  100. //----------------------------------------------------------------------
  101.  
  102. void CheckEnvironment(void)
  103. {
  104.     OSErr            err;
  105.     long            response;
  106.     
  107.  
  108.     // check to see if the Display Manager is present. If it is 
  109.     // then we have a PowerMac or System 7.5.
  110.     err = Gestalt(gestaltDisplayMgrAttr, &response);
  111.     
  112.     if (err != noErr || ((response & (1 << gestaltDisplayMgrPresent)) == 0))
  113.          HandleAlert(kNeedsDisplayManager);
  114.     
  115.     // check for Display Manager 2.0
  116.     else {
  117.         Gestalt(gestaltDisplayMgrVers, (long*)&response);
  118.         gHasDMTwo = (response >= 0x00020000);
  119.     }
  120.  
  121. }
  122.  
  123.  
  124. //----------------------------------------------------------------------
  125. //
  126. //    InitApp - initialization all the application specific stuff
  127. //
  128. //
  129. //----------------------------------------------------------------------
  130.  
  131. OSErr InitApp(void)
  132. {
  133.     OSErr                err;
  134.  
  135.     // init AppleEvents
  136.     err = AEInit();
  137.     MenuSetup();
  138.  
  139.     // we have DM 2.0 so install
  140.     // world changed notification proc
  141.     if (gHasDMTwo)
  142.         err = InstallDMNotification();
  143.  
  144.     // we have DM 1.0 so install AppleEvent Notification
  145.     else
  146.         err = InstallAEDMNotification();
  147.  
  148.     // init any globals
  149.     gWindCount = 1;
  150.  
  151.     return err;                    
  152. }
  153.  
  154.  
  155. //----------------------------------------------------------------------
  156. //
  157. //    MenuSetup - 
  158. //
  159. //
  160. //----------------------------------------------------------------------
  161.  
  162. void MenuSetup(void)
  163. {
  164.     Handle            menu;
  165.         
  166.         
  167.     menu = GetNewMBar(rMBarID);        //    get our menus from resource
  168.     SetMenuBar(menu);
  169.     DisposeHandle(menu);
  170.     AddResMenu(GetMHandle(mApple ), 'DRVR');        //    add apple menu items
  171.  
  172.     DrawMenuBar();
  173.  
  174.         
  175. }
  176.