1 /****************************************************************************
2 * Copyright (c) 1998-2016,2018 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Juergen Pfeifer, 1995,1997 *
31 ****************************************************************************/
33 /***************************************************************************
35 * Assign application specific routines for automatic invocation by menus *
36 ***************************************************************************/
38 #include "menu.priv.h"
40 MODULE_ID("$Id: m_hook.c,v 1.18 2018/12/16 00:13:36 tom Exp $")
42 /* "Template" macro to generate function to set application specific hook */
43 #define GEN_HOOK_SET_FUNCTION( typ, name ) \
44 NCURSES_IMPEXP int NCURSES_API set_ ## typ ## _ ## name (MENU *menu, Menu_Hook func )\
47 T((T_CALLED("set_" #typ "_" #name "(%p,%s)"), (void *) menu, TR_FUNC_ARG(0, func)));\
48 (Normalize_Menu(menu) -> typ ## name = func );\
52 /* "Template" macro to generate function to get application specific hook */
53 #define GEN_HOOK_GET_FUNCTION( typ, name ) \
54 NCURSES_IMPEXP Menu_Hook NCURSES_API typ ## _ ## name ( const MENU *menu )\
56 T((T_CALLED(#typ "_" #name "(%p)"), (const void *) menu));\
57 returnMenuHook(Normalize_Menu(menu) -> typ ## name);\
60 /*---------------------------------------------------------------------------
62 | Function : int set_menu_init(MENU *menu, void (*f)(MENU *))
64 | Description : Set user-exit which is called when menu is posted
65 | or just after the top row changes.
67 | Return Values : E_OK - success
68 +--------------------------------------------------------------------------*/
69 GEN_HOOK_SET_FUNCTION(menu, init)
71 /*---------------------------------------------------------------------------
73 | Function : void (*)(MENU *) menu_init(const MENU *menu)
75 | Description : Return address of user-exit function which is called
76 | when a menu is posted or just after the top row
79 | Return Values : Menu init function address or NULL
80 +--------------------------------------------------------------------------*/
81 GEN_HOOK_GET_FUNCTION(menu, init)
83 /*---------------------------------------------------------------------------
85 | Function : int set_menu_term (MENU *menu, void (*f)(MENU *))
87 | Description : Set user-exit which is called when menu is unposted
88 | or just before the top row changes.
90 | Return Values : E_OK - success
91 +--------------------------------------------------------------------------*/
92 GEN_HOOK_SET_FUNCTION(menu, term)
94 /*---------------------------------------------------------------------------
96 | Function : void (*)(MENU *) menu_term(const MENU *menu)
98 | Description : Return address of user-exit function which is called
99 | when a menu is unposted or just before the top row
102 | Return Values : Menu finalization function address or NULL
103 +--------------------------------------------------------------------------*/
104 GEN_HOOK_GET_FUNCTION(menu, term)
106 /*---------------------------------------------------------------------------
107 | Facility : libnmenu
108 | Function : int set_item_init (MENU *menu, void (*f)(MENU *))
110 | Description : Set user-exit which is called when menu is posted
111 | or just after the current item changes.
113 | Return Values : E_OK - success
114 +--------------------------------------------------------------------------*/
115 GEN_HOOK_SET_FUNCTION(item, init)
117 /*---------------------------------------------------------------------------
118 | Facility : libnmenu
119 | Function : void (*)(MENU *) item_init (const MENU *menu)
121 | Description : Return address of user-exit function which is called
122 | when a menu is posted or just after the current item
125 | Return Values : Item init function address or NULL
126 +--------------------------------------------------------------------------*/
127 GEN_HOOK_GET_FUNCTION(item, init)
129 /*---------------------------------------------------------------------------
130 | Facility : libnmenu
131 | Function : int set_item_term (MENU *menu, void (*f)(MENU *))
133 | Description : Set user-exit which is called when menu is unposted
134 | or just before the current item changes.
136 | Return Values : E_OK - success
137 +--------------------------------------------------------------------------*/
138 GEN_HOOK_SET_FUNCTION(item, term)
140 /*---------------------------------------------------------------------------
141 | Facility : libnmenu
142 | Function : void (*)(MENU *) item_init (const MENU *menu)
144 | Description : Return address of user-exit function which is called
145 | when a menu is unposted or just before the current item
148 | Return Values : Item finalization function address or NULL
149 +--------------------------------------------------------------------------*/
150 GEN_HOOK_GET_FUNCTION(item, term)
152 /* m_hook.c ends here */