blob: 495e409b601b649b8d706157bdbd300657dea59a [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002 * Copyright 2020,2021 Thomas E. Dickey *
3 * Copyright 1998-2004,2010 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304 * *
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: *
12 * *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
15 * *
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. *
23 * *
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 *
27 * authorization. *
28 ****************************************************************************/
29
30/****************************************************************************
31 * Author: Juergen Pfeifer, 1995,1997 *
32 ****************************************************************************/
33
34/***************************************************************************
35* Module m_item_opt *
36* Menus item option routines *
37***************************************************************************/
38
39#include "menu.priv.h"
40
micky3879b9f5e72025-07-08 18:04:53 -040041MODULE_ID("$Id: m_item_opt.c,v 1.22 2021/06/17 21:20:30 tom Exp $")
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053042
43/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -040044| Facility : libnmenu
45| Function : int set_item_opts(ITEM *item, Item_Options opts)
46|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053047| 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.
50|
51| Return Values : E_OK - success
52| E_BAD_ARGUMENT - invalid item options
53+--------------------------------------------------------------------------*/
micky3879b9f5e72025-07-08 18:04:53 -040054MENU_EXPORT(int)
55set_item_opts(ITEM *item, Item_Options opts)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053056{
Steve Kondikae271bc2015-11-15 02:50:53 +010057 T((T_CALLED("set_menu_opts(%p,%d)"), (void *)item, opts));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053058
59 opts &= ALL_ITEM_OPTS;
60
61 if (opts & ~ALL_ITEM_OPTS)
62 RETURN(E_BAD_ARGUMENT);
63
64 if (item)
65 {
66 if (item->opt != opts)
67 {
68 MENU *menu = item->imenu;
69
70 item->opt = opts;
71
72 if ((!(opts & O_SELECTABLE)) && item->value)
73 item->value = FALSE;
74
75 if (menu && (menu->status & _POSTED))
76 {
77 Move_And_Post_Item(menu, item);
78 _nc_Show_Menu(menu);
79 }
80 }
81 }
82 else
83 _nc_Default_Item.opt = opts;
84
85 RETURN(E_OK);
86}
87
88/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -040089| Facility : libnmenu
90| Function : int item_opts_off(ITEM *item, Item_Options opts)
91|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053092| Description : Switch of the options for this item.
93|
94| Return Values : E_OK - success
95| E_BAD_ARGUMENT - invalid options
96+--------------------------------------------------------------------------*/
micky3879b9f5e72025-07-08 18:04:53 -040097MENU_EXPORT(int)
98item_opts_off(ITEM *item, Item_Options opts)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053099{
100 ITEM *citem = item; /* use a copy because set_item_opts must detect
101
102 NULL item itself to adjust its behavior */
103
Steve Kondikae271bc2015-11-15 02:50:53 +0100104 T((T_CALLED("item_opts_off(%p,%d)"), (void *)item, opts));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530105
106 if (opts & ~ALL_ITEM_OPTS)
107 RETURN(E_BAD_ARGUMENT);
108 else
109 {
110 Normalize_Item(citem);
111 opts = citem->opt & ~(opts & ALL_ITEM_OPTS);
112 returnCode(set_item_opts(item, opts));
113 }
114}
115
116/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -0400117| Facility : libnmenu
118| Function : int item_opts_on(ITEM *item, Item_Options opts)
119|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530120| Description : Switch on the options for this item.
121|
122| Return Values : E_OK - success
123| E_BAD_ARGUMENT - invalid options
124+--------------------------------------------------------------------------*/
micky3879b9f5e72025-07-08 18:04:53 -0400125MENU_EXPORT(int)
126item_opts_on(ITEM *item, Item_Options opts)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530127{
128 ITEM *citem = item; /* use a copy because set_item_opts must detect
129
130 NULL item itself to adjust its behavior */
131
Steve Kondikae271bc2015-11-15 02:50:53 +0100132 T((T_CALLED("item_opts_on(%p,%d)"), (void *)item, opts));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530133
134 opts &= ALL_ITEM_OPTS;
135 if (opts & ~ALL_ITEM_OPTS)
136 RETURN(E_BAD_ARGUMENT);
137 else
138 {
139 Normalize_Item(citem);
140 opts = citem->opt | opts;
141 returnCode(set_item_opts(item, opts));
142 }
143}
144
145/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -0400146| Facility : libnmenu
147| Function : Item_Options item_opts(const ITEM *item)
148|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530149| Description : Switch of the options for this item.
150|
151| Return Values : Items options
152+--------------------------------------------------------------------------*/
micky3879b9f5e72025-07-08 18:04:53 -0400153MENU_EXPORT(Item_Options)
154item_opts(const ITEM *item)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530155{
Steve Kondikae271bc2015-11-15 02:50:53 +0100156 T((T_CALLED("item_opts(%p)"), (const void *)item));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530157 returnItemOpts(ALL_ITEM_OPTS & Normalize_Item(item)->opt);
158}
159
160/* m_item_opt.c ends here */