]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/demo_menus.c
ncurses 5.8 - patch 20110307
[ncurses.git] / test / demo_menus.c
index fc7c89358ac3e467ad9cf111d8990e44e09819ab..4f758079e793998d8e27873963b250941490fe84 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2005-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 2005-2010,2011 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.27 2008/08/04 15:37:52 tom Exp $
+ * $Id: demo_menus.c,v 1.32 2011/01/15 20:02:47 tom Exp $
  *
  * Demonstrate a variety of functions from the menu library.
  * Thomas Dickey - 2005/4/9
@@ -107,6 +107,8 @@ static MENU *mpBanner;
 static MENU *mpFile;
 static MENU *mpSelect;
 
+static bool loaded_file = FALSE;
+
 #if !HAVE_STRDUP
 #define strdup my_strdup
 static char *
@@ -200,7 +202,7 @@ menu_offset(MenuNo number)
 #endif
 
        /* FIXME: MENU.itemlen seems the only way to get actual width of items */
-       result = (number - (eBanner + 1)) * (mpBanner->itemlen + spc_rows);
+       result = (number - (eBanner + 1)) * (menu_itemwidth(mpBanner) + spc_rows);
     }
     return result;
 }
@@ -258,13 +260,13 @@ menu_destroy(MENU * m)
 {
     int count;
 
-    Trace(("menu_destroy %p", m));
+    Trace(("menu_destroy %p", (void *) m));
     if (m != 0) {
        ITEM **items = menu_items(m);
        const char *blob = 0;
 
        count = item_count(m);
-       Trace(("menu_destroy %p count %d", m, count));
+       Trace(("menu_destroy %p count %d", (void *) m, count));
        if ((count > 0) && (m == mpSelect)) {
            blob = item_name(*items);
        }
@@ -274,7 +276,7 @@ menu_destroy(MENU * m)
 
        /* free the extra data allocated in build_select_menu() */
        if ((count > 0) && (m == mpSelect)) {
-           if (blob) {
+           if (blob && loaded_file) {
                Trace(("freeing blob %p", blob));
                free((char *) blob);
            }
@@ -366,7 +368,9 @@ build_select_menu(MenuNo number, char *filename)
            CONST_MENUS char **list = typeCalloc(CONST_MENUS char *, size + 1);
 
            items = typeCalloc(ITEM *, size + 1);
-           Trace(("build_select_menu blob=%p, items=%p", blob, items));
+           Trace(("build_select_menu blob=%p, items=%p",
+                  (void *) blob,
+                  (void *) items));
            if (blob != 0 && list != 0) {
                FILE *fp = fopen(filename, "r");
                if (fp != 0) {
@@ -392,6 +396,7 @@ build_select_menu(MenuNo number, char *filename)
                    }
                    fclose(fp);
                }
+               loaded_file = TRUE;
            }
        }
     }
@@ -541,8 +546,8 @@ perform_trace_menu(int cmd)
            trace(newtrace);
            Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
 
-           (void) mvprintw(LINES - 2, 0,
-                           "Trace level is %s\n", tracetrace(_nc_tracing));
+           MvPrintw(LINES - 2, 0,
+                    "Trace level is %s\n", tracetrace(_nc_tracing));
            refresh();
        }
     }