1 /*-----------------------------------------------------------------------------+
2 | The ncurses menu library is Copyright (C) 1995-1997 |
3 | by Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> |
4 | All Rights Reserved. |
6 | Permission to use, copy, modify, and distribute this software and its |
7 | documentation for any purpose and without fee is hereby granted, provided |
8 | that the above copyright notice appear in all copies and that both that |
9 | copyright notice and this permission notice appear in supporting |
10 | documentation, and that the name of the above listed copyright holder(s) not |
11 | be used in advertising or publicity pertaining to distribution of the |
12 | software without specific, written prior permission. |
14 | THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO |
15 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- |
16 | NESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR |
17 | ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RE- |
18 | SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
19 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH |
20 | THE USE OR PERFORMANCE OF THIS SOFTWARE. |
21 +-----------------------------------------------------------------------------*/
23 /***************************************************************************
24 * Module menu_format *
25 * Set and get maximum numbers of rows and columns in menus *
26 ***************************************************************************/
28 #include "menu.priv.h"
30 MODULE_ID("$Id: m_format.c,v 1.5 1997/05/01 16:47:26 juergen Exp $")
32 #define minimum(a,b) ((a)<(b) ? (a): (b))
34 /*---------------------------------------------------------------------------
36 | Function : int set_menu_format(MENU *menu, int rows, int cols)
38 | Description : Sets the maximum number of rows and columns of items
39 | that may be displayed at one time on a menu. If the
40 | menu contains more items than can be displayed at
41 | once, the menu will be scrollable.
43 | Return Values : E_OK - success
44 | E_BAD_ARGUMENT - invalid values passed
45 | E_NOT_CONNECTED - there are no items connected
46 | E_POSTED - the menu is already posted
47 +--------------------------------------------------------------------------*/
48 int set_menu_format(MENU *menu, int rows, int cols)
50 int total_rows, total_cols;
53 RETURN(E_BAD_ARGUMENT);
57 if ( menu->status & _POSTED )
61 RETURN(E_NOT_CONNECTED);
74 assert(rows>0 && cols>0);
75 total_rows = (menu->nitems - 1)/cols + 1;
76 total_cols = (menu->status & O_ROWMAJOR) ?
77 minimum(menu->nitems,cols) :
78 (menu->nitems-1)/total_rows + 1;
80 menu->rows = total_rows;
81 menu->cols = total_cols;
82 menu->arows = minimum(total_rows,rows);
84 menu->curitem = *(menu->items);
85 assert(menu->curitem);
86 menu->status |= _LINK_NEEDED;
87 _nc_Calculate_Item_Length_and_Width(menu);
91 if (rows>0) _nc_Default_Menu.frows = rows;
92 if (cols>0) _nc_Default_Menu.fcols = cols;
98 /*---------------------------------------------------------------------------
100 | Function : void menu_format(const MENU *menu, int *rows, int *cols)
102 | Description : Returns the maximum number of rows and columns that may
103 | be displayed at one time on menu.
106 +--------------------------------------------------------------------------*/
107 void menu_format(const MENU *menu, int *rows, int *cols)
110 *rows = Normalize_Menu(menu)->frows;
112 *cols = Normalize_Menu(menu)->fcols;
115 /* m_format.c ends here */