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"
59 #include "tuiGeneralWin.h"
62 #include "tuiDisassem.h"
63 #include "tuiSource.h"
64 #include "tuiSourceWin.h"
65 #include "tuiDataWin.h"
67 /*******************************
69 ********************************/
70 static void _makeVisibleWithNewHeight (TuiWinInfoPtr
);
71 static void _makeInvisibleAndSetNewHeight (TuiWinInfoPtr
, int);
72 static TuiStatus
_tuiAdjustWinHeights (TuiWinInfoPtr
, int);
73 static int _newHeightOk (TuiWinInfoPtr
, int);
74 static void _tuiSetTabWidth_command (char *, int);
75 static void _tuiRefreshAll_command (char *, int);
76 static void _tuiSetWinHeight_command (char *, int);
77 static void _tuiXDBsetWinHeight_command (char *, int);
78 static void _tuiAllWindowsInfo (char *, int);
79 static void _tuiSetFocus_command (char *, int);
80 static void _tuiScrollForward_command (char *, int);
81 static void _tuiScrollBackward_command (char *, int);
82 static void _tuiScrollLeft_command (char *, int);
83 static void _tuiScrollRight_command (char *, int);
84 static void _parseScrollingArgs (char *, TuiWinInfoPtr
*, int *);
87 /***************************************
89 ***************************************/
90 #define WIN_HEIGHT_USAGE "Usage: winheight <win_name> [+ | -] <#lines>\n"
91 #define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n"
92 #define FOCUS_USAGE "Usage: focus {<win> | next | prev}\n"
94 /***************************************
96 ***************************************/
98 /* Possible values for tui-border-kind variable. */
99 static const char *tui_border_kind_enums
[] = {
106 /* Possible values for tui-border-mode and tui-active-border-mode. */
107 static const char *tui_border_mode_enums
[] = {
124 /* Translation table for border-mode variables.
125 The list of values must be terminated by a NULL.
126 After the NULL value, an entry defines the default. */
127 struct tui_translate tui_border_mode_translate
[] = {
128 { "normal", A_NORMAL
},
129 { "standout", A_STANDOUT
},
130 { "reverse", A_REVERSE
},
132 { "half-standout", A_DIM
| A_STANDOUT
},
134 { "bold-standout", A_BOLD
| A_STANDOUT
},
136 { "normal", A_NORMAL
}
139 /* Translation tables for border-kind, one for each border
140 character (see wborder, border curses operations).
141 -1 is used to indicate the ACS because ACS characters
142 are determined at run time by curses (depends on terminal). */
143 struct tui_translate tui_border_kind_translate_vline
[] = {
151 struct tui_translate tui_border_kind_translate_hline
[] = {
159 struct tui_translate tui_border_kind_translate_ulcorner
[] = {
167 struct tui_translate tui_border_kind_translate_urcorner
[] = {
175 struct tui_translate tui_border_kind_translate_llcorner
[] = {
183 struct tui_translate tui_border_kind_translate_lrcorner
[] = {
192 /* Tui configuration variables controlled with set/show command. */
193 const char *tui_active_border_mode
= "bold-standout";
194 const char *tui_border_mode
= "normal";
195 const char *tui_border_kind
= "acs";
197 /* Tui internal configuration variables. These variables are
198 updated by tui_update_variables to reflect the tui configuration
200 chtype tui_border_vline
;
201 chtype tui_border_hline
;
202 chtype tui_border_ulcorner
;
203 chtype tui_border_urcorner
;
204 chtype tui_border_llcorner
;
205 chtype tui_border_lrcorner
;
207 int tui_border_attrs
;
208 int tui_active_border_attrs
;
210 /* Identify the item in the translation table.
211 When the item is not recognized, use the default entry. */
212 static struct tui_translate
*
213 translate (const char *name
, struct tui_translate
*table
)
217 if (name
&& strcmp (table
->name
, name
) == 0)
222 /* Not found, return default entry. */
227 /* Update the tui internal configuration according to gdb settings.
228 Returns 1 if the configuration has changed and the screen should
231 tui_update_variables ()
234 struct tui_translate
*entry
;
236 entry
= translate (tui_border_mode
, tui_border_mode_translate
);
237 if (tui_border_attrs
!= entry
->value
)
239 tui_border_attrs
= entry
->value
;
242 entry
= translate (tui_active_border_mode
, tui_border_mode_translate
);
243 if (tui_active_border_attrs
!= entry
->value
)
245 tui_active_border_attrs
= entry
->value
;
249 /* If one corner changes, all characters are changed.
250 Only check the first one. The ACS characters are determined at
251 run time by curses terminal management. */
252 entry
= translate (tui_border_kind
, tui_border_kind_translate_lrcorner
);
253 if (tui_border_lrcorner
!= (chtype
) entry
->value
)
255 tui_border_lrcorner
= (entry
->value
< 0) ? ACS_LRCORNER
: entry
->value
;
258 entry
= translate (tui_border_kind
, tui_border_kind_translate_llcorner
);
259 tui_border_llcorner
= (entry
->value
< 0) ? ACS_LLCORNER
: entry
->value
;
261 entry
= translate (tui_border_kind
, tui_border_kind_translate_ulcorner
);
262 tui_border_ulcorner
= (entry
->value
< 0) ? ACS_ULCORNER
: entry
->value
;
264 entry
= translate (tui_border_kind
, tui_border_kind_translate_urcorner
);
265 tui_border_urcorner
= (entry
->value
< 0) ? ACS_URCORNER
: entry
->value
;
267 entry
= translate (tui_border_kind
, tui_border_kind_translate_hline
);
268 tui_border_hline
= (entry
->value
< 0) ? ACS_HLINE
: entry
->value
;
270 entry
= translate (tui_border_kind
, tui_border_kind_translate_vline
);
271 tui_border_vline
= (entry
->value
< 0) ? ACS_VLINE
: entry
->value
;
277 set_tui_cmd (char *args
, int from_tty
)
282 show_tui_cmd (char *args
, int from_tty
)
287 ** _initialize_tuiWin().
288 ** Function to initialize gdb commands, for tui window manipulation.
291 _initialize_tuiWin (void)
293 struct cmd_list_element
*c
;
294 static struct cmd_list_element
*tui_setlist
;
295 static struct cmd_list_element
*tui_showlist
;
297 /* Define the classes of commands.
298 They will appear in the help list in the reverse of this order. */
299 add_cmd ("tui", class_tui
, NULL
,
300 "Text User Interface commands.",
303 add_prefix_cmd ("tui", class_tui
, set_tui_cmd
,
304 "TUI configuration variables",
305 &tui_setlist
, "set tui ",
306 0/*allow-unknown*/, &setlist
);
307 add_prefix_cmd ("tui", class_tui
, show_tui_cmd
,
308 "TUI configuration variables",
309 &tui_showlist
, "show tui ",
310 0/*allow-unknown*/, &showlist
);
312 add_com ("refresh", class_tui
, _tuiRefreshAll_command
,
313 "Refresh the terminal display.\n");
315 add_com_alias ("U", "refresh", class_tui
, 0);
316 add_com ("tabset", class_tui
, _tuiSetTabWidth_command
,
317 "Set the width (in characters) of tab stops.\n\
318 Usage: tabset <n>\n");
319 add_com ("winheight", class_tui
, _tuiSetWinHeight_command
,
320 "Set the height of a specified window.\n\
321 Usage: winheight <win_name> [+ | -] <#lines>\n\
323 src : the source window\n\
324 cmd : the command window\n\
325 asm : the disassembly window\n\
326 regs : the register display\n");
327 add_com_alias ("wh", "winheight", class_tui
, 0);
328 add_info ("win", _tuiAllWindowsInfo
,
329 "List of all displayed windows.\n");
330 add_com ("focus", class_tui
, _tuiSetFocus_command
,
331 "Set focus to named window or next/prev window.\n\
332 Usage: focus {<win> | next | prev}\n\
333 Valid Window names are:\n\
334 src : the source window\n\
335 asm : the disassembly window\n\
336 regs : the register display\n\
337 cmd : the command window\n");
338 add_com_alias ("fs", "focus", class_tui
, 0);
339 add_com ("+", class_tui
, _tuiScrollForward_command
,
340 "Scroll window forward.\nUsage: + [win] [n]\n");
341 add_com ("-", class_tui
, _tuiScrollBackward_command
,
342 "Scroll window backward.\nUsage: - [win] [n]\n");
343 add_com ("<", class_tui
, _tuiScrollLeft_command
,
344 "Scroll window forward.\nUsage: < [win] [n]\n");
345 add_com (">", class_tui
, _tuiScrollRight_command
,
346 "Scroll window backward.\nUsage: > [win] [n]\n");
348 add_com ("w", class_xdb
, _tuiXDBsetWinHeight_command
,
349 "XDB compatibility command for setting the height of a command window.\n\
350 Usage: w <#lines>\n");
352 /* Define the tui control variables. */
354 ("border-kind", no_class
,
355 tui_border_kind_enums
, &tui_border_kind
,
356 "Set the kind of border for TUI windows.\n"
357 "This variable controls the border of TUI windows:\n"
358 "space use a white space\n"
359 "ascii use ascii characters + - | for the border\n"
360 "acs use the Alternate Character Set\n",
362 add_show_from_set (c
, &tui_showlist
);
365 ("border-mode", no_class
,
366 tui_border_mode_enums
, &tui_border_mode
,
367 "Set the attribute mode to use for the TUI window borders.\n"
368 "This variable controls the attributes to use for the window borders:\n"
369 "normal normal display\n"
370 "standout use highlight mode of terminal\n"
371 "reverse use reverse video mode\n"
372 "half use half bright\n"
373 "half-standout use half bright and standout mode\n"
374 "bold use extra bright or bold\n"
375 "bold-standout use extra bright or bold with standout mode\n",
377 add_show_from_set (c
, &tui_showlist
);
380 ("active-border-mode", no_class
,
381 tui_border_mode_enums
, &tui_active_border_mode
,
382 "Set the attribute mode to use for the active TUI window border.\n"
383 "This variable controls the attributes to use for the active window border:\n"
384 "normal normal display\n"
385 "standout use highlight mode of terminal\n"
386 "reverse use reverse video mode\n"
387 "half use half bright\n"
388 "half-standout use half bright and standout mode\n"
389 "bold use extra bright or bold\n"
390 "bold-standout use extra bright or bold with standout mode\n",
392 add_show_from_set (c
, &tui_showlist
);
395 /* Update gdb's knowledge of the terminal size. */
397 tui_update_gdb_sizes ()
400 extern int screenheight
, screenwidth
; /* in readline */
402 /* Set to TUI command window dimension or use readline values. */
403 sprintf (cmd
, "set width %d",
404 tui_active
? cmdWin
->generic
.width
: screenwidth
);
405 execute_command (cmd
, 0);
406 sprintf (cmd
, "set height %d",
407 tui_active
? cmdWin
->generic
.height
: screenheight
);
408 execute_command (cmd
, 0);
414 ** Set the logical focus to winInfo
417 tuiSetWinFocusTo (TuiWinInfoPtr winInfo
)
419 if (m_winPtrNotNull (winInfo
))
421 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
423 if (m_winPtrNotNull (winWithFocus
) &&
424 winWithFocus
->generic
.type
!= CMD_WIN
)
425 unhighlightWin (winWithFocus
);
426 tuiSetWinWithFocus (winInfo
);
427 if (winInfo
->generic
.type
!= CMD_WIN
)
428 highlightWin (winInfo
);
432 } /* tuiSetWinFocusTo */
436 ** tuiScrollForward().
439 tuiScrollForward (TuiWinInfoPtr winToScroll
, int numToScroll
)
441 if (winToScroll
!= cmdWin
)
443 int _numToScroll
= numToScroll
;
445 if (numToScroll
== 0)
446 _numToScroll
= winToScroll
->generic
.height
- 3;
448 ** If we are scrolling the source or disassembly window, do a
449 ** "psuedo" scroll since not all of the source is in memory,
450 ** only what is in the viewport. If winToScroll is the
451 ** command window do nothing since the term should handle it.
453 if (winToScroll
== srcWin
)
454 tuiVerticalSourceScroll (FORWARD_SCROLL
, _numToScroll
);
455 else if (winToScroll
== disassemWin
)
456 tuiVerticalDisassemScroll (FORWARD_SCROLL
, _numToScroll
);
457 else if (winToScroll
== dataWin
)
458 tuiVerticalDataScroll (FORWARD_SCROLL
, _numToScroll
);
462 } /* tuiScrollForward */
466 ** tuiScrollBackward().
469 tuiScrollBackward (TuiWinInfoPtr winToScroll
, int numToScroll
)
471 if (winToScroll
!= cmdWin
)
473 int _numToScroll
= numToScroll
;
475 if (numToScroll
== 0)
476 _numToScroll
= winToScroll
->generic
.height
- 3;
478 ** If we are scrolling the source or disassembly window, do a
479 ** "psuedo" scroll since not all of the source is in memory,
480 ** only what is in the viewport. If winToScroll is the
481 ** command window do nothing since the term should handle it.
483 if (winToScroll
== srcWin
)
484 tuiVerticalSourceScroll (BACKWARD_SCROLL
, _numToScroll
);
485 else if (winToScroll
== disassemWin
)
486 tuiVerticalDisassemScroll (BACKWARD_SCROLL
, _numToScroll
);
487 else if (winToScroll
== dataWin
)
488 tuiVerticalDataScroll (BACKWARD_SCROLL
, _numToScroll
);
491 } /* tuiScrollBackward */
498 tuiScrollLeft (TuiWinInfoPtr winToScroll
, int numToScroll
)
500 if (winToScroll
!= cmdWin
)
502 int _numToScroll
= numToScroll
;
504 if (_numToScroll
== 0)
507 ** If we are scrolling the source or disassembly window, do a
508 ** "psuedo" scroll since not all of the source is in memory,
509 ** only what is in the viewport. If winToScroll is the
510 ** command window do nothing since the term should handle it.
512 if (winToScroll
== srcWin
|| winToScroll
== disassemWin
)
513 tuiHorizontalSourceScroll (winToScroll
, LEFT_SCROLL
, _numToScroll
);
516 } /* tuiScrollLeft */
523 tuiScrollRight (TuiWinInfoPtr winToScroll
, int numToScroll
)
525 if (winToScroll
!= cmdWin
)
527 int _numToScroll
= numToScroll
;
529 if (_numToScroll
== 0)
532 ** If we are scrolling the source or disassembly window, do a
533 ** "psuedo" scroll since not all of the source is in memory,
534 ** only what is in the viewport. If winToScroll is the
535 ** command window do nothing since the term should handle it.
537 if (winToScroll
== srcWin
|| winToScroll
== disassemWin
)
538 tuiHorizontalSourceScroll (winToScroll
, RIGHT_SCROLL
, _numToScroll
);
541 } /* tuiScrollRight */
546 ** Scroll a window. Arguments are passed through a va_list.
549 tui_scroll (TuiScrollDirection direction
,
550 TuiWinInfoPtr winToScroll
,
556 tuiScrollForward (winToScroll
, numToScroll
);
558 case BACKWARD_SCROLL
:
559 tuiScrollBackward (winToScroll
, numToScroll
);
562 tuiScrollLeft (winToScroll
, numToScroll
);
565 tuiScrollRight (winToScroll
, numToScroll
);
581 clearok (curscr
, TRUE
);
582 refreshAll (winList
);
583 for (type
= SRC_WIN
; type
< MAX_MAJOR_WINDOWS
; type
++)
585 if (winList
[type
] && winList
[type
]->generic
.isVisible
)
591 tuiShowSourceContent (winList
[type
]);
592 checkAndDisplayHighlightIfNeeded (winList
[type
]);
593 tuiEraseExecInfoContent (winList
[type
]);
594 tuiUpdateExecInfo (winList
[type
]);
597 tuiRefreshDataWin ();
604 tuiShowLocatorContent ();
610 ** Resize all the windows based on the the terminal size. This
611 ** function gets called from within the readline sinwinch handler.
616 int heightDiff
, widthDiff
;
617 extern int screenheight
, screenwidth
; /* in readline */
619 widthDiff
= screenwidth
- termWidth ();
620 heightDiff
= screenheight
- termHeight ();
621 if (heightDiff
|| widthDiff
)
623 TuiLayoutType curLayout
= currentLayout ();
624 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
625 TuiWinInfoPtr firstWin
, secondWin
;
626 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
628 int newHeight
, splitDiff
, cmdSplitDiff
, numWinsDisplayed
= 2;
630 /* turn keypad off while we resize */
631 if (winWithFocus
!= cmdWin
)
632 keypad (cmdWin
->generic
.handle
, FALSE
);
633 tui_update_gdb_sizes ();
634 setTermHeightTo (screenheight
);
635 setTermWidthTo (screenwidth
);
636 if (curLayout
== SRC_DISASSEM_COMMAND
||
637 curLayout
== SRC_DATA_COMMAND
|| curLayout
== DISASSEM_DATA_COMMAND
)
639 splitDiff
= heightDiff
/ numWinsDisplayed
;
640 cmdSplitDiff
= splitDiff
;
641 if (heightDiff
% numWinsDisplayed
)
648 /* now adjust each window */
654 case DISASSEM_COMMAND
:
655 firstWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
656 firstWin
->generic
.width
+= widthDiff
;
657 locator
->width
+= widthDiff
;
658 /* check for invalid heights */
660 newHeight
= firstWin
->generic
.height
;
661 else if ((firstWin
->generic
.height
+ splitDiff
) >=
662 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
663 newHeight
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
664 else if ((firstWin
->generic
.height
+ splitDiff
) <= 0)
665 newHeight
= MIN_WIN_HEIGHT
;
667 newHeight
= firstWin
->generic
.height
+ splitDiff
;
669 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
670 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
671 cmdWin
->generic
.width
+= widthDiff
;
672 newHeight
= screenheight
- cmdWin
->generic
.origin
.y
;
673 _makeInvisibleAndSetNewHeight (cmdWin
, newHeight
);
674 _makeVisibleWithNewHeight (firstWin
);
675 _makeVisibleWithNewHeight (cmdWin
);
676 if (firstWin
->generic
.contentSize
<= 0)
677 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
680 if (curLayout
== SRC_DISASSEM_COMMAND
)
683 firstWin
->generic
.width
+= widthDiff
;
684 secondWin
= disassemWin
;
685 secondWin
->generic
.width
+= widthDiff
;
690 firstWin
->generic
.width
+= widthDiff
;
691 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
692 secondWin
->generic
.width
+= widthDiff
;
694 /* Change the first window's height/width */
695 /* check for invalid heights */
697 newHeight
= firstWin
->generic
.height
;
698 else if ((firstWin
->generic
.height
+
699 secondWin
->generic
.height
+ (splitDiff
* 2)) >=
700 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
701 newHeight
= (screenheight
- MIN_CMD_WIN_HEIGHT
- 1) / 2;
702 else if ((firstWin
->generic
.height
+ splitDiff
) <= 0)
703 newHeight
= MIN_WIN_HEIGHT
;
705 newHeight
= firstWin
->generic
.height
+ splitDiff
;
706 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
708 if (firstWin
== dataWin
&& widthDiff
!= 0)
709 firstWin
->detail
.dataDisplayInfo
.regsColumnCount
=
710 tuiCalculateRegsColumnCount (
711 firstWin
->detail
.dataDisplayInfo
.regsDisplayType
);
712 locator
->width
+= widthDiff
;
714 /* Change the second window's height/width */
715 /* check for invalid heights */
717 newHeight
= secondWin
->generic
.height
;
718 else if ((firstWin
->generic
.height
+
719 secondWin
->generic
.height
+ (splitDiff
* 2)) >=
720 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
722 newHeight
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
724 newHeight
= (newHeight
/ 2) + 1;
728 else if ((secondWin
->generic
.height
+ splitDiff
) <= 0)
729 newHeight
= MIN_WIN_HEIGHT
;
731 newHeight
= secondWin
->generic
.height
+ splitDiff
;
732 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
733 _makeInvisibleAndSetNewHeight (secondWin
, newHeight
);
735 /* Change the command window's height/width */
736 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
737 _makeInvisibleAndSetNewHeight (
738 cmdWin
, cmdWin
->generic
.height
+ cmdSplitDiff
);
739 _makeVisibleWithNewHeight (firstWin
);
740 _makeVisibleWithNewHeight (secondWin
);
741 _makeVisibleWithNewHeight (cmdWin
);
742 if (firstWin
->generic
.contentSize
<= 0)
743 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
744 if (secondWin
->generic
.contentSize
<= 0)
745 tuiEraseSourceContent (secondWin
, EMPTY_SOURCE_PROMPT
);
749 ** Now remove all invisible windows, and their content so that they get
750 ** created again when called for with the new size
752 for (winType
= SRC_WIN
; (winType
< MAX_MAJOR_WINDOWS
); winType
++)
754 if (winType
!= CMD_WIN
&& m_winPtrNotNull (winList
[winType
]) &&
755 !winList
[winType
]->generic
.isVisible
)
757 freeWindow (winList
[winType
]);
758 winList
[winType
] = (TuiWinInfoPtr
) NULL
;
761 tuiSetWinResizedTo (TRUE
);
762 /* turn keypad back on, unless focus is in the command window */
763 if (winWithFocus
!= cmdWin
)
764 keypad (cmdWin
->generic
.handle
, TRUE
);
771 ** tuiSigwinchHandler()
772 ** SIGWINCH signal handler for the tui. This signal handler is
773 ** always called, even when the readline package clears signals
774 ** because it is set as the old_sigwinch() (TUI only)
777 tuiSigwinchHandler (int signal
)
780 ** Say that a resize was done so that the readline can do it
781 ** later when appropriate.
783 tuiSetWinResizedTo (TRUE
);
786 } /* tuiSigwinchHandler */
790 /*************************
791 ** STATIC LOCAL FUNCTIONS
792 **************************/
796 ** _tuiScrollForward_command().
799 _tuiScrollForward_command (char *arg
, int fromTTY
)
802 TuiWinInfoPtr winToScroll
;
804 /* Make sure the curses mode is enabled. */
806 if (arg
== (char *) NULL
)
807 _parseScrollingArgs (arg
, &winToScroll
, (int *) NULL
);
809 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
810 tui_scroll (FORWARD_SCROLL
, winToScroll
, numToScroll
);
815 ** _tuiScrollBackward_command().
818 _tuiScrollBackward_command (char *arg
, int fromTTY
)
821 TuiWinInfoPtr winToScroll
;
823 /* Make sure the curses mode is enabled. */
825 if (arg
== (char *) NULL
)
826 _parseScrollingArgs (arg
, &winToScroll
, (int *) NULL
);
828 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
829 tui_scroll (BACKWARD_SCROLL
, winToScroll
, numToScroll
);
834 ** _tuiScrollLeft_command().
837 _tuiScrollLeft_command (char *arg
, int fromTTY
)
840 TuiWinInfoPtr winToScroll
;
842 /* Make sure the curses mode is enabled. */
844 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
845 tui_scroll (LEFT_SCROLL
, winToScroll
, numToScroll
);
850 ** _tuiScrollRight_command().
853 _tuiScrollRight_command (char *arg
, int fromTTY
)
856 TuiWinInfoPtr winToScroll
;
858 /* Make sure the curses mode is enabled. */
860 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
861 tui_scroll (RIGHT_SCROLL
, winToScroll
, numToScroll
);
867 ** Set focus to the window named by 'arg'
870 _tuiSetFocus (char *arg
, int fromTTY
)
872 if (arg
!= (char *) NULL
)
874 char *bufPtr
= (char *) xstrdup (arg
);
876 TuiWinInfoPtr winInfo
= (TuiWinInfoPtr
) NULL
;
878 for (i
= 0; (i
< strlen (bufPtr
)); i
++)
879 bufPtr
[i
] = toupper (arg
[i
]);
881 if (subset_compare (bufPtr
, "NEXT"))
882 winInfo
= tuiNextWin (tuiWinWithFocus ());
883 else if (subset_compare (bufPtr
, "PREV"))
884 winInfo
= tuiPrevWin (tuiWinWithFocus ());
886 winInfo
= partialWinByName (bufPtr
);
888 if (winInfo
== (TuiWinInfoPtr
) NULL
|| !winInfo
->generic
.isVisible
)
889 warning ("Invalid window specified. \n\
890 The window name specified must be valid and visible.\n");
893 tuiSetWinFocusTo (winInfo
);
894 keypad (cmdWin
->generic
.handle
, (winInfo
!= cmdWin
));
897 if (dataWin
&& dataWin
->generic
.isVisible
)
898 tuiRefreshDataWin ();
900 printf_filtered ("Focus set to %s window.\n",
901 winName ((TuiGenWinInfoPtr
) tuiWinWithFocus ()));
904 warning ("Incorrect Number of Arguments.\n%s", FOCUS_USAGE
);
910 ** _tuiSetFocus_command()
913 _tuiSetFocus_command (char *arg
, int fromTTY
)
915 /* Make sure the curses mode is enabled. */
917 _tuiSetFocus (arg
, fromTTY
);
922 ** _tuiAllWindowsInfo().
925 _tuiAllWindowsInfo (char *arg
, int fromTTY
)
928 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
930 for (type
= SRC_WIN
; (type
< MAX_MAJOR_WINDOWS
); type
++)
931 if (winList
[type
]->generic
.isVisible
)
933 if (winWithFocus
== winList
[type
])
934 printf_filtered (" %s\t(%d lines) <has focus>\n",
935 winName (&winList
[type
]->generic
),
936 winList
[type
]->generic
.height
);
938 printf_filtered (" %s\t(%d lines)\n",
939 winName (&winList
[type
]->generic
),
940 winList
[type
]->generic
.height
);
944 } /* _tuiAllWindowsInfo */
948 ** _tuiRefreshAll_command().
951 _tuiRefreshAll_command (char *arg
, int fromTTY
)
953 /* Make sure the curses mode is enabled. */
961 ** _tuiSetWinTabWidth_command().
962 ** Set the height of the specified window.
965 _tuiSetTabWidth_command (char *arg
, int fromTTY
)
967 /* Make sure the curses mode is enabled. */
969 if (arg
!= (char *) NULL
)
975 tuiSetDefaultTabLen (ts
);
977 warning ("Tab widths greater than 0 must be specified.\n");
981 } /* _tuiSetTabWidth_command */
985 ** _tuiSetWinHeight().
986 ** Set the height of the specified window.
989 _tuiSetWinHeight (char *arg
, int fromTTY
)
991 /* Make sure the curses mode is enabled. */
993 if (arg
!= (char *) NULL
)
995 char *buf
= xstrdup (arg
);
997 char *wname
= (char *) NULL
;
999 TuiWinInfoPtr winInfo
;
1002 bufPtr
= strchr (bufPtr
, ' ');
1003 if (bufPtr
!= (char *) NULL
)
1008 ** Validate the window name
1010 for (i
= 0; i
< strlen (wname
); i
++)
1011 wname
[i
] = toupper (wname
[i
]);
1012 winInfo
= partialWinByName (wname
);
1014 if (winInfo
== (TuiWinInfoPtr
) NULL
|| !winInfo
->generic
.isVisible
)
1015 warning ("Invalid window specified. \n\
1016 The window name specified must be valid and visible.\n");
1019 /* Process the size */
1020 while (*(++bufPtr
) == ' ')
1023 if (*bufPtr
!= (char) 0)
1026 int fixedSize
= TRUE
;
1029 if (*bufPtr
== '+' || *bufPtr
== '-')
1036 inputNo
= atoi (bufPtr
);
1042 newHeight
= inputNo
;
1044 newHeight
= winInfo
->generic
.height
+ inputNo
;
1046 ** Now change the window's height, and adjust all
1047 ** other windows around it
1049 if (_tuiAdjustWinHeights (winInfo
,
1050 newHeight
) == TUI_FAILURE
)
1051 warning ("Invalid window height specified.\n%s",
1054 tui_update_gdb_sizes ();
1057 warning ("Invalid window height specified.\n%s",
1063 printf_filtered (WIN_HEIGHT_USAGE
);
1065 if (buf
!= (char *) NULL
)
1069 printf_filtered (WIN_HEIGHT_USAGE
);
1072 } /* _tuiSetWinHeight */
1075 ** _tuiSetWinHeight_command().
1076 ** Set the height of the specified window, with va_list.
1079 _tuiSetWinHeight_command (char *arg
, int fromTTY
)
1081 /* Make sure the curses mode is enabled. */
1083 _tuiSetWinHeight (arg
, fromTTY
);
1088 ** _tuiXDBsetWinHeight().
1089 ** XDB Compatibility command for setting the window height. This will
1090 ** increase or decrease the command window by the specified amount.
1093 _tuiXDBsetWinHeight (char *arg
, int fromTTY
)
1095 /* Make sure the curses mode is enabled. */
1097 if (arg
!= (char *) NULL
)
1099 int inputNo
= atoi (arg
);
1102 { /* Add 1 for the locator */
1103 int newHeight
= termHeight () - (inputNo
+ 1);
1105 if (!_newHeightOk (winList
[CMD_WIN
], newHeight
) ||
1106 _tuiAdjustWinHeights (winList
[CMD_WIN
],
1107 newHeight
) == TUI_FAILURE
)
1108 warning ("Invalid window height specified.\n%s",
1109 XDBWIN_HEIGHT_USAGE
);
1112 warning ("Invalid window height specified.\n%s",
1113 XDBWIN_HEIGHT_USAGE
);
1116 warning ("Invalid window height specified.\n%s", XDBWIN_HEIGHT_USAGE
);
1119 } /* _tuiXDBsetWinHeight */
1122 ** _tuiSetWinHeight_command().
1123 ** Set the height of the specified window, with va_list.
1126 _tuiXDBsetWinHeight_command (char *arg
, int fromTTY
)
1128 _tuiXDBsetWinHeight (arg
, fromTTY
);
1133 ** _tuiAdjustWinHeights().
1134 ** Function to adjust all window heights around the primary
1137 _tuiAdjustWinHeights (TuiWinInfoPtr primaryWinInfo
, int newHeight
)
1139 TuiStatus status
= TUI_FAILURE
;
1141 if (_newHeightOk (primaryWinInfo
, newHeight
))
1143 status
= TUI_SUCCESS
;
1144 if (newHeight
!= primaryWinInfo
->generic
.height
)
1147 TuiWinInfoPtr winInfo
;
1148 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
1149 TuiLayoutType curLayout
= currentLayout ();
1151 diff
= (newHeight
- primaryWinInfo
->generic
.height
) * (-1);
1152 if (curLayout
== SRC_COMMAND
|| curLayout
== DISASSEM_COMMAND
)
1154 TuiWinInfoPtr srcWinInfo
;
1156 _makeInvisibleAndSetNewHeight (primaryWinInfo
, newHeight
);
1157 if (primaryWinInfo
->generic
.type
== CMD_WIN
)
1159 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1160 srcWinInfo
= winInfo
;
1164 winInfo
= winList
[CMD_WIN
];
1165 srcWinInfo
= primaryWinInfo
;
1167 _makeInvisibleAndSetNewHeight (winInfo
,
1168 winInfo
->generic
.height
+ diff
);
1169 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1170 _makeVisibleWithNewHeight (winInfo
);
1171 _makeVisibleWithNewHeight (primaryWinInfo
);
1172 if (srcWinInfo
->generic
.contentSize
<= 0)
1173 tuiEraseSourceContent (srcWinInfo
, EMPTY_SOURCE_PROMPT
);
1177 TuiWinInfoPtr firstWin
, secondWin
;
1179 if (curLayout
== SRC_DISASSEM_COMMAND
)
1182 secondWin
= disassemWin
;
1187 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1189 if (primaryWinInfo
== cmdWin
)
1191 ** Split the change in height accross the 1st & 2nd windows
1192 ** adjusting them as well.
1194 int firstSplitDiff
= diff
/ 2; /* subtract the locator */
1195 int secondSplitDiff
= firstSplitDiff
;
1199 if (firstWin
->generic
.height
>
1200 secondWin
->generic
.height
)
1213 /* make sure that the minimum hieghts are honored */
1214 while ((firstWin
->generic
.height
+ firstSplitDiff
) < 3)
1219 while ((secondWin
->generic
.height
+ secondSplitDiff
) < 3)
1224 _makeInvisibleAndSetNewHeight (
1226 firstWin
->generic
.height
+ firstSplitDiff
);
1227 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
1228 _makeInvisibleAndSetNewHeight (
1229 secondWin
, secondWin
->generic
.height
+ secondSplitDiff
);
1230 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1231 _makeInvisibleAndSetNewHeight (cmdWin
, newHeight
);
1235 if ((cmdWin
->generic
.height
+ diff
) < 1)
1237 ** If there is no way to increase the command window
1238 ** take real estate from the 1st or 2nd window.
1240 if ((cmdWin
->generic
.height
+ diff
) < 1)
1243 for (i
= cmdWin
->generic
.height
+ diff
;
1245 if (primaryWinInfo
== firstWin
)
1246 secondWin
->generic
.height
--;
1248 firstWin
->generic
.height
--;
1251 if (primaryWinInfo
== firstWin
)
1252 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
1254 _makeInvisibleAndSetNewHeight (
1256 firstWin
->generic
.height
);
1257 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
1258 if (primaryWinInfo
== secondWin
)
1259 _makeInvisibleAndSetNewHeight (secondWin
, newHeight
);
1261 _makeInvisibleAndSetNewHeight (
1262 secondWin
, secondWin
->generic
.height
);
1263 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1264 if ((cmdWin
->generic
.height
+ diff
) < 1)
1265 _makeInvisibleAndSetNewHeight (cmdWin
, 1);
1267 _makeInvisibleAndSetNewHeight (
1268 cmdWin
, cmdWin
->generic
.height
+ diff
);
1270 _makeVisibleWithNewHeight (cmdWin
);
1271 _makeVisibleWithNewHeight (secondWin
);
1272 _makeVisibleWithNewHeight (firstWin
);
1273 if (firstWin
->generic
.contentSize
<= 0)
1274 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
1275 if (secondWin
->generic
.contentSize
<= 0)
1276 tuiEraseSourceContent (secondWin
, EMPTY_SOURCE_PROMPT
);
1282 } /* _tuiAdjustWinHeights */
1286 ** _makeInvisibleAndSetNewHeight().
1287 ** Function make the target window (and auxillary windows associated
1288 ** with the targer) invisible, and set the new height and location.
1291 _makeInvisibleAndSetNewHeight (TuiWinInfoPtr winInfo
, int height
)
1294 TuiGenWinInfoPtr genWinInfo
;
1297 m_beInvisible (&winInfo
->generic
);
1298 winInfo
->generic
.height
= height
;
1300 winInfo
->generic
.viewportHeight
= height
- 1;
1302 winInfo
->generic
.viewportHeight
= height
;
1303 if (winInfo
!= cmdWin
)
1304 winInfo
->generic
.viewportHeight
--;
1306 /* Now deal with the auxillary windows associated with winInfo */
1307 switch (winInfo
->generic
.type
)
1311 genWinInfo
= winInfo
->detail
.sourceInfo
.executionInfo
;
1312 m_beInvisible (genWinInfo
);
1313 genWinInfo
->height
= height
;
1314 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
;
1316 genWinInfo
->viewportHeight
= height
- 1;
1318 genWinInfo
->viewportHeight
= height
;
1319 if (winInfo
!= cmdWin
)
1320 genWinInfo
->viewportHeight
--;
1322 if (m_hasLocator (winInfo
))
1324 genWinInfo
= locatorWinInfoPtr ();
1325 m_beInvisible (genWinInfo
);
1326 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
+ height
;
1330 /* delete all data item windows */
1331 for (i
= 0; i
< winInfo
->generic
.contentSize
; i
++)
1333 genWinInfo
= (TuiGenWinInfoPtr
) & ((TuiWinElementPtr
)
1334 winInfo
->generic
.content
[i
])->whichElement
.dataWindow
;
1335 tuiDelwin (genWinInfo
->handle
);
1336 genWinInfo
->handle
= (WINDOW
*) NULL
;
1346 ** _makeVisibleWithNewHeight().
1347 ** Function to make the windows with new heights visible.
1348 ** This means re-creating the windows' content since the window
1349 ** had to be destroyed to be made invisible.
1352 _makeVisibleWithNewHeight (TuiWinInfoPtr winInfo
)
1356 m_beVisible (&winInfo
->generic
);
1357 checkAndDisplayHighlightIfNeeded (winInfo
);
1358 switch (winInfo
->generic
.type
)
1362 freeWinContent (winInfo
->detail
.sourceInfo
.executionInfo
);
1363 m_beVisible (winInfo
->detail
.sourceInfo
.executionInfo
);
1364 if (winInfo
->generic
.content
!= (OpaquePtr
) NULL
)
1366 TuiLineOrAddress lineOrAddr
;
1368 if (winInfo
->generic
.type
== SRC_WIN
)
1370 winInfo
->detail
.sourceInfo
.startLineOrAddr
.lineNo
;
1373 winInfo
->detail
.sourceInfo
.startLineOrAddr
.addr
;
1374 freeWinContent (&winInfo
->generic
);
1375 tuiUpdateSourceWindow (winInfo
,
1376 current_source_symtab
, lineOrAddr
, TRUE
);
1378 else if (selected_frame
!= (struct frame_info
*) NULL
)
1380 TuiLineOrAddress line
;
1381 extern int current_source_line
;
1383 s
= find_pc_symtab (selected_frame
->pc
);
1384 if (winInfo
->generic
.type
== SRC_WIN
)
1385 line
.lineNo
= current_source_line
;
1388 find_line_pc (s
, current_source_line
, &line
.addr
);
1390 tuiUpdateSourceWindow (winInfo
, s
, line
, TRUE
);
1392 if (m_hasLocator (winInfo
))
1394 m_beVisible (locatorWinInfoPtr ());
1395 tuiShowLocatorContent ();
1399 tuiDisplayAllData ();
1402 winInfo
->detail
.commandInfo
.curLine
= 0;
1403 winInfo
->detail
.commandInfo
.curch
= 0;
1404 wmove (winInfo
->generic
.handle
,
1405 winInfo
->detail
.commandInfo
.curLine
,
1406 winInfo
->detail
.commandInfo
.curch
);
1413 } /* _makeVisibleWithNewHeight */
1417 _newHeightOk (TuiWinInfoPtr primaryWinInfo
, int newHeight
)
1419 int ok
= (newHeight
< termHeight ());
1424 TuiLayoutType curLayout
= currentLayout ();
1426 diff
= (newHeight
- primaryWinInfo
->generic
.height
) * (-1);
1427 if (curLayout
== SRC_COMMAND
|| curLayout
== DISASSEM_COMMAND
)
1429 ok
= ((primaryWinInfo
->generic
.type
== CMD_WIN
&&
1430 newHeight
<= (termHeight () - 4) &&
1431 newHeight
>= MIN_CMD_WIN_HEIGHT
) ||
1432 (primaryWinInfo
->generic
.type
!= CMD_WIN
&&
1433 newHeight
<= (termHeight () - 2) &&
1434 newHeight
>= MIN_WIN_HEIGHT
));
1436 { /* check the total height */
1437 TuiWinInfoPtr winInfo
;
1439 if (primaryWinInfo
== cmdWin
)
1440 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1444 (winInfo
->generic
.height
+ diff
)) <= termHeight ());
1449 int curTotalHeight
, totalHeight
, minHeight
;
1450 TuiWinInfoPtr firstWin
, secondWin
;
1452 if (curLayout
== SRC_DISASSEM_COMMAND
)
1455 secondWin
= disassemWin
;
1460 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1463 ** We could simply add all the heights to obtain the same result
1464 ** but below is more explicit since we subtract 1 for the
1465 ** line that the first and second windows share, and add one
1469 (firstWin
->generic
.height
+ secondWin
->generic
.height
- 1)
1470 + cmdWin
->generic
.height
+ 1 /*locator */ ;
1471 if (primaryWinInfo
== cmdWin
)
1473 /* locator included since first & second win share a line */
1474 ok
= ((firstWin
->generic
.height
+
1475 secondWin
->generic
.height
+ diff
) >=
1476 (MIN_WIN_HEIGHT
* 2) &&
1477 newHeight
>= MIN_CMD_WIN_HEIGHT
);
1480 totalHeight
= newHeight
+ (firstWin
->generic
.height
+
1481 secondWin
->generic
.height
+ diff
);
1482 minHeight
= MIN_CMD_WIN_HEIGHT
;
1487 minHeight
= MIN_WIN_HEIGHT
;
1489 ** First see if we can increase/decrease the command
1490 ** window. And make sure that the command window is
1493 ok
= ((cmdWin
->generic
.height
+ diff
) > 0);
1496 ** Looks like we have to increase/decrease one of
1497 ** the other windows
1499 if (primaryWinInfo
== firstWin
)
1500 ok
= (secondWin
->generic
.height
+ diff
) >= minHeight
;
1502 ok
= (firstWin
->generic
.height
+ diff
) >= minHeight
;
1506 if (primaryWinInfo
== firstWin
)
1507 totalHeight
= newHeight
+
1508 secondWin
->generic
.height
+
1509 cmdWin
->generic
.height
+ diff
;
1511 totalHeight
= newHeight
+
1512 firstWin
->generic
.height
+
1513 cmdWin
->generic
.height
+ diff
;
1517 ** Now make sure that the proposed total height doesn't exceed
1518 ** the old total height.
1521 ok
= (newHeight
>= minHeight
&& totalHeight
<= curTotalHeight
);
1526 } /* _newHeightOk */
1530 ** _parseScrollingArgs().
1533 _parseScrollingArgs (char *arg
, TuiWinInfoPtr
* winToScroll
, int *numToScroll
)
1537 *winToScroll
= tuiWinWithFocus ();
1540 ** First set up the default window to scroll, in case there is no
1543 if (arg
!= (char *) NULL
)
1547 /* process the number of lines to scroll */
1548 buf
= bufPtr
= xstrdup (arg
);
1549 if (isdigit (*bufPtr
))
1554 bufPtr
= strchr (bufPtr
, ' ');
1555 if (bufPtr
!= (char *) NULL
)
1559 *numToScroll
= atoi (numStr
);
1562 else if (numToScroll
)
1563 *numToScroll
= atoi (numStr
);
1566 /* process the window name if one is specified */
1567 if (bufPtr
!= (char *) NULL
)
1573 while (*(++bufPtr
) == ' ')
1576 if (*bufPtr
!= (char) 0)
1581 /* Validate the window name */
1582 for (i
= 0; i
< strlen (wname
); i
++)
1583 wname
[i
] = toupper (wname
[i
]);
1584 *winToScroll
= partialWinByName (wname
);
1586 if (*winToScroll
== (TuiWinInfoPtr
) NULL
||
1587 !(*winToScroll
)->generic
.isVisible
)
1588 warning ("Invalid window specified. \n\
1589 The window name specified must be valid and visible.\n");
1590 else if (*winToScroll
== cmdWin
)
1591 *winToScroll
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1597 } /* _parseScrollingArgs */