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