home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Display Manager SDK / Sample Code / Display Changed CWPro3 / Source / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-20  |  3.7 KB  |  168 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2. #
  3. #        init.c
  4. #
  5. #        basic initialization code.
  6. #
  7. #        Author(s):     Michael Marinkovich
  8. #                    marink@apple.com
  9. #
  10. #        Modification History: 
  11. #
  12. #            1/19/99        ewa     update to CWPro3 and universal interfaces                     
  13. #            10/12/95    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. //    Globals -
  41. //----------------------------------------------------------------------
  42.  
  43. extern Boolean             gHasDMTwo;
  44. extern Boolean             gHasDrag;
  45. extern Boolean            gInBackground;
  46. extern short            gWindCount;
  47.  
  48.  
  49. //----------------------------------------------------------------------
  50. //
  51. //    Initialize - the main entry point for the initialization
  52. //
  53. //
  54. //----------------------------------------------------------------------
  55.  
  56. OSErr Initialize(void)
  57. {
  58.     OSErr        err = noErr;
  59.     
  60.     
  61.     ToolBoxInit();
  62.     CheckEnvironment();
  63.     err = InitApp();
  64.     
  65.     return err;
  66. }
  67.  
  68.  
  69. //----------------------------------------------------------------------
  70. //
  71. //    ToolBoxInit - initialization all the needed managers
  72. //
  73. //
  74. //----------------------------------------------------------------------
  75.  
  76. void ToolBoxInit(void)
  77. {
  78.  
  79.     InitGraf(&qd.thePort);
  80.     InitFonts();
  81.     InitWindows();
  82.     InitMenus();
  83.     TEInit();
  84.     InitDialogs(nil);
  85.     InitCursor();
  86.         
  87.     FlushEvents(everyEvent, 0);
  88.  
  89. }
  90.  
  91.  
  92. //----------------------------------------------------------------------
  93. //
  94. //    CheckEnvironment - make sure we can run with current sys and managers.
  95. //                       Also initialize globals - have drag & drop
  96. //                      
  97. //----------------------------------------------------------------------
  98.  
  99. void CheckEnvironment(void)
  100. {
  101.     OSErr            err;
  102.     long            response;
  103.     
  104.  
  105.     // check to see if the Display Manager is present. If it is 
  106.     // then we have a PowerMac or System 7.5.
  107.     err = Gestalt(gestaltDisplayMgrAttr, &response);
  108.     
  109.     if (err != noErr || ((response & (1 << gestaltDisplayMgrPresent)) == 0))
  110.          HandleAlert(kNeedsDisplayManager);
  111.     
  112.     // check for Display Manager 2.0
  113.     else 
  114.     {
  115.         Gestalt(gestaltDisplayMgrVers, (long*)&response);
  116.         gHasDMTwo = (response >= 0x00020000);
  117.     }
  118.  
  119. }
  120.  
  121.  
  122. //----------------------------------------------------------------------
  123. //
  124. //    InitApp - initialization all the application specific stuff
  125. //
  126. //
  127. //----------------------------------------------------------------------
  128.  
  129. OSErr InitApp(void)
  130. {
  131.     OSErr                err;
  132.  
  133.     // init AppleEvents
  134.     err = AEInit();
  135.     MenuSetup();
  136.     
  137.     // install AppleEvent Display Notification
  138.     err = InstallAEDMNotification();
  139.  
  140.     // init any globals
  141.     gWindCount = 1;
  142.  
  143.     return err;                    
  144. }
  145.  
  146.  
  147. //----------------------------------------------------------------------
  148. //
  149. //    MenuSetup - 
  150. //
  151. //
  152. //----------------------------------------------------------------------
  153.  
  154. void MenuSetup(void)
  155. {
  156.     Handle            menu;
  157.         
  158.         
  159.     menu = GetNewMBar(rMBarID);        //    get our menus from resource
  160.     SetMenuBar(menu);
  161.     DisposeHandle(menu);
  162.     AppendResMenu(GetMenuHandle(mApple ), 'DRVR');        //    add apple menu items
  163.  
  164.     DrawMenuBar();
  165.  
  166.         
  167. }
  168.