#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* */
|
| 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;
|
| Return Values : -
+--------------------------------------------------------------------------*/
-INLINE static void
+NCURSES_INLINE static void
ResetConnectionInfo(MENU * menu, ITEM ** items)
{
ITEM **item;
{
#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
#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)
{
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