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_scroll (TuiScrollDirection direction
,
319 TuiWinInfoPtr winToScroll
,
325 tuiScrollForward (winToScroll
, numToScroll
);
327 case BACKWARD_SCROLL
:
328 tuiScrollBackward (winToScroll
, numToScroll
);
331 tuiScrollLeft (winToScroll
, numToScroll
);
334 tuiScrollRight (winToScroll
, numToScroll
);
350 refreshAll (winList
);
351 for (type
= SRC_WIN
; type
< MAX_MAJOR_WINDOWS
; type
++)
353 if (winList
[type
] && winList
[type
]->generic
.isVisible
)
359 tuiClearWin (&winList
[type
]->generic
);
360 if (winList
[type
]->detail
.sourceInfo
.hasLocator
)
361 tuiClearLocatorDisplay ();
362 tuiShowSourceContent (winList
[type
]);
363 checkAndDisplayHighlightIfNeeded (winList
[type
]);
364 tuiEraseExecInfoContent (winList
[type
]);
365 tuiUpdateExecInfo (winList
[type
]);
368 tuiRefreshDataWin ();
375 tuiClearLocatorDisplay ();
376 tuiShowLocatorContent ();
379 } /* tuiRefreshAll */
384 ** Resize all the windows based on the the terminal size. This
385 ** function gets called from within the readline sinwinch handler.
390 int heightDiff
, widthDiff
;
391 extern int screenheight
, screenwidth
; /* in readline */
393 widthDiff
= screenwidth
- termWidth ();
394 heightDiff
= screenheight
- termHeight ();
395 if (heightDiff
|| widthDiff
)
397 TuiLayoutType curLayout
= currentLayout ();
398 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
399 TuiWinInfoPtr firstWin
, secondWin
;
400 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
402 int i
, newHeight
, splitDiff
, cmdSplitDiff
, numWinsDisplayed
= 2;
404 /* turn keypad off while we resize */
405 if (winWithFocus
!= cmdWin
)
406 keypad (cmdWin
->generic
.handle
, FALSE
);
408 setTermHeightTo (screenheight
);
409 setTermWidthTo (screenwidth
);
410 if (curLayout
== SRC_DISASSEM_COMMAND
||
411 curLayout
== SRC_DATA_COMMAND
|| curLayout
== DISASSEM_DATA_COMMAND
)
413 splitDiff
= heightDiff
/ numWinsDisplayed
;
414 cmdSplitDiff
= splitDiff
;
415 if (heightDiff
% numWinsDisplayed
)
422 /* now adjust each window */
428 case DISASSEM_COMMAND
:
429 firstWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
430 firstWin
->generic
.width
+= widthDiff
;
431 locator
->width
+= widthDiff
;
432 /* check for invalid heights */
434 newHeight
= firstWin
->generic
.height
;
435 else if ((firstWin
->generic
.height
+ splitDiff
) >=
436 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
437 newHeight
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
438 else if ((firstWin
->generic
.height
+ splitDiff
) <= 0)
439 newHeight
= MIN_WIN_HEIGHT
;
441 newHeight
= firstWin
->generic
.height
+ splitDiff
;
443 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
444 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
445 cmdWin
->generic
.width
+= widthDiff
;
446 newHeight
= screenheight
- cmdWin
->generic
.origin
.y
;
447 _makeInvisibleAndSetNewHeight (cmdWin
, newHeight
);
448 _makeVisibleWithNewHeight (firstWin
);
449 _makeVisibleWithNewHeight (cmdWin
);
450 if (firstWin
->generic
.contentSize
<= 0)
451 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
454 if (curLayout
== SRC_DISASSEM_COMMAND
)
457 firstWin
->generic
.width
+= widthDiff
;
458 secondWin
= disassemWin
;
459 secondWin
->generic
.width
+= widthDiff
;
464 firstWin
->generic
.width
+= widthDiff
;
465 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
466 secondWin
->generic
.width
+= widthDiff
;
468 /* Change the first window's height/width */
469 /* check for invalid heights */
471 newHeight
= firstWin
->generic
.height
;
472 else if ((firstWin
->generic
.height
+
473 secondWin
->generic
.height
+ (splitDiff
* 2)) >=
474 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
475 newHeight
= (screenheight
- MIN_CMD_WIN_HEIGHT
- 1) / 2;
476 else if ((firstWin
->generic
.height
+ splitDiff
) <= 0)
477 newHeight
= MIN_WIN_HEIGHT
;
479 newHeight
= firstWin
->generic
.height
+ splitDiff
;
480 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
482 if (firstWin
== dataWin
&& widthDiff
!= 0)
483 firstWin
->detail
.dataDisplayInfo
.regsColumnCount
=
484 tuiCalculateRegsColumnCount (
485 firstWin
->detail
.dataDisplayInfo
.regsDisplayType
);
486 locator
->width
+= widthDiff
;
488 /* Change the second window's height/width */
489 /* check for invalid heights */
491 newHeight
= secondWin
->generic
.height
;
492 else if ((firstWin
->generic
.height
+
493 secondWin
->generic
.height
+ (splitDiff
* 2)) >=
494 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
496 newHeight
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
498 newHeight
= (newHeight
/ 2) + 1;
502 else if ((secondWin
->generic
.height
+ splitDiff
) <= 0)
503 newHeight
= MIN_WIN_HEIGHT
;
505 newHeight
= secondWin
->generic
.height
+ splitDiff
;
506 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
507 _makeInvisibleAndSetNewHeight (secondWin
, newHeight
);
509 /* Change the command window's height/width */
510 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
511 _makeInvisibleAndSetNewHeight (
512 cmdWin
, cmdWin
->generic
.height
+ cmdSplitDiff
);
513 _makeVisibleWithNewHeight (firstWin
);
514 _makeVisibleWithNewHeight (secondWin
);
515 _makeVisibleWithNewHeight (cmdWin
);
516 if (firstWin
->generic
.contentSize
<= 0)
517 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
518 if (secondWin
->generic
.contentSize
<= 0)
519 tuiEraseSourceContent (secondWin
, EMPTY_SOURCE_PROMPT
);
523 ** Now remove all invisible windows, and their content so that they get
524 ** created again when called for with the new size
526 for (winType
= SRC_WIN
; (winType
< MAX_MAJOR_WINDOWS
); winType
++)
528 if (winType
!= CMD_WIN
&& m_winPtrNotNull (winList
[winType
]) &&
529 !winList
[winType
]->generic
.isVisible
)
531 freeWindow (winList
[winType
]);
532 winList
[winType
] = (TuiWinInfoPtr
) NULL
;
535 tuiSetWinResizedTo (TRUE
);
536 /* turn keypad back on, unless focus is in the command window */
537 if (winWithFocus
!= cmdWin
)
538 keypad (cmdWin
->generic
.handle
, TRUE
);
545 ** tuiSigwinchHandler()
546 ** SIGWINCH signal handler for the tui. This signal handler is
547 ** always called, even when the readline package clears signals
548 ** because it is set as the old_sigwinch() (TUI only)
551 tuiSigwinchHandler (int signal
)
554 ** Say that a resize was done so that the readline can do it
555 ** later when appropriate.
557 tuiSetWinResizedTo (TRUE
);
560 } /* tuiSigwinchHandler */
564 /*************************
565 ** STATIC LOCAL FUNCTIONS
566 **************************/
570 ** _tuiScrollForward_command().
573 _tuiScrollForward_command (char *arg
, int fromTTY
)
576 TuiWinInfoPtr winToScroll
;
578 if (arg
== (char *) NULL
)
579 _parseScrollingArgs (arg
, &winToScroll
, (int *) NULL
);
581 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
582 tui_scroll (FORWARD_SCROLL
, winToScroll
, numToScroll
);
587 ** _tuiScrollBackward_command().
590 _tuiScrollBackward_command (char *arg
, int fromTTY
)
593 TuiWinInfoPtr winToScroll
;
595 if (arg
== (char *) NULL
)
596 _parseScrollingArgs (arg
, &winToScroll
, (int *) NULL
);
598 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
599 tui_scroll (BACKWARD_SCROLL
, winToScroll
, numToScroll
);
604 ** _tuiScrollLeft_command().
607 _tuiScrollLeft_command (char *arg
, int fromTTY
)
610 TuiWinInfoPtr winToScroll
;
612 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
613 tui_scroll (LEFT_SCROLL
, winToScroll
, numToScroll
);
618 ** _tuiScrollRight_command().
621 _tuiScrollRight_command (char *arg
, int fromTTY
)
624 TuiWinInfoPtr winToScroll
;
626 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
627 tui_scroll (RIGHT_SCROLL
, winToScroll
, numToScroll
);
633 ** Set focus to the window named by 'arg'
636 _tuiSetFocus (char *arg
, int fromTTY
)
638 if (arg
!= (char *) NULL
)
640 char *bufPtr
= (char *) tuiStrDup (arg
);
642 TuiWinInfoPtr winInfo
= (TuiWinInfoPtr
) NULL
;
644 for (i
= 0; (i
< strlen (bufPtr
)); i
++)
645 bufPtr
[i
] = toupper (arg
[i
]);
647 if (subset_compare (bufPtr
, "NEXT"))
648 winInfo
= tuiNextWin (tuiWinWithFocus ());
649 else if (subset_compare (bufPtr
, "PREV"))
650 winInfo
= tuiPrevWin (tuiWinWithFocus ());
652 winInfo
= partialWinByName (bufPtr
);
654 if (winInfo
== (TuiWinInfoPtr
) NULL
|| !winInfo
->generic
.isVisible
)
655 warning ("Invalid window specified. \n\
656 The window name specified must be valid and visible.\n");
659 tuiSetWinFocusTo (winInfo
);
660 keypad (cmdWin
->generic
.handle
, (winInfo
!= cmdWin
));
663 if (dataWin
&& dataWin
->generic
.isVisible
)
664 tuiRefreshDataWin ();
666 printf_filtered ("Focus set to %s window.\n",
667 winName ((TuiGenWinInfoPtr
) tuiWinWithFocus ()));
670 warning ("Incorrect Number of Arguments.\n%s", FOCUS_USAGE
);
680 _tui_vSetFocus (va_list args
)
682 char *arg
= va_arg (args
, char *);
683 int fromTTY
= va_arg (args
, int);
685 _tuiSetFocus (arg
, fromTTY
);
688 } /* tui_vSetFocus */
692 ** _tuiSetFocus_command()
695 _tuiSetFocus_command (char *arg
, int fromTTY
)
697 _tuiSetFocus (arg
, fromTTY
);
702 ** _tuiAllWindowsInfo().
705 _tuiAllWindowsInfo (char *arg
, int fromTTY
)
708 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
710 for (type
= SRC_WIN
; (type
< MAX_MAJOR_WINDOWS
); type
++)
711 if (winList
[type
]->generic
.isVisible
)
713 if (winWithFocus
== winList
[type
])
714 printf_filtered (" %s\t(%d lines) <has focus>\n",
715 winName (&winList
[type
]->generic
),
716 winList
[type
]->generic
.height
);
718 printf_filtered (" %s\t(%d lines)\n",
719 winName (&winList
[type
]->generic
),
720 winList
[type
]->generic
.height
);
724 } /* _tuiAllWindowsInfo */
728 ** _tuiRefreshAll_command().
731 _tuiRefreshAll_command (char *arg
, int fromTTY
)
738 ** _tuiSetWinTabWidth_command().
739 ** Set the height of the specified window.
742 _tuiSetTabWidth_command (char *arg
, int fromTTY
)
744 if (arg
!= (char *) NULL
)
750 tuiSetDefaultTabLen (ts
);
752 warning ("Tab widths greater than 0 must be specified.\n");
756 } /* _tuiSetTabWidth_command */
760 ** _tuiSetWinHeight().
761 ** Set the height of the specified window.
764 _tuiSetWinHeight (char *arg
, int fromTTY
)
766 if (arg
!= (char *) NULL
)
768 char *buf
= tuiStrDup (arg
);
770 char *wname
= (char *) NULL
;
772 TuiWinInfoPtr winInfo
;
775 bufPtr
= strchr (bufPtr
, ' ');
776 if (bufPtr
!= (char *) NULL
)
781 ** Validate the window name
783 for (i
= 0; i
< strlen (wname
); i
++)
784 wname
[i
] = toupper (wname
[i
]);
785 winInfo
= partialWinByName (wname
);
787 if (winInfo
== (TuiWinInfoPtr
) NULL
|| !winInfo
->generic
.isVisible
)
788 warning ("Invalid window specified. \n\
789 The window name specified must be valid and visible.\n");
792 /* Process the size */
793 while (*(++bufPtr
) == ' ')
796 if (*bufPtr
!= (char) 0)
799 int fixedSize
= TRUE
;
802 if (*bufPtr
== '+' || *bufPtr
== '-')
809 inputNo
= atoi (bufPtr
);
817 newHeight
= winInfo
->generic
.height
+ inputNo
;
819 ** Now change the window's height, and adjust all
820 ** other windows around it
822 if (_tuiAdjustWinHeights (winInfo
,
823 newHeight
) == TUI_FAILURE
)
824 warning ("Invalid window height specified.\n%s",
830 warning ("Invalid window height specified.\n%s",
836 printf_filtered (WIN_HEIGHT_USAGE
);
838 if (buf
!= (char *) NULL
)
842 printf_filtered (WIN_HEIGHT_USAGE
);
845 } /* _tuiSetWinHeight */
849 ** _tui_vSetWinHeight().
850 ** Set the height of the specified window, with va_list.
853 _tui_vSetWinHeight (va_list args
)
855 char *arg
= va_arg (args
, char *);
856 int fromTTY
= va_arg (args
, int);
858 _tuiSetWinHeight (arg
, fromTTY
);
861 } /* _tui_vSetWinHeight */
865 ** _tuiSetWinHeight_command().
866 ** Set the height of the specified window, with va_list.
869 _tuiSetWinHeight_command (char *arg
, int fromTTY
)
871 _tuiSetWinHeight (arg
, fromTTY
);
876 ** _tuiXDBsetWinHeight().
877 ** XDB Compatibility command for setting the window height. This will
878 ** increase or decrease the command window by the specified amount.
881 _tuiXDBsetWinHeight (char *arg
, int fromTTY
)
883 if (arg
!= (char *) NULL
)
885 int inputNo
= atoi (arg
);
888 { /* Add 1 for the locator */
889 int newHeight
= termHeight () - (inputNo
+ 1);
891 if (!_newHeightOk (winList
[CMD_WIN
], newHeight
) ||
892 _tuiAdjustWinHeights (winList
[CMD_WIN
],
893 newHeight
) == TUI_FAILURE
)
894 warning ("Invalid window height specified.\n%s",
895 XDBWIN_HEIGHT_USAGE
);
898 warning ("Invalid window height specified.\n%s",
899 XDBWIN_HEIGHT_USAGE
);
902 warning ("Invalid window height specified.\n%s", XDBWIN_HEIGHT_USAGE
);
905 } /* _tuiXDBsetWinHeight */
909 ** _tui_vXDBsetWinHeight().
910 ** Set the height of the specified window, with va_list.
913 _tui_vXDBsetWinHeight (va_list args
)
915 char *arg
= va_arg (args
, char *);
916 int fromTTY
= va_arg (args
, int);
918 _tuiXDBsetWinHeight (arg
, fromTTY
);
921 } /* _tui_vXDBsetWinHeight */
925 ** _tuiSetWinHeight_command().
926 ** Set the height of the specified window, with va_list.
929 _tuiXDBsetWinHeight_command (char *arg
, int fromTTY
)
931 _tuiXDBsetWinHeight (arg
, fromTTY
);
936 ** _tuiAdjustWinHeights().
937 ** Function to adjust all window heights around the primary
940 _tuiAdjustWinHeights (TuiWinInfoPtr primaryWinInfo
, int newHeight
)
942 TuiStatus status
= TUI_FAILURE
;
944 if (_newHeightOk (primaryWinInfo
, newHeight
))
946 status
= TUI_SUCCESS
;
947 if (newHeight
!= primaryWinInfo
->generic
.height
)
950 TuiWinInfoPtr winInfo
;
951 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
952 TuiLayoutType curLayout
= currentLayout ();
954 diff
= (newHeight
- primaryWinInfo
->generic
.height
) * (-1);
955 if (curLayout
== SRC_COMMAND
|| curLayout
== DISASSEM_COMMAND
)
957 TuiWinInfoPtr srcWinInfo
;
959 _makeInvisibleAndSetNewHeight (primaryWinInfo
, newHeight
);
960 if (primaryWinInfo
->generic
.type
== CMD_WIN
)
962 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
963 srcWinInfo
= winInfo
;
967 winInfo
= winList
[CMD_WIN
];
968 srcWinInfo
= primaryWinInfo
;
970 _makeInvisibleAndSetNewHeight (winInfo
,
971 winInfo
->generic
.height
+ diff
);
972 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
973 _makeVisibleWithNewHeight (winInfo
);
974 _makeVisibleWithNewHeight (primaryWinInfo
);
975 if (srcWinInfo
->generic
.contentSize
<= 0)
976 tuiEraseSourceContent (srcWinInfo
, EMPTY_SOURCE_PROMPT
);
980 TuiWinInfoPtr firstWin
, secondWin
;
982 if (curLayout
== SRC_DISASSEM_COMMAND
)
985 secondWin
= disassemWin
;
990 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
992 if (primaryWinInfo
== cmdWin
)
994 ** Split the change in height accross the 1st & 2nd windows
995 ** adjusting them as well.
997 int firstSplitDiff
= diff
/ 2; /* subtract the locator */
998 int secondSplitDiff
= firstSplitDiff
;
1002 if (firstWin
->generic
.height
>
1003 secondWin
->generic
.height
)
1016 /* make sure that the minimum hieghts are honored */
1017 while ((firstWin
->generic
.height
+ firstSplitDiff
) < 3)
1022 while ((secondWin
->generic
.height
+ secondSplitDiff
) < 3)
1027 _makeInvisibleAndSetNewHeight (
1029 firstWin
->generic
.height
+ firstSplitDiff
);
1030 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
1031 _makeInvisibleAndSetNewHeight (
1032 secondWin
, secondWin
->generic
.height
+ secondSplitDiff
);
1033 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1034 _makeInvisibleAndSetNewHeight (cmdWin
, newHeight
);
1038 if ((cmdWin
->generic
.height
+ diff
) < 1)
1040 ** If there is no way to increase the command window
1041 ** take real estate from the 1st or 2nd window.
1043 if ((cmdWin
->generic
.height
+ diff
) < 1)
1046 for (i
= cmdWin
->generic
.height
+ diff
;
1048 if (primaryWinInfo
== firstWin
)
1049 secondWin
->generic
.height
--;
1051 firstWin
->generic
.height
--;
1054 if (primaryWinInfo
== firstWin
)
1055 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
1057 _makeInvisibleAndSetNewHeight (
1059 firstWin
->generic
.height
);
1060 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
1061 if (primaryWinInfo
== secondWin
)
1062 _makeInvisibleAndSetNewHeight (secondWin
, newHeight
);
1064 _makeInvisibleAndSetNewHeight (
1065 secondWin
, secondWin
->generic
.height
);
1066 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1067 if ((cmdWin
->generic
.height
+ diff
) < 1)
1068 _makeInvisibleAndSetNewHeight (cmdWin
, 1);
1070 _makeInvisibleAndSetNewHeight (
1071 cmdWin
, cmdWin
->generic
.height
+ diff
);
1073 _makeVisibleWithNewHeight (cmdWin
);
1074 _makeVisibleWithNewHeight (secondWin
);
1075 _makeVisibleWithNewHeight (firstWin
);
1076 if (firstWin
->generic
.contentSize
<= 0)
1077 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
1078 if (secondWin
->generic
.contentSize
<= 0)
1079 tuiEraseSourceContent (secondWin
, EMPTY_SOURCE_PROMPT
);
1085 } /* _tuiAdjustWinHeights */
1089 ** _makeInvisibleAndSetNewHeight().
1090 ** Function make the target window (and auxillary windows associated
1091 ** with the targer) invisible, and set the new height and location.
1094 _makeInvisibleAndSetNewHeight (TuiWinInfoPtr winInfo
, int height
)
1098 TuiGenWinInfoPtr genWinInfo
;
1101 m_beInvisible (&winInfo
->generic
);
1102 winInfo
->generic
.height
= height
;
1104 winInfo
->generic
.viewportHeight
= height
- 1;
1106 winInfo
->generic
.viewportHeight
= height
;
1107 if (winInfo
!= cmdWin
)
1108 winInfo
->generic
.viewportHeight
--;
1110 /* Now deal with the auxillary windows associated with winInfo */
1111 switch (winInfo
->generic
.type
)
1115 genWinInfo
= winInfo
->detail
.sourceInfo
.executionInfo
;
1116 m_beInvisible (genWinInfo
);
1117 genWinInfo
->height
= height
;
1118 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
;
1120 genWinInfo
->viewportHeight
= height
- 1;
1122 genWinInfo
->viewportHeight
= height
;
1123 if (winInfo
!= cmdWin
)
1124 genWinInfo
->viewportHeight
--;
1126 if (m_hasLocator (winInfo
))
1128 genWinInfo
= locatorWinInfoPtr ();
1129 m_beInvisible (genWinInfo
);
1130 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
+ height
;
1134 /* delete all data item windows */
1135 for (i
= 0; i
< winInfo
->generic
.contentSize
; i
++)
1137 genWinInfo
= (TuiGenWinInfoPtr
) & ((TuiWinElementPtr
)
1138 winInfo
->generic
.content
[i
])->whichElement
.dataWindow
;
1139 tuiDelwin (genWinInfo
->handle
);
1140 genWinInfo
->handle
= (WINDOW
*) NULL
;
1148 } /* _makeInvisibleAndSetNewHeight */
1152 ** _makeVisibleWithNewHeight().
1153 ** Function to make the windows with new heights visible.
1154 ** This means re-creating the windows' content since the window
1155 ** had to be destroyed to be made invisible.
1158 _makeVisibleWithNewHeight (TuiWinInfoPtr winInfo
)
1163 m_beVisible (&winInfo
->generic
);
1164 checkAndDisplayHighlightIfNeeded (winInfo
);
1165 switch (winInfo
->generic
.type
)
1169 freeWinContent (winInfo
->detail
.sourceInfo
.executionInfo
);
1170 m_beVisible (winInfo
->detail
.sourceInfo
.executionInfo
);
1171 if (winInfo
->generic
.content
!= (OpaquePtr
) NULL
)
1173 TuiLineOrAddress lineOrAddr
;
1175 if (winInfo
->generic
.type
== SRC_WIN
)
1177 winInfo
->detail
.sourceInfo
.startLineOrAddr
.lineNo
;
1180 winInfo
->detail
.sourceInfo
.startLineOrAddr
.addr
;
1181 freeWinContent (&winInfo
->generic
);
1182 tuiUpdateSourceWindow (winInfo
,
1183 current_source_symtab
,
1184 ((winInfo
->generic
.type
== SRC_WIN
) ?
1185 (Opaque
) lineOrAddr
.lineNo
:
1189 else if (selected_frame
!= (struct frame_info
*) NULL
)
1192 extern int current_source_line
;
1194 s
= find_pc_symtab (selected_frame
->pc
);
1195 if (winInfo
->generic
.type
== SRC_WIN
)
1196 line
= (Opaque
) current_source_line
;
1201 find_line_pc (s
, current_source_line
, &pc
);
1204 tuiUpdateSourceWindow (winInfo
, s
, line
, TRUE
);
1206 if (m_hasLocator (winInfo
))
1208 m_beVisible (locatorWinInfoPtr ());
1209 tuiClearLocatorDisplay ();
1210 tuiShowLocatorContent ();
1214 tuiDisplayAllData ();
1217 winInfo
->detail
.commandInfo
.curLine
= 0;
1218 winInfo
->detail
.commandInfo
.curch
= 0;
1219 wmove (winInfo
->generic
.handle
,
1220 winInfo
->detail
.commandInfo
.curLine
,
1221 winInfo
->detail
.commandInfo
.curch
);
1228 } /* _makeVisibleWithNewHeight */
1232 _newHeightOk (TuiWinInfoPtr primaryWinInfo
, int newHeight
)
1234 int ok
= (newHeight
< termHeight ());
1238 int diff
, curHeight
;
1239 TuiLayoutType curLayout
= currentLayout ();
1241 diff
= (newHeight
- primaryWinInfo
->generic
.height
) * (-1);
1242 if (curLayout
== SRC_COMMAND
|| curLayout
== DISASSEM_COMMAND
)
1244 ok
= ((primaryWinInfo
->generic
.type
== CMD_WIN
&&
1245 newHeight
<= (termHeight () - 4) &&
1246 newHeight
>= MIN_CMD_WIN_HEIGHT
) ||
1247 (primaryWinInfo
->generic
.type
!= CMD_WIN
&&
1248 newHeight
<= (termHeight () - 2) &&
1249 newHeight
>= MIN_WIN_HEIGHT
));
1251 { /* check the total height */
1252 TuiWinInfoPtr winInfo
;
1254 if (primaryWinInfo
== cmdWin
)
1255 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1259 (winInfo
->generic
.height
+ diff
)) <= termHeight ());
1264 int curTotalHeight
, totalHeight
, minHeight
;
1265 TuiWinInfoPtr firstWin
, secondWin
;
1267 if (curLayout
== SRC_DISASSEM_COMMAND
)
1270 secondWin
= disassemWin
;
1275 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1278 ** We could simply add all the heights to obtain the same result
1279 ** but below is more explicit since we subtract 1 for the
1280 ** line that the first and second windows share, and add one
1284 (firstWin
->generic
.height
+ secondWin
->generic
.height
- 1)
1285 + cmdWin
->generic
.height
+ 1 /*locator */ ;
1286 if (primaryWinInfo
== cmdWin
)
1288 /* locator included since first & second win share a line */
1289 ok
= ((firstWin
->generic
.height
+
1290 secondWin
->generic
.height
+ diff
) >=
1291 (MIN_WIN_HEIGHT
* 2) &&
1292 newHeight
>= MIN_CMD_WIN_HEIGHT
);
1295 totalHeight
= newHeight
+ (firstWin
->generic
.height
+
1296 secondWin
->generic
.height
+ diff
);
1297 minHeight
= MIN_CMD_WIN_HEIGHT
;
1302 minHeight
= MIN_WIN_HEIGHT
;
1304 ** First see if we can increase/decrease the command
1305 ** window. And make sure that the command window is
1308 ok
= ((cmdWin
->generic
.height
+ diff
) > 0);
1311 ** Looks like we have to increase/decrease one of
1312 ** the other windows
1314 if (primaryWinInfo
== firstWin
)
1315 ok
= (secondWin
->generic
.height
+ diff
) >= minHeight
;
1317 ok
= (firstWin
->generic
.height
+ diff
) >= minHeight
;
1321 if (primaryWinInfo
== firstWin
)
1322 totalHeight
= newHeight
+
1323 secondWin
->generic
.height
+
1324 cmdWin
->generic
.height
+ diff
;
1326 totalHeight
= newHeight
+
1327 firstWin
->generic
.height
+
1328 cmdWin
->generic
.height
+ diff
;
1332 ** Now make sure that the proposed total height doesn't exceed
1333 ** the old total height.
1336 ok
= (newHeight
>= minHeight
&& totalHeight
<= curTotalHeight
);
1341 } /* _newHeightOk */
1345 ** _parseScrollingArgs().
1348 _parseScrollingArgs (char *arg
, TuiWinInfoPtr
* winToScroll
, int *numToScroll
)
1352 *winToScroll
= tuiWinWithFocus ();
1355 ** First set up the default window to scroll, in case there is no
1358 if (arg
!= (char *) NULL
)
1362 /* process the number of lines to scroll */
1363 buf
= bufPtr
= tuiStrDup (arg
);
1364 if (isdigit (*bufPtr
))
1369 bufPtr
= strchr (bufPtr
, ' ');
1370 if (bufPtr
!= (char *) NULL
)
1374 *numToScroll
= atoi (numStr
);
1377 else if (numToScroll
)
1378 *numToScroll
= atoi (numStr
);
1381 /* process the window name if one is specified */
1382 if (bufPtr
!= (char *) NULL
)
1388 while (*(++bufPtr
) == ' ')
1391 if (*bufPtr
!= (char) 0)
1394 /* Validate the window name */
1395 for (i
= 0; i
< strlen (wname
); i
++)
1396 wname
[i
] = toupper (wname
[i
]);
1397 *winToScroll
= partialWinByName (wname
);
1399 if (*winToScroll
== (TuiWinInfoPtr
) NULL
||
1400 !(*winToScroll
)->generic
.isVisible
)
1401 warning ("Invalid window specified. \n\
1402 The window name specified must be valid and visible.\n");
1403 else if (*winToScroll
== cmdWin
)
1404 *winToScroll
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1410 } /* _parseScrollingArgs */