📄 dialog.c
字号:
{ XtRealizeWidget(dObject->dialogShell);} /* dialog_realize *//*dialog_activate() maps the dialog box. If the dialog box has amodal configuration, it blocks the application until the userselects a command button. See dialog_modal_prompt() for analternative approach for activating a modal dialog box.*/void dialog_activate(dObject)Dialog dObject;{ if (dObject->dialogText && !dObject->remember_string_response) XmTextSetString(dObject->dialogText, ""); /* clean slate */ position_dialog(dObject); if (dObject->modal_dialog) popup_and_wait_for_button_response(dObject); else XtPopup(dObject->dialogShell, XtGrabNone);} /* dialog_activate *//*dialog_deactivate() removes the dialog box.*/void dialog_deactivate(dObject)Dialog dObject;{ XtPopdown(dObject->dialogShell);} /* dialog_deactivate *//*dialog_modal_prompt() maps the dialog box, waits for a response,and returns the (integer) index of the chosen button, zero-based.It does not return the value of the client data stored with thechosen button. See dialog_activate() for an alternative approachfor activating a dialog box.*/int dialog_modal_prompt(dObject, prompt)Dialog dObject;char *prompt;{ if (dObject->modal_dialog) { if (dObject->dialogText && !dObject->remember_string_response) XmTextSetString(dObject->dialogText, ""); /* clean slate */ position_dialog(dObject); dialog_set_prompt(dObject, prompt); popup_and_wait_for_button_response(dObject); return dObject->button_pressed; } else return dialog_BTN_NULL;} /* dialog_modal_prompt *//*dialog_set_prompt() allows the application to set thedialog box's prompt, independent of invoking the dialogbox. The temporary `XmString' variable is freed--thisfunction could be called a zillion times.*/void dialog_set_prompt(dObject, prompt)Dialog dObject;char *prompt;{ if (prompt && *prompt) { Arg args[1]; XmString str_prompt = XmStringCreateLtoR(prompt, dObject->char_set); XtSetArg(args[0], XmNlabelString, (XtArgVal) str_prompt); XtSetValues(dObject->dialogPrompt, args, 1); /* fixed */ XmStringFree(str_prompt); }} /* dialog_set_prompt *//*dialog_get_text() returns the user's string response fromthe text edit widget. The caller must free the text withXtFree(). Note that string response may not be enabled fora particular dialog box instance.*/char *dialog_get_text(dObject)Dialog dObject;{ return (dObject->dialogText) ? (char *) XmTextGetString(dObject->dialogText) : NULL;} /* dialog_get_text *//*dialog_set_text() allows the application to set, or update,the user's string response from the text-edit widget.*/void dialog_set_text(dObject, string)Dialog dObject;char *string;{ if (dObject->dialogText && string && *string) XmTextSetString(dObject->dialogText, string);} /* dialog_set_text *//*dialog_forget_text() modifies the behavior of a dialog boxwith a string-response field, so that the dialog is mapped eachtime with an empty text entry field.*/void dialog_forget_text(dObject)Dialog dObject;{ dObject->remember_string_response = False;} /* dialog_forget_text *//*dialog_remember_text() modifies the behavior of a dialog boxwith a string-response field, so that the dialog is mapped eachtime without clearing the text entry field.*/void dialog_remember_text(dObject)Dialog dObject;{ dObject->remember_string_response = True;} /* dialog_remember_text *//*dialog_get_most_recent_button_response() returns the user's mostrecent button response/selection.*/XtPointer dialog_get_most_recent_button_response(dObject)Dialog dObject;{ return dObject->most_recent_button_data;} /* dialog_get_most_recent_button_response *//*dialog_cancel() can be used to cancel a dialog box withoutwaiting for a user's response. For example, if the user selectsthe window manager's "Close" button in a modal dialog, theapplication can call this function to terminate the dialog.In most cases, the application will interpret this action tobe equivalent to selecting one of the dialog's button, forexample, the "Cancel" button.*/void dialog_cancel(dObject, button_pressed)Dialog dObject;int button_pressed;{ dObject->button_pressed = button_pressed; XtPopdown(dObject->dialogShell);} /* dialog_cancel *//*For the following functions dialog_<widget_name>() returnsthe widget IDs of the internal widgets. Many of thesearen't really needed and could be deleted. Using macros isanother possibility. And, of course, Xt provides functionsfor obtaining this information.*/Widget dialog_dialogShell(dObject)Dialog dObject;{ return dObject->dialogShell;} /* dialog_dialogShell */Widget dialog_instance(dObject)Dialog dObject;{ return dObject->instance;} /* dialog_instance */Widget dialog_class(dObject)Dialog dObject;{ return dObject->class;} /* dialog_class */Widget dialog_dialogPane(dObject)Dialog dObject;{ return dObject->dialogPane;} /* dialog_dialogPane */Widget dialog_dialogControl(dObject)Dialog dObject;{ return dObject->dialogControl;} /* dialog_dialogControl */Widget dialog_dialogPrompt(dObject)Dialog dObject;{ return dObject->dialogPrompt;} /* dialog_dialogPrompt */Widget dialog_dialogText(dObject)Dialog dObject;{ return dObject->dialogText;} /* dialog_dialogText */Widget dialog_dialogAction(dObject)Dialog dObject;{ return dObject->dialogAction;} /* dialog_dialogAction *//*Private callback functions:*//*DialogDismiss() is a private callback that removesthe dialog box.*//*ARGSUSED*/static void DialogDismiss(w, client_data, call_data)Widget w;XtPointer client_data;XtPointer call_data;{ Dialog dObject = (Dialog) client_data; XtPopdown(dObject->dialogShell);} /* DialogDismiss *//*UpdateButtonResponse() is a private callback that recordsthe data associated with the most recent button selection.It also sets an indicator variable that signals that abutton has been selected; the latter is used only withdialogs configured for modal behavior.*//*ARGSUSED*/static void UpdateButtonResponse(w, client_data, call_data)Widget w;XtPointer client_data;XtPointer call_data;{ Dialog dObject = (Dialog) client_data; Arg args[1]; XtPointer user_data; int i; XtSetArg(args[0], XmNuserData, &user_data); XtGetValues(w, args, 1); /* fixed */ dObject->most_recent_button_data = user_data; for (i = 0; i < dObject->num_buttons; i++) if (w == dObject->buttons[i]) { dObject->button_pressed = i; break; }} /* UpdateButtonResponse *//*Private support functions:*//*popup_and_wait_for_button_response() is called tosynchronize execution for a modal dialog.*/static void popup_and_wait_for_button_response(dObject)Dialog dObject;{ dObject->button_pressed = dialog_BTN_NULL; XtPopup(dObject->dialogShell, XtGrabExclusive); while (dObject->button_pressed == dialog_BTN_NULL) { XEvent event; XtAppNextEvent(dObject->app, &event); XtDispatchEvent(&event); }} /* popup_and_wait_for_button_response *//*position_dialog() positions the dialog on the screen. Currently, thisfunction does not enforce any dialog placement policy. That is, itallows the programmer to position a top-level shell, even though itis generally accepted that this should be left up to the user--theprogrammer is in control.*/static void position_dialog(dObject)Dialog dObject;{ Arg args[3]; int i; Dimension width, height;/* if (dObject->max_win_mgr) return;*/ if (dObject->dialog_position == dialog_DEFAULT) return; if (!XtIsRealized(dObject->dialogShell)) return; i = 0; XtSetArg(args[i], XmNwidth, &width); i++; XtSetArg(args[i], XmNheight, &height); i++; XtGetValues(dObject->dialogShell, args, i); if (dObject->dialog_position == dialog_CENTER) { Screen *screen = XtScreen(dObject->dialogShell); i = 0; XtSetArg(args[i], XmNx, (XtArgVal) ((XWidthOfScreen(screen) - (int) width) / 2)); i++; XtSetArg(args[i], XmNy, (XtArgVal) ((XHeightOfScreen(screen) - (int) height) / 2)); i++; } else if (dObject->dialog_position == dialog_POINTER) { Window dummy_win; int root_x, root_y, dummy_xy; unsigned int dummy_keys; XQueryPointer(XtDisplay(dObject->dialogShell), XtWindow(dObject->dialogShell), &dummy_win, &dummy_win, &root_x, &root_y, &dummy_xy, &dummy_xy, &dummy_keys); /* Motif will keep it on-screen: */ i = 0; XtSetArg(args[i], XmNx, (XtArgVal) (root_x - ((int) width / 2))); i++; XtSetArg(args[i], XmNy, (XtArgVal) (root_y - ((int) height / 2))); i++; } XtSetValues(dObject->dialogShell, args, i);} /* position_dialog */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -