blob: 0bc6147e07d9237c3308c1138c533a2955e3d47a [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002 * Copyright 2020 Thomas E. Dickey *
3 * Copyright 1998-2016,2017 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304 * *
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
micky3879b9f5e72025-07-08 18:04:53 -040034/* $Id: menu.priv.h,v 1.29 2020/05/24 01:40:20 anonymous.maarten Exp $ */
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053035
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
Steve Kondikae271bc2015-11-15 02:50:53 +010043/* *INDENT-OFF* */
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053044
45#include "curses.priv.h"
micky3879b9f5e72025-07-08 18:04:53 -040046
47#define NCURSES_OPAQUE_MENU 0
48
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053049#include "mf_common.h"
50#include "menu.h"
51
52/* Backspace code */
53#define BS (8)
54
micky3879b9f5e72025-07-08 18:04:53 -040055extern MENU_EXPORT_VAR(ITEM) _nc_Default_Item;
56extern MENU_EXPORT_VAR(MENU) _nc_Default_Menu;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053057
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
Steve Kondikae271bc2015-11-15 02:50:53 +010064#define Get_Menu_Screen( menu ) (menu->userwin ? \
65 _nc_screen_of(menu->userwin) : CURRENT_SCREEN)
66
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053067/* Get the user defined (framing) window of the menu */
Steve Kondikae271bc2015-11-15 02:50:53 +010068#define Get_Menu_UserWin(menu) ((menu)->userwin ? \
69 (menu)->userwin : CURRENT_SCREEN->_stdscr)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053070
71/* Normalize menu window */
72#define Get_Menu_Window( menu ) \
73 ((menu)->usersub ? (menu)->usersub : Get_Menu_UserWin(menu))
74
75/* menu specific status flags */
76#define _LINK_NEEDED (0x04)
77#define _MARK_ALLOCATED (0x08)
78
79#define ALL_MENU_OPTS ( \
80 O_ONEVALUE | \
81 O_SHOWDESC | \
82 O_ROWMAJOR | \
83 O_IGNORECASE | \
84 O_SHOWMATCH | \
micky3879b9f5e72025-07-08 18:04:53 -040085 O_NONCYCLIC | \
86 O_MOUSE_MENU )
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053087
88#define ALL_ITEM_OPTS (O_SELECTABLE)
89
90/* Move to the window position of an item and draw it */
91#define Move_And_Post_Item(menu,item) \
92 {wmove((menu)->win,(menu)->spc_rows*(item)->y,((menu)->itemlen+(menu)->spc_cols)*(item)->x);\
93 _nc_Post_Item((menu),(item));}
94
95#define Move_To_Current_Item(menu,item) \
96 if ( (item) != (menu)->curitem)\
97 {\
98 Move_And_Post_Item(menu,item);\
99 Move_And_Post_Item(menu,(menu)->curitem);\
100 }
101
102/* This macro ensures, that the item becomes visible, if possible with the
103 specified row as the top row of the window. If this is not possible,
104 the top row will be adjusted and the value is stored in the row argument.
105*/
106#define Adjust_Current_Item(menu,row,item) \
107 { if ((item)->y < row) \
Steve Kondikae271bc2015-11-15 02:50:53 +0100108 row = (short) (item)->y; \
109 if ( (item)->y >= (row + (menu)->arows) ) \
110 row = (short) (( (item)->y < ((menu)->rows - row) ) \
111 ? (item)->y \
112 : (menu)->rows - (menu)->arows); \
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530113 _nc_New_TopRow_and_CurrentItem(menu,row,item); }
114
115/* Reset the match pattern buffer */
116#define Reset_Pattern(menu) \
117 { (menu)->pindex = 0; \
118 (menu)->pattern[0] = '\0'; }
119
120#define UChar(c) ((unsigned char)(c))
121
122/* Internal functions. */
micky3879b9f5e72025-07-08 18:04:53 -0400123extern MENU_EXPORT(void) _nc_Draw_Menu (const MENU *);
124extern MENU_EXPORT(void) _nc_Show_Menu (const MENU *);
125extern MENU_EXPORT(void) _nc_Calculate_Item_Length_and_Width (MENU *);
126extern MENU_EXPORT(int) _nc_Calculate_Text_Width(const TEXT *);
127extern MENU_EXPORT(void) _nc_Post_Item (const MENU *, const ITEM *);
128extern MENU_EXPORT(bool) _nc_Connect_Items (MENU *, ITEM **);
129extern MENU_EXPORT(void) _nc_Disconnect_Items (MENU *);
130extern MENU_EXPORT(void) _nc_New_TopRow_and_CurrentItem (MENU *,int, ITEM *);
131extern MENU_EXPORT(void) _nc_Link_Items (MENU *);
132extern MENU_EXPORT(int) _nc_Match_Next_Character_In_Item_Name (MENU*,int,ITEM**);
133extern MENU_EXPORT(int) _nc_menu_cursor_pos (const MENU* menu, const ITEM* item,
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530134 int* pY, int* pX);
135
136#ifdef TRACE
137
Steve Kondikae271bc2015-11-15 02:50:53 +0100138#define returnItem(code) TRACE_RETURN1(code,item)
139#define returnItemPtr(code) TRACE_RETURN1(code,item_ptr)
140#define returnItemOpts(code) TRACE_RETURN1(code,item_opts)
141#define returnMenu(code) TRACE_RETURN1(code,menu)
142#define returnMenuHook(code) TRACE_RETURN1(code,menu_hook)
143#define returnMenuOpts(code) TRACE_RETURN1(code,menu_opts)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530144
micky3879b9f5e72025-07-08 18:04:53 -0400145extern MENU_EXPORT(ITEM *) _nc_retrace_item (ITEM *);
146extern MENU_EXPORT(ITEM **) _nc_retrace_item_ptr (ITEM **);
147extern MENU_EXPORT(Item_Options) _nc_retrace_item_opts (Item_Options);
148extern MENU_EXPORT(MENU *) _nc_retrace_menu (MENU *);
149extern MENU_EXPORT(Menu_Hook) _nc_retrace_menu_hook (Menu_Hook);
150extern MENU_EXPORT(Menu_Options) _nc_retrace_menu_opts (Menu_Options);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530151
152#else /* !TRACE */
153
154#define returnItem(code) return code
155#define returnItemPtr(code) return code
156#define returnItemOpts(code) return code
157#define returnMenu(code) return code
158#define returnMenuHook(code) return code
159#define returnMenuOpts(code) return code
160
161#endif /* TRACE/!TRACE */
Steve Kondikae271bc2015-11-15 02:50:53 +0100162/* *INDENT-ON* */
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530163
164#endif /* MENU_PRIV_H_incl */