home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / language / harvest.cpt / Harvest C / Tcl 6.2 / CTclShell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-16  |  4.8 KB  |  201 lines

  1. /*
  2.     Harvest C
  3.     Copyright 1992 Eric W. Sink.  All rights reserved.
  4.     
  5.     This file is part of Harvest C.
  6.     
  7.     Harvest C is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU Generic Public License as published by
  9.     the Free Software Foundation; either version 2, or (at your option)
  10.     any later version.
  11.     
  12.     Harvest C is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.     
  17.     You should have received a copy of the GNU General Public License
  18.     along with Harvest C; see the file COPYING.  If not, write to
  19.     the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.     
  21.     Harvest C is not in any way a product of the Free Software Foundation.
  22.     Harvest C is not GNU software.
  23.     Harvest C is not public domain.
  24.  
  25.     This file may have other copyrights which are applicable as well.
  26.  
  27. */
  28.  
  29. /******************************************************************************
  30.     CTclShell.c
  31.     
  32.     Copyright 1992 Eric W. Sink        
  33.     Copyright ⌐ 1989 Symantec Corporation. All rights reserved.
  34.  
  35.  ******************************************************************************/
  36.  
  37. #include <Global.h>
  38. #include <Commands.h>
  39. #include <CApplication.h>
  40. #include <CBartender.h>
  41. #include <CDataFile.h>
  42. #include <CDecorator.h>
  43. #include <CDesktop.h>
  44. #include <CError.h>
  45. #include <CPanorama.h>
  46. #include <CScrollPane.h>
  47. #include <TBUtilities.h>
  48. #include "CTclShell.h"
  49. #include "HarvestCommands.h"
  50. #include "CTclPane.h"
  51. #include "CWindow.h"
  52. #include "stdarg.h"
  53.  
  54. #define    WINDculture        128        /* Resource ID for WIND template */
  55.  
  56. extern    CApplication *gApplication;    /* The application */
  57. extern    CBartender    *gBartender;    /* The menu handling object */
  58. extern    CDecorator    *gDecorator;    /* Window dressing object    */
  59. extern    CDesktop    *gDesktop;        /* The enclosure for all windows */
  60. extern    CBureaucrat    *gGopher;        /* The current boss in the chain of command */
  61. extern    OSType        gSignature;        /* The application's signature */
  62. extern    CError        *gError;        /* The error handling object */
  63.  
  64. extern  CTclShell *gShell;    /* One global Tcl Shell is allowed in Harvest C. */
  65.  
  66. /***
  67.  * ITclShell
  68.  *
  69.  ***/
  70.  
  71. void CTclShell::ITclShell(CApplication *aSupervisor, Boolean printable)
  72.  
  73. {
  74.     CDocument::IDocument(aSupervisor, printable);
  75.     
  76.     /* A Tcl shell has its own interpreter */
  77.  
  78.     myInterp = Tcl_CreateInterp();
  79.     Tcl_InitMacintosh(myInterp);
  80.     InitHarvestTcl(myInterp);
  81.     init_environment();
  82. }
  83.  
  84.  
  85. /***
  86.  * NewFile
  87.  *
  88.  *
  89.  ***/
  90. void CTclShell::NewFile(void)
  91.  
  92. {
  93.     BuildWindow(NULL);
  94.     itsWindow->Select();
  95.     itsWindow->SetTitle("\pTool Command Language");
  96. }
  97.  
  98.  
  99.  
  100. /***
  101.  * BuildWindow
  102.  *
  103.  ***/
  104.  
  105. void CTclShell::BuildWindow (Handle theData)
  106.  
  107. {
  108.     CScrollPane        *theScrollPane;
  109.     CTclPane        *theMainPane;
  110.     Rect            margin;
  111.  
  112.     itsWindow = new(CWindow);
  113.     itsWindow->IWindow(WINDculture, FALSE, gDesktop, this);
  114.     
  115.     theScrollPane = new(CScrollPane);
  116.     
  117.     theScrollPane->IScrollPane(itsWindow, this, 10, 10, 0, 0,
  118.                                 sizELASTIC, sizELASTIC,
  119.                                 TRUE, TRUE, TRUE);
  120.  
  121.     theScrollPane->FitToEnclFrame(TRUE, TRUE);
  122.  
  123.  
  124.     theMainPane = new(CTclPane);
  125.     itsMainPane = theMainPane;
  126.     itsGopher = theMainPane;
  127.  
  128.     theMainPane->ITclPane(theScrollPane, this, myInterp);
  129.  
  130.     theScrollPane->InstallPanorama(theMainPane);
  131.  
  132.     if (theData)
  133.         theMainPane->SetTextHandle(theData);
  134.     
  135.     gDecorator->PlaceNewWindow(itsWindow);
  136. }
  137.  
  138.  
  139.  
  140. /***
  141.  * UpdateMenus
  142. ***/
  143.  
  144.  void CTclShell::UpdateMenus()
  145.  
  146.  {
  147.  /* CUSTOM You will want to change these to support other menus or commands */
  148.  
  149.     inherited::UpdateMenus();
  150.     gBartender->DisableCmd(cmdSave);   
  151.     gBartender->DisableCmd(cmdSaveAs);
  152.     gBartender->DisableCmd(cmdTclShell);
  153.     gBartender->EnableCmd(cmdClose);
  154.     gBartender->DisableCmd(cmdPrint);
  155.  }
  156.  
  157. /******************************************************************************
  158.  Close {OVERRIDE}
  159.  
  160.         Close a Document
  161.  ******************************************************************************/
  162.  
  163. Boolean    CTclShell::Close(
  164.     Boolean        quitting)                /* Is this part of a quit sequence?    */
  165. {
  166.     /* CUSTOM Harvest C does not want to include any editor, so I disable
  167.         saving of Tcl shell windows */
  168.  
  169.     dirty = 0;
  170.     itsFile = NULL;
  171.     inherited::Close(quitting);
  172.     return(TRUE);                    /* Document has been closed            */
  173. }
  174.     
  175. /* Outside routines may insert text into this shell using this method */
  176.  
  177. void CTclShell::Hprintf(char *s, ...)
  178. {
  179.     va_list ap;
  180.     char *m;
  181.     va_start(ap,s);
  182.     m = (char *) icemalloc(2048);
  183.     vsprintf(m,s,ap);
  184.     va_end(ap);
  185.     ((CTclPane *) itsMainPane)->InsertTextPtr((Ptr) m,strlen(m),TRUE);
  186.     icefree(m);
  187. }
  188.  
  189. /* Outside routines may borrow our Tcl interpreter using this method */
  190.  
  191. int CTclShell::Eval(char *cmd,int flags, char **termPtr) {
  192.     Tcl_Eval(myInterp,cmd,flags,termPtr);
  193. }
  194.  
  195. void CTclShell::Dispose()
  196. {
  197.     gShell = NULL;
  198.     Tcl_DeleteInterp(myInterp);    /* Kill our interpreter when we leave */
  199.     inherited::Dispose();
  200. }
  201.