1 /****************************************************************************
2 * Copyright 2020,2021 Thomas E. Dickey *
3 * Copyright 1998-2010,2012 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 * Control menus display attributes *
37 ***************************************************************************/
39 #include "menu.priv.h"
41 MODULE_ID("$Id: m_attribs.c,v 1.20 2021/06/17 21:20:30 tom Exp $")
43 /* Macro to redraw menu if it is posted and changed */
44 #define Refresh_Menu(menu) \
45 if ( (menu) && ((menu)->status & _POSTED) )\
47 _nc_Draw_Menu( menu );\
48 _nc_Show_Menu( menu );\
51 /* "Template" macro to generate a function to set a menus attribute */
52 #define GEN_MENU_ATTR_SET_FCT( name ) \
53 MENU_EXPORT(int) NCURSES_API set_menu_ ## name (MENU* menu, chtype attr) \
55 T((T_CALLED("set_menu_" #name "(%p,%s)"), (void *) menu, _traceattr(attr))); \
56 if (!(attr==A_NORMAL || (attr & A_ATTRIBUTES)==attr))\
57 RETURN(E_BAD_ARGUMENT);\
58 if (menu && ( menu -> name != attr))\
60 (menu -> name) = attr;\
63 Normalize_Menu( menu ) -> name = attr;\
67 /* "Template" macro to generate a function to get a menu's attribute */
68 #define GEN_MENU_ATTR_GET_FCT( name ) \
69 MENU_EXPORT(chtype) NCURSES_API menu_ ## name (const MENU * menu)\
71 T((T_CALLED("menu_" #name "(%p)"), (const void *) menu));\
72 returnAttr(Normalize_Menu( menu ) -> name);\
75 /*---------------------------------------------------------------------------
77 | Function : int set_menu_fore(MENU *menu, chtype attr)
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.
84 | Return Values : E_OK - success
85 | E_BAD_ARGUMENT - an invalid value has been passed
86 +--------------------------------------------------------------------------*/
87 GEN_MENU_ATTR_SET_FCT(fore)
89 /*---------------------------------------------------------------------------
91 | Function : chtype menu_fore(const MENU* menu)
93 | Description : Return the attribute used for selectable items that
94 | are current (single-valued menu) or selected (multi-
97 | Return Values : Attribute value
98 +--------------------------------------------------------------------------*/
99 GEN_MENU_ATTR_GET_FCT(fore)
101 /*---------------------------------------------------------------------------
102 | Facility : libnmenu
103 | Function : int set_menu_back(MENU *menu, chtype attr)
105 | Description : Set the attribute for selectable but not yet selected
108 | Return Values : E_OK - success
109 | E_BAD_ARGUMENT - an invalid value has been passed
110 +--------------------------------------------------------------------------*/
111 GEN_MENU_ATTR_SET_FCT(back)
113 /*---------------------------------------------------------------------------
114 | Facility : libnmenu
115 | Function : chtype menu_back(const MENU *menu)
117 | Description : Return the attribute used for selectable but not yet
120 | Return Values : Attribute value
121 +--------------------------------------------------------------------------*/
122 GEN_MENU_ATTR_GET_FCT(back)
124 /*---------------------------------------------------------------------------
125 | Facility : libnmenu
126 | Function : int set_menu_grey(MENU *menu, chtype attr)
128 | Description : Set the attribute for unselectable items.
130 | Return Values : E_OK - success
131 | E_BAD_ARGUMENT - an invalid value has been passed
132 +--------------------------------------------------------------------------*/
133 GEN_MENU_ATTR_SET_FCT(grey)
135 /*---------------------------------------------------------------------------
136 | Facility : libnmenu
137 | Function : chtype menu_grey(const MENU *menu)
139 | Description : Return the attribute used for non-selectable items
141 | Return Values : Attribute value
142 +--------------------------------------------------------------------------*/
143 GEN_MENU_ATTR_GET_FCT(grey)
145 /* m_attribs.c ends here */