1
/****************************************************************************
2
* Copyright (c) 2005,2006 Free Software Foundation, Inc. *
4
* Permission is hereby granted, free of charge, to any person obtaining a *
5
* copy of this software and associated documentation files (the *
6
* "Software"), to deal in the Software without restriction, including *
7
* without limitation the rights to use, copy, modify, merge, publish, *
8
* distribute, distribute with modifications, sublicense, and/or sell *
9
* copies of the Software, and to permit persons to whom the Software is *
10
* furnished to do so, subject to the following conditions: *
12
* The above copyright notice and this permission notice shall be included *
13
* in all copies or substantial portions of the Software. *
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23
* Except as contained in this notice, the name(s) of the above copyright *
24
* holders shall not be used in advertising or otherwise to promote the *
25
* sale, use or other dealings in this Software without prior written *
27
****************************************************************************/
2
* $Id: demo_menus.c,v 1.13 2005/10/01 15:54:31 tom Exp $
29
* $Id: demo_menus.c,v 1.20 2006/06/17 17:39:37 tom Exp $
4
31
* Demonstrate a variety of functions from the menu library.
5
32
* Thomas Dickey - 2005/4/9
185
213
int mrows, mcols;
186
int y = ((int) number >= 0) ? MENU_Y : 0;
214
int y = okMenuNo(number) ? MENU_Y : 0;
187
215
int x = menu_offset(number);
188
216
int margin = (y == MENU_Y) ? 1 : 0;
189
217
int maxcol = (ncols + x) < COLS ? ncols : (COLS - x - 1);
558
587
*ip++ = new_item(*ap, "");
559
588
*ip = (ITEM *) 0;
561
mpBanner = menu_create(items, SIZEOF(labels) - 1, SIZEOF(labels) - 1, eUnknown);
590
mpBanner = menu_create(items, SIZEOF(labels) - 1, SIZEOF(labels) - 1, eBanner);
562
591
set_menu_mark(mpBanner, ">");
564
593
build_file_menu(eFile);
601
move_menu(MENU * menu, MENU * current, int by_y, int by_x)
603
WINDOW *top_win = menu_win(menu);
604
WINDOW *sub_win = menu_sub(menu);
609
getbegyx(top_win, y0, x0);
613
getbegyx(sub_win, y1, x1);
617
if ((result = mvwin(top_win, y0, x0)) != ERR) {
618
#if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH < 20060218)
622
mvwin(sub_win, y1, x1);
624
if (menu == current) {
626
wnoutrefresh(top_win);
633
* Move the menus around on the screen, to test mvwin().
636
move_menus(MENU * current, int by_y, int by_x)
638
if (move_menu(mpBanner, current, by_y, by_x) != ERR) {
640
wnoutrefresh(stdscr);
641
move_menu(mpFile, current, by_y, by_x);
642
move_menu(mpSelect, current, by_y, by_x);
644
move_menu(mpTrace, current, by_y, by_x);
651
show_status(int ch, MENU * menu)
654
printw("key %s, menu %d, mark %s, match %s",
572
664
perform_menus(void)
575
667
MENU *last_menu = mpFile;
576
int code = E_UNKNOWN_COMMAND, cmd, ch;
668
int code = E_UNKNOWN_COMMAND;
578
672
#ifdef NCURSES_MOUSE_VERSION
579
673
mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
582
676
menu_display(last_menu);
681
show_status(ch, last_menu);
585
683
ch = menu_getc(mpBanner);
686
* Provide for moving the menu around in the screen using shifted
691
move_menus(last_menu, 1, 0);
694
move_menus(last_menu, -1, 0);
697
move_menus(last_menu, 0, -1);
700
move_menus(last_menu, 0, 1);
586
703
cmd = menu_virtualize(ch);
664
781
menu_destroy(mpBanner);
786
rip_footer(WINDOW *win, int cols)
788
wbkgd(win, A_REVERSE);
791
wprintw(win, "footer: %d columns", cols);
797
rip_header(WINDOW *win, int cols)
799
wbkgd(win, A_REVERSE);
802
wprintw(win, "header: %d columns", cols);
806
#endif /* HAVE_RIPOFFLINE */
811
static const char *const tbl[] =
813
"Usage: demo_menus [options]"
817
," -f rip-off footer line (can repeat)"
818
," -h rip-off header line (can repeat)"
821
," -t mask specify default trace-level (may toggle with ^T)"
825
for (n = 0; n < SIZEOF(tbl); n++)
826
fprintf(stderr, "%s\n", tbl[n]);
827
ExitProgram(EXIT_FAILURE);
668
831
main(int argc, char *argv[])
670
835
setlocale(LC_ALL, "");
837
while ((c = getopt(argc, argv, "a:de:fhmp:s:t:")) != EOF) {
841
ripoffline(-1, rip_footer);
844
ripoffline(1, rip_header);
846
#endif /* HAVE_RIPOFFLINE */
849
trace(strtoul(optarg, 0, 0));