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"
58 #include "tuiGeneralWin.h"
61 #include "tuiDisassem.h"
62 #include "tuiSource.h"
63 #include "tuiSourceWin.h"
64 #include "tuiDataWin.h"
66 /*******************************
67 ** External Declarations
68 ********************************/
69 extern void init_page_info ();
71 /*******************************
73 ********************************/
74 static void _makeVisibleWithNewHeight (TuiWinInfoPtr
);
75 static void _makeInvisibleAndSetNewHeight (TuiWinInfoPtr
, int);
76 static TuiStatus
_tuiAdjustWinHeights (TuiWinInfoPtr
, int);
77 static int _newHeightOk (TuiWinInfoPtr
, int);
78 static void _tuiSetTabWidth_command (char *, int);
79 static void _tuiRefreshAll_command (char *, int);
80 static void _tuiSetWinHeight_command (char *, int);
81 static void _tuiXDBsetWinHeight_command (char *, int);
82 static void _tuiAllWindowsInfo (char *, int);
83 static void _tuiSetFocus_command (char *, int);
84 static void _tuiScrollForward_command (char *, int);
85 static void _tuiScrollBackward_command (char *, int);
86 static void _tuiScrollLeft_command (char *, int);
87 static void _tuiScrollRight_command (char *, int);
88 static void _parseScrollingArgs (char *, TuiWinInfoPtr
*, int *);
91 /***************************************
93 ***************************************/
94 #define WIN_HEIGHT_USAGE "Usage: winheight <win_name> [+ | -] <#lines>\n"
95 #define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n"
96 #define FOCUS_USAGE "Usage: focus {<win> | next | prev}\n"
98 /***************************************
100 ***************************************/
102 /* Possible values for tui-border-kind variable. */
103 static const char *tui_border_kind_enums
[] = {
110 /* Possible values for tui-border-mode and tui-active-border-mode. */
111 static const char *tui_border_mode_enums
[] = {
128 /* Translation table for border-mode variables.
129 The list of values must be terminated by a NULL.
130 After the NULL value, an entry defines the default. */
131 struct tui_translate tui_border_mode_translate
[] = {
132 { "normal", A_NORMAL
},
133 { "standout", A_STANDOUT
},
134 { "reverse", A_REVERSE
},
136 { "half-standout", A_DIM
| A_STANDOUT
},
138 { "bold-standout", A_BOLD
| A_STANDOUT
},
140 { "normal", A_NORMAL
}
143 /* Translation tables for border-kind, one for each border
144 character (see wborder, border curses operations).
145 -1 is used to indicate the ACS because ACS characters
146 are determined at run time by curses (depends on terminal). */
147 struct tui_translate tui_border_kind_translate_vline
[] = {
155 struct tui_translate tui_border_kind_translate_hline
[] = {
163 struct tui_translate tui_border_kind_translate_ulcorner
[] = {
171 struct tui_translate tui_border_kind_translate_urcorner
[] = {
179 struct tui_translate tui_border_kind_translate_llcorner
[] = {
187 struct tui_translate tui_border_kind_translate_lrcorner
[] = {
196 /* Tui configuration variables controlled with set/show command. */
197 const char *tui_active_border_mode
= "bold-standout";
198 const char *tui_border_mode
= "normal";
199 const char *tui_border_kind
= "acs";
201 /* Tui internal configuration variables. These variables are
202 updated by tui_update_variables to reflect the tui configuration
204 chtype tui_border_vline
;
205 chtype tui_border_hline
;
206 chtype tui_border_ulcorner
;
207 chtype tui_border_urcorner
;
208 chtype tui_border_llcorner
;
209 chtype tui_border_lrcorner
;
211 int tui_border_attrs
;
212 int tui_active_border_attrs
;
214 /* Identify the item in the translation table.
215 When the item is not recognized, use the default entry. */
216 static struct tui_translate
*
217 translate (const char *name
, struct tui_translate
*table
)
221 if (name
&& strcmp (table
->name
, name
) == 0)
226 /* Not found, return default entry. */
231 /* Update the tui internal configuration according to gdb settings.
232 Returns 1 if the configuration has changed and the screen should
235 tui_update_variables ()
238 struct tui_translate
*entry
;
240 entry
= translate (tui_border_mode
, tui_border_mode_translate
);
241 if (tui_border_attrs
!= entry
->value
)
243 tui_border_attrs
= entry
->value
;
246 entry
= translate (tui_active_border_mode
, tui_border_mode_translate
);
247 if (tui_active_border_attrs
!= entry
->value
)
249 tui_active_border_attrs
= entry
->value
;
253 /* If one corner changes, all characters are changed.
254 Only check the first one. The ACS characters are determined at
255 run time by curses terminal management. */
256 entry
= translate (tui_border_kind
, tui_border_kind_translate_lrcorner
);
257 if (tui_border_lrcorner
!= (chtype
) entry
->value
)
259 tui_border_lrcorner
= (entry
->value
< 0) ? ACS_LRCORNER
: entry
->value
;
262 entry
= translate (tui_border_kind
, tui_border_kind_translate_llcorner
);
263 tui_border_llcorner
= (entry
->value
< 0) ? ACS_LLCORNER
: entry
->value
;
265 entry
= translate (tui_border_kind
, tui_border_kind_translate_ulcorner
);
266 tui_border_ulcorner
= (entry
->value
< 0) ? ACS_ULCORNER
: entry
->value
;
268 entry
= translate (tui_border_kind
, tui_border_kind_translate_urcorner
);
269 tui_border_urcorner
= (entry
->value
< 0) ? ACS_URCORNER
: entry
->value
;
271 entry
= translate (tui_border_kind
, tui_border_kind_translate_hline
);
272 tui_border_hline
= (entry
->value
< 0) ? ACS_HLINE
: entry
->value
;
274 entry
= translate (tui_border_kind
, tui_border_kind_translate_vline
);
275 tui_border_vline
= (entry
->value
< 0) ? ACS_VLINE
: entry
->value
;
281 set_tui_cmd (char *args
, int from_tty
)
286 show_tui_cmd (char *args
, int from_tty
)
291 ** _initialize_tuiWin().
292 ** Function to initialize gdb commands, for tui window manipulation.
295 _initialize_tuiWin (void)
297 struct cmd_list_element
*c
;
298 static struct cmd_list_element
*tui_setlist
;
299 static struct cmd_list_element
*tui_showlist
;
301 /* Define the classes of commands.
302 They will appear in the help list in the reverse of this order. */
303 add_cmd ("tui", class_tui
, NULL
,
304 "Text User Interface commands.",
307 add_prefix_cmd ("tui", class_tui
, set_tui_cmd
,
308 "TUI configuration variables",
309 &tui_setlist
, "set tui ",
310 0/*allow-unknown*/, &setlist
);
311 add_prefix_cmd ("tui", class_tui
, show_tui_cmd
,
312 "TUI configuration variables",
313 &tui_showlist
, "show tui ",
314 0/*allow-unknown*/, &showlist
);
316 add_com ("refresh", class_tui
, _tuiRefreshAll_command
,
317 "Refresh the terminal display.\n");
319 add_com_alias ("U", "refresh", class_tui
, 0);
320 add_com ("tabset", class_tui
, _tuiSetTabWidth_command
,
321 "Set the width (in characters) of tab stops.\n\
322 Usage: tabset <n>\n");
323 add_com ("winheight", class_tui
, _tuiSetWinHeight_command
,
324 "Set the height of a specified window.\n\
325 Usage: winheight <win_name> [+ | -] <#lines>\n\
327 src : the source window\n\
328 cmd : the command window\n\
329 asm : the disassembly window\n\
330 regs : the register display\n");
331 add_com_alias ("wh", "winheight", class_tui
, 0);
332 add_info ("win", _tuiAllWindowsInfo
,
333 "List of all displayed windows.\n");
334 add_com ("focus", class_tui
, _tuiSetFocus_command
,
335 "Set focus to named window or next/prev window.\n\
336 Usage: focus {<win> | next | prev}\n\
337 Valid Window names are:\n\
338 src : the source window\n\
339 asm : the disassembly window\n\
340 regs : the register display\n\
341 cmd : the command window\n");
342 add_com_alias ("fs", "focus", class_tui
, 0);
343 add_com ("+", class_tui
, _tuiScrollForward_command
,
344 "Scroll window forward.\nUsage: + [win] [n]\n");
345 add_com ("-", class_tui
, _tuiScrollBackward_command
,
346 "Scroll window backward.\nUsage: - [win] [n]\n");
347 add_com ("<", class_tui
, _tuiScrollLeft_command
,
348 "Scroll window forward.\nUsage: < [win] [n]\n");
349 add_com (">", class_tui
, _tuiScrollRight_command
,
350 "Scroll window backward.\nUsage: > [win] [n]\n");
352 add_com ("w", class_xdb
, _tuiXDBsetWinHeight_command
,
353 "XDB compatibility command for setting the height of a command window.\n\
354 Usage: w <#lines>\n");
356 /* Define the tui control variables. */
358 ("border-kind", no_class
,
359 tui_border_kind_enums
, &tui_border_kind
,
360 "Set the kind of border for TUI windows.\n"
361 "This variable controls the border of TUI windows:\n"
362 "space use a white space\n"
363 "ascii use ascii characters + - | for the border\n"
364 "acs use the Alternate Character Set\n",
366 add_show_from_set (c
, &tui_showlist
);
369 ("border-mode", no_class
,
370 tui_border_mode_enums
, &tui_border_mode
,
371 "Set the attribute mode to use for the TUI window borders.\n"
372 "This variable controls the attributes to use for the window borders:\n"
373 "normal normal display\n"
374 "standout use highlight mode of terminal\n"
375 "reverse use reverse video mode\n"
376 "half use half bright\n"
377 "half-standout use half bright and standout mode\n"
378 "bold use extra bright or bold\n"
379 "bold-standout use extra bright or bold with standout mode\n",
381 add_show_from_set (c
, &tui_showlist
);
384 ("active-border-mode", no_class
,
385 tui_border_mode_enums
, &tui_active_border_mode
,
386 "Set the attribute mode to use for the active TUI window border.\n"
387 "This variable controls the attributes to use for the active window border:\n"
388 "normal normal display\n"
389 "standout use highlight mode of terminal\n"
390 "reverse use reverse video mode\n"
391 "half use half bright\n"
392 "half-standout use half bright and standout mode\n"
393 "bold use extra bright or bold\n"
394 "bold-standout use extra bright or bold with standout mode\n",
396 add_show_from_set (c
, &tui_showlist
);
402 ** Set the logical focus to winInfo
405 tuiSetWinFocusTo (TuiWinInfoPtr winInfo
)
407 if (m_winPtrNotNull (winInfo
))
409 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
411 if (m_winPtrNotNull (winWithFocus
) &&
412 winWithFocus
->generic
.type
!= CMD_WIN
)
413 unhighlightWin (winWithFocus
);
414 tuiSetWinWithFocus (winInfo
);
415 if (winInfo
->generic
.type
!= CMD_WIN
)
416 highlightWin (winInfo
);
420 } /* tuiSetWinFocusTo */
424 ** tuiScrollForward().
427 tuiScrollForward (TuiWinInfoPtr winToScroll
, int numToScroll
)
429 if (winToScroll
!= cmdWin
)
431 int _numToScroll
= numToScroll
;
433 if (numToScroll
== 0)
434 _numToScroll
= winToScroll
->generic
.height
- 3;
436 ** If we are scrolling the source or disassembly window, do a
437 ** "psuedo" scroll since not all of the source is in memory,
438 ** only what is in the viewport. If winToScroll is the
439 ** command window do nothing since the term should handle it.
441 if (winToScroll
== srcWin
)
442 tuiVerticalSourceScroll (FORWARD_SCROLL
, _numToScroll
);
443 else if (winToScroll
== disassemWin
)
444 tuiVerticalDisassemScroll (FORWARD_SCROLL
, _numToScroll
);
445 else if (winToScroll
== dataWin
)
446 tuiVerticalDataScroll (FORWARD_SCROLL
, _numToScroll
);
450 } /* tuiScrollForward */
454 ** tuiScrollBackward().
457 tuiScrollBackward (TuiWinInfoPtr winToScroll
, int numToScroll
)
459 if (winToScroll
!= cmdWin
)
461 int _numToScroll
= numToScroll
;
463 if (numToScroll
== 0)
464 _numToScroll
= winToScroll
->generic
.height
- 3;
466 ** If we are scrolling the source or disassembly window, do a
467 ** "psuedo" scroll since not all of the source is in memory,
468 ** only what is in the viewport. If winToScroll is the
469 ** command window do nothing since the term should handle it.
471 if (winToScroll
== srcWin
)
472 tuiVerticalSourceScroll (BACKWARD_SCROLL
, _numToScroll
);
473 else if (winToScroll
== disassemWin
)
474 tuiVerticalDisassemScroll (BACKWARD_SCROLL
, _numToScroll
);
475 else if (winToScroll
== dataWin
)
476 tuiVerticalDataScroll (BACKWARD_SCROLL
, _numToScroll
);
479 } /* tuiScrollBackward */
486 tuiScrollLeft (TuiWinInfoPtr winToScroll
, int numToScroll
)
488 if (winToScroll
!= cmdWin
)
490 int _numToScroll
= numToScroll
;
492 if (_numToScroll
== 0)
495 ** If we are scrolling the source or disassembly window, do a
496 ** "psuedo" scroll since not all of the source is in memory,
497 ** only what is in the viewport. If winToScroll is the
498 ** command window do nothing since the term should handle it.
500 if (winToScroll
== srcWin
|| winToScroll
== disassemWin
)
501 tuiHorizontalSourceScroll (winToScroll
, LEFT_SCROLL
, _numToScroll
);
504 } /* tuiScrollLeft */
511 tuiScrollRight (TuiWinInfoPtr winToScroll
, int numToScroll
)
513 if (winToScroll
!= cmdWin
)
515 int _numToScroll
= numToScroll
;
517 if (_numToScroll
== 0)
520 ** If we are scrolling the source or disassembly window, do a
521 ** "psuedo" scroll since not all of the source is in memory,
522 ** only what is in the viewport. If winToScroll is the
523 ** command window do nothing since the term should handle it.
525 if (winToScroll
== srcWin
|| winToScroll
== disassemWin
)
526 tuiHorizontalSourceScroll (winToScroll
, RIGHT_SCROLL
, _numToScroll
);
529 } /* tuiScrollRight */
534 ** Scroll a window. Arguments are passed through a va_list.
537 tui_scroll (TuiScrollDirection direction
,
538 TuiWinInfoPtr winToScroll
,
544 tuiScrollForward (winToScroll
, numToScroll
);
546 case BACKWARD_SCROLL
:
547 tuiScrollBackward (winToScroll
, numToScroll
);
550 tuiScrollLeft (winToScroll
, numToScroll
);
553 tuiScrollRight (winToScroll
, numToScroll
);
569 clearok (curscr
, TRUE
);
570 refreshAll (winList
);
571 for (type
= SRC_WIN
; type
< MAX_MAJOR_WINDOWS
; type
++)
573 if (winList
[type
] && winList
[type
]->generic
.isVisible
)
579 tuiShowSourceContent (winList
[type
]);
580 checkAndDisplayHighlightIfNeeded (winList
[type
]);
581 tuiEraseExecInfoContent (winList
[type
]);
582 tuiUpdateExecInfo (winList
[type
]);
585 tuiRefreshDataWin ();
592 tuiShowLocatorContent ();
598 ** Resize all the windows based on the the terminal size. This
599 ** function gets called from within the readline sinwinch handler.
604 int heightDiff
, widthDiff
;
605 extern int screenheight
, screenwidth
; /* in readline */
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
);
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 tuiEraseSourceContent (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 tuiCalculateRegsColumnCount (
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 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
732 if (secondWin
->generic
.contentSize
<= 0)
733 tuiEraseSourceContent (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 tuiSetWinFocusTo (winInfo
);
882 keypad (cmdWin
->generic
.handle
, (winInfo
!= cmdWin
));
885 if (dataWin
&& dataWin
->generic
.isVisible
)
886 tuiRefreshDataWin ();
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
]->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. */
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",
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 tuiEraseSourceContent (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 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
1263 if (secondWin
->generic
.contentSize
<= 0)
1264 tuiEraseSourceContent (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
;
1285 m_beInvisible (&winInfo
->generic
);
1286 winInfo
->generic
.height
= height
;
1288 winInfo
->generic
.viewportHeight
= height
- 1;
1290 winInfo
->generic
.viewportHeight
= height
;
1291 if (winInfo
!= cmdWin
)
1292 winInfo
->generic
.viewportHeight
--;
1294 /* Now deal with the auxillary windows associated with winInfo */
1295 switch (winInfo
->generic
.type
)
1299 genWinInfo
= winInfo
->detail
.sourceInfo
.executionInfo
;
1300 m_beInvisible (genWinInfo
);
1301 genWinInfo
->height
= height
;
1302 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
;
1304 genWinInfo
->viewportHeight
= height
- 1;
1306 genWinInfo
->viewportHeight
= height
;
1307 if (winInfo
!= cmdWin
)
1308 genWinInfo
->viewportHeight
--;
1310 if (m_hasLocator (winInfo
))
1312 genWinInfo
= locatorWinInfoPtr ();
1313 m_beInvisible (genWinInfo
);
1314 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
+ height
;
1318 /* delete all data item windows */
1319 for (i
= 0; i
< winInfo
->generic
.contentSize
; i
++)
1321 genWinInfo
= (TuiGenWinInfoPtr
) & ((TuiWinElementPtr
)
1322 winInfo
->generic
.content
[i
])->whichElement
.dataWindow
;
1323 tuiDelwin (genWinInfo
->handle
);
1324 genWinInfo
->handle
= (WINDOW
*) NULL
;
1334 ** _makeVisibleWithNewHeight().
1335 ** Function to make the windows with new heights visible.
1336 ** This means re-creating the windows' content since the window
1337 ** had to be destroyed to be made invisible.
1340 _makeVisibleWithNewHeight (TuiWinInfoPtr winInfo
)
1344 m_beVisible (&winInfo
->generic
);
1345 checkAndDisplayHighlightIfNeeded (winInfo
);
1346 switch (winInfo
->generic
.type
)
1350 freeWinContent (winInfo
->detail
.sourceInfo
.executionInfo
);
1351 m_beVisible (winInfo
->detail
.sourceInfo
.executionInfo
);
1352 if (winInfo
->generic
.content
!= (OpaquePtr
) NULL
)
1354 TuiLineOrAddress lineOrAddr
;
1356 if (winInfo
->generic
.type
== SRC_WIN
)
1358 winInfo
->detail
.sourceInfo
.startLineOrAddr
.lineNo
;
1361 winInfo
->detail
.sourceInfo
.startLineOrAddr
.addr
;
1362 freeWinContent (&winInfo
->generic
);
1363 tuiUpdateSourceWindow (winInfo
,
1364 current_source_symtab
, lineOrAddr
, TRUE
);
1366 else if (selected_frame
!= (struct frame_info
*) NULL
)
1368 TuiLineOrAddress line
;
1369 extern int current_source_line
;
1371 s
= find_pc_symtab (selected_frame
->pc
);
1372 if (winInfo
->generic
.type
== SRC_WIN
)
1373 line
.lineNo
= current_source_line
;
1376 find_line_pc (s
, current_source_line
, &line
.addr
);
1378 tuiUpdateSourceWindow (winInfo
, s
, line
, TRUE
);
1380 if (m_hasLocator (winInfo
))
1382 m_beVisible (locatorWinInfoPtr ());
1383 tuiShowLocatorContent ();
1387 tuiDisplayAllData ();
1390 winInfo
->detail
.commandInfo
.curLine
= 0;
1391 winInfo
->detail
.commandInfo
.curch
= 0;
1392 wmove (winInfo
->generic
.handle
,
1393 winInfo
->detail
.commandInfo
.curLine
,
1394 winInfo
->detail
.commandInfo
.curch
);
1401 } /* _makeVisibleWithNewHeight */
1405 _newHeightOk (TuiWinInfoPtr primaryWinInfo
, int newHeight
)
1407 int ok
= (newHeight
< termHeight ());
1412 TuiLayoutType curLayout
= currentLayout ();
1414 diff
= (newHeight
- primaryWinInfo
->generic
.height
) * (-1);
1415 if (curLayout
== SRC_COMMAND
|| curLayout
== DISASSEM_COMMAND
)
1417 ok
= ((primaryWinInfo
->generic
.type
== CMD_WIN
&&
1418 newHeight
<= (termHeight () - 4) &&
1419 newHeight
>= MIN_CMD_WIN_HEIGHT
) ||
1420 (primaryWinInfo
->generic
.type
!= CMD_WIN
&&
1421 newHeight
<= (termHeight () - 2) &&
1422 newHeight
>= MIN_WIN_HEIGHT
));
1424 { /* check the total height */
1425 TuiWinInfoPtr winInfo
;
1427 if (primaryWinInfo
== cmdWin
)
1428 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1432 (winInfo
->generic
.height
+ diff
)) <= termHeight ());
1437 int curTotalHeight
, totalHeight
, minHeight
;
1438 TuiWinInfoPtr firstWin
, secondWin
;
1440 if (curLayout
== SRC_DISASSEM_COMMAND
)
1443 secondWin
= disassemWin
;
1448 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1451 ** We could simply add all the heights to obtain the same result
1452 ** but below is more explicit since we subtract 1 for the
1453 ** line that the first and second windows share, and add one
1457 (firstWin
->generic
.height
+ secondWin
->generic
.height
- 1)
1458 + cmdWin
->generic
.height
+ 1 /*locator */ ;
1459 if (primaryWinInfo
== cmdWin
)
1461 /* locator included since first & second win share a line */
1462 ok
= ((firstWin
->generic
.height
+
1463 secondWin
->generic
.height
+ diff
) >=
1464 (MIN_WIN_HEIGHT
* 2) &&
1465 newHeight
>= MIN_CMD_WIN_HEIGHT
);
1468 totalHeight
= newHeight
+ (firstWin
->generic
.height
+
1469 secondWin
->generic
.height
+ diff
);
1470 minHeight
= MIN_CMD_WIN_HEIGHT
;
1475 minHeight
= MIN_WIN_HEIGHT
;
1477 ** First see if we can increase/decrease the command
1478 ** window. And make sure that the command window is
1481 ok
= ((cmdWin
->generic
.height
+ diff
) > 0);
1484 ** Looks like we have to increase/decrease one of
1485 ** the other windows
1487 if (primaryWinInfo
== firstWin
)
1488 ok
= (secondWin
->generic
.height
+ diff
) >= minHeight
;
1490 ok
= (firstWin
->generic
.height
+ diff
) >= minHeight
;
1494 if (primaryWinInfo
== firstWin
)
1495 totalHeight
= newHeight
+
1496 secondWin
->generic
.height
+
1497 cmdWin
->generic
.height
+ diff
;
1499 totalHeight
= newHeight
+
1500 firstWin
->generic
.height
+
1501 cmdWin
->generic
.height
+ diff
;
1505 ** Now make sure that the proposed total height doesn't exceed
1506 ** the old total height.
1509 ok
= (newHeight
>= minHeight
&& totalHeight
<= curTotalHeight
);
1514 } /* _newHeightOk */
1518 ** _parseScrollingArgs().
1521 _parseScrollingArgs (char *arg
, TuiWinInfoPtr
* winToScroll
, int *numToScroll
)
1525 *winToScroll
= tuiWinWithFocus ();
1528 ** First set up the default window to scroll, in case there is no
1531 if (arg
!= (char *) NULL
)
1535 /* process the number of lines to scroll */
1536 buf
= bufPtr
= xstrdup (arg
);
1537 if (isdigit (*bufPtr
))
1542 bufPtr
= strchr (bufPtr
, ' ');
1543 if (bufPtr
!= (char *) NULL
)
1547 *numToScroll
= atoi (numStr
);
1550 else if (numToScroll
)
1551 *numToScroll
= atoi (numStr
);
1554 /* process the window name if one is specified */
1555 if (bufPtr
!= (char *) NULL
)
1561 while (*(++bufPtr
) == ' ')
1564 if (*bufPtr
!= (char) 0)
1569 /* Validate the window name */
1570 for (i
= 0; i
< strlen (wname
); i
++)
1571 wname
[i
] = toupper (wname
[i
]);
1572 *winToScroll
= partialWinByName (wname
);
1574 if (*winToScroll
== (TuiWinInfoPtr
) NULL
||
1575 !(*winToScroll
)->generic
.isVisible
)
1576 warning ("Invalid window specified. \n\
1577 The window name specified must be valid and visible.\n");
1578 else if (*winToScroll
== cmdWin
)
1579 *winToScroll
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1585 } /* _parseScrollingArgs */