home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 48 / Mac Magazin CD 48.iso / Software / Entwickler / Drop UNIX 1.3 / DropUNIX Library ƒ / Lib Sources / DropShell.c next >
Encoding:
C/C++ Source or Header  |  1997-06-22  |  6.7 KB  |  291 lines  |  [TEXT/CWIE]

  1. /******************************************************************************
  2. **
  3. **  Project Name:    DropShell
  4. **     File Name:    DropShell.c
  5. **
  6. **   Description:    Main application code for the QuickShell
  7. **
  8. *******************************************************************************
  9. **                       A U T H O R   I D E N T I T Y
  10. *******************************************************************************
  11. **
  12. **    Initials    Name
  13. **    --------    -----------------------------------------------
  14. **    LDR            Leonard Rosenthol
  15. **    MTC            Marshall Clow
  16. **    SCS            Stephan Somogyi
  17. **
  18. *******************************************************************************
  19. **                      R E V I S I O N   H I S T O R Y
  20. *******************************************************************************
  21. **
  22. **      Date        Author    Description
  23. **    ---------    ------    ---------------------------------------------
  24. **    04/15/96    RWD        Removed #ifndef __MWERKS__ which caused problems
  25. **                        when not using Precompiled Headers.
  26. **    23 Jun    94    LDR        Implemented support for disk insertion events
  27. **    02 Feb    94    LDR        Updated for Final SDK & CodeWarrior a2
  28. **                        Removed the ResumeProc as per new Apple recommendations
  29. **    11 Dec 93    SCS        Universal Headers/UPPs (Phoenix 68k/PPC & PPCC)
  30. **                        Skipped System 6 compatible rev of DropShell source
  31. **    09 Dec 91    LDR        Added support for new "Select File…" menu item
  32. **                        Quit now sends AEVT to self to be politically correct
  33. **                        Added support for the new gSplashScreen
  34. **    24 Nov 91    LDR        Added support for the Apple Menu (duh!)
  35. **    29 Oct 91    SCS        Changes for THINK C 5
  36. **    28 Oct 91    LDR        Officially renamed DropShell (from QuickShell)
  37. **                        Added a bunch of comments for clarification
  38. **    06 Oct 91    MTC        Converted to MPW C
  39. **    09 Apr 91    LDR        Added to Projector
  40. **
  41. ******************************************************************************/
  42.  
  43. #include <Menus.h>
  44. #include <Devices.h>
  45. #include <Events.h>
  46. #include <Dialogs.h>
  47. #include <Errors.h>
  48. #include <Files.h>
  49. #include <Fonts.h>
  50. #include <Memory.h>
  51. #include <Menus.h>
  52. #include <StandardFile.h>
  53. #include <TextEdit.h>
  54. #include <Types.h>
  55. #include <Windows.h>
  56. #include <DiskInit.h>
  57.  
  58. #include "DSGlobals.h"
  59. #include "DSUtils.h"
  60. #include "DSUserProcs.h"
  61. #include "DSAppleEvents.h"
  62.  
  63. #include "DropShell.h"
  64.  
  65. Boolean        gDone, gOApped, gHasAppleEvents, gWasEvent;
  66. EventRecord    gEvent;
  67. MenuHandle    gAppleMenu, gFileMenu;
  68. WindowPtr    gSplashScreen;
  69.  
  70. #ifdef MPW
  71. extern void _DataInit();    
  72. #endif
  73.  
  74. void InitToolbox (void) 
  75. {
  76.  
  77. #ifdef MPW
  78.     UnloadSeg ((Ptr) _DataInit );
  79. #endif
  80.  
  81.     InitGraf ( &qd.thePort );
  82.     InitFonts ();
  83.     InitWindows ();
  84.     InitMenus ();
  85.     TEInit ();
  86.     InitDialogs (NULL);        // use of ResumeProcs no longer approved by Apple
  87.     InitCursor ();
  88.     FlushEvents ( everyEvent, 0 );
  89.     
  90.     // how about some memory fun! Two should be enough!
  91.     MoreMasters ();
  92.     MoreMasters ();
  93.     }
  94.  
  95. /*
  96.     Let's setup those global variables that the DropShell uses.
  97.     
  98.     If you add any globals for your own use,
  99.     init them in the InitUserGlobals routine in DSUserProcs.c
  100. */
  101.  
  102. Boolean InitGlobals (void) 
  103. {
  104.     long aLong;
  105.  
  106.     gDone            = false;
  107.     gOApped            = false;    // probably not since users are supposed to DROP things!
  108.     gHasAppleEvents    = Gestalt ( gestaltAppleEventsAttr, &aLong ) == noErr;
  109.     gSplashScreen    = NULL;
  110.  
  111.     return(InitUserGlobals());    // call the user proc
  112. }
  113.  
  114. /*
  115.     Again, nothing fancy.  Just setting up the menus.
  116.     
  117.     If you add any menus to your DropBox - insert them here!
  118. */
  119.  
  120. void SetUpMenus (void) {
  121.  
  122. //    gAppleMenu = GetMenu ( kAppleNum );
  123. //    AppendResMenu ( gAppleMenu, 'DRVR' );
  124. //    InsertMenu ( gAppleMenu, 0 );
  125. //
  126. //    gFileMenu = GetMenu ( kFileNum );
  127. //    InsertMenu ( gFileMenu, 0 );
  128.     Handle aHand = NULL;
  129.     aHand = GetNewMBar(128);
  130.     if (aHand != NULL) {
  131.         SetMenuBar(aHand);
  132.         DrawMenuBar ();
  133.     } else {
  134.         Panic ( kResourceLoadError );
  135.     }
  136. }
  137.  
  138. /*
  139.     This routine is called during startup to display a splash screen.
  140.     
  141.     This was recommend by the Blue Team HI person, John Sullivan, who
  142.     feels that all apps should display something so that users can easily
  143.     tell what is running, and be able to switch by clicking.  Thanks John!
  144. */
  145.  
  146. void InstallSplashScreen(void) 
  147. {
  148.     #define windowPicID    128
  149.  
  150.     PicHandle    picH;
  151.  
  152.     if (!gSplashScreen) {  // show the splash screen window
  153.         picH = GetPicture(windowPicID);
  154.         if (picH) {
  155.             gSplashScreen = GetNewWindow(windowPicID, NULL, (WindowPtr)-1L);
  156.             if (gSplashScreen) {
  157.                 SetWindowPic(gSplashScreen, picH);
  158.                 // Don't show it here, since we only want to it for oapp launches!
  159.                 // ShowWindow(gSplashScreen);
  160.             }
  161.         }
  162.     }
  163. }
  164.  
  165.  
  166. /*    --------------- Standard Event Handling routines ---------------------- */
  167.  
  168. void ShowAbout () {
  169.     (void) Alert ( 128, NULL );
  170.     }
  171.  
  172.  
  173.  
  174. void DoMenu ( long retVal ) {
  175.     short    menuID, itemID;
  176.     Str255    itemStr;
  177.  
  178.     menuID = HiWord ( retVal );
  179.     itemID = LoWord ( retVal );
  180.     
  181.     switch ( menuID ) {
  182.         case kAppleNum:
  183.             if ( itemID == 1 )
  184.                 ShowAbout ();    /*    Show the about box */
  185.             else
  186.             {
  187.                 GetMenuItemText(GetMenuHandle(kAppleNum), itemID, itemStr);
  188.                 OpenDeskAcc(itemStr);
  189.             }
  190.             break;
  191.             
  192.         case kFileNum:
  193.             if ( itemID == 1 )
  194.                 SelectFile();        // call file selection userProc
  195.             else
  196.                 SendQuitToSelf();    // send self a 'quit' event
  197.             break;
  198.         
  199.         default:
  200.             break;
  201.             
  202.         }
  203.     HiliteMenu(0);        // turn it off!
  204.     }
  205.  
  206.  
  207.  
  208. void DoMouseDown ( EventRecord *curEvent ) {
  209.     WindowPtr    whichWindow;
  210.     short        whichPart;
  211.  
  212.     whichPart = FindWindow ( curEvent->where, &whichWindow );
  213.     switch ( whichPart ) {
  214.         case inMenuBar:
  215.             DoMenu ( MenuSelect ( curEvent->where ));
  216.             break;
  217.         
  218.         case inSysWindow:
  219.             SystemClick ( curEvent, whichWindow );
  220.             break;
  221.         
  222.         case inDrag:
  223.             {
  224.                 Rect    boundsRect = (*GetGrayRgn())->rgnBBox;
  225.                 DragWindow ( whichWindow, curEvent->where, &boundsRect );
  226.             }
  227.         default:
  228.             break;
  229.         }
  230.     }
  231.  
  232.  
  233.  
  234. void DoKeyDown ( EventRecord *curEvent ) {
  235.     if ( curEvent->modifiers & cmdKey )
  236.         DoMenu ( MenuKey ((char) curEvent->message & charCodeMask ));
  237.     }
  238.  
  239.  
  240.  
  241.  
  242. void main ( ) 
  243. {
  244.     InitToolbox ();
  245.  
  246.     if ( InitGlobals () ) {    // if we succeeding in initting self
  247.         if ( !gHasAppleEvents )
  248.             ErrorAlert ( kErrStringID, kCantRunErr);
  249.         else {
  250.             InitAEVTStuff ();
  251.             SetUpMenus ();
  252.             InstallSplashScreen ();
  253.             
  254.             while ( !gDone ) {
  255.                 gWasEvent = WaitNextEvent ( everyEvent, &gEvent, 0, NULL );
  256.                 if ( gWasEvent ) {
  257.                     switch ( gEvent.what ) {
  258.                         case kHighLevelEvent:
  259.                             DoHighLevelEvent ( &gEvent );
  260.                             break;
  261.                             
  262.                         case mouseDown:
  263.                             DoMouseDown ( &gEvent );
  264.                             break;
  265.                             
  266.                         case keyDown:
  267.                         case autoKey:
  268.                             DoKeyDown ( &gEvent );
  269.                             break;
  270.  
  271.                         case diskEvt:
  272.                             if (HiWord(gEvent.message)) {
  273.                                 Point diskInitPt;
  274.                                 
  275.                                 diskInitPt.v = diskInitPt.h = 100;
  276.                                 DILoad();
  277.                                 DIBadMount(diskInitPt, gEvent.message);
  278.                                 DIUnload();
  279.                             }
  280.                             break;
  281.                             
  282.                         default:
  283.                             break;
  284.                     }
  285.                 }
  286.             }
  287.         }
  288.         DisposeUserGlobals();    // call the userproc to clean itself up
  289.     }
  290. }
  291.