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