1*c7ef0cfcSnicm /* $OpenBSD: m_hook.c,v 1.8 2023/10/17 09:52:10 nicm Exp $ */ 29f1aa62bSmillert 3457960bfSmillert /**************************************************************************** 4*c7ef0cfcSnicm * Copyright 2018-2020,2021 Thomas E. Dickey * 5*c7ef0cfcSnicm * Copyright 1998-2012,2016 Free Software Foundation, Inc. * 6457960bfSmillert * * 7457960bfSmillert * Permission is hereby granted, free of charge, to any person obtaining a * 8457960bfSmillert * copy of this software and associated documentation files (the * 9457960bfSmillert * "Software"), to deal in the Software without restriction, including * 10457960bfSmillert * without limitation the rights to use, copy, modify, merge, publish, * 11457960bfSmillert * distribute, distribute with modifications, sublicense, and/or sell * 12457960bfSmillert * copies of the Software, and to permit persons to whom the Software is * 13457960bfSmillert * furnished to do so, subject to the following conditions: * 14457960bfSmillert * * 15457960bfSmillert * The above copyright notice and this permission notice shall be included * 16457960bfSmillert * in all copies or substantial portions of the Software. * 17457960bfSmillert * * 18457960bfSmillert * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 19457960bfSmillert * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 20457960bfSmillert * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 21457960bfSmillert * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 22457960bfSmillert * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 23457960bfSmillert * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 24457960bfSmillert * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 25457960bfSmillert * * 26457960bfSmillert * Except as contained in this notice, the name(s) of the above copyright * 27457960bfSmillert * holders shall not be used in advertising or otherwise to promote the * 28457960bfSmillert * sale, use or other dealings in this Software without prior written * 29457960bfSmillert * authorization. * 30457960bfSmillert ****************************************************************************/ 31457960bfSmillert 32457960bfSmillert /**************************************************************************** 3381d8c4e1Snicm * Author: Juergen Pfeifer, 1995,1997 * 34457960bfSmillert ****************************************************************************/ 35c166cd22Stholo 36c166cd22Stholo /*************************************************************************** 379f1aa62bSmillert * Module m_hook * 38c166cd22Stholo * Assign application specific routines for automatic invocation by menus * 39c166cd22Stholo ***************************************************************************/ 40c166cd22Stholo 41c166cd22Stholo #include "menu.priv.h" 42c166cd22Stholo 43*c7ef0cfcSnicm MODULE_ID("$Id: m_hook.c,v 1.8 2023/10/17 09:52:10 nicm Exp $") 440107aba4Smillert 45c166cd22Stholo /* "Template" macro to generate function to set application specific hook */ 46c166cd22Stholo #define GEN_HOOK_SET_FUNCTION( typ, name ) \ 47*c7ef0cfcSnicm MENU_EXPORT(int) NCURSES_API set_ ## typ ## _ ## name (MENU *menu, Menu_Hook func )\ 48c166cd22Stholo {\ 49*c7ef0cfcSnicm TR_FUNC_BFR(1);\ 50*c7ef0cfcSnicm T((T_CALLED("set_" #typ "_" #name "(%p,%s)"), (void *) menu, TR_FUNC_ARG(0, func)));\ 51c166cd22Stholo (Normalize_Menu(menu) -> typ ## name = func );\ 52c166cd22Stholo RETURN(E_OK);\ 53c166cd22Stholo } 54c166cd22Stholo 55c166cd22Stholo /* "Template" macro to generate function to get application specific hook */ 56c166cd22Stholo #define GEN_HOOK_GET_FUNCTION( typ, name ) \ 57*c7ef0cfcSnicm MENU_EXPORT(Menu_Hook) NCURSES_API typ ## _ ## name ( const MENU *menu )\ 58c166cd22Stholo {\ 59*c7ef0cfcSnicm T((T_CALLED(#typ "_" #name "(%p)"), (const void *) menu));\ 6081d8c4e1Snicm returnMenuHook(Normalize_Menu(menu) -> typ ## name);\ 61c166cd22Stholo } 62c166cd22Stholo 63c166cd22Stholo /*--------------------------------------------------------------------------- 64c166cd22Stholo | Facility : libnmenu 65c166cd22Stholo | Function : int set_menu_init(MENU *menu, void (*f)(MENU *)) 66c166cd22Stholo | 67c166cd22Stholo | Description : Set user-exit which is called when menu is posted 68c166cd22Stholo | or just after the top row changes. 69c166cd22Stholo | 70c166cd22Stholo | Return Values : E_OK - success 71c166cd22Stholo +--------------------------------------------------------------------------*/ 72c166cd22Stholo GEN_HOOK_SET_FUNCTION(menu, init) 73c166cd22Stholo 74c166cd22Stholo /*--------------------------------------------------------------------------- 75c166cd22Stholo | Facility : libnmenu 76c166cd22Stholo | Function : void (*)(MENU *) menu_init(const MENU *menu) 77c166cd22Stholo | 78c166cd22Stholo | Description : Return address of user-exit function which is called 79c166cd22Stholo | when a menu is posted or just after the top row 80c166cd22Stholo | changes. 81c166cd22Stholo | 82c166cd22Stholo | Return Values : Menu init function address or NULL 83c166cd22Stholo +--------------------------------------------------------------------------*/ 84c166cd22Stholo GEN_HOOK_GET_FUNCTION(menu, init) 85c166cd22Stholo 86c166cd22Stholo /*--------------------------------------------------------------------------- 87c166cd22Stholo | Facility : libnmenu 88c166cd22Stholo | Function : int set_menu_term (MENU *menu, void (*f)(MENU *)) 89c166cd22Stholo | 90c166cd22Stholo | Description : Set user-exit which is called when menu is unposted 91c166cd22Stholo | or just before the top row changes. 92c166cd22Stholo | 93c166cd22Stholo | Return Values : E_OK - success 94c166cd22Stholo +--------------------------------------------------------------------------*/ 95c166cd22Stholo GEN_HOOK_SET_FUNCTION(menu, term) 96c166cd22Stholo 97c166cd22Stholo /*--------------------------------------------------------------------------- 98c166cd22Stholo | Facility : libnmenu 99c166cd22Stholo | Function : void (*)(MENU *) menu_term(const MENU *menu) 100c166cd22Stholo | 101c166cd22Stholo | Description : Return address of user-exit function which is called 102c166cd22Stholo | when a menu is unposted or just before the top row 103c166cd22Stholo | changes. 104c166cd22Stholo | 105c166cd22Stholo | Return Values : Menu finalization function address or NULL 106c166cd22Stholo +--------------------------------------------------------------------------*/ 107c166cd22Stholo GEN_HOOK_GET_FUNCTION(menu, term) 108c166cd22Stholo 109c166cd22Stholo /*--------------------------------------------------------------------------- 110c166cd22Stholo | Facility : libnmenu 111c166cd22Stholo | Function : int set_item_init (MENU *menu, void (*f)(MENU *)) 112c166cd22Stholo | 113c166cd22Stholo | Description : Set user-exit which is called when menu is posted 114c166cd22Stholo | or just after the current item changes. 115c166cd22Stholo | 116c166cd22Stholo | Return Values : E_OK - success 117c166cd22Stholo +--------------------------------------------------------------------------*/ 118c166cd22Stholo GEN_HOOK_SET_FUNCTION(item, init) 119c166cd22Stholo 120c166cd22Stholo /*--------------------------------------------------------------------------- 121c166cd22Stholo | Facility : libnmenu 122c166cd22Stholo | Function : void (*)(MENU *) item_init (const MENU *menu) 123c166cd22Stholo | 124c166cd22Stholo | Description : Return address of user-exit function which is called 125c166cd22Stholo | when a menu is posted or just after the current item 126c166cd22Stholo | changes. 127c166cd22Stholo | 128c166cd22Stholo | Return Values : Item init function address or NULL 129c166cd22Stholo +--------------------------------------------------------------------------*/ 130c166cd22Stholo GEN_HOOK_GET_FUNCTION(item, init) 131c166cd22Stholo 132c166cd22Stholo /*--------------------------------------------------------------------------- 133c166cd22Stholo | Facility : libnmenu 134c166cd22Stholo | Function : int set_item_term (MENU *menu, void (*f)(MENU *)) 135c166cd22Stholo | 136c166cd22Stholo | Description : Set user-exit which is called when menu is unposted 137c166cd22Stholo | or just before the current item changes. 138c166cd22Stholo | 139c166cd22Stholo | Return Values : E_OK - success 140c166cd22Stholo +--------------------------------------------------------------------------*/ 141c166cd22Stholo GEN_HOOK_SET_FUNCTION(item, term) 142c166cd22Stholo 143c166cd22Stholo /*--------------------------------------------------------------------------- 144c166cd22Stholo | Facility : libnmenu 145c166cd22Stholo | Function : void (*)(MENU *) item_init (const MENU *menu) 146c166cd22Stholo | 147c166cd22Stholo | Description : Return address of user-exit function which is called 148c166cd22Stholo | when a menu is unposted or just before the current item 149c166cd22Stholo | changes. 150c166cd22Stholo | 151c166cd22Stholo | Return Values : Item finalization function address or NULL 152c166cd22Stholo +--------------------------------------------------------------------------*/ 153c166cd22Stholo GEN_HOOK_GET_FUNCTION(item, term) 154c166cd22Stholo 155c166cd22Stholo /* m_hook.c ends here */ 156