1/* $OpenBSD: m_attribs.c,v 1.8 2023/10/17 09:52:10 nicm Exp $ */
2
3/****************************************************************************
4 * Copyright 2020,2021 Thomas E. Dickey                                     *
5 * Copyright 1998-2010,2012 Free Software Foundation, Inc.                  *
6 *                                                                          *
7 * Permission is hereby granted, free of charge, to any person obtaining a  *
8 * copy of this software and associated documentation files (the            *
9 * "Software"), to deal in the Software without restriction, including      *
10 * without limitation the rights to use, copy, modify, merge, publish,      *
11 * distribute, distribute with modifications, sublicense, and/or sell       *
12 * copies of the Software, and to permit persons to whom the Software is    *
13 * furnished to do so, subject to the following conditions:                 *
14 *                                                                          *
15 * The above copyright notice and this permission notice shall be included  *
16 * in all copies or substantial portions of the Software.                   *
17 *                                                                          *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
21 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
24 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
25 *                                                                          *
26 * Except as contained in this notice, the name(s) of the above copyright   *
27 * holders shall not be used in advertising or otherwise to promote the     *
28 * sale, use or other dealings in this Software without prior written       *
29 * authorization.                                                           *
30 ****************************************************************************/
31
32/****************************************************************************
33 *   Author:  Juergen Pfeifer, 1995,1997                                    *
34 ****************************************************************************/
35
36/***************************************************************************
37* Module m_attribs                                                         *
38* Control menus display attributes                                         *
39***************************************************************************/
40
41#include "menu.priv.h"
42
43MODULE_ID("$Id: m_attribs.c,v 1.8 2023/10/17 09:52:10 nicm Exp $")
44
45/* Macro to redraw menu if it is posted and changed */
46#define Refresh_Menu(menu) \
47   if ( (menu) && ((menu)->status & _POSTED) )\
48   {\
49      _nc_Draw_Menu( menu );\
50      _nc_Show_Menu( menu );\
51   }
52
53/* "Template" macro to generate a function to set a menus attribute */
54#define GEN_MENU_ATTR_SET_FCT( name ) \
55MENU_EXPORT(int) NCURSES_API set_menu_ ## name (MENU* menu, chtype attr) \
56{\
57  T((T_CALLED("set_menu_" #name "(%p,%s)"), (void *) menu, _traceattr(attr))); \
58   if (!(attr==A_NORMAL || (attr & A_ATTRIBUTES)==attr))\
59      RETURN(E_BAD_ARGUMENT);\
60   if (menu && ( menu -> name != attr))\
61     {\
62       (menu -> name) = attr;\
63       Refresh_Menu(menu);\
64     }\
65   Normalize_Menu( menu ) -> name = attr;\
66   RETURN(E_OK);\
67}
68
69/* "Template" macro to generate a function to get a menu's attribute */
70#define GEN_MENU_ATTR_GET_FCT( name ) \
71MENU_EXPORT(chtype) NCURSES_API menu_ ## name (const MENU * menu)\
72{\
73   T((T_CALLED("menu_" #name "(%p)"), (const void *) menu));\
74   returnAttr(Normalize_Menu( menu ) -> name);\
75}
76
77/*---------------------------------------------------------------------------
78|   Facility      :  libnmenu
79|   Function      :  int set_menu_fore(MENU *menu, chtype attr)
80|
81|   Description   :  Set the attribute for selectable items. In single-
82|                    valued menus this is used to highlight the current
83|                    item ((i.e. where the cursor is), in multi-valued
84|                    menus this is used to highlight the selected items.
85|
86|   Return Values :  E_OK              - success
87|                    E_BAD_ARGUMENT    - an invalid value has been passed
88+--------------------------------------------------------------------------*/
89GEN_MENU_ATTR_SET_FCT(fore)
90
91/*---------------------------------------------------------------------------
92|   Facility      :  libnmenu
93|   Function      :  chtype menu_fore(const MENU* menu)
94|
95|   Description   :  Return the attribute used for selectable items that
96|                    are current (single-valued menu) or selected (multi-
97|                    valued menu).
98|
99|   Return Values :  Attribute value
100+--------------------------------------------------------------------------*/
101GEN_MENU_ATTR_GET_FCT(fore)
102
103/*---------------------------------------------------------------------------
104|   Facility      :  libnmenu
105|   Function      :  int set_menu_back(MENU *menu, chtype attr)
106|
107|   Description   :  Set the attribute for selectable but not yet selected
108|                    items.
109|
110|   Return Values :  E_OK             - success
111|                    E_BAD_ARGUMENT   - an invalid value has been passed
112+--------------------------------------------------------------------------*/
113GEN_MENU_ATTR_SET_FCT(back)
114
115/*---------------------------------------------------------------------------
116|   Facility      :  libnmenu
117|   Function      :  chtype menu_back(const MENU *menu)
118|
119|   Description   :  Return the attribute used for selectable but not yet
120|                    selected items.
121|
122|   Return Values :  Attribute value
123+--------------------------------------------------------------------------*/
124GEN_MENU_ATTR_GET_FCT(back)
125
126/*---------------------------------------------------------------------------
127|   Facility      :  libnmenu
128|   Function      :  int set_menu_grey(MENU *menu, chtype attr)
129|
130|   Description   :  Set the attribute for unselectable items.
131|
132|   Return Values :  E_OK             - success
133|                    E_BAD_ARGUMENT   - an invalid value has been passed
134+--------------------------------------------------------------------------*/
135GEN_MENU_ATTR_SET_FCT(grey)
136
137/*---------------------------------------------------------------------------
138|   Facility      :  libnmenu
139|   Function      :  chtype menu_grey(const MENU *menu)
140|
141|   Description   :  Return the attribute used for non-selectable items
142|
143|   Return Values :  Attribute value
144+--------------------------------------------------------------------------*/
145GEN_MENU_ATTR_GET_FCT(grey)
146
147/* m_attribs.c ends here */
148