summaryrefslogtreecommitdiffstats
path: root/package/config/lxdialog
diff options
context:
space:
mode:
Diffstat (limited to 'package/config/lxdialog')
-rw-r--r--package/config/lxdialog/check-lxdialog.sh84
-rw-r--r--package/config/lxdialog/checklist.c587
-rw-r--r--package/config/lxdialog/dialog.h207
-rw-r--r--package/config/lxdialog/inputbox.c394
-rw-r--r--package/config/lxdialog/menubox.c672
-rw-r--r--package/config/lxdialog/textbox.c797
-rw-r--r--package/config/lxdialog/util.c795
-rw-r--r--package/config/lxdialog/yesno.c156
8 files changed, 1922 insertions, 1770 deletions
diff --git a/package/config/lxdialog/check-lxdialog.sh b/package/config/lxdialog/check-lxdialog.sh
new file mode 100644
index 000000000..120d624e6
--- /dev/null
+++ b/package/config/lxdialog/check-lxdialog.sh
@@ -0,0 +1,84 @@
+#!/bin/sh
+# Check ncurses compatibility
+
+# What library to link
+ldflags()
+{
+ $cc -print-file-name=libncursesw.so | grep -q /
+ if [ $? -eq 0 ]; then
+ echo '-lncursesw'
+ exit
+ fi
+ $cc -print-file-name=libncurses.so | grep -q /
+ if [ $? -eq 0 ]; then
+ echo '-lncurses'
+ exit
+ fi
+ $cc -print-file-name=libcurses.so | grep -q /
+ if [ $? -eq 0 ]; then
+ echo '-lcurses'
+ exit
+ fi
+ exit 1
+}
+
+# Where is ncurses.h?
+ccflags()
+{
+ if [ -f /usr/include/ncurses/ncurses.h ]; then
+ echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"'
+ elif [ -f /usr/include/ncurses/curses.h ]; then
+ echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses/curses.h>"'
+ elif [ -f /usr/include/ncurses.h ]; then
+ echo '-DCURSES_LOC="<ncurses.h>"'
+ else
+ echo '-DCURSES_LOC="<curses.h>"'
+ fi
+}
+
+# Temp file, try to clean up after us
+tmp=.lxdialog.tmp
+trap "rm -f $tmp" 0 1 2 3 15
+
+# Check if we can link to ncurses
+check() {
+ echo "main() {}" | $cc -xc - -o $tmp 2> /dev/null
+ if [ $? != 0 ]; then
+ echo " *** Unable to find the ncurses libraries." 1>&2
+ echo " *** make menuconfig require the ncurses libraries" 1>&2
+ echo " *** " 1>&2
+ echo " *** Install ncurses (ncurses-devel) and try again" 1>&2
+ echo " *** " 1>&2
+ exit 1
+ fi
+}
+
+usage() {
+ printf "Usage: $0 [-check compiler options|-header|-library]\n"
+}
+
+if [ $# == 0 ]; then
+ usage
+ exit 1
+fi
+
+cc=""
+case "$1" in
+ "-check")
+ shift
+ cc="$@"
+ check
+ ;;
+ "-ccflags")
+ ccflags
+ ;;
+ "-ldflags")
+ shift
+ cc="$@"
+ ldflags
+ ;;
+ "*")
+ usage
+ exit 1
+ ;;
+esac
diff --git a/package/config/lxdialog/checklist.c b/package/config/lxdialog/checklist.c
index 71de4a191..cf697080d 100644
--- a/package/config/lxdialog/checklist.c
+++ b/package/config/lxdialog/checklist.c
@@ -23,350 +23,303 @@
#include "dialog.h"
-static int list_width, check_x, item_x, checkflag;
+static int list_width, check_x, item_x;
/*
* Print list item
*/
-static void
-print_item (WINDOW * win, const char *item, int status,
- int choice, int selected)
+static void print_item(WINDOW * win, int choice, int selected)
{
- int i;
-
- /* Clear 'residue' of last item */
- wattrset (win, menubox_attr);
- wmove (win, choice, 0);
- for (i = 0; i < list_width; i++)
- waddch (win, ' ');
-
- wmove (win, choice, check_x);
- wattrset (win, selected ? check_selected_attr : check_attr);
- if (checkflag == FLAG_CHECK)
- wprintw (win, "[%c]", status ? 'X' : ' ');
- else
- wprintw (win, "(%c)", status ? 'X' : ' ');
-
- wattrset (win, selected ? tag_selected_attr : tag_attr);
- mvwaddch(win, choice, item_x, item[0]);
- wattrset (win, selected ? item_selected_attr : item_attr);
- waddstr (win, (char *)item+1);
- if (selected) {
- wmove (win, choice, check_x+1);
- wrefresh (win);
- }
+ int i;
+
+ /* Clear 'residue' of last item */
+ wattrset(win, dlg.menubox.atr);
+ wmove(win, choice, 0);
+ for (i = 0; i < list_width; i++)
+ waddch(win, ' ');
+
+ wmove(win, choice, check_x);
+ wattrset(win, selected ? dlg.check_selected.atr
+ : dlg.check.atr);
+ wprintw(win, "(%c)", item_is_tag('X') ? 'X' : ' ');
+
+ wattrset(win, selected ? dlg.tag_selected.atr : dlg.tag.atr);
+ mvwaddch(win, choice, item_x, item_str()[0]);
+ wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr);
+ waddstr(win, (char *)item_str() + 1);
+ if (selected) {
+ wmove(win, choice, check_x + 1);
+ wrefresh(win);
+ }
}
/*
* Print the scroll indicators.
*/
-static void
-print_arrows (WINDOW * win, int choice, int item_no, int scroll,
- int y, int x, int height)
+static void print_arrows(WINDOW * win, int choice, int item_no, int scroll,
+ int y, int x, int height)
{
- wmove(win, y, x);
-
- if (scroll > 0) {
- wattrset (win, uarrow_attr);
- waddch (win, ACS_UARROW);
- waddstr (win, "(-)");
- }
- else {
- wattrset (win, menubox_attr);
- waddch (win, ACS_HLINE);
- waddch (win, ACS_HLINE);
- waddch (win, ACS_HLINE);
- waddch (win, ACS_HLINE);
- }
-
- y = y + height + 1;
- wmove(win, y, x);
-
- if ((height < item_no) && (scroll + choice < item_no - 1)) {
- wattrset (win, darrow_attr);
- waddch (win, ACS_DARROW);
- waddstr (win, "(+)");
- }
- else {
- wattrset (win, menubox_border_attr);
- waddch (win, ACS_HLINE);
- waddch (win, ACS_HLINE);
- waddch (win, ACS_HLINE);
- waddch (win, ACS_HLINE);
- }
+ wmove(win, y, x);
+
+ if (scroll > 0) {
+ wattrset(win, dlg.uarrow.atr);
+ waddch(win, ACS_UARROW);
+ waddstr(win, "(-)");
+ } else {
+ wattrset(win, dlg.menubox.atr);
+ waddch(win, ACS_HLINE);
+ waddch(win, ACS_HLINE);
+ waddch(win, ACS_HLINE);
+ waddch(win, ACS_HLINE);
+ }
+
+ y = y + height + 1;
+ wmove(win, y, x);
+
+ if ((height < item_no) && (scroll + choice < item_no - 1)) {
+ wattrset(win, dlg.darrow.atr);
+ waddch(win, ACS_DARROW);
+ waddstr(win, "(+)");
+ } else {
+ wattrset(win, dlg.menubox_border.atr);
+ waddch(win, ACS_HLINE);
+ waddch(win, ACS_HLINE);
+ waddch(win, ACS_HLINE);
+ waddch(win, ACS_HLINE);
+ }
}
/*
* Display the termination buttons
*/
-static void
-print_buttons( WINDOW *dialog, int height, int width, int selected)
+static void print_buttons(WINDOW * dialog, int height, int width, int selected)
{
- int x = width / 2 - 11;
- int y = height - 2;
+ int x = width / 2 - 11;
+ int y = height - 2;
- print_button (dialog, "Select", y, x, selected == 0);
- print_button (dialog, " Help ", y, x + 14, selected == 1);
+ print_button(dialog, "Select", y, x, selected == 0);
+ print_button(dialog, " Help ", y, x + 14, selected == 1);
- wmove(dialog, y, x+1 + 14*selected);
- wrefresh (dialog);
+ wmove(dialog, y, x + 1 + 14 * selected);
+ wrefresh(dialog);
}
/*
* Display a dialog box with a list of options that can be turned on or off
- * The `flag' parameter is used to select between radiolist and checklist.
+ * in the style of radiolist (only one option turned on at a time).
*/
-int
-dialog_checklist (const char *title, const char *prompt, int height, int width,
- int list_height, int item_no, struct dialog_list_item ** items,
- int flag)
-
+int dialog_checklist(const char *title, const char *prompt, int height,
+ int width, int list_height)
{
- int i, x, y, box_x, box_y;
- int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status;
- WINDOW *dialog, *list;
-
- checkflag = flag;
-
- /* Allocate space for storing item on/off status */
- if ((status = malloc (sizeof (int) * item_no)) == NULL) {
- endwin ();
- fprintf (stderr,
- "\nCan't allocate memory in dialog_checklist().\n");
- exit (-1);
- }
-
- /* Initializes status */
- for (i = 0; i < item_no; i++) {
- status[i] = (items[i]->selected == 1); /* ON */
- if ((!choice && status[i]) || items[i]->selected == 2) /* SELECTED */
- choice = i + 1;
- }
- if (choice)
- choice--;
-
- max_choice = MIN (list_height, item_no);
-
- /* center dialog box on screen */
- x = (COLS - width) / 2;
- y = (LINES - height) / 2;
-
- draw_shadow (stdscr, y, x, height, width);
-
- dialog = newwin (height, width, y, x);
- keypad (dialog, TRUE);
-
- draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr);
- wattrset (dialog, border_attr);
- mvwaddch (dialog, height-3, 0, ACS_LTEE);
- for (i = 0; i < width - 2; i++)
- waddch (dialog, ACS_HLINE);
- wattrset (dialog, dialog_attr);
- waddch (dialog, ACS_RTEE);
-
- if (title != NULL && strlen(title) >= width-2 ) {
- /* truncate long title -- mec */
- char * title2 = malloc(width-2+1);
- memcpy( title2, title, width-2 );
- title2[width-2] = '\0';
- title = title2;
- }
-
- if (title != NULL) {
- wattrset (dialog, title_attr);
- mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' ');
- waddstr (dialog, (char *)title);
- waddch (dialog, ' ');
- }
-
- wattrset (dialog, dialog_attr);
- print_autowrap (dialog, prompt, width - 2, 1, 3);
-
- list_width = width - 6;
- box_y = height - list_height - 5;
- box_x = (width - list_width) / 2 - 1;
-
- /* create new window for the list */
- list = subwin (dialog, list_height, list_width, y+box_y+1, x+box_x+1);
-
- keypad (list, TRUE);
-
- /* draw a box around the list items */
- draw_box (dialog, box_y, box_x, list_height + 2, list_width + 2,
- menubox_border_attr, menubox_attr);
-
- /* Find length of longest item in order to center checklist */
- check_x = 0;
- for (i = 0; i < item_no; i++)
- check_x = MAX (check_x, + strlen (items[i]->name) + 4);
-
- check_x = (list_width - check_x) / 2;
- item_x = check_x + 4;
-
- if (choice >= list_height) {
- scroll = choice - list_height + 1;
- choice -= scroll;
- }
-
- /* Print the list */
- for (i = 0; i < max_choice; i++) {
- print_item (list, items[scroll + i]->name,
- status[i+scroll], i, i == choice);
- }
-
- print_arrows(dialog, choice, item_no, scroll,
- box_y, box_x + check_x + 5, list_height);
-
- print_buttons(dialog, height, width, 0);
-
- wnoutrefresh (list);
- wnoutrefresh (dialog);
- doupdate ();
-
- while (key != ESC) {
- key = wgetch (dialog);
-
- for (i = 0; i < max_choice; i++)
- if (toupper(key) == toupper(items[scroll + i]->name[0]))
- break;
-
-
- if ( i < max_choice || key == KEY_UP || key == KEY_DOWN ||
- key == '+' || key == '-' ) {
- if (key == KEY_UP || key == '-') {
- if (!choice) {
- if (!scroll)
- continue;
- /* Scroll list down */
- if (list_height > 1) {
- /* De-highlight current first item */
- print_item (list, items[scroll]->name,
- status[scroll], 0, FALSE);
- scrollok (list, TRUE);
- wscrl (list, -1);
- scrollok (list, FALSE);
- }
- scroll--;
- print_item (list, items[scroll]->name,
- status[scroll], 0, TRUE);
- wnoutrefresh (list);
-
- print_arrows(dialog, choice, item_no, scroll,
- box_y, box_x + check_x + 5, list_height);
-
- wrefresh (dialog);
-
- continue; /* wait for another key press */
- } else
- i = choice - 1;
- } else if (key == KEY_DOWN || key == '+') {
- if (choice == max_choice - 1) {
- if (scroll + choice >= item_no - 1)
- continue;
- /* Scroll list up */
- if (list_height > 1) {
- /* De-highlight current last item before scrolling up */
- print_item (list, items[scroll + max_choice - 1]->name,
- status[scroll + max_choice - 1],
- max_choice - 1, FALSE);
- scrollok (list, TRUE);
- scroll (list);
- scrollok (list, FALSE);
- }
- scroll++;
- print_item (list, items[scroll + max_choice - 1]->name,
- status[scroll + max_choice - 1],
- max_choice - 1, TRUE);
- wnoutrefresh (list);
-
- print_arrows(dialog, choice, item_no, scroll,
- box_y, box_x + check_x + 5, list_height);
-
- wrefresh (dialog);
-
- continue; /* wait for another key press */
- } else
- i = choice + 1;
- }
- if (i != choice) {
- /* De-highlight current item */
- print_item (list, items[scroll + choice]->name,
- status[scroll + choice], choice, FALSE);
- /* Highlight new item */
- choice = i;
- print_item (list, items[scroll + choice]->name,
- status[scroll + choice], choice, TRUE);
- wnoutrefresh (list);
- wrefresh (dialog);
- }
- continue; /* wait for another key press */
- }
- switch (key) {
- case 'H':
- case 'h':
- case '?':
- for (i = 0; i < item_no; i++)
- items[i]->selected = 0;
- items[scroll + choice]->selected = 1;
- delwin (dialog);
- free (status);
- return 1;
- case TAB:
- case KEY_LEFT:
- case KEY_RIGHT:
- button = ((key == KEY_LEFT ? --button : ++button) < 0)
- ? 1 : (button > 1 ? 0 : button);
-
- print_buttons(dialog, height, width, button);
- wrefresh (dialog);
- break;
- case 'S':
- case 's':
- case ' ':
- case '\n':
- if (!button) {
- if (flag == FLAG_CHECK) {
- status[scroll + choice] = !status[scroll + choice];
- wmove (list, choice, check_x);
- wattrset (list, check_selected_attr);
- wprintw (list, "[%c]", status[scroll + choice] ? 'X' : ' ');
- } else {
- if (!status[scroll + choice]) {
- for (i = 0; i < item_no; i++)
- status[i] = 0;
- status[scroll + choice] = 1;
- for (i = 0; i < max_choice; i++)
- print_item (list, items[scroll + i]->name,
- status[scroll + i], i, i == choice);
- }
+ int i, x, y, box_x, box_y;
+ int key = 0, button = 0, choice = 0, scroll = 0, max_choice;
+ WINDOW *dialog, *list;
+
+ /* which item to highlight */
+ item_foreach() {
+ if (item_is_tag('X'))
+ choice = item_n();
+ if (item_is_selected()) {
+ choice = item_n();
+ break;
}
- wnoutrefresh (list);
- wrefresh (dialog);
-
- for (i = 0; i < item_no; i++) {
- items[i]->selected = status[i];
- }
- } else {
- for (i = 0; i < item_no; i++)
- items[i]->selected = 0;
- items[scroll + choice]->selected = 1;
- }
- delwin (dialog);
- free (status);
- return button;
- case 'X':
- case 'x':
- key = ESC;
- case ESC:
- break;
}
- /* Now, update everything... */
- doupdate ();
- }
-
+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 */
+ x = (COLS - width) / 2;
+ y = (LINES - height) / 2;
+
+ draw_shadow(stdscr, y, x, height, width);
+
+ dialog = newwin(height, width, y, x);
+ keypad(dialog, TRUE);
+
+ draw_box(dialog, 0, 0, height, width,
+ dlg.dialog.atr, dlg.border.atr);
+ wattrset(dialog, dlg.border.atr);
+ mvwaddch(dialog, height - 3, 0, ACS_LTEE);
+ for (i = 0; i < width - 2; i++)
+ waddch(dialog, ACS_HLINE);
+ wattrset(dialog, dlg.dialog.atr);
+ waddch(dialog, ACS_RTEE);
+
+ print_title(dialog, title, width);
+
+ wattrset(dialog, dlg.dialog.atr);
+ print_autowrap(dialog, prompt, width - 2, 1, 3);
+
+ list_width = width - 6;
+ box_y = height - list_height - 5;
+ box_x = (width - list_width) / 2 - 1;
+
+ /* create new window for the list */
+ list = subwin(dialog, list_height, list_width, y + box_y + 1,
+ x + box_x + 1);
+
+ keypad(list, TRUE);
+
+ /* draw a box around the list items */
+ draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2,
+ dlg.menubox_border.atr, dlg.menubox.atr);
- delwin (dialog);
- free (status);
- return -1; /* ESC pressed */
+ /* Find length of longest item in order to center checklist */
+ check_x = 0;
+ item_foreach()
+ check_x = MAX(check_x, strlen(item_str()) + 4);
+
+ check_x = (list_width - check_x) / 2;
+ item_x = check_x + 4;
+
+ if (choice >= list_height) {
+ scroll = choice - list_height + 1;
+ choice -= scroll;
+ }
+
+ /* Print the list */
+ for (i = 0; i < max_choice; i++) {
+ item_set(scroll + i);
+ print_item(list, i, i == choice);
+ }
+
+ print_arrows(dialog, choice, item_count(), scroll,
+ box_y, box_x + check_x + 5, list_height);
+
+ print_buttons(dialog, height, width, 0);
+
+ wnoutrefresh(dialog);
+ wnoutrefresh(list);
+ doupdate();
+
+ while (key != KEY_ESC) {
+ key = wgetch(dialog);
+
+ for (i = 0; i < max_choice; i++) {
+ item_set(i + scroll);
+ if (toupper(key) == toupper(item_str()[0]))
+ break;
+ }
+
+ if (i < max_choice || key == KEY_UP || key == KEY_DOWN ||
+ key == '+' || key == '-') {
+ if (key == KEY_UP || key == '-') {
+ if (!choice) {
+ if (!scroll)
+ continue;
+ /* Scroll list down */
+ if (list_height > 1) {
+ /* De-highlight current first item */
+ item_set(scroll);
+ print_item(list, 0, FALSE);
+ scrollok(list, TRUE);
+ wscrl(list, -1);
+ scrollok(list, FALSE);
+ }
+ scroll--;
+ item_set(scroll);
+ print_item(list, 0, TRUE);
+ print_arrows(dialog, choice, item_count(),
+ scroll, box_y, box_x + check_x + 5, list_height);
+
+ wnoutrefresh(dialog);
+ wrefresh(list);
+
+ continue; /* wait for another key press */
+ } else
+ i = choice - 1;
+ } else if (key == KEY_DOWN || key == '+') {
+ if (choice == max_choice - 1) {
+ if (scroll + choice >= item_count() - 1)
+ continue;
+ /* Scroll list up */
+ if (list_height > 1) {
+ /* De-highlight current last item before scrolling up */
+ item_set(scroll + max_choice - 1);
+ print_item(list,
+ max_choice - 1,
+ FALSE);
+ scrollok(list, TRUE);
+ wscrl(list, 1);
+ scrollok(list, FALSE);
+ }
+ scroll++;
+ item_set(scroll + max_choice - 1);
+ print_item(list, max_choice - 1, TRUE);
+
+ print_arrows(dialog, choice, item_count(),
+ scroll, box_y, box_x + check_x + 5, list_height);
+
+ wnoutrefresh(dialog);
+ wrefresh(list);
+
+ continue; /* wait for another key press */
+ } else
+ i = choice + 1;
+ }
+ if (i != choice) {
+ /* De-highlight current item */
+ item_set(scroll + choice);
+ print_item(list, choice, FALSE);
+ /* Highlight new item */
+ choice = i;
+ item_set(scroll + choice);
+ print_item(list, choice, TRUE);
+ wnoutrefresh(dialog);
+ wrefresh(list);
+ }
+ continue; /* wait for another key press */
+ }
+ switch (key) {
+ case 'H':
+ case 'h':
+ case '?':
+ button = 1;
+ /* fall-through */
+ case 'S':
+ case 's':
+ case ' ':
+ case '\n':
+ item_foreach()
+ item_set_selected(0);
+ item_set(scroll + choice);
+ item_set_selected(1);
+ delwin(list);
+ delwin(dialog);
+ return button;
+ case TAB:
+ case KEY_LEFT:
+ case KEY_RIGHT:
+ button = ((key == KEY_LEFT ? --button : ++button) < 0)
+ ? 1 : (button > 1 ? 0 : button);
+
+ print_buttons(dialog, height, width, button);
+ wrefresh(dialog);
+ break;
+ case 'X':
+ case 'x':
+ key = KEY_ESC;
+ break;
+ 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... */
+ doupdate();
+ }
+ delwin(list);
+ delwin(dialog);
+ return key; /* ESC pressed */
}
diff --git a/package/config/lxdialog/dialog.h b/package/config/lxdialog/dialog.h
index 7bab3ad0e..fd695e107 100644
--- a/package/config/lxdialog/dialog.h
+++ b/package/config/lxdialog/dialog.h
@@ -1,4 +1,3 @@
-
/*
* dialog.h -- common declarations for all dialog modules
*
@@ -25,8 +24,8 @@
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
+#include <stdbool.h>
-#ifdef CURSES_LOC
#ifdef __sun__
#define CURS_MACROS
#endif
@@ -43,21 +42,20 @@
#if defined(NCURSES_VERSION) && defined(_NEED_WRAP) && !defined(GCC_PRINTFLIKE)
#define OLD_NCURSES 1
#undef wbkgdset
-#define wbkgdset(w,p) /*nothing*/
+#define wbkgdset(w,p) /*nothing */
#else
#define OLD_NCURSES 0
#endif
#define TR(params) _tracef params
-#define ESC 27
+#define KEY_ESC 27
#define TAB 9
#define MAX_LEN 2048
#define BUF_SIZE (10*1024)
#define MIN(x,y) (x < y ? x : y)
#define MAX(x,y) (x > y ? x : y)
-
#ifndef ACS_ULCORNER
#define ACS_ULCORNER '+'
#endif
@@ -89,93 +87,130 @@
#define ACS_DARROW 'v'
#endif
-/*
- * Attribute names
- */
-#define screen_attr attributes[0]
-#define shadow_attr attributes[1]
-#define dialog_attr attributes[2]
-#define title_attr attributes[3]
-#define border_attr attributes[4]
-#define button_active_attr attributes[5]
-#define button_inactive_attr attributes[6]
-#define button_key_active_attr attributes[7]
-#define button_key_inactive_attr attributes[8]
-#define button_label_active_attr attributes[9]
-#define button_label_inactive_attr attributes[10]
-#define inputbox_attr attributes[11]
-#define inputbox_border_attr attributes[12]
-#define searchbox_attr attributes[13]
-#define searchbox_title_attr attributes[14]
-#define searchbox_border_attr attributes[15]
-#define position_indicator_attr attributes[16]
-#define menubox_attr attributes[17]
-#define menubox_border_attr attributes[18]
-#define item_attr attributes[19]
-#define item_selected_attr attributes[20]
-#define tag_attr attributes[21]
-#define tag_selected_attr attributes[22]
-#define tag_key_attr attributes[23]
-#define tag_key_selected_attr attributes[24]
-#define check_attr attributes[25]
-#define check_selected_attr attributes[26]
-#define uarrow_attr attributes[27]
-#define darrow_attr attributes[28]
-
-/* number of attributes */
-#define ATTRIBUTE_COUNT 29
+/* error return codes */
+#define ERRDISPLAYTOOSMALL (KEY_MAX + 1)
/*
- * Global variables
+ * Color definitions
*/
-extern bool use_colors;
-
-extern chtype attributes[];
-#endif
-
-extern const char *backtitle;
+struct dialog_color {
+ chtype atr; /* Color attribute */
+ int fg; /* foreground */
+ int bg; /* background */
+ int hl; /* highlight this item */
+};
-struct dialog_list_item {
- char *name;
- int namelen;
- char *tag;
- int selected; /* Set to 1 by dialog_*() function. */
+struct dialog_info {
+ const char *backtitle;
+ struct dialog_color screen;
+ struct dialog_color shadow;
+ struct dialog_color dialog;
+ struct dialog_color title;
+ struct dialog_color border;
+ struct dialog_color button_active;
+ struct dialog_color button_inactive;
+ struct dialog_color button_key_active;
+ struct dialog_color button_key_inactive;
+ struct dialog_color button_label_active;
+ struct dialog_color button_label_inactive;
+ struct dialog_color inputbox;
+ struct dialog_color inputbox_border;
+ struct dialog_color searchbox;
+ struct dialog_color searchbox_title;
+ struct dialog_color searchbox_border;
+ struct dialog_color position_indicator;
+ struct dialog_color menubox;
+ struct dialog_color menubox_border;
+ struct dialog_color item;
+ struct dialog_color item_selected;
+ struct dialog_color tag;
+ struct dialog_color tag_selected;
+ struct dialog_color tag_key;
+ struct dialog_color tag_key_selected;
+ struct dialog_color check;
+ struct dialog_color check_selected;
+ struct dialog_color uarrow;
+ struct dialog_color darrow;
};
/*
+ * Global variables
+ */
+extern struct dialog_info dlg;
+extern char dialog_input_result[];
+
+/*
* Function prototypes
*/
-void init_dialog (void);
-void end_dialog (void);
-void dialog_clear (void);
-#ifdef CURSES_LOC
-void attr_clear (WINDOW * win, int height, int width, chtype attr);
-void color_setup (void);
-void print_autowrap (WINDOW * win, const char *prompt, int width, int y, int x);
-void print_button (WINDOW * win, const char *label, int y, int x, int selected);
-void draw_box (WINDOW * win, int y, int x, int height, int width, chtype box,
- chtype border);
-void draw_shadow (WINDOW * win, int y, int x, int height, int width);
-#endif
+/* item list as used by checklist and menubox */
+void item_reset(void);
+void item_make(const char *fmt, ...);
+void item_add_str(const char *fmt, ...);
+void item_set_tag(char tag);
+void item_set_data(void *p);
+void item_set_selected(int val);
+int item_activate_selected(void);
+void *item_data(void);
+char item_tag(void);
+
+/* item list manipulation for lxdialog use */
+#define MAXITEMSTR 200
+struct dialog_item {
+ char str[MAXITEMSTR]; /* promtp displayed */
+ char tag;
+ void *data; /* pointer to menu item - used by menubox+checklist */
+ int selected; /* Set to 1 by dialog_*() function if selected. */
+};
+
+/* list of lialog_items */
+struct dialog_list {
+ struct dialog_item node;
+ struct dialog_list *next;
+};
-int first_alpha (const char *string, const char *exempt);
-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 char *choice, int item_no,
- struct dialog_list_item ** items);
-int dialog_checklist (const char *title, const char *prompt, int height,
- int width, int list_height, int item_no,
- struct dialog_list_item ** items, int flag);
-extern unsigned char dialog_input_result[];
-int dialog_inputbox (const char *title, const char *prompt, int height,
- int width, const char *init);
-
-struct dialog_list_item *first_sel_item(int item_no,
- struct dialog_list_item ** items);
+extern struct dialog_list *item_cur;
+extern struct dialog_list item_nil;
+extern struct dialog_list *item_head;
+
+int item_count(void);
+void item_set(int n);
+int item_n(void);
+const char *item_str(void);
+int item_is_selected(void);
+int item_is_tag(char tag);
+#define item_foreach() \
+ for (item_cur = item_head ? item_head: item_cur; \
+ item_cur && (item_cur != &item_nil); item_cur = item_cur->next)
+
+/* generic key handlers */
+int on_key_esc(WINDOW *win);
+int on_key_resize(void);
+
+void init_dialog(const char *backtitle);
+void reset_dialog(void);
+void end_dialog(void);
+void attr_clear(WINDOW * win, int height, int width, chtype attr);
+void dialog_clear(void);
+void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x);
+void print_button(WINDOW * win, const char *label, int y, int x, int selected);
+void print_title(WINDOW *dialog, const char *title, int width);
+void draw_box(WINDOW * win, int y, int x, int height, int width, chtype box,
+ chtype border);
+void draw_shadow(WINDOW * win, int y, int x, int height, int width);
+
+int first_alpha(const char *string, const char *exempt);
+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,
+ 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[];
+int dialog_inputbox(const char *title, const char *prompt, int height,
+ int width, const char *init);
/*
* This is the base for fictitious keys, which activate
@@ -186,14 +221,4 @@ struct dialog_list_item *first_sel_item(int item_no,
* -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o')
* -- uppercase chars are used to invoke the button (M_EVENT + 'O')
*/
-#ifdef CURSES_LOC
#define M_EVENT (KEY_MAX+1)
-#endif
-
-
-/*
- * The `flag' parameter in checklist is used to select between
- * radiolist and checklist
- */
-#define FLAG_CHECK 1
-#define FLAG_RADIO 0
diff --git a/package/config/lxdialog/inputbox.c b/package/config/lxdialog/inputbox.c
index fa7bebc69..05e72066b 100644
--- a/package/config/lxdialog/inputbox.c
+++ b/package/config/lxdialog/inputbox.c
@@ -21,220 +21,218 @@
#include "dialog.h"
-unsigned char dialog_input_result[MAX_LEN + 1];
+char dialog_input_result[MAX_LEN + 1];
/*
* Print the termination buttons
*/
-static void
-print_buttons(WINDOW *dialog, int height, int width, int selected)
+static void print_buttons(WINDOW * dialog, int height, int width, int selected)
{
- int x = width / 2 - 11;
- int y = height - 2;
+ int x = width / 2 - 11;
+ int y = height - 2;
- print_button (dialog, " Ok ", y, x, selected==0);
- print_button (dialog, " Help ", y, x + 14, selected==1);
+ print_button(dialog, " Ok ", y, x, selected == 0);
+ print_button(dialog, " Help ", y, x + 14, selected == 1);
- wmove(dialog, y, x+1+14*selected);
- wrefresh(dialog);
+ wmove(dialog, y, x + 1 + 14 * selected);
+ wrefresh(dialog);
}
/*
* Display a dialog box for inputing a string
*/
-int
-dialog_inputbox (const char *title, const char *prompt, int height, int width,
- const char *init)
+int dialog_inputbox(const char *title, const char *prompt, int height, int width,
+ const char *init)
{
- int i, x, y, box_y, box_x, box_width;
- int input_x = 0, scroll = 0, key = 0, button = -1;
- unsigned char *instr = dialog_input_result;
- WINDOW *dialog;
-
- /* center dialog box on screen */
- x = (COLS - width) / 2;
- y = (LINES - height) / 2;
-
-
- draw_shadow (stdscr, y, x, height, width);
-
- dialog = newwin (height, width, y, x);
- keypad (dialog, TRUE);
-
- draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr);
- wattrset (dialog, border_attr);
- mvwaddch (dialog, height-3, 0, ACS_LTEE);
- for (i = 0; i < width - 2; i++)
- waddch (dialog, ACS_HLINE);
- wattrset (dialog, dialog_attr);
- waddch (dialog, ACS_RTEE);
-
- if (title != NULL && strlen(title) >= width-2 ) {
- /* truncate long title -- mec */
- char * title2 = malloc(width-2+1);
- memcpy( title2, title, width-2 );
- title2[width-2] = '\0';
- title = title2;
- }
-
- if (title != NULL) {
- wattrset (dialog, title_attr);
- mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' ');
- waddstr (dialog, (char *)title);
- waddch (dialog, ' ');
- }
-
- wattrset (dialog, dialog_attr);
- print_autowrap (dialog, prompt, width - 2, 1, 3);
-
- /* Draw the input field box */
- box_width = width - 6;
- getyx (dialog, y, x);
- box_y = y + 2;
- box_x = (width - box_width) / 2;
- draw_box (dialog, y + 1, box_x - 1, 3, box_width + 2,
- border_attr, dialog_attr);
-
- print_buttons(dialog, height, width, 0);
-
- /* Set up the initial value */
- wmove (dialog, box_y, box_x);
- wattrset (dialog, inputbox_attr);
-
- if (!init)
- instr[0] = '\0';
- else
- strcpy (instr, init);
-
- input_x = strlen (instr);
-
- if (input_x >= box_width) {
- scroll = input_x - box_width + 1;
- input_x = box_width - 1;
- for (i = 0; i < box_width - 1; i++)
- waddch (dialog, instr[scroll + i]);
- } else
- waddstr (dialog, instr);
-
- wmove (dialog, box_y, box_x + input_x);
-
- wrefresh (dialog);
-
- while (key != ESC) {
- key = wgetch (dialog);
-
- if (button == -1) { /* Input box selected */
- switch (key) {
- case TAB:
- case KEY_UP:
- case KEY_DOWN:
- break;
- case KEY_LEFT:
- continue;
- case KEY_RIGHT:
- continue;
- case KEY_BACKSPACE:
- case 127:
- if (input_x || scroll) {
- wattrset (dialog, inputbox_attr);
- if (!input_x) {
- scroll = scroll < box_width - 1 ?
- 0 : scroll - (box_width - 1);
- wmove (dialog, box_y, box_x);
- for (i = 0; i < box_width; i++)
- waddch (dialog, instr[scroll + input_x + i] ?
- instr[scroll + input_x + i] : ' ');
- input_x = strlen (instr) - scroll;
- } else
- input_x--;
- instr[scroll + input_x] = '\0';
- mvwaddch (dialog, box_y, input_x + box_x, ' ');
- wmove (dialog, box_y, input_x + box_x);
- wrefresh (dialog);
+ int i, x, y, box_y, box_x, box_width;
+ int input_x = 0, scroll = 0, key = 0, button = -1;
+ 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;
+
+ draw_shadow(stdscr, y, x, height, width);
+
+ dialog = newwin(height, width, y, x);
+ keypad(dialog, TRUE);
+
+ draw_box(dialog, 0, 0, height, width,
+ dlg.dialog.atr, dlg.border.atr);
+ wattrset(dialog, dlg.border.atr);
+ mvwaddch(dialog, height - 3, 0, ACS_LTEE);
+ for (i = 0; i < width - 2; i++)
+ waddch(dialog, ACS_HLINE);
+ wattrset(dialog, dlg.dialog.atr);
+ waddch(dialog, ACS_RTEE);
+
+ print_title(dialog, title, width);
+
+ wattrset(dialog, dlg.dialog.atr);
+ print_autowrap(dialog, prompt, width - 2, 1, 3);
+
+ /* Draw the input field box */
+ box_width = width - 6;
+ getyx(dialog, y, x);
+ box_y = y + 2;
+ box_x = (width - box_width) / 2;
+ draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2,
+ dlg.border.atr, dlg.dialog.atr);
+
+ print_buttons(dialog, height, width, 0);
+
+ /* Set up the initial value */
+ wmove(dialog, box_y, box_x);
+ wattrset(dialog, dlg.inputbox.atr);
+
+ input_x = strlen(instr);
+
+ if (input_x >= box_width) {
+ scroll = input_x - box_width + 1;
+ input_x = box_width - 1;
+ for (i = 0; i < box_width - 1; i++)
+ waddch(dialog, instr[scroll + i]);
+ } else {
+ waddstr(dialog, instr);
+ }
+
+ wmove(dialog, box_y, box_x + input_x);
+
+ wrefresh(dialog);
+
+ while (key != KEY_ESC) {
+ key = wgetch(dialog);
+
+ if (button == -1) { /* Input box selected */
+ switch (key) {
+ case TAB:
+ case KEY_UP:
+ case KEY_DOWN:
+ break;
+ case KEY_LEFT:
+ continue;
+ case KEY_RIGHT:
+ continue;
+ case KEY_BACKSPACE:
+ case 127:
+ if (input_x || scroll) {
+ wattrset(dialog, dlg.inputbox.atr);
+ if (!input_x) {
+ scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1);
+ wmove(dialog, box_y, box_x);
+ for (i = 0; i < box_width; i++)
+ waddch(dialog,
+ instr[scroll + input_x + i] ?
+ instr[scroll + input_x + i] : ' ');
+ input_x = strlen(instr) - scroll;
+ } else
+ input_x--;
+ instr[scroll + input_x] = '\0';
+ mvwaddch(dialog, box_y, input_x + box_x, ' ');
+ wmove(dialog, box_y, input_x + box_x);
+ wrefresh(dialog);
+ }
+ continue;
+ default:
+ if (key < 0x100 && isprint(key)) {
+ if (scroll + input_x < MAX_LEN) {
+ wattrset(dialog, dlg.inputbox.atr);
+ instr[scroll + input_x] = key;
+ instr[scroll + input_x + 1] = '\0';
+ if (input_x == box_width - 1) {
+ scroll++;
+ wmove(dialog, box_y, box_x);
+ for (i = 0; i < box_width - 1; i++)
+ waddch(dialog, instr [scroll + i]);
+ } else {
+ wmove(dialog, box_y, input_x++ + box_x);
+ waddch(dialog, key);
+ }
+ wrefresh(dialog);
+ } else
+ flash(); /* Alarm user about overflow */
+ continue;
+ }
+ }
}
- continue;
- default:
- if (key < 0x100 && isprint (key)) {
- if (scroll + input_x < MAX_LEN) {
- wattrset (dialog, inputbox_attr);
- instr[scroll + input_x] = key;
- instr[scroll + input_x + 1] = '\0';
- if (input_x == box_width - 1) {
- scroll++;
- wmove (dialog, box_y, box_x);
- for (i = 0; i < box_width - 1; i++)
- waddch (dialog, instr[scroll + i]);
- } else {
- wmove (dialog, box_y, input_x++ + box_x);
- waddch (dialog, key);
+ switch (key) {
+ case 'O':
+ case 'o':
+ delwin(dialog);
+ return 0;
+ case 'H':
+ case 'h':
+ delwin(dialog);
+ return 1;
+ case KEY_UP:
+ case KEY_LEFT:
+ switch (button) {
+ case -1:
+ button = 1; /* Indicates "Cancel" button is selected */
+ print_buttons(dialog, height, width, 1);
+ break;
+ case 0:
+ button = -1; /* Indicates input box is selected */
+ print_buttons(dialog, height, width, 0);
+ wmove(dialog, box_y, box_x + input_x);
+ wrefresh(dialog);
+ break;
+ case 1:
+ button = 0; /* Indicates "OK" button is selected */
+ print_buttons(dialog, height, width, 0);
+ break;
}
- wrefresh (dialog);
- } else
- flash (); /* Alarm user about overflow */
- continue;
+ break;
+ case TAB:
+ case KEY_DOWN:
+ case KEY_RIGHT:
+ switch (button) {
+ case -1:
+ button = 0; /* Indicates "OK" button is selected */
+ print_buttons(dialog, height, width, 0);
+ break;
+ case 0:
+ button = 1; /* Indicates "Cancel" button is selected */
+ print_buttons(dialog, height, width, 1);
+ break;
+ case 1:
+ button = -1; /* Indicates input box is selected */
+ print_buttons(dialog, height, width, 0);
+ wmove(dialog, box_y, box_x + input_x);
+ wrefresh(dialog);
+ break;
+ }
+ break;
+ case ' ':
+ case '\n':
+ delwin(dialog);
+ return (button == -1 ? 0 : button);
+ case 'X':
+ case 'x':
+ key = KEY_ESC;
+ break;
+ case KEY_ESC:
+ key = on_key_esc(dialog);
+ break;
+ case KEY_RESIZE:
+ delwin(dialog);
+ on_key_resize();
+ goto do_resize;
}
- }
- }
- switch (key) {
- case 'O':
- case 'o':
- delwin (dialog);
- return 0;
- case 'H':
- case 'h':
- delwin (dialog);
- return 1;
- case KEY_UP:
- case KEY_LEFT:
- switch (button) {
- case -1:
- button = 1; /* Indicates "Cancel" button is selected */
- print_buttons(dialog, height, width, 1);
- break;
- case 0:
- button = -1; /* Indicates input box is selected */
- print_buttons(dialog, height, width, 0);
- wmove (dialog, box_y, box_x + input_x);
- wrefresh (dialog);
- break;
- case 1:
- button = 0; /* Indicates "OK" button is selected */
- print_buttons(dialog, height, width, 0);
- break;
- }
- break;
- case TAB:
- case KEY_DOWN:
- case KEY_RIGHT:
- switch (button) {
- case -1:
- button = 0; /* Indicates "OK" button is selected */
- print_buttons(dialog, height, width, 0);
- break;
- case 0:
- button = 1; /* Indicates "Cancel" button is selected */
- print_buttons(dialog, height, width, 1);
- break;
- case 1:
- button = -1; /* Indicates input box is selected */
- print_buttons(dialog, height, width, 0);
- wmove (dialog, box_y, box_x + input_x);
- wrefresh (dialog);
- break;
- }
- break;
- case ' ':
- case '\n':
- delwin (dialog);
- return (button == -1 ? 0 : button);
- case 'X':
- case 'x':
- key = ESC;
- case ESC:
- break;
}
- }
- delwin (dialog);
- return -1; /* ESC pressed */
+ delwin(dialog);
+ return KEY_ESC; /* ESC pressed */
}
diff --git a/package/config/lxdialog/menubox.c b/package/config/lxdialog/menubox.c
index 873dc587b..0d83159d9 100644
--- a/package/config/lxdialog/menubox.c
+++ b/package/config/lxdialog/menubox.c
@@ -63,376 +63,372 @@ static int menu_width, item_x;
/*
* Print menu item
*/
-static void
-print_item (WINDOW * win, const char *item, int choice, int selected, int hotkey)
+static void do_print_item(WINDOW * win, const char *item, int line_y,
+ int selected, int hotkey)
{
- int j;
- char menu_item[menu_width+1];
+ int j;
+ char *menu_item = malloc(menu_width + 1);
- strncpy(menu_item, item, menu_width);
- menu_item[menu_width] = 0;
- j = first_alpha(menu_item, "YyNnMmHh");
+ strncpy(menu_item, item, menu_width - item_x);
+ menu_item[menu_width - item_x] = '\0';
+ j = first_alpha(menu_item, "YyNnMmHh");
- /* Clear 'residue' of last item */
- wattrset (win, menubox_attr);
- wmove (win, choice, 0);
+ /* Clear 'residue' of last item */
+ wattrset(win, dlg.menubox.atr);
+ wmove(win, line_y, 0);
#if OLD_NCURSES
- {
- int i;
- for (i = 0; i < menu_width; i++)
- waddch (win, ' ');
- }
+ {
+ int i;
+ for (i = 0; i < menu_width; i++)
+ waddch(win, ' ');
+ }
#else
- wclrtoeol(win);
+ wclrtoeol(win);
#endif
- wattrset (win, selected ? item_selected_attr : item_attr);
- mvwaddstr (win, choice, item_x, menu_item);
- if (hotkey) {
- wattrset (win, selected ? tag_key_selected_attr : tag_key_attr);
- mvwaddch(win, choice, item_x+j, menu_item[j]);
- }
- if (selected) {
- wmove (win, choice, item_x+1);
- wrefresh (win);
- }
+ wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr);
+ mvwaddstr(win, line_y, item_x, menu_item);
+ if (hotkey) {
+ wattrset(win, selected ? dlg.tag_key_selected.atr
+ : dlg.tag_key.atr);
+ mvwaddch(win, line_y, item_x + j, menu_item[j]);
+ }
+ if (selected) {
+ wmove(win, line_y, item_x + 1);
+ }
+ free(menu_item);
+ wrefresh(win);
}
+#define print_item(index, choice, selected) \
+do { \
+ item_set(index); \
+ do_print_item(menu, item_str(), choice, selected, !item_is_tag(':')); \
+} while (0)
+
/*
* Print the scroll indicators.
*/
-static void
-print_arrows (WINDOW * win, int item_no, int scroll,
- int y, int x, int height)
+static void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x,
+ int height)
{
- int cur_y, cur_x;
-
- getyx(win, cur_y, cur_x);
-
- wmove(win, y, x);
-
- if (scroll > 0) {
- wattrset (win, uarrow_attr);
- waddch (win, ACS_UARROW);
- waddstr (win, "(-)");
- }
- else {
- wattrset (win, menubox_attr);
- waddch (win, ACS_HLINE);
- waddch (win, ACS_HLINE);
- waddch (win, ACS_HLINE);
- waddch (win, ACS_HLINE);
- }
-
- y = y + height + 1;
- wmove(win, y, x);
-
- if ((height < item_no) && (scroll + height < item_no)) {
- wattrset (win, darrow_attr);
- waddch (win, ACS_DARROW);
- waddstr (win, "(+)");
- }
- else {
- wattrset (win, menubox_border_attr);
- waddch (win, ACS_HLINE);
- waddch (win, ACS_HLINE);
- waddch (win, ACS_HLINE);
- waddch (win, ACS_HLINE);
- }
-
- wmove(win, cur_y, cur_x);
+ int cur_y, cur_x;
+
+ getyx(win, cur_y, cur_x);
+
+ wmove(win, y, x);
+
+ if (scroll > 0) {
+ wattrset(win, dlg.uarrow.atr);
+ waddch(win, ACS_UARROW);
+ waddstr(win, "(-)");
+ } else {
+ wattrset(win, dlg.menubox.atr);
+ waddch(win, ACS_HLINE);
+ waddch(win, ACS_HLINE);
+ waddch(win, ACS_HLINE);
+ waddch(win, ACS_HLINE);
+ }
+
+ y = y + height + 1;
+ wmove(win, y, x);
+ wrefresh(win);
+
+ if ((height < item_no) && (scroll + height < item_no)) {
+ wattrset(win, dlg.darrow.atr);
+ waddch(win, ACS_DARROW);
+ waddstr(win, "(+)");
+ } else {
+ wattrset(win, dlg.menubox_border.atr);
+ waddch(win, ACS_HLINE);
+ waddch(win, ACS_HLINE);
+ waddch(win, ACS_HLINE);
+ waddch(win, ACS_HLINE);
+ }
+
+ wmove(win, cur_y, cur_x);
+ wrefresh(win);
}
/*
* Display the termination buttons.
*/
-static void
-print_buttons (WINDOW *win, int height, int width, int selected)
+static void print_buttons(WINDOW * win, int height, int width, int selected)
{
- int x = width / 2 - 16;
- int y = height - 2;
+ int x = width / 2 - 16;
+ int y = height - 2;
+
+ print_button(win, "Select", y, x, selected == 0);
+ print_button(win, " Exit ", y, x + 12, selected == 1);
+ print_button(win, " Help ", y, x + 24, selected == 2);
- print_button (win, "Select", y, x, selected == 0);
- print_button (win, " Exit ", y, x + 12, selected == 1);
- print_button (win, " Help ", y, x + 24, selected == 2);
+ wmove(win, y, x + 1 + 12 * selected);
+ wrefresh(win);
+}
- wmove(win, y, x+1+12*selected);
- wrefresh (win);
+/* scroll up n lines (n may be negative) */
+static void do_scroll(WINDOW *win, int *scroll, int n)
+{
+ /* Scroll menu up */
+ scrollok(win, TRUE);
+ wscrl(win, n);
+ scrollok(win, FALSE);
+ *scroll = *scroll + n;
+ wrefresh(win);
}
/*
* 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 char *current, int item_no,
- struct dialog_list_item ** items)
+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 key = 0, button = 0, scroll = 0, choice = 0, first_item = 0, max_choice;
- WINDOW *dialog, *menu;
- FILE *f;
-
- max_choice = MIN (menu_height, item_no);
-
- /* center dialog box on screen */
- x = (COLS - width) / 2;
- y = (LINES - height) / 2;
-
- draw_shadow (stdscr, y, x, height, width);
-
- dialog = newwin (height, width, y, x);
- keypad (dialog, TRUE);
-
- draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr);
- wattrset (dialog, border_attr);
- mvwaddch (dialog, height - 3, 0, ACS_LTEE);
- for (i = 0; i < width - 2; i++)
- waddch (dialog, ACS_HLINE);
- wattrset (dialog, dialog_attr);
- wbkgdset (dialog, dialog_attr & A_COLOR);
- waddch (dialog, ACS_RTEE);
-
- if (title != NULL && strlen(title) >= width-2 ) {
- /* truncate long title -- mec */
- char * title2 = malloc(width-2+1);
- memcpy( title2, title, width-2 );
- title2[width-2] = '\0';
- title = title2;
- }
-
- if (title != NULL) {
- wattrset (dialog, title_attr);
- mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' ');
- waddstr (dialog, (char *)title);
- waddch (dialog, ' ');
- }
-
- wattrset (dialog, dialog_attr);
- print_autowrap (dialog, prompt, width - 2, 1, 3);
-
- menu_width = width - 6;
- box_y = height - menu_height - 5;
- box_x = (width - menu_width) / 2 - 1;
-
- /* create new window for the menu */
- menu = subwin (dialog, menu_height, menu_width,
- y + box_y + 1, x + box_x + 1);
- keypad (menu, TRUE);
-
- /* draw a box around the menu items */
- draw_box (dialog, box_y, box_x, menu_height + 2, menu_width + 2,
- menubox_border_attr, menubox_attr);
-
- /*
- * Find length of longest item in order to center menu.
- * Set 'choice' to default item.
- */
- item_x = 0;
- for (i = 0; i < item_no; i++) {
- item_x = MAX (item_x, MIN(menu_width, strlen (items[i]->name) + 2));
- if (strcmp(current, items[i]->tag) == 0) choice = i;
- }
-
- item_x = (menu_width - item_x) / 2;
-
- /* get the scroll info from the temp file */
- if ( (f=fopen("lxdialog.scrltmp","r")) != NULL ) {
- if ( (fscanf(f,"%d\n",&scroll) == 1) && (scroll <= choice) &&
- (scroll+max_choice > choice) && (scroll >= 0) &&
- (scroll+max_choice <= item_no) ) {
- first_item = scroll;
- choice = choice - scroll;
- fclose(f);
+ 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 */
+ x = (COLS - width) / 2;
+ y = (LINES - height) / 2;
+
+ draw_shadow(stdscr, y, x, height, width);
+
+ dialog = newwin(height, width, y, x);
+ keypad(dialog, TRUE);
+
+ draw_box(dialog, 0, 0, height, width,
+ dlg.dialog.atr, dlg.border.atr);
+ wattrset(dialog, dlg.border.atr);
+ mvwaddch(dialog, height - 3, 0, ACS_LTEE);
+ for (i = 0; i < width - 2; i++)
+ waddch(dialog, ACS_HLINE);
+ wattrset(dialog, dlg.dialog.atr);
+ wbkgdset(dialog, dlg.dialog.atr & A_COLOR);
+ waddch(dialog, ACS_RTEE);
+
+ print_title(dialog, title, width);
+
+ wattrset(dialog, dlg.dialog.atr);
+ print_autowrap(dialog, prompt, width - 2, 1, 3);
+
+ menu_width = width - 6;
+ box_y = height - menu_height - 5;
+ box_x = (width - menu_width) / 2 - 1;
+
+ /* create new window for the menu */
+ menu = subwin(dialog, menu_height, menu_width,
+ y + box_y + 1, x + box_x + 1);
+ keypad(menu, TRUE);
+
+ /* draw a box around the menu items */
+ draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
+ dlg.menubox_border.atr, dlg.menubox.atr);
+
+ if (menu_width >= 80)
+ item_x = (menu_width - 70) / 2;
+ else
+ item_x = 4;
+
+ /* Set choice to default item */
+ item_foreach()
+ if (selected && (selected == item_data()))
+ choice = item_n();
+ /* get the saved scroll info */
+ scroll = *s_scroll;
+ if ((scroll <= choice) && (scroll + max_choice > choice) &&
+ (scroll >= 0) && (scroll + max_choice <= item_count())) {
+ first_item = scroll;
+ choice = choice - scroll;
} else {
- scroll=0;
- remove("lxdialog.scrltmp");
- fclose(f);
- f=NULL;
+ scroll = 0;
+ }
+ if ((choice >= max_choice)) {
+ if (choice >= item_count() - max_choice / 2)
+ scroll = first_item = item_count() - max_choice;
+ else
+ scroll = first_item = choice - max_choice / 2;
+ choice = choice - scroll;
}
- }
- if ( (choice >= max_choice) || (f==NULL && choice >= max_choice/2) ) {
- if (choice >= item_no-max_choice/2)
- scroll = first_item = item_no-max_choice;
- else
- scroll = first_item = choice - max_choice/2;
- choice = choice - scroll;
- }
-
- /* Print the menu */
- for (i=0; i < max_choice; i++) {
- print_item (menu, items[first_item + i]->name, i, i == choice,
- (items[first_item + i]->tag[0] != ':'));
- }
-
- wnoutrefresh (menu);
-
- print_arrows(dialog, item_no, scroll,
- box_y, box_x+item_x+1, menu_height);
-
- print_buttons (dialog, height, width, 0);
- wmove (menu, choice, item_x+1);
- wrefresh (menu);
- while (key != ESC) {
- key = wgetch(menu);
+ /* Print the menu */
+ for (i = 0; i < max_choice; i++) {
+ print_item(first_item + i, i, i == choice);
+ }
- if (key < 256 && isalpha(key)) key = tolower(key);
+ wnoutrefresh(menu);
+
+ print_arrows(dialog, item_count(), scroll,
+ box_y, box_x + item_x + 1, menu_height);
+
+ print_buttons(dialog, height, width, 0);
+ wmove(menu, choice, item_x + 1);
+ wrefresh(menu);
+
+ while (key != KEY_ESC) {
+ key = wgetch(menu);
+
+ if (key < 256 && isalpha(key))
+ key = tolower(key);
+
+ if (strchr("ynmh", key))
+ i = max_choice;
+ else {
+ for (i = choice + 1; i < max_choice; i++) {
+ item_set(scroll + i);
+ j = first_alpha(item_str(), "YyNnMmHh");
+ if (key == tolower(item_str()[j]))
+ break;
+ }
+ if (i == max_choice)
+ for (i = 0; i < max_choice; i++) {
+ item_set(scroll + i);
+ j = first_alpha(item_str(), "YyNnMmHh");
+ if (key == tolower(item_str()[j]))
+ break;
+ }
+ }
- if (strchr("ynmh", key))
- i = max_choice;
- else {
- for (i = choice+1; i < max_choice; i++) {
- j = first_alpha(items[scroll + i]->name, "YyNnMmHh");
- if (key == tolower(items[scroll + i]->name[j]))
- break;
- }
- if (i == max_choice)
- for (i = 0; i < max_choice; i++) {
- j = first_alpha(items[scroll + i]->name, "YyNnMmHh");
- if (key == tolower(items[scroll + i]->name[j]))
- break;
+ if (i < max_choice ||
+ key == KEY_UP || key == KEY_DOWN ||
+ key == '-' || key == '+' ||
+ key == KEY_PPAGE || key == KEY_NPAGE) {
+ /* Remove highligt of current item */
+ print_item(scroll + choice, choice, FALSE);
+
+ if (key == KEY_UP || key == '-') {
+ if (choice < 2 && scroll) {
+ /* Scroll menu down */
+ do_scroll(menu, &scroll, -1);
+
+ print_item(scroll, 0, FALSE);
+ } else
+ choice = MAX(choice - 1, 0);
+
+ } else if (key == KEY_DOWN || key == '+') {
+ print_item(scroll+choice, choice, FALSE);
+
+ if ((choice > max_choice - 3) &&
+ (scroll + max_choice < item_count())) {
+ /* Scroll menu up */
+ do_scroll(menu, &scroll, 1);
+
+ print_item(scroll+max_choice - 1,
+ max_choice - 1, FALSE);
+ } else
+ choice = MIN(choice + 1, max_choice - 1);
+
+ } else if (key == KEY_PPAGE) {
+ scrollok(menu, TRUE);
+ for (i = 0; (i < max_choice); i++) {
+ if (scroll > 0) {
+ do_scroll(menu, &scroll, -1);
+ print_item(scroll, 0, FALSE);
+ } else {
+ if (choice > 0)
+ choice--;
+ }
+ }
+
+ } else if (key == KEY_NPAGE) {
+ for (i = 0; (i < max_choice); i++) {
+ if (scroll + max_choice < item_count()) {
+ do_scroll(menu, &scroll, 1);
+ print_item(scroll+max_choice-1,
+ max_choice - 1, FALSE);
+ } else {
+ if (choice + 1 < max_choice)
+ choice++;
+ }
+ }
+ } else
+ choice = i;
+
+ print_item(scroll + choice, choice, TRUE);
+
+ print_arrows(dialog, item_count(), scroll,
+ box_y, box_x + item_x + 1, menu_height);
+
+ wnoutrefresh(dialog);
+ wrefresh(menu);
+
+ continue; /* wait for another key press */
}
- }
- if (i < max_choice ||
- key == KEY_UP || key == KEY_DOWN ||
- key == '-' || key == '+' ||
- key == KEY_PPAGE || key == KEY_NPAGE) {
-
- print_item (menu, items[scroll + choice]->name, choice, FALSE,
- (items[scroll + choice]->tag[0] != ':'));
-
- if (key == KEY_UP || key == '-') {
- if (choice < 2 && scroll) {
- /* Scroll menu down */
- scrollok (menu, TRUE);
- wscrl (menu, -1);
- scrollok (menu, FALSE);
-
- scroll--;
-
- print_item (menu, items[scroll]->name, 0, FALSE,
- (items[scroll]->tag[0] != ':'));
- } else
- choice = MAX(choice - 1, 0);
-
- } else if (key == KEY_DOWN || key == '+') {
-
- print_item (menu, items[scroll + choice]->name, choice, FALSE,
- (items[scroll + choice]->tag[0] != ':'));
-
- if ((choice > max_choice-3) &&
- (scroll + max_choice < item_no)
- ) {
- /* Scroll menu up */
- scrollok (menu, TRUE);
- scroll (menu);
- scrollok (menu, FALSE);
-
- scroll++;
-
- print_item (menu, items[scroll + max_choice - 1]->name,
- max_choice-1, FALSE,
- (items[scroll + max_choice - 1]->tag[0] != ':'));
- } else
- choice = MIN(choice+1, max_choice-1);
-
- } else if (key == KEY_PPAGE) {
- scrollok (menu, TRUE);
- for (i=0; (i < max_choice); i++) {
- if (scroll > 0) {
- wscrl (menu, -1);
- scroll--;
- print_item (menu, items[scroll]->name, 0, FALSE,
- (items[scroll]->tag[0] != ':'));
- } else {
- if (choice > 0)
- choice--;
- }
- }
- scrollok (menu, FALSE);
-
- } else if (key == KEY_NPAGE) {
- for (i=0; (i < max_choice); i++) {
- if (scroll+max_choice < item_no) {
- scrollok (menu, TRUE);
- scroll(menu);
- scrollok (menu, FALSE);
- scroll++;
- print_item (menu, items[scroll + max_choice - 1]->name,
- max_choice-1, FALSE,
- (items[scroll + max_choice - 1]->tag[0] != ':'));
- } else {
- if (choice+1 < max_choice)
- choice++;
- }
- }
-
- } else
- choice = i;
-
- print_item (menu, items[scroll + choice]->name, choice, TRUE,
- (items[scroll + choice]->tag[0] != ':'));
-
- print_arrows(dialog, item_no, scroll,
- box_y, box_x+item_x+1, menu_height);
-
- wnoutrefresh (dialog);
- wrefresh (menu);
-
- continue; /* wait for another key press */
- }
-
- switch (key) {
- case KEY_LEFT:
- case TAB:
- case KEY_RIGHT:
- button = ((key == KEY_LEFT ? --button : ++button) < 0)
- ? 2 : (button > 2 ? 0 : button);
-
- print_buttons(dialog, height, width, button);
- wrefresh (menu);
- break;
- case ' ':
- case 's':
- case 'y':
- case 'n':
- case 'm':
- case '/':
- /* save scroll info */
- if ( (f=fopen("lxdialog.scrltmp","w")) != NULL ) {
- fprintf(f,"%d\n",scroll);
- fclose(f);
- }
- delwin (dialog);
- items[scroll + choice]->selected = 1;
- switch (key) {
- case 's': return 3;
- case 'y': return 3;
- case 'n': return 4;
- case 'm': return 5;
- case ' ': return 6;
- case '/': return 7;
- }
- return 0;
- case 'h':
- case '?':
- button = 2;
- case '\n':
- delwin (dialog);
- items[scroll + choice]->selected = 1;
-
- remove("lxdialog.scrltmp");
- return button;
- case 'e':
- case 'x':
- key = ESC;
- case ESC:
- break;
+ switch (key) {
+ case KEY_LEFT:
+ case TAB:
+ case KEY_RIGHT:
+ button = ((key == KEY_LEFT ? --button : ++button) < 0)
+ ? 2 : (button > 2 ? 0 : button);
+
+ print_buttons(dialog, height, width, button);
+ wrefresh(menu);
+ break;
+ case ' ':
+ case 's':
+ case 'y':
+ case 'n':
+ case 'm':
+ case '/':
+ /* save scroll info */
+ *s_scroll = scroll;
+ delwin(menu);
+ delwin(dialog);
+ item_set(scroll + choice);
+ item_set_selected(1);
+ switch (key) {
+ case 's':
+ return 3;
+ case 'y':
+ return 3;
+ case 'n':
+ return 4;
+ case 'm':
+ return 5;
+ case ' ':
+ return 6;
+ case '/':
+ return 7;
+ }
+ return 0;
+ case 'h':
+ case '?':
+ button = 2;
+ case '\n':
+ *s_scroll = scroll;
+ delwin(menu);
+ delwin(dialog);
+ item_set(scroll + choice);
+ item_set_selected(1);
+ return button;
+ case 'e':
+ case 'x':
+ key = KEY_ESC;
+ break;
+ case KEY_ESC:
+ key = on_key_esc(menu);
+ break;
+ case KEY_RESIZE:
+ on_key_resize();
+ delwin(menu);
+ delwin(dialog);
+ goto do_resize;
+ }
}
- }
-
- delwin (dialog);
- remove("lxdialog.scrltmp");
- return -1; /* ESC pressed */
+ delwin(menu);
+ delwin(dialog);
+ return key; /* ESC pressed */
}
diff --git a/package/config/lxdialog/textbox.c b/package/config/lxdialog/textbox.c
index a5a460b5c..fabfc1ad7 100644
--- a/package/config/lxdialog/textbox.c
+++ b/package/config/lxdialog/textbox.c
@@ -21,463 +21,324 @@
#include "dialog.h"
-static void back_lines (int n);
-static void print_page (WINDOW * win, int height, int width);
-static void print_line (WINDOW * win, int row, int width);
-static char *get_line (void);
-static void print_position (WINDOW * win, int height, int width);
+static void back_lines(int n);
+static void print_page(WINDOW * win, int height, int width);
+static void print_line(WINDOW * win, int row, int width);
+static char *get_line(void);
+static void print_position(WINDOW * win);
+
+static int hscroll;
+static int begin_reached, end_reached, page_length;
+static const char *buf;
+static const char *page;
+
+/*
+ * refresh window content
+ */
+static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw,
+ int cur_y, int cur_x)
+{
+ print_page(box, boxh, boxw);
+ print_position(dialog);
+ wmove(dialog, cur_y, cur_x); /* Restore cursor position */
+ wrefresh(dialog);
+}
-static int hscroll, fd, file_size, bytes_read;
-static int begin_reached = 1, end_reached, page_length;
-static char *buf, *page;
/*
* Display text from a file in a dialog box.
*/
-int
-dialog_textbox (const char *title, const char *file, int height, int width)
+int dialog_textbox(const char *title, const char *tbuf,
+ int initial_height, int initial_width)
{
- int i, x, y, cur_x, cur_y, fpos, key = 0;
- int passed_end;
- char search_term[MAX_LEN + 1];
- WINDOW *dialog, *text;
-
- search_term[0] = '\0'; /* no search term entered yet */
-
- /* Open input file for reading */
- if ((fd = open (file, O_RDONLY)) == -1) {
- endwin ();
- fprintf (stderr,
- "\nCan't open input file in dialog_textbox().\n");
- exit (-1);
- }
- /* Get file size. Actually, 'file_size' is the real file size - 1,
- since it's only the last byte offset from the beginning */
- if ((file_size = lseek (fd, 0, SEEK_END)) == -1) {
- endwin ();
- fprintf (stderr, "\nError getting file size in dialog_textbox().\n");
- exit (-1);
- }
- /* Restore file pointer to beginning of file after getting file size */
- if (lseek (fd, 0, SEEK_SET) == -1) {
- endwin ();
- fprintf (stderr, "\nError moving file pointer in dialog_textbox().\n");
- exit (-1);
- }
- /* Allocate space for read buffer */
- if ((buf = malloc (BUF_SIZE + 1)) == NULL) {
- endwin ();
- fprintf (stderr, "\nCan't allocate memory in dialog_textbox().\n");
- exit (-1);
- }
- if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) {
- endwin ();
- fprintf (stderr, "\nError reading file in dialog_textbox().\n");
- exit (-1);
- }
- buf[bytes_read] = '\0'; /* mark end of valid data */
- page = buf; /* page is pointer to start of page to be displayed */
-
- /* center dialog box on screen */
- x = (COLS - width) / 2;
- y = (LINES - height) / 2;
-
-
- draw_shadow (stdscr, y, x, height, width);
-
- dialog = newwin (height, width, y, x);
- keypad (dialog, TRUE);
-
- /* Create window for text region, used for scrolling text */
- text = subwin (dialog, height - 4, width - 2, y + 1, x + 1);
- wattrset (text, dialog_attr);
- wbkgdset (text, dialog_attr & A_COLOR);
-
- keypad (text, TRUE);
-
- /* register the new window, along with its borders */
- draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr);
-
- wattrset (dialog, border_attr);
- mvwaddch (dialog, height-3, 0, ACS_LTEE);
- for (i = 0; i < width - 2; i++)
- waddch (dialog, ACS_HLINE);
- wattrset (dialog, dialog_attr);
- wbkgdset (dialog, dialog_attr & A_COLOR);
- waddch (dialog, ACS_RTEE);
-
- if (title != NULL && strlen(title) >= width-2 ) {
- /* truncate long title -- mec */
- char * title2 = malloc(width-2+1);
- memcpy( title2, title, width-2 );
- title2[width-2] = '\0';
- title = title2;
- }
-
- if (title != NULL) {
- wattrset (dialog, title_attr);
- mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' ');
- waddstr (dialog, (char *)title);
- waddch (dialog, ' ');
- }
- print_button (dialog, " Exit ", height - 2, width / 2 - 4, TRUE);
- wnoutrefresh (dialog);
- getyx (dialog, cur_y, cur_x); /* Save cursor position */
-
- /* Print first page of text */
- attr_clear (text, height - 4, width - 2, dialog_attr);
- print_page (text, height - 4, width - 2);
- print_position (dialog, height, width);
- wmove (dialog, cur_y, cur_x); /* Restore cursor position */
- wrefresh (dialog);
-
- while ((key != ESC) && (key != '\n')) {
- key = wgetch (dialog);
- switch (key) {
- case 'E': /* Exit */
- case 'e':
- case 'X':
- case 'x':
- delwin (dialog);
- free (buf);
- close (fd);
- return 0;
- case 'g': /* First page */
- case KEY_HOME:
- if (!begin_reached) {
- begin_reached = 1;
- /* First page not in buffer? */
- if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) {
- endwin ();
- fprintf (stderr,
- "\nError moving file pointer in dialog_textbox().\n");
- exit (-1);
- }
- if (fpos > bytes_read) { /* Yes, we have to read it in */
- if (lseek (fd, 0, SEEK_SET) == -1) {
- endwin ();
- fprintf (stderr, "\nError moving file pointer in "
- "dialog_textbox().\n");
- exit (-1);
- }
- if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) {
- endwin ();
- fprintf (stderr,
- "\nError reading file in dialog_textbox().\n");
- exit (-1);
- }
- buf[bytes_read] = '\0';
- }
- page = buf;
- print_page (text, height - 4, width - 2);
- print_position (dialog, height, width);
- wmove (dialog, cur_y, cur_x); /* Restore cursor position */
- wrefresh (dialog);
- }
- break;
- case 'G': /* Last page */
- case KEY_END:
-
- end_reached = 1;
- /* Last page not in buffer? */
- if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) {
- endwin ();
- fprintf (stderr,
- "\nError moving file pointer in dialog_textbox().\n");
- exit (-1);
- }
- if (fpos < file_size) { /* Yes, we have to read it in */
- if (lseek (fd, -BUF_SIZE, SEEK_END) == -1) {
- endwin ();
- fprintf (stderr,
- "\nError moving file pointer in dialog_textbox().\n");
- exit (-1);
- }
- if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) {
- endwin ();
- fprintf (stderr,
- "\nError reading file in dialog_textbox().\n");
- exit (-1);
- }
- buf[bytes_read] = '\0';
- }
- page = buf + bytes_read;
- back_lines (height - 4);
- print_page (text, height - 4, width - 2);
- print_position (dialog, height, width);
- wmove (dialog, cur_y, cur_x); /* Restore cursor position */
- wrefresh (dialog);
- break;
- case 'K': /* Previous line */
- case 'k':
- case KEY_UP:
- if (!begin_reached) {
- back_lines (page_length + 1);
-
- /* We don't call print_page() here but use scrolling to ensure
- faster screen update. However, 'end_reached' and
- 'page_length' should still be updated, and 'page' should
- point to start of next page. This is done by calling
- get_line() in the following 'for' loop. */
- scrollok (text, TRUE);
- wscrl (text, -1); /* Scroll text region down one line */
- scrollok (text, FALSE);
- page_length = 0;
- passed_end = 0;
- for (i = 0; i < height - 4; i++) {
- if (!i) {
- /* print first line of page */
- print_line (text, 0, width - 2);
- wnoutrefresh (text);
- } else
- /* Called to update 'end_reached' and 'page' */
- get_line ();
- if (!passed_end)
- page_length++;
- if (end_reached && !passed_end)
- passed_end = 1;
+ int i, x, y, cur_x, cur_y, key = 0;
+ int height, width, boxh, boxw;
+ int passed_end;
+ WINDOW *dialog, *box;
+
+ begin_reached = 1;
+ end_reached = 0;
+ page_length = 0;
+ hscroll = 0;
+ buf = tbuf;
+ page = buf; /* page is pointer to start of page to be displayed */
+
+do_resize:
+ getmaxyx(stdscr, height, width);
+ if (height < 8 || width < 8)
+ return -ERRDISPLAYTOOSMALL;
+ if (initial_height != 0)
+ height = initial_height;
+ else
+ if (height > 4)
+ height -= 4;
+ else
+ height = 0;
+ if (initial_width != 0)
+ width = initial_width;
+ else
+ if (width > 5)
+ width -= 5;
+ else
+ width = 0;
+
+ /* center dialog box on screen */
+ x = (COLS - width) / 2;
+ y = (LINES - height) / 2;
+
+ draw_shadow(stdscr, y, x, height, width);
+
+ dialog = newwin(height, width, y, x);
+ keypad(dialog, TRUE);
+
+ /* Create window for box region, used for scrolling text */
+ boxh = height - 4;
+ boxw = width - 2;
+ box = subwin(dialog, boxh, boxw, y + 1, x + 1);
+ wattrset(box, dlg.dialog.atr);
+ wbkgdset(box, dlg.dialog.atr & A_COLOR);
+
+ keypad(box, TRUE);
+
+ /* register the new window, along with its borders */
+ draw_box(dialog, 0, 0, height, width,
+ dlg.dialog.atr, dlg.border.atr);
+
+ wattrset(dialog, dlg.border.atr);
+ mvwaddch(dialog, height - 3, 0, ACS_LTEE);
+ for (i = 0; i < width - 2; i++)
+ waddch(dialog, ACS_HLINE);
+ wattrset(dialog, dlg.dialog.atr);
+ wbkgdset(dialog, dlg.dialog.atr & A_COLOR);
+ waddch(dialog, ACS_RTEE);
+
+ print_title(dialog, title, width);
+
+ print_button(dialog, " Exit ", height - 2, width / 2 - 4, TRUE);
+ wnoutrefresh(dialog);
+ getyx(dialog, cur_y, cur_x); /* Save cursor position */
+
+ /* Print first page of text */
+ attr_clear(box, boxh, boxw, dlg.dialog.atr);
+ refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);
+
+ while ((key != KEY_ESC) && (key != '\n')) {
+ key = wgetch(dialog);
+ switch (key) {
+ case 'E': /* Exit */
+ case 'e':
+ case 'X':
+ case 'x':
+ delwin(box);
+ delwin(dialog);
+ return 0;
+ case 'g': /* First page */
+ case KEY_HOME:
+ if (!begin_reached) {
+ begin_reached = 1;
+ page = buf;
+ refresh_text_box(dialog, box, boxh, boxw,
+ cur_y, cur_x);
+ }
+ break;
+ case 'G': /* Last page */
+ case KEY_END:
+
+ end_reached = 1;
+ /* point to last char in buf */
+ page = buf + strlen(buf);
+ back_lines(boxh);
+ refresh_text_box(dialog, box, boxh, boxw,
+ cur_y, cur_x);
+ break;
+ case 'K': /* Previous line */
+ case 'k':
+ case KEY_UP:
+ if (!begin_reached) {
+ back_lines(page_length + 1);
+
+ /* We don't call print_page() here but use
+ * scrolling to ensure faster screen update.
+ * However, 'end_reached' and 'page_length'
+ * should still be updated, and 'page' should
+ * point to start of next page. This is done
+ * by calling get_line() in the following
+ * 'for' loop. */
+ scrollok(box, TRUE);
+ wscrl(box, -1); /* Scroll box region down one line */
+ scrollok(box, FALSE);
+ page_length = 0;
+ passed_end = 0;
+ for (i = 0; i < boxh; i++) {
+ if (!i) {
+ /* print first line of page */
+ print_line(box, 0, boxw);
+ wnoutrefresh(box);
+ } else
+ /* Called to update 'end_reached' and 'page' */
+ get_line();
+ if (!passed_end)
+ page_length++;
+ if (end_reached && !passed_end)
+ passed_end = 1;
+ }
+
+ print_position(dialog);
+ wmove(dialog, cur_y, cur_x); /* Restore cursor position */
+ wrefresh(dialog);
+ }
+ break;
+ case 'B': /* Previous page */
+ case 'b':
+ case KEY_PPAGE:
+ if (begin_reached)
+ break;
+ back_lines(page_length + boxh);
+ refresh_text_box(dialog, box, boxh, boxw,
+ cur_y, cur_x);
+ break;
+ case 'J': /* Next line */
+ case 'j':
+ case KEY_DOWN:
+ if (!end_reached) {
+ begin_reached = 0;
+ scrollok(box, TRUE);
+ scroll(box); /* Scroll box region up one line */
+ scrollok(box, FALSE);
+ print_line(box, boxh - 1, boxw);
+ wnoutrefresh(box);
+ print_position(dialog);
+ wmove(dialog, cur_y, cur_x); /* Restore cursor position */
+ wrefresh(dialog);
+ }
+ break;
+ case KEY_NPAGE: /* Next page */
+ case ' ':
+ if (end_reached)
+ break;
+
+ begin_reached = 0;
+ refresh_text_box(dialog, box, boxh, boxw,
+ cur_y, cur_x);
+ break;
+ case '0': /* Beginning of line */
+ case 'H': /* Scroll left */
+ case 'h':
+ case KEY_LEFT:
+ if (hscroll <= 0)
+ break;
+
+ if (key == '0')
+ hscroll = 0;
+ else
+ hscroll--;
+ /* Reprint current page to scroll horizontally */
+ back_lines(page_length);
+ refresh_text_box(dialog, box, boxh, boxw,
+ cur_y, cur_x);
+ break;
+ case 'L': /* Scroll right */
+ case 'l':
+ case KEY_RIGHT:
+ if (hscroll >= MAX_LEN)
+ break;
+ hscroll++;
+ /* Reprint current page to scroll horizontally */
+ back_lines(page_length);
+ refresh_text_box(dialog, box, boxh, boxw,
+ cur_y, cur_x);
+ break;
+ case KEY_ESC:
+ key = on_key_esc(dialog);
+ break;
+ case KEY_RESIZE:
+ back_lines(height);
+ delwin(box);
+ delwin(dialog);
+ on_key_resize();
+ goto do_resize;
}
-
- print_position (dialog, height, width);
- wmove (dialog, cur_y, cur_x); /* Restore cursor position */
- wrefresh (dialog);
- }
- break;
- case 'B': /* Previous page */
- case 'b':
- case KEY_PPAGE:
- if (begin_reached)
- break;
- back_lines (page_length + height - 4);
- print_page (text, height - 4, width - 2);
- print_position (dialog, height, width);
- wmove (dialog, cur_y, cur_x);
- wrefresh (dialog);
- break;
- case 'J': /* Next line */
- case 'j':
- case KEY_DOWN:
- if (!end_reached) {
- begin_reached = 0;
- scrollok (text, TRUE);
- scroll (text); /* Scroll text region up one line */
- scrollok (text, FALSE);
- print_line (text, height - 5, width - 2);
- wnoutrefresh (text);
- print_position (dialog, height, width);
- wmove (dialog, cur_y, cur_x); /* Restore cursor position */
- wrefresh (dialog);
- }
- break;
- case KEY_NPAGE: /* Next page */
- case ' ':
- if (end_reached)
- break;
-
- begin_reached = 0;
- print_page (text, height - 4, width - 2);
- print_position (dialog, height, width);
- wmove (dialog, cur_y, cur_x);
- wrefresh (dialog);
- break;
- case '0': /* Beginning of line */
- case 'H': /* Scroll left */
- case 'h':
- case KEY_LEFT:
- if (hscroll <= 0)
- break;
-
- if (key == '0')
- hscroll = 0;
- else
- hscroll--;
- /* Reprint current page to scroll horizontally */
- back_lines (page_length);
- print_page (text, height - 4, width - 2);
- wmove (dialog, cur_y, cur_x);
- wrefresh (dialog);
- break;
- case 'L': /* Scroll right */
- case 'l':
- case KEY_RIGHT:
- if (hscroll >= MAX_LEN)
- break;
- hscroll++;
- /* Reprint current page to scroll horizontally */
- back_lines (page_length);
- print_page (text, height - 4, width - 2);
- wmove (dialog, cur_y, cur_x);
- wrefresh (dialog);
- break;
- case ESC:
- break;
}
- }
-
- delwin (dialog);
- free (buf);
- close (fd);
- return 1; /* ESC pressed */
+ delwin(box);
+ delwin(dialog);
+ return key; /* ESC pressed */
}
/*
- * Go back 'n' lines in text file. Called by dialog_textbox().
+ * Go back 'n' lines in text. Called by dialog_textbox().
* 'page' will be updated to point to the desired line in 'buf'.
*/
-static void
-back_lines (int n)
+static void back_lines(int n)
{
- int i, fpos;
-
- begin_reached = 0;
- /* We have to distinguish between end_reached and !end_reached
- since at end of file, the line is not ended by a '\n'.
- The code inside 'if' basically does a '--page' to move one
- character backward so as to skip '\n' of the previous line */
- if (!end_reached) {
- /* Either beginning of buffer or beginning of file reached? */
- if (page == buf) {
- if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) {
- endwin ();
- fprintf (stderr, "\nError moving file pointer in "
- "back_lines().\n");
- exit (-1);
- }
- if (fpos > bytes_read) { /* Not beginning of file yet */
- /* We've reached beginning of buffer, but not beginning of
- file yet, so read previous part of file into buffer.
- Note that we only move backward for BUF_SIZE/2 bytes,
- but not BUF_SIZE bytes to avoid re-reading again in
- print_page() later */
- /* Really possible to move backward BUF_SIZE/2 bytes? */
- if (fpos < BUF_SIZE / 2 + bytes_read) {
- /* No, move less then */
- if (lseek (fd, 0, SEEK_SET) == -1) {
- endwin ();
- fprintf (stderr, "\nError moving file pointer in "
- "back_lines().\n");
- exit (-1);
- }
- page = buf + fpos - bytes_read;
- } else { /* Move backward BUF_SIZE/2 bytes */
- if (lseek (fd, -(BUF_SIZE / 2 + bytes_read), SEEK_CUR)
- == -1) {
- endwin ();
- fprintf (stderr, "\nError moving file pointer "
- "in back_lines().\n");
- exit (-1);
- }
- page = buf + BUF_SIZE / 2;
- }
- if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) {
- endwin ();
- fprintf (stderr, "\nError reading file in back_lines().\n");
- exit (-1);
+ int i;
+
+ begin_reached = 0;
+ /* Go back 'n' lines */
+ for (i = 0; i < n; i++) {
+ if (*page == '\0') {
+ if (end_reached) {
+ end_reached = 0;
+ continue;
+ }
}
- buf[bytes_read] = '\0';
- } else { /* Beginning of file reached */
- begin_reached = 1;
- return;
- }
- }
- if (*(--page) != '\n') { /* '--page' here */
- /* Something's wrong... */
- endwin ();
- fprintf (stderr, "\nInternal error in back_lines().\n");
- exit (-1);
- }
- }
- /* Go back 'n' lines */
- for (i = 0; i < n; i++)
- do {
- if (page == buf) {
- if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) {
- endwin ();
- fprintf (stderr,
- "\nError moving file pointer in back_lines().\n");
- exit (-1);
+ if (page == buf) {
+ begin_reached = 1;
+ return;
}
- if (fpos > bytes_read) {
- /* Really possible to move backward BUF_SIZE/2 bytes? */
- if (fpos < BUF_SIZE / 2 + bytes_read) {
- /* No, move less then */
- if (lseek (fd, 0, SEEK_SET) == -1) {
- endwin ();
- fprintf (stderr, "\nError moving file pointer "
- "in back_lines().\n");
- exit (-1);
- }
- page = buf + fpos - bytes_read;
- } else { /* Move backward BUF_SIZE/2 bytes */
- if (lseek (fd, -(BUF_SIZE / 2 + bytes_read),
- SEEK_CUR) == -1) {
- endwin ();
- fprintf (stderr, "\nError moving file pointer"
- " in back_lines().\n");
- exit (-1);
+ page--;
+ do {
+ if (page == buf) {
+ begin_reached = 1;
+ return;
}
- page = buf + BUF_SIZE / 2;
- }
- if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) {
- endwin ();
- fprintf (stderr, "\nError reading file in "
- "back_lines().\n");
- exit (-1);
- }
- buf[bytes_read] = '\0';
- } else { /* Beginning of file reached */
- begin_reached = 1;
- return;
- }
- }
- } while (*(--page) != '\n');
- page++;
+ page--;
+ } while (*page != '\n');
+ page++;
+ }
}
/*
* Print a new page of text. Called by dialog_textbox().
*/
-static void
-print_page (WINDOW * win, int height, int width)
+static void print_page(WINDOW * win, int height, int width)
{
- int i, passed_end = 0;
-
- page_length = 0;
- for (i = 0; i < height; i++) {
- print_line (win, i, width);
- if (!passed_end)
- page_length++;
- if (end_reached && !passed_end)
- passed_end = 1;
- }
- wnoutrefresh (win);
+ int i, passed_end = 0;
+
+ page_length = 0;
+ for (i = 0; i < height; i++) {
+ print_line(win, i, width);
+ if (!passed_end)
+ page_length++;
+ if (end_reached && !passed_end)
+ passed_end = 1;
+ }
+ wnoutrefresh(win);
}
/*
* Print a new line of text. Called by dialog_textbox() and print_page().
*/
-static void
-print_line (WINDOW * win, int row, int width)
+static void print_line(WINDOW * win, int row, int width)
{
- int y, x;
- char *line;
+ int y, x;
+ char *line;
- line = get_line ();
- line += MIN (strlen (line), hscroll); /* Scroll horizontally */
- wmove (win, row, 0); /* move cursor to correct line */
- waddch (win, ' ');
- waddnstr (win, line, MIN (strlen (line), width - 2));
+ line = get_line();
+ line += MIN(strlen(line), hscroll); /* Scroll horizontally */
+ wmove(win, row, 0); /* move cursor to correct line */
+ waddch(win, ' ');
+ waddnstr(win, line, MIN(strlen(line), width - 2));
- getyx (win, y, x);
- /* Clear 'residue' of previous line */
+ getyx(win, y, x);
+ /* Clear 'residue' of previous line */
#if OLD_NCURSES
- {
- int i;
- for (i = 0; i < width - x; i++)
- waddch (win, ' ');
- }
+ {
+ int i;
+ for (i = 0; i < width - x; i++)
+ waddch(win, ' ');
+ }
#else
- wclrtoeol(win);
+ wclrtoeol(win);
#endif
}
@@ -486,71 +347,45 @@ print_line (WINDOW * win, int row, int width)
* 'page' should point to start of current line before calling, and will be
* updated to point to start of next line.
*/
-static char *
-get_line (void)
+static char *get_line(void)
{
- int i = 0, fpos;
- static char line[MAX_LEN + 1];
-
- end_reached = 0;
- while (*page != '\n') {
- if (*page == '\0') {
- /* Either end of file or end of buffer reached */
- if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) {
- endwin ();
- fprintf (stderr, "\nError moving file pointer in "
- "get_line().\n");
- exit (-1);
- }
- if (fpos < file_size) { /* Not end of file yet */
- /* We've reached end of buffer, but not end of file yet,
- so read next part of file into buffer */
- if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) {
- endwin ();
- fprintf (stderr, "\nError reading file in get_line().\n");
- exit (-1);
+ int i = 0;
+ static char line[MAX_LEN + 1];
+
+ end_reached = 0;
+ while (*page != '\n') {
+ if (*page == '\0') {
+ if (!end_reached) {
+ end_reached = 1;
+ break;
+ }
+ } else if (i < MAX_LEN)
+ line[i++] = *(page++);
+ else {
+ /* Truncate lines longer than MAX_LEN characters */
+ if (i == MAX_LEN)
+ line[i++] = '\0';
+ page++;
}
- buf[bytes_read] = '\0';
- page = buf;
- } else {
- if (!end_reached)
- end_reached = 1;
- break;
- }
- } else if (i < MAX_LEN)
- line[i++] = *(page++);
- else {
- /* Truncate lines longer than MAX_LEN characters */
- if (i == MAX_LEN)
- line[i++] = '\0';
- page++;
}
- }
- if (i <= MAX_LEN)
- line[i] = '\0';
- if (!end_reached)
- page++; /* move pass '\n' */
+ if (i <= MAX_LEN)
+ line[i] = '\0';
+ if (!end_reached)
+ page++; /* move pass '\n' */
- return line;
+ return line;
}
/*
* Print current position
*/
-static void
-print_position (WINDOW * win, int height, int width)
+static void print_position(WINDOW * win)
{
- int fpos, percent;
-
- if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) {
- endwin ();
- fprintf (stderr, "\nError moving file pointer in print_position().\n");
- exit (-1);
- }
- wattrset (win, position_indicator_attr);
- wbkgdset (win, position_indicator_attr & A_COLOR);
- percent = !file_size ?
- 100 : ((fpos - bytes_read + page - buf) * 100) / file_size;
- wmove (win, height - 3, width - 9);
- wprintw (win, "(%3d%%)", percent);
+ int percent;
+
+ wattrset(win, dlg.position_indicator.atr);
+ wbkgdset(win, dlg.position_indicator.atr & A_COLOR);
+ percent = (page - buf) * 100 / strlen(buf);
+ wmove(win, getmaxy(win) - 3, getmaxx(win) - 9);
+ wprintw(win, "(%3d%%)", percent);
}
diff --git a/package/config/lxdialog/util.c b/package/config/lxdialog/util.c
index 6f83951b9..d54440fc1 100644
--- a/package/config/lxdialog/util.c
+++ b/package/config/lxdialog/util.c
@@ -21,172 +21,287 @@
#include "dialog.h"
+struct dialog_info dlg;
-/* use colors by default? */
-bool use_colors = 1;
+static void set_mono_theme(void)
+{
+ dlg.screen.atr = A_NORMAL;
+ dlg.shadow.atr = A_NORMAL;
+ dlg.dialog.atr = A_NORMAL;
+ dlg.title.atr = A_BOLD;
+ dlg.border.atr = A_NORMAL;
+ dlg.button_active.atr = A_REVERSE;
+ dlg.button_inactive.atr = A_DIM;
+ dlg.button_key_active.atr = A_REVERSE;
+ dlg.button_key_inactive.atr = A_BOLD;
+ dlg.button_label_active.atr = A_REVERSE;
+ dlg.button_label_inactive.atr = A_NORMAL;
+ dlg.inputbox.atr = A_NORMAL;
+ dlg.inputbox_border.atr = A_NORMAL;
+ dlg.searchbox.atr = A_NORMAL;
+ dlg.searchbox_title.atr = A_BOLD;
+ dlg.searchbox_border.atr = A_NORMAL;
+ dlg.position_indicator.atr = A_BOLD;
+ dlg.menubox.atr = A_NORMAL;
+ dlg.menubox_border.atr = A_NORMAL;
+ dlg.item.atr = A_NORMAL;
+ dlg.item_selected.atr = A_REVERSE;
+ dlg.tag.atr = A_BOLD;
+ dlg.tag_selected.atr = A_REVERSE;
+ dlg.tag_key.atr = A_BOLD;
+ dlg.tag_key_selected.atr = A_REVERSE;
+ dlg.check.atr = A_BOLD;
+ dlg.check_selected.atr = A_REVERSE;
+ dlg.uarrow.atr = A_BOLD;
+ dlg.darrow.atr = A_BOLD;
+}
-const char *backtitle = NULL;
+#define DLG_COLOR(dialog, f, b, h) \
+do { \
+ dlg.dialog.fg = (f); \
+ dlg.dialog.bg = (b); \
+ dlg.dialog.hl = (h); \
+} while (0)
-const char *dialog_result;
+static void set_classic_theme(void)
+{
+ DLG_COLOR(screen, COLOR_CYAN, COLOR_BLUE, true);
+ DLG_COLOR(shadow, COLOR_BLACK, COLOR_BLACK, true);
+ DLG_COLOR(dialog, COLOR_BLACK, COLOR_WHITE, false);
+ DLG_COLOR(title, COLOR_YELLOW, COLOR_WHITE, true);
+ DLG_COLOR(border, COLOR_WHITE, COLOR_WHITE, true);
+ DLG_COLOR(button_active, COLOR_WHITE, COLOR_BLUE, true);
+ DLG_COLOR(button_inactive, COLOR_BLACK, COLOR_WHITE, false);
+ DLG_COLOR(button_key_active, COLOR_WHITE, COLOR_BLUE, true);
+ DLG_COLOR(button_key_inactive, COLOR_RED, COLOR_WHITE, false);
+ DLG_COLOR(button_label_active, COLOR_YELLOW, COLOR_BLUE, true);
+ DLG_COLOR(button_label_inactive, COLOR_BLACK, COLOR_WHITE, true);
+ DLG_COLOR(inputbox, COLOR_BLACK, COLOR_WHITE, false);
+ DLG_COLOR(inputbox_border, COLOR_BLACK, COLOR_WHITE, false);
+ DLG_COLOR(searchbox, COLOR_BLACK, COLOR_WHITE, false);
+ DLG_COLOR(searchbox_title, COLOR_YELLOW, COLOR_WHITE, true);
+ DLG_COLOR(searchbox_border, COLOR_WHITE, COLOR_WHITE, true);
+ DLG_COLOR(position_indicator, COLOR_YELLOW, COLOR_WHITE, true);
+ DLG_COLOR(menubox, COLOR_BLACK, COLOR_WHITE, false);
+ DLG_COLOR(menubox_border, COLOR_WHITE, COLOR_WHITE, true);
+ DLG_COLOR(item, COLOR_BLACK, COLOR_WHITE, false);
+ DLG_COLOR(item_selected, COLOR_WHITE, COLOR_BLUE, true);
+ DLG_COLOR(tag, COLOR_YELLOW, COLOR_WHITE, true);
+ DLG_COLOR(tag_selected, COLOR_YELLOW, COLOR_BLUE, true);
+ DLG_COLOR(tag_key, COLOR_YELLOW, COLOR_WHITE, true);
+ DLG_COLOR(tag_key_selected, COLOR_YELLOW, COLOR_BLUE, true);
+ DLG_COLOR(check, COLOR_BLACK, COLOR_WHITE, false);
+ DLG_COLOR(check_selected, COLOR_WHITE, COLOR_BLUE, true);
+ DLG_COLOR(uarrow, COLOR_GREEN, COLOR_WHITE, true);
+ DLG_COLOR(darrow, COLOR_GREEN, COLOR_WHITE, true);
+}
-/*
- * Attribute values, default is for mono display
- */
-chtype attributes[] =
-{
- A_NORMAL, /* screen_attr */
- A_NORMAL, /* shadow_attr */
- A_NORMAL, /* dialog_attr */
- A_BOLD, /* title_attr */
- A_NORMAL, /* border_attr */
- A_REVERSE, /* button_active_attr */
- A_DIM, /* button_inactive_attr */
- A_REVERSE, /* button_key_active_attr */
- A_BOLD, /* button_key_inactive_attr */
- A_REVERSE, /* button_label_active_attr */
- A_NORMAL, /* button_label_inactive_attr */
- A_NORMAL, /* inputbox_attr */
- A_NORMAL, /* inputbox_border_attr */
- A_NORMAL, /* searchbox_attr */
- A_BOLD, /* searchbox_title_attr */
- A_NORMAL, /* searchbox_border_attr */
- A_BOLD, /* position_indicator_attr */
- A_NORMAL, /* menubox_attr */
- A_NORMAL, /* menubox_border_attr */
- A_NORMAL, /* item_attr */
- A_REVERSE, /* item_selected_attr */
- A_BOLD, /* tag_attr */
- A_REVERSE, /* tag_selected_attr */
- A_BOLD, /* tag_key_attr */
- A_REVERSE, /* tag_key_selected_attr */
- A_BOLD, /* check_attr */
- A_REVERSE, /* check_selected_attr */
- A_BOLD, /* uarrow_attr */
- A_BOLD /* darrow_attr */
-};
-
-
-#include "colors.h"
+static void set_blackbg_theme(void)
+{
+ DLG_COLOR(screen, COLOR_RED, COLOR_BLACK, true);
+ DLG_COLOR(shadow, COLOR_BLACK, COLOR_BLACK, false);
+ DLG_COLOR(dialog, COLOR_WHITE, COLOR_BLACK, false);
+ DLG_COLOR(title, COLOR_RED, COLOR_BLACK, false);
+ DLG_COLOR(border, COLOR_BLACK, COLOR_BLACK, true);
-/*
- * Table of color values
- */
-int color_table[][3] =
-{
- {SCREEN_FG, SCREEN_BG, SCREEN_HL},
- {SHADOW_FG, SHADOW_BG, SHADOW_HL},
- {DIALOG_FG, DIALOG_BG, DIALOG_HL},
- {TITLE_FG, TITLE_BG, TITLE_HL},
- {BORDER_FG, BORDER_BG, BORDER_HL},
- {BUTTON_ACTIVE_FG, BUTTON_ACTIVE_BG, BUTTON_ACTIVE_HL},
- {BUTTON_INACTIVE_FG, BUTTON_INACTIVE_BG, BUTTON_INACTIVE_HL},
- {BUTTON_KEY_ACTIVE_FG, BUTTON_KEY_ACTIVE_BG, BUTTON_KEY_ACTIVE_HL},
- {BUTTON_KEY_INACTIVE_FG, BUTTON_KEY_INACTIVE_BG, BUTTON_KEY_INACTIVE_HL},
- {BUTTON_LABEL_ACTIVE_FG, BUTTON_LABEL_ACTIVE_BG, BUTTON_LABEL_ACTIVE_HL},
- {BUTTON_LABEL_INACTIVE_FG, BUTTON_LABEL_INACTIVE_BG,
- BUTTON_LABEL_INACTIVE_HL},
- {INPUTBOX_FG, INPUTBOX_BG, INPUTBOX_HL},
- {INPUTBOX_BORDER_FG, INPUTBOX_BORDER_BG, INPUTBOX_BORDER_HL},
- {SEARCHBOX_FG, SEARCHBOX_BG, SEARCHBOX_HL},
- {SEARCHBOX_TITLE_FG, SEARCHBOX_TITLE_BG, SEARCHBOX_TITLE_HL},
- {SEARCHBOX_BORDER_FG, SEARCHBOX_BORDER_BG, SEARCHBOX_BORDER_HL},
- {POSITION_INDICATOR_FG, POSITION_INDICATOR_BG, POSITION_INDICATOR_HL},
- {MENUBOX_FG, MENUBOX_BG, MENUBOX_HL},
- {MENUBOX_BORDER_FG, MENUBOX_BORDER_BG, MENUBOX_BORDER_HL},
- {ITEM_FG, ITEM_BG, ITEM_HL},
- {ITEM_SELECTED_FG, ITEM_SELECTED_BG, ITEM_SELECTED_HL},
- {TAG_FG, TAG_BG, TAG_HL},
- {TAG_SELECTED_FG, TAG_SELECTED_BG, TAG_SELECTED_HL},
- {TAG_KEY_FG, TAG_KEY_BG, TAG_KEY_HL},
- {TAG_KEY_SELECTED_FG, TAG_KEY_SELECTED_BG, TAG_KEY_SELECTED_HL},
- {CHECK_FG, CHECK_BG, CHECK_HL},
- {CHECK_SELECTED_FG, CHECK_SELECTED_BG, CHECK_SELECTED_HL},
- {UARROW_FG, UARROW_BG, UARROW_HL},
- {DARROW_FG, DARROW_BG, DARROW_HL},
-}; /* color_table */
+ DLG_COLOR(button_active, COLOR_YELLOW, COLOR_RED, false);
+ DLG_COLOR(button_inactive, COLOR_YELLOW, COLOR_BLACK, false);
+ DLG_COLOR(button_key_active, COLOR_YELLOW, COLOR_RED, true);
+ DLG_COLOR(button_key_inactive, COLOR_RED, COLOR_BLACK, false);
+ DLG_COLOR(button_label_active, COLOR_WHITE, COLOR_RED, false);
+ DLG_COLOR(button_label_inactive, COLOR_BLACK, COLOR_BLACK, true);
-/*
- * Set window to attribute 'attr'
- */
-void
-attr_clear (WINDOW * win, int height, int width, chtype attr)
-{
- int i, j;
+ DLG_COLOR(inputbox, COLOR_YELLOW, COLOR_BLACK, false);
+ DLG_COLOR(inputbox_border, COLOR_YELLOW, COLOR_BLACK, false);
+
+ DLG_COLOR(searchbox, COLOR_YELLOW, COLOR_BLACK, false);
+ DLG_COLOR(searchbox_title, COLOR_YELLOW, COLOR_BLACK, true);
+ DLG_COLOR(searchbox_border, COLOR_BLACK, COLOR_BLACK, true);
+
+ DLG_COLOR(position_indicator, COLOR_RED, COLOR_BLACK, false);
- wattrset (win, attr);
- for (i = 0; i < height; i++) {
- wmove (win, i, 0);
- for (j = 0; j < width; j++)
- waddch (win, ' ');
- }
- touchwin (win);
+ DLG_COLOR(menubox, COLOR_YELLOW, COLOR_BLACK, false);
+ DLG_COLOR(menubox_border, COLOR_BLACK, COLOR_BLACK, true);
+
+ DLG_COLOR(item, COLOR_WHITE, COLOR_BLACK, false);
+ DLG_COLOR(item_selected, COLOR_WHITE, COLOR_RED, false);
+
+ DLG_COLOR(tag, COLOR_RED, COLOR_BLACK, false);
+ DLG_COLOR(tag_selected, COLOR_YELLOW, COLOR_RED, true);
+ DLG_COLOR(tag_key, COLOR_RED, COLOR_BLACK, false);
+ DLG_COLOR(tag_key_selected, COLOR_YELLOW, COLOR_RED, true);
+
+ DLG_COLOR(check, COLOR_YELLOW, COLOR_BLACK, false);
+ DLG_COLOR(check_selected, COLOR_YELLOW, COLOR_RED, true);
+
+ DLG_COLOR(uarrow, COLOR_RED, COLOR_BLACK, false);
+ DLG_COLOR(darrow, COLOR_RED, COLOR_BLACK, false);
}
-void dialog_clear (void)
+static void set_bluetitle_theme(void)
{
- attr_clear (stdscr, LINES, COLS, screen_attr);
- /* Display background title if it exists ... - SLH */
- if (backtitle != NULL) {
- int i;
+ set_classic_theme();
+ DLG_COLOR(title, COLOR_BLUE, COLOR_WHITE, true);
+ DLG_COLOR(button_key_active, COLOR_YELLOW, COLOR_BLUE, true);
+ DLG_COLOR(button_label_active, COLOR_WHITE, COLOR_BLUE, true);
+ DLG_COLOR(searchbox_title, COLOR_BLUE, COLOR_WHITE, true);
+ DLG_COLOR(position_indicator, COLOR_BLUE, COLOR_WHITE, true);
+ DLG_COLOR(tag, COLOR_BLUE, COLOR_WHITE, true);
+ DLG_COLOR(tag_key, COLOR_BLUE, COLOR_WHITE, true);
- wattrset (stdscr, screen_attr);
- mvwaddstr (stdscr, 0, 1, (char *)backtitle);
- wmove (stdscr, 1, 1);
- for (i = 1; i < COLS - 1; i++)
- waddch (stdscr, ACS_HLINE);
- }
- wnoutrefresh (stdscr);
}
/*
- * Do some initialization for dialog
+ * Select color theme
*/
-void
-init_dialog (void)
+static int set_theme(const char *theme)
{
- initscr (); /* Init curses */
- keypad (stdscr, TRUE);
- cbreak ();
- noecho ();
-
-
- if (use_colors) /* Set up colors */
- color_setup ();
+ int use_color = 1;
+ if (!theme)
+ set_bluetitle_theme();
+ else if (strcmp(theme, "classic") == 0)
+ set_classic_theme();
+ else if (strcmp(theme, "bluetitle") == 0)
+ set_bluetitle_theme();
+ else if (strcmp(theme, "blackbg") == 0)
+ set_blackbg_theme();
+ else if (strcmp(theme, "mono") == 0)
+ use_color = 0;
+
+ return use_color;
+}
+static void init_one_color(struct dialog_color *color)
+{
+ static int pair = 0;
+
+ pair++;
+ init_pair(pair, color->fg, color->bg);
+ if (color->hl)
+ color->atr = A_BOLD | COLOR_PAIR(pair);
+ else
+ color->atr = COLOR_PAIR(pair);
+}
- dialog_clear ();
+static void init_dialog_colors(void)
+{
+ init_one_color(&dlg.screen);
+ init_one_color(&dlg.shadow);
+ init_one_color(&dlg.dialog);
+ init_one_color(&dlg.title);
+ init_one_color(&dlg.border);
+ init_one_color(&dlg.button_active);
+ init_one_color(&dlg.button_inactive);
+ init_one_color(&dlg.button_key_active);
+ init_one_color(&dlg.button_key_inactive);
+ init_one_color(&dlg.button_label_active);
+ init_one_color(&dlg.button_label_inactive);
+ init_one_color(&dlg.inputbox);
+ init_one_color(&dlg.inputbox_border);
+ init_one_color(&dlg.searchbox);
+ init_one_color(&dlg.searchbox_title);
+ init_one_color(&dlg.searchbox_border);
+ init_one_color(&dlg.position_indicator);
+ init_one_color(&dlg.menubox);
+ init_one_color(&dlg.menubox_border);
+ init_one_color(&dlg.item);
+ init_one_color(&dlg.item_selected);
+ init_one_color(&dlg.tag);
+ init_one_color(&dlg.tag_selected);
+ init_one_color(&dlg.tag_key);
+ init_one_color(&dlg.tag_key_selected);
+ init_one_color(&dlg.check);
+ init_one_color(&dlg.check_selected);
+ init_one_color(&dlg.uarrow);
+ init_one_color(&dlg.darrow);
}
/*
* Setup for color display
*/
-void
-color_setup (void)
+static void color_setup(const char *theme)
+{
+ int use_color;
+
+ use_color = set_theme(theme);
+ if (use_color && has_colors()) {
+ start_color();
+ init_dialog_colors();
+ } else
+ set_mono_theme();
+}
+
+/*
+ * Set window to attribute 'attr'
+ */
+void attr_clear(WINDOW * win, int height, int width, chtype attr)
{
- int i;
+ int i, j;
- if (has_colors ()) { /* Terminal supports color? */
- start_color ();
+ wattrset(win, attr);
+ for (i = 0; i < height; i++) {
+ wmove(win, i, 0);
+ for (j = 0; j < width; j++)
+ waddch(win, ' ');
+ }
+ touchwin(win);
+}
- /* Initialize color pairs */
- for (i = 0; i < ATTRIBUTE_COUNT; i++)
- init_pair (i + 1, color_table[i][0], color_table[i][1]);
+void dialog_clear(void)
+{
+ attr_clear(stdscr, LINES, COLS, dlg.screen.atr);
+ /* Display background title if it exists ... - SLH */
+ if (dlg.backtitle != NULL) {
+ int i;
+
+ wattrset(stdscr, dlg.screen.atr);
+ mvwaddstr(stdscr, 0, 1, (char *)dlg.backtitle);
+ wmove(stdscr, 1, 1);
+ for (i = 1; i < COLS - 1; i++)
+ waddch(stdscr, ACS_HLINE);
+ }
+ wnoutrefresh(stdscr);
+}
+
+/*
+ * Do some initialization for dialog
+ */
+void init_dialog(const char *backtitle)
+{
+ dlg.backtitle = backtitle;
+ color_setup(getenv("MENUCONFIG_COLOR"));
+}
- /* Setup color attributes */
- for (i = 0; i < ATTRIBUTE_COUNT; i++)
- attributes[i] = C_ATTR (color_table[i][2], i + 1);
- }
+void reset_dialog(void)
+{
+ initscr(); /* Init curses */
+ keypad(stdscr, TRUE);
+ cbreak();
+ noecho();
+ dialog_clear();
}
/*
* End using dialog functions.
*/
-void
-end_dialog (void)
+void end_dialog(void)
{
- endwin ();
+ endwin();
}
+/* Print the title of the dialog. Center the title and truncate
+ * tile if wider than dialog (- 2 chars).
+ **/
+void print_title(WINDOW *dialog, const char *title, int width)
+{
+ if (title) {
+ int tlen = MIN(width - 2, strlen(title));
+ wattrset(dialog, dlg.title.atr);
+ mvwaddch(dialog, 0, (width - tlen) / 2 - 1, ' ');
+ mvwaddnstr(dialog, 0, (width - tlen)/2, title, tlen);
+ waddch(dialog, ' ');
+ }
+}
/*
* Print a string of text in a window, automatically wrap around to the
@@ -194,164 +309,166 @@ end_dialog (void)
* characters '\n' are replaced by spaces. We start on a new line
* if there is no room for at least 4 nonblanks following a double-space.
*/
-void
-print_autowrap (WINDOW * win, const char *prompt, int width, int y, int x)
-{
- int newl, cur_x, cur_y;
- int i, prompt_len, room, wlen;
- char tempstr[MAX_LEN + 1], *word, *sp, *sp2;
-
- strcpy (tempstr, prompt);
-
- prompt_len = strlen(tempstr);
-
- /*
- * Remove newlines
- */
- for(i=0; i<prompt_len; i++) {
- if(tempstr[i] == '\n') tempstr[i] = ' ';
- }
-
- if (prompt_len <= width - x * 2) { /* If prompt is short */
- wmove (win, y, (width - prompt_len) / 2);
- waddstr (win, tempstr);
- } else {
- cur_x = x;
- cur_y = y;
- newl = 1;
- word = tempstr;
- while (word && *word) {
- sp = index(word, ' ');
- if (sp)
- *sp++ = 0;
-
- /* Wrap to next line if either the word does not fit,
- or it is the first word of a new sentence, and it is
- short, and the next word does not fit. */
- room = width - cur_x;
- wlen = strlen(word);
- if (wlen > room ||
- (newl && wlen < 4 && sp && wlen+1+strlen(sp) > room
- && (!(sp2 = index(sp, ' ')) || wlen+1+(sp2-sp) > room))) {
- cur_y++;
+void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x)
+{
+ int newl, cur_x, cur_y;
+ int i, prompt_len, room, wlen;
+ char tempstr[MAX_LEN + 1], *word, *sp, *sp2;
+
+ strcpy(tempstr, prompt);
+
+ prompt_len = strlen(tempstr);
+
+ /*
+ * Remove newlines
+ */
+ for (i = 0; i < prompt_len; i++) {
+ if (tempstr[i] == '\n')
+ tempstr[i] = ' ';
+ }
+
+ if (prompt_len <= width - x * 2) { /* If prompt is short */
+ wmove(win, y, (width - prompt_len) / 2);
+ waddstr(win, tempstr);
+ } else {
cur_x = x;
- }
- wmove (win, cur_y, cur_x);
- waddstr (win, word);
- getyx (win, cur_y, cur_x);
- cur_x++;
- if (sp && *sp == ' ') {
- cur_x++; /* double space */
- while (*++sp == ' ');
+ cur_y = y;
newl = 1;
- } else
- newl = 0;
- word = sp;
+ word = tempstr;
+ while (word && *word) {
+ sp = index(word, ' ');
+ if (sp)
+ *sp++ = 0;
+
+ /* Wrap to next line if either the word does not fit,
+ or it is the first word of a new sentence, and it is
+ short, and the next word does not fit. */
+ room = width - cur_x;
+ wlen = strlen(word);
+ if (wlen > room ||
+ (newl && wlen < 4 && sp
+ && wlen + 1 + strlen(sp) > room
+ && (!(sp2 = index(sp, ' '))
+ || wlen + 1 + (sp2 - sp) > room))) {
+ cur_y++;
+ cur_x = x;
+ }
+ wmove(win, cur_y, cur_x);
+ waddstr(win, word);
+ getyx(win, cur_y, cur_x);
+ cur_x++;
+ if (sp && *sp == ' ') {
+ cur_x++; /* double space */
+ while (*++sp == ' ') ;
+ newl = 1;
+ } else
+ newl = 0;
+ word = sp;
+ }
}
- }
}
/*
* Print a button
*/
-void
-print_button (WINDOW * win, const char *label, int y, int x, int selected)
-{
- int i, temp;
-
- wmove (win, y, x);
- wattrset (win, selected ? button_active_attr : button_inactive_attr);
- waddstr (win, "<");
- temp = strspn (label, " ");
- label += temp;
- wattrset (win, selected ? button_label_active_attr
- : button_label_inactive_attr);
- for (i = 0; i < temp; i++)
- waddch (win, ' ');
- wattrset (win, selected ? button_key_active_attr
- : button_key_inactive_attr);
- waddch (win, label[0]);
- wattrset (win, selected ? button_label_active_attr
- : button_label_inactive_attr);
- waddstr (win, (char *)label + 1);
- wattrset (win, selected ? button_active_attr : button_inactive_attr);
- waddstr (win, ">");
- wmove (win, y, x + temp + 1);
+void print_button(WINDOW * win, const char *label, int y, int x, int selected)
+{
+ int i, temp;
+
+ wmove(win, y, x);
+ wattrset(win, selected ? dlg.button_active.atr
+ : dlg.button_inactive.atr);
+ waddstr(win, "<");
+ temp = strspn(label, " ");
+ label += temp;
+ wattrset(win, selected ? dlg.button_label_active.atr
+ : dlg.button_label_inactive.atr);
+ for (i = 0; i < temp; i++)
+ waddch(win, ' ');
+ wattrset(win, selected ? dlg.button_key_active.atr
+ : dlg.button_key_inactive.atr);
+ waddch(win, label[0]);
+ wattrset(win, selected ? dlg.button_label_active.atr
+ : dlg.button_label_inactive.atr);
+ waddstr(win, (char *)label + 1);
+ wattrset(win, selected ? dlg.button_active.atr
+ : dlg.button_inactive.atr);
+ waddstr(win, ">");
+ wmove(win, y, x + temp + 1);
}
/*
* Draw a rectangular box with line drawing characters
*/
void
-draw_box (WINDOW * win, int y, int x, int height, int width,
- chtype box, chtype border)
-{
- int i, j;
-
- wattrset (win, 0);
- for (i = 0; i < height; i++) {
- wmove (win, y + i, x);
- for (j = 0; j < width; j++)
- if (!i && !j)
- waddch (win, border | ACS_ULCORNER);
- else if (i == height - 1 && !j)
- waddch (win, border | ACS_LLCORNER);
- else if (!i && j == width - 1)
- waddch (win, box | ACS_URCORNER);
- else if (i == height - 1 && j == width - 1)
- waddch (win, box | ACS_LRCORNER);
- else if (!i)
- waddch (win, border | ACS_HLINE);
- else if (i == height - 1)
- waddch (win, box | ACS_HLINE);
- else if (!j)
- waddch (win, border | ACS_VLINE);
- else if (j == width - 1)
- waddch (win, box | ACS_VLINE);
- else
- waddch (win, box | ' ');
- }
+draw_box(WINDOW * win, int y, int x, int height, int width,
+ chtype box, chtype border)
+{
+ int i, j;
+
+ wattrset(win, 0);
+ for (i = 0; i < height; i++) {
+ wmove(win, y + i, x);
+ for (j = 0; j < width; j++)
+ if (!i && !j)
+ waddch(win, border | ACS_ULCORNER);
+ else if (i == height - 1 && !j)
+ waddch(win, border | ACS_LLCORNER);
+ else if (!i && j == width - 1)
+ waddch(win, box | ACS_URCORNER);
+ else if (i == height - 1 && j == width - 1)
+ waddch(win, box | ACS_LRCORNER);
+ else if (!i)
+ waddch(win, border | ACS_HLINE);
+ else if (i == height - 1)
+ waddch(win, box | ACS_HLINE);
+ else if (!j)
+ waddch(win, border | ACS_VLINE);
+ else if (j == width - 1)
+ waddch(win, box | ACS_VLINE);
+ else
+ waddch(win, box | ' ');
+ }
}
/*
* Draw shadows along the right and bottom edge to give a more 3D look
* to the boxes
*/
-void
-draw_shadow (WINDOW * win, int y, int x, int height, int width)
-{
- int i;
-
- if (has_colors ()) { /* Whether terminal supports color? */
- wattrset (win, shadow_attr);
- wmove (win, y + height, x + 2);
- for (i = 0; i < width; i++)
- waddch (win, winch (win) & A_CHARTEXT);
- for (i = y + 1; i < y + height + 1; i++) {
- wmove (win, i, x + width);
- waddch (win, winch (win) & A_CHARTEXT);
- waddch (win, winch (win) & A_CHARTEXT);
+void draw_shadow(WINDOW * win, int y, int x, int height, int width)
+{
+ int i;
+
+ if (has_colors()) { /* Whether terminal supports color? */
+ wattrset(win, dlg.shadow.atr);
+ wmove(win, y + height, x + 2);
+ for (i = 0; i < width; i++)
+ waddch(win, winch(win) & A_CHARTEXT);
+ for (i = y + 1; i < y + height + 1; i++) {
+ wmove(win, i, x + width);
+ waddch(win, winch(win) & A_CHARTEXT);
+ waddch(win, winch(win) & A_CHARTEXT);
+ }
+ wnoutrefresh(win);
}
- wnoutrefresh (win);
- }
}
/*
* Return the position of the first alphabetic character in a string.
*/
-int
-first_alpha(const char *string, const char *exempt)
+int first_alpha(const char *string, const char *exempt)
{
- int i, in_paren=0, c;
+ int i, in_paren = 0, c;
for (i = 0; i < strlen(string); i++) {
c = tolower(string[i]);
- if (strchr("<[(", c)) ++in_paren;
- if (strchr(">])", c) && in_paren > 0) --in_paren;
+ if (strchr("<[(", c))
+ ++in_paren;
+ if (strchr(">])", c) && in_paren > 0)
+ --in_paren;
- if ((! in_paren) && isalpha(c) &&
- strchr(exempt, c) == 0)
+ if ((!in_paren) && isalpha(c) && strchr(exempt, c) == 0)
return i;
}
@@ -359,17 +476,165 @@ first_alpha(const char *string, const char *exempt)
}
/*
- * Get the first selected item in the dialog_list_item list.
+ * ncurses uses ESC to detect escaped char sequences. This resutl in
+ * a small timeout before ESC is actually delivered to the application.
+ * lxdialog suggest <ESC> <ESC> which is correctly translated to two
+ * times esc. But then we need to ignore the second esc to avoid stepping
+ * out one menu too much. Filter away all escaped key sequences since
+ * keypad(FALSE) turn off ncurses support for escape sequences - and thats
+ * needed to make notimeout() do as expected.
*/
-struct dialog_list_item *
-first_sel_item(int item_no, struct dialog_list_item ** items)
+int on_key_esc(WINDOW *win)
{
- int i;
+ int key;
+ int key2;
+ int key3;
+
+ nodelay(win, TRUE);
+ keypad(win, FALSE);
+ key = wgetch(win);
+ key2 = wgetch(win);
+ do {
+ key3 = wgetch(win);
+ } while (key3 != ERR);
+ nodelay(win, FALSE);
+ keypad(win, TRUE);
+ if (key == KEY_ESC && key2 == ERR)
+ return KEY_ESC;
+ else if (key != ERR && key != KEY_ESC && key2 == ERR)
+ ungetch(key);
+
+ return -1;
+}
+
+/* redraw screen in new size */
+int on_key_resize(void)
+{
+ dialog_clear();
+ return KEY_RESIZE;
+}
+
+struct dialog_list *item_cur;
+struct dialog_list item_nil;
+struct dialog_list *item_head;
+
+void item_reset(void)
+{
+ struct dialog_list *p, *next;
+
+ for (p = item_head; p; p = next) {
+ next = p->next;
+ free(p);
+ }
+ item_head = NULL;
+ item_cur = &item_nil;
+}
+
+void item_make(const char *fmt, ...)
+{
+ va_list ap;
+ struct dialog_list *p = malloc(sizeof(*p));
+
+ if (item_head)
+ item_cur->next = p;
+ else
+ item_head = p;
+ item_cur = p;
+ memset(p, 0, sizeof(*p));
+
+ va_start(ap, fmt);
+ vsnprintf(item_cur->node.str, sizeof(item_cur->node.str), fmt, ap);
+ va_end(ap);
+}
+
+void item_add_str(const char *fmt, ...)
+{
+ va_list ap;
+ size_t avail;
+
+ avail = sizeof(item_cur->node.str) - strlen(item_cur->node.str);
+
+ va_start(ap, fmt);
+ vsnprintf(item_cur->node.str + strlen(item_cur->node.str),
+ avail, fmt, ap);
+ item_cur->node.str[sizeof(item_cur->node.str) - 1] = '\0';
+ va_end(ap);
+}
+
+void item_set_tag(char tag)
+{
+ item_cur->node.tag = tag;
+}
+void item_set_data(void *ptr)
+{
+ item_cur->node.data = ptr;
+}
+
+void item_set_selected(int val)
+{
+ item_cur->node.selected = val;
+}
+
+int item_activate_selected(void)
+{
+ item_foreach()
+ if (item_is_selected())
+ return 1;
+ return 0;
+}
+
+void *item_data(void)
+{
+ return item_cur->node.data;
+}
+
+char item_tag(void)
+{
+ return item_cur->node.tag;
+}
+
+int item_count(void)
+{
+ int n = 0;
+ struct dialog_list *p;
+
+ for (p = item_head; p; p = p->next)
+ n++;
+ return n;
+}
+
+void item_set(int n)
+{
+ int i = 0;
+ item_foreach()
+ if (i++ == n)
+ return;
+}
- for (i = 0; i < item_no; i++) {
- if (items[i]->selected)
- return items[i];
+int item_n(void)
+{
+ int n = 0;
+ struct dialog_list *p;
+
+ for (p = item_head; p; p = p->next) {
+ if (p == item_cur)
+ return n;
+ n++;
}
+ return 0;
+}
- return NULL;
+const char *item_str(void)
+{
+ return item_cur->node.str;
+}
+
+int item_is_selected(void)
+{
+ return (item_cur->node.selected != 0);
+}
+
+int item_is_tag(char tag)
+{
+ return (item_cur->node.tag == tag);
}
diff --git a/package/config/lxdialog/yesno.c b/package/config/lxdialog/yesno.c
index 11fcc25f5..ee0a04e3e 100644
--- a/package/config/lxdialog/yesno.c
+++ b/package/config/lxdialog/yesno.c
@@ -24,95 +24,91 @@
/*
* Display termination buttons
*/
-static void
-print_buttons(WINDOW *dialog, int height, int width, int selected)
+static void print_buttons(WINDOW * dialog, int height, int width, int selected)
{
- int x = width / 2 - 10;
- int y = height - 2;
+ int x = width / 2 - 10;
+ int y = height - 2;
- print_button (dialog, " Yes ", y, x, selected == 0);
- print_button (dialog, " No ", y, x + 13, selected == 1);
+ print_button(dialog, " Yes ", y, x, selected == 0);
+ print_button(dialog, " No ", y, x + 13, selected == 1);
- wmove(dialog, y, x+1 + 13*selected );
- wrefresh (dialog);
+ wmove(dialog, y, x + 1 + 13 * selected);
+ wrefresh(dialog);
}
/*
* Display a dialog box with two buttons - Yes and No
*/
-int
-dialog_yesno (const char *title, const char *prompt, int height, int width)
+int dialog_yesno(const char *title, const char *prompt, int height, int width)
{
- int i, x, y, key = 0, button = 0;
- WINDOW *dialog;
-
- /* center dialog box on screen */
- x = (COLS - width) / 2;
- y = (LINES - height) / 2;
-
- draw_shadow (stdscr, y, x, height, width);
-
- dialog = newwin (height, width, y, x);
- keypad (dialog, TRUE);
-
- draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr);
- wattrset (dialog, border_attr);
- mvwaddch (dialog, height-3, 0, ACS_LTEE);
- for (i = 0; i < width - 2; i++)
- waddch (dialog, ACS_HLINE);
- wattrset (dialog, dialog_attr);
- waddch (dialog, ACS_RTEE);
-
- if (title != NULL && strlen(title) >= width-2 ) {
- /* truncate long title -- mec */
- char * title2 = malloc(width-2+1);
- memcpy( title2, title, width-2 );
- title2[width-2] = '\0';
- title = title2;
- }
-
- if (title != NULL) {
- wattrset (dialog, title_attr);
- mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' ');
- waddstr (dialog, (char *)title);
- waddch (dialog, ' ');
- }
-
- wattrset (dialog, dialog_attr);
- print_autowrap (dialog, prompt, width - 2, 1, 3);
-
- print_buttons(dialog, height, width, 0);
-
- while (key != ESC) {
- key = wgetch (dialog);
- switch (key) {
- case 'Y':
- case 'y':
- delwin (dialog);
- return 0;
- case 'N':
- case 'n':
- delwin (dialog);
- return 1;
-
- case TAB:
- case KEY_LEFT:
- case KEY_RIGHT:
- button = ((key == KEY_LEFT ? --button : ++button) < 0)
- ? 1 : (button > 1 ? 0 : button);
-
- print_buttons(dialog, height, width, button);
- wrefresh (dialog);
- break;
- case ' ':
- case '\n':
- delwin (dialog);
- return button;
- case ESC:
- break;
+ int i, x, y, key = 0, button = 0;
+ WINDOW *dialog;
+
+do_resize:
+ if (getmaxy(stdscr) < (height + 4))
+ return -ERRDISPLAYTOOSMALL;
+ if (getmaxx(stdscr) < (width + 4))
+ return -ERRDISPLAYTOOSMALL;
+
+ /* center dialog box on screen */
+ x = (COLS - width) / 2;
+ y = (LINES - height) / 2;
+
+ draw_shadow(stdscr, y, x, height, width);
+
+ dialog = newwin(height, width, y, x);
+ keypad(dialog, TRUE);
+
+ draw_box(dialog, 0, 0, height, width,
+ dlg.dialog.atr, dlg.border.atr);
+ wattrset(dialog, dlg.border.atr);
+ mvwaddch(dialog, height - 3, 0, ACS_LTEE);
+ for (i = 0; i < width - 2; i++)
+ waddch(dialog, ACS_HLINE);
+ wattrset(dialog, dlg.dialog.atr);
+ waddch(dialog, ACS_RTEE);
+
+ print_title(dialog, title, width);
+
+ wattrset(dialog, dlg.dialog.atr);
+ print_autowrap(dialog, prompt, width - 2, 1, 3);
+
+ print_buttons(dialog, height, width, 0);
+
+ while (key != KEY_ESC) {
+ key = wgetch(dialog);
+ switch (key) {
+ case 'Y':
+ case 'y':
+ delwin(dialog);
+ return 0;
+ case 'N':
+ case 'n':
+ delwin(dialog);
+ return 1;
+
+ case TAB:
+ case KEY_LEFT:
+ case KEY_RIGHT:
+ button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button);
+
+ print_buttons(dialog, height, width, button);
+ wrefresh(dialog);
+ break;
+ case ' ':
+ case '\n':
+ delwin(dialog);
+ return button;
+ case KEY_ESC:
+ key = on_key_esc(dialog);
+ break;
+ case KEY_RESIZE:
+ delwin(dialog);
+ on_key_resize();
+ goto do_resize;
+ }
}
- }
- delwin (dialog);
- return -1; /* ESC pressed */
+ delwin(dialog);
+ return key; /* ESC pressed */
}