1 /****************************************************************************
2 * Copyright 2020 Thomas E. Dickey *
3 * Copyright 1998-2010,2016 Free Software Foundation, Inc. *
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: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
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. *
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 *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Juergen Pfeifer, 1995,1997 *
32 ****************************************************************************/
34 #include "form.priv.h"
36 MODULE_ID("$Id: fld_attr.c,v 1.15 2020/12/11 22:05:24 tom Exp $")
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)\
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) )\
49 Normalize_Field( field );\
52 if ((field -> name) != attr)\
54 field -> name = attr;\
55 res = _nc_Synchronize_Attributes( field );\
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)\
70 T((T_CALLED("field_" #name "(%p)"), (const void *) field));\
71 returnAttr( A_ATTRIBUTES & (Normalize_Field( field ) -> name) );\
74 /*---------------------------------------------------------------------------
76 | Function : int set_field_fore(FIELD *field, chtype attr)
78 | Description : Sets the foreground of the field used to display the
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)
87 /*---------------------------------------------------------------------------
89 | Function : chtype field_fore(const FIELD *)
91 | Description : Retrieve field's foreground attribute
93 | Return Values : The foreground attribute
94 +--------------------------------------------------------------------------*/
95 GEN_FIELD_ATTR_GET_FCT(fore)
97 /*---------------------------------------------------------------------------
99 | Function : int set_field_back(FIELD *field, chtype attr)
101 | Description : Sets the background of the field used to display the
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)
110 /*---------------------------------------------------------------------------
111 | Facility : libnform
112 | Function : chtype field_back(const
114 | Description : Retrieve field's background attribute
116 | Return Values : The background attribute
117 +--------------------------------------------------------------------------*/
118 GEN_FIELD_ATTR_GET_FCT(back)
120 /* fld_attr.c ends here */