|
|
Sometimes, you may want the menu driver to execute a specific routine during the change of an item or menu. The following functions let you do this easily.
SYNOPSIS
typedef void (PTF_void) ();int set_menu_init (menu, func) MENU menu; PTF_void func;
PTF_void menu_init (menu) MENU menu;
int set_menu_term (menu, func) MENU menu; PTF_void func;
PTF_void menu_term (menu) MENU menu;
int set_item_init (menu, func) MENU menu; PTF_void func;
PTF_void item_init (menu) MENU menu;
int set_item_term (menu, func) MENU menu; PTF_void func;
PTF_void item_term (menu) MENU menu;
If you want your application to execute an application-defined function at one of the initialization or termination points listed below, you should call the appropriate set_ routine at the start of your program. If you do not want a specific function executed in these cases, you may refrain from calling these routines altogether.
The following subsections summarize when each initialization and termination routine is executed.
The argument func to this function is automatically called by the menu system
The argument func is automatically called by the menu system
The argument func is automatically called by the menu system
The argument func is automatically called by the menu system
WINDOW * prompt_window;void display_prompt (s) char * s; { WINDOW * w = prompt_window;
werase (w); wmove (w, 0, 0); /* move to window origin */ waddstr (w, s); /* write prompt in window */ wrefresh (w); /* display prompt */ } void generate_prompt (m) MENU * m; {
/* display the prompt string associated with the current item */
char * s = item_userptr (current_item (m)); display_prompt (s); } ITEM * items[NUMBER_OF_ITEMS + 1];
main () { MENU * m;
for (i = 0; i < NUMBER_OF_ITEMS; ++i) {
/* read in name and prompt strings here */
items[i] = new_item (name, ""); set_item_userptr (items[i], prompt); } items[i] = (ITEM *) 0;
m = new_menu (items); set_item_init (m, generate_prompt); /* set initialization routine */ }
Using an initialization routine to generate item prompts
Function set_item_init arranges to call generate_prompt whenever the menu item changes. Function generate_prompt fetches the item user pointer associated with the current item and calls display_prompt, which displays the item prompt. Function display_prompt is a separate function to enable you to use it for other prompts as well.