Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | /**************************************************************************** |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 2 | * Copyright 2020,2021 Thomas E. Dickey * |
| 3 | * Copyright 1998-2004,2010 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 4 | * * |
| 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 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 41 | MODULE_ID("$Id: m_item_opt.c,v 1.22 2021/06/17 21:20:30 tom Exp $") |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 42 | |
| 43 | /*--------------------------------------------------------------------------- |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 44 | | Facility : libnmenu |
| 45 | | Function : int set_item_opts(ITEM *item, Item_Options opts) |
| 46 | | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 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. |
| 50 | | |
| 51 | | Return Values : E_OK - success |
| 52 | | E_BAD_ARGUMENT - invalid item options |
| 53 | +--------------------------------------------------------------------------*/ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 54 | MENU_EXPORT(int) |
| 55 | set_item_opts(ITEM *item, Item_Options opts) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 56 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 57 | T((T_CALLED("set_menu_opts(%p,%d)"), (void *)item, opts)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 58 | |
| 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 | /*--------------------------------------------------------------------------- |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 89 | | Facility : libnmenu |
| 90 | | Function : int item_opts_off(ITEM *item, Item_Options opts) |
| 91 | | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 92 | | Description : Switch of the options for this item. |
| 93 | | |
| 94 | | Return Values : E_OK - success |
| 95 | | E_BAD_ARGUMENT - invalid options |
| 96 | +--------------------------------------------------------------------------*/ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 97 | MENU_EXPORT(int) |
| 98 | item_opts_off(ITEM *item, Item_Options opts) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 99 | { |
| 100 | ITEM *citem = item; /* use a copy because set_item_opts must detect |
| 101 | |
| 102 | NULL item itself to adjust its behavior */ |
| 103 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 104 | T((T_CALLED("item_opts_off(%p,%d)"), (void *)item, opts)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 105 | |
| 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 | /*--------------------------------------------------------------------------- |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 117 | | Facility : libnmenu |
| 118 | | Function : int item_opts_on(ITEM *item, Item_Options opts) |
| 119 | | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 120 | | Description : Switch on the options for this item. |
| 121 | | |
| 122 | | Return Values : E_OK - success |
| 123 | | E_BAD_ARGUMENT - invalid options |
| 124 | +--------------------------------------------------------------------------*/ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 125 | MENU_EXPORT(int) |
| 126 | item_opts_on(ITEM *item, Item_Options opts) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 127 | { |
| 128 | ITEM *citem = item; /* use a copy because set_item_opts must detect |
| 129 | |
| 130 | NULL item itself to adjust its behavior */ |
| 131 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 132 | T((T_CALLED("item_opts_on(%p,%d)"), (void *)item, opts)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 133 | |
| 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 | /*--------------------------------------------------------------------------- |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 146 | | Facility : libnmenu |
| 147 | | Function : Item_Options item_opts(const ITEM *item) |
| 148 | | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 149 | | Description : Switch of the options for this item. |
| 150 | | |
| 151 | | Return Values : Items options |
| 152 | +--------------------------------------------------------------------------*/ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 153 | MENU_EXPORT(Item_Options) |
| 154 | item_opts(const ITEM *item) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 155 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 156 | T((T_CALLED("item_opts(%p)"), (const void *)item)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 157 | returnItemOpts(ALL_ITEM_OPTS & Normalize_Item(item)->opt); |
| 158 | } |
| 159 | |
| 160 | /* m_item_opt.c ends here */ |