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"
37 #include "tuiGeneralWin.h"
40 #include "tuiDisassem.h"
41 #include "tuiSource.h"
42 #include "tuiSourceWin.h"
43 #include "tuiDataWin.h"
45 /*******************************
46 ** External Declarations
47 ********************************/
48 extern void init_page_info ();
50 /*******************************
52 ********************************/
53 static void _makeVisibleWithNewHeight (TuiWinInfoPtr
);
54 static void _makeInvisibleAndSetNewHeight (TuiWinInfoPtr
, int);
55 static TuiStatus
_tuiAdjustWinHeights (TuiWinInfoPtr
, int);
56 static int _newHeightOk (TuiWinInfoPtr
, int);
57 static void _tuiSetTabWidth_command (char *, int);
58 static void _tuiRefreshAll_command (char *, int);
59 static void _tuiSetWinHeight_command (char *, int);
60 static void _tuiXDBsetWinHeight_command (char *, int);
61 static void _tuiAllWindowsInfo (char *, int);
62 static void _tuiSetFocus_command (char *, int);
63 static void _tuiScrollForward_command (char *, int);
64 static void _tuiScrollBackward_command (char *, int);
65 static void _tuiScrollLeft_command (char *, int);
66 static void _tuiScrollRight_command (char *, int);
67 static void _parseScrollingArgs (char *, TuiWinInfoPtr
*, int *);
70 /***************************************
72 ***************************************/
73 #define WIN_HEIGHT_USAGE "Usage: winheight <win_name> [+ | -] <#lines>\n"
74 #define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n"
75 #define FOCUS_USAGE "Usage: focus {<win> | next | prev}\n"
77 /***************************************
79 ***************************************/
82 ** _initialize_tuiWin().
83 ** Function to initialize gdb commands, for tui window manipulation.
86 _initialize_tuiWin (void)
90 add_com ("refresh", class_tui
, _tuiRefreshAll_command
,
91 "Refresh the terminal display.\n");
93 add_com_alias ("U", "refresh", class_tui
, 0);
94 add_com ("tabset", class_tui
, _tuiSetTabWidth_command
,
95 "Set the width (in characters) of tab stops.\n\
96 Usage: tabset <n>\n");
97 add_com ("winheight", class_tui
, _tuiSetWinHeight_command
,
98 "Set the height of a specified window.\n\
99 Usage: winheight <win_name> [+ | -] <#lines>\n\
101 src : the source window\n\
102 cmd : the command window\n\
103 asm : the disassembly window\n\
104 regs : the register display\n");
105 add_com_alias ("wh", "winheight", class_tui
, 0);
106 add_info ("win", _tuiAllWindowsInfo
,
107 "List of all displayed windows.\n");
108 add_com ("focus", class_tui
, _tuiSetFocus_command
,
109 "Set focus to named window or next/prev window.\n\
110 Usage: focus {<win> | next | prev}\n\
111 Valid Window names are:\n\
112 src : the source window\n\
113 asm : the disassembly window\n\
114 regs : the register display\n\
115 cmd : the command window\n");
116 add_com_alias ("fs", "focus", class_tui
, 0);
117 add_com ("+", class_tui
, _tuiScrollForward_command
,
118 "Scroll window forward.\nUsage: + [win] [n]\n");
119 add_com ("-", class_tui
, _tuiScrollBackward_command
,
120 "Scroll window backward.\nUsage: - [win] [n]\n");
121 add_com ("<", class_tui
, _tuiScrollLeft_command
,
122 "Scroll window forward.\nUsage: < [win] [n]\n");
123 add_com (">", class_tui
, _tuiScrollRight_command
,
124 "Scroll window backward.\nUsage: > [win] [n]\n");
126 add_com ("w", class_xdb
, _tuiXDBsetWinHeight_command
,
127 "XDB compatibility command for setting the height of a command window.\n\
128 Usage: w <#lines>\n");
132 } /* _intialize_tuiWin */
136 ** tuiClearWinFocusFrom
137 ** Clear the logical focus from winInfo
140 tuiClearWinFocusFrom (TuiWinInfoPtr winInfo
)
142 if (m_winPtrNotNull (winInfo
))
144 if (winInfo
->generic
.type
!= CMD_WIN
)
145 unhighlightWin (winInfo
);
146 tuiSetWinWithFocus ((TuiWinInfoPtr
) NULL
);
150 } /* tuiClearWinFocusFrom */
154 ** tuiClearWinFocus().
155 ** Clear the window that has focus.
158 tuiClearWinFocus (void)
160 tuiClearWinFocusFrom (tuiWinWithFocus ());
163 } /* tuiClearWinFocus */
168 ** Set the logical focus to winInfo
171 tuiSetWinFocusTo (TuiWinInfoPtr winInfo
)
173 if (m_winPtrNotNull (winInfo
))
175 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
177 if (m_winPtrNotNull (winWithFocus
) &&
178 winWithFocus
->generic
.type
!= CMD_WIN
)
179 unhighlightWin (winWithFocus
);
180 tuiSetWinWithFocus (winInfo
);
181 if (winInfo
->generic
.type
!= CMD_WIN
)
182 highlightWin (winInfo
);
186 } /* tuiSetWinFocusTo */
190 tuiStrDup (char *str
)
192 char *newStr
= (char *) NULL
;
194 if (str
!= (char *) NULL
)
196 newStr
= (char *) xmalloc (strlen (str
) + 1);
197 strcpy (newStr
, str
);
205 ** tuiScrollForward().
208 tuiScrollForward (TuiWinInfoPtr winToScroll
, int numToScroll
)
210 if (winToScroll
!= cmdWin
)
212 int _numToScroll
= numToScroll
;
214 if (numToScroll
== 0)
215 _numToScroll
= winToScroll
->generic
.height
- 3;
217 ** If we are scrolling the source or disassembly window, do a
218 ** "psuedo" scroll since not all of the source is in memory,
219 ** only what is in the viewport. If winToScroll is the
220 ** command window do nothing since the term should handle it.
222 if (winToScroll
== srcWin
)
223 tuiVerticalSourceScroll (FORWARD_SCROLL
, _numToScroll
);
224 else if (winToScroll
== disassemWin
)
225 tuiVerticalDisassemScroll (FORWARD_SCROLL
, _numToScroll
);
226 else if (winToScroll
== dataWin
)
227 tuiVerticalDataScroll (FORWARD_SCROLL
, _numToScroll
);
231 } /* tuiScrollForward */
235 ** tuiScrollBackward().
238 tuiScrollBackward (TuiWinInfoPtr winToScroll
, int numToScroll
)
240 if (winToScroll
!= cmdWin
)
242 int _numToScroll
= numToScroll
;
244 if (numToScroll
== 0)
245 _numToScroll
= winToScroll
->generic
.height
- 3;
247 ** If we are scrolling the source or disassembly window, do a
248 ** "psuedo" scroll since not all of the source is in memory,
249 ** only what is in the viewport. If winToScroll is the
250 ** command window do nothing since the term should handle it.
252 if (winToScroll
== srcWin
)
253 tuiVerticalSourceScroll (BACKWARD_SCROLL
, _numToScroll
);
254 else if (winToScroll
== disassemWin
)
255 tuiVerticalDisassemScroll (BACKWARD_SCROLL
, _numToScroll
);
256 else if (winToScroll
== dataWin
)
257 tuiVerticalDataScroll (BACKWARD_SCROLL
, _numToScroll
);
260 } /* tuiScrollBackward */
267 tuiScrollLeft (TuiWinInfoPtr winToScroll
, int numToScroll
)
269 if (winToScroll
!= cmdWin
)
271 int _numToScroll
= numToScroll
;
273 if (_numToScroll
== 0)
276 ** If we are scrolling the source or disassembly window, do a
277 ** "psuedo" scroll since not all of the source is in memory,
278 ** only what is in the viewport. If winToScroll is the
279 ** command window do nothing since the term should handle it.
281 if (winToScroll
== srcWin
|| winToScroll
== disassemWin
)
282 tuiHorizontalSourceScroll (winToScroll
, LEFT_SCROLL
, _numToScroll
);
285 } /* tuiScrollLeft */
292 tuiScrollRight (TuiWinInfoPtr winToScroll
, int numToScroll
)
294 if (winToScroll
!= cmdWin
)
296 int _numToScroll
= numToScroll
;
298 if (_numToScroll
== 0)
301 ** If we are scrolling the source or disassembly window, do a
302 ** "psuedo" scroll since not all of the source is in memory,
303 ** only what is in the viewport. If winToScroll is the
304 ** command window do nothing since the term should handle it.
306 if (winToScroll
== srcWin
|| winToScroll
== disassemWin
)
307 tuiHorizontalSourceScroll (winToScroll
, RIGHT_SCROLL
, _numToScroll
);
310 } /* tuiScrollRight */
315 ** Scroll a window. Arguments are passed through a va_list.
318 tui_vScroll (va_list args
)
320 TuiScrollDirection direction
= va_arg (args
, TuiScrollDirection
);
321 TuiWinInfoPtr winToScroll
= va_arg (args
, TuiWinInfoPtr
);
322 int numToScroll
= va_arg (args
, int);
327 tuiScrollForward (winToScroll
, numToScroll
);
329 case BACKWARD_SCROLL
:
330 tuiScrollBackward (winToScroll
, numToScroll
);
333 tuiScrollLeft (winToScroll
, numToScroll
);
336 tuiScrollRight (winToScroll
, numToScroll
);
354 refreshAll (winList
);
355 for (type
= SRC_WIN
; type
< MAX_MAJOR_WINDOWS
; type
++)
357 if (winList
[type
] && winList
[type
]->generic
.isVisible
)
363 tuiClearWin (&winList
[type
]->generic
);
364 if (winList
[type
]->detail
.sourceInfo
.hasLocator
)
365 tuiClearLocatorDisplay ();
366 tuiShowSourceContent (winList
[type
]);
367 checkAndDisplayHighlightIfNeeded (winList
[type
]);
368 tuiEraseExecInfoContent (winList
[type
]);
369 tuiUpdateExecInfo (winList
[type
]);
372 tuiRefreshDataWin ();
379 tuiClearLocatorDisplay ();
380 tuiShowLocatorContent ();
383 } /* tuiRefreshAll */
388 ** Resize all the windows based on the the terminal size. This
389 ** function gets called from within the readline sinwinch handler.
394 int heightDiff
, widthDiff
;
395 extern int screenheight
, screenwidth
; /* in readline */
397 widthDiff
= screenwidth
- termWidth ();
398 heightDiff
= screenheight
- termHeight ();
399 if (heightDiff
|| widthDiff
)
401 TuiLayoutType curLayout
= currentLayout ();
402 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
403 TuiWinInfoPtr firstWin
, secondWin
;
404 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
406 int i
, newHeight
, splitDiff
, cmdSplitDiff
, numWinsDisplayed
= 2;
408 /* turn keypad off while we resize */
409 if (winWithFocus
!= cmdWin
)
410 keypad (cmdWin
->generic
.handle
, FALSE
);
412 setTermHeightTo (screenheight
);
413 setTermWidthTo (screenwidth
);
414 if (curLayout
== SRC_DISASSEM_COMMAND
||
415 curLayout
== SRC_DATA_COMMAND
|| curLayout
== DISASSEM_DATA_COMMAND
)
417 splitDiff
= heightDiff
/ numWinsDisplayed
;
418 cmdSplitDiff
= splitDiff
;
419 if (heightDiff
% numWinsDisplayed
)
426 /* now adjust each window */
432 case DISASSEM_COMMAND
:
433 firstWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
434 firstWin
->generic
.width
+= widthDiff
;
435 locator
->width
+= widthDiff
;
436 /* check for invalid heights */
438 newHeight
= firstWin
->generic
.height
;
439 else if ((firstWin
->generic
.height
+ splitDiff
) >=
440 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
441 newHeight
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
442 else if ((firstWin
->generic
.height
+ splitDiff
) <= 0)
443 newHeight
= MIN_WIN_HEIGHT
;
445 newHeight
= firstWin
->generic
.height
+ splitDiff
;
447 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
448 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
449 cmdWin
->generic
.width
+= widthDiff
;
450 newHeight
= screenheight
- cmdWin
->generic
.origin
.y
;
451 _makeInvisibleAndSetNewHeight (cmdWin
, newHeight
);
452 _makeVisibleWithNewHeight (firstWin
);
453 _makeVisibleWithNewHeight (cmdWin
);
454 if (firstWin
->generic
.contentSize
<= 0)
455 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
458 if (curLayout
== SRC_DISASSEM_COMMAND
)
461 firstWin
->generic
.width
+= widthDiff
;
462 secondWin
= disassemWin
;
463 secondWin
->generic
.width
+= widthDiff
;
468 firstWin
->generic
.width
+= widthDiff
;
469 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
470 secondWin
->generic
.width
+= widthDiff
;
472 /* Change the first window's height/width */
473 /* check for invalid heights */
475 newHeight
= firstWin
->generic
.height
;
476 else if ((firstWin
->generic
.height
+
477 secondWin
->generic
.height
+ (splitDiff
* 2)) >=
478 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
479 newHeight
= (screenheight
- MIN_CMD_WIN_HEIGHT
- 1) / 2;
480 else if ((firstWin
->generic
.height
+ splitDiff
) <= 0)
481 newHeight
= MIN_WIN_HEIGHT
;
483 newHeight
= firstWin
->generic
.height
+ splitDiff
;
484 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
486 if (firstWin
== dataWin
&& widthDiff
!= 0)
487 firstWin
->detail
.dataDisplayInfo
.regsColumnCount
=
488 tuiCalculateRegsColumnCount (
489 firstWin
->detail
.dataDisplayInfo
.regsDisplayType
);
490 locator
->width
+= widthDiff
;
492 /* Change the second window's height/width */
493 /* check for invalid heights */
495 newHeight
= secondWin
->generic
.height
;
496 else if ((firstWin
->generic
.height
+
497 secondWin
->generic
.height
+ (splitDiff
* 2)) >=
498 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
500 newHeight
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
502 newHeight
= (newHeight
/ 2) + 1;
506 else if ((secondWin
->generic
.height
+ splitDiff
) <= 0)
507 newHeight
= MIN_WIN_HEIGHT
;
509 newHeight
= secondWin
->generic
.height
+ splitDiff
;
510 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
511 _makeInvisibleAndSetNewHeight (secondWin
, newHeight
);
513 /* Change the command window's height/width */
514 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
515 _makeInvisibleAndSetNewHeight (
516 cmdWin
, cmdWin
->generic
.height
+ cmdSplitDiff
);
517 _makeVisibleWithNewHeight (firstWin
);
518 _makeVisibleWithNewHeight (secondWin
);
519 _makeVisibleWithNewHeight (cmdWin
);
520 if (firstWin
->generic
.contentSize
<= 0)
521 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
522 if (secondWin
->generic
.contentSize
<= 0)
523 tuiEraseSourceContent (secondWin
, EMPTY_SOURCE_PROMPT
);
527 ** Now remove all invisible windows, and their content so that they get
528 ** created again when called for with the new size
530 for (winType
= SRC_WIN
; (winType
< MAX_MAJOR_WINDOWS
); winType
++)
532 if (winType
!= CMD_WIN
&& m_winPtrNotNull (winList
[winType
]) &&
533 !winList
[winType
]->generic
.isVisible
)
535 freeWindow (winList
[winType
]);
536 winList
[winType
] = (TuiWinInfoPtr
) NULL
;
539 tuiSetWinResizedTo (TRUE
);
540 /* turn keypad back on, unless focus is in the command window */
541 if (winWithFocus
!= cmdWin
)
542 keypad (cmdWin
->generic
.handle
, TRUE
);
549 ** tuiSigwinchHandler()
550 ** SIGWINCH signal handler for the tui. This signal handler is
551 ** always called, even when the readline package clears signals
552 ** because it is set as the old_sigwinch() (TUI only)
555 tuiSigwinchHandler (int signal
)
558 ** Say that a resize was done so that the readline can do it
559 ** later when appropriate.
561 tuiSetWinResizedTo (TRUE
);
564 } /* tuiSigwinchHandler */
568 /*************************
569 ** STATIC LOCAL FUNCTIONS
570 **************************/
574 ** _tuiScrollForward_command().
577 _tuiScrollForward_command (char *arg
, int fromTTY
)
580 TuiWinInfoPtr winToScroll
;
582 if (arg
== (char *) NULL
)
583 _parseScrollingArgs (arg
, &winToScroll
, (int *) NULL
);
585 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
586 tuiDo ((TuiOpaqueFuncPtr
) tui_vScroll
,
592 } /* _tuiScrollForward_command */
596 ** _tuiScrollBackward_command().
599 _tuiScrollBackward_command (char *arg
, int fromTTY
)
602 TuiWinInfoPtr winToScroll
;
604 if (arg
== (char *) NULL
)
605 _parseScrollingArgs (arg
, &winToScroll
, (int *) NULL
);
607 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
608 tuiDo ((TuiOpaqueFuncPtr
) tui_vScroll
,
614 } /* _tuiScrollBackward_command */
618 ** _tuiScrollLeft_command().
621 _tuiScrollLeft_command (char *arg
, int fromTTY
)
624 TuiWinInfoPtr winToScroll
;
626 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
627 tuiDo ((TuiOpaqueFuncPtr
) tui_vScroll
,
633 } /* _tuiScrollLeft_command */
637 ** _tuiScrollRight_command().
640 _tuiScrollRight_command (char *arg
, int fromTTY
)
643 TuiWinInfoPtr winToScroll
;
645 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
646 tuiDo ((TuiOpaqueFuncPtr
) tui_vScroll
,
652 } /* _tuiScrollRight_command */
657 ** Set focus to the window named by 'arg'
660 _tuiSetFocus (char *arg
, int fromTTY
)
662 if (arg
!= (char *) NULL
)
664 char *bufPtr
= (char *) tuiStrDup (arg
);
666 TuiWinInfoPtr winInfo
= (TuiWinInfoPtr
) NULL
;
668 for (i
= 0; (i
< strlen (bufPtr
)); i
++)
669 bufPtr
[i
] = toupper (arg
[i
]);
671 if (subset_compare (bufPtr
, "NEXT"))
672 winInfo
= tuiNextWin (tuiWinWithFocus ());
673 else if (subset_compare (bufPtr
, "PREV"))
674 winInfo
= tuiPrevWin (tuiWinWithFocus ());
676 winInfo
= partialWinByName (bufPtr
);
678 if (winInfo
== (TuiWinInfoPtr
) NULL
|| !winInfo
->generic
.isVisible
)
679 warning ("Invalid window specified. \n\
680 The window name specified must be valid and visible.\n");
683 tuiSetWinFocusTo (winInfo
);
684 keypad (cmdWin
->generic
.handle
, (winInfo
!= cmdWin
));
687 if (dataWin
&& dataWin
->generic
.isVisible
)
688 tuiRefreshDataWin ();
690 printf_filtered ("Focus set to %s window.\n",
691 winName ((TuiGenWinInfoPtr
) tuiWinWithFocus ()));
694 warning ("Incorrect Number of Arguments.\n%s", FOCUS_USAGE
);
704 _tui_vSetFocus (va_list args
)
706 char *arg
= va_arg (args
, char *);
707 int fromTTY
= va_arg (args
, int);
709 _tuiSetFocus (arg
, fromTTY
);
712 } /* tui_vSetFocus */
716 ** _tuiSetFocus_command()
719 _tuiSetFocus_command (char *arg
, int fromTTY
)
721 tuiDo ((TuiOpaqueFuncPtr
) _tui_vSetFocus
, arg
, fromTTY
);
728 ** _tuiAllWindowsInfo().
731 _tuiAllWindowsInfo (char *arg
, int fromTTY
)
734 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
736 for (type
= SRC_WIN
; (type
< MAX_MAJOR_WINDOWS
); type
++)
737 if (winList
[type
]->generic
.isVisible
)
739 if (winWithFocus
== winList
[type
])
740 printf_filtered (" %s\t(%d lines) <has focus>\n",
741 winName (&winList
[type
]->generic
),
742 winList
[type
]->generic
.height
);
744 printf_filtered (" %s\t(%d lines)\n",
745 winName (&winList
[type
]->generic
),
746 winList
[type
]->generic
.height
);
750 } /* _tuiAllWindowsInfo */
754 ** _tuiRefreshAll_command().
757 _tuiRefreshAll_command (char *arg
, int fromTTY
)
759 tuiDo ((TuiOpaqueFuncPtr
) tuiRefreshAll
);
764 ** _tuiSetWinTabWidth_command().
765 ** Set the height of the specified window.
768 _tuiSetTabWidth_command (char *arg
, int fromTTY
)
770 if (arg
!= (char *) NULL
)
776 tuiSetDefaultTabLen (ts
);
778 warning ("Tab widths greater than 0 must be specified.\n");
782 } /* _tuiSetTabWidth_command */
786 ** _tuiSetWinHeight().
787 ** Set the height of the specified window.
790 _tuiSetWinHeight (char *arg
, int fromTTY
)
792 if (arg
!= (char *) NULL
)
794 char *buf
= tuiStrDup (arg
);
796 char *wname
= (char *) NULL
;
798 TuiWinInfoPtr winInfo
;
801 bufPtr
= strchr (bufPtr
, ' ');
802 if (bufPtr
!= (char *) NULL
)
807 ** Validate the window name
809 for (i
= 0; i
< strlen (wname
); i
++)
810 wname
[i
] = toupper (wname
[i
]);
811 winInfo
= partialWinByName (wname
);
813 if (winInfo
== (TuiWinInfoPtr
) NULL
|| !winInfo
->generic
.isVisible
)
814 warning ("Invalid window specified. \n\
815 The window name specified must be valid and visible.\n");
818 /* Process the size */
819 while (*(++bufPtr
) == ' ')
822 if (*bufPtr
!= (char) 0)
825 int fixedSize
= TRUE
;
828 if (*bufPtr
== '+' || *bufPtr
== '-')
835 inputNo
= atoi (bufPtr
);
843 newHeight
= winInfo
->generic
.height
+ inputNo
;
845 ** Now change the window's height, and adjust all
846 ** other windows around it
848 if (_tuiAdjustWinHeights (winInfo
,
849 newHeight
) == TUI_FAILURE
)
850 warning ("Invalid window height specified.\n%s",
856 warning ("Invalid window height specified.\n%s",
862 printf_filtered (WIN_HEIGHT_USAGE
);
864 if (buf
!= (char *) NULL
)
868 printf_filtered (WIN_HEIGHT_USAGE
);
871 } /* _tuiSetWinHeight */
875 ** _tui_vSetWinHeight().
876 ** Set the height of the specified window, with va_list.
879 _tui_vSetWinHeight (va_list args
)
881 char *arg
= va_arg (args
, char *);
882 int fromTTY
= va_arg (args
, int);
884 _tuiSetWinHeight (arg
, fromTTY
);
887 } /* _tui_vSetWinHeight */
891 ** _tuiSetWinHeight_command().
892 ** Set the height of the specified window, with va_list.
895 _tuiSetWinHeight_command (char *arg
, int fromTTY
)
897 tuiDo ((TuiOpaqueFuncPtr
) _tui_vSetWinHeight
, arg
, fromTTY
);
900 } /* _tuiSetWinHeight_command */
904 ** _tuiXDBsetWinHeight().
905 ** XDB Compatibility command for setting the window height. This will
906 ** increase or decrease the command window by the specified amount.
909 _tuiXDBsetWinHeight (char *arg
, int fromTTY
)
911 if (arg
!= (char *) NULL
)
913 int inputNo
= atoi (arg
);
916 { /* Add 1 for the locator */
917 int newHeight
= termHeight () - (inputNo
+ 1);
919 if (!_newHeightOk (winList
[CMD_WIN
], newHeight
) ||
920 _tuiAdjustWinHeights (winList
[CMD_WIN
],
921 newHeight
) == TUI_FAILURE
)
922 warning ("Invalid window height specified.\n%s",
923 XDBWIN_HEIGHT_USAGE
);
926 warning ("Invalid window height specified.\n%s",
927 XDBWIN_HEIGHT_USAGE
);
930 warning ("Invalid window height specified.\n%s", XDBWIN_HEIGHT_USAGE
);
933 } /* _tuiXDBsetWinHeight */
937 ** _tui_vXDBsetWinHeight().
938 ** Set the height of the specified window, with va_list.
941 _tui_vXDBsetWinHeight (va_list args
)
943 char *arg
= va_arg (args
, char *);
944 int fromTTY
= va_arg (args
, int);
946 _tuiXDBsetWinHeight (arg
, fromTTY
);
949 } /* _tui_vXDBsetWinHeight */
953 ** _tuiSetWinHeight_command().
954 ** Set the height of the specified window, with va_list.
957 _tuiXDBsetWinHeight_command (char *arg
, int fromTTY
)
959 tuiDo ((TuiOpaqueFuncPtr
) _tui_vXDBsetWinHeight
, arg
, fromTTY
);
962 } /* _tuiXDBsetWinHeight_command */
966 ** _tuiAdjustWinHeights().
967 ** Function to adjust all window heights around the primary
970 _tuiAdjustWinHeights (TuiWinInfoPtr primaryWinInfo
, int newHeight
)
972 TuiStatus status
= TUI_FAILURE
;
974 if (_newHeightOk (primaryWinInfo
, newHeight
))
976 status
= TUI_SUCCESS
;
977 if (newHeight
!= primaryWinInfo
->generic
.height
)
980 TuiWinInfoPtr winInfo
;
981 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
982 TuiLayoutType curLayout
= currentLayout ();
984 diff
= (newHeight
- primaryWinInfo
->generic
.height
) * (-1);
985 if (curLayout
== SRC_COMMAND
|| curLayout
== DISASSEM_COMMAND
)
987 TuiWinInfoPtr srcWinInfo
;
989 _makeInvisibleAndSetNewHeight (primaryWinInfo
, newHeight
);
990 if (primaryWinInfo
->generic
.type
== CMD_WIN
)
992 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
993 srcWinInfo
= winInfo
;
997 winInfo
= winList
[CMD_WIN
];
998 srcWinInfo
= primaryWinInfo
;
1000 _makeInvisibleAndSetNewHeight (winInfo
,
1001 winInfo
->generic
.height
+ diff
);
1002 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1003 _makeVisibleWithNewHeight (winInfo
);
1004 _makeVisibleWithNewHeight (primaryWinInfo
);
1005 if (srcWinInfo
->generic
.contentSize
<= 0)
1006 tuiEraseSourceContent (srcWinInfo
, EMPTY_SOURCE_PROMPT
);
1010 TuiWinInfoPtr firstWin
, secondWin
;
1012 if (curLayout
== SRC_DISASSEM_COMMAND
)
1015 secondWin
= disassemWin
;
1020 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1022 if (primaryWinInfo
== cmdWin
)
1024 ** Split the change in height accross the 1st & 2nd windows
1025 ** adjusting them as well.
1027 int firstSplitDiff
= diff
/ 2; /* subtract the locator */
1028 int secondSplitDiff
= firstSplitDiff
;
1032 if (firstWin
->generic
.height
>
1033 secondWin
->generic
.height
)
1046 /* make sure that the minimum hieghts are honored */
1047 while ((firstWin
->generic
.height
+ firstSplitDiff
) < 3)
1052 while ((secondWin
->generic
.height
+ secondSplitDiff
) < 3)
1057 _makeInvisibleAndSetNewHeight (
1059 firstWin
->generic
.height
+ firstSplitDiff
);
1060 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
1061 _makeInvisibleAndSetNewHeight (
1062 secondWin
, secondWin
->generic
.height
+ secondSplitDiff
);
1063 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1064 _makeInvisibleAndSetNewHeight (cmdWin
, newHeight
);
1068 if ((cmdWin
->generic
.height
+ diff
) < 1)
1070 ** If there is no way to increase the command window
1071 ** take real estate from the 1st or 2nd window.
1073 if ((cmdWin
->generic
.height
+ diff
) < 1)
1076 for (i
= cmdWin
->generic
.height
+ diff
;
1078 if (primaryWinInfo
== firstWin
)
1079 secondWin
->generic
.height
--;
1081 firstWin
->generic
.height
--;
1084 if (primaryWinInfo
== firstWin
)
1085 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
1087 _makeInvisibleAndSetNewHeight (
1089 firstWin
->generic
.height
);
1090 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
1091 if (primaryWinInfo
== secondWin
)
1092 _makeInvisibleAndSetNewHeight (secondWin
, newHeight
);
1094 _makeInvisibleAndSetNewHeight (
1095 secondWin
, secondWin
->generic
.height
);
1096 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1097 if ((cmdWin
->generic
.height
+ diff
) < 1)
1098 _makeInvisibleAndSetNewHeight (cmdWin
, 1);
1100 _makeInvisibleAndSetNewHeight (
1101 cmdWin
, cmdWin
->generic
.height
+ diff
);
1103 _makeVisibleWithNewHeight (cmdWin
);
1104 _makeVisibleWithNewHeight (secondWin
);
1105 _makeVisibleWithNewHeight (firstWin
);
1106 if (firstWin
->generic
.contentSize
<= 0)
1107 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
1108 if (secondWin
->generic
.contentSize
<= 0)
1109 tuiEraseSourceContent (secondWin
, EMPTY_SOURCE_PROMPT
);
1115 } /* _tuiAdjustWinHeights */
1119 ** _makeInvisibleAndSetNewHeight().
1120 ** Function make the target window (and auxillary windows associated
1121 ** with the targer) invisible, and set the new height and location.
1124 _makeInvisibleAndSetNewHeight (TuiWinInfoPtr winInfo
, int height
)
1128 TuiGenWinInfoPtr genWinInfo
;
1131 m_beInvisible (&winInfo
->generic
);
1132 winInfo
->generic
.height
= height
;
1134 winInfo
->generic
.viewportHeight
= height
- 1;
1136 winInfo
->generic
.viewportHeight
= height
;
1137 if (winInfo
!= cmdWin
)
1138 winInfo
->generic
.viewportHeight
--;
1140 /* Now deal with the auxillary windows associated with winInfo */
1141 switch (winInfo
->generic
.type
)
1145 genWinInfo
= winInfo
->detail
.sourceInfo
.executionInfo
;
1146 m_beInvisible (genWinInfo
);
1147 genWinInfo
->height
= height
;
1148 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
;
1150 genWinInfo
->viewportHeight
= height
- 1;
1152 genWinInfo
->viewportHeight
= height
;
1153 if (winInfo
!= cmdWin
)
1154 genWinInfo
->viewportHeight
--;
1156 if (m_hasLocator (winInfo
))
1158 genWinInfo
= locatorWinInfoPtr ();
1159 m_beInvisible (genWinInfo
);
1160 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
+ height
;
1164 /* delete all data item windows */
1165 for (i
= 0; i
< winInfo
->generic
.contentSize
; i
++)
1167 genWinInfo
= (TuiGenWinInfoPtr
) & ((TuiWinElementPtr
)
1168 winInfo
->generic
.content
[i
])->whichElement
.dataWindow
;
1169 tuiDelwin (genWinInfo
->handle
);
1170 genWinInfo
->handle
= (WINDOW
*) NULL
;
1178 } /* _makeInvisibleAndSetNewHeight */
1182 ** _makeVisibleWithNewHeight().
1183 ** Function to make the windows with new heights visible.
1184 ** This means re-creating the windows' content since the window
1185 ** had to be destroyed to be made invisible.
1188 _makeVisibleWithNewHeight (TuiWinInfoPtr winInfo
)
1193 m_beVisible (&winInfo
->generic
);
1194 checkAndDisplayHighlightIfNeeded (winInfo
);
1195 switch (winInfo
->generic
.type
)
1199 freeWinContent (winInfo
->detail
.sourceInfo
.executionInfo
);
1200 m_beVisible (winInfo
->detail
.sourceInfo
.executionInfo
);
1201 if (winInfo
->generic
.content
!= (OpaquePtr
) NULL
)
1203 TuiLineOrAddress lineOrAddr
;
1205 if (winInfo
->generic
.type
== SRC_WIN
)
1207 winInfo
->detail
.sourceInfo
.startLineOrAddr
.lineNo
;
1210 winInfo
->detail
.sourceInfo
.startLineOrAddr
.addr
;
1211 freeWinContent (&winInfo
->generic
);
1212 tuiUpdateSourceWindow (winInfo
,
1213 current_source_symtab
,
1214 ((winInfo
->generic
.type
== SRC_WIN
) ?
1215 (Opaque
) lineOrAddr
.lineNo
:
1219 else if (selected_frame
!= (struct frame_info
*) NULL
)
1222 extern int current_source_line
;
1224 s
= find_pc_symtab (selected_frame
->pc
);
1225 if (winInfo
->generic
.type
== SRC_WIN
)
1226 line
= (Opaque
) current_source_line
;
1231 find_line_pc (s
, current_source_line
, &pc
);
1234 tuiUpdateSourceWindow (winInfo
, s
, line
, TRUE
);
1236 if (m_hasLocator (winInfo
))
1238 m_beVisible (locatorWinInfoPtr ());
1239 tuiClearLocatorDisplay ();
1240 tuiShowLocatorContent ();
1244 tuiDisplayAllData ();
1247 winInfo
->detail
.commandInfo
.curLine
= 0;
1248 winInfo
->detail
.commandInfo
.curch
= 0;
1249 wmove (winInfo
->generic
.handle
,
1250 winInfo
->detail
.commandInfo
.curLine
,
1251 winInfo
->detail
.commandInfo
.curch
);
1258 } /* _makeVisibleWithNewHeight */
1262 _newHeightOk (TuiWinInfoPtr primaryWinInfo
, int newHeight
)
1264 int ok
= (newHeight
< termHeight ());
1268 int diff
, curHeight
;
1269 TuiLayoutType curLayout
= currentLayout ();
1271 diff
= (newHeight
- primaryWinInfo
->generic
.height
) * (-1);
1272 if (curLayout
== SRC_COMMAND
|| curLayout
== DISASSEM_COMMAND
)
1274 ok
= ((primaryWinInfo
->generic
.type
== CMD_WIN
&&
1275 newHeight
<= (termHeight () - 4) &&
1276 newHeight
>= MIN_CMD_WIN_HEIGHT
) ||
1277 (primaryWinInfo
->generic
.type
!= CMD_WIN
&&
1278 newHeight
<= (termHeight () - 2) &&
1279 newHeight
>= MIN_WIN_HEIGHT
));
1281 { /* check the total height */
1282 TuiWinInfoPtr winInfo
;
1284 if (primaryWinInfo
== cmdWin
)
1285 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1289 (winInfo
->generic
.height
+ diff
)) <= termHeight ());
1294 int curTotalHeight
, totalHeight
, minHeight
;
1295 TuiWinInfoPtr firstWin
, secondWin
;
1297 if (curLayout
== SRC_DISASSEM_COMMAND
)
1300 secondWin
= disassemWin
;
1305 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1308 ** We could simply add all the heights to obtain the same result
1309 ** but below is more explicit since we subtract 1 for the
1310 ** line that the first and second windows share, and add one
1314 (firstWin
->generic
.height
+ secondWin
->generic
.height
- 1)
1315 + cmdWin
->generic
.height
+ 1 /*locator */ ;
1316 if (primaryWinInfo
== cmdWin
)
1318 /* locator included since first & second win share a line */
1319 ok
= ((firstWin
->generic
.height
+
1320 secondWin
->generic
.height
+ diff
) >=
1321 (MIN_WIN_HEIGHT
* 2) &&
1322 newHeight
>= MIN_CMD_WIN_HEIGHT
);
1325 totalHeight
= newHeight
+ (firstWin
->generic
.height
+
1326 secondWin
->generic
.height
+ diff
);
1327 minHeight
= MIN_CMD_WIN_HEIGHT
;
1332 minHeight
= MIN_WIN_HEIGHT
;
1334 ** First see if we can increase/decrease the command
1335 ** window. And make sure that the command window is
1338 ok
= ((cmdWin
->generic
.height
+ diff
) > 0);
1341 ** Looks like we have to increase/decrease one of
1342 ** the other windows
1344 if (primaryWinInfo
== firstWin
)
1345 ok
= (secondWin
->generic
.height
+ diff
) >= minHeight
;
1347 ok
= (firstWin
->generic
.height
+ diff
) >= minHeight
;
1351 if (primaryWinInfo
== firstWin
)
1352 totalHeight
= newHeight
+
1353 secondWin
->generic
.height
+
1354 cmdWin
->generic
.height
+ diff
;
1356 totalHeight
= newHeight
+
1357 firstWin
->generic
.height
+
1358 cmdWin
->generic
.height
+ diff
;
1362 ** Now make sure that the proposed total height doesn't exceed
1363 ** the old total height.
1366 ok
= (newHeight
>= minHeight
&& totalHeight
<= curTotalHeight
);
1371 } /* _newHeightOk */
1375 ** _parseScrollingArgs().
1378 _parseScrollingArgs (char *arg
, TuiWinInfoPtr
* winToScroll
, int *numToScroll
)
1382 *winToScroll
= tuiWinWithFocus ();
1385 ** First set up the default window to scroll, in case there is no
1388 if (arg
!= (char *) NULL
)
1392 /* process the number of lines to scroll */
1393 buf
= bufPtr
= tuiStrDup (arg
);
1394 if (isdigit (*bufPtr
))
1399 bufPtr
= strchr (bufPtr
, ' ');
1400 if (bufPtr
!= (char *) NULL
)
1404 *numToScroll
= atoi (numStr
);
1407 else if (numToScroll
)
1408 *numToScroll
= atoi (numStr
);
1411 /* process the window name if one is specified */
1412 if (bufPtr
!= (char *) NULL
)
1418 while (*(++bufPtr
) == ' ')
1421 if (*bufPtr
!= (char) 0)
1424 /* Validate the window name */
1425 for (i
= 0; i
< strlen (wname
); i
++)
1426 wname
[i
] = toupper (wname
[i
]);
1427 *winToScroll
= partialWinByName (wname
);
1429 if (*winToScroll
== (TuiWinInfoPtr
) NULL
||
1430 !(*winToScroll
)->generic
.isVisible
)
1431 warning ("Invalid window specified. \n\
1432 The window name specified must be valid and visible.\n");
1433 else if (*winToScroll
== cmdWin
)
1434 *winToScroll
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1440 } /* _parseScrollingArgs */