1 /****************************************************************************
2 * Copyright 2018,2020 Thomas E. Dickey *
3 * Copyright 1998-2012,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 /***************************************************************************
36 * Assign application specific routines for automatic invocation by menus *
37 ***************************************************************************/
39 #include "menu.priv.h"
41 MODULE_ID("$Id: m_hook.c,v 1.20 2020/07/04 19:45:16 tom Exp $")
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 )\
48 T((T_CALLED("set_" #typ "_" #name "(%p,%s)"), (void *) menu, TR_FUNC_ARG(0, func)));\
49 (Normalize_Menu(menu) -> typ ## name = func );\
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 )\
57 T((T_CALLED(#typ "_" #name "(%p)"), (const void *) menu));\
58 returnMenuHook(Normalize_Menu(menu) -> typ ## name);\
61 /*---------------------------------------------------------------------------
63 | Function : int set_menu_init(MENU *menu, void (*f)(MENU *))
65 | Description : Set user-exit which is called when menu is posted
66 | or just after the top row changes.
68 | Return Values : E_OK - success
69 +--------------------------------------------------------------------------*/
70 GEN_HOOK_SET_FUNCTION(menu, init)
72 /*---------------------------------------------------------------------------
74 | Function : void (*)(MENU *) menu_init(const MENU *menu)
76 | Description : Return address of user-exit function which is called
77 | when a menu is posted or just after the top row
80 | Return Values : Menu init function address or NULL
81 +--------------------------------------------------------------------------*/
82 GEN_HOOK_GET_FUNCTION(menu, init)
84 /*---------------------------------------------------------------------------
86 | Function : int set_menu_term (MENU *menu, void (*f)(MENU *))
88 | Description : Set user-exit which is called when menu is unposted
89 | or just before the top row changes.
91 | Return Values : E_OK - success
92 +--------------------------------------------------------------------------*/
93 GEN_HOOK_SET_FUNCTION(menu, term)
95 /*---------------------------------------------------------------------------
97 | Function : void (*)(MENU *) menu_term(const MENU *menu)
99 | Description : Return address of user-exit function which is called
100 | when a menu is unposted or just before the top row
103 | Return Values : Menu finalization function address or NULL
104 +--------------------------------------------------------------------------*/
105 GEN_HOOK_GET_FUNCTION(menu, term)
107 /*---------------------------------------------------------------------------
108 | Facility : libnmenu
109 | Function : int set_item_init (MENU *menu, void (*f)(MENU *))
111 | Description : Set user-exit which is called when menu is posted
112 | or just after the current item changes.
114 | Return Values : E_OK - success
115 +--------------------------------------------------------------------------*/
116 GEN_HOOK_SET_FUNCTION(item, init)
118 /*---------------------------------------------------------------------------
119 | Facility : libnmenu
120 | Function : void (*)(MENU *) item_init (const MENU *menu)
122 | Description : Return address of user-exit function which is called
123 | when a menu is posted or just after the current item
126 | Return Values : Item init function address or NULL
127 +--------------------------------------------------------------------------*/
128 GEN_HOOK_GET_FUNCTION(item, init)
130 /*---------------------------------------------------------------------------
131 | Facility : libnmenu
132 | Function : int set_item_term (MENU *menu, void (*f)(MENU *))
134 | Description : Set user-exit which is called when menu is unposted
135 | or just before the current item changes.
137 | Return Values : E_OK - success
138 +--------------------------------------------------------------------------*/
139 GEN_HOOK_SET_FUNCTION(item, term)
141 /*---------------------------------------------------------------------------
142 | Facility : libnmenu
143 | Function : void (*)(MENU *) item_init (const MENU *menu)
145 | Description : Return address of user-exit function which is called
146 | when a menu is unposted or just before the current item
149 | Return Values : Item finalization function address or NULL
150 +--------------------------------------------------------------------------*/
151 GEN_HOOK_GET_FUNCTION(item, term)
153 /* m_hook.c ends here */