1 /****************************************************************************
2 * Copyright (c) 1998 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> 1995,1997 *
31 ****************************************************************************/
33 /***************************************************************************
35 * Menus option routines *
36 ***************************************************************************/
38 #include "menu.priv.h"
40 MODULE_ID("$Id: m_opts.c,v 1.8 1998/02/11 12:13:49 tom Exp $")
42 /*---------------------------------------------------------------------------
44 | Function : int set_menu_opts(MENU *menu, Menu_Options opts)
46 | Description : Set the options for this menu. If the new settings
47 | end up in a change of the geometry of the menu, it
48 | will be recalculated. This operation is forbidden if
49 | the menu is already posted.
51 | Return Values : E_OK - success
52 | E_BAD_ARGUMENT - invalid menu options
53 | E_POSTED - menu is already posted
54 +--------------------------------------------------------------------------*/
55 int set_menu_opts(MENU * menu, Menu_Options opts)
57 if (opts & ~ALL_MENU_OPTS)
58 RETURN(E_BAD_ARGUMENT);
62 if ( menu->status & _POSTED )
65 if ( (opts&O_ROWMAJOR) != (menu->opt&O_ROWMAJOR))
67 /* we need this only if the layout really changed ... */
68 if (menu->items && menu->items[0])
71 menu->curitem = menu->items[0];
72 assert(menu->curitem);
73 set_menu_format( menu, menu->frows, menu->fcols );
79 if (opts & O_ONEVALUE)
83 if ( ((item=menu->items) != (ITEM**)0) )
85 (*item)->value = FALSE;
88 if (opts & O_SHOWDESC) /* this also changes the geometry */
89 _nc_Calculate_Item_Length_and_Width( menu );
92 _nc_Default_Menu.opt = opts;
97 /*---------------------------------------------------------------------------
99 | Function : int menu_opts_off(MENU *menu, Menu_Options opts)
101 | Description : Switch off the options for this menu. If the new settings
102 | end up in a change of the geometry of the menu, it
103 | will be recalculated. This operation is forbidden if
104 | the menu is already posted.
106 | Return Values : E_OK - success
107 | E_BAD_ARGUMENT - invalid options
108 | E_POSTED - menu is already posted
109 +--------------------------------------------------------------------------*/
110 int menu_opts_off(MENU *menu, Menu_Options opts)
112 MENU *cmenu = menu; /* use a copy because set_menu_opts must detect
113 NULL menu itself to adjust its behaviour */
115 if (opts & ~ALL_MENU_OPTS)
116 RETURN(E_BAD_ARGUMENT);
119 Normalize_Menu(cmenu);
120 opts = cmenu->opt & ~opts;
121 return set_menu_opts( menu, opts );
125 /*---------------------------------------------------------------------------
126 | Facility : libnmenu
127 | Function : int menu_opts_on(MENU *menu, Menu_Options opts)
129 | Description : Switch on the options for this menu. If the new settings
130 | end up in a change of the geometry of the menu, it
131 | will be recalculated. This operation is forbidden if
132 | the menu is already posted.
134 | Return Values : E_OK - success
135 | E_BAD_ARGUMENT - invalid menu options
136 | E_POSTED - menu is already posted
137 +--------------------------------------------------------------------------*/
138 int menu_opts_on(MENU * menu, Menu_Options opts)
140 MENU *cmenu = menu; /* use a copy because set_menu_opts must detect
141 NULL menu itself to adjust its behaviour */
143 if (opts & ~ALL_MENU_OPTS)
144 RETURN(E_BAD_ARGUMENT);
147 Normalize_Menu(cmenu);
148 opts = cmenu->opt | opts;
149 return set_menu_opts(menu, opts);
153 /*---------------------------------------------------------------------------
154 | Facility : libnmenu
155 | Function : Menu_Options menu_opts(const MENU *menu)
157 | Description : Return the options for this menu.
159 | Return Values : Menu options
160 +--------------------------------------------------------------------------*/
161 Menu_Options menu_opts(const MENU *menu)
163 return (ALL_MENU_OPTS & Normalize_Menu( menu )->opt);
166 /* m_opts.c ends here */