home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / DropFTP / DropShell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  6.4 KB  |  283 lines  |  [TEXT/MPS ]

  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        Time    Author    Description
  23. **    --------    -----    ------    ---------------------------------------------
  24. **    12/09/91            LDR        Added support for new "Select File…" menu item
  25. **                                Quit now sends AEVT to self to be politically correct
  26. **                                Added support for the new gSplashScreen
  27. **    11/24/91            LDR        Added support for the Apple Menu (duh!)
  28. **    10/29/91            SCS        Changes for THINK C 5
  29. **    10/28/91            LDR        Officially renamed DropShell (from QuickShell)
  30. **                                Added a bunch of comments for clarification
  31. **    10/06/91    00:02    MTC        Converted to MPW C
  32. **    04/09/91    00:02    LDR        Added to Projector
  33. **
  34. ******************************************************************************/
  35.  
  36. #define kOpenFile     1
  37. #define kPrefs        2
  38.  
  39. #include "DSGlobals.h"
  40. #include "DSUserProcs.h"
  41. #include "DSAppleEvents.h"
  42. #include "ftp.h"
  43. #include "DropShell.h"
  44. #include "DLOG129.h"
  45.  
  46. #ifndef THINK_C
  47.     #include <Fonts.h>
  48.     #include <OSEvents.h>
  49.     #include <Resources.h>
  50.     #include <Desk.h>
  51. #endif
  52.  
  53.  
  54. Boolean        gDone, gOApped, gHasAppleEvents, gWasEvent;
  55. EventRecord    gEvent;
  56. MenuHandle    gAppleMenu, gFileMenu;
  57. WindowPtr    gSplashScreen;
  58.  
  59. OSErr InitNetwork(void);
  60. extern void _DataInit();    
  61.  
  62. /*
  63.     Simple routine installed by InitDialogs for the Resume button in Bomb boxes
  64. */
  65. #pragma segment Main
  66.  
  67. void Panic () {
  68.     ExitToShell ();
  69. }
  70.  
  71.  
  72. #pragma segment Initialize
  73. void InitToolbox (void) 
  74. {
  75.  
  76. #ifndef THINK_C
  77.     UnloadSeg ((Ptr) _DataInit );
  78. #endif
  79.  
  80.     InitGraf ( &qd.thePort );
  81.     InitFonts ();
  82.     InitWindows ();
  83.     InitMenus ();
  84.     TEInit ();
  85.     InitDialogs ((ResumeProcPtr) Panic );
  86.     InitCursor ();
  87.     FlushEvents ( everyEvent, 0 );
  88.     
  89.     // how about some memory fun! Two should be enough!
  90.     MoreMasters ();
  91.     MoreMasters ();
  92.     }
  93.  
  94. /*
  95.     Let's setup those global variables that the DropShell uses.
  96.     
  97.     If you add any globals for your own use,
  98.     init them in the InitUserGlobals routine in DSUserProcs.c
  99. */
  100. #pragma segment Initialize
  101. Boolean InitGlobals (void) 
  102. {
  103.     long aLong;
  104.     short oe;
  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.     oe =  InitNetwork ();
  112.     return(InitUserGlobals());    // call the user proc
  113.     
  114. }
  115.  
  116. /*
  117.     Again, nothing fancy.  Just setting up the menus.
  118.     
  119.     If you add any menus to your DropBox - insert them here!
  120. */
  121. #pragma segment Initialize
  122. void SetUpMenus (void) {
  123.  
  124.     gAppleMenu = GetMenu ( kAppleNum );
  125.     AddResMenu ( gAppleMenu, 'DRVR' );
  126.     InsertMenu ( gAppleMenu, 0 );
  127.  
  128.     gFileMenu = GetMenu ( kFileNum );
  129.     InsertMenu ( gFileMenu, 0 );
  130.     DrawMenuBar ();
  131. }
  132.  
  133. /*
  134.     This routine is called during startup to display a splash screen.
  135.     
  136.     This was recommend by the Blue Team HI person, John Sullivan, who
  137.     feels that all apps should display something so that users can easily
  138.     tell what is running, and be able to switch by clicking.  Thanks John!
  139. */
  140. #pragma segment Initialize
  141. void InstallSplashScreen(void) 
  142. {
  143.     #define windowPicID    128
  144.  
  145.     PicHandle    picH;
  146.  
  147.     if (!gSplashScreen) {  // show the splash screen window
  148.         picH = GetPicture(windowPicID);
  149.         if (picH) {
  150.             gSplashScreen = GetNewWindow(windowPicID, NULL, (WindowPtr)-1L);
  151.             if (gSplashScreen) {
  152.             //    SetWindowPic(gSplashScreen, picH);
  153.                 // Don't show it here, since we only want to it for oapp launches!
  154.                 // ShowWindow(gSplashScreen);
  155.             }
  156.         }
  157.     }
  158. }
  159.  
  160.  
  161. /*    --------------- Standard Event Handling routines ---------------------- */
  162. #pragma segment Main
  163. void ShowAbout () {
  164.     (void) Alert ( 128, NULL );
  165.     }
  166.  
  167.  
  168.  
  169. #pragma segment Main
  170. void DoMenu ( long retVal ) {
  171.     short    menuID, itemID;
  172.     Str255    itemStr;
  173.  
  174.     menuID = HiWord ( retVal );
  175.     itemID = LoWord ( retVal );
  176.     
  177.     switch ( menuID ) {
  178.         case kAppleNum:
  179.             if ( itemID == 1 )
  180.                 ShowAbout ();    /*    Show the about box */
  181.             else
  182.             {
  183.                 GetItem(GetMHandle(kAppleNum), itemID, itemStr);
  184.                 OpenDeskAcc(itemStr);
  185.             }
  186.             break;
  187.             
  188.         case kFileNum:
  189.             switch ( itemID) {
  190.                 case kOpenFile:
  191.                     SelectFile();        // call file selection userProc
  192.                     break;
  193.                 case kPrefs:
  194.                     DoPrefs(true);
  195.                     break;
  196.                 default:
  197.                     SendQuitToSelf();    // send self a 'quit' event
  198.             }
  199.         default:
  200.             break;
  201.             
  202.         }
  203.     HiliteMenu(0);        // turn it off!
  204.     }
  205.  
  206.  
  207. #pragma segment Main
  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.             #ifndef THINK_C
  224.                 DragWindow ( whichWindow, curEvent->where, &qd.screenBits.bounds );
  225.             #else
  226.                 DragWindow ( whichWindow, curEvent->where, &screenBits.bounds );
  227.             #endif
  228.         default:
  229.             break;
  230.         }
  231.     }
  232.  
  233.  
  234. #pragma segment Main
  235. void DoKeyDown ( EventRecord *curEvent ) {
  236.     if ( curEvent->modifiers & cmdKey )
  237.         DoMenu ( MenuKey ((char) curEvent->message & charCodeMask ));
  238.     }
  239.  
  240.  
  241.  
  242. #pragma segment Main
  243. void main ( ) 
  244. {
  245.  
  246.     InitToolbox ();
  247.     if ( InitGlobals () ) {    // if we succeeding in initting self
  248.         if ( !gHasAppleEvents )
  249.             ErrorAlert ( kErrStringID, kCantRunErr, 0 );
  250.         else {
  251.             InitAEVTStuff ();
  252.             SetUpMenus ();
  253.             InstallSplashScreen ();
  254.             
  255.             while ( !gDone ) {
  256.                 gWasEvent = WaitNextEvent ( everyEvent, &gEvent, 0, NULL );
  257.                 if ( gWasEvent ) {
  258.                     switch ( gEvent.what ) {
  259.                         case kHighLevelEvent:
  260.                             DoHighLevelEvent ( &gEvent );
  261.                             break;
  262.                             
  263.                         case mouseDown:
  264.                             DoMouseDown ( &gEvent );
  265.                             break;
  266.                             
  267.                         case keyDown:
  268.                         case autoKey:
  269.                             DoKeyDown ( &gEvent );
  270.                             break;
  271.                         case updateEvt:
  272.                             HandleUpdate((WindowPtr)(gEvent.message));
  273.                             break;    
  274.                         default:
  275.                             break;
  276.                     }
  277.                 }
  278.             }
  279.         }
  280.         DisposeUserGlobals();    // call the userproc to clean itself up
  281.     }
  282. }
  283.