1 /****************************************************************************
2 * Copyright (c) 1998,2000 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, 1995,1997 *
31 * Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en *
32 ****************************************************************************/
34 /***************************************************************************
36 * Menus option routines *
37 ***************************************************************************/
39 #include "menu.priv.h"
41 MODULE_ID("$Id: m_opts.c,v 1.14 2002/07/06 15:22:16 juergen 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 opts &= ALL_MENU_OPTS;
61 if (opts & ~ALL_MENU_OPTS)
62 RETURN(E_BAD_ARGUMENT);
66 if ( menu->status & _POSTED )
69 if ( (opts&O_ROWMAJOR) != (menu->opt&O_ROWMAJOR))
71 /* we need this only if the layout really changed ... */
72 if (menu->items && menu->items[0])
75 menu->curitem = menu->items[0];
76 assert(menu->curitem);
77 set_menu_format( menu, menu->frows, menu->fcols );
83 if (opts & O_ONEVALUE)
87 if ( ((item=menu->items) != (ITEM**)0) )
89 (*item)->value = FALSE;
92 if (opts & O_SHOWDESC) /* this also changes the geometry */
93 _nc_Calculate_Item_Length_and_Width( menu );
96 _nc_Default_Menu.opt = opts;
101 /*---------------------------------------------------------------------------
102 | Facility : libnmenu
103 | Function : int menu_opts_off(MENU *menu, Menu_Options opts)
105 | Description : Switch off the options for this menu. If the new settings
106 | end up in a change of the geometry of the menu, it
107 | will be recalculated. This operation is forbidden if
108 | the menu is already posted.
110 | Return Values : E_OK - success
111 | E_BAD_ARGUMENT - invalid options
112 | E_POSTED - menu is already posted
113 +--------------------------------------------------------------------------*/
115 menu_opts_off (MENU *menu, Menu_Options opts)
117 MENU *cmenu = menu; /* use a copy because set_menu_opts must detect
118 NULL menu itself to adjust its behaviour */
120 opts &= ALL_MENU_OPTS;
121 if (opts & ~ALL_MENU_OPTS)
122 RETURN(E_BAD_ARGUMENT);
125 Normalize_Menu(cmenu);
126 opts = cmenu->opt & ~opts;
127 return set_menu_opts( menu, opts );
131 /*---------------------------------------------------------------------------
132 | Facility : libnmenu
133 | Function : int menu_opts_on(MENU *menu, Menu_Options opts)
135 | Description : Switch on the options for this menu. If the new settings
136 | end up in a change of the geometry of the menu, it
137 | will be recalculated. This operation is forbidden if
138 | the menu is already posted.
140 | Return Values : E_OK - success
141 | E_BAD_ARGUMENT - invalid menu options
142 | E_POSTED - menu is already posted
143 +--------------------------------------------------------------------------*/
145 menu_opts_on (MENU * menu, Menu_Options opts)
147 MENU *cmenu = menu; /* use a copy because set_menu_opts must detect
148 NULL menu itself to adjust its behaviour */
150 opts &= ALL_MENU_OPTS;
151 if (opts & ~ALL_MENU_OPTS)
152 RETURN(E_BAD_ARGUMENT);
155 Normalize_Menu(cmenu);
156 opts = cmenu->opt | opts;
157 return set_menu_opts(menu, opts);
161 /*---------------------------------------------------------------------------
162 | Facility : libnmenu
163 | Function : Menu_Options menu_opts(const MENU *menu)
165 | Description : Return the options for this menu.
167 | Return Values : Menu options
168 +--------------------------------------------------------------------------*/
169 NCURSES_EXPORT(Menu_Options)
170 menu_opts (const MENU *menu)
172 return (ALL_MENU_OPTS & Normalize_Menu( menu )->opt);
175 /* m_opts.c ends here */