blob: a9275d08049e91f9903a43bcf8d8316b655019d3 [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-2010,2012 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_attribs *
36* Control menus display attributes *
37***************************************************************************/
38
39#include "menu.priv.h"
40
micky3879b9f5e72025-07-08 18:04:53 -040041MODULE_ID("$Id: m_attribs.c,v 1.20 2021/06/17 21:20:30 tom Exp $")
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053042
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 ) \
micky3879b9f5e72025-07-08 18:04:53 -040053MENU_EXPORT(int) NCURSES_API set_menu_ ## name (MENU* menu, chtype attr) \
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053054{\
Steve Kondikae271bc2015-11-15 02:50:53 +010055 T((T_CALLED("set_menu_" #name "(%p,%s)"), (void *) menu, _traceattr(attr))); \
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053056 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 ) \
micky3879b9f5e72025-07-08 18:04:53 -040069MENU_EXPORT(chtype) NCURSES_API menu_ ## name (const MENU * menu)\
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053070{\
Steve Kondikae271bc2015-11-15 02:50:53 +010071 T((T_CALLED("menu_" #name "(%p)"), (const void *) menu));\
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053072 returnAttr(Normalize_Menu( menu ) -> name);\
73}
74
75/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -040076| Facility : libnmenu
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053077| Function : int set_menu_fore(MENU *menu, chtype attr)
micky3879b9f5e72025-07-08 18:04:53 -040078|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053079| 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
micky3879b9f5e72025-07-08 18:04:53 -040085| E_BAD_ARGUMENT - an invalid value has been passed
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053086+--------------------------------------------------------------------------*/
87GEN_MENU_ATTR_SET_FCT(fore)
88
89/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -040090| Facility : libnmenu
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053091| Function : chtype menu_fore(const MENU* menu)
micky3879b9f5e72025-07-08 18:04:53 -040092|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053093| Description : Return the attribute used for selectable items that
94| are current (single-valued menu) or selected (multi-
micky3879b9f5e72025-07-08 18:04:53 -040095| valued menu).
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053096|
97| Return Values : Attribute value
98+--------------------------------------------------------------------------*/
99GEN_MENU_ATTR_GET_FCT(fore)
100
101/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -0400102| Facility : libnmenu
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530103| Function : int set_menu_back(MENU *menu, chtype attr)
micky3879b9f5e72025-07-08 18:04:53 -0400104|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530105| Description : Set the attribute for selectable but not yet selected
106| items.
107|
micky3879b9f5e72025-07-08 18:04:53 -0400108| Return Values : E_OK - success
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530109| E_BAD_ARGUMENT - an invalid value has been passed
110+--------------------------------------------------------------------------*/
111GEN_MENU_ATTR_SET_FCT(back)
112
113/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -0400114| Facility : libnmenu
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530115| Function : chtype menu_back(const MENU *menu)
micky3879b9f5e72025-07-08 18:04:53 -0400116|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530117| Description : Return the attribute used for selectable but not yet
micky3879b9f5e72025-07-08 18:04:53 -0400118| selected items.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530119|
120| Return Values : Attribute value
121+--------------------------------------------------------------------------*/
122GEN_MENU_ATTR_GET_FCT(back)
123
124/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -0400125| Facility : libnmenu
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530126| Function : int set_menu_grey(MENU *menu, chtype attr)
micky3879b9f5e72025-07-08 18:04:53 -0400127|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530128| Description : Set the attribute for unselectable items.
129|
130| Return Values : E_OK - success
micky3879b9f5e72025-07-08 18:04:53 -0400131| E_BAD_ARGUMENT - an invalid value has been passed
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530132+--------------------------------------------------------------------------*/
133GEN_MENU_ATTR_SET_FCT(grey)
134
135/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -0400136| Facility : libnmenu
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530137| Function : chtype menu_grey(const MENU *menu)
micky3879b9f5e72025-07-08 18:04:53 -0400138|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530139| Description : Return the attribute used for non-selectable items
140|
141| Return Values : Attribute value
142+--------------------------------------------------------------------------*/
143GEN_MENU_ATTR_GET_FCT(grey)
Steve Kondikae271bc2015-11-15 02:50:53 +0100144
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530145/* m_attribs.c ends here */