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