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

📄 dialogf.c

📁 nedit 是一款linux下的开发源码的功能强大的编辑器
💻 C
📖 第 1 页 / 共 2 页
字号:
         /* Also add a callback to detect unexpected destruction (eg, because           the parent window is destroyed) */        XtAddCallback(dialog, XmNdestroyCallback,             (XtCallbackProc)destroy_callback, &df);	/* A previous call to SetDialogFPromptHistory can request that an	   up-arrow history-recall mechanism be attached.  If so, do it here */	if (NPromptHistoryItems != -1)	    AddHistoryToTextWidget(XmSelectionBoxGetChild(dialog,XmDIALOG_TEXT),		    &PromptHistory, &NPromptHistoryItems);	    	/* Pop up the dialog */	ManageDialogCenteredOnPointer(dialog);		/* Get the focus to the input string.  There is some timing problem	   within Motif that requires this to be called several times */	for (i=0; i<20; i++)	    XmProcessTraversal(XmSelectionBoxGetChild(dialog, XmDIALOG_TEXT),		    XmTRAVERSE_CURRENT);		/* Wait for a response to the dialog */	while (!df.done_with_dialog && !df.destroyed)	    XtAppProcessEvent (XtWidgetToApplicationContext(dialog), XtIMAll);                if (!df.destroyed) {	    argcount = 0; /* Pass back string user entered */	    XtSetArg (args[argcount], XmNtextString, &input_string_xms); argcount++;	    XtGetValues (dialog, args, argcount);	    XmStringGetLtoR (input_string_xms, XmSTRING_DEFAULT_CHARSET,		&input_string_ptr);	    strcpy (input_string, input_string_ptr);  /* This step is necessary */	    XmStringFree(input_string_xms );            XtFree(input_string_ptr);             /* Important! Only intercept unexpected destroy events. */	    XtRemoveCallback(dialog, XmNdestroyCallback,             	(XtCallbackProc)destroy_callback, &df);	    XtDestroyWidget(dialog);	}	PromptHistory = NULL;    	NPromptHistoryItems = -1;    }						  /* End prompt dialog path */    else {				/* MessageBox dialogs */	XtSetArg (args[argcount], XmNmessageString, msgstr_xms); argcount++;	XtSetArg (args[argcount], XmNdialogType, dialog_types[dialog_num]);		argcount ++;	XtSetArg (args[argcount], XmNdialogTitle, titstr_xms);		argcount++;	XtSetArg (args[argcount], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL);		argcount ++;	dialog_shell = CreateDialogShell (parent, dialog_name[dialog_num],			0, 0);	dialog = XmCreateMessageBox (dialog_shell, "msg box", args, argcount);        	XtAddCallback (dialog, XmNokCallback, (XtCallbackProc)ok_callback,		(char *)&df);	XtAddCallback (dialog, XmNcancelCallback,		(XtCallbackProc)cancel_callback, (char *)&df);	XtAddCallback (dialog, XmNhelpCallback, (XtCallbackProc)help_callback,		(char *)&df);	/* Make extraneous buttons disappear */	switch (n) {		/* n = number of buttons requested */	case 0: case 3:	    break;		/* default (0) gets you 3 buttons */	case 1:	    XtUnmanageChild (XmMessageBoxGetChild (dialog,			XmDIALOG_CANCEL_BUTTON) );	case 2:	    XtUnmanageChild (XmMessageBoxGetChild (dialog,			XmDIALOG_HELP_BUTTON) );	    break;	default:	    break;	}        /* Try to create some sensible default mnemonics */        createMnemonics(dialog_shell);        AddDialogMnemonicHandler(dialog_shell, TRUE);    	/* If the button labeled cancel or dismiss is not the cancel button, or    	   if there is no button labeled cancel or dismiss, redirect escape key    	   events (this is necessary because the XmNcancelButton resource in    	   the bulletin board widget class is blocked from being reset) */    	if (cancel_index == -1)    	    addEscapeHandler(dialog, NULL, 0);    	else if (cancel_index != CANCEL_BTN)    	    addEscapeHandler(dialog, &df, cancel_index);    	/* Add a callback to the window manager close callback for the dialog */    	AddMotifCloseCallback(XtParent(dialog),    	    	(XtCallbackProc)(cancel_index == APPLY_BTN ? apply_callback :    	    	(cancel_index == CANCEL_BTN ? cancel_callback :    	    	(cancel_index == HELP_BTN ? help_callback : ok_callback))),&df);                /* Also add a callback to detect unexpected destruction (eg, because           the parent window is destroyed) */        XtAddCallback(dialog_shell, XmNdestroyCallback, 	    (XtCallbackProc)destroy_callback, &df);	/* Pop up the dialog, wait for response*/	ManageDialogCenteredOnPointer(dialog);	while (!df.done_with_dialog && !df.destroyed)	    XtAppProcessEvent (XtWidgetToApplicationContext(dialog), XtIMAll);		if (!df.destroyed) {             /* Important! Only intercept unexpected destroy events. */	    XtRemoveCallback(dialog_shell, XmNdestroyCallback,             	(XtCallbackProc)destroy_callback, &df);	    XtDestroyWidget(dialog_shell);        }    }    XmStringFree(msgstr_xms);    XmStringFree(titstr_xms);    for (i = 0; i < num_but_lbls; ++i)	XmStringFree(but_lbl_xms[i]);        /* If the dialog was destroyed unexpectedly, the button was not set yet,       so we must set the index of the cancel button. */    if (df.destroyed) {	df.button = cancel_index == APPLY_BTN ? 2 :        	(cancel_index == CANCEL_BTN ? 2 + df.apply_up :                (cancel_index == HELP_BTN ? 3 + df.apply_up : 1));    }		    df.apply_up = 0;			/* default is apply button unmanaged */    return (df.button);}/*** Add up-arrow history recall to the next DialogF(DF_PROMPT... call (see** AddHistoryToTextWidget in misc.c).  This must be re-set before each call.** calling DialogF with a dialog type of DF_PROMPT automatically resets** this mode back to no-history-recall.*/void SetDialogFPromptHistory(char **historyList, int nItems){    PromptHistory = historyList;    NPromptHistoryItems = nItems;}static void ok_callback (Widget w, struct dfcallbackstruct *client_data,	caddr_t call_data){    client_data->done_with_dialog = True;    client_data->button = 1;		/* Return Button number pressed */}static void cancel_callback (Widget w, struct dfcallbackstruct *client_data,	caddr_t call_data){    client_data->done_with_dialog = True;    client_data->button = 2 + client_data->apply_up; /* =3 if apply button managed */}static void help_callback (Widget w, struct dfcallbackstruct *client_data,	caddr_t call_data){    client_data->done_with_dialog = True;    client_data->button = 3 + client_data->apply_up; /* =4 if apply button managed */}static void apply_callback (Widget w, struct dfcallbackstruct *client_data,	caddr_t call_data){    client_data->done_with_dialog = True;    client_data->button = 2;		/* Motif puts between OK and cancel */}static void destroy_callback (Widget w, struct dfcallbackstruct *client_data,	caddr_t call_data){    client_data->destroyed = True;}/*** callback for returning default button status to the ok button once we're** sure the text area in the prompt dialog has input focus.*/static void focusCB(Widget w, Widget dialog, caddr_t call_data){    XtVaSetValues(dialog, XmNdefaultButton,    	    XmSelectionBoxGetChild(dialog, XmDIALOG_OK_BUTTON), NULL);}/*** Message and prompt dialogs hardwire the cancel button to the XmNcancelButton** resource in the bulletin board dialog.  Since we rename the buttons, the** cancel label may not be on the dialog's idea of the Cancel button.  The only** way to make the accelerator for Cancel and Dismiss (the escape key) work** correctly in this situation is to brutally catch and redirect the event.** This routine redirects escape key events in the dialog to the callback for** the button "whichBtn", passing it argument "df".  If "df" is NULL, simply** block the event from reaching the dialog.*/static void addEscapeHandler(Widget dialog, struct dfcallbackstruct *df,    	int whichBtn){    XtAddEventHandler(dialog, KeyPressMask, False, whichBtn == APPLY_BTN ?    	    escapeApplyCB : escapeHelpCB, (XtPointer)df);    XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog), XK_Escape), 0,	    True, GrabModeAsync, GrabModeAsync);}/*** Event handler for escape key to redirect the event to the help button.** Attached when cancel label appears on Help button.*/static void escapeHelpCB(Widget w, XtPointer callData, XEvent *event,    	Boolean *cont){    if (event->xkey.keycode != XKeysymToKeycode(XtDisplay(w), XK_Escape))    	return;    if (callData != NULL)    	help_callback(w, (struct dfcallbackstruct *)callData, NULL);    *cont = False;}/*** Event handler for escape key to redirect event to the apply button.** Attached when cancel label appears on Apply button.*/static void escapeApplyCB(Widget w, XtPointer callData, XEvent *event,    	Boolean *cont){    if (event->xkey.keycode != XKeysymToKeycode(XtDisplay(w), XK_Escape))    	return;    if (callData != NULL)    	apply_callback(w, (struct dfcallbackstruct *)callData, NULL);    *cont = False;}/*** Only used by createMnemonics(Widget w)*/static void recurseCreateMnemonics(Widget w, Boolean *mnemonicUsed){    WidgetList children;    Cardinal   numChildren, i;    XtVaGetValues(w,                  XmNchildren,    &children,                  XmNnumChildren, &numChildren,                  NULL);    for (i = 0; i < numChildren; i++)    {        Widget child = children[i];                if (XtIsComposite(child))        {            recurseCreateMnemonics(child, mnemonicUsed);        }        else if (XtIsSubclass(child, xmPushButtonWidgetClass) ||                 XtIsSubclass(child, xmPushButtonGadgetClass))        {            XmString xmslabel;            char *label;            int c;                        XtVaGetValues(child, XmNlabelString, &xmslabel, NULL);            if (XmStringGetLtoR(xmslabel, XmSTRING_DEFAULT_CHARSET, &label))            {                /* Scan through the string to see if the label is already used */                            int labelLen = strlen(label);                for (c = 0; c < labelLen; c++)                {                    unsigned char lc = tolower((unsigned char)label[c]);                    if (!mnemonicUsed[lc])                    {                        mnemonicUsed[lc] = TRUE;                        XtVaSetValues(child, XmNmnemonic, label[c], NULL);                        break;                    }                }                XtFree(label);            }            XmStringFree(xmslabel);        }    }}/*** Automatically create mnemonics for a widget.  Traverse all it's** children.  If the child is a push button, snag the first unused letter** and make that the mnemonic.  This is useful for DialogF dialogs which** can have arbitrary text in the buttons.*/static void createMnemonics(Widget w){    Boolean mnemonicUsed[UCHAR_MAX + 1];        memset(mnemonicUsed, FALSE, sizeof mnemonicUsed / sizeof *mnemonicUsed);    recurseCreateMnemonics(w, mnemonicUsed);}

⌨️ 快捷键说明

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