📄 dialogp.h
字号:
/**** dialogP.h ****//**************************************************************************A `Dialog' object is a Motif dialog box in a shell that supportsobject-level configuration for modal or nonmodal behavior, numberof buttons, and optional string input.A `Dialog' object maintains its state between invocations of thedialog box, making it convenient for the application to retrievedata stored with the dialog, such as a user's string response (inthe case of a dialog box configured for string input) and/or thedata associated with the most recently selected button.Sample usage:#include "dialog.h"......void main(argc, argv)int argc;char *argv[];{ void DialogSelection1(), ...; Widget topLevel, ...; Dialog dialog1, dialog2; Arg args[10]; int i; static int one = 1, two = 2, three = 3; static DialogButtonItem items1[] = { {"Button 1", DialogSelection1, (XtPointer) &one}, {"Button 2", DialogSelection1, (XtPointer) &two}, {"Button 3", DialogSelection1, (XtPointer) &three}, {NULL, NULL, NULL}, }; static DialogButtonItem items2[] = { {"Dismiss", Dismiss, (XtPointer) "one"}, {"Button 2", DialogSelection2, (XtPointer) "two"}, {"Button 3", DialogSelection2, (XtPointer) "three"}, {"Button 4", DialogSelection2, (XtPointer) "four"}, {NULL, NULL, NULL}, }; XtAppContext app; topLevel = XtAppInitialize(&app, "TestDialog", (XrmOptionDescList) NULL, 0, &argc, argv, (String *) NULL, (ArgList) NULL, 0);......\*********************************************************************** dialog_create(app, parent, instance_name, items, num_columns, title, prompt, char_set, dialog_position, modal_dialog, max_win_mgr, string_input, auto_popdown, default_button);***********************************************************************\ dialog1 = dialog_create(app, topLevel, "dialog1", items1, 30, "Dialog Box #1", "This is only a test...", XmSTRING_DEFAULT_CHARSET, dialog_CENTER, TRUE, FALSE, FALSE, TRUE, 0); dialog2 = dialog_create(app, topLevel, "dialog2", items2, 30, "Dialog Box #2", "This is only a test...", XmSTRING_DEFAULT_CHARSET, dialog_DEFAULT, FALSE, TRUE, TRUE, FALSE, 0);...... XtRealizeWidget(topLevel); dialog_realize(dialog1); dialog_realize(dialog2);......NOTE: A `Dialog' stores pointers (XtPointer) to client data for theconvenience of the application programmer. In particular, a `Dialog'objects stores the client data associated with the most recentlyselected button, and provides an access function that retrieves thisvalue, dialog_get_most_recent_button_response(). Thus, theapplication should always pass addresses as client data. Becauseclient data can be of any type, there is no reason that the `Dialog'object should interpret the client data's type, or store it locally.In particular, if the application wants to associate integer data witheach button, it should define storage for the data in the application(within the scope of its anticipated retrieval of the data withdialog_get_most_recent_button_response()), pass the address of thisdata in the array of button data, and then interpret (dereference)the address that's returned. E.g., in the first example below, it'sincorrect to pass the *value* of the integer, because Xt will storethat value internally and it may then be out of scope in a futurereference. Examples:main(...)...{ static DialogButtonItem items1[] = { {"Button 1", DialogSelection1, (XtPointer) 1}, // wrong // {"Button 2", DialogSelection1, (XtPointer) 2}, // wrong // {"Button 3", DialogSelection1, (XtPointer) 3}, // wrong // {NULL, NULL, NULL}, }; ... ... { int v = (int) dialog_get_most_recent_button_response(dialog); // wrong // printf("Most recently selected button's value: %d\n", v); // wrong // } ...}main(...)...{ static int one = 1, two = 2, three = 3; static DialogButtonItem items1[] = { {"Button 1", DialogSelection1, (XtPointer) &one}, // right // {"Button 2", DialogSelection1, (XtPointer) &two}, // right // {"Button 3", DialogSelection1, (XtPointer) &three}, // right // {NULL, NULL, NULL}, }; ... ... { int *v = (int *) dialog_get_most_recent_button_response(dialog); // right // if (v) printf("Most recently selected button's value: %d\n", *v); // right // } ...}**************************************************************************/#ifndef _dialogP_h#define _dialogP_h/*Constants:*/#define dialog_BTN_WIDTH_FACTOR 40#define dialog_BTN_SPACE_FACTOR 8#define dialog_NO_DEFAULT_BTN -100/*Private convenience structure for the button labels, their callbacks,and data:*/typedef struct { char *label; void (*callback)(); /* should NOT be XtCallbackProc */ XtPointer client_data;} _DialogButtonItem;/*Private dialog structure:*/typedef struct { void *self; Widget dialogShell; Widget instance; Widget class; Widget dialogPane; Widget dialogControl; Widget dialogPrompt; Widget dialogText; Widget dialogAction; Widget *buttons; /* or `WidgetList buttons;' */ XtPointer most_recent_button_data; XtAppContext app; XmStringCharSet char_set; int num_buttons; int button_pressed; int dialog_position; Boolean modal_dialog; Boolean max_win_mgr; Boolean remember_string_response;} _Dialog;#endif /* _dialogP_h */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -