xref: /openbsd-src/lib/libform/frm_hook.c (revision c7ef0cfc17afcba97172c25e1e3a943e893bc632)
1*c7ef0cfcSnicm /*	$OpenBSD: frm_hook.c,v 1.9 2023/10/17 09:52:10 nicm Exp $	*/
202f2426aSmillert /****************************************************************************
3*c7ef0cfcSnicm  * Copyright 2018,2020 Thomas E. Dickey                                     *
4*c7ef0cfcSnicm  * Copyright 1998-2012,2016 Free Software Foundation, Inc.                  *
502f2426aSmillert  *                                                                          *
602f2426aSmillert  * Permission is hereby granted, free of charge, to any person obtaining a  *
702f2426aSmillert  * copy of this software and associated documentation files (the            *
802f2426aSmillert  * "Software"), to deal in the Software without restriction, including      *
902f2426aSmillert  * without limitation the rights to use, copy, modify, merge, publish,      *
1002f2426aSmillert  * distribute, distribute with modifications, sublicense, and/or sell       *
1102f2426aSmillert  * copies of the Software, and to permit persons to whom the Software is    *
1202f2426aSmillert  * furnished to do so, subject to the following conditions:                 *
1302f2426aSmillert  *                                                                          *
1402f2426aSmillert  * The above copyright notice and this permission notice shall be included  *
1502f2426aSmillert  * in all copies or substantial portions of the Software.                   *
1602f2426aSmillert  *                                                                          *
1702f2426aSmillert  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
1802f2426aSmillert  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
1902f2426aSmillert  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
2002f2426aSmillert  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
2102f2426aSmillert  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
2202f2426aSmillert  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
2302f2426aSmillert  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
2402f2426aSmillert  *                                                                          *
2502f2426aSmillert  * Except as contained in this notice, the name(s) of the above copyright   *
2602f2426aSmillert  * holders shall not be used in advertising or otherwise to promote the     *
2702f2426aSmillert  * sale, use or other dealings in this Software without prior written       *
2802f2426aSmillert  * authorization.                                                           *
2902f2426aSmillert  ****************************************************************************/
3002f2426aSmillert 
3102f2426aSmillert /****************************************************************************
3281d8c4e1Snicm  *   Author:  Juergen Pfeifer, 1995,1997                                    *
3302f2426aSmillert  ****************************************************************************/
34ae611fdaStholo 
35ae611fdaStholo #include "form.priv.h"
36ae611fdaStholo 
37*c7ef0cfcSnicm MODULE_ID("$Id: frm_hook.c,v 1.9 2023/10/17 09:52:10 nicm Exp $")
386cd90de4Smillert 
39ae611fdaStholo /* "Template" macro to generate function to set application specific hook */
40ae611fdaStholo #define GEN_HOOK_SET_FUNCTION( typ, name ) \
41*c7ef0cfcSnicm FORM_IMPEXP int NCURSES_API set_ ## typ ## _ ## name (FORM *form, Form_Hook func)\
42ae611fdaStholo {\
43*c7ef0cfcSnicm    TR_FUNC_BFR(1); \
44*c7ef0cfcSnicm    T((T_CALLED("set_" #typ"_"#name"(%p,%s)"), (void *) form, TR_FUNC_ARG(0, func)));\
45ae611fdaStholo    (Normalize_Form( form ) -> typ ## name) = func ;\
46ae611fdaStholo    RETURN(E_OK);\
47ae611fdaStholo }
48ae611fdaStholo 
49ae611fdaStholo /* "Template" macro to generate function to get application specific hook */
50ae611fdaStholo #define GEN_HOOK_GET_FUNCTION( typ, name ) \
51*c7ef0cfcSnicm FORM_IMPEXP Form_Hook NCURSES_API typ ## _ ## name ( const FORM *form )\
52ae611fdaStholo {\
53*c7ef0cfcSnicm    T((T_CALLED(#typ "_" #name "(%p)"), (const void *) form));\
5481d8c4e1Snicm    returnFormHook( Normalize_Form( form ) -> typ ## name );\
55ae611fdaStholo }
5681d8c4e1Snicm 
57ae611fdaStholo /*---------------------------------------------------------------------------
58ae611fdaStholo |   Facility      :  libnform
59ae611fdaStholo |   Function      :  int set_field_init(FORM *form, Form_Hook f)
60ae611fdaStholo |
61ae611fdaStholo |   Description   :  Assigns an application defined initialization function
62ae611fdaStholo |                    to be called when the form is posted and just after
63ae611fdaStholo |                    the current field changes.
64ae611fdaStholo |
65ae611fdaStholo |   Return Values :  E_OK      - success
66ae611fdaStholo +--------------------------------------------------------------------------*/
67ae611fdaStholo GEN_HOOK_SET_FUNCTION(field, init)
68ae611fdaStholo 
69ae611fdaStholo /*---------------------------------------------------------------------------
70ae611fdaStholo |   Facility      :  libnform
71ae611fdaStholo |   Function      :  Form_Hook field_init(const FORM *form)
72ae611fdaStholo |
73ae611fdaStholo |   Description   :  Retrieve field initialization routine address.
74ae611fdaStholo |
75ae611fdaStholo |   Return Values :  The address or NULL if no hook defined.
76ae611fdaStholo +--------------------------------------------------------------------------*/
77ae611fdaStholo GEN_HOOK_GET_FUNCTION(field, init)
78ae611fdaStholo 
79ae611fdaStholo /*---------------------------------------------------------------------------
80ae611fdaStholo |   Facility      :  libnform
81ae611fdaStholo |   Function      :  int set_field_term(FORM *form, Form_Hook f)
82ae611fdaStholo |
83ae611fdaStholo |   Description   :  Assigns an application defined finalization function
84ae611fdaStholo |                    to be called when the form is unposted and just before
85ae611fdaStholo |                    the current field changes.
86ae611fdaStholo |
87ae611fdaStholo |   Return Values :  E_OK      - success
88ae611fdaStholo +--------------------------------------------------------------------------*/
89ae611fdaStholo GEN_HOOK_SET_FUNCTION(field, term)
90ae611fdaStholo 
91ae611fdaStholo /*---------------------------------------------------------------------------
92ae611fdaStholo |   Facility      :  libnform
93ae611fdaStholo |   Function      :  Form_Hook field_term(const FORM *form)
94ae611fdaStholo |
95ae611fdaStholo |   Description   :  Retrieve field finalization routine address.
96ae611fdaStholo |
97ae611fdaStholo |   Return Values :  The address or NULL if no hook defined.
98ae611fdaStholo +--------------------------------------------------------------------------*/
99ae611fdaStholo GEN_HOOK_GET_FUNCTION(field, term)
100ae611fdaStholo 
101ae611fdaStholo /*---------------------------------------------------------------------------
102ae611fdaStholo |   Facility      :  libnform
103ae611fdaStholo |   Function      :  int set_form_init(FORM *form, Form_Hook f)
104ae611fdaStholo |
105ae611fdaStholo |   Description   :  Assigns an application defined initialization function
106ae611fdaStholo |                    to be called when the form is posted and just after
107ae611fdaStholo |                    a page change.
108ae611fdaStholo |
109ae611fdaStholo |   Return Values :  E_OK       - success
110ae611fdaStholo +--------------------------------------------------------------------------*/
111ae611fdaStholo GEN_HOOK_SET_FUNCTION(form, init)
112ae611fdaStholo 
113ae611fdaStholo /*---------------------------------------------------------------------------
114ae611fdaStholo |   Facility      :  libnform
115ae611fdaStholo |   Function      :  Form_Hook form_init(const FORM *form)
116ae611fdaStholo |
117ae611fdaStholo |   Description   :  Retrieve form initialization routine address.
118ae611fdaStholo |
119ae611fdaStholo |   Return Values :  The address or NULL if no hook defined.
120ae611fdaStholo +--------------------------------------------------------------------------*/
121ae611fdaStholo GEN_HOOK_GET_FUNCTION(form, init)
122ae611fdaStholo 
123ae611fdaStholo /*---------------------------------------------------------------------------
124ae611fdaStholo |   Facility      :  libnform
125ae611fdaStholo |   Function      :  int set_form_term(FORM *form, Form_Hook f)
126ae611fdaStholo |
127ae611fdaStholo |   Description   :  Assigns an application defined finalization function
128ae611fdaStholo |                    to be called when the form is unposted and just before
129ae611fdaStholo |                    a page change.
130ae611fdaStholo |
131ae611fdaStholo |   Return Values :  E_OK       - success
132ae611fdaStholo +--------------------------------------------------------------------------*/
133ae611fdaStholo GEN_HOOK_SET_FUNCTION(form, term)
134ae611fdaStholo 
135ae611fdaStholo /*---------------------------------------------------------------------------
136ae611fdaStholo |   Facility      :  libnform
137ae611fdaStholo |   Function      :  Form_Hook form_term(const FORM *form)
138ae611fdaStholo |
139ae611fdaStholo |   Description   :  Retrieve form finalization routine address.
140ae611fdaStholo |
141ae611fdaStholo |   Return Values :  The address or NULL if no hook defined.
142ae611fdaStholo +--------------------------------------------------------------------------*/
143ae611fdaStholo GEN_HOOK_GET_FUNCTION(form, term)
144ae611fdaStholo 
145ae611fdaStholo /* frm_hook.c ends here */
146