/*********** * CCompSeqApp.c * * Application methods for SequncerCompiler + Editor * * *********/ #include #include "SeqCommands.h" #include #include "CCompSeqApp.h" #include "CDLOGCompSeqDirector.h" /*#include "download.h"*/ #include "seq.h" extern CBartender *gBartender; #define kExtraMasters 10 #define kRainyDayFund 45000 #define kCriticalBalance 40000 #define kToolboxBalance 20000 #include "Global.h" #include "Constants.h" #include "CApplication.h" #include "Commands.h" #include "OSChecks.h" #include "CDirector.h" #include "CDecorator.h" #include "CError.h" #include "TCLUtilities.h" #include "TBUtilities.h" #include "CDesktop.h" #include "CBartender.h" #include "CClipboard.h" #include "CChore.h" #include "CSwitchboard.h" #include "CWindow.h" #include "CList.h" #include "CTask.h" #include "CAppleEvent.h" #include #include #include #include #include "CRadioGroupPane.h" /*** Global Variables ***/ extern CApplication *gApplication; /* Application object */ extern CDesktop *gDesktop; /* The visible Desktop */ extern CBartender *gBartender; /* Manages all menus */ extern CClipboard *gClipboard; /* Copies and Pastes data */ extern CBureaucrat *gGopher; /* First in line to get commands */ extern CError *gError; /* Error handler */ extern long gSleepTime; /* Max time between events */ extern Boolean gInBackground; /* In background under MultiFinder */ extern OSType gSignature; /* Creator for Application's files */ extern EventRecord gLastMouseDown; /* Previous mouse down event */ extern EventRecord gLastMouseUp; /* Previous mouse up event */ extern CView *gLastViewHit; /* Last view clicked in */ extern CDecorator *gDecorator; /* Decorator for arranging windows */ extern short gClicks; /* Click counter, = 1 single click */ /* = 2 double click */ /* etc. */ extern CursHandle gIBeamCursor; /* I-beam for text views */ extern CursHandle gWatchCursor; /* Watch cursor for waiting */ extern RgnHandle gUtilRgn; /* Utility region */ /*** Class Constants ***/ #define GROW_FAILURE 0L /* Return codes from GrowZoneFunc */ #define GROW_SUCCESS 1L /*** * ICompSeqApp * * Initialize the application. Your initialization method should * at least call the inherited method. If your application class * defines its own instance variables or global variables, this * is a good place to initialize them. * ***/ void CCompSeqApp::ICompSeqApp(void) { CApplication::IApplication( kExtraMasters, kRainyDayFund, kCriticalBalance, kToolboxBalance); } /*** * SetUpMenus * * In this method, you add special menu items and set the * menu item dimming and checking options for your menus. * The most common special menu items are the names of the * fonts. For this tiny editor, you also want to set up the * dimming and checking options so only the current font * and size are checked. * ***/ void CCompSeqApp::SetUpMenus(void) { /** ** Let the default method read the menus from ** the MBAR 1 resource. ** **/ inherited::SetUpMenus(); /** ** Add the fonts in the system to the ** Font menu. Remember, MENUfont is one ** of the reserved font numbers. ** **/ AddResMenu(GetMHandle(MENUfont), 'FONT'); /** ** The UpdateMenus() method sets up the dimming ** for menu items. By default, the bartender dims ** all the menus, and each bureaucrat is reponsible ** for turning on the items that correspond to the commands ** it can handle. ** ** Set up the options here. The edit pane's UpdateMenus() ** method takes care of doing the work. ** ** For Font and Size menus, you want all the items to ** be enabled all the time. In other words, you don't ** want the bartender to ever dim any of the items ** in these two menus. ** **/ gBartender->SetDimOption(MENUfont, dimNONE); gBartender->SetDimOption(MENUsize, dimNONE); gBartender->SetDimOption(MENUstyle, dimNONE); gBartender->SetDimOption(MENUcompile, dimNONE); /** ** For Font and Size menus, one of the items ** is always checked. Setting the unchecking option ** to TRUE lets the bartender know that it should ** uncheck all the menu items because an UpdateMenus() ** method will check the right items. ** For the Style menu, uncheck all the items and ** let the edit pane's UpdateMenus() method check the ** appropriate ones. ** **/ gBartender->SetUnchecking(MENUfont, TRUE); gBartender->SetUnchecking(MENUsize, TRUE); gBartender->SetUnchecking(MENUstyle, TRUE); gBartender->SetUnchecking(MENUcompile, TRUE); } /****************************************************************************** UpdateMenus {OVERRIDE} Perform menu management tasks ******************************************************************************/ void CCompSeqApp::UpdateMenus(void) { Str63 undoStr; CWindow *topWindow; Boolean isModalWindow; // Is the frontmost window modal? topWindow = gDesktop->GetTopWindow(); isModalWindow = topWindow? topWindow->IsModal() : FALSE; gBartender->EnableCmd(cmdQuit); gBartender->EnableCmd(cmdAbout); gBartender->EnableCmd(cmdRun); /*gBartender->EnableCmd(cmdDownload); */ if (gInBackground) { gBartender->EnableCmd(cmdClose); gBartender->EnableCmd(cmdUndo); gBartender->EnableCmd(cmdCut); gBartender->EnableCmd(cmdCopy); gBartender->EnableCmd(cmdPaste); gBartender->EnableCmd(cmdClear); } else if (!isModalWindow) { gBartender->EnableCmd(cmdToggleClip); } if (!rainyDayUsed && !isModalWindow) { gBartender->EnableCmd(cmdNew); gBartender->EnableCmd(cmdOpen); } GetIndString(undoStr, STRcommon, strUNDO); gBartender->SetCmdText(cmdUndo, undoStr); } /****************************************************************************** DoCommand Handle a command. Application has no supervisor which can handle the command. If we don't handle the command here, it will never be executed (and that's an error). ******************************************************************************/ void CCompSeqApp::DoCommand( register long theCommand) /* Command number */ { CDirector *director; CWindow *window; Str255 theDA; /* Name of Desk Accessory to open */ SFReply macSFReply; /* Standard File reply record */ SEQCompPtr CompileDialog; int i; short CompilationError; long numDirectors, SelectionStart, SelectionEnd; CList *itsDirectors; CAppleEvent *theEvent; FSSpec InputDoc; CEditPane *SeqEditPane; short defaultFontSize = 9; DialogPtr dialog; Boolean dialogDone = false; short itemHit; if (theCommand < 0) { if (HiShort(-theCommand) == MENUapple) { /* Open a DA or launch another */ /* application under MultiFinder */ GetItem(GetMHandle(MENUapple), LoShort(-theCommand), theDA); OpenDeskAcc(theDA); } } else { switch (theCommand) { case cmdAbout: dialog = GetNewDialog(3002, nil, (WindowPtr)-1L ); ShowWindow( dialog ); SetPort( dialog ); SetDialogDefaultItem(dialog, ok); while(! dialogDone) { ModalDialog( nil, &itemHit); if(itemHit==ok) { dialogDone = true; break; } } DisposDialog(dialog); break; case cmdNew: SetCursor(*gWatchCursor); CreateDocument(); break; case cmdOpen: ChooseFile(&macSFReply); if (macSFReply.good) { SetCursor(*gWatchCursor); OpenDocument(&macSFReply); SeqEditPane = (CEditPane *)(theDocument->itsMainPane); SeqEditPane->SetFontName("\pMonaco"); SeqEditPane->SetFontSize(defaultFontSize); } break; case cmdClose: if (IsSystemWindow((WindowPeek)FrontWindow())) CloseDeskAcc(((WindowPeek)FrontWindow())->windowKind); break; case cmdQuit: Quit(); break; case cmdUndo: case cmdCut: case cmdCopy: case cmdPaste: case cmdClear: SystemEdit((short)(theCommand - cmdUndo)); break; case cmdToggleClip: gClipboard->Toggle(); break; case cmdRun: CompileSequence(&macSFReply,&CompilationError); if(macSFReply.good == 1) { OpenDocument(&macSFReply); // do not open File if no error! SeqEditPane = (CEditPane *)(theDocument->itsMainPane); SeqEditPane->SetFontName("\pMonaco"); SeqEditPane->SetFontSize(defaultFontSize); if( CompilationError >= 0 ) { SelectionStart=(*SeqEditPane->macTE)->lineStarts[CompilationError]; SelectionEnd =(*SeqEditPane->macTE)->lineStarts[CompilationError+1]; } else { SelectionStart=0; // set cursor to first position in text SAP 30/3/94 SelectionEnd =0; } SeqEditPane->SetSelection(SelectionStart,SelectionEnd,TRUE); SeqEditPane->ScrollToSelection(); } break; /* case cmdDownload: DownLoad(); break; */ default: inherited::DoCommand( theCommand); break; } } } /*** * OpenDocument * * The user chose OpenŠ from the File menu. * In this method you need to create a document * and send it an OpenFile() message. * * The macSFReply is a good SFReply record that contains * the name and vRefNum of the file the user chose to * open. * ***/ void CCompSeqApp::OpenDocument(SFReply *macSFReply) { // In the event that opening the document fails, // we setup an exception handler here. If any // of the methods called within the scope of this // TRY block fail, an exception will be raised and // control will be transferred to the CATCH block. // Here, the CATCH block takes care of disposing // of the partially opened document. TRY { theDocument = new(CEditDoc); /** ** Send your document an initialization ** message. The first argument is the ** supervisor (the application). The second ** argument is TRUE if the document is printable. ** **/ theDocument->IEditDoc(this, TRUE); /** ** Send the document an OpenFile() message. ** The document will open a window, open ** the file specified in the macSFReply record, ** and display it in its window. ** **/ theDocument->OpenFile(macSFReply); } CATCH { ForgetObject( theDocument); } ENDTRY; }