⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editor.c

📁 `smith.motif.tar.Z includes the source code for the book "Designing X clients with Xt/Motif," by Je
💻 C
📖 第 1 页 / 共 2 页
字号:
Widget editor_menuCopyButton(eObject)		/* maintain consistent interface */Editor eObject;{	return edit_menu[1].id;}	/* editor_menuCopyButton *//*ARGSUSED*/Widget editor_menuPasteButton(eObject)		/* maintain consistent interface */Editor eObject;{	return edit_menu[2].id;}	/* editor_menuPasteButton *//*ARGSUSED*/Widget editor_menuSearchButton(eObject)		/* maintain consistent interface */Editor eObject;{	return find_menu[0].id;}	/* editor_menuSearchButton *//*ARGSUSED*/Widget editor_menuReplaceButton(eObject)	/* maintain consistent interface */Editor eObject;{	return find_menu[1].id;}	/* editor_menuReplaceButton */Widget editor_editWindow(eObject)Editor eObject;{	return eObject->editWindow;}	/* editor_editWindow */Widget editor_edit(eObject)Editor eObject;{	return eObject->edit;}	/* editor_edit */Widget editor_replaceShell(eObject)Editor eObject;{	return eObject->replaceShell;}	/* editor_replaceShell */Widget editor_replaceInstance(eObject)Editor eObject;{	return eObject->replaceInstance;}	/* editor_replaceInstance */Widget editor_replaceClass(eObject)Editor eObject;{	return eObject->replaceClass;}	/* editor_replaceClass */Widget editor_replacePane(eObject)Editor eObject;{	return eObject->replacePane;}	/* editor_replacePane */Widget editor_replaceBox(eObject)Editor eObject;{	return eObject->replaceBox;}	/* editor_replaceBox */Widget editor_replaceLabel(eObject)Editor eObject;{	return eObject->replaceLabel;}	/* editor_replaceLabel */Widget editor_replaceFindBox(eObject)Editor eObject;{	return eObject->replaceFindBox;}	/* editor_replaceFindBox */Widget editor_replaceReplaceBox(eObject)Editor eObject;{	return eObject->replaceReplaceBox;}	/* editor_replaceReplaceBox */Widget editor_replaceFindLabel(eObject)Editor eObject;{	return eObject->replaceFindLabel;}	/* editor_replaceFindLabel */Widget editor_replaceReplaceLabel(eObject)Editor eObject;{	return eObject->replaceReplaceLabel;}	/* editor_replaceReplaceLabel */Widget editor_replaceFindText(eObject)Editor eObject;{	return eObject->replaceFindText;}	/* editor_replaceFindText */Widget editor_replaceReplaceText(eObject)Editor eObject;{	return eObject->replaceReplaceText;}	/* editor_replaceReplaceText */Widget editor_replaceButtonBox(eObject)Editor eObject;{	return eObject->replaceButtonBox;}	/* editor_replaceButtonBox */Widget editor_replaceFindButton(eObject)Editor eObject;{	return eObject->replaceFindButton;}	/* editor_replaceFindButton */Widget editor_replaceReplaceButton(eObject)Editor eObject;{	return eObject->replaceReplaceButton;}	/* editor_replaceReplaceButton */Widget editor_replaceDismissButton(eObject)Editor eObject;{	return eObject->replaceDismissButton;}	/* editor_replaceDismissButton */#endif /* WIDGET_ACCESS *//*Private callback functions:*//*CutText() is a private callback for the "Cut" function.*//*ARGSUSED*/static void CutText(w, client_data, call_data)Widget w;XtPointer client_data;XmAnyCallbackStruct *call_data;{	Editor eObject = (Editor) client_data;#ifdef MANUAL_CLIP	if (selection_to_clipboard(eObject,			call_data->event->xbutton.time))		XmTextRemove(eObject->edit);#else/*********************************************************This function still has errors in certain Motif 1.1's.*********************************************************/	XmTextCut(eObject->edit, call_data->event->xbutton.time);#endif MANUAL_CLIP}	/* CutText *//*CopyText() is a private callback for the "Copy" function.*//*ARGSUSED*/static void CopyText(w, client_data, call_data)Widget w;XtPointer client_data;XmAnyCallbackStruct *call_data;{	Editor eObject = (Editor) client_data;#ifdef MANUAL_CLIP	if (!selection_to_clipboard(eObject, call_data->event->xbutton.time))		;										/* silent, at present */#else/*********************************************************This function still has errors in certain Motif 1.1's.*********************************************************/	XmTextCopy(eObject->edit, call_data->event->xbutton.time);#endif MANUAL_CLIP}	/* CopyText *//*PasteText() is a private callback for the "Paste" function.*//*ARGSUSED*/static void PasteText(w, client_data, call_data)Widget w;XtPointer client_data;XmAnyCallbackStruct *call_data;{	Editor eObject = (Editor) client_data;	char *buffer;#ifdef MANUAL_CLIP	if ((buffer = retrieve_from_clipboard(eObject)) != NULL) {		XmTextPosition cur_pos = get_text_cursor_position(eObject);		XmTextReplace(eObject->edit, cur_pos, cur_pos, buffer);		XtFree(buffer);	}#else/*********************************************************This function still has errors in certain Motif 1.1's.*********************************************************/	XmTextPaste(eObject->edit);#endif MANUAL_CLIP}	/* PasteText *//*ClearText() is a private callback for the "Clear" function.It clears the clipboard, not the primary selection.*//*ARGSUSED*/static void ClearText(w, client_data, call_data)Widget w;XtPointer client_data;XmAnyCallbackStruct *call_data;{	Editor eObject = (Editor) client_data;	long item_id;	int data_id;	char *buffer = "";	/* null string */	XmString clip_label = XmStringCreateSimple(eObject->app_name);	while (XmClipboardStartCopy(XtDisplay(eObject->edit),			XtWindow(eObject->edit), clip_label,			call_data->event->xbutton.time,			eObject->edit, NULL, &item_id) != ClipboardSuccess)		;	while (XmClipboardCopy(XtDisplay(eObject->edit),			XtWindow(eObject->edit), item_id, "STRING", buffer,			(unsigned long) (strlen(buffer)),			0, &data_id) != ClipboardSuccess)		;	while (XmClipboardEndCopy(XtDisplay(eObject->edit),			XtWindow(eObject->edit), item_id) != ClipboardSuccess)		;	XmStringFree(clip_label);/************************************************************************Clearing the selection, not the clipboard would be another possibility:	XmTextClearSelection(eObject->edit, call_data->event->xbutton.time);************************************************************************/}	/* ClearText *//*FindSelection() is a private callback for the"Find Selection" operation.*//*ARGSUSED*/static void FindSelection(w, client_data, call_data)Widget w;XtPointer client_data;XmAnyCallbackStruct *call_data;{	Editor eObject = (Editor) client_data;	char *buffer, *selection;	if ((selection = XmTextGetSelection(eObject->edit)) == NULL)		return;	if ((buffer = XmTextGetString(eObject->edit)) != NULL) {		XmTextPosition cur_pos = get_text_cursor_position(eObject);		Arg arg;		cur_pos++;	/* don't want to find the same text if the		*/					/* cursor is at the beginning of the selection	*/		cur_pos = (XmTextPosition) string_search(buffer,			selection, (int) cur_pos);		if (cur_pos != string_NO_MATCH) {			XmTextSetSelection(eObject->edit, cur_pos,				cur_pos + (XmTextPosition) strlen(selection),				call_data->event->xbutton.time);			XtSetArg(arg, XmNcursorPosition, cur_pos);			XtSetValues(eObject->edit, &arg, 1);		}		XtFree(buffer);	}	XtFree(selection);}	/* FindSelection *//*ReplaceText() is a private callback that mapsthe search and replace window.*//*ARGSUSED*/static void ReplaceText(w, client_data, call_data)Widget w;XtPointer client_data;XmAnyCallbackStruct *call_data;{	Editor eObject = (Editor) client_data;	if (!XtIsRealized(eObject->replaceShell))		return;	XtMapWidget(eObject->replaceShell);}	/* ReplaceText *//*ReplaceDismiss() is a private callback that removesthe search and replace window.*//*ARGSUSED*/static void ReplaceDismiss(w, client_data, call_data)Widget w;XtPointer client_data;XmAnyCallbackStruct *call_data;{	Editor eObject = (Editor) client_data;	XtUnmapWidget(eObject->replaceShell);}	/* ReplaceDismiss *//*ReplaceFind() is a private callback for the "Find" button in the searchand replace button that finds the next occurrence of the text.*//*ARGSUSED*/static void ReplaceFind(w, client_data, call_data)Widget w;XtPointer client_data;XmAnyCallbackStruct *call_data;{	Editor eObject = (Editor) client_data;	char *buffer, *search_text;	if ((search_text = XmTextGetString(eObject->replaceFindText)) == NULL)		return;	if ((buffer = XmTextGetString(eObject->edit)) != NULL) {		XmTextPosition cur_pos = get_text_cursor_position(eObject);		Arg arg;		cur_pos++; /* don't find the "current" text again */		cur_pos = (XmTextPosition) string_search(buffer,			search_text, (int) cur_pos);		if (cur_pos != (XmTextPosition) string_NO_MATCH) {			XmTextSetSelection(eObject->edit, cur_pos,				cur_pos + (XmTextPosition) strlen(search_text),				call_data->event->xbutton.time);			XtSetArg(arg, XmNcursorPosition, cur_pos);			XtSetValues(eObject->edit, &arg, 1);		}		XtFree(buffer);	}	XtFree(search_text);}	/* ReplaceFind *//*ReplaceReplace() is a private callback that replaces themost recently "found" text.*//*ARGSUSED*/static void ReplaceReplace(w, client_data, call_data)Widget w;XtPointer client_data;XmAnyCallbackStruct *call_data;{	Editor eObject = (Editor) client_data;	char *replace_text;	XmTextPosition cur_pos;	if (!XmTextRemove(eObject->edit))		return;				/* policy:  return silently */	if ((replace_text = XmTextGetString(eObject->replaceReplaceText)) == NULL)		replace_text = "";	/* don't trust Motif to return "" */	cur_pos = get_text_cursor_position(eObject);	XmTextReplace(eObject->edit, cur_pos, cur_pos, replace_text);	XtFree(replace_text);}	/* ReplaceFind *//*Private event handlers:*//*PostMenu() invokes the pop-up menu.*//*ARGSUSED*/static void PostMenu(w, menu, event)Widget w;Widget menu;XEvent *event;{	if (event->type != ButtonPress)		/* paranoia */		return;	XmMenuPosition(menu, (XButtonPressedEvent *) event);	XtManageChild(menu);}	/* PostMenu *//*Private support functions:*//*get_text_cursor_position() returns the current text position.*/static XmTextPosition get_text_cursor_position(eObject)Editor eObject;{	XmTextPosition cur_pos;	Arg arg;	XtSetArg(arg, XmNcursorPosition, &cur_pos);	XtGetValues(eObject->edit, &arg, 1);	return cur_pos;}	/* get_text_cursor_position */#ifdef MANUAL_CLIP/*selection_to_clipboard() copies the current selection tothe clipboard.*/static int selection_to_clipboard(eObject, time_stamp)Editor eObject;Time time_stamp;{	char *selection;	long item_id;	int data_id;	Display *dpy = XtDisplay(eObject->edit);	Window win = XtWindow(eObject->edit);	XmString clip_label = XmStringCreateSimple(eObject->app_name);	if ((selection = XmTextGetSelection(eObject->edit)) == NULL)		return False;	while (XmClipboardStartCopy(dpy, win, clip_label, time_stamp,			eObject->edit, NULL, &item_id) != ClipboardSuccess)		;	while (XmClipboardCopy(dpy, win, item_id, "STRING", selection,			(unsigned long) strlen(selection),			0, &data_id) != ClipboardSuccess)		;	while (XmClipboardEndCopy(dpy, win, item_id) != ClipboardSuccess)		;	XmStringFree(clip_label);	return True;}	/* selection_to_clipboard *//*retrieve_from_clipboard() gets the text from the clipboard,stores it in an internal buffer, and then returns a pointerto the text.  The CALLER must free the buffer, beforecalling this function a second time.*/static char *retrieve_from_clipboard(eObject)Editor eObject;{	char *buffer;	unsigned long buf_len, num_bytes;	int attempts, status;	Display *dpy = XtDisplay(eObject->edit);	Window win = XtWindow(eObject->edit);	for (attempts = 0;			attempts < 3 &&			(status = XmClipboardInquireLength(dpy, win, "STRING", &buf_len))				== ClipboardLocked;			attempts++)		;	if (buf_len == 0 || status != ClipboardSuccess)		return NULL;	if ((buffer = XtMalloc((Cardinal) (buf_len + 2))) == NULL)		return NULL;	/* return silently */	while ((status = XmClipboardRetrieve(dpy, win, "STRING", buffer,			(unsigned long) (buf_len + 1), &num_bytes, NULL))			== ClipboardLocked)		;	if (status == ClipboardSuccess && num_bytes == buf_len) {		buffer[num_bytes] = '\0';		return buffer;	}	else {		XtFree(buffer);		return NULL;	}}	/* retrieve_from_clipboard */#endif MANUAL_CLIP

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -