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