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