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
36MODULE_ID("$Id: fld_attr.c,v 1.13 2020/02/02 23:34:34 tom Exp $")
37
38/*----------------------------------------------------------------------------
39  Field-Attribute manipulation routines
40  --------------------------------------------------------------------------*/
41/* "Template" macro to generate a function to set a fields attribute */
42#define GEN_FIELD_ATTR_SET_FCT( name ) \
43NCURSES_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 fields attribute */
67#define GEN_FIELD_ATTR_GET_FCT( name ) \
68NCURSES_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+--------------------------------------------------------------------------*/
85GEN_FIELD_ATTR_SET_FCT(fore)
86
87/*---------------------------------------------------------------------------
88|   Facility      :  libnform
89|   Function      :  chtype field_fore(const FIELD *)
90|
91|   Description   :  Retrieve fields foreground attribute
92|
93|   Return Values :  The foreground attribute
94+--------------------------------------------------------------------------*/
95GEN_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|                    fields extend.
103|
104|   Return Values :  E_OK             - success
105|                    E_BAD_ARGUMENT   - invalid attributes
106|                    E_SYSTEM_ERROR   - system error
107+--------------------------------------------------------------------------*/
108GEN_FIELD_ATTR_SET_FCT(back)
109
110/*---------------------------------------------------------------------------
111|   Facility      :  libnform
112|   Function      :  chtype field_back(const
113|
114|   Description   :  Retrieve fields background attribute
115|
116|   Return Values :  The background attribute
117+--------------------------------------------------------------------------*/
118GEN_FIELD_ATTR_GET_FCT(back)
119
120/* fld_attr.c ends here */
121