MFC corrected printing of the slice number when adding a GPT partition.
[dragonfly.git] / contrib / ncurses-5.4 / menu / m_opts.c
blob70fc7d2b633ef5290aa2f0fbcb8d5560b6fd63b9
1 /****************************************************************************
2 * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
3 * *
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: *
11 * *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
14 * *
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. *
22 * *
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 *
26 * authorization. *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Juergen Pfeifer, 1995,1997 *
31 ****************************************************************************/
33 /***************************************************************************
34 * Module m_opts *
35 * Menus option routines *
36 ***************************************************************************/
38 #include "menu.priv.h"
40 MODULE_ID("$Id: m_opts.c,v 1.16 2003/11/08 20:50:19 tom Exp $")
42 /*---------------------------------------------------------------------------
43 | Facility : libnmenu
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 NCURSES_EXPORT(int)
56 set_menu_opts (MENU * menu, Menu_Options opts)
58 opts &= ALL_MENU_OPTS;
60 if (opts & ~ALL_MENU_OPTS)
61 RETURN(E_BAD_ARGUMENT);
63 if (menu)
65 if ( menu->status & _POSTED )
66 RETURN(E_POSTED);
68 if ( (opts&O_ROWMAJOR) != (menu->opt&O_ROWMAJOR))
70 /* we need this only if the layout really changed ... */
71 if (menu->items && menu->items[0])
73 menu->toprow = 0;
74 menu->curitem = menu->items[0];
75 assert(menu->curitem);
76 set_menu_format( menu, menu->frows, menu->fcols );
80 menu->opt = opts;
82 if (opts & O_ONEVALUE)
84 ITEM **item;
86 if ( ((item=menu->items) != (ITEM**)0) )
87 for(;*item;item++)
88 (*item)->value = FALSE;
91 if (opts & O_SHOWDESC) /* this also changes the geometry */
92 _nc_Calculate_Item_Length_and_Width( menu );
94 else
95 _nc_Default_Menu.opt = opts;
97 RETURN(E_OK);
100 /*---------------------------------------------------------------------------
101 | Facility : libnmenu
102 | Function : int menu_opts_off(MENU *menu, Menu_Options opts)
104 | Description : Switch off the options for this menu. If the new settings
105 | end up in a change of the geometry of the menu, it
106 | will be recalculated. This operation is forbidden if
107 | the menu is already posted.
109 | Return Values : E_OK - success
110 | E_BAD_ARGUMENT - invalid options
111 | E_POSTED - menu is already posted
112 +--------------------------------------------------------------------------*/
113 NCURSES_EXPORT(int)
114 menu_opts_off (MENU *menu, Menu_Options opts)
116 MENU *cmenu = menu; /* use a copy because set_menu_opts must detect
117 NULL menu itself to adjust its behavior */
119 opts &= ALL_MENU_OPTS;
120 if (opts & ~ALL_MENU_OPTS)
121 RETURN(E_BAD_ARGUMENT);
122 else
124 Normalize_Menu(cmenu);
125 opts = cmenu->opt & ~opts;
126 return set_menu_opts( menu, opts );
130 /*---------------------------------------------------------------------------
131 | Facility : libnmenu
132 | Function : int menu_opts_on(MENU *menu, Menu_Options opts)
134 | Description : Switch on the options for this menu. If the new settings
135 | end up in a change of the geometry of the menu, it
136 | will be recalculated. This operation is forbidden if
137 | the menu is already posted.
139 | Return Values : E_OK - success
140 | E_BAD_ARGUMENT - invalid menu options
141 | E_POSTED - menu is already posted
142 +--------------------------------------------------------------------------*/
143 NCURSES_EXPORT(int)
144 menu_opts_on (MENU * menu, Menu_Options opts)
146 MENU *cmenu = menu; /* use a copy because set_menu_opts must detect
147 NULL menu itself to adjust its behavior */
149 opts &= ALL_MENU_OPTS;
150 if (opts & ~ALL_MENU_OPTS)
151 RETURN(E_BAD_ARGUMENT);
152 else
154 Normalize_Menu(cmenu);
155 opts = cmenu->opt | opts;
156 return set_menu_opts(menu, opts);
160 /*---------------------------------------------------------------------------
161 | Facility : libnmenu
162 | Function : Menu_Options menu_opts(const MENU *menu)
164 | Description : Return the options for this menu.
166 | Return Values : Menu options
167 +--------------------------------------------------------------------------*/
168 NCURSES_EXPORT(Menu_Options)
169 menu_opts (const MENU *menu)
171 return (ALL_MENU_OPTS & Normalize_Menu( menu )->opt);
174 /* m_opts.c ends here */