xref: /openbsd/lib/libform/fld_attr.c (revision 5dea098c)
1 /*	$OpenBSD: fld_attr.c,v 1.7 2023/10/17 09:52:10 nicm Exp $	*/
2 /****************************************************************************
3  * Copyright 2020 Thomas E. Dickey                                          *
4  * Copyright 1998-2010,2016 Free Software Foundation, Inc.                  *
5  *                                                                          *
6  * Permission is hereby granted, free of charge, to any person obtaining a  *
7  * copy of this software and associated documentation files (the            *
8  * "Software"), to deal in the Software without restriction, including      *
9  * without limitation the rights to use, copy, modify, merge, publish,      *
10  * distribute, distribute with modifications, sublicense, and/or sell       *
11  * copies of the Software, and to permit persons to whom the Software is    *
12  * furnished to do so, subject to the following conditions:                 *
13  *                                                                          *
14  * The above copyright notice and this permission notice shall be included  *
15  * in all copies or substantial portions of the Software.                   *
16  *                                                                          *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24  *                                                                          *
25  * Except as contained in this notice, the name(s) of the above copyright   *
26  * holders shall not be used in advertising or otherwise to promote the     *
27  * sale, use or other dealings in this Software without prior written       *
28  * authorization.                                                           *
29  ****************************************************************************/
30 
31 /****************************************************************************
32  *   Author:  Juergen Pfeifer, 1995,1997                                    *
33  ****************************************************************************/
34 
35 #include "form.priv.h"
36 
37 MODULE_ID("$Id: fld_attr.c,v 1.7 2023/10/17 09:52:10 nicm Exp $")
38 
39 /*----------------------------------------------------------------------------
40   Field-Attribute manipulation routines
41   --------------------------------------------------------------------------*/
42 /* "Template" macro to generate a function to set a field's attribute */
43 #define GEN_FIELD_ATTR_SET_FCT( name ) \
44 FORM_IMPEXP int NCURSES_API set_field_ ## name (FIELD * field, chtype attr)\
45 {\
46    int res = E_BAD_ARGUMENT;\
47    T((T_CALLED("set_field_" #name "(%p,%s)"), (void *)field, _traceattr(attr)));\
48    if ( attr==A_NORMAL || ((attr & A_ATTRIBUTES)==attr) )\
49      {\
50        Normalize_Field( field );\
51        if (field != 0) \
52 	 { \
53 	 if ((field -> name) != attr)\
54 	   {\
55 	     field -> name = attr;\
56 	     res = _nc_Synchronize_Attributes( field );\
57 	   }\
58 	 else\
59 	   {\
60 	     res = E_OK;\
61 	   }\
62 	 }\
63      }\
64    RETURN(res);\
65 }
66 
67 /* "Template" macro to generate a function to get a field's attribute */
68 #define GEN_FIELD_ATTR_GET_FCT( name ) \
69 FORM_IMPEXP chtype NCURSES_API field_ ## name (const FIELD * field)\
70 {\
71    T((T_CALLED("field_" #name "(%p)"), (const void *) field));\
72    returnAttr( A_ATTRIBUTES & (Normalize_Field( field ) -> name) );\
73 }
74 
75 /*---------------------------------------------------------------------------
76 |   Facility      :  libnform
77 |   Function      :  int set_field_fore(FIELD *field, chtype attr)
78 |
79 |   Description   :  Sets the foreground of the field used to display the
80 |                    field contents.
81 |
82 |   Return Values :  E_OK             - success
83 |                    E_BAD_ARGUMENT   - invalid attributes
84 |                    E_SYSTEM_ERROR   - system error
85 +--------------------------------------------------------------------------*/
86 GEN_FIELD_ATTR_SET_FCT(fore)
87 
88 /*---------------------------------------------------------------------------
89 |   Facility      :  libnform
90 |   Function      :  chtype field_fore(const FIELD *)
91 |
92 |   Description   :  Retrieve field's foreground attribute
93 |
94 |   Return Values :  The foreground attribute
95 +--------------------------------------------------------------------------*/
96 GEN_FIELD_ATTR_GET_FCT(fore)
97 
98 /*---------------------------------------------------------------------------
99 |   Facility      :  libnform
100 |   Function      :  int set_field_back(FIELD *field, chtype attr)
101 |
102 |   Description   :  Sets the background of the field used to display the
103 |                    field's extend.
104 |
105 |   Return Values :  E_OK             - success
106 |                    E_BAD_ARGUMENT   - invalid attributes
107 |                    E_SYSTEM_ERROR   - system error
108 +--------------------------------------------------------------------------*/
109 GEN_FIELD_ATTR_SET_FCT(back)
110 
111 /*---------------------------------------------------------------------------
112 |   Facility      :  libnform
113 |   Function      :  chtype field_back(const
114 |
115 |   Description   :  Retrieve field's background attribute
116 |
117 |   Return Values :  The background attribute
118 +--------------------------------------------------------------------------*/
119 GEN_FIELD_ATTR_GET_FCT(back)
120 
121 /* fld_attr.c ends here */
122