XmTEXT_FORWARD, &pos);
if (found) {
nfound++;
if (reason == SEARCH_SHOW_ALL)
XmTextSetHighlight (text_edit, pos, pos + search_len,
XmHIGHLIGHT_SELECTED);
else
XmTextReplace (text_edit, pos, pos + search_len, new_pat);
pos++;
}
}
while (found);
}
if (nfound == 0) {
XmTextSetString (text_output, "Pattern not found");
} else {
switch (reason) {
case SEARCH_FIND_NEXT :
sprintf (buf, "Pattern found at position %ld.", pos);
XmTextSetInsertionPosition (text_edit, pos);
break;
case SEARCH_SHOW_ALL :
sprintf (buf, "Found %d occurrences.", nfound);
break;
case SEARCH_REPLACE :
sprintf (buf, "Made %d replacements.", nfound);
}
XmTextSetString (text_output, buf);
}
XtFree (string);
XtFree (search_pat);
XtFree (new_pat);
}
/* the callback routine for the items in the edit menu */
void
edit_cb (widget, client_data, call_data)
Widget widget;
XtPointer client_data;
XtPointer call_data;
{
Boolean result = True;
EditOp reason = *((EditOp *) client_data);
XEvent *event = ((XmPushButtonCallbackStruct *) call_data)−>event;
Time when;
XmTextSetString (text_output, NULL); /* clear the message area */
if (event != NULL &&
reason == EDIT_CUT || reason == EDIT_COPY || reason == EDIT_CLEAR) {
switch (event−>type) {
case ButtonRelease :
when = event−>xbutton.time;
break;
case KeyRelease :
when = event−>xkey.time;
break;
default:
when = CurrentTime;
break;
26 Building an Application With UIL 26.2 Creating the Application
713