]> ncurses.scripts.mit.edu Git - ncurses.git/blob - menu/menu.priv.h
ncurses 6.1 - patch 20190914
[ncurses.git] / menu / menu.priv.h
1 /****************************************************************************
2  * Copyright (c) 1998-2016,2017 Free Software Foundation, Inc.              *
3  *                                                                          *
4  * Permission is hereby granted, free of charge, to any person obtaining a  *
5  * copy of this software and associated documentation files (the            *
6  * "Software"), to deal in the Software without restriction, including      *
7  * without limitation the rights to use, copy, modify, merge, publish,      *
8  * distribute, distribute with modifications, sublicense, and/or sell       *
9  * copies of the Software, and to permit persons to whom the Software is    *
10  * furnished to do so, subject to the following conditions:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22  *                                                                          *
23  * Except as contained in this notice, the name(s) of the above copyright   *
24  * holders shall not be used in advertising or otherwise to promote the     *
25  * sale, use or other dealings in this Software without prior written       *
26  * authorization.                                                           *
27  ****************************************************************************/
28
29 /****************************************************************************
30  *   Author:  Juergen Pfeifer, 1995,1997                                    *
31  ****************************************************************************/
32
33 /* $Id: menu.priv.h,v 1.27 2017/02/11 16:50:12 tom Exp $ */
34
35 /***************************************************************************
36 * Module menu.priv.h                                                       *
37 * Top level private header file for all libnmenu modules                   *
38 ***************************************************************************/
39
40 #ifndef MENU_PRIV_H_incl
41 #define MENU_PRIV_H_incl 1
42 /* *INDENT-OFF* */
43
44 #include "curses.priv.h"
45
46 #define NCURSES_OPAQUE_MENU 0
47
48 #include "mf_common.h"
49 #include "menu.h"
50
51 /* Backspace code */
52 #define BS (8)
53
54 extern NCURSES_EXPORT_VAR(ITEM) _nc_Default_Item;
55 extern NCURSES_EXPORT_VAR(MENU) _nc_Default_Menu;
56
57 /* Normalize item to default if none was given */
58 #define Normalize_Item( item ) ((item)=(item)?(item):&_nc_Default_Item)
59
60 /* Normalize menu to default if none was given */
61 #define Normalize_Menu( menu ) ((menu)=(menu)?(menu):&_nc_Default_Menu)
62
63 #define Get_Menu_Screen( menu ) (menu->userwin ? \
64                                  _nc_screen_of(menu->userwin) : CURRENT_SCREEN)
65
66 /* Get the user defined (framing) window of the menu */
67 #define Get_Menu_UserWin(menu) ((menu)->userwin ? \
68     (menu)->userwin : CURRENT_SCREEN->_stdscr)
69
70 /* Normalize menu window */
71 #define Get_Menu_Window(  menu ) \
72    ((menu)->usersub  ? (menu)->usersub  : Get_Menu_UserWin(menu))
73
74 /* menu specific status flags */
75 #define _LINK_NEEDED    (0x04)
76 #define _MARK_ALLOCATED (0x08)
77
78 #define ALL_MENU_OPTS (                 \
79                        O_ONEVALUE     | \
80                        O_SHOWDESC     | \
81                        O_ROWMAJOR     | \
82                        O_IGNORECASE   | \
83                        O_SHOWMATCH    | \
84                        O_NONCYCLIC    | \
85                        O_MOUSE_MENU   )
86
87 #define ALL_ITEM_OPTS (O_SELECTABLE)
88
89 /* Move to the window position of an item and draw it */
90 #define Move_And_Post_Item(menu,item) \
91   {wmove((menu)->win,(menu)->spc_rows*(item)->y,((menu)->itemlen+(menu)->spc_cols)*(item)->x);\
92    _nc_Post_Item((menu),(item));}
93
94 #define Move_To_Current_Item(menu,item) \
95   if ( (item) != (menu)->curitem)\
96     {\
97       Move_And_Post_Item(menu,item);\
98       Move_And_Post_Item(menu,(menu)->curitem);\
99     }
100
101 /* This macro ensures, that the item becomes visible, if possible with the
102    specified row as the top row of the window. If this is not possible,
103    the top row will be adjusted and the value is stored in the row argument.
104 */
105 #define Adjust_Current_Item(menu,row,item) \
106   { if ((item)->y < row) \
107       row = (short) (item)->y; \
108     if ( (item)->y >= (row + (menu)->arows) ) \
109       row = (short) (( (item)->y < ((menu)->rows - row) ) \
110                      ? (item)->y \
111                      : (menu)->rows - (menu)->arows); \
112     _nc_New_TopRow_and_CurrentItem(menu,row,item); }
113
114 /* Reset the match pattern buffer */
115 #define Reset_Pattern(menu) \
116   { (menu)->pindex = 0; \
117     (menu)->pattern[0] = '\0'; }
118
119 #define UChar(c)        ((unsigned char)(c))
120
121 /* Internal functions. */
122 extern NCURSES_EXPORT(void) _nc_Draw_Menu (const MENU *);
123 extern NCURSES_EXPORT(void) _nc_Show_Menu (const MENU *);
124 extern NCURSES_EXPORT(void) _nc_Calculate_Item_Length_and_Width (MENU *);
125 extern NCURSES_EXPORT(int)  _nc_Calculate_Text_Width(const TEXT *);
126 extern NCURSES_EXPORT(void) _nc_Post_Item (const MENU *, const ITEM *);
127 extern NCURSES_EXPORT(bool) _nc_Connect_Items (MENU *, ITEM **);
128 extern NCURSES_EXPORT(void) _nc_Disconnect_Items (MENU *);
129 extern NCURSES_EXPORT(void) _nc_New_TopRow_and_CurrentItem (MENU *,int, ITEM *);
130 extern NCURSES_EXPORT(void) _nc_Link_Items (MENU *);
131 extern NCURSES_EXPORT(int)  _nc_Match_Next_Character_In_Item_Name (MENU*,int,ITEM**);
132 extern NCURSES_EXPORT(int)  _nc_menu_cursor_pos (const MENU* menu, const ITEM* item,
133                                 int* pY, int* pX);
134
135 #ifdef TRACE
136
137 #define returnItem(code)        TRACE_RETURN1(code,item)
138 #define returnItemPtr(code)     TRACE_RETURN1(code,item_ptr)
139 #define returnItemOpts(code)    TRACE_RETURN1(code,item_opts)
140 #define returnMenu(code)        TRACE_RETURN1(code,menu)
141 #define returnMenuHook(code)    TRACE_RETURN1(code,menu_hook)
142 #define returnMenuOpts(code)    TRACE_RETURN1(code,menu_opts)
143
144 extern NCURSES_EXPORT(ITEM *)       _nc_retrace_item (ITEM *);
145 extern NCURSES_EXPORT(ITEM **)      _nc_retrace_item_ptr (ITEM **);
146 extern NCURSES_EXPORT(Item_Options) _nc_retrace_item_opts (Item_Options);
147 extern NCURSES_EXPORT(MENU *)       _nc_retrace_menu (MENU *);
148 extern NCURSES_EXPORT(Menu_Hook)    _nc_retrace_menu_hook (Menu_Hook);
149 extern NCURSES_EXPORT(Menu_Options) _nc_retrace_menu_opts (Menu_Options);
150
151 #else /* !TRACE */
152
153 #define returnItem(code)        return code
154 #define returnItemPtr(code)     return code
155 #define returnItemOpts(code)    return code
156 #define returnMenu(code)        return code
157 #define returnMenuHook(code)    return code
158 #define returnMenuOpts(code)    return code
159
160 #endif /* TRACE/!TRACE */
161 /* *INDENT-ON* */
162
163 #endif /* MENU_PRIV_H_incl */