]> ncurses.scripts.mit.edu Git - ncurses.git/blob - menu/m_attribs.c
34db8802d5187576c7073dbc0ef805dbbb1fd2bf
[ncurses.git] / menu / m_attribs.c
1 /****************************************************************************
2  * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
3  *                                                                          *
4  * Permission is hereby granted, free of charge, to any person obtaining a  *
5  * copy of this software and associated documentation files (the            *
6  * "Software"), to deal in the Software without restriction, including      *
7  * without limitation the rights to use, copy, modify, merge, publish,      *
8  * distribute, distribute with modifications, sublicense, and/or sell       *
9  * copies of the Software, and to permit persons to whom the Software is    *
10  * furnished to do so, subject to the following conditions:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22  *                                                                          *
23  * Except as contained in this notice, the name(s) of the above copyright   *
24  * holders shall not be used in advertising or otherwise to promote the     *
25  * sale, use or other dealings in this Software without prior written       *
26  * authorization.                                                           *
27  ****************************************************************************/
28
29 /****************************************************************************
30  *   Author:  Juergen Pfeifer, 1995,1997                                    *
31  *   Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en             *
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.10 2002/07/06 15:22:16 juergen 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 NCURSES_IMPEXP int NCURSES_API set_menu_ ## name (MENU * menu, chtype attr)\
54 {\
55    if (!(attr==A_NORMAL || (attr & A_ATTRIBUTES)==attr))\
56       RETURN(E_BAD_ARGUMENT);\
57    if (menu && ( menu -> name != attr))\
58      {\
59        (menu -> name) = attr;\
60        Refresh_Menu(menu);\
61      }\
62    Normalize_Menu( menu ) -> name = attr;\
63    RETURN(E_OK);\
64 }
65
66 /* "Template" macro to generate a function to get a menus attribute */
67 #define GEN_MENU_ATTR_GET_FCT( name ) \
68 NCURSES_IMPEXP chtype NCURSES_API menu_ ## name (const MENU * menu)\
69 {\
70    return (Normalize_Menu( menu ) -> name);\
71 }
72
73 /*---------------------------------------------------------------------------
74 |   Facility      :  libnmenu  
75 |   Function      :  int set_menu_fore(MENU *menu, chtype attr)
76 |   
77 |   Description   :  Set the attribute for selectable items. In single-
78 |                    valued menus thiis is used to highlight the current
79 |                    item ((i.e. where the cursor is), in multi-valued
80 |                    menus this is used to highlight the selected items.
81 |
82 |   Return Values :  E_OK              - success
83 |                    E_BAD_ARGUMENT    - an invalid value has been passed   
84 +--------------------------------------------------------------------------*/
85 GEN_MENU_ATTR_SET_FCT( fore )
86
87 /*---------------------------------------------------------------------------
88 |   Facility      :  libnmenu  
89 |   Function      :  chtype menu_fore(const MENU* menu)
90 |   
91 |   Description   :  Return the attribute used for selectable items that
92 |                    are current (single-valued menu) or selected (multi-
93 |                    valued menu).   
94 |
95 |   Return Values :  Attribute value
96 +--------------------------------------------------------------------------*/
97 GEN_MENU_ATTR_GET_FCT( fore )
98
99 /*---------------------------------------------------------------------------
100 |   Facility      :  libnmenu  
101 |   Function      :  int set_menu_back(MENU *menu, chtype attr)
102 |   
103 |   Description   :  Set the attribute for selectable but not yet selected
104 |                    items.
105 |
106 |   Return Values :  E_OK             - success  
107 |                    E_BAD_ARGUMENT   - an invalid value has been passed
108 +--------------------------------------------------------------------------*/
109 GEN_MENU_ATTR_SET_FCT( back )
110
111 /*---------------------------------------------------------------------------
112 |   Facility      :  libnmenu  
113 |   Function      :  chtype menu_back(const MENU *menu)
114 |   
115 |   Description   :  Return the attribute used for selectable but not yet
116 |                    selected items. 
117 |
118 |   Return Values :  Attribute value
119 +--------------------------------------------------------------------------*/
120 GEN_MENU_ATTR_GET_FCT( back )
121
122 /*---------------------------------------------------------------------------
123 |   Facility      :  libnmenu  
124 |   Function      :  int set_menu_grey(MENU *menu, chtype attr)
125 |   
126 |   Description   :  Set the attribute for unselectable items.
127 |
128 |   Return Values :  E_OK             - success
129 |                    E_BAD_ARGUMENT   - an invalid value has been passed    
130 +--------------------------------------------------------------------------*/
131 GEN_MENU_ATTR_SET_FCT( grey )
132
133 /*---------------------------------------------------------------------------
134 |   Facility      :  libnmenu  
135 |   Function      :  chtype menu_grey(const MENU *menu)
136 |   
137 |   Description   :  Return the attribute used for non-selectable items
138 |
139 |   Return Values :  Attribute value
140 +--------------------------------------------------------------------------*/
141 GEN_MENU_ATTR_GET_FCT( grey )
142 /* m_attribs.c ends here */