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