1 /* TUI window generic functions.
3 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation,
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 */
30 /* FIXME: cagney/2002-02-28: The GDB coding standard indicates that
31 "defs.h" should be included first. Unfortunatly some systems
32 (currently Debian GNU/Linux) include the <stdbool.h> via <curses.h>
33 and they clash with "bfd.h"'s definiton of true/false. The correct
34 fix is to remove true/false from "bfd.h", however, until that
35 happens, hack around it by including "config.h" and <curses.h>
52 #include "breakpoint.h"
54 #include "cli/cli-cmds.h"
60 #include "tuiGeneralWin.h"
63 #include "tuiDisassem.h"
64 #include "tuiSource.h"
65 #include "tuiSourceWin.h"
66 #include "tuiDataWin.h"
68 /*******************************
70 ********************************/
71 static void _makeVisibleWithNewHeight (TuiWinInfoPtr
);
72 static void _makeInvisibleAndSetNewHeight (TuiWinInfoPtr
, int);
73 static TuiStatus
_tuiAdjustWinHeights (TuiWinInfoPtr
, int);
74 static int _newHeightOk (TuiWinInfoPtr
, int);
75 static void _tuiSetTabWidth_command (char *, int);
76 static void _tuiRefreshAll_command (char *, int);
77 static void _tuiSetWinHeight_command (char *, int);
78 static void _tuiXDBsetWinHeight_command (char *, int);
79 static void _tuiAllWindowsInfo (char *, int);
80 static void _tuiSetFocus_command (char *, int);
81 static void _tuiScrollForward_command (char *, int);
82 static void _tuiScrollBackward_command (char *, int);
83 static void _tuiScrollLeft_command (char *, int);
84 static void _tuiScrollRight_command (char *, int);
85 static void _parseScrollingArgs (char *, TuiWinInfoPtr
*, int *);
88 /***************************************
90 ***************************************/
91 #define WIN_HEIGHT_USAGE "Usage: winheight <win_name> [+ | -] <#lines>\n"
92 #define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n"
93 #define FOCUS_USAGE "Usage: focus {<win> | next | prev}\n"
95 /***************************************
97 ***************************************/
100 # define ACS_LRCORNER '+'
103 # define ACS_LLCORNER '+'
106 # define ACS_ULCORNER '+'
109 # define ACS_URCORNER '+'
112 # define ACS_HLINE '-'
115 # define ACS_VLINE '|'
118 /* Possible values for tui-border-kind variable. */
119 static const char *tui_border_kind_enums
[] = {
126 /* Possible values for tui-border-mode and tui-active-border-mode. */
127 static const char *tui_border_mode_enums
[] = {
144 /* Translation table for border-mode variables.
145 The list of values must be terminated by a NULL.
146 After the NULL value, an entry defines the default. */
147 struct tui_translate tui_border_mode_translate
[] = {
148 { "normal", A_NORMAL
},
149 { "standout", A_STANDOUT
},
150 { "reverse", A_REVERSE
},
152 { "half-standout", A_DIM
| A_STANDOUT
},
154 { "bold-standout", A_BOLD
| A_STANDOUT
},
156 { "normal", A_NORMAL
}
159 /* Translation tables for border-kind, one for each border
160 character (see wborder, border curses operations).
161 -1 is used to indicate the ACS because ACS characters
162 are determined at run time by curses (depends on terminal). */
163 struct tui_translate tui_border_kind_translate_vline
[] = {
171 struct tui_translate tui_border_kind_translate_hline
[] = {
179 struct tui_translate tui_border_kind_translate_ulcorner
[] = {
187 struct tui_translate tui_border_kind_translate_urcorner
[] = {
195 struct tui_translate tui_border_kind_translate_llcorner
[] = {
203 struct tui_translate tui_border_kind_translate_lrcorner
[] = {
212 /* Tui configuration variables controlled with set/show command. */
213 const char *tui_active_border_mode
= "bold-standout";
214 const char *tui_border_mode
= "normal";
215 const char *tui_border_kind
= "acs";
217 /* Tui internal configuration variables. These variables are
218 updated by tui_update_variables to reflect the tui configuration
220 chtype tui_border_vline
;
221 chtype tui_border_hline
;
222 chtype tui_border_ulcorner
;
223 chtype tui_border_urcorner
;
224 chtype tui_border_llcorner
;
225 chtype tui_border_lrcorner
;
227 int tui_border_attrs
;
228 int tui_active_border_attrs
;
230 /* Identify the item in the translation table.
231 When the item is not recognized, use the default entry. */
232 static struct tui_translate
*
233 translate (const char *name
, struct tui_translate
*table
)
237 if (name
&& strcmp (table
->name
, name
) == 0)
242 /* Not found, return default entry. */
247 /* Update the tui internal configuration according to gdb settings.
248 Returns 1 if the configuration has changed and the screen should
251 tui_update_variables ()
254 struct tui_translate
*entry
;
256 entry
= translate (tui_border_mode
, tui_border_mode_translate
);
257 if (tui_border_attrs
!= entry
->value
)
259 tui_border_attrs
= entry
->value
;
262 entry
= translate (tui_active_border_mode
, tui_border_mode_translate
);
263 if (tui_active_border_attrs
!= entry
->value
)
265 tui_active_border_attrs
= entry
->value
;
269 /* If one corner changes, all characters are changed.
270 Only check the first one. The ACS characters are determined at
271 run time by curses terminal management. */
272 entry
= translate (tui_border_kind
, tui_border_kind_translate_lrcorner
);
273 if (tui_border_lrcorner
!= (chtype
) entry
->value
)
275 tui_border_lrcorner
= (entry
->value
< 0) ? ACS_LRCORNER
: entry
->value
;
278 entry
= translate (tui_border_kind
, tui_border_kind_translate_llcorner
);
279 tui_border_llcorner
= (entry
->value
< 0) ? ACS_LLCORNER
: entry
->value
;
281 entry
= translate (tui_border_kind
, tui_border_kind_translate_ulcorner
);
282 tui_border_ulcorner
= (entry
->value
< 0) ? ACS_ULCORNER
: entry
->value
;
284 entry
= translate (tui_border_kind
, tui_border_kind_translate_urcorner
);
285 tui_border_urcorner
= (entry
->value
< 0) ? ACS_URCORNER
: entry
->value
;
287 entry
= translate (tui_border_kind
, tui_border_kind_translate_hline
);
288 tui_border_hline
= (entry
->value
< 0) ? ACS_HLINE
: entry
->value
;
290 entry
= translate (tui_border_kind
, tui_border_kind_translate_vline
);
291 tui_border_vline
= (entry
->value
< 0) ? ACS_VLINE
: entry
->value
;
297 set_tui_cmd (char *args
, int from_tty
)
302 show_tui_cmd (char *args
, int from_tty
)
307 ** _initialize_tuiWin().
308 ** Function to initialize gdb commands, for tui window manipulation.
311 _initialize_tuiWin (void)
313 struct cmd_list_element
*c
;
314 static struct cmd_list_element
*tui_setlist
;
315 static struct cmd_list_element
*tui_showlist
;
317 /* Define the classes of commands.
318 They will appear in the help list in the reverse of this order. */
319 add_cmd ("tui", class_tui
, NULL
,
320 "Text User Interface commands.",
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
, _tuiRefreshAll_command
,
333 "Refresh the terminal display.\n");
335 add_com_alias ("U", "refresh", class_tui
, 0);
336 add_com ("tabset", class_tui
, _tuiSetTabWidth_command
,
337 "Set the width (in characters) of tab stops.\n\
338 Usage: tabset <n>\n");
339 add_com ("winheight", class_tui
, _tuiSetWinHeight_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", _tuiAllWindowsInfo
,
349 "List of all displayed windows.\n");
350 add_com ("focus", class_tui
, _tuiSetFocus_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
, _tuiScrollForward_command
,
360 "Scroll window forward.\nUsage: + [win] [n]\n");
361 add_com ("-", class_tui
, _tuiScrollBackward_command
,
362 "Scroll window backward.\nUsage: - [win] [n]\n");
363 add_com ("<", class_tui
, _tuiScrollLeft_command
,
364 "Scroll window forward.\nUsage: < [win] [n]\n");
365 add_com (">", class_tui
, _tuiScrollRight_command
,
366 "Scroll window backward.\nUsage: > [win] [n]\n");
368 add_com ("w", class_xdb
, _tuiXDBsetWinHeight_command
,
369 "XDB compatibility command for setting the height of a command window.\n\
370 Usage: w <#lines>\n");
372 /* Define the tui control variables. */
374 ("border-kind", no_class
,
375 tui_border_kind_enums
, &tui_border_kind
,
376 "Set the kind of border for TUI windows.\n"
377 "This variable controls the border of TUI windows:\n"
378 "space use a white space\n"
379 "ascii use ascii characters + - | for the border\n"
380 "acs use the Alternate Character Set\n",
382 add_show_from_set (c
, &tui_showlist
);
385 ("border-mode", no_class
,
386 tui_border_mode_enums
, &tui_border_mode
,
387 "Set the attribute mode to use for the TUI window borders.\n"
388 "This variable controls the attributes to use for the window borders:\n"
389 "normal normal display\n"
390 "standout use highlight mode of terminal\n"
391 "reverse use reverse video mode\n"
392 "half use half bright\n"
393 "half-standout use half bright and standout mode\n"
394 "bold use extra bright or bold\n"
395 "bold-standout use extra bright or bold with standout mode\n",
397 add_show_from_set (c
, &tui_showlist
);
400 ("active-border-mode", no_class
,
401 tui_border_mode_enums
, &tui_active_border_mode
,
402 "Set the attribute mode to use for the active TUI window border.\n"
403 "This variable controls the attributes to use for the active window border:\n"
404 "normal normal display\n"
405 "standout use highlight mode of terminal\n"
406 "reverse use reverse video mode\n"
407 "half use half bright\n"
408 "half-standout use half bright and standout mode\n"
409 "bold use extra bright or bold\n"
410 "bold-standout use extra bright or bold with standout mode\n",
412 add_show_from_set (c
, &tui_showlist
);
415 /* Update gdb's knowledge of the terminal size. */
417 tui_update_gdb_sizes ()
420 extern int screenheight
, screenwidth
; /* in readline */
422 /* Set to TUI command window dimension or use readline values. */
423 sprintf (cmd
, "set width %d",
424 tui_active
? cmdWin
->generic
.width
: screenwidth
);
425 execute_command (cmd
, 0);
426 sprintf (cmd
, "set height %d",
427 tui_active
? cmdWin
->generic
.height
: screenheight
);
428 execute_command (cmd
, 0);
434 ** Set the logical focus to winInfo
437 tuiSetWinFocusTo (TuiWinInfoPtr winInfo
)
439 if (m_winPtrNotNull (winInfo
))
441 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
443 if (m_winPtrNotNull (winWithFocus
) &&
444 winWithFocus
->generic
.type
!= CMD_WIN
)
445 unhighlightWin (winWithFocus
);
446 tuiSetWinWithFocus (winInfo
);
447 if (winInfo
->generic
.type
!= CMD_WIN
)
448 highlightWin (winInfo
);
452 } /* tuiSetWinFocusTo */
456 ** tuiScrollForward().
459 tuiScrollForward (TuiWinInfoPtr winToScroll
, int numToScroll
)
461 if (winToScroll
!= cmdWin
)
463 int _numToScroll
= numToScroll
;
465 if (numToScroll
== 0)
466 _numToScroll
= winToScroll
->generic
.height
- 3;
468 ** If we are scrolling the source or disassembly window, do a
469 ** "psuedo" scroll since not all of the source is in memory,
470 ** only what is in the viewport. If winToScroll is the
471 ** command window do nothing since the term should handle it.
473 if (winToScroll
== srcWin
)
474 tuiVerticalSourceScroll (FORWARD_SCROLL
, _numToScroll
);
475 else if (winToScroll
== disassemWin
)
476 tuiVerticalDisassemScroll (FORWARD_SCROLL
, _numToScroll
);
477 else if (winToScroll
== dataWin
)
478 tuiVerticalDataScroll (FORWARD_SCROLL
, _numToScroll
);
482 } /* tuiScrollForward */
486 ** tuiScrollBackward().
489 tuiScrollBackward (TuiWinInfoPtr winToScroll
, int numToScroll
)
491 if (winToScroll
!= cmdWin
)
493 int _numToScroll
= numToScroll
;
495 if (numToScroll
== 0)
496 _numToScroll
= winToScroll
->generic
.height
- 3;
498 ** If we are scrolling the source or disassembly window, do a
499 ** "psuedo" scroll since not all of the source is in memory,
500 ** only what is in the viewport. If winToScroll is the
501 ** command window do nothing since the term should handle it.
503 if (winToScroll
== srcWin
)
504 tuiVerticalSourceScroll (BACKWARD_SCROLL
, _numToScroll
);
505 else if (winToScroll
== disassemWin
)
506 tuiVerticalDisassemScroll (BACKWARD_SCROLL
, _numToScroll
);
507 else if (winToScroll
== dataWin
)
508 tuiVerticalDataScroll (BACKWARD_SCROLL
, _numToScroll
);
511 } /* tuiScrollBackward */
518 tuiScrollLeft (TuiWinInfoPtr winToScroll
, int numToScroll
)
520 if (winToScroll
!= cmdWin
)
522 int _numToScroll
= numToScroll
;
524 if (_numToScroll
== 0)
527 ** If we are scrolling the source or disassembly window, do a
528 ** "psuedo" scroll since not all of the source is in memory,
529 ** only what is in the viewport. If winToScroll is the
530 ** command window do nothing since the term should handle it.
532 if (winToScroll
== srcWin
|| winToScroll
== disassemWin
)
533 tuiHorizontalSourceScroll (winToScroll
, LEFT_SCROLL
, _numToScroll
);
536 } /* tuiScrollLeft */
543 tuiScrollRight (TuiWinInfoPtr winToScroll
, int numToScroll
)
545 if (winToScroll
!= cmdWin
)
547 int _numToScroll
= numToScroll
;
549 if (_numToScroll
== 0)
552 ** If we are scrolling the source or disassembly window, do a
553 ** "psuedo" scroll since not all of the source is in memory,
554 ** only what is in the viewport. If winToScroll is the
555 ** command window do nothing since the term should handle it.
557 if (winToScroll
== srcWin
|| winToScroll
== disassemWin
)
558 tuiHorizontalSourceScroll (winToScroll
, RIGHT_SCROLL
, _numToScroll
);
561 } /* tuiScrollRight */
566 ** Scroll a window. Arguments are passed through a va_list.
569 tui_scroll (TuiScrollDirection direction
,
570 TuiWinInfoPtr winToScroll
,
576 tuiScrollForward (winToScroll
, numToScroll
);
578 case BACKWARD_SCROLL
:
579 tuiScrollBackward (winToScroll
, numToScroll
);
582 tuiScrollLeft (winToScroll
, numToScroll
);
585 tuiScrollRight (winToScroll
, numToScroll
);
601 clearok (curscr
, TRUE
);
602 refreshAll (winList
);
603 for (type
= SRC_WIN
; type
< MAX_MAJOR_WINDOWS
; type
++)
605 if (winList
[type
] && winList
[type
]->generic
.isVisible
)
611 tuiShowSourceContent (winList
[type
]);
612 checkAndDisplayHighlightIfNeeded (winList
[type
]);
613 tuiEraseExecInfoContent (winList
[type
]);
614 tuiUpdateExecInfo (winList
[type
]);
617 tuiRefreshDataWin ();
624 tuiShowLocatorContent ();
630 ** Resize all the windows based on the the terminal size. This
631 ** function gets called from within the readline sinwinch handler.
636 int heightDiff
, widthDiff
;
637 extern int screenheight
, screenwidth
; /* in readline */
639 widthDiff
= screenwidth
- termWidth ();
640 heightDiff
= screenheight
- termHeight ();
641 if (heightDiff
|| widthDiff
)
643 TuiLayoutType curLayout
= currentLayout ();
644 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
645 TuiWinInfoPtr firstWin
, secondWin
;
646 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
648 int newHeight
, splitDiff
, cmdSplitDiff
, numWinsDisplayed
= 2;
650 /* turn keypad off while we resize */
651 if (winWithFocus
!= cmdWin
)
652 keypad (cmdWin
->generic
.handle
, FALSE
);
653 tui_update_gdb_sizes ();
654 setTermHeightTo (screenheight
);
655 setTermWidthTo (screenwidth
);
656 if (curLayout
== SRC_DISASSEM_COMMAND
||
657 curLayout
== SRC_DATA_COMMAND
|| curLayout
== DISASSEM_DATA_COMMAND
)
659 splitDiff
= heightDiff
/ numWinsDisplayed
;
660 cmdSplitDiff
= splitDiff
;
661 if (heightDiff
% numWinsDisplayed
)
668 /* now adjust each window */
674 case DISASSEM_COMMAND
:
675 firstWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
676 firstWin
->generic
.width
+= widthDiff
;
677 locator
->width
+= widthDiff
;
678 /* check for invalid heights */
680 newHeight
= firstWin
->generic
.height
;
681 else if ((firstWin
->generic
.height
+ splitDiff
) >=
682 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
683 newHeight
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
684 else if ((firstWin
->generic
.height
+ splitDiff
) <= 0)
685 newHeight
= MIN_WIN_HEIGHT
;
687 newHeight
= firstWin
->generic
.height
+ splitDiff
;
689 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
690 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
691 cmdWin
->generic
.width
+= widthDiff
;
692 newHeight
= screenheight
- cmdWin
->generic
.origin
.y
;
693 _makeInvisibleAndSetNewHeight (cmdWin
, newHeight
);
694 _makeVisibleWithNewHeight (firstWin
);
695 _makeVisibleWithNewHeight (cmdWin
);
696 if (firstWin
->generic
.contentSize
<= 0)
697 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
700 if (curLayout
== SRC_DISASSEM_COMMAND
)
703 firstWin
->generic
.width
+= widthDiff
;
704 secondWin
= disassemWin
;
705 secondWin
->generic
.width
+= widthDiff
;
710 firstWin
->generic
.width
+= widthDiff
;
711 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
712 secondWin
->generic
.width
+= widthDiff
;
714 /* Change the first window's height/width */
715 /* check for invalid heights */
717 newHeight
= firstWin
->generic
.height
;
718 else if ((firstWin
->generic
.height
+
719 secondWin
->generic
.height
+ (splitDiff
* 2)) >=
720 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
721 newHeight
= (screenheight
- MIN_CMD_WIN_HEIGHT
- 1) / 2;
722 else if ((firstWin
->generic
.height
+ splitDiff
) <= 0)
723 newHeight
= MIN_WIN_HEIGHT
;
725 newHeight
= firstWin
->generic
.height
+ splitDiff
;
726 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
728 if (firstWin
== dataWin
&& widthDiff
!= 0)
729 firstWin
->detail
.dataDisplayInfo
.regsColumnCount
=
730 tuiCalculateRegsColumnCount (
731 firstWin
->detail
.dataDisplayInfo
.regsDisplayType
);
732 locator
->width
+= widthDiff
;
734 /* Change the second window's height/width */
735 /* check for invalid heights */
737 newHeight
= secondWin
->generic
.height
;
738 else if ((firstWin
->generic
.height
+
739 secondWin
->generic
.height
+ (splitDiff
* 2)) >=
740 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
742 newHeight
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
744 newHeight
= (newHeight
/ 2) + 1;
748 else if ((secondWin
->generic
.height
+ splitDiff
) <= 0)
749 newHeight
= MIN_WIN_HEIGHT
;
751 newHeight
= secondWin
->generic
.height
+ splitDiff
;
752 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
753 _makeInvisibleAndSetNewHeight (secondWin
, newHeight
);
755 /* Change the command window's height/width */
756 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
757 _makeInvisibleAndSetNewHeight (
758 cmdWin
, cmdWin
->generic
.height
+ cmdSplitDiff
);
759 _makeVisibleWithNewHeight (firstWin
);
760 _makeVisibleWithNewHeight (secondWin
);
761 _makeVisibleWithNewHeight (cmdWin
);
762 if (firstWin
->generic
.contentSize
<= 0)
763 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
764 if (secondWin
->generic
.contentSize
<= 0)
765 tuiEraseSourceContent (secondWin
, EMPTY_SOURCE_PROMPT
);
769 ** Now remove all invisible windows, and their content so that they get
770 ** created again when called for with the new size
772 for (winType
= SRC_WIN
; (winType
< MAX_MAJOR_WINDOWS
); winType
++)
774 if (winType
!= CMD_WIN
&& m_winPtrNotNull (winList
[winType
]) &&
775 !winList
[winType
]->generic
.isVisible
)
777 freeWindow (winList
[winType
]);
778 winList
[winType
] = (TuiWinInfoPtr
) NULL
;
781 tuiSetWinResizedTo (TRUE
);
782 /* turn keypad back on, unless focus is in the command window */
783 if (winWithFocus
!= cmdWin
)
784 keypad (cmdWin
->generic
.handle
, TRUE
);
791 ** tuiSigwinchHandler()
792 ** SIGWINCH signal handler for the tui. This signal handler is
793 ** always called, even when the readline package clears signals
794 ** because it is set as the old_sigwinch() (TUI only)
797 tuiSigwinchHandler (int signal
)
800 ** Say that a resize was done so that the readline can do it
801 ** later when appropriate.
803 tuiSetWinResizedTo (TRUE
);
806 } /* tuiSigwinchHandler */
810 /*************************
811 ** STATIC LOCAL FUNCTIONS
812 **************************/
816 ** _tuiScrollForward_command().
819 _tuiScrollForward_command (char *arg
, int fromTTY
)
822 TuiWinInfoPtr winToScroll
;
824 /* Make sure the curses mode is enabled. */
826 if (arg
== (char *) NULL
)
827 _parseScrollingArgs (arg
, &winToScroll
, (int *) NULL
);
829 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
830 tui_scroll (FORWARD_SCROLL
, winToScroll
, numToScroll
);
835 ** _tuiScrollBackward_command().
838 _tuiScrollBackward_command (char *arg
, int fromTTY
)
841 TuiWinInfoPtr winToScroll
;
843 /* Make sure the curses mode is enabled. */
845 if (arg
== (char *) NULL
)
846 _parseScrollingArgs (arg
, &winToScroll
, (int *) NULL
);
848 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
849 tui_scroll (BACKWARD_SCROLL
, winToScroll
, numToScroll
);
854 ** _tuiScrollLeft_command().
857 _tuiScrollLeft_command (char *arg
, int fromTTY
)
860 TuiWinInfoPtr winToScroll
;
862 /* Make sure the curses mode is enabled. */
864 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
865 tui_scroll (LEFT_SCROLL
, winToScroll
, numToScroll
);
870 ** _tuiScrollRight_command().
873 _tuiScrollRight_command (char *arg
, int fromTTY
)
876 TuiWinInfoPtr winToScroll
;
878 /* Make sure the curses mode is enabled. */
880 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
881 tui_scroll (RIGHT_SCROLL
, winToScroll
, numToScroll
);
887 ** Set focus to the window named by 'arg'
890 _tuiSetFocus (char *arg
, int fromTTY
)
892 if (arg
!= (char *) NULL
)
894 char *bufPtr
= (char *) xstrdup (arg
);
896 TuiWinInfoPtr winInfo
= (TuiWinInfoPtr
) NULL
;
898 for (i
= 0; (i
< strlen (bufPtr
)); i
++)
899 bufPtr
[i
] = toupper (arg
[i
]);
901 if (subset_compare (bufPtr
, "NEXT"))
902 winInfo
= tuiNextWin (tuiWinWithFocus ());
903 else if (subset_compare (bufPtr
, "PREV"))
904 winInfo
= tuiPrevWin (tuiWinWithFocus ());
906 winInfo
= partialWinByName (bufPtr
);
908 if (winInfo
== (TuiWinInfoPtr
) NULL
|| !winInfo
->generic
.isVisible
)
909 warning ("Invalid window specified. \n\
910 The window name specified must be valid and visible.\n");
913 tuiSetWinFocusTo (winInfo
);
914 keypad (cmdWin
->generic
.handle
, (winInfo
!= cmdWin
));
917 if (dataWin
&& dataWin
->generic
.isVisible
)
918 tuiRefreshDataWin ();
920 printf_filtered ("Focus set to %s window.\n",
921 winName ((TuiGenWinInfoPtr
) tuiWinWithFocus ()));
924 warning ("Incorrect Number of Arguments.\n%s", FOCUS_USAGE
);
930 ** _tuiSetFocus_command()
933 _tuiSetFocus_command (char *arg
, int fromTTY
)
935 /* Make sure the curses mode is enabled. */
937 _tuiSetFocus (arg
, fromTTY
);
942 ** _tuiAllWindowsInfo().
945 _tuiAllWindowsInfo (char *arg
, int fromTTY
)
948 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
950 for (type
= SRC_WIN
; (type
< MAX_MAJOR_WINDOWS
); type
++)
951 if (winList
[type
] && winList
[type
]->generic
.isVisible
)
953 if (winWithFocus
== winList
[type
])
954 printf_filtered (" %s\t(%d lines) <has focus>\n",
955 winName (&winList
[type
]->generic
),
956 winList
[type
]->generic
.height
);
958 printf_filtered (" %s\t(%d lines)\n",
959 winName (&winList
[type
]->generic
),
960 winList
[type
]->generic
.height
);
964 } /* _tuiAllWindowsInfo */
968 ** _tuiRefreshAll_command().
971 _tuiRefreshAll_command (char *arg
, int fromTTY
)
973 /* Make sure the curses mode is enabled. */
981 ** _tuiSetWinTabWidth_command().
982 ** Set the height of the specified window.
985 _tuiSetTabWidth_command (char *arg
, int fromTTY
)
987 /* Make sure the curses mode is enabled. */
989 if (arg
!= (char *) NULL
)
995 tuiSetDefaultTabLen (ts
);
997 warning ("Tab widths greater than 0 must be specified.\n");
1001 } /* _tuiSetTabWidth_command */
1005 ** _tuiSetWinHeight().
1006 ** Set the height of the specified window.
1009 _tuiSetWinHeight (char *arg
, int fromTTY
)
1011 /* Make sure the curses mode is enabled. */
1013 if (arg
!= (char *) NULL
)
1015 char *buf
= xstrdup (arg
);
1017 char *wname
= (char *) NULL
;
1019 TuiWinInfoPtr winInfo
;
1022 bufPtr
= strchr (bufPtr
, ' ');
1023 if (bufPtr
!= (char *) NULL
)
1028 ** Validate the window name
1030 for (i
= 0; i
< strlen (wname
); i
++)
1031 wname
[i
] = toupper (wname
[i
]);
1032 winInfo
= partialWinByName (wname
);
1034 if (winInfo
== (TuiWinInfoPtr
) NULL
|| !winInfo
->generic
.isVisible
)
1035 warning ("Invalid window specified. \n\
1036 The window name specified must be valid and visible.\n");
1039 /* Process the size */
1040 while (*(++bufPtr
) == ' ')
1043 if (*bufPtr
!= (char) 0)
1046 int fixedSize
= TRUE
;
1049 if (*bufPtr
== '+' || *bufPtr
== '-')
1056 inputNo
= atoi (bufPtr
);
1062 newHeight
= inputNo
;
1064 newHeight
= winInfo
->generic
.height
+ inputNo
;
1066 ** Now change the window's height, and adjust all
1067 ** other windows around it
1069 if (_tuiAdjustWinHeights (winInfo
,
1070 newHeight
) == TUI_FAILURE
)
1071 warning ("Invalid window height specified.\n%s",
1074 tui_update_gdb_sizes ();
1077 warning ("Invalid window height specified.\n%s",
1083 printf_filtered (WIN_HEIGHT_USAGE
);
1085 if (buf
!= (char *) NULL
)
1089 printf_filtered (WIN_HEIGHT_USAGE
);
1092 } /* _tuiSetWinHeight */
1095 ** _tuiSetWinHeight_command().
1096 ** Set the height of the specified window, with va_list.
1099 _tuiSetWinHeight_command (char *arg
, int fromTTY
)
1101 /* Make sure the curses mode is enabled. */
1103 _tuiSetWinHeight (arg
, fromTTY
);
1108 ** _tuiXDBsetWinHeight().
1109 ** XDB Compatibility command for setting the window height. This will
1110 ** increase or decrease the command window by the specified amount.
1113 _tuiXDBsetWinHeight (char *arg
, int fromTTY
)
1115 /* Make sure the curses mode is enabled. */
1117 if (arg
!= (char *) NULL
)
1119 int inputNo
= atoi (arg
);
1122 { /* Add 1 for the locator */
1123 int newHeight
= termHeight () - (inputNo
+ 1);
1125 if (!_newHeightOk (winList
[CMD_WIN
], newHeight
) ||
1126 _tuiAdjustWinHeights (winList
[CMD_WIN
],
1127 newHeight
) == TUI_FAILURE
)
1128 warning ("Invalid window height specified.\n%s",
1129 XDBWIN_HEIGHT_USAGE
);
1132 warning ("Invalid window height specified.\n%s",
1133 XDBWIN_HEIGHT_USAGE
);
1136 warning ("Invalid window height specified.\n%s", XDBWIN_HEIGHT_USAGE
);
1139 } /* _tuiXDBsetWinHeight */
1142 ** _tuiSetWinHeight_command().
1143 ** Set the height of the specified window, with va_list.
1146 _tuiXDBsetWinHeight_command (char *arg
, int fromTTY
)
1148 _tuiXDBsetWinHeight (arg
, fromTTY
);
1153 ** _tuiAdjustWinHeights().
1154 ** Function to adjust all window heights around the primary
1157 _tuiAdjustWinHeights (TuiWinInfoPtr primaryWinInfo
, int newHeight
)
1159 TuiStatus status
= TUI_FAILURE
;
1161 if (_newHeightOk (primaryWinInfo
, newHeight
))
1163 status
= TUI_SUCCESS
;
1164 if (newHeight
!= primaryWinInfo
->generic
.height
)
1167 TuiWinInfoPtr winInfo
;
1168 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
1169 TuiLayoutType curLayout
= currentLayout ();
1171 diff
= (newHeight
- primaryWinInfo
->generic
.height
) * (-1);
1172 if (curLayout
== SRC_COMMAND
|| curLayout
== DISASSEM_COMMAND
)
1174 TuiWinInfoPtr srcWinInfo
;
1176 _makeInvisibleAndSetNewHeight (primaryWinInfo
, newHeight
);
1177 if (primaryWinInfo
->generic
.type
== CMD_WIN
)
1179 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1180 srcWinInfo
= winInfo
;
1184 winInfo
= winList
[CMD_WIN
];
1185 srcWinInfo
= primaryWinInfo
;
1187 _makeInvisibleAndSetNewHeight (winInfo
,
1188 winInfo
->generic
.height
+ diff
);
1189 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1190 _makeVisibleWithNewHeight (winInfo
);
1191 _makeVisibleWithNewHeight (primaryWinInfo
);
1192 if (srcWinInfo
->generic
.contentSize
<= 0)
1193 tuiEraseSourceContent (srcWinInfo
, EMPTY_SOURCE_PROMPT
);
1197 TuiWinInfoPtr firstWin
, secondWin
;
1199 if (curLayout
== SRC_DISASSEM_COMMAND
)
1202 secondWin
= disassemWin
;
1207 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1209 if (primaryWinInfo
== cmdWin
)
1211 ** Split the change in height accross the 1st & 2nd windows
1212 ** adjusting them as well.
1214 int firstSplitDiff
= diff
/ 2; /* subtract the locator */
1215 int secondSplitDiff
= firstSplitDiff
;
1219 if (firstWin
->generic
.height
>
1220 secondWin
->generic
.height
)
1233 /* make sure that the minimum hieghts are honored */
1234 while ((firstWin
->generic
.height
+ firstSplitDiff
) < 3)
1239 while ((secondWin
->generic
.height
+ secondSplitDiff
) < 3)
1244 _makeInvisibleAndSetNewHeight (
1246 firstWin
->generic
.height
+ firstSplitDiff
);
1247 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
1248 _makeInvisibleAndSetNewHeight (
1249 secondWin
, secondWin
->generic
.height
+ secondSplitDiff
);
1250 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1251 _makeInvisibleAndSetNewHeight (cmdWin
, newHeight
);
1255 if ((cmdWin
->generic
.height
+ diff
) < 1)
1257 ** If there is no way to increase the command window
1258 ** take real estate from the 1st or 2nd window.
1260 if ((cmdWin
->generic
.height
+ diff
) < 1)
1263 for (i
= cmdWin
->generic
.height
+ diff
;
1265 if (primaryWinInfo
== firstWin
)
1266 secondWin
->generic
.height
--;
1268 firstWin
->generic
.height
--;
1271 if (primaryWinInfo
== firstWin
)
1272 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
1274 _makeInvisibleAndSetNewHeight (
1276 firstWin
->generic
.height
);
1277 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
1278 if (primaryWinInfo
== secondWin
)
1279 _makeInvisibleAndSetNewHeight (secondWin
, newHeight
);
1281 _makeInvisibleAndSetNewHeight (
1282 secondWin
, secondWin
->generic
.height
);
1283 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1284 if ((cmdWin
->generic
.height
+ diff
) < 1)
1285 _makeInvisibleAndSetNewHeight (cmdWin
, 1);
1287 _makeInvisibleAndSetNewHeight (
1288 cmdWin
, cmdWin
->generic
.height
+ diff
);
1290 _makeVisibleWithNewHeight (cmdWin
);
1291 _makeVisibleWithNewHeight (secondWin
);
1292 _makeVisibleWithNewHeight (firstWin
);
1293 if (firstWin
->generic
.contentSize
<= 0)
1294 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
1295 if (secondWin
->generic
.contentSize
<= 0)
1296 tuiEraseSourceContent (secondWin
, EMPTY_SOURCE_PROMPT
);
1302 } /* _tuiAdjustWinHeights */
1306 ** _makeInvisibleAndSetNewHeight().
1307 ** Function make the target window (and auxillary windows associated
1308 ** with the targer) invisible, and set the new height and location.
1311 _makeInvisibleAndSetNewHeight (TuiWinInfoPtr winInfo
, int height
)
1314 TuiGenWinInfoPtr genWinInfo
;
1317 m_beInvisible (&winInfo
->generic
);
1318 winInfo
->generic
.height
= height
;
1320 winInfo
->generic
.viewportHeight
= height
- 1;
1322 winInfo
->generic
.viewportHeight
= height
;
1323 if (winInfo
!= cmdWin
)
1324 winInfo
->generic
.viewportHeight
--;
1326 /* Now deal with the auxillary windows associated with winInfo */
1327 switch (winInfo
->generic
.type
)
1331 genWinInfo
= winInfo
->detail
.sourceInfo
.executionInfo
;
1332 m_beInvisible (genWinInfo
);
1333 genWinInfo
->height
= height
;
1334 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
;
1336 genWinInfo
->viewportHeight
= height
- 1;
1338 genWinInfo
->viewportHeight
= height
;
1339 if (winInfo
!= cmdWin
)
1340 genWinInfo
->viewportHeight
--;
1342 if (m_hasLocator (winInfo
))
1344 genWinInfo
= locatorWinInfoPtr ();
1345 m_beInvisible (genWinInfo
);
1346 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
+ height
;
1350 /* delete all data item windows */
1351 for (i
= 0; i
< winInfo
->generic
.contentSize
; i
++)
1353 genWinInfo
= (TuiGenWinInfoPtr
) & ((TuiWinElementPtr
)
1354 winInfo
->generic
.content
[i
])->whichElement
.dataWindow
;
1355 tuiDelwin (genWinInfo
->handle
);
1356 genWinInfo
->handle
= (WINDOW
*) NULL
;
1366 ** _makeVisibleWithNewHeight().
1367 ** Function to make the windows with new heights visible.
1368 ** This means re-creating the windows' content since the window
1369 ** had to be destroyed to be made invisible.
1372 _makeVisibleWithNewHeight (TuiWinInfoPtr winInfo
)
1376 m_beVisible (&winInfo
->generic
);
1377 checkAndDisplayHighlightIfNeeded (winInfo
);
1378 switch (winInfo
->generic
.type
)
1382 freeWinContent (winInfo
->detail
.sourceInfo
.executionInfo
);
1383 m_beVisible (winInfo
->detail
.sourceInfo
.executionInfo
);
1384 if (winInfo
->generic
.content
!= (OpaquePtr
) NULL
)
1386 TuiLineOrAddress lineOrAddr
;
1387 struct symtab_and_line cursal
1388 = get_current_source_symtab_and_line ();
1390 if (winInfo
->generic
.type
== SRC_WIN
)
1392 winInfo
->detail
.sourceInfo
.startLineOrAddr
.lineNo
;
1395 winInfo
->detail
.sourceInfo
.startLineOrAddr
.addr
;
1396 freeWinContent (&winInfo
->generic
);
1397 tuiUpdateSourceWindow (winInfo
,
1398 cursal
.symtab
, lineOrAddr
, TRUE
);
1400 else if (deprecated_selected_frame
!= (struct frame_info
*) NULL
)
1402 TuiLineOrAddress line
;
1403 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
1406 s
= find_pc_symtab (deprecated_selected_frame
->pc
);
1407 if (winInfo
->generic
.type
== SRC_WIN
)
1408 line
.lineNo
= cursal
.line
;
1411 find_line_pc (s
, cursal
.line
, &line
.addr
);
1413 tuiUpdateSourceWindow (winInfo
, s
, line
, TRUE
);
1415 if (m_hasLocator (winInfo
))
1417 m_beVisible (locatorWinInfoPtr ());
1418 tuiShowLocatorContent ();
1422 tuiDisplayAllData ();
1425 winInfo
->detail
.commandInfo
.curLine
= 0;
1426 winInfo
->detail
.commandInfo
.curch
= 0;
1427 wmove (winInfo
->generic
.handle
,
1428 winInfo
->detail
.commandInfo
.curLine
,
1429 winInfo
->detail
.commandInfo
.curch
);
1436 } /* _makeVisibleWithNewHeight */
1440 _newHeightOk (TuiWinInfoPtr primaryWinInfo
, int newHeight
)
1442 int ok
= (newHeight
< termHeight ());
1447 TuiLayoutType curLayout
= currentLayout ();
1449 diff
= (newHeight
- primaryWinInfo
->generic
.height
) * (-1);
1450 if (curLayout
== SRC_COMMAND
|| curLayout
== DISASSEM_COMMAND
)
1452 ok
= ((primaryWinInfo
->generic
.type
== CMD_WIN
&&
1453 newHeight
<= (termHeight () - 4) &&
1454 newHeight
>= MIN_CMD_WIN_HEIGHT
) ||
1455 (primaryWinInfo
->generic
.type
!= CMD_WIN
&&
1456 newHeight
<= (termHeight () - 2) &&
1457 newHeight
>= MIN_WIN_HEIGHT
));
1459 { /* check the total height */
1460 TuiWinInfoPtr winInfo
;
1462 if (primaryWinInfo
== cmdWin
)
1463 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1467 (winInfo
->generic
.height
+ diff
)) <= termHeight ());
1472 int curTotalHeight
, totalHeight
, minHeight
= 0;
1473 TuiWinInfoPtr firstWin
, secondWin
;
1475 if (curLayout
== SRC_DISASSEM_COMMAND
)
1478 secondWin
= disassemWin
;
1483 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1486 ** We could simply add all the heights to obtain the same result
1487 ** but below is more explicit since we subtract 1 for the
1488 ** line that the first and second windows share, and add one
1491 totalHeight
= curTotalHeight
=
1492 (firstWin
->generic
.height
+ secondWin
->generic
.height
- 1)
1493 + cmdWin
->generic
.height
+ 1 /*locator */ ;
1494 if (primaryWinInfo
== cmdWin
)
1496 /* locator included since first & second win share a line */
1497 ok
= ((firstWin
->generic
.height
+
1498 secondWin
->generic
.height
+ diff
) >=
1499 (MIN_WIN_HEIGHT
* 2) &&
1500 newHeight
>= MIN_CMD_WIN_HEIGHT
);
1503 totalHeight
= newHeight
+ (firstWin
->generic
.height
+
1504 secondWin
->generic
.height
+ diff
);
1505 minHeight
= MIN_CMD_WIN_HEIGHT
;
1510 minHeight
= MIN_WIN_HEIGHT
;
1512 ** First see if we can increase/decrease the command
1513 ** window. And make sure that the command window is
1516 ok
= ((cmdWin
->generic
.height
+ diff
) > 0);
1519 ** Looks like we have to increase/decrease one of
1520 ** the other windows
1522 if (primaryWinInfo
== firstWin
)
1523 ok
= (secondWin
->generic
.height
+ diff
) >= minHeight
;
1525 ok
= (firstWin
->generic
.height
+ diff
) >= minHeight
;
1529 if (primaryWinInfo
== firstWin
)
1530 totalHeight
= newHeight
+
1531 secondWin
->generic
.height
+
1532 cmdWin
->generic
.height
+ diff
;
1534 totalHeight
= newHeight
+
1535 firstWin
->generic
.height
+
1536 cmdWin
->generic
.height
+ diff
;
1540 ** Now make sure that the proposed total height doesn't exceed
1541 ** the old total height.
1544 ok
= (newHeight
>= minHeight
&& totalHeight
<= curTotalHeight
);
1549 } /* _newHeightOk */
1553 ** _parseScrollingArgs().
1556 _parseScrollingArgs (char *arg
, TuiWinInfoPtr
* winToScroll
, int *numToScroll
)
1560 *winToScroll
= tuiWinWithFocus ();
1563 ** First set up the default window to scroll, in case there is no
1566 if (arg
!= (char *) NULL
)
1570 /* process the number of lines to scroll */
1571 buf
= bufPtr
= xstrdup (arg
);
1572 if (isdigit (*bufPtr
))
1577 bufPtr
= strchr (bufPtr
, ' ');
1578 if (bufPtr
!= (char *) NULL
)
1582 *numToScroll
= atoi (numStr
);
1585 else if (numToScroll
)
1586 *numToScroll
= atoi (numStr
);
1589 /* process the window name if one is specified */
1590 if (bufPtr
!= (char *) NULL
)
1596 while (*(++bufPtr
) == ' ')
1599 if (*bufPtr
!= (char) 0)
1604 /* Validate the window name */
1605 for (i
= 0; i
< strlen (wname
); i
++)
1606 wname
[i
] = toupper (wname
[i
]);
1607 *winToScroll
= partialWinByName (wname
);
1609 if (*winToScroll
== (TuiWinInfoPtr
) NULL
||
1610 !(*winToScroll
)->generic
.isVisible
)
1611 warning ("Invalid window specified. \n\
1612 The window name specified must be valid and visible.\n");
1613 else if (*winToScroll
== cmdWin
)
1614 *winToScroll
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1620 } /* _parseScrollingArgs */