/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2012,2014 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
#include "menu.priv.h"
-MODULE_ID("$Id: m_global.c,v 1.31 2020/05/24 01:40:20 anonymous.maarten Exp $")
+MODULE_ID("$Id: m_global.c,v 1.33 2021/03/27 23:46:29 tom Exp $")
static char mark[] = "-";
/* *INDENT-OFF* */
| Return Values : -
+--------------------------------------------------------------------------*/
NCURSES_INLINE static void
-ComputeMaximum_NameDesc_Lengths(MENU * menu)
+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++)
{
- check = (unsigned)_nc_Calculate_Text_Width(&((*items)->name));
+ unsigned check = (unsigned)_nc_Calculate_Text_Width(&((*items)->name));
+
if (check > MaximumNameLength)
MaximumNameLength = check;
| Return Values : -
+--------------------------------------------------------------------------*/
NCURSES_INLINE static void
-ResetConnectionInfo(MENU * menu, ITEM ** items)
+ResetConnectionInfo(MENU *menu, ITEM **items)
{
ITEM **item;
for (item = items; *item; item++)
{
(*item)->index = 0;
- (*item)->imenu = (MENU *) 0;
+ (*item)->imenu = (MENU *)0;
}
if (menu->pattern)
free(menu->pattern);
menu->pattern = (char *)0;
menu->pindex = 0;
- menu->items = (ITEM **) 0;
+ menu->items = (ITEM **)0;
menu->nitems = 0;
}
| FALSE - connection failed
+--------------------------------------------------------------------------*/
MENU_EXPORT(bool)
-_nc_Connect_Items(MENU * menu, ITEM ** items)
+_nc_Connect_Items(MENU *menu, ITEM **items)
{
- ITEM **item;
unsigned int ItemCount = 0;
if (menu && items)
{
+ ITEM **item;
+
for (item = items; *item; item++)
{
if ((*item)->imenu)
| Return Values : -
+--------------------------------------------------------------------------*/
MENU_EXPORT(void)
-_nc_Disconnect_Items(MENU * menu)
+_nc_Disconnect_Items(MENU *menu)
{
if (menu && menu->items)
ResetConnectionInfo(menu, menu->items);
| Return Values : the width
+--------------------------------------------------------------------------*/
MENU_EXPORT(int)
-_nc_Calculate_Text_Width(const TEXT * item /*FIXME: limit length */ )
+_nc_Calculate_Text_Width(const TEXT *item /*FIXME: limit length */ )
{
#if USE_WIDEC_SUPPORT
int result = item->length;
*/
#if USE_WIDEC_SUPPORT
static int
-calculate_actual_width(MENU * menu, bool name)
+calculate_actual_width(MENU *menu, bool name)
{
int width = 0;
- int check = 0;
- ITEM **items;
assert(menu && menu->items);
if (menu->items != 0)
{
+ ITEM **items;
+
for (items = menu->items; *items; items++)
{
- if (name)
- {
- check = _nc_Calculate_Text_Width(&((*items)->name));
- }
- else
- {
- check = _nc_Calculate_Text_Width(&((*items)->description));
- }
+ int check = (name
+ ? _nc_Calculate_Text_Width(&((*items)->name))
+ : _nc_Calculate_Text_Width(&((*items)->description)));
+
if (check > width)
width = check;
}
| Return Values : -
+--------------------------------------------------------------------------*/
MENU_EXPORT(void)
-_nc_Calculate_Item_Length_and_Width(MENU * menu)
+_nc_Calculate_Item_Length_and_Width(MENU *menu)
{
int l;
| Return Values : -
+--------------------------------------------------------------------------*/
MENU_EXPORT(void)
-_nc_Link_Items(MENU * menu)
+_nc_Link_Items(MENU *menu)
{
if (menu && menu->items && *(menu->items))
{
- int i, j;
+ int i;
ITEM *item;
int Number_Of_Items = menu->nitems;
int col = 0, row = 0;
(cycle ? menu->items[(Last_in_Row >= Number_Of_Items) ?
Number_Of_Items - 1 :
Last_in_Row] :
- (ITEM *) 0);
+ (ITEM *)0);
item->right = ((col < (Number_Of_Columns - 1)) &&
((i + 1) < Number_Of_Items)
)?
menu->items[i + 1] :
(cycle ? menu->items[row * Number_Of_Columns] :
- (ITEM *) 0
+ (ITEM *)0
);
Last_in_Column = (menu->rows - 1) * Number_Of_Columns + col;
(cycle ? menu->items[(Last_in_Column >= Number_Of_Items) ?
Number_Of_Items - 1 :
Last_in_Column] :
- (ITEM *) 0);
+ (ITEM *)0);
item->down = ((i + Number_Of_Columns) < Number_Of_Items)
?
menu->items[i + Number_Of_Columns] :
(cycle ? menu->items[(row + 1) < menu->rows ?
Number_Of_Items - 1 : col] :
- (ITEM *) 0);
+ (ITEM *)0);
item->x = (short)col;
item->y = (short)row;
if (++col == Number_Of_Columns)
else
{
int Number_Of_Rows = menu->rows;
+ int j;
for (j = 0; j < Number_Of_Items; j++)
{
(cycle ? (Last_in_Column >= Number_Of_Items) ?
menu->items[Last_in_Column - Number_Of_Rows] :
menu->items[Last_in_Column] :
- (ITEM *) 0);
+ (ITEM *)0);
item->right = ((i + Number_Of_Rows) < Number_Of_Items)
?
menu->items[i + Number_Of_Rows] :
- (cycle ? menu->items[row] : (ITEM *) 0);
+ (cycle ? menu->items[row] : (ITEM *)0);
Last_in_Row = col * Number_Of_Rows + (Number_Of_Rows - 1);
menu->items[(Last_in_Row >= Number_Of_Items) ?
Number_Of_Items - 1 :
Last_in_Row] :
- (ITEM *) 0);
+ (ITEM *)0);
item->down = (row < (Number_Of_Rows - 1))
?
(col - 1) * Number_Of_Rows + row + 1]) :
(cycle ?
menu->items[col * Number_Of_Rows] :
- (ITEM *) 0
+ (ITEM *)0
);
item->x = (short)col;
| Return Values : -
+--------------------------------------------------------------------------*/
MENU_EXPORT(void)
-_nc_Show_Menu(const MENU * menu)
+_nc_Show_Menu(const MENU *menu)
{
- WINDOW *win;
- int maxy, maxx;
-
assert(menu);
if ((menu->status & _POSTED) && !(menu->status & _IN_DRIVER))
{
+ WINDOW *win;
+ int maxy, maxx;
+
/* adjust the internal subwindow to start on the current top */
assert(menu->sub);
mvderwin(menu->sub, menu->spc_rows * menu->toprow, 0);
+--------------------------------------------------------------------------*/
MENU_EXPORT(void)
_nc_New_TopRow_and_CurrentItem(
- MENU * menu,
+ MENU *menu,
int new_toprow,
- ITEM * new_current_item)
+ ITEM *new_current_item)
{
- ITEM *cur_item;
- bool mterm_called = FALSE;
- bool iterm_called = FALSE;
-
assert(menu);
if (menu->status & _POSTED)
{
+ ITEM *cur_item;
+ bool mterm_called = FALSE;
+ bool iterm_called = FALSE;
+
if (new_current_item != menu->curitem)
{
Call_Hook(menu, itemterm);