home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************
- Project : MacPerl - Real Perl Application
- File : MPMain.c - The main event loop
- Author : Matthias Neeracher
-
- A lot of this code is borrowed from 7Edit written by
- Apple Developer Support UK
-
- Language : MPW C
-
- $Log: MPMain.c,v $
- Revision 1.2 1994/05/04 02:52:40 neeri
- Inline Input.
-
- Revision 1.1 1994/02/27 23:01:21 neeri
- Initial revision
-
- Revision 0.9 1993/12/30 00:00:00 neeri
- DeferredKeys
-
- Revision 0.8 1993/12/20 00:00:00 neeri
- Trying to be more subtle about cursors
-
- Revision 0.7 1993/12/12 00:00:00 neeri
- SacrificialGoat
-
- Revision 0.6 1993/10/17 00:00:00 neeri
- Mercutio Support
-
- Revision 0.5 1993/08/17 00:00:00 neeri
- Preferences
-
- Revision 0.4 1993/08/16 00:00:00 neeri
- Moved scripting to separate file
-
- Revision 0.3 1993/07/15 00:00:00 neeri
- Beginning to see the light
-
- Revision 0.2 1993/05/30 00:00:00 neeri
- Support Console Windows
-
- Revision 0.1 1993/05/29 00:00:00 neeri
- Compiles correctly
-
- *********************************************************************/
-
- #include <Memory.h>
- #include <QuickDraw.h>
- #include <Types.h>
- #include <Menus.h>
- #include <Windows.h>
- #include <Dialogs.h>
- #include <Traps.h>
- #include <Packages.h>
- #include <PPCToolbox.h>
- #include <Resources.h>
- #include <Editions.h>
- #include <Printing.h>
- #include <ToolUtils.h>
- #include <Desk.h>
- #include <Scrap.h>
- #include <OSEvents.h>
- #include <AppleEvents.h>
- #include <AEObjects.h>
- #include <Errors.h>
- #include <StandardFile.h>
- #include <Balloons.h>
- #include <String.h>
- #include <CType.h>
- #include <PLStringFuncs.h>
- #include <StdLib.h>
- #include <CursorCtl.h>
- #include <Script.h>
-
- #include "MPGlobals.h"
- #include "MPUtils.h"
- #include "MPEditions.h"
- #include "MPAppleEvents.h"
- #include "MPWindow.h"
- #include "MPFile.h"
- #include "MPHelp.h"
- #include "MPScript.h"
- #include "MPUtils.h"
- #include "MPPreferences.h"
- #include "Mercutio.h"
-
- #define RESOLVE_MAC_CONFLICTS
- #include <EXTERN.h>
- #include <perl.h>
-
- #pragma segment Main
-
- pascal void MaintainCursor(Boolean busy)
- {
- Point pt;
- WindowPtr wPtr;
- GrafPtr savePort;
- DPtr theDoc;
- Boolean inText = false;
-
- if (busy) {
- SpinCursor(1);
-
- return;
- }
-
- wPtr = FrontWindow();
- if (Ours(wPtr)) {
- theDoc = DPtrFromWindowPtr(wPtr);
- GetPort(&savePort);
- SetPort(wPtr);
- GetMouse(&pt);
- #ifndef RUNTIME
- if (gTextServicesImplemented && SetTSMCursor(pt))
- return;
- #endif
- if (theDoc->theText)
- if (inText = PtInRect(pt, &(**(theDoc->theText)).viewRect))
- SetCursor(&editCursor);
- else
- SetCursor(&qd.arrow);
- else
- SetCursor(&qd.arrow);
-
- if (theDoc->theText)
- TEIdle(theDoc->theText);
-
- #ifndef RUNTIME
- DoHelp(wPtr, theDoc, pt, inText);
- #endif
-
- SetPort(savePort);
- } else if (!wPtr)
- SetCursor(&qd.arrow);
- }
-
- #pragma segment Main
-
- pascal void MaintainMenus(void)
- {
- DPtr theDoc;
- WindowPtr firstWindow;
- SectHandle currSection;
- static Boolean mRunningPerl;
-
- firstWindow = FrontWindow();
- if (!Ours(firstWindow)) {
- EnableItem(myMenus[fileM], fmNew);
- EnableItem(myMenus[fileM], fmOpen);
- DisableItem(myMenus[fileM], fmClose);
- DisableItem(myMenus[fileM], fmSave);
- DisableItem(myMenus[fileM], fmSaveAs);
- DisableItem(myMenus[fileM], fmRevert);
- DisableItem(myMenus[fileM], fmPrint);
- DisableItem(myMenus[fileM], fmPageSetUp);
- EnableItem(myMenus[fileM], fmQuit);
-
- #ifndef RUNTIME
- DisableItem(myMenus[editM], cPublisher);
- DisableItem(myMenus[editM], cSubscriber);
- DisableItem(myMenus[editM], cOptions);
- DisableItem(myMenus[editM], cBorders);
-
- EnableItem(myMenus[helpM], hmExplain);
- #endif
-
- if (gRunningPerl != mRunningPerl) {
- if (gRunningPerl)
- DeleteMenu(perlID);
- else
- InsertMenu(myMenus[perlM], 0);
-
- mRunningPerl = gRunningPerl;
-
- DrawMenuBar();
- }
-
- if (!mRunningPerl) {
- SetItem(myMenus[perlM], pmRunFront, "\pRun Front Window");
- DisableItem(myMenus[perlM], pmRunFront);
- }
-
- EnableItem(myMenus[editM], emPreferences);
-
- if (firstWindow) {
- EnableItem(myMenus[editM], undoCommand);
- EnableItem(myMenus[editM], cutCommand);
- EnableItem(myMenus[editM], copyCommand);
- EnableItem(myMenus[editM], pasteCommand);
- EnableItem(myMenus[editM], clearCommand);
- }
- } else {
- theDoc = DPtrFromWindowPtr(firstWindow);
-
- if (theDoc->kind == kDocumentWindow) {
- EnableItem(myMenus[editM], pasteCommand);
- #ifndef RUNTIME
- EnableItem(myMenus[editM], cBorders);
- #endif
- if (!mRunningPerl) {
- Str255 title;
-
- PLstrcpy(title, "\pRun ");
- GetWTitle(firstWindow, title+5);
- title[0] = title[5] + 6;
- title[5] = '"';
- title[title[0]] = '"';
- SetItem(myMenus[perlM], pmRunFront, title);
- EnableItem(myMenus[perlM], pmRunFront);
- }
- } else {
- #ifndef RUNTIME
- DisableItem(myMenus[editM], cBorders);
- #endif
-
- if ((*theDoc->theText)->selStart < theDoc->u.cons.fence)
- DisableItem(myMenus[editM], pasteCommand);
- else
- EnableItem(myMenus[editM], pasteCommand);
-
- if (!mRunningPerl) {
- SetItem(myMenus[perlM], pmRunFront, "\pRun Front Window");
- DisableItem(myMenus[perlM], pmRunFront);
- }
- }
-
- EnableItem(myMenus[fileM], fmClose);
- EnableItem(myMenus[fileM], fmSave);
- EnableItem(myMenus[fileM], fmSaveAs);
- EnableItem(myMenus[fileM], fmPrint);
- EnableItem(myMenus[fileM], fmPageSetUp);
- EnableItem(myMenus[fileM], fmQuit);
-
- if (theDoc->kind == kDocumentWindow && theDoc->dirty)
- EnableItem(myMenus[fileM], fmRevert);
- else
- DisableItem(myMenus[fileM], fmRevert);
-
- DisableItem(myMenus[editM], undoCommand);
-
- if (((**(theDoc->theText)).selEnd - (**(theDoc->theText)).selStart) < 0) {
- DisableItem(myMenus[editM], cutCommand);
- DisableItem(myMenus[editM], copyCommand);
- DisableItem(myMenus[editM], clearCommand);
- #ifndef RUNTIME
- DisableItem(myMenus[editM], cPublisher);
- #endif
- } else {
- EnableItem(myMenus[editM], cutCommand);
- EnableItem(myMenus[editM], copyCommand);
- EnableItem(myMenus[editM], clearCommand);
- #ifndef RUNTIME
- EnableItem(myMenus[editM], cPublisher);
- #endif
- }
-
- EnableItem(myMenus[editM], emPreferences);
-
- #ifndef RUNTIME
- currSection =
- GetSection(
- (**(theDoc->theText)).selStart,
- (**(theDoc->theText)).selEnd,
- theDoc);
-
- if (theDoc->kind != kDocumentWindow) {
- DisableItem(myMenus[editM], cPublisher);
- DisableItem(myMenus[editM], cSubscriber);
- DisableItem(myMenus[editM], cOptions);
- } else if (currSection) {
- DisableItem(myMenus[editM], cPublisher);
- DisableItem(myMenus[editM], cSubscriber);
- EnableItem(myMenus[editM], cOptions);
- if ((**(**currSection).fSectHandle).kind == stPublisher)
- SetItem(myMenus[editM], cOptions, "\pPublisher Options…");
- else
- SetItem(myMenus[editM], cOptions, "\pSubscriber Options…");
- } else {
- EnableItem(myMenus[editM], cPublisher);
- EnableItem(myMenus[editM], cSubscriber);
- DisableItem(myMenus[editM], cOptions);
- }
-
- EnableItem(myMenus[helpM], hmExplain);
- #endif
-
- if (gRunningPerl != mRunningPerl) {
- if (gRunningPerl)
- DeleteMenu(perlID);
- else
- InsertMenu(myMenus[perlM], 0);
-
- mRunningPerl = gRunningPerl;
-
- DrawMenuBar();
- }
- }
- }
-
- #pragma segment Main
-
- pascal void SetUpCursors(void)
- {
- CursHandle hCurs;
-
- hCurs = GetCursor(1);
- editCursor = **hCurs;
- hCurs = GetCursor(watchCursor);
- waitCursor = **hCurs;
- }
-
- #pragma segment Main
-
- pascal void SetUpMenus(void)
- {
- short i;
- StringHandle str;
-
- myMenus[appleM] = GetMenu(appleID);
- AddResMenu(myMenus[appleM], 'DRVR');
- myMenus[fileM] = GetMenu(fileID);
- myMenus[editM] = GetMenu(editID);
- myMenus[windowM] = GetMenu(windowID);
- myMenus[perlM] = GetMenu(perlID);
-
- #ifndef RUNTIME
- for (i = appleM; i < kLastMenu; i++)
- InsertMenu(myMenus[i], 0);
-
- HMGetHelpMenuHandle(&myMenus[helpM]);
- str = GetString(helpID);
-
- HLock((Handle) str);
- AppendMenu(myMenus[helpM], *str);
- ReleaseResource((Handle) str);
- #else
- for (i = appleM; i <= kLastMenu; i++)
- InsertMenu(myMenus[i], 0);
- #endif
-
- SetShortMenus(); /* Does a DrawMenuBar() */
- }
-
- pascal void DoFile(short theItem)
- {
- short alertResult;
- DPtr theDoc;
- FSSpec theFSSpec;
- OSErr fileErr;
- TPrint thePSetup;
-
- switch (theItem){
- case fmNew:
- IssueAENewWindow();
- break;
-
- case fmOpen:
- if (GetFile(&theFSSpec)==noErr)
- fileErr = IssueAEOpenDoc(theFSSpec);
- break;
-
- case fmClose:
- IssueCloseCommand(FrontWindow());
- break;
-
- case fmSave:
- case fmSaveAs:
- theDoc = DPtrFromWindowPtr(FrontWindow());
-
- if (theItem==fmSaveAs || theDoc->kind != kDocumentWindow || !theDoc->u.reg.everSaved) {
- fileErr = GetFileNameToSaveAs(theDoc);
- if (!fileErr)
- fileErr = IssueSaveCommand(theDoc->theWindow, &theDoc->theFSSpec);
- else if (fileErr != userCanceledErr)
- FileError("\perror saving ", theDoc->theFileName);
-
- if (fileErr == noErr)
- SetWTitle(theDoc->theWindow, theDoc->theFSSpec.name);
- } else
- fileErr = IssueSaveCommand(theDoc->theWindow, nil);
- break;
-
- case fmRevert:
- SetCursor(&qd.arrow);
- theDoc = DPtrFromWindowPtr(FrontWindow());
-
- ParamText(theDoc->theFileName, "", "", "");
- alertResult = Alert(RevertAlert, nil);
- switch (alertResult){
- case aaSave:
- if (IssueRevertCommand(theDoc->theWindow))
- FileError("\perror reverting ", theDoc->theFileName);
- }
- break;
-
- case fmPageSetUp:
- theDoc = DPtrFromWindowPtr(FrontWindow());
- if (DoPageSetup(theDoc)) {
- thePSetup = **(theDoc->thePrintSetup);
- IssuePageSetupWindow(theDoc->theWindow, thePSetup);
- }
- break;
-
- case fmPrint:
- IssuePrintWindow(FrontWindow());
- break;
-
- case fmQuit:
- IssueQuitCommand();
- break;
- } /*of switch*/
- }
-
- #pragma segment Main
-
- pascal void DoCommand(long mResult)
- {
- short theItem;
- short err;
- Str255 name;
- DPtr theDocument;
-
- if (!mResult)
- return;
-
- theDocument = DPtrFromWindowPtr(FrontWindow());
-
- #ifndef RUNTIME
- if (gTextServicesImplemented && TSMMenuSelect(mResult))
- goto done;
- if (theDocument && theDocument->tsmDoc)
- FixTSMDocument(theDocument->tsmDoc);
- #endif
-
- theItem = LoWord(mResult);
-
- switch (HiWord(mResult)) {
- case appleID:
- if (theItem == aboutItem) {
- DoAbout();
- } else {
- GetItem(myMenus[appleM], theItem, name);
- err = OpenDeskAcc(name);
- SetPort(FrontWindow());
- }
- break;
-
- case fileID:
- DoFile(theItem);
- break;
-
- case editID:
- SystemEdit(theItem - 1);
-
- switch (theItem) {
- case cutCommand:
- IssueCutCommand(theDocument);
- break;
-
- case copyCommand:
- IssueCopyCommand(theDocument);
- break;
-
- case pasteCommand :
- IssuePasteCommand(theDocument);
- break;
-
- case clearCommand :
- IssueClearCommand(theDocument);
- break;
-
- case selectAllCommand:
- if (theDocument)
- TESetSelect(0, (**(theDocument->theText)).teLength, theDocument->theText);
- break;
-
- #ifndef RUNTIME
- case cPublisher:
- IssueCreatePublisher(theDocument);
- break;
-
- case cSubscriber:
- DoSubscribe(theDocument);
- break;
-
- case cOptions:
- DoSectionOptions(theDocument);
- break;
-
- case cBorders:
- IssueShowBorders(theDocument->theWindow, !theDocument->u.reg.showBorders);
- break;
- #endif
-
- case emFormat:
- IssueFormatCommand(theDocument);
- break;
-
- case emPreferences:
- DoPrefDialog();
- break;
- } /*of switch*/
-
- ShowSelect(theDocument);
- break;
-
- case windowID:
- DoSelectWindow(theItem);
- break;
-
- case perlID:
- DoScriptMenu(theItem);
- break;
-
- #ifndef RUNTIME
- case kHMHelpMenuID:
- Explain(theDocument);
- break;
- #endif
- } /*of switch*/
-
- done:
- HiliteMenu(0);
- }
-
- #pragma segment Main
-
- pascal void DoMouseDown(EventRecord *myEvent)
- {
- WindowPtr whichWindow;
- Point p;
- Rect dragRect;
-
- p = myEvent->where;
- switch (FindWindow(p, &whichWindow)) {
- case inDesk:
- SysBeep(10);
- break;
-
- case inGoAway:
- if (Ours(whichWindow))
- if (TrackGoAway(whichWindow, p))
- IssueCloseCommand(whichWindow);
- break;
-
- case inMenuBar:
- SetCursor(&qd.arrow);
- SetupWindowMenu();
- DoCommand(MenuSelect(p));
- HiliteMenu(0);
- break;
-
- case inSysWindow:
- SystemClick(myEvent, whichWindow);
- break;
-
- case inDrag:
- dragRect = qd.screenBits.bounds;
-
- if (Ours(whichWindow)) {
- DragWindow(whichWindow, p, &dragRect);
- /*
- As rgnBBox may be passed by address
- */
- dragRect = (**((WindowPeek)whichWindow)->strucRgn).rgnBBox;
- /*
- The windows already there, but still tell
- the our AppleEvents core about the move in case
- they want to do anything
- */
- IssueMoveWindow(whichWindow, dragRect);
- }
- break;
-
- case inGrow:
- SetCursor(&qd.arrow);
- if (Ours(whichWindow))
- MyGrowWindow(whichWindow, p);
- break;
-
- case inZoomIn:
- DoZoom(whichWindow, inZoomIn, p);
- break;
-
- case inZoomOut:
- DoZoom(whichWindow, inZoomOut, p);
- break;
-
- case inContent:
- if (whichWindow != FrontWindow())
- SelectWindow(whichWindow);
- else
- if (Ours(whichWindow))
- DoContent(whichWindow, myEvent);
- break;
- } /*of switch*/
- }
-
- #pragma segment Main
-
- pascal long GetSleep(void)
- {
- long sleep;
- WindowPtr theWindow;
- DPtr theDoc;
-
- sleep = 30;
- if (!gInBackground)
- {
- theWindow = FrontWindow();
- if (theWindow)
- {
- theDoc = DPtrFromWindowPtr(theWindow);
- if ((**(theDoc->theText)).selStart == (**(theDoc->theText)).selEnd)
- sleep = GetCaretTime();
- }
- }
- return(sleep);
- } /*GetSleep*/
-
- long FindMenuKey(EventRecord * ev)
- {
- #ifndef RUNTIME
- /* Work around Help manager bug */
- short item = CountMItems(myMenus[helpM]);
- short key;
-
- GetItemCmd(myMenus[helpM], item, &key);
-
- if (toupper((char) key) == toupper(ev->message & charCodeMask))
- return (kHMHelpMenuID << 16) | item;
- else
- #endif
- return PowerMenuKey(ev->message, ev->modifiers, myMenus[fileM]);
- }
-
- #pragma segment Main
-
- typedef enum {keyOK, keyRetry, keyAbort} KeyStatus;
-
- KeyStatus TryKey(DPtr theDoc, char theChar)
- {
- switch (theChar) {
- case 0:
- case 1:
- case 2:
- case 4:
- case 5:
- case 6:
- case 7:
- case 10:
- case 11:
- case 12:
- case 14:
- case 15:
- case 16:
- case 17:
- case 18:
- case 19:
- case 20:
- case 21:
- case 22:
- case 23:
- case 24:
- case 25:
- case 26:
- case 27:
- return keyAbort;
- break;
- case ETX:
- theChar = CR;
-
- break;
- default:
- break;
- }
-
- #ifndef RUNTIME
- {
- SectHandle currSection;
-
- /*
- don't allow a subscriber to be changed
- */
- currSection =
- GetSection(
- (**(theDoc->theText)).selStart,
- (**(theDoc->theText)).selEnd,
- theDoc);
-
- if (currSection)
- if ((**(**currSection).fSectHandle).kind == stSubscriber)
- if (!KeyOKinSubscriber(theChar))
- return keyAbort;
- }
- #endif
-
- if (theDoc->kind == kDocumentWindow) {
- #ifndef RUNTIME
- DoTEKeySectionRecalc(theDoc, theChar);
- #endif
- } else if (theChar == BS) {
- if (AllSelected(theDoc->theText)) {
- if (theDoc->u.cons.fence < 32767)
- theDoc->u.cons.fence = 0;
- } else if ((*theDoc->theText)->selStart == (*theDoc->theText)->selEnd)
- if ((*theDoc->theText)->selStart-1 < theDoc->u.cons.fence)
- return keyAbort;
- else if ((*theDoc->theText)->selStart < theDoc->u.cons.fence)
- return keyAbort;
- } else if (
- (*theDoc->theText)->selStart < theDoc->u.cons.fence &&
- !KeyOKinSubscriber(theChar)
- )
- return keyAbort;
- else if (!theDoc->u.cons.selected)
- return keyRetry;
-
- #ifndef RUNTIME
- AddKeyToTypingBuffer(theDoc, theChar);
- #endif
-
- TEKey(theChar, theDoc->theText);
- EnforceMemory(theDoc, theDoc->theText);
- AdjustScrollbars(theDoc, false);
- ShowSelect(theDoc);
-
- theDoc->dirty = true;
-
- return keyOK;
- }
-
- #ifndef RUNTIME
-
- #pragma segment Main
-
- static Boolean IntlTSMEvent(EventRecord *event)
- {
- short oldFont;
- ScriptCode keyboardScript;
-
- if (qd.thePort != nil)
- {
- oldFont = qd.thePort->txFont;
- keyboardScript = GetSMVariable(smKeyScript);
- if (FontToScript(oldFont) != keyboardScript)
- TextFont(GetScriptVariable(keyboardScript, smScriptAppFond));
- };
- return TSMEvent(event);
- }
-
- #endif
- /* Our cursor/WaitNextEvent strategy */
-
- #define BUSY_WAIT 120
- #define FRONT_FREQUENCY 30
- #define BACK_FREQUENCY 10
-
- static long lastNonBusy = 0;
- static long lastWNE = 0;
- static char deferredKeys[256];
- static short deferredRd;
- static short deferredWr;
- static RgnHandle mouseRgn;
-
- #pragma segment Main
-
- pascal void MainEvent(Boolean busy)
- {
- DPtr theDoc;
- char theChar;
- Boolean activate;
- Boolean gotEvent;
- WindowPtr theWindow;
- long now;
- EventRecord myEvent;
- Point mouse;
-
- if (!gSacrificialGoat) /* Memory trouble */
- if (gRunningPerl) /* This script has gone too far */
- fatal("Out of memory ! Aborting script for your own good...\n");
- else /* We aborted it, now buy a new goat */
- if (!(gSacrificialGoat = NewHandle(SACRIFICE)))
- exit(0); /* Save our sorry ass. Shouldn't happen */
-
- now = TickCount();
- if (busy) {
- if (now - lastNonBusy < BUSY_WAIT)
- busy = false;
- } else
- lastNonBusy = now;
-
- if (busy) {
- MaintainCursor(busy);
-
- if (now - lastWNE < (gInBackground ? BACK_FREQUENCY : FRONT_FREQUENCY))
- return;
- } else {
- MaintainCursor(busy);
- MaintainMenus();
- }
-
- lastWNE = now;
- gGotEof = nil;
-
- if (!gRunningPerl && GetHandleSize((Handle) gWaitingScripts)) {
- AppleEvent * ev = (*gWaitingScripts)[0];
- AppleEvent * repl = (*gWaitingScripts)[1];
-
- Munger((Handle) gWaitingScripts, 0, nil, 8, (Ptr) -1, 0);
-
- AEResumeTheCurrentEvent(
- ev, repl, (EventHandlerProcPtr) kAEUseStandardDispatch, -1);
- }
-
- if ((theDoc = DPtrFromWindowPtr(FrontWindow())) && theDoc->theText)
- while (deferredKeys[deferredRd]) {
- switch (TryKey(theDoc, deferredKeys[deferredRd])) {
- case keyOK:
- case keyAbort:
- deferredKeys[deferredRd] = 0;
- deferredRd = (deferredRd + 1) & 255;
- continue;
- }
- break;
- }
-
- if (!(theWindow = FrontWindow()))
- GetWMgrPort(&theWindow);
-
- SetPort(theWindow);
-
- #ifndef RUNTIME
- SetSMVariable(smFontForce, gSavedFontForce);
- #endif
-
- if (!busy) {
- if (!mouseRgn)
- mouseRgn = NewRgn();
-
- GetMouse(&mouse);
- SetRectRgn(mouseRgn, mouse.h, mouse.v, mouse.h, mouse.v);
- gotEvent = WaitNextEvent(everyEvent, &myEvent, GetSleep(), mouseRgn);
- } else
- gotEvent = WaitNextEvent(everyEvent, &myEvent, 0, nil);
-
- #ifndef RUNTIME
- // clear fontForce again so it doesn't upset our operations
- gSavedFontForce = GetSMVariable(smFontForce);
- (void) SetSMVariable(smFontForce, 0);
-
- if (gotEvent && gTextServicesImplemented && IntlTSMEvent(&myEvent))
- gotEvent = false; // TSMTE handled it without our help
- #endif
-
- if (gotEvent)
- switch (myEvent.what) {
- case mouseDown:
- #ifndef RUNTIME
- FlushAndRecordTypingBuffer();
- #endif
- DoMouseDown(&myEvent);
- lastNonBusy = now;
- break;
-
- case keyDown:
- case autoKey:
- if (WeirdChar(&myEvent, cmdKey, ETX)
- || WeirdChar(&myEvent, controlKey, 'd')
- ) {
- if (theDoc->kind != kDocumentWindow) {
- gGotEof = theDoc;
- theDoc->dirty = true;
- }
-
- break;
- }
-
- theChar = myEvent.message & charCodeMask;
-
- if ((myEvent.modifiers & cmdKey) == cmdKey) {
- DoCommand(FindMenuKey(&myEvent));
- HiliteMenu(0);
- } else if (theDoc && theDoc->theText)
- switch (TryKey(theDoc, theChar)) {
- case keyOK:
- case keyAbort:
- break;
- case keyRetry:
- deferredKeys[deferredWr] = theChar;
- deferredWr = (deferredWr + 1) & 255;
- break;
- }
- break;
-
- case activateEvt:
- activate = ((myEvent.modifiers & activeFlag) != 0);
- theWindow = (WindowPtr)myEvent.message;
- DoActivate(theWindow, activate);
- break;
-
- case updateEvt:
- theDoc = DPtrFromWindowPtr((WindowPtr)myEvent.message);
- DoUpdate(theDoc);
- break;
-
- case kHighLevelEvent:
- #ifndef RUNTIME
- FlushAndRecordTypingBuffer();
- #endif
- DoAppleEvent(myEvent);
- break;
-
- case kOSEvent:
- switch (myEvent.message & osEvtMessageMask) { /*high byte of message*/
- case 0x01000000:
- gInBackground = ((myEvent.message & resumeFlag) == 0);
- if (!gInBackground)
- InitCursor();
- DoActivate(FrontWindow(), !gInBackground);
- }
- }
-
- if (gQuitting && gRunningPerl)
- exit(0);
- }
-
- pascal long VoodooChile(Size cbNeeded)
- {
- long oldA5 = SetCurrentA5();
- long res;
-
- if (gSacrificialGoat && (GZSaveHnd() != gSacrificialGoat)) {
- /* Oh Memory Manager, our dark Lord. Take the blood of this animal to
- unwield thy power to crush our enemies.
-
- (Chant 7 times)
- */
- DisposeHandle(gSacrificialGoat);
-
- gSacrificialGoat = 0;
- res = SACRIFICE;
- } else
- res = 0;
-
- SetA5(oldA5);
-
- return res;
- }
-
- #pragma segment Main
-
- void main()
- {
- OSErr err;
- short result;
-
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- MaxApplZone();
- SetGrowZone(&VoodooChile);
- SetUpCursors();
-
- /*check environment checks to see if we are running 7.0*/
- if (!CheckEnvironment()) {
- SetCursor(&qd.arrow);
- /*pose the only 7.0 alert*/
- result = Alert(302, nil);
- return;
- }
-
- gPerlPrefs.version = PerlPrefVersion413;
- gPerlPrefs.runFinderOpens = false;
- gPerlPrefs.checkType = false;
- gPerlPrefs.inlineInput = true;
-
- OpenPreferences();
-
- SetUpMenus();
-
- gWCount = 0;
- gNewDocCount = 0;
- gQuitting = false;
- gFontMItem = 0;
- gConsoleList = nil;
- gActiveWindow = nil;
- gAppFile = CurResFile();
- gScriptFile = gAppFile;
- gWaitingScripts = (AppleEvent ***) NewHandle(0);
- gGotEof = nil;
- gSacrificialGoat = NewHandle(SACRIFICE);
-
- #ifndef RUNTIME
- if (err = InitEditionPack()) {
- ShowError("\pInitEditionPack", err);
- gQuitting = true;
- }
-
- if (err = AEObjectInit()) {
- ShowError("\pAEObjectInit", err);
- gQuitting = true;
- }
-
- InitAppleEvents();
-
- if (err = PPCInit()) {
- ShowError("\pPPCInit", err);
- gQuitting = true;
- }
-
- if (!(gTSMTEImplemented && !InitTSMAwareApplication())) {
- gTextServicesImplemented = false;
- gTSMTEImplemented = false;
- }
-
- gSavedFontForce = GetSMVariable(smFontForce);
- (void) SetSMVariable(smFontForce, 0);
- #else
- if (gAppleEventsImplemented) {
- InitAppleEvents();
-
- if (err = PPCInit()) {
- ShowError("\pPPCInit", err);
- gQuitting = true;
- }
- }
- #endif
-
- if (gQuitting)
- exit(0);
-
- InitPerlEnviron();
-
- for (gQuitting = DoRuntime(); !gQuitting; )
- MainEvent(false);
-
- #ifndef RUNTIME
- if (gTextServicesImplemented)
- CloseTSMAwareApplication();
- SetSMVariable(smFontForce, gSavedFontForce);
- #endif
- }
-