xref: /freebsd/contrib/ncurses/menu/m_hook.c (revision 1603881667360c015f6685131f2f25474fa67a72)
1 /****************************************************************************
2  * Copyright 2018,2020 Thomas E. Dickey                                     *
3  * Copyright 1998-2012,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 /***************************************************************************
35 * Module m_hook                                                            *
36 * Assign application specific routines for automatic invocation by menus   *
37 ***************************************************************************/
38 
39 #include "menu.priv.h"
40 
41 MODULE_ID("$Id: m_hook.c,v 1.20 2020/07/04 19:45:16 tom Exp $")
42 
43 /* "Template" macro to generate function to set application specific hook */
44 #define GEN_HOOK_SET_FUNCTION( typ, name ) \
45 MENU_EXPORT(int) NCURSES_API set_ ## typ ## _ ## name (MENU *menu, Menu_Hook func )\
46 {\
47    TR_FUNC_BFR(1);\
48    T((T_CALLED("set_" #typ "_" #name "(%p,%s)"), (void *) menu, TR_FUNC_ARG(0, func)));\
49    (Normalize_Menu(menu) -> typ ## name = func );\
50    RETURN(E_OK);\
51 }
52 
53 /* "Template" macro to generate function to get application specific hook */
54 #define GEN_HOOK_GET_FUNCTION( typ, name ) \
55 MENU_EXPORT(Menu_Hook) NCURSES_API typ ## _ ## name ( const MENU *menu )\
56 {\
57    T((T_CALLED(#typ "_" #name "(%p)"), (const void *) menu));\
58    returnMenuHook(Normalize_Menu(menu) -> typ ## name);\
59 }
60 
61 /*---------------------------------------------------------------------------
62 |   Facility      :  libnmenu
63 |   Function      :  int set_menu_init(MENU *menu, void (*f)(MENU *))
64 |
65 |   Description   :  Set user-exit which is called when menu is posted
66 |                    or just after the top row changes.
67 |
68 |   Return Values :  E_OK               - success
69 +--------------------------------------------------------------------------*/
70 GEN_HOOK_SET_FUNCTION(menu, init)
71 
72 /*---------------------------------------------------------------------------
73 |   Facility      :  libnmenu
74 |   Function      :  void (*)(MENU *) menu_init(const MENU *menu)
75 |
76 |   Description   :  Return address of user-exit function which is called
77 |                    when a menu is posted or just after the top row
78 |                    changes.
79 |
80 |   Return Values :  Menu init function address or NULL
81 +--------------------------------------------------------------------------*/
82 GEN_HOOK_GET_FUNCTION(menu, init)
83 
84 /*---------------------------------------------------------------------------
85 |   Facility      :  libnmenu
86 |   Function      :  int set_menu_term (MENU *menu, void (*f)(MENU *))
87 |
88 |   Description   :  Set user-exit which is called when menu is unposted
89 |                    or just before the top row changes.
90 |
91 |   Return Values :  E_OK               - success
92 +--------------------------------------------------------------------------*/
93 GEN_HOOK_SET_FUNCTION(menu, term)
94 
95 /*---------------------------------------------------------------------------
96 |   Facility      :  libnmenu
97 |   Function      :  void (*)(MENU *) menu_term(const MENU *menu)
98 |
99 |   Description   :  Return address of user-exit function which is called
100 |                    when a menu is unposted or just before the top row
101 |                    changes.
102 |
103 |   Return Values :  Menu finalization function address or NULL
104 +--------------------------------------------------------------------------*/
105 GEN_HOOK_GET_FUNCTION(menu, term)
106 
107 /*---------------------------------------------------------------------------
108 |   Facility      :  libnmenu
109 |   Function      :  int set_item_init (MENU *menu, void (*f)(MENU *))
110 |
111 |   Description   :  Set user-exit which is called when menu is posted
112 |                    or just after the current item changes.
113 |
114 |   Return Values :  E_OK               - success
115 +--------------------------------------------------------------------------*/
116 GEN_HOOK_SET_FUNCTION(item, init)
117 
118 /*---------------------------------------------------------------------------
119 |   Facility      :  libnmenu
120 |   Function      :  void (*)(MENU *) item_init (const MENU *menu)
121 |
122 |   Description   :  Return address of user-exit function which is called
123 |                    when a menu is posted or just after the current item
124 |                    changes.
125 |
126 |   Return Values :  Item init function address or NULL
127 +--------------------------------------------------------------------------*/
128 GEN_HOOK_GET_FUNCTION(item, init)
129 
130 /*---------------------------------------------------------------------------
131 |   Facility      :  libnmenu
132 |   Function      :  int set_item_term (MENU *menu, void (*f)(MENU *))
133 |
134 |   Description   :  Set user-exit which is called when menu is unposted
135 |                    or just before the current item changes.
136 |
137 |   Return Values :  E_OK               - success
138 +--------------------------------------------------------------------------*/
139 GEN_HOOK_SET_FUNCTION(item, term)
140 
141 /*---------------------------------------------------------------------------
142 |   Facility      :  libnmenu
143 |   Function      :  void (*)(MENU *) item_init (const MENU *menu)
144 |
145 |   Description   :  Return address of user-exit function which is called
146 |                    when a menu is unposted or just before the current item
147 |                    changes.
148 |
149 |   Return Values :  Item finalization function address or NULL
150 +--------------------------------------------------------------------------*/
151 GEN_HOOK_GET_FUNCTION(item, term)
152 
153 /* m_hook.c ends here */
154