Previous | Contents | Index |
Example 4-6 shows the code that implements the help widget for the OpenVMS DECburger sample application. The complete UIL source code for the OpenVMS DECburger application in DECW$EXAMPLES on OpenVMS systems.
Example 4-6 UIL Help Widget Implementation |
---|
. . . !module DECburger_demo module decburger version = 'v1.1.1' names = case_sensitive objects = { XmSeparator = gadget ; XmLabel = gadget ; XmPushButton = gadget ; XmToggleButton = gadget ; } procedure toggle_proc (integer); activate_proc (integer); create_proc (integer); scale_proc (integer); list_proc (integer); exit_proc (string); show_hide_proc (integer); pull_proc (integer); (1)sens_help_proc (compound_string); help_system_proc (string); ok_color_proc (); apply_color_proc (); cancel_color_proc (); value k_create_order : 1; k_order_pdme : 2; k_file_pdme : 3; k_edit_pdme : 4; k_nyi : 5; k_ok : 6; ! NOTE: ok, apply, reset, cancel k_apply : 7; ! must be sequential k_reset : 8; k_cancel : 9; k_cancel_order : 10; k_submit_order : 11; k_order_box : 12; k_burger_min : 13; k_burger_rare : 13; k_burger_medium : 14; k_burger_well : 15; k_burger_ketchup : 16; k_burger_mustard : 17; k_burger_onion : 18; k_burger_mayo : 19; k_burger_pickle : 20; k_burger_max : 20; k_burger_quantity : 21; k_fries_tiny : 22; k_fries_small : 23; k_fries_medium : 24; k_fries_large : 25; k_fries_huge : 26; k_fries_quantity : 27; k_drink_list : 28; k_drink_add : 29; k_drink_sub : 30; k_drink_quantity : 31; k_total_order : 32; k_burger_label : 33; k_fries_label : 34; k_drink_label : 35; k_menu_bar : 36; k_file_menu : 37; k_edit_menu : 38; k_order_menu : 39; k_help_pdme : 40; k_help_menu : 41; k_help_overview : 42; k_help_about : 43; k_help_onhelp : 44; k_help_sensitive : 45; k_print : 46; k_options_pdme : 47; k_options_menu : 48; k_create_options : 49; k_fries_optionmenu : 50; value k_decburger_title : 'DECburger: Order Entry Box'; k_nyi_label_text : 'This feature is not yet implemented.'; k_file_label_text : 'File'; k_print_label_text : 'Print Order..'; k_exit_label_text : 'Exit'; k_edit_label_text : 'Edit'; k_cut_dot_label_text : 'Cut'; k_copy_dot_label_text : 'Copy'; k_paste_dot_label_text : 'Paste'; k_clear_dot_label_text : 'Clear'; k_select_all_label_text : 'Select All'; k_order_label_text : 'Order'; k_cancel_order_label_text : 'Cancel Order'; k_submit_order_label_text : 'Submit Order'; k_options_label_text : 'Options'; k_options_color_label_text : 'Background Color...'; (2)k_help_label_text : 'Help'; k_sensitive_label_text : 'On Context'; k_overview_label_text : 'On Window'; k_about_label_text : 'On Version'; k_onhelp_label_text : 'On Help'; k_hamburgers_label_text : 'Hamburgers'; k_rare_label_text : 'Rare'; k_medium_label_text : 'Medium'; k_well_done_label_text : 'Well Done'; k_ketchup_label_text : 'Ketchup'; k_mustard_label_text : 'Mustard'; k_onion_label_text : 'Onion'; k_mayonnaise_label_text : 'Mayonnaise'; k_pickle_label_text : 'Pickle'; k_quantity_label_text : 'Quantity'; k_fries_label_text : 'Fries'; k_size_label_text : 'Size'; k_tiny_label_text : 'Tiny'; k_small_label_text : 'Small'; k_large_label_text : 'Large'; k_huge_label_text : 'Huge'; k_drinks_label_text : 'Drinks'; k_0_label_text : ' 0'; k_drink_list_text : string_table ( 'Apple Juice', 'Orange Juice', 'Grape Juice', 'Cola', 'Punch', 'Root beer', 'Water', 'Ginger Ale', 'Milk', 'Coffee', 'Tea'); k_drink_list_select : string_table('Apple Juice'); k_ok_label_text : 'OK'; k_apply_label_text : 'Apply'; k_reset_label_text : 'Reset'; k_cancel_label_text : 'Cancel'; !Compound strings to use for context-sensitive help callbacks (3)value k_order_help : compound_string ("order"); k_print_help : compound_string ("print"); k_options_help : compound_string ("options"); k_menu_bar_help : compound_string ("menu_bar"); k_file_help : compound_string ("file_menu"); k_edit_help : compound_string ("edit_menu"); k_order_menu_help : compound_string ("order_menu"); k_help_help : compound_string ("help"); k_sensitive_help : compound_string ("sensitive"); k_onhelp_help : compound_string ("onhelp"); k_about_help : compound_string ("about"); k_overview_help : compound_string ("overview"); k_nyi_help : compound_string ("not_implemented"); . . . (4)object main_help : DXmHelpDialog { arguments { DXmNapplicationName = compound_string("Help Example"); DXmNglossaryTopic = compound_string("glossary"); DXmNoverviewTopic = compound_string("overview"); DXmNlibrarySpec = compound_string("decburger.hlb"); }; }; . . . object s_menu_bar : XmMenuBar { arguments { XmNorientation = XmHORIZONTAL; (5)XmNmenuHelpWidget = XmCascadeButton help_menu_entry; }; controls { XmCascadeButton file_menu_entry; XmCascadeButton edit_menu_entry; XmCascadeButton order_menu_entry; XmCascadeButton options_menu_entry; (6)XmCascadeButton help_menu_entry; }; callbacks { MrmNcreateCallback = procedure create_proc (k_menu_bar); (7)XmNhelpCallback = procedure sens_help_proc(k_menu_bar_help); }; }; . . . (8)object help_menu_entry : XmCascadeButton { arguments { XmNlabelString = k_help_label_text; XmNmnemonic = keysym("H"); }; controls { XmPulldownMenu help_menu; }; callbacks { XmNhelpCallback = procedure sens_help_proc(k_help_help); }; }; (9)object help_menu : XmPulldownMenu { controls { XmPushButton help_sensitive; XmPushButton help_window; XmPushButton help_version; XmPushButton help_onhelp; }; callbacks { XmNhelpCallback = procedure sens_help_proc(k_help_help); }; }; object help_sensitive : XmPushButton { arguments { XmNlabelString = k_sensitive_label_text; XmNmnemonic = keysym("C"); }; callbacks { (10)XmNactivateCallback = procedure activate_proc (k_help_sensitive); XmNhelpCallback = procedure sens_help_proc(k_sensitive_help); }; }; object help_onhelp : XmPushButton { arguments { XmNlabelString = k_onhelp_label_text; XmNmnemonic = keysym("H"); }; callbacks { XmNactivateCallback = procedure activate_proc (k_help_onhelp); XmNhelpCallback = procedure sens_help_proc(k_onhelp_help); }; }; object help_version : XmPushButton { arguments { XmNlabelString = k_about_label_text; XmNmnemonic = keysym("V"); }; callbacks { XmNactivateCallback = procedure activate_proc (k_help_about); XmNhelpCallback = procedure sens_help_proc(k_about_help); }; }; object help_window : XmPushButton { arguments { XmNlabelString = k_overview_label_text; XmNmnemonic = keysym("W"); }; callbacks { XmNactivateCallback = procedure activate_proc (k_help_overview); XmNhelpCallback = procedure sens_help_proc(k_overview_help); }; }; . . . |
Example 4-7 and Example 4-8 show the C language code that implements the help widget created in Example 4-9. The complete C source code for the OpenVMS DECburger application is included in DECW$EXAMPLES on OpenVMS systems.
Example 4-7 Help Widget Implementation---C Language Module |
---|
. . . #include <stdio.h> /* For printf and so on. */ #include <Xm/Text.h> #include <Mrm/MrmAppl.h> (1)#include <DXm/DXmHelpB.h> #include <DXm/DXmPrint.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #include <DXm/DXmColor.h> #include <DXm/DECspecific.h> #ifdef VMS /* For OpenVMS systems, use the following include file: */ #include <sys$library/DECw$Cursor.h> #else /* For UNIX systems, use the following include file: */ #include <X11/decwcursor.h> #endif /* * These numbers are matched with corresponding numbers in the * OpenVMS DECburger UIL module. */ #define k_create_order 1 #define k_order_pdme 2 #define k_file_pdme 3 #define k_edit_pdme 4 #define k_nyi 5 #define k_ok 6 /* NOTE: ok, apply, reset, cancel */ #define k_apply 7 /* must be sequential */ #define k_reset 8 #define k_cancel 9 #define k_cancel_order 10 #define k_submit_order 11 #define k_order_box 12 #define k_burger_min 13 #define k_burger_rare 13 #define k_burger_medium 14 #define k_burger_well 15 #define k_burger_ketchup 16 #define k_burger_mustard 17 #define k_burger_onion 18 #define k_burger_mayo 19 #define k_burger_pickle 20 #define k_burger_max 20 #define k_burger_quantity 21 #define k_fries_tiny 22 #define k_fries_small 23 #define k_fries_medium 24 #define k_fries_large 25 #define k_fries_huge 26 #define k_fries_quantity 27 #define k_drink_list 28 #define k_drink_add 29 #define k_drink_sub 30 #define k_drink_quantity 31 #define k_total_order 32 #define k_burger_label 33 #define k_fries_label 34 #define k_drink_label 35 #define k_menu_bar 36 #define k_file_menu 37 #define k_edit_menu 38 #define k_order_menu 39 (2)#define k_help_pdme 40 #define k_help_menu 41 #define k_help_overview 42 #define k_help_about 43 #define k_help_onhelp 44 #define k_help_sensitive 45 #define k_print 46 #define k_custom_pdme 47 #define k_custom_menu 48 #define k_create_custom 49 #define k_fries_optionmenu 50 #define k_max_widget 50 #define MAX_WIDGETS (k_max_widget + 1) #define NUM_BOOLEAN (k_burger_max - k_burger_min + 1) #define k_burger_index 0 #define k_fries_index 1 #define k_drinks_index 2 #define k_index_count 3 /* * Global data */ static Cursor watch = NULL; static Widget toplevel_widget = (Widget)NULL, /* Root widget ID of our application. */ main_window_widget = (Widget)NULL, /* Root widget ID of main MRM fetch */ widget_array[MAX_WIDGETS], /* Place to keep all other widget IDs */ (3)main_help_widget = (Widget)NULL, /* Primary help widget */ (4)help_widget[MAX_WIDGETS], /* Array of help widgets */ help_array[MAX_WIDGETS], /* Array of help widgets for Toolkit */ print_widget = (Widget)NULL, /* Print widget */ color_widget = (Widget)NULL; /* Color Mix widget */ static Screen *the_screen; /* Pointer to screen data*/ static Display *the_display; /* Pointer to display data */ static XColor savecolor; static int help_num = 0; /* make sure they start zero */ static int low_num = 0; . . . /* * Forward declarations */ static void s_error(); static void get_something(); static void set_something(); static void activate_proc(); static void create_proc(); static void list_proc(); static void exit_proc(); static void pull_proc(); static void scale_proc(); static void show_hide_proc(); static void show_label_proc(); static void toggle_proc(); (5)static void create_help(); static void tracking_help(); static void sens_help_proc(); static void help_system_proc(); static void create_print(); static void activate_print(); static void create_color(); static void ok_color_proc(); static void apply_color_proc(); static void cancel_color_proc(); static void xmstring_append(); static void start_watch(); static void stop_watch(); /* The names and addresses of things that Mrm has to bind. The names do * not have to be in alphabetical order. */ static MrmRegisterArg reglist[] = { {"activate_proc", (caddr_t) activate_proc}, {"create_proc", (caddr_t) create_proc}, {"list_proc", (caddr_t) list_proc}, {"pull_proc", (caddr_t) pull_proc}, {"exit_proc", (caddr_t) exit_proc}, {"scale_proc", (caddr_t) scale_proc}, {"show_hide_proc", (caddr_t) show_hide_proc}, {"show_label_proc", (caddr_t) show_label_proc}, {"toggle_proc", (caddr_t) toggle_proc}, (6){"sens_help_proc", (caddr_t) sens_help_proc}, {"help_system_proc", (caddr_t) help_system_proc}, {"cancel_color_proc", (caddr_t) cancel_color_proc}, {"apply_color_proc", (caddr_t) apply_color_proc}, {"ok_color_proc", (caddr_t) ok_color_proc} }; static int reglist_num = (sizeof reglist / sizeof reglist [0]); static font_unit = 400; /* * OS transfer point. The main routine does all the one-time setup and * then calls XtMainLoop. */ static String fallback = "DECburger.title: DECburger\nDECburger.x: 100\nDECburger.y: 100"; unsigned int main(argc, argv) unsigned int argc; /* Command line argument count. */ char *argv[]; /* Pointers to command line args. */ { XtAppContext app_context; MrmInitialize(); /* Initialize MRM before initializing /* the X Toolkit. */ (7)DXmInitialize(); /* Initialize DXm widgets */ /* If we had user-defined widgets, we would register them with Mrm here. */ /* Initialize the X Toolkit. We get back a top level shell widget. */ toplevel_widget = XtAppInitialize( &app_context, /* App. context is returned */ "DECburger", /* Root class name. */ NULL, /* No option list. */ 0, /* Number of options. */ &argc, /* Address of argc */ argv, /* argv */ &fallback, /* Fallback resources */ NULL, /* No override resources */ 0); /* No override resources */ /* Open the UID files (the output of the UIL compiler) in the hierarchy*/ if (MrmOpenHierarchy( db_filename_num, /* Number of files. */ db_filename_vec, /* Array of file names. */ NULL, /* Default OS extension. */ &s_MrmHierarchy) /* Pointer to returned MRM ID */ !=MrmSUCCESS) s_error("can't open hierarchy"); init_application(); /* Register the items MRM needs to bind for us. */ MrmRegisterNames(reglist, reglist_num); /* Go get the main part of the application. */ if (MrmFetchWidget(s_MrmHierarchy, "S_MAIN_WINDOW", toplevel_widget, &main_window_widget, &dummy_class) != MrmSUCCESS) s_error("can't fetch main window"); /* Save some frequently used values */ the_screen = XtScreen(toplevel_widget); the_display = XtDisplay(toplevel_widget); /* If it's a color display, map customize color menu entry */ if ((XDefaultVisualOfScreen(the_screen))->class == TrueColor || (XDefaultVisualOfScreen(the_screen))->class == PseudoColor || (XDefaultVisualOfScreen(the_screen))->class == DirectColor || (XDefaultVisualOfScreen(the_screen))->class == StaticColor) XtSetMappedWhenManaged(widget_array[k_custom_pdme], TRUE); /* Manage the main part and realize everything. The interface comes up * on the display now. */ XtManageChild(main_window_widget); XtRealizeWidget(toplevel_widget); . . . /* Sit around forever waiting to process X-events. We never leave * XtAppMainLoop. From here on, we only execute our callback routines. */ XtAppMainLoop(app_context); } /* * One-time initialization of application data structures. */ static int init_application() { int k; int i; /* Initialize the application data structures. */ for (k = 0; k < MAX_WIDGETS; k++) widget_array[k] = NULL; for (k = 0; k < NUM_BOOLEAN; k++) toggle_array[k] = FALSE; /* Initialize CS help widgets. */ (8)for (i = 0; i < MAX_WIDGETS; i++) help_widget[i] = NULL; . . . |
Example 4-8 Help Widget Implementation---Callbacks |
---|
. . . /* * All push buttons in this application call back to this routine. We * use the tag to tell us what widget it is, then react accordingly. */ static void activate_proc(w, tag, reason) Widget w; int *tag; XmAnyCallbackStruct *reason; { int widget_num = *tag; /* Convert tag to widget number. */ int i, value; XmString topic; switch (widget_num) { case k_nyi: /* The user activated a 'not yet implemented' push button. Send * the user a message. */ if (widget_array[k_nyi] == NULL) { /* The first time, fetch from the data base. */ if (MrmFetchWidget(s_MrmHierarchy, "nyi", toplevel_widget, &widget_array[k_nyi], &dummy_class) != MrmSUCCESS) { s_error("can't fetch nyi widget"); } } /* Put up the message box saying 'not yet implemented'. */ XtManageChild(widget_array[k_nyi]); break; case k_submit_order: /* This would send the order off to the kitchen. In this case, * we just pretend the order was submitted. */ clear_order(); break; . . . (1)case k_help_overview: topic = XmStringCreateLtoR("overview",XmSTRING_ISO8859_1); create_help(topic); XmStringFree(topic); break; case k_help_about: topic = XmStringCreateLtoR("about",XmSTRING_ISO8859_1); create_help(topic); XmStringFree(topic); break; case k_help_onhelp: topic = XmStringCreateLtoR("onhelp",XmSTRING_ISO8859_1); create_help(topic); XmStringFree(topic); break; case k_help_sensitive: tracking_help(); break; case k_print: create_print(); break; case k_create_custom: create_color(); break; default: break; } } . . . /* * Context sensitive help callback. */ (2)static void sens_help_proc(w, tag, reason) Widget w; XmString *tag; XmAnyCallbackStruct *reason; { create_help(tag); } /* Creates an instance of the help widget for the push buttons in the help pull-down menu and for context-sensitive help callbacks. */ (3)static void create_help (help_topic) XmString help_topic; { Arg arglist[1]; start_watch(); if (!main_help_widget) { if (MrmFetchWidget (s_MrmHierarchy, "main_help", toplevel_widget, &main_help_widget, &dummy_class) != MrmSUCCESS) s_error ("can't fetch help widget"); } if (XtIsManaged(main_help_widget)) { if (MrmFetchWidget (s_MrmHierarchy, "main_help", toplevel_widget, &help_widget[help_num], &dummy_class) != MrmSUCCESS) s_error ("can't fetch help widget"); XtSetArg (arglist[0], DXmNfirstTopic, help_topic); XtSetValues (help_widget[help_num], arglist, 1); XtManageChild(help_widget[help_num]); help_num++; return; } XtSetArg (arglist[0], DXmNfirstTopic, help_topic); XtSetValues (main_help_widget, arglist, 1); XtManageChild(main_help_widget); stop_watch(); } . . . |
Previous | Next | Contents | Index |