home *** CD-ROM | disk | FTP | other *** search
- /*________________________________________________________________________________
-
- BadAPPL.c
-
- Copyright © 1993-1995 Onyx Technology - All rights reserved
-
- ________________________________________________________________________________*/
-
- #define _DEFINE_GLOBS_ // so our apps globals are declared (see BadGlobs.h)
- #ifndef _H_BadAPPL
- #include "BadAPPL.h"
- #endif
- #ifndef _H_BadWindows
- #include "BadWindows.h"
- #endif
- #ifndef _H_BadUtils
- #include "BadUtils.h"
- #endif
- #ifndef _H_BadGestalt
- #include "BadGestalt.h"
- #endif
- #ifndef _H_BadErrors
- #include "BadErrors.h"
- #endif
- #ifndef _H_BadGlobs
- #include "BadGlobs.h"
- #endif
- #ifndef _H_BadMacros
- #include "BadMacros.h"
- #endif
- #ifndef _H_QCAPI
- #include "QCAPI.h"
- #endif
-
- // static functions
- static void InitGlobals(void);
- static short MainEvent(void);
- static short DoCommand(long mResult);
- static void DoMouseDown(short windowPart, WindowPtr whichWindow, EventRecord *myEvent);
- static void TogglePower(void);
-
- /*________________________________________________________________________________
-
- main()
-
- info: this is main for this bad little app.
- ________________________________________________________________________________*/
-
- void main(void)
- {
- QCCallBackUPP handlerProc;
- QCErr result;
-
- InitGraf((Ptr) &qd.thePort); // works for MPW and Think
-
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
- MaxApplZone();
-
- gAppHeap = GetZone(); // save the zone we are running in right now
- result = QCInstalled(); // is QC extension installed?
- if (result)
- {
- if (result == kQCAPIMismatch)
- BadAlert("\pOoops! There is a mismatch between the QCAPI library in use,",
- "\pand the version of QC™ extension code in use.", 0L);
- gQCInstalled = false;
- }
- else
- gQCInstalled = true;
-
- InitGlobals();
- SetUpMenus();
-
- if (!gQCInstalled)
- {
- BadAlert("\pSorry, the QC INIT is not installed. Some testing functions will be disabled.",
- "\pYou can cause Errors, but QC isn’t available to detect them.", 0L);
- }
-
- SetUpWindows();
-
- if (gTEH)
- {
- #ifdef powerc
- OutputString( kStringsID, kRunningPPC, 0L );
- #else
- OutputString( kStringsID, kRunning68K, 0L );
- #endif
-
- if (!gQCInstalled)
- OutputString( kStringsID, kInitNotLoaded, 0L );
- else
- OutputString( kStringsID, kInitLoaded, 0L );
- }
-
- handlerProc = InstallHandler(); // install our QC error handler
- while (MainEvent()); // start a eternal loop until the user quits
- RemoveHandler(handlerProc); // remove out QC error handler
- }
-
- /*________________________________________________________________________________
-
- DoBeforeQuit()
-
- info: Do any house cleanup needed before we ExitToShell.
-
- ________________________________________________________________________________*/
- void DoBeforeQuit(void)
- {
- if (QCIsActive()) // make sure we turn QC off if it is on
- QCDeActivate();
-
- if (gTestListH)
- DisposeHandle((Handle)gTestListH);
-
- ExitToShell(); // time to say goodnight, Gracie…
- }
-
- #pragma mark -
-
- /*________________________________________________________________________________
-
- MainEvent()
-
- info: Handle a mouse down event
-
- ________________________________________________________________________________*/
- static short MainEvent(void)
- {
- EventRecord myEvent;
- WindowPtr whichWindow;
- short windowPart;
-
- MaintainCursor();
- SystemTask();
-
- if (GetNextEvent(everyEvent, &myEvent))
- {
- switch (myEvent.what)
- {
- case mouseDown:
- windowPart = FindWindow(myEvent.where, &whichWindow);
- DoMouseDown(windowPart, whichWindow, &myEvent);
- break;
-
- case keyDown:
- case autoKey:
- {
- register char theChar;
-
- theChar = myEvent.message & charCodeMask;
- if ((myEvent.modifiers & cmdKey) != 0)
- return(DoCommand(MenuKey( theChar)));
- }
- break;
-
- case activateEvt:
- if (ourWindow((WindowPtr)myEvent.message))
- {
- if (myEvent.modifiers & activeFlag)
- {
- TEActivate(gTEH);
- ShowControl(gVScroll);
- DisableItem(gMenus[editM], undoCommand);
- }
- else
- {
- TEDeactivate(gTEH);
- HideControl(gVScroll);
- }
- }
- break;
-
- case updateEvt:
- if (ourWindow((WindowPtr) myEvent.message))
- UpdateWindow(gStatusWindow);
- break;
- } // end of case myEvent.what
- }
-
- return(1);
- }
-
- /*________________________________________________________________________________
-
- DoCommand()
-
- info: Do a menu command
-
- entry: long result from MenuSelect
-
- return: at present, always returns true
- ________________________________________________________________________________*/
- static short DoCommand(long mResult)
- {
- short theItem, err;
- Str255 name;
-
- theItem = LoWord(mResult);
- switch (HiWord(mResult))
- {
- case kAppleID:
- switch(theItem)
- {
- case aboutCommand:
- DoDialog(aboutDLOG);
- break;
- default:
- GetMenuItemText(gMenus[appleM], theItem, name);
- OpenDeskAcc(name);
- SetPort(gStatusWindow);
- break;
- }
- break;
-
- case kFileID:
- switch(theItem)
- {
- case onCommand:
- TogglePower();
- break;
- case quitCommand:
- DoBeforeQuit();
- break;
- }
- break;
-
- case kEditID:
- if (SystemEdit(theItem-1) == 0)
- ShowSelect();
- break;
-
- case kControlID:
- MaintainControlMenu(theItem, kDoState);
- break;
-
- case kErrorsID:
- switch(theItem)
- {
- case bkOverwriteID:
- DoBlockOverwrite();
- }
- break;
-
- case kStateID:
- switch(theItem)
- {
- case saveCommand:
- gQCSavedStateH = QCGetState();
- if (gQCSavedStateH)
- OutputString( kStringsID, kStateSaved, 0L);
- else
- OutputString( kErrStringsID, kStateRestored, 0L);
- break;
- case restoreCommand:
- err = QCSetState(gQCSavedStateH);
- if (!err)
- OutputString( kStringsID, kStateRestored, 0L);
- else
- OutputString( kErrStringsID, kStateRestored, (long) err);
-
- QCDisposeState(gQCSavedStateH);
- gQCSavedStateH = 0L; // make sure this is cleared out
-
- break;
- }
- break;
-
- case handleID:
- switch(theItem)
- {
- case createDisposHndCommand:
- DoHandlePtrExistance(true); // true indicates test Handles
- break;
- case resizeHndCommand:
- DoHandlePtrResize(true); // true indicates test Handles
- break;
- case verifyHndCommand:
- DoHandlePtrVerify(true);
- break;
- }
- break;
-
- case ptrID:
- switch(theItem)
- {
- case createDisposPtrCommand:
- DoHandlePtrExistance(false); // false indicates test Pointers
- break;
- case resizePtrCommand:
- DoHandlePtrResize(false); // false indicates test Pointers
- break;
- case verifyPtrCommand:
- DoHandlePtrVerify(false);
- break;
- }
- break;
-
- case addrZeroID:
- switch(theItem)
- {
- case write2ZeroCommand:
- WriteToZeroTest();
- break;
- case derefZeroCommand:
- DerefZeroTest();
- break;
- }
- break;
-
- case purgeID:
- // at this time, (09/10/91) there is only one purge menu item. Sometime in the
- // future there may be more so…keep an eye out for a switch later on…
- DoPurgeTest();
- break;
- }
-
- HiliteMenu(0);
- return(1);
- }
-
- /*________________________________________________________________________________
-
- DoMouseDown()
-
- info: Handle a mouse down event
-
- ________________________________________________________________________________*/
- static void DoMouseDown(short windowPart, WindowPtr whichWindow, EventRecord *myEvent)
- {
- Rect dragRect = { 0, 0, 1024, 1024 };
-
- switch (windowPart)
- {
- case inGoAway:
- if (ourWindow(whichWindow))
- if (TrackGoAway(gStatusWindow, myEvent->where))
- CloseMyWindow();
- break;
-
- case inMenuBar:
- MaintainMenus();
- DoCommand(MenuSelect(myEvent->where));
-
- case inSysWindow:
- SystemClick(myEvent, whichWindow);
- break;
-
- case inDrag:
- if (ourWindow(whichWindow))
- DragWindow(whichWindow, myEvent->where, &dragRect);
- break;
-
- case inGrow:
- if (ourWindow(whichWindow))
- MyGrowWindow(whichWindow, myEvent->where);
- break;
-
- case inContent:
- if (whichWindow != FrontWindow())
- SelectWindow(whichWindow);
- else if (ourWindow(whichWindow))
- DoContent(whichWindow, myEvent);
- break;
- }
- }
-
- /*________________________________________________________________________________
-
- InitGlobals()
-
- info: Initialize any necessary globals.
-
- ________________________________________________________________________________*/
- static void InitGlobals(void)
- {
- if (GetSystemVers() >= System7)
- gAtleastSys7 = true;
- else
- gAtleastSys7 = false;
-
- gQCSavedStateH = 0L;
- }
-
- /*________________________________________________________________________________
-
- TogglePower()
-
- info: Toggle the activating and deactivating of QC.
- ________________________________________________________________________________*/
- static void TogglePower(void)
- {
- short err;
-
- if (gQCInstalled) // is the INIT available?
- {
- if (QCIsActive()) // are we currently on?
- {
- err = QCDeActivate(); // then turn us off…
- if (!err)
- OutputString(kStringsID, kOffIndx, 0L);
- else
- OutputString(kErrStringsID, kQCDeActivateIndx, (long) err);
- }
- else
- {
- // Note that we are specifically giving QCActivate() a heap to activate on.
- // If we passed 0L, QCActivate() would activate on the current heap zone.
-
- err = QCActivate(gAppHeap); // check this specific zone for errors
- if (!err)
- OutputString(kStringsID, kOnIndx, 0L);
- else
- OutputString(kErrStringsID, kQCActivateIndx, (long) err);
- }
-
- ShowSelect(); // update our status text edit window
- }
- }
-