1 /* TUI window generic functions.
2 Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Hewlett-Packard Company.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* This module contains procedures for handling tui window functions
23 like resize, scrolling, scrolling, changing focus, etc.
25 Author: Susan B. Macchia */
32 #include "breakpoint.h"
34 #include "cli/cli-cmds.h"
38 #include "tuiGeneralWin.h"
41 #include "tuiDisassem.h"
42 #include "tuiSource.h"
43 #include "tuiSourceWin.h"
44 #include "tuiDataWin.h"
46 /*******************************
47 ** External Declarations
48 ********************************/
49 extern void init_page_info ();
51 /*******************************
53 ********************************/
54 static void _makeVisibleWithNewHeight (TuiWinInfoPtr
);
55 static void _makeInvisibleAndSetNewHeight (TuiWinInfoPtr
, int);
56 static TuiStatus
_tuiAdjustWinHeights (TuiWinInfoPtr
, int);
57 static int _newHeightOk (TuiWinInfoPtr
, int);
58 static void _tuiSetTabWidth_command (char *, int);
59 static void _tuiRefreshAll_command (char *, int);
60 static void _tuiSetWinHeight_command (char *, int);
61 static void _tuiXDBsetWinHeight_command (char *, int);
62 static void _tuiAllWindowsInfo (char *, int);
63 static void _tuiSetFocus_command (char *, int);
64 static void _tuiScrollForward_command (char *, int);
65 static void _tuiScrollBackward_command (char *, int);
66 static void _tuiScrollLeft_command (char *, int);
67 static void _tuiScrollRight_command (char *, int);
68 static void _parseScrollingArgs (char *, TuiWinInfoPtr
*, int *);
71 /***************************************
73 ***************************************/
74 #define WIN_HEIGHT_USAGE "Usage: winheight <win_name> [+ | -] <#lines>\n"
75 #define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n"
76 #define FOCUS_USAGE "Usage: focus {<win> | next | prev}\n"
78 /***************************************
80 ***************************************/
82 /* Possible values for tui-border-kind variable. */
83 static const char *tui_border_kind_enums
[] = {
90 /* Possible values for tui-border-mode and tui-active-border-mode. */
91 static const char *tui_border_mode_enums
[] = {
108 /* Translation table for border-mode variables.
109 The list of values must be terminated by a NULL.
110 After the NULL value, an entry defines the default. */
111 struct tui_translate tui_border_mode_translate
[] = {
112 { "normal", A_NORMAL
},
113 { "standout", A_STANDOUT
},
114 { "reverse", A_REVERSE
},
116 { "half-standout", A_DIM
| A_STANDOUT
},
118 { "bold-standout", A_BOLD
| A_STANDOUT
},
120 { "normal", A_NORMAL
}
123 /* Translation tables for border-kind, one for each border
124 character (see wborder, border curses operations).
125 -1 is used to indicate the ACS because ACS characters
126 are determined at run time by curses (depends on terminal). */
127 struct tui_translate tui_border_kind_translate_vline
[] = {
135 struct tui_translate tui_border_kind_translate_hline
[] = {
143 struct tui_translate tui_border_kind_translate_ulcorner
[] = {
151 struct tui_translate tui_border_kind_translate_urcorner
[] = {
159 struct tui_translate tui_border_kind_translate_llcorner
[] = {
167 struct tui_translate tui_border_kind_translate_lrcorner
[] = {
176 /* Tui configuration variables controlled with set/show command. */
177 const char *tui_active_border_mode
= "bold-standout";
178 const char *tui_border_mode
= "normal";
179 const char *tui_border_kind
= "acs";
181 /* Tui internal configuration variables. These variables are
182 updated by tui_update_variables to reflect the tui configuration
184 chtype tui_border_vline
;
185 chtype tui_border_hline
;
186 chtype tui_border_ulcorner
;
187 chtype tui_border_urcorner
;
188 chtype tui_border_llcorner
;
189 chtype tui_border_lrcorner
;
191 int tui_border_attrs
;
192 int tui_active_border_attrs
;
194 /* Identify the item in the translation table.
195 When the item is not recognized, use the default entry. */
196 static struct tui_translate
*
197 translate (const char *name
, struct tui_translate
*table
)
201 if (name
&& strcmp (table
->name
, name
) == 0)
206 /* Not found, return default entry. */
211 /* Update the tui internal configuration according to gdb settings.
212 Returns 1 if the configuration has changed and the screen should
215 tui_update_variables ()
218 struct tui_translate
*entry
;
220 entry
= translate (tui_border_mode
, tui_border_mode_translate
);
221 if (tui_border_attrs
!= entry
->value
)
223 tui_border_attrs
= entry
->value
;
226 entry
= translate (tui_active_border_mode
, tui_border_mode_translate
);
227 if (tui_active_border_attrs
!= entry
->value
)
229 tui_active_border_attrs
= entry
->value
;
233 /* If one corner changes, all characters are changed.
234 Only check the first one. The ACS characters are determined at
235 run time by curses terminal management. */
236 entry
= translate (tui_border_kind
, tui_border_kind_translate_lrcorner
);
237 if (tui_border_lrcorner
!= (chtype
) entry
->value
)
239 tui_border_lrcorner
= (entry
->value
< 0) ? ACS_LRCORNER
: entry
->value
;
242 entry
= translate (tui_border_kind
, tui_border_kind_translate_llcorner
);
243 tui_border_llcorner
= (entry
->value
< 0) ? ACS_LLCORNER
: entry
->value
;
245 entry
= translate (tui_border_kind
, tui_border_kind_translate_ulcorner
);
246 tui_border_ulcorner
= (entry
->value
< 0) ? ACS_ULCORNER
: entry
->value
;
248 entry
= translate (tui_border_kind
, tui_border_kind_translate_urcorner
);
249 tui_border_urcorner
= (entry
->value
< 0) ? ACS_URCORNER
: entry
->value
;
251 entry
= translate (tui_border_kind
, tui_border_kind_translate_hline
);
252 tui_border_hline
= (entry
->value
< 0) ? ACS_HLINE
: entry
->value
;
254 entry
= translate (tui_border_kind
, tui_border_kind_translate_vline
);
255 tui_border_vline
= (entry
->value
< 0) ? ACS_VLINE
: entry
->value
;
261 set_tui_cmd (char *args
, int from_tty
)
266 show_tui_cmd (char *args
, int from_tty
)
271 ** _initialize_tuiWin().
272 ** Function to initialize gdb commands, for tui window manipulation.
275 _initialize_tuiWin (void)
277 struct cmd_list_element
*c
;
278 static struct cmd_list_element
*tui_setlist
;
279 static struct cmd_list_element
*tui_showlist
;
281 /* Define the classes of commands.
282 They will appear in the help list in the reverse of this order. */
283 add_cmd ("tui", class_tui
, NO_FUNCTION
,
284 "Text User Interface commands.",
287 add_prefix_cmd ("tui", class_tui
, set_tui_cmd
,
288 "TUI configuration variables",
289 &tui_setlist
, "set tui ",
290 0/*allow-unknown*/, &setlist
);
291 add_prefix_cmd ("tui", class_tui
, show_tui_cmd
,
292 "TUI configuration variables",
293 &tui_showlist
, "show tui ",
294 0/*allow-unknown*/, &showlist
);
296 add_com ("refresh", class_tui
, _tuiRefreshAll_command
,
297 "Refresh the terminal display.\n");
299 add_com_alias ("U", "refresh", class_tui
, 0);
300 add_com ("tabset", class_tui
, _tuiSetTabWidth_command
,
301 "Set the width (in characters) of tab stops.\n\
302 Usage: tabset <n>\n");
303 add_com ("winheight", class_tui
, _tuiSetWinHeight_command
,
304 "Set the height of a specified window.\n\
305 Usage: winheight <win_name> [+ | -] <#lines>\n\
307 src : the source window\n\
308 cmd : the command window\n\
309 asm : the disassembly window\n\
310 regs : the register display\n");
311 add_com_alias ("wh", "winheight", class_tui
, 0);
312 add_info ("win", _tuiAllWindowsInfo
,
313 "List of all displayed windows.\n");
314 add_com ("focus", class_tui
, _tuiSetFocus_command
,
315 "Set focus to named window or next/prev window.\n\
316 Usage: focus {<win> | next | prev}\n\
317 Valid Window names are:\n\
318 src : the source window\n\
319 asm : the disassembly window\n\
320 regs : the register display\n\
321 cmd : the command window\n");
322 add_com_alias ("fs", "focus", class_tui
, 0);
323 add_com ("+", class_tui
, _tuiScrollForward_command
,
324 "Scroll window forward.\nUsage: + [win] [n]\n");
325 add_com ("-", class_tui
, _tuiScrollBackward_command
,
326 "Scroll window backward.\nUsage: - [win] [n]\n");
327 add_com ("<", class_tui
, _tuiScrollLeft_command
,
328 "Scroll window forward.\nUsage: < [win] [n]\n");
329 add_com (">", class_tui
, _tuiScrollRight_command
,
330 "Scroll window backward.\nUsage: > [win] [n]\n");
332 add_com ("w", class_xdb
, _tuiXDBsetWinHeight_command
,
333 "XDB compatibility command for setting the height of a command window.\n\
334 Usage: w <#lines>\n");
336 /* Define the tui control variables. */
338 ("border-kind", no_class
,
339 tui_border_kind_enums
, &tui_border_kind
,
340 "Set the kind of border for TUI windows.\n"
341 "This variable controls the border of TUI windows:\n"
342 "space use a white space\n"
343 "ascii use ascii characters + - | for the border\n"
344 "acs use the Alternate Character Set\n",
346 add_show_from_set (c
, &tui_showlist
);
349 ("border-mode", no_class
,
350 tui_border_mode_enums
, &tui_border_mode
,
351 "Set the attribute mode to use for the TUI window borders.\n"
352 "This variable controls the attributes to use for the window borders:\n"
353 "normal normal display\n"
354 "standout use highlight mode of terminal\n"
355 "reverse use reverse video mode\n"
356 "half use half bright\n"
357 "half-standout use half bright and standout mode\n"
358 "bold use extra bright or bold\n"
359 "bold-standout use extra bright or bold with standout mode\n",
361 add_show_from_set (c
, &tui_showlist
);
364 ("active-border-mode", no_class
,
365 tui_border_mode_enums
, &tui_active_border_mode
,
366 "Set the attribute mode to use for the active TUI window border.\n"
367 "This variable controls the attributes to use for the active window border:\n"
368 "normal normal display\n"
369 "standout use highlight mode of terminal\n"
370 "reverse use reverse video mode\n"
371 "half use half bright\n"
372 "half-standout use half bright and standout mode\n"
373 "bold use extra bright or bold\n"
374 "bold-standout use extra bright or bold with standout mode\n",
376 add_show_from_set (c
, &tui_showlist
);
381 ** tuiClearWinFocusFrom
382 ** Clear the logical focus from winInfo
385 tuiClearWinFocusFrom (TuiWinInfoPtr winInfo
)
387 if (m_winPtrNotNull (winInfo
))
389 if (winInfo
->generic
.type
!= CMD_WIN
)
390 unhighlightWin (winInfo
);
391 tuiSetWinWithFocus ((TuiWinInfoPtr
) NULL
);
395 } /* tuiClearWinFocusFrom */
399 ** tuiClearWinFocus().
400 ** Clear the window that has focus.
403 tuiClearWinFocus (void)
405 tuiClearWinFocusFrom (tuiWinWithFocus ());
408 } /* tuiClearWinFocus */
413 ** Set the logical focus to winInfo
416 tuiSetWinFocusTo (TuiWinInfoPtr winInfo
)
418 if (m_winPtrNotNull (winInfo
))
420 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
422 if (m_winPtrNotNull (winWithFocus
) &&
423 winWithFocus
->generic
.type
!= CMD_WIN
)
424 unhighlightWin (winWithFocus
);
425 tuiSetWinWithFocus (winInfo
);
426 if (winInfo
->generic
.type
!= CMD_WIN
)
427 highlightWin (winInfo
);
431 } /* tuiSetWinFocusTo */
435 ** tuiScrollForward().
438 tuiScrollForward (TuiWinInfoPtr winToScroll
, int numToScroll
)
440 if (winToScroll
!= cmdWin
)
442 int _numToScroll
= numToScroll
;
444 if (numToScroll
== 0)
445 _numToScroll
= winToScroll
->generic
.height
- 3;
447 ** If we are scrolling the source or disassembly window, do a
448 ** "psuedo" scroll since not all of the source is in memory,
449 ** only what is in the viewport. If winToScroll is the
450 ** command window do nothing since the term should handle it.
452 if (winToScroll
== srcWin
)
453 tuiVerticalSourceScroll (FORWARD_SCROLL
, _numToScroll
);
454 else if (winToScroll
== disassemWin
)
455 tuiVerticalDisassemScroll (FORWARD_SCROLL
, _numToScroll
);
456 else if (winToScroll
== dataWin
)
457 tuiVerticalDataScroll (FORWARD_SCROLL
, _numToScroll
);
461 } /* tuiScrollForward */
465 ** tuiScrollBackward().
468 tuiScrollBackward (TuiWinInfoPtr winToScroll
, int numToScroll
)
470 if (winToScroll
!= cmdWin
)
472 int _numToScroll
= numToScroll
;
474 if (numToScroll
== 0)
475 _numToScroll
= winToScroll
->generic
.height
- 3;
477 ** If we are scrolling the source or disassembly window, do a
478 ** "psuedo" scroll since not all of the source is in memory,
479 ** only what is in the viewport. If winToScroll is the
480 ** command window do nothing since the term should handle it.
482 if (winToScroll
== srcWin
)
483 tuiVerticalSourceScroll (BACKWARD_SCROLL
, _numToScroll
);
484 else if (winToScroll
== disassemWin
)
485 tuiVerticalDisassemScroll (BACKWARD_SCROLL
, _numToScroll
);
486 else if (winToScroll
== dataWin
)
487 tuiVerticalDataScroll (BACKWARD_SCROLL
, _numToScroll
);
490 } /* tuiScrollBackward */
497 tuiScrollLeft (TuiWinInfoPtr winToScroll
, int numToScroll
)
499 if (winToScroll
!= cmdWin
)
501 int _numToScroll
= numToScroll
;
503 if (_numToScroll
== 0)
506 ** If we are scrolling the source or disassembly window, do a
507 ** "psuedo" scroll since not all of the source is in memory,
508 ** only what is in the viewport. If winToScroll is the
509 ** command window do nothing since the term should handle it.
511 if (winToScroll
== srcWin
|| winToScroll
== disassemWin
)
512 tuiHorizontalSourceScroll (winToScroll
, LEFT_SCROLL
, _numToScroll
);
515 } /* tuiScrollLeft */
522 tuiScrollRight (TuiWinInfoPtr winToScroll
, int numToScroll
)
524 if (winToScroll
!= cmdWin
)
526 int _numToScroll
= numToScroll
;
528 if (_numToScroll
== 0)
531 ** If we are scrolling the source or disassembly window, do a
532 ** "psuedo" scroll since not all of the source is in memory,
533 ** only what is in the viewport. If winToScroll is the
534 ** command window do nothing since the term should handle it.
536 if (winToScroll
== srcWin
|| winToScroll
== disassemWin
)
537 tuiHorizontalSourceScroll (winToScroll
, RIGHT_SCROLL
, _numToScroll
);
540 } /* tuiScrollRight */
545 ** Scroll a window. Arguments are passed through a va_list.
548 tui_scroll (TuiScrollDirection direction
,
549 TuiWinInfoPtr winToScroll
,
555 tuiScrollForward (winToScroll
, numToScroll
);
557 case BACKWARD_SCROLL
:
558 tuiScrollBackward (winToScroll
, numToScroll
);
561 tuiScrollLeft (winToScroll
, numToScroll
);
564 tuiScrollRight (winToScroll
, numToScroll
);
580 clearok (curscr
, TRUE
);
581 refreshAll (winList
);
582 for (type
= SRC_WIN
; type
< MAX_MAJOR_WINDOWS
; type
++)
584 if (winList
[type
] && winList
[type
]->generic
.isVisible
)
590 tuiClearWin (&winList
[type
]->generic
);
591 if (winList
[type
]->detail
.sourceInfo
.hasLocator
)
592 tuiClearLocatorDisplay ();
593 tuiShowSourceContent (winList
[type
]);
594 checkAndDisplayHighlightIfNeeded (winList
[type
]);
595 tuiEraseExecInfoContent (winList
[type
]);
596 tuiUpdateExecInfo (winList
[type
]);
599 tuiRefreshDataWin ();
606 tuiClearLocatorDisplay ();
607 tuiShowLocatorContent ();
610 } /* tuiRefreshAll */
615 ** Resize all the windows based on the the terminal size. This
616 ** function gets called from within the readline sinwinch handler.
621 int heightDiff
, widthDiff
;
622 extern int screenheight
, screenwidth
; /* in readline */
624 widthDiff
= screenwidth
- termWidth ();
625 heightDiff
= screenheight
- termHeight ();
626 if (heightDiff
|| widthDiff
)
628 TuiLayoutType curLayout
= currentLayout ();
629 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
630 TuiWinInfoPtr firstWin
, secondWin
;
631 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
633 int i
, newHeight
, splitDiff
, cmdSplitDiff
, numWinsDisplayed
= 2;
635 /* turn keypad off while we resize */
636 if (winWithFocus
!= cmdWin
)
637 keypad (cmdWin
->generic
.handle
, FALSE
);
639 setTermHeightTo (screenheight
);
640 setTermWidthTo (screenwidth
);
641 if (curLayout
== SRC_DISASSEM_COMMAND
||
642 curLayout
== SRC_DATA_COMMAND
|| curLayout
== DISASSEM_DATA_COMMAND
)
644 splitDiff
= heightDiff
/ numWinsDisplayed
;
645 cmdSplitDiff
= splitDiff
;
646 if (heightDiff
% numWinsDisplayed
)
653 /* now adjust each window */
659 case DISASSEM_COMMAND
:
660 firstWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
661 firstWin
->generic
.width
+= widthDiff
;
662 locator
->width
+= widthDiff
;
663 /* check for invalid heights */
665 newHeight
= firstWin
->generic
.height
;
666 else if ((firstWin
->generic
.height
+ splitDiff
) >=
667 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
668 newHeight
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
669 else if ((firstWin
->generic
.height
+ splitDiff
) <= 0)
670 newHeight
= MIN_WIN_HEIGHT
;
672 newHeight
= firstWin
->generic
.height
+ splitDiff
;
674 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
675 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
676 cmdWin
->generic
.width
+= widthDiff
;
677 newHeight
= screenheight
- cmdWin
->generic
.origin
.y
;
678 _makeInvisibleAndSetNewHeight (cmdWin
, newHeight
);
679 _makeVisibleWithNewHeight (firstWin
);
680 _makeVisibleWithNewHeight (cmdWin
);
681 if (firstWin
->generic
.contentSize
<= 0)
682 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
685 if (curLayout
== SRC_DISASSEM_COMMAND
)
688 firstWin
->generic
.width
+= widthDiff
;
689 secondWin
= disassemWin
;
690 secondWin
->generic
.width
+= widthDiff
;
695 firstWin
->generic
.width
+= widthDiff
;
696 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
697 secondWin
->generic
.width
+= widthDiff
;
699 /* Change the first window's height/width */
700 /* check for invalid heights */
702 newHeight
= firstWin
->generic
.height
;
703 else if ((firstWin
->generic
.height
+
704 secondWin
->generic
.height
+ (splitDiff
* 2)) >=
705 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
706 newHeight
= (screenheight
- MIN_CMD_WIN_HEIGHT
- 1) / 2;
707 else if ((firstWin
->generic
.height
+ splitDiff
) <= 0)
708 newHeight
= MIN_WIN_HEIGHT
;
710 newHeight
= firstWin
->generic
.height
+ splitDiff
;
711 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
713 if (firstWin
== dataWin
&& widthDiff
!= 0)
714 firstWin
->detail
.dataDisplayInfo
.regsColumnCount
=
715 tuiCalculateRegsColumnCount (
716 firstWin
->detail
.dataDisplayInfo
.regsDisplayType
);
717 locator
->width
+= widthDiff
;
719 /* Change the second window's height/width */
720 /* check for invalid heights */
722 newHeight
= secondWin
->generic
.height
;
723 else if ((firstWin
->generic
.height
+
724 secondWin
->generic
.height
+ (splitDiff
* 2)) >=
725 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
727 newHeight
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
729 newHeight
= (newHeight
/ 2) + 1;
733 else if ((secondWin
->generic
.height
+ splitDiff
) <= 0)
734 newHeight
= MIN_WIN_HEIGHT
;
736 newHeight
= secondWin
->generic
.height
+ splitDiff
;
737 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
738 _makeInvisibleAndSetNewHeight (secondWin
, newHeight
);
740 /* Change the command window's height/width */
741 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
742 _makeInvisibleAndSetNewHeight (
743 cmdWin
, cmdWin
->generic
.height
+ cmdSplitDiff
);
744 _makeVisibleWithNewHeight (firstWin
);
745 _makeVisibleWithNewHeight (secondWin
);
746 _makeVisibleWithNewHeight (cmdWin
);
747 if (firstWin
->generic
.contentSize
<= 0)
748 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
749 if (secondWin
->generic
.contentSize
<= 0)
750 tuiEraseSourceContent (secondWin
, EMPTY_SOURCE_PROMPT
);
754 ** Now remove all invisible windows, and their content so that they get
755 ** created again when called for with the new size
757 for (winType
= SRC_WIN
; (winType
< MAX_MAJOR_WINDOWS
); winType
++)
759 if (winType
!= CMD_WIN
&& m_winPtrNotNull (winList
[winType
]) &&
760 !winList
[winType
]->generic
.isVisible
)
762 freeWindow (winList
[winType
]);
763 winList
[winType
] = (TuiWinInfoPtr
) NULL
;
766 tuiSetWinResizedTo (TRUE
);
767 /* turn keypad back on, unless focus is in the command window */
768 if (winWithFocus
!= cmdWin
)
769 keypad (cmdWin
->generic
.handle
, TRUE
);
776 ** tuiSigwinchHandler()
777 ** SIGWINCH signal handler for the tui. This signal handler is
778 ** always called, even when the readline package clears signals
779 ** because it is set as the old_sigwinch() (TUI only)
782 tuiSigwinchHandler (int signal
)
785 ** Say that a resize was done so that the readline can do it
786 ** later when appropriate.
788 tuiSetWinResizedTo (TRUE
);
791 } /* tuiSigwinchHandler */
795 /*************************
796 ** STATIC LOCAL FUNCTIONS
797 **************************/
801 ** _tuiScrollForward_command().
804 _tuiScrollForward_command (char *arg
, int fromTTY
)
807 TuiWinInfoPtr winToScroll
;
809 /* Make sure the curses mode is enabled. */
811 if (arg
== (char *) NULL
)
812 _parseScrollingArgs (arg
, &winToScroll
, (int *) NULL
);
814 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
815 tui_scroll (FORWARD_SCROLL
, winToScroll
, numToScroll
);
820 ** _tuiScrollBackward_command().
823 _tuiScrollBackward_command (char *arg
, int fromTTY
)
826 TuiWinInfoPtr winToScroll
;
828 /* Make sure the curses mode is enabled. */
830 if (arg
== (char *) NULL
)
831 _parseScrollingArgs (arg
, &winToScroll
, (int *) NULL
);
833 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
834 tui_scroll (BACKWARD_SCROLL
, winToScroll
, numToScroll
);
839 ** _tuiScrollLeft_command().
842 _tuiScrollLeft_command (char *arg
, int fromTTY
)
845 TuiWinInfoPtr winToScroll
;
847 /* Make sure the curses mode is enabled. */
849 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
850 tui_scroll (LEFT_SCROLL
, winToScroll
, numToScroll
);
855 ** _tuiScrollRight_command().
858 _tuiScrollRight_command (char *arg
, int fromTTY
)
861 TuiWinInfoPtr winToScroll
;
863 /* Make sure the curses mode is enabled. */
865 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
866 tui_scroll (RIGHT_SCROLL
, winToScroll
, numToScroll
);
872 ** Set focus to the window named by 'arg'
875 _tuiSetFocus (char *arg
, int fromTTY
)
877 if (arg
!= (char *) NULL
)
879 char *bufPtr
= (char *) xstrdup (arg
);
881 TuiWinInfoPtr winInfo
= (TuiWinInfoPtr
) NULL
;
883 for (i
= 0; (i
< strlen (bufPtr
)); i
++)
884 bufPtr
[i
] = toupper (arg
[i
]);
886 if (subset_compare (bufPtr
, "NEXT"))
887 winInfo
= tuiNextWin (tuiWinWithFocus ());
888 else if (subset_compare (bufPtr
, "PREV"))
889 winInfo
= tuiPrevWin (tuiWinWithFocus ());
891 winInfo
= partialWinByName (bufPtr
);
893 if (winInfo
== (TuiWinInfoPtr
) NULL
|| !winInfo
->generic
.isVisible
)
894 warning ("Invalid window specified. \n\
895 The window name specified must be valid and visible.\n");
898 tuiSetWinFocusTo (winInfo
);
899 keypad (cmdWin
->generic
.handle
, (winInfo
!= cmdWin
));
902 if (dataWin
&& dataWin
->generic
.isVisible
)
903 tuiRefreshDataWin ();
905 printf_filtered ("Focus set to %s window.\n",
906 winName ((TuiGenWinInfoPtr
) tuiWinWithFocus ()));
909 warning ("Incorrect Number of Arguments.\n%s", FOCUS_USAGE
);
915 ** _tuiSetFocus_command()
918 _tuiSetFocus_command (char *arg
, int fromTTY
)
920 /* Make sure the curses mode is enabled. */
922 _tuiSetFocus (arg
, fromTTY
);
927 ** _tuiAllWindowsInfo().
930 _tuiAllWindowsInfo (char *arg
, int fromTTY
)
933 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
935 for (type
= SRC_WIN
; (type
< MAX_MAJOR_WINDOWS
); type
++)
936 if (winList
[type
]->generic
.isVisible
)
938 if (winWithFocus
== winList
[type
])
939 printf_filtered (" %s\t(%d lines) <has focus>\n",
940 winName (&winList
[type
]->generic
),
941 winList
[type
]->generic
.height
);
943 printf_filtered (" %s\t(%d lines)\n",
944 winName (&winList
[type
]->generic
),
945 winList
[type
]->generic
.height
);
949 } /* _tuiAllWindowsInfo */
953 ** _tuiRefreshAll_command().
956 _tuiRefreshAll_command (char *arg
, int fromTTY
)
958 /* Make sure the curses mode is enabled. */
966 ** _tuiSetWinTabWidth_command().
967 ** Set the height of the specified window.
970 _tuiSetTabWidth_command (char *arg
, int fromTTY
)
972 /* Make sure the curses mode is enabled. */
974 if (arg
!= (char *) NULL
)
980 tuiSetDefaultTabLen (ts
);
982 warning ("Tab widths greater than 0 must be specified.\n");
986 } /* _tuiSetTabWidth_command */
990 ** _tuiSetWinHeight().
991 ** Set the height of the specified window.
994 _tuiSetWinHeight (char *arg
, int fromTTY
)
996 /* Make sure the curses mode is enabled. */
998 if (arg
!= (char *) NULL
)
1000 char *buf
= xstrdup (arg
);
1002 char *wname
= (char *) NULL
;
1004 TuiWinInfoPtr winInfo
;
1007 bufPtr
= strchr (bufPtr
, ' ');
1008 if (bufPtr
!= (char *) NULL
)
1013 ** Validate the window name
1015 for (i
= 0; i
< strlen (wname
); i
++)
1016 wname
[i
] = toupper (wname
[i
]);
1017 winInfo
= partialWinByName (wname
);
1019 if (winInfo
== (TuiWinInfoPtr
) NULL
|| !winInfo
->generic
.isVisible
)
1020 warning ("Invalid window specified. \n\
1021 The window name specified must be valid and visible.\n");
1024 /* Process the size */
1025 while (*(++bufPtr
) == ' ')
1028 if (*bufPtr
!= (char) 0)
1031 int fixedSize
= TRUE
;
1034 if (*bufPtr
== '+' || *bufPtr
== '-')
1041 inputNo
= atoi (bufPtr
);
1047 newHeight
= inputNo
;
1049 newHeight
= winInfo
->generic
.height
+ inputNo
;
1051 ** Now change the window's height, and adjust all
1052 ** other windows around it
1054 if (_tuiAdjustWinHeights (winInfo
,
1055 newHeight
) == TUI_FAILURE
)
1056 warning ("Invalid window height specified.\n%s",
1062 warning ("Invalid window height specified.\n%s",
1068 printf_filtered (WIN_HEIGHT_USAGE
);
1070 if (buf
!= (char *) NULL
)
1074 printf_filtered (WIN_HEIGHT_USAGE
);
1077 } /* _tuiSetWinHeight */
1080 ** _tuiSetWinHeight_command().
1081 ** Set the height of the specified window, with va_list.
1084 _tuiSetWinHeight_command (char *arg
, int fromTTY
)
1086 /* Make sure the curses mode is enabled. */
1088 _tuiSetWinHeight (arg
, fromTTY
);
1093 ** _tuiXDBsetWinHeight().
1094 ** XDB Compatibility command for setting the window height. This will
1095 ** increase or decrease the command window by the specified amount.
1098 _tuiXDBsetWinHeight (char *arg
, int fromTTY
)
1100 /* Make sure the curses mode is enabled. */
1102 if (arg
!= (char *) NULL
)
1104 int inputNo
= atoi (arg
);
1107 { /* Add 1 for the locator */
1108 int newHeight
= termHeight () - (inputNo
+ 1);
1110 if (!_newHeightOk (winList
[CMD_WIN
], newHeight
) ||
1111 _tuiAdjustWinHeights (winList
[CMD_WIN
],
1112 newHeight
) == TUI_FAILURE
)
1113 warning ("Invalid window height specified.\n%s",
1114 XDBWIN_HEIGHT_USAGE
);
1117 warning ("Invalid window height specified.\n%s",
1118 XDBWIN_HEIGHT_USAGE
);
1121 warning ("Invalid window height specified.\n%s", XDBWIN_HEIGHT_USAGE
);
1124 } /* _tuiXDBsetWinHeight */
1127 ** _tuiSetWinHeight_command().
1128 ** Set the height of the specified window, with va_list.
1131 _tuiXDBsetWinHeight_command (char *arg
, int fromTTY
)
1133 _tuiXDBsetWinHeight (arg
, fromTTY
);
1138 ** _tuiAdjustWinHeights().
1139 ** Function to adjust all window heights around the primary
1142 _tuiAdjustWinHeights (TuiWinInfoPtr primaryWinInfo
, int newHeight
)
1144 TuiStatus status
= TUI_FAILURE
;
1146 if (_newHeightOk (primaryWinInfo
, newHeight
))
1148 status
= TUI_SUCCESS
;
1149 if (newHeight
!= primaryWinInfo
->generic
.height
)
1152 TuiWinInfoPtr winInfo
;
1153 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
1154 TuiLayoutType curLayout
= currentLayout ();
1156 diff
= (newHeight
- primaryWinInfo
->generic
.height
) * (-1);
1157 if (curLayout
== SRC_COMMAND
|| curLayout
== DISASSEM_COMMAND
)
1159 TuiWinInfoPtr srcWinInfo
;
1161 _makeInvisibleAndSetNewHeight (primaryWinInfo
, newHeight
);
1162 if (primaryWinInfo
->generic
.type
== CMD_WIN
)
1164 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1165 srcWinInfo
= winInfo
;
1169 winInfo
= winList
[CMD_WIN
];
1170 srcWinInfo
= primaryWinInfo
;
1172 _makeInvisibleAndSetNewHeight (winInfo
,
1173 winInfo
->generic
.height
+ diff
);
1174 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1175 _makeVisibleWithNewHeight (winInfo
);
1176 _makeVisibleWithNewHeight (primaryWinInfo
);
1177 if (srcWinInfo
->generic
.contentSize
<= 0)
1178 tuiEraseSourceContent (srcWinInfo
, EMPTY_SOURCE_PROMPT
);
1182 TuiWinInfoPtr firstWin
, secondWin
;
1184 if (curLayout
== SRC_DISASSEM_COMMAND
)
1187 secondWin
= disassemWin
;
1192 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1194 if (primaryWinInfo
== cmdWin
)
1196 ** Split the change in height accross the 1st & 2nd windows
1197 ** adjusting them as well.
1199 int firstSplitDiff
= diff
/ 2; /* subtract the locator */
1200 int secondSplitDiff
= firstSplitDiff
;
1204 if (firstWin
->generic
.height
>
1205 secondWin
->generic
.height
)
1218 /* make sure that the minimum hieghts are honored */
1219 while ((firstWin
->generic
.height
+ firstSplitDiff
) < 3)
1224 while ((secondWin
->generic
.height
+ secondSplitDiff
) < 3)
1229 _makeInvisibleAndSetNewHeight (
1231 firstWin
->generic
.height
+ firstSplitDiff
);
1232 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
1233 _makeInvisibleAndSetNewHeight (
1234 secondWin
, secondWin
->generic
.height
+ secondSplitDiff
);
1235 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1236 _makeInvisibleAndSetNewHeight (cmdWin
, newHeight
);
1240 if ((cmdWin
->generic
.height
+ diff
) < 1)
1242 ** If there is no way to increase the command window
1243 ** take real estate from the 1st or 2nd window.
1245 if ((cmdWin
->generic
.height
+ diff
) < 1)
1248 for (i
= cmdWin
->generic
.height
+ diff
;
1250 if (primaryWinInfo
== firstWin
)
1251 secondWin
->generic
.height
--;
1253 firstWin
->generic
.height
--;
1256 if (primaryWinInfo
== firstWin
)
1257 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
1259 _makeInvisibleAndSetNewHeight (
1261 firstWin
->generic
.height
);
1262 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
1263 if (primaryWinInfo
== secondWin
)
1264 _makeInvisibleAndSetNewHeight (secondWin
, newHeight
);
1266 _makeInvisibleAndSetNewHeight (
1267 secondWin
, secondWin
->generic
.height
);
1268 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1269 if ((cmdWin
->generic
.height
+ diff
) < 1)
1270 _makeInvisibleAndSetNewHeight (cmdWin
, 1);
1272 _makeInvisibleAndSetNewHeight (
1273 cmdWin
, cmdWin
->generic
.height
+ diff
);
1275 _makeVisibleWithNewHeight (cmdWin
);
1276 _makeVisibleWithNewHeight (secondWin
);
1277 _makeVisibleWithNewHeight (firstWin
);
1278 if (firstWin
->generic
.contentSize
<= 0)
1279 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
1280 if (secondWin
->generic
.contentSize
<= 0)
1281 tuiEraseSourceContent (secondWin
, EMPTY_SOURCE_PROMPT
);
1287 } /* _tuiAdjustWinHeights */
1291 ** _makeInvisibleAndSetNewHeight().
1292 ** Function make the target window (and auxillary windows associated
1293 ** with the targer) invisible, and set the new height and location.
1296 _makeInvisibleAndSetNewHeight (TuiWinInfoPtr winInfo
, int height
)
1300 TuiGenWinInfoPtr genWinInfo
;
1303 m_beInvisible (&winInfo
->generic
);
1304 winInfo
->generic
.height
= height
;
1306 winInfo
->generic
.viewportHeight
= height
- 1;
1308 winInfo
->generic
.viewportHeight
= height
;
1309 if (winInfo
!= cmdWin
)
1310 winInfo
->generic
.viewportHeight
--;
1312 /* Now deal with the auxillary windows associated with winInfo */
1313 switch (winInfo
->generic
.type
)
1317 genWinInfo
= winInfo
->detail
.sourceInfo
.executionInfo
;
1318 m_beInvisible (genWinInfo
);
1319 genWinInfo
->height
= height
;
1320 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
;
1322 genWinInfo
->viewportHeight
= height
- 1;
1324 genWinInfo
->viewportHeight
= height
;
1325 if (winInfo
!= cmdWin
)
1326 genWinInfo
->viewportHeight
--;
1328 if (m_hasLocator (winInfo
))
1330 genWinInfo
= locatorWinInfoPtr ();
1331 m_beInvisible (genWinInfo
);
1332 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
+ height
;
1336 /* delete all data item windows */
1337 for (i
= 0; i
< winInfo
->generic
.contentSize
; i
++)
1339 genWinInfo
= (TuiGenWinInfoPtr
) & ((TuiWinElementPtr
)
1340 winInfo
->generic
.content
[i
])->whichElement
.dataWindow
;
1341 tuiDelwin (genWinInfo
->handle
);
1342 genWinInfo
->handle
= (WINDOW
*) NULL
;
1350 } /* _makeInvisibleAndSetNewHeight */
1354 ** _makeVisibleWithNewHeight().
1355 ** Function to make the windows with new heights visible.
1356 ** This means re-creating the windows' content since the window
1357 ** had to be destroyed to be made invisible.
1360 _makeVisibleWithNewHeight (TuiWinInfoPtr winInfo
)
1365 m_beVisible (&winInfo
->generic
);
1366 checkAndDisplayHighlightIfNeeded (winInfo
);
1367 switch (winInfo
->generic
.type
)
1371 freeWinContent (winInfo
->detail
.sourceInfo
.executionInfo
);
1372 m_beVisible (winInfo
->detail
.sourceInfo
.executionInfo
);
1373 if (winInfo
->generic
.content
!= (OpaquePtr
) NULL
)
1375 TuiLineOrAddress lineOrAddr
;
1377 if (winInfo
->generic
.type
== SRC_WIN
)
1379 winInfo
->detail
.sourceInfo
.startLineOrAddr
.lineNo
;
1382 winInfo
->detail
.sourceInfo
.startLineOrAddr
.addr
;
1383 freeWinContent (&winInfo
->generic
);
1384 tuiUpdateSourceWindow (winInfo
,
1385 current_source_symtab
, lineOrAddr
, TRUE
);
1387 else if (selected_frame
!= (struct frame_info
*) NULL
)
1389 TuiLineOrAddress line
;
1390 extern int current_source_line
;
1392 s
= find_pc_symtab (selected_frame
->pc
);
1393 if (winInfo
->generic
.type
== SRC_WIN
)
1394 line
.lineNo
= current_source_line
;
1397 find_line_pc (s
, current_source_line
, &line
.addr
);
1399 tuiUpdateSourceWindow (winInfo
, s
, line
, TRUE
);
1401 if (m_hasLocator (winInfo
))
1403 m_beVisible (locatorWinInfoPtr ());
1404 tuiClearLocatorDisplay ();
1405 tuiShowLocatorContent ();
1409 tuiDisplayAllData ();
1412 winInfo
->detail
.commandInfo
.curLine
= 0;
1413 winInfo
->detail
.commandInfo
.curch
= 0;
1414 wmove (winInfo
->generic
.handle
,
1415 winInfo
->detail
.commandInfo
.curLine
,
1416 winInfo
->detail
.commandInfo
.curch
);
1423 } /* _makeVisibleWithNewHeight */
1427 _newHeightOk (TuiWinInfoPtr primaryWinInfo
, int newHeight
)
1429 int ok
= (newHeight
< termHeight ());
1433 int diff
, curHeight
;
1434 TuiLayoutType curLayout
= currentLayout ();
1436 diff
= (newHeight
- primaryWinInfo
->generic
.height
) * (-1);
1437 if (curLayout
== SRC_COMMAND
|| curLayout
== DISASSEM_COMMAND
)
1439 ok
= ((primaryWinInfo
->generic
.type
== CMD_WIN
&&
1440 newHeight
<= (termHeight () - 4) &&
1441 newHeight
>= MIN_CMD_WIN_HEIGHT
) ||
1442 (primaryWinInfo
->generic
.type
!= CMD_WIN
&&
1443 newHeight
<= (termHeight () - 2) &&
1444 newHeight
>= MIN_WIN_HEIGHT
));
1446 { /* check the total height */
1447 TuiWinInfoPtr winInfo
;
1449 if (primaryWinInfo
== cmdWin
)
1450 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1454 (winInfo
->generic
.height
+ diff
)) <= termHeight ());
1459 int curTotalHeight
, totalHeight
, minHeight
;
1460 TuiWinInfoPtr firstWin
, secondWin
;
1462 if (curLayout
== SRC_DISASSEM_COMMAND
)
1465 secondWin
= disassemWin
;
1470 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1473 ** We could simply add all the heights to obtain the same result
1474 ** but below is more explicit since we subtract 1 for the
1475 ** line that the first and second windows share, and add one
1479 (firstWin
->generic
.height
+ secondWin
->generic
.height
- 1)
1480 + cmdWin
->generic
.height
+ 1 /*locator */ ;
1481 if (primaryWinInfo
== cmdWin
)
1483 /* locator included since first & second win share a line */
1484 ok
= ((firstWin
->generic
.height
+
1485 secondWin
->generic
.height
+ diff
) >=
1486 (MIN_WIN_HEIGHT
* 2) &&
1487 newHeight
>= MIN_CMD_WIN_HEIGHT
);
1490 totalHeight
= newHeight
+ (firstWin
->generic
.height
+
1491 secondWin
->generic
.height
+ diff
);
1492 minHeight
= MIN_CMD_WIN_HEIGHT
;
1497 minHeight
= MIN_WIN_HEIGHT
;
1499 ** First see if we can increase/decrease the command
1500 ** window. And make sure that the command window is
1503 ok
= ((cmdWin
->generic
.height
+ diff
) > 0);
1506 ** Looks like we have to increase/decrease one of
1507 ** the other windows
1509 if (primaryWinInfo
== firstWin
)
1510 ok
= (secondWin
->generic
.height
+ diff
) >= minHeight
;
1512 ok
= (firstWin
->generic
.height
+ diff
) >= minHeight
;
1516 if (primaryWinInfo
== firstWin
)
1517 totalHeight
= newHeight
+
1518 secondWin
->generic
.height
+
1519 cmdWin
->generic
.height
+ diff
;
1521 totalHeight
= newHeight
+
1522 firstWin
->generic
.height
+
1523 cmdWin
->generic
.height
+ diff
;
1527 ** Now make sure that the proposed total height doesn't exceed
1528 ** the old total height.
1531 ok
= (newHeight
>= minHeight
&& totalHeight
<= curTotalHeight
);
1536 } /* _newHeightOk */
1540 ** _parseScrollingArgs().
1543 _parseScrollingArgs (char *arg
, TuiWinInfoPtr
* winToScroll
, int *numToScroll
)
1547 *winToScroll
= tuiWinWithFocus ();
1550 ** First set up the default window to scroll, in case there is no
1553 if (arg
!= (char *) NULL
)
1557 /* process the number of lines to scroll */
1558 buf
= bufPtr
= xstrdup (arg
);
1559 if (isdigit (*bufPtr
))
1564 bufPtr
= strchr (bufPtr
, ' ');
1565 if (bufPtr
!= (char *) NULL
)
1569 *numToScroll
= atoi (numStr
);
1572 else if (numToScroll
)
1573 *numToScroll
= atoi (numStr
);
1576 /* process the window name if one is specified */
1577 if (bufPtr
!= (char *) NULL
)
1583 while (*(++bufPtr
) == ' ')
1586 if (*bufPtr
!= (char) 0)
1591 /* Validate the window name */
1592 for (i
= 0; i
< strlen (wname
); i
++)
1593 wname
[i
] = toupper (wname
[i
]);
1594 *winToScroll
= partialWinByName (wname
);
1596 if (*winToScroll
== (TuiWinInfoPtr
) NULL
||
1597 !(*winToScroll
)->generic
.isVisible
)
1598 warning ("Invalid window specified. \n\
1599 The window name specified must be valid and visible.\n");
1600 else if (*winToScroll
== cmdWin
)
1601 *winToScroll
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1607 } /* _parseScrollingArgs */