home *** CD-ROM | disk | FTP | other *** search
- /*
- Harvest C
- Copyright 1992 Eric W. Sink. All rights reserved.
-
- This file is part of Harvest C.
-
- Harvest C is free software; you can redistribute it and/or modify
- it under the terms of the GNU Generic Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- Harvest C is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Harvest C; see the file COPYING. If not, write to
- the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
- Harvest C is not in any way a product of the Free Software Foundation.
- Harvest C is not GNU software.
- Harvest C is not public domain.
-
- This file may have other copyrights which are applicable as well.
-
- */
-
- /******************************************************************************
- CTclShell.c
-
- Copyright 1992 Eric W. Sink
- Copyright ⌐ 1989 Symantec Corporation. All rights reserved.
-
- ******************************************************************************/
-
- #include <Global.h>
- #include <Commands.h>
- #include <CApplication.h>
- #include <CBartender.h>
- #include <CDataFile.h>
- #include <CDecorator.h>
- #include <CDesktop.h>
- #include <CError.h>
- #include <CPanorama.h>
- #include <CScrollPane.h>
- #include <TBUtilities.h>
- #include "CTclShell.h"
- #include "HarvestCommands.h"
- #include "CTclPane.h"
- #include "CWindow.h"
- #include "stdarg.h"
-
- #define WINDculture 128 /* Resource ID for WIND template */
-
- extern CApplication *gApplication; /* The application */
- extern CBartender *gBartender; /* The menu handling object */
- extern CDecorator *gDecorator; /* Window dressing object */
- extern CDesktop *gDesktop; /* The enclosure for all windows */
- extern CBureaucrat *gGopher; /* The current boss in the chain of command */
- extern OSType gSignature; /* The application's signature */
- extern CError *gError; /* The error handling object */
-
- extern CTclShell *gShell; /* One global Tcl Shell is allowed in Harvest C. */
-
- /***
- * ITclShell
- *
- ***/
-
- void CTclShell::ITclShell(CApplication *aSupervisor, Boolean printable)
-
- {
- CDocument::IDocument(aSupervisor, printable);
-
- /* A Tcl shell has its own interpreter */
-
- myInterp = Tcl_CreateInterp();
- Tcl_InitMacintosh(myInterp);
- InitHarvestTcl(myInterp);
- init_environment();
- }
-
-
- /***
- * NewFile
- *
- *
- ***/
- void CTclShell::NewFile(void)
-
- {
- BuildWindow(NULL);
- itsWindow->Select();
- itsWindow->SetTitle("\pTool Command Language");
- }
-
-
-
- /***
- * BuildWindow
- *
- ***/
-
- void CTclShell::BuildWindow (Handle theData)
-
- {
- CScrollPane *theScrollPane;
- CTclPane *theMainPane;
- Rect margin;
-
- itsWindow = new(CWindow);
- itsWindow->IWindow(WINDculture, FALSE, gDesktop, this);
-
- theScrollPane = new(CScrollPane);
-
- theScrollPane->IScrollPane(itsWindow, this, 10, 10, 0, 0,
- sizELASTIC, sizELASTIC,
- TRUE, TRUE, TRUE);
-
- theScrollPane->FitToEnclFrame(TRUE, TRUE);
-
-
- theMainPane = new(CTclPane);
- itsMainPane = theMainPane;
- itsGopher = theMainPane;
-
- theMainPane->ITclPane(theScrollPane, this, myInterp);
-
- theScrollPane->InstallPanorama(theMainPane);
-
- if (theData)
- theMainPane->SetTextHandle(theData);
-
- gDecorator->PlaceNewWindow(itsWindow);
- }
-
-
-
- /***
- * UpdateMenus
- ***/
-
- void CTclShell::UpdateMenus()
-
- {
- /* CUSTOM You will want to change these to support other menus or commands */
-
- inherited::UpdateMenus();
- gBartender->DisableCmd(cmdSave);
- gBartender->DisableCmd(cmdSaveAs);
- gBartender->DisableCmd(cmdTclShell);
- gBartender->EnableCmd(cmdClose);
- gBartender->DisableCmd(cmdPrint);
- }
-
- /******************************************************************************
- Close {OVERRIDE}
-
- Close a Document
- ******************************************************************************/
-
- Boolean CTclShell::Close(
- Boolean quitting) /* Is this part of a quit sequence? */
- {
- /* CUSTOM Harvest C does not want to include any editor, so I disable
- saving of Tcl shell windows */
-
- dirty = 0;
- itsFile = NULL;
- inherited::Close(quitting);
- return(TRUE); /* Document has been closed */
- }
-
- /* Outside routines may insert text into this shell using this method */
-
- void CTclShell::Hprintf(char *s, ...)
- {
- va_list ap;
- char *m;
- va_start(ap,s);
- m = (char *) icemalloc(2048);
- vsprintf(m,s,ap);
- va_end(ap);
- ((CTclPane *) itsMainPane)->InsertTextPtr((Ptr) m,strlen(m),TRUE);
- icefree(m);
- }
-
- /* Outside routines may borrow our Tcl interpreter using this method */
-
- int CTclShell::Eval(char *cmd,int flags, char **termPtr) {
- Tcl_Eval(myInterp,cmd,flags,termPtr);
- }
-
- void CTclShell::Dispose()
- {
- gShell = NULL;
- Tcl_DeleteInterp(myInterp); /* Kill our interpreter when we leave */
- inherited::Dispose();
- }
-