xref: /freebsd/contrib/ncurses/menu/m_attribs.c (revision e1c4c8dd8d2d10b6104f06856a77bd5b4813a801)
1 /****************************************************************************
2  * Copyright 2020 Thomas E. Dickey                                          *
3  * Copyright 1998-2010,2012 Free Software Foundation, Inc.                  *
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 
41 MODULE_ID("$Id: m_attribs.c,v 1.19 2020/07/04 19:44:58 tom Exp $")
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 ) \
53 MENU_EXPORT(int) NCURSES_API set_menu_ ## name (MENU* menu, chtype attr) \
54 {\
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))\
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 ) \
69 MENU_EXPORT(chtype) NCURSES_API menu_ ## name (const MENU * menu)\
70 {\
71    T((T_CALLED("menu_" #name "(%p)"), (const void *) menu));\
72    returnAttr(Normalize_Menu( menu ) -> name);\
73 }
74 
75 /*---------------------------------------------------------------------------
76 |   Facility      :  libnmenu
77 |   Function      :  int set_menu_fore(MENU *menu, chtype attr)
78 |
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
85 |                    E_BAD_ARGUMENT    - an invalid value has been passed
86 +--------------------------------------------------------------------------*/
87 GEN_MENU_ATTR_SET_FCT(fore)
88 
89 /*---------------------------------------------------------------------------
90 |   Facility      :  libnmenu
91 |   Function      :  chtype menu_fore(const MENU* menu)
92 |
93 |   Description   :  Return the attribute used for selectable items that
94 |                    are current (single-valued menu) or selected (multi-
95 |                    valued menu).
96 |
97 |   Return Values :  Attribute value
98 +--------------------------------------------------------------------------*/
99 GEN_MENU_ATTR_GET_FCT(fore)
100 
101 /*---------------------------------------------------------------------------
102 |   Facility      :  libnmenu
103 |   Function      :  int set_menu_back(MENU *menu, chtype attr)
104 |
105 |   Description   :  Set the attribute for selectable but not yet selected
106 |                    items.
107 |
108 |   Return Values :  E_OK             - success
109 |                    E_BAD_ARGUMENT   - an invalid value has been passed
110 +--------------------------------------------------------------------------*/
111 GEN_MENU_ATTR_SET_FCT(back)
112 
113 /*---------------------------------------------------------------------------
114 |   Facility      :  libnmenu
115 |   Function      :  chtype menu_back(const MENU *menu)
116 |
117 |   Description   :  Return the attribute used for selectable but not yet
118 |                    selected items.
119 |
120 |   Return Values :  Attribute value
121 +--------------------------------------------------------------------------*/
122 GEN_MENU_ATTR_GET_FCT(back)
123 
124 /*---------------------------------------------------------------------------
125 |   Facility      :  libnmenu
126 |   Function      :  int set_menu_grey(MENU *menu, chtype attr)
127 |
128 |   Description   :  Set the attribute for unselectable items.
129 |
130 |   Return Values :  E_OK             - success
131 |                    E_BAD_ARGUMENT   - an invalid value has been passed
132 +--------------------------------------------------------------------------*/
133 GEN_MENU_ATTR_SET_FCT(grey)
134 
135 /*---------------------------------------------------------------------------
136 |   Facility      :  libnmenu
137 |   Function      :  chtype menu_grey(const MENU *menu)
138 |
139 |   Description   :  Return the attribute used for non-selectable items
140 |
141 |   Return Values :  Attribute value
142 +--------------------------------------------------------------------------*/
143 GEN_MENU_ATTR_GET_FCT(grey)
144 
145 /* m_attribs.c ends here */
146