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 */
31 #include "breakpoint.h"
36 #include "tuiGeneralWin.h"
38 #include "tuiSourceWin.h"
39 #include "tuiDataWin.h"
41 /*******************************
42 ** External Declarations
43 ********************************/
44 extern void init_page_info ();
46 /*******************************
48 ********************************/
49 static void _makeVisibleWithNewHeight (TuiWinInfoPtr
);
50 static void _makeInvisibleAndSetNewHeight (TuiWinInfoPtr
, int);
51 static TuiStatus
_tuiAdjustWinHeights (TuiWinInfoPtr
, int);
52 static int _newHeightOk (TuiWinInfoPtr
, int);
53 static void _tuiSetTabWidth_command (char *, int);
54 static void _tuiRefreshAll_command (char *, int);
55 static void _tuiSetWinHeight_command (char *, int);
56 static void _tuiXDBsetWinHeight_command (char *, int);
57 static void _tuiAllWindowsInfo (char *, int);
58 static void _tuiSetFocus_command (char *, int);
59 static void _tuiScrollForward_command (char *, int);
60 static void _tuiScrollBackward_command (char *, int);
61 static void _tuiScrollLeft_command (char *, int);
62 static void _tuiScrollRight_command (char *, int);
63 static void _parseScrollingArgs (char *, TuiWinInfoPtr
*, int *);
66 /***************************************
68 ***************************************/
69 #define WIN_HEIGHT_USAGE "Usage: winheight <win_name> [+ | -] <#lines>\n"
70 #define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n"
71 #define FOCUS_USAGE "Usage: focus {<win> | next | prev}\n"
73 /***************************************
75 ***************************************/
78 ** _initialize_tuiWin().
79 ** Function to initialize gdb commands, for tui window manipulation.
82 _initialize_tuiWin (void)
86 add_com ("refresh", class_tui
, _tuiRefreshAll_command
,
87 "Refresh the terminal display.\n");
89 add_com_alias ("U", "refresh", class_tui
, 0);
90 add_com ("tabset", class_tui
, _tuiSetTabWidth_command
,
91 "Set the width (in characters) of tab stops.\n\
92 Usage: tabset <n>\n");
93 add_com ("winheight", class_tui
, _tuiSetWinHeight_command
,
94 "Set the height of a specified window.\n\
95 Usage: winheight <win_name> [+ | -] <#lines>\n\
97 src : the source window\n\
98 cmd : the command window\n\
99 asm : the disassembly window\n\
100 regs : the register display\n");
101 add_com_alias ("wh", "winheight", class_tui
, 0);
102 add_info ("win", _tuiAllWindowsInfo
,
103 "List of all displayed windows.\n");
104 add_com ("focus", class_tui
, _tuiSetFocus_command
,
105 "Set focus to named window or next/prev window.\n\
106 Usage: focus {<win> | next | prev}\n\
107 Valid Window names are:\n\
108 src : the source window\n\
109 asm : the disassembly window\n\
110 regs : the register display\n\
111 cmd : the command window\n");
112 add_com_alias ("fs", "focus", class_tui
, 0);
113 add_com ("+", class_tui
, _tuiScrollForward_command
,
114 "Scroll window forward.\nUsage: + [win] [n]\n");
115 add_com ("-", class_tui
, _tuiScrollBackward_command
,
116 "Scroll window backward.\nUsage: - [win] [n]\n");
117 add_com ("<", class_tui
, _tuiScrollLeft_command
,
118 "Scroll window forward.\nUsage: < [win] [n]\n");
119 add_com (">", class_tui
, _tuiScrollRight_command
,
120 "Scroll window backward.\nUsage: > [win] [n]\n");
122 add_com ("w", class_xdb
, _tuiXDBsetWinHeight_command
,
123 "XDB compatibility command for setting the height of a command window.\n\
124 Usage: w <#lines>\n");
128 } /* _intialize_tuiWin */
132 ** tuiClearWinFocusFrom
133 ** Clear the logical focus from winInfo
136 tuiClearWinFocusFrom (TuiWinInfoPtr winInfo
)
138 if (m_winPtrNotNull (winInfo
))
140 if (winInfo
->generic
.type
!= CMD_WIN
)
141 unhighlightWin (winInfo
);
142 tuiSetWinWithFocus ((TuiWinInfoPtr
) NULL
);
146 } /* tuiClearWinFocusFrom */
150 ** tuiClearWinFocus().
151 ** Clear the window that has focus.
154 tuiClearWinFocus (void)
156 tuiClearWinFocusFrom (tuiWinWithFocus ());
159 } /* tuiClearWinFocus */
164 ** Set the logical focus to winInfo
167 tuiSetWinFocusTo (TuiWinInfoPtr winInfo
)
169 if (m_winPtrNotNull (winInfo
))
171 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
173 if (m_winPtrNotNull (winWithFocus
) &&
174 winWithFocus
->generic
.type
!= CMD_WIN
)
175 unhighlightWin (winWithFocus
);
176 tuiSetWinWithFocus (winInfo
);
177 if (winInfo
->generic
.type
!= CMD_WIN
)
178 highlightWin (winInfo
);
182 } /* tuiSetWinFocusTo */
186 tuiStrDup (char *str
)
188 char *newStr
= (char *) NULL
;
190 if (str
!= (char *) NULL
)
192 newStr
= (char *) xmalloc (strlen (str
) + 1);
193 strcpy (newStr
, str
);
201 ** tuiScrollForward().
204 tuiScrollForward (TuiWinInfoPtr winToScroll
, int numToScroll
)
206 if (winToScroll
!= cmdWin
)
208 int _numToScroll
= numToScroll
;
210 if (numToScroll
== 0)
211 _numToScroll
= winToScroll
->generic
.height
- 3;
213 ** If we are scrolling the source or disassembly window, do a
214 ** "psuedo" scroll since not all of the source is in memory,
215 ** only what is in the viewport. If winToScroll is the
216 ** command window do nothing since the term should handle it.
218 if (winToScroll
== srcWin
)
219 tuiVerticalSourceScroll (FORWARD_SCROLL
, _numToScroll
);
220 else if (winToScroll
== disassemWin
)
221 tuiVerticalDisassemScroll (FORWARD_SCROLL
, _numToScroll
);
222 else if (winToScroll
== dataWin
)
223 tuiVerticalDataScroll (FORWARD_SCROLL
, _numToScroll
);
227 } /* tuiScrollForward */
231 ** tuiScrollBackward().
234 tuiScrollBackward (TuiWinInfoPtr winToScroll
, int numToScroll
)
236 if (winToScroll
!= cmdWin
)
238 int _numToScroll
= numToScroll
;
240 if (numToScroll
== 0)
241 _numToScroll
= winToScroll
->generic
.height
- 3;
243 ** If we are scrolling the source or disassembly window, do a
244 ** "psuedo" scroll since not all of the source is in memory,
245 ** only what is in the viewport. If winToScroll is the
246 ** command window do nothing since the term should handle it.
248 if (winToScroll
== srcWin
)
249 tuiVerticalSourceScroll (BACKWARD_SCROLL
, _numToScroll
);
250 else if (winToScroll
== disassemWin
)
251 tuiVerticalDisassemScroll (BACKWARD_SCROLL
, _numToScroll
);
252 else if (winToScroll
== dataWin
)
253 tuiVerticalDataScroll (BACKWARD_SCROLL
, _numToScroll
);
256 } /* tuiScrollBackward */
263 tuiScrollLeft (TuiWinInfoPtr winToScroll
, int numToScroll
)
265 if (winToScroll
!= cmdWin
)
267 int _numToScroll
= numToScroll
;
269 if (_numToScroll
== 0)
272 ** If we are scrolling the source or disassembly window, do a
273 ** "psuedo" scroll since not all of the source is in memory,
274 ** only what is in the viewport. If winToScroll is the
275 ** command window do nothing since the term should handle it.
277 if (winToScroll
== srcWin
|| winToScroll
== disassemWin
)
278 tuiHorizontalSourceScroll (winToScroll
, LEFT_SCROLL
, _numToScroll
);
281 } /* tuiScrollLeft */
288 tuiScrollRight (TuiWinInfoPtr winToScroll
, int numToScroll
)
290 if (winToScroll
!= cmdWin
)
292 int _numToScroll
= numToScroll
;
294 if (_numToScroll
== 0)
297 ** If we are scrolling the source or disassembly window, do a
298 ** "psuedo" scroll since not all of the source is in memory,
299 ** only what is in the viewport. If winToScroll is the
300 ** command window do nothing since the term should handle it.
302 if (winToScroll
== srcWin
|| winToScroll
== disassemWin
)
303 tuiHorizontalSourceScroll (winToScroll
, RIGHT_SCROLL
, _numToScroll
);
306 } /* tuiScrollRight */
311 ** Scroll a window. Arguments are passed through a va_list.
314 tui_vScroll (va_list args
)
316 TuiScrollDirection direction
= va_arg (args
, TuiScrollDirection
);
317 TuiWinInfoPtr winToScroll
= va_arg (args
, TuiWinInfoPtr
);
318 int numToScroll
= va_arg (args
, int);
323 tuiScrollForward (winToScroll
, numToScroll
);
325 case BACKWARD_SCROLL
:
326 tuiScrollBackward (winToScroll
, numToScroll
);
329 tuiScrollLeft (winToScroll
, numToScroll
);
332 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 tuiDo ((TuiOpaqueFuncPtr
) tui_vScroll
,
588 } /* _tuiScrollForward_command */
592 ** _tuiScrollBackward_command().
595 _tuiScrollBackward_command (char *arg
, int fromTTY
)
598 TuiWinInfoPtr winToScroll
;
600 if (arg
== (char *) NULL
)
601 _parseScrollingArgs (arg
, &winToScroll
, (int *) NULL
);
603 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
604 tuiDo ((TuiOpaqueFuncPtr
) tui_vScroll
,
610 } /* _tuiScrollBackward_command */
614 ** _tuiScrollLeft_command().
617 _tuiScrollLeft_command (char *arg
, int fromTTY
)
620 TuiWinInfoPtr winToScroll
;
622 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
623 tuiDo ((TuiOpaqueFuncPtr
) tui_vScroll
,
629 } /* _tuiScrollLeft_command */
633 ** _tuiScrollRight_command().
636 _tuiScrollRight_command (char *arg
, int fromTTY
)
639 TuiWinInfoPtr winToScroll
;
641 _parseScrollingArgs (arg
, &winToScroll
, &numToScroll
);
642 tuiDo ((TuiOpaqueFuncPtr
) tui_vScroll
,
648 } /* _tuiScrollRight_command */
653 ** Set focus to the window named by 'arg'
656 _tuiSetFocus (char *arg
, int fromTTY
)
658 if (arg
!= (char *) NULL
)
660 char *bufPtr
= (char *) tuiStrDup (arg
);
662 TuiWinInfoPtr winInfo
= (TuiWinInfoPtr
) NULL
;
664 for (i
= 0; (i
< strlen (bufPtr
)); i
++)
665 bufPtr
[i
] = toupper (arg
[i
]);
667 if (subsetCompare (bufPtr
, "NEXT"))
668 winInfo
= tuiNextWin (tuiWinWithFocus ());
669 else if (subsetCompare (bufPtr
, "PREV"))
670 winInfo
= tuiPrevWin (tuiWinWithFocus ());
672 winInfo
= partialWinByName (bufPtr
);
674 if (winInfo
== (TuiWinInfoPtr
) NULL
|| !winInfo
->generic
.isVisible
)
675 warning ("Invalid window specified. \n\
676 The window name specified must be valid and visible.\n");
679 tuiSetWinFocusTo (winInfo
);
680 keypad (cmdWin
->generic
.handle
, (winInfo
!= cmdWin
));
683 if (dataWin
&& dataWin
->generic
.isVisible
)
684 tuiRefreshDataWin ();
686 printf_filtered ("Focus set to %s window.\n",
687 winName ((TuiGenWinInfoPtr
) tuiWinWithFocus ()));
690 warning ("Incorrect Number of Arguments.\n%s", FOCUS_USAGE
);
700 _tui_vSetFocus (va_list args
)
702 char *arg
= va_arg (args
, char *);
703 int fromTTY
= va_arg (args
, int);
705 _tuiSetFocus (arg
, fromTTY
);
708 } /* tui_vSetFocus */
712 ** _tuiSetFocus_command()
715 _tuiSetFocus_command (char *arg
, int fromTTY
)
717 tuiDo ((TuiOpaqueFuncPtr
) _tui_vSetFocus
, arg
, fromTTY
);
724 ** _tuiAllWindowsInfo().
727 _tuiAllWindowsInfo (char *arg
, int fromTTY
)
730 TuiWinInfoPtr winWithFocus
= tuiWinWithFocus ();
732 for (type
= SRC_WIN
; (type
< MAX_MAJOR_WINDOWS
); type
++)
733 if (winList
[type
]->generic
.isVisible
)
735 if (winWithFocus
== winList
[type
])
736 printf_filtered (" %s\t(%d lines) <has focus>\n",
737 winName (&winList
[type
]->generic
),
738 winList
[type
]->generic
.height
);
740 printf_filtered (" %s\t(%d lines)\n",
741 winName (&winList
[type
]->generic
),
742 winList
[type
]->generic
.height
);
746 } /* _tuiAllWindowsInfo */
750 ** _tuiRefreshAll_command().
753 _tuiRefreshAll_command (char *arg
, int fromTTY
)
755 tuiDo ((TuiOpaqueFuncPtr
) tuiRefreshAll
);
760 ** _tuiSetWinTabWidth_command().
761 ** Set the height of the specified window.
764 _tuiSetTabWidth_command (char *arg
, int fromTTY
)
766 if (arg
!= (char *) NULL
)
772 tuiSetDefaultTabLen (ts
);
774 warning ("Tab widths greater than 0 must be specified.\n");
778 } /* _tuiSetTabWidth_command */
782 ** _tuiSetWinHeight().
783 ** Set the height of the specified window.
786 _tuiSetWinHeight (char *arg
, int fromTTY
)
788 if (arg
!= (char *) NULL
)
790 char *buf
= tuiStrDup (arg
);
792 char *wname
= (char *) NULL
;
794 TuiWinInfoPtr winInfo
;
797 bufPtr
= strchr (bufPtr
, ' ');
798 if (bufPtr
!= (char *) NULL
)
803 ** Validate the window name
805 for (i
= 0; i
< strlen (wname
); i
++)
806 wname
[i
] = toupper (wname
[i
]);
807 winInfo
= partialWinByName (wname
);
809 if (winInfo
== (TuiWinInfoPtr
) NULL
|| !winInfo
->generic
.isVisible
)
810 warning ("Invalid window specified. \n\
811 The window name specified must be valid and visible.\n");
814 /* Process the size */
815 while (*(++bufPtr
) == ' ')
818 if (*bufPtr
!= (char) 0)
821 int fixedSize
= TRUE
;
824 if (*bufPtr
== '+' || *bufPtr
== '-')
831 inputNo
= atoi (bufPtr
);
839 newHeight
= winInfo
->generic
.height
+ inputNo
;
841 ** Now change the window's height, and adjust all
842 ** other windows around it
844 if (_tuiAdjustWinHeights (winInfo
,
845 newHeight
) == TUI_FAILURE
)
846 warning ("Invalid window height specified.\n%s",
852 warning ("Invalid window height specified.\n%s",
858 printf_filtered (WIN_HEIGHT_USAGE
);
860 if (buf
!= (char *) NULL
)
864 printf_filtered (WIN_HEIGHT_USAGE
);
867 } /* _tuiSetWinHeight */
871 ** _tui_vSetWinHeight().
872 ** Set the height of the specified window, with va_list.
875 _tui_vSetWinHeight (va_list args
)
877 char *arg
= va_arg (args
, char *);
878 int fromTTY
= va_arg (args
, int);
880 _tuiSetWinHeight (arg
, fromTTY
);
883 } /* _tui_vSetWinHeight */
887 ** _tuiSetWinHeight_command().
888 ** Set the height of the specified window, with va_list.
891 _tuiSetWinHeight_command (char *arg
, int fromTTY
)
893 tuiDo ((TuiOpaqueFuncPtr
) _tui_vSetWinHeight
, arg
, fromTTY
);
896 } /* _tuiSetWinHeight_command */
900 ** _tuiXDBsetWinHeight().
901 ** XDB Compatibility command for setting the window height. This will
902 ** increase or decrease the command window by the specified amount.
905 _tuiXDBsetWinHeight (char *arg
, int fromTTY
)
907 if (arg
!= (char *) NULL
)
909 int inputNo
= atoi (arg
);
912 { /* Add 1 for the locator */
913 int newHeight
= termHeight () - (inputNo
+ 1);
915 if (!_newHeightOk (winList
[CMD_WIN
], newHeight
) ||
916 _tuiAdjustWinHeights (winList
[CMD_WIN
],
917 newHeight
) == TUI_FAILURE
)
918 warning ("Invalid window height specified.\n%s",
919 XDBWIN_HEIGHT_USAGE
);
922 warning ("Invalid window height specified.\n%s",
923 XDBWIN_HEIGHT_USAGE
);
926 warning ("Invalid window height specified.\n%s", XDBWIN_HEIGHT_USAGE
);
929 } /* _tuiXDBsetWinHeight */
933 ** _tui_vXDBsetWinHeight().
934 ** Set the height of the specified window, with va_list.
937 _tui_vXDBsetWinHeight (va_list args
)
939 char *arg
= va_arg (args
, char *);
940 int fromTTY
= va_arg (args
, int);
942 _tuiXDBsetWinHeight (arg
, fromTTY
);
945 } /* _tui_vXDBsetWinHeight */
949 ** _tuiSetWinHeight_command().
950 ** Set the height of the specified window, with va_list.
953 _tuiXDBsetWinHeight_command (char *arg
, int fromTTY
)
955 tuiDo ((TuiOpaqueFuncPtr
) _tui_vXDBsetWinHeight
, arg
, fromTTY
);
958 } /* _tuiXDBsetWinHeight_command */
962 ** _tuiAdjustWinHeights().
963 ** Function to adjust all window heights around the primary
966 _tuiAdjustWinHeights (TuiWinInfoPtr primaryWinInfo
, int newHeight
)
968 TuiStatus status
= TUI_FAILURE
;
970 if (_newHeightOk (primaryWinInfo
, newHeight
))
972 status
= TUI_SUCCESS
;
973 if (newHeight
!= primaryWinInfo
->generic
.height
)
976 TuiWinInfoPtr winInfo
;
977 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
978 TuiLayoutType curLayout
= currentLayout ();
980 diff
= (newHeight
- primaryWinInfo
->generic
.height
) * (-1);
981 if (curLayout
== SRC_COMMAND
|| curLayout
== DISASSEM_COMMAND
)
983 TuiWinInfoPtr srcWinInfo
;
985 _makeInvisibleAndSetNewHeight (primaryWinInfo
, newHeight
);
986 if (primaryWinInfo
->generic
.type
== CMD_WIN
)
988 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
989 srcWinInfo
= winInfo
;
993 winInfo
= winList
[CMD_WIN
];
994 srcWinInfo
= primaryWinInfo
;
996 _makeInvisibleAndSetNewHeight (winInfo
,
997 winInfo
->generic
.height
+ diff
);
998 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
999 _makeVisibleWithNewHeight (winInfo
);
1000 _makeVisibleWithNewHeight (primaryWinInfo
);
1001 if (srcWinInfo
->generic
.contentSize
<= 0)
1002 tuiEraseSourceContent (srcWinInfo
, EMPTY_SOURCE_PROMPT
);
1006 TuiWinInfoPtr firstWin
, secondWin
;
1008 if (curLayout
== SRC_DISASSEM_COMMAND
)
1011 secondWin
= disassemWin
;
1016 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1018 if (primaryWinInfo
== cmdWin
)
1020 ** Split the change in height accross the 1st & 2nd windows
1021 ** adjusting them as well.
1023 int firstSplitDiff
= diff
/ 2; /* subtract the locator */
1024 int secondSplitDiff
= firstSplitDiff
;
1028 if (firstWin
->generic
.height
>
1029 secondWin
->generic
.height
)
1042 /* make sure that the minimum hieghts are honored */
1043 while ((firstWin
->generic
.height
+ firstSplitDiff
) < 3)
1048 while ((secondWin
->generic
.height
+ secondSplitDiff
) < 3)
1053 _makeInvisibleAndSetNewHeight (
1055 firstWin
->generic
.height
+ firstSplitDiff
);
1056 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
1057 _makeInvisibleAndSetNewHeight (
1058 secondWin
, secondWin
->generic
.height
+ secondSplitDiff
);
1059 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1060 _makeInvisibleAndSetNewHeight (cmdWin
, newHeight
);
1064 if ((cmdWin
->generic
.height
+ diff
) < 1)
1066 ** If there is no way to increase the command window
1067 ** take real estate from the 1st or 2nd window.
1069 if ((cmdWin
->generic
.height
+ diff
) < 1)
1072 for (i
= cmdWin
->generic
.height
+ diff
;
1074 if (primaryWinInfo
== firstWin
)
1075 secondWin
->generic
.height
--;
1077 firstWin
->generic
.height
--;
1080 if (primaryWinInfo
== firstWin
)
1081 _makeInvisibleAndSetNewHeight (firstWin
, newHeight
);
1083 _makeInvisibleAndSetNewHeight (
1085 firstWin
->generic
.height
);
1086 secondWin
->generic
.origin
.y
= firstWin
->generic
.height
- 1;
1087 if (primaryWinInfo
== secondWin
)
1088 _makeInvisibleAndSetNewHeight (secondWin
, newHeight
);
1090 _makeInvisibleAndSetNewHeight (
1091 secondWin
, secondWin
->generic
.height
);
1092 cmdWin
->generic
.origin
.y
= locator
->origin
.y
+ 1;
1093 if ((cmdWin
->generic
.height
+ diff
) < 1)
1094 _makeInvisibleAndSetNewHeight (cmdWin
, 1);
1096 _makeInvisibleAndSetNewHeight (
1097 cmdWin
, cmdWin
->generic
.height
+ diff
);
1099 _makeVisibleWithNewHeight (cmdWin
);
1100 _makeVisibleWithNewHeight (secondWin
);
1101 _makeVisibleWithNewHeight (firstWin
);
1102 if (firstWin
->generic
.contentSize
<= 0)
1103 tuiEraseSourceContent (firstWin
, EMPTY_SOURCE_PROMPT
);
1104 if (secondWin
->generic
.contentSize
<= 0)
1105 tuiEraseSourceContent (secondWin
, EMPTY_SOURCE_PROMPT
);
1111 } /* _tuiAdjustWinHeights */
1115 ** _makeInvisibleAndSetNewHeight().
1116 ** Function make the target window (and auxillary windows associated
1117 ** with the targer) invisible, and set the new height and location.
1120 _makeInvisibleAndSetNewHeight (TuiWinInfoPtr winInfo
, int height
)
1124 TuiGenWinInfoPtr genWinInfo
;
1127 m_beInvisible (&winInfo
->generic
);
1128 winInfo
->generic
.height
= height
;
1130 winInfo
->generic
.viewportHeight
= height
- 1;
1132 winInfo
->generic
.viewportHeight
= height
;
1133 if (winInfo
!= cmdWin
)
1134 winInfo
->generic
.viewportHeight
--;
1136 /* Now deal with the auxillary windows associated with winInfo */
1137 switch (winInfo
->generic
.type
)
1141 genWinInfo
= winInfo
->detail
.sourceInfo
.executionInfo
;
1142 m_beInvisible (genWinInfo
);
1143 genWinInfo
->height
= height
;
1144 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
;
1146 genWinInfo
->viewportHeight
= height
- 1;
1148 genWinInfo
->viewportHeight
= height
;
1149 if (winInfo
!= cmdWin
)
1150 genWinInfo
->viewportHeight
--;
1152 if (m_hasLocator (winInfo
))
1154 genWinInfo
= locatorWinInfoPtr ();
1155 m_beInvisible (genWinInfo
);
1156 genWinInfo
->origin
.y
= winInfo
->generic
.origin
.y
+ height
;
1160 /* delete all data item windows */
1161 for (i
= 0; i
< winInfo
->generic
.contentSize
; i
++)
1163 genWinInfo
= (TuiGenWinInfoPtr
) & ((TuiWinElementPtr
)
1164 winInfo
->generic
.content
[i
])->whichElement
.dataWindow
;
1165 tuiDelwin (genWinInfo
->handle
);
1166 genWinInfo
->handle
= (WINDOW
*) NULL
;
1174 } /* _makeInvisibleAndSetNewHeight */
1178 ** _makeVisibleWithNewHeight().
1179 ** Function to make the windows with new heights visible.
1180 ** This means re-creating the windows' content since the window
1181 ** had to be destroyed to be made invisible.
1184 _makeVisibleWithNewHeight (TuiWinInfoPtr winInfo
)
1189 m_beVisible (&winInfo
->generic
);
1190 checkAndDisplayHighlightIfNeeded (winInfo
);
1191 switch (winInfo
->generic
.type
)
1195 freeWinContent (winInfo
->detail
.sourceInfo
.executionInfo
);
1196 m_beVisible (winInfo
->detail
.sourceInfo
.executionInfo
);
1197 if (winInfo
->generic
.content
!= (OpaquePtr
) NULL
)
1199 TuiLineOrAddress lineOrAddr
;
1201 if (winInfo
->generic
.type
== SRC_WIN
)
1203 winInfo
->detail
.sourceInfo
.startLineOrAddr
.lineNo
;
1206 winInfo
->detail
.sourceInfo
.startLineOrAddr
.addr
;
1207 freeWinContent (&winInfo
->generic
);
1208 tuiUpdateSourceWindow (winInfo
,
1209 current_source_symtab
,
1210 ((winInfo
->generic
.type
== SRC_WIN
) ?
1211 (Opaque
) lineOrAddr
.lineNo
:
1215 else if (selected_frame
!= (struct frame_info
*) NULL
)
1218 extern int current_source_line
;
1220 s
= find_pc_symtab (selected_frame
->pc
);
1221 if (winInfo
->generic
.type
== SRC_WIN
)
1222 line
= (Opaque
) current_source_line
;
1224 line
= (Opaque
) find_line_pc (s
, current_source_line
);
1225 tuiUpdateSourceWindow (winInfo
, s
, line
, TRUE
);
1227 if (m_hasLocator (winInfo
))
1229 m_beVisible (locatorWinInfoPtr ());
1230 tuiClearLocatorDisplay ();
1231 tuiShowLocatorContent ();
1235 tuiDisplayAllData ();
1238 winInfo
->detail
.commandInfo
.curLine
= 0;
1239 winInfo
->detail
.commandInfo
.curch
= 0;
1240 wmove (winInfo
->generic
.handle
,
1241 winInfo
->detail
.commandInfo
.curLine
,
1242 winInfo
->detail
.commandInfo
.curch
);
1249 } /* _makeVisibleWithNewHeight */
1253 _newHeightOk (TuiWinInfoPtr primaryWinInfo
, int newHeight
)
1255 int ok
= (newHeight
< termHeight ());
1259 int diff
, curHeight
;
1260 TuiLayoutType curLayout
= currentLayout ();
1262 diff
= (newHeight
- primaryWinInfo
->generic
.height
) * (-1);
1263 if (curLayout
== SRC_COMMAND
|| curLayout
== DISASSEM_COMMAND
)
1265 ok
= ((primaryWinInfo
->generic
.type
== CMD_WIN
&&
1266 newHeight
<= (termHeight () - 4) &&
1267 newHeight
>= MIN_CMD_WIN_HEIGHT
) ||
1268 (primaryWinInfo
->generic
.type
!= CMD_WIN
&&
1269 newHeight
<= (termHeight () - 2) &&
1270 newHeight
>= MIN_WIN_HEIGHT
));
1272 { /* check the total height */
1273 TuiWinInfoPtr winInfo
;
1275 if (primaryWinInfo
== cmdWin
)
1276 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1280 (winInfo
->generic
.height
+ diff
)) <= termHeight ());
1285 int curTotalHeight
, totalHeight
, minHeight
;
1286 TuiWinInfoPtr firstWin
, secondWin
;
1288 if (curLayout
== SRC_DISASSEM_COMMAND
)
1291 secondWin
= disassemWin
;
1296 secondWin
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1299 ** We could simply add all the heights to obtain the same result
1300 ** but below is more explicit since we subtract 1 for the
1301 ** line that the first and second windows share, and add one
1305 (firstWin
->generic
.height
+ secondWin
->generic
.height
- 1)
1306 + cmdWin
->generic
.height
+ 1 /*locator */ ;
1307 if (primaryWinInfo
== cmdWin
)
1309 /* locator included since first & second win share a line */
1310 ok
= ((firstWin
->generic
.height
+
1311 secondWin
->generic
.height
+ diff
) >=
1312 (MIN_WIN_HEIGHT
* 2) &&
1313 newHeight
>= MIN_CMD_WIN_HEIGHT
);
1316 totalHeight
= newHeight
+ (firstWin
->generic
.height
+
1317 secondWin
->generic
.height
+ diff
);
1318 minHeight
= MIN_CMD_WIN_HEIGHT
;
1323 minHeight
= MIN_WIN_HEIGHT
;
1325 ** First see if we can increase/decrease the command
1326 ** window. And make sure that the command window is
1329 ok
= ((cmdWin
->generic
.height
+ diff
) > 0);
1332 ** Looks like we have to increase/decrease one of
1333 ** the other windows
1335 if (primaryWinInfo
== firstWin
)
1336 ok
= (secondWin
->generic
.height
+ diff
) >= minHeight
;
1338 ok
= (firstWin
->generic
.height
+ diff
) >= minHeight
;
1342 if (primaryWinInfo
== firstWin
)
1343 totalHeight
= newHeight
+
1344 secondWin
->generic
.height
+
1345 cmdWin
->generic
.height
+ diff
;
1347 totalHeight
= newHeight
+
1348 firstWin
->generic
.height
+
1349 cmdWin
->generic
.height
+ diff
;
1353 ** Now make sure that the proposed total height doesn't exceed
1354 ** the old total height.
1357 ok
= (newHeight
>= minHeight
&& totalHeight
<= curTotalHeight
);
1362 } /* _newHeightOk */
1366 ** _parseScrollingArgs().
1369 _parseScrollingArgs (char *arg
, TuiWinInfoPtr
* winToScroll
, int *numToScroll
)
1373 *winToScroll
= tuiWinWithFocus ();
1376 ** First set up the default window to scroll, in case there is no
1379 if (arg
!= (char *) NULL
)
1383 /* process the number of lines to scroll */
1384 buf
= bufPtr
= tuiStrDup (arg
);
1385 if (isdigit (*bufPtr
))
1390 bufPtr
= strchr (bufPtr
, ' ');
1391 if (bufPtr
!= (char *) NULL
)
1395 *numToScroll
= atoi (numStr
);
1398 else if (numToScroll
)
1399 *numToScroll
= atoi (numStr
);
1402 /* process the window name if one is specified */
1403 if (bufPtr
!= (char *) NULL
)
1409 while (*(++bufPtr
) == ' ')
1412 if (*bufPtr
!= (char) 0)
1415 /* Validate the window name */
1416 for (i
= 0; i
< strlen (wname
); i
++)
1417 wname
[i
] = toupper (wname
[i
]);
1418 *winToScroll
= partialWinByName (wname
);
1420 if (*winToScroll
== (TuiWinInfoPtr
) NULL
||
1421 !(*winToScroll
)->generic
.isVisible
)
1422 warning ("Invalid window specified. \n\
1423 The window name specified must be valid and visible.\n");
1424 else if (*winToScroll
== cmdWin
)
1425 *winToScroll
= (TuiWinInfoPtr
) (sourceWindows ())->list
[0];
1431 } /* _parseScrollingArgs */