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