appletops.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletops.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include <Processes.h>
00008 #include "appletstrings.h"
00009 #include "appletops.h"
00010 
00011 
00012 #ifdef MPWC
00013 
00014     #include <osevents.h>
00015 
00016 #endif
00017 
00018 
00019 /*
00020 7/19/94 dmb: Updated for Univeral Headers
00021 */
00022 
00023 
00024 
00025 typedef struct tymemoryconfig {
00026     
00027     long minstacksize; /*minimum stack space required*/
00028     
00029     long minheapsize; /*minimum heap space to run program*/
00030     
00031     long avghandlesize; /*to determine # of master blocks; use zero for none*/
00032     
00033     long reserved1;
00034     
00035     long reserved2;
00036     } tymemoryconfig, **hdlmemoryconfig;
00037 
00038 
00039 
00040 boolean initmacintosh () {
00041 
00042     /*
00043     the magic stuff that every Macintosh application needs to do 
00044     before doing anything else.
00045     
00046     2/4/93 dmb: added support for MCFG resource to enforce heap/stack sizes
00047     */
00048     
00049     short i;
00050     hdlmemoryconfig h;
00051     long ctbytes;
00052     long ctstack, ctheap;
00053     short ctmasters = 10;
00054     
00055     h = (hdlmemoryconfig) Get1Resource ('MCFG', 1);
00056 
00057     if (h != nil) { /*first check stack size*/
00058     
00059         ctbytes = (**h).minstacksize;
00060     
00061         ctstack = LMGetCurStackBase () - GetApplLimit (); /*current stack size*/
00062     
00063         if (ctbytes > ctstack)
00064             SetApplLimit (LMGetCurStackBase () - ctbytes);
00065         }
00066         
00067     MaxApplZone ();
00068     
00069     if (h != nil) { /*check heap size and master pointers*/
00070         
00071         ctbytes = (**h).minheapsize;
00072         
00073         ctheap = FreeMem ();
00074         
00075         if (ctbytes > ctheap)
00076             return (false);
00077         
00078         ctbytes = (**h).avghandlesize;
00079         
00080         if (ctbytes > 0)
00081             ctmasters = (ctheap / ctbytes) / (*GetZone ()).moreMast;
00082         
00083         ReleaseResource ((Handle) h); /*we're done with it*/
00084         }
00085     
00086     for (i = 1; i <= ctmasters; i++) 
00087         MoreMasters ();
00088     
00089     InitGraf (&quickdrawglobal (thePort));
00090     
00091     InitFonts ();
00092     
00093     FlushEvents (everyEvent, 0);
00094     
00095     InitWindows ();
00096     
00097     InitMenus ();
00098     
00099     TEInit ();
00100     
00101     InitDialogs (0L);
00102     
00103     InitCursor ();
00104     
00105     for (i = 1; i <= 5; i++) { /*register with Multifinder*/
00106         
00107         EventRecord ev;
00108         
00109         EventAvail (everyEvent, &ev); /*see TN180 -- splash screen*/
00110         } /*for*/
00111     
00112     return (true);
00113     } /*initmacintosh*/
00114     
00115 
00116 short minint (short x, short y) {
00117 
00118     if (x < y)
00119         return (x);
00120     else
00121         return (y);
00122     } /*minint*/
00123     
00124     
00125 boolean cometofront () {
00126     
00127     short i;
00128     ProcessSerialNumber psn;
00129     EventRecord ev;
00130     
00131     GetCurrentProcess (&psn);
00132     
00133     SetFrontProcess (&psn);
00134     
00135     for (i = 1; i <= 3; i++)
00136         WaitNextEvent (nullEvent, &ev, 1, nil); 
00137 
00138     return (true);
00139     } /*cometofront*/
00140     
00141     
00142 void delayticks (short ct) {
00143     
00144     long tc;
00145     
00146     tc = TickCount () + ct;
00147     
00148     while (TickCount () < tc) {}
00149     } /*delayticks*/
00150     
00151     
00152 void delayseconds (short ct) {
00153     
00154     delayticks (60 * ct);
00155     } /*delayseconds*/
00156     
00157     
00158 void timestamp (unsigned long *stamp) {
00159     
00160     GetDateTime (stamp);
00161     } /*timestamp*/
00162     
00163     
00164 boolean getstringlist (short listnum, short id, bigstring bs) {
00165     
00166     /*
00167     the Mac routine GetIndString doesn't set ResError true when we fall off
00168     the end of the indicated list, so we return false if the returned string
00169     is of zero length.
00170     */
00171     
00172     GetIndString (bs, listnum, id);
00173     
00174     return (stringlength (bs) > 0);
00175     } /*getstringlist*/
00176     
00177     
00178 
00179 
00180     
00181     

Generated on Wed May 31 18:19:43 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6