150276Speter/**************************************************************************** 2166124Srafan * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc. * 350276Speter * * 450276Speter * Permission is hereby granted, free of charge, to any person obtaining a * 550276Speter * copy of this software and associated documentation files (the * 650276Speter * "Software"), to deal in the Software without restriction, including * 750276Speter * without limitation the rights to use, copy, modify, merge, publish, * 850276Speter * distribute, distribute with modifications, sublicense, and/or sell * 950276Speter * copies of the Software, and to permit persons to whom the Software is * 1050276Speter * furnished to do so, subject to the following conditions: * 1150276Speter * * 1250276Speter * The above copyright notice and this permission notice shall be included * 1350276Speter * in all copies or substantial portions of the Software. * 1450276Speter * * 1550276Speter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 1650276Speter * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 1750276Speter * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 1850276Speter * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 1950276Speter * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 2050276Speter * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 2150276Speter * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 2250276Speter * * 2350276Speter * Except as contained in this notice, the name(s) of the above copyright * 2450276Speter * holders shall not be used in advertising or otherwise to promote the * 2550276Speter * sale, use or other dealings in this Software without prior written * 2650276Speter * authorization. * 2750276Speter ****************************************************************************/ 2850276Speter 2950276Speter/**************************************************************************** 30166124Srafan * Author: Juergen Pfeifer, 1995,1997 * 3150276Speter ****************************************************************************/ 3250276Speter 3350276Speter/*************************************************************************** 3450276Speter* Module m_format * 3550276Speter* Set and get maximum numbers of rows and columns in menus * 3650276Speter***************************************************************************/ 3750276Speter 3850276Speter#include "menu.priv.h" 3950276Speter 40166124SrafanMODULE_ID("$Id: m_format.c,v 1.15 2004/12/11 23:11:21 tom Exp $") 4150276Speter 4250276Speter#define minimum(a,b) ((a)<(b) ? (a): (b)) 4350276Speter 4450276Speter/*--------------------------------------------------------------------------- 45166124Srafan| Facility : libnmenu 4650276Speter| Function : int set_menu_format(MENU *menu, int rows, int cols) 47166124Srafan| 4850276Speter| Description : Sets the maximum number of rows and columns of items 4950276Speter| that may be displayed at one time on a menu. If the 5050276Speter| menu contains more items than can be displayed at 5150276Speter| once, the menu will be scrollable. 5250276Speter| 5350276Speter| Return Values : E_OK - success 5450276Speter| E_BAD_ARGUMENT - invalid values passed 5550276Speter| E_NOT_CONNECTED - there are no items connected 5650276Speter| E_POSTED - the menu is already posted 5750276Speter+--------------------------------------------------------------------------*/ 5876726SpeterNCURSES_EXPORT(int) 59166124Srafanset_menu_format(MENU * menu, int rows, int cols) 6050276Speter{ 6150276Speter int total_rows, total_cols; 62166124Srafan 63166124Srafan T((T_CALLED("set_menu_format(%p,%d,%d)"), menu, rows, cols)); 64166124Srafan 65166124Srafan if (rows < 0 || cols < 0) 6650276Speter RETURN(E_BAD_ARGUMENT); 67166124Srafan 6850276Speter if (menu) 6950276Speter { 70166124Srafan if (menu->status & _POSTED) 7150276Speter RETURN(E_POSTED); 72166124Srafan 7350276Speter if (!(menu->items)) 7450276Speter RETURN(E_NOT_CONNECTED); 75166124Srafan 76166124Srafan if (rows == 0) 7750276Speter rows = menu->frows; 78166124Srafan if (cols == 0) 7950276Speter cols = menu->fcols; 80166124Srafan 8150276Speter if (menu->pattern) 8250276Speter Reset_Pattern(menu); 83166124Srafan 8450276Speter menu->frows = rows; 8550276Speter menu->fcols = cols; 86166124Srafan 87166124Srafan assert(rows > 0 && cols > 0); 88166124Srafan total_rows = (menu->nitems - 1) / cols + 1; 89166124Srafan total_cols = (menu->opt & O_ROWMAJOR) ? 90166124Srafan minimum(menu->nitems, cols) : 91166124Srafan (menu->nitems - 1) / total_rows + 1; 92166124Srafan 93166124Srafan menu->rows = total_rows; 94166124Srafan menu->cols = total_cols; 95166124Srafan menu->arows = minimum(total_rows, rows); 96166124Srafan menu->toprow = 0; 9750276Speter menu->curitem = *(menu->items); 9850276Speter assert(menu->curitem); 9950276Speter menu->status |= _LINK_NEEDED; 10050276Speter _nc_Calculate_Item_Length_and_Width(menu); 10150276Speter } 10250276Speter else 10350276Speter { 104166124Srafan if (rows > 0) 105166124Srafan _nc_Default_Menu.frows = rows; 106166124Srafan if (cols > 0) 107166124Srafan _nc_Default_Menu.fcols = cols; 10850276Speter } 109166124Srafan 11050276Speter RETURN(E_OK); 11150276Speter} 11250276Speter 11350276Speter/*--------------------------------------------------------------------------- 114166124Srafan| Facility : libnmenu 11550276Speter| Function : void menu_format(const MENU *menu, int *rows, int *cols) 116166124Srafan| 11750276Speter| Description : Returns the maximum number of rows and columns that may 11850276Speter| be displayed at one time on menu. 11950276Speter| 12050276Speter| Return Values : - 12150276Speter+--------------------------------------------------------------------------*/ 12276726SpeterNCURSES_EXPORT(void) 123166124Srafanmenu_format(const MENU * menu, int *rows, int *cols) 12450276Speter{ 12550276Speter if (rows) 12650276Speter *rows = Normalize_Menu(menu)->frows; 12750276Speter if (cols) 12850276Speter *cols = Normalize_Menu(menu)->fcols; 12950276Speter} 13050276Speter 13150276Speter/* m_format.c ends here */ 132