X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=menu%2Fm_global.c;h=90f6f25925b7fcfd2b60c99b74956dd7e99a4729;hp=5aeb021f7edd442afd2e822f11668f6641d113c2;hb=9d7a689764468c4dcea1fa7ffc6a2b37b8740330;hpb=55ccd2b959766810cf7db8d1c4462f338ce0afc8;ds=sidebyside diff --git a/menu/m_global.c b/menu/m_global.c index 5aeb021f..90f6f259 100644 --- a/menu/m_global.c +++ b/menu/m_global.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc. * + * Copyright (c) 1998-2009,2010 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 * @@ -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.25 2010/01/23 21:20:10 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) + T((T_CALLED("_nc_menu_text_width(%p)"), (const void *)item)); + 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 @@ -482,7 +496,7 @@ _nc_Link_Items(MENU * menu) /*--------------------------------------------------------------------------- | Facility : libnmenu -| Function : void _nc_Show_Menu(const MENU *menu) +| Function : void _nc_Show_Menu(const MENU* menu) | | Description : Update the window that is associated with the menu | @@ -529,8 +543,10 @@ _nc_Show_Menu(const MENU * menu) | Return Values : - +--------------------------------------------------------------------------*/ NCURSES_EXPORT(void) - _nc_New_TopRow_and_CurrentItem - (MENU * menu, int new_toprow, ITEM * new_current_item) +_nc_New_TopRow_and_CurrentItem( + MENU * menu, + int new_toprow, + ITEM * new_current_item) { ITEM *cur_item; bool mterm_called = FALSE;