Skip to content

Commit

Permalink
kconfig/lxdialog: support resize
Browse files Browse the repository at this point in the history
In all dialogs now properly catch KEY_RESIZE and take proper action.
In mconf try to behave sensibly when a dialog routine returns
-ERRDISPLAYTOOSMALL.

The original check for a screnn size of 80x19 is kept for now.
It may make sense to remove it later, but thats anyway what
much text is adjusted for.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
  • Loading branch information
Sam Ravnborg authored and Sam Ravnborg committed Sep 30, 2006
1 parent f3cbcdc commit c8dc68a
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 71 deletions.
11 changes: 11 additions & 0 deletions scripts/kconfig/lxdialog/checklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ int dialog_checklist(const char *title, const char *prompt, int height,
}
}

do_resize:
if (getmaxy(stdscr) < (height + 6))
return -ERRDISPLAYTOOSMALL;
if (getmaxx(stdscr) < (width + 6))
return -ERRDISPLAYTOOSMALL;

max_choice = MIN(list_height, item_count());

/* center dialog box on screen */
Expand Down Expand Up @@ -303,6 +309,11 @@ int dialog_checklist(const char *title, const char *prompt, int height,
case KEY_ESC:
key = on_key_esc(dialog);
break;
case KEY_RESIZE:
delwin(list);
delwin(dialog);
on_key_resize();
goto do_resize;
}

/* Now, update everything... */
Expand Down
8 changes: 6 additions & 2 deletions scripts/kconfig/lxdialog/dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
#define ACS_DARROW 'v'
#endif

/* error return codes */
#define ERRDISPLAYTOOSMALL (KEY_MAX + 1)

/*
* Color definitions
*/
Expand Down Expand Up @@ -181,6 +184,7 @@ int item_is_tag(char tag);

/* generic key handlers */
int on_key_esc(WINDOW *win);
int on_key_resize(void);

void init_dialog(const char *backtitle);
void reset_dialog(void);
Expand All @@ -199,8 +203,8 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width);
int dialog_msgbox(const char *title, const char *prompt, int height,
int width, int pause);
int dialog_textbox(const char *title, const char *file, int height, int width);
int dialog_menu(const char *title, const char *prompt, int height, int width,
int menu_height, const void *selected, int *s_scroll);
int dialog_menu(const char *title, const char *prompt,
const void *selected, int *s_scroll);
int dialog_checklist(const char *title, const char *prompt, int height,
int width, int list_height);
extern char dialog_input_result[];
Expand Down
20 changes: 15 additions & 5 deletions scripts/kconfig/lxdialog/inputbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
char *instr = dialog_input_result;
WINDOW *dialog;

if (!init)
instr[0] = '\0';
else
strcpy(instr, init);

do_resize:
if (getmaxy(stdscr) <= (height - 2))
return -ERRDISPLAYTOOSMALL;
if (getmaxx(stdscr) <= (width - 2))
return -ERRDISPLAYTOOSMALL;

/* center dialog box on screen */
x = (COLS - width) / 2;
y = (LINES - height) / 2;
Expand Down Expand Up @@ -86,11 +97,6 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
wmove(dialog, box_y, box_x);
wattrset(dialog, dlg.inputbox.atr);

if (!init)
instr[0] = '\0';
else
strcpy(instr, init);

input_x = strlen(instr);

if (input_x >= box_width) {
Expand Down Expand Up @@ -220,6 +226,10 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
case KEY_ESC:
key = on_key_esc(dialog);
break;
case KEY_RESIZE:
delwin(dialog);
on_key_resize();
goto do_resize;
}
}

Expand Down
25 changes: 22 additions & 3 deletions scripts/kconfig/lxdialog/menubox.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,25 @@ static void do_scroll(WINDOW *win, int *scroll, int n)
/*
* Display a menu for choosing among a number of options
*/
int dialog_menu(const char *title, const char *prompt, int height, int width,
int menu_height, const void *selected, int *s_scroll)
int dialog_menu(const char *title, const char *prompt,
const void *selected, int *s_scroll)
{
int i, j, x, y, box_x, box_y;
int height, width, menu_height;
int key = 0, button = 0, scroll = 0, choice = 0;
int first_item = 0, max_choice;
WINDOW *dialog, *menu;

do_resize:
height = getmaxy(stdscr);
width = getmaxx(stdscr);
if (height < 15 || width < 65)
return -ERRDISPLAYTOOSMALL;

height -= 4;
width -= 5;
menu_height = height - 10;

max_choice = MIN(menu_height, item_count());

/* center dialog box on screen */
Expand Down Expand Up @@ -226,7 +237,10 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
dlg.menubox_border.atr, dlg.menubox.atr);

item_x = (menu_width - 70) / 2;
if (menu_width >= 80)
item_x = (menu_width - 70) / 2;
else
item_x = 4;

/* Set choice to default item */
item_foreach()
Expand Down Expand Up @@ -407,6 +421,11 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
case KEY_ESC:
key = on_key_esc(menu);
break;
case KEY_RESIZE:
on_key_resize();
delwin(menu);
delwin(dialog);
goto do_resize;
}
}
delwin(menu);
Expand Down
Loading

0 comments on commit c8dc68a

Please sign in to comment.