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