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.
-
- */
-
- /******************************************************************************
- CTclPane.c
-
- Copyright 1992 Eric W. Sink
- Copyright ⌐ 1989 Symantec Corporation. All rights reserved.
-
- ******************************************************************************/
-
-
- #include "CTclPane.h"
- #include <Commands.h>
- #include <CDocument.h>
- #include <CBartender.h>
- #include <Constants.h>
- #include "tcl.h"
-
- extern CBartender *gBartender;
-
- void CTclPane::ITclPane(CView *anEnclosure, CBureaucrat *aSupervisor, Tcl_Interp *anInterp)
-
- {
- Rect margin;
-
- myInterp = anInterp;
-
- CEditText::IEditText(anEnclosure, aSupervisor, 1, 1, 0, 0,
- sizELASTIC, sizELASTIC, 432);
- FitToEnclosure(TRUE, TRUE);
-
- SetRect(&margin, 2, 2, -2, -2);
- ChangeSize(&margin, FALSE);
- }
-
- void CTclPane::DoCommand(long theCommand)
-
- {
-
- /* I don't support any commands here CUSTOM */
-
- inherited::DoCommand(theCommand);
- }
-
- /* This is a hack. If this had been a serious, clean routine, the information
- signal you just saw would have been followed by a routine which was much more
- well thought out than this one. This is only a hack. */
- void strip_cr(char *s)
- {
- int len;
- len = strlen(s);
- if (s[len-1] == '\r') {
- s[len-1] = 0;
- }
- }
-
- void CTclPane::DoKeyDown(char theChar, Byte keyCode, EventRecord *macEvent)
-
- {
- /* The meat of my shell is here. Basically, this Tcl Shell executes the
- selected text or the current line whenever the enter key is pressed.
- The code below seems to work ok for me - please report any bugs.
- */
-
- char *text;
- if (theChar == kEnterKey) {
- long selStart;
- long selEnd;
- int code;
- int line;
- int len;
- GetSelection(&selStart,&selEnd);
- if (selStart == selEnd) {
- line = FindLine(selEnd);
- selStart = ((**macTE).lineStarts)[line];
- selEnd = ((**macTE).lineStarts)[line+1];
- }
- text = malloc(selEnd-selStart+2);
- strncpy(text,((*(**macTE).hText)+selStart),(selEnd-selStart));
- text[selEnd-selStart] = 0;
- strip_cr(text);
- code = Tcl_Eval(myInterp,text,0,0);
- GetSelection(&selStart,&selEnd);
- line = FindLine(selEnd);
- if (line >= GetNumLines()) {
- selStart = selEnd = (**macTE).teLength;
- }
- else {
- selStart = selEnd = ((**macTE).lineStarts)[line+1];
- if (!selStart) {
- selStart = selEnd = (**macTE).teLength;
- }
- }
- SetSelection(selEnd,selEnd,TRUE);
-
- len = strlen(myInterp->result);
-
- /* CUSTOM I have chosen to insert the "result" of each command
- into the shell. You may not want to do this. Tickle does
- not, for example.*/
- InsertTextPtr("\r",1,FALSE);
- InsertTextPtr(myInterp->result,len,FALSE);
- InsertTextPtr("\r",1,TRUE);
-
- ScrollToSelection();
-
- if (code) SysBeep(1);
- free(text);
- InitCursor();
- }
- else {
- inherited::DoKeyDown(theChar, keyCode, macEvent);
- }
-
- switch (keyCode) {
-
- case KeyHome:
- case KeyEnd:
- case KeyPageUp:
- case KeyPageDown:
- break;
-
- default:
- if (!((CDocument *)itsSupervisor)->dirty) {
- ((CDocument *)itsSupervisor)->dirty = TRUE;
- gBartender->EnableCmd(cmdSave);
- gBartender->EnableCmd(cmdSaveAs);
- }
- break;
- }
- }
-
-
- void CTclPane::DoAutoKey(char theChar, Byte keyCode, EventRecord *macEvent)
-
- {
-
- inherited::DoAutoKey(theChar, keyCode, macEvent);
-
- switch (keyCode) {
-
- case KeyHome:
- case KeyEnd:
- case KeyPageUp:
- case KeyPageDown:
- break;
-
- default:
- if (!((CDocument *)itsSupervisor)->dirty) {
- ((CDocument *)itsSupervisor)->dirty = TRUE;
- gBartender->EnableCmd(cmdSave);
- gBartender->EnableCmd(cmdSaveAs);
- }
- break;
- }
- }
-