xref: /freebsd/contrib/ncurses/form/fld_attr.c (revision ebacd8013fe5f7fdf9f6a5b286f6680dd2891036)
1 /****************************************************************************
2  * Copyright 2020 Thomas E. Dickey                                          *
3  * Copyright 1998-2010,2016 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 #include "form.priv.h"
35 
36 MODULE_ID("$Id: fld_attr.c,v 1.15 2020/12/11 22:05:24 tom Exp $")
37 
38 /*----------------------------------------------------------------------------
39   Field-Attribute manipulation routines
40   --------------------------------------------------------------------------*/
41 /* "Template" macro to generate a function to set a field's attribute */
42 #define GEN_FIELD_ATTR_SET_FCT( name ) \
43 FORM_IMPEXP int NCURSES_API set_field_ ## name (FIELD * field, chtype attr)\
44 {\
45    int res = E_BAD_ARGUMENT;\
46    T((T_CALLED("set_field_" #name "(%p,%s)"), (void *)field, _traceattr(attr)));\
47    if ( attr==A_NORMAL || ((attr & A_ATTRIBUTES)==attr) )\
48      {\
49        Normalize_Field( field );\
50        if (field != 0) \
51 	 { \
52 	 if ((field -> name) != attr)\
53 	   {\
54 	     field -> name = attr;\
55 	     res = _nc_Synchronize_Attributes( field );\
56 	   }\
57 	 else\
58 	   {\
59 	     res = E_OK;\
60 	   }\
61 	 }\
62      }\
63    RETURN(res);\
64 }
65 
66 /* "Template" macro to generate a function to get a field's attribute */
67 #define GEN_FIELD_ATTR_GET_FCT( name ) \
68 FORM_IMPEXP chtype NCURSES_API field_ ## name (const FIELD * field)\
69 {\
70    T((T_CALLED("field_" #name "(%p)"), (const void *) field));\
71    returnAttr( A_ATTRIBUTES & (Normalize_Field( field ) -> name) );\
72 }
73 
74 /*---------------------------------------------------------------------------
75 |   Facility      :  libnform
76 |   Function      :  int set_field_fore(FIELD *field, chtype attr)
77 |
78 |   Description   :  Sets the foreground of the field used to display the
79 |                    field contents.
80 |
81 |   Return Values :  E_OK             - success
82 |                    E_BAD_ARGUMENT   - invalid attributes
83 |                    E_SYSTEM_ERROR   - system error
84 +--------------------------------------------------------------------------*/
85 GEN_FIELD_ATTR_SET_FCT(fore)
86 
87 /*---------------------------------------------------------------------------
88 |   Facility      :  libnform
89 |   Function      :  chtype field_fore(const FIELD *)
90 |
91 |   Description   :  Retrieve field's foreground attribute
92 |
93 |   Return Values :  The foreground attribute
94 +--------------------------------------------------------------------------*/
95 GEN_FIELD_ATTR_GET_FCT(fore)
96 
97 /*---------------------------------------------------------------------------
98 |   Facility      :  libnform
99 |   Function      :  int set_field_back(FIELD *field, chtype attr)
100 |
101 |   Description   :  Sets the background of the field used to display the
102 |                    field's extend.
103 |
104 |   Return Values :  E_OK             - success
105 |                    E_BAD_ARGUMENT   - invalid attributes
106 |                    E_SYSTEM_ERROR   - system error
107 +--------------------------------------------------------------------------*/
108 GEN_FIELD_ATTR_SET_FCT(back)
109 
110 /*---------------------------------------------------------------------------
111 |   Facility      :  libnform
112 |   Function      :  chtype field_back(const
113 |
114 |   Description   :  Retrieve field's background attribute
115 |
116 |   Return Values :  The background attribute
117 +--------------------------------------------------------------------------*/
118 GEN_FIELD_ATTR_GET_FCT(back)
119 
120 /* fld_attr.c ends here */
121