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