/**********************************************************************/ /* Example illustrating how to append items to one of the standard */ /* menus or how to add a custom menu. */ /* $Header: Last edited: 21-Nov-1998 1.2 $ */ /**********************************************************************/ # include extern list menu_bar_hook; void main() { /***********************************************/ /* Ensure we get called when menus are */ /* being created. */ /***********************************************/ menu_bar_hook += "my_menu_hook"; } /**********************************************************************/ /* Hook functions gets called with three arguments: a reason code, */ /* a name associated with a menu about to be popped up, and the */ /* screen dialog object id. */ /**********************************************************************/ int my_menu_hook(int reason, string name_id, int obj_id) { list mlist; dynamic objects; // objects is a local variable in the calling function. int pos; if (reason == MENU_CALLBACK_CREATED) { /***********************************************/ /* This code gets called after the main */ /* menus have been created. This allows us */ /* to intercept the menu creation and put */ /* in our own custom menu. */ /***********************************************/ /***********************************************/ /* Here we demonstrate how we can add a new */ /* custom menu rather than inserting into */ /* an existing menu hierarchy. */ /* */ /***********************************************/ mlist = make_list( DBOX_MENU_BUTTON, "My Menu", DBOX_SUB_GROUP_START, /***********************************************/ /* Create a new menu itm, and display a */ /* message when called. */ /***********************************************/ DBOX_MENU_ITEM, "Action &1", DBOX_CALLBACK, "message \"you called sir\"", /***********************************************/ /* Menu item which puts up the edit file */ /* dialog. */ /***********************************************/ DBOX_MENU_ITEM, "Action &2 -- edit a file", DBOX_CALLBACK, "usr_edit_file", DBOX_HELP_STRING, "You can edit a file with this entry", DBOX_GROUP_END); /***********************************************/ /* The following code looks for the Help */ /* menu button and inserts our new custom */ /* menu just before it. */ /***********************************************/ pos = re_search(SF_UNIX, "&Help", objects); objects = delete_nth(objects, pos - 1, 999) + mlist + delete_nth(objects, 0, pos - 1); return 0; } if (reason != MENU_CALLBACK_INITED) { /***********************************************/ /* We may get called because a menu is */ /* about to be popped up. */ /***********************************************/ return 0; } /***********************************************/ /* MENU_CALLBACK_INITED means we just */ /* created the popup menu. Now we have */ /* something to insert our entries onto. */ /* */ /* Detect which menu just got created and */ /* add our entries to this menu. */ /***********************************************/ switch (name_id) { case "file_menu_button": /***********************************************/ /* Add custom menu items here. */ /***********************************************/ insert_object(obj_id, name_id, 0, name_id, DBOX_MENU_ITEM," My menu item &1", DBOX_CALLBACK, "my_callback1", DBOX_HELP_STRING, "Do something #1.", DBOX_MENU_ITEM," My menu item &2", DBOX_CALLBACK, "my_callback2", DBOX_HELP_STRING, "Do something #2.", DBOX_MENU_ITEM," My menu item &3", DBOX_CALLBACK, "my_callback3", DBOX_HELP_STRING, "Do something #3." ); return 0; /***********************************************/ /* Other possible menus are (see xwin.cr */ /* for details). */ /***********************************************/ // File "file_menu_button" // Edit "edit_menu_button" // View "view_menu_button" // Find "find_menu_button" // Options "options_menu_button" // Tools "tools_menu_button" // Window "window_menu_button" // Help "help_menu_button" } return 0; }