/****************************************************************************
- * Copyright (c) 2005-2012,2013 Free Software Foundation, Inc. *
+ * Copyright (c) 2005-2016,2017 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 *
* authorization. *
****************************************************************************/
/*
- * $Id: demo_menus.c,v 1.51 2013/09/07 16:20:08 tom Exp $
+ * $Id: demo_menus.c,v 1.65 2017/11/24 21:03:30 tom Exp $
*
* Demonstrate a variety of functions from the menu library.
* Thomas Dickey - 2005/4/9
#ifdef NCURSES_VERSION
#ifdef TRACE
static unsigned save_trace = TRACE_ORDINARY | TRACE_CALLS;
-extern unsigned _nc_tracing;
static MENU *mpTrace;
#endif
-#else
-#undef TRACE
#endif
typedef enum {
#define MENU_Y 1
typedef struct {
- const char *name;
+ NCURSES_CONST char *name;
void (*func) (int);
unsigned mask;
} MENU_DATA;
static bool loaded_file = FALSE;
+static char empty[1];
+static void failed(const char *s) GCC_NORETURN;
+
+static void
+failed(const char *s)
+{
+ perror(s);
+ endwin();
+ ExitProgram(EXIT_FAILURE);
+}
+
/* Common function to allow ^T to toggle trace-mode in the middle of a test
* so that trace-files can be made smaller.
*/
int result = 0;
if (okMenuNo(number)) {
- int spc_desc, spc_rows, spc_cols;
-
+ int spc_rows;
#ifdef NCURSES_VERSION
+ int spc_desc, spc_cols;
menu_spacing(mpBanner, &spc_desc, &spc_rows, &spc_cols);
#else
spc_rows = 0;
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);
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);
if ((count > 0) && (m == mpSelect)) {
if (blob && loaded_file) {
Trace(("freeing blob %p", blob));
- free((char *) blob);
+ free((void *) blob);
}
free(items);
items = 0;
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;
MENU_DATA *ap = 0;
MENU_DATA *myList = 0;
int i;
- unsigned count = 0;
+ size_t count = 0;
if (filename != 0) {
struct stat sb;
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;
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;
tracetrace(unsigned tlevel)
{
static char *buf;
+ static size_t need = 12;
int n;
if (buf == 0) {
- size_t need = 12;
for (n = 0; t_tbl[n].name != 0; n++)
need += strlen(t_tbl[n].name) + 2;
buf = typeMalloc(char, need);
+ if (!buf)
+ failed("tracetrace");
}
- sprintf(buf, "0x%02x = {", tlevel);
+ _nc_SPRINTF(buf, _nc_SLIMIT(need) "0x%02x = {", tlevel);
if (tlevel == 0) {
- sprintf(buf + strlen(buf), "%s, ", t_tbl[0].name);
+ _nc_STRCAT(buf, t_tbl[0].name, need);
+ _nc_STRCAT(buf, ", ", need);
} else {
for (n = 1; t_tbl[n].name != 0; n++)
if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
- strcat(buf, t_tbl[n].name);
- strcat(buf, ", ");
+ _nc_STRCAT(buf, t_tbl[n].name, need);
+ _nc_STRCAT(buf, ", ", need);
}
}
if (buf[strlen(buf) - 2] == ',')
buf[strlen(buf) - 2] = '\0';
- return (strcat(buf, "}"));
+ _nc_STRCAT(buf, "}", need);
+ return buf;
}
/* fake a dynamically reconfigurable menu using the 0th entry to deselect
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;
}
}
+#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)
{
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);
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);
#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;
}
beep();
continue;
}
-
-#ifdef NCURSES_MOUSE_VERSION
- mousemask(0, (mmask_t *) 0);
-#endif
}
static void
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':