📄 find.c
字号:
/************************************************************************* **** find.c **** **** Text Editor -- "Find" Dialog Module **** *************************************************************************/#include <string.h>#include <Xm/BulletinB.h>#include <Xm/MessageB.h>#include <Xm/Label.h>#include <Xm/PushB.h>#include <Xm/Separator.h>#include <Xm/Text.h>#include "textedit.h"/************************************************************************* **** F O R W A R D D E F I N I T I O N S **** *************************************************************************/static void FindCB();static void FindCanCB();/************************************************************************* **** L O C A L V A R I A B L E S **** *************************************************************************/static Widget find_db, /* The dialog box */ find_lbl, /* Label: "Find:" */ find_txt, /* Find-string Entry Field */ find_sep, /* Sep between pres & conf */ find_btn_1, /* Action pushbutton */ find_btn_2, /* Go-away pushbutton */ cantfind_db; /* "Can't Find" Alert */static XmString find_str, /* XmString for "Find" */ can_str, /* XmString for "Cancel" */ next_str, /* XmString for "Next" */ done_str; /* XmString for "Done" */static int finding; /* Flag for FindCB() *//************************************************************************* **** InitFindDB() **** **** Creates the "Find" dialog box, which is controlled by the **** Edit/Find... pull-down menu choice. **** **** Modifies the global variable "find_db", and local variables **** "find_txt", "find_ok_btn", and "find_nxt_btn". **** *************************************************************************/void InitFindDB(){ Widget temp; find_db = XmCreateBulletinBoardDialog( mainwin, "FindDB", NULL, 0 ); find_lbl = XmCreateLabel( find_db, "Find_Lbl", NULL, 0 ); XtManageChild( find_lbl ); find_txt = XmCreateText( find_db, "Find_Txt", NULL, 0 ); XtManageChild( find_txt ); find_sep = XmCreateSeparator( find_db, "Find_Sep", NULL, 0 ); XtManageChild( find_sep ); find_btn_1 = XmCreatePushButton( find_db, "Find_Btn1", NULL, 0 ); XtManageChild( find_btn_1 ); find_btn_2 = XmCreatePushButton( find_db, "Find_Btn2", NULL, 0 ); XtManageChild( find_btn_2 ); XtAddCallback( find_btn_1, XmNactivateCallback, FindCB, NULL ); XtAddCallback( find_btn_2, XmNactivateCallback, FindCanCB, NULL ); XtSetArg( arglist[0], XmNdefaultButton, find_btn_1 ); XtSetValues( find_db, arglist, 1 ); find_str = XmStringCreate( "Find", XmSTRING_DEFAULT_CHARSET ); can_str = XmStringCreate( "Cancel", XmSTRING_DEFAULT_CHARSET ); next_str = XmStringCreate( "Next", XmSTRING_DEFAULT_CHARSET ); done_str = XmStringCreate( "Done", XmSTRING_DEFAULT_CHARSET ); cantfind_db = XmCreateMessageDialog( mainwin, "CantFind", NULL, 0 ); temp = XmMessageBoxGetChild( cantfind_db, XmDIALOG_CANCEL_BUTTON ); XtUnmanageChild( temp ); temp = XmMessageBoxGetChild( cantfind_db, XmDIALOG_HELP_BUTTON ); XtUnmanageChild( temp );}/************************************************************************* **** ManageFindDB() **** **** Called when the dialog box is first presented, this function **** manages the DB and sets the labels of its buttons to "Find" **** and "Cancel". It also sets the "finding" flag FALSE, for the **** first call to FindCB. **** *************************************************************************/void ManageFindDB(){ XtManageChild( find_db ); _XmGrabTheFocus( find_txt ); XtSetArg( arglist[0], XmNlabelString, find_str ); XtSetValues( find_btn_1, arglist, 1 ); XtSetArg( arglist[0], XmNlabelString, can_str ); XtSetValues( find_btn_2, arglist, 1 ); finding = FALSE;}/************************************************************************* **** FindCB( w, client_data, call_data ) **** **** Called from the "Find" or "Next" buttons of the Find DB. This **** function searches for the first/next occurrence of the search **** string. The "client_data" param points to a string -- "Fnd" or **** "Nxt" -- which indicates which button this is called from; it **** must initialize its local variables for the first call. **** **** In operation, this function searches for the next occurrence of **** the target string in the text buffer, and selects it. **** *************************************************************************/static void FindCB( w, client_data, call_data ) Widget w; char *client_data; XmAnyCallbackStruct *call_data;{ static int curpos; char *findstr, *txtbuf, *txtptr; int start, end; if (!finding) { finding = TRUE; curpos = 0; XtSetArg( arglist[0], XmNlabelString, next_str ); XtSetValues( find_btn_1, arglist, 1 ); XtSetArg( arglist[0], XmNlabelString, done_str ); XtSetValues( find_btn_2, arglist, 1 ); } findstr = XmTextGetString( find_txt ); txtbuf = XmTextGetString( textwin ); txtptr = StrFind( (txtbuf + curpos), findstr ); if (txtptr == NULL) { XtUnmanageChild( find_db ); XtManageChild( cantfind_db ); } else { start = txtptr - txtbuf; end = start + strlen(findstr); XtSetArg( arglist[0], XmNcursorPosition, end ); XtSetValues( textwin, arglist, 1 ); XmTextSetSelection( textwin, start, end, call_data->event->xbutton.time ); curpos = start + 1; } XtFree( txtbuf ); XtFree( findstr );}/************************************************************************* **** FindCanCB( w, client_data, call_data ) **** **** Called from the "Cancel" or "OK" buttons of the Find DB. This **** simply unmanages the DB. **** *************************************************************************/static void FindCanCB( w, client_data, call_data ) Widget w; char *client_data; XmAnyCallbackStruct *call_data;{ XtUnmanageChild( find_db );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -