1 /* TUI window generic functions.
3 Copyright (C) 1998-2013 Free Software Foundation, Inc.
5 Contributed by Hewlett-Packard Company.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 /* This module contains procedures for handling tui window functions
23 like resize, scrolling, scrolling, changing focus, etc.
25 Author: Susan B. Macchia */
30 #include "breakpoint.h"
32 #include "cli/cli-cmds.h"
37 #include "tui/tui-data.h"
38 #include "tui/tui-wingeneral.h"
39 #include "tui/tui-stack.h"
40 #include "tui/tui-regs.h"
41 #include "tui/tui-disasm.h"
42 #include "tui/tui-source.h"
43 #include "tui/tui-winsource.h"
44 #include "tui/tui-windata.h"
45 #include "tui/tui-win.h"
47 #include "gdb_curses.h"
49 #include "gdb_string.h"
51 #include "readline/readline.h"
55 /*******************************
57 ********************************/
58 static void make_visible_with_new_height (struct tui_win_info *);
59 static void make_invisible_and_set_new_height (struct tui_win_info *,
61 static enum tui_status tui_adjust_win_heights (struct tui_win_info *,
63 static int new_height_ok (struct tui_win_info *, int);
64 static void tui_set_tab_width_command (char *, int);
65 static void tui_refresh_all_command (char *, int);
66 static void tui_set_win_height_command (char *, int);
67 static void tui_xdb_set_win_height_command (char *, int);
68 static void tui_all_windows_info (char *, int);
69 static void tui_set_focus_command (char *, int);
70 static void tui_scroll_forward_command (char *, int);
71 static void tui_scroll_backward_command (char *, int);
72 static void tui_scroll_left_command (char *, int);
73 static void tui_scroll_right_command (char *, int);
74 static void parse_scrolling_args (char *,
75 struct tui_win_info **,
79 /***************************************
81 ***************************************/
82 #define WIN_HEIGHT_USAGE "Usage: winheight <win_name> [+ | -] <#lines>\n"
83 #define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n"
84 #define FOCUS_USAGE "Usage: focus {<win> | next | prev}\n"
86 /***************************************
88 ***************************************/
91 # define ACS_LRCORNER '+'
94 # define ACS_LLCORNER '+'
97 # define ACS_ULCORNER '+'
100 # define ACS_URCORNER '+'
103 # define ACS_HLINE '-'
106 # define ACS_VLINE '|'
109 /* Possible values for tui-border-kind variable. */
110 static const char *const tui_border_kind_enums[] = {
117 /* Possible values for tui-border-mode and tui-active-border-mode. */
118 static const char *const tui_border_mode_enums[] = {
135 /* Translation table for border-mode variables.
136 The list of values must be terminated by a NULL.
137 After the NULL value, an entry defines the default. */
138 struct tui_translate tui_border_mode_translate[] = {
139 { "normal", A_NORMAL },
140 { "standout", A_STANDOUT },
141 { "reverse", A_REVERSE },
143 { "half-standout", A_DIM | A_STANDOUT },
145 { "bold-standout", A_BOLD | A_STANDOUT },
147 { "normal", A_NORMAL }
150 /* Translation tables for border-kind, one for each border
151 character (see wborder, border curses operations).
152 -1 is used to indicate the ACS because ACS characters
153 are determined at run time by curses (depends on terminal). */
154 struct tui_translate tui_border_kind_translate_vline[] = {
162 struct tui_translate tui_border_kind_translate_hline[] = {
170 struct tui_translate tui_border_kind_translate_ulcorner[] = {
178 struct tui_translate tui_border_kind_translate_urcorner[] = {
186 struct tui_translate tui_border_kind_translate_llcorner[] = {
194 struct tui_translate tui_border_kind_translate_lrcorner[] = {
203 /* Tui configuration variables controlled with set/show command. */
204 const char *tui_active_border_mode = "bold-standout";
206 show_tui_active_border_mode (struct ui_file *file,
208 struct cmd_list_element *c,
211 fprintf_filtered (file, _("\
212 The attribute mode to use for the active TUI window border is \"%s\".\n"),
216 const char *tui_border_mode = "normal";
218 show_tui_border_mode (struct ui_file *file,
220 struct cmd_list_element *c,
223 fprintf_filtered (file, _("\
224 The attribute mode to use for the TUI window borders is \"%s\".\n"),
228 const char *tui_border_kind = "acs";
230 show_tui_border_kind (struct ui_file *file,
232 struct cmd_list_element *c,
235 fprintf_filtered (file, _("The kind of border for TUI windows is \"%s\".\n"),
240 /* Tui internal configuration variables. These variables are updated
241 by tui_update_variables to reflect the tui configuration
243 chtype tui_border_vline;
244 chtype tui_border_hline;
245 chtype tui_border_ulcorner;
246 chtype tui_border_urcorner;
247 chtype tui_border_llcorner;
248 chtype tui_border_lrcorner;
250 int tui_border_attrs;
251 int tui_active_border_attrs;
253 /* Identify the item in the translation table.
254 When the item is not recognized, use the default entry. */
255 static struct tui_translate *
256 translate (const char *name, struct tui_translate *table)
260 if (name && strcmp (table->name, name) == 0)
265 /* Not found, return default entry. */
270 /* Update the tui internal configuration according to gdb settings.
271 Returns 1 if the configuration has changed and the screen should
274 tui_update_variables (void)
277 struct tui_translate *entry;
279 entry = translate (tui_border_mode, tui_border_mode_translate);
280 if (tui_border_attrs != entry->value)
282 tui_border_attrs = entry->value;
285 entry = translate (tui_active_border_mode, tui_border_mode_translate);
286 if (tui_active_border_attrs != entry->value)
288 tui_active_border_attrs = entry->value;
292 /* If one corner changes, all characters are changed.
293 Only check the first one. The ACS characters are determined at
294 run time by curses terminal management. */
295 entry = translate (tui_border_kind, tui_border_kind_translate_lrcorner);
296 if (tui_border_lrcorner != (chtype) entry->value)
298 tui_border_lrcorner = (entry->value < 0) ? ACS_LRCORNER : entry->value;
301 entry = translate (tui_border_kind, tui_border_kind_translate_llcorner);
302 tui_border_llcorner = (entry->value < 0) ? ACS_LLCORNER : entry->value;
304 entry = translate (tui_border_kind, tui_border_kind_translate_ulcorner);
305 tui_border_ulcorner = (entry->value < 0) ? ACS_ULCORNER : entry->value;
307 entry = translate (tui_border_kind, tui_border_kind_translate_urcorner);
308 tui_border_urcorner = (entry->value < 0) ? ACS_URCORNER : entry->value;
310 entry = translate (tui_border_kind, tui_border_kind_translate_hline);
311 tui_border_hline = (entry->value < 0) ? ACS_HLINE : entry->value;
313 entry = translate (tui_border_kind, tui_border_kind_translate_vline);
314 tui_border_vline = (entry->value < 0) ? ACS_VLINE : entry->value;
320 set_tui_cmd (char *args, int from_tty)
325 show_tui_cmd (char *args, int from_tty)
329 static struct cmd_list_element *tuilist;
332 tui_command (char *args, int from_tty)
334 printf_unfiltered (_("\"tui\" must be followed by the name of a "
336 help_list (tuilist, "tui ", -1, gdb_stdout);
339 struct cmd_list_element **
340 tui_get_cmd_list (void)
343 add_prefix_cmd ("tui", class_tui, tui_command,
344 _("Text User Interface commands."),
345 &tuilist, "tui ", 0, &cmdlist);
349 /* Function to initialize gdb commands, for tui window
352 /* Provide a prototype to silence -Wmissing-prototypes. */
353 extern initialize_file_ftype _initialize_tui_win;
356 _initialize_tui_win (void)
358 static struct cmd_list_element *tui_setlist;
359 static struct cmd_list_element *tui_showlist;
361 /* Define the classes of commands.
362 They will appear in the help list in the reverse of this order. */
363 add_prefix_cmd ("tui", class_tui, set_tui_cmd,
364 _("TUI configuration variables"),
365 &tui_setlist, "set tui ",
366 0 /* allow-unknown */, &setlist);
367 add_prefix_cmd ("tui", class_tui, show_tui_cmd,
368 _("TUI configuration variables"),
369 &tui_showlist, "show tui ",
370 0 /* allow-unknown */, &showlist);
372 add_com ("refresh", class_tui, tui_refresh_all_command,
373 _("Refresh the terminal display.\n"));
375 add_com_alias ("U", "refresh", class_tui, 0);
376 add_com ("tabset", class_tui, tui_set_tab_width_command, _("\
377 Set the width (in characters) of tab stops.\n\
378 Usage: tabset <n>\n"));
379 add_com ("winheight", class_tui, tui_set_win_height_command, _("\
380 Set the height of a specified window.\n\
381 Usage: winheight <win_name> [+ | -] <#lines>\n\
383 src : the source window\n\
384 cmd : the command window\n\
385 asm : the disassembly window\n\
386 regs : the register display\n"));
387 add_com_alias ("wh", "winheight", class_tui, 0);
388 add_info ("win", tui_all_windows_info,
389 _("List of all displayed windows.\n"));
390 add_com ("focus", class_tui, tui_set_focus_command, _("\
391 Set focus to named window or next/prev window.\n\
392 Usage: focus {<win> | next | prev}\n\
393 Valid Window names are:\n\
394 src : the source window\n\
395 asm : the disassembly window\n\
396 regs : the register display\n\
397 cmd : the command window\n"));
398 add_com_alias ("fs", "focus", class_tui, 0);
399 add_com ("+", class_tui, tui_scroll_forward_command, _("\
400 Scroll window forward.\n\
401 Usage: + [win] [n]\n"));
402 add_com ("-", class_tui, tui_scroll_backward_command, _("\
403 Scroll window backward.\n\
404 Usage: - [win] [n]\n"));
405 add_com ("<", class_tui, tui_scroll_left_command, _("\
406 Scroll window forward.\n\
407 Usage: < [win] [n]\n"));
408 add_com (">", class_tui, tui_scroll_right_command, _("\
409 Scroll window backward.\n\
410 Usage: > [win] [n]\n"));
412 add_com ("w", class_xdb, tui_xdb_set_win_height_command, _("\
413 XDB compatibility command for setting the height of a command window.\n\
414 Usage: w <#lines>\n"));
416 /* Define the tui control variables. */
417 add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums,
418 &tui_border_kind, _("\
419 Set the kind of border for TUI windows."), _("\
420 Show the kind of border for TUI windows."), _("\
421 This variable controls the border of TUI windows:\n\
422 space use a white space\n\
423 ascii use ascii characters + - | for the border\n\
424 acs use the Alternate Character Set"),
426 show_tui_border_kind,
427 &tui_setlist, &tui_showlist);
429 add_setshow_enum_cmd ("border-mode", no_class, tui_border_mode_enums,
430 &tui_border_mode, _("\
431 Set the attribute mode to use for the TUI window borders."), _("\
432 Show the attribute mode to use for the TUI window borders."), _("\
433 This variable controls the attributes to use for the window borders:\n\
434 normal normal display\n\
435 standout use highlight mode of terminal\n\
436 reverse use reverse video mode\n\
437 half use half bright\n\
438 half-standout use half bright and standout mode\n\
439 bold use extra bright or bold\n\
440 bold-standout use extra bright or bold with standout mode"),
442 show_tui_border_mode,
443 &tui_setlist, &tui_showlist);
445 add_setshow_enum_cmd ("active-border-mode", no_class, tui_border_mode_enums,
446 &tui_active_border_mode, _("\
447 Set the attribute mode to use for the active TUI window border."), _("\
448 Show the attribute mode to use for the active TUI window border."), _("\
449 This variable controls the attributes to use for the active window border:\n\
450 normal normal display\n\
451 standout use highlight mode of terminal\n\
452 reverse use reverse video mode\n\
453 half use half bright\n\
454 half-standout use half bright and standout mode\n\
455 bold use extra bright or bold\n\
456 bold-standout use extra bright or bold with standout mode"),
458 show_tui_active_border_mode,
459 &tui_setlist, &tui_showlist);
462 /* Update gdb's knowledge of the terminal size. */
464 tui_update_gdb_sizes (void)
468 /* Set to TUI command window dimension or use readline values. */
469 xsnprintf (cmd, sizeof (cmd), "set width %d",
470 tui_active ? TUI_CMD_WIN->generic.width : tui_term_width());
471 execute_command (cmd, 0);
472 xsnprintf (cmd, sizeof (cmd), "set height %d",
473 tui_active ? TUI_CMD_WIN->generic.height : tui_term_height());
474 execute_command (cmd, 0);
478 /* Set the logical focus to win_info. */
480 tui_set_win_focus_to (struct tui_win_info *win_info)
482 if (win_info != NULL)
484 struct tui_win_info *win_with_focus = tui_win_with_focus ();
486 if (win_with_focus != NULL
487 && win_with_focus->generic.type != CMD_WIN)
488 tui_unhighlight_win (win_with_focus);
489 tui_set_win_with_focus (win_info);
490 if (win_info->generic.type != CMD_WIN)
491 tui_highlight_win (win_info);
497 tui_scroll_forward (struct tui_win_info *win_to_scroll,
500 if (win_to_scroll != TUI_CMD_WIN)
502 int _num_to_scroll = num_to_scroll;
504 if (num_to_scroll == 0)
505 _num_to_scroll = win_to_scroll->generic.height - 3;
507 /* If we are scrolling the source or disassembly window, do a
508 "psuedo" scroll since not all of the source is in memory,
509 only what is in the viewport. If win_to_scroll is the
510 command window do nothing since the term should handle
512 if (win_to_scroll == TUI_SRC_WIN)
513 tui_vertical_source_scroll (FORWARD_SCROLL, _num_to_scroll);
514 else if (win_to_scroll == TUI_DISASM_WIN)
515 tui_vertical_disassem_scroll (FORWARD_SCROLL, _num_to_scroll);
516 else if (win_to_scroll == TUI_DATA_WIN)
517 tui_vertical_data_scroll (FORWARD_SCROLL, _num_to_scroll);
522 tui_scroll_backward (struct tui_win_info *win_to_scroll,
525 if (win_to_scroll != TUI_CMD_WIN)
527 int _num_to_scroll = num_to_scroll;
529 if (num_to_scroll == 0)
530 _num_to_scroll = win_to_scroll->generic.height - 3;
532 /* If we are scrolling the source or disassembly window, do a
533 "psuedo" scroll since not all of the source is in memory,
534 only what is in the viewport. If win_to_scroll is the
535 command window do nothing since the term should handle
537 if (win_to_scroll == TUI_SRC_WIN)
538 tui_vertical_source_scroll (BACKWARD_SCROLL, _num_to_scroll);
539 else if (win_to_scroll == TUI_DISASM_WIN)
540 tui_vertical_disassem_scroll (BACKWARD_SCROLL, _num_to_scroll);
541 else if (win_to_scroll == TUI_DATA_WIN)
542 tui_vertical_data_scroll (BACKWARD_SCROLL, _num_to_scroll);
548 tui_scroll_left (struct tui_win_info *win_to_scroll,
551 if (win_to_scroll != TUI_CMD_WIN)
553 int _num_to_scroll = num_to_scroll;
555 if (_num_to_scroll == 0)
558 /* If we are scrolling the source or disassembly window, do a
559 "psuedo" scroll since not all of the source is in memory,
560 only what is in the viewport. If win_to_scroll is the command
561 window do nothing since the term should handle it. */
562 if (win_to_scroll == TUI_SRC_WIN
563 || win_to_scroll == TUI_DISASM_WIN)
564 tui_horizontal_source_scroll (win_to_scroll, LEFT_SCROLL,
571 tui_scroll_right (struct tui_win_info *win_to_scroll,
574 if (win_to_scroll != TUI_CMD_WIN)
576 int _num_to_scroll = num_to_scroll;
578 if (_num_to_scroll == 0)
581 /* If we are scrolling the source or disassembly window, do a
582 "psuedo" scroll since not all of the source is in memory,
583 only what is in the viewport. If win_to_scroll is the command
584 window do nothing since the term should handle it. */
585 if (win_to_scroll == TUI_SRC_WIN
586 || win_to_scroll == TUI_DISASM_WIN)
587 tui_horizontal_source_scroll (win_to_scroll, RIGHT_SCROLL,
593 /* Scroll a window. Arguments are passed through a va_list. */
595 tui_scroll (enum tui_scroll_direction direction,
596 struct tui_win_info *win_to_scroll,
602 tui_scroll_forward (win_to_scroll, num_to_scroll);
604 case BACKWARD_SCROLL:
605 tui_scroll_backward (win_to_scroll, num_to_scroll);
608 tui_scroll_left (win_to_scroll, num_to_scroll);
611 tui_scroll_right (win_to_scroll, num_to_scroll);
620 tui_refresh_all_win (void)
622 enum tui_win_type type;
624 clearok (curscr, TRUE);
625 tui_refresh_all (tui_win_list);
626 for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++)
628 if (tui_win_list[type]
629 && tui_win_list[type]->generic.is_visible)
635 tui_show_source_content (tui_win_list[type]);
636 tui_check_and_display_highlight_if_needed (tui_win_list[type]);
637 tui_erase_exec_info_content (tui_win_list[type]);
638 tui_update_exec_info (tui_win_list[type]);
641 tui_refresh_data_win ();
648 tui_show_locator_content ();
652 /* Resize all the windows based on the terminal size. This function
653 gets called from within the readline sinwinch handler. */
655 tui_resize_all (void)
657 int height_diff, width_diff;
658 int screenheight, screenwidth;
660 rl_get_screen_size (&screenheight, &screenwidth);
661 width_diff = screenwidth - tui_term_width ();
662 height_diff = screenheight - tui_term_height ();
663 if (height_diff || width_diff)
665 enum tui_layout_type cur_layout = tui_current_layout ();
666 struct tui_win_info *win_with_focus = tui_win_with_focus ();
667 struct tui_win_info *first_win;
668 struct tui_win_info *second_win;
669 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
670 enum tui_win_type win_type;
671 int new_height, split_diff, cmd_split_diff, num_wins_displayed = 2;
673 #ifdef HAVE_RESIZE_TERM
674 resize_term (screenheight, screenwidth);
676 /* Turn keypad off while we resize. */
677 if (win_with_focus != TUI_CMD_WIN)
678 keypad (TUI_CMD_WIN->generic.handle, FALSE);
679 tui_update_gdb_sizes ();
680 tui_set_term_height_to (screenheight);
681 tui_set_term_width_to (screenwidth);
682 if (cur_layout == SRC_DISASSEM_COMMAND
683 || cur_layout == SRC_DATA_COMMAND
684 || cur_layout == DISASSEM_DATA_COMMAND)
685 num_wins_displayed++;
686 split_diff = height_diff / num_wins_displayed;
687 cmd_split_diff = split_diff;
688 if (height_diff % num_wins_displayed)
695 /* Now adjust each window. */
696 /* erase + clearok are used instead of a straightforward clear as
697 AIX 5.3 does not define clear. */
699 clearok (curscr, TRUE);
704 case DISASSEM_COMMAND:
705 first_win = (struct tui_win_info *) (tui_source_windows ())->list[0];
706 first_win->generic.width += width_diff;
707 locator->width += width_diff;
708 /* Check for invalid heights. */
709 if (height_diff == 0)
710 new_height = first_win->generic.height;
711 else if ((first_win->generic.height + split_diff) >=
712 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
713 new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1;
714 else if ((first_win->generic.height + split_diff) <= 0)
715 new_height = MIN_WIN_HEIGHT;
717 new_height = first_win->generic.height + split_diff;
719 locator->origin.y = new_height + 1;
720 make_invisible_and_set_new_height (first_win, new_height);
721 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
722 TUI_CMD_WIN->generic.width += width_diff;
723 new_height = screenheight - TUI_CMD_WIN->generic.origin.y;
724 make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);
725 make_visible_with_new_height (first_win);
726 make_visible_with_new_height (TUI_CMD_WIN);
727 if (first_win->generic.content_size <= 0)
728 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
731 if (cur_layout == SRC_DISASSEM_COMMAND)
733 first_win = TUI_SRC_WIN;
734 first_win->generic.width += width_diff;
735 second_win = TUI_DISASM_WIN;
736 second_win->generic.width += width_diff;
740 first_win = TUI_DATA_WIN;
741 first_win->generic.width += width_diff;
742 second_win = (struct tui_win_info *)
743 (tui_source_windows ())->list[0];
744 second_win->generic.width += width_diff;
746 /* Change the first window's height/width. */
747 /* Check for invalid heights. */
748 if (height_diff == 0)
749 new_height = first_win->generic.height;
750 else if ((first_win->generic.height +
751 second_win->generic.height + (split_diff * 2)) >=
752 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
753 new_height = (screenheight - MIN_CMD_WIN_HEIGHT - 1) / 2;
754 else if ((first_win->generic.height + split_diff) <= 0)
755 new_height = MIN_WIN_HEIGHT;
757 new_height = first_win->generic.height + split_diff;
758 make_invisible_and_set_new_height (first_win, new_height);
760 locator->width += width_diff;
762 /* Change the second window's height/width. */
763 /* Check for invalid heights. */
764 if (height_diff == 0)
765 new_height = second_win->generic.height;
766 else if ((first_win->generic.height +
767 second_win->generic.height + (split_diff * 2)) >=
768 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
770 new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1;
772 new_height = (new_height / 2) + 1;
776 else if ((second_win->generic.height + split_diff) <= 0)
777 new_height = MIN_WIN_HEIGHT;
779 new_height = second_win->generic.height + split_diff;
780 second_win->generic.origin.y = first_win->generic.height - 1;
781 make_invisible_and_set_new_height (second_win, new_height);
783 /* Change the command window's height/width. */
784 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
785 make_invisible_and_set_new_height (TUI_CMD_WIN,
786 TUI_CMD_WIN->generic.height
788 make_visible_with_new_height (first_win);
789 make_visible_with_new_height (second_win);
790 make_visible_with_new_height (TUI_CMD_WIN);
791 if (first_win->generic.content_size <= 0)
792 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
793 if (second_win->generic.content_size <= 0)
794 tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
797 /* Now remove all invisible windows, and their content so that
798 they get created again when called for with the new size. */
799 for (win_type = SRC_WIN; (win_type < MAX_MAJOR_WINDOWS); win_type++)
801 if (win_type != CMD_WIN
802 && (tui_win_list[win_type] != NULL)
803 && !tui_win_list[win_type]->generic.is_visible)
805 tui_free_window (tui_win_list[win_type]);
806 tui_win_list[win_type] = (struct tui_win_info *) NULL;
809 /* Turn keypad back on, unless focus is in the command
811 if (win_with_focus != TUI_CMD_WIN)
812 keypad (TUI_CMD_WIN->generic.handle, TRUE);
817 /* SIGWINCH signal handler for the tui. This signal handler is always
818 called, even when the readline package clears signals because it is
819 set as the old_sigwinch() (TUI only). */
821 tui_sigwinch_handler (int signal)
823 /* Say that a resize was done so that the readline can do it later
825 tui_set_win_resized_to (TRUE);
829 /* Initializes SIGWINCH signal handler for the tui. */
831 tui_initialize_win (void)
834 #ifdef HAVE_SIGACTION
835 struct sigaction old_winch;
837 memset (&old_winch, 0, sizeof (old_winch));
838 old_winch.sa_handler = &tui_sigwinch_handler;
839 sigaction (SIGWINCH, &old_winch, NULL);
841 signal (SIGWINCH, &tui_sigwinch_handler);
847 /*************************
848 ** STATIC LOCAL FUNCTIONS
849 **************************/
853 tui_scroll_forward_command (char *arg, int from_tty)
855 int num_to_scroll = 1;
856 struct tui_win_info *win_to_scroll;
858 /* Make sure the curses mode is enabled. */
860 if (arg == (char *) NULL)
861 parse_scrolling_args (arg, &win_to_scroll, (int *) NULL);
863 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
864 tui_scroll (FORWARD_SCROLL, win_to_scroll, num_to_scroll);
869 tui_scroll_backward_command (char *arg, int from_tty)
871 int num_to_scroll = 1;
872 struct tui_win_info *win_to_scroll;
874 /* Make sure the curses mode is enabled. */
876 if (arg == (char *) NULL)
877 parse_scrolling_args (arg, &win_to_scroll, (int *) NULL);
879 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
880 tui_scroll (BACKWARD_SCROLL, win_to_scroll, num_to_scroll);
885 tui_scroll_left_command (char *arg, int from_tty)
888 struct tui_win_info *win_to_scroll;
890 /* Make sure the curses mode is enabled. */
892 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
893 tui_scroll (LEFT_SCROLL, win_to_scroll, num_to_scroll);
898 tui_scroll_right_command (char *arg, int from_tty)
901 struct tui_win_info *win_to_scroll;
903 /* Make sure the curses mode is enabled. */
905 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
906 tui_scroll (RIGHT_SCROLL, win_to_scroll, num_to_scroll);
910 /* Set focus to the window named by 'arg'. */
912 tui_set_focus (char *arg, int from_tty)
914 if (arg != (char *) NULL)
916 char *buf_ptr = (char *) xstrdup (arg);
918 struct tui_win_info *win_info = (struct tui_win_info *) NULL;
920 for (i = 0; (i < strlen (buf_ptr)); i++)
921 buf_ptr[i] = toupper (arg[i]);
923 if (subset_compare (buf_ptr, "NEXT"))
924 win_info = tui_next_win (tui_win_with_focus ());
925 else if (subset_compare (buf_ptr, "PREV"))
926 win_info = tui_prev_win (tui_win_with_focus ());
928 win_info = tui_partial_win_by_name (buf_ptr);
930 if (win_info == (struct tui_win_info *) NULL
931 || !win_info->generic.is_visible)
932 warning (_("Invalid window specified. \n\
933 The window name specified must be valid and visible.\n"));
936 tui_set_win_focus_to (win_info);
937 keypad (TUI_CMD_WIN->generic.handle, (win_info != TUI_CMD_WIN));
940 if (TUI_DATA_WIN && TUI_DATA_WIN->generic.is_visible)
941 tui_refresh_data_win ();
943 printf_filtered (_("Focus set to %s window.\n"),
944 tui_win_name ((struct tui_gen_win_info *)
945 tui_win_with_focus ()));
948 warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE);
952 tui_set_focus_command (char *arg, int from_tty)
954 /* Make sure the curses mode is enabled. */
956 tui_set_focus (arg, from_tty);
961 tui_all_windows_info (char *arg, int from_tty)
963 enum tui_win_type type;
964 struct tui_win_info *win_with_focus = tui_win_with_focus ();
966 for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
967 if (tui_win_list[type]
968 && tui_win_list[type]->generic.is_visible)
970 if (win_with_focus == tui_win_list[type])
971 printf_filtered (" %s\t(%d lines) <has focus>\n",
972 tui_win_name (&tui_win_list[type]->generic),
973 tui_win_list[type]->generic.height);
975 printf_filtered (" %s\t(%d lines)\n",
976 tui_win_name (&tui_win_list[type]->generic),
977 tui_win_list[type]->generic.height);
983 tui_refresh_all_command (char *arg, int from_tty)
985 /* Make sure the curses mode is enabled. */
988 tui_refresh_all_win ();
992 /* Set the height of the specified window. */
994 tui_set_tab_width_command (char *arg, int from_tty)
996 /* Make sure the curses mode is enabled. */
998 if (arg != (char *) NULL)
1004 tui_set_default_tab_len (ts);
1006 warning (_("Tab widths greater than 0 must be specified."));
1011 /* Set the height of the specified window. */
1013 tui_set_win_height (char *arg, int from_tty)
1015 /* Make sure the curses mode is enabled. */
1017 if (arg != (char *) NULL)
1019 char *buf = xstrdup (arg);
1020 char *buf_ptr = buf;
1021 char *wname = (char *) NULL;
1023 struct tui_win_info *win_info;
1026 buf_ptr = strchr (buf_ptr, ' ');
1027 if (buf_ptr != (char *) NULL)
1029 *buf_ptr = (char) 0;
1031 /* Validate the window name. */
1032 for (i = 0; i < strlen (wname); i++)
1033 wname[i] = toupper (wname[i]);
1034 win_info = tui_partial_win_by_name (wname);
1036 if (win_info == (struct tui_win_info *) NULL
1037 || !win_info->generic.is_visible)
1038 warning (_("Invalid window specified. \n\
1039 The window name specified must be valid and visible.\n"));
1042 /* Process the size. */
1043 while (*(++buf_ptr) == ' ')
1046 if (*buf_ptr != (char) 0)
1049 int fixed_size = TRUE;
1052 if (*buf_ptr == '+' || *buf_ptr == '-')
1054 if (*buf_ptr == '-')
1059 input_no = atoi (buf_ptr);
1065 new_height = input_no;
1067 new_height = win_info->generic.height + input_no;
1069 /* Now change the window's height, and adjust
1070 all other windows around it. */
1071 if (tui_adjust_win_heights (win_info,
1072 new_height) == TUI_FAILURE)
1073 warning (_("Invalid window height specified.\n%s"),
1076 tui_update_gdb_sizes ();
1079 warning (_("Invalid window height specified.\n%s"),
1085 printf_filtered (WIN_HEIGHT_USAGE);
1087 if (buf != (char *) NULL)
1091 printf_filtered (WIN_HEIGHT_USAGE);
1094 /* Set the height of the specified window, with va_list. */
1096 tui_set_win_height_command (char *arg, int from_tty)
1098 /* Make sure the curses mode is enabled. */
1100 tui_set_win_height (arg, from_tty);
1104 /* XDB Compatibility command for setting the window height. This will
1105 increase or decrease the command window by the specified
1108 tui_xdb_set_win_height (char *arg, int from_tty)
1110 /* Make sure the curses mode is enabled. */
1112 if (arg != (char *) NULL)
1114 int input_no = atoi (arg);
1117 { /* Add 1 for the locator. */
1118 int new_height = tui_term_height () - (input_no + 1);
1120 if (!new_height_ok (tui_win_list[CMD_WIN], new_height)
1121 || tui_adjust_win_heights (tui_win_list[CMD_WIN],
1122 new_height) == TUI_FAILURE)
1123 warning (_("Invalid window height specified.\n%s"),
1124 XDBWIN_HEIGHT_USAGE);
1127 warning (_("Invalid window height specified.\n%s"),
1128 XDBWIN_HEIGHT_USAGE);
1131 warning (_("Invalid window height specified.\n%s"), XDBWIN_HEIGHT_USAGE);
1134 /* Set the height of the specified window, with va_list. */
1136 tui_xdb_set_win_height_command (char *arg, int from_tty)
1138 tui_xdb_set_win_height (arg, from_tty);
1142 /* Function to adjust all window heights around the primary. */
1143 static enum tui_status
1144 tui_adjust_win_heights (struct tui_win_info *primary_win_info,
1147 enum tui_status status = TUI_FAILURE;
1149 if (new_height_ok (primary_win_info, new_height))
1151 status = TUI_SUCCESS;
1152 if (new_height != primary_win_info->generic.height)
1155 struct tui_win_info *win_info;
1156 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
1157 enum tui_layout_type cur_layout = tui_current_layout ();
1159 diff = (new_height - primary_win_info->generic.height) * (-1);
1160 if (cur_layout == SRC_COMMAND
1161 || cur_layout == DISASSEM_COMMAND)
1163 struct tui_win_info *src_win_info;
1165 make_invisible_and_set_new_height (primary_win_info, new_height);
1166 if (primary_win_info->generic.type == CMD_WIN)
1168 win_info = (tui_source_windows ())->list[0];
1169 src_win_info = win_info;
1173 win_info = tui_win_list[CMD_WIN];
1174 src_win_info = primary_win_info;
1176 make_invisible_and_set_new_height (win_info,
1177 win_info->generic.height + diff);
1178 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
1179 make_visible_with_new_height (win_info);
1180 make_visible_with_new_height (primary_win_info);
1181 if (src_win_info->generic.content_size <= 0)
1182 tui_erase_source_content (src_win_info, EMPTY_SOURCE_PROMPT);
1186 struct tui_win_info *first_win;
1187 struct tui_win_info *second_win;
1189 if (cur_layout == SRC_DISASSEM_COMMAND)
1191 first_win = TUI_SRC_WIN;
1192 second_win = TUI_DISASM_WIN;
1196 first_win = TUI_DATA_WIN;
1197 second_win = (tui_source_windows ())->list[0];
1199 if (primary_win_info == TUI_CMD_WIN)
1200 { /* Split the change in height accross the 1st & 2nd
1201 windows, adjusting them as well. */
1202 /* Subtract the locator. */
1203 int first_split_diff = diff / 2;
1204 int second_split_diff = first_split_diff;
1208 if (first_win->generic.height >
1209 second_win->generic.height)
1217 second_split_diff--;
1219 second_split_diff++;
1222 /* Make sure that the minimum hieghts are
1224 while ((first_win->generic.height + first_split_diff) < 3)
1227 second_split_diff--;
1229 while ((second_win->generic.height + second_split_diff) < 3)
1231 second_split_diff++;
1234 make_invisible_and_set_new_height (
1236 first_win->generic.height + first_split_diff);
1237 second_win->generic.origin.y = first_win->generic.height - 1;
1238 make_invisible_and_set_new_height (second_win,
1239 second_win->generic.height
1240 + second_split_diff);
1241 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
1242 make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);
1246 if ((TUI_CMD_WIN->generic.height + diff) < 1)
1247 { /* If there is no way to increase the command
1248 window take real estate from the 1st or 2nd
1250 if ((TUI_CMD_WIN->generic.height + diff) < 1)
1254 for (i = TUI_CMD_WIN->generic.height + diff;
1256 if (primary_win_info == first_win)
1257 second_win->generic.height--;
1259 first_win->generic.height--;
1262 if (primary_win_info == first_win)
1263 make_invisible_and_set_new_height (first_win, new_height);
1265 make_invisible_and_set_new_height (
1267 first_win->generic.height);
1268 second_win->generic.origin.y = first_win->generic.height - 1;
1269 if (primary_win_info == second_win)
1270 make_invisible_and_set_new_height (second_win, new_height);
1272 make_invisible_and_set_new_height (
1273 second_win, second_win->generic.height);
1274 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
1275 if ((TUI_CMD_WIN->generic.height + diff) < 1)
1276 make_invisible_and_set_new_height (TUI_CMD_WIN, 1);
1278 make_invisible_and_set_new_height (TUI_CMD_WIN,
1279 TUI_CMD_WIN->generic.height + diff);
1281 make_visible_with_new_height (TUI_CMD_WIN);
1282 make_visible_with_new_height (second_win);
1283 make_visible_with_new_height (first_win);
1284 if (first_win->generic.content_size <= 0)
1285 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
1286 if (second_win->generic.content_size <= 0)
1287 tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
1296 /* Function make the target window (and auxillary windows associated
1297 with the targer) invisible, and set the new height and
1300 make_invisible_and_set_new_height (struct tui_win_info *win_info,
1304 struct tui_gen_win_info *gen_win_info;
1306 tui_make_invisible (&win_info->generic);
1307 win_info->generic.height = height;
1309 win_info->generic.viewport_height = height - 1;
1311 win_info->generic.viewport_height = height;
1312 if (win_info != TUI_CMD_WIN)
1313 win_info->generic.viewport_height--;
1315 /* Now deal with the auxillary windows associated with win_info. */
1316 switch (win_info->generic.type)
1320 gen_win_info = win_info->detail.source_info.execution_info;
1321 tui_make_invisible (gen_win_info);
1322 gen_win_info->height = height;
1323 gen_win_info->origin.y = win_info->generic.origin.y;
1325 gen_win_info->viewport_height = height - 1;
1327 gen_win_info->viewport_height = height;
1328 if (win_info != TUI_CMD_WIN)
1329 gen_win_info->viewport_height--;
1331 if (tui_win_has_locator (win_info))
1333 gen_win_info = tui_locator_win_info_ptr ();
1334 tui_make_invisible (gen_win_info);
1335 gen_win_info->origin.y = win_info->generic.origin.y + height;
1339 /* Delete all data item windows. */
1340 for (i = 0; i < win_info->generic.content_size; i++)
1342 gen_win_info = (struct tui_gen_win_info *)
1343 &((struct tui_win_element *)
1344 win_info->generic.content[i])->which_element.data_window;
1345 tui_delete_win (gen_win_info->handle);
1346 gen_win_info->handle = (WINDOW *) NULL;
1355 /* Function to make the windows with new heights visible. This means
1356 re-creating the windows' content since the window had to be
1357 destroyed to be made invisible. */
1359 make_visible_with_new_height (struct tui_win_info *win_info)
1363 tui_make_visible (&win_info->generic);
1364 tui_check_and_display_highlight_if_needed (win_info);
1365 switch (win_info->generic.type)
1369 tui_free_win_content (win_info->detail.source_info.execution_info);
1370 tui_make_visible (win_info->detail.source_info.execution_info);
1371 if (win_info->generic.content != NULL)
1373 struct gdbarch *gdbarch = win_info->detail.source_info.gdbarch;
1374 struct tui_line_or_address line_or_addr;
1375 struct symtab_and_line cursal
1376 = get_current_source_symtab_and_line ();
1378 line_or_addr = win_info->detail.source_info.start_line_or_addr;
1379 tui_free_win_content (&win_info->generic);
1380 tui_update_source_window (win_info, gdbarch,
1381 cursal.symtab, line_or_addr, TRUE);
1383 else if (deprecated_safe_get_selected_frame () != NULL)
1385 struct tui_line_or_address line;
1386 struct symtab_and_line cursal
1387 = get_current_source_symtab_and_line ();
1388 struct frame_info *frame = deprecated_safe_get_selected_frame ();
1389 struct gdbarch *gdbarch = get_frame_arch (frame);
1391 s = find_pc_symtab (get_frame_pc (frame));
1392 if (win_info->generic.type == SRC_WIN)
1394 line.loa = LOA_LINE;
1395 line.u.line_no = cursal.line;
1399 line.loa = LOA_ADDRESS;
1400 find_line_pc (s, cursal.line, &line.u.addr);
1402 tui_update_source_window (win_info, gdbarch, s, line, TRUE);
1404 if (tui_win_has_locator (win_info))
1406 tui_make_visible (tui_locator_win_info_ptr ());
1407 tui_show_locator_content ();
1411 tui_display_all_data ();
1414 win_info->detail.command_info.cur_line = 0;
1415 win_info->detail.command_info.curch = 0;
1417 wresize (TUI_CMD_WIN->generic.handle,
1418 TUI_CMD_WIN->generic.height,
1419 TUI_CMD_WIN->generic.width);
1421 mvwin (TUI_CMD_WIN->generic.handle,
1422 TUI_CMD_WIN->generic.origin.y,
1423 TUI_CMD_WIN->generic.origin.x);
1424 wmove (win_info->generic.handle,
1425 win_info->detail.command_info.cur_line,
1426 win_info->detail.command_info.curch);
1435 new_height_ok (struct tui_win_info *primary_win_info,
1438 int ok = (new_height < tui_term_height ());
1443 enum tui_layout_type cur_layout = tui_current_layout ();
1445 diff = (new_height - primary_win_info->generic.height) * (-1);
1446 if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND)
1448 ok = ((primary_win_info->generic.type == CMD_WIN
1449 && new_height <= (tui_term_height () - 4)
1450 && new_height >= MIN_CMD_WIN_HEIGHT)
1451 || (primary_win_info->generic.type != CMD_WIN
1452 && new_height <= (tui_term_height () - 2)
1453 && new_height >= MIN_WIN_HEIGHT));
1455 { /* Check the total height. */
1456 struct tui_win_info *win_info;
1458 if (primary_win_info == TUI_CMD_WIN)
1459 win_info = (tui_source_windows ())->list[0];
1461 win_info = TUI_CMD_WIN;
1463 (win_info->generic.height + diff)) <= tui_term_height ());
1468 int cur_total_height, total_height, min_height = 0;
1469 struct tui_win_info *first_win;
1470 struct tui_win_info *second_win;
1472 if (cur_layout == SRC_DISASSEM_COMMAND)
1474 first_win = TUI_SRC_WIN;
1475 second_win = TUI_DISASM_WIN;
1479 first_win = TUI_DATA_WIN;
1480 second_win = (tui_source_windows ())->list[0];
1482 /* We could simply add all the heights to obtain the same
1483 result but below is more explicit since we subtract 1 for
1484 the line that the first and second windows share, and add
1485 one for the locator. */
1486 total_height = cur_total_height =
1487 (first_win->generic.height + second_win->generic.height - 1)
1488 + TUI_CMD_WIN->generic.height + 1; /* Locator. */
1489 if (primary_win_info == TUI_CMD_WIN)
1491 /* Locator included since first & second win share a line. */
1492 ok = ((first_win->generic.height +
1493 second_win->generic.height + diff) >=
1494 (MIN_WIN_HEIGHT * 2)
1495 && new_height >= MIN_CMD_WIN_HEIGHT);
1498 total_height = new_height +
1499 (first_win->generic.height +
1500 second_win->generic.height + diff);
1501 min_height = MIN_CMD_WIN_HEIGHT;
1506 min_height = MIN_WIN_HEIGHT;
1508 /* First see if we can increase/decrease the command
1509 window. And make sure that the command window is at
1511 ok = ((TUI_CMD_WIN->generic.height + diff) > 0);
1513 { /* Looks like we have to increase/decrease one of
1514 the other windows. */
1515 if (primary_win_info == first_win)
1516 ok = (second_win->generic.height + diff) >= min_height;
1518 ok = (first_win->generic.height + diff) >= min_height;
1522 if (primary_win_info == first_win)
1523 total_height = new_height +
1524 second_win->generic.height +
1525 TUI_CMD_WIN->generic.height + diff;
1527 total_height = new_height +
1528 first_win->generic.height +
1529 TUI_CMD_WIN->generic.height + diff;
1532 /* Now make sure that the proposed total height doesn't
1533 exceed the old total height. */
1535 ok = (new_height >= min_height
1536 && total_height <= cur_total_height);
1545 parse_scrolling_args (char *arg,
1546 struct tui_win_info **win_to_scroll,
1551 *win_to_scroll = tui_win_with_focus ();
1553 /* First set up the default window to scroll, in case there is no
1555 if (arg != (char *) NULL)
1557 char *buf, *buf_ptr;
1559 /* Process the number of lines to scroll. */
1560 buf = buf_ptr = xstrdup (arg);
1561 if (isdigit (*buf_ptr))
1566 buf_ptr = strchr (buf_ptr, ' ');
1567 if (buf_ptr != (char *) NULL)
1569 *buf_ptr = (char) 0;
1571 *num_to_scroll = atoi (num_str);
1574 else if (num_to_scroll)
1575 *num_to_scroll = atoi (num_str);
1578 /* Process the window name if one is specified. */
1579 if (buf_ptr != (char *) NULL)
1584 if (*buf_ptr == ' ')
1585 while (*(++buf_ptr) == ' ')
1588 if (*buf_ptr != (char) 0)
1592 /* Validate the window name. */
1593 for (i = 0; i < strlen (wname); i++)
1594 wname[i] = toupper (wname[i]);
1599 *win_to_scroll = tui_partial_win_by_name (wname);
1601 if (*win_to_scroll == (struct tui_win_info *) NULL
1602 || !(*win_to_scroll)->generic.is_visible)
1603 error (_("Invalid window specified. \n\
1604 The window name specified must be valid and visible.\n"));
1605 else if (*win_to_scroll == TUI_CMD_WIN)
1606 *win_to_scroll = (tui_source_windows ())->list[0];