blob: c7d9fe91af7fcee27830206e0b255c0a59ed4665 [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002 * Copyright 2018-2020,2021 Thomas E. Dickey *
3 * Copyright 1998-2012,2016 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304 * *
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
micky3879b9f5e72025-07-08 18:04:53 -040041MODULE_ID("$Id: m_hook.c,v 1.21 2021/06/17 21:26:02 tom Exp $")
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053042
43/* "Template" macro to generate function to set application specific hook */
44#define GEN_HOOK_SET_FUNCTION( typ, name ) \
micky3879b9f5e72025-07-08 18:04:53 -040045MENU_EXPORT(int) NCURSES_API set_ ## typ ## _ ## name (MENU *menu, Menu_Hook func )\
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053046{\
micky3879b9f5e72025-07-08 18:04:53 -040047 TR_FUNC_BFR(1);\
48 T((T_CALLED("set_" #typ "_" #name "(%p,%s)"), (void *) menu, TR_FUNC_ARG(0, func)));\
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053049 (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 ) \
micky3879b9f5e72025-07-08 18:04:53 -040055MENU_EXPORT(Menu_Hook) NCURSES_API typ ## _ ## name ( const MENU *menu )\
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053056{\
Steve Kondikae271bc2015-11-15 02:50:53 +010057 T((T_CALLED(#typ "_" #name "(%p)"), (const void *) menu));\
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053058 returnMenuHook(Normalize_Menu(menu) -> typ ## name);\
59}
60
61/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -040062| Facility : libnmenu
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053063| Function : int set_menu_init(MENU *menu, void (*f)(MENU *))
micky3879b9f5e72025-07-08 18:04:53 -040064|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053065| 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+--------------------------------------------------------------------------*/
70GEN_HOOK_SET_FUNCTION(menu, init)
71
72/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -040073| Facility : libnmenu
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053074| Function : void (*)(MENU *) menu_init(const MENU *menu)
micky3879b9f5e72025-07-08 18:04:53 -040075|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053076| Description : Return address of user-exit function which is called
micky3879b9f5e72025-07-08 18:04:53 -040077| when a menu is posted or just after the top row
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053078| changes.
79|
80| Return Values : Menu init function address or NULL
81+--------------------------------------------------------------------------*/
82GEN_HOOK_GET_FUNCTION(menu, init)
83
84/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -040085| Facility : libnmenu
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053086| Function : int set_menu_term (MENU *menu, void (*f)(MENU *))
micky3879b9f5e72025-07-08 18:04:53 -040087|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053088| 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+--------------------------------------------------------------------------*/
93GEN_HOOK_SET_FUNCTION(menu, term)
94
95/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -040096| Facility : libnmenu
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053097| Function : void (*)(MENU *) menu_term(const MENU *menu)
micky3879b9f5e72025-07-08 18:04:53 -040098|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053099| Description : Return address of user-exit function which is called
micky3879b9f5e72025-07-08 18:04:53 -0400100| when a menu is unposted or just before the top row
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530101| changes.
102|
103| Return Values : Menu finalization function address or NULL
104+--------------------------------------------------------------------------*/
105GEN_HOOK_GET_FUNCTION(menu, term)
106
107/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -0400108| Facility : libnmenu
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530109| Function : int set_item_init (MENU *menu, void (*f)(MENU *))
micky3879b9f5e72025-07-08 18:04:53 -0400110|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530111| 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+--------------------------------------------------------------------------*/
116GEN_HOOK_SET_FUNCTION(item, init)
117
118/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -0400119| Facility : libnmenu
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530120| Function : void (*)(MENU *) item_init (const MENU *menu)
micky3879b9f5e72025-07-08 18:04:53 -0400121|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530122| Description : Return address of user-exit function which is called
micky3879b9f5e72025-07-08 18:04:53 -0400123| when a menu is posted or just after the current item
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530124| changes.
125|
126| Return Values : Item init function address or NULL
127+--------------------------------------------------------------------------*/
128GEN_HOOK_GET_FUNCTION(item, init)
129
130/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -0400131| Facility : libnmenu
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530132| Function : int set_item_term (MENU *menu, void (*f)(MENU *))
micky3879b9f5e72025-07-08 18:04:53 -0400133|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530134| 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+--------------------------------------------------------------------------*/
139GEN_HOOK_SET_FUNCTION(item, term)
140
141/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -0400142| Facility : libnmenu
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530143| Function : void (*)(MENU *) item_init (const MENU *menu)
micky3879b9f5e72025-07-08 18:04:53 -0400144|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530145| Description : Return address of user-exit function which is called
micky3879b9f5e72025-07-08 18:04:53 -0400146| when a menu is unposted or just before the current item
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530147| changes.
148|
149| Return Values : Item finalization function address or NULL
150+--------------------------------------------------------------------------*/
151GEN_HOOK_GET_FUNCTION(item, term)
152
153/* m_hook.c ends here */