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