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