1 /* TUI window generic functions.
3 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007
4 Free Software Foundation, Inc.
6 Contributed by Hewlett-Packard Company.
8 This file is part of GDB.
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 3 of the License, or
13 (at your option) any later version.
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.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 /* This module contains procedures for handling tui window functions
24 like resize, scrolling, scrolling, changing focus, etc.
26 Author: Susan B. Macchia */
31 #include "breakpoint.h"
33 #include "cli/cli-cmds.h"
38 #include "tui/tui-data.h"
39 #include "tui/tui-wingeneral.h"
40 #include "tui/tui-stack.h"
41 #include "tui/tui-regs.h"
42 #include "tui/tui-disasm.h"
43 #include "tui/tui-source.h"
44 #include "tui/tui-winsource.h"
45 #include "tui/tui-windata.h"
47 #include "gdb_curses.h"
49 #include "gdb_string.h"
51 #include "readline/readline.h"
53 /*******************************
55 ********************************/
56 static void make_visible_with_new_height (struct tui_win_info
*);
57 static void make_invisible_and_set_new_height (struct tui_win_info
*,
59 static enum tui_status
tui_adjust_win_heights (struct tui_win_info
*,
61 static int new_height_ok (struct tui_win_info
*, int);
62 static void tui_set_tab_width_command (char *, int);
63 static void tui_refresh_all_command (char *, int);
64 static void tui_set_win_height_command (char *, int);
65 static void tui_xdb_set_win_height_command (char *, int);
66 static void tui_all_windows_info (char *, int);
67 static void tui_set_focus_command (char *, int);
68 static void tui_scroll_forward_command (char *, int);
69 static void tui_scroll_backward_command (char *, int);
70 static void tui_scroll_left_command (char *, int);
71 static void tui_scroll_right_command (char *, int);
72 static void parse_scrolling_args (char *,
73 struct tui_win_info
**,
77 /***************************************
79 ***************************************/
80 #define WIN_HEIGHT_USAGE "Usage: winheight <win_name> [+ | -] <#lines>\n"
81 #define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n"
82 #define FOCUS_USAGE "Usage: focus {<win> | next | prev}\n"
84 /***************************************
86 ***************************************/
89 # define ACS_LRCORNER '+'
92 # define ACS_LLCORNER '+'
95 # define ACS_ULCORNER '+'
98 # define ACS_URCORNER '+'
101 # define ACS_HLINE '-'
104 # define ACS_VLINE '|'
107 /* Possible values for tui-border-kind variable. */
108 static const char *tui_border_kind_enums
[] = {
115 /* Possible values for tui-border-mode and tui-active-border-mode. */
116 static const char *tui_border_mode_enums
[] = {
133 /* Translation table for border-mode variables.
134 The list of values must be terminated by a NULL.
135 After the NULL value, an entry defines the default. */
136 struct tui_translate tui_border_mode_translate
[] = {
137 { "normal", A_NORMAL
},
138 { "standout", A_STANDOUT
},
139 { "reverse", A_REVERSE
},
141 { "half-standout", A_DIM
| A_STANDOUT
},
143 { "bold-standout", A_BOLD
| A_STANDOUT
},
145 { "normal", A_NORMAL
}
148 /* Translation tables for border-kind, one for each border
149 character (see wborder, border curses operations).
150 -1 is used to indicate the ACS because ACS characters
151 are determined at run time by curses (depends on terminal). */
152 struct tui_translate tui_border_kind_translate_vline
[] = {
160 struct tui_translate tui_border_kind_translate_hline
[] = {
168 struct tui_translate tui_border_kind_translate_ulcorner
[] = {
176 struct tui_translate tui_border_kind_translate_urcorner
[] = {
184 struct tui_translate tui_border_kind_translate_llcorner
[] = {
192 struct tui_translate tui_border_kind_translate_lrcorner
[] = {
201 /* Tui configuration variables controlled with set/show command. */
202 const char *tui_active_border_mode
= "bold-standout";
204 show_tui_active_border_mode (struct ui_file
*file
,
206 struct cmd_list_element
*c
,
209 fprintf_filtered (file
, _("\
210 The attribute mode to use for the active TUI window border is \"%s\".\n"),
214 const char *tui_border_mode
= "normal";
216 show_tui_border_mode (struct ui_file
*file
,
218 struct cmd_list_element
*c
,
221 fprintf_filtered (file
, _("\
222 The attribute mode to use for the TUI window borders is \"%s\".\n"),
226 const char *tui_border_kind
= "acs";
228 show_tui_border_kind (struct ui_file
*file
,
230 struct cmd_list_element
*c
,
233 fprintf_filtered (file
, _("The kind of border for TUI windows is \"%s\".\n"),
238 /* Tui internal configuration variables. These variables are updated
239 by tui_update_variables to reflect the tui configuration
241 chtype tui_border_vline
;
242 chtype tui_border_hline
;
243 chtype tui_border_ulcorner
;
244 chtype tui_border_urcorner
;
245 chtype tui_border_llcorner
;
246 chtype tui_border_lrcorner
;
248 int tui_border_attrs
;
249 int tui_active_border_attrs
;
251 /* Identify the item in the translation table.
252 When the item is not recognized, use the default entry. */
253 static struct tui_translate
*
254 translate (const char *name
, struct tui_translate
*table
)
258 if (name
&& strcmp (table
->name
, name
) == 0)
263 /* Not found, return default entry. */
268 /* Update the tui internal configuration according to gdb settings.
269 Returns 1 if the configuration has changed and the screen should
272 tui_update_variables (void)
275 struct tui_translate
*entry
;
277 entry
= translate (tui_border_mode
, tui_border_mode_translate
);
278 if (tui_border_attrs
!= entry
->value
)
280 tui_border_attrs
= entry
->value
;
283 entry
= translate (tui_active_border_mode
, tui_border_mode_translate
);
284 if (tui_active_border_attrs
!= entry
->value
)
286 tui_active_border_attrs
= entry
->value
;
290 /* If one corner changes, all characters are changed.
291 Only check the first one. The ACS characters are determined at
292 run time by curses terminal management. */
293 entry
= translate (tui_border_kind
, tui_border_kind_translate_lrcorner
);
294 if (tui_border_lrcorner
!= (chtype
) entry
->value
)
296 tui_border_lrcorner
= (entry
->value
< 0) ? ACS_LRCORNER
: entry
->value
;
299 entry
= translate (tui_border_kind
, tui_border_kind_translate_llcorner
);
300 tui_border_llcorner
= (entry
->value
< 0) ? ACS_LLCORNER
: entry
->value
;
302 entry
= translate (tui_border_kind
, tui_border_kind_translate_ulcorner
);
303 tui_border_ulcorner
= (entry
->value
< 0) ? ACS_ULCORNER
: entry
->value
;
305 entry
= translate (tui_border_kind
, tui_border_kind_translate_urcorner
);
306 tui_border_urcorner
= (entry
->value
< 0) ? ACS_URCORNER
: entry
->value
;
308 entry
= translate (tui_border_kind
, tui_border_kind_translate_hline
);
309 tui_border_hline
= (entry
->value
< 0) ? ACS_HLINE
: entry
->value
;
311 entry
= translate (tui_border_kind
, tui_border_kind_translate_vline
);
312 tui_border_vline
= (entry
->value
< 0) ? ACS_VLINE
: entry
->value
;
318 set_tui_cmd (char *args
, int from_tty
)
323 show_tui_cmd (char *args
, int from_tty
)
327 static struct cmd_list_element
*tuilist
;
330 tui_command (char *args
, int from_tty
)
332 printf_unfiltered (_("\"tui\" must be followed by the name of a "
334 help_list (tuilist
, "tui ", -1, gdb_stdout
);
337 struct cmd_list_element
**
338 tui_get_cmd_list (void)
341 add_prefix_cmd ("tui", class_tui
, tui_command
,
342 _("Text User Interface commands."),
343 &tuilist
, "tui ", 0, &cmdlist
);
347 /* Function to initialize gdb commands, for tui window
350 _initialize_tui_win (void)
352 struct cmd_list_element
*c
;
353 static struct cmd_list_element
*tui_setlist
;
354 static struct cmd_list_element
*tui_showlist
;
356 /* Define the classes of commands.
357 They will appear in the help list in the reverse of this order. */
358 add_prefix_cmd ("tui", class_tui
, set_tui_cmd
,
359 _("TUI configuration variables"),
360 &tui_setlist
, "set tui ",
361 0 /* allow-unknown */, &setlist
);
362 add_prefix_cmd ("tui", class_tui
, show_tui_cmd
,
363 _("TUI configuration variables"),
364 &tui_showlist
, "show tui ",
365 0 /* allow-unknown */, &showlist
);
367 add_com ("refresh", class_tui
, tui_refresh_all_command
,
368 _("Refresh the terminal display.\n"));
370 add_com_alias ("U", "refresh", class_tui
, 0);
371 add_com ("tabset", class_tui
, tui_set_tab_width_command
, _("\
372 Set the width (in characters) of tab stops.\n\
373 Usage: tabset <n>\n"));
374 add_com ("winheight", class_tui
, tui_set_win_height_command
, _("\
375 Set the height of a specified window.\n\
376 Usage: winheight <win_name> [+ | -] <#lines>\n\
378 src : the source window\n\
379 cmd : the command window\n\
380 asm : the disassembly window\n\
381 regs : the register display\n"));
382 add_com_alias ("wh", "winheight", class_tui
, 0);
383 add_info ("win", tui_all_windows_info
,
384 _("List of all displayed windows.\n"));
385 add_com ("focus", class_tui
, tui_set_focus_command
, _("\
386 Set focus to named window or next/prev window.\n\
387 Usage: focus {<win> | next | prev}\n\
388 Valid Window names are:\n\
389 src : the source window\n\
390 asm : the disassembly window\n\
391 regs : the register display\n\
392 cmd : the command window\n"));
393 add_com_alias ("fs", "focus", class_tui
, 0);
394 add_com ("+", class_tui
, tui_scroll_forward_command
, _("\
395 Scroll window forward.\n\
396 Usage: + [win] [n]\n"));
397 add_com ("-", class_tui
, tui_scroll_backward_command
, _("\
398 Scroll window backward.\n\
399 Usage: - [win] [n]\n"));
400 add_com ("<", class_tui
, tui_scroll_left_command
, _("\
401 Scroll window forward.\n\
402 Usage: < [win] [n]\n"));
403 add_com (">", class_tui
, tui_scroll_right_command
, _("\
404 Scroll window backward.\n\
405 Usage: > [win] [n]\n"));
407 add_com ("w", class_xdb
, tui_xdb_set_win_height_command
, _("\
408 XDB compatibility command for setting the height of a command window.\n\
409 Usage: w <#lines>\n"));
411 /* Define the tui control variables. */
412 add_setshow_enum_cmd ("border-kind", no_class
, tui_border_kind_enums
,
413 &tui_border_kind
, _("\
414 Set the kind of border for TUI windows."), _("\
415 Show the kind of border for TUI windows."), _("\
416 This variable controls the border of TUI windows:\n\
417 space use a white space\n\
418 ascii use ascii characters + - | for the border\n\
419 acs use the Alternate Character Set"),
421 show_tui_border_kind
,
422 &tui_setlist
, &tui_showlist
);
424 add_setshow_enum_cmd ("border-mode", no_class
, tui_border_mode_enums
,
425 &tui_border_mode
, _("\
426 Set the attribute mode to use for the TUI window borders."), _("\
427 Show the attribute mode to use for the TUI window borders."), _("\
428 This variable controls the attributes to use for the window borders:\n\
429 normal normal display\n\
430 standout use highlight mode of terminal\n\
431 reverse use reverse video mode\n\
432 half use half bright\n\
433 half-standout use half bright and standout mode\n\
434 bold use extra bright or bold\n\
435 bold-standout use extra bright or bold with standout mode"),
437 show_tui_border_mode
,
438 &tui_setlist
, &tui_showlist
);
440 add_setshow_enum_cmd ("active-border-mode", no_class
, tui_border_mode_enums
,
441 &tui_active_border_mode
, _("\
442 Set the attribute mode to use for the active TUI window border."), _("\
443 Show the attribute mode to use for the active TUI window border."), _("\
444 This variable controls the attributes to use for the active window border:\n\
445 normal normal display\n\
446 standout use highlight mode of terminal\n\
447 reverse use reverse video mode\n\
448 half use half bright\n\
449 half-standout use half bright and standout mode\n\
450 bold use extra bright or bold\n\
451 bold-standout use extra bright or bold with standout mode"),
453 show_tui_active_border_mode
,
454 &tui_setlist
, &tui_showlist
);
457 /* Update gdb's knowledge of the terminal size. */
459 tui_update_gdb_sizes (void)
463 /* Set to TUI command window dimension or use readline values. */
464 sprintf (cmd
, "set width %d",
465 tui_active
? TUI_CMD_WIN
->generic
.width
: tui_term_width());
466 execute_command (cmd
, 0);
467 sprintf (cmd
, "set height %d",
468 tui_active
? TUI_CMD_WIN
->generic
.height
: tui_term_height());
469 execute_command (cmd
, 0);
473 /* Set the logical focus to win_info. */
475 tui_set_win_focus_to (struct tui_win_info
*win_info
)
477 if (win_info
!= NULL
)
479 struct tui_win_info
*win_with_focus
= tui_win_with_focus ();
481 if (win_with_focus
!= NULL
482 && win_with_focus
->generic
.type
!= CMD_WIN
)
483 tui_unhighlight_win (win_with_focus
);
484 tui_set_win_with_focus (win_info
);
485 if (win_info
->generic
.type
!= CMD_WIN
)
486 tui_highlight_win (win_info
);
492 tui_scroll_forward (struct tui_win_info
*win_to_scroll
,
495 if (win_to_scroll
!= TUI_CMD_WIN
)
497 int _num_to_scroll
= num_to_scroll
;
499 if (num_to_scroll
== 0)
500 _num_to_scroll
= win_to_scroll
->generic
.height
- 3;
502 /* If we are scrolling the source or disassembly window, do a
503 "psuedo" scroll since not all of the source is in memory,
504 only what is in the viewport. If win_to_scroll is the
505 command window do nothing since the term should handle
507 if (win_to_scroll
== TUI_SRC_WIN
)
508 tui_vertical_source_scroll (FORWARD_SCROLL
, _num_to_scroll
);
509 else if (win_to_scroll
== TUI_DISASM_WIN
)
510 tui_vertical_disassem_scroll (FORWARD_SCROLL
, _num_to_scroll
);
511 else if (win_to_scroll
== TUI_DATA_WIN
)
512 tui_vertical_data_scroll (FORWARD_SCROLL
, _num_to_scroll
);
517 tui_scroll_backward (struct tui_win_info
*win_to_scroll
,
520 if (win_to_scroll
!= TUI_CMD_WIN
)
522 int _num_to_scroll
= num_to_scroll
;
524 if (num_to_scroll
== 0)
525 _num_to_scroll
= win_to_scroll
->generic
.height
- 3;
527 /* If we are scrolling the source or disassembly window, do a
528 "psuedo" scroll since not all of the source is in memory,
529 only what is in the viewport. If win_to_scroll is the
530 command window do nothing since the term should handle
532 if (win_to_scroll
== TUI_SRC_WIN
)
533 tui_vertical_source_scroll (BACKWARD_SCROLL
, _num_to_scroll
);
534 else if (win_to_scroll
== TUI_DISASM_WIN
)
535 tui_vertical_disassem_scroll (BACKWARD_SCROLL
, _num_to_scroll
);
536 else if (win_to_scroll
== TUI_DATA_WIN
)
537 tui_vertical_data_scroll (BACKWARD_SCROLL
, _num_to_scroll
);
543 tui_scroll_left (struct tui_win_info
*win_to_scroll
,
546 if (win_to_scroll
!= TUI_CMD_WIN
)
548 int _num_to_scroll
= num_to_scroll
;
550 if (_num_to_scroll
== 0)
553 /* If we are scrolling the source or disassembly window, do a
554 "psuedo" scroll since not all of the source is in memory,
555 only what is in the viewport. If win_to_scroll is the command
556 window do nothing since the term should handle it. */
557 if (win_to_scroll
== TUI_SRC_WIN
558 || win_to_scroll
== TUI_DISASM_WIN
)
559 tui_horizontal_source_scroll (win_to_scroll
, LEFT_SCROLL
, _num_to_scroll
);
565 tui_scroll_right (struct tui_win_info
*win_to_scroll
,
568 if (win_to_scroll
!= TUI_CMD_WIN
)
570 int _num_to_scroll
= num_to_scroll
;
572 if (_num_to_scroll
== 0)
575 /* If we are scrolling the source or disassembly window, do a
576 "psuedo" scroll since not all of the source is in memory,
577 only what is in the viewport. If win_to_scroll is the command
578 window do nothing since the term should handle it. */
579 if (win_to_scroll
== TUI_SRC_WIN
580 || win_to_scroll
== TUI_DISASM_WIN
)
581 tui_horizontal_source_scroll (win_to_scroll
, RIGHT_SCROLL
, _num_to_scroll
);
586 /* Scroll a window. Arguments are passed through a va_list. */
588 tui_scroll (enum tui_scroll_direction direction
,
589 struct tui_win_info
*win_to_scroll
,
595 tui_scroll_forward (win_to_scroll
, num_to_scroll
);
597 case BACKWARD_SCROLL
:
598 tui_scroll_backward (win_to_scroll
, num_to_scroll
);
601 tui_scroll_left (win_to_scroll
, num_to_scroll
);
604 tui_scroll_right (win_to_scroll
, num_to_scroll
);
613 tui_refresh_all_win (void)
615 enum tui_win_type type
;
617 clearok (curscr
, TRUE
);
618 tui_refresh_all (tui_win_list
);
619 for (type
= SRC_WIN
; type
< MAX_MAJOR_WINDOWS
; type
++)
621 if (tui_win_list
[type
]
622 && tui_win_list
[type
]->generic
.is_visible
)
628 tui_show_source_content (tui_win_list
[type
]);
629 tui_check_and_display_highlight_if_needed (tui_win_list
[type
]);
630 tui_erase_exec_info_content (tui_win_list
[type
]);
631 tui_update_exec_info (tui_win_list
[type
]);
634 tui_refresh_data_win ();
641 tui_show_locator_content ();
645 /* Resize all the windows based on the the terminal size. This
646 function gets called from within the readline sinwinch handler. */
648 tui_resize_all (void)
650 int height_diff
, width_diff
;
651 int screenheight
, screenwidth
;
653 rl_get_screen_size (&screenheight
, &screenwidth
);
654 width_diff
= screenwidth
- tui_term_width ();
655 height_diff
= screenheight
- tui_term_height ();
656 if (height_diff
|| width_diff
)
658 enum tui_layout_type cur_layout
= tui_current_layout ();
659 struct tui_win_info
*win_with_focus
= tui_win_with_focus ();
660 struct tui_win_info
*first_win
;
661 struct tui_win_info
*second_win
;
662 struct tui_gen_win_info
*locator
= tui_locator_win_info_ptr ();
663 enum tui_win_type win_type
;
664 int new_height
, split_diff
, cmd_split_diff
, num_wins_displayed
= 2;
666 #ifdef HAVE_RESIZE_TERM
667 resize_term (screenheight
, screenwidth
);
669 /* Turn keypad off while we resize. */
670 if (win_with_focus
!= TUI_CMD_WIN
)
671 keypad (TUI_CMD_WIN
->generic
.handle
, FALSE
);
672 tui_update_gdb_sizes ();
673 tui_set_term_height_to (screenheight
);
674 tui_set_term_width_to (screenwidth
);
675 if (cur_layout
== SRC_DISASSEM_COMMAND
676 || cur_layout
== SRC_DATA_COMMAND
677 || cur_layout
== DISASSEM_DATA_COMMAND
)
678 num_wins_displayed
++;
679 split_diff
= height_diff
/ num_wins_displayed
;
680 cmd_split_diff
= split_diff
;
681 if (height_diff
% num_wins_displayed
)
688 /* Now adjust each window. */
694 case DISASSEM_COMMAND
:
695 first_win
= (struct tui_win_info
*) (tui_source_windows ())->list
[0];
696 first_win
->generic
.width
+= width_diff
;
697 locator
->width
+= width_diff
;
698 /* Check for invalid heights. */
699 if (height_diff
== 0)
700 new_height
= first_win
->generic
.height
;
701 else if ((first_win
->generic
.height
+ split_diff
) >=
702 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
703 new_height
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
704 else if ((first_win
->generic
.height
+ split_diff
) <= 0)
705 new_height
= MIN_WIN_HEIGHT
;
707 new_height
= first_win
->generic
.height
+ split_diff
;
709 make_invisible_and_set_new_height (first_win
, new_height
);
710 TUI_CMD_WIN
->generic
.origin
.y
= locator
->origin
.y
+ 1;
711 TUI_CMD_WIN
->generic
.width
+= width_diff
;
712 new_height
= screenheight
- TUI_CMD_WIN
->generic
.origin
.y
;
713 make_invisible_and_set_new_height (TUI_CMD_WIN
, new_height
);
714 make_visible_with_new_height (first_win
);
715 make_visible_with_new_height (TUI_CMD_WIN
);
716 if (first_win
->generic
.content_size
<= 0)
717 tui_erase_source_content (first_win
, EMPTY_SOURCE_PROMPT
);
720 if (cur_layout
== SRC_DISASSEM_COMMAND
)
722 first_win
= TUI_SRC_WIN
;
723 first_win
->generic
.width
+= width_diff
;
724 second_win
= TUI_DISASM_WIN
;
725 second_win
->generic
.width
+= width_diff
;
729 first_win
= TUI_DATA_WIN
;
730 first_win
->generic
.width
+= width_diff
;
731 second_win
= (struct tui_win_info
*) (tui_source_windows ())->list
[0];
732 second_win
->generic
.width
+= width_diff
;
734 /* Change the first window's height/width. */
735 /* Check for invalid heights. */
736 if (height_diff
== 0)
737 new_height
= first_win
->generic
.height
;
738 else if ((first_win
->generic
.height
+
739 second_win
->generic
.height
+ (split_diff
* 2)) >=
740 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
741 new_height
= (screenheight
- MIN_CMD_WIN_HEIGHT
- 1) / 2;
742 else if ((first_win
->generic
.height
+ split_diff
) <= 0)
743 new_height
= MIN_WIN_HEIGHT
;
745 new_height
= first_win
->generic
.height
+ split_diff
;
746 make_invisible_and_set_new_height (first_win
, new_height
);
748 locator
->width
+= width_diff
;
750 /* Change the second window's height/width. */
751 /* Check for invalid heights. */
752 if (height_diff
== 0)
753 new_height
= second_win
->generic
.height
;
754 else if ((first_win
->generic
.height
+
755 second_win
->generic
.height
+ (split_diff
* 2)) >=
756 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
758 new_height
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
760 new_height
= (new_height
/ 2) + 1;
764 else if ((second_win
->generic
.height
+ split_diff
) <= 0)
765 new_height
= MIN_WIN_HEIGHT
;
767 new_height
= second_win
->generic
.height
+ split_diff
;
768 second_win
->generic
.origin
.y
= first_win
->generic
.height
- 1;
769 make_invisible_and_set_new_height (second_win
, new_height
);
771 /* Change the command window's height/width. */
772 TUI_CMD_WIN
->generic
.origin
.y
= locator
->origin
.y
+ 1;
773 make_invisible_and_set_new_height (
774 TUI_CMD_WIN
, TUI_CMD_WIN
->generic
.height
+ cmd_split_diff
);
775 make_visible_with_new_height (first_win
);
776 make_visible_with_new_height (second_win
);
777 make_visible_with_new_height (TUI_CMD_WIN
);
778 if (first_win
->generic
.content_size
<= 0)
779 tui_erase_source_content (first_win
, EMPTY_SOURCE_PROMPT
);
780 if (second_win
->generic
.content_size
<= 0)
781 tui_erase_source_content (second_win
, EMPTY_SOURCE_PROMPT
);
784 /* Now remove all invisible windows, and their content so that
785 they get created again when called for with the new size. */
786 for (win_type
= SRC_WIN
; (win_type
< MAX_MAJOR_WINDOWS
); win_type
++)
788 if (win_type
!= CMD_WIN
789 && (tui_win_list
[win_type
] != NULL
)
790 && !tui_win_list
[win_type
]->generic
.is_visible
)
792 tui_free_window (tui_win_list
[win_type
]);
793 tui_win_list
[win_type
] = (struct tui_win_info
*) NULL
;
796 tui_set_win_resized_to (TRUE
);
797 /* Turn keypad back on, unless focus is in the command
799 if (win_with_focus
!= TUI_CMD_WIN
)
800 keypad (TUI_CMD_WIN
->generic
.handle
, TRUE
);
805 /* SIGWINCH signal handler for the tui. This signal handler is always
806 called, even when the readline package clears signals because it is
807 set as the old_sigwinch() (TUI only). */
809 tui_sigwinch_handler (int signal
)
811 /* Say that a resize was done so that the readline can do it later
813 tui_set_win_resized_to (TRUE
);
818 /*************************
819 ** STATIC LOCAL FUNCTIONS
820 **************************/
824 tui_scroll_forward_command (char *arg
, int from_tty
)
826 int num_to_scroll
= 1;
827 struct tui_win_info
*win_to_scroll
;
829 /* Make sure the curses mode is enabled. */
831 if (arg
== (char *) NULL
)
832 parse_scrolling_args (arg
, &win_to_scroll
, (int *) NULL
);
834 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
835 tui_scroll (FORWARD_SCROLL
, win_to_scroll
, num_to_scroll
);
840 tui_scroll_backward_command (char *arg
, int from_tty
)
842 int num_to_scroll
= 1;
843 struct tui_win_info
*win_to_scroll
;
845 /* Make sure the curses mode is enabled. */
847 if (arg
== (char *) NULL
)
848 parse_scrolling_args (arg
, &win_to_scroll
, (int *) NULL
);
850 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
851 tui_scroll (BACKWARD_SCROLL
, win_to_scroll
, num_to_scroll
);
856 tui_scroll_left_command (char *arg
, int from_tty
)
859 struct tui_win_info
*win_to_scroll
;
861 /* Make sure the curses mode is enabled. */
863 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
864 tui_scroll (LEFT_SCROLL
, win_to_scroll
, num_to_scroll
);
869 tui_scroll_right_command (char *arg
, int from_tty
)
872 struct tui_win_info
*win_to_scroll
;
874 /* Make sure the curses mode is enabled. */
876 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
877 tui_scroll (RIGHT_SCROLL
, win_to_scroll
, num_to_scroll
);
881 /* Set focus to the window named by 'arg'. */
883 tui_set_focus (char *arg
, int from_tty
)
885 if (arg
!= (char *) NULL
)
887 char *buf_ptr
= (char *) xstrdup (arg
);
889 struct tui_win_info
*win_info
= (struct tui_win_info
*) NULL
;
891 for (i
= 0; (i
< strlen (buf_ptr
)); i
++)
892 buf_ptr
[i
] = toupper (arg
[i
]);
894 if (subset_compare (buf_ptr
, "NEXT"))
895 win_info
= tui_next_win (tui_win_with_focus ());
896 else if (subset_compare (buf_ptr
, "PREV"))
897 win_info
= tui_prev_win (tui_win_with_focus ());
899 win_info
= tui_partial_win_by_name (buf_ptr
);
901 if (win_info
== (struct tui_win_info
*) NULL
902 || !win_info
->generic
.is_visible
)
903 warning (_("Invalid window specified. \n\
904 The window name specified must be valid and visible.\n"));
907 tui_set_win_focus_to (win_info
);
908 keypad (TUI_CMD_WIN
->generic
.handle
, (win_info
!= TUI_CMD_WIN
));
911 if (TUI_DATA_WIN
&& TUI_DATA_WIN
->generic
.is_visible
)
912 tui_refresh_data_win ();
914 printf_filtered (_("Focus set to %s window.\n"),
915 tui_win_name ((struct tui_gen_win_info
*) tui_win_with_focus ()));
918 warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE
);
922 tui_set_focus_command (char *arg
, int from_tty
)
924 /* Make sure the curses mode is enabled. */
926 tui_set_focus (arg
, from_tty
);
931 tui_all_windows_info (char *arg
, int from_tty
)
933 enum tui_win_type type
;
934 struct tui_win_info
*win_with_focus
= tui_win_with_focus ();
936 for (type
= SRC_WIN
; (type
< MAX_MAJOR_WINDOWS
); type
++)
937 if (tui_win_list
[type
]
938 && tui_win_list
[type
]->generic
.is_visible
)
940 if (win_with_focus
== tui_win_list
[type
])
941 printf_filtered (" %s\t(%d lines) <has focus>\n",
942 tui_win_name (&tui_win_list
[type
]->generic
),
943 tui_win_list
[type
]->generic
.height
);
945 printf_filtered (" %s\t(%d lines)\n",
946 tui_win_name (&tui_win_list
[type
]->generic
),
947 tui_win_list
[type
]->generic
.height
);
953 tui_refresh_all_command (char *arg
, int from_tty
)
955 /* Make sure the curses mode is enabled. */
958 tui_refresh_all_win ();
962 /* Set the height of the specified window. */
964 tui_set_tab_width_command (char *arg
, int from_tty
)
966 /* Make sure the curses mode is enabled. */
968 if (arg
!= (char *) NULL
)
974 tui_set_default_tab_len (ts
);
976 warning (_("Tab widths greater than 0 must be specified."));
981 /* Set the height of the specified window. */
983 tui_set_win_height (char *arg
, int from_tty
)
985 /* Make sure the curses mode is enabled. */
987 if (arg
!= (char *) NULL
)
989 char *buf
= xstrdup (arg
);
991 char *wname
= (char *) NULL
;
993 struct tui_win_info
*win_info
;
996 buf_ptr
= strchr (buf_ptr
, ' ');
997 if (buf_ptr
!= (char *) NULL
)
1001 /* Validate the window name. */
1002 for (i
= 0; i
< strlen (wname
); i
++)
1003 wname
[i
] = toupper (wname
[i
]);
1004 win_info
= tui_partial_win_by_name (wname
);
1006 if (win_info
== (struct tui_win_info
*) NULL
1007 || !win_info
->generic
.is_visible
)
1008 warning (_("Invalid window specified. \n\
1009 The window name specified must be valid and visible.\n"));
1012 /* Process the size. */
1013 while (*(++buf_ptr
) == ' ')
1016 if (*buf_ptr
!= (char) 0)
1019 int fixed_size
= TRUE
;
1022 if (*buf_ptr
== '+' || *buf_ptr
== '-')
1024 if (*buf_ptr
== '-')
1029 input_no
= atoi (buf_ptr
);
1035 new_height
= input_no
;
1037 new_height
= win_info
->generic
.height
+ input_no
;
1039 /* Now change the window's height, and adjust
1040 all other windows around it. */
1041 if (tui_adjust_win_heights (win_info
,
1042 new_height
) == TUI_FAILURE
)
1043 warning (_("Invalid window height specified.\n%s"),
1046 tui_update_gdb_sizes ();
1049 warning (_("Invalid window height specified.\n%s"),
1055 printf_filtered (WIN_HEIGHT_USAGE
);
1057 if (buf
!= (char *) NULL
)
1061 printf_filtered (WIN_HEIGHT_USAGE
);
1064 /* Set the height of the specified window, with va_list. */
1066 tui_set_win_height_command (char *arg
, int from_tty
)
1068 /* Make sure the curses mode is enabled. */
1070 tui_set_win_height (arg
, from_tty
);
1074 /* XDB Compatibility command for setting the window height. This will
1075 increase or decrease the command window by the specified
1078 tui_xdb_set_win_height (char *arg
, int from_tty
)
1080 /* Make sure the curses mode is enabled. */
1082 if (arg
!= (char *) NULL
)
1084 int input_no
= atoi (arg
);
1087 { /* Add 1 for the locator. */
1088 int new_height
= tui_term_height () - (input_no
+ 1);
1090 if (!new_height_ok (tui_win_list
[CMD_WIN
], new_height
)
1091 || tui_adjust_win_heights (tui_win_list
[CMD_WIN
],
1092 new_height
) == TUI_FAILURE
)
1093 warning (_("Invalid window height specified.\n%s"),
1094 XDBWIN_HEIGHT_USAGE
);
1097 warning (_("Invalid window height specified.\n%s"),
1098 XDBWIN_HEIGHT_USAGE
);
1101 warning (_("Invalid window height specified.\n%s"), XDBWIN_HEIGHT_USAGE
);
1104 /* Set the height of the specified window, with va_list. */
1106 tui_xdb_set_win_height_command (char *arg
, int from_tty
)
1108 tui_xdb_set_win_height (arg
, from_tty
);
1112 /* Function to adjust all window heights around the primary. */
1113 static enum tui_status
1114 tui_adjust_win_heights (struct tui_win_info
*primary_win_info
,
1117 enum tui_status status
= TUI_FAILURE
;
1119 if (new_height_ok (primary_win_info
, new_height
))
1121 status
= TUI_SUCCESS
;
1122 if (new_height
!= primary_win_info
->generic
.height
)
1125 struct tui_win_info
*win_info
;
1126 struct tui_gen_win_info
*locator
= tui_locator_win_info_ptr ();
1127 enum tui_layout_type cur_layout
= tui_current_layout ();
1129 diff
= (new_height
- primary_win_info
->generic
.height
) * (-1);
1130 if (cur_layout
== SRC_COMMAND
1131 || cur_layout
== DISASSEM_COMMAND
)
1133 struct tui_win_info
*src_win_info
;
1135 make_invisible_and_set_new_height (primary_win_info
, new_height
);
1136 if (primary_win_info
->generic
.type
== CMD_WIN
)
1138 win_info
= (tui_source_windows ())->list
[0];
1139 src_win_info
= win_info
;
1143 win_info
= tui_win_list
[CMD_WIN
];
1144 src_win_info
= primary_win_info
;
1146 make_invisible_and_set_new_height (win_info
,
1147 win_info
->generic
.height
+ diff
);
1148 TUI_CMD_WIN
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1149 make_visible_with_new_height (win_info
);
1150 make_visible_with_new_height (primary_win_info
);
1151 if (src_win_info
->generic
.content_size
<= 0)
1152 tui_erase_source_content (src_win_info
, EMPTY_SOURCE_PROMPT
);
1156 struct tui_win_info
*first_win
;
1157 struct tui_win_info
*second_win
;
1159 if (cur_layout
== SRC_DISASSEM_COMMAND
)
1161 first_win
= TUI_SRC_WIN
;
1162 second_win
= TUI_DISASM_WIN
;
1166 first_win
= TUI_DATA_WIN
;
1167 second_win
= (tui_source_windows ())->list
[0];
1169 if (primary_win_info
== TUI_CMD_WIN
)
1170 { /* Split the change in height accross the 1st & 2nd
1171 windows, adjusting them as well. */
1172 /* Subtract the locator. */
1173 int first_split_diff
= diff
/ 2;
1174 int second_split_diff
= first_split_diff
;
1178 if (first_win
->generic
.height
>
1179 second_win
->generic
.height
)
1187 second_split_diff
--;
1189 second_split_diff
++;
1192 /* Make sure that the minimum hieghts are
1194 while ((first_win
->generic
.height
+ first_split_diff
) < 3)
1197 second_split_diff
--;
1199 while ((second_win
->generic
.height
+ second_split_diff
) < 3)
1201 second_split_diff
++;
1204 make_invisible_and_set_new_height (
1206 first_win
->generic
.height
+ first_split_diff
);
1207 second_win
->generic
.origin
.y
= first_win
->generic
.height
- 1;
1208 make_invisible_and_set_new_height (
1209 second_win
, second_win
->generic
.height
+ second_split_diff
);
1210 TUI_CMD_WIN
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1211 make_invisible_and_set_new_height (TUI_CMD_WIN
, new_height
);
1215 if ((TUI_CMD_WIN
->generic
.height
+ diff
) < 1)
1216 { /* If there is no way to increase the command
1217 window take real estate from the 1st or 2nd
1219 if ((TUI_CMD_WIN
->generic
.height
+ diff
) < 1)
1222 for (i
= TUI_CMD_WIN
->generic
.height
+ diff
;
1224 if (primary_win_info
== first_win
)
1225 second_win
->generic
.height
--;
1227 first_win
->generic
.height
--;
1230 if (primary_win_info
== first_win
)
1231 make_invisible_and_set_new_height (first_win
, new_height
);
1233 make_invisible_and_set_new_height (
1235 first_win
->generic
.height
);
1236 second_win
->generic
.origin
.y
= first_win
->generic
.height
- 1;
1237 if (primary_win_info
== second_win
)
1238 make_invisible_and_set_new_height (second_win
, new_height
);
1240 make_invisible_and_set_new_height (
1241 second_win
, second_win
->generic
.height
);
1242 TUI_CMD_WIN
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1243 if ((TUI_CMD_WIN
->generic
.height
+ diff
) < 1)
1244 make_invisible_and_set_new_height (TUI_CMD_WIN
, 1);
1246 make_invisible_and_set_new_height (
1247 TUI_CMD_WIN
, TUI_CMD_WIN
->generic
.height
+ diff
);
1249 make_visible_with_new_height (TUI_CMD_WIN
);
1250 make_visible_with_new_height (second_win
);
1251 make_visible_with_new_height (first_win
);
1252 if (first_win
->generic
.content_size
<= 0)
1253 tui_erase_source_content (first_win
, EMPTY_SOURCE_PROMPT
);
1254 if (second_win
->generic
.content_size
<= 0)
1255 tui_erase_source_content (second_win
, EMPTY_SOURCE_PROMPT
);
1264 /* Function make the target window (and auxillary windows associated
1265 with the targer) invisible, and set the new height and
1268 make_invisible_and_set_new_height (struct tui_win_info
*win_info
,
1272 struct tui_gen_win_info
*gen_win_info
;
1274 tui_make_invisible (&win_info
->generic
);
1275 win_info
->generic
.height
= height
;
1277 win_info
->generic
.viewport_height
= height
- 1;
1279 win_info
->generic
.viewport_height
= height
;
1280 if (win_info
!= TUI_CMD_WIN
)
1281 win_info
->generic
.viewport_height
--;
1283 /* Now deal with the auxillary windows associated with win_info. */
1284 switch (win_info
->generic
.type
)
1288 gen_win_info
= win_info
->detail
.source_info
.execution_info
;
1289 tui_make_invisible (gen_win_info
);
1290 gen_win_info
->height
= height
;
1291 gen_win_info
->origin
.y
= win_info
->generic
.origin
.y
;
1293 gen_win_info
->viewport_height
= height
- 1;
1295 gen_win_info
->viewport_height
= height
;
1296 if (win_info
!= TUI_CMD_WIN
)
1297 gen_win_info
->viewport_height
--;
1299 if (tui_win_has_locator (win_info
))
1301 gen_win_info
= tui_locator_win_info_ptr ();
1302 tui_make_invisible (gen_win_info
);
1303 gen_win_info
->origin
.y
= win_info
->generic
.origin
.y
+ height
;
1307 /* Delete all data item windows. */
1308 for (i
= 0; i
< win_info
->generic
.content_size
; i
++)
1310 gen_win_info
= (struct tui_gen_win_info
*) & ((struct tui_win_element
*)
1311 win_info
->generic
.content
[i
])->which_element
.data_window
;
1312 tui_delete_win (gen_win_info
->handle
);
1313 gen_win_info
->handle
= (WINDOW
*) NULL
;
1322 /* Function to make the windows with new heights visible. This means
1323 re-creating the windows' content since the window had to be
1324 destroyed to be made invisible. */
1326 make_visible_with_new_height (struct tui_win_info
*win_info
)
1330 tui_make_visible (&win_info
->generic
);
1331 tui_check_and_display_highlight_if_needed (win_info
);
1332 switch (win_info
->generic
.type
)
1336 tui_free_win_content (win_info
->detail
.source_info
.execution_info
);
1337 tui_make_visible (win_info
->detail
.source_info
.execution_info
);
1338 if (win_info
->generic
.content
!= NULL
)
1340 struct tui_line_or_address line_or_addr
;
1341 struct symtab_and_line cursal
1342 = get_current_source_symtab_and_line ();
1344 line_or_addr
= win_info
->detail
.source_info
.start_line_or_addr
;
1345 tui_free_win_content (&win_info
->generic
);
1346 tui_update_source_window (win_info
, cursal
.symtab
, line_or_addr
, TRUE
);
1348 else if (deprecated_safe_get_selected_frame () != NULL
)
1350 struct tui_line_or_address line
;
1351 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
1352 struct frame_info
*frame
= deprecated_safe_get_selected_frame ();
1354 s
= find_pc_symtab (get_frame_pc (frame
));
1355 if (win_info
->generic
.type
== SRC_WIN
)
1357 line
.loa
= LOA_LINE
;
1358 line
.u
.line_no
= cursal
.line
;
1362 line
.loa
= LOA_ADDRESS
;
1363 find_line_pc (s
, cursal
.line
, &line
.u
.addr
);
1365 tui_update_source_window (win_info
, s
, line
, TRUE
);
1367 if (tui_win_has_locator (win_info
))
1369 tui_make_visible (tui_locator_win_info_ptr ());
1370 tui_show_locator_content ();
1374 tui_display_all_data ();
1377 win_info
->detail
.command_info
.cur_line
= 0;
1378 win_info
->detail
.command_info
.curch
= 0;
1379 wmove (win_info
->generic
.handle
,
1380 win_info
->detail
.command_info
.cur_line
,
1381 win_info
->detail
.command_info
.curch
);
1390 new_height_ok (struct tui_win_info
*primary_win_info
,
1393 int ok
= (new_height
< tui_term_height ());
1398 enum tui_layout_type cur_layout
= tui_current_layout ();
1400 diff
= (new_height
- primary_win_info
->generic
.height
) * (-1);
1401 if (cur_layout
== SRC_COMMAND
|| cur_layout
== DISASSEM_COMMAND
)
1403 ok
= ((primary_win_info
->generic
.type
== CMD_WIN
1404 && new_height
<= (tui_term_height () - 4)
1405 && new_height
>= MIN_CMD_WIN_HEIGHT
)
1406 || (primary_win_info
->generic
.type
!= CMD_WIN
1407 && new_height
<= (tui_term_height () - 2)
1408 && new_height
>= MIN_WIN_HEIGHT
));
1410 { /* Check the total height. */
1411 struct tui_win_info
*win_info
;
1413 if (primary_win_info
== TUI_CMD_WIN
)
1414 win_info
= (tui_source_windows ())->list
[0];
1416 win_info
= TUI_CMD_WIN
;
1418 (win_info
->generic
.height
+ diff
)) <= tui_term_height ());
1423 int cur_total_height
, total_height
, min_height
= 0;
1424 struct tui_win_info
*first_win
;
1425 struct tui_win_info
*second_win
;
1427 if (cur_layout
== SRC_DISASSEM_COMMAND
)
1429 first_win
= TUI_SRC_WIN
;
1430 second_win
= TUI_DISASM_WIN
;
1434 first_win
= TUI_DATA_WIN
;
1435 second_win
= (tui_source_windows ())->list
[0];
1437 /* We could simply add all the heights to obtain the same
1438 result but below is more explicit since we subtract 1 for
1439 the line that the first and second windows share, and add
1440 one for the locator. */
1441 total_height
= cur_total_height
=
1442 (first_win
->generic
.height
+ second_win
->generic
.height
- 1)
1443 + TUI_CMD_WIN
->generic
.height
+ 1; /* Locator. */
1444 if (primary_win_info
== TUI_CMD_WIN
)
1446 /* Locator included since first & second win share a line. */
1447 ok
= ((first_win
->generic
.height
+
1448 second_win
->generic
.height
+ diff
) >=
1449 (MIN_WIN_HEIGHT
* 2)
1450 && new_height
>= MIN_CMD_WIN_HEIGHT
);
1453 total_height
= new_height
+
1454 (first_win
->generic
.height
+
1455 second_win
->generic
.height
+ diff
);
1456 min_height
= MIN_CMD_WIN_HEIGHT
;
1461 min_height
= MIN_WIN_HEIGHT
;
1463 /* First see if we can increase/decrease the command
1464 window. And make sure that the command window is at
1466 ok
= ((TUI_CMD_WIN
->generic
.height
+ diff
) > 0);
1468 { /* Looks like we have to increase/decrease one of
1469 the other windows. */
1470 if (primary_win_info
== first_win
)
1471 ok
= (second_win
->generic
.height
+ diff
) >= min_height
;
1473 ok
= (first_win
->generic
.height
+ diff
) >= min_height
;
1477 if (primary_win_info
== first_win
)
1478 total_height
= new_height
+
1479 second_win
->generic
.height
+
1480 TUI_CMD_WIN
->generic
.height
+ diff
;
1482 total_height
= new_height
+
1483 first_win
->generic
.height
+
1484 TUI_CMD_WIN
->generic
.height
+ diff
;
1487 /* Now make sure that the proposed total height doesn't
1488 exceed the old total height. */
1490 ok
= (new_height
>= min_height
1491 && total_height
<= cur_total_height
);
1500 parse_scrolling_args (char *arg
,
1501 struct tui_win_info
**win_to_scroll
,
1506 *win_to_scroll
= tui_win_with_focus ();
1508 /* First set up the default window to scroll, in case there is no
1510 if (arg
!= (char *) NULL
)
1512 char *buf
, *buf_ptr
;
1514 /* Process the number of lines to scroll. */
1515 buf
= buf_ptr
= xstrdup (arg
);
1516 if (isdigit (*buf_ptr
))
1521 buf_ptr
= strchr (buf_ptr
, ' ');
1522 if (buf_ptr
!= (char *) NULL
)
1524 *buf_ptr
= (char) 0;
1526 *num_to_scroll
= atoi (num_str
);
1529 else if (num_to_scroll
)
1530 *num_to_scroll
= atoi (num_str
);
1533 /* Process the window name if one is specified. */
1534 if (buf_ptr
!= (char *) NULL
)
1539 if (*buf_ptr
== ' ')
1540 while (*(++buf_ptr
) == ' ')
1543 if (*buf_ptr
!= (char) 0)
1548 /* Validate the window name. */
1549 for (i
= 0; i
< strlen (wname
); i
++)
1550 wname
[i
] = toupper (wname
[i
]);
1551 *win_to_scroll
= tui_partial_win_by_name (wname
);
1553 if (*win_to_scroll
== (struct tui_win_info
*) NULL
1554 || !(*win_to_scroll
)->generic
.is_visible
)
1555 error (_("Invalid window specified. \n\
1556 The window name specified must be valid and visible.\n"));
1557 else if (*win_to_scroll
== TUI_CMD_WIN
)
1558 *win_to_scroll
= (tui_source_windows ())->list
[0];