Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | /**************************************************************************** |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 2 | * Copyright 2020 Thomas E. Dickey * |
| 3 | * Copyright 1998-2016,2017 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 4 | * * |
| 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 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 34 | /* $Id: menu.priv.h,v 1.29 2020/05/24 01:40:20 anonymous.maarten Exp $ */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 35 | |
| 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 Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 43 | /* *INDENT-OFF* */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 44 | |
| 45 | #include "curses.priv.h" |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 46 | |
| 47 | #define NCURSES_OPAQUE_MENU 0 |
| 48 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 49 | #include "mf_common.h" |
| 50 | #include "menu.h" |
| 51 | |
| 52 | /* Backspace code */ |
| 53 | #define BS (8) |
| 54 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 55 | extern MENU_EXPORT_VAR(ITEM) _nc_Default_Item; |
| 56 | extern MENU_EXPORT_VAR(MENU) _nc_Default_Menu; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 57 | |
| 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 Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 64 | #define Get_Menu_Screen( menu ) (menu->userwin ? \ |
| 65 | _nc_screen_of(menu->userwin) : CURRENT_SCREEN) |
| 66 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 67 | /* Get the user defined (framing) window of the menu */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 68 | #define Get_Menu_UserWin(menu) ((menu)->userwin ? \ |
| 69 | (menu)->userwin : CURRENT_SCREEN->_stdscr) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 70 | |
| 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 | \ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 85 | O_NONCYCLIC | \ |
| 86 | O_MOUSE_MENU ) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 87 | |
| 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 Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 108 | 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 Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 113 | _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. */ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 123 | extern MENU_EXPORT(void) _nc_Draw_Menu (const MENU *); |
| 124 | extern MENU_EXPORT(void) _nc_Show_Menu (const MENU *); |
| 125 | extern MENU_EXPORT(void) _nc_Calculate_Item_Length_and_Width (MENU *); |
| 126 | extern MENU_EXPORT(int) _nc_Calculate_Text_Width(const TEXT *); |
| 127 | extern MENU_EXPORT(void) _nc_Post_Item (const MENU *, const ITEM *); |
| 128 | extern MENU_EXPORT(bool) _nc_Connect_Items (MENU *, ITEM **); |
| 129 | extern MENU_EXPORT(void) _nc_Disconnect_Items (MENU *); |
| 130 | extern MENU_EXPORT(void) _nc_New_TopRow_and_CurrentItem (MENU *,int, ITEM *); |
| 131 | extern MENU_EXPORT(void) _nc_Link_Items (MENU *); |
| 132 | extern MENU_EXPORT(int) _nc_Match_Next_Character_In_Item_Name (MENU*,int,ITEM**); |
| 133 | extern MENU_EXPORT(int) _nc_menu_cursor_pos (const MENU* menu, const ITEM* item, |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 134 | int* pY, int* pX); |
| 135 | |
| 136 | #ifdef TRACE |
| 137 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 138 | #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 Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 144 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 145 | extern MENU_EXPORT(ITEM *) _nc_retrace_item (ITEM *); |
| 146 | extern MENU_EXPORT(ITEM **) _nc_retrace_item_ptr (ITEM **); |
| 147 | extern MENU_EXPORT(Item_Options) _nc_retrace_item_opts (Item_Options); |
| 148 | extern MENU_EXPORT(MENU *) _nc_retrace_menu (MENU *); |
| 149 | extern MENU_EXPORT(Menu_Hook) _nc_retrace_menu_hook (Menu_Hook); |
| 150 | extern MENU_EXPORT(Menu_Options) _nc_retrace_menu_opts (Menu_Options); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 151 | |
| 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 Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 162 | /* *INDENT-ON* */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 163 | |
| 164 | #endif /* MENU_PRIV_H_incl */ |