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