xref: /src/contrib/ncurses/menu/menu.priv.h (revision 68ad2b0d7af2a3571c4abac9afa712f9b09b721c)
1 /****************************************************************************
2  * Copyright 2020,2024 Thomas E. Dickey                                     *
3  * Copyright 1998-2016,2017 Free Software Foundation, Inc.                  *
4  *                                                                          *
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 /* $Id: menu.priv.h,v 1.30 2024/08/03 15:41:22 tom Exp $ */
35 
36 /***************************************************************************
37 * Module menu.priv.h                                                       *
38 * Top level private header file for all libnmenu modules                   *
39 ***************************************************************************/
40 
41 #ifndef MENU_PRIV_H_incl
42 #define MENU_PRIV_H_incl 1
43 /* *INDENT-OFF* */
44 
45 #include "curses.priv.h"
46 
47 #define NCURSES_OPAQUE_MENU 0
48 
49 #include "mf_common.h"
50 #include "menu.h"
51 
52 /* Backspace code */
53 #define BS (8)
54 
55 extern MENU_EXPORT_VAR(ITEM) _nc_Default_Item;
56 extern MENU_EXPORT_VAR(MENU) _nc_Default_Menu;
57 
58 /* Normalize item to default if none was given */
59 #define Normalize_Item( item ) ((item)=(item)?(item):&_nc_Default_Item)
60 
61 /* Normalize menu to default if none was given */
62 #define Normalize_Menu( menu ) ((menu)=(menu)?(menu):&_nc_Default_Menu)
63 
64 /* Get the user defined (framing) window of the menu */
65 #define Get_Menu_UserWin(menu) ((menu)->userwin ? \
66     (menu)->userwin : CURRENT_SCREEN->_stdscr)
67 
68 /* Normalize menu window */
69 #define Get_Menu_Window(  menu ) \
70    ((menu)->usersub  ? (menu)->usersub  : Get_Menu_UserWin(menu))
71 
72 /* menu specific status flags */
73 #define _LINK_NEEDED    (0x04)
74 #define _MARK_ALLOCATED (0x08)
75 
76 #define ALL_MENU_OPTS (                 \
77 		       O_ONEVALUE     | \
78 		       O_SHOWDESC     | \
79 		       O_ROWMAJOR     | \
80 		       O_IGNORECASE   | \
81 		       O_SHOWMATCH    | \
82 		       O_NONCYCLIC    | \
83 		       O_MOUSE_MENU   )
84 
85 #define ALL_ITEM_OPTS (O_SELECTABLE)
86 
87 /* Move to the window position of an item and draw it */
88 #define Move_And_Post_Item(menu,item) \
89   {wmove((menu)->win,(menu)->spc_rows*(item)->y,((menu)->itemlen+(menu)->spc_cols)*(item)->x);\
90    _nc_Post_Item((menu),(item));}
91 
92 #define Move_To_Current_Item(menu,item) \
93   if ( (item) != (menu)->curitem)\
94     {\
95       Move_And_Post_Item(menu,item);\
96       Move_And_Post_Item(menu,(menu)->curitem);\
97     }
98 
99 /* This macro ensures, that the item becomes visible, if possible with the
100    specified row as the top row of the window. If this is not possible,
101    the top row will be adjusted and the value is stored in the row argument.
102 */
103 #define Adjust_Current_Item(menu,row,item) \
104   { if ((item)->y < row) \
105       row = (short) (item)->y; \
106     if ( (item)->y >= (row + (menu)->arows) ) \
107       row = (short) (( (item)->y < ((menu)->rows - row) ) \
108                      ? (item)->y \
109 		     : (menu)->rows - (menu)->arows); \
110     _nc_New_TopRow_and_CurrentItem(menu,row,item); }
111 
112 /* Reset the match pattern buffer */
113 #define Reset_Pattern(menu) \
114   { (menu)->pindex = 0; \
115     (menu)->pattern[0] = '\0'; }
116 
117 #define UChar(c)	((unsigned char)(c))
118 
119 /* Internal functions. */
120 extern MENU_EXPORT(void) _nc_Draw_Menu (const MENU *);
121 extern MENU_EXPORT(void) _nc_Show_Menu (const MENU *);
122 extern MENU_EXPORT(void) _nc_Calculate_Item_Length_and_Width (MENU *);
123 extern MENU_EXPORT(int)  _nc_Calculate_Text_Width(const TEXT *);
124 extern MENU_EXPORT(void) _nc_Post_Item (const MENU *, const ITEM *);
125 extern MENU_EXPORT(bool) _nc_Connect_Items (MENU *, ITEM **);
126 extern MENU_EXPORT(void) _nc_Disconnect_Items (MENU *);
127 extern MENU_EXPORT(void) _nc_New_TopRow_and_CurrentItem (MENU *,int, ITEM *);
128 extern MENU_EXPORT(void) _nc_Link_Items (MENU *);
129 extern MENU_EXPORT(int)  _nc_Match_Next_Character_In_Item_Name (MENU*,int,ITEM**);
130 extern MENU_EXPORT(int)  _nc_menu_cursor_pos (const MENU* menu, const ITEM* item,
131 				int* pY, int* pX);
132 
133 #ifdef TRACE
134 
135 #define returnItem(code)	TRACE_RETURN1(code,item)
136 #define returnItemPtr(code)	TRACE_RETURN1(code,item_ptr)
137 #define returnItemOpts(code)	TRACE_RETURN1(code,item_opts)
138 #define returnMenu(code)	TRACE_RETURN1(code,menu)
139 #define returnMenuHook(code)	TRACE_RETURN1(code,menu_hook)
140 #define returnMenuOpts(code)	TRACE_RETURN1(code,menu_opts)
141 
142 extern MENU_EXPORT(ITEM *)	    _nc_retrace_item (ITEM *);
143 extern MENU_EXPORT(ITEM **)	    _nc_retrace_item_ptr (ITEM **);
144 extern MENU_EXPORT(Item_Options) _nc_retrace_item_opts (Item_Options);
145 extern MENU_EXPORT(MENU *)	    _nc_retrace_menu (MENU *);
146 extern MENU_EXPORT(Menu_Hook)    _nc_retrace_menu_hook (Menu_Hook);
147 extern MENU_EXPORT(Menu_Options) _nc_retrace_menu_opts (Menu_Options);
148 
149 #else /* !TRACE */
150 
151 #define returnItem(code)	return code
152 #define returnItemPtr(code)	return code
153 #define returnItemOpts(code)	return code
154 #define returnMenu(code)	return code
155 #define returnMenuHook(code)	return code
156 #define returnMenuOpts(code)	return code
157 
158 #endif /* TRACE/!TRACE */
159 /* *INDENT-ON* */
160 
161 #endif /* MENU_PRIV_H_incl */
162