home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
luschsrc.sit
/
setup.c
< prev
next >
Wrap
Text File
|
1990-05-23
|
6KB
|
258 lines
/********************************************************************************
* setup.c
*
* Initialization Segment Routines
*
* Written by Paco Xander Nathan
* ⌐1990, Motorola Inc. Public domain source code.
********************************************************************************/
#include "applic.h"
#include "window.h"
#include "dialog.h"
#include "context.h"
#include "list.h"
#include "text.h"
#include "document.h"
#include "error.h"
#include "print.h"
#include "about.h"
#include <SegmentLdr.h>
#include <OSUtil.h>
#include "setup.h"
#include "test.h"
#include "gnosis.h"
#include "analysis.h"
#define UnImplementedTrap 0x9f
#define WaitNextEventTrap 0x60
#ifdef PROTOTYPES
/* Local Function Prototypes
*/
void SetupAntiBug (void);
void SetupRsrc (void);
void SetupLaMachine (void);
void SetupMenus (void);
void SetupWindows (void);
#endif
/* Initiate various anti-bugging measures
*/
static void
SetupAntiBug ()
{
#ifdef DEVELOPING
register unsigned long *zero;
/* First, trap NIL references by placing an odd value long integer into
* the NULL memory location. NB: the specified value will cause an address
* error on an SE or Plus, and a bus error on a II or later model.
*/
zero = NULL;
*zero = 0x5FFFC001;
#endif
/* Next, trap potential stack overflows by placing a routine that displays
* a warning alert as the grow zone callback routine
*/
SetGrowZone(ErrGrowZone);
/* Make sure that the memory error alert is loaded and locked so that
* the application can notify the user even if a memory allocation error
* occurs.
*/
CouldAlert(yesnoAlertID);
/* Allocate a "avatar block" of memory that can be purged at the last
* resort. Blessed be the concept.
*/
errAvatarHdl = NewHandle(4098L);
}
/* Load miscellaneous resources
*/
static void
SetupRsrc ()
{
register SignedByte hdlState;
register Handle sicnHdl;
register short i;
/* Load the watch cursor frame pointer 'acur' resource
*/
if (curList = (acurHandle) GetResource('acur', WatchACUR)) {
hdlState = HGetState(curList);
HLock(curList = (acurHandle) GetResource('acur', WatchACUR));
/* Load each "frame" in the animation
*/
for (i = 0; i < (*curList)->frames; i++)
(*curList)->curs[i] = GetCursor(HiWord((long) (*curList)->curs[i]));
HSetState(curList, hdlState);
}
}
/* Setup the machine configuration
*/
static void
SetupLaMachine ()
{
SysEnvRec theWorld;
SysEnvirons(1, &theWorld);
laMachine.hasWNE = GetTrapAddress(WaitNextEventTrap) != GetTrapAddress(UnImplementedTrap);
laMachine.hasSound = (theWorld.machineType == envMachUnknown) || (theWorld.machineType == envMacII) || (theWorld.systemVersion >= 0x600);
laMachine.hasColor = theWorld.hasColorQD;
laMachine.inBackground = FALSE;
}
/* Setup the menu bar and menu handles
*/
static void
SetupMenus ()
{
register short i;
/* Install all MBar and hierarchical menus into the menu bar
*/
for (i = 0; i < MAXMENU; i++) {
ApplSpinCurs(FALSE);
if (menu[i] = GetMenu(RSRCBASE + i))
InsertMenu(menu[i], 0);
}
/* Add the desk accessories, etc. from the System and draw the menu bar
*/
if (menu[appleM])
AddResMenu(menu[appleM], 'DRVR');
DrawMenuBar();
}
/* Initialize the application's windows
*/
static void
SetupWindows ()
{
/* Setup screen/window limits to fit this particular screen
*/
growArea = screenBits.bounds;
growArea.top += GetMBarHeight();
dragArea = growArea;
InsetRect(&dragArea, 5, 5);
}
/* Initialize the application and process the Finder launch info
*/
void
SetupAppl ()
{
register Handle luchHdl = NULL;
register long waitTime;
EventRecord theEvent;
AppFile theFile;
short theMsg;
short nDocs;
/* Allocate a reasonably huge heap for our bristling young memory hog
*/
MaxApplZone();
MoreMasters();
MoreMasters();
MoreMasters();
MoreMasters();
MoreMasters();
/* Required Mac Toolbox initialization calls
*/
FlushEvents(everyEvent, 0);
InitGraf(&thePort);
InitCursor();
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(NULL);
GetDateTime((unsigned long *) &randSeed);
/* Setup the application resources and data structures
*/
SetupAntiBug();
SetupRsrc();
SetupLaMachine();
ApplSpinCurs(TRUE);
SetupMenus();
ApplSpinCurs(FALSE);
SetupWindows();
ApplSpinCurs(FALSE);
/* Application specific initialization
*/
if (laMachine.hasColor)
InitPalettes();
dPtrAnal = DlogWindow(analDlogID);
wPtrText = TextWindow(widText, 5, 5, TRUE);
wPtrGnos = ListWindow(widGnos, 0, 0, TRUE);
wPtrTest = WindAllocate(widTest, TRUE);
TestSetup();
/* Present an ominously threatening copyright notice, ie. show the about
* dialog as a splash screen.
*/
AboutAppl();
waitTime = TickCount() + 120L;
/* Allow the user time to finish reading the copyright notice
*/
while (TickCount() < waitTime) {
SystemTask();
ApplSpinCurs(FALSE);
(void) GetNextEvent(everyEvent, &theEvent);
if (IsDialogEvent(&theEvent))
DlogModelessEvent(&theEvent);
}
WindClose((WindowPtr) dPtrAbout);
WindSwitch(dPtrAnal, FALSE);
/* Cheap hack to jam the user mode setting
*/
if (luchHdl = GetResource(LUCH_TAG, RSRCBASE)) {
testUser = FALSE;
ReleaseResource(luchHdl);
}
/* Get the finder launch info then open or print any launched documents
*/
CountAppFiles(&theMsg, &nDocs);
if (nDocs > 0) {
GetAppFiles(1, &theFile);
ApplSpinCurs(FALSE);
DocOpenFile(wPtrGnos, theFile.fName, theFile.vRefNum);
ClrAppFiles(1);
}
else
DocNew(wPtrGnos);
}