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-2010,2012 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_attribs * |
| 36 | * Control menus display attributes * |
| 37 | ***************************************************************************/ |
| 38 | |
| 39 | #include "menu.priv.h" |
| 40 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 41 | MODULE_ID("$Id: m_attribs.c,v 1.20 2021/06/17 21:20:30 tom Exp $") |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 42 | |
| 43 | /* Macro to redraw menu if it is posted and changed */ |
| 44 | #define Refresh_Menu(menu) \ |
| 45 | if ( (menu) && ((menu)->status & _POSTED) )\ |
| 46 | {\ |
| 47 | _nc_Draw_Menu( menu );\ |
| 48 | _nc_Show_Menu( menu );\ |
| 49 | } |
| 50 | |
| 51 | /* "Template" macro to generate a function to set a menus attribute */ |
| 52 | #define GEN_MENU_ATTR_SET_FCT( name ) \ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 53 | MENU_EXPORT(int) NCURSES_API set_menu_ ## name (MENU* menu, chtype attr) \ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 54 | {\ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 55 | T((T_CALLED("set_menu_" #name "(%p,%s)"), (void *) menu, _traceattr(attr))); \ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 56 | if (!(attr==A_NORMAL || (attr & A_ATTRIBUTES)==attr))\ |
| 57 | RETURN(E_BAD_ARGUMENT);\ |
| 58 | if (menu && ( menu -> name != attr))\ |
| 59 | {\ |
| 60 | (menu -> name) = attr;\ |
| 61 | Refresh_Menu(menu);\ |
| 62 | }\ |
| 63 | Normalize_Menu( menu ) -> name = attr;\ |
| 64 | RETURN(E_OK);\ |
| 65 | } |
| 66 | |
| 67 | /* "Template" macro to generate a function to get a menu's attribute */ |
| 68 | #define GEN_MENU_ATTR_GET_FCT( name ) \ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 69 | MENU_EXPORT(chtype) NCURSES_API menu_ ## name (const MENU * menu)\ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 70 | {\ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 71 | T((T_CALLED("menu_" #name "(%p)"), (const void *) menu));\ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 72 | returnAttr(Normalize_Menu( menu ) -> name);\ |
| 73 | } |
| 74 | |
| 75 | /*--------------------------------------------------------------------------- |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 76 | | Facility : libnmenu |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 77 | | Function : int set_menu_fore(MENU *menu, chtype attr) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 78 | | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 79 | | Description : Set the attribute for selectable items. In single- |
| 80 | | valued menus this is used to highlight the current |
| 81 | | item ((i.e. where the cursor is), in multi-valued |
| 82 | | menus this is used to highlight the selected items. |
| 83 | | |
| 84 | | Return Values : E_OK - success |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 85 | | E_BAD_ARGUMENT - an invalid value has been passed |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 86 | +--------------------------------------------------------------------------*/ |
| 87 | GEN_MENU_ATTR_SET_FCT(fore) |
| 88 | |
| 89 | /*--------------------------------------------------------------------------- |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 90 | | Facility : libnmenu |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 91 | | Function : chtype menu_fore(const MENU* menu) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 92 | | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 93 | | Description : Return the attribute used for selectable items that |
| 94 | | are current (single-valued menu) or selected (multi- |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 95 | | valued menu). |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 96 | | |
| 97 | | Return Values : Attribute value |
| 98 | +--------------------------------------------------------------------------*/ |
| 99 | GEN_MENU_ATTR_GET_FCT(fore) |
| 100 | |
| 101 | /*--------------------------------------------------------------------------- |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 102 | | Facility : libnmenu |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 103 | | Function : int set_menu_back(MENU *menu, chtype attr) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 104 | | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 105 | | Description : Set the attribute for selectable but not yet selected |
| 106 | | items. |
| 107 | | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 108 | | Return Values : E_OK - success |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 109 | | E_BAD_ARGUMENT - an invalid value has been passed |
| 110 | +--------------------------------------------------------------------------*/ |
| 111 | GEN_MENU_ATTR_SET_FCT(back) |
| 112 | |
| 113 | /*--------------------------------------------------------------------------- |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 114 | | Facility : libnmenu |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 115 | | Function : chtype menu_back(const MENU *menu) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 116 | | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 117 | | Description : Return the attribute used for selectable but not yet |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 118 | | selected items. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 119 | | |
| 120 | | Return Values : Attribute value |
| 121 | +--------------------------------------------------------------------------*/ |
| 122 | GEN_MENU_ATTR_GET_FCT(back) |
| 123 | |
| 124 | /*--------------------------------------------------------------------------- |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 125 | | Facility : libnmenu |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 126 | | Function : int set_menu_grey(MENU *menu, chtype attr) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 127 | | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 128 | | Description : Set the attribute for unselectable items. |
| 129 | | |
| 130 | | Return Values : E_OK - success |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 131 | | E_BAD_ARGUMENT - an invalid value has been passed |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 132 | +--------------------------------------------------------------------------*/ |
| 133 | GEN_MENU_ATTR_SET_FCT(grey) |
| 134 | |
| 135 | /*--------------------------------------------------------------------------- |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 136 | | Facility : libnmenu |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 137 | | Function : chtype menu_grey(const MENU *menu) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 138 | | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 139 | | Description : Return the attribute used for non-selectable items |
| 140 | | |
| 141 | | Return Values : Attribute value |
| 142 | +--------------------------------------------------------------------------*/ |
| 143 | GEN_MENU_ATTR_GET_FCT(grey) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 144 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 145 | /* m_attribs.c ends here */ |