MCPcopy Create free account
hub / github.com/Entware/Entware / dialog_menu

Function dialog_menu

scripts/config/lxdialog/menubox.c:163–416  ·  view source on GitHub ↗

* Display a menu for choosing among a number of options */

Source from the content-addressed store, hash-verified

161 * Display a menu for choosing among a number of options
162 */
163int dialog_menu(const char *title, const char *prompt,
164 const void *selected, int *s_scroll)
165{
166 int i, j, x, y, box_x, box_y;
167 int height, width, menu_height;
168 int key = 0, button = 0, scroll = 0, choice = 0;
169 int first_item = 0, max_choice;
170 WINDOW *dialog, *menu;
171
172do_resize:
173 height = getmaxy(stdscr);
174 width = getmaxx(stdscr);
175 if (height < MENUBOX_HEIGTH_MIN || width < MENUBOX_WIDTH_MIN)
176 return -ERRDISPLAYTOOSMALL;
177
178 height -= 4;
179 width -= 5;
180 menu_height = height - 10;
181
182 max_choice = MIN(menu_height, item_count());
183
184 /* center dialog box on screen */
185 x = (getmaxx(stdscr) - width) / 2;
186 y = (getmaxy(stdscr) - height) / 2;
187
188 draw_shadow(stdscr, y, x, height, width);
189
190 dialog = newwin(height, width, y, x);
191 keypad(dialog, TRUE);
192
193 draw_box(dialog, 0, 0, height, width,
194 dlg.dialog.atr, dlg.border.atr);
195 wattrset(dialog, dlg.border.atr);
196 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
197 for (i = 0; i < width - 2; i++)
198 waddch(dialog, ACS_HLINE);
199 wattrset(dialog, dlg.dialog.atr);
200 wbkgdset(dialog, dlg.dialog.atr & A_COLOR);
201 waddch(dialog, ACS_RTEE);
202
203 print_title(dialog, title, width);
204
205 wattrset(dialog, dlg.dialog.atr);
206 print_autowrap(dialog, prompt, width - 2, 1, 3);
207
208 menu_width = width - 6;
209 box_y = height - menu_height - 5;
210 box_x = (width - menu_width) / 2 - 1;
211
212 /* create new window for the menu */
213 menu = subwin(dialog, menu_height, menu_width,
214 y + box_y + 1, x + box_x + 1);
215 keypad(menu, TRUE);
216
217 /* draw a box around the menu items */
218 draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
219 dlg.menubox_border.atr, dlg.menubox.atr);
220

Callers 1

confFunction · 0.85

Calls 15

item_countFunction · 0.85
draw_shadowFunction · 0.85
draw_boxFunction · 0.85
print_titleFunction · 0.85
print_autowrapFunction · 0.85
item_nFunction · 0.85
print_itemFunction · 0.85
item_setFunction · 0.85
first_alphaFunction · 0.85
item_strFunction · 0.85
do_scrollFunction · 0.85
item_set_selectedFunction · 0.85

Tested by

no test coverage detected