X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fdemo_menus.c;h=7fe0ea37394dab003ead0e3b3e9eb243f83c8a71;hp=28a34a1c9979a3dcc7bf6b71f19fa11a5b90d41b;hb=3e0f770501852be3a2cb05d8044219d7b04dbfad;hpb=73b54c0812e4b8dfddcf87f59c7488bb3c10e10d diff --git a/test/demo_menus.c b/test/demo_menus.c index 28a34a1c..7fe0ea37 100644 --- a/test/demo_menus.c +++ b/test/demo_menus.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2005-2013,2014 Free Software Foundation, Inc. * + * Copyright (c) 2005-2015,2016 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: demo_menus.c,v 1.53 2014/08/02 17:24:07 tom Exp $ + * $Id: demo_menus.c,v 1.59 2016/03/27 00:02:01 tom Exp $ * * Demonstrate a variety of functions from the menu library. * Thomas Dickey - 2005/4/9 @@ -97,7 +97,7 @@ typedef enum { #define MENU_Y 1 typedef struct { - const char *name; + NCURSES_CONST char *name; void (*func) (int); unsigned mask; } MENU_DATA; @@ -112,6 +112,8 @@ static WINDOW *status; static bool loaded_file = FALSE; +static char empty[1]; + /* Common function to allow ^T to toggle trace-mode in the middle of a test * so that trace-files can be made smaller. */ @@ -268,13 +270,6 @@ menu_create(ITEM ** items, int count, int ncols, MenuNo number) if (mcols + (2 * margin + x) >= COLS) mcols = COLS - (2 * margin + x); -#ifdef TRACE - if (number == eTrace) - menu_opts_off(result, O_ONEVALUE); - else - menu_opts_on(result, O_ONEVALUE); -#endif - menuwin = newwin(mrows + (2 * margin), mcols + (2 * margin), y, x); set_menu_win(result, menuwin); keypad(menuwin, TRUE); @@ -283,6 +278,16 @@ menu_create(ITEM ** items, int count, int ncols, MenuNo number) set_menu_sub(result, derwin(menuwin, mrows, mcols, margin, margin)); +#ifdef TRACE + if (number == eTrace) + menu_opts_off(result, O_ONEVALUE); + else + menu_opts_on(result, O_ONEVALUE); +#endif +#if defined(NCURSES_MOUSE_VERSION) && defined(O_MOUSE_MENU) + menu_opts_on(result, O_MOUSE_MENU); +#endif + post_menu(result); set_menu_init(result, my_menu_init); @@ -356,8 +361,8 @@ build_file_menu(MenuNo number) int n; for (n = 0; table[n].name != 0; ++n) { - *ip = new_item(table[n].name, ""); - set_item_userptr(*ip, &table[n]); + *ip = new_item(table[n].name, empty); + set_item_userptr(*ip, (void *) &table[n]); ++ip; } *ip = (ITEM *) 0; @@ -464,8 +469,8 @@ build_select_menu(MenuNo number, char *filename) for (i = 0; ap[i].name != 0; ++i) { ap[i].func = call_select; ap[i].mask = (unsigned) i; - *ip = new_item(ap[i].name, ""); - set_item_userptr(*ip, &table[i]); + *ip = new_item(ap[i].name, empty); + set_item_userptr(*ip, (void *) &table[i]); ++ip; } *ip = 0; @@ -526,8 +531,8 @@ build_trace_menu(MenuNo number) int n; for (n = 0; t_tbl[n].name != 0; n++) { - *ip = new_item(t_tbl[n].name, ""); - set_item_userptr(*ip, &t_tbl[n]); + *ip = new_item(t_tbl[n].name, empty); + set_item_userptr(*ip, (void *) &t_tbl[n]); ++ip; } *ip = (ITEM *) 0; @@ -683,8 +688,8 @@ build_menus(char *filename) int n; for (n = 0; table[n].name != 0; ++n) { - *ip = new_item(table[n].name, ""); - set_item_userptr(*ip, &table[n]); + *ip = new_item(table[n].name, empty); + set_item_userptr(*ip, (void *) &table[n]); ++ip; } *ip = (ITEM *) 0; @@ -749,6 +754,36 @@ move_menus(MENU * current, int by_y, int by_x) } } +#ifdef KEY_RESIZE +static void +resize_menu(MENU ** menu) +{ +#if 0 + WINDOW *win = menu_win(*menu); + WINDOW *sub = menu_sub(*menu); +#endif + (void) menu; +} + +static void +resize_menus(MENU * current) +{ + (void) current; + + werase(status); + wnoutrefresh(status); + wresize(status, 1, COLS); + mvwin(status, LINES - 1, 0); + + resize_menu(&mpBanner); + resize_menu(&mpFile); + resize_menu(&mpSelect); +#ifdef TRACE + resize_menu(&mpTrace); +#endif +} +#endif + static void show_status(int ch, MENU * menu) { @@ -772,7 +807,7 @@ perform_menus(void) int ch = ERR; #ifdef NCURSES_MOUSE_VERSION - mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0); + mousemask(BUTTON1_CLICKED, (mmask_t *) 0); #endif menu_display(last_menu); @@ -801,6 +836,11 @@ perform_menus(void) case KEY_SRIGHT: move_menus(last_menu, 0, 1); continue; +#ifdef KEY_RESIZE + case KEY_RESIZE: + resize_menus(last_menu); + continue; +#endif } cmd = menu_virtualize(ch); @@ -834,9 +874,17 @@ perform_menus(void) #endif } +#if defined(NCURSES_MOUSE_VERSION) && defined(O_MOUSE_MENU) if ((code == E_REQUEST_DENIED) && (cmd == KEY_MOUSE)) { + (void) menu_getc(mpBanner); code = menu_driver(mpBanner, cmd); + if (code == E_REQUEST_DENIED) { + MEVENT event; + if (menu_getc(mpBanner) == KEY_MOUSE) + getmouse(&event); /* give up */ + } } +#endif break; } @@ -866,10 +914,6 @@ perform_menus(void) beep(); continue; } - -#ifdef NCURSES_MOUSE_VERSION - mousemask(0, (mmask_t *) 0); -#endif } static void @@ -948,7 +992,7 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); - while ((c = getopt(argc, argv, "a:de:fhmp:s:t:")) != -1) { + while ((c = getopt(argc, argv, "fht:")) != -1) { switch (c) { #if HAVE_RIPOFFLINE case 'f':