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"
59 #include <readline/readline.h>
61 /*******************************
63 ********************************/
64 static void _makeVisibleWithNewHeight (TuiWinInfoPtr
);
65 static void _makeInvisibleAndSetNewHeight (TuiWinInfoPtr
, int);
66 static TuiStatus
_tuiAdjustWinHeights (TuiWinInfoPtr
, int);
67 static int _newHeightOk (TuiWinInfoPtr
, int);
68 static void _tuiSetTabWidth_command (char *, int);
69 static void _tuiRefreshAll_command (char *, int);
70 static void _tuiSetWinHeight_command (char *, int);
71 static void _tuiXDBsetWinHeight_command (char *, int);
72 static void _tuiAllWindowsInfo (char *, int);
73 static void _tuiSetFocus_command (char *, int);
74 static void _tuiScrollForward_command (char *, int);
75 static void _tuiScrollBackward_command (char *, int);
76 static void _tuiScrollLeft_command (char *, int);
77 static void _tuiScrollRight_command (char *, int);
78 static void _parseScrollingArgs (char *, TuiWinInfoPtr
*, 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 ()
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
)
300 ** _initialize_tuiWin().
301 ** Function to initialize gdb commands, for tui window manipulation.
304 _initialize_tuiWin (void)
306 struct cmd_list_element
*c
;
307 static struct cmd_list_element
*tui_setlist
;
308 static struct cmd_list_element
*tui_showlist
;
310 /* Define the classes of commands.
311 They will appear in the help list in the reverse of this order. */
312 add_cmd ("tui", class_tui
, NULL
,
313 "Text User Interface commands.",
316 add_prefix_cmd ("tui", class_tui
, set_tui_cmd
,
317 "TUI configuration variables",
318 &tui_setlist
, "set tui ",
319 0/*allow-unknown*/, &setlist
);
320 add_prefix_cmd ("tui", class_tui
, show_tui_cmd
,
321 "TUI configuration variables",
322 &tui_showlist
, "show tui ",
323 0/*allow-unknown*/, &showlist
);
325 add_com ("refresh", class_tui
, _tuiRefreshAll_command
,
326 "Refresh the terminal display.\n");
328 add_com_alias ("U", "refresh", class_tui
, 0);
329 add_com ("tabset", class_tui
, _tuiSetTabWidth_command
,
330 "Set the width (in characters) of tab stops.\n\
331 Usage: tabset <n>\n");
332 add_com ("winheight", class_tui
, _tuiSetWinHeight_command
,
333 "Set the height of a specified window.\n\
334 Usage: winheight <win_name> [+ | -] <#lines>\n\
336 src : the source window\n\
337 cmd : the command window\n\
338 asm : the disassembly window\n\
339 regs : the register display\n");
340 add_com_alias ("wh", "winheight", class_tui
, 0);
341 add_info ("win", _tuiAllWindowsInfo
,
342 "List of all displayed windows.\n");
343 add_com ("focus", class_tui
, _tuiSetFocus_command
,
344 "Set focus to named window or next/prev window.\n\
345 Usage: focus {<win> | next | prev}\n\
346 Valid Window names are:\n\
347 src : the source window\n\
348 asm : the disassembly window\n\
349 regs : the register display\n\
350 cmd : the command window\n");
351 add_com_alias ("fs", "focus", class_tui
, 0);
352 add_com ("+", class_tui
, _tuiScrollForward_command
,
353 "Scroll window forward.\nUsage: + [win] [n]\n");
354 add_com ("-", class_tui
, _tuiScrollBackward_command
,
355 "Scroll window backward.\nUsage: - [win] [n]\n");
356 add_com ("<", class_tui
, _tuiScrollLeft_command
,
357 "Scroll window forward.\nUsage: < [win] [n]\n");
358 add_com (">", class_tui
, _tuiScrollRight_command
,
359 "Scroll window backward.\nUsage: > [win] [n]\n");
361 add_com ("w", class_xdb
, _tuiXDBsetWinHeight_command
,
362 "XDB compatibility command for setting the height of a command window.\n\
363 Usage: w <#lines>\n");
365 /* Define the tui control variables. */
367 ("border-kind", no_class
,
368 tui_border_kind_enums
, &tui_border_kind
,
369 "Set the kind of border for TUI windows.\n"
370 "This variable controls the border of TUI windows:\n"
371 "space use a white space\n"
372 "ascii use ascii characters + - | for the border\n"
373 "acs use the Alternate Character Set\n",
375 add_show_from_set (c
, &tui_showlist
);
378 ("border-mode", no_class
,
379 tui_border_mode_enums
, &tui_border_mode
,
380 "Set the attribute mode to use for the TUI window borders.\n"
381 "This variable controls the attributes to use for the window borders:\n"
382 "normal normal display\n"
383 "standout use highlight mode of terminal\n"
384 "reverse use reverse video mode\n"
385 "half use half bright\n"
386 "half-standout use half bright and standout mode\n"
387 "bold use extra bright or bold\n"
388 "bold-standout use extra bright or bold with standout mode\n",
390 add_show_from_set (c
, &tui_showlist
);
393 ("active-border-mode", no_class
,
394 tui_border_mode_enums
, &tui_active_border_mode
,
395 "Set the attribute mode to use for the active TUI window border.\n"
396 "This variable controls the attributes to use for the active window border:\n"
397 "normal normal display\n"
398 "standout use highlight mode of terminal\n"
399 "reverse use reverse video mode\n"
400 "half use half bright\n"
401 "half-standout use half bright and standout mode\n"
402 "bold use extra bright or bold\n"
403 "bold-standout use extra bright or bold with standout mode\n",
405 add_show_from_set (c
, &tui_showlist
);
408 /* Update gdb's knowledge of the terminal size. */
410 tui_update_gdb_sizes ()
413 int screenheight
, screenwidth
;
415 rl_get_screen_size (&screenheight
, &screenwidth
);
416 /* Set to TUI command window dimension or use readline values. */
417 sprintf (cmd
, "set width %d",
418 tui_active
? cmdWin
->generic
.width
: screenwidth
);
419 execute_command (cmd
, 0);
420 sprintf (cmd
, "set height %d",
421 tui_active
? cmdWin
->generic
.height
: screenheight
);
422 execute_command (cmd
, 0);
426 /* Set the logical focus to winInfo. */
428 tui_set_win_focus_to (TuiWinInfoPtr winInfo
)
430 if (m_winPtrNotNull (winInfo
))
432 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
434 if (m_winPtrNotNull (winWithFocus
) &&
435 winWithFocus
->generic
.type
!= CMD_WIN
)
436 tui_unhighlight_win (winWithFocus
);
437 tuiSetWinWithFocus (winInfo
);
438 if (winInfo
->generic
.type
!= CMD_WIN
)
439 tui_highlight_win (winInfo
);
443 } /* tuiSetWinFocusTo */
447 tui_scroll_forward (TuiWinInfoPtr winToScroll
, int numToScroll
)
449 if (winToScroll
!= cmdWin
)
451 int _numToScroll
= numToScroll
;
453 if (numToScroll
== 0)
454 _numToScroll
= winToScroll
->generic
.height
- 3;
456 ** If we are scrolling the source or disassembly window, do a
457 ** "psuedo" scroll since not all of the source is in memory,
458 ** only what is in the viewport. If winToScroll is the
459 ** command window do nothing since the term should handle it.
461 if (winToScroll
== srcWin
)
462 tuiVerticalSourceScroll (FORWARD_SCROLL
, _numToScroll
);
463 else if (winToScroll
== disassemWin
)
464 tui_vertical_disassem_scroll (FORWARD_SCROLL
, _numToScroll
);
465 else if (winToScroll
== dataWin
)
466 tui_vertical_data_scroll (FORWARD_SCROLL
, _numToScroll
);
471 tui_scroll_backward (TuiWinInfoPtr winToScroll
, int numToScroll
)
473 if (winToScroll
!= cmdWin
)
475 int _numToScroll
= numToScroll
;
477 if (numToScroll
== 0)
478 _numToScroll
= winToScroll
->generic
.height
- 3;
480 ** If we are scrolling the source or disassembly window, do a
481 ** "psuedo" scroll since not all of the source is in memory,
482 ** only what is in the viewport. If winToScroll is the
483 ** command window do nothing since the term should handle it.
485 if (winToScroll
== srcWin
)
486 tuiVerticalSourceScroll (BACKWARD_SCROLL
, _numToScroll
);
487 else if (winToScroll
== disassemWin
)
488 tui_vertical_disassem_scroll (BACKWARD_SCROLL
, _numToScroll
);
489 else if (winToScroll
== dataWin
)
490 tui_vertical_data_scroll (BACKWARD_SCROLL
, _numToScroll
);
496 tui_scroll_left (TuiWinInfoPtr winToScroll
, int numToScroll
)
498 if (winToScroll
!= cmdWin
)
500 int _numToScroll
= numToScroll
;
502 if (_numToScroll
== 0)
505 ** If we are scrolling the source or disassembly window, do a
506 ** "psuedo" scroll since not all of the source is in memory,
507 ** only what is in the viewport. If winToScroll is the
508 ** command window do nothing since the term should handle it.
510 if (winToScroll
== srcWin
|| winToScroll
== disassemWin
)
511 tui_horizontal_source_scroll (winToScroll
, LEFT_SCROLL
, _numToScroll
);
517 tui_scroll_right (TuiWinInfoPtr winToScroll
, int numToScroll
)
519 if (winToScroll
!= cmdWin
)
521 int _numToScroll
= numToScroll
;
523 if (_numToScroll
== 0)
526 ** If we are scrolling the source or disassembly window, do a
527 ** "psuedo" scroll since not all of the source is in memory,
528 ** only what is in the viewport. If winToScroll is the
529 ** command window do nothing since the term should handle it.
531 if (winToScroll
== srcWin
|| winToScroll
== disassemWin
)
532 tui_horizontal_source_scroll (winToScroll
, RIGHT_SCROLL
, _numToScroll
);
537 /* Scroll a window. Arguments are passed through a va_list. */
539 tui_scroll (TuiScrollDirection direction
,
540 TuiWinInfoPtr winToScroll
,
546 tui_scroll_forward (winToScroll
, numToScroll
);
548 case BACKWARD_SCROLL
:
549 tui_scroll_backward (winToScroll
, numToScroll
);
552 tui_scroll_left (winToScroll
, numToScroll
);
555 tui_scroll_right (winToScroll
, numToScroll
);
564 tui_refresh_all_win (void)
568 clearok (curscr
, TRUE
);
569 tui_refresh_all (winList
);
570 for (type
= SRC_WIN
; type
< MAX_MAJOR_WINDOWS
; type
++)
572 if (winList
[type
] && winList
[type
]->generic
.isVisible
)
578 tui_show_source_content (winList
[type
]);
579 tui_check_and_display_highlight_if_needed (winList
[type
]);
580 tui_erase_exec_info_content (winList
[type
]);
581 tui_update_exec_info (winList
[type
]);
584 tui_refresh_data_win ();
591 tui_show_locator_content ();
597 ** Resize all the windows based on the the terminal size. This
598 ** function gets called from within the readline sinwinch handler.
603 int heightDiff
, widthDiff
;
604 int screenheight
, screenwidth
;
606 rl_get_screen_size (&screenheight
, &screenwidth
);
607 widthDiff
= screenwidth
- termWidth ();
608 heightDiff
= screenheight
- termHeight ();
609 if (heightDiff
|| widthDiff
)
611 TuiLayoutType curLayout
= currentLayout ();
612 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
613 TuiWinInfoPtr firstWin
, secondWin
;
614 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
616 int newHeight
, splitDiff
, cmdSplitDiff
, numWinsDisplayed
= 2;
618 /* turn keypad off while we resize */
619 if (winWithFocus
!= cmdWin
)
620 keypad (cmdWin
->generic
.handle
, FALSE
);
621 tui_update_gdb_sizes ();
622 setTermHeightTo (screenheight
);
623 setTermWidthTo (screenwidth
);
624 if (curLayout
== SRC_DISASSEM_COMMAND
||
625 curLayout
== SRC_DATA_COMMAND
|| curLayout
== DISASSEM_DATA_COMMAND
)
627 splitDiff
= heightDiff
/ numWinsDisplayed
;
628 cmdSplitDiff
= splitDiff
;
629 if (heightDiff
% numWinsDisplayed
)
636 /* now adjust each window */
642 case DISASSEM_COMMAND
:
643 firstWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
644 firstWin
->generic
.width
+= widthDiff
;
645 locator
->width
+= widthDiff
;
646 /* check for invalid heights */
648 newHeight
= firstWin
->generic
.height
;
649 else if ((firstWin
->generic
.height
+ splitDiff
) >=
650 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
651 newHeight
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
652 else if ((firstWin
->generic
.height
+ splitDiff
) <= 0)
653 newHeight
= MIN_WIN_HEIGHT
;
655 newHeight
= firstWin
->generic
.height
+ splitDiff
;
657 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
658 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
659 cmdWin
->generic
.width
+= widthDiff
;
660 newHeight
= screenheight
- cmdWin
->generic
.origin
.y
;
661 _makeInvisibleAndSetNewHeight (cmdWin
, newHeight
);
662 _makeVisibleWithNewHeight (firstWin
);
663 _makeVisibleWithNewHeight (cmdWin
);
664 if (firstWin
->generic
.contentSize
<= 0)
665 tui_erase_source_content (firstWin
, EMPTY_SOURCE_PROMPT
);
668 if (curLayout
== SRC_DISASSEM_COMMAND
)
671 firstWin
->generic
.width
+= widthDiff
;
672 secondWin
= disassemWin
;
673 secondWin
->generic
.width
+= widthDiff
;
678 firstWin
->generic
.width
+= widthDiff
;
679 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
680 secondWin
->generic
.width
+= widthDiff
;
682 /* Change the first window's height/width */
683 /* check for invalid heights */
685 newHeight
= firstWin
->generic
.height
;
686 else if ((firstWin
->generic
.height
+
687 secondWin
->generic
.height
+ (splitDiff
* 2)) >=
688 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
689 newHeight
= (screenheight
- MIN_CMD_WIN_HEIGHT
- 1) / 2;
690 else if ((firstWin
->generic
.height
+ splitDiff
) <= 0)
691 newHeight
= MIN_WIN_HEIGHT
;
693 newHeight
= firstWin
->generic
.height
+ splitDiff
;
694 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
696 if (firstWin
== dataWin
&& widthDiff
!= 0)
697 firstWin
->detail
.dataDisplayInfo
.regsColumnCount
=
698 tui_calculate_regs_column_count (
699 firstWin
->detail
.dataDisplayInfo
.regsDisplayType
);
700 locator
->width
+= widthDiff
;
702 /* Change the second window's height/width */
703 /* check for invalid heights */
705 newHeight
= secondWin
->generic
.height
;
706 else if ((firstWin
->generic
.height
+
707 secondWin
->generic
.height
+ (splitDiff
* 2)) >=
708 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
710 newHeight
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
712 newHeight
= (newHeight
/ 2) + 1;
716 else if ((secondWin
->generic
.height
+ splitDiff
) <= 0)
717 newHeight
= MIN_WIN_HEIGHT
;
719 newHeight
= secondWin
->generic
.height
+ splitDiff
;
720 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
721 _makeInvisibleAndSetNewHeight (secondWin
, newHeight
);
723 /* Change the command window's height/width */
724 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
725 _makeInvisibleAndSetNewHeight (
726 cmdWin
, cmdWin
->generic
.height
+ cmdSplitDiff
);
727 _makeVisibleWithNewHeight (firstWin
);
728 _makeVisibleWithNewHeight (secondWin
);
729 _makeVisibleWithNewHeight (cmdWin
);
730 if (firstWin
->generic
.contentSize
<= 0)
731 tui_erase_source_content (firstWin
, EMPTY_SOURCE_PROMPT
);
732 if (secondWin
->generic
.contentSize
<= 0)
733 tui_erase_source_content (secondWin
, EMPTY_SOURCE_PROMPT
);
737 ** Now remove all invisible windows, and their content so that they get
738 ** created again when called for with the new size
740 for (winType
= SRC_WIN
; (winType
< MAX_MAJOR_WINDOWS
); winType
++)
742 if (winType
!= CMD_WIN
&& m_winPtrNotNull (winList
[winType
]) &&
743 !winList
[winType
]->generic
.isVisible
)
745 freeWindow (winList
[winType
]);
746 winList
[winType
] = (TuiWinInfoPtr
) NULL
;
749 tuiSetWinResizedTo (TRUE
);
750 /* turn keypad back on, unless focus is in the command window */
751 if (winWithFocus
!= cmdWin
)
752 keypad (cmdWin
->generic
.handle
, TRUE
);
759 ** tuiSigwinchHandler()
760 ** SIGWINCH signal handler for the tui. This signal handler is
761 ** always called, even when the readline package clears signals
762 ** because it is set as the old_sigwinch() (TUI only)
765 tuiSigwinchHandler (int signal
)
768 ** Say that a resize was done so that the readline can do it
769 ** later when appropriate.
771 tuiSetWinResizedTo (TRUE
);
774 } /* tuiSigwinchHandler */
778 /*************************
779 ** STATIC LOCAL FUNCTIONS
780 **************************/
784 ** _tuiScrollForward_command().
787 _tuiScrollForward_command (char *arg
, int fromTTY
)
790 TuiWinInfoPtr winToScroll
;
792 /* Make sure the curses mode is enabled. */
794 if (arg
== (char *) NULL
)
795 _parseScrollingArgs (arg
, &winToScroll
, (int *) NULL
);
797 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
798 tui_scroll (FORWARD_SCROLL
, winToScroll
, numToScroll
);
803 ** _tuiScrollBackward_command().
806 _tuiScrollBackward_command (char *arg
, int fromTTY
)
809 TuiWinInfoPtr winToScroll
;
811 /* Make sure the curses mode is enabled. */
813 if (arg
== (char *) NULL
)
814 _parseScrollingArgs (arg
, &winToScroll
, (int *) NULL
);
816 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
817 tui_scroll (BACKWARD_SCROLL
, winToScroll
, numToScroll
);
822 ** _tuiScrollLeft_command().
825 _tuiScrollLeft_command (char *arg
, int fromTTY
)
828 TuiWinInfoPtr winToScroll
;
830 /* Make sure the curses mode is enabled. */
832 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
833 tui_scroll (LEFT_SCROLL
, winToScroll
, numToScroll
);
838 ** _tuiScrollRight_command().
841 _tuiScrollRight_command (char *arg
, int fromTTY
)
844 TuiWinInfoPtr winToScroll
;
846 /* Make sure the curses mode is enabled. */
848 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
849 tui_scroll (RIGHT_SCROLL
, winToScroll
, numToScroll
);
855 ** Set focus to the window named by 'arg'
858 _tuiSetFocus (char *arg
, int fromTTY
)
860 if (arg
!= (char *) NULL
)
862 char *bufPtr
= (char *) xstrdup (arg
);
864 TuiWinInfoPtr winInfo
= (TuiWinInfoPtr
) NULL
;
866 for (i
= 0; (i
< strlen (bufPtr
)); i
++)
867 bufPtr
[i
] = toupper (arg
[i
]);
869 if (subset_compare (bufPtr
, "NEXT"))
870 winInfo
= tuiNextWin (tuiWinWithFocus ());
871 else if (subset_compare (bufPtr
, "PREV"))
872 winInfo
= tuiPrevWin (tuiWinWithFocus ());
874 winInfo
= partialWinByName (bufPtr
);
876 if (winInfo
== (TuiWinInfoPtr
) NULL
|| !winInfo
->generic
.isVisible
)
877 warning ("Invalid window specified. \n\
878 The window name specified must be valid and visible.\n");
881 tui_set_win_focus_to (winInfo
);
882 keypad (cmdWin
->generic
.handle
, (winInfo
!= cmdWin
));
885 if (dataWin
&& dataWin
->generic
.isVisible
)
886 tui_refresh_data_win ();
888 printf_filtered ("Focus set to %s window.\n",
889 winName ((TuiGenWinInfoPtr
) tuiWinWithFocus ()));
892 warning ("Incorrect Number of Arguments.\n%s", FOCUS_USAGE
);
898 ** _tuiSetFocus_command()
901 _tuiSetFocus_command (char *arg
, int fromTTY
)
903 /* Make sure the curses mode is enabled. */
905 _tuiSetFocus (arg
, fromTTY
);
910 ** _tuiAllWindowsInfo().
913 _tuiAllWindowsInfo (char *arg
, int fromTTY
)
916 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
918 for (type
= SRC_WIN
; (type
< MAX_MAJOR_WINDOWS
); type
++)
919 if (winList
[type
] && winList
[type
]->generic
.isVisible
)
921 if (winWithFocus
== winList
[type
])
922 printf_filtered (" %s\t(%d lines) <has focus>\n",
923 winName (&winList
[type
]->generic
),
924 winList
[type
]->generic
.height
);
926 printf_filtered (" %s\t(%d lines)\n",
927 winName (&winList
[type
]->generic
),
928 winList
[type
]->generic
.height
);
932 } /* _tuiAllWindowsInfo */
936 ** _tuiRefreshAll_command().
939 _tuiRefreshAll_command (char *arg
, int fromTTY
)
941 /* Make sure the curses mode is enabled. */
944 tui_refresh_all_win ();
949 ** _tuiSetWinTabWidth_command().
950 ** Set the height of the specified window.
953 _tuiSetTabWidth_command (char *arg
, int fromTTY
)
955 /* Make sure the curses mode is enabled. */
957 if (arg
!= (char *) NULL
)
963 tuiSetDefaultTabLen (ts
);
965 warning ("Tab widths greater than 0 must be specified.\n");
969 } /* _tuiSetTabWidth_command */
973 ** _tuiSetWinHeight().
974 ** Set the height of the specified window.
977 _tuiSetWinHeight (char *arg
, int fromTTY
)
979 /* Make sure the curses mode is enabled. */
981 if (arg
!= (char *) NULL
)
983 char *buf
= xstrdup (arg
);
985 char *wname
= (char *) NULL
;
987 TuiWinInfoPtr winInfo
;
990 bufPtr
= strchr (bufPtr
, ' ');
991 if (bufPtr
!= (char *) NULL
)
996 ** Validate the window name
998 for (i
= 0; i
< strlen (wname
); i
++)
999 wname
[i
] = toupper (wname
[i
]);
1000 winInfo
= partialWinByName (wname
);
1002 if (winInfo
== (TuiWinInfoPtr
) NULL
|| !winInfo
->generic
.isVisible
)
1003 warning ("Invalid window specified. \n\
1004 The window name specified must be valid and visible.\n");
1007 /* Process the size */
1008 while (*(++bufPtr
) == ' ')
1011 if (*bufPtr
!= (char) 0)
1014 int fixedSize
= TRUE
;
1017 if (*bufPtr
== '+' || *bufPtr
== '-')
1024 inputNo
= atoi (bufPtr
);
1030 newHeight
= inputNo
;
1032 newHeight
= winInfo
->generic
.height
+ inputNo
;
1034 ** Now change the window's height, and adjust all
1035 ** other windows around it
1037 if (_tuiAdjustWinHeights (winInfo
,
1038 newHeight
) == TUI_FAILURE
)
1039 warning ("Invalid window height specified.\n%s",
1042 tui_update_gdb_sizes ();
1045 warning ("Invalid window height specified.\n%s",
1051 printf_filtered (WIN_HEIGHT_USAGE
);
1053 if (buf
!= (char *) NULL
)
1057 printf_filtered (WIN_HEIGHT_USAGE
);
1060 } /* _tuiSetWinHeight */
1063 ** _tuiSetWinHeight_command().
1064 ** Set the height of the specified window, with va_list.
1067 _tuiSetWinHeight_command (char *arg
, int fromTTY
)
1069 /* Make sure the curses mode is enabled. */
1071 _tuiSetWinHeight (arg
, fromTTY
);
1076 ** _tuiXDBsetWinHeight().
1077 ** XDB Compatibility command for setting the window height. This will
1078 ** increase or decrease the command window by the specified amount.
1081 _tuiXDBsetWinHeight (char *arg
, int fromTTY
)
1083 /* Make sure the curses mode is enabled. */
1085 if (arg
!= (char *) NULL
)
1087 int inputNo
= atoi (arg
);
1090 { /* Add 1 for the locator */
1091 int newHeight
= termHeight () - (inputNo
+ 1);
1093 if (!_newHeightOk (winList
[CMD_WIN
], newHeight
) ||
1094 _tuiAdjustWinHeights (winList
[CMD_WIN
],
1095 newHeight
) == TUI_FAILURE
)
1096 warning ("Invalid window height specified.\n%s",
1097 XDBWIN_HEIGHT_USAGE
);
1100 warning ("Invalid window height specified.\n%s",
1101 XDBWIN_HEIGHT_USAGE
);
1104 warning ("Invalid window height specified.\n%s", XDBWIN_HEIGHT_USAGE
);
1107 } /* _tuiXDBsetWinHeight */
1110 ** _tuiSetWinHeight_command().
1111 ** Set the height of the specified window, with va_list.
1114 _tuiXDBsetWinHeight_command (char *arg
, int fromTTY
)
1116 _tuiXDBsetWinHeight (arg
, fromTTY
);
1121 ** _tuiAdjustWinHeights().
1122 ** Function to adjust all window heights around the primary
1125 _tuiAdjustWinHeights (TuiWinInfoPtr primaryWinInfo
, int newHeight
)
1127 TuiStatus status
= TUI_FAILURE
;
1129 if (_newHeightOk (primaryWinInfo
, newHeight
))
1131 status
= TUI_SUCCESS
;
1132 if (newHeight
!= primaryWinInfo
->generic
.height
)
1135 TuiWinInfoPtr winInfo
;
1136 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
1137 TuiLayoutType curLayout
= currentLayout ();
1139 diff
= (newHeight
- primaryWinInfo
->generic
.height
) * (-1);
1140 if (curLayout
== SRC_COMMAND
|| curLayout
== DISASSEM_COMMAND
)
1142 TuiWinInfoPtr srcWinInfo
;
1144 _makeInvisibleAndSetNewHeight (primaryWinInfo
, newHeight
);
1145 if (primaryWinInfo
->generic
.type
== CMD_WIN
)
1147 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1148 srcWinInfo
= winInfo
;
1152 winInfo
= winList
[CMD_WIN
];
1153 srcWinInfo
= primaryWinInfo
;
1155 _makeInvisibleAndSetNewHeight (winInfo
,
1156 winInfo
->generic
.height
+ diff
);
1157 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1158 _makeVisibleWithNewHeight (winInfo
);
1159 _makeVisibleWithNewHeight (primaryWinInfo
);
1160 if (srcWinInfo
->generic
.contentSize
<= 0)
1161 tui_erase_source_content (srcWinInfo
, EMPTY_SOURCE_PROMPT
);
1165 TuiWinInfoPtr firstWin
, secondWin
;
1167 if (curLayout
== SRC_DISASSEM_COMMAND
)
1170 secondWin
= disassemWin
;
1175 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1177 if (primaryWinInfo
== cmdWin
)
1179 ** Split the change in height accross the 1st & 2nd windows
1180 ** adjusting them as well.
1182 int firstSplitDiff
= diff
/ 2; /* subtract the locator */
1183 int secondSplitDiff
= firstSplitDiff
;
1187 if (firstWin
->generic
.height
>
1188 secondWin
->generic
.height
)
1201 /* make sure that the minimum hieghts are honored */
1202 while ((firstWin
->generic
.height
+ firstSplitDiff
) < 3)
1207 while ((secondWin
->generic
.height
+ secondSplitDiff
) < 3)
1212 _makeInvisibleAndSetNewHeight (
1214 firstWin
->generic
.height
+ firstSplitDiff
);
1215 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
1216 _makeInvisibleAndSetNewHeight (
1217 secondWin
, secondWin
->generic
.height
+ secondSplitDiff
);
1218 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1219 _makeInvisibleAndSetNewHeight (cmdWin
, newHeight
);
1223 if ((cmdWin
->generic
.height
+ diff
) < 1)
1225 ** If there is no way to increase the command window
1226 ** take real estate from the 1st or 2nd window.
1228 if ((cmdWin
->generic
.height
+ diff
) < 1)
1231 for (i
= cmdWin
->generic
.height
+ diff
;
1233 if (primaryWinInfo
== firstWin
)
1234 secondWin
->generic
.height
--;
1236 firstWin
->generic
.height
--;
1239 if (primaryWinInfo
== firstWin
)
1240 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
1242 _makeInvisibleAndSetNewHeight (
1244 firstWin
->generic
.height
);
1245 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
1246 if (primaryWinInfo
== secondWin
)
1247 _makeInvisibleAndSetNewHeight (secondWin
, newHeight
);
1249 _makeInvisibleAndSetNewHeight (
1250 secondWin
, secondWin
->generic
.height
);
1251 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1252 if ((cmdWin
->generic
.height
+ diff
) < 1)
1253 _makeInvisibleAndSetNewHeight (cmdWin
, 1);
1255 _makeInvisibleAndSetNewHeight (
1256 cmdWin
, cmdWin
->generic
.height
+ diff
);
1258 _makeVisibleWithNewHeight (cmdWin
);
1259 _makeVisibleWithNewHeight (secondWin
);
1260 _makeVisibleWithNewHeight (firstWin
);
1261 if (firstWin
->generic
.contentSize
<= 0)
1262 tui_erase_source_content (firstWin
, EMPTY_SOURCE_PROMPT
);
1263 if (secondWin
->generic
.contentSize
<= 0)
1264 tui_erase_source_content (secondWin
, EMPTY_SOURCE_PROMPT
);
1270 } /* _tuiAdjustWinHeights */
1274 ** _makeInvisibleAndSetNewHeight().
1275 ** Function make the target window (and auxillary windows associated
1276 ** with the targer) invisible, and set the new height and location.
1279 _makeInvisibleAndSetNewHeight (TuiWinInfoPtr winInfo
, int height
)
1282 TuiGenWinInfoPtr genWinInfo
;
1284 tui_make_invisible (&winInfo
->generic
);
1285 winInfo
->generic
.height
= height
;
1287 winInfo
->generic
.viewportHeight
= height
- 1;
1289 winInfo
->generic
.viewportHeight
= height
;
1290 if (winInfo
!= cmdWin
)
1291 winInfo
->generic
.viewportHeight
--;
1293 /* Now deal with the auxillary windows associated with winInfo */
1294 switch (winInfo
->generic
.type
)
1298 genWinInfo
= winInfo
->detail
.sourceInfo
.executionInfo
;
1299 tui_make_invisible (genWinInfo
);
1300 genWinInfo
->height
= height
;
1301 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
;
1303 genWinInfo
->viewportHeight
= height
- 1;
1305 genWinInfo
->viewportHeight
= height
;
1306 if (winInfo
!= cmdWin
)
1307 genWinInfo
->viewportHeight
--;
1309 if (m_hasLocator (winInfo
))
1311 genWinInfo
= locatorWinInfoPtr ();
1312 tui_make_invisible (genWinInfo
);
1313 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
+ height
;
1317 /* delete all data item windows */
1318 for (i
= 0; i
< winInfo
->generic
.contentSize
; i
++)
1320 genWinInfo
= (TuiGenWinInfoPtr
) & ((TuiWinElementPtr
)
1321 winInfo
->generic
.content
[i
])->whichElement
.dataWindow
;
1322 tui_delete_win (genWinInfo
->handle
);
1323 genWinInfo
->handle
= (WINDOW
*) NULL
;
1333 ** _makeVisibleWithNewHeight().
1334 ** Function to make the windows with new heights visible.
1335 ** This means re-creating the windows' content since the window
1336 ** had to be destroyed to be made invisible.
1339 _makeVisibleWithNewHeight (TuiWinInfoPtr winInfo
)
1343 tui_make_visible (&winInfo
->generic
);
1344 tui_check_and_display_highlight_if_needed (winInfo
);
1345 switch (winInfo
->generic
.type
)
1349 freeWinContent (winInfo
->detail
.sourceInfo
.executionInfo
);
1350 tui_make_visible (winInfo
->detail
.sourceInfo
.executionInfo
);
1351 if (winInfo
->generic
.content
!= (OpaquePtr
) NULL
)
1353 TuiLineOrAddress lineOrAddr
;
1354 struct symtab_and_line cursal
1355 = get_current_source_symtab_and_line ();
1357 if (winInfo
->generic
.type
== SRC_WIN
)
1359 winInfo
->detail
.sourceInfo
.startLineOrAddr
.lineNo
;
1362 winInfo
->detail
.sourceInfo
.startLineOrAddr
.addr
;
1363 freeWinContent (&winInfo
->generic
);
1364 tui_update_source_window (winInfo
, cursal
.symtab
, lineOrAddr
, TRUE
);
1366 else if (deprecated_selected_frame
!= (struct frame_info
*) NULL
)
1368 TuiLineOrAddress line
;
1369 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
1372 s
= find_pc_symtab (get_frame_pc (deprecated_selected_frame
));
1373 if (winInfo
->generic
.type
== SRC_WIN
)
1374 line
.lineNo
= cursal
.line
;
1377 find_line_pc (s
, cursal
.line
, &line
.addr
);
1379 tui_update_source_window (winInfo
, s
, line
, TRUE
);
1381 if (m_hasLocator (winInfo
))
1383 tui_make_visible (locatorWinInfoPtr ());
1384 tui_show_locator_content ();
1388 tui_display_all_data ();
1391 winInfo
->detail
.commandInfo
.curLine
= 0;
1392 winInfo
->detail
.commandInfo
.curch
= 0;
1393 wmove (winInfo
->generic
.handle
,
1394 winInfo
->detail
.commandInfo
.curLine
,
1395 winInfo
->detail
.commandInfo
.curch
);
1402 } /* _makeVisibleWithNewHeight */
1406 _newHeightOk (TuiWinInfoPtr primaryWinInfo
, int newHeight
)
1408 int ok
= (newHeight
< termHeight ());
1413 TuiLayoutType curLayout
= currentLayout ();
1415 diff
= (newHeight
- primaryWinInfo
->generic
.height
) * (-1);
1416 if (curLayout
== SRC_COMMAND
|| curLayout
== DISASSEM_COMMAND
)
1418 ok
= ((primaryWinInfo
->generic
.type
== CMD_WIN
&&
1419 newHeight
<= (termHeight () - 4) &&
1420 newHeight
>= MIN_CMD_WIN_HEIGHT
) ||
1421 (primaryWinInfo
->generic
.type
!= CMD_WIN
&&
1422 newHeight
<= (termHeight () - 2) &&
1423 newHeight
>= MIN_WIN_HEIGHT
));
1425 { /* check the total height */
1426 TuiWinInfoPtr winInfo
;
1428 if (primaryWinInfo
== cmdWin
)
1429 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1433 (winInfo
->generic
.height
+ diff
)) <= termHeight ());
1438 int curTotalHeight
, totalHeight
, minHeight
= 0;
1439 TuiWinInfoPtr firstWin
, secondWin
;
1441 if (curLayout
== SRC_DISASSEM_COMMAND
)
1444 secondWin
= disassemWin
;
1449 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1452 ** We could simply add all the heights to obtain the same result
1453 ** but below is more explicit since we subtract 1 for the
1454 ** line that the first and second windows share, and add one
1457 totalHeight
= curTotalHeight
=
1458 (firstWin
->generic
.height
+ secondWin
->generic
.height
- 1)
1459 + cmdWin
->generic
.height
+ 1 /*locator */ ;
1460 if (primaryWinInfo
== cmdWin
)
1462 /* locator included since first & second win share a line */
1463 ok
= ((firstWin
->generic
.height
+
1464 secondWin
->generic
.height
+ diff
) >=
1465 (MIN_WIN_HEIGHT
* 2) &&
1466 newHeight
>= MIN_CMD_WIN_HEIGHT
);
1469 totalHeight
= newHeight
+ (firstWin
->generic
.height
+
1470 secondWin
->generic
.height
+ diff
);
1471 minHeight
= MIN_CMD_WIN_HEIGHT
;
1476 minHeight
= MIN_WIN_HEIGHT
;
1478 ** First see if we can increase/decrease the command
1479 ** window. And make sure that the command window is
1482 ok
= ((cmdWin
->generic
.height
+ diff
) > 0);
1485 ** Looks like we have to increase/decrease one of
1486 ** the other windows
1488 if (primaryWinInfo
== firstWin
)
1489 ok
= (secondWin
->generic
.height
+ diff
) >= minHeight
;
1491 ok
= (firstWin
->generic
.height
+ diff
) >= minHeight
;
1495 if (primaryWinInfo
== firstWin
)
1496 totalHeight
= newHeight
+
1497 secondWin
->generic
.height
+
1498 cmdWin
->generic
.height
+ diff
;
1500 totalHeight
= newHeight
+
1501 firstWin
->generic
.height
+
1502 cmdWin
->generic
.height
+ diff
;
1506 ** Now make sure that the proposed total height doesn't exceed
1507 ** the old total height.
1510 ok
= (newHeight
>= minHeight
&& totalHeight
<= curTotalHeight
);
1515 } /* _newHeightOk */
1519 ** _parseScrollingArgs().
1522 _parseScrollingArgs (char *arg
, TuiWinInfoPtr
* winToScroll
, int *numToScroll
)
1526 *winToScroll
= tuiWinWithFocus ();
1529 ** First set up the default window to scroll, in case there is no
1532 if (arg
!= (char *) NULL
)
1536 /* process the number of lines to scroll */
1537 buf
= bufPtr
= xstrdup (arg
);
1538 if (isdigit (*bufPtr
))
1543 bufPtr
= strchr (bufPtr
, ' ');
1544 if (bufPtr
!= (char *) NULL
)
1548 *numToScroll
= atoi (numStr
);
1551 else if (numToScroll
)
1552 *numToScroll
= atoi (numStr
);
1555 /* process the window name if one is specified */
1556 if (bufPtr
!= (char *) NULL
)
1562 while (*(++bufPtr
) == ' ')
1565 if (*bufPtr
!= (char) 0)
1570 /* Validate the window name */
1571 for (i
= 0; i
< strlen (wname
); i
++)
1572 wname
[i
] = toupper (wname
[i
]);
1573 *winToScroll
= partialWinByName (wname
);
1575 if (*winToScroll
== (TuiWinInfoPtr
) NULL
||
1576 !(*winToScroll
)->generic
.isVisible
)
1577 warning ("Invalid window specified. \n\
1578 The window name specified must be valid and visible.\n");
1579 else if (*winToScroll
== cmdWin
)
1580 *winToScroll
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1586 } /* _parseScrollingArgs */