Lines Matching refs:menu

1 /*	$NetBSD: menu.c,v 1.17 2012/03/21 05:33:27 matt Exp $	*/
30 __RCSID("$NetBSD: menu.c,v 1.17 2012/03/21 05:33:27 matt Exp $");
33 #include <menu.h>
47 O_ONEVALUE, /* menu options */
51 0, /* is the menu posted? */
52 A_REVERSE, /* menu foreground */
53 A_NORMAL, /* menu background */
54 A_UNDERLINE, /* unselectable menu item */
57 0, /* top row of menu */
58 0, /* widest item in the menu */
59 0, /* the width of a menu column */
60 0, /* number of items attached to the menu */
61 NULL, /* items in the menu */
62 0, /* current menu item */
64 NULL, /* function called when menu posted */
65 NULL, /* function called when menu is unposted */
68 NULL, /* the menu window */
69 NULL, /* the menu subwindow */
76 * Set the menu mark character
81 MENU *menu = m;
83 if (m == NULL) menu = &_menui_default_menu;
86 if (menu->mark.string != NULL) free(menu->mark.string);
88 if ((menu->mark.string = (char *) malloc(strlen(mark) + 1)) == NULL)
91 strcpy(menu->mark.string, mark);
92 menu->mark.length = strlen(mark);
95 _menui_max_item_size(menu);
100 * Return the menu mark string for the menu.
103 menu_mark(MENU *menu)
105 if (menu == NULL)
108 return menu->mark.string;
112 * Set the menu unmark character
117 MENU *menu = m;
119 if (m == NULL) menu = &_menui_default_menu;
122 if (menu->unmark.string != NULL) free(menu->unmark.string);
124 if ((menu->unmark.string = (char *) malloc(strlen(mark) + 1)) == NULL)
127 strcpy(menu->unmark.string, mark);
128 menu->unmark.length = strlen(mark);
130 _menui_max_item_size(menu);
135 * Return the menu unmark string for the menu.
138 menu_unmark(MENU *menu)
140 if (menu == NULL)
143 return menu->unmark.string;
147 * Set the menu window to the window passed.
150 set_menu_win(MENU *menu, WINDOW *win)
152 if (menu == NULL) {
156 if (menu->posted == TRUE) {
159 menu->menu_win = win;
160 menu->scrwin = win;
168 * Return the pointer to the menu window
171 menu_win(MENU *menu)
173 if (menu == NULL)
176 return menu->menu_win;
180 * Set the menu subwindow for the menu.
183 set_menu_sub(MENU *menu, WINDOW *sub)
185 if (menu == NULL) {
189 if (menu->posted == TRUE)
192 menu->menu_subwin = sub;
193 menu->scrwin = sub;
200 * Return the subwindow pointer for the menu
203 menu_sub(MENU *menu)
205 if (menu == NULL)
208 return menu->menu_subwin;
217 MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
219 menu->rows = rows;
220 menu->cols = cols;
222 if (menu->items != NULL)
224 return _menui_stitch_items(menu);
235 MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
237 *rows = menu->rows;
238 *cols = menu->cols;
242 * Set the user defined function to call when a menu is posted.
245 set_menu_init(MENU *menu, Menu_Hook func)
247 if (menu == NULL)
250 menu->menu_init = func;
255 * Return the pointer to the menu init function.
258 menu_init(MENU *menu)
260 if (menu == NULL)
263 return menu->menu_init;
267 * Set the user defined function called when a menu is unposted.
270 set_menu_term(MENU *menu, Menu_Hook func)
272 if (menu == NULL)
275 menu->menu_term = func;
280 * Return the user defined menu termination function pointer.
283 menu_term(MENU *menu)
285 if (menu == NULL)
288 return menu->menu_term;
292 * Return the current menu options set.
295 menu_opts(MENU *menu)
297 if (menu == NULL)
300 return menu->opts;
304 * Set the menu options to the given options.
310 MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
311 OPTIONS old_opts = menu->opts;
313 menu->opts = opts;
319 if (((opts & O_RADIO) == O_RADIO) && (menu->items != NULL) &&
320 (menu->items[0] != NULL)) {
322 for (i = 0; i < menu->item_count; i++) {
323 if (menu->items[i]->selected == 1) {
327 menu->items[i]->selected = 0;
334 menu->items[0]->selected = 1;
337 if ((menu->opts & O_ROWMAJOR) != (old_opts & O_ROWMAJOR))
338 /* changed menu layout - need to recalc neighbours */
339 _menui_stitch_items(menu);
345 * Turn on the options in menu given by opts.
351 MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
352 OPTIONS old_opts = menu->opts;
354 menu->opts |= opts;
360 if (((opts & O_RADIO) == O_RADIO) && (menu->items != NULL) &&
361 (menu->items[0] != NULL)) {
363 for (i = 0; i < menu->item_count; i++) {
364 if (menu->items[i]->selected == 1) {
368 menu->items[i]->selected = 0;
374 menu->items[0]->selected = 1;
377 if ((menu->items != NULL) &&
378 (menu->opts & O_ROWMAJOR) != (old_opts & O_ROWMAJOR))
379 /* changed menu layout - need to recalc neighbours */
380 _menui_stitch_items(menu);
386 * Turn off the menu options given in opts.
391 MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
392 OPTIONS old_opts = menu->opts;
394 menu->opts &= ~(opts);
396 if ((menu->items != NULL ) &&
397 (menu->opts & O_ROWMAJOR) != (old_opts & O_ROWMAJOR))
398 /* changed menu layout - need to recalc neighbours */
399 _menui_stitch_items(menu);
405 * Return the menu pattern buffer.
408 menu_pattern(MENU *menu)
410 if (menu == NULL)
413 return menu->pattern;
417 * Set the menu pattern buffer to pat and attempt to match the pattern in
423 MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
430 if ((menu->pattern = (char *) realloc(menu->pattern,
434 strcpy(menu->pattern, pat);
435 menu->plen = strlen(pat);
438 return _menui_match_items(menu, MATCH_FORWARD, &menu->cur_item);
442 * Allocate a new menu structure and fill it in.
509 * Free up storage allocated to the menu object and destroy it.
512 free_menu(MENU *menu)
516 if (menu == NULL)
519 if (menu->posted != 0)
522 if (menu->pattern != NULL)
523 free(menu->pattern);
525 if (menu->mark.string != NULL)
526 free(menu->mark.string);
528 if (menu->items != NULL) {
529 /* disconnect the items from this menu */
530 for (i = 0; i < menu->item_count; i++) {
531 menu->items[i]->parent = NULL;
535 free(menu);
540 * Calculate the minimum window size for the menu.
545 MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
547 if (menu->items == NULL)
551 _menui_max_item_size(menu);
553 *rows = menu->rows;
554 *cols = menu->cols * menu->max_item_width;
559 *cols += (menu->cols - 1);
565 * Set the menu item list to the one given.
570 MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
573 /* don't change if menu is posted */
574 if (menu->posted == 1)
580 (items[new_count]->parent != menu))
588 * don't allow multiple selected items if menu is radio
591 if (((menu->opts & O_RADIO) == O_RADIO) &&
596 if (menu->items != NULL) {
597 for (i = 0; i < menu->item_count; i++) {
598 menu->items[i]->parent = NULL;
599 menu->items[i]->index = -1;
603 menu->item_count = new_count;
605 /* connect the new items to the menu */
607 items[i]->parent = menu;
611 menu->items = items;
612 menu->cur_item = 0; /* reset current item just in case */
613 menu->top_row = 0; /* and the top row too */
614 if (menu->pattern != NULL) { /* and the pattern buffer....sigh */
615 free(menu->pattern);
616 menu->plen = 0;
617 menu->match_len = 0;
622 * button style menu.
624 if (((menu->opts & O_RADIO) == O_RADIO) && (sel_count == 0))
625 menu->items[0]->selected = 1;
628 _menui_stitch_items(menu); /* recalculate the item neighbours */
634 * Return the pointer to the menu items array.
637 menu_items(MENU *menu)
639 if (menu == NULL)
642 return menu->items;
646 * Return the count of items connected to the menu
649 item_count(MENU *menu)
651 if (menu == NULL)
654 return menu->item_count;
658 * Set the menu top row to be the given row. The current item becomes the
659 * leftmost item on that row in the menu.
664 MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
667 if (row > menu->item_rows)
670 if (menu->items == NULL)
673 if (menu->in_init == 1)
678 for (i = 0; i < menu->item_count; i++) {
681 if (row == menu->items[i]->row) {
688 menu->in_init = 1; /* just in case we call the init/term routines */
690 if (menu->posted == 1) {
691 if (menu->menu_term != NULL)
692 menu->menu_term(menu);
693 if (menu->item_term != NULL)
694 menu->item_term(menu);
697 menu->cur_item = cur_item;
698 menu->top_row = row;
700 if (menu->posted == 1) {
701 if (menu->menu_init != NULL)
702 menu->menu_init(menu);
703 if (menu->item_init != NULL)
704 menu->item_init(menu);
707 menu->in_init = 0;
719 MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
721 if (menu->items == NULL)
724 return menu->top_row;
728 * Position the cursor at the correct place in the menu.
732 pos_menu_cursor(MENU *menu)
736 if (menu == NULL)
739 maxmark = max(menu->mark.length, menu->unmark.length);
740 movx = maxmark + (menu->items[menu->cur_item]->col
741 * (menu->col_width + 1));
743 if (menu->match_len > 0)
744 movx += menu->match_len - 1;
746 wmove(menu->scrwin,
747 menu->items[menu->cur_item]->row - menu->top_row, movx);