1 /****************************************************************************
2 * Copyright 2020 Thomas E. Dickey *
3 * Copyright 1998-2004,2010 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Juergen Pfeifer, 1995,1997 *
32 ****************************************************************************/
34 /***************************************************************************
36 * Menus option routines *
37 ***************************************************************************/
39 #include "menu.priv.h"
41 MODULE_ID("$Id: m_opts.c,v 1.23 2020/12/12 00:38:08 tom Exp $")
43 /*---------------------------------------------------------------------------
45 | Function : int set_menu_opts(MENU *menu, Menu_Options opts)
47 | Description : Set the options for this menu. If the new settings
48 | end up in a change of the geometry of the menu, it
49 | will be recalculated. This operation is forbidden if
50 | the menu is already posted.
52 | Return Values : E_OK - success
53 | E_BAD_ARGUMENT - invalid menu options
54 | E_POSTED - menu is already posted
55 +--------------------------------------------------------------------------*/
57 set_menu_opts(MENU *menu, Menu_Options opts)
59 T((T_CALLED("set_menu_opts(%p,%d)"), (void *)menu, opts));
61 opts &= ALL_MENU_OPTS;
63 if (opts & ~ALL_MENU_OPTS)
64 RETURN(E_BAD_ARGUMENT);
68 if (menu->status & _POSTED)
71 if ((opts & O_ROWMAJOR) != (menu->opt & O_ROWMAJOR))
73 /* we need this only if the layout really changed ... */
74 if (menu->items && menu->items[0])
77 menu->curitem = menu->items[0];
78 assert(menu->curitem);
79 set_menu_format(menu, menu->frows, menu->fcols);
85 if (opts & O_ONEVALUE)
89 if (((item = menu->items) != (ITEM **)0))
91 (*item)->value = FALSE;
94 if (opts & O_SHOWDESC) /* this also changes the geometry */
95 _nc_Calculate_Item_Length_and_Width(menu);
98 _nc_Default_Menu.opt = opts;
103 /*---------------------------------------------------------------------------
104 | Facility : libnmenu
105 | Function : int menu_opts_off(MENU *menu, Menu_Options opts)
107 | Description : Switch off the options for this menu. If the new settings
108 | end up in a change of the geometry of the menu, it
109 | will be recalculated. This operation is forbidden if
110 | the menu is already posted.
112 | Return Values : E_OK - success
113 | E_BAD_ARGUMENT - invalid options
114 | E_POSTED - menu is already posted
115 +--------------------------------------------------------------------------*/
117 menu_opts_off(MENU *menu, Menu_Options opts)
119 MENU *cmenu = menu; /* use a copy because set_menu_opts must detect
121 NULL menu itself to adjust its behavior */
123 T((T_CALLED("menu_opts_off(%p,%d)"), (void *)menu, opts));
125 opts &= ALL_MENU_OPTS;
126 if (opts & ~ALL_MENU_OPTS)
127 RETURN(E_BAD_ARGUMENT);
130 Normalize_Menu(cmenu);
131 opts = cmenu->opt & ~opts;
132 returnCode(set_menu_opts(menu, opts));
136 /*---------------------------------------------------------------------------
137 | Facility : libnmenu
138 | Function : int menu_opts_on(MENU *menu, Menu_Options opts)
140 | Description : Switch on the options for this menu. If the new settings
141 | end up in a change of the geometry of the menu, it
142 | will be recalculated. This operation is forbidden if
143 | the menu is already posted.
145 | Return Values : E_OK - success
146 | E_BAD_ARGUMENT - invalid menu options
147 | E_POSTED - menu is already posted
148 +--------------------------------------------------------------------------*/
150 menu_opts_on(MENU *menu, Menu_Options opts)
152 MENU *cmenu = menu; /* use a copy because set_menu_opts must detect
154 NULL menu itself to adjust its behavior */
156 T((T_CALLED("menu_opts_on(%p,%d)"), (void *)menu, opts));
158 opts &= ALL_MENU_OPTS;
159 if (opts & ~ALL_MENU_OPTS)
160 RETURN(E_BAD_ARGUMENT);
163 Normalize_Menu(cmenu);
164 opts = cmenu->opt | opts;
165 returnCode(set_menu_opts(menu, opts));
169 /*---------------------------------------------------------------------------
170 | Facility : libnmenu
171 | Function : Menu_Options menu_opts(const MENU *menu)
173 | Description : Return the options for this menu.
175 | Return Values : Menu options
176 +--------------------------------------------------------------------------*/
177 MENU_EXPORT(Menu_Options)
178 menu_opts(const MENU *menu)
180 T((T_CALLED("menu_opts(%p)"), (const void *)menu));
181 returnMenuOpts(ALL_MENU_OPTS & Normalize_Menu(menu)->opt);
184 /* m_opts.c ends here */