home *** CD-ROM | disk | FTP | other *** search
- #include <MacIncludes.h>
- #include "Rk.h"
- #include "Structs.h"
- #include "file+rk.h"
- #include "Offscreen.h"
- #include "Help.h"
- #include "utl.h"
-
- /* #define PERFORMANCE */
- #define OPENCLOSES
-
-
-
-
- #ifdef PERFORMANCE
- #include <Perf.h>
- TP2PerfGlobals ThePGlobals;
- #endif
-
-
- #define PRED_CLIP 0
- #define TEXT_CLIP 1
-
-
- extern pascal void AsmClikLoop();
- extern void _DataInit();
-
- /* This routine is part of the MPW runtime library. This external
- reference to it is done so that we can unload its segment, %A5Init. */
-
-
-
- SysEnvRec gMac;
- WindowPtr gPredict,gText;
- Boolean gHasWaitNextEvent; /* set up by Initialize */
- Boolean gHaveAUX;
- Boolean gInBackground; /* maintained by Initialize and DoEvent */
- short gLogFileRef;
- short gNumDocuments; /* maintained by Initialize, DoNew, and DoCloseWindow */
- short gContextBar=60;
- FontInfo gFInfo,gNormFInfo;
- short gSpecialFont;
- Rect gHiliteRect;
- ControlHandle gPredScroll;
- Ptr Hilite=HiliteMode;
- short gPredScrollNum=0;
- GrafPort goffScreen;
- Boolean gDontSleep=false;
- PrefHandle gPrefs,gOldPrefs,gStartPrefs;
- int gSelLine=-1, gSelChar=-1;
- Boolean gNewLine;
- int gPrinting;
- short gFileCount;
- Rect gFreqRect,gOrderRect;
- Rect gFreqPromptRect,gOrderPromptRect;
- MenuHandle gFreqPop, gOrderPop;
- short gLastFreq,gLastOrder;
-
- extern Boolean gNewFile;
- Str255 gFileName="\pUntitled";
- Boolean gChanged;
- Boolean gLowMem=false;
- Boolean gReport=false;
-
- extern WindowPtr HelpWindow; /* ptr to help window */
-
-
- extern THPrint gPrinterRecord;
-
- void AlertUser();
- void EventLoop( void );
- void DoEvent( EventRecord *event );
- Boolean IsAppWindow( WindowPtr window );
- Boolean IsDAWindow( WindowPtr window );
- void AdjustMenus( void );
- void DoMenuCommand( long menuResult );
- void DoUpdate( WindowPtr window );
- void DrawPredictWindow(WindowPtr window);
- void DoActivate( WindowPtr window, Boolean becomingActive );
- void DoContentClick( WindowPtr window, EventRecord *event );
- void DoGrowWindow( WindowPtr window, EventRecord *event );
- void DoZoomWindow( WindowPtr window, short part );
- void ResizeWindow( WindowPtr window );
- void Terminate( void );
- Boolean DoCloseWindow( WindowPtr window );
- void DrawNewPredictions(void);
- void ReDrawPredictions(void);
- void DrawPrediction(char *prediction,int right);
- void SpecialLine(char *line,char *prediction);
- pascal void VActionProc( ControlHandle control, short part );
- pascal void HActionProc( ControlHandle control, short part );
- pascal void PredActionProc( ControlHandle control, short part );
- void DoKeyDown( EventRecord *event );
- void DrawWindow( WindowPtr window );
- void GetLocalUpdateRgn( WindowPtr window, RgnHandle localRgn );
- void AdjustTE( WindowPtr window );
- void AdjustHV( Boolean isVert, ControlHandle control, TEHandle docTE,
- Boolean canRedraw );
- void AdjustScrollValues( WindowPtr window, Boolean canRedraw );
- void AdjustScrollSizes( WindowPtr window );
- void AdjustScrollbars( WindowPtr window, Boolean needsResize );
- void CommonAction( ControlHandle control, short *amount );
- void AdjustViewRect( TEHandle docTE );
- void GetTERect( WindowPtr window, Rect *teRect );
- pascal void PascalClikLoop();
- pascal ProcPtr GetOldClikLoop();
- void DoNew( void );
- void DoIdle();
- unsigned long GetSleep();
- void NewContext();
- void DoOpen();
- void DoSave();
- void DoPrefs();
- void GetPrefs();
- void DoAbout();
- void SetCheckBox(dialog,item,state);
- char *PathNameFromDirID(long DirID, short vRefNum, char *s);
- char *PathNameFromWD(long vRefNum, char *s);
-
- extern void DoOpen();
- extern void DoSave();
- extern void AdjustCursor( Point mouse, RgnHandle region );
- extern void AdjustCurPred(Point mouse,RgnHandle region, WindowPtr window);
- extern void AdjustCurText(Point mouse,RgnHandle region, WindowPtr window);
- extern void GetGlobalRect (WindowPtr window, Rect *globalRect);
-
-
-
-
- extern int pred_number;
- int num_buffers=1;
- char output_string[1024], temp_str[1024];
- int output_string_length;
- char ed_context[MAX_CMD_LINE_LENGTH];
- /* extern ED_STRUCT editor_data; */
-
- #define TopLeft(aRect) (* (Point *) &(aRect).top)
- #define BotRight(aRect) (* (Point *) &(aRect).bottom)
-
-
-
- #pragma segment Main
-
- main(){
-
- #ifdef PERFORMANCE
- if (!InitPerf(&ThePGlobals,
- 4, /* ms */
- 8, /* bytes */
- true, /* measure ROM code */
- true, /* measure application code */
- (StringPtr)"\pCODE",/* segments to measure */
- 0, /* Let the performance tools calculate the ROM id */
- (StringPtr)"\p", /* Let the performance tools find the ROM name */
- false, /* don't measure RAM */
- 0, /* low RAM address */
- 0xFFFFF, /* high RAM address */
- 16 /* RAM bucket size */
- )){
- DebugStr("\pInitPerf Failed!!!");
- ExitToShell();
- }
- #endif
- #ifdef PERFORMANCE
- PerfControl(ThePGlobals,true);
- #endif
- UnloadSeg((Ptr) _DataInit); /* note that _DataInit must not be in Main! */
-
- MaxApplZone(); /* expand the heap so code segments load at the top */
-
- Init(); /* initialize the program */
- UnloadSeg((Ptr) Init); /* note that Initialize must not be in Main! */
- EventLoop();
-
- }
-
-
- #pragma segment Main
- void AlertUser(error)
- short error;
- {
- short itemHit;
- Str255 message;
-
- SetCursor(&qd.arrow);
- /* type Str255 is an array in MPW 3 */
- GetIndString(message, rErrStrings, error);
- ParamText(message, "", "", "");
-
- itemHit = Alert(rUserAlert, nil);
- } /* AlertUser */
-
- #pragma segment Main
- void EventLoop()
- {
- RgnHandle cursorRgn;
- Boolean gotEvent;
- EventRecord event;
-
- cursorRgn = NewRgn(); /* we╒ll pass WNE an empty region the 1st time thru */
- do {
- /* use WNE if it is available */
- #ifdef PERFORMANCE
- PerfControl(ThePGlobals,false);
- #endif
- if ( gHasWaitNextEvent )
- gotEvent = WaitNextEvent(everyEvent, &event, GetSleep(cursorRgn), cursorRgn);
- else {
- SystemTask();
- gotEvent = GetNextEvent(everyEvent, &event);
- }
- #ifdef PERFORMANCE
- PerfControl(ThePGlobals,true);
- #endif
- if ( gotEvent ) {
- /* make sure we have the right cursor before handling the event */
- AdjustCursor(event.where, cursorRgn);
- DoEvent(&event);
- }
- else
- DoIdle(); /* perform idle tasks when it╒s not our event */
- /* change the cursor (and region) if necessary */
- AdjustCursor(event.where, cursorRgn);
- } while ( true ); /* loop forever; we quit via ExitToShell */
- } /*EventLoop*/
-
- #pragma segment Main
- void DoIdle()
- {
- WindowPtr window;
-
- window = FrontWindow();
- if ( window == gText )
- TEIdle(((DocumentPeek) window)->docTE);
-
- if( gLowMem && !gReport){
- gReport=true;
- StopAlert(rLowMems,nil);
- }
- } /*DoIdle*/
-
- #pragma segment Main
- void DoEvent(event)
- EventRecord *event;
- {
- short part;
- WindowPtr window;
- Boolean hit;
- char key;
- WindowObject *whichObj; /* ptr to object for window clicked in */
- Boolean Help=false;
- Point where;
- unsigned long newSize;
-
-
- switch ( event->what ) {
- case nullEvent:
- /* we idle for null/mouse moved events ands for events which aren╒t
- ours (see EventLoop) */
- DoIdle();
- break;
-
- case mouseDown:
- part = FindWindow(event->where, &window);
- SetPort(window);
- if (window && window == HelpWindow) {
- Help=true;
- whichObj = (WindowObject*)((WindowPeek)window)->refCon;
- }
- switch ( part ) {
- case inMenuBar: /* process a mouse menu command (if any) */
- AdjustMenus();
- DoMenuCommand(MenuSelect(event->where));
- break;
- case inSysWindow: /* let the system handle the mouseDown */
- SystemClick(event, window);
- break;
- case inContent:
- if ( window != FrontWindow() ) {
- SelectWindow(window);
- /*DoContentClick(window,event);*/ /* use this line for "do first click" */
- } else if(Help){
- SetPort(window);
- where = event->where;
- GlobalToLocal(&where);
- if (whichObj->click)
- (*whichObj->click)(where, event->modifiers);
- } else
- DoContentClick(window,event);
- break;
- case inDrag: /* pass screenBits.bounds to get all gDevices */
- DragWindow(window, event->where, &qd.screenBits.bounds);
- break;
- case inGrow:
- if(window==gPredict){
- long growsize;
- Rect inval;
- int oldhsize = window->portRect.right -window->portRect.left;
-
- inval = qd.screenBits.bounds;
- inval.left = kMinPredWidth;
- inval.top = kMinPredHeight;
- growsize=GrowWindow(gPredict,event->where,&inval);
- if(growsize){
- SizeWindow(gPredict,LoWord(growsize),HiWord(growsize),1);
- SetRect(&inval,0,0,LoWord(growsize),HiWord(growsize));
- InvalRect(&inval);
- MoveControl(gPredScroll, window->portRect.right - kScrollbarAdjust, -1);
- SizeControl(gPredScroll, kScrollbarWidth, (window->portRect.bottom -
- window->portRect.top) - (kScrollbarAdjust - kScrollTweek));
- if(gContextBar>(LoWord(growsize)-kMinPredWidth/2))
- gContextBar=LoWord(growsize)-(oldhsize-gContextBar);
- if(gContextBar<(kMinPredWidth/2)) gContextBar = kMinPredWidth/2;
- }
- }else if(window==gText)
- DoGrowWindow(window, event);
- else if(Help){
- SetPort(window);
- newSize = GrowWindow(window, event->where,
- &whichObj->sizeRect);
- if (newSize && whichObj->grow)
- (*whichObj->grow)(newSize >> 16, newSize & 0xffff);
- }
- break;
- case inGoAway:
- if(TrackGoAway(window,event->where)){
- if(Help){
- if (whichObj->close) (*whichObj->close)();
- }else{
- DoCloseWindow(window); /* ignore the result */
- }
- }
- break;
- case inZoomIn:
- case inZoomOut:
- if (window==gPredict)
- {
- int oldhsize = window->portRect.right -window->portRect.left;
- hit = TrackBox(window, event->where, part);
- if ( hit ) {
- SetPort(window); /* the window must be the current port... */
- EraseRect(&window->portRect); /* because of a bug in ZoomWindow */
- ZoomWindow(window, part, true); /* note that we invalidate and erase... */
- InvalRect(&window->portRect); /* to make things look better on-screen */
- MoveControl(gPredScroll, window->portRect.right - kScrollbarAdjust, -1);
- SizeControl(gPredScroll, kScrollbarWidth, (window->portRect.bottom -
- window->portRect.top) - (kScrollbarAdjust - kScrollTweek));
- if(gContextBar>((window->portRect.right-window->portRect.left)-kMinPredWidth/2))
- gContextBar=(window->portRect.right-window->portRect.left)-(oldhsize-gContextBar);
- if(gContextBar<(kMinPredWidth/2)) gContextBar = kMinPredWidth/2;
- }
- } else if(window==gText)
- if ( TrackBox(window, event->where, part) )
- DoZoomWindow(window, part);
- break;
- }
- break;
- case keyDown:
- case autoKey: /* check for menukey equivalents */
- if (event->what == keyDown || event->what == autoKey) {
- key = event->message & charCodeMask;
- switch (key) {
- case homeKey:
- key = upArrow;
- event->modifiers |= cmdKey | shiftKey;
- break;
- case endKey:
- key = downArrow;
- event->modifiers |= cmdKey | shiftKey;
- break;
- case helpKey:
- key = '?';
- event->modifiers |= cmdKey;
- break;
- case pageUpKey:
- key = upArrow;
- event->modifiers |= cmdKey;
- break;
- case pageDownKey:
- key = downArrow;
- event->modifiers |= cmdKey;
- break;
- }
- event->message = (event->message & ~charCodeMask) | key;
- }
-
- key = event->message & charCodeMask;
- if ( event->modifiers & cmdKey ){ /* Command key down */
- if ( event->what == keyDown ) {
- AdjustMenus(); /* enable/disable/check menu items properly */
- DoMenuCommand(MenuKey(key));
- }
- } else {
- if(FrontWindow()==HelpWindow){
- WindowObject *FrontObj = (WindowObject*)((WindowPeek)FrontWindow())->refCon;
- if (FrontObj->key) (*FrontObj->key)(key, event->modifiers);
- }else
- DoKeyDown(event);
- }
- break;
- case activateEvt:
- window = (WindowPtr)event->message;
- if (window && window == HelpWindow) {
- whichObj = (WindowObject*)((WindowPeek)window)->refCon;
- SetPort(window);
- if (event->modifiers & activeFlag) {
- if (whichObj->activate) (*whichObj->activate)();
- } else {
- if (whichObj->deactivate) (*whichObj->deactivate)();
- }
- } else
- DoActivate((WindowPtr) event->message, (event->modifiers & activeFlag) != 0);
- break;
- case updateEvt:
- window = (WindowPtr)event->message;
- if (window && window == HelpWindow) {
- whichObj = (WindowObject*)((WindowPeek)window)->refCon;
- SetPort(window);
- BeginUpdate(window);
- EraseRect(&window->portRect);
- if (whichObj->update) (*whichObj->update)();
- EndUpdate(window);
- } else
- DoUpdate((WindowPtr) event->message);
- break;
- case kOSEvent:
- switch (event->message >> 24) { /* high byte of message */
- case kMouseMovedMessage:
- DoIdle(); /* mouse-moved is also an idle event */
- break;
- case kSuspendResumeMessage: /* suspend/resume is also an activate/deactivate */
- gInBackground = (event->message & kResumeMask) == 0;
- window = FrontWindow();
- if (window && window == HelpWindow) {
- whichObj = (WindowObject*)((WindowPeek)window)->refCon;
- SetPort(window);
- if (!gInBackground) {
- if (whichObj->activate) (*whichObj->activate)();
- } else {
- if (whichObj->deactivate) (*whichObj->deactivate)();
- }
- } else
- DoActivate(FrontWindow(), !gInBackground);
- break;
- }
- break;
- }
- } /*DoEvent*/
-
- #pragma segment Main
- unsigned long GetSleep(RgnHandle cursorRgn)
- {
- long sleep;
- WindowPtr window;
- TEHandle te;
- Point theMouse;
-
- sleep = 50; /* default value for sleep */
- GetMouse(&theMouse);
- LocalToGlobal(&theMouse);
- if(!PtInRgn(theMouse,cursorRgn)){
- return(0);
- }
- if ( !gInBackground ) {
- window = FrontWindow(); /* and the front window is ours... */
- if ( IsAppWindow(window) && (window != gPredict) && (window!=HelpWindow) ) {
- te = ((DocumentPeek) (window))->docTE; /* and the selection is an insertion point... */
- if ( (*te)->selStart == (*te)->selEnd )
- sleep = GetCaretTime(); /* blink time for the insertion point */
- }
- }
- return sleep;
- } /*GetSleep*/
-
- #pragma segment Main
- pascal void nullEraseRect(GrafVerb verb,const Rect *r)
- {
- if(verb!=erase)
- {
- StdRect(verb,r);
- }
- }
-
-
-
- void SetCheckBox(dialog,item,state)
- DialogPtr dialog;
- short item;
- short state;
- {
- short kind;
- Handle h;
- Rect r;
-
- GetDItem(dialog,item,&kind,&h,&r);
- SetCtlValue((ControlHandle)h,state);
- }
-
- #pragma segment Main
- Boolean IsAppWindow(window)
- WindowPtr window;
- {
- short windowKind;
-
- if ( window == nil )
- return false;
- else { /* application windows have windowKinds >= userKind (8) or dialogKind (2) */
- windowKind = ((WindowPeek) window)->windowKind;
- return (windowKind >= userKind) || (windowKind == dialogKind);
- }
- } /*IsAppWindow*/
-
-
- /* Check to see if a window belongs to a desk accessory. */
-
- #pragma segment Main
- Boolean IsDAWindow(window)
- WindowPtr window;
- {
- if ( window == nil )
- return false;
- else /* DA windows have negative windowKinds */
- return ((WindowPeek) window)->windowKind < 0;
- } /*IsDAWindow*/
-
- #pragma segment Main
- void AdjustMenus()
- {
- WindowPtr window;
- MenuHandle menu;
- long offset;
- Boolean undo;
- Boolean cutCopyClear;
- Boolean paste;
- TEHandle te;
- WindowObject *whichObj; /* ptr to object for window clicked in */
-
- window = FrontWindow();
- if(window&&window==HelpWindow){
- whichObj = (WindowObject*)((WindowPeek)window)->refCon;
- if (whichObj->adjust) (*whichObj->adjust)();
- } else {
-
- menu = GetMHandle(mFile);
-
- EnableItem(menu, iPrime); /* We can Always Prime */
- EnableItem(menu, iPageSetup); /* Ditto */
-
-
- #ifndef OPENCLOSES
- if ( gNumDocuments < kMaxOpenDocuments ){
- EnableItem(menu, iNew); /* New is enabled when we can open more documents */
- EnableItem(menu, iOpen); /* Open as well */
- } else {
- DisableItem(menu, iNew);
- DisableItem(menu, iOpen);
- }
- #else
- EnableItem(menu, iNew); /* New is enabled when we can open more documents */
- EnableItem(menu, iOpen); /* Open as well */
- #endif
- if (IsAppWindow(window)) /* Close is enabled when there is a window to close */
- EnableItem(menu, iClose);
- else
- DisableItem(menu, iClose);
- if (IsAppWindow(window)){ /* Save is enabled when there is a window to save */
- EnableItem(menu, iSave);
- EnableItem(menu, iSaveAs);
- if(!gNewFile){
- EnableItem(menu, iRevert);
- } else {
- DisableItem(menu, iRevert);
- }
- } else {
- DisableItem(menu, iSave);
- DisableItem(menu, iSaveAs);
- DisableItem(menu, iRevert);
- }
- if (window==gText){ /* Print is enabled when there is a window to Print */
- EnableItem(menu, iPrint);
- } else {
- DisableItem(menu, iPrint);
- }
-
-
- menu = GetMHandle(mEdit);
- undo = false;
- cutCopyClear = false;
- paste = false;
- if ( IsDAWindow(window) ) {
- undo = true; /* all editing is enabled for DA windows */
- cutCopyClear = true;
- paste = true;
- } else if ( IsAppWindow(window) ) {
- te = ((DocumentPeek) window)->docTE;
- if ( (*te)->selStart < (*te)->selEnd )
- cutCopyClear = true;
- /* Cut, Copy, and Clear is enabled for app. windows with selections */
- if ( GetScrap(nil, 'TEXT', &offset) )
- paste = true; /* if there╒s any text in the clipboard, paste is enabled */
- }
- if ( undo )
- EnableItem(menu, iUndo);
- else
- DisableItem(menu, iUndo);
- if ( cutCopyClear ) {
- EnableItem(menu, iCut);
- EnableItem(menu, iCopy);
- EnableItem(menu, iClear);
- } else {
- DisableItem(menu, iCut);
- DisableItem(menu, iCopy);
- DisableItem(menu, iClear);
- }
- if ( paste )
- EnableItem(menu, iPaste);
- else
- DisableItem(menu, iPaste);
- }
- } /*AdjustMenus*/
-
-
- #pragma segment Main
- void DoMenuCommand(menuResult)
- long menuResult;
- {
- short menuID, menuItem;
- short daRefNum;
- Str255 daName;
- OSErr saveErr;
- TEHandle te;
- WindowPtr window;
- Handle aHandle;
- long oldSize, newSize;
- long total, contig;
- WindowObject *whichObj; /* ptr to object for window clicked in */
- Boolean Help=false;
-
- window = FrontWindow();
- if(window==HelpWindow){
- whichObj = (WindowObject*)((WindowPeek)window)->refCon;
- Help=true;
- }
- menuID = HiWord(menuResult); /* use macros for efficiency to... */
- menuItem = LoWord(menuResult); /* get menu item number and menu number */
- switch ( menuID ) {
- case mApple:
- switch ( menuItem ) {
- case iAbout: /* bring up Dialog for About */
- help_Open(0);
- break;
- default: /* all non-About items in this menu are DAs et al */
- /* type Str255 is an array in MPW 3 */
- GetItem(GetMHandle(mApple), menuItem, daName);
- daRefNum = OpenDeskAcc(daName);
- break;
- }
- break;
- case mFile:
- switch ( menuItem ) {
- case iNew:
- #ifdef OPENCLOSES
- if(gNumDocuments == 1){
- if(DoCloseWindow(gText))
- DoNew();
- }else
- #endif
- DoNew();
- break;
- case iOpen:
- #ifdef OPENCLOSES
- if(gNumDocuments == 1){
- if(DoCloseWindow(gText))
- DoOpen();
- }else
- #endif
- DoOpen();
- break;
- case iPrime:
- DoPrime();
- break;
- case iSave:
- if(Help){
- if (whichObj->save) (*whichObj->save)();
- } else
- DoSave();
- break;
- case iSaveAs:
- if(Help){
- if (whichObj->save) (*whichObj->save)();
- } else
- DoSaveAs(gFileName);
- break;
- case iRevert:
- DoRevert();
- break;
- case iPageSetup:
- if(Help){
- if (whichObj->pageSetup){
- PrOpen();
- (*whichObj->pageSetup)();
- PrClose();
- }
- } else{
- PrOpen();
- if(PrError() == noErr)
- PrStlDialog(gPrinterRecord);
- PrClose();
- }
- break;
- case iPrint:
- if(Help){
- if (whichObj->print)
- PrOpen();
- (*whichObj->print)(false);
- PrClose();
- } else {
- SetPort(gText);
- PrintText(((DocumentPeek) FrontWindow())->docTE);
- }
- break;
- case iClose:
- if(Help){
- if (whichObj->close) (*whichObj->close)();
- } else
- DoCloseWindow(FrontWindow()); /* ignore the result */
- break;
- case iQuit:
- Terminate();
- break;
- }
- break;
- case mEdit: /* call SystemEdit for DA editing & MultiFinder */
- if ( !SystemEdit(menuItem-1) ) {
- gChanged = true;
- te = ((DocumentPeek) FrontWindow())->docTE;
- switch ( menuItem ) {
- case iCut:
- if ( ZeroScrap() == noErr ) {
- PurgeSpace(&total, &contig);
- if ((*te)->selEnd - (*te)->selStart + kTESlop > contig)
- AlertUser(eNoSpaceCut);
- else {
- TECut(te);
- if ( TEToScrap() != noErr ) {
- AlertUser(eNoCut);
- ZeroScrap();
- }
- }
- }
- break;
- case iCopy:
- if ( ZeroScrap() == noErr ) {
- TECopy(te); /* after copying, export the TE scrap */
- if ( TEToScrap() != noErr ) {
- AlertUser(eNoCopy);
- ZeroScrap();
- }
- }
- break;
- case iPaste: /* import the TE scrap before pasting */
- if ( TEFromScrap() == noErr ) {
- if ( TEGetScrapLen() + ((*te)->teLength -
- ((*te)->selEnd - (*te)->selStart)) > kMaxTELength )
- AlertUser(eExceedPaste);
- else {
- aHandle = (Handle) TEGetText(te);
- oldSize = GetHandleSize(aHandle);
- newSize = oldSize + TEGetScrapLen() + kTESlop;
- SetHandleSize(aHandle, newSize);
- saveErr = MemError();
- SetHandleSize(aHandle, oldSize);
- if (saveErr != noErr)
- AlertUser(eNoSpacePaste);
- else
- TEPaste(te);
- }
- }
- else
- AlertUser(eNoPaste);
- break;
- case iClear:
- TEDelete(te);
- break;
- }
- AdjustScrollbars(window, false);
- AdjustTE(window);
- }
- break;
- case mOptions:
- switch ( menuItem ) {
- case iModelOpts: /* bring up Dialog for Prefs */
- DoPrefs();
- break;
- }
- break;
-
- }
- HiliteMenu(0); /* unhighlight what MenuSelect (or MenuKey) hilited */
- } /*DoMenuCommand*/
-
- #pragma segment Main
- void DoUpdate( WindowPtr window )
- {
- if(window==gPredict){
- DrawPredictWindow(gPredict);
- } else if ( IsAppWindow(window) ) {
- BeginUpdate(window); /* this sets up the visRgn */
- if ( ! EmptyRgn(window->visRgn) ) /* draw if updating needs to be done */
- DrawWindow(window);
- EndUpdate(window);
- }
- } /*DoUpdate*/
-
-
- void DrawPredictWindow(WindowPtr window)
- {
- Rect globalRect;
- Boolean drawNeeded;
- BitMapPtr backMap,selectMap;
- BitMap MyMap=window->portBits;
- Rect Clip;
-
- SetPort(window);
-
- PushClip(PRED_CLIP);
-
- SetRect(&Clip,window->portRect.left,window->portRect.top,window->portRect.right, window->portRect.bottom);
- ClipRect(&Clip);
-
- GetGlobalRect(window,&globalRect);
-
- if(CheckBoundsOffscreen(((OffscreenPeek)window)->fSelectHandle,&globalRect, &drawNeeded)) /* Handle Memerr? */;
-
- BeginUpdateOffscreen(((OffscreenPeek)window)->fSelectHandle,window);
-
- if(CheckBoundsOffscreen(((OffscreenPeek)window)->fBackHandle,&globalRect, &drawNeeded)) /* Handle Memerr? */;
-
- if(drawNeeded){
- BeginOffscreenDrawing(((OffscreenPeek)window)->fBackHandle,window);
- EraseRect(&window->portRect);
- ReDrawPredictions();
- DrawGrowIcon(window);
- DrawControls(window);
- EndOffscreenDrawing(((OffscreenPeek)window)->fBackHandle);
- }
- backMap = GetMap(((OffscreenPeek)window)->fBackHandle);
- selectMap = GetMap(((OffscreenPeek)window)->fSelectHandle);
-
- if(backMap){
- ForeColor(blackColor);
- BackColor(whiteColor);
- if(selectMap){
- CopyBits(backMap, selectMap, &window->portRect, &window->portRect, srcCopy, nil);
- }else{
- CopyBits(backMap, &MyMap, &window->portRect, &window->portRect, srcCopy, nil);
- }
- ValidRectOffscreen(((OffscreenPeek)window)->fBackHandle, nil, &window->portRect);
- }
-
-
- EndUpdateOffscreen(((OffscreenPeek)window)->fSelectHandle,window);
- ClipRect(&(window->portRect));
- DrawGrowIcon(window);
- DrawControls(window);
- SetPort(gPredict);
- PopClip(PRED_CLIP);
- }
-
- #pragma segment Main
- void DoActivate(window, becomingActive)
- WindowPtr window;
- Boolean becomingActive;
- {
- RgnHandle tempRgn, clipRgn;
- Rect growRect;
- DocumentPeek doc;
- Rect TextRect;
- TEHandle te;
-
- if(IsAppWindow(window)){
- if (window != gPredict) {
- SetPort(window);
- doc = (DocumentPeek) window;
- if ( becomingActive ) {
- /* since we don╒t want TEActivate to draw a selection in an area where
- we╒re going to erase and redraw, we╒ll clip out the update region
- before calling it. */
- tempRgn = NewRgn();
- clipRgn = NewRgn();
- GetLocalUpdateRgn(window, tempRgn); /* get localized update region */
- GetClip(clipRgn);
- DiffRgn(clipRgn, tempRgn, tempRgn); /* subtract updateRgn from clipRgn */
- SetClip(tempRgn);
- TEActivate(doc->docTE);
- SetClip(clipRgn); /* restore the full-blown clipRgn */
- DisposeRgn(tempRgn);
- DisposeRgn(clipRgn);
-
- /* the controls must be redrawn on activation: */
- (*doc->docVScroll)->contrlVis = kControlVisible;
- (*doc->docHScroll)->contrlVis = kControlVisible;
- InvalRect(&(*doc->docVScroll)->contrlRect);
- InvalRect(&(*doc->docHScroll)->contrlRect);
- /* the growbox needs to be redrawn on activation: */
- growRect = window->portRect;
- /* adjust for the scrollbars */
- growRect.top = growRect.bottom - kScrollbarAdjust;
- growRect.left = growRect.right - kScrollbarAdjust;
- InvalRect(&growRect);
-
- }
- else {
- TEDeactivate(doc->docTE);
- /* the controls must be hidden on deactivation: */
- HideControl(doc->docVScroll);
- HideControl(doc->docHScroll);
- /* the growbox should be changed immediately on deactivation: */
- DrawGrowIcon(window);
- }
- } else {
- te = ((DocumentPeek) gText)->docTE;
- SetPort(gPredict);
- if( becomingActive ) {
- Rect inval=(*gPredScroll)->contrlRect;
- inval.bottom+=16;
- (*gPredScroll)->contrlVis = kControlVisible;
- InvalRect(&inval);
- }else{
- Rect inval=(*gPredScroll)->contrlRect;
-
-
- HideControl(gPredScroll);
- inval.bottom+=16;
- InvalRectOffscreen(((OffscreenPeek)gPredict)->fBackHandle,gPredict,&inval);
- InvalRectOffscreen(((OffscreenPeek)gPredict)->fSelectHandle,gPredict,&inval);
- SetPort(gText);
- SetRect(&TextRect,(*te)->selRect.left
- ,(*te)->selRect.top,
- (*te)->selRect.left+(goffScreen.portBits.bounds.right -
- goffScreen.portBits.bounds.left),
- (*te)->selRect.top+
- gNormFInfo.ascent+gNormFInfo.descent
- +gNormFInfo.leading);
- InvalRect(&TextRect);
- SetPort(gPredict);
- }
- }
- }
- } /*DoActivate*/
-
- #pragma segment Main
- void DoContentClick( WindowPtr window, EventRecord *event )
- {
- Point mouse;
- ControlHandle control;
- short part, value;
- Boolean shiftDown;
- DocumentPeek doc;
- Rect teRect;
- Rect MoveRect,LimitRect,SlopRect,iBeamRect;
- RgnHandle MoveRgn;
- long offset;
- long Count;
- char prediction[100];
- char line[100];
-
- SetPort(window);
- mouse = event->where; /* get the click position */
- GlobalToLocal(&mouse);
-
- if (window==gPredict) {
- MoveRgn=NewRgn();
- SetRect(&MoveRect,gContextBar-1,0,gContextBar+2,
- gPredict->portRect.bottom-gPredict->portRect.top-16);
- SetRect(&iBeamRect,0,2,
- (gPredict->portRect.right-gPredict->portRect.left)-18,
- (gPredict->portRect.bottom-gPredict->portRect.top)-18 );
-
- if(PtInRect(mouse,&MoveRect)){
- RectRgn(MoveRgn, &MoveRect);
- SlopRect=gPredict->portRect;
- LimitRect=gPredict->portRect;
- InsetRect(&LimitRect,30,0);
- offset=DragGrayRgn(MoveRgn,mouse,&LimitRect,&SlopRect,hAxisOnly,nil);
- if((short)LoWord(offset)!=(short)0x8000){
- gContextBar+=LoWord(offset);
- DrawNewPredictions();
- }
- }else if(PtInRect(mouse,&iBeamRect)){
- if(mouse.h>gContextBar){
- pred_number=(mouse.v-2)/
- (gFInfo.ascent+gFInfo.descent+gFInfo.leading)+gPredScrollNum;
- if((pred_number<((gPredict->portRect.bottom-gPredict->portRect.top-20)/
- (gFInfo.ascent+gFInfo.descent+gFInfo.leading))+gPredScrollNum)&&pred_number<96){
- make_a_prediction(prediction);
- SpecialLine(line,prediction);
- Count=1;
- while(((TextWidth(line,0,Count++)+gContextBar+5)<mouse.h)
- && *(line+Count-1));
-
- TEInsert(prediction,Count-1,((DocumentPeek)gText)->docTE);
- gChanged = true;
- TEDelete(((DocumentPeek)gText)->docTE);
- NewContext();
- update_the_model();
- DrawNewPredictions();
- }
- }else{
- char buffer[100];
- CharsHandle TEText=TEGetText(((DocumentPeek)gText)->docTE);
- Count=(*((DocumentPeek)gText)->docTE)->selStart>100?(*((DocumentPeek)gText)->docTE)->selStart-100:0;
- strncpy(buffer,((char *)*TEText)+Count,(*((DocumentPeek)gText)->docTE)->selStart-Count);
-
- SpecialLine(buffer,buffer);
- Count=(*((DocumentPeek)gText)->docTE)->selStart - (((gContextBar-2)-mouse.h)/CharWidth(' '));
- if(Count< 0 ) Count=0;
- /*
- Count=(*((DocumentPeek)gText)->docTE)->selStart;
-
- while(((gContextBar-2)-(TextWidth(buffer,Count,(*((DocumentPeek)gText)->docTE)->selStart-Count))>mouse.h)
- && Count)Count--;
- */
- TESetSelect(Count,(*((DocumentPeek)gText)->docTE)->selEnd,((DocumentPeek)gText)->docTE);
- TEDelete(((DocumentPeek)gText)->docTE);
- gChanged = true;
- DrawWindow(gText);
- NewContext();
- DrawNewPredictions();
- }
- }else{
- part = FindControl(mouse, window, &control);
- SetPort(gPredict);
- switch ( part ) {
- case 0: /* do nothing for viewRect case */
- break;
- case inThumb:
- if ( control == gPredScroll ){
- PushClip(PRED_CLIP);
- ClipRect(&(gPredict->portRect));
- value = GetCtlValue(control);
- part = TrackControl(control, mouse, nil);
- gPredScrollNum=GetCtlValue(control);
- PopClip(PRED_CLIP);
- }else
- DebugStr("FindControl returned inThumb to strange Control");
- break;
- default: /* they clicked in an arrow, so track & scroll */
- if ( control == gPredScroll )
- value = TrackControl(control, mouse, (ProcPtr) PredActionProc);
- break;
- }
- DrawNewPredictions();
- }
- DisposeRgn(MoveRgn);
- } else if ( IsAppWindow(window) ) {
- doc = (DocumentPeek) window;
- /* see if we are in the viewRect. if so, we won╒t check the controls */
- GetTERect(window, &teRect);
- if ( PtInRect(mouse, &teRect) ) {
- /* see if we need to extend the selection */
- shiftDown = (event->modifiers & shiftKey) != 0; /* extend if Shift is down */
- TEClick(mouse, shiftDown, doc->docTE);
- NewContext();
- DrawNewPredictions();
- } else {
- part = FindControl(mouse, window, &control);
- switch ( part ) {
- case 0: /* do nothing for viewRect case */
- break;
- case inThumb:
- value = GetCtlValue(control);
- part = TrackControl(control, mouse, nil);
- if ( part != 0 ) {
- value -= GetCtlValue(control);
- /* value now has CHANGE in value; if value changed, scroll */
- if ( value != 0 )
- if ( control == doc->docVScroll )
- TEScroll(0, value * (*doc->docTE)->lineHeight, doc->docTE);
- else
- TEScroll(value, 0, doc->docTE);
- }
- break;
- default: /* they clicked in an arrow, so track & scroll */
- if ( control == doc->docVScroll )
- value = TrackControl(control, mouse, (ProcPtr) VActionProc);
- else
- value = TrackControl(control, mouse, (ProcPtr) HActionProc);
- break;
- }
- DrawNewPredictions();
- }
- }
- } /*DoContentClick*/
-
-
- #pragma segment Main
- void Terminate()
- {
- WindowPtr aWindow;
- Boolean closed;
- #ifdef PERFORMANCE
- int perferr;
- #endif
-
-
- closed = true;
- do {
- aWindow = FrontWindow(); /* get the current front window */
- if (aWindow != nil);
- closed = DoCloseWindow(aWindow); /* close this window */
- }
- while (closed && (aWindow != nil));
- if (closed){
- #ifdef PERFORMANCE
- perferr=PerfDump(ThePGlobals,"\pPerform.out", true, 80);
- if(perferr!=noErr)
- {
- DebugStr("\pPerfDump Failed!!");
- ExitToShell();
- }
- TermPerf(ThePGlobals);
- #endif
-
- ExitToShell(); /* exit if no cancellation */
- }
- } /*Terminate*/
-
- #pragma segment Main
- Boolean DoCloseWindow(window)
- WindowPtr window;
- {
-
- WindowObject *whichObj;
- short itemHit;
-
-
- if ( IsDAWindow(window) )
- CloseDeskAcc(((WindowPeek) window)->windowKind);
- else if ( IsAppWindow(window) ){
- if(window==HelpWindow){
- whichObj = (WindowObject*)((WindowPeek)window)->refCon;
- if (whichObj->close) (*whichObj->close)();
- }else{
- SetCursor(&qd.arrow);
- ParamText(gFileName, "\pClosing", "", "");
-
- if(gChanged) itemHit = Alert(rCloseAlert, nil);
- else itemHit = iNo;
- switch(itemHit){
-
- case iYes:
- DoSave();
- if(gNewFile) return false;
- case iNo:
- gNumDocuments--;
- CloseWindow(gPredict);
- CloseWindow(gText);
- return true;
- break;
- case iCancel:
- return false;
- break;
- }
- }
- }
- return true;
- } /*DoCloseWindow*/
-
- #pragma segment Main
- void FileSystemError(Str255 FileName,Str255 doing, OSErr err, Boolean fatal)
- {
- DialogPtr ErrorDLOG;
- Str255 ErrorString;
- short hit;
-
- NumToString((long)err,&ErrorString);
- ParamText(fatal?"\pfatal ":"\p",doing,FileName,ErrorString);
- ErrorDLOG=GetNewDialog(rFileErrorDialog,nil, (void *) -1);
- do{
- ModalDialog(nil,&hit);
- }while(hit!=1);
- DisposDialog(ErrorDLOG);
- if(fatal) ExitToShell();
- }
-
- void DrawNewPredictions()
- {
- InvalRectOffscreen(((OffscreenPeek)gPredict)->fBackHandle,gPredict,&gPredict->portRect);
- InvalRectOffscreen(((OffscreenPeek)gPredict)->fSelectHandle,gPredict,&gPredict->portRect);
- DrawPredictWindow(gPredict);
- }
-
- #pragma segment Main
- void ReDrawPredictions()
- {
- char prediction[100];
- char buffer[100];
- Point penpt;
- CharsHandle TEText;
- TEHandle te;
- int Count;
-
-
- te = ((DocumentPeek) gText)->docTE;
- PenSize(2,2);
- ForeColor(blackColor);
- MoveTo(gContextBar,0);
- LineTo(gContextBar,gPredict->portRect.bottom-gPredict->portRect.top-16);
- PenSize(1,1);
- MoveTo(gContextBar+5,4+(gFInfo.ascent));
- for(pred_number=gPredScrollNum;
- pred_number<((gPredict->portRect.bottom-gPredict->portRect.top-20)/
- (gFInfo.ascent+gFInfo.descent+gFInfo.leading))+gPredScrollNum;
- pred_number++){
- if(pred_number<96){
- make_a_prediction(prediction);
- DrawPrediction(prediction,(gPredict->portRect.right-gPredict->portRect.left));
- }
- GetPen(&penpt);
- Move(-(penpt.h-gContextBar-5),gFInfo.ascent+gFInfo.descent+gFInfo.leading);
- }
- TEText=TEGetText(te);
- for(Count=(*te)->selStart;(Count>0)&&
- ((TextWidth((Ptr)(*TEText),Count,(*te)->selStart-Count))<(gContextBar-2))
- ;Count--);
- strncpy(buffer,((char *)*TEText)+Count,(*te)->selStart-Count);
- SpecialLine(buffer,buffer);
- if((*te)->selStart==0){
- MoveTo((gContextBar-2)-TextWidth("(NONE)",0,6),4+(gFInfo.ascent));
- DrawString("\p(NONE)");
- }
- else
- {
- MoveTo((gContextBar-2)-TextWidth(buffer,0,
- (*te)->selStart-Count), 4+(gFInfo.ascent));
- DrawText(buffer,0,(*te)->selStart-Count);
- }
- }
-
- #pragma segment Main
- void DrawPrediction(char *prediction,int right)
- {
- Point penpt;
- int x;
- char line[128];
-
- GetPen(&penpt);
- SpecialLine(line,prediction);
- for(x=0;(TextWidth(line,0,x)<((right-penpt.h)-(kScrollbarWidth+3)))&&line[x];x++);
- if(x>0) DrawText(line,0,x);
- }
-
- #pragma segment Main
- void SpecialLine(char *line,char *prediction)
- {
- if((*gPrefs)->pshowSpecial){
- while(*prediction){
- switch (*prediction){
- case 13: *line++ = kCrSpec;
- prediction++;
- break;
- case 32: *line++ = kSpSpec;
- prediction++;
- break;
- case 9: *line++ = kTabSpec;
- prediction++;
- break;
- default: *line++ = *prediction++;
- break;
- }
- }
- *(line)=0;
- } else strcpy(line,prediction);
- }
-
- #pragma segment Main
- GetOffscreen()
- {
- GrafPtr oldPort;
-
- SetPort(gText);
- GetFontInfo(&gNormFInfo);
- GetPort(&oldPort);
- OpenPort(&goffScreen);
- SetPort(oldPort);
- SetRect(&goffScreen.portRect,0,0,
- qd.screenBits.bounds.right-qd.screenBits.bounds.left,
- gNormFInfo.ascent+gNormFInfo.descent+gNormFInfo.leading);
- /* rowBytes is size of row, rounded up to an even number of bytes */
- goffScreen.portBits.rowBytes = (((goffScreen.portBits.bounds.right -
- goffScreen.portBits.bounds.left) + 15) >> 4) << 1;
-
- /* number of bytes in BitMap is rowBytes * number of rows */
- /* this calculation must be done with longs */
- goffScreen.portBits.baseAddr = NewPtr(goffScreen.portBits.rowBytes *
- (long) (goffScreen.portBits.bounds.bottom -
- goffScreen.portBits.bounds.top));
- SetPort(&goffScreen);
- TextFont(gSpecialFont);
- SetPort(gText);
- }
-
- #pragma segment Main
- void DoNew()
- {
- Boolean good;
- Boolean noBuffs=false;
- Ptr storage;
- Ptr predstorage;
- Rect destRect, viewRect;
- DocumentPeek doc;
-
- predstorage=NewPtr(sizeof(OffscreenRecord));
- if (predstorage==nil) AlertUser(eNoWindow);
- gPredict=nil;
- if(gMac.hasColorQD){
- gPredict=GetNewCWindow(rPredictWindow,predstorage,(void *) -1);
- }else {
- gPredict=GetNewWindow(rPredictWindow,predstorage,(void *) -1);
- }
- if (gPredict==nil) AlertUser(eNoWindow);
- ((OffscreenPeek)gPredict)->fBackHandle = nil;
- ((OffscreenPeek)gPredict)->fSelectHandle = nil;
-
- NewOffscreenForWindow(gPredict,&noBuffs,&((OffscreenPeek)gPredict)->fBackHandle);
- NewOffscreenForWindow(gPredict,&noBuffs,&((OffscreenPeek)gPredict)->fSelectHandle);
-
- SetPort(gPredict);
- GetFNum(kFontName,&gSpecialFont);
- TextFont(gSpecialFont);
- TextSize(12);
- TextFace(0);
- GetFontInfo(&gFInfo);
- gPredScroll=GetNewControl(rPredScroll,gPredict);
-
- storage = NewPtr(sizeof(DocumentRecord));
- if ( storage != nil ) {
- gText = GetNewWindow(rTermWindow, storage, (WindowPtr) -1);
- if ( gText != nil ) {
- gNumDocuments += 1; /* this will be decremented when we call DoCloseWindow */
- good = false;
- SetPort(gText);
- doc = (DocumentPeek) gText;
- GetTERect(gText, &viewRect);
- destRect = viewRect;
- destRect.right = destRect.left + kMaxDocWidth;
- doc->docTE = TENew(&destRect, &viewRect);
- AdjustViewRect(doc->docTE);
- TEAutoView(true, doc->docTE);
- doc->docClik = (ProcPtr) (*doc->docTE)->clikLoop;
- (*doc->docTE)->clikLoop = (ClikLoopProcPtr) AsmClikLoop;
-
- good = doc->docTE != nil; /* if TENew succeeded, we have a good document */
- if ( good ) { /* good document? ╤ get scrollbars */
- doc->docVScroll = GetNewControl(rVScroll, gText);
- good = (doc->docVScroll != nil);
- }
- if ( good) {
- doc->docHScroll = GetNewControl(rHScroll, gText);
- good = (doc->docHScroll != nil);
- }
-
- if ( good ) { /* good? ╤ adjust & draw the controls, draw the window */
- /* false to AdjustScrollValues means musn╒t redraw; technically, of course,
- the window is hidden so it wouldn╒t matter whether we called ShowControl or not. */
- AdjustScrollValues(gText, false);
- ShowWindow(gText);
- GetOffscreen();
- } else {
- DoCloseWindow(gText); /* otherwise regret we ever created it... */
- gText=nil;
- AlertUser(eNoWindow); /* and tell user */
- }
- } else
- DisposPtr(storage); /* get rid of the storage if it is never used */
- }
- gChanged = false;
- } /*DoNew*/
-
- #pragma segment Main
- void DoKeyDown(EventRecord *event)
- {
- WindowPtr window;
- char key;
- TEHandle te;
-
- window = FrontWindow();
- if ( window == gPredict)
- SelectWindow(gText);
- if ( IsAppWindow(window) ) {
- gChanged = true;
- te = ((DocumentPeek) gText)->docTE;
- key = event->message & charCodeMask;
- /* we have a char. for our window; see if we are still below TextEdit╒s
- limit for the number of characters (but deletes are always rad) */
- if ( key == kDelChar ||
- (*te)->teLength - ((*te)->selEnd - (*te)->selStart) + 1 <
- kMaxTELength ) {
-
- TEKey(key, te);
- NewContext();
- #ifdef EVERYKEY
- update_the_model();
- #else
- if(key==13)
- update_the_model();
- #endif
- DrawNewPredictions();
-
- AdjustScrollbars(gText, false);
- AdjustTE(gText);
- } else
- AlertUser(eExceedChar);
- }
- } /*DoKeyDown*/
-
-
- #pragma segment Main
- pascal void VActionProc(control,part)
- ControlHandle control;
- short part;
- {
- short amount;
- WindowPtr window;
- TEPtr te;
-
- if ( part != 0 ) { /* if it was actually in the control */
- window = (*control)->contrlOwner;
- te = *((DocumentPeek) window)->docTE;
- switch ( part ) {
- case inUpButton:
- case inDownButton: /* one line */
- amount = 1;
- break;
- case inPageUp: /* one page */
- case inPageDown:
- amount = (te->viewRect.bottom - te->viewRect.top) / te->lineHeight;
- break;
- }
- if ( (part == inDownButton) || (part == inPageDown) )
- amount = -amount; /* reverse direction for a downer */
- CommonAction(control, &amount);
- if ( amount != 0 )
- TEScroll(0, amount * te->lineHeight, ((DocumentPeek) window)->docTE);
- }
- } /* VActionProc */
-
-
- #pragma segment Main
- pascal void HActionProc(control,part)
- ControlHandle control;
- short part;
- {
- short amount;
- WindowPtr window;
- TEPtr te;
-
- if ( part != 0 ) {
- window = (*control)->contrlOwner;
- te = *((DocumentPeek) window)->docTE;
- switch ( part ) {
- case inUpButton:
- case inDownButton: /* a few pixels */
- amount = kButtonScroll;
- break;
- case inPageUp: /* a page */
- case inPageDown:
- amount = te->viewRect.right - te->viewRect.left;
- break;
- }
- if ( (part == inDownButton) || (part == inPageDown) )
- amount = -amount; /* reverse direction */
- CommonAction(control, &amount);
- if ( amount != 0 )
- TEScroll(amount, 0, ((DocumentPeek) window)->docTE);
- }
- } /* VActionProc */
-
- #pragma segment Main
- void DrawWindow(window)
- WindowPtr window;
- {
- SetPort(window);
- EraseRect(&window->portRect);
- DrawControls(window);
- DrawGrowIcon(window);
- TEUpdate(&window->portRect, ((DocumentPeek) window)->docTE);
- } /*DrawWindow*/
-
- #pragma segment Main
- void GetLocalUpdateRgn(window,localRgn)
- WindowPtr window;
- RgnHandle localRgn;
- {
- CopyRgn(((WindowPeek) window)->updateRgn, localRgn); /* save old update region */
- OffsetRgn(localRgn, window->portBits.bounds.left, window->portBits.bounds.top);
- } /* GetLocalUpdateRgn */
-
-
- #pragma segment Main
- void AdjustTE(window)
- WindowPtr window;
- {
- TEPtr te;
-
- te = *((DocumentPeek)window)->docTE;
- TEScroll((te->viewRect.left - te->destRect.left) -
- GetCtlValue(((DocumentPeek)window)->docHScroll),
- (te->viewRect.top - te->destRect.top) -
- (GetCtlValue(((DocumentPeek)window)->docVScroll) *
- te->lineHeight),
- ((DocumentPeek)window)->docTE);
- } /*AdjustTE*/
-
- #pragma segment Main
- void AdjustHV(isVert,control,docTE,canRedraw)
- Boolean isVert;
- ControlHandle control;
- TEHandle docTE;
- Boolean canRedraw;
- {
- short value, lines, max;
- short oldValue, oldMax;
- TEPtr te;
-
- oldValue = GetCtlValue(control);
- oldMax = GetCtlMax(control);
- te = *docTE; /* point to TERec for convenience */
- if ( isVert ) {
- lines = te->nLines;
- /* since nLines isn╒t right if the last character is a return, check for that case */
- if ( *(*te->hText + te->teLength - 1) == kCrChar )
- lines += 1;
- max = lines - ((te->viewRect.bottom - te->viewRect.top) /
- te->lineHeight);
- } else
- max = kMaxDocWidth - (te->viewRect.right - te->viewRect.left);
-
- if ( max < 0 ) max = 0;
- SetCtlMax(control, max);
-
- /* Must deref. after SetCtlMax since, technically, it could draw and therefore move
- memory. This is why we don╒t just do it once at the beginning. */
- te = *docTE;
- if ( isVert )
- value = (te->viewRect.top - te->destRect.top) / te->lineHeight;
- else
- value = te->viewRect.left - te->destRect.left;
-
- if ( value < 0 ) value = 0;
- else if ( value > max ) value = max;
-
- SetCtlValue(control, value);
- /* now redraw the control if it needs to be and can be */
- if ( canRedraw || (max != oldMax) || (value != oldValue) )
- ShowControl(control);
- } /*AdjustHV*/
-
-
- /* Simply call the common adjust routine for the vertical and horizontal scrollbars. */
-
- #pragma segment Main
- void AdjustScrollValues(window,canRedraw)
- WindowPtr window;
- Boolean canRedraw;
- {
- DocumentPeek doc;
-
- doc = (DocumentPeek)window;
- AdjustHV(true, doc->docVScroll, doc->docTE, canRedraw);
- AdjustHV(false, doc->docHScroll, doc->docTE, canRedraw);
- } /*AdjustScrollValues*/
-
-
- /* Re-calculate the position and size of the viewRect and the scrollbars.
- kScrollTweek compensates for off-by-one requirements of the scrollbars
- to have borders coincide with the growbox. */
-
- #pragma segment Main
- void AdjustScrollSizes(window)
- WindowPtr window;
- {
- Rect teRect;
- DocumentPeek doc;
-
- doc = (DocumentPeek) window;
- GetTERect(window, &teRect); /* start with TERect */
- (*doc->docTE)->viewRect = teRect;
- AdjustViewRect(doc->docTE); /* snap to nearest line */
- MoveControl(doc->docVScroll, window->portRect.right - kScrollbarAdjust, -1);
- SizeControl(doc->docVScroll, kScrollbarWidth, (window->portRect.bottom -
- window->portRect.top) - (kScrollbarAdjust - kScrollTweek));
- MoveControl(doc->docHScroll, -1, window->portRect.bottom - kScrollbarAdjust);
- SizeControl(doc->docHScroll, (window->portRect.right -
- window->portRect.left) - (kScrollbarAdjust - kScrollTweek),
- kScrollbarWidth);
- } /*AdjustScrollSizes*/
-
-
- /* Turn off the controls by jamming a zero into their contrlVis fields (HideControl erases them
- and we don't want that). If the controls are to be resized as well, call the procedure to do that,
- then call the procedure to adjust the maximum and current values. Finally re-enable the controls
- by jamming a $FF in their contrlVis fields. */
-
- #pragma segment Main
- void AdjustScrollbars(window,needsResize)
- WindowPtr window;
- Boolean needsResize;
- {
- DocumentPeek doc;
-
- doc = (DocumentPeek) window;
- /* First, turn visibility of scrollbars off so we won╒t get unwanted redrawing */
- (*doc->docVScroll)->contrlVis = kControlInvisible; /* turn them off */
- (*doc->docHScroll)->contrlVis = kControlInvisible;
- if ( needsResize ) /* move & size as needed */
- AdjustScrollSizes(window);
- AdjustScrollValues(window, needsResize); /* fool with max and current value */
- /* Now, restore visibility in case we never had to ShowControl during adjustment */
- (*doc->docVScroll)->contrlVis = kControlVisible; /* turn them on */
- (*doc->docHScroll)->contrlVis = kControlVisible;
- } /* AdjustScrollbars */
-
- #pragma segment Main
- void CommonAction(control,amount)
- ControlHandle control;
- short *amount;
- {
- short value, max;
-
- value = GetCtlValue(control); /* get current value */
- max = GetCtlMax(control); /* and maximum value */
- *amount = value - *amount;
- if ( *amount < 0 )
- *amount = 0;
- else if ( *amount > max )
- *amount = max;
- SetCtlValue(control, *amount);
- *amount = value - *amount; /* calculate the real change */
- } /* CommonAction */
-
- #pragma segment Main
- void AdjustViewRect(docTE)
- TEHandle docTE;
- {
- TEPtr te;
-
- te = *docTE;
- te->viewRect.bottom = (((te->viewRect.bottom - te->viewRect.top) / te->lineHeight)
- * te->lineHeight) + te->viewRect.top;
- } /*AdjustViewRect*/
-
- #pragma segment Main
- void GetTERect(window,teRect)
- WindowPtr window;
- Rect *teRect;
- {
- *teRect = window->portRect;
- InsetRect(teRect, kTextMargin, kTextMargin); /* adjust for margin */
- teRect->bottom = teRect->bottom - 15; /* and for the scrollbars */
- teRect->right = teRect->right - 15;
- } /*GetTERect*/
-
- #pragma segment Main
- pascal void PascalClikLoop()
- {
- WindowPtr window;
- RgnHandle region;
-
- window = FrontWindow();
- region = NewRgn();
- GetClip(region); /* save clip */
- ClipRect(&window->portRect);
- AdjustScrollValues(window, true); /* pass true for canRedraw */
- SetClip(region); /* restore clip */
- DisposeRgn(region);
- } /* PascalClikLoop */
-
-
- #pragma segment Main
- pascal ProcPtr GetOldClikLoop()
- {
- return ((DocumentPeek)FrontWindow())->docClik;
- } /* GetOldClikLoop */
-
-
- #pragma segment Main
- void DoGrowWindow(window,event)
- WindowPtr window;
- EventRecord *event;
- {
- long growResult;
- Rect tempRect;
- RgnHandle tempRgn;
- DocumentPeek doc;
-
- SetPort(window);
- tempRect = qd.screenBits.bounds; /* set up limiting values */
- tempRect.left = kMinDocDim;
- tempRect.top = kMinDocDim;
- growResult = GrowWindow(window, event->where, &tempRect);
- /* see if it really changed size */
- if ( growResult != 0 ) {
- doc = (DocumentPeek) window;
- tempRect = (*doc->docTE)->viewRect; /* save old text box */
- tempRgn = NewRgn();
- GetLocalUpdateRgn(window, tempRgn); /* get localized update region */
- SizeWindow(window, LoWord(growResult), HiWord(growResult), true);
- ResizeWindow(window);
- /* calculate & validate the region that hasn╒t changed so it won╒t get redrawn */
- SectRect(&tempRect, &(*doc->docTE)->viewRect, &tempRect);
- ValidRect(&tempRect); /* take it out of update */
- InvalRgn(tempRgn); /* put back any prior update */
- DisposeRgn(tempRgn);
- }
- } /* DoGrowWindow */
-
-
- /* Called when a mouseClick occurs in the zoom box of an active window.
- Everything has to get re-drawn here, so we don't mind that
- ResizeWindow invalidates the whole portRect. */
-
- #pragma segment Main
- void DoZoomWindow(window,part)
- WindowPtr window;
- short part;
- {
- EraseRect(&window->portRect);
- ZoomWindow(window, part, window == FrontWindow());
- ResizeWindow(window);
- } /* DoZoomWindow */
-
- #pragma segment Main
- void ResizeWindow(window)
- WindowPtr window;
- {
- SetPort(window);
- AdjustScrollbars(window, true);
- AdjustTE(window);
- InvalRect(&window->portRect);
- } /* ResizeWindow */
-
-
-
- #pragma segment Main
- pascal void PredActionProc(control,part)
- ControlHandle control;
- short part;
- {
- short amount;
- short value, max;
-
-
- if ( part != 0 ) { /* if it was actually in the control */
- switch ( part ) {
- case inUpButton:
- case inDownButton: /* one line */
- amount = 1;
- break;
- case inPageUp: /* one page */
- case inPageDown:
- amount = (gPredict->portRect.bottom-gPredict->portRect.top-20)/
- (gFInfo.ascent+gFInfo.descent+gFInfo.leading);
- break;
- }
- if ( (part == inDownButton) || (part == inPageDown) )
- amount = -amount; /* reverse direction for a downer */
-
- value = GetCtlValue(control); /* get current value */
- max = GetCtlMax(control); /* and maximum value */
- amount = value - amount;
- if ( amount < 0 )
- amount = 0;
- else if ( amount > max )
- amount = max;
- SetCtlValue(control, amount);
- gPredScrollNum=GetCtlValue(control);
- DrawNewPredictions();
- }
- } /* PredActionProc */
-
- #pragma segment Main
- void NewContext()
- {
- TEHandle te;
- CharsHandle TEText;
- int x;
-
- SetCtlValue(gPredScroll,0);
- gPredScrollNum=0;
-
- te = ((DocumentPeek) gText)->docTE;
- TECalText(te);
- TEText=TEGetText(te);
-
- for(x=(*te)->selStart;(x>0)&&(x>(*te)->selStart-128);x--);
- strncpy(ed_context,(char *) (*TEText)+x,(*te)->selStart-x);
- ed_context[(*te)->selStart-x]=0;
- #ifdef DEBUG
- {
- KeyMap theKeys;
- GetKeys(&theKeys);
- if(theKeys[1] == 32773){
- debugstr(ed_context);
- }
- }
- #endif
- }
-
-
- #pragma segment Prefs
- pascal void DrawRndRect(theDialog,theItem)
- DialogPtr theDialog;
- short int theItem;
-
- {
- short int iType; /*returned item type*/
- Rect iBox; /*returned bounds rect*/
- Handle iHdl; /*returned item handle*/
-
- GetDItem(theDialog,theItem,&iType,&iHdl,&iBox); /*get the box*/
- InsetRect(&iBox,-4,-4);
- PenSize(3,3);
- FrameRoundRect(&iBox,10,10);
- PenNormal();
- } /*DrawRndRect*/
-
- #pragma segment Prefs
- pascal void DrawPopup(theDialog,theItem)
- DialogPtr theDialog;
- short int theItem;
-
- {
- short int iType; /*returned item type*/
- Rect iBox; /*returned bounds rect*/
- Handle iHdl; /*returned item handle*/
- Str255 CurText;
- int wid,newWid,newLen;
- MenuHandle theMenu;
- short lastChoice;
-
- switch(theItem){
- case iFreqPop:
- theMenu = gFreqPop;
- lastChoice = gLastFreq;
- break;
- case iOrderPop:
- theMenu=gOrderPop;
- lastChoice = gLastOrder;
- break;
- default:
- abortit("Bad case in switch (DrawPopup)");
- }
-
- GetDItem(theDialog,theItem,&iType,&iHdl,&iBox); /*get the box*/
-
- GetItem(theMenu,lastChoice,CurText);
- wid = (iBox.right-iBox.left)-(kLeftSlop+kRightSlop);
- newWid = StringWidth(CurText);
- if(newWid > wid) {
- newLen = CurText[0];
- wid -= CharWidth('╔');
- while((newWid > wid) && CurText[0]){
- newWid -= CharWidth(CurText[newLen]);
- newLen--;
- }
- CurText[++newLen]= '╔';
- CurText[0]=newLen;
- }
- FrameRect(&iBox);
- MoveTo(iBox.right, iBox.top+2);
- LineTo(iBox.right, iBox.bottom);
- LineTo(iBox.left, iBox.bottom);
- MoveTo(iBox.left+kLeftSlop,iBox.bottom-kBotSlop);
- DrawString(CurText);
- } /* DrawPopup */
-
-
- #pragma segment Prefs
- pascal Boolean PrefsFilter(theDialog,theEvent,itemHit)
- DialogPtr theDialog;
- EventRecord *theEvent;
- short int *itemHit;
- {
-
- char key; /*for enter/return*/
- Point mouseLoc,popLoc;
- short newChoice;
- long chosen;
-
-
- SetPort(theDialog);
- switch (theEvent->what) /*which event?*/
- {
- case keyDown:
- case autoKey: /*she hit a key*/
- key = theEvent->message; /*get ascii code*/
- if ((key ==3) || (key == 13))
- { /*she hit CR or Enter*/
- *itemHit = 1; /*she hit the 1st item*/
- return(true); /*we handled it*/
- } else if (!isdigit(key)&&(isprint(key))) {
- theEvent->what = nullEvent;
- }
- break; /* case keydown, case autoKey */
- case mouseDown:
- mouseLoc=theEvent->where;
- GlobalToLocal(&mouseLoc);
- switch(FindDItem(theDialog,mouseLoc) + 1){
- case iFreqPop:
- InvertRect(&gFreqPromptRect);
- InsertMenu(gFreqPop,-1);
- popLoc = TopLeft(gFreqRect);
- LocalToGlobal(&popLoc);
- CalcMenuSize(gFreqPop);
- chosen = PopUpMenuSelect(gFreqPop,popLoc.v,popLoc.h, gLastFreq);
- InvertRect(&gFreqPromptRect);
- DeleteMenu(mFreqPop);
- if(chosen){
- newChoice = LoWord(chosen);
- if(newChoice != gLastFreq){
- SetItemMark(gFreqPop,gLastFreq,' ');
- SetItemMark(gFreqPop,newChoice,checkMark);
- gLastFreq = newChoice;
- EraseRect(&gFreqRect);
- DrawPopup(theDialog,iFreqPop);
- *itemHit = iFreqPop;
- return(true);
- }
- }
- break;
- case iOrderPop:
- InvertRect(&gOrderPromptRect);
- InsertMenu(gOrderPop,-1);
- popLoc = TopLeft(gOrderRect);
- LocalToGlobal(&popLoc);
- CalcMenuSize(gOrderPop);
- chosen = PopUpMenuSelect(gOrderPop,popLoc.v,popLoc.h, gLastOrder);
- InvertRect(&gOrderPromptRect);
- DeleteMenu(mOrderPop);
- if(chosen){
- newChoice = LoWord(chosen);
- if(newChoice != gLastOrder){
- SetItemMark(gOrderPop,gLastOrder,' ');
- SetItemMark(gOrderPop,newChoice,checkMark);
- gLastOrder = newChoice;
- EraseRect(&gOrderRect);
- DrawPopup(theDialog,iOrderPop);
- *itemHit = iOrderPop;
- return(true);
- }
- }
- break;
- }
- break;
- } /*event switch*/
- return(false); /* we╒re still here, so return false (we didn't handle the event) */
- } /*PrefsFilter*/
-
-
- #pragma segment Prefs
- void DoPrefs()
- {
- DialogPtr PrefsDialog;
- short item=0;
- Boolean changed=false;
- Boolean done=false;
- Handle itemHand;
- short itemType;
- Rect itemRect;
- short CtlVal;
- PrefHandle newPrefs=NewHandle(sizeof(Preferences));
- Str255 Text;
- int Value;
- int err;
- char errortxt[100];
-
- (**newPrefs)=(**gPrefs);
- MoveHHi((Handle)newPrefs);
- HLock((Handle)newPrefs);
-
-
- PrefsDialog = GetNewDialog(rPrefs,nil,(void *)-1);
- gFreqPop = GetMenu(mFreqPop);
- gOrderPop = GetMenu(mOrderPop);
- gLastFreq = Log2((*newPrefs)->pMaxCount);
-
- gLastOrder = (*newPrefs)->pOrder - 1;
-
- SetItemMark(gFreqPop, gLastFreq, checkMark);
- SetItemMark(gOrderPop, gLastOrder, checkMark);
-
- GetDItem(PrefsDialog,iUserItem,&itemType,&itemHand,&itemRect);
- SetDItem(PrefsDialog,iUserItem,itemType,(Handle)DrawRndRect,&itemRect); /*install draw proc*/
-
- GetDItem(PrefsDialog,iFreqPop,&itemType,&itemHand,&gFreqRect);
- SetDItem(PrefsDialog,iFreqPop,itemType,(Handle)DrawPopup,&gFreqRect); /*install draw proc*/
-
- GetDItem(PrefsDialog,iOrderPop,&itemType,&itemHand,&gOrderRect);
- SetDItem(PrefsDialog,iOrderPop,itemType,(Handle)DrawPopup,&gOrderRect); /*install draw proc*/
-
- GetDItem(PrefsDialog,iFreqPrompt,&itemType,&itemHand,&gFreqPromptRect);
-
- GetDItem(PrefsDialog,iOrderPrompt,&itemType,&itemHand,&gOrderPromptRect);
-
- GetDItem(PrefsDialog,iStartUpEdit,&itemType,&itemHand,&itemRect);
- SelIText(PrefsDialog,iStartUpEdit,0,32767);
-
- ShowWindow(PrefsDialog); /*make it visible*/
-
- SetPort(PrefsDialog);
- while(!done){
- GetDItem(PrefsDialog,iStopAtCRBox,&itemType,&itemHand,&itemRect);
- SetCtlValue((ControlHandle)itemHand,(*newPrefs)->pstopAtCR);
- GetDItem(PrefsDialog,iShowSpcTabBox,&itemType,&itemHand,&itemRect);
- SetCtlValue((ControlHandle)itemHand,(*newPrefs)->pshowSpecial);
- GetDItem(PrefsDialog,iStartUpEdit,&itemType,&itemHand,&itemRect);
- NumToString((*newPrefs)->pStartup,Text);
- SetIText(itemHand,Text);
- SelIText(PrefsDialog,iStartUpEdit,0,32767);
- item=0;
- while((item!=iOk) && (item != iCancel)){
- ModalDialog(PrefsFilter,&item);
- GetDItem(PrefsDialog,item,&itemType,&itemHand,&itemRect);
- switch(item){
- case iStopAtCRBox:
- CtlVal=GetCtlValue((ControlHandle)itemHand);
- SetCtlValue((ControlHandle)itemHand,!CtlVal);
- (*newPrefs)->pstopAtCR = !CtlVal;
- break;
- case iShowSpcTabBox:
- CtlVal=GetCtlValue((ControlHandle)itemHand);
- SetCtlValue((ControlHandle)itemHand,!CtlVal);
- (*newPrefs)->pshowSpecial = !CtlVal;
- break;
-
- case iPrimeButton:
- if(GetPrimeFile(true,newPrefs) || ((*newPrefs)->pHasPrime != (*gPrefs)->pHasPrime))
- changed=true;
- break;
- case iZeroButton:
- if(GetPrimeFile(false,newPrefs) || ((*newPrefs)->pHasZero != (*gPrefs)->pHasZero))
- changed=true;
- break;
- case iFreqPop:
- case iOrderPop:
- break;
- case iStartUpEdit:
- changed=true;
- break;
- }
- }
-
- if(item==iOk){
- done=true;
- GetDItem(PrefsDialog,iStartUpEdit,&itemType,&itemHand,&itemRect);
- GetIText(itemHand, Text);
- StringToNum(Text,&Value);
- if(Value>=0) {
- (*newPrefs)->pStartup=Value;
- }else {
- (*newPrefs)->pStartup=0;
- ParamText(Text,"\p0","\p░",nil);
- if(done) Alert(rOutOfRange,nil);
- done=false;
- }
- if((*newPrefs)->pMaxCount !=1<<gLastFreq) changed = true;
- (*newPrefs)->pMaxCount = 1<<gLastFreq;
- if((*newPrefs)->pOrder != gLastOrder+1) changed = true;
- (*newPrefs)->pOrder = gLastOrder+1;
-
- if(done && changed)
- Alert(rPrefChanges,nil);
- if(done){
- (**gPrefs)=(**newPrefs);
- }
- }
- if(item==iCancel){
- done=true;
- }
- }
- HUnlock((Handle)newPrefs);
- DisposHandle((Handle)newPrefs);
- DisposDialog(PrefsDialog);
- DisposeMenu(gFreqPop);
- DisposeMenu(gOrderPop);
- ChangedResource((Handle)gPrefs);
- if((err=ResError())!=noErr){
- sprintf(errortxt,"Resource Manager Error(ChangeRes): %d",err);
- abortit(errortxt);
- }
- WriteResource((Handle)gPrefs);
- if((err=ResError())!=noErr){
- sprintf(errortxt,"Resource Manager Error(WriteRes): %d",err);
- abortit(errortxt);
- }
- if(IsAppWindow(FrontWindow())){
- DrawNewPredictions();
- }
- }
-
- #pragma segment Prefs
- void GetPrefs()
- {
- short OldVol;
- int PrefFile;
- int err;
- char errortxt[100];
- Str255 PrefName,OldName;
- GetIndString(&PrefName, rNameStrings, iPrefsName);
- GetVol(&OldName,&OldVol);
- if(SetVol(nil,gMac.sysVRefNum))
- DebugStr("\p SetVol to System Folder failed.");
- if((PrefFile=OpenResFile(PrefName))==-1){
- CreateResFile(PrefName);
- if((PrefFile=OpenResFile(PrefName)) == -1){
- gPrefs = (PrefHandle) NewHandle(sizeof(Preferences));
- SetUpDefaults();
- return;
- }
- UseResFile(PrefFile);
- gPrefs = (PrefHandle) NewHandle(sizeof(Preferences));
- SetUpDefaults();
- AddResource((Handle)gPrefs,rPrefType,rPrefID,PrefName);
- if((err=ResError())!=noErr){
- sprintf(errortxt,"Resource Manager Error(AddRes1): %d",err);
- abortit(errortxt);
- }
- UpdateResFile(PrefFile);
- }else{
- UseResFile(PrefFile);
- if((gPrefs = (PrefHandle) GetResource(rPrefType,rPrefID))==0){
- gPrefs = (PrefHandle) NewHandle(sizeof(Preferences));
- SetUpDefaults();
- AddResource((Handle)gPrefs,rPrefType,rPrefID,PrefName);
- if((err=ResError())!=noErr){
- sprintf(errortxt,"Resource Manager Error(AddRes2): %d",err);
- abortit(errortxt);
- }
- UpdateResFile(PrefFile);
- }
- }
- SetVol(nil,OldVol);
- gStartPrefs = (PrefHandle) NewHandle(sizeof(Preferences));
- (**gStartPrefs)=(**gPrefs);
- MoveHHi((Handle)gStartPrefs);
- HLock((Handle)gStartPrefs);
-
- }
-
- #pragma segment Prefs
-
- SetUpDefaults()
- {
- (*gPrefs)->pshowSpecial=true;
- (*gPrefs)->pstopAtCR=true;
- (*gPrefs)->pMaxCount=128;
- (*gPrefs)->pOrder=8;
- (*gPrefs)->pHasPrime=false;
- (*gPrefs)->pStartup=32000;
- (*gPrefs)->pHasZero=false;
- (*gPrefs)->pShowPredInBuffer=true;
- }
-
-
- pascal void DrawHelp(theDialog,theItem)
- DialogPtr theDialog;
- short int theItem;
-
- {
- short int iType;
- Rect iBox;
- Handle iHdl;
-
- GetDItem(theDialog,theItem,&iType,&iHdl,&iBox);
- MoveTo((iBox.right-iBox.left)/2-(StringWidth("\pPut Help Here")/2),
- (iBox.bottom-iBox.top)/2);
- DrawString("\pPut Help Here");
-
-
- FrameRect(&iBox);
- } /*DrawHelp*/
-
- pascal Boolean HelpFilter(theDialog,theEvent,itemHit)
- DialogPtr theDialog;
- EventRecord *theEvent;
- short int *itemHit;
-
- {
- char key; /*for enter/return*/
- short int iType; /*returned item type*/
- Rect iBox; /*returned boundsrect*/
- Handle iHdl; /*returned item handle*/
- Point mouseLoc; /*we'll play w/ mouse*/
-
- SetPort(theDialog);
- switch (theEvent->what) /*which event?*/
- {
- case keyDown:
- case autoKey: /*he hit a key*/
- key = theEvent->message; /*get ascii code*/
- if ((key ==3) || (key == 13))
- { /*he hit CR or Enter*/
- *itemHit = 1; /*he hit the 1st item*/
- return(true); /*we handled it*/
- } /*he hit CR or enter*/
- break; /* case keydown, case autoKey */
- case mouseDown: /*he clicked*/
- mouseLoc = theEvent->where; /*get the mouse pos'n*/
- GlobalToLocal(&mouseLoc); /*convert to local*/
- GetDItem(theDialog,2,&iType,&iHdl,&iBox); /*get our box*/
- if (PtInRect(mouseLoc,&iBox))
- { /*he hit our item*/
- InvertRect(&iBox);
- *itemHit = 2; /*he hit the userItem*/
- return(true); /*we handled it*/
- } /*if he hit our userItem*/
- break; /*case mouseDown */
- } /*event switch*/
- return(false); /* we╒re still here, so return false (we didn't
- handle the event) */
- } /*HelpFilter*/
-
-
-