aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/lxdialog/textbox.c
diff options
context:
space:
mode:
authorSam Ravnborg <sam@mars.ravnborg.org>2006-07-29 16:48:57 -0400
committerSam Ravnborg <sam@neptun.ravnborg.org>2006-09-30 05:19:20 -0400
commitc8dc68ad0fbd934e78e913b8a8d7b45945db4930 (patch)
tree62169927ce5ca83e3f280e6bbe06053989462968 /scripts/kconfig/lxdialog/textbox.c
parentf3cbcdc955d0d2c8b4c52d6b73fc536b01b68c64 (diff)
kconfig/lxdialog: support resize
In all dialogs now properly catch KEY_RESIZE and take proper action. In mconf try to behave sensibly when a dialog routine returns -ERRDISPLAYTOOSMALL. The original check for a screnn size of 80x19 is kept for now. It may make sense to remove it later, but thats anyway what much text is adjusted for. Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts/kconfig/lxdialog/textbox.c')
-rw-r--r--scripts/kconfig/lxdialog/textbox.c140
1 files changed, 83 insertions, 57 deletions
diff --git a/scripts/kconfig/lxdialog/textbox.c b/scripts/kconfig/lxdialog/textbox.c
index a99e1f497d67..fabfc1ad789d 100644
--- a/scripts/kconfig/lxdialog/textbox.c
+++ b/scripts/kconfig/lxdialog/textbox.c
@@ -25,7 +25,7 @@ static void back_lines(int n);
25static void print_page(WINDOW * win, int height, int width); 25static void print_page(WINDOW * win, int height, int width);
26static void print_line(WINDOW * win, int row, int width); 26static void print_line(WINDOW * win, int row, int width);
27static char *get_line(void); 27static char *get_line(void);
28static void print_position(WINDOW * win, int height, int width); 28static void print_position(WINDOW * win);
29 29
30static int hscroll; 30static int hscroll;
31static int begin_reached, end_reached, page_length; 31static int begin_reached, end_reached, page_length;
@@ -33,14 +33,28 @@ static const char *buf;
33static const char *page; 33static const char *page;
34 34
35/* 35/*
36 * refresh window content
37 */
38static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw,
39 int cur_y, int cur_x)
40{
41 print_page(box, boxh, boxw);
42 print_position(dialog);
43 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
44 wrefresh(dialog);
45}
46
47
48/*
36 * Display text from a file in a dialog box. 49 * Display text from a file in a dialog box.
37 */ 50 */
38int dialog_textbox(const char *title, const char *tbuf, int height, int width) 51int dialog_textbox(const char *title, const char *tbuf,
52 int initial_height, int initial_width)
39{ 53{
40 int i, x, y, cur_x, cur_y, key = 0; 54 int i, x, y, cur_x, cur_y, key = 0;
41 int texth, textw; 55 int height, width, boxh, boxw;
42 int passed_end; 56 int passed_end;
43 WINDOW *dialog, *text; 57 WINDOW *dialog, *box;
44 58
45 begin_reached = 1; 59 begin_reached = 1;
46 end_reached = 0; 60 end_reached = 0;
@@ -49,6 +63,25 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width)
49 buf = tbuf; 63 buf = tbuf;
50 page = buf; /* page is pointer to start of page to be displayed */ 64 page = buf; /* page is pointer to start of page to be displayed */
51 65
66do_resize:
67 getmaxyx(stdscr, height, width);
68 if (height < 8 || width < 8)
69 return -ERRDISPLAYTOOSMALL;
70 if (initial_height != 0)
71 height = initial_height;
72 else
73 if (height > 4)
74 height -= 4;
75 else
76 height = 0;
77 if (initial_width != 0)
78 width = initial_width;
79 else
80 if (width > 5)
81 width -= 5;
82 else
83 width = 0;
84
52 /* center dialog box on screen */ 85 /* center dialog box on screen */
53 x = (COLS - width) / 2; 86 x = (COLS - width) / 2;
54 y = (LINES - height) / 2; 87 y = (LINES - height) / 2;
@@ -58,14 +91,14 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width)
58 dialog = newwin(height, width, y, x); 91 dialog = newwin(height, width, y, x);
59 keypad(dialog, TRUE); 92 keypad(dialog, TRUE);
60 93
61 /* Create window for text region, used for scrolling text */ 94 /* Create window for box region, used for scrolling text */
62 texth = height - 4; 95 boxh = height - 4;
63 textw = width - 2; 96 boxw = width - 2;
64 text = subwin(dialog, texth, textw, y + 1, x + 1); 97 box = subwin(dialog, boxh, boxw, y + 1, x + 1);
65 wattrset(text, dlg.dialog.atr); 98 wattrset(box, dlg.dialog.atr);
66 wbkgdset(text, dlg.dialog.atr & A_COLOR); 99 wbkgdset(box, dlg.dialog.atr & A_COLOR);
67 100
68 keypad(text, TRUE); 101 keypad(box, TRUE);
69 102
70 /* register the new window, along with its borders */ 103 /* register the new window, along with its borders */
71 draw_box(dialog, 0, 0, height, width, 104 draw_box(dialog, 0, 0, height, width,
@@ -86,11 +119,8 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width)
86 getyx(dialog, cur_y, cur_x); /* Save cursor position */ 119 getyx(dialog, cur_y, cur_x); /* Save cursor position */
87 120
88 /* Print first page of text */ 121 /* Print first page of text */
89 attr_clear(text, texth, textw, dlg.dialog.atr); 122 attr_clear(box, boxh, boxw, dlg.dialog.atr);
90 print_page(text, texth, textw); 123 refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);
91 print_position(dialog, height, width);
92 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
93 wrefresh(dialog);
94 124
95 while ((key != KEY_ESC) && (key != '\n')) { 125 while ((key != KEY_ESC) && (key != '\n')) {
96 key = wgetch(dialog); 126 key = wgetch(dialog);
@@ -99,7 +129,7 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width)
99 case 'e': 129 case 'e':
100 case 'X': 130 case 'X':
101 case 'x': 131 case 'x':
102 delwin(text); 132 delwin(box);
103 delwin(dialog); 133 delwin(dialog);
104 return 0; 134 return 0;
105 case 'g': /* First page */ 135 case 'g': /* First page */
@@ -107,10 +137,8 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width)
107 if (!begin_reached) { 137 if (!begin_reached) {
108 begin_reached = 1; 138 begin_reached = 1;
109 page = buf; 139 page = buf;
110 print_page(text, texth, textw); 140 refresh_text_box(dialog, box, boxh, boxw,
111 print_position(dialog, height, width); 141 cur_y, cur_x);
112 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
113 wrefresh(dialog);
114 } 142 }
115 break; 143 break;
116 case 'G': /* Last page */ 144 case 'G': /* Last page */
@@ -119,11 +147,9 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width)
119 end_reached = 1; 147 end_reached = 1;
120 /* point to last char in buf */ 148 /* point to last char in buf */
121 page = buf + strlen(buf); 149 page = buf + strlen(buf);
122 back_lines(texth); 150 back_lines(boxh);
123 print_page(text, texth, textw); 151 refresh_text_box(dialog, box, boxh, boxw,
124 print_position(dialog, height, width); 152 cur_y, cur_x);
125 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
126 wrefresh(dialog);
127 break; 153 break;
128 case 'K': /* Previous line */ 154 case 'K': /* Previous line */
129 case 'k': 155 case 'k':
@@ -138,16 +164,16 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width)
138 * point to start of next page. This is done 164 * point to start of next page. This is done
139 * by calling get_line() in the following 165 * by calling get_line() in the following
140 * 'for' loop. */ 166 * 'for' loop. */
141 scrollok(text, TRUE); 167 scrollok(box, TRUE);
142 wscrl(text, -1); /* Scroll text region down one line */ 168 wscrl(box, -1); /* Scroll box region down one line */
143 scrollok(text, FALSE); 169 scrollok(box, FALSE);
144 page_length = 0; 170 page_length = 0;
145 passed_end = 0; 171 passed_end = 0;
146 for (i = 0; i < texth; i++) { 172 for (i = 0; i < boxh; i++) {
147 if (!i) { 173 if (!i) {
148 /* print first line of page */ 174 /* print first line of page */
149 print_line(text, 0, textw); 175 print_line(box, 0, boxw);
150 wnoutrefresh(text); 176 wnoutrefresh(box);
151 } else 177 } else
152 /* Called to update 'end_reached' and 'page' */ 178 /* Called to update 'end_reached' and 'page' */
153 get_line(); 179 get_line();
@@ -157,7 +183,7 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width)
157 passed_end = 1; 183 passed_end = 1;
158 } 184 }
159 185
160 print_position(dialog, height, width); 186 print_position(dialog);
161 wmove(dialog, cur_y, cur_x); /* Restore cursor position */ 187 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
162 wrefresh(dialog); 188 wrefresh(dialog);
163 } 189 }
@@ -167,23 +193,21 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width)
167 case KEY_PPAGE: 193 case KEY_PPAGE:
168 if (begin_reached) 194 if (begin_reached)
169 break; 195 break;
170 back_lines(page_length + texth); 196 back_lines(page_length + boxh);
171 print_page(text, texth, textw); 197 refresh_text_box(dialog, box, boxh, boxw,
172 print_position(dialog, height, width); 198 cur_y, cur_x);
173 wmove(dialog, cur_y, cur_x);
174 wrefresh(dialog);
175 break; 199 break;
176 case 'J': /* Next line */ 200 case 'J': /* Next line */
177 case 'j': 201 case 'j':
178 case KEY_DOWN: 202 case KEY_DOWN:
179 if (!end_reached) { 203 if (!end_reached) {
180 begin_reached = 0; 204 begin_reached = 0;
181 scrollok(text, TRUE); 205 scrollok(box, TRUE);
182 scroll(text); /* Scroll text region up one line */ 206 scroll(box); /* Scroll box region up one line */
183 scrollok(text, FALSE); 207 scrollok(box, FALSE);
184 print_line(text, texth - 1, textw); 208 print_line(box, boxh - 1, boxw);
185 wnoutrefresh(text); 209 wnoutrefresh(box);
186 print_position(dialog, height, width); 210 print_position(dialog);
187 wmove(dialog, cur_y, cur_x); /* Restore cursor position */ 211 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
188 wrefresh(dialog); 212 wrefresh(dialog);
189 } 213 }
@@ -194,10 +218,8 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width)
194 break; 218 break;
195 219
196 begin_reached = 0; 220 begin_reached = 0;
197 print_page(text, texth, textw); 221 refresh_text_box(dialog, box, boxh, boxw,
198 print_position(dialog, height, width); 222 cur_y, cur_x);
199 wmove(dialog, cur_y, cur_x);
200 wrefresh(dialog);
201 break; 223 break;
202 case '0': /* Beginning of line */ 224 case '0': /* Beginning of line */
203 case 'H': /* Scroll left */ 225 case 'H': /* Scroll left */
@@ -212,9 +234,8 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width)
212 hscroll--; 234 hscroll--;
213 /* Reprint current page to scroll horizontally */ 235 /* Reprint current page to scroll horizontally */
214 back_lines(page_length); 236 back_lines(page_length);
215 print_page(text, texth, textw); 237 refresh_text_box(dialog, box, boxh, boxw,
216 wmove(dialog, cur_y, cur_x); 238 cur_y, cur_x);
217 wrefresh(dialog);
218 break; 239 break;
219 case 'L': /* Scroll right */ 240 case 'L': /* Scroll right */
220 case 'l': 241 case 'l':
@@ -224,16 +245,21 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width)
224 hscroll++; 245 hscroll++;
225 /* Reprint current page to scroll horizontally */ 246 /* Reprint current page to scroll horizontally */
226 back_lines(page_length); 247 back_lines(page_length);
227 print_page(text, texth, textw); 248 refresh_text_box(dialog, box, boxh, boxw,
228 wmove(dialog, cur_y, cur_x); 249 cur_y, cur_x);
229 wrefresh(dialog);
230 break; 250 break;
231 case KEY_ESC: 251 case KEY_ESC:
232 key = on_key_esc(dialog); 252 key = on_key_esc(dialog);
233 break; 253 break;
254 case KEY_RESIZE:
255 back_lines(height);
256 delwin(box);
257 delwin(dialog);
258 on_key_resize();
259 goto do_resize;
234 } 260 }
235 } 261 }
236 delwin(text); 262 delwin(box);
237 delwin(dialog); 263 delwin(dialog);
238 return key; /* ESC pressed */ 264 return key; /* ESC pressed */
239} 265}
@@ -353,13 +379,13 @@ static char *get_line(void)
353/* 379/*
354 * Print current position 380 * Print current position
355 */ 381 */
356static void print_position(WINDOW * win, int height, int width) 382static void print_position(WINDOW * win)
357{ 383{
358 int percent; 384 int percent;
359 385
360 wattrset(win, dlg.position_indicator.atr); 386 wattrset(win, dlg.position_indicator.atr);
361 wbkgdset(win, dlg.position_indicator.atr & A_COLOR); 387 wbkgdset(win, dlg.position_indicator.atr & A_COLOR);
362 percent = (page - buf) * 100 / strlen(buf); 388 percent = (page - buf) * 100 / strlen(buf);
363 wmove(win, height - 3, width - 9); 389 wmove(win, getmaxy(win) - 3, getmaxx(win) - 9);
364 wprintw(win, "(%3d%%)", percent); 390 wprintw(win, "(%3d%%)", percent);
365} 391}