]> ncurses.scripts.mit.edu Git - ncurses.git/blob - menu/m_attribs.c
ncurses 4.1
[ncurses.git] / menu / m_attribs.c
1 /*-----------------------------------------------------------------------------+
2 |           The ncurses menu library is  Copyright (C) 1995-1997               |
3 |             by Juergen Pfeifer <Juergen.Pfeifer@T-Online.de>                 |
4 |                          All Rights Reserved.                                |
5 |                                                                              |
6 | Permission to use, copy, modify, and distribute this software and its        |
7 | documentation for any purpose and without fee is hereby granted, provided    |
8 | that the above copyright notice appear in all copies and that both that      |
9 | copyright notice and this permission notice appear in supporting             |
10 | documentation, and that the name of the above listed copyright holder(s) not |
11 | be used in advertising or publicity pertaining to distribution of the        |
12 | software without specific, written prior permission.                         | 
13 |                                                                              |
14 | THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO  |
15 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-  |
16 | NESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR   |
17 | ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RE- |
18 | SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
19 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH    |
20 | THE USE OR PERFORMANCE OF THIS SOFTWARE.                                     |
21 +-----------------------------------------------------------------------------*/
22
23 /***************************************************************************
24 * Module menu_attribs                                                      *
25 * Control menus display attributes                                         *
26 ***************************************************************************/
27
28 #include "menu.priv.h"
29
30 MODULE_ID("$Id: m_attribs.c,v 1.4 1997/05/01 16:47:26 juergen Exp $")
31
32 /* Macro to redraw menu if it is posted and changed */
33 #define Refresh_Menu(menu) \
34    if ( (menu) && ((menu)->status & _POSTED) )\
35    {\
36       _nc_Draw_Menu( menu );\
37       _nc_Show_Menu( menu );\
38    }
39
40 /* "Template" macro to generate a function to set a menus attribute */
41 #define GEN_MENU_ATTR_SET_FCT( name ) \
42 int set_menu_ ## name (MENU * menu, chtype attr)\
43 {\
44    if (!(attr==A_NORMAL || (attr & A_ATTRIBUTES)==attr))\
45       RETURN(E_BAD_ARGUMENT);\
46    if (menu && ( menu -> name != attr))\
47      {\
48        (menu -> name) = attr;\
49        Refresh_Menu(menu);\
50      }\
51    Normalize_Menu( menu ) -> name = attr;\
52    RETURN(E_OK);\
53 }
54
55 /* "Template" macro to generate a function to get a menus attribute */
56 #define GEN_MENU_ATTR_GET_FCT( name ) \
57 chtype menu_ ## name (const MENU * menu)\
58 {\
59    return (Normalize_Menu( menu ) -> name);\
60 }
61
62 /*---------------------------------------------------------------------------
63 |   Facility      :  libnmenu  
64 |   Function      :  int set_menu_fore(MENU *menu, chtype attr)
65 |   
66 |   Description   :  Set the attribute for selectable items. In single-
67 |                    valued menus thiis is used to highlight the current
68 |                    item ((i.e. where the cursor is), in multi-valued
69 |                    menus this is used to highlight the selected items.
70 |
71 |   Return Values :  E_OK              - success
72 |                    E_BAD_ARGUMENT    - an invalid value has been passed   
73 +--------------------------------------------------------------------------*/
74 GEN_MENU_ATTR_SET_FCT( fore )
75
76 /*---------------------------------------------------------------------------
77 |   Facility      :  libnmenu  
78 |   Function      :  chtype menu_fore(const MENU* menu)
79 |   
80 |   Description   :  Return the attribute used for selectable items that
81 |                    are current (single-valued menu) or selected (multi-
82 |                    valued menu).   
83 |
84 |   Return Values :  Attribute value
85 +--------------------------------------------------------------------------*/
86 GEN_MENU_ATTR_GET_FCT( fore )
87
88 /*---------------------------------------------------------------------------
89 |   Facility      :  libnmenu  
90 |   Function      :  int set_menu_back(MENU *menu, chtype attr)
91 |   
92 |   Description   :  Set the attribute for selectable but not yet selected
93 |                    items.
94 |
95 |   Return Values :  E_OK             - success  
96 |                    E_BAD_ARGUMENT   - an invalid value has been passed
97 +--------------------------------------------------------------------------*/
98 GEN_MENU_ATTR_SET_FCT( back )
99
100 /*---------------------------------------------------------------------------
101 |   Facility      :  libnmenu  
102 |   Function      :  chtype menu_back(const MENU *menu)
103 |   
104 |   Description   :  Return the attribute used for selectable but not yet
105 |                    selected items. 
106 |
107 |   Return Values :  Attribute value
108 +--------------------------------------------------------------------------*/
109 GEN_MENU_ATTR_GET_FCT( back )
110
111 /*---------------------------------------------------------------------------
112 |   Facility      :  libnmenu  
113 |   Function      :  int set_menu_grey(MENU *menu, chtype attr)
114 |   
115 |   Description   :  Set the attribute for unselectable items.
116 |
117 |   Return Values :  E_OK             - success
118 |                    E_BAD_ARGUMENT   - an invalid value has been passed    
119 +--------------------------------------------------------------------------*/
120 GEN_MENU_ATTR_SET_FCT( grey )
121
122 /*---------------------------------------------------------------------------
123 |   Facility      :  libnmenu  
124 |   Function      :  chtype menu_grey(const MENU *menu)
125 |   
126 |   Description   :  Return the attribute used for non-selectable items
127 |
128 |   Return Values :  Attribute value
129 +--------------------------------------------------------------------------*/
130 GEN_MENU_ATTR_GET_FCT( grey )
131 \f
132 /*---------------------------------------------------------------------------
133 |   Facility      :  libnmenu  
134 |   Function      :  int set_menu_pad(MENU *menu, int pad)
135 |   
136 |   Description   :  Set the character to be used to separate the item name
137 |                    from its description. This must be a printable 
138 |                    character.
139 |
140 |   Return Values :  E_OK              - success
141 |                    E_BAD_ARGUMENT    - an invalid value has been passed
142 +--------------------------------------------------------------------------*/
143 int set_menu_pad(MENU *menu, int pad)
144 {
145   bool do_refresh = !(menu);
146
147   if (!isprint((unsigned char)pad))
148     RETURN(E_BAD_ARGUMENT);
149   
150   Normalize_Menu( menu );
151   menu->pad = pad;
152   
153   if (do_refresh)
154       Refresh_Menu( menu );
155
156   RETURN(E_OK);
157 }
158
159 /*---------------------------------------------------------------------------
160 |   Facility      :  libnmenu  
161 |   Function      :  int menu_pad(const MENU *menu)
162 |   
163 |   Description   :  Return the value of the padding character
164 |
165 |   Return Values :  The pad character
166 +--------------------------------------------------------------------------*/
167 int menu_pad(const MENU * menu)
168 {
169   return (Normalize_Menu( menu ) -> pad);
170 }
171
172 /* m_attribs.c ends here */