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"
57 #include "gdb_string.h"
59 #include <readline/readline.h>
61 /*******************************
63 ********************************/
64 static void make_visible_with_new_height (struct tui_win_info
*);
65 static void make_invisible_and_set_new_height (struct tui_win_info
*, int);
66 static enum tui_status
tui_adjust_win_heights (struct tui_win_info
*, int);
67 static int new_height_ok (struct tui_win_info
*, int);
68 static void tui_set_tab_width_command (char *, int);
69 static void tui_refresh_all_command (char *, int);
70 static void tui_set_win_height_command (char *, int);
71 static void tui_xdb_set_win_height_command (char *, int);
72 static void tui_all_windows_info (char *, int);
73 static void tui_set_focus_command (char *, int);
74 static void tui_scroll_forward_command (char *, int);
75 static void tui_scroll_backward_command (char *, int);
76 static void tui_scroll_left_command (char *, int);
77 static void tui_scroll_right_command (char *, int);
78 static void parse_scrolling_args (char *, struct tui_win_info
* *, int *);
81 /***************************************
83 ***************************************/
84 #define WIN_HEIGHT_USAGE "Usage: winheight <win_name> [+ | -] <#lines>\n"
85 #define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n"
86 #define FOCUS_USAGE "Usage: focus {<win> | next | prev}\n"
88 /***************************************
90 ***************************************/
93 # define ACS_LRCORNER '+'
96 # define ACS_LLCORNER '+'
99 # define ACS_ULCORNER '+'
102 # define ACS_URCORNER '+'
105 # define ACS_HLINE '-'
108 # define ACS_VLINE '|'
111 /* Possible values for tui-border-kind variable. */
112 static const char *tui_border_kind_enums
[] = {
119 /* Possible values for tui-border-mode and tui-active-border-mode. */
120 static const char *tui_border_mode_enums
[] = {
137 /* Translation table for border-mode variables.
138 The list of values must be terminated by a NULL.
139 After the NULL value, an entry defines the default. */
140 struct tui_translate tui_border_mode_translate
[] = {
141 { "normal", A_NORMAL
},
142 { "standout", A_STANDOUT
},
143 { "reverse", A_REVERSE
},
145 { "half-standout", A_DIM
| A_STANDOUT
},
147 { "bold-standout", A_BOLD
| A_STANDOUT
},
149 { "normal", A_NORMAL
}
152 /* Translation tables for border-kind, one for each border
153 character (see wborder, border curses operations).
154 -1 is used to indicate the ACS because ACS characters
155 are determined at run time by curses (depends on terminal). */
156 struct tui_translate tui_border_kind_translate_vline
[] = {
164 struct tui_translate tui_border_kind_translate_hline
[] = {
172 struct tui_translate tui_border_kind_translate_ulcorner
[] = {
180 struct tui_translate tui_border_kind_translate_urcorner
[] = {
188 struct tui_translate tui_border_kind_translate_llcorner
[] = {
196 struct tui_translate tui_border_kind_translate_lrcorner
[] = {
205 /* Tui configuration variables controlled with set/show command. */
206 const char *tui_active_border_mode
= "bold-standout";
207 const char *tui_border_mode
= "normal";
208 const char *tui_border_kind
= "acs";
210 /* Tui internal configuration variables. These variables are
211 updated by tui_update_variables to reflect the tui configuration
213 chtype tui_border_vline
;
214 chtype tui_border_hline
;
215 chtype tui_border_ulcorner
;
216 chtype tui_border_urcorner
;
217 chtype tui_border_llcorner
;
218 chtype tui_border_lrcorner
;
220 int tui_border_attrs
;
221 int tui_active_border_attrs
;
223 /* Identify the item in the translation table.
224 When the item is not recognized, use the default entry. */
225 static struct tui_translate
*
226 translate (const char *name
, struct tui_translate
*table
)
230 if (name
&& strcmp (table
->name
, name
) == 0)
235 /* Not found, return default entry. */
240 /* Update the tui internal configuration according to gdb settings.
241 Returns 1 if the configuration has changed and the screen should
244 tui_update_variables (void)
247 struct tui_translate
*entry
;
249 entry
= translate (tui_border_mode
, tui_border_mode_translate
);
250 if (tui_border_attrs
!= entry
->value
)
252 tui_border_attrs
= entry
->value
;
255 entry
= translate (tui_active_border_mode
, tui_border_mode_translate
);
256 if (tui_active_border_attrs
!= entry
->value
)
258 tui_active_border_attrs
= entry
->value
;
262 /* If one corner changes, all characters are changed.
263 Only check the first one. The ACS characters are determined at
264 run time by curses terminal management. */
265 entry
= translate (tui_border_kind
, tui_border_kind_translate_lrcorner
);
266 if (tui_border_lrcorner
!= (chtype
) entry
->value
)
268 tui_border_lrcorner
= (entry
->value
< 0) ? ACS_LRCORNER
: entry
->value
;
271 entry
= translate (tui_border_kind
, tui_border_kind_translate_llcorner
);
272 tui_border_llcorner
= (entry
->value
< 0) ? ACS_LLCORNER
: entry
->value
;
274 entry
= translate (tui_border_kind
, tui_border_kind_translate_ulcorner
);
275 tui_border_ulcorner
= (entry
->value
< 0) ? ACS_ULCORNER
: entry
->value
;
277 entry
= translate (tui_border_kind
, tui_border_kind_translate_urcorner
);
278 tui_border_urcorner
= (entry
->value
< 0) ? ACS_URCORNER
: entry
->value
;
280 entry
= translate (tui_border_kind
, tui_border_kind_translate_hline
);
281 tui_border_hline
= (entry
->value
< 0) ? ACS_HLINE
: entry
->value
;
283 entry
= translate (tui_border_kind
, tui_border_kind_translate_vline
);
284 tui_border_vline
= (entry
->value
< 0) ? ACS_VLINE
: entry
->value
;
290 set_tui_cmd (char *args
, int from_tty
)
295 show_tui_cmd (char *args
, int from_tty
)
299 /* Function to initialize gdb commands, for tui window manipulation. */
301 _initialize_tui_win (void)
303 struct cmd_list_element
*c
;
304 static struct cmd_list_element
*tui_setlist
;
305 static struct cmd_list_element
*tui_showlist
;
307 /* Define the classes of commands.
308 They will appear in the help list in the reverse of this order. */
309 add_cmd ("tui", class_tui
, NULL
,
310 "Text User Interface commands.",
313 add_prefix_cmd ("tui", class_tui
, set_tui_cmd
,
314 "TUI configuration variables",
315 &tui_setlist
, "set tui ",
316 0/*allow-unknown*/, &setlist
);
317 add_prefix_cmd ("tui", class_tui
, show_tui_cmd
,
318 "TUI configuration variables",
319 &tui_showlist
, "show tui ",
320 0/*allow-unknown*/, &showlist
);
322 add_com ("refresh", class_tui
, tui_refresh_all_command
,
323 "Refresh the terminal display.\n");
325 add_com_alias ("U", "refresh", class_tui
, 0);
326 add_com ("tabset", class_tui
, tui_set_tab_width_command
,
327 "Set the width (in characters) of tab stops.\n\
328 Usage: tabset <n>\n");
329 add_com ("winheight", class_tui
, tui_set_win_height_command
,
330 "Set the height of a specified window.\n\
331 Usage: winheight <win_name> [+ | -] <#lines>\n\
333 src : the source window\n\
334 cmd : the command window\n\
335 asm : the disassembly window\n\
336 regs : the register display\n");
337 add_com_alias ("wh", "winheight", class_tui
, 0);
338 add_info ("win", tui_all_windows_info
,
339 "List of all displayed windows.\n");
340 add_com ("focus", class_tui
, tui_set_focus_command
,
341 "Set focus to named window or next/prev window.\n\
342 Usage: focus {<win> | next | prev}\n\
343 Valid Window names are:\n\
344 src : the source window\n\
345 asm : the disassembly window\n\
346 regs : the register display\n\
347 cmd : the command window\n");
348 add_com_alias ("fs", "focus", class_tui
, 0);
349 add_com ("+", class_tui
, tui_scroll_forward_command
,
350 "Scroll window forward.\nUsage: + [win] [n]\n");
351 add_com ("-", class_tui
, tui_scroll_backward_command
,
352 "Scroll window backward.\nUsage: - [win] [n]\n");
353 add_com ("<", class_tui
, tui_scroll_left_command
,
354 "Scroll window forward.\nUsage: < [win] [n]\n");
355 add_com (">", class_tui
, tui_scroll_right_command
,
356 "Scroll window backward.\nUsage: > [win] [n]\n");
358 add_com ("w", class_xdb
, tui_xdb_set_win_height_command
,
359 "XDB compatibility command for setting the height of a command window.\n\
360 Usage: w <#lines>\n");
362 /* Define the tui control variables. */
364 ("border-kind", no_class
,
365 tui_border_kind_enums
, &tui_border_kind
,
366 "Set the kind of border for TUI windows.\n"
367 "This variable controls the border of TUI windows:\n"
368 "space use a white space\n"
369 "ascii use ascii characters + - | for the border\n"
370 "acs use the Alternate Character Set\n",
372 add_show_from_set (c
, &tui_showlist
);
375 ("border-mode", no_class
,
376 tui_border_mode_enums
, &tui_border_mode
,
377 "Set the attribute mode to use for the TUI window borders.\n"
378 "This variable controls the attributes to use for the window borders:\n"
379 "normal normal display\n"
380 "standout use highlight mode of terminal\n"
381 "reverse use reverse video mode\n"
382 "half use half bright\n"
383 "half-standout use half bright and standout mode\n"
384 "bold use extra bright or bold\n"
385 "bold-standout use extra bright or bold with standout mode\n",
387 add_show_from_set (c
, &tui_showlist
);
390 ("active-border-mode", no_class
,
391 tui_border_mode_enums
, &tui_active_border_mode
,
392 "Set the attribute mode to use for the active TUI window border.\n"
393 "This variable controls the attributes to use for the active window border:\n"
394 "normal normal display\n"
395 "standout use highlight mode of terminal\n"
396 "reverse use reverse video mode\n"
397 "half use half bright\n"
398 "half-standout use half bright and standout mode\n"
399 "bold use extra bright or bold\n"
400 "bold-standout use extra bright or bold with standout mode\n",
402 add_show_from_set (c
, &tui_showlist
);
405 /* Update gdb's knowledge of the terminal size. */
407 tui_update_gdb_sizes (void)
410 int screenheight
, screenwidth
;
412 rl_get_screen_size (&screenheight
, &screenwidth
);
413 /* Set to TUI command window dimension or use readline values. */
414 sprintf (cmd
, "set width %d",
415 tui_active
? TUI_CMD_WIN
->generic
.width
: screenwidth
);
416 execute_command (cmd
, 0);
417 sprintf (cmd
, "set height %d",
418 tui_active
? TUI_CMD_WIN
->generic
.height
: screenheight
);
419 execute_command (cmd
, 0);
423 /* Set the logical focus to win_info. */
425 tui_set_win_focus_to (struct tui_win_info
* win_info
)
427 if (win_info
!= NULL
)
429 struct tui_win_info
* win_with_focus
= tui_win_with_focus ();
431 if (win_with_focus
!= NULL
432 && win_with_focus
->generic
.type
!= CMD_WIN
)
433 tui_unhighlight_win (win_with_focus
);
434 tui_set_win_with_focus (win_info
);
435 if (win_info
->generic
.type
!= CMD_WIN
)
436 tui_highlight_win (win_info
);
442 tui_scroll_forward (struct tui_win_info
* win_to_scroll
, int num_to_scroll
)
444 if (win_to_scroll
!= TUI_CMD_WIN
)
446 int _num_to_scroll
= num_to_scroll
;
448 if (num_to_scroll
== 0)
449 _num_to_scroll
= win_to_scroll
->generic
.height
- 3;
451 ** If we are scrolling the source or disassembly window, do a
452 ** "psuedo" scroll since not all of the source is in memory,
453 ** only what is in the viewport. If win_to_scroll is the
454 ** command window do nothing since the term should handle it.
456 if (win_to_scroll
== TUI_SRC_WIN
)
457 tui_vertical_source_scroll (FORWARD_SCROLL
, _num_to_scroll
);
458 else if (win_to_scroll
== TUI_DISASM_WIN
)
459 tui_vertical_disassem_scroll (FORWARD_SCROLL
, _num_to_scroll
);
460 else if (win_to_scroll
== TUI_DATA_WIN
)
461 tui_vertical_data_scroll (FORWARD_SCROLL
, _num_to_scroll
);
466 tui_scroll_backward (struct tui_win_info
* win_to_scroll
, int num_to_scroll
)
468 if (win_to_scroll
!= TUI_CMD_WIN
)
470 int _num_to_scroll
= num_to_scroll
;
472 if (num_to_scroll
== 0)
473 _num_to_scroll
= win_to_scroll
->generic
.height
- 3;
475 ** If we are scrolling the source or disassembly window, do a
476 ** "psuedo" scroll since not all of the source is in memory,
477 ** only what is in the viewport. If win_to_scroll is the
478 ** command window do nothing since the term should handle it.
480 if (win_to_scroll
== TUI_SRC_WIN
)
481 tui_vertical_source_scroll (BACKWARD_SCROLL
, _num_to_scroll
);
482 else if (win_to_scroll
== TUI_DISASM_WIN
)
483 tui_vertical_disassem_scroll (BACKWARD_SCROLL
, _num_to_scroll
);
484 else if (win_to_scroll
== TUI_DATA_WIN
)
485 tui_vertical_data_scroll (BACKWARD_SCROLL
, _num_to_scroll
);
491 tui_scroll_left (struct tui_win_info
* win_to_scroll
, int num_to_scroll
)
493 if (win_to_scroll
!= TUI_CMD_WIN
)
495 int _num_to_scroll
= num_to_scroll
;
497 if (_num_to_scroll
== 0)
500 ** If we are scrolling the source or disassembly window, do a
501 ** "psuedo" scroll since not all of the source is in memory,
502 ** only what is in the viewport. If win_to_scroll is the
503 ** command window do nothing since the term should handle it.
505 if (win_to_scroll
== TUI_SRC_WIN
|| win_to_scroll
== TUI_DISASM_WIN
)
506 tui_horizontal_source_scroll (win_to_scroll
, LEFT_SCROLL
, _num_to_scroll
);
512 tui_scroll_right (struct tui_win_info
* win_to_scroll
, int num_to_scroll
)
514 if (win_to_scroll
!= TUI_CMD_WIN
)
516 int _num_to_scroll
= num_to_scroll
;
518 if (_num_to_scroll
== 0)
521 ** If we are scrolling the source or disassembly window, do a
522 ** "psuedo" scroll since not all of the source is in memory,
523 ** only what is in the viewport. If win_to_scroll is the
524 ** command window do nothing since the term should handle it.
526 if (win_to_scroll
== TUI_SRC_WIN
|| win_to_scroll
== TUI_DISASM_WIN
)
527 tui_horizontal_source_scroll (win_to_scroll
, RIGHT_SCROLL
, _num_to_scroll
);
532 /* Scroll a window. Arguments are passed through a va_list. */
534 tui_scroll (enum tui_scroll_direction direction
,
535 struct tui_win_info
* win_to_scroll
,
541 tui_scroll_forward (win_to_scroll
, num_to_scroll
);
543 case BACKWARD_SCROLL
:
544 tui_scroll_backward (win_to_scroll
, num_to_scroll
);
547 tui_scroll_left (win_to_scroll
, num_to_scroll
);
550 tui_scroll_right (win_to_scroll
, num_to_scroll
);
559 tui_refresh_all_win (void)
561 enum tui_win_type type
;
563 clearok (curscr
, TRUE
);
564 tui_refresh_all (tui_win_list
);
565 for (type
= SRC_WIN
; type
< MAX_MAJOR_WINDOWS
; type
++)
567 if (tui_win_list
[type
] && tui_win_list
[type
]->generic
.is_visible
)
573 tui_show_source_content (tui_win_list
[type
]);
574 tui_check_and_display_highlight_if_needed (tui_win_list
[type
]);
575 tui_erase_exec_info_content (tui_win_list
[type
]);
576 tui_update_exec_info (tui_win_list
[type
]);
579 tui_refresh_data_win ();
586 tui_show_locator_content ();
590 /* Resize all the windows based on the the terminal size. This
591 function gets called from within the readline sinwinch handler. */
593 tui_resize_all (void)
595 int height_diff
, width_diff
;
596 int screenheight
, screenwidth
;
598 rl_get_screen_size (&screenheight
, &screenwidth
);
599 width_diff
= screenwidth
- tui_term_width ();
600 height_diff
= screenheight
- tui_term_height ();
601 if (height_diff
|| width_diff
)
603 enum tui_layout_type cur_layout
= tui_current_layout ();
604 struct tui_win_info
* win_with_focus
= tui_win_with_focus ();
605 struct tui_win_info
*first_win
;
606 struct tui_win_info
*second_win
;
607 struct tui_gen_win_info
* locator
= tui_locator_win_info_ptr ();
608 enum tui_win_type win_type
;
609 int new_height
, split_diff
, cmd_split_diff
, num_wins_displayed
= 2;
611 /* turn keypad off while we resize */
612 if (win_with_focus
!= TUI_CMD_WIN
)
613 keypad (TUI_CMD_WIN
->generic
.handle
, FALSE
);
614 tui_update_gdb_sizes ();
615 tui_set_term_height_to (screenheight
);
616 tui_set_term_width_to (screenwidth
);
617 if (cur_layout
== SRC_DISASSEM_COMMAND
||
618 cur_layout
== SRC_DATA_COMMAND
|| cur_layout
== DISASSEM_DATA_COMMAND
)
619 num_wins_displayed
++;
620 split_diff
= height_diff
/ num_wins_displayed
;
621 cmd_split_diff
= split_diff
;
622 if (height_diff
% num_wins_displayed
)
629 /* now adjust each window */
635 case DISASSEM_COMMAND
:
636 first_win
= (struct tui_win_info
*) (tui_source_windows ())->list
[0];
637 first_win
->generic
.width
+= width_diff
;
638 locator
->width
+= width_diff
;
639 /* check for invalid heights */
640 if (height_diff
== 0)
641 new_height
= first_win
->generic
.height
;
642 else if ((first_win
->generic
.height
+ split_diff
) >=
643 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
644 new_height
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
645 else if ((first_win
->generic
.height
+ split_diff
) <= 0)
646 new_height
= MIN_WIN_HEIGHT
;
648 new_height
= first_win
->generic
.height
+ split_diff
;
650 make_invisible_and_set_new_height (first_win
, new_height
);
651 TUI_CMD_WIN
->generic
.origin
.y
= locator
->origin
.y
+ 1;
652 TUI_CMD_WIN
->generic
.width
+= width_diff
;
653 new_height
= screenheight
- TUI_CMD_WIN
->generic
.origin
.y
;
654 make_invisible_and_set_new_height (TUI_CMD_WIN
, new_height
);
655 make_visible_with_new_height (first_win
);
656 make_visible_with_new_height (TUI_CMD_WIN
);
657 if (first_win
->generic
.content_size
<= 0)
658 tui_erase_source_content (first_win
, EMPTY_SOURCE_PROMPT
);
661 if (cur_layout
== SRC_DISASSEM_COMMAND
)
663 first_win
= TUI_SRC_WIN
;
664 first_win
->generic
.width
+= width_diff
;
665 second_win
= TUI_DISASM_WIN
;
666 second_win
->generic
.width
+= width_diff
;
670 first_win
= TUI_DATA_WIN
;
671 first_win
->generic
.width
+= width_diff
;
672 second_win
= (struct tui_win_info
*) (tui_source_windows ())->list
[0];
673 second_win
->generic
.width
+= width_diff
;
675 /* Change the first window's height/width */
676 /* check for invalid heights */
677 if (height_diff
== 0)
678 new_height
= first_win
->generic
.height
;
679 else if ((first_win
->generic
.height
+
680 second_win
->generic
.height
+ (split_diff
* 2)) >=
681 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
682 new_height
= (screenheight
- MIN_CMD_WIN_HEIGHT
- 1) / 2;
683 else if ((first_win
->generic
.height
+ split_diff
) <= 0)
684 new_height
= MIN_WIN_HEIGHT
;
686 new_height
= first_win
->generic
.height
+ split_diff
;
687 make_invisible_and_set_new_height (first_win
, new_height
);
689 if (first_win
== TUI_DATA_WIN
&& width_diff
!= 0)
690 first_win
->detail
.data_display_info
.regs_column_count
=
691 tui_calculate_regs_column_count (
692 first_win
->detail
.data_display_info
.regs_display_type
);
693 locator
->width
+= width_diff
;
695 /* Change the second window's height/width */
696 /* check for invalid heights */
697 if (height_diff
== 0)
698 new_height
= second_win
->generic
.height
;
699 else if ((first_win
->generic
.height
+
700 second_win
->generic
.height
+ (split_diff
* 2)) >=
701 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
703 new_height
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
705 new_height
= (new_height
/ 2) + 1;
709 else if ((second_win
->generic
.height
+ split_diff
) <= 0)
710 new_height
= MIN_WIN_HEIGHT
;
712 new_height
= second_win
->generic
.height
+ split_diff
;
713 second_win
->generic
.origin
.y
= first_win
->generic
.height
- 1;
714 make_invisible_and_set_new_height (second_win
, new_height
);
716 /* Change the command window's height/width */
717 TUI_CMD_WIN
->generic
.origin
.y
= locator
->origin
.y
+ 1;
718 make_invisible_and_set_new_height (
719 TUI_CMD_WIN
, TUI_CMD_WIN
->generic
.height
+ cmd_split_diff
);
720 make_visible_with_new_height (first_win
);
721 make_visible_with_new_height (second_win
);
722 make_visible_with_new_height (TUI_CMD_WIN
);
723 if (first_win
->generic
.content_size
<= 0)
724 tui_erase_source_content (first_win
, EMPTY_SOURCE_PROMPT
);
725 if (second_win
->generic
.content_size
<= 0)
726 tui_erase_source_content (second_win
, EMPTY_SOURCE_PROMPT
);
730 ** Now remove all invisible windows, and their content so that they get
731 ** created again when called for with the new size
733 for (win_type
= SRC_WIN
; (win_type
< MAX_MAJOR_WINDOWS
); win_type
++)
735 if (win_type
!= CMD_WIN
&& (tui_win_list
[win_type
] != NULL
)
736 && !tui_win_list
[win_type
]->generic
.is_visible
)
738 tui_free_window (tui_win_list
[win_type
]);
739 tui_win_list
[win_type
] = (struct tui_win_info
*) NULL
;
742 tui_set_win_resized_to (TRUE
);
743 /* turn keypad back on, unless focus is in the command window */
744 if (win_with_focus
!= TUI_CMD_WIN
)
745 keypad (TUI_CMD_WIN
->generic
.handle
, TRUE
);
750 /* SIGWINCH signal handler for the tui. This signal handler is always
751 called, even when the readline package clears signals because it is
752 set as the old_sigwinch() (TUI only). */
754 tui_sigwinch_handler (int signal
)
757 ** Say that a resize was done so that the readline can do it
758 ** later when appropriate.
760 tui_set_win_resized_to (TRUE
);
765 /*************************
766 ** STATIC LOCAL FUNCTIONS
767 **************************/
771 tui_scroll_forward_command (char *arg
, int from_tty
)
773 int num_to_scroll
= 1;
774 struct tui_win_info
* win_to_scroll
;
776 /* Make sure the curses mode is enabled. */
778 if (arg
== (char *) NULL
)
779 parse_scrolling_args (arg
, &win_to_scroll
, (int *) NULL
);
781 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
782 tui_scroll (FORWARD_SCROLL
, win_to_scroll
, num_to_scroll
);
787 tui_scroll_backward_command (char *arg
, int from_tty
)
789 int num_to_scroll
= 1;
790 struct tui_win_info
* win_to_scroll
;
792 /* Make sure the curses mode is enabled. */
794 if (arg
== (char *) NULL
)
795 parse_scrolling_args (arg
, &win_to_scroll
, (int *) NULL
);
797 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
798 tui_scroll (BACKWARD_SCROLL
, win_to_scroll
, num_to_scroll
);
803 tui_scroll_left_command (char *arg
, int from_tty
)
806 struct tui_win_info
* win_to_scroll
;
808 /* Make sure the curses mode is enabled. */
810 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
811 tui_scroll (LEFT_SCROLL
, win_to_scroll
, num_to_scroll
);
816 tui_scroll_right_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 (RIGHT_SCROLL
, win_to_scroll
, num_to_scroll
);
828 /* Set focus to the window named by 'arg'. */
830 tui_set_focus (char *arg
, int from_tty
)
832 if (arg
!= (char *) NULL
)
834 char *buf_ptr
= (char *) xstrdup (arg
);
836 struct tui_win_info
* win_info
= (struct tui_win_info
*) NULL
;
838 for (i
= 0; (i
< strlen (buf_ptr
)); i
++)
839 buf_ptr
[i
] = toupper (arg
[i
]);
841 if (subset_compare (buf_ptr
, "NEXT"))
842 win_info
= tui_next_win (tui_win_with_focus ());
843 else if (subset_compare (buf_ptr
, "PREV"))
844 win_info
= tui_prev_win (tui_win_with_focus ());
846 win_info
= tui_partial_win_by_name (buf_ptr
);
848 if (win_info
== (struct tui_win_info
*) NULL
|| !win_info
->generic
.is_visible
)
849 warning ("Invalid window specified. \n\
850 The window name specified must be valid and visible.\n");
853 tui_set_win_focus_to (win_info
);
854 keypad (TUI_CMD_WIN
->generic
.handle
, (win_info
!= TUI_CMD_WIN
));
857 if (TUI_DATA_WIN
&& TUI_DATA_WIN
->generic
.is_visible
)
858 tui_refresh_data_win ();
860 printf_filtered ("Focus set to %s window.\n",
861 tui_win_name ((struct tui_gen_win_info
*) tui_win_with_focus ()));
864 warning ("Incorrect Number of Arguments.\n%s", FOCUS_USAGE
);
868 tui_set_focus_command (char *arg
, int from_tty
)
870 /* Make sure the curses mode is enabled. */
872 tui_set_focus (arg
, from_tty
);
877 tui_all_windows_info (char *arg
, int from_tty
)
879 enum tui_win_type type
;
880 struct tui_win_info
* win_with_focus
= tui_win_with_focus ();
882 for (type
= SRC_WIN
; (type
< MAX_MAJOR_WINDOWS
); type
++)
883 if (tui_win_list
[type
] && tui_win_list
[type
]->generic
.is_visible
)
885 if (win_with_focus
== tui_win_list
[type
])
886 printf_filtered (" %s\t(%d lines) <has focus>\n",
887 tui_win_name (&tui_win_list
[type
]->generic
),
888 tui_win_list
[type
]->generic
.height
);
890 printf_filtered (" %s\t(%d lines)\n",
891 tui_win_name (&tui_win_list
[type
]->generic
),
892 tui_win_list
[type
]->generic
.height
);
898 tui_refresh_all_command (char *arg
, int from_tty
)
900 /* Make sure the curses mode is enabled. */
903 tui_refresh_all_win ();
907 /* Set the height of the specified window. */
909 tui_set_tab_width_command (char *arg
, int from_tty
)
911 /* Make sure the curses mode is enabled. */
913 if (arg
!= (char *) NULL
)
919 tui_set_default_tab_len (ts
);
921 warning ("Tab widths greater than 0 must be specified.\n");
926 /* Set the height of the specified window. */
928 tui_set_win_height (char *arg
, int from_tty
)
930 /* Make sure the curses mode is enabled. */
932 if (arg
!= (char *) NULL
)
934 char *buf
= xstrdup (arg
);
936 char *wname
= (char *) NULL
;
938 struct tui_win_info
* win_info
;
941 buf_ptr
= strchr (buf_ptr
, ' ');
942 if (buf_ptr
!= (char *) NULL
)
947 ** Validate the window name
949 for (i
= 0; i
< strlen (wname
); i
++)
950 wname
[i
] = toupper (wname
[i
]);
951 win_info
= tui_partial_win_by_name (wname
);
953 if (win_info
== (struct tui_win_info
*) NULL
|| !win_info
->generic
.is_visible
)
954 warning ("Invalid window specified. \n\
955 The window name specified must be valid and visible.\n");
958 /* Process the size */
959 while (*(++buf_ptr
) == ' ')
962 if (*buf_ptr
!= (char) 0)
965 int fixed_size
= TRUE
;
968 if (*buf_ptr
== '+' || *buf_ptr
== '-')
975 input_no
= atoi (buf_ptr
);
981 new_height
= input_no
;
983 new_height
= win_info
->generic
.height
+ input_no
;
985 ** Now change the window's height, and adjust all
986 ** other windows around it
988 if (tui_adjust_win_heights (win_info
,
989 new_height
) == TUI_FAILURE
)
990 warning ("Invalid window height specified.\n%s",
993 tui_update_gdb_sizes ();
996 warning ("Invalid window height specified.\n%s",
1002 printf_filtered (WIN_HEIGHT_USAGE
);
1004 if (buf
!= (char *) NULL
)
1008 printf_filtered (WIN_HEIGHT_USAGE
);
1011 /* Set the height of the specified window, with va_list. */
1013 tui_set_win_height_command (char *arg
, int from_tty
)
1015 /* Make sure the curses mode is enabled. */
1017 tui_set_win_height (arg
, from_tty
);
1021 /* XDB Compatibility command for setting the window height. This will
1022 increase or decrease the command window by the specified amount. */
1024 tui_xdb_set_win_height (char *arg
, int from_tty
)
1026 /* Make sure the curses mode is enabled. */
1028 if (arg
!= (char *) NULL
)
1030 int input_no
= atoi (arg
);
1033 { /* Add 1 for the locator */
1034 int new_height
= tui_term_height () - (input_no
+ 1);
1036 if (!new_height_ok (tui_win_list
[CMD_WIN
], new_height
) ||
1037 tui_adjust_win_heights (tui_win_list
[CMD_WIN
],
1038 new_height
) == TUI_FAILURE
)
1039 warning ("Invalid window height specified.\n%s",
1040 XDBWIN_HEIGHT_USAGE
);
1043 warning ("Invalid window height specified.\n%s",
1044 XDBWIN_HEIGHT_USAGE
);
1047 warning ("Invalid window height specified.\n%s", XDBWIN_HEIGHT_USAGE
);
1050 /* Set the height of the specified window, with va_list. */
1052 tui_xdb_set_win_height_command (char *arg
, int from_tty
)
1054 tui_xdb_set_win_height (arg
, from_tty
);
1058 /* Function to adjust all window heights around the primary. */
1059 static enum tui_status
1060 tui_adjust_win_heights (struct tui_win_info
* primary_win_info
, int new_height
)
1062 enum tui_status status
= TUI_FAILURE
;
1064 if (new_height_ok (primary_win_info
, new_height
))
1066 status
= TUI_SUCCESS
;
1067 if (new_height
!= primary_win_info
->generic
.height
)
1070 struct tui_win_info
* win_info
;
1071 struct tui_gen_win_info
* locator
= tui_locator_win_info_ptr ();
1072 enum tui_layout_type cur_layout
= tui_current_layout ();
1074 diff
= (new_height
- primary_win_info
->generic
.height
) * (-1);
1075 if (cur_layout
== SRC_COMMAND
|| cur_layout
== DISASSEM_COMMAND
)
1077 struct tui_win_info
* src_win_info
;
1079 make_invisible_and_set_new_height (primary_win_info
, new_height
);
1080 if (primary_win_info
->generic
.type
== CMD_WIN
)
1082 win_info
= (struct tui_win_info
*) (tui_source_windows ())->list
[0];
1083 src_win_info
= win_info
;
1087 win_info
= tui_win_list
[CMD_WIN
];
1088 src_win_info
= primary_win_info
;
1090 make_invisible_and_set_new_height (win_info
,
1091 win_info
->generic
.height
+ diff
);
1092 TUI_CMD_WIN
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1093 make_visible_with_new_height (win_info
);
1094 make_visible_with_new_height (primary_win_info
);
1095 if (src_win_info
->generic
.content_size
<= 0)
1096 tui_erase_source_content (src_win_info
, EMPTY_SOURCE_PROMPT
);
1100 struct tui_win_info
*first_win
;
1101 struct tui_win_info
*second_win
;
1103 if (cur_layout
== SRC_DISASSEM_COMMAND
)
1105 first_win
= TUI_SRC_WIN
;
1106 second_win
= TUI_DISASM_WIN
;
1110 first_win
= TUI_DATA_WIN
;
1111 second_win
= (struct tui_win_info
*) (tui_source_windows ())->list
[0];
1113 if (primary_win_info
== TUI_CMD_WIN
)
1115 ** Split the change in height accross the 1st & 2nd windows
1116 ** adjusting them as well.
1118 int first_split_diff
= diff
/ 2; /* subtract the locator */
1119 int second_split_diff
= first_split_diff
;
1123 if (first_win
->generic
.height
>
1124 second_win
->generic
.height
)
1132 second_split_diff
--;
1134 second_split_diff
++;
1137 /* make sure that the minimum hieghts are honored */
1138 while ((first_win
->generic
.height
+ first_split_diff
) < 3)
1141 second_split_diff
--;
1143 while ((second_win
->generic
.height
+ second_split_diff
) < 3)
1145 second_split_diff
++;
1148 make_invisible_and_set_new_height (
1150 first_win
->generic
.height
+ first_split_diff
);
1151 second_win
->generic
.origin
.y
= first_win
->generic
.height
- 1;
1152 make_invisible_and_set_new_height (
1153 second_win
, second_win
->generic
.height
+ second_split_diff
);
1154 TUI_CMD_WIN
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1155 make_invisible_and_set_new_height (TUI_CMD_WIN
, new_height
);
1159 if ((TUI_CMD_WIN
->generic
.height
+ diff
) < 1)
1161 ** If there is no way to increase the command window
1162 ** take real estate from the 1st or 2nd window.
1164 if ((TUI_CMD_WIN
->generic
.height
+ diff
) < 1)
1167 for (i
= TUI_CMD_WIN
->generic
.height
+ diff
;
1169 if (primary_win_info
== first_win
)
1170 second_win
->generic
.height
--;
1172 first_win
->generic
.height
--;
1175 if (primary_win_info
== first_win
)
1176 make_invisible_and_set_new_height (first_win
, new_height
);
1178 make_invisible_and_set_new_height (
1180 first_win
->generic
.height
);
1181 second_win
->generic
.origin
.y
= first_win
->generic
.height
- 1;
1182 if (primary_win_info
== second_win
)
1183 make_invisible_and_set_new_height (second_win
, new_height
);
1185 make_invisible_and_set_new_height (
1186 second_win
, second_win
->generic
.height
);
1187 TUI_CMD_WIN
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1188 if ((TUI_CMD_WIN
->generic
.height
+ diff
) < 1)
1189 make_invisible_and_set_new_height (TUI_CMD_WIN
, 1);
1191 make_invisible_and_set_new_height (
1192 TUI_CMD_WIN
, TUI_CMD_WIN
->generic
.height
+ diff
);
1194 make_visible_with_new_height (TUI_CMD_WIN
);
1195 make_visible_with_new_height (second_win
);
1196 make_visible_with_new_height (first_win
);
1197 if (first_win
->generic
.content_size
<= 0)
1198 tui_erase_source_content (first_win
, EMPTY_SOURCE_PROMPT
);
1199 if (second_win
->generic
.content_size
<= 0)
1200 tui_erase_source_content (second_win
, EMPTY_SOURCE_PROMPT
);
1209 /* Function make the target window (and auxillary windows associated
1210 with the targer) invisible, and set the new height and location. */
1212 make_invisible_and_set_new_height (struct tui_win_info
* win_info
, int height
)
1215 struct tui_gen_win_info
* gen_win_info
;
1217 tui_make_invisible (&win_info
->generic
);
1218 win_info
->generic
.height
= height
;
1220 win_info
->generic
.viewport_height
= height
- 1;
1222 win_info
->generic
.viewport_height
= height
;
1223 if (win_info
!= TUI_CMD_WIN
)
1224 win_info
->generic
.viewport_height
--;
1226 /* Now deal with the auxillary windows associated with win_info */
1227 switch (win_info
->generic
.type
)
1231 gen_win_info
= win_info
->detail
.source_info
.execution_info
;
1232 tui_make_invisible (gen_win_info
);
1233 gen_win_info
->height
= height
;
1234 gen_win_info
->origin
.y
= win_info
->generic
.origin
.y
;
1236 gen_win_info
->viewport_height
= height
- 1;
1238 gen_win_info
->viewport_height
= height
;
1239 if (win_info
!= TUI_CMD_WIN
)
1240 gen_win_info
->viewport_height
--;
1242 if (tui_win_has_locator (win_info
))
1244 gen_win_info
= tui_locator_win_info_ptr ();
1245 tui_make_invisible (gen_win_info
);
1246 gen_win_info
->origin
.y
= win_info
->generic
.origin
.y
+ height
;
1250 /* delete all data item windows */
1251 for (i
= 0; i
< win_info
->generic
.content_size
; i
++)
1253 gen_win_info
= (struct tui_gen_win_info
*) & ((struct tui_win_element
*)
1254 win_info
->generic
.content
[i
])->which_element
.data_window
;
1255 tui_delete_win (gen_win_info
->handle
);
1256 gen_win_info
->handle
= (WINDOW
*) NULL
;
1265 /* Function to make the windows with new heights visible. This means
1266 re-creating the windows' content since the window had to be
1267 destroyed to be made invisible. */
1269 make_visible_with_new_height (struct tui_win_info
* win_info
)
1273 tui_make_visible (&win_info
->generic
);
1274 tui_check_and_display_highlight_if_needed (win_info
);
1275 switch (win_info
->generic
.type
)
1279 tui_free_win_content (win_info
->detail
.source_info
.execution_info
);
1280 tui_make_visible (win_info
->detail
.source_info
.execution_info
);
1281 if (win_info
->generic
.content
!= NULL
)
1283 union tui_line_or_address line_or_addr
;
1284 struct symtab_and_line cursal
1285 = get_current_source_symtab_and_line ();
1287 if (win_info
->generic
.type
== SRC_WIN
)
1288 line_or_addr
.line_no
=
1289 win_info
->detail
.source_info
.start_line_or_addr
.line_no
;
1292 win_info
->detail
.source_info
.start_line_or_addr
.addr
;
1293 tui_free_win_content (&win_info
->generic
);
1294 tui_update_source_window (win_info
, cursal
.symtab
, line_or_addr
, TRUE
);
1296 else if (deprecated_selected_frame
!= (struct frame_info
*) NULL
)
1298 union tui_line_or_address line
;
1299 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
1302 s
= find_pc_symtab (get_frame_pc (deprecated_selected_frame
));
1303 if (win_info
->generic
.type
== SRC_WIN
)
1304 line
.line_no
= cursal
.line
;
1307 find_line_pc (s
, cursal
.line
, &line
.addr
);
1309 tui_update_source_window (win_info
, s
, line
, TRUE
);
1311 if (tui_win_has_locator (win_info
))
1313 tui_make_visible (tui_locator_win_info_ptr ());
1314 tui_show_locator_content ();
1318 tui_display_all_data ();
1321 win_info
->detail
.command_info
.cur_line
= 0;
1322 win_info
->detail
.command_info
.curch
= 0;
1323 wmove (win_info
->generic
.handle
,
1324 win_info
->detail
.command_info
.cur_line
,
1325 win_info
->detail
.command_info
.curch
);
1334 new_height_ok (struct tui_win_info
* primary_win_info
, int new_height
)
1336 int ok
= (new_height
< tui_term_height ());
1341 enum tui_layout_type cur_layout
= tui_current_layout ();
1343 diff
= (new_height
- primary_win_info
->generic
.height
) * (-1);
1344 if (cur_layout
== SRC_COMMAND
|| cur_layout
== DISASSEM_COMMAND
)
1346 ok
= ((primary_win_info
->generic
.type
== CMD_WIN
&&
1347 new_height
<= (tui_term_height () - 4) &&
1348 new_height
>= MIN_CMD_WIN_HEIGHT
) ||
1349 (primary_win_info
->generic
.type
!= CMD_WIN
&&
1350 new_height
<= (tui_term_height () - 2) &&
1351 new_height
>= MIN_WIN_HEIGHT
));
1353 { /* check the total height */
1354 struct tui_win_info
* win_info
;
1356 if (primary_win_info
== TUI_CMD_WIN
)
1357 win_info
= (struct tui_win_info
*) (tui_source_windows ())->list
[0];
1359 win_info
= TUI_CMD_WIN
;
1361 (win_info
->generic
.height
+ diff
)) <= tui_term_height ());
1366 int cur_total_height
, total_height
, min_height
= 0;
1367 struct tui_win_info
*first_win
;
1368 struct tui_win_info
*second_win
;
1370 if (cur_layout
== SRC_DISASSEM_COMMAND
)
1372 first_win
= TUI_SRC_WIN
;
1373 second_win
= TUI_DISASM_WIN
;
1377 first_win
= TUI_DATA_WIN
;
1378 second_win
= (struct tui_win_info
*) (tui_source_windows ())->list
[0];
1381 ** We could simply add all the heights to obtain the same result
1382 ** but below is more explicit since we subtract 1 for the
1383 ** line that the first and second windows share, and add one
1386 total_height
= cur_total_height
=
1387 (first_win
->generic
.height
+ second_win
->generic
.height
- 1)
1388 + TUI_CMD_WIN
->generic
.height
+ 1 /*locator */ ;
1389 if (primary_win_info
== TUI_CMD_WIN
)
1391 /* locator included since first & second win share a line */
1392 ok
= ((first_win
->generic
.height
+
1393 second_win
->generic
.height
+ diff
) >=
1394 (MIN_WIN_HEIGHT
* 2) &&
1395 new_height
>= MIN_CMD_WIN_HEIGHT
);
1398 total_height
= new_height
+ (first_win
->generic
.height
+
1399 second_win
->generic
.height
+ diff
);
1400 min_height
= MIN_CMD_WIN_HEIGHT
;
1405 min_height
= MIN_WIN_HEIGHT
;
1407 ** First see if we can increase/decrease the command
1408 ** window. And make sure that the command window is
1411 ok
= ((TUI_CMD_WIN
->generic
.height
+ diff
) > 0);
1414 ** Looks like we have to increase/decrease one of
1415 ** the other windows
1417 if (primary_win_info
== first_win
)
1418 ok
= (second_win
->generic
.height
+ diff
) >= min_height
;
1420 ok
= (first_win
->generic
.height
+ diff
) >= min_height
;
1424 if (primary_win_info
== first_win
)
1425 total_height
= new_height
+
1426 second_win
->generic
.height
+
1427 TUI_CMD_WIN
->generic
.height
+ diff
;
1429 total_height
= new_height
+
1430 first_win
->generic
.height
+
1431 TUI_CMD_WIN
->generic
.height
+ diff
;
1435 ** Now make sure that the proposed total height doesn't exceed
1436 ** the old total height.
1439 ok
= (new_height
>= min_height
&& total_height
<= cur_total_height
);
1448 parse_scrolling_args (char *arg
, struct tui_win_info
* * win_to_scroll
,
1453 *win_to_scroll
= tui_win_with_focus ();
1456 ** First set up the default window to scroll, in case there is no
1459 if (arg
!= (char *) NULL
)
1461 char *buf
, *buf_ptr
;
1463 /* process the number of lines to scroll */
1464 buf
= buf_ptr
= xstrdup (arg
);
1465 if (isdigit (*buf_ptr
))
1470 buf_ptr
= strchr (buf_ptr
, ' ');
1471 if (buf_ptr
!= (char *) NULL
)
1473 *buf_ptr
= (char) 0;
1475 *num_to_scroll
= atoi (num_str
);
1478 else if (num_to_scroll
)
1479 *num_to_scroll
= atoi (num_str
);
1482 /* process the window name if one is specified */
1483 if (buf_ptr
!= (char *) NULL
)
1488 if (*buf_ptr
== ' ')
1489 while (*(++buf_ptr
) == ' ')
1492 if (*buf_ptr
!= (char) 0)
1497 /* Validate the window name */
1498 for (i
= 0; i
< strlen (wname
); i
++)
1499 wname
[i
] = toupper (wname
[i
]);
1500 *win_to_scroll
= tui_partial_win_by_name (wname
);
1502 if (*win_to_scroll
== (struct tui_win_info
*) NULL
||
1503 !(*win_to_scroll
)->generic
.is_visible
)
1504 warning ("Invalid window specified. \n\
1505 The window name specified must be valid and visible.\n");
1506 else if (*win_to_scroll
== TUI_CMD_WIN
)
1507 *win_to_scroll
= (struct tui_win_info
*) (tui_source_windows ())->list
[0];