1 /* TUI window generic functions.
3 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
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 2 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, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* This module contains procedures for handling tui window functions
26 like resize, scrolling, scrolling, changing focus, etc.
28 Author: Susan B. Macchia */
33 #include "breakpoint.h"
35 #include "cli/cli-cmds.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"
49 #include "gdb_curses.h"
51 #include "gdb_string.h"
53 #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
*, int);
60 static enum tui_status
tui_adjust_win_heights (struct tui_win_info
*, int);
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 *, struct tui_win_info
* *, int *);
75 /***************************************
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"
82 /***************************************
84 ***************************************/
87 # define ACS_LRCORNER '+'
90 # define ACS_LLCORNER '+'
93 # define ACS_ULCORNER '+'
96 # define ACS_URCORNER '+'
99 # define ACS_HLINE '-'
102 # define ACS_VLINE '|'
105 /* Possible values for tui-border-kind variable. */
106 static const char *tui_border_kind_enums
[] = {
113 /* Possible values for tui-border-mode and tui-active-border-mode. */
114 static const char *tui_border_mode_enums
[] = {
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. */
134 struct tui_translate tui_border_mode_translate
[] = {
135 { "normal", A_NORMAL
},
136 { "standout", A_STANDOUT
},
137 { "reverse", A_REVERSE
},
139 { "half-standout", A_DIM
| A_STANDOUT
},
141 { "bold-standout", A_BOLD
| A_STANDOUT
},
143 { "normal", A_NORMAL
}
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). */
150 struct tui_translate tui_border_kind_translate_vline
[] = {
158 struct tui_translate tui_border_kind_translate_hline
[] = {
166 struct tui_translate tui_border_kind_translate_ulcorner
[] = {
174 struct tui_translate tui_border_kind_translate_urcorner
[] = {
182 struct tui_translate tui_border_kind_translate_llcorner
[] = {
190 struct tui_translate tui_border_kind_translate_lrcorner
[] = {
199 /* Tui configuration variables controlled with set/show command. */
200 const char *tui_active_border_mode
= "bold-standout";
201 const char *tui_border_mode
= "normal";
202 const char *tui_border_kind
= "acs";
204 /* Tui internal configuration variables. These variables are
205 updated by tui_update_variables to reflect the tui configuration
207 chtype tui_border_vline
;
208 chtype tui_border_hline
;
209 chtype tui_border_ulcorner
;
210 chtype tui_border_urcorner
;
211 chtype tui_border_llcorner
;
212 chtype tui_border_lrcorner
;
214 int tui_border_attrs
;
215 int tui_active_border_attrs
;
217 /* Identify the item in the translation table.
218 When the item is not recognized, use the default entry. */
219 static struct tui_translate
*
220 translate (const char *name
, struct tui_translate
*table
)
224 if (name
&& strcmp (table
->name
, name
) == 0)
229 /* Not found, return default entry. */
234 /* Update the tui internal configuration according to gdb settings.
235 Returns 1 if the configuration has changed and the screen should
238 tui_update_variables (void)
241 struct tui_translate
*entry
;
243 entry
= translate (tui_border_mode
, tui_border_mode_translate
);
244 if (tui_border_attrs
!= entry
->value
)
246 tui_border_attrs
= entry
->value
;
249 entry
= translate (tui_active_border_mode
, tui_border_mode_translate
);
250 if (tui_active_border_attrs
!= entry
->value
)
252 tui_active_border_attrs
= entry
->value
;
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
)
262 tui_border_lrcorner
= (entry
->value
< 0) ? ACS_LRCORNER
: entry
->value
;
265 entry
= translate (tui_border_kind
, tui_border_kind_translate_llcorner
);
266 tui_border_llcorner
= (entry
->value
< 0) ? ACS_LLCORNER
: entry
->value
;
268 entry
= translate (tui_border_kind
, tui_border_kind_translate_ulcorner
);
269 tui_border_ulcorner
= (entry
->value
< 0) ? ACS_ULCORNER
: entry
->value
;
271 entry
= translate (tui_border_kind
, tui_border_kind_translate_urcorner
);
272 tui_border_urcorner
= (entry
->value
< 0) ? ACS_URCORNER
: entry
->value
;
274 entry
= translate (tui_border_kind
, tui_border_kind_translate_hline
);
275 tui_border_hline
= (entry
->value
< 0) ? ACS_HLINE
: entry
->value
;
277 entry
= translate (tui_border_kind
, tui_border_kind_translate_vline
);
278 tui_border_vline
= (entry
->value
< 0) ? ACS_VLINE
: entry
->value
;
284 set_tui_cmd (char *args
, int from_tty
)
289 show_tui_cmd (char *args
, int from_tty
)
293 static struct cmd_list_element
*tuilist
;
296 tui_command (char *args
, int from_tty
)
298 printf_unfiltered (_("\"tui\" must be followed by the name of a "
300 help_list (tuilist
, "tui ", -1, gdb_stdout
);
303 struct cmd_list_element
**
304 tui_get_cmd_list (void)
307 add_prefix_cmd ("tui", class_tui
, tui_command
,
308 _("Text User Interface commands."),
309 &tuilist
, "tui ", 0, &cmdlist
);
313 /* Function to initialize gdb commands, for tui window manipulation. */
315 _initialize_tui_win (void)
317 struct cmd_list_element
*c
;
318 static struct cmd_list_element
*tui_setlist
;
319 static struct cmd_list_element
*tui_showlist
;
321 /* Define the classes of commands.
322 They will appear in the help list in the reverse of this order. */
323 add_prefix_cmd ("tui", class_tui
, set_tui_cmd
,
324 _("TUI configuration variables"),
325 &tui_setlist
, "set tui ",
326 0/*allow-unknown*/, &setlist
);
327 add_prefix_cmd ("tui", class_tui
, show_tui_cmd
,
328 _("TUI configuration variables"),
329 &tui_showlist
, "show tui ",
330 0/*allow-unknown*/, &showlist
);
332 add_com ("refresh", class_tui
, tui_refresh_all_command
,
333 _("Refresh the terminal display.\n"));
335 add_com_alias ("U", "refresh", class_tui
, 0);
336 add_com ("tabset", class_tui
, tui_set_tab_width_command
, _("\
337 Set the width (in characters) of tab stops.\n\
338 Usage: tabset <n>\n"));
339 add_com ("winheight", class_tui
, tui_set_win_height_command
, _("\
340 Set the height of a specified window.\n\
341 Usage: winheight <win_name> [+ | -] <#lines>\n\
343 src : the source window\n\
344 cmd : the command window\n\
345 asm : the disassembly window\n\
346 regs : the register display\n"));
347 add_com_alias ("wh", "winheight", class_tui
, 0);
348 add_info ("win", tui_all_windows_info
,
349 _("List of all displayed windows.\n"));
350 add_com ("focus", class_tui
, tui_set_focus_command
, _("\
351 Set focus to named window or next/prev window.\n\
352 Usage: focus {<win> | next | prev}\n\
353 Valid Window names are:\n\
354 src : the source window\n\
355 asm : the disassembly window\n\
356 regs : the register display\n\
357 cmd : the command window\n"));
358 add_com_alias ("fs", "focus", class_tui
, 0);
359 add_com ("+", class_tui
, tui_scroll_forward_command
, _("\
360 Scroll window forward.\n\
361 Usage: + [win] [n]\n"));
362 add_com ("-", class_tui
, tui_scroll_backward_command
, _("\
363 Scroll window backward.\n\
364 Usage: - [win] [n]\n"));
365 add_com ("<", class_tui
, tui_scroll_left_command
, _("\
366 Scroll window forward.\n\
367 Usage: < [win] [n]\n"));
368 add_com (">", class_tui
, tui_scroll_right_command
, _("\
369 Scroll window backward.\n\
370 Usage: > [win] [n]\n"));
372 add_com ("w", class_xdb
, tui_xdb_set_win_height_command
, _("\
373 XDB compatibility command for setting the height of a command window.\n\
374 Usage: w <#lines>\n"));
376 /* Define the tui control variables. */
378 ("border-kind", no_class
,
379 tui_border_kind_enums
, &tui_border_kind
,
380 "Set the kind of border for TUI windows.\n"
381 "This variable controls the border of TUI windows:\n"
382 "space use a white space\n"
383 "ascii use ascii characters + - | for the border\n"
384 "acs use the Alternate Character Set\n",
386 deprecated_add_show_from_set (c
, &tui_showlist
);
389 ("border-mode", no_class
,
390 tui_border_mode_enums
, &tui_border_mode
,
391 "Set the attribute mode to use for the TUI window borders.\n"
392 "This variable controls the attributes to use for the window borders:\n"
393 "normal normal display\n"
394 "standout use highlight mode of terminal\n"
395 "reverse use reverse video mode\n"
396 "half use half bright\n"
397 "half-standout use half bright and standout mode\n"
398 "bold use extra bright or bold\n"
399 "bold-standout use extra bright or bold with standout mode\n",
401 deprecated_add_show_from_set (c
, &tui_showlist
);
404 ("active-border-mode", no_class
,
405 tui_border_mode_enums
, &tui_active_border_mode
,
406 "Set the attribute mode to use for the active TUI window border.\n"
407 "This variable controls the attributes to use for the active window border:\n"
408 "normal normal display\n"
409 "standout use highlight mode of terminal\n"
410 "reverse use reverse video mode\n"
411 "half use half bright\n"
412 "half-standout use half bright and standout mode\n"
413 "bold use extra bright or bold\n"
414 "bold-standout use extra bright or bold with standout mode\n",
416 deprecated_add_show_from_set (c
, &tui_showlist
);
419 /* Update gdb's knowledge of the terminal size. */
421 tui_update_gdb_sizes (void)
424 int screenheight
, screenwidth
;
426 rl_get_screen_size (&screenheight
, &screenwidth
);
427 /* Set to TUI command window dimension or use readline values. */
428 sprintf (cmd
, "set width %d",
429 tui_active
? TUI_CMD_WIN
->generic
.width
: screenwidth
);
430 execute_command (cmd
, 0);
431 sprintf (cmd
, "set height %d",
432 tui_active
? TUI_CMD_WIN
->generic
.height
: screenheight
);
433 execute_command (cmd
, 0);
437 /* Set the logical focus to win_info. */
439 tui_set_win_focus_to (struct tui_win_info
* win_info
)
441 if (win_info
!= NULL
)
443 struct tui_win_info
* win_with_focus
= tui_win_with_focus ();
445 if (win_with_focus
!= NULL
446 && win_with_focus
->generic
.type
!= CMD_WIN
)
447 tui_unhighlight_win (win_with_focus
);
448 tui_set_win_with_focus (win_info
);
449 if (win_info
->generic
.type
!= CMD_WIN
)
450 tui_highlight_win (win_info
);
456 tui_scroll_forward (struct tui_win_info
* win_to_scroll
, int num_to_scroll
)
458 if (win_to_scroll
!= TUI_CMD_WIN
)
460 int _num_to_scroll
= num_to_scroll
;
462 if (num_to_scroll
== 0)
463 _num_to_scroll
= win_to_scroll
->generic
.height
- 3;
465 ** If we are scrolling the source or disassembly window, do a
466 ** "psuedo" scroll since not all of the source is in memory,
467 ** only what is in the viewport. If win_to_scroll is the
468 ** command window do nothing since the term should handle it.
470 if (win_to_scroll
== TUI_SRC_WIN
)
471 tui_vertical_source_scroll (FORWARD_SCROLL
, _num_to_scroll
);
472 else if (win_to_scroll
== TUI_DISASM_WIN
)
473 tui_vertical_disassem_scroll (FORWARD_SCROLL
, _num_to_scroll
);
474 else if (win_to_scroll
== TUI_DATA_WIN
)
475 tui_vertical_data_scroll (FORWARD_SCROLL
, _num_to_scroll
);
480 tui_scroll_backward (struct tui_win_info
* win_to_scroll
, int num_to_scroll
)
482 if (win_to_scroll
!= TUI_CMD_WIN
)
484 int _num_to_scroll
= num_to_scroll
;
486 if (num_to_scroll
== 0)
487 _num_to_scroll
= win_to_scroll
->generic
.height
- 3;
489 ** If we are scrolling the source or disassembly window, do a
490 ** "psuedo" scroll since not all of the source is in memory,
491 ** only what is in the viewport. If win_to_scroll is the
492 ** command window do nothing since the term should handle it.
494 if (win_to_scroll
== TUI_SRC_WIN
)
495 tui_vertical_source_scroll (BACKWARD_SCROLL
, _num_to_scroll
);
496 else if (win_to_scroll
== TUI_DISASM_WIN
)
497 tui_vertical_disassem_scroll (BACKWARD_SCROLL
, _num_to_scroll
);
498 else if (win_to_scroll
== TUI_DATA_WIN
)
499 tui_vertical_data_scroll (BACKWARD_SCROLL
, _num_to_scroll
);
505 tui_scroll_left (struct tui_win_info
* win_to_scroll
, int num_to_scroll
)
507 if (win_to_scroll
!= TUI_CMD_WIN
)
509 int _num_to_scroll
= num_to_scroll
;
511 if (_num_to_scroll
== 0)
514 ** If we are scrolling the source or disassembly window, do a
515 ** "psuedo" scroll since not all of the source is in memory,
516 ** only what is in the viewport. If win_to_scroll is the
517 ** command window do nothing since the term should handle it.
519 if (win_to_scroll
== TUI_SRC_WIN
|| win_to_scroll
== TUI_DISASM_WIN
)
520 tui_horizontal_source_scroll (win_to_scroll
, LEFT_SCROLL
, _num_to_scroll
);
526 tui_scroll_right (struct tui_win_info
* win_to_scroll
, int num_to_scroll
)
528 if (win_to_scroll
!= TUI_CMD_WIN
)
530 int _num_to_scroll
= num_to_scroll
;
532 if (_num_to_scroll
== 0)
535 ** If we are scrolling the source or disassembly window, do a
536 ** "psuedo" scroll since not all of the source is in memory,
537 ** only what is in the viewport. If win_to_scroll is the
538 ** command window do nothing since the term should handle it.
540 if (win_to_scroll
== TUI_SRC_WIN
|| win_to_scroll
== TUI_DISASM_WIN
)
541 tui_horizontal_source_scroll (win_to_scroll
, RIGHT_SCROLL
, _num_to_scroll
);
546 /* Scroll a window. Arguments are passed through a va_list. */
548 tui_scroll (enum tui_scroll_direction direction
,
549 struct tui_win_info
* win_to_scroll
,
555 tui_scroll_forward (win_to_scroll
, num_to_scroll
);
557 case BACKWARD_SCROLL
:
558 tui_scroll_backward (win_to_scroll
, num_to_scroll
);
561 tui_scroll_left (win_to_scroll
, num_to_scroll
);
564 tui_scroll_right (win_to_scroll
, num_to_scroll
);
573 tui_refresh_all_win (void)
575 enum tui_win_type type
;
577 clearok (curscr
, TRUE
);
578 tui_refresh_all (tui_win_list
);
579 for (type
= SRC_WIN
; type
< MAX_MAJOR_WINDOWS
; type
++)
581 if (tui_win_list
[type
] && tui_win_list
[type
]->generic
.is_visible
)
587 tui_show_source_content (tui_win_list
[type
]);
588 tui_check_and_display_highlight_if_needed (tui_win_list
[type
]);
589 tui_erase_exec_info_content (tui_win_list
[type
]);
590 tui_update_exec_info (tui_win_list
[type
]);
593 tui_refresh_data_win ();
600 tui_show_locator_content ();
604 /* Resize all the windows based on the the terminal size. This
605 function gets called from within the readline sinwinch handler. */
607 tui_resize_all (void)
609 int height_diff
, width_diff
;
610 int screenheight
, screenwidth
;
612 rl_get_screen_size (&screenheight
, &screenwidth
);
613 width_diff
= screenwidth
- tui_term_width ();
614 height_diff
= screenheight
- tui_term_height ();
615 if (height_diff
|| width_diff
)
617 enum tui_layout_type cur_layout
= tui_current_layout ();
618 struct tui_win_info
* win_with_focus
= tui_win_with_focus ();
619 struct tui_win_info
*first_win
;
620 struct tui_win_info
*second_win
;
621 struct tui_gen_win_info
* locator
= tui_locator_win_info_ptr ();
622 enum tui_win_type win_type
;
623 int new_height
, split_diff
, cmd_split_diff
, num_wins_displayed
= 2;
625 #ifdef HAVE_RESIZE_TERM
626 resize_term (screenheight
, screenwidth
);
628 /* turn keypad off while we resize */
629 if (win_with_focus
!= TUI_CMD_WIN
)
630 keypad (TUI_CMD_WIN
->generic
.handle
, FALSE
);
631 tui_update_gdb_sizes ();
632 tui_set_term_height_to (screenheight
);
633 tui_set_term_width_to (screenwidth
);
634 if (cur_layout
== SRC_DISASSEM_COMMAND
||
635 cur_layout
== SRC_DATA_COMMAND
|| cur_layout
== DISASSEM_DATA_COMMAND
)
636 num_wins_displayed
++;
637 split_diff
= height_diff
/ num_wins_displayed
;
638 cmd_split_diff
= split_diff
;
639 if (height_diff
% num_wins_displayed
)
646 /* now adjust each window */
652 case DISASSEM_COMMAND
:
653 first_win
= (struct tui_win_info
*) (tui_source_windows ())->list
[0];
654 first_win
->generic
.width
+= width_diff
;
655 locator
->width
+= width_diff
;
656 /* check for invalid heights */
657 if (height_diff
== 0)
658 new_height
= first_win
->generic
.height
;
659 else if ((first_win
->generic
.height
+ split_diff
) >=
660 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
661 new_height
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
662 else if ((first_win
->generic
.height
+ split_diff
) <= 0)
663 new_height
= MIN_WIN_HEIGHT
;
665 new_height
= first_win
->generic
.height
+ split_diff
;
667 make_invisible_and_set_new_height (first_win
, new_height
);
668 TUI_CMD_WIN
->generic
.origin
.y
= locator
->origin
.y
+ 1;
669 TUI_CMD_WIN
->generic
.width
+= width_diff
;
670 new_height
= screenheight
- TUI_CMD_WIN
->generic
.origin
.y
;
671 make_invisible_and_set_new_height (TUI_CMD_WIN
, new_height
);
672 make_visible_with_new_height (first_win
);
673 make_visible_with_new_height (TUI_CMD_WIN
);
674 if (first_win
->generic
.content_size
<= 0)
675 tui_erase_source_content (first_win
, EMPTY_SOURCE_PROMPT
);
678 if (cur_layout
== SRC_DISASSEM_COMMAND
)
680 first_win
= TUI_SRC_WIN
;
681 first_win
->generic
.width
+= width_diff
;
682 second_win
= TUI_DISASM_WIN
;
683 second_win
->generic
.width
+= width_diff
;
687 first_win
= TUI_DATA_WIN
;
688 first_win
->generic
.width
+= width_diff
;
689 second_win
= (struct tui_win_info
*) (tui_source_windows ())->list
[0];
690 second_win
->generic
.width
+= width_diff
;
692 /* Change the first window's height/width */
693 /* check for invalid heights */
694 if (height_diff
== 0)
695 new_height
= first_win
->generic
.height
;
696 else if ((first_win
->generic
.height
+
697 second_win
->generic
.height
+ (split_diff
* 2)) >=
698 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
699 new_height
= (screenheight
- MIN_CMD_WIN_HEIGHT
- 1) / 2;
700 else if ((first_win
->generic
.height
+ split_diff
) <= 0)
701 new_height
= MIN_WIN_HEIGHT
;
703 new_height
= first_win
->generic
.height
+ split_diff
;
704 make_invisible_and_set_new_height (first_win
, new_height
);
706 locator
->width
+= width_diff
;
708 /* Change the second window's height/width */
709 /* check for invalid heights */
710 if (height_diff
== 0)
711 new_height
= second_win
->generic
.height
;
712 else if ((first_win
->generic
.height
+
713 second_win
->generic
.height
+ (split_diff
* 2)) >=
714 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
716 new_height
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
718 new_height
= (new_height
/ 2) + 1;
722 else if ((second_win
->generic
.height
+ split_diff
) <= 0)
723 new_height
= MIN_WIN_HEIGHT
;
725 new_height
= second_win
->generic
.height
+ split_diff
;
726 second_win
->generic
.origin
.y
= first_win
->generic
.height
- 1;
727 make_invisible_and_set_new_height (second_win
, new_height
);
729 /* Change the command window's height/width */
730 TUI_CMD_WIN
->generic
.origin
.y
= locator
->origin
.y
+ 1;
731 make_invisible_and_set_new_height (
732 TUI_CMD_WIN
, TUI_CMD_WIN
->generic
.height
+ cmd_split_diff
);
733 make_visible_with_new_height (first_win
);
734 make_visible_with_new_height (second_win
);
735 make_visible_with_new_height (TUI_CMD_WIN
);
736 if (first_win
->generic
.content_size
<= 0)
737 tui_erase_source_content (first_win
, EMPTY_SOURCE_PROMPT
);
738 if (second_win
->generic
.content_size
<= 0)
739 tui_erase_source_content (second_win
, EMPTY_SOURCE_PROMPT
);
743 ** Now remove all invisible windows, and their content so that they get
744 ** created again when called for with the new size
746 for (win_type
= SRC_WIN
; (win_type
< MAX_MAJOR_WINDOWS
); win_type
++)
748 if (win_type
!= CMD_WIN
&& (tui_win_list
[win_type
] != NULL
)
749 && !tui_win_list
[win_type
]->generic
.is_visible
)
751 tui_free_window (tui_win_list
[win_type
]);
752 tui_win_list
[win_type
] = (struct tui_win_info
*) NULL
;
755 tui_set_win_resized_to (TRUE
);
756 /* turn keypad back on, unless focus is in the command window */
757 if (win_with_focus
!= TUI_CMD_WIN
)
758 keypad (TUI_CMD_WIN
->generic
.handle
, TRUE
);
763 /* SIGWINCH signal handler for the tui. This signal handler is always
764 called, even when the readline package clears signals because it is
765 set as the old_sigwinch() (TUI only). */
767 tui_sigwinch_handler (int signal
)
770 ** Say that a resize was done so that the readline can do it
771 ** later when appropriate.
773 tui_set_win_resized_to (TRUE
);
778 /*************************
779 ** STATIC LOCAL FUNCTIONS
780 **************************/
784 tui_scroll_forward_command (char *arg
, int from_tty
)
786 int num_to_scroll
= 1;
787 struct tui_win_info
* win_to_scroll
;
789 /* Make sure the curses mode is enabled. */
791 if (arg
== (char *) NULL
)
792 parse_scrolling_args (arg
, &win_to_scroll
, (int *) NULL
);
794 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
795 tui_scroll (FORWARD_SCROLL
, win_to_scroll
, num_to_scroll
);
800 tui_scroll_backward_command (char *arg
, int from_tty
)
802 int num_to_scroll
= 1;
803 struct tui_win_info
* win_to_scroll
;
805 /* Make sure the curses mode is enabled. */
807 if (arg
== (char *) NULL
)
808 parse_scrolling_args (arg
, &win_to_scroll
, (int *) NULL
);
810 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
811 tui_scroll (BACKWARD_SCROLL
, win_to_scroll
, num_to_scroll
);
816 tui_scroll_left_command (char *arg
, int from_tty
)
819 struct tui_win_info
* win_to_scroll
;
821 /* Make sure the curses mode is enabled. */
823 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
824 tui_scroll (LEFT_SCROLL
, win_to_scroll
, num_to_scroll
);
829 tui_scroll_right_command (char *arg
, int from_tty
)
832 struct tui_win_info
* win_to_scroll
;
834 /* Make sure the curses mode is enabled. */
836 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
837 tui_scroll (RIGHT_SCROLL
, win_to_scroll
, num_to_scroll
);
841 /* Set focus to the window named by 'arg'. */
843 tui_set_focus (char *arg
, int from_tty
)
845 if (arg
!= (char *) NULL
)
847 char *buf_ptr
= (char *) xstrdup (arg
);
849 struct tui_win_info
* win_info
= (struct tui_win_info
*) NULL
;
851 for (i
= 0; (i
< strlen (buf_ptr
)); i
++)
852 buf_ptr
[i
] = toupper (arg
[i
]);
854 if (subset_compare (buf_ptr
, "NEXT"))
855 win_info
= tui_next_win (tui_win_with_focus ());
856 else if (subset_compare (buf_ptr
, "PREV"))
857 win_info
= tui_prev_win (tui_win_with_focus ());
859 win_info
= tui_partial_win_by_name (buf_ptr
);
861 if (win_info
== (struct tui_win_info
*) NULL
|| !win_info
->generic
.is_visible
)
862 warning (_("Invalid window specified. \n\
863 The window name specified must be valid and visible.\n"));
866 tui_set_win_focus_to (win_info
);
867 keypad (TUI_CMD_WIN
->generic
.handle
, (win_info
!= TUI_CMD_WIN
));
870 if (TUI_DATA_WIN
&& TUI_DATA_WIN
->generic
.is_visible
)
871 tui_refresh_data_win ();
873 printf_filtered (_("Focus set to %s window.\n"),
874 tui_win_name ((struct tui_gen_win_info
*) tui_win_with_focus ()));
877 warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE
);
881 tui_set_focus_command (char *arg
, int from_tty
)
883 /* Make sure the curses mode is enabled. */
885 tui_set_focus (arg
, from_tty
);
890 tui_all_windows_info (char *arg
, int from_tty
)
892 enum tui_win_type type
;
893 struct tui_win_info
* win_with_focus
= tui_win_with_focus ();
895 for (type
= SRC_WIN
; (type
< MAX_MAJOR_WINDOWS
); type
++)
896 if (tui_win_list
[type
] && tui_win_list
[type
]->generic
.is_visible
)
898 if (win_with_focus
== tui_win_list
[type
])
899 printf_filtered (" %s\t(%d lines) <has focus>\n",
900 tui_win_name (&tui_win_list
[type
]->generic
),
901 tui_win_list
[type
]->generic
.height
);
903 printf_filtered (" %s\t(%d lines)\n",
904 tui_win_name (&tui_win_list
[type
]->generic
),
905 tui_win_list
[type
]->generic
.height
);
911 tui_refresh_all_command (char *arg
, int from_tty
)
913 /* Make sure the curses mode is enabled. */
916 tui_refresh_all_win ();
920 /* Set the height of the specified window. */
922 tui_set_tab_width_command (char *arg
, int from_tty
)
924 /* Make sure the curses mode is enabled. */
926 if (arg
!= (char *) NULL
)
932 tui_set_default_tab_len (ts
);
934 warning (_("Tab widths greater than 0 must be specified."));
939 /* Set the height of the specified window. */
941 tui_set_win_height (char *arg
, int from_tty
)
943 /* Make sure the curses mode is enabled. */
945 if (arg
!= (char *) NULL
)
947 char *buf
= xstrdup (arg
);
949 char *wname
= (char *) NULL
;
951 struct tui_win_info
* win_info
;
954 buf_ptr
= strchr (buf_ptr
, ' ');
955 if (buf_ptr
!= (char *) NULL
)
960 ** Validate the window name
962 for (i
= 0; i
< strlen (wname
); i
++)
963 wname
[i
] = toupper (wname
[i
]);
964 win_info
= tui_partial_win_by_name (wname
);
966 if (win_info
== (struct tui_win_info
*) NULL
|| !win_info
->generic
.is_visible
)
967 warning (_("Invalid window specified. \n\
968 The window name specified must be valid and visible.\n"));
971 /* Process the size */
972 while (*(++buf_ptr
) == ' ')
975 if (*buf_ptr
!= (char) 0)
978 int fixed_size
= TRUE
;
981 if (*buf_ptr
== '+' || *buf_ptr
== '-')
988 input_no
= atoi (buf_ptr
);
994 new_height
= input_no
;
996 new_height
= win_info
->generic
.height
+ input_no
;
998 ** Now change the window's height, and adjust all
999 ** other windows around it
1001 if (tui_adjust_win_heights (win_info
,
1002 new_height
) == TUI_FAILURE
)
1003 warning (_("Invalid window height specified.\n%s"),
1006 tui_update_gdb_sizes ();
1009 warning (_("Invalid window height specified.\n%s"),
1015 printf_filtered (WIN_HEIGHT_USAGE
);
1017 if (buf
!= (char *) NULL
)
1021 printf_filtered (WIN_HEIGHT_USAGE
);
1024 /* Set the height of the specified window, with va_list. */
1026 tui_set_win_height_command (char *arg
, int from_tty
)
1028 /* Make sure the curses mode is enabled. */
1030 tui_set_win_height (arg
, from_tty
);
1034 /* XDB Compatibility command for setting the window height. This will
1035 increase or decrease the command window by the specified amount. */
1037 tui_xdb_set_win_height (char *arg
, int from_tty
)
1039 /* Make sure the curses mode is enabled. */
1041 if (arg
!= (char *) NULL
)
1043 int input_no
= atoi (arg
);
1046 { /* Add 1 for the locator */
1047 int new_height
= tui_term_height () - (input_no
+ 1);
1049 if (!new_height_ok (tui_win_list
[CMD_WIN
], new_height
) ||
1050 tui_adjust_win_heights (tui_win_list
[CMD_WIN
],
1051 new_height
) == TUI_FAILURE
)
1052 warning (_("Invalid window height specified.\n%s"),
1053 XDBWIN_HEIGHT_USAGE
);
1056 warning (_("Invalid window height specified.\n%s"),
1057 XDBWIN_HEIGHT_USAGE
);
1060 warning (_("Invalid window height specified.\n%s"), XDBWIN_HEIGHT_USAGE
);
1063 /* Set the height of the specified window, with va_list. */
1065 tui_xdb_set_win_height_command (char *arg
, int from_tty
)
1067 tui_xdb_set_win_height (arg
, from_tty
);
1071 /* Function to adjust all window heights around the primary. */
1072 static enum tui_status
1073 tui_adjust_win_heights (struct tui_win_info
* primary_win_info
, int new_height
)
1075 enum tui_status status
= TUI_FAILURE
;
1077 if (new_height_ok (primary_win_info
, new_height
))
1079 status
= TUI_SUCCESS
;
1080 if (new_height
!= primary_win_info
->generic
.height
)
1083 struct tui_win_info
* win_info
;
1084 struct tui_gen_win_info
* locator
= tui_locator_win_info_ptr ();
1085 enum tui_layout_type cur_layout
= tui_current_layout ();
1087 diff
= (new_height
- primary_win_info
->generic
.height
) * (-1);
1088 if (cur_layout
== SRC_COMMAND
|| cur_layout
== DISASSEM_COMMAND
)
1090 struct tui_win_info
* src_win_info
;
1092 make_invisible_and_set_new_height (primary_win_info
, new_height
);
1093 if (primary_win_info
->generic
.type
== CMD_WIN
)
1095 win_info
= (struct tui_win_info
*) (tui_source_windows ())->list
[0];
1096 src_win_info
= win_info
;
1100 win_info
= tui_win_list
[CMD_WIN
];
1101 src_win_info
= primary_win_info
;
1103 make_invisible_and_set_new_height (win_info
,
1104 win_info
->generic
.height
+ diff
);
1105 TUI_CMD_WIN
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1106 make_visible_with_new_height (win_info
);
1107 make_visible_with_new_height (primary_win_info
);
1108 if (src_win_info
->generic
.content_size
<= 0)
1109 tui_erase_source_content (src_win_info
, EMPTY_SOURCE_PROMPT
);
1113 struct tui_win_info
*first_win
;
1114 struct tui_win_info
*second_win
;
1116 if (cur_layout
== SRC_DISASSEM_COMMAND
)
1118 first_win
= TUI_SRC_WIN
;
1119 second_win
= TUI_DISASM_WIN
;
1123 first_win
= TUI_DATA_WIN
;
1124 second_win
= (struct tui_win_info
*) (tui_source_windows ())->list
[0];
1126 if (primary_win_info
== TUI_CMD_WIN
)
1128 ** Split the change in height accross the 1st & 2nd windows
1129 ** adjusting them as well.
1131 int first_split_diff
= diff
/ 2; /* subtract the locator */
1132 int second_split_diff
= first_split_diff
;
1136 if (first_win
->generic
.height
>
1137 second_win
->generic
.height
)
1145 second_split_diff
--;
1147 second_split_diff
++;
1150 /* make sure that the minimum hieghts are honored */
1151 while ((first_win
->generic
.height
+ first_split_diff
) < 3)
1154 second_split_diff
--;
1156 while ((second_win
->generic
.height
+ second_split_diff
) < 3)
1158 second_split_diff
++;
1161 make_invisible_and_set_new_height (
1163 first_win
->generic
.height
+ first_split_diff
);
1164 second_win
->generic
.origin
.y
= first_win
->generic
.height
- 1;
1165 make_invisible_and_set_new_height (
1166 second_win
, second_win
->generic
.height
+ second_split_diff
);
1167 TUI_CMD_WIN
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1168 make_invisible_and_set_new_height (TUI_CMD_WIN
, new_height
);
1172 if ((TUI_CMD_WIN
->generic
.height
+ diff
) < 1)
1174 ** If there is no way to increase the command window
1175 ** take real estate from the 1st or 2nd window.
1177 if ((TUI_CMD_WIN
->generic
.height
+ diff
) < 1)
1180 for (i
= TUI_CMD_WIN
->generic
.height
+ diff
;
1182 if (primary_win_info
== first_win
)
1183 second_win
->generic
.height
--;
1185 first_win
->generic
.height
--;
1188 if (primary_win_info
== first_win
)
1189 make_invisible_and_set_new_height (first_win
, new_height
);
1191 make_invisible_and_set_new_height (
1193 first_win
->generic
.height
);
1194 second_win
->generic
.origin
.y
= first_win
->generic
.height
- 1;
1195 if (primary_win_info
== second_win
)
1196 make_invisible_and_set_new_height (second_win
, new_height
);
1198 make_invisible_and_set_new_height (
1199 second_win
, second_win
->generic
.height
);
1200 TUI_CMD_WIN
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1201 if ((TUI_CMD_WIN
->generic
.height
+ diff
) < 1)
1202 make_invisible_and_set_new_height (TUI_CMD_WIN
, 1);
1204 make_invisible_and_set_new_height (
1205 TUI_CMD_WIN
, TUI_CMD_WIN
->generic
.height
+ diff
);
1207 make_visible_with_new_height (TUI_CMD_WIN
);
1208 make_visible_with_new_height (second_win
);
1209 make_visible_with_new_height (first_win
);
1210 if (first_win
->generic
.content_size
<= 0)
1211 tui_erase_source_content (first_win
, EMPTY_SOURCE_PROMPT
);
1212 if (second_win
->generic
.content_size
<= 0)
1213 tui_erase_source_content (second_win
, EMPTY_SOURCE_PROMPT
);
1222 /* Function make the target window (and auxillary windows associated
1223 with the targer) invisible, and set the new height and location. */
1225 make_invisible_and_set_new_height (struct tui_win_info
* win_info
, int height
)
1228 struct tui_gen_win_info
* gen_win_info
;
1230 tui_make_invisible (&win_info
->generic
);
1231 win_info
->generic
.height
= height
;
1233 win_info
->generic
.viewport_height
= height
- 1;
1235 win_info
->generic
.viewport_height
= height
;
1236 if (win_info
!= TUI_CMD_WIN
)
1237 win_info
->generic
.viewport_height
--;
1239 /* Now deal with the auxillary windows associated with win_info */
1240 switch (win_info
->generic
.type
)
1244 gen_win_info
= win_info
->detail
.source_info
.execution_info
;
1245 tui_make_invisible (gen_win_info
);
1246 gen_win_info
->height
= height
;
1247 gen_win_info
->origin
.y
= win_info
->generic
.origin
.y
;
1249 gen_win_info
->viewport_height
= height
- 1;
1251 gen_win_info
->viewport_height
= height
;
1252 if (win_info
!= TUI_CMD_WIN
)
1253 gen_win_info
->viewport_height
--;
1255 if (tui_win_has_locator (win_info
))
1257 gen_win_info
= tui_locator_win_info_ptr ();
1258 tui_make_invisible (gen_win_info
);
1259 gen_win_info
->origin
.y
= win_info
->generic
.origin
.y
+ height
;
1263 /* delete all data item windows */
1264 for (i
= 0; i
< win_info
->generic
.content_size
; i
++)
1266 gen_win_info
= (struct tui_gen_win_info
*) & ((struct tui_win_element
*)
1267 win_info
->generic
.content
[i
])->which_element
.data_window
;
1268 tui_delete_win (gen_win_info
->handle
);
1269 gen_win_info
->handle
= (WINDOW
*) NULL
;
1278 /* Function to make the windows with new heights visible. This means
1279 re-creating the windows' content since the window had to be
1280 destroyed to be made invisible. */
1282 make_visible_with_new_height (struct tui_win_info
* win_info
)
1286 tui_make_visible (&win_info
->generic
);
1287 tui_check_and_display_highlight_if_needed (win_info
);
1288 switch (win_info
->generic
.type
)
1292 tui_free_win_content (win_info
->detail
.source_info
.execution_info
);
1293 tui_make_visible (win_info
->detail
.source_info
.execution_info
);
1294 if (win_info
->generic
.content
!= NULL
)
1296 union tui_line_or_address line_or_addr
;
1297 struct symtab_and_line cursal
1298 = get_current_source_symtab_and_line ();
1300 if (win_info
->generic
.type
== SRC_WIN
)
1301 line_or_addr
.line_no
=
1302 win_info
->detail
.source_info
.start_line_or_addr
.line_no
;
1305 win_info
->detail
.source_info
.start_line_or_addr
.addr
;
1306 tui_free_win_content (&win_info
->generic
);
1307 tui_update_source_window (win_info
, cursal
.symtab
, line_or_addr
, TRUE
);
1309 else if (deprecated_selected_frame
!= (struct frame_info
*) NULL
)
1311 union tui_line_or_address line
;
1312 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
1315 s
= find_pc_symtab (get_frame_pc (deprecated_selected_frame
));
1316 if (win_info
->generic
.type
== SRC_WIN
)
1317 line
.line_no
= cursal
.line
;
1320 find_line_pc (s
, cursal
.line
, &line
.addr
);
1322 tui_update_source_window (win_info
, s
, line
, TRUE
);
1324 if (tui_win_has_locator (win_info
))
1326 tui_make_visible (tui_locator_win_info_ptr ());
1327 tui_show_locator_content ();
1331 tui_display_all_data ();
1334 win_info
->detail
.command_info
.cur_line
= 0;
1335 win_info
->detail
.command_info
.curch
= 0;
1336 wmove (win_info
->generic
.handle
,
1337 win_info
->detail
.command_info
.cur_line
,
1338 win_info
->detail
.command_info
.curch
);
1347 new_height_ok (struct tui_win_info
* primary_win_info
, int new_height
)
1349 int ok
= (new_height
< tui_term_height ());
1354 enum tui_layout_type cur_layout
= tui_current_layout ();
1356 diff
= (new_height
- primary_win_info
->generic
.height
) * (-1);
1357 if (cur_layout
== SRC_COMMAND
|| cur_layout
== DISASSEM_COMMAND
)
1359 ok
= ((primary_win_info
->generic
.type
== CMD_WIN
&&
1360 new_height
<= (tui_term_height () - 4) &&
1361 new_height
>= MIN_CMD_WIN_HEIGHT
) ||
1362 (primary_win_info
->generic
.type
!= CMD_WIN
&&
1363 new_height
<= (tui_term_height () - 2) &&
1364 new_height
>= MIN_WIN_HEIGHT
));
1366 { /* check the total height */
1367 struct tui_win_info
* win_info
;
1369 if (primary_win_info
== TUI_CMD_WIN
)
1370 win_info
= (struct tui_win_info
*) (tui_source_windows ())->list
[0];
1372 win_info
= TUI_CMD_WIN
;
1374 (win_info
->generic
.height
+ diff
)) <= tui_term_height ());
1379 int cur_total_height
, total_height
, min_height
= 0;
1380 struct tui_win_info
*first_win
;
1381 struct tui_win_info
*second_win
;
1383 if (cur_layout
== SRC_DISASSEM_COMMAND
)
1385 first_win
= TUI_SRC_WIN
;
1386 second_win
= TUI_DISASM_WIN
;
1390 first_win
= TUI_DATA_WIN
;
1391 second_win
= (struct tui_win_info
*) (tui_source_windows ())->list
[0];
1394 ** We could simply add all the heights to obtain the same result
1395 ** but below is more explicit since we subtract 1 for the
1396 ** line that the first and second windows share, and add one
1399 total_height
= cur_total_height
=
1400 (first_win
->generic
.height
+ second_win
->generic
.height
- 1)
1401 + TUI_CMD_WIN
->generic
.height
+ 1 /*locator */ ;
1402 if (primary_win_info
== TUI_CMD_WIN
)
1404 /* locator included since first & second win share a line */
1405 ok
= ((first_win
->generic
.height
+
1406 second_win
->generic
.height
+ diff
) >=
1407 (MIN_WIN_HEIGHT
* 2) &&
1408 new_height
>= MIN_CMD_WIN_HEIGHT
);
1411 total_height
= new_height
+ (first_win
->generic
.height
+
1412 second_win
->generic
.height
+ diff
);
1413 min_height
= MIN_CMD_WIN_HEIGHT
;
1418 min_height
= MIN_WIN_HEIGHT
;
1420 ** First see if we can increase/decrease the command
1421 ** window. And make sure that the command window is
1424 ok
= ((TUI_CMD_WIN
->generic
.height
+ diff
) > 0);
1427 ** Looks like we have to increase/decrease one of
1428 ** the other windows
1430 if (primary_win_info
== first_win
)
1431 ok
= (second_win
->generic
.height
+ diff
) >= min_height
;
1433 ok
= (first_win
->generic
.height
+ diff
) >= min_height
;
1437 if (primary_win_info
== first_win
)
1438 total_height
= new_height
+
1439 second_win
->generic
.height
+
1440 TUI_CMD_WIN
->generic
.height
+ diff
;
1442 total_height
= new_height
+
1443 first_win
->generic
.height
+
1444 TUI_CMD_WIN
->generic
.height
+ diff
;
1448 ** Now make sure that the proposed total height doesn't exceed
1449 ** the old total height.
1452 ok
= (new_height
>= min_height
&& total_height
<= cur_total_height
);
1461 parse_scrolling_args (char *arg
, struct tui_win_info
* * win_to_scroll
,
1466 *win_to_scroll
= tui_win_with_focus ();
1469 ** First set up the default window to scroll, in case there is no
1472 if (arg
!= (char *) NULL
)
1474 char *buf
, *buf_ptr
;
1476 /* process the number of lines to scroll */
1477 buf
= buf_ptr
= xstrdup (arg
);
1478 if (isdigit (*buf_ptr
))
1483 buf_ptr
= strchr (buf_ptr
, ' ');
1484 if (buf_ptr
!= (char *) NULL
)
1486 *buf_ptr
= (char) 0;
1488 *num_to_scroll
= atoi (num_str
);
1491 else if (num_to_scroll
)
1492 *num_to_scroll
= atoi (num_str
);
1495 /* process the window name if one is specified */
1496 if (buf_ptr
!= (char *) NULL
)
1501 if (*buf_ptr
== ' ')
1502 while (*(++buf_ptr
) == ' ')
1505 if (*buf_ptr
!= (char) 0)
1510 /* Validate the window name */
1511 for (i
= 0; i
< strlen (wname
); i
++)
1512 wname
[i
] = toupper (wname
[i
]);
1513 *win_to_scroll
= tui_partial_win_by_name (wname
);
1515 if (*win_to_scroll
== (struct tui_win_info
*) NULL
||
1516 !(*win_to_scroll
)->generic
.is_visible
)
1517 warning (_("Invalid window specified. \n\
1518 The window name specified must be valid and visible.\n"));
1519 else if (*win_to_scroll
== TUI_CMD_WIN
)
1520 *win_to_scroll
= (struct tui_win_info
*) (tui_source_windows ())->list
[0];