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 ***************************************/
83 ** _initialize_tuiWin().
84 ** Function to initialize gdb commands, for tui window manipulation.
87 _initialize_tuiWin (void)
89 /* Define the classes of commands.
90 They will appear in the help list in the reverse of this order. */
92 add_cmd ("tui", class_tui
, NO_FUNCTION
,
93 "Text User Interface commands.",
96 add_com ("refresh", class_tui
, _tuiRefreshAll_command
,
97 "Refresh the terminal display.\n");
99 add_com_alias ("U", "refresh", class_tui
, 0);
100 add_com ("tabset", class_tui
, _tuiSetTabWidth_command
,
101 "Set the width (in characters) of tab stops.\n\
102 Usage: tabset <n>\n");
103 add_com ("winheight", class_tui
, _tuiSetWinHeight_command
,
104 "Set the height of a specified window.\n\
105 Usage: winheight <win_name> [+ | -] <#lines>\n\
107 src : the source window\n\
108 cmd : the command window\n\
109 asm : the disassembly window\n\
110 regs : the register display\n");
111 add_com_alias ("wh", "winheight", class_tui
, 0);
112 add_info ("win", _tuiAllWindowsInfo
,
113 "List of all displayed windows.\n");
114 add_com ("focus", class_tui
, _tuiSetFocus_command
,
115 "Set focus to named window or next/prev window.\n\
116 Usage: focus {<win> | next | prev}\n\
117 Valid Window names are:\n\
118 src : the source window\n\
119 asm : the disassembly window\n\
120 regs : the register display\n\
121 cmd : the command window\n");
122 add_com_alias ("fs", "focus", class_tui
, 0);
123 add_com ("+", class_tui
, _tuiScrollForward_command
,
124 "Scroll window forward.\nUsage: + [win] [n]\n");
125 add_com ("-", class_tui
, _tuiScrollBackward_command
,
126 "Scroll window backward.\nUsage: - [win] [n]\n");
127 add_com ("<", class_tui
, _tuiScrollLeft_command
,
128 "Scroll window forward.\nUsage: < [win] [n]\n");
129 add_com (">", class_tui
, _tuiScrollRight_command
,
130 "Scroll window backward.\nUsage: > [win] [n]\n");
132 add_com ("w", class_xdb
, _tuiXDBsetWinHeight_command
,
133 "XDB compatibility command for setting the height of a command window.\n\
134 Usage: w <#lines>\n");
139 ** tuiClearWinFocusFrom
140 ** Clear the logical focus from winInfo
143 tuiClearWinFocusFrom (TuiWinInfoPtr winInfo
)
145 if (m_winPtrNotNull (winInfo
))
147 if (winInfo
->generic
.type
!= CMD_WIN
)
148 unhighlightWin (winInfo
);
149 tuiSetWinWithFocus ((TuiWinInfoPtr
) NULL
);
153 } /* tuiClearWinFocusFrom */
157 ** tuiClearWinFocus().
158 ** Clear the window that has focus.
161 tuiClearWinFocus (void)
163 tuiClearWinFocusFrom (tuiWinWithFocus ());
166 } /* tuiClearWinFocus */
171 ** Set the logical focus to winInfo
174 tuiSetWinFocusTo (TuiWinInfoPtr winInfo
)
176 if (m_winPtrNotNull (winInfo
))
178 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
180 if (m_winPtrNotNull (winWithFocus
) &&
181 winWithFocus
->generic
.type
!= CMD_WIN
)
182 unhighlightWin (winWithFocus
);
183 tuiSetWinWithFocus (winInfo
);
184 if (winInfo
->generic
.type
!= CMD_WIN
)
185 highlightWin (winInfo
);
189 } /* tuiSetWinFocusTo */
193 tuiStrDup (char *str
)
195 char *newStr
= (char *) NULL
;
197 if (str
!= (char *) NULL
)
199 newStr
= (char *) xmalloc (strlen (str
) + 1);
200 strcpy (newStr
, str
);
208 ** tuiScrollForward().
211 tuiScrollForward (TuiWinInfoPtr winToScroll
, int numToScroll
)
213 if (winToScroll
!= cmdWin
)
215 int _numToScroll
= numToScroll
;
217 if (numToScroll
== 0)
218 _numToScroll
= winToScroll
->generic
.height
- 3;
220 ** If we are scrolling the source or disassembly window, do a
221 ** "psuedo" scroll since not all of the source is in memory,
222 ** only what is in the viewport. If winToScroll is the
223 ** command window do nothing since the term should handle it.
225 if (winToScroll
== srcWin
)
226 tuiVerticalSourceScroll (FORWARD_SCROLL
, _numToScroll
);
227 else if (winToScroll
== disassemWin
)
228 tuiVerticalDisassemScroll (FORWARD_SCROLL
, _numToScroll
);
229 else if (winToScroll
== dataWin
)
230 tuiVerticalDataScroll (FORWARD_SCROLL
, _numToScroll
);
234 } /* tuiScrollForward */
238 ** tuiScrollBackward().
241 tuiScrollBackward (TuiWinInfoPtr winToScroll
, int numToScroll
)
243 if (winToScroll
!= cmdWin
)
245 int _numToScroll
= numToScroll
;
247 if (numToScroll
== 0)
248 _numToScroll
= winToScroll
->generic
.height
- 3;
250 ** If we are scrolling the source or disassembly window, do a
251 ** "psuedo" scroll since not all of the source is in memory,
252 ** only what is in the viewport. If winToScroll is the
253 ** command window do nothing since the term should handle it.
255 if (winToScroll
== srcWin
)
256 tuiVerticalSourceScroll (BACKWARD_SCROLL
, _numToScroll
);
257 else if (winToScroll
== disassemWin
)
258 tuiVerticalDisassemScroll (BACKWARD_SCROLL
, _numToScroll
);
259 else if (winToScroll
== dataWin
)
260 tuiVerticalDataScroll (BACKWARD_SCROLL
, _numToScroll
);
263 } /* tuiScrollBackward */
270 tuiScrollLeft (TuiWinInfoPtr winToScroll
, int numToScroll
)
272 if (winToScroll
!= cmdWin
)
274 int _numToScroll
= numToScroll
;
276 if (_numToScroll
== 0)
279 ** If we are scrolling the source or disassembly window, do a
280 ** "psuedo" scroll since not all of the source is in memory,
281 ** only what is in the viewport. If winToScroll is the
282 ** command window do nothing since the term should handle it.
284 if (winToScroll
== srcWin
|| winToScroll
== disassemWin
)
285 tuiHorizontalSourceScroll (winToScroll
, LEFT_SCROLL
, _numToScroll
);
288 } /* tuiScrollLeft */
295 tuiScrollRight (TuiWinInfoPtr winToScroll
, int numToScroll
)
297 if (winToScroll
!= cmdWin
)
299 int _numToScroll
= numToScroll
;
301 if (_numToScroll
== 0)
304 ** If we are scrolling the source or disassembly window, do a
305 ** "psuedo" scroll since not all of the source is in memory,
306 ** only what is in the viewport. If winToScroll is the
307 ** command window do nothing since the term should handle it.
309 if (winToScroll
== srcWin
|| winToScroll
== disassemWin
)
310 tuiHorizontalSourceScroll (winToScroll
, RIGHT_SCROLL
, _numToScroll
);
313 } /* tuiScrollRight */
318 ** Scroll a window. Arguments are passed through a va_list.
321 tui_scroll (TuiScrollDirection direction
,
322 TuiWinInfoPtr winToScroll
,
328 tuiScrollForward (winToScroll
, numToScroll
);
330 case BACKWARD_SCROLL
:
331 tuiScrollBackward (winToScroll
, numToScroll
);
334 tuiScrollLeft (winToScroll
, numToScroll
);
337 tuiScrollRight (winToScroll
, numToScroll
);
353 refreshAll (winList
);
354 for (type
= SRC_WIN
; type
< MAX_MAJOR_WINDOWS
; type
++)
356 if (winList
[type
] && winList
[type
]->generic
.isVisible
)
362 tuiClearWin (&winList
[type
]->generic
);
363 if (winList
[type
]->detail
.sourceInfo
.hasLocator
)
364 tuiClearLocatorDisplay ();
365 tuiShowSourceContent (winList
[type
]);
366 checkAndDisplayHighlightIfNeeded (winList
[type
]);
367 tuiEraseExecInfoContent (winList
[type
]);
368 tuiUpdateExecInfo (winList
[type
]);
371 tuiRefreshDataWin ();
378 tuiClearLocatorDisplay ();
379 tuiShowLocatorContent ();
382 } /* tuiRefreshAll */
387 ** Resize all the windows based on the the terminal size. This
388 ** function gets called from within the readline sinwinch handler.
393 int heightDiff
, widthDiff
;
394 extern int screenheight
, screenwidth
; /* in readline */
396 widthDiff
= screenwidth
- termWidth ();
397 heightDiff
= screenheight
- termHeight ();
398 if (heightDiff
|| widthDiff
)
400 TuiLayoutType curLayout
= currentLayout ();
401 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
402 TuiWinInfoPtr firstWin
, secondWin
;
403 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
405 int i
, newHeight
, splitDiff
, cmdSplitDiff
, numWinsDisplayed
= 2;
407 /* turn keypad off while we resize */
408 if (winWithFocus
!= cmdWin
)
409 keypad (cmdWin
->generic
.handle
, FALSE
);
411 setTermHeightTo (screenheight
);
412 setTermWidthTo (screenwidth
);
413 if (curLayout
== SRC_DISASSEM_COMMAND
||
414 curLayout
== SRC_DATA_COMMAND
|| curLayout
== DISASSEM_DATA_COMMAND
)
416 splitDiff
= heightDiff
/ numWinsDisplayed
;
417 cmdSplitDiff
= splitDiff
;
418 if (heightDiff
% numWinsDisplayed
)
425 /* now adjust each window */
431 case DISASSEM_COMMAND
:
432 firstWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
433 firstWin
->generic
.width
+= widthDiff
;
434 locator
->width
+= widthDiff
;
435 /* check for invalid heights */
437 newHeight
= firstWin
->generic
.height
;
438 else if ((firstWin
->generic
.height
+ splitDiff
) >=
439 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
440 newHeight
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
441 else if ((firstWin
->generic
.height
+ splitDiff
) <= 0)
442 newHeight
= MIN_WIN_HEIGHT
;
444 newHeight
= firstWin
->generic
.height
+ splitDiff
;
446 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
447 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
448 cmdWin
->generic
.width
+= widthDiff
;
449 newHeight
= screenheight
- cmdWin
->generic
.origin
.y
;
450 _makeInvisibleAndSetNewHeight (cmdWin
, newHeight
);
451 _makeVisibleWithNewHeight (firstWin
);
452 _makeVisibleWithNewHeight (cmdWin
);
453 if (firstWin
->generic
.contentSize
<= 0)
454 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
457 if (curLayout
== SRC_DISASSEM_COMMAND
)
460 firstWin
->generic
.width
+= widthDiff
;
461 secondWin
= disassemWin
;
462 secondWin
->generic
.width
+= widthDiff
;
467 firstWin
->generic
.width
+= widthDiff
;
468 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
469 secondWin
->generic
.width
+= widthDiff
;
471 /* Change the first window's height/width */
472 /* check for invalid heights */
474 newHeight
= firstWin
->generic
.height
;
475 else if ((firstWin
->generic
.height
+
476 secondWin
->generic
.height
+ (splitDiff
* 2)) >=
477 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
478 newHeight
= (screenheight
- MIN_CMD_WIN_HEIGHT
- 1) / 2;
479 else if ((firstWin
->generic
.height
+ splitDiff
) <= 0)
480 newHeight
= MIN_WIN_HEIGHT
;
482 newHeight
= firstWin
->generic
.height
+ splitDiff
;
483 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
485 if (firstWin
== dataWin
&& widthDiff
!= 0)
486 firstWin
->detail
.dataDisplayInfo
.regsColumnCount
=
487 tuiCalculateRegsColumnCount (
488 firstWin
->detail
.dataDisplayInfo
.regsDisplayType
);
489 locator
->width
+= widthDiff
;
491 /* Change the second window's height/width */
492 /* check for invalid heights */
494 newHeight
= secondWin
->generic
.height
;
495 else if ((firstWin
->generic
.height
+
496 secondWin
->generic
.height
+ (splitDiff
* 2)) >=
497 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
499 newHeight
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
501 newHeight
= (newHeight
/ 2) + 1;
505 else if ((secondWin
->generic
.height
+ splitDiff
) <= 0)
506 newHeight
= MIN_WIN_HEIGHT
;
508 newHeight
= secondWin
->generic
.height
+ splitDiff
;
509 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
510 _makeInvisibleAndSetNewHeight (secondWin
, newHeight
);
512 /* Change the command window's height/width */
513 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
514 _makeInvisibleAndSetNewHeight (
515 cmdWin
, cmdWin
->generic
.height
+ cmdSplitDiff
);
516 _makeVisibleWithNewHeight (firstWin
);
517 _makeVisibleWithNewHeight (secondWin
);
518 _makeVisibleWithNewHeight (cmdWin
);
519 if (firstWin
->generic
.contentSize
<= 0)
520 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
521 if (secondWin
->generic
.contentSize
<= 0)
522 tuiEraseSourceContent (secondWin
, EMPTY_SOURCE_PROMPT
);
526 ** Now remove all invisible windows, and their content so that they get
527 ** created again when called for with the new size
529 for (winType
= SRC_WIN
; (winType
< MAX_MAJOR_WINDOWS
); winType
++)
531 if (winType
!= CMD_WIN
&& m_winPtrNotNull (winList
[winType
]) &&
532 !winList
[winType
]->generic
.isVisible
)
534 freeWindow (winList
[winType
]);
535 winList
[winType
] = (TuiWinInfoPtr
) NULL
;
538 tuiSetWinResizedTo (TRUE
);
539 /* turn keypad back on, unless focus is in the command window */
540 if (winWithFocus
!= cmdWin
)
541 keypad (cmdWin
->generic
.handle
, TRUE
);
548 ** tuiSigwinchHandler()
549 ** SIGWINCH signal handler for the tui. This signal handler is
550 ** always called, even when the readline package clears signals
551 ** because it is set as the old_sigwinch() (TUI only)
554 tuiSigwinchHandler (int signal
)
557 ** Say that a resize was done so that the readline can do it
558 ** later when appropriate.
560 tuiSetWinResizedTo (TRUE
);
563 } /* tuiSigwinchHandler */
567 /*************************
568 ** STATIC LOCAL FUNCTIONS
569 **************************/
573 ** _tuiScrollForward_command().
576 _tuiScrollForward_command (char *arg
, int fromTTY
)
579 TuiWinInfoPtr winToScroll
;
581 if (arg
== (char *) NULL
)
582 _parseScrollingArgs (arg
, &winToScroll
, (int *) NULL
);
584 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
585 tui_scroll (FORWARD_SCROLL
, winToScroll
, numToScroll
);
590 ** _tuiScrollBackward_command().
593 _tuiScrollBackward_command (char *arg
, int fromTTY
)
596 TuiWinInfoPtr winToScroll
;
598 if (arg
== (char *) NULL
)
599 _parseScrollingArgs (arg
, &winToScroll
, (int *) NULL
);
601 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
602 tui_scroll (BACKWARD_SCROLL
, winToScroll
, numToScroll
);
607 ** _tuiScrollLeft_command().
610 _tuiScrollLeft_command (char *arg
, int fromTTY
)
613 TuiWinInfoPtr winToScroll
;
615 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
616 tui_scroll (LEFT_SCROLL
, winToScroll
, numToScroll
);
621 ** _tuiScrollRight_command().
624 _tuiScrollRight_command (char *arg
, int fromTTY
)
627 TuiWinInfoPtr winToScroll
;
629 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
630 tui_scroll (RIGHT_SCROLL
, winToScroll
, numToScroll
);
636 ** Set focus to the window named by 'arg'
639 _tuiSetFocus (char *arg
, int fromTTY
)
641 if (arg
!= (char *) NULL
)
643 char *bufPtr
= (char *) tuiStrDup (arg
);
645 TuiWinInfoPtr winInfo
= (TuiWinInfoPtr
) NULL
;
647 for (i
= 0; (i
< strlen (bufPtr
)); i
++)
648 bufPtr
[i
] = toupper (arg
[i
]);
650 if (subset_compare (bufPtr
, "NEXT"))
651 winInfo
= tuiNextWin (tuiWinWithFocus ());
652 else if (subset_compare (bufPtr
, "PREV"))
653 winInfo
= tuiPrevWin (tuiWinWithFocus ());
655 winInfo
= partialWinByName (bufPtr
);
657 if (winInfo
== (TuiWinInfoPtr
) NULL
|| !winInfo
->generic
.isVisible
)
658 warning ("Invalid window specified. \n\
659 The window name specified must be valid and visible.\n");
662 tuiSetWinFocusTo (winInfo
);
663 keypad (cmdWin
->generic
.handle
, (winInfo
!= cmdWin
));
666 if (dataWin
&& dataWin
->generic
.isVisible
)
667 tuiRefreshDataWin ();
669 printf_filtered ("Focus set to %s window.\n",
670 winName ((TuiGenWinInfoPtr
) tuiWinWithFocus ()));
673 warning ("Incorrect Number of Arguments.\n%s", FOCUS_USAGE
);
683 _tui_vSetFocus (va_list args
)
685 char *arg
= va_arg (args
, char *);
686 int fromTTY
= va_arg (args
, int);
688 _tuiSetFocus (arg
, fromTTY
);
691 } /* tui_vSetFocus */
695 ** _tuiSetFocus_command()
698 _tuiSetFocus_command (char *arg
, int fromTTY
)
700 _tuiSetFocus (arg
, fromTTY
);
705 ** _tuiAllWindowsInfo().
708 _tuiAllWindowsInfo (char *arg
, int fromTTY
)
711 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
713 for (type
= SRC_WIN
; (type
< MAX_MAJOR_WINDOWS
); type
++)
714 if (winList
[type
]->generic
.isVisible
)
716 if (winWithFocus
== winList
[type
])
717 printf_filtered (" %s\t(%d lines) <has focus>\n",
718 winName (&winList
[type
]->generic
),
719 winList
[type
]->generic
.height
);
721 printf_filtered (" %s\t(%d lines)\n",
722 winName (&winList
[type
]->generic
),
723 winList
[type
]->generic
.height
);
727 } /* _tuiAllWindowsInfo */
731 ** _tuiRefreshAll_command().
734 _tuiRefreshAll_command (char *arg
, int fromTTY
)
741 ** _tuiSetWinTabWidth_command().
742 ** Set the height of the specified window.
745 _tuiSetTabWidth_command (char *arg
, int fromTTY
)
747 if (arg
!= (char *) NULL
)
753 tuiSetDefaultTabLen (ts
);
755 warning ("Tab widths greater than 0 must be specified.\n");
759 } /* _tuiSetTabWidth_command */
763 ** _tuiSetWinHeight().
764 ** Set the height of the specified window.
767 _tuiSetWinHeight (char *arg
, int fromTTY
)
769 if (arg
!= (char *) NULL
)
771 char *buf
= tuiStrDup (arg
);
773 char *wname
= (char *) NULL
;
775 TuiWinInfoPtr winInfo
;
778 bufPtr
= strchr (bufPtr
, ' ');
779 if (bufPtr
!= (char *) NULL
)
784 ** Validate the window name
786 for (i
= 0; i
< strlen (wname
); i
++)
787 wname
[i
] = toupper (wname
[i
]);
788 winInfo
= partialWinByName (wname
);
790 if (winInfo
== (TuiWinInfoPtr
) NULL
|| !winInfo
->generic
.isVisible
)
791 warning ("Invalid window specified. \n\
792 The window name specified must be valid and visible.\n");
795 /* Process the size */
796 while (*(++bufPtr
) == ' ')
799 if (*bufPtr
!= (char) 0)
802 int fixedSize
= TRUE
;
805 if (*bufPtr
== '+' || *bufPtr
== '-')
812 inputNo
= atoi (bufPtr
);
820 newHeight
= winInfo
->generic
.height
+ inputNo
;
822 ** Now change the window's height, and adjust all
823 ** other windows around it
825 if (_tuiAdjustWinHeights (winInfo
,
826 newHeight
) == TUI_FAILURE
)
827 warning ("Invalid window height specified.\n%s",
833 warning ("Invalid window height specified.\n%s",
839 printf_filtered (WIN_HEIGHT_USAGE
);
841 if (buf
!= (char *) NULL
)
845 printf_filtered (WIN_HEIGHT_USAGE
);
848 } /* _tuiSetWinHeight */
852 ** _tui_vSetWinHeight().
853 ** Set the height of the specified window, with va_list.
856 _tui_vSetWinHeight (va_list args
)
858 char *arg
= va_arg (args
, char *);
859 int fromTTY
= va_arg (args
, int);
861 _tuiSetWinHeight (arg
, fromTTY
);
864 } /* _tui_vSetWinHeight */
868 ** _tuiSetWinHeight_command().
869 ** Set the height of the specified window, with va_list.
872 _tuiSetWinHeight_command (char *arg
, int fromTTY
)
874 _tuiSetWinHeight (arg
, fromTTY
);
879 ** _tuiXDBsetWinHeight().
880 ** XDB Compatibility command for setting the window height. This will
881 ** increase or decrease the command window by the specified amount.
884 _tuiXDBsetWinHeight (char *arg
, int fromTTY
)
886 if (arg
!= (char *) NULL
)
888 int inputNo
= atoi (arg
);
891 { /* Add 1 for the locator */
892 int newHeight
= termHeight () - (inputNo
+ 1);
894 if (!_newHeightOk (winList
[CMD_WIN
], newHeight
) ||
895 _tuiAdjustWinHeights (winList
[CMD_WIN
],
896 newHeight
) == TUI_FAILURE
)
897 warning ("Invalid window height specified.\n%s",
898 XDBWIN_HEIGHT_USAGE
);
901 warning ("Invalid window height specified.\n%s",
902 XDBWIN_HEIGHT_USAGE
);
905 warning ("Invalid window height specified.\n%s", XDBWIN_HEIGHT_USAGE
);
908 } /* _tuiXDBsetWinHeight */
912 ** _tui_vXDBsetWinHeight().
913 ** Set the height of the specified window, with va_list.
916 _tui_vXDBsetWinHeight (va_list args
)
918 char *arg
= va_arg (args
, char *);
919 int fromTTY
= va_arg (args
, int);
921 _tuiXDBsetWinHeight (arg
, fromTTY
);
924 } /* _tui_vXDBsetWinHeight */
928 ** _tuiSetWinHeight_command().
929 ** Set the height of the specified window, with va_list.
932 _tuiXDBsetWinHeight_command (char *arg
, int fromTTY
)
934 _tuiXDBsetWinHeight (arg
, fromTTY
);
939 ** _tuiAdjustWinHeights().
940 ** Function to adjust all window heights around the primary
943 _tuiAdjustWinHeights (TuiWinInfoPtr primaryWinInfo
, int newHeight
)
945 TuiStatus status
= TUI_FAILURE
;
947 if (_newHeightOk (primaryWinInfo
, newHeight
))
949 status
= TUI_SUCCESS
;
950 if (newHeight
!= primaryWinInfo
->generic
.height
)
953 TuiWinInfoPtr winInfo
;
954 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
955 TuiLayoutType curLayout
= currentLayout ();
957 diff
= (newHeight
- primaryWinInfo
->generic
.height
) * (-1);
958 if (curLayout
== SRC_COMMAND
|| curLayout
== DISASSEM_COMMAND
)
960 TuiWinInfoPtr srcWinInfo
;
962 _makeInvisibleAndSetNewHeight (primaryWinInfo
, newHeight
);
963 if (primaryWinInfo
->generic
.type
== CMD_WIN
)
965 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
966 srcWinInfo
= winInfo
;
970 winInfo
= winList
[CMD_WIN
];
971 srcWinInfo
= primaryWinInfo
;
973 _makeInvisibleAndSetNewHeight (winInfo
,
974 winInfo
->generic
.height
+ diff
);
975 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
976 _makeVisibleWithNewHeight (winInfo
);
977 _makeVisibleWithNewHeight (primaryWinInfo
);
978 if (srcWinInfo
->generic
.contentSize
<= 0)
979 tuiEraseSourceContent (srcWinInfo
, EMPTY_SOURCE_PROMPT
);
983 TuiWinInfoPtr firstWin
, secondWin
;
985 if (curLayout
== SRC_DISASSEM_COMMAND
)
988 secondWin
= disassemWin
;
993 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
995 if (primaryWinInfo
== cmdWin
)
997 ** Split the change in height accross the 1st & 2nd windows
998 ** adjusting them as well.
1000 int firstSplitDiff
= diff
/ 2; /* subtract the locator */
1001 int secondSplitDiff
= firstSplitDiff
;
1005 if (firstWin
->generic
.height
>
1006 secondWin
->generic
.height
)
1019 /* make sure that the minimum hieghts are honored */
1020 while ((firstWin
->generic
.height
+ firstSplitDiff
) < 3)
1025 while ((secondWin
->generic
.height
+ secondSplitDiff
) < 3)
1030 _makeInvisibleAndSetNewHeight (
1032 firstWin
->generic
.height
+ firstSplitDiff
);
1033 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
1034 _makeInvisibleAndSetNewHeight (
1035 secondWin
, secondWin
->generic
.height
+ secondSplitDiff
);
1036 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1037 _makeInvisibleAndSetNewHeight (cmdWin
, newHeight
);
1041 if ((cmdWin
->generic
.height
+ diff
) < 1)
1043 ** If there is no way to increase the command window
1044 ** take real estate from the 1st or 2nd window.
1046 if ((cmdWin
->generic
.height
+ diff
) < 1)
1049 for (i
= cmdWin
->generic
.height
+ diff
;
1051 if (primaryWinInfo
== firstWin
)
1052 secondWin
->generic
.height
--;
1054 firstWin
->generic
.height
--;
1057 if (primaryWinInfo
== firstWin
)
1058 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
1060 _makeInvisibleAndSetNewHeight (
1062 firstWin
->generic
.height
);
1063 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
1064 if (primaryWinInfo
== secondWin
)
1065 _makeInvisibleAndSetNewHeight (secondWin
, newHeight
);
1067 _makeInvisibleAndSetNewHeight (
1068 secondWin
, secondWin
->generic
.height
);
1069 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1070 if ((cmdWin
->generic
.height
+ diff
) < 1)
1071 _makeInvisibleAndSetNewHeight (cmdWin
, 1);
1073 _makeInvisibleAndSetNewHeight (
1074 cmdWin
, cmdWin
->generic
.height
+ diff
);
1076 _makeVisibleWithNewHeight (cmdWin
);
1077 _makeVisibleWithNewHeight (secondWin
);
1078 _makeVisibleWithNewHeight (firstWin
);
1079 if (firstWin
->generic
.contentSize
<= 0)
1080 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
1081 if (secondWin
->generic
.contentSize
<= 0)
1082 tuiEraseSourceContent (secondWin
, EMPTY_SOURCE_PROMPT
);
1088 } /* _tuiAdjustWinHeights */
1092 ** _makeInvisibleAndSetNewHeight().
1093 ** Function make the target window (and auxillary windows associated
1094 ** with the targer) invisible, and set the new height and location.
1097 _makeInvisibleAndSetNewHeight (TuiWinInfoPtr winInfo
, int height
)
1101 TuiGenWinInfoPtr genWinInfo
;
1104 m_beInvisible (&winInfo
->generic
);
1105 winInfo
->generic
.height
= height
;
1107 winInfo
->generic
.viewportHeight
= height
- 1;
1109 winInfo
->generic
.viewportHeight
= height
;
1110 if (winInfo
!= cmdWin
)
1111 winInfo
->generic
.viewportHeight
--;
1113 /* Now deal with the auxillary windows associated with winInfo */
1114 switch (winInfo
->generic
.type
)
1118 genWinInfo
= winInfo
->detail
.sourceInfo
.executionInfo
;
1119 m_beInvisible (genWinInfo
);
1120 genWinInfo
->height
= height
;
1121 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
;
1123 genWinInfo
->viewportHeight
= height
- 1;
1125 genWinInfo
->viewportHeight
= height
;
1126 if (winInfo
!= cmdWin
)
1127 genWinInfo
->viewportHeight
--;
1129 if (m_hasLocator (winInfo
))
1131 genWinInfo
= locatorWinInfoPtr ();
1132 m_beInvisible (genWinInfo
);
1133 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
+ height
;
1137 /* delete all data item windows */
1138 for (i
= 0; i
< winInfo
->generic
.contentSize
; i
++)
1140 genWinInfo
= (TuiGenWinInfoPtr
) & ((TuiWinElementPtr
)
1141 winInfo
->generic
.content
[i
])->whichElement
.dataWindow
;
1142 tuiDelwin (genWinInfo
->handle
);
1143 genWinInfo
->handle
= (WINDOW
*) NULL
;
1151 } /* _makeInvisibleAndSetNewHeight */
1155 ** _makeVisibleWithNewHeight().
1156 ** Function to make the windows with new heights visible.
1157 ** This means re-creating the windows' content since the window
1158 ** had to be destroyed to be made invisible.
1161 _makeVisibleWithNewHeight (TuiWinInfoPtr winInfo
)
1166 m_beVisible (&winInfo
->generic
);
1167 checkAndDisplayHighlightIfNeeded (winInfo
);
1168 switch (winInfo
->generic
.type
)
1172 freeWinContent (winInfo
->detail
.sourceInfo
.executionInfo
);
1173 m_beVisible (winInfo
->detail
.sourceInfo
.executionInfo
);
1174 if (winInfo
->generic
.content
!= (OpaquePtr
) NULL
)
1176 TuiLineOrAddress lineOrAddr
;
1178 if (winInfo
->generic
.type
== SRC_WIN
)
1180 winInfo
->detail
.sourceInfo
.startLineOrAddr
.lineNo
;
1183 winInfo
->detail
.sourceInfo
.startLineOrAddr
.addr
;
1184 freeWinContent (&winInfo
->generic
);
1185 tuiUpdateSourceWindow (winInfo
,
1186 current_source_symtab
,
1187 ((winInfo
->generic
.type
== SRC_WIN
) ?
1188 (Opaque
) lineOrAddr
.lineNo
:
1192 else if (selected_frame
!= (struct frame_info
*) NULL
)
1195 extern int current_source_line
;
1197 s
= find_pc_symtab (selected_frame
->pc
);
1198 if (winInfo
->generic
.type
== SRC_WIN
)
1199 line
= (Opaque
) current_source_line
;
1204 find_line_pc (s
, current_source_line
, &pc
);
1207 tuiUpdateSourceWindow (winInfo
, s
, line
, TRUE
);
1209 if (m_hasLocator (winInfo
))
1211 m_beVisible (locatorWinInfoPtr ());
1212 tuiClearLocatorDisplay ();
1213 tuiShowLocatorContent ();
1217 tuiDisplayAllData ();
1220 winInfo
->detail
.commandInfo
.curLine
= 0;
1221 winInfo
->detail
.commandInfo
.curch
= 0;
1222 wmove (winInfo
->generic
.handle
,
1223 winInfo
->detail
.commandInfo
.curLine
,
1224 winInfo
->detail
.commandInfo
.curch
);
1231 } /* _makeVisibleWithNewHeight */
1235 _newHeightOk (TuiWinInfoPtr primaryWinInfo
, int newHeight
)
1237 int ok
= (newHeight
< termHeight ());
1241 int diff
, curHeight
;
1242 TuiLayoutType curLayout
= currentLayout ();
1244 diff
= (newHeight
- primaryWinInfo
->generic
.height
) * (-1);
1245 if (curLayout
== SRC_COMMAND
|| curLayout
== DISASSEM_COMMAND
)
1247 ok
= ((primaryWinInfo
->generic
.type
== CMD_WIN
&&
1248 newHeight
<= (termHeight () - 4) &&
1249 newHeight
>= MIN_CMD_WIN_HEIGHT
) ||
1250 (primaryWinInfo
->generic
.type
!= CMD_WIN
&&
1251 newHeight
<= (termHeight () - 2) &&
1252 newHeight
>= MIN_WIN_HEIGHT
));
1254 { /* check the total height */
1255 TuiWinInfoPtr winInfo
;
1257 if (primaryWinInfo
== cmdWin
)
1258 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1262 (winInfo
->generic
.height
+ diff
)) <= termHeight ());
1267 int curTotalHeight
, totalHeight
, minHeight
;
1268 TuiWinInfoPtr firstWin
, secondWin
;
1270 if (curLayout
== SRC_DISASSEM_COMMAND
)
1273 secondWin
= disassemWin
;
1278 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1281 ** We could simply add all the heights to obtain the same result
1282 ** but below is more explicit since we subtract 1 for the
1283 ** line that the first and second windows share, and add one
1287 (firstWin
->generic
.height
+ secondWin
->generic
.height
- 1)
1288 + cmdWin
->generic
.height
+ 1 /*locator */ ;
1289 if (primaryWinInfo
== cmdWin
)
1291 /* locator included since first & second win share a line */
1292 ok
= ((firstWin
->generic
.height
+
1293 secondWin
->generic
.height
+ diff
) >=
1294 (MIN_WIN_HEIGHT
* 2) &&
1295 newHeight
>= MIN_CMD_WIN_HEIGHT
);
1298 totalHeight
= newHeight
+ (firstWin
->generic
.height
+
1299 secondWin
->generic
.height
+ diff
);
1300 minHeight
= MIN_CMD_WIN_HEIGHT
;
1305 minHeight
= MIN_WIN_HEIGHT
;
1307 ** First see if we can increase/decrease the command
1308 ** window. And make sure that the command window is
1311 ok
= ((cmdWin
->generic
.height
+ diff
) > 0);
1314 ** Looks like we have to increase/decrease one of
1315 ** the other windows
1317 if (primaryWinInfo
== firstWin
)
1318 ok
= (secondWin
->generic
.height
+ diff
) >= minHeight
;
1320 ok
= (firstWin
->generic
.height
+ diff
) >= minHeight
;
1324 if (primaryWinInfo
== firstWin
)
1325 totalHeight
= newHeight
+
1326 secondWin
->generic
.height
+
1327 cmdWin
->generic
.height
+ diff
;
1329 totalHeight
= newHeight
+
1330 firstWin
->generic
.height
+
1331 cmdWin
->generic
.height
+ diff
;
1335 ** Now make sure that the proposed total height doesn't exceed
1336 ** the old total height.
1339 ok
= (newHeight
>= minHeight
&& totalHeight
<= curTotalHeight
);
1344 } /* _newHeightOk */
1348 ** _parseScrollingArgs().
1351 _parseScrollingArgs (char *arg
, TuiWinInfoPtr
* winToScroll
, int *numToScroll
)
1355 *winToScroll
= tuiWinWithFocus ();
1358 ** First set up the default window to scroll, in case there is no
1361 if (arg
!= (char *) NULL
)
1365 /* process the number of lines to scroll */
1366 buf
= bufPtr
= tuiStrDup (arg
);
1367 if (isdigit (*bufPtr
))
1372 bufPtr
= strchr (bufPtr
, ' ');
1373 if (bufPtr
!= (char *) NULL
)
1377 *numToScroll
= atoi (numStr
);
1380 else if (numToScroll
)
1381 *numToScroll
= atoi (numStr
);
1384 /* process the window name if one is specified */
1385 if (bufPtr
!= (char *) NULL
)
1391 while (*(++bufPtr
) == ' ')
1394 if (*bufPtr
!= (char) 0)
1397 /* Validate the window name */
1398 for (i
= 0; i
< strlen (wname
); i
++)
1399 wname
[i
] = toupper (wname
[i
]);
1400 *winToScroll
= partialWinByName (wname
);
1402 if (*winToScroll
== (TuiWinInfoPtr
) NULL
||
1403 !(*winToScroll
)->generic
.isVisible
)
1404 warning ("Invalid window specified. \n\
1405 The window name specified must be valid and visible.\n");
1406 else if (*winToScroll
== cmdWin
)
1407 *winToScroll
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1413 } /* _parseScrollingArgs */