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