home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright © 1991-1995 by TopSoft Inc. All rights reserved.
-
- You may distribute this file under the terms of the TopSoft
- Artistic License, accompanying this package.
-
- This file was developed by George (ty) Tempel in connection with
- TopSoft, Inc.
-
- See the Modification History for more details.
-
- Product
- About Box Test/Demo application
-
- FILE
- ABoxTest.c
-
- NAME
- ABoxTest.c, part of the ABox project source code,
- responsible for the demonstration and testing of the ABox.
-
- DESCRIPTION
- This file contains the entire source for the ABoxTest application,
- including defines.
-
- DEVELOPED BY
- George (ty) Tempel netromancr@aol.com
- All code in this file, and its associated header file was
- Created by George (ty) Tempel in connection with TopSoft, Inc.
- "FilterTop" application development, except where noted.
-
- This shell--ABoxTest.c--is shamelessly based upon MModal.c by
- C.K. Haun of Apple DTS, and borrows portions of ModelessSample
- by Nitin Ganatra of Apple DTS.
-
- CARETAKER - George (ty) Tempel <netromancr@aol.com>
- Please consult this person for any changes or suggestions to this file.
-
- MODIFICATION HISTORY
-
- dd mmm yy - xxx - patchxx: description of patch
- 10 June 94 - ty - Initial Version Created
- 12-jan-95 - ty - updated for release 1.1; cleaned up for CodeWarrior 5
- release; substituted UpdateWindowUPP where I was
- using proc pointers.
- 23-may-95 - ty - changes for compatibility with the CodeWarrior CW6
- release and the associated Universal Headers from Apple:
- most methods that returned references now have "Ref" at
- the end of their methods names to prevent possible collisions
- with datatypes and classes of the same name (older versions
- of the compiler didn't have a problem with this).
-
- */
-
- /*===========================================================================*/
-
- /*======= Segmentation directives ========*/
-
- /*============ Header files ==============*/
-
- #include "ABox.h"
-
-
- /*============ Enumerations ==============*/
-
- enum {
- kMBarID = 128
- };
-
- enum {
- kAppleMenu = 128,
- kFileMenu,
- kEditMenu,
- kToolsMenu,
- kDebuggerMenu
- };
-
- enum {
- kEnterDebugger = 1,
- kToggleLeaks,
- kToggleHeapScramble
- };
-
- enum {
- kToggleLeaksOn = 1,
- kToggleLeaksOff,
- kToggleHeapScrambleOn,
- kToggleHeapScrambleOff
- };
-
- #define kResumeMask 1 /* bit of message field for resume vs. suspend */
- #define kSampHelp 129
- #define kAboutBox 128
- #define kHelpString 128
- #define kNewItem 1
- #define kCloseButton 128
- #define kQuitItem 10
- #define kGenStrings 128
- #define kMyModalKind 1000
- #define kMyDocumentKind 1002
-
- enum {
- kItem1 = 1
- };
-
-
- //============ for use with GetDebuggerInfo ==========
- //
- // from "debugger.c", from the Apple _develop_ #18 CD collection
- // of DTS Snippets
- //
- /* stuff that should be defined in C, but isn't (it's in Private.a) */
- #define MacJmp (Ptr *) 0x120 /* MACSBUG jumptable [pointer] */
- #define MacJmpByte (char *) 0x120 /* MACSBUG flags in 24 bit mode [byte] */
- #define MacJmpFlag (char *) 0xBFF /* MacsBug flag [byte] */
-
- enum dTypes {
- noDebugger,
- macsbug,
- tmon,
- other
- };
-
- typedef enum dTypes debuggerTypes;
-
- // stuff for use in this code
- #define DebuggerInstalled 5
-
-
- /*============ Globals ==============*/
-
- MenuHandle gAppleMenuHandle,
- gFileMenuHandle,
- gEditMenuHandle,
- gToolMenuHandle,
- gDebuggerMenuHandle;
-
- Boolean gQuit,
- gInBackground;
- short gAppResFile;
-
- ABox *gABox = NULL;
- UpdateWindowUPP gUpdateUPP;
-
- short gDummyResFileRefNum;
- Str255 gDummyResFile = "\pABoxTest test-file";
- WindowPtr gFirstWindow,
- gSecondWindow;
- Boolean gDoSomethingSilly;
- Boolean gDebuggerPresent = false;
-
-
- /*============ Prototypes ==============*/
-
- void HandleUpdate(WindowPtr window);
- OSErr PrepareABox (ABox *abox,
- ABoxSplashTimeType splashTimeSeconds,
- ABoxModalIndicator modality,
- FSSpecPtr homeSpec);
- void Initialize(void);
-
-
- void DoDaCall(MenuHandle themenu, long theit);
- void DrawMain(WindowPtr drawIt);
- void DrawMain2(WindowPtr drawIt);
- Boolean DoSelected(long val);
- void DoDebuggerMenu(short loval);
- void DoHighLevel(EventRecord *AERecord);
- void OpenTheABox(short aboxTypes);
- void CloseTheABox(void);
- OSErr DoEvents(void);
- void DoDiskEvents(long dinfo); // hi word is error code, lo word is drive number
-
- OSErr DoSomethingSilly(void);
-
-
- Boolean GetDebuggerInfo(debuggerTypes *kind, short *signature);
-
-
-
-
- //============ code begins here.... =====================
-
-
-
-
- /*=============================== GetDebuggerInfo ================================*/
- //
- // from "debugger.c", from the Apple _develop_ #18 CD collection
- // of DTS Snippets
- //
- /*
- ** GetDebuggerInfo
- ** as documented in the "Macsbug Reference & Debugging Guide", page 412
- ** if we have a 32 bit capable Memory Manager, debugger flags are at $BFF
- ** if we have a 24 bit capable Memory Manager, debugger flags are at $120
- ** Ptr at $120
- **
- ** Note that the documentation is slightly obscure--you check if the machine
- ** is capable of 32-bit mode, _not_ if you are running in 32 bit mode.
- **/
- /*
- ** This is a small snippet of code that can be used to to detect if
- ** macsbug is installed or not. NOTE: This code is intended to only
- ** work with version 6.2 of macsbug. You should refer to your Low Level
- ** Debugger's manual for more information on how they install
- ** themselves.
- **
- ** This code is based on information obtained from the MacsBug
- ** Reference. The basic assumptions are that macsbug will install itself
- ** in the following manner:
- **
- ** If you are running with a Memory Manager that only works in 24 bit
- ** mode, then the high -order byte of MacJmp is a flags byte that
- ** contains the following information:
- **
- ** Bit Meaning
- ** --- --------------------------------------
- ** 7 - Set if debugger is running
- ** 6 - Set if debugger can handle system errors
- ** 5 - Set if debugger is installed
- ** 4 - Set if debugger can support discipline utility
- **
- ** The lower 3 bytes are used to store the address of the debugger's
- ** entry point.
- **
- ** If you are running with a Memory Manager that works in 32-bit mode,
- ** the flags byte is moved to address 0xBFF and the long word at MacJmp
- ** becomes a full 32-bit address that points to the debugger's entry
- ** point..
- **
- ** Symantec has a comment in the Think Reference 2.0.1 which states:
- **
- ** "ADDENDUM: The above information seems to be incorrect in the
- ** reference manual. I have found through testing etc. that in both
- ** modes, the Flag Byte appears at location 0xBFF. The code reflects
- ** these findings."
- **
- ** This is because they confused running in 24 bit mode, running in 32
- ** bit mode, and the _ability_ to run in 32 bit mode. It is the latter
- ** ability which you must test to determine the location of the debugger
- ** flags.
- **
- */
- Boolean GetDebuggerInfo(debuggerTypes *callerKind, short *callerSignature)
- {
- short debugFlags;
- Ptr debugEntry;
- short **debugWorld;
- Ptr ROMBaseWorld;
- long addressingMode;
-
- debuggerTypes kind;
- short signature;
- Boolean gotIt = false;
-
- // initialize defaults, assuming no debugger present
- kind = noDebugger;
- signature = ' ';
-
- Gestalt(gestaltAddressingModeAttr, &addressingMode);
- if (addressingMode & (1 << gestalt32BitCapable))
- debugFlags = *MacJmpFlag;
- else
- debugFlags = *MacJmpByte;
-
- if ( debugFlags & (1 << DebuggerInstalled) )
- {
-
- // we've got a debugger. what is it?
- debugEntry = StripAddress(*MacJmp);
- ROMBaseWorld = StripAddress(LMGetROMBase());
-
- if (debugEntry < ROMBaseWorld)
- { // not ROM based debugger
-
- debugWorld = (short **)StripAddress(debugEntry - sizeof(Ptr));
- signature = **debugWorld;
- switch (signature)
- {
- case 'MT':
- kind = macsbug;
- break;
- case 'WH':
- kind = tmon;
- break;
- default:
- kind = other;
- break;
- } // end switch block
- } // end if (debugEntry...) block
-
- gotIt = true;
- } // end if (debugFlags... ) block
-
- if (callerKind)
- *callerKind = kind;
- if (callerSignature)
- *callerSignature = signature;
-
- return gotIt;
- } // end GetDebuggerInfo()
-
-
-
-
-
-
- /*=============================== HandleUpdate ================================*/
- void HandleUpdate(WindowPtr window)
- {
- GrafPtr oldPort;
- UpdateWindowUPP drawProc;
- short tempKind;
-
-
- if (!window)
- return;
-
- GetPort(&oldPort);
- tempKind = ((WindowPeek)window)->windowKind;
- // Make sure it's my window before I jump through the refCon
- // Why, since DA's have they're own layer in 7.0?
- // BECAUSE there are other people in the universe who will
- // add things to your windowList.BalloonWriter, for example
- // so you still need to be careful
- //
- // ty: HOWEVER---this majorly does not work with modal dialogs,
- // because the System reserves a special kind for ModalDialog,
- // and if you stomp on it things wont behave properly. So
- // be nice!
- //
- if (tempKind == kMyModalKind || tempKind == kMyDocumentKind)
- {
- // get the drawing proc from the refCon
- drawProc = (UpdateWindowUPP)GetWRefCon(window);
- // jump to it
- //drawProc(window);
- // 1.1--updated for new compiler, and might as well make use
- // of the UPP i defined a long time ago...
- if (drawProc)
- CallWindowUpdateProc(drawProc, window);
- if (gDoSomethingSilly)
- (void)DoSomethingSilly();
- } // end if block
-
- SetPort (oldPort);
- } // end of test function HandleUpdate()
-
-
-
-
- /*=============================== Initialize ================================*/
- void Initialize(void)
- {
- short i;
- Handle myMenu;
-
- Str255 theName;
-
- // begin here...
-
- MaxApplZone();
- for (i = 1; i <= 10; i++)
- MoreMasters();
-
- // initialize the globals here...
-
- InitGraf (&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
-
- // set up my menu junk
- myMenu = GetNewMBar(kMBarID);
- SetMenuBar(myMenu);
- gAppleMenuHandle = GetMHandle(kAppleMenu);
- gFileMenuHandle = GetMHandle(kFileMenu);
- gEditMenuHandle = GetMHandle(kEditMenu);
- gToolMenuHandle = GetMHandle(kToolsMenu);
- gDebuggerMenuHandle = GetMHandle(kDebuggerMenu);
- AddResMenu(gAppleMenuHandle, 'DRVR');
- DrawMenuBar();
-
- // we of course don't do anything here in this simple app
- // except open our window
- gFirstWindow = GetNewWindow(128, nil, (WindowPtr)-1);
- ((WindowPeek)gFirstWindow)->windowKind = kMyDocumentKind;
-
- // install drawing proc
- UpdateWindowUPP drawProc = NewWindowUpdateProc(DrawMain);
- SetWRefCon(gFirstWindow, (long)drawProc);
-
- // open another one, so we can demonstrate shuffling inhibiting
- gSecondWindow = GetNewWindow(128, nil, (WindowPtr)-1);
- ((WindowPeek)gSecondWindow)->windowKind = kMyDocumentKind;
-
- // install drawing proc
- UpdateWindowUPP drawProc2 = NewWindowUpdateProc(DrawMain);
- SetWRefCon(gSecondWindow, (long)drawProc2);
- GetIndString(theName, kGenStrings, 1);
- SetWTitle(gSecondWindow, theName);
- SelectWindow(gFirstWindow);
- SetPort(gFirstWindow);
-
- gAppResFile = CurResFile();
-
- // check for the presense of a debugger...if we can't find one
- // then disable the entire gDebuggerMenuHandle menu in the menu bar
-
- gDebuggerPresent = GetDebuggerInfo(NULL, NULL);
- if (!gDebuggerPresent)
- DisableItem(gDebuggerMenuHandle, 0);
-
- return;
- } // end Initialize
-
-
-
-
-
- /*=============================== main ================================*/
- void main(void)
- {
- OSErr error = noErr;
-
- // begin here...
- Initialize();
-
- gUpdateUPP = NewWindowUpdateProc(HandleUpdate);
-
- // open up a silly resource file just to toss a wrench
- // into the spokes, so to speak...
- gDummyResFileRefNum = OpenResFile (gDummyResFile);
- error = ResError();
- if (error)
- // oops! something's wrong, so we'll use the system for
- // for some extra resource stuff
- gDummyResFileRefNum = 0;
-
- DoEvents();
-
- // ===========
-
-
- // ok, we're all finished here, so leave
- DisposeRoutineDescriptor (gUpdateUPP);
-
- // if we had a silly resource file open, close it up
- // before we leave.
- if (gDummyResFileRefNum > 0)
- CloseResFile (gDummyResFileRefNum);
-
- delete gABox;
-
- } // end of function main()
-
-
-
- /*=============================== DoSomethingSilly ================================*/
- //
- // this function will just do something silly and meaningless, like
- // read from a bunch of string resources. This is used to simulate
- // the real application busy doing something while the abox is up
- // doing something as a splash screen.
- //
- OSErr DoSomethingSilly(void)
- {
- OSErr error = noErr;
- short limit;
- short index;
- StringHandle stringHandle = NULL;
- short curResFile = CurResFile();
- GrafPtr oldPort;
- const ResType stringType = 'STR ';
-
- // begin here...
-
- // switch to our silly resource file and read
- // some random string from it
-
- UseResFile (gDummyResFileRefNum);
- limit = Count1Resources (stringType);
- error = ResError();
- if (limit < 1)
- limit = 1;
-
- index = (TickCount() % limit) + 1;
- stringHandle = (StringHandle)Get1IndResource (stringType, index);
- error = ResError();
-
- // now draw the string into one of the windows...we'll alternate
- // which one we want based upon some bizarre method
- //
- // phase of the moon? color of the entrails? alignment of the planets?
- // Nah...we'll just modulate on the index
- //
- if (!error)
- {
- WindowPtr theWindow = (TickCount() % 2) ? gFirstWindow : gSecondWindow;
- Rect theRect = theWindow->portRect;
-
- GetPort (&oldPort);
- SetPort (theWindow);
-
- theRect.left = 20;
- theRect.bottom -= 15;
- theRect.top = theRect.bottom - 20;
- EraseRect (&theRect);
- theRect.bottom -= 5;
-
- MoveTo (theRect.left, theRect.bottom);
- if (stringHandle)
- {
- HLock((Handle)stringHandle);
- DrawString (*stringHandle);
- HUnlock((Handle)stringHandle);
- } else {
- DrawString ("\pDuh....no 'STR ' resource to work with");
- } // end if else block
-
- SetPort (oldPort);
- //localTick = TickCount();
- } // end if block
-
- UseResFile (curResFile);
- return error;
- } // end DoSomethingSilly
-
-
-
-
- /*=============================== DoEvents ================================*/
- //
- OSErr DoEvents(void)
- {
- EventRecord eRecord;
- unsigned long mySleep = 30;
- OSErr error;
- WindowPtr aboxWindow = NULL;
- ABoxModalIndicator aboxModality = kABoxModeless;
- WindowPtr twindow;
- Boolean aboxHandled = false;
- short index = 0, limit = 250;
-
- // begin here...
-
- if (gABox)
- {
- error = gABox->GetProperty (kABoxWindow, &aboxWindow, NULL);
- error = gABox->GetProperty (kABoxModalIndicator, &aboxModality, NULL);
- } // end if block
-
- do
- {
-
- WaitNextEvent(everyEvent, &eRecord, mySleep, nil);
-
- if (gDoSomethingSilly)
- {
- if (index < limit)
- {
- error = DoSomethingSilly();
- ++index;
- } else {
- gDoSomethingSilly = false;
- index = 0;
- CloseTheABox();
- } // end if block
-
- } // end if block
-
- if (gABox)
- {
- Boolean aboxFinished = false;
-
- aboxHandled = gABox->Event(&eRecord);
- error = gABox->GetProperty (kABoxIsFinished, &aboxFinished, NULL);
- if (aboxFinished)
- {
- CloseTheABox();
- } else if (aboxHandled) {
- continue;
- } // end if block
- } // end if block
-
-
- switch (eRecord.what)
- {
- case nullEvent:
- if (gDoSomethingSilly)
- error = DoSomethingSilly();
-
- break;
-
- case updateEvt:
- if (((WindowPtr)eRecord.message) != aboxWindow)
- HandleUpdate((WindowPtr)(eRecord.message));
-
- break;
-
- case mouseDown:
- // first see where the hit was
- // When you first think about the Movable Modal issue, you may
- // say to yerself "Hey!if there's a mouseDown all I have to do is
- // see if it's in the portRect of the front window, and SysBeep if it isn't!"
- // Nah, too easy.Remember, you want a user to be able to switch out
- // of your application when a movable modal is up, so you still need
- // to call FindWindow and see if it was a hit in the desktop, other
- // app window (same as desktop), or in the Help or Application menus.
-
- switch (FindWindow(eRecord.where, &twindow))
- {
-
- case inDesk: // if they hit in desk, then the process manager
- break; // will switch us out, we don't need to do anything
-
- case inMenuBar:
- // let Help and Application menus happen always
- DoSelected(MenuSelect(eRecord.where));
- break;
-
- case inSysWindow:
- // pass to the system
- SystemClick(&eRecord, twindow);
- break;
-
- case inContent:
- // Handle content and control clicks here
-
- SelectWindow(twindow); // select the window
-
- break;
-
- case inDrag:
- SelectWindow(twindow);
- DragWindow(twindow, eRecord.where, &qd.screenBits.bounds);
- break;
-
- case inGrow:
- // Call GrowWindow here if you have a grow box
- break;
-
- case inGoAway:
- // Click in Close box
- break;
- }
- break;
- case mouseUp:
- // don't care
- break;
- // same action for key or auto key
- case keyDown:
- case autoKey:
- if (eRecord.modifiers & cmdKey)
- DoSelected(MenuKey(eRecord.message & charCodeMask));
- break;
-
- case keyUp:
- // don't care
- break;
-
- case diskEvt:
- // I don't do anything special for disk events, this just passes them
- // to a function that checks for an error on the mount
- DoDiskEvents(eRecord.message);
- break;
-
- case activateEvt:
- // not doing anything on activates
- break;
-
- case networkEvt:
- // don't care
- break;
-
- case driverEvt:
- // don't care
- break;
-
- case app4Evt:
- // If we're switching layers and I have my MModal up, I want to
- // change the state of the control
- switch ((eRecord.message >> 24) & 0x0FF)
- { // high byte of message
-
- case suspendResumeMessage: // suspend/resume is also an activate/deactivate
- gInBackground = (eRecord.message & kResumeMask) == 0;
- break;
-
- }
- break;
-
- // This dispatches high level events (AppleEvents, for example)
- // to our dispatch routine.This is NEW in the event loop for
- // System 7
- case kHighLevelEvent:
- DoHighLevel(&eRecord);
- break;
- default:
- break;
-
- }
-
- } while (gQuit != true);
-
- return error;
- } // end doevents
-
-
-
- /*=============================== DoDiskEvents ================================*/
- //
- // DoDiskEvents just checks the error code from the disk mount,
- // and puts up the 'Format' dialog (through DIBadMount) if need be
- // You can do much more here if you care about what disks are
- // in the drive
- void DoDiskEvents(long dinfo) // hi word is error code, lo word is drive number
- {
- short hival, loval, tommy;
- Point fredpoint = { 40, 40 };
-
- hival = HiWord(dinfo);
- loval = LoWord(dinfo);
- if (hival != noErr) // something happened
- {
- tommy = DIBadMount(fredpoint, dinfo);
- }
- }
-
-
- /*=============================== DoDaCall ================================*/
- //
- // DoDaCall opens the requested DA.It's here as a seperate routine if you'd
- // like to perform some action or just know when a DA is opened in your
- // layer.Can be handy to track memory problems when a DA is opened
- // with an Option-open
- void DoDaCall(MenuHandle themenu, long theit)
- {
- long qq;
- Str255 DAname;
- GetItem(themenu, theit, DAname);
- qq = OpenDeskAcc(DAname);
- } // end DoDaCall
-
-
- /*=============================== DrawMain ================================*/
- //
- // draws my window.Pretty simple
- void DrawMain(WindowPtr drawIt)
- {
- Handle theText;
- WindowPtr tempWP;
- GetPort(&tempWP);
- BeginUpdate(drawIt);
- SetPort(drawIt);
- EraseRect(&drawIt->portRect);
- theText = GetResource('TEXT', 128);
- if (theText) {
- Rect textRect;
- HLock(theText);
- HUnlock(theText);
- textRect = drawIt->portRect;
- InsetRect(&textRect, 20, 20);
- TextBox(*theText, GetHandleSize(theText), &textRect, 0);
- ReleaseResource(theText);
- }
- EndUpdate(drawIt);
- SetPort(tempWP);
- }
-
-
- /*=============================== DrawMain2 ================================*/
- //
- // a second version for variety
- void DrawMain2(WindowPtr drawIt)
- {
- Handle theText;
- WindowPtr tempWP;
- GetPort(&tempWP);
-
- BeginUpdate(drawIt);
- SetPort(drawIt);
- EraseRect(&drawIt->portRect);
- theText = GetResource('TEXT', 130);
- if (theText) {
- Rect textRect;
- HLock(theText);
- HUnlock(theText);
- textRect = drawIt->portRect;
- InsetRect(&textRect, 20, 20);
- TextBox(*theText, GetHandleSize(theText), &textRect, 0);
- ReleaseResource(theText);
- }
- EndUpdate(drawIt);
- SetPort(tempWP);
- }
-
-
-
- /*=============================== DoSelected ================================*/
- //
- // my menu action taker.It returns a Boolean which I usually ignore, but it
- // might be handy someday
- Boolean DoSelected(long val)
- {
- short loval, hival;
- Boolean returnVal = false;
- loval = LoWord(val);
- hival = HiWord(val);
-
- switch (hival) { // switch off the menu number selected
- case kAppleMenu: // Apple menu
- if (loval != 1) { // if this was not About, it's a DA
- DoDaCall(gAppleMenuHandle, loval);
- } else {
- OpenTheABox(loval); // do about box
- }
- returnVal = true;
- break;
- case kFileMenu: // File menu
- switch (loval) {
- case kQuitItem:
- gQuit = true; // onlyitem
- returnVal = true;
- break;
- default:
- break;
- }
- break;
-
- case kEditMenu:
- // edit menu junk
- // don't care
- break;
-
- case kToolsMenu:
- // add all your test stuff here
- OpenTheABox(loval);
- break;
- case kDebuggerMenu:
- // do some debugger stuff...
- DoDebuggerMenu(loval);
- break;
- case kHMHelpMenuID: // Defined in Balloons.h
- // I only care about this item. If anything else is returned here, I don't know what
- // it is, so I leave it alone.Remember, the Help Manager chapter says that
- // Apple reserves the right to add and change things in the Help menu
- break;
-
- }
- HiliteMenu(0);
- return(returnVal);
- }
-
-
- /*=============================== DoHighLevel ================================*/
- //
- // I'm not doing error handling in this sample for clarities sake, you should. Hah,
- // easy for me to say, huh?
- void DoHighLevel(EventRecord *AERecord)
- {
-
- AEProcessAppleEvent(AERecord);
-
- }
-
-
-
- /*=============================== DoDebuggerMenu ================================*/
- //
- //
- void DoDebuggerMenu (short menuItem)
- {
- OSErr error = noErr;
-
- Str255 debuggerString;
-
- // begin here...
-
- GetItem (gDebuggerMenuHandle, menuItem, debuggerString);
- DebugStr (debuggerString);
-
- return;
- } // end DoDebuggerMenu
-
-
-
-
-
- /*=============================== OpenTheABox ================================*/
- //
- // Opens the MModal dialog.
- //
- void OpenTheABox(short aboxTypes)
- {
- OSErr error = noErr;
- long dirID = 0;
- short vRefNum = 0;
- FSSpec homeSpec;
-
- ABoxSplashTimeType splashTime;
- ABoxModalIndicator modality;
-
- // begin here...
-
- if (aboxTypes % 4 == 0)
- // not an item...sorry
- return;
-
- // create the FSSpec that should point to the "home" for the application
- //
- // application developers note: this FSSpec should point to the root of some
- // file tree that contains information for the about box. The tree can be anywhere,
- // just make sure that the FSSpec is set and passed to the AboutBox. The example
- // below sets the FSSpec to the same directory (folder) as this application; you would
- // perhaps do something different.
-
- error = FSMakeFSSpec ( vRefNum,
- dirID,
- "\p:ABox info...",
- &homeSpec);
-
- switch (aboxTypes)
- {
- case 1:
- case 5:
- case 9:
- modality = kABoxModal;
- break;
- case 2:
- case 6:
- case 10:
- modality = kABoxMoveableModal;
- break;
- case 3:
- case 7:
- case 11:
- modality = kABoxModeless;
- break;
- } // end switch block
-
- switch (aboxTypes / 4)
- {
- case 0: splashTime = kABoxNoSplash; break;
- case 1: splashTime = kABoxWaitForClickSplash; break;
- case 2: splashTime = kABoxWaitForApplicationSplash; gDoSomethingSilly = true; break;
- case 3: splashTime = 5 /* seconds */; break;
- } // end switch block
-
- // kill all the menus except the Test, Help, and App
- if (modality != kABoxModeless)
- {
- DisableItem(gAppleMenuHandle, 0);
- DisableItem(gFileMenuHandle, 0);
- DisableItem(gEditMenuHandle, 0);
- DisableItem(gToolMenuHandle, 0);
- DisableItem(gDebuggerMenuHandle, 0);
- DrawMenuBar();
- } // end if block
-
- if (gABox)
- {
- CloseTheABox();
- delete gABox;
- } // end if block
-
- gABox = new ABox;
- if (gABox)
- {
- error = PrepareABox (gABox, splashTime, modality, &homeSpec);
- if (error == noErr)
- error = gABox->Draw(NULL);
- if (error == noErr)
- error = gABox->Event(NULL);
- }
-
- }
-
-
- /*=============================== PrepareABox ================================*/
- OSErr PrepareABox (ABox *abox,
- ABoxSplashTimeType splashTimeSeconds,
- ABoxModalIndicator modality,
- FSSpecPtr homeSpec)
- {
- OSErr error = noErr;
-
- StringHandle nameAndVersion = (StringHandle)NewHandleClear(sizeof(Str255));
- StringHandle modalityString = (StringHandle)NewHandleClear(sizeof(Str255));
- ABIndex firstItem = 1;
- ABoxTextFontType textFace = 0;
- ABoxTextFontType textSize = 9;
- ABoxTextFontType textFont = geneva;
-
- UpdateWindowUPP windowUpdater = NewWindowUpdateProc(HandleUpdate);
-
- // begin here...
-
- if (!abox)
- return paramErr;
-
- error = abox->SetProperty (kABoxModalIndicator, &modality, kABoxModalIndicatorSize);
- error = abox->SetProperty (kABoxSplashTimeSeconds, &splashTimeSeconds, sizeof(splashTimeSeconds));
- error = abox->SetProperty (kABoxHomeFolder, homeSpec, kABoxHomeFolderSize);
- error = abox->SetProperty (kABoxAppResFile, &gAppResFile, sizeof(gAppResFile));
- error = abox->SetProperty (kABoxFirstTopicNumber, &firstItem, sizeof(firstItem));
- error = abox->SetProperty (kABoxFirstSlideNumber, &firstItem, sizeof(firstItem));
- error = abox->SetProperty (kABoxTextFont, &textFont, sizeof(textFont));
- error = abox->SetProperty (kABoxTextFace, &textFace, sizeof(textFace));
- error = abox->SetProperty (kABoxTextSize, &textSize, sizeof(textSize));
- error = abox->SetProperty (kABoxUpdater, &windowUpdater, kABoxUpdaterSize);
-
- switch (splashTimeSeconds)
- {
- case kABoxNoSplash:
- SetString (nameAndVersion, "\pNo splash screen.");
- break;
- case kABoxWaitForClickSplash:
- SetString (nameAndVersion, "\pWait for click splash screen...please click.");
- break;
- case kABoxWaitForApplicationSplash:
- SetString (nameAndVersion, "\pApplication controlled splash screen...");
- break;
- default:
- SetString (nameAndVersion, "\pTimed splash screen...just watch...");
- break;
- } // end switch block
-
- switch (modality)
- {
- case kABoxModal:
- SetString (modalityString, "\pModal Dialog");
- break;
- case kABoxModeless:
- SetString (modalityString, "\pModeless Dialog");
- break;
- case kABoxMoveableModal:
- SetString (modalityString, "\pMoveable Modal Dialog");
- break;
- default:
- SetString (modalityString, "\pClueless Dialog");
- break;
- } // end switch block
-
- error = HandAndHand ((Handle)modalityString, (Handle)nameAndVersion);
-
- HLock ((Handle)nameAndVersion);
- error = abox->SetProperty (kABoxAppNameAndVersion, *nameAndVersion, **nameAndVersion + 1);
- HUnlock ((Handle)nameAndVersion);
-
- HLock ((Handle)modalityString);
- error = abox->SetProperty (kABoxWindowTitle, *modalityString, **modalityString + 1);
- HUnlock ((Handle)modalityString);
-
- return error;
- } // end PrepareABox
-
-
-
-
- /*=============================== CloseTheABox ================================*/
- //
- void CloseTheABox(void)
- {
- OSErr error = noErr;
-
- // begin here...
-
- if (gABox)
- {
- error = gABox->Close();
- delete gABox;
- gABox = NULL;
- } // end if block
-
- /* turn our menus back on */
- EnableItem(gAppleMenuHandle, 0);
- EnableItem(gFileMenuHandle, 0);
- EnableItem(gEditMenuHandle, 0);
- EnableItem(gToolMenuHandle, 0);
- if (gDebuggerPresent)
- EnableItem(gDebuggerMenuHandle, 0);
-
- DrawMenuBar();
-
- gDoSomethingSilly = false;
- }
-
-
-
-
- // end of file ABoxTest.c