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 item option routines *
37 ***************************************************************************/
39 #include "menu.priv.h"
41 MODULE_ID("$Id: m_item_opt.c,v 1.12 2002/07/06 15:22:16 juergen Exp $")
43 /*---------------------------------------------------------------------------
45 | Function : int set_item_opts(ITEM *item, Item_Options opts)
47 | Description : Set the options of the item. If there are relevant
48 | changes, the item is connected and the menu is posted,
49 | the menu will be redisplayed.
51 | Return Values : E_OK - success
52 | E_BAD_ARGUMENT - invalid item options
53 +--------------------------------------------------------------------------*/
55 set_item_opts (ITEM *item, Item_Options opts)
57 opts &= ALL_ITEM_OPTS;
59 if (opts & ~ALL_ITEM_OPTS)
60 RETURN(E_BAD_ARGUMENT);
64 if (item->opt != opts)
66 MENU *menu = item->imenu;
70 if ((!(opts & O_SELECTABLE)) && item->value)
73 if (menu && (menu->status & _POSTED))
75 Move_And_Post_Item( menu, item );
81 _nc_Default_Item.opt = opts;
86 /*---------------------------------------------------------------------------
88 | Function : int item_opts_off(ITEM *item, Item_Options opts)
90 | Description : Switch of the options for this item.
92 | Return Values : E_OK - success
93 | E_BAD_ARGUMENT - invalid options
94 +--------------------------------------------------------------------------*/
96 item_opts_off (ITEM *item, Item_Options opts)
98 ITEM *citem = item; /* use a copy because set_item_opts must detect
99 NULL item itself to adjust its behaviour */
101 if (opts & ~ALL_ITEM_OPTS)
102 RETURN(E_BAD_ARGUMENT);
105 Normalize_Item(citem);
106 opts = citem->opt & ~(opts & ALL_ITEM_OPTS);
107 return set_item_opts( item, opts );
111 /*---------------------------------------------------------------------------
112 | Facility : libnmenu
113 | Function : int item_opts_on(ITEM *item, Item_Options opts)
115 | Description : Switch on the options for this item.
117 | Return Values : E_OK - success
118 | E_BAD_ARGUMENT - invalid options
119 +--------------------------------------------------------------------------*/
121 item_opts_on (ITEM *item, Item_Options opts)
123 ITEM *citem = item; /* use a copy because set_item_opts must detect
124 NULL item itself to adjust its behaviour */
126 opts &= ALL_ITEM_OPTS;
127 if (opts & ~ALL_ITEM_OPTS)
128 RETURN(E_BAD_ARGUMENT);
131 Normalize_Item(citem);
132 opts = citem->opt | opts;
133 return set_item_opts( item, opts );
137 /*---------------------------------------------------------------------------
138 | Facility : libnmenu
139 | Function : Item_Options item_opts(const ITEM *item)
141 | Description : Switch of the options for this item.
143 | Return Values : Items options
144 +--------------------------------------------------------------------------*/
145 NCURSES_EXPORT(Item_Options)
146 item_opts (const ITEM * item)
148 return (ALL_ITEM_OPTS & Normalize_Item(item)->opt);
151 /* m_item_opt.c ends here */