home *** CD-ROM | disk | FTP | other *** search
/ AppleScript - The Beta Release / AppleScript - The Beta Release.iso / Development Tools / Sample Applications / MenuScripter 1.0d4.1 / MenuScripter Source / MSMain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-24  |  17.7 KB  |  720 lines  |  [TEXT/MPS ]

  1. /*
  2.     MSMain.c
  3.     
  4.     Version 1.0d4
  5.     
  6.     Copyright © Apple Computer UK Ltd. 1992
  7.     
  8.     All rights reserved.
  9.     
  10.     Produced by : UK Developer Technical Support
  11.     AppleLink   : UK.DTS
  12.  
  13.     Changes for 1.0d2 :
  14.     
  15.     11-Aug-92 : NH : Quit via AppleEvent
  16.     
  17.     Changes for 1.0d3 :
  18.     
  19.     27-Aug-92 : NH : Duplicate ScriptForMenuExists, ExecuteScriptForMenu in DoFile zapped
  20.                                      Prompt on new file when reverting fixed.
  21.                                      added failure check on ExecuteScriptForMenu - saves problems if
  22.                                      gustav quits before we do.
  23. */
  24.  
  25. #include <Memory.h>
  26. #include <QuickDraw.h>
  27. #include <Types.h>
  28. #include <Menus.h>
  29. #include <Windows.h>
  30. #include <Dialogs.h>
  31. #include <Traps.h>
  32. #include <Packages.h>
  33. #include <PPCToolbox.h>
  34. #include <Editions.h>
  35. #include <Printing.h>
  36. #include <ToolUtils.h>
  37. #include <Desk.h>
  38. #include <Scrap.h>
  39. #include <OsEvents.h>
  40. #include <AppleEvents.h>
  41. #include <AEObjects.h>
  42. #include <Errors.h>
  43. #include <PLStringFuncs.h>
  44.  
  45. #include "MSGlobals.h"
  46. #include "MSUtils.h"
  47. #include "MSEditions.h"
  48. #include "MSAppleEvents.h"
  49. #include "MSWindow.h"
  50. #include "MSFile.h"
  51. #include "MSScript.h"
  52.  
  53. /*-----------------------------------------------------------------------*/
  54. /**----------                         Standard Main routines                  --------------**/
  55. /*-----------------------------------------------------------------------*/
  56.  
  57. #pragma segment Main
  58.  
  59.     pascal void MaintainCursor(void)
  60.         {
  61.             Point     pt;
  62.             WindowPtr wPtr;
  63.             GrafPtr   savePort;
  64.             DPtr      theDoc;
  65.  
  66.             wPtr = FrontWindow();
  67.             if (Ours(wPtr))
  68.                 {
  69.                     theDoc = DPtrFromWindowPtr(wPtr);
  70.                     GetPort(&savePort);
  71.                     SetPort(wPtr);
  72.                     GetMouse(&pt);
  73.                     if (theDoc->theText)
  74.                         if (PtInRect(pt, &(**(theDoc->theText)).viewRect))
  75.                             SetCursor(&editCursor);
  76.                         else
  77.                             SetCursor(&qd.arrow);
  78.                     else
  79.                         SetCursor(&qd.arrow);
  80.  
  81.                     if (theDoc->theText)
  82.                         TEIdle(theDoc->theText);
  83.  
  84.                     SetPort(savePort);
  85.                 }
  86.         }
  87.  
  88. #pragma segment Main
  89.  
  90. pascal void MaintainMenus(void)
  91.     {
  92.         DPtr       theDoc;
  93.         WindowPtr  firstWindow;
  94.         SectHandle currSection;
  95.  
  96.         firstWindow = FrontWindow();
  97.         if (!Ours(firstWindow))
  98.             {
  99.                 EnableItem(myMenus[fileM], fmNew);
  100.                 EnableItem(myMenus[fileM], fmOpen);
  101.                 DisableItem(myMenus[fileM], fmClose);
  102.                 DisableItem(myMenus[fileM], fmSave);
  103.                 DisableItem(myMenus[fileM], fmSaveAs);
  104.                 DisableItem(myMenus[fileM], fmRevert);
  105.                 DisableItem(myMenus[fileM], fmPrint);
  106.                 DisableItem(myMenus[fileM], fmPageSetUp);
  107.                 
  108.                 DisableItem(myMenus[editM],  cPublisher);
  109.                 DisableItem(myMenus[editM],  cSubscriber);
  110.                 DisableItem(myMenus[editM],  cOptions);
  111.                 DisableItem(myMenus[editM],  cBorders);
  112.  
  113.                 DisableItem(myMenus[scriptM], cCompile);
  114.                 DisableItem(myMenus[scriptM], cExecute);
  115.                 
  116.                 if (firstWindow)
  117.                     {
  118.                         EnableItem(myMenus[editM], undoCommand);
  119.                         EnableItem(myMenus[editM], cutCommand);
  120.                         EnableItem(myMenus[editM], copyCommand);
  121.                         EnableItem(myMenus[editM], pasteCommand);
  122.                         EnableItem(myMenus[editM], clearCommand);
  123.                     }
  124.             }
  125.         else
  126.             {
  127.                 theDoc = DPtrFromWindowPtr(firstWindow);
  128.                 EnableItem(myMenus[editM], pasteCommand);
  129.                 EnableItem(myMenus[editM], cBorders);
  130.                 EnableItem(myMenus[fileM], fmClose);
  131.                 EnableItem(myMenus[fileM], fmSaveAs);
  132.                 EnableItem(myMenus[fileM], fmPrint);
  133.                 EnableItem(myMenus[fileM], fmPageSetUp);
  134.  
  135.                 if (theDoc->dirty)
  136.                     EnableItem(myMenus[fileM], fmRevert);
  137.                 else
  138.                     DisableItem(myMenus[fileM], fmRevert);
  139.                     
  140.                 if ((theDoc->dirty) && (theDoc->everSaved))
  141.                     EnableItem(myMenus[fileM], fmSave);
  142.                 else
  143.                     DisableItem(myMenus[fileM], fmSave);
  144.  
  145.                 DisableItem(myMenus[editM], undoCommand);
  146.                 
  147.                 if (((**(theDoc->theText)).selEnd - (**(theDoc->theText)).selStart) < 0)
  148.                     {
  149.                         DisableItem(myMenus[editM], cutCommand);
  150.                         DisableItem(myMenus[editM], copyCommand);
  151.                         DisableItem(myMenus[editM], clearCommand);
  152.                         DisableItem(myMenus[editM], cPublisher);
  153.                     }
  154.                 else
  155.                     {
  156.                         EnableItem(myMenus[editM], cutCommand);
  157.                         EnableItem(myMenus[editM], copyCommand);
  158.                         EnableItem(myMenus[editM], clearCommand);
  159.                         EnableItem(myMenus[editM], cPublisher);
  160.                     }
  161.  
  162.                 currSection = GetSection((**(theDoc->theText)).selStart,
  163.                                                                  (**(theDoc->theText)).selEnd,
  164.                                                                  theDoc);
  165.                 if (currSection)
  166.                     {
  167.                         DisableItem(myMenus[editM], cPublisher);
  168.                         DisableItem(myMenus[editM], cSubscriber);
  169.                         EnableItem(myMenus[editM],  cOptions);
  170.                         if ((**(**currSection).fSectHandle).kind == stPublisher)
  171.                             SetItem(myMenus[editM], cOptions, "\pPublisher Options…");
  172.                         else
  173.                             SetItem(myMenus[editM], cOptions, "\pSubscriber Options…");
  174.                     }
  175.                 else
  176.                     {
  177.                         EnableItem(myMenus[editM],  cPublisher);
  178.                         EnableItem(myMenus[editM],  cSubscriber);
  179.                         DisableItem(myMenus[editM], cOptions);
  180.                     }
  181.                     
  182.                 EnableItem(myMenus[scriptM], cCompile);
  183.                 EnableItem(myMenus[scriptM], cExecute);
  184.             }
  185.     }
  186.  
  187. #pragma segment Main
  188.  
  189. pascal void SetUpCursors(void)
  190.  
  191.     {
  192.         CursHandle  hCurs;
  193.  
  194.         hCurs = GetCursor(1);
  195.         editCursor = **hCurs;
  196.         hCurs = GetCursor(watchCursor);
  197.         waitCursor = **hCurs;
  198.     }
  199.  
  200. #pragma segment Main
  201.  
  202. pascal void SetUpMenus(void)
  203.     {
  204.         short i;
  205.         
  206.         myMenus[appleM] = GetMenu(appleID);
  207.         AddResMenu(myMenus[appleM], 'DRVR');
  208.         myMenus[fileM] = GetMenu(fileID);
  209.         myMenus[editM] = GetMenu(editID);
  210.         myMenus[fontM] = GetMenu(mfontID);
  211.         AddResMenu(myMenus[fontM], 'FONT');
  212.         myMenus[sizeM]  = GetMenu(sizeID);
  213.         myMenus[styleM] = GetMenu(styleID);
  214.         myMenus[scriptM] = GetMenu(mscriptID);
  215.  
  216.         for (i = appleM; i <= kLastMenu; i++)
  217.             InsertMenu(myMenus[i], 0);
  218.  
  219.         SetItemStyle(myMenus[styleM], cPlain, 0);
  220.         SetItemStyle(myMenus[styleM], cBold, bold);
  221.         SetItemStyle(myMenus[styleM], cItalic, italic);
  222.         SetItemStyle(myMenus[styleM], cUnderline, underline);
  223.         SetItemStyle(myMenus[styleM], cOutline, outline);
  224.         SetItemStyle(myMenus[styleM], cShadow, shadow);
  225.         SetItemStyle(myMenus[styleM], cCondense, condense);
  226.         SetItemStyle(myMenus[styleM], cExtend, extend);
  227.  
  228.         SetShortMenus(); /* Does a DrawMenuBar() */
  229.     }
  230.  
  231. pascal void DoFile(short theItem)
  232.     {        
  233.         short   alertResult;
  234.         DPtr    theDoc;
  235.         FSSpec  theFSSpec;
  236.         OSErr   fileErr;
  237.         TPrint  thePSetup;
  238.         Str255  revertName;
  239.     
  240.         switch (theItem){
  241.             case fmNew : IssueAENewWindow();
  242.                                      break;
  243.             case fmOpen: if (GetFile(&theFSSpec)==noErr)
  244.                                          fileErr = IssueAEOpenDoc(theFSSpec);
  245.                                      break;
  246.             case fmClose:IssueCloseCommand(FrontWindow());
  247.                                      break;
  248.             case fmSave:
  249.             case fmSaveAs:
  250.                                         theDoc = DPtrFromWindowPtr(FrontWindow());
  251.                     
  252.                                         if (theDoc->everSaved == false || theItem==fmSaveAs)
  253.                                             {
  254.                                                 fileErr = GetFileNameToSaveAs(theDoc);
  255.                                                 if (fileErr!=noErr && fileErr!=userCanceledErr)
  256.                                                     FileError("\perror saving ", theDoc->theFileName);
  257.                                                 else
  258.                                                     fileErr = IssueSaveCommand(theDoc->theWindow, &theDoc->theFSSpec);
  259.                     
  260.                                                 if (fileErr == noErr)
  261.                                                     SetWTitle(theDoc->theWindow, theDoc->theFSSpec.name);
  262.                                             }
  263.                                         else
  264.                                             fileErr = IssueSaveCommand(theDoc->theWindow, nil);
  265.                                         break;
  266.     
  267.             case fmRevert:SetCursor(&qd.arrow);
  268.                                         theDoc = DPtrFromWindowPtr(FrontWindow());
  269.                                         
  270.                                         if (theDoc->everSaved)
  271.                                             PLstrcpy(revertName,theDoc->theFileName);
  272.                                         else
  273.                                             GetWTitle(theDoc->theWindow, revertName);
  274.                                             
  275.                                         ParamText("\pRevert to the last saved version of ", revertName, "", "");
  276.                                         alertResult = Alert(AdviseAlert, nil);
  277.                                         switch (alertResult){
  278.                                             case aaSave:if (IssueRevertCommand(theDoc->theWindow))
  279.                                                                         FileError("\perror reverting ", theDoc->theFileName);
  280.                                         }
  281.                                         break;
  282.  
  283.             case fmPageSetUp:
  284.                                              theDoc = DPtrFromWindowPtr(FrontWindow());
  285.                                              if (DoPageSetup(theDoc))
  286.                                                  {
  287.                                                      thePSetup = **(theDoc->thePrintSetup);
  288.                                                      IssuePageSetupWindow(theDoc->theWindow, thePSetup);
  289.                                                  }
  290.                                              break;
  291.  
  292.             case fmPrint: IssuePrintWindow(FrontWindow());
  293.                                         break;
  294.  
  295.             case fmQuit : IssueQuitCommand();
  296.                                         break;
  297.         }                 /*of switch*/
  298.     }
  299.  
  300. #pragma segment Main
  301.  
  302. pascal void DoCommand(long mResult)
  303.     {
  304.         short   theItem;
  305.         short   theMenuID;
  306.         short   err;
  307.         long    result;
  308.         Str255  name;
  309.         DPtr    theDocument;
  310.         Boolean exists;
  311.         Boolean useOldCode;
  312.  
  313.         theDocument = DPtrFromWindowPtr(FrontWindow());
  314.         
  315.         theItem   = LoWord(mResult);
  316.         theMenuID = HiWord(mResult);
  317.         
  318.         err = ScriptForMenuExists(theMenuID, theItem, &exists);
  319.         
  320.         if (err==noErr && exists==true)
  321.             useOldCode = (ExecuteScriptForMenu(theMenuID, theItem)!=noErr);
  322.         else
  323.             useOldCode = true;
  324.             
  325.         if (useOldCode)
  326.             switch (theMenuID){
  327.     
  328.                 case appleID:
  329.                     if (theItem == aboutItem)
  330.                         {
  331.                             SetCursor(&qd.arrow);
  332.                             result = Alert(258, nil);
  333.                         }
  334.                     else
  335.                         {
  336.                             GetItem(myMenus[appleM], theItem, name);
  337.                             err = OpenDeskAcc(name);
  338.                             SetPort(FrontWindow());
  339.                         }
  340.                     break;
  341.                     
  342.                 case fileID: DoFile(theItem);
  343.                                          break;
  344.     
  345.                 case editID:
  346.                         if (SystemEdit(theItem - 1) == false);
  347.     
  348.                         switch (theItem){
  349.     
  350.                             case cutCommand   : IssueCutCommand(theDocument);
  351.                                                          break;
  352.                                                          
  353.                             case copyCommand  : IssueCopyCommand(theDocument);
  354.                                                          break;
  355.                                                          
  356.                             case pasteCommand : IssuePasteCommand(theDocument);
  357.                                                          break;
  358.                                                          
  359.                             case clearCommand : IssueClearCommand(theDocument);
  360.                                                          break;
  361.                                                          
  362.                             case selectAllCommand :
  363.                                                          if (theDocument)
  364.                                                              TESetSelect(0,
  365.                                                                                      (**(theDocument->theText)).teLength,
  366.                                                                                      theDocument->theText);
  367.                                                          break;
  368.                                                          
  369.                             case cPublisher : IssueCreatePublisher(theDocument);
  370.                                                      break;
  371.                                                          
  372.                             case cSubscriber: DoSubscribe(theDocument);
  373.                                                      break;
  374.                                                          
  375.                             case cOptions   : DoSectionOptions(theDocument);
  376.                                                      break;
  377.                                                          
  378.                             case cBorders   : IssueShowBorders(theDocument->theWindow,
  379.                                                                                         !theDocument->showBorders);
  380.                                                      break;
  381.                                                          
  382.                         }     /*of switch*/
  383.                         ShowSelect(theDocument);
  384.                         break;
  385.     
  386.                 case mfontID: IssueFontCommand(theDocument, theItem);
  387.                                             break;
  388.     
  389.                 case sizeID: IssueSizeCommand(theDocument, theItem);
  390.                                 break;
  391.     
  392.                 case styleID: IssueStyleCommand(theDocument, theItem);
  393.                                  break;
  394.                                  
  395.                 case mscriptID: switch (theItem){
  396.     
  397.                                                 case cCompile  : CompileDocument(theDocument);
  398.                                                                                  break;
  399.                                                 case cExecute  : ExecuteDocument(theDocument);
  400.                                                                                  break;
  401.                                                 }
  402.                                                 break;
  403.     
  404.             }                 /*of switch*/
  405.  
  406.     } /* DoCommand */
  407.  
  408. #pragma segment Main
  409.  
  410. pascal void DoMouseDown(const EventRecord *myEvent)
  411.     {
  412.         WindowPtr whichWindow;
  413.         Point     p;
  414.         Rect      dragRect;
  415.         Rect      oldPosn;
  416.         DPtr      theDoc;
  417.         long      menuResult;
  418.         OSErr     myErr;
  419.         Boolean   scriptExists;
  420.         WindowPtr oldFront;
  421.  
  422.         p = myEvent->where;
  423.         switch (FindWindow(p, &whichWindow)){
  424.  
  425.             case inDesk: SysBeep(10);
  426.                                      break;
  427.  
  428.             case inGoAway:if (Ours(whichWindow))
  429.                                             if (TrackGoAway(whichWindow, p))
  430.                                                 IssueCloseCommand(whichWindow);
  431.                                         break;
  432.             case inMenuBar:
  433.                                         SetCursor(&qd.arrow);
  434.                                         theDoc = DPtrFromWindowPtr(FrontWindow());
  435.                                         if (theDoc)
  436.                                             {
  437.                                                 SetFontMenu(theDoc);
  438.                                                 SetEditMenu(theDoc);
  439.                                             }
  440.                                         
  441.                                         menuResult = MenuSelect(p);
  442.                                         
  443.                                         /*
  444.                                             Check for script editing -
  445.                                           ctrl+option when selecting the menu = Edit Script )if any)
  446.                                         */
  447.                                         
  448.                                         if (OptionKeyPressed(myEvent) && CtrlKeyPressed(myEvent))
  449.                                             {
  450.                                                 myErr = ScriptForMenuExists(HiWord(menuResult), LoWord(menuResult), &scriptExists);
  451.                                                 if (scriptExists && myErr==noErr)
  452.                                                     EditMenuScript(HiWord(menuResult), LoWord(menuResult));
  453.                                                 else
  454.                                                     SysBeep(10);
  455.                                             }
  456.                                         else
  457.                                             DoCommand(menuResult);
  458.                                             
  459.                                         HiliteMenu(0);
  460.                                             
  461.                                         break;
  462.  
  463.             case inSysWindow: SystemClick(myEvent, whichWindow);
  464.                                                 break;
  465.  
  466.             case inDrag:
  467.                 
  468.                     dragRect = qd.screenBits.bounds;
  469.                     
  470.                     if (Ours(whichWindow))
  471.                         {
  472.                             oldFront = FrontWindow();
  473.                             oldPosn  = (**((WindowPeek)whichWindow)->strucRgn).rgnBBox;
  474.                             
  475.                             DragWindow(whichWindow, p, &dragRect);
  476.                             
  477.                             if ((whichWindow==FrontWindow()) &&
  478.                                 (whichWindow!=oldFront))
  479.                                 IssueSelectWindowCommand(whichWindow, oldFront); // Record the select part of drag
  480.                             /*
  481.                                 As rgnBBox may be passed by address
  482.                             */
  483.                             dragRect = (**((WindowPeek)whichWindow)->strucRgn).rgnBBox;
  484.                             /*
  485.                                 The windows already there, but still tell
  486.                                 the our AppleEvents core about the move in case
  487.                                 they want to do anything - or record
  488.                             */
  489.                             if (EqualRect(&dragRect, &oldPosn)==false)
  490.                                 IssueMoveWindow(whichWindow, dragRect);
  491.                         }
  492.                     break;
  493.  
  494.             case inGrow:SetCursor(&qd.arrow);
  495.                                     if (Ours(whichWindow))
  496.                                         MyGrowWindow(whichWindow, p);
  497.                                     break;
  498.                                 
  499.             case inZoomIn : DoZoom(whichWindow, inZoomIn, p);
  500.                                             break;
  501.  
  502.             case inZoomOut: DoZoom(whichWindow, inZoomOut, p);
  503.                                             break;
  504.             case inContent: if (whichWindow != FrontWindow())
  505.                                                 {
  506.                                                     IssueSelectWindowCommand(whichWindow, FrontWindow()); // Record the selectWindow
  507.                                                     SelectWindow(whichWindow);
  508.                                                 }
  509.                                             else
  510.                                                 if (Ours(whichWindow))
  511.                                                     DoContent(whichWindow, *myEvent);
  512.                                             break;
  513.         }                 /*of switch*/
  514.     }
  515.  
  516. #pragma segment Main
  517.  
  518. pascal long GetSleep(void)
  519.     {
  520.         long      sleep;
  521.         WindowPtr theWindow;
  522.         DPtr      theDoc;
  523.  
  524.         sleep = 0x7fffffff;
  525.         if (!gInBackground)
  526.             {
  527.                 theWindow = FrontWindow();
  528.                 if (theWindow)
  529.                     {
  530.                         theDoc = DPtrFromWindowPtr(theWindow);
  531.                         if ((**(theDoc->theText)).selStart == (**(theDoc->theText)).selEnd)
  532.                             sleep = GetCaretTime();
  533.                     }
  534.             }
  535.         return(sleep);
  536.     }                     /*GetSleep*/
  537.  
  538. #pragma segment Main
  539.  
  540.     
  541. pascal void MainEvent(void)
  542.     {
  543.         DPtr        theDoc;
  544.         EventRecord myEvent;
  545.         char        theChar;
  546.         WindowPtr   theWindow;
  547.         Boolean     activate;
  548.         Boolean     keyIsOk;
  549.         SectHandle  currSection;
  550.         
  551.  
  552.         MaintainCursor(); /* TEIdle in here for now */
  553.         MaintainMenus();
  554.  
  555.         if (WaitNextEvent(everyEvent, &myEvent, GetSleep(), nil))
  556.             {
  557.                 switch (myEvent.what) {
  558.                     case mouseDown: FlushAndRecordTypingBuffer();
  559.                                                     DoMouseDown(&myEvent);
  560.                                     break;
  561.                     case keyDown:
  562.                     case autoKey:
  563.                                 theDoc = DPtrFromWindowPtr(FrontWindow());
  564.     
  565.                                 theChar = myEvent.message & charCodeMask;
  566.                   
  567.                                 if (theChar==3) // Enter key == compile
  568.                                     {
  569.                                         CompileDocument(theDoc);
  570.                                     }
  571.                                 else
  572.                                 if ((myEvent.modifiers & cmdKey) == cmdKey)
  573.                                     {
  574.                                         DoCommand(MenuKey(theChar));
  575.                                         HiliteMenu(0);
  576.                                     }
  577.                                 else
  578.                                     if (theDoc->theText)
  579.                                         {
  580.                                             keyIsOk = true;
  581.                                             /*
  582.                                                 don't allow a subscriber to be changed
  583.                                             */
  584.                                             currSection = GetSection((**(theDoc->theText)).selStart,
  585.                                                                                              (**(theDoc->theText)).selEnd,
  586.                                                                                              theDoc);
  587.                                             
  588.                                             if (currSection)
  589.                                                 if ((**(**currSection).fSectHandle).kind == stSubscriber)
  590.                                                     keyIsOk = KeyOKinSubscriber(theChar);                                                    
  591.                                             
  592.                                             if (keyIsOk)
  593.                                                 {
  594.                                                     DoTEKeySectionRecalc(theDoc, theChar);
  595.                                                     
  596.                                                     AddKeyToTypingBuffer(theDoc, theChar);
  597.                                                     
  598.                                                     TEKey(theChar, theDoc->theText);
  599.                                                     
  600.                                                     RecalcChangedSectionBorders(theDoc);
  601.                                                     AdjustScrollbars(theDoc, false);
  602.                                                     ShowSelect(theDoc);
  603.                                                     
  604.                                                     theDoc->dirty = true;
  605.                                                 }
  606.                                         }
  607.                               break;
  608.                         
  609.                     case activateEvt:
  610.                             activate = ((myEvent.modifiers & activeFlag) != 0);
  611.                             theWindow = (WindowPtr)myEvent.message;
  612.                             DoActivate(theWindow, activate);
  613.                           break;
  614.  
  615.                     case updateEvt:
  616.                             theDoc = DPtrFromWindowPtr((WindowPtr)myEvent.message);
  617.                             DoUpdate(theDoc);
  618.                           break;
  619.  
  620.                     case kHighLevelEvent: FlushAndRecordTypingBuffer();
  621.                                                                 DoAppleEvent(myEvent);
  622.                                 break;
  623.                     case kOSEvent:
  624.                         
  625.                         switch (myEvent.message & osEvtMessageMask) { /*high byte of message*/
  626.                             case 0x01000000:
  627.                                 {
  628.                                     gInBackground = ((myEvent.message & resumeFlag) == 0);
  629.                                     DoActivate(FrontWindow(), !gInBackground);
  630.                                 }
  631.                         }
  632.                     }
  633.                 }             /*of switch*/
  634.         }
  635.  
  636. #pragma segment Main
  637.  
  638. pascal void DoSVEdit(void)
  639.     {
  640.         OSErr  err;
  641.         short  result;
  642.  
  643.         InitGraf(&qd.thePort);
  644.         InitFonts();
  645.         FlushEvents(everyEvent, 0);
  646.         InitWindows();
  647.         InitMenus();
  648.         TEInit();
  649.         InitDialogs(nil);
  650.         InitCursor();
  651.  
  652.         MaxApplZone();
  653.         SetUpCursors();
  654.  
  655.         SetUpMenus();
  656.  
  657.         gWCount      = 0;
  658.         gNewDocCount = 0;
  659.         gQuitting    = false;
  660.         gFontMItem   = 0;
  661.  
  662.         gGestaltAvailable          = false;
  663.         gAppleEventsImplemented    = false;
  664.         gAliasManagerImplemented   = false;
  665.         gEditionManagerImplemented = false;
  666.         gOutlineFontsImplemented   = false;
  667.  
  668.         /*check environment checks to see if we are running 7.0*/
  669.         if (!CheckEnvironment())
  670.             {
  671.                 SetCursor(&qd.arrow);
  672.                 /*pose the only 7.0 alert*/
  673.                 result = Alert(302, nil);
  674.                 return;
  675.             }
  676.  
  677.         err = InitEditionPack();
  678.         if (err)
  679.             {
  680.                 ShowError("\pInitEditionPack", err);
  681.                 gQuitting = true;
  682.             }
  683.  
  684.         err = AEObjectInit();
  685.         if (err)
  686.             {
  687.                 ShowError("\pAEObjectInit", err);
  688.                 gQuitting = true;
  689.             }
  690.  
  691.         InitAppleEvents();
  692.  
  693.         err = PPCInit();
  694.         if (err)
  695.             {
  696.                 ShowError("\pPPCInit", err);
  697.                 gQuitting = true;
  698.             }
  699.  
  700.     err = InitEditorScripting();
  701.         if (err)
  702.             {
  703.                 ShowError("\pInitEditorScripting", err);
  704.                 gQuitting = true;
  705.             }
  706.         else
  707.             {
  708.                 while (!gQuitting)
  709.                     MainEvent();
  710.             
  711.                 err = CloseEditorScripting();
  712.             }
  713.     }
  714.     
  715. main ()
  716.     {
  717.         /*the main routine starts here*/
  718.         DoSVEdit();
  719.     }
  720.