]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - menu/m_global.c
ncurses 5.6 - patch 20080925
[ncurses.git] / menu / m_global.c
index 5aeb021f7edd442afd2e822f11668f6641d113c2..28e836dd644e01a5eb009c4c46818e1be88326d4 100644 (file)
@@ -37,7 +37,7 @@
 
 #include "menu.priv.h"
 
-MODULE_ID("$Id: m_global.c,v 1.20 2005/04/16 17:30:57 tom Exp $")
+MODULE_ID("$Id: m_global.c,v 1.23 2005/12/31 21:51:52 tom Exp $")
 
 static char mark[] = "-";
 /* *INDENT-OFF* */
@@ -106,21 +106,24 @@ NCURSES_EXPORT_VAR(ITEM) _nc_Default_Item = {
 |
 |   Return Values :  -
 +--------------------------------------------------------------------------*/
-INLINE static void
+NCURSES_INLINE static void
 ComputeMaximum_NameDesc_Lengths(MENU * menu)
 {
   unsigned MaximumNameLength = 0;
   unsigned MaximumDescriptionLength = 0;
   ITEM **items;
+  unsigned check;
 
   assert(menu && menu->items);
   for (items = menu->items; *items; items++)
     {
-      if (items[0]->name.length > MaximumNameLength)
-       MaximumNameLength = items[0]->name.length;
+      check = _nc_Calculate_Text_Width(&((*items)->name));
+      if (check > MaximumNameLength)
+       MaximumNameLength = check;
 
-      if (items[0]->description.length > MaximumDescriptionLength)
-       MaximumDescriptionLength = items[0]->description.length;
+      check = _nc_Calculate_Text_Width(&((*items)->description));
+      if (check > MaximumDescriptionLength)
+       MaximumDescriptionLength = check;
     }
 
   menu->namelen = MaximumNameLength;
@@ -137,7 +140,7 @@ ComputeMaximum_NameDesc_Lengths(MENU * menu)
 |
 |   Return Values :  -
 +--------------------------------------------------------------------------*/
-INLINE static void
+NCURSES_INLINE static void
 ResetConnectionInfo(MENU * menu, ITEM ** items)
 {
   ITEM **item;
@@ -249,26 +252,30 @@ _nc_Calculate_Text_Width(const TEXT * item /*FIXME: limit length */ )
 {
 #if USE_WIDEC_SUPPORT
   int result = item->length;
-  int count = mbstowcs(0, item->str, 0);
-  wchar_t *temp = 0;
 
   T((T_CALLED("_nc_menu_text_width(%p)"), item));
-  if (count > 0
-      && (temp = typeMalloc(wchar_t, 2 + count)) != 0)
+  if (result != 0 && item->str != 0)
     {
-      int n;
+      int count = mbstowcs(0, item->str, 0);
+      wchar_t *temp = 0;
 
-      result = 0;
-      mbstowcs(temp, item->str, (unsigned)count);
-      for (n = 0; n < count; ++n)
+      if (count > 0
+         && (temp = typeMalloc(wchar_t, 2 + count)) != 0)
        {
-         int test = wcwidth(temp[n]);
+         int n;
 
-         if (test <= 0)
-           test = 1;
-         result += test;
+         result = 0;
+         mbstowcs(temp, item->str, (unsigned)count);
+         for (n = 0; n < count; ++n)
+           {
+             int test = wcwidth(temp[n]);
+
+             if (test <= 0)
+               test = 1;
+             result += test;
+           }
+         free(temp);
        }
-      free(temp);
     }
   returnCode(result);
 #else
@@ -276,10 +283,10 @@ _nc_Calculate_Text_Width(const TEXT * item /*FIXME: limit length */ )
 #endif
 }
 
-/* FIXME: this is experimental, should cache the results but don't want to
- * modify the MENU struct to do this until it's complete.
+/*
+ * Calculate the actual width of a menu entry for wide-characters.
  */
-#if 0                          /* USE_WIDEC_SUPPORT */
+#if USE_WIDEC_SUPPORT
 static int
 calculate_actual_width(MENU * menu, bool name)
 {
@@ -288,25 +295,32 @@ calculate_actual_width(MENU * menu, bool name)
   ITEM **items;
 
   assert(menu && menu->items);
-  for (items = menu->items; *items; items++)
+
+  if (menu->items != 0)
     {
-      if (name)
-       {
-         check = _nc_Calculate_Text_Width(&((*items)->name));
-       }
-      else
+      for (items = menu->items; *items; items++)
        {
-         check = _nc_Calculate_Text_Width(&((*items)->description));
+         if (name)
+           {
+             check = _nc_Calculate_Text_Width(&((*items)->name));
+           }
+         else
+           {
+             check = _nc_Calculate_Text_Width(&((*items)->description));
+           }
+         if (check > width)
+           width = check;
        }
-      if (check > width)
-       width = check;
+    }
+  else
+    {
+      width = (name ? menu->namelen : menu->desclen);
     }
 
   T(("calculate_actual_width %s = %d/%d",
      name ? "name" : "desc",
      width,
      name ? menu->namelen : menu->desclen));
-  width += 2;                  /* FIXME - need this? */
   return width;
 }
 #else