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