// findwind.c // // This file implements the "Find..." window's menus, controls and events. // // by John D. de Boer #include "twist.h" #include "twindow.h" extern GlobalOpts Opt; extern void *Sel,*Was; extern int FINDS,FOUNDHEIGHT; //extern IBNibRef Nib; int FIT, // the number of finds that fit vertically into the pane VSCR; // the top find visible window *FindWind; // the "Find" window rect FoundPane, // the area containing the found list TopPane, // the area on top of FoundPane EditBox, // where the edit text appears LegendBox; // where the text with the currently found text goes ControlRef EditField, // the edit-text field FindButton; // the "Find" button static ControlRef RootCtl; static rect VScrRect, // the vertical scroll bar's area ButtonRect; // the "Find" button's area static Rect QDEditBox, QDVScrRect, QDButtonRect; //static string Title; // window title from resource // static void FindAction(void) { char *S; S=NULL; getedittext(EditField,&S); if (!S) return; Find(S); redraw(FindWind); } // Menus for the infomation window static void InitFindMenus(void) { } static void SetUpFindMenus(void) { SetUpFileMenu(); SetUpWindowMenu(); } static void AdjustFindMenus(window *W) { AdjustFileMenu(W); } static bool FindCommand(window *W, UInt32 C) { return FileCommand(W,C); } // Contextual Menus static bool FindPopup(window *W, point Pt) { if (!Sel) return 0; if (VoidIsPers(Sel)) return PersonPopup(W,Pt,1,1,1,1,Sel); if (VoidIsEvent(Sel)) return EventPopup(W,Pt,1,1,1,Sel); return 0; } // Controls static int EXTRA; // the number that don't fit into the pane static ControlActionUPP FindUPP, // control action procedure for vertical scroll bar ButtonUPP; // control action procedure for action button static void CalcFindFit(void) { FIT= height(FoundPane) / FOUNDHEIGHT; EXTRA=gtr(0,FINDS - FIT); } static pascal void findscroll(ControlRef C, short PART) { int INCR,OLD; window *W; if (!C) return; W=controlswindow(C); if (!W) return; CalcFindFit(); if (PART==kControlIndicatorPart) { OLD=VSCR; VSCR=GetControlValue(C); if (VSCR!=OLD) redraw(W); return; } INCR=partincrement(PART,1,FIT - 1); OLD=VSCR; VSCR=between(VSCR + INCR,0,EXTRA); if (VSCR==OLD) return; SetControlValue(C,VSCR); redraw(W); } static pascal void findbutton(ControlRef C, short PART) { window *W; if (!C) return; W=controlswindow(C); if (!W) return; FindAction(); redraw(W); } void SetFindScroll(void) { CalcFindFit(); VSCR=0; // between(VSCR,0,EXTRA); setscrollbar(FindWind->vsb,VSCR,0,EXTRA); } static void InitFindControls(window *W) { OSStatus err; if (!W || !W->wmw) return; VSCR=0; FindUPP=NewControlActionUPP(&findscroll); givevertscroll(W); SetControlAction(W->vsb,FindUPP); resizecontrol(W->vsb,&QDVScrRect); err=CreatePushButtonControl(W->wmw,&QDButtonRect,CFSTR("Find"),&FindButton); err=EmbedControl(FindButton,RootCtl); ButtonUPP=NewControlActionUPP(&findbutton); SetControlAction(FindButton,ButtonUPP); //err=SetControlCommandID(FindButton,'twfd'); //err=CreateEditTextControl(W->wmw,&QDEditBox,NULL,0,0,NULL,&EditField); err=CreateEditUnicodeTextControl(W->wmw,&QDEditBox,NULL,0,NULL,&EditField); err=EmbedControl(EditField,RootCtl); } // Window events static bool FindContent(mouseclick *M) { long CONTEXTTIME; if (!M) return 0; //if (pointinrect(M->point,EditBox)) return 0; if (!pointinrect(M->point,FoundPane)) return 0; CONTEXTTIME= TickCount() + GetDblTime(); Was=Sel; Sel=FindHit(M); if (M->right && Sel) { if (Sel==Was) redraw(M->wind); else RedisplayAll(); return FindPopup(M->wind,M->point); } //if (M->cmnd) { if (Sel) SwitchToInfo(); else if (Was) RedisplayAll(); return 1; } if (Sel!=Was) RedisplayAll(); while (stilldown(M)) if (Sel && TickCount()>CONTEXTTIME) return FindPopup(M->wind,M->point); return 1; } /* static bool FindDouble(mouseclick *M) { if (!M) return 0; Was=Sel; Sel=FindHit(M); if (Sel && Sel==Was) { SwitchToTimeLine(); return 1; } return FindContent(M); }*/ /* static void SelectAll(ControlRef C) { OSErr err; Size SIZE; ControlEditTextSelectionRec Sel; if (!C) return; err=GetControlDataSize(EditField,kControlEntireControl,kControlEditTextTextTag,&SIZE); if (SIZE<1) return; Sel.selStart=0; Sel.selEnd=SIZE; err=SetControlData(C,kControlEntireControl,kControlEditTextSelectionTag,sizeof(Sel),&Sel); }*/ static bool FindKey(keystroke *K) { if (!K) return 0; if (K->c==3 || linebreak(K->c)) { FindAction(); return 1; } return 0; } void BringFindToFront(void) { //SelectAll(EditField); revealwindow(FindWind); } // Initialisation static void oldrect(window *W, rect R, Rect *Q) { if (!W || !Q) return; SetRect(Q,left(R),top(W->page) - top(R),right(R),top(W->page) - bottom(R)); } static void InitFindRects(window *W) { if (!W) return; FoundPane=W->page; settop(&FoundPane,top(W->page) - 65); VScrRect=FoundPane; setleft(&VScrRect,right(VScrRect) - W->thickness); setright(&FoundPane,left(VScrRect)); TopPane=W->page; setbottom(&TopPane,top(FoundPane)); setright(&TopPane,left(VScrRect)); ButtonRect=TopPane; inset(&ButtonRect,13); setleft(&ButtonRect,right(ButtonRect) - 70); setbottom(&ButtonRect,top(ButtonRect) - 20); setrect(&EditBox,45,top(TopPane) - 33,100,19); setright(&EditBox,left(ButtonRect) - 15); setrect(&LegendBox,45,top(TopPane) - 63,100,10); setright(&LegendBox,left(ButtonRect) - 15); oldrect(W,EditBox,&QDEditBox); oldrect(W,VScrRect,&QDVScrRect); oldrect(W,ButtonRect,&QDButtonRect); } void InitFindWindow(void) { OSErr err; InitFindMenus(); InitFindInfo(); //Title=resstring(204); FindWind=customwindow("Find",400,65 + (12 * FOUNDHEIGHT),0); //err=GetRootControl(FindWind->wmw,&RootCtl); if (err) halt(fig(err)); // gives err err=CreateRootControl(FindWind->wmw,&RootCtl); InitFindRects(FindWind); InitFindControls(FindWind); installmenus(FindWind,NULL,&SetUpFindMenus,&AdjustFindMenus,&FindCommand); installpaint(FindWind,&DrawFind); installclick(FindWind,&FindContent,&concealwindow,&DrawFind); //installdouble(FindWind,&FindDouble); installkey(FindWind,&FindKey); }