Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI window generic functions. |
f33c6cbf | 2 | |
88d83552 | 3 | Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software |
55fb0713 | 4 | Foundation, Inc. |
f33c6cbf | 5 | |
f377b406 | 6 | Contributed by Hewlett-Packard Company. |
c906108c | 7 | |
f377b406 SC |
8 | This file is part of GDB. |
9 | ||
10 | This program is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2 of the License, or | |
13 | (at your option) any later version. | |
14 | ||
15 | This program is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with this program; if not, write to the Free Software | |
88d83552 EZ |
22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 | Boston, MA 02110-1301, USA. */ | |
f377b406 SC |
24 | |
25 | /* This module contains procedures for handling tui window functions | |
26 | like resize, scrolling, scrolling, changing focus, etc. | |
27 | ||
28 | Author: Susan B. Macchia */ | |
c906108c | 29 | |
c906108c SS |
30 | #include "defs.h" |
31 | #include "command.h" | |
32 | #include "symtab.h" | |
33 | #include "breakpoint.h" | |
34 | #include "frame.h" | |
41783295 | 35 | #include "cli/cli-cmds.h" |
3e752b04 | 36 | #include "top.h" |
52575520 | 37 | #include "source.h" |
c906108c | 38 | |
d7b2e967 AC |
39 | #include "tui/tui.h" |
40 | #include "tui/tui-data.h" | |
41 | #include "tui/tui-wingeneral.h" | |
42 | #include "tui/tui-stack.h" | |
43 | #include "tui/tui-regs.h" | |
44 | #include "tui/tui-disasm.h" | |
45 | #include "tui/tui-source.h" | |
46 | #include "tui/tui-winsource.h" | |
47 | #include "tui/tui-windata.h" | |
c906108c | 48 | |
6a83354a | 49 | #include "gdb_curses.h" |
96ec9981 | 50 | |
d02c80cd | 51 | #include "gdb_string.h" |
96ec9981 | 52 | #include <ctype.h> |
dbda9972 | 53 | #include "readline/readline.h" |
96ec9981 | 54 | |
c906108c SS |
55 | /******************************* |
56 | ** Static Local Decls | |
57 | ********************************/ | |
6ba8e26f AC |
58 | static void make_visible_with_new_height (struct tui_win_info *); |
59 | static void make_invisible_and_set_new_height (struct tui_win_info *, int); | |
60 | static enum tui_status tui_adjust_win_heights (struct tui_win_info *, int); | |
61 | static int new_height_ok (struct tui_win_info *, int); | |
62 | static void tui_set_tab_width_command (char *, int); | |
63 | static void tui_refresh_all_command (char *, int); | |
64 | static void tui_set_win_height_command (char *, int); | |
65 | static void tui_xdb_set_win_height_command (char *, int); | |
66 | static void tui_all_windows_info (char *, int); | |
67 | static void tui_set_focus_command (char *, int); | |
68 | static void tui_scroll_forward_command (char *, int); | |
69 | static void tui_scroll_backward_command (char *, int); | |
70 | static void tui_scroll_left_command (char *, int); | |
71 | static void tui_scroll_right_command (char *, int); | |
72 | static void parse_scrolling_args (char *, struct tui_win_info * *, int *); | |
c906108c SS |
73 | |
74 | ||
75 | /*************************************** | |
76 | ** DEFINITIONS | |
77 | ***************************************/ | |
78 | #define WIN_HEIGHT_USAGE "Usage: winheight <win_name> [+ | -] <#lines>\n" | |
79 | #define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n" | |
80 | #define FOCUS_USAGE "Usage: focus {<win> | next | prev}\n" | |
81 | ||
82 | /*************************************** | |
83 | ** PUBLIC FUNCTIONS | |
84 | ***************************************/ | |
85 | ||
17aae570 SC |
86 | #ifndef ACS_LRCORNER |
87 | # define ACS_LRCORNER '+' | |
88 | #endif | |
89 | #ifndef ACS_LLCORNER | |
90 | # define ACS_LLCORNER '+' | |
91 | #endif | |
92 | #ifndef ACS_ULCORNER | |
93 | # define ACS_ULCORNER '+' | |
94 | #endif | |
95 | #ifndef ACS_URCORNER | |
96 | # define ACS_URCORNER '+' | |
97 | #endif | |
98 | #ifndef ACS_HLINE | |
99 | # define ACS_HLINE '-' | |
100 | #endif | |
101 | #ifndef ACS_VLINE | |
102 | # define ACS_VLINE '|' | |
103 | #endif | |
104 | ||
af101512 SC |
105 | /* Possible values for tui-border-kind variable. */ |
106 | static const char *tui_border_kind_enums[] = { | |
107 | "space", | |
108 | "ascii", | |
109 | "acs", | |
110 | NULL | |
111 | }; | |
112 | ||
113 | /* Possible values for tui-border-mode and tui-active-border-mode. */ | |
114 | static const char *tui_border_mode_enums[] = { | |
115 | "normal", | |
116 | "standout", | |
117 | "reverse", | |
118 | "half", | |
119 | "half-standout", | |
120 | "bold", | |
121 | "bold-standout", | |
122 | NULL | |
123 | }; | |
124 | ||
125 | struct tui_translate | |
126 | { | |
127 | const char *name; | |
128 | int value; | |
129 | }; | |
130 | ||
131 | /* Translation table for border-mode variables. | |
132 | The list of values must be terminated by a NULL. | |
133 | After the NULL value, an entry defines the default. */ | |
134 | struct tui_translate tui_border_mode_translate[] = { | |
135 | { "normal", A_NORMAL }, | |
136 | { "standout", A_STANDOUT }, | |
137 | { "reverse", A_REVERSE }, | |
138 | { "half", A_DIM }, | |
139 | { "half-standout", A_DIM | A_STANDOUT }, | |
140 | { "bold", A_BOLD }, | |
141 | { "bold-standout", A_BOLD | A_STANDOUT }, | |
142 | { 0, 0 }, | |
143 | { "normal", A_NORMAL } | |
144 | }; | |
145 | ||
146 | /* Translation tables for border-kind, one for each border | |
147 | character (see wborder, border curses operations). | |
148 | -1 is used to indicate the ACS because ACS characters | |
149 | are determined at run time by curses (depends on terminal). */ | |
150 | struct tui_translate tui_border_kind_translate_vline[] = { | |
151 | { "space", ' ' }, | |
152 | { "ascii", '|' }, | |
153 | { "acs", -1 }, | |
154 | { 0, 0 }, | |
155 | { "ascii", '|' } | |
156 | }; | |
157 | ||
158 | struct tui_translate tui_border_kind_translate_hline[] = { | |
159 | { "space", ' ' }, | |
160 | { "ascii", '-' }, | |
161 | { "acs", -1 }, | |
162 | { 0, 0 }, | |
163 | { "ascii", '-' } | |
164 | }; | |
165 | ||
166 | struct tui_translate tui_border_kind_translate_ulcorner[] = { | |
167 | { "space", ' ' }, | |
168 | { "ascii", '+' }, | |
169 | { "acs", -1 }, | |
170 | { 0, 0 }, | |
171 | { "ascii", '+' } | |
172 | }; | |
173 | ||
174 | struct tui_translate tui_border_kind_translate_urcorner[] = { | |
175 | { "space", ' ' }, | |
176 | { "ascii", '+' }, | |
177 | { "acs", -1 }, | |
178 | { 0, 0 }, | |
179 | { "ascii", '+' } | |
180 | }; | |
181 | ||
182 | struct tui_translate tui_border_kind_translate_llcorner[] = { | |
183 | { "space", ' ' }, | |
184 | { "ascii", '+' }, | |
185 | { "acs", -1 }, | |
186 | { 0, 0 }, | |
187 | { "ascii", '+' } | |
188 | }; | |
189 | ||
190 | struct tui_translate tui_border_kind_translate_lrcorner[] = { | |
191 | { "space", ' ' }, | |
192 | { "ascii", '+' }, | |
193 | { "acs", -1 }, | |
194 | { 0, 0 }, | |
195 | { "ascii", '+' } | |
196 | }; | |
197 | ||
198 | ||
199 | /* Tui configuration variables controlled with set/show command. */ | |
200 | const char *tui_active_border_mode = "bold-standout"; | |
920d2a44 AC |
201 | static void |
202 | show_tui_active_border_mode (struct ui_file *file, int from_tty, | |
203 | struct cmd_list_element *c, const char *value) | |
204 | { | |
205 | fprintf_filtered (file, _("\ | |
206 | The attribute mode to use for the active TUI window border is \"%s\".\n"), | |
207 | value); | |
208 | } | |
209 | ||
af101512 | 210 | const char *tui_border_mode = "normal"; |
920d2a44 AC |
211 | static void |
212 | show_tui_border_mode (struct ui_file *file, int from_tty, | |
213 | struct cmd_list_element *c, const char *value) | |
214 | { | |
215 | fprintf_filtered (file, _("\ | |
216 | The attribute mode to use for the TUI window borders is \"%s\".\n"), | |
217 | value); | |
218 | } | |
219 | ||
af101512 | 220 | const char *tui_border_kind = "acs"; |
920d2a44 AC |
221 | static void |
222 | show_tui_border_kind (struct ui_file *file, int from_tty, | |
223 | struct cmd_list_element *c, const char *value) | |
224 | { | |
225 | fprintf_filtered (file, _("The kind of border for TUI windows is \"%s\".\n"), | |
226 | value); | |
227 | } | |
228 | ||
af101512 SC |
229 | |
230 | /* Tui internal configuration variables. These variables are | |
231 | updated by tui_update_variables to reflect the tui configuration | |
232 | variables. */ | |
233 | chtype tui_border_vline; | |
234 | chtype tui_border_hline; | |
235 | chtype tui_border_ulcorner; | |
236 | chtype tui_border_urcorner; | |
237 | chtype tui_border_llcorner; | |
238 | chtype tui_border_lrcorner; | |
239 | ||
240 | int tui_border_attrs; | |
241 | int tui_active_border_attrs; | |
242 | ||
243 | /* Identify the item in the translation table. | |
244 | When the item is not recognized, use the default entry. */ | |
245 | static struct tui_translate * | |
246 | translate (const char *name, struct tui_translate *table) | |
247 | { | |
248 | while (table->name) | |
249 | { | |
250 | if (name && strcmp (table->name, name) == 0) | |
251 | return table; | |
252 | table++; | |
253 | } | |
254 | ||
255 | /* Not found, return default entry. */ | |
256 | table++; | |
257 | return table; | |
258 | } | |
259 | ||
260 | /* Update the tui internal configuration according to gdb settings. | |
261 | Returns 1 if the configuration has changed and the screen should | |
262 | be redrawn. */ | |
263 | int | |
d02c80cd | 264 | tui_update_variables (void) |
af101512 SC |
265 | { |
266 | int need_redraw = 0; | |
267 | struct tui_translate *entry; | |
268 | ||
269 | entry = translate (tui_border_mode, tui_border_mode_translate); | |
270 | if (tui_border_attrs != entry->value) | |
271 | { | |
272 | tui_border_attrs = entry->value; | |
273 | need_redraw = 1; | |
274 | } | |
275 | entry = translate (tui_active_border_mode, tui_border_mode_translate); | |
276 | if (tui_active_border_attrs != entry->value) | |
277 | { | |
278 | tui_active_border_attrs = entry->value; | |
279 | need_redraw = 1; | |
280 | } | |
281 | ||
282 | /* If one corner changes, all characters are changed. | |
283 | Only check the first one. The ACS characters are determined at | |
284 | run time by curses terminal management. */ | |
285 | entry = translate (tui_border_kind, tui_border_kind_translate_lrcorner); | |
286 | if (tui_border_lrcorner != (chtype) entry->value) | |
287 | { | |
288 | tui_border_lrcorner = (entry->value < 0) ? ACS_LRCORNER : entry->value; | |
289 | need_redraw = 1; | |
290 | } | |
291 | entry = translate (tui_border_kind, tui_border_kind_translate_llcorner); | |
292 | tui_border_llcorner = (entry->value < 0) ? ACS_LLCORNER : entry->value; | |
293 | ||
294 | entry = translate (tui_border_kind, tui_border_kind_translate_ulcorner); | |
295 | tui_border_ulcorner = (entry->value < 0) ? ACS_ULCORNER : entry->value; | |
296 | ||
297 | entry = translate (tui_border_kind, tui_border_kind_translate_urcorner); | |
298 | tui_border_urcorner = (entry->value < 0) ? ACS_URCORNER : entry->value; | |
299 | ||
300 | entry = translate (tui_border_kind, tui_border_kind_translate_hline); | |
301 | tui_border_hline = (entry->value < 0) ? ACS_HLINE : entry->value; | |
302 | ||
303 | entry = translate (tui_border_kind, tui_border_kind_translate_vline); | |
304 | tui_border_vline = (entry->value < 0) ? ACS_VLINE : entry->value; | |
305 | ||
306 | return need_redraw; | |
307 | } | |
308 | ||
c9684879 SC |
309 | static void |
310 | set_tui_cmd (char *args, int from_tty) | |
311 | { | |
312 | } | |
313 | ||
314 | static void | |
315 | show_tui_cmd (char *args, int from_tty) | |
316 | { | |
317 | } | |
af101512 | 318 | |
10f59415 SC |
319 | static struct cmd_list_element *tuilist; |
320 | ||
321 | static void | |
322 | tui_command (char *args, int from_tty) | |
323 | { | |
a3f17187 AC |
324 | printf_unfiltered (_("\"tui\" must be followed by the name of a " |
325 | "tui command.\n")); | |
10f59415 SC |
326 | help_list (tuilist, "tui ", -1, gdb_stdout); |
327 | } | |
328 | ||
329 | struct cmd_list_element ** | |
da745b36 | 330 | tui_get_cmd_list (void) |
10f59415 SC |
331 | { |
332 | if (tuilist == 0) | |
333 | add_prefix_cmd ("tui", class_tui, tui_command, | |
1bedd215 | 334 | _("Text User Interface commands."), |
10f59415 SC |
335 | &tuilist, "tui ", 0, &cmdlist); |
336 | return &tuilist; | |
337 | } | |
338 | ||
6ba8e26f | 339 | /* Function to initialize gdb commands, for tui window manipulation. */ |
c906108c | 340 | void |
6ba8e26f | 341 | _initialize_tui_win (void) |
c906108c | 342 | { |
af101512 | 343 | struct cmd_list_element *c; |
c9684879 SC |
344 | static struct cmd_list_element *tui_setlist; |
345 | static struct cmd_list_element *tui_showlist; | |
af101512 | 346 | |
41783295 SC |
347 | /* Define the classes of commands. |
348 | They will appear in the help list in the reverse of this order. */ | |
c9684879 | 349 | add_prefix_cmd ("tui", class_tui, set_tui_cmd, |
1bedd215 | 350 | _("TUI configuration variables"), |
c9684879 SC |
351 | &tui_setlist, "set tui ", |
352 | 0/*allow-unknown*/, &setlist); | |
353 | add_prefix_cmd ("tui", class_tui, show_tui_cmd, | |
1bedd215 | 354 | _("TUI configuration variables"), |
c9684879 SC |
355 | &tui_showlist, "show tui ", |
356 | 0/*allow-unknown*/, &showlist); | |
357 | ||
6ba8e26f | 358 | add_com ("refresh", class_tui, tui_refresh_all_command, |
1bedd215 | 359 | _("Refresh the terminal display.\n")); |
41783295 SC |
360 | if (xdb_commands) |
361 | add_com_alias ("U", "refresh", class_tui, 0); | |
1bedd215 AC |
362 | add_com ("tabset", class_tui, tui_set_tab_width_command, _("\ |
363 | Set the width (in characters) of tab stops.\n\ | |
364 | Usage: tabset <n>\n")); | |
365 | add_com ("winheight", class_tui, tui_set_win_height_command, _("\ | |
366 | Set the height of a specified window.\n\ | |
c906108c SS |
367 | Usage: winheight <win_name> [+ | -] <#lines>\n\ |
368 | Window names are:\n\ | |
369 | src : the source window\n\ | |
370 | cmd : the command window\n\ | |
371 | asm : the disassembly window\n\ | |
1bedd215 | 372 | regs : the register display\n")); |
41783295 | 373 | add_com_alias ("wh", "winheight", class_tui, 0); |
6ba8e26f | 374 | add_info ("win", tui_all_windows_info, |
1bedd215 AC |
375 | _("List of all displayed windows.\n")); |
376 | add_com ("focus", class_tui, tui_set_focus_command, _("\ | |
377 | Set focus to named window or next/prev window.\n\ | |
c906108c SS |
378 | Usage: focus {<win> | next | prev}\n\ |
379 | Valid Window names are:\n\ | |
380 | src : the source window\n\ | |
381 | asm : the disassembly window\n\ | |
382 | regs : the register display\n\ | |
1bedd215 | 383 | cmd : the command window\n")); |
41783295 | 384 | add_com_alias ("fs", "focus", class_tui, 0); |
1bedd215 AC |
385 | add_com ("+", class_tui, tui_scroll_forward_command, _("\ |
386 | Scroll window forward.\n\ | |
387 | Usage: + [win] [n]\n")); | |
388 | add_com ("-", class_tui, tui_scroll_backward_command, _("\ | |
389 | Scroll window backward.\n\ | |
390 | Usage: - [win] [n]\n")); | |
391 | add_com ("<", class_tui, tui_scroll_left_command, _("\ | |
392 | Scroll window forward.\n\ | |
393 | Usage: < [win] [n]\n")); | |
394 | add_com (">", class_tui, tui_scroll_right_command, _("\ | |
395 | Scroll window backward.\n\ | |
396 | Usage: > [win] [n]\n")); | |
41783295 | 397 | if (xdb_commands) |
1bedd215 AC |
398 | add_com ("w", class_xdb, tui_xdb_set_win_height_command, _("\ |
399 | XDB compatibility command for setting the height of a command window.\n\ | |
400 | Usage: w <#lines>\n")); | |
af101512 SC |
401 | |
402 | /* Define the tui control variables. */ | |
7ab04401 AC |
403 | add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums, |
404 | &tui_border_kind, _("\ | |
405 | Set the kind of border for TUI windows."), _("\ | |
406 | Show the kind of border for TUI windows."), _("\ | |
407 | This variable controls the border of TUI windows:\n\ | |
408 | space use a white space\n\ | |
409 | ascii use ascii characters + - | for the border\n\ | |
410 | acs use the Alternate Character Set"), | |
411 | NULL, | |
920d2a44 | 412 | show_tui_border_kind, |
7ab04401 AC |
413 | &tui_setlist, &tui_showlist); |
414 | ||
415 | add_setshow_enum_cmd ("border-mode", no_class, tui_border_mode_enums, | |
416 | &tui_border_mode, _("\ | |
417 | Set the attribute mode to use for the TUI window borders."), _("\ | |
418 | Show the attribute mode to use for the TUI window borders."), _("\ | |
419 | This variable controls the attributes to use for the window borders:\n\ | |
420 | normal normal display\n\ | |
421 | standout use highlight mode of terminal\n\ | |
422 | reverse use reverse video mode\n\ | |
423 | half use half bright\n\ | |
424 | half-standout use half bright and standout mode\n\ | |
425 | bold use extra bright or bold\n\ | |
426 | bold-standout use extra bright or bold with standout mode"), | |
427 | NULL, | |
920d2a44 | 428 | show_tui_border_mode, |
7ab04401 AC |
429 | &tui_setlist, &tui_showlist); |
430 | ||
431 | add_setshow_enum_cmd ("active-border-mode", no_class, tui_border_mode_enums, | |
432 | &tui_active_border_mode, _("\ | |
433 | Set the attribute mode to use for the active TUI window border."), _("\ | |
434 | Show the attribute mode to use for the active TUI window border."), _("\ | |
435 | This variable controls the attributes to use for the active window border:\n\ | |
436 | normal normal display\n\ | |
437 | standout use highlight mode of terminal\n\ | |
438 | reverse use reverse video mode\n\ | |
439 | half use half bright\n\ | |
440 | half-standout use half bright and standout mode\n\ | |
441 | bold use extra bright or bold\n\ | |
442 | bold-standout use extra bright or bold with standout mode"), | |
443 | NULL, | |
920d2a44 | 444 | show_tui_active_border_mode, |
7ab04401 | 445 | &tui_setlist, &tui_showlist); |
41783295 | 446 | } |
c906108c | 447 | |
3e752b04 SC |
448 | /* Update gdb's knowledge of the terminal size. */ |
449 | void | |
d02c80cd | 450 | tui_update_gdb_sizes (void) |
3e752b04 SC |
451 | { |
452 | char cmd[50]; | |
3e752b04 SC |
453 | |
454 | /* Set to TUI command window dimension or use readline values. */ | |
455 | sprintf (cmd, "set width %d", | |
fddb59b7 | 456 | tui_active ? TUI_CMD_WIN->generic.width : tui_term_width()); |
3e752b04 SC |
457 | execute_command (cmd, 0); |
458 | sprintf (cmd, "set height %d", | |
fddb59b7 | 459 | tui_active ? TUI_CMD_WIN->generic.height : tui_term_height()); |
3e752b04 SC |
460 | execute_command (cmd, 0); |
461 | } | |
462 | ||
c906108c | 463 | |
6d012f14 | 464 | /* Set the logical focus to win_info. */ |
c906108c | 465 | void |
6d012f14 | 466 | tui_set_win_focus_to (struct tui_win_info * win_info) |
c906108c | 467 | { |
6d012f14 | 468 | if (win_info != NULL) |
c906108c | 469 | { |
6ba8e26f | 470 | struct tui_win_info * win_with_focus = tui_win_with_focus (); |
c906108c | 471 | |
6ba8e26f AC |
472 | if (win_with_focus != NULL |
473 | && win_with_focus->generic.type != CMD_WIN) | |
474 | tui_unhighlight_win (win_with_focus); | |
6d012f14 AC |
475 | tui_set_win_with_focus (win_info); |
476 | if (win_info->generic.type != CMD_WIN) | |
477 | tui_highlight_win (win_info); | |
c906108c | 478 | } |
6ba8e26f | 479 | } |
c906108c SS |
480 | |
481 | ||
c906108c | 482 | void |
6ba8e26f | 483 | tui_scroll_forward (struct tui_win_info * win_to_scroll, int num_to_scroll) |
c906108c | 484 | { |
6ba8e26f | 485 | if (win_to_scroll != TUI_CMD_WIN) |
c906108c | 486 | { |
6ba8e26f | 487 | int _num_to_scroll = num_to_scroll; |
c906108c | 488 | |
6ba8e26f AC |
489 | if (num_to_scroll == 0) |
490 | _num_to_scroll = win_to_scroll->generic.height - 3; | |
c906108c | 491 | /* |
c5aa993b JM |
492 | ** If we are scrolling the source or disassembly window, do a |
493 | ** "psuedo" scroll since not all of the source is in memory, | |
6ba8e26f | 494 | ** only what is in the viewport. If win_to_scroll is the |
c5aa993b JM |
495 | ** command window do nothing since the term should handle it. |
496 | */ | |
6ba8e26f AC |
497 | if (win_to_scroll == TUI_SRC_WIN) |
498 | tui_vertical_source_scroll (FORWARD_SCROLL, _num_to_scroll); | |
499 | else if (win_to_scroll == TUI_DISASM_WIN) | |
500 | tui_vertical_disassem_scroll (FORWARD_SCROLL, _num_to_scroll); | |
501 | else if (win_to_scroll == TUI_DATA_WIN) | |
502 | tui_vertical_data_scroll (FORWARD_SCROLL, _num_to_scroll); | |
c906108c | 503 | } |
a21fcd8f | 504 | } |
c906108c | 505 | |
c906108c | 506 | void |
6ba8e26f | 507 | tui_scroll_backward (struct tui_win_info * win_to_scroll, int num_to_scroll) |
c906108c | 508 | { |
6ba8e26f | 509 | if (win_to_scroll != TUI_CMD_WIN) |
c906108c | 510 | { |
6ba8e26f | 511 | int _num_to_scroll = num_to_scroll; |
c906108c | 512 | |
6ba8e26f AC |
513 | if (num_to_scroll == 0) |
514 | _num_to_scroll = win_to_scroll->generic.height - 3; | |
c906108c | 515 | /* |
c5aa993b JM |
516 | ** If we are scrolling the source or disassembly window, do a |
517 | ** "psuedo" scroll since not all of the source is in memory, | |
6ba8e26f | 518 | ** only what is in the viewport. If win_to_scroll is the |
c5aa993b JM |
519 | ** command window do nothing since the term should handle it. |
520 | */ | |
6ba8e26f AC |
521 | if (win_to_scroll == TUI_SRC_WIN) |
522 | tui_vertical_source_scroll (BACKWARD_SCROLL, _num_to_scroll); | |
523 | else if (win_to_scroll == TUI_DISASM_WIN) | |
524 | tui_vertical_disassem_scroll (BACKWARD_SCROLL, _num_to_scroll); | |
525 | else if (win_to_scroll == TUI_DATA_WIN) | |
526 | tui_vertical_data_scroll (BACKWARD_SCROLL, _num_to_scroll); | |
c906108c | 527 | } |
a21fcd8f | 528 | } |
c906108c SS |
529 | |
530 | ||
c906108c | 531 | void |
6ba8e26f | 532 | tui_scroll_left (struct tui_win_info * win_to_scroll, int num_to_scroll) |
c906108c | 533 | { |
6ba8e26f | 534 | if (win_to_scroll != TUI_CMD_WIN) |
c906108c | 535 | { |
6ba8e26f | 536 | int _num_to_scroll = num_to_scroll; |
c906108c | 537 | |
6ba8e26f AC |
538 | if (_num_to_scroll == 0) |
539 | _num_to_scroll = 1; | |
c906108c | 540 | /* |
c5aa993b JM |
541 | ** If we are scrolling the source or disassembly window, do a |
542 | ** "psuedo" scroll since not all of the source is in memory, | |
6ba8e26f | 543 | ** only what is in the viewport. If win_to_scroll is the |
c5aa993b JM |
544 | ** command window do nothing since the term should handle it. |
545 | */ | |
6ba8e26f AC |
546 | if (win_to_scroll == TUI_SRC_WIN || win_to_scroll == TUI_DISASM_WIN) |
547 | tui_horizontal_source_scroll (win_to_scroll, LEFT_SCROLL, _num_to_scroll); | |
c906108c | 548 | } |
a21fcd8f | 549 | } |
c906108c SS |
550 | |
551 | ||
c906108c | 552 | void |
6ba8e26f | 553 | tui_scroll_right (struct tui_win_info * win_to_scroll, int num_to_scroll) |
c906108c | 554 | { |
6ba8e26f | 555 | if (win_to_scroll != TUI_CMD_WIN) |
c906108c | 556 | { |
6ba8e26f | 557 | int _num_to_scroll = num_to_scroll; |
c906108c | 558 | |
6ba8e26f AC |
559 | if (_num_to_scroll == 0) |
560 | _num_to_scroll = 1; | |
c906108c | 561 | /* |
c5aa993b JM |
562 | ** If we are scrolling the source or disassembly window, do a |
563 | ** "psuedo" scroll since not all of the source is in memory, | |
6ba8e26f | 564 | ** only what is in the viewport. If win_to_scroll is the |
c5aa993b JM |
565 | ** command window do nothing since the term should handle it. |
566 | */ | |
6ba8e26f AC |
567 | if (win_to_scroll == TUI_SRC_WIN || win_to_scroll == TUI_DISASM_WIN) |
568 | tui_horizontal_source_scroll (win_to_scroll, RIGHT_SCROLL, _num_to_scroll); | |
c906108c | 569 | } |
a21fcd8f | 570 | } |
c906108c SS |
571 | |
572 | ||
a21fcd8f | 573 | /* Scroll a window. Arguments are passed through a va_list. */ |
c906108c | 574 | void |
2a8854a7 | 575 | tui_scroll (enum tui_scroll_direction direction, |
6ba8e26f AC |
576 | struct tui_win_info * win_to_scroll, |
577 | int num_to_scroll) | |
c906108c | 578 | { |
c906108c SS |
579 | switch (direction) |
580 | { | |
581 | case FORWARD_SCROLL: | |
6ba8e26f | 582 | tui_scroll_forward (win_to_scroll, num_to_scroll); |
c906108c SS |
583 | break; |
584 | case BACKWARD_SCROLL: | |
6ba8e26f | 585 | tui_scroll_backward (win_to_scroll, num_to_scroll); |
c906108c SS |
586 | break; |
587 | case LEFT_SCROLL: | |
6ba8e26f | 588 | tui_scroll_left (win_to_scroll, num_to_scroll); |
c906108c SS |
589 | break; |
590 | case RIGHT_SCROLL: | |
6ba8e26f | 591 | tui_scroll_right (win_to_scroll, num_to_scroll); |
c906108c SS |
592 | break; |
593 | default: | |
594 | break; | |
595 | } | |
e8b915dc | 596 | } |
c906108c SS |
597 | |
598 | ||
c906108c | 599 | void |
a21fcd8f | 600 | tui_refresh_all_win (void) |
c906108c | 601 | { |
22940a24 | 602 | enum tui_win_type type; |
c906108c | 603 | |
3e266828 | 604 | clearok (curscr, TRUE); |
6d012f14 | 605 | tui_refresh_all (tui_win_list); |
c906108c SS |
606 | for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++) |
607 | { | |
6d012f14 | 608 | if (tui_win_list[type] && tui_win_list[type]->generic.is_visible) |
c906108c SS |
609 | { |
610 | switch (type) | |
611 | { | |
612 | case SRC_WIN: | |
613 | case DISASSEM_WIN: | |
6d012f14 AC |
614 | tui_show_source_content (tui_win_list[type]); |
615 | tui_check_and_display_highlight_if_needed (tui_win_list[type]); | |
616 | tui_erase_exec_info_content (tui_win_list[type]); | |
617 | tui_update_exec_info (tui_win_list[type]); | |
c906108c SS |
618 | break; |
619 | case DATA_WIN: | |
edae1ccf | 620 | tui_refresh_data_win (); |
c906108c SS |
621 | break; |
622 | default: | |
623 | break; | |
624 | } | |
625 | } | |
626 | } | |
47d3492a | 627 | tui_show_locator_content (); |
bc712bbf | 628 | } |
c906108c SS |
629 | |
630 | ||
6ba8e26f AC |
631 | /* Resize all the windows based on the the terminal size. This |
632 | function gets called from within the readline sinwinch handler. */ | |
c906108c | 633 | void |
6ba8e26f | 634 | tui_resize_all (void) |
c906108c | 635 | { |
6ba8e26f | 636 | int height_diff, width_diff; |
9255ee31 | 637 | int screenheight, screenwidth; |
c906108c | 638 | |
9255ee31 | 639 | rl_get_screen_size (&screenheight, &screenwidth); |
6ba8e26f AC |
640 | width_diff = screenwidth - tui_term_width (); |
641 | height_diff = screenheight - tui_term_height (); | |
642 | if (height_diff || width_diff) | |
c906108c | 643 | { |
6ba8e26f AC |
644 | enum tui_layout_type cur_layout = tui_current_layout (); |
645 | struct tui_win_info * win_with_focus = tui_win_with_focus (); | |
646 | struct tui_win_info *first_win; | |
647 | struct tui_win_info *second_win; | |
2a8854a7 | 648 | struct tui_gen_win_info * locator = tui_locator_win_info_ptr (); |
6ba8e26f AC |
649 | enum tui_win_type win_type; |
650 | int new_height, split_diff, cmd_split_diff, num_wins_displayed = 2; | |
c906108c | 651 | |
10f59415 SC |
652 | #ifdef HAVE_RESIZE_TERM |
653 | resize_term (screenheight, screenwidth); | |
654 | #endif | |
c906108c | 655 | /* turn keypad off while we resize */ |
6ba8e26f | 656 | if (win_with_focus != TUI_CMD_WIN) |
6d012f14 | 657 | keypad (TUI_CMD_WIN->generic.handle, FALSE); |
3e752b04 | 658 | tui_update_gdb_sizes (); |
dd1abb8c AC |
659 | tui_set_term_height_to (screenheight); |
660 | tui_set_term_width_to (screenwidth); | |
6ba8e26f AC |
661 | if (cur_layout == SRC_DISASSEM_COMMAND || |
662 | cur_layout == SRC_DATA_COMMAND || cur_layout == DISASSEM_DATA_COMMAND) | |
663 | num_wins_displayed++; | |
664 | split_diff = height_diff / num_wins_displayed; | |
665 | cmd_split_diff = split_diff; | |
666 | if (height_diff % num_wins_displayed) | |
c906108c | 667 | { |
6ba8e26f AC |
668 | if (height_diff < 0) |
669 | cmd_split_diff--; | |
c906108c | 670 | else |
6ba8e26f | 671 | cmd_split_diff++; |
c906108c SS |
672 | } |
673 | /* now adjust each window */ | |
674 | clear (); | |
675 | refresh (); | |
6ba8e26f | 676 | switch (cur_layout) |
c906108c SS |
677 | { |
678 | case SRC_COMMAND: | |
679 | case DISASSEM_COMMAND: | |
6ba8e26f AC |
680 | first_win = (struct tui_win_info *) (tui_source_windows ())->list[0]; |
681 | first_win->generic.width += width_diff; | |
682 | locator->width += width_diff; | |
c906108c | 683 | /* check for invalid heights */ |
6ba8e26f AC |
684 | if (height_diff == 0) |
685 | new_height = first_win->generic.height; | |
686 | else if ((first_win->generic.height + split_diff) >= | |
c906108c | 687 | (screenheight - MIN_CMD_WIN_HEIGHT - 1)) |
6ba8e26f AC |
688 | new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1; |
689 | else if ((first_win->generic.height + split_diff) <= 0) | |
690 | new_height = MIN_WIN_HEIGHT; | |
c906108c | 691 | else |
6ba8e26f | 692 | new_height = first_win->generic.height + split_diff; |
c906108c | 693 | |
6ba8e26f | 694 | make_invisible_and_set_new_height (first_win, new_height); |
6d012f14 | 695 | TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1; |
6ba8e26f AC |
696 | TUI_CMD_WIN->generic.width += width_diff; |
697 | new_height = screenheight - TUI_CMD_WIN->generic.origin.y; | |
698 | make_invisible_and_set_new_height (TUI_CMD_WIN, new_height); | |
699 | make_visible_with_new_height (first_win); | |
700 | make_visible_with_new_height (TUI_CMD_WIN); | |
701 | if (first_win->generic.content_size <= 0) | |
702 | tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT); | |
c906108c SS |
703 | break; |
704 | default: | |
6ba8e26f | 705 | if (cur_layout == SRC_DISASSEM_COMMAND) |
c906108c | 706 | { |
6ba8e26f AC |
707 | first_win = TUI_SRC_WIN; |
708 | first_win->generic.width += width_diff; | |
709 | second_win = TUI_DISASM_WIN; | |
710 | second_win->generic.width += width_diff; | |
c906108c SS |
711 | } |
712 | else | |
713 | { | |
6ba8e26f AC |
714 | first_win = TUI_DATA_WIN; |
715 | first_win->generic.width += width_diff; | |
716 | second_win = (struct tui_win_info *) (tui_source_windows ())->list[0]; | |
717 | second_win->generic.width += width_diff; | |
c906108c SS |
718 | } |
719 | /* Change the first window's height/width */ | |
720 | /* check for invalid heights */ | |
6ba8e26f AC |
721 | if (height_diff == 0) |
722 | new_height = first_win->generic.height; | |
723 | else if ((first_win->generic.height + | |
724 | second_win->generic.height + (split_diff * 2)) >= | |
c906108c | 725 | (screenheight - MIN_CMD_WIN_HEIGHT - 1)) |
6ba8e26f AC |
726 | new_height = (screenheight - MIN_CMD_WIN_HEIGHT - 1) / 2; |
727 | else if ((first_win->generic.height + split_diff) <= 0) | |
728 | new_height = MIN_WIN_HEIGHT; | |
c906108c | 729 | else |
6ba8e26f AC |
730 | new_height = first_win->generic.height + split_diff; |
731 | make_invisible_and_set_new_height (first_win, new_height); | |
c906108c | 732 | |
6ba8e26f | 733 | locator->width += width_diff; |
c906108c SS |
734 | |
735 | /* Change the second window's height/width */ | |
736 | /* check for invalid heights */ | |
6ba8e26f AC |
737 | if (height_diff == 0) |
738 | new_height = second_win->generic.height; | |
739 | else if ((first_win->generic.height + | |
740 | second_win->generic.height + (split_diff * 2)) >= | |
c906108c SS |
741 | (screenheight - MIN_CMD_WIN_HEIGHT - 1)) |
742 | { | |
6ba8e26f AC |
743 | new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1; |
744 | if (new_height % 2) | |
745 | new_height = (new_height / 2) + 1; | |
c906108c | 746 | else |
6ba8e26f | 747 | new_height /= 2; |
c906108c | 748 | } |
6ba8e26f AC |
749 | else if ((second_win->generic.height + split_diff) <= 0) |
750 | new_height = MIN_WIN_HEIGHT; | |
c906108c | 751 | else |
6ba8e26f AC |
752 | new_height = second_win->generic.height + split_diff; |
753 | second_win->generic.origin.y = first_win->generic.height - 1; | |
754 | make_invisible_and_set_new_height (second_win, new_height); | |
c906108c SS |
755 | |
756 | /* Change the command window's height/width */ | |
6d012f14 | 757 | TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1; |
6ba8e26f AC |
758 | make_invisible_and_set_new_height ( |
759 | TUI_CMD_WIN, TUI_CMD_WIN->generic.height + cmd_split_diff); | |
760 | make_visible_with_new_height (first_win); | |
761 | make_visible_with_new_height (second_win); | |
762 | make_visible_with_new_height (TUI_CMD_WIN); | |
763 | if (first_win->generic.content_size <= 0) | |
764 | tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT); | |
765 | if (second_win->generic.content_size <= 0) | |
766 | tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT); | |
c906108c SS |
767 | break; |
768 | } | |
769 | /* | |
c5aa993b JM |
770 | ** Now remove all invisible windows, and their content so that they get |
771 | ** created again when called for with the new size | |
772 | */ | |
6ba8e26f | 773 | for (win_type = SRC_WIN; (win_type < MAX_MAJOR_WINDOWS); win_type++) |
c906108c | 774 | { |
6ba8e26f AC |
775 | if (win_type != CMD_WIN && (tui_win_list[win_type] != NULL) |
776 | && !tui_win_list[win_type]->generic.is_visible) | |
c906108c | 777 | { |
6ba8e26f AC |
778 | tui_free_window (tui_win_list[win_type]); |
779 | tui_win_list[win_type] = (struct tui_win_info *) NULL; | |
c906108c SS |
780 | } |
781 | } | |
dd1abb8c | 782 | tui_set_win_resized_to (TRUE); |
c906108c | 783 | /* turn keypad back on, unless focus is in the command window */ |
6ba8e26f | 784 | if (win_with_focus != TUI_CMD_WIN) |
6d012f14 | 785 | keypad (TUI_CMD_WIN->generic.handle, TRUE); |
c906108c | 786 | } |
6ba8e26f | 787 | } |
c906108c SS |
788 | |
789 | ||
6ba8e26f AC |
790 | /* SIGWINCH signal handler for the tui. This signal handler is always |
791 | called, even when the readline package clears signals because it is | |
792 | set as the old_sigwinch() (TUI only). */ | |
c906108c | 793 | void |
6ba8e26f | 794 | tui_sigwinch_handler (int signal) |
c906108c SS |
795 | { |
796 | /* | |
c5aa993b JM |
797 | ** Say that a resize was done so that the readline can do it |
798 | ** later when appropriate. | |
799 | */ | |
dd1abb8c | 800 | tui_set_win_resized_to (TRUE); |
6ba8e26f | 801 | } |
c906108c SS |
802 | |
803 | ||
804 | ||
805 | /************************* | |
806 | ** STATIC LOCAL FUNCTIONS | |
807 | **************************/ | |
808 | ||
809 | ||
c906108c | 810 | static void |
6ba8e26f | 811 | tui_scroll_forward_command (char *arg, int from_tty) |
c906108c | 812 | { |
6ba8e26f AC |
813 | int num_to_scroll = 1; |
814 | struct tui_win_info * win_to_scroll; | |
c906108c | 815 | |
1854bb21 SC |
816 | /* Make sure the curses mode is enabled. */ |
817 | tui_enable (); | |
c906108c | 818 | if (arg == (char *) NULL) |
6ba8e26f | 819 | parse_scrolling_args (arg, &win_to_scroll, (int *) NULL); |
c906108c | 820 | else |
6ba8e26f AC |
821 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
822 | tui_scroll (FORWARD_SCROLL, win_to_scroll, num_to_scroll); | |
e8b915dc | 823 | } |
c906108c SS |
824 | |
825 | ||
c906108c | 826 | static void |
6ba8e26f | 827 | tui_scroll_backward_command (char *arg, int from_tty) |
c906108c | 828 | { |
6ba8e26f AC |
829 | int num_to_scroll = 1; |
830 | struct tui_win_info * win_to_scroll; | |
c906108c | 831 | |
1854bb21 SC |
832 | /* Make sure the curses mode is enabled. */ |
833 | tui_enable (); | |
c906108c | 834 | if (arg == (char *) NULL) |
6ba8e26f | 835 | parse_scrolling_args (arg, &win_to_scroll, (int *) NULL); |
c906108c | 836 | else |
6ba8e26f AC |
837 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
838 | tui_scroll (BACKWARD_SCROLL, win_to_scroll, num_to_scroll); | |
e8b915dc | 839 | } |
c906108c SS |
840 | |
841 | ||
c906108c | 842 | static void |
6ba8e26f | 843 | tui_scroll_left_command (char *arg, int from_tty) |
c906108c | 844 | { |
6ba8e26f AC |
845 | int num_to_scroll; |
846 | struct tui_win_info * win_to_scroll; | |
c906108c | 847 | |
1854bb21 SC |
848 | /* Make sure the curses mode is enabled. */ |
849 | tui_enable (); | |
6ba8e26f AC |
850 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
851 | tui_scroll (LEFT_SCROLL, win_to_scroll, num_to_scroll); | |
e8b915dc | 852 | } |
c906108c SS |
853 | |
854 | ||
c906108c | 855 | static void |
6ba8e26f | 856 | tui_scroll_right_command (char *arg, int from_tty) |
c906108c | 857 | { |
6ba8e26f AC |
858 | int num_to_scroll; |
859 | struct tui_win_info * win_to_scroll; | |
c906108c | 860 | |
1854bb21 SC |
861 | /* Make sure the curses mode is enabled. */ |
862 | tui_enable (); | |
6ba8e26f AC |
863 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
864 | tui_scroll (RIGHT_SCROLL, win_to_scroll, num_to_scroll); | |
e8b915dc | 865 | } |
c906108c SS |
866 | |
867 | ||
6ba8e26f | 868 | /* Set focus to the window named by 'arg'. */ |
c906108c | 869 | static void |
6ba8e26f | 870 | tui_set_focus (char *arg, int from_tty) |
c906108c SS |
871 | { |
872 | if (arg != (char *) NULL) | |
873 | { | |
6ba8e26f | 874 | char *buf_ptr = (char *) xstrdup (arg); |
c906108c | 875 | int i; |
6d012f14 | 876 | struct tui_win_info * win_info = (struct tui_win_info *) NULL; |
c906108c | 877 | |
6ba8e26f AC |
878 | for (i = 0; (i < strlen (buf_ptr)); i++) |
879 | buf_ptr[i] = toupper (arg[i]); | |
c906108c | 880 | |
6ba8e26f | 881 | if (subset_compare (buf_ptr, "NEXT")) |
6d012f14 | 882 | win_info = tui_next_win (tui_win_with_focus ()); |
6ba8e26f | 883 | else if (subset_compare (buf_ptr, "PREV")) |
6d012f14 | 884 | win_info = tui_prev_win (tui_win_with_focus ()); |
c906108c | 885 | else |
6ba8e26f | 886 | win_info = tui_partial_win_by_name (buf_ptr); |
c906108c | 887 | |
6d012f14 | 888 | if (win_info == (struct tui_win_info *) NULL || !win_info->generic.is_visible) |
8a3fe4f8 AC |
889 | warning (_("Invalid window specified. \n\ |
890 | The window name specified must be valid and visible.\n")); | |
c906108c SS |
891 | else |
892 | { | |
6d012f14 AC |
893 | tui_set_win_focus_to (win_info); |
894 | keypad (TUI_CMD_WIN->generic.handle, (win_info != TUI_CMD_WIN)); | |
c906108c SS |
895 | } |
896 | ||
6d012f14 | 897 | if (TUI_DATA_WIN && TUI_DATA_WIN->generic.is_visible) |
edae1ccf | 898 | tui_refresh_data_win (); |
6ba8e26f | 899 | xfree (buf_ptr); |
a3f17187 | 900 | printf_filtered (_("Focus set to %s window.\n"), |
2a8854a7 | 901 | tui_win_name ((struct tui_gen_win_info *) tui_win_with_focus ())); |
c906108c SS |
902 | } |
903 | else | |
8a3fe4f8 | 904 | warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE); |
6ba8e26f | 905 | } |
c906108c | 906 | |
c906108c | 907 | static void |
6ba8e26f | 908 | tui_set_focus_command (char *arg, int from_tty) |
c906108c | 909 | { |
1854bb21 SC |
910 | /* Make sure the curses mode is enabled. */ |
911 | tui_enable (); | |
6ba8e26f | 912 | tui_set_focus (arg, from_tty); |
e8b915dc | 913 | } |
c906108c SS |
914 | |
915 | ||
c906108c | 916 | static void |
6ba8e26f | 917 | tui_all_windows_info (char *arg, int from_tty) |
c906108c | 918 | { |
22940a24 | 919 | enum tui_win_type type; |
6ba8e26f | 920 | struct tui_win_info * win_with_focus = tui_win_with_focus (); |
c906108c SS |
921 | |
922 | for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++) | |
6d012f14 | 923 | if (tui_win_list[type] && tui_win_list[type]->generic.is_visible) |
c906108c | 924 | { |
6ba8e26f | 925 | if (win_with_focus == tui_win_list[type]) |
c906108c | 926 | printf_filtered (" %s\t(%d lines) <has focus>\n", |
6d012f14 AC |
927 | tui_win_name (&tui_win_list[type]->generic), |
928 | tui_win_list[type]->generic.height); | |
c906108c SS |
929 | else |
930 | printf_filtered (" %s\t(%d lines)\n", | |
6d012f14 AC |
931 | tui_win_name (&tui_win_list[type]->generic), |
932 | tui_win_list[type]->generic.height); | |
c906108c | 933 | } |
6ba8e26f | 934 | } |
c906108c SS |
935 | |
936 | ||
c906108c | 937 | static void |
6ba8e26f | 938 | tui_refresh_all_command (char *arg, int from_tty) |
c906108c | 939 | { |
1854bb21 SC |
940 | /* Make sure the curses mode is enabled. */ |
941 | tui_enable (); | |
942 | ||
a21fcd8f | 943 | tui_refresh_all_win (); |
c906108c SS |
944 | } |
945 | ||
946 | ||
6ba8e26f | 947 | /* Set the height of the specified window. */ |
c906108c | 948 | static void |
6ba8e26f | 949 | tui_set_tab_width_command (char *arg, int from_tty) |
c906108c | 950 | { |
1854bb21 SC |
951 | /* Make sure the curses mode is enabled. */ |
952 | tui_enable (); | |
c906108c SS |
953 | if (arg != (char *) NULL) |
954 | { | |
955 | int ts; | |
956 | ||
957 | ts = atoi (arg); | |
958 | if (ts > 0) | |
dd1abb8c | 959 | tui_set_default_tab_len (ts); |
c906108c | 960 | else |
8a3fe4f8 | 961 | warning (_("Tab widths greater than 0 must be specified.")); |
c906108c | 962 | } |
6ba8e26f | 963 | } |
c906108c SS |
964 | |
965 | ||
6ba8e26f | 966 | /* Set the height of the specified window. */ |
c906108c | 967 | static void |
6ba8e26f | 968 | tui_set_win_height (char *arg, int from_tty) |
c906108c | 969 | { |
1854bb21 SC |
970 | /* Make sure the curses mode is enabled. */ |
971 | tui_enable (); | |
c906108c SS |
972 | if (arg != (char *) NULL) |
973 | { | |
1854bb21 | 974 | char *buf = xstrdup (arg); |
6ba8e26f | 975 | char *buf_ptr = buf; |
c906108c | 976 | char *wname = (char *) NULL; |
6ba8e26f | 977 | int new_height, i; |
6d012f14 | 978 | struct tui_win_info * win_info; |
c906108c | 979 | |
6ba8e26f AC |
980 | wname = buf_ptr; |
981 | buf_ptr = strchr (buf_ptr, ' '); | |
982 | if (buf_ptr != (char *) NULL) | |
c906108c | 983 | { |
6ba8e26f | 984 | *buf_ptr = (char) 0; |
c906108c SS |
985 | |
986 | /* | |
c5aa993b JM |
987 | ** Validate the window name |
988 | */ | |
c906108c SS |
989 | for (i = 0; i < strlen (wname); i++) |
990 | wname[i] = toupper (wname[i]); | |
6d012f14 | 991 | win_info = tui_partial_win_by_name (wname); |
c906108c | 992 | |
6d012f14 | 993 | if (win_info == (struct tui_win_info *) NULL || !win_info->generic.is_visible) |
8a3fe4f8 AC |
994 | warning (_("Invalid window specified. \n\ |
995 | The window name specified must be valid and visible.\n")); | |
c906108c SS |
996 | else |
997 | { | |
998 | /* Process the size */ | |
6ba8e26f | 999 | while (*(++buf_ptr) == ' ') |
c906108c SS |
1000 | ; |
1001 | ||
6ba8e26f | 1002 | if (*buf_ptr != (char) 0) |
c906108c SS |
1003 | { |
1004 | int negate = FALSE; | |
6ba8e26f AC |
1005 | int fixed_size = TRUE; |
1006 | int input_no;; | |
c906108c | 1007 | |
6ba8e26f | 1008 | if (*buf_ptr == '+' || *buf_ptr == '-') |
c906108c | 1009 | { |
6ba8e26f | 1010 | if (*buf_ptr == '-') |
c906108c | 1011 | negate = TRUE; |
6ba8e26f AC |
1012 | fixed_size = FALSE; |
1013 | buf_ptr++; | |
c906108c | 1014 | } |
6ba8e26f AC |
1015 | input_no = atoi (buf_ptr); |
1016 | if (input_no > 0) | |
c906108c SS |
1017 | { |
1018 | if (negate) | |
6ba8e26f AC |
1019 | input_no *= (-1); |
1020 | if (fixed_size) | |
1021 | new_height = input_no; | |
c906108c | 1022 | else |
6ba8e26f | 1023 | new_height = win_info->generic.height + input_no; |
c906108c | 1024 | /* |
c5aa993b JM |
1025 | ** Now change the window's height, and adjust all |
1026 | ** other windows around it | |
1027 | */ | |
6ba8e26f AC |
1028 | if (tui_adjust_win_heights (win_info, |
1029 | new_height) == TUI_FAILURE) | |
8a3fe4f8 | 1030 | warning (_("Invalid window height specified.\n%s"), |
c906108c SS |
1031 | WIN_HEIGHT_USAGE); |
1032 | else | |
3e752b04 | 1033 | tui_update_gdb_sizes (); |
c906108c SS |
1034 | } |
1035 | else | |
8a3fe4f8 | 1036 | warning (_("Invalid window height specified.\n%s"), |
c906108c SS |
1037 | WIN_HEIGHT_USAGE); |
1038 | } | |
1039 | } | |
1040 | } | |
1041 | else | |
1042 | printf_filtered (WIN_HEIGHT_USAGE); | |
1043 | ||
1044 | if (buf != (char *) NULL) | |
22940a24 | 1045 | xfree (buf); |
c906108c SS |
1046 | } |
1047 | else | |
1048 | printf_filtered (WIN_HEIGHT_USAGE); | |
6ba8e26f | 1049 | } |
c906108c | 1050 | |
6ba8e26f | 1051 | /* Set the height of the specified window, with va_list. */ |
c906108c | 1052 | static void |
6ba8e26f | 1053 | tui_set_win_height_command (char *arg, int from_tty) |
c906108c | 1054 | { |
1854bb21 SC |
1055 | /* Make sure the curses mode is enabled. */ |
1056 | tui_enable (); | |
6ba8e26f | 1057 | tui_set_win_height (arg, from_tty); |
e8b915dc | 1058 | } |
c906108c SS |
1059 | |
1060 | ||
6ba8e26f AC |
1061 | /* XDB Compatibility command for setting the window height. This will |
1062 | increase or decrease the command window by the specified amount. */ | |
c906108c | 1063 | static void |
6ba8e26f | 1064 | tui_xdb_set_win_height (char *arg, int from_tty) |
c906108c | 1065 | { |
1854bb21 SC |
1066 | /* Make sure the curses mode is enabled. */ |
1067 | tui_enable (); | |
c906108c SS |
1068 | if (arg != (char *) NULL) |
1069 | { | |
6ba8e26f | 1070 | int input_no = atoi (arg); |
c906108c | 1071 | |
6ba8e26f | 1072 | if (input_no > 0) |
c906108c | 1073 | { /* Add 1 for the locator */ |
6ba8e26f | 1074 | int new_height = tui_term_height () - (input_no + 1); |
c906108c | 1075 | |
6ba8e26f AC |
1076 | if (!new_height_ok (tui_win_list[CMD_WIN], new_height) || |
1077 | tui_adjust_win_heights (tui_win_list[CMD_WIN], | |
1078 | new_height) == TUI_FAILURE) | |
8a3fe4f8 | 1079 | warning (_("Invalid window height specified.\n%s"), |
c906108c SS |
1080 | XDBWIN_HEIGHT_USAGE); |
1081 | } | |
1082 | else | |
8a3fe4f8 | 1083 | warning (_("Invalid window height specified.\n%s"), |
c906108c SS |
1084 | XDBWIN_HEIGHT_USAGE); |
1085 | } | |
1086 | else | |
8a3fe4f8 | 1087 | warning (_("Invalid window height specified.\n%s"), XDBWIN_HEIGHT_USAGE); |
6ba8e26f | 1088 | } |
c906108c | 1089 | |
6ba8e26f | 1090 | /* Set the height of the specified window, with va_list. */ |
c906108c | 1091 | static void |
6ba8e26f | 1092 | tui_xdb_set_win_height_command (char *arg, int from_tty) |
c906108c | 1093 | { |
6ba8e26f | 1094 | tui_xdb_set_win_height (arg, from_tty); |
e8b915dc | 1095 | } |
c906108c SS |
1096 | |
1097 | ||
6ba8e26f | 1098 | /* Function to adjust all window heights around the primary. */ |
22940a24 | 1099 | static enum tui_status |
6ba8e26f | 1100 | tui_adjust_win_heights (struct tui_win_info * primary_win_info, int new_height) |
c906108c | 1101 | { |
22940a24 | 1102 | enum tui_status status = TUI_FAILURE; |
c906108c | 1103 | |
6ba8e26f | 1104 | if (new_height_ok (primary_win_info, new_height)) |
c906108c SS |
1105 | { |
1106 | status = TUI_SUCCESS; | |
6ba8e26f | 1107 | if (new_height != primary_win_info->generic.height) |
c906108c | 1108 | { |
bc712bbf | 1109 | int diff; |
6d012f14 | 1110 | struct tui_win_info * win_info; |
2a8854a7 | 1111 | struct tui_gen_win_info * locator = tui_locator_win_info_ptr (); |
6ba8e26f | 1112 | enum tui_layout_type cur_layout = tui_current_layout (); |
c906108c | 1113 | |
6ba8e26f AC |
1114 | diff = (new_height - primary_win_info->generic.height) * (-1); |
1115 | if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND) | |
c906108c | 1116 | { |
6ba8e26f | 1117 | struct tui_win_info * src_win_info; |
c906108c | 1118 | |
6ba8e26f AC |
1119 | make_invisible_and_set_new_height (primary_win_info, new_height); |
1120 | if (primary_win_info->generic.type == CMD_WIN) | |
c906108c | 1121 | { |
6d012f14 | 1122 | win_info = (struct tui_win_info *) (tui_source_windows ())->list[0]; |
6ba8e26f | 1123 | src_win_info = win_info; |
c906108c SS |
1124 | } |
1125 | else | |
1126 | { | |
6d012f14 | 1127 | win_info = tui_win_list[CMD_WIN]; |
6ba8e26f | 1128 | src_win_info = primary_win_info; |
c906108c | 1129 | } |
6ba8e26f | 1130 | make_invisible_and_set_new_height (win_info, |
6d012f14 AC |
1131 | win_info->generic.height + diff); |
1132 | TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1; | |
6ba8e26f AC |
1133 | make_visible_with_new_height (win_info); |
1134 | make_visible_with_new_height (primary_win_info); | |
1135 | if (src_win_info->generic.content_size <= 0) | |
1136 | tui_erase_source_content (src_win_info, EMPTY_SOURCE_PROMPT); | |
c906108c SS |
1137 | } |
1138 | else | |
1139 | { | |
6ba8e26f AC |
1140 | struct tui_win_info *first_win; |
1141 | struct tui_win_info *second_win; | |
c906108c | 1142 | |
6ba8e26f | 1143 | if (cur_layout == SRC_DISASSEM_COMMAND) |
c906108c | 1144 | { |
6ba8e26f AC |
1145 | first_win = TUI_SRC_WIN; |
1146 | second_win = TUI_DISASM_WIN; | |
c906108c SS |
1147 | } |
1148 | else | |
1149 | { | |
6ba8e26f AC |
1150 | first_win = TUI_DATA_WIN; |
1151 | second_win = (struct tui_win_info *) (tui_source_windows ())->list[0]; | |
c906108c | 1152 | } |
6ba8e26f | 1153 | if (primary_win_info == TUI_CMD_WIN) |
c906108c | 1154 | { /* |
c5aa993b JM |
1155 | ** Split the change in height accross the 1st & 2nd windows |
1156 | ** adjusting them as well. | |
1157 | */ | |
6ba8e26f AC |
1158 | int first_split_diff = diff / 2; /* subtract the locator */ |
1159 | int second_split_diff = first_split_diff; | |
c906108c SS |
1160 | |
1161 | if (diff % 2) | |
1162 | { | |
6ba8e26f AC |
1163 | if (first_win->generic.height > |
1164 | second_win->generic.height) | |
c906108c | 1165 | if (diff < 0) |
6ba8e26f | 1166 | first_split_diff--; |
c906108c | 1167 | else |
6ba8e26f | 1168 | first_split_diff++; |
c906108c SS |
1169 | else |
1170 | { | |
1171 | if (diff < 0) | |
6ba8e26f | 1172 | second_split_diff--; |
c906108c | 1173 | else |
6ba8e26f | 1174 | second_split_diff++; |
c906108c SS |
1175 | } |
1176 | } | |
1177 | /* make sure that the minimum hieghts are honored */ | |
6ba8e26f | 1178 | while ((first_win->generic.height + first_split_diff) < 3) |
c906108c | 1179 | { |
6ba8e26f AC |
1180 | first_split_diff++; |
1181 | second_split_diff--; | |
c906108c | 1182 | } |
6ba8e26f | 1183 | while ((second_win->generic.height + second_split_diff) < 3) |
c906108c | 1184 | { |
6ba8e26f AC |
1185 | second_split_diff++; |
1186 | first_split_diff--; | |
c906108c | 1187 | } |
6ba8e26f AC |
1188 | make_invisible_and_set_new_height ( |
1189 | first_win, | |
1190 | first_win->generic.height + first_split_diff); | |
1191 | second_win->generic.origin.y = first_win->generic.height - 1; | |
1192 | make_invisible_and_set_new_height ( | |
1193 | second_win, second_win->generic.height + second_split_diff); | |
6d012f14 | 1194 | TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1; |
6ba8e26f | 1195 | make_invisible_and_set_new_height (TUI_CMD_WIN, new_height); |
c906108c SS |
1196 | } |
1197 | else | |
1198 | { | |
6d012f14 | 1199 | if ((TUI_CMD_WIN->generic.height + diff) < 1) |
c906108c | 1200 | { /* |
c5aa993b JM |
1201 | ** If there is no way to increase the command window |
1202 | ** take real estate from the 1st or 2nd window. | |
1203 | */ | |
6d012f14 | 1204 | if ((TUI_CMD_WIN->generic.height + diff) < 1) |
c906108c SS |
1205 | { |
1206 | int i; | |
6d012f14 | 1207 | for (i = TUI_CMD_WIN->generic.height + diff; |
c906108c | 1208 | (i < 1); i++) |
6ba8e26f AC |
1209 | if (primary_win_info == first_win) |
1210 | second_win->generic.height--; | |
c906108c | 1211 | else |
6ba8e26f | 1212 | first_win->generic.height--; |
c906108c SS |
1213 | } |
1214 | } | |
6ba8e26f AC |
1215 | if (primary_win_info == first_win) |
1216 | make_invisible_and_set_new_height (first_win, new_height); | |
c906108c | 1217 | else |
6ba8e26f AC |
1218 | make_invisible_and_set_new_height ( |
1219 | first_win, | |
1220 | first_win->generic.height); | |
1221 | second_win->generic.origin.y = first_win->generic.height - 1; | |
1222 | if (primary_win_info == second_win) | |
1223 | make_invisible_and_set_new_height (second_win, new_height); | |
c906108c | 1224 | else |
6ba8e26f AC |
1225 | make_invisible_and_set_new_height ( |
1226 | second_win, second_win->generic.height); | |
6d012f14 AC |
1227 | TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1; |
1228 | if ((TUI_CMD_WIN->generic.height + diff) < 1) | |
6ba8e26f | 1229 | make_invisible_and_set_new_height (TUI_CMD_WIN, 1); |
c906108c | 1230 | else |
6ba8e26f | 1231 | make_invisible_and_set_new_height ( |
6d012f14 | 1232 | TUI_CMD_WIN, TUI_CMD_WIN->generic.height + diff); |
c906108c | 1233 | } |
6ba8e26f AC |
1234 | make_visible_with_new_height (TUI_CMD_WIN); |
1235 | make_visible_with_new_height (second_win); | |
1236 | make_visible_with_new_height (first_win); | |
1237 | if (first_win->generic.content_size <= 0) | |
1238 | tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT); | |
1239 | if (second_win->generic.content_size <= 0) | |
1240 | tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT); | |
c906108c SS |
1241 | } |
1242 | } | |
1243 | } | |
1244 | ||
1245 | return status; | |
6ba8e26f | 1246 | } |
c906108c SS |
1247 | |
1248 | ||
6ba8e26f AC |
1249 | /* Function make the target window (and auxillary windows associated |
1250 | with the targer) invisible, and set the new height and location. */ | |
c906108c | 1251 | static void |
6ba8e26f | 1252 | make_invisible_and_set_new_height (struct tui_win_info * win_info, int height) |
c906108c SS |
1253 | { |
1254 | int i; | |
6ba8e26f | 1255 | struct tui_gen_win_info * gen_win_info; |
c906108c | 1256 | |
6d012f14 AC |
1257 | tui_make_invisible (&win_info->generic); |
1258 | win_info->generic.height = height; | |
c906108c | 1259 | if (height > 1) |
6d012f14 | 1260 | win_info->generic.viewport_height = height - 1; |
c906108c | 1261 | else |
6d012f14 AC |
1262 | win_info->generic.viewport_height = height; |
1263 | if (win_info != TUI_CMD_WIN) | |
1264 | win_info->generic.viewport_height--; | |
c906108c | 1265 | |
6d012f14 AC |
1266 | /* Now deal with the auxillary windows associated with win_info */ |
1267 | switch (win_info->generic.type) | |
c906108c SS |
1268 | { |
1269 | case SRC_WIN: | |
1270 | case DISASSEM_WIN: | |
6ba8e26f AC |
1271 | gen_win_info = win_info->detail.source_info.execution_info; |
1272 | tui_make_invisible (gen_win_info); | |
1273 | gen_win_info->height = height; | |
1274 | gen_win_info->origin.y = win_info->generic.origin.y; | |
c906108c | 1275 | if (height > 1) |
6ba8e26f | 1276 | gen_win_info->viewport_height = height - 1; |
c906108c | 1277 | else |
6ba8e26f | 1278 | gen_win_info->viewport_height = height; |
6d012f14 | 1279 | if (win_info != TUI_CMD_WIN) |
6ba8e26f | 1280 | gen_win_info->viewport_height--; |
c906108c | 1281 | |
6d012f14 | 1282 | if (tui_win_has_locator (win_info)) |
c906108c | 1283 | { |
6ba8e26f AC |
1284 | gen_win_info = tui_locator_win_info_ptr (); |
1285 | tui_make_invisible (gen_win_info); | |
1286 | gen_win_info->origin.y = win_info->generic.origin.y + height; | |
c906108c SS |
1287 | } |
1288 | break; | |
1289 | case DATA_WIN: | |
1290 | /* delete all data item windows */ | |
6d012f14 | 1291 | for (i = 0; i < win_info->generic.content_size; i++) |
c906108c | 1292 | { |
6ba8e26f | 1293 | gen_win_info = (struct tui_gen_win_info *) & ((struct tui_win_element *) |
6d012f14 | 1294 | win_info->generic.content[i])->which_element.data_window; |
6ba8e26f AC |
1295 | tui_delete_win (gen_win_info->handle); |
1296 | gen_win_info->handle = (WINDOW *) NULL; | |
c906108c SS |
1297 | } |
1298 | break; | |
1299 | default: | |
1300 | break; | |
1301 | } | |
bc712bbf | 1302 | } |
c906108c SS |
1303 | |
1304 | ||
6ba8e26f AC |
1305 | /* Function to make the windows with new heights visible. This means |
1306 | re-creating the windows' content since the window had to be | |
1307 | destroyed to be made invisible. */ | |
c906108c | 1308 | static void |
6ba8e26f | 1309 | make_visible_with_new_height (struct tui_win_info * win_info) |
c906108c | 1310 | { |
c906108c SS |
1311 | struct symtab *s; |
1312 | ||
6d012f14 AC |
1313 | tui_make_visible (&win_info->generic); |
1314 | tui_check_and_display_highlight_if_needed (win_info); | |
1315 | switch (win_info->generic.type) | |
c906108c SS |
1316 | { |
1317 | case SRC_WIN: | |
1318 | case DISASSEM_WIN: | |
6d012f14 AC |
1319 | tui_free_win_content (win_info->detail.source_info.execution_info); |
1320 | tui_make_visible (win_info->detail.source_info.execution_info); | |
1321 | if (win_info->generic.content != NULL) | |
c906108c | 1322 | { |
362c05fe | 1323 | struct tui_line_or_address line_or_addr; |
52575520 EZ |
1324 | struct symtab_and_line cursal |
1325 | = get_current_source_symtab_and_line (); | |
c906108c | 1326 | |
362c05fe | 1327 | line_or_addr = win_info->detail.source_info.start_line_or_addr; |
6d012f14 | 1328 | tui_free_win_content (&win_info->generic); |
6ba8e26f | 1329 | tui_update_source_window (win_info, cursal.symtab, line_or_addr, TRUE); |
c906108c | 1330 | } |
6e7f8b9c | 1331 | else if (deprecated_selected_frame != (struct frame_info *) NULL) |
c906108c | 1332 | { |
362c05fe | 1333 | struct tui_line_or_address line; |
52575520 EZ |
1334 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
1335 | ||
c906108c | 1336 | |
f70a7d61 | 1337 | s = find_pc_symtab (get_frame_pc (deprecated_selected_frame)); |
6d012f14 | 1338 | if (win_info->generic.type == SRC_WIN) |
362c05fe AS |
1339 | { |
1340 | line.loa = LOA_LINE; | |
1341 | line.u.line_no = cursal.line; | |
1342 | } | |
c906108c | 1343 | else |
84b1e7c7 | 1344 | { |
362c05fe AS |
1345 | line.loa = LOA_ADDRESS; |
1346 | find_line_pc (s, cursal.line, &line.u.addr); | |
84b1e7c7 | 1347 | } |
6d012f14 | 1348 | tui_update_source_window (win_info, s, line, TRUE); |
c906108c | 1349 | } |
6d012f14 | 1350 | if (tui_win_has_locator (win_info)) |
c906108c | 1351 | { |
dd1abb8c | 1352 | tui_make_visible (tui_locator_win_info_ptr ()); |
47d3492a | 1353 | tui_show_locator_content (); |
c906108c SS |
1354 | } |
1355 | break; | |
1356 | case DATA_WIN: | |
edae1ccf | 1357 | tui_display_all_data (); |
c906108c SS |
1358 | break; |
1359 | case CMD_WIN: | |
6d012f14 AC |
1360 | win_info->detail.command_info.cur_line = 0; |
1361 | win_info->detail.command_info.curch = 0; | |
1362 | wmove (win_info->generic.handle, | |
1363 | win_info->detail.command_info.cur_line, | |
1364 | win_info->detail.command_info.curch); | |
c906108c SS |
1365 | break; |
1366 | default: | |
1367 | break; | |
1368 | } | |
6ba8e26f | 1369 | } |
c906108c SS |
1370 | |
1371 | ||
1372 | static int | |
6ba8e26f | 1373 | new_height_ok (struct tui_win_info * primary_win_info, int new_height) |
c906108c | 1374 | { |
6ba8e26f | 1375 | int ok = (new_height < tui_term_height ()); |
c906108c SS |
1376 | |
1377 | if (ok) | |
1378 | { | |
bc712bbf | 1379 | int diff; |
6d012f14 | 1380 | enum tui_layout_type cur_layout = tui_current_layout (); |
c906108c | 1381 | |
6ba8e26f | 1382 | diff = (new_height - primary_win_info->generic.height) * (-1); |
6d012f14 | 1383 | if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND) |
c906108c | 1384 | { |
6ba8e26f AC |
1385 | ok = ((primary_win_info->generic.type == CMD_WIN && |
1386 | new_height <= (tui_term_height () - 4) && | |
1387 | new_height >= MIN_CMD_WIN_HEIGHT) || | |
1388 | (primary_win_info->generic.type != CMD_WIN && | |
1389 | new_height <= (tui_term_height () - 2) && | |
1390 | new_height >= MIN_WIN_HEIGHT)); | |
c906108c SS |
1391 | if (ok) |
1392 | { /* check the total height */ | |
6d012f14 | 1393 | struct tui_win_info * win_info; |
c906108c | 1394 | |
6ba8e26f | 1395 | if (primary_win_info == TUI_CMD_WIN) |
6d012f14 | 1396 | win_info = (struct tui_win_info *) (tui_source_windows ())->list[0]; |
c906108c | 1397 | else |
6d012f14 | 1398 | win_info = TUI_CMD_WIN; |
6ba8e26f | 1399 | ok = ((new_height + |
6d012f14 | 1400 | (win_info->generic.height + diff)) <= tui_term_height ()); |
c906108c SS |
1401 | } |
1402 | } | |
1403 | else | |
1404 | { | |
6ba8e26f AC |
1405 | int cur_total_height, total_height, min_height = 0; |
1406 | struct tui_win_info *first_win; | |
1407 | struct tui_win_info *second_win; | |
c906108c | 1408 | |
6d012f14 | 1409 | if (cur_layout == SRC_DISASSEM_COMMAND) |
c906108c | 1410 | { |
6ba8e26f AC |
1411 | first_win = TUI_SRC_WIN; |
1412 | second_win = TUI_DISASM_WIN; | |
c906108c SS |
1413 | } |
1414 | else | |
1415 | { | |
6ba8e26f AC |
1416 | first_win = TUI_DATA_WIN; |
1417 | second_win = (struct tui_win_info *) (tui_source_windows ())->list[0]; | |
c906108c SS |
1418 | } |
1419 | /* | |
c5aa993b JM |
1420 | ** We could simply add all the heights to obtain the same result |
1421 | ** but below is more explicit since we subtract 1 for the | |
1422 | ** line that the first and second windows share, and add one | |
1423 | ** for the locator. | |
1424 | */ | |
6ba8e26f AC |
1425 | total_height = cur_total_height = |
1426 | (first_win->generic.height + second_win->generic.height - 1) | |
6d012f14 | 1427 | + TUI_CMD_WIN->generic.height + 1 /*locator */ ; |
6ba8e26f | 1428 | if (primary_win_info == TUI_CMD_WIN) |
c906108c SS |
1429 | { |
1430 | /* locator included since first & second win share a line */ | |
6ba8e26f AC |
1431 | ok = ((first_win->generic.height + |
1432 | second_win->generic.height + diff) >= | |
c906108c | 1433 | (MIN_WIN_HEIGHT * 2) && |
6ba8e26f | 1434 | new_height >= MIN_CMD_WIN_HEIGHT); |
c906108c SS |
1435 | if (ok) |
1436 | { | |
6ba8e26f AC |
1437 | total_height = new_height + (first_win->generic.height + |
1438 | second_win->generic.height + diff); | |
1439 | min_height = MIN_CMD_WIN_HEIGHT; | |
c906108c SS |
1440 | } |
1441 | } | |
1442 | else | |
1443 | { | |
6ba8e26f | 1444 | min_height = MIN_WIN_HEIGHT; |
c906108c | 1445 | /* |
c5aa993b JM |
1446 | ** First see if we can increase/decrease the command |
1447 | ** window. And make sure that the command window is | |
1448 | ** at least 1 line | |
1449 | */ | |
6d012f14 | 1450 | ok = ((TUI_CMD_WIN->generic.height + diff) > 0); |
c906108c SS |
1451 | if (!ok) |
1452 | { /* | |
c5aa993b JM |
1453 | ** Looks like we have to increase/decrease one of |
1454 | ** the other windows | |
1455 | */ | |
6ba8e26f AC |
1456 | if (primary_win_info == first_win) |
1457 | ok = (second_win->generic.height + diff) >= min_height; | |
c906108c | 1458 | else |
6ba8e26f | 1459 | ok = (first_win->generic.height + diff) >= min_height; |
c906108c SS |
1460 | } |
1461 | if (ok) | |
1462 | { | |
6ba8e26f AC |
1463 | if (primary_win_info == first_win) |
1464 | total_height = new_height + | |
1465 | second_win->generic.height + | |
6d012f14 | 1466 | TUI_CMD_WIN->generic.height + diff; |
c906108c | 1467 | else |
6ba8e26f AC |
1468 | total_height = new_height + |
1469 | first_win->generic.height + | |
6d012f14 | 1470 | TUI_CMD_WIN->generic.height + diff; |
c906108c SS |
1471 | } |
1472 | } | |
1473 | /* | |
c5aa993b JM |
1474 | ** Now make sure that the proposed total height doesn't exceed |
1475 | ** the old total height. | |
1476 | */ | |
c906108c | 1477 | if (ok) |
6ba8e26f | 1478 | ok = (new_height >= min_height && total_height <= cur_total_height); |
c906108c SS |
1479 | } |
1480 | } | |
1481 | ||
1482 | return ok; | |
6ba8e26f | 1483 | } |
c906108c SS |
1484 | |
1485 | ||
c906108c | 1486 | static void |
6ba8e26f AC |
1487 | parse_scrolling_args (char *arg, struct tui_win_info * * win_to_scroll, |
1488 | int *num_to_scroll) | |
c906108c | 1489 | { |
6ba8e26f AC |
1490 | if (num_to_scroll) |
1491 | *num_to_scroll = 0; | |
1492 | *win_to_scroll = tui_win_with_focus (); | |
c906108c SS |
1493 | |
1494 | /* | |
c5aa993b JM |
1495 | ** First set up the default window to scroll, in case there is no |
1496 | ** window name arg | |
1497 | */ | |
c906108c SS |
1498 | if (arg != (char *) NULL) |
1499 | { | |
6ba8e26f | 1500 | char *buf, *buf_ptr; |
c906108c SS |
1501 | |
1502 | /* process the number of lines to scroll */ | |
6ba8e26f AC |
1503 | buf = buf_ptr = xstrdup (arg); |
1504 | if (isdigit (*buf_ptr)) | |
c906108c | 1505 | { |
6ba8e26f | 1506 | char *num_str; |
c906108c | 1507 | |
6ba8e26f AC |
1508 | num_str = buf_ptr; |
1509 | buf_ptr = strchr (buf_ptr, ' '); | |
1510 | if (buf_ptr != (char *) NULL) | |
c906108c | 1511 | { |
6ba8e26f AC |
1512 | *buf_ptr = (char) 0; |
1513 | if (num_to_scroll) | |
1514 | *num_to_scroll = atoi (num_str); | |
1515 | buf_ptr++; | |
c906108c | 1516 | } |
6ba8e26f AC |
1517 | else if (num_to_scroll) |
1518 | *num_to_scroll = atoi (num_str); | |
c906108c SS |
1519 | } |
1520 | ||
1521 | /* process the window name if one is specified */ | |
6ba8e26f | 1522 | if (buf_ptr != (char *) NULL) |
c906108c SS |
1523 | { |
1524 | char *wname; | |
1525 | int i; | |
1526 | ||
6ba8e26f AC |
1527 | if (*buf_ptr == ' ') |
1528 | while (*(++buf_ptr) == ' ') | |
c906108c SS |
1529 | ; |
1530 | ||
6ba8e26f AC |
1531 | if (*buf_ptr != (char) 0) |
1532 | wname = buf_ptr; | |
a4b99e53 SC |
1533 | else |
1534 | wname = "?"; | |
1535 | ||
c906108c SS |
1536 | /* Validate the window name */ |
1537 | for (i = 0; i < strlen (wname); i++) | |
1538 | wname[i] = toupper (wname[i]); | |
6ba8e26f | 1539 | *win_to_scroll = tui_partial_win_by_name (wname); |
c906108c | 1540 | |
6ba8e26f AC |
1541 | if (*win_to_scroll == (struct tui_win_info *) NULL || |
1542 | !(*win_to_scroll)->generic.is_visible) | |
ec502284 | 1543 | error (_("Invalid window specified. \n\ |
8a3fe4f8 | 1544 | The window name specified must be valid and visible.\n")); |
6ba8e26f AC |
1545 | else if (*win_to_scroll == TUI_CMD_WIN) |
1546 | *win_to_scroll = (struct tui_win_info *) (tui_source_windows ())->list[0]; | |
c906108c | 1547 | } |
22940a24 | 1548 | xfree (buf); |
c906108c | 1549 | } |
6ba8e26f | 1550 | } |