home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / online / source / c / compilers / Tickle-4.0.sit.hqx / Tickle-4.0 / src / init.c < prev    next >
Text File  |  1993-11-21  |  5KB  |  210 lines

  1.  
  2. #pragma segment MISC
  3.  
  4. /*
  5. ** This source code was written by Tim Endres
  6. ** Email: time@ice.com.
  7. ** USMail: 8840 Main Street, Whitmore Lake, MI  48189
  8. **
  9. ** Some portions of this application utilize sources
  10. ** that are copyrighted by ICE Engineering, Inc., and
  11. ** ICE Engineering retains all rights to those sources.
  12. **
  13. ** Neither ICE Engineering, Inc., nor Tim Endres, 
  14. ** warrants this source code for any reason, and neither
  15. ** party assumes any responsbility for the use of these
  16. ** sources, libraries, or applications. The user of these
  17. ** sources and binaries assumes all responsbilities for
  18. ** any resulting consequences.
  19. */
  20.  
  21. #include "tickle.h"
  22. #include <fcntl.h>
  23. #include <string.h>
  24. #include <traps.h>
  25. #include "tge.h"
  26. #include "tclMac.h"
  27.  
  28.  
  29. #pragma segment Init
  30.  
  31. InitApplication()
  32.     {
  33.     int        i;
  34.     char    volname[32];
  35.     Handle    SystemResource();
  36.  
  37.     /*
  38.     ** FIRST THING!!!!
  39.     ** Before any lame procedures start changing the directory...
  40.     */
  41.     TclMac_CWDInitialize();
  42.  
  43.     /* Initialize globals before calling other
  44.     ** initialization routines, as they may need
  45.     ** these globals to be initialized.
  46.     */
  47.     verbose = true;
  48.     quiet = false;
  49.     
  50.     /* Get application's open resource fork reference number. */
  51.     app_refnum = CurResFile();
  52.     /* Get working directory/volume reference number of application. */
  53.     GetVol(volname, &app_vrefnum);
  54.     g_log_wdref = app_vrefnum;
  55.     
  56.     if ( GetRefnumFileName(app_filename, app_refnum) != noErr )
  57.         {
  58.         strcpy(app_filename, "Tickle");
  59.         c2pstr(app_filename);
  60.         }
  61.  
  62. #ifdef TCL_APPL
  63.     SFWDDefault(app_vrefnum);
  64.     SFSaveDefault();
  65. #endif
  66.     
  67.     /* Set up some Macintosh variables for the desktop stuff. */
  68.     dragrect = scrnrect = qd.screenBits.bounds;
  69.     dragrect.top += 20;            /* Adjust for menu bar (20 pels)    */
  70.     InsetRect(&dragrect, 4, 4);    /* Limit to ON screen                */
  71.     
  72.     has_wait_next_event = WNEAvailable();
  73.  
  74. #ifdef TCLENGINE
  75.     SetVol(NULL, app_vrefnum);
  76.     logfile = fopen("ENGINE LOG", "a");
  77.     if (logfile == NULL)
  78.         {
  79.         extern int errno;
  80.         
  81.         message_alert("Error #%d opening log file.", errno);
  82.         }
  83. #endif
  84.     
  85. #ifdef TCLAPPL
  86.     /* Initialize our focus-ing routines. */
  87.     InitFocus();
  88.  
  89.     /* Set up the Macintosh menus for DiskTool. */
  90.     create_menus();
  91.  
  92.     /*
  93.     ** WARNING: Be sure to do this AFTER setting up scrnrect, which CenterAll()'s
  94.     **          algorithm requires.
  95.     */
  96.     CenterAll((ResType)'DLOG', 1);
  97.     CenterAll((ResType)'ALRT', 1);
  98.     PrintInit();
  99. #endif
  100.     
  101.     notify_icons[NOTIFY_COPY_COMPLETE]
  102.                 = SystemResource((ResType)'SICN', NOTIFY_ID(NOTIFY_COPY_COMPLETE));
  103.     notify_icons[NOTIFY_BINHEX]
  104.                 = SystemResource((ResType)'SICN', NOTIFY_ID(NOTIFY_BINHEX));
  105.     notify_icons[NOTIFY_SIT]
  106.                 = SystemResource((ResType)'SICN', NOTIFY_ID(NOTIFY_SIT));
  107.     notify_icons[NOTIFY_ZED]
  108.                 = SystemResource((ResType)'SICN', NOTIFY_ID(NOTIFY_ZED));
  109.     notify_icons[NOTIFY_UU]
  110.                 = SystemResource((ResType)'SICN', NOTIFY_ID(NOTIFY_UU));
  111.     notify_icons[NOTIFY_NEED_DISK]
  112.                 = SystemResource((ResType)'SICN', NOTIFY_ID(NOTIFY_NEED_DISK));
  113.     for (i=0; i < NUM_OF_NOTIFY_ICONS; i++)
  114.         HNoPurge(notify_icons[i]);
  115.     
  116.     tge_sicns = GetResource((ResType)'SICN', (short)8888);
  117.     if (tge_sicns != NULL) {
  118.         LoadResource(tge_sicns);
  119.         DetachResource(tge_sicns);
  120.         MoveHHi(tge_sicns);
  121.         HNoPurge(tge_sicns);
  122.         }
  123.     
  124. #ifdef TCLAPPL
  125.     InitFeedbackWindow();
  126.     ShowFeedback();
  127. #endif
  128.     
  129.     if (gHasAppleEvents)
  130.         InitAEStuff();
  131.     
  132. #ifdef TCLENGINE
  133.     Feedback("tclEngine - Derived from uAccess and other USENET efforts.");
  134. #else
  135.     Feedback("tickle - Derived from uAccess and other USENET efforts.");
  136. #endif
  137.  
  138.     TclMac_InitializeOnce(app_refnum);
  139.     
  140.     TclTickle_InitializeOnce(app_vrefnum);
  141.     
  142.     UInitCursor();
  143.     }
  144.  
  145. ShutDownApplication()
  146.     {
  147. #ifdef TCLAPPL
  148.     WindowPeek    myWindow, lastW = NULL;
  149.  
  150.     /*
  151.     ** Walk through the linked list of visible windows
  152.     ** and send the "close" message to each of OUR windows.
  153.     */
  154.     myWindow = (WindowPeek) FrontWindow();
  155.     while (myWindow != NULL && app_done) {
  156.         if (myWindow == lastW)
  157.             {
  158.             CloseWindow((WindowPtr) myWindow);
  159.             myWindow = (WindowPeek) FrontWindow();
  160.             lastW = (WindowPeek) 0;
  161.             continue;
  162.             }
  163.         
  164.         if (checkmywindow(myWindow))
  165.             wind_parse(myWindow, NULL, wClose);
  166.         
  167.         lastW = myWindow;
  168.         myWindow = (WindowPeek) FrontWindow();
  169.         }
  170. #endif
  171.     
  172.     if (! app_done)
  173.         return;
  174.     
  175.     TclTickle_ShutDown();
  176.     
  177.     clear_notify_q(NOTIFY_ALL);
  178.  
  179.     if (xtcl_refnum != -1)
  180.         CloseResFile(xtcl_refnum);
  181.     
  182.     if (logfile != NULL)
  183.         fclose(logfile);
  184.     }
  185.  
  186. CenterAll(type, high_flag)
  187.     ResType        type;
  188.     int            high_flag;        /* If true, then bump em up a little. */
  189.     {
  190.     short        saveref;        /* ref num of our resource file */
  191.     short        number;            /* number of resources of type rezType */
  192.     short        i;                /* index into resource list */
  193.     Handle        rsrc;            /* handle to resource */
  194.  
  195.     saveref = CurResFile();
  196.     UseResFile(app_refnum);
  197.     
  198.     number = Count1Resources(type);
  199.     for (i = 1; i <= number; i++) {
  200.         rsrc = Get1IndResource(type, i);
  201.         if (rsrc != NULL)
  202.             if (high_flag)
  203.                 HighCenterRect(*( (Rect **) rsrc ));
  204.             else
  205.                 CenterRect(*( (Rect **) rsrc ));
  206.         }
  207.     
  208.     UseResFile(saveref);
  209.     }
  210.