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