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 item option routines *
37 ***************************************************************************/
39 #include "menu.priv.h"
41 MODULE_ID("$Id: m_item_opt.c,v 1.20 2020/05/24 01:40:20 anonymous.maarten 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 T((T_CALLED("set_menu_opts(%p,%d)"), (void *)item, opts));
59 opts &= ALL_ITEM_OPTS;
61 if (opts & ~ALL_ITEM_OPTS)
62 RETURN(E_BAD_ARGUMENT);
66 if (item->opt != opts)
68 MENU *menu = item->imenu;
72 if ((!(opts & O_SELECTABLE)) && item->value)
75 if (menu && (menu->status & _POSTED))
77 Move_And_Post_Item(menu, item);
83 _nc_Default_Item.opt = opts;
88 /*---------------------------------------------------------------------------
90 | Function : int item_opts_off(ITEM *item, Item_Options opts)
92 | Description : Switch of the options for this item.
94 | Return Values : E_OK - success
95 | E_BAD_ARGUMENT - invalid options
96 +--------------------------------------------------------------------------*/
98 item_opts_off(ITEM * item, Item_Options opts)
100 ITEM *citem = item; /* use a copy because set_item_opts must detect
102 NULL item itself to adjust its behavior */
104 T((T_CALLED("item_opts_off(%p,%d)"), (void *)item, opts));
106 if (opts & ~ALL_ITEM_OPTS)
107 RETURN(E_BAD_ARGUMENT);
110 Normalize_Item(citem);
111 opts = citem->opt & ~(opts & ALL_ITEM_OPTS);
112 returnCode(set_item_opts(item, opts));
116 /*---------------------------------------------------------------------------
117 | Facility : libnmenu
118 | Function : int item_opts_on(ITEM *item, Item_Options opts)
120 | Description : Switch on the options for this item.
122 | Return Values : E_OK - success
123 | E_BAD_ARGUMENT - invalid options
124 +--------------------------------------------------------------------------*/
126 item_opts_on(ITEM * item, Item_Options opts)
128 ITEM *citem = item; /* use a copy because set_item_opts must detect
130 NULL item itself to adjust its behavior */
132 T((T_CALLED("item_opts_on(%p,%d)"), (void *)item, opts));
134 opts &= ALL_ITEM_OPTS;
135 if (opts & ~ALL_ITEM_OPTS)
136 RETURN(E_BAD_ARGUMENT);
139 Normalize_Item(citem);
140 opts = citem->opt | opts;
141 returnCode(set_item_opts(item, opts));
145 /*---------------------------------------------------------------------------
146 | Facility : libnmenu
147 | Function : Item_Options item_opts(const ITEM *item)
149 | Description : Switch of the options for this item.
151 | Return Values : Items options
152 +--------------------------------------------------------------------------*/
153 MENU_EXPORT(Item_Options)
154 item_opts(const ITEM * item)
156 T((T_CALLED("item_opts(%p)"), (const void *)item));
157 returnItemOpts(ALL_ITEM_OPTS & Normalize_Item(item)->opt);
160 /* m_item_opt.c ends here */