X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=menu%2Fm_global.c;h=489987febaa161c3e2de483c06221fbf9af2fd99;hp=267c8564287739a33d91ff167dc68a339cfa83ee;hb=7503e8d82292a2a0a4d8bb55bdf3f8a203159f68;hpb=b94faec6aab7c3613c1e7d217f6df6f42d929234 diff --git a/menu/m_global.c b/menu/m_global.c index 267c8564..489987fe 100644 --- a/menu/m_global.c +++ b/menu/m_global.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 1998-2005,2009 Free Software Foundation, Inc. * + * Copyright 2020 Thomas E. Dickey * + * Copyright 1998-2012,2014 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 +38,7 @@ #include "menu.priv.h" -MODULE_ID("$Id: m_global.c,v 1.24 2009/02/28 21:02:46 juergen Exp $") +MODULE_ID("$Id: m_global.c,v 1.30 2020/02/02 23:34:34 tom Exp $") static char mark[] = "-"; /* *INDENT-OFF* */ @@ -53,7 +54,7 @@ NCURSES_EXPORT_VAR(MENU) _nc_Default_Menu = { 0, /* length of widest description */ 1, /* length of mark */ 1, /* length of one item */ - 1, /* Spacing for descriptor */ + 1, /* Spacing for descriptor */ 1, /* Spacing for columns */ 1, /* Spacing for rows */ (char *)0, /* buffer used to store match chars */ @@ -68,7 +69,7 @@ NCURSES_EXPORT_VAR(MENU) _nc_Default_Menu = { 0, /* Top row of menu */ (chtype)A_REVERSE, /* Attribute for selection */ (chtype)A_NORMAL, /* Attribute for nonselection */ - (chtype)A_UNDERLINE, /* Attribute for inactive */ + (chtype)A_UNDERLINE, /* Attribute for inactive */ ' ', /* Pad character */ (Menu_Hook)0, /* Menu init */ (Menu_Hook)0, /* Menu term */ @@ -77,7 +78,7 @@ NCURSES_EXPORT_VAR(MENU) _nc_Default_Menu = { (void *)0, /* userptr */ mark, /* mark */ ALL_MENU_OPTS, /* options */ - 0 /* status */ + 0 /* status */ }; NCURSES_EXPORT_VAR(ITEM) _nc_Default_Item = { @@ -98,9 +99,9 @@ NCURSES_EXPORT_VAR(ITEM) _nc_Default_Item = { /* *INDENT-ON* */ /*--------------------------------------------------------------------------- -| Facility : libnmenu +| Facility : libnmenu | Function : static void ComputeMaximum_NameDesc_Lenths(MENU *menu) -| +| | Description : Calculates the maximum name and description lengths | of the items connected to the menu | @@ -117,25 +118,25 @@ ComputeMaximum_NameDesc_Lengths(MENU * menu) assert(menu && menu->items); for (items = menu->items; *items; items++) { - check = _nc_Calculate_Text_Width(&((*items)->name)); + check = (unsigned)_nc_Calculate_Text_Width(&((*items)->name)); if (check > MaximumNameLength) MaximumNameLength = check; - check = _nc_Calculate_Text_Width(&((*items)->description)); + check = (unsigned)_nc_Calculate_Text_Width(&((*items)->description)); if (check > MaximumDescriptionLength) MaximumDescriptionLength = check; } - menu->namelen = MaximumNameLength; - menu->desclen = MaximumDescriptionLength; + menu->namelen = (short)MaximumNameLength; + menu->desclen = (short)MaximumDescriptionLength; T(("ComputeMaximum_NameDesc_Lengths %d,%d", menu->namelen, menu->desclen)); } /*--------------------------------------------------------------------------- -| Facility : libnmenu +| Facility : libnmenu | Function : static void ResetConnectionInfo(MENU *, ITEM **) -| -| Description : Reset all informations in the menu and the items in +| +| Description : Reset all information in the menu and the items in | the item array that indicates a connection | | Return Values : - @@ -160,7 +161,7 @@ ResetConnectionInfo(MENU * menu, ITEM ** items) } /*--------------------------------------------------------------------------- -| Facility : libnmenu +| Facility : libnmenu | Function : bool _nc_Connect_Items(MENU *menu, ITEM **items) | | Description : Connect the items in the item array to the menu. @@ -195,7 +196,7 @@ _nc_Connect_Items(MENU * menu, ITEM ** items) { (*item)->value = FALSE; } - (*item)->index = ItemCount++; + (*item)->index = (short)ItemCount++; (*item)->imenu = menu; } } @@ -206,7 +207,7 @@ _nc_Connect_Items(MENU * menu, ITEM ** items) if (ItemCount != 0) { menu->items = items; - menu->nitems = ItemCount; + menu->nitems = (short)ItemCount; ComputeMaximum_NameDesc_Lengths(menu); if ((menu->pattern = typeMalloc(char, (unsigned)(1 + menu->namelen)))) { @@ -218,16 +219,16 @@ _nc_Connect_Items(MENU * menu, ITEM ** items) } } - /* If we fall through to this point, we have to reset all items connection + /* If we fall through to this point, we have to reset all items connection and inform about a reject connection */ ResetConnectionInfo(menu, items); return (FALSE); } /*--------------------------------------------------------------------------- -| Facility : libnmenu +| Facility : libnmenu | Function : void _nc_Disconnect_Items(MENU *menu) -| +| | Description : Disconnect the menus item array from the menu | | Return Values : - @@ -240,9 +241,9 @@ _nc_Disconnect_Items(MENU * menu) } /*--------------------------------------------------------------------------- -| Facility : libnmenu +| Facility : libnmenu | Function : int _nc_Calculate_Text_Width(const TEXT * item) -| +| | Description : Calculate the number of columns for a TEXT. | | Return Values : the width @@ -253,10 +254,10 @@ _nc_Calculate_Text_Width(const TEXT * item /*FIXME: limit length */ ) #if USE_WIDEC_SUPPORT int result = item->length; - T((T_CALLED("_nc_menu_text_width(%p)"), item)); + T((T_CALLED("_nc_menu_text_width(%p)"), (const void *)item)); if (result != 0 && item->str != 0) { - int count = mbstowcs(0, item->str, 0); + int count = (int)mbstowcs(0, item->str, 0); wchar_t *temp = 0; if (count > 0 @@ -328,9 +329,9 @@ calculate_actual_width(MENU * menu, bool name) #endif /*--------------------------------------------------------------------------- -| Facility : libnmenu +| Facility : libnmenu | Function : void _nc_Calculate_Item_Length_and_Width(MENU *menu) -| +| | Description : Calculate the length of an item and the width of the | whole menu. | @@ -343,7 +344,7 @@ _nc_Calculate_Item_Length_and_Width(MENU * menu) assert(menu); - menu->height = 1 + menu->spc_rows * (menu->arows - 1); + menu->height = (short)(1 + menu->spc_rows * (menu->arows - 1)); l = calculate_actual_width(menu, TRUE); l += menu->marklen; @@ -354,10 +355,10 @@ _nc_Calculate_Item_Length_and_Width(MENU * menu) l += menu->spc_desc; } - menu->itemlen = l; + menu->itemlen = (short)l; l *= menu->cols; l += (menu->cols - 1) * menu->spc_cols; /* for the padding between the columns */ - menu->width = l; + menu->width = (short)l; T(("_nc_CalculateItem_Length_and_Width columns %d, item %d, width %d", menu->cols, @@ -366,9 +367,9 @@ _nc_Calculate_Item_Length_and_Width(MENU * menu) } /*--------------------------------------------------------------------------- -| Facility : libnmenu +| Facility : libnmenu | Function : void _nc_Link_Item(MENU *menu) -| +| | Description : Statically calculate for every item its four neighbors. | This depends on the orientation of the menu. This | static approach simplifies navigation in the menu a lot. @@ -388,7 +389,7 @@ _nc_Link_Items(MENU * menu) int Last_in_Column; bool cycle = (menu->opt & O_NONCYCLIC) ? FALSE : TRUE; - menu->status &= ~_LINK_NEEDED; + ClrStatus(menu, _LINK_NEEDED); if (menu->opt & O_ROWMAJOR) { @@ -431,8 +432,8 @@ _nc_Link_Items(MENU * menu) (cycle ? menu->items[(row + 1) < menu->rows ? Number_Of_Items - 1 : col] : (ITEM *) 0); - item->x = col; - item->y = row; + item->x = (short)col; + item->y = (short)row; if (++col == Number_Of_Columns) { row++; @@ -482,8 +483,8 @@ _nc_Link_Items(MENU * menu) (ITEM *) 0 ); - item->x = col; - item->y = row; + item->x = (short)col; + item->y = (short)row; if ((++row) == Number_Of_Rows) { col++; @@ -495,9 +496,9 @@ _nc_Link_Items(MENU * menu) } /*--------------------------------------------------------------------------- -| Facility : libnmenu +| Facility : libnmenu | Function : void _nc_Show_Menu(const MENU* menu) -| +| | Description : Update the window that is associated with the menu | | Return Values : - @@ -530,12 +531,12 @@ _nc_Show_Menu(const MENU * menu) } /*--------------------------------------------------------------------------- -| Facility : libnmenu +| Facility : libnmenu | Function : void _nc_New_TopRow_and_CurrentItem( -| MENU *menu, -| int new_toprow, +| MENU *menu, +| int new_toprow, | ITEM *new_current_item) -| +| | Description : Redisplay the menu so that the given row becomes the | top row and the given item becomes the new current | item. @@ -568,7 +569,9 @@ _nc_New_TopRow_and_CurrentItem( cur_item = menu->curitem; assert(cur_item); - menu->toprow = new_toprow; + menu->toprow = (short)(((menu->rows - menu->frows) >= 0) + ? min(menu->rows - menu->frows, new_toprow) + : 0); menu->curitem = new_current_item; if (mterm_called) @@ -590,7 +593,9 @@ _nc_New_TopRow_and_CurrentItem( } else { /* if we are not posted, this is quite simple */ - menu->toprow = new_toprow; + menu->toprow = (short)(((menu->rows - menu->frows) >= 0) + ? min(menu->rows - menu->frows, new_toprow) + : 0); menu->curitem = new_current_item; } }