1 /* TUI window generic functions.
3 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
6 Contributed by Hewlett-Packard Company.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* This module contains procedures for handling tui window functions
26 like resize, scrolling, scrolling, changing focus, etc.
28 Author: Susan B. Macchia */
33 #include "breakpoint.h"
35 #include "cli/cli-cmds.h"
40 #include "tui/tui-data.h"
41 #include "tui/tui-wingeneral.h"
42 #include "tui/tui-stack.h"
43 #include "tui/tui-regs.h"
44 #include "tui/tui-disasm.h"
45 #include "tui/tui-source.h"
46 #include "tui/tui-winsource.h"
47 #include "tui/tui-windata.h"
59 #include <readline/readline.h>
61 /*******************************
63 ********************************/
64 static void _makeVisibleWithNewHeight (TuiWinInfoPtr);
65 static void _makeInvisibleAndSetNewHeight (TuiWinInfoPtr, int);
66 static TuiStatus _tuiAdjustWinHeights (TuiWinInfoPtr, int);
67 static int _newHeightOk (TuiWinInfoPtr, int);
68 static void _tuiSetTabWidth_command (char *, int);
69 static void _tuiRefreshAll_command (char *, int);
70 static void _tuiSetWinHeight_command (char *, int);
71 static void _tuiXDBsetWinHeight_command (char *, int);
72 static void _tuiAllWindowsInfo (char *, int);
73 static void _tuiSetFocus_command (char *, int);
74 static void _tuiScrollForward_command (char *, int);
75 static void _tuiScrollBackward_command (char *, int);
76 static void _tuiScrollLeft_command (char *, int);
77 static void _tuiScrollRight_command (char *, int);
78 static void _parseScrollingArgs (char *, TuiWinInfoPtr *, int *);
81 /***************************************
83 ***************************************/
84 #define WIN_HEIGHT_USAGE "Usage: winheight <win_name> [+ | -] <#lines>\n"
85 #define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n"
86 #define FOCUS_USAGE "Usage: focus {<win> | next | prev}\n"
88 /***************************************
90 ***************************************/
93 # define ACS_LRCORNER '+'
96 # define ACS_LLCORNER '+'
99 # define ACS_ULCORNER '+'
102 # define ACS_URCORNER '+'
105 # define ACS_HLINE '-'
108 # define ACS_VLINE '|'
111 /* Possible values for tui-border-kind variable. */
112 static const char *tui_border_kind_enums[] = {
119 /* Possible values for tui-border-mode and tui-active-border-mode. */
120 static const char *tui_border_mode_enums[] = {
137 /* Translation table for border-mode variables.
138 The list of values must be terminated by a NULL.
139 After the NULL value, an entry defines the default. */
140 struct tui_translate tui_border_mode_translate[] = {
141 { "normal", A_NORMAL },
142 { "standout", A_STANDOUT },
143 { "reverse", A_REVERSE },
145 { "half-standout", A_DIM | A_STANDOUT },
147 { "bold-standout", A_BOLD | A_STANDOUT },
149 { "normal", A_NORMAL }
152 /* Translation tables for border-kind, one for each border
153 character (see wborder, border curses operations).
154 -1 is used to indicate the ACS because ACS characters
155 are determined at run time by curses (depends on terminal). */
156 struct tui_translate tui_border_kind_translate_vline[] = {
164 struct tui_translate tui_border_kind_translate_hline[] = {
172 struct tui_translate tui_border_kind_translate_ulcorner[] = {
180 struct tui_translate tui_border_kind_translate_urcorner[] = {
188 struct tui_translate tui_border_kind_translate_llcorner[] = {
196 struct tui_translate tui_border_kind_translate_lrcorner[] = {
205 /* Tui configuration variables controlled with set/show command. */
206 const char *tui_active_border_mode = "bold-standout";
207 const char *tui_border_mode = "normal";
208 const char *tui_border_kind = "acs";
210 /* Tui internal configuration variables. These variables are
211 updated by tui_update_variables to reflect the tui configuration
213 chtype tui_border_vline;
214 chtype tui_border_hline;
215 chtype tui_border_ulcorner;
216 chtype tui_border_urcorner;
217 chtype tui_border_llcorner;
218 chtype tui_border_lrcorner;
220 int tui_border_attrs;
221 int tui_active_border_attrs;
223 /* Identify the item in the translation table.
224 When the item is not recognized, use the default entry. */
225 static struct tui_translate *
226 translate (const char *name, struct tui_translate *table)
230 if (name && strcmp (table->name, name) == 0)
235 /* Not found, return default entry. */
240 /* Update the tui internal configuration according to gdb settings.
241 Returns 1 if the configuration has changed and the screen should
244 tui_update_variables ()
247 struct tui_translate *entry;
249 entry = translate (tui_border_mode, tui_border_mode_translate);
250 if (tui_border_attrs != entry->value)
252 tui_border_attrs = entry->value;
255 entry = translate (tui_active_border_mode, tui_border_mode_translate);
256 if (tui_active_border_attrs != entry->value)
258 tui_active_border_attrs = entry->value;
262 /* If one corner changes, all characters are changed.
263 Only check the first one. The ACS characters are determined at
264 run time by curses terminal management. */
265 entry = translate (tui_border_kind, tui_border_kind_translate_lrcorner);
266 if (tui_border_lrcorner != (chtype) entry->value)
268 tui_border_lrcorner = (entry->value < 0) ? ACS_LRCORNER : entry->value;
271 entry = translate (tui_border_kind, tui_border_kind_translate_llcorner);
272 tui_border_llcorner = (entry->value < 0) ? ACS_LLCORNER : entry->value;
274 entry = translate (tui_border_kind, tui_border_kind_translate_ulcorner);
275 tui_border_ulcorner = (entry->value < 0) ? ACS_ULCORNER : entry->value;
277 entry = translate (tui_border_kind, tui_border_kind_translate_urcorner);
278 tui_border_urcorner = (entry->value < 0) ? ACS_URCORNER : entry->value;
280 entry = translate (tui_border_kind, tui_border_kind_translate_hline);
281 tui_border_hline = (entry->value < 0) ? ACS_HLINE : entry->value;
283 entry = translate (tui_border_kind, tui_border_kind_translate_vline);
284 tui_border_vline = (entry->value < 0) ? ACS_VLINE : entry->value;
290 set_tui_cmd (char *args, int from_tty)
295 show_tui_cmd (char *args, int from_tty)
300 ** _initialize_tuiWin().
301 ** Function to initialize gdb commands, for tui window manipulation.
304 _initialize_tuiWin (void)
306 struct cmd_list_element *c;
307 static struct cmd_list_element *tui_setlist;
308 static struct cmd_list_element *tui_showlist;
310 /* Define the classes of commands.
311 They will appear in the help list in the reverse of this order. */
312 add_cmd ("tui", class_tui, NULL,
313 "Text User Interface commands.",
316 add_prefix_cmd ("tui", class_tui, set_tui_cmd,
317 "TUI configuration variables",
318 &tui_setlist, "set tui ",
319 0/*allow-unknown*/, &setlist);
320 add_prefix_cmd ("tui", class_tui, show_tui_cmd,
321 "TUI configuration variables",
322 &tui_showlist, "show tui ",
323 0/*allow-unknown*/, &showlist);
325 add_com ("refresh", class_tui, _tuiRefreshAll_command,
326 "Refresh the terminal display.\n");
328 add_com_alias ("U", "refresh", class_tui, 0);
329 add_com ("tabset", class_tui, _tuiSetTabWidth_command,
330 "Set the width (in characters) of tab stops.\n\
331 Usage: tabset <n>\n");
332 add_com ("winheight", class_tui, _tuiSetWinHeight_command,
333 "Set the height of a specified window.\n\
334 Usage: winheight <win_name> [+ | -] <#lines>\n\
336 src : the source window\n\
337 cmd : the command window\n\
338 asm : the disassembly window\n\
339 regs : the register display\n");
340 add_com_alias ("wh", "winheight", class_tui, 0);
341 add_info ("win", _tuiAllWindowsInfo,
342 "List of all displayed windows.\n");
343 add_com ("focus", class_tui, _tuiSetFocus_command,
344 "Set focus to named window or next/prev window.\n\
345 Usage: focus {<win> | next | prev}\n\
346 Valid Window names are:\n\
347 src : the source window\n\
348 asm : the disassembly window\n\
349 regs : the register display\n\
350 cmd : the command window\n");
351 add_com_alias ("fs", "focus", class_tui, 0);
352 add_com ("+", class_tui, _tuiScrollForward_command,
353 "Scroll window forward.\nUsage: + [win] [n]\n");
354 add_com ("-", class_tui, _tuiScrollBackward_command,
355 "Scroll window backward.\nUsage: - [win] [n]\n");
356 add_com ("<", class_tui, _tuiScrollLeft_command,
357 "Scroll window forward.\nUsage: < [win] [n]\n");
358 add_com (">", class_tui, _tuiScrollRight_command,
359 "Scroll window backward.\nUsage: > [win] [n]\n");
361 add_com ("w", class_xdb, _tuiXDBsetWinHeight_command,
362 "XDB compatibility command for setting the height of a command window.\n\
363 Usage: w <#lines>\n");
365 /* Define the tui control variables. */
367 ("border-kind", no_class,
368 tui_border_kind_enums, &tui_border_kind,
369 "Set the kind of border for TUI windows.\n"
370 "This variable controls the border of TUI windows:\n"
371 "space use a white space\n"
372 "ascii use ascii characters + - | for the border\n"
373 "acs use the Alternate Character Set\n",
375 add_show_from_set (c, &tui_showlist);
378 ("border-mode", no_class,
379 tui_border_mode_enums, &tui_border_mode,
380 "Set the attribute mode to use for the TUI window borders.\n"
381 "This variable controls the attributes to use for the window borders:\n"
382 "normal normal display\n"
383 "standout use highlight mode of terminal\n"
384 "reverse use reverse video mode\n"
385 "half use half bright\n"
386 "half-standout use half bright and standout mode\n"
387 "bold use extra bright or bold\n"
388 "bold-standout use extra bright or bold with standout mode\n",
390 add_show_from_set (c, &tui_showlist);
393 ("active-border-mode", no_class,
394 tui_border_mode_enums, &tui_active_border_mode,
395 "Set the attribute mode to use for the active TUI window border.\n"
396 "This variable controls the attributes to use for the active window border:\n"
397 "normal normal display\n"
398 "standout use highlight mode of terminal\n"
399 "reverse use reverse video mode\n"
400 "half use half bright\n"
401 "half-standout use half bright and standout mode\n"
402 "bold use extra bright or bold\n"
403 "bold-standout use extra bright or bold with standout mode\n",
405 add_show_from_set (c, &tui_showlist);
408 /* Update gdb's knowledge of the terminal size. */
410 tui_update_gdb_sizes ()
413 int screenheight, screenwidth;
415 rl_get_screen_size (&screenheight, &screenwidth);
416 /* Set to TUI command window dimension or use readline values. */
417 sprintf (cmd, "set width %d",
418 tui_active ? cmdWin->generic.width : screenwidth);
419 execute_command (cmd, 0);
420 sprintf (cmd, "set height %d",
421 tui_active ? cmdWin->generic.height : screenheight);
422 execute_command (cmd, 0);
428 ** Set the logical focus to winInfo
431 tuiSetWinFocusTo (TuiWinInfoPtr winInfo)
433 if (m_winPtrNotNull (winInfo))
435 TuiWinInfoPtr winWithFocus = tuiWinWithFocus ();
437 if (m_winPtrNotNull (winWithFocus) &&
438 winWithFocus->generic.type != CMD_WIN)
439 unhighlightWin (winWithFocus);
440 tuiSetWinWithFocus (winInfo);
441 if (winInfo->generic.type != CMD_WIN)
442 highlightWin (winInfo);
446 } /* tuiSetWinFocusTo */
450 ** tuiScrollForward().
453 tuiScrollForward (TuiWinInfoPtr winToScroll, int numToScroll)
455 if (winToScroll != cmdWin)
457 int _numToScroll = numToScroll;
459 if (numToScroll == 0)
460 _numToScroll = winToScroll->generic.height - 3;
462 ** If we are scrolling the source or disassembly window, do a
463 ** "psuedo" scroll since not all of the source is in memory,
464 ** only what is in the viewport. If winToScroll is the
465 ** command window do nothing since the term should handle it.
467 if (winToScroll == srcWin)
468 tuiVerticalSourceScroll (FORWARD_SCROLL, _numToScroll);
469 else if (winToScroll == disassemWin)
470 tui_vertical_disassem_scroll (FORWARD_SCROLL, _numToScroll);
471 else if (winToScroll == dataWin)
472 tuiVerticalDataScroll (FORWARD_SCROLL, _numToScroll);
476 } /* tuiScrollForward */
480 ** tuiScrollBackward().
483 tuiScrollBackward (TuiWinInfoPtr winToScroll, int numToScroll)
485 if (winToScroll != cmdWin)
487 int _numToScroll = numToScroll;
489 if (numToScroll == 0)
490 _numToScroll = winToScroll->generic.height - 3;
492 ** If we are scrolling the source or disassembly window, do a
493 ** "psuedo" scroll since not all of the source is in memory,
494 ** only what is in the viewport. If winToScroll is the
495 ** command window do nothing since the term should handle it.
497 if (winToScroll == srcWin)
498 tuiVerticalSourceScroll (BACKWARD_SCROLL, _numToScroll);
499 else if (winToScroll == disassemWin)
500 tui_vertical_disassem_scroll (BACKWARD_SCROLL, _numToScroll);
501 else if (winToScroll == dataWin)
502 tuiVerticalDataScroll (BACKWARD_SCROLL, _numToScroll);
505 } /* tuiScrollBackward */
512 tuiScrollLeft (TuiWinInfoPtr winToScroll, int numToScroll)
514 if (winToScroll != cmdWin)
516 int _numToScroll = numToScroll;
518 if (_numToScroll == 0)
521 ** If we are scrolling the source or disassembly window, do a
522 ** "psuedo" scroll since not all of the source is in memory,
523 ** only what is in the viewport. If winToScroll is the
524 ** command window do nothing since the term should handle it.
526 if (winToScroll == srcWin || winToScroll == disassemWin)
527 tuiHorizontalSourceScroll (winToScroll, LEFT_SCROLL, _numToScroll);
530 } /* tuiScrollLeft */
537 tuiScrollRight (TuiWinInfoPtr winToScroll, int numToScroll)
539 if (winToScroll != cmdWin)
541 int _numToScroll = numToScroll;
543 if (_numToScroll == 0)
546 ** If we are scrolling the source or disassembly window, do a
547 ** "psuedo" scroll since not all of the source is in memory,
548 ** only what is in the viewport. If winToScroll is the
549 ** command window do nothing since the term should handle it.
551 if (winToScroll == srcWin || winToScroll == disassemWin)
552 tuiHorizontalSourceScroll (winToScroll, RIGHT_SCROLL, _numToScroll);
555 } /* tuiScrollRight */
560 ** Scroll a window. Arguments are passed through a va_list.
563 tui_scroll (TuiScrollDirection direction,
564 TuiWinInfoPtr winToScroll,
570 tuiScrollForward (winToScroll, numToScroll);
572 case BACKWARD_SCROLL:
573 tuiScrollBackward (winToScroll, numToScroll);
576 tuiScrollLeft (winToScroll, numToScroll);
579 tuiScrollRight (winToScroll, numToScroll);
595 clearok (curscr, TRUE);
596 refreshAll (winList);
597 for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++)
599 if (winList[type] && winList[type]->generic.isVisible)
605 tuiShowSourceContent (winList[type]);
606 checkAndDisplayHighlightIfNeeded (winList[type]);
607 tuiEraseExecInfoContent (winList[type]);
608 tuiUpdateExecInfo (winList[type]);
611 tuiRefreshDataWin ();
618 tui_show_locator_content ();
624 ** Resize all the windows based on the the terminal size. This
625 ** function gets called from within the readline sinwinch handler.
630 int heightDiff, widthDiff;
631 int screenheight, screenwidth;
633 rl_get_screen_size (&screenheight, &screenwidth);
634 widthDiff = screenwidth - termWidth ();
635 heightDiff = screenheight - termHeight ();
636 if (heightDiff || widthDiff)
638 TuiLayoutType curLayout = currentLayout ();
639 TuiWinInfoPtr winWithFocus = tuiWinWithFocus ();
640 TuiWinInfoPtr firstWin, secondWin;
641 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
643 int newHeight, splitDiff, cmdSplitDiff, numWinsDisplayed = 2;
645 /* turn keypad off while we resize */
646 if (winWithFocus != cmdWin)
647 keypad (cmdWin->generic.handle, FALSE);
648 tui_update_gdb_sizes ();
649 setTermHeightTo (screenheight);
650 setTermWidthTo (screenwidth);
651 if (curLayout == SRC_DISASSEM_COMMAND ||
652 curLayout == SRC_DATA_COMMAND || curLayout == DISASSEM_DATA_COMMAND)
654 splitDiff = heightDiff / numWinsDisplayed;
655 cmdSplitDiff = splitDiff;
656 if (heightDiff % numWinsDisplayed)
663 /* now adjust each window */
669 case DISASSEM_COMMAND:
670 firstWin = (TuiWinInfoPtr) (sourceWindows ())->list[0];
671 firstWin->generic.width += widthDiff;
672 locator->width += widthDiff;
673 /* check for invalid heights */
675 newHeight = firstWin->generic.height;
676 else if ((firstWin->generic.height + splitDiff) >=
677 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
678 newHeight = screenheight - MIN_CMD_WIN_HEIGHT - 1;
679 else if ((firstWin->generic.height + splitDiff) <= 0)
680 newHeight = MIN_WIN_HEIGHT;
682 newHeight = firstWin->generic.height + splitDiff;
684 _makeInvisibleAndSetNewHeight (firstWin, newHeight);
685 cmdWin->generic.origin.y = locator->origin.y + 1;
686 cmdWin->generic.width += widthDiff;
687 newHeight = screenheight - cmdWin->generic.origin.y;
688 _makeInvisibleAndSetNewHeight (cmdWin, newHeight);
689 _makeVisibleWithNewHeight (firstWin);
690 _makeVisibleWithNewHeight (cmdWin);
691 if (firstWin->generic.contentSize <= 0)
692 tuiEraseSourceContent (firstWin, EMPTY_SOURCE_PROMPT);
695 if (curLayout == SRC_DISASSEM_COMMAND)
698 firstWin->generic.width += widthDiff;
699 secondWin = disassemWin;
700 secondWin->generic.width += widthDiff;
705 firstWin->generic.width += widthDiff;
706 secondWin = (TuiWinInfoPtr) (sourceWindows ())->list[0];
707 secondWin->generic.width += widthDiff;
709 /* Change the first window's height/width */
710 /* check for invalid heights */
712 newHeight = firstWin->generic.height;
713 else if ((firstWin->generic.height +
714 secondWin->generic.height + (splitDiff * 2)) >=
715 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
716 newHeight = (screenheight - MIN_CMD_WIN_HEIGHT - 1) / 2;
717 else if ((firstWin->generic.height + splitDiff) <= 0)
718 newHeight = MIN_WIN_HEIGHT;
720 newHeight = firstWin->generic.height + splitDiff;
721 _makeInvisibleAndSetNewHeight (firstWin, newHeight);
723 if (firstWin == dataWin && widthDiff != 0)
724 firstWin->detail.dataDisplayInfo.regsColumnCount =
725 tui_calculate_regs_column_count (
726 firstWin->detail.dataDisplayInfo.regsDisplayType);
727 locator->width += widthDiff;
729 /* Change the second window's height/width */
730 /* check for invalid heights */
732 newHeight = secondWin->generic.height;
733 else if ((firstWin->generic.height +
734 secondWin->generic.height + (splitDiff * 2)) >=
735 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
737 newHeight = screenheight - MIN_CMD_WIN_HEIGHT - 1;
739 newHeight = (newHeight / 2) + 1;
743 else if ((secondWin->generic.height + splitDiff) <= 0)
744 newHeight = MIN_WIN_HEIGHT;
746 newHeight = secondWin->generic.height + splitDiff;
747 secondWin->generic.origin.y = firstWin->generic.height - 1;
748 _makeInvisibleAndSetNewHeight (secondWin, newHeight);
750 /* Change the command window's height/width */
751 cmdWin->generic.origin.y = locator->origin.y + 1;
752 _makeInvisibleAndSetNewHeight (
753 cmdWin, cmdWin->generic.height + cmdSplitDiff);
754 _makeVisibleWithNewHeight (firstWin);
755 _makeVisibleWithNewHeight (secondWin);
756 _makeVisibleWithNewHeight (cmdWin);
757 if (firstWin->generic.contentSize <= 0)
758 tuiEraseSourceContent (firstWin, EMPTY_SOURCE_PROMPT);
759 if (secondWin->generic.contentSize <= 0)
760 tuiEraseSourceContent (secondWin, EMPTY_SOURCE_PROMPT);
764 ** Now remove all invisible windows, and their content so that they get
765 ** created again when called for with the new size
767 for (winType = SRC_WIN; (winType < MAX_MAJOR_WINDOWS); winType++)
769 if (winType != CMD_WIN && m_winPtrNotNull (winList[winType]) &&
770 !winList[winType]->generic.isVisible)
772 freeWindow (winList[winType]);
773 winList[winType] = (TuiWinInfoPtr) NULL;
776 tuiSetWinResizedTo (TRUE);
777 /* turn keypad back on, unless focus is in the command window */
778 if (winWithFocus != cmdWin)
779 keypad (cmdWin->generic.handle, TRUE);
786 ** tuiSigwinchHandler()
787 ** SIGWINCH signal handler for the tui. This signal handler is
788 ** always called, even when the readline package clears signals
789 ** because it is set as the old_sigwinch() (TUI only)
792 tuiSigwinchHandler (int signal)
795 ** Say that a resize was done so that the readline can do it
796 ** later when appropriate.
798 tuiSetWinResizedTo (TRUE);
801 } /* tuiSigwinchHandler */
805 /*************************
806 ** STATIC LOCAL FUNCTIONS
807 **************************/
811 ** _tuiScrollForward_command().
814 _tuiScrollForward_command (char *arg, int fromTTY)
817 TuiWinInfoPtr winToScroll;
819 /* Make sure the curses mode is enabled. */
821 if (arg == (char *) NULL)
822 _parseScrollingArgs (arg, &winToScroll, (int *) NULL);
824 _parseScrollingArgs (arg, &winToScroll, &numToScroll);
825 tui_scroll (FORWARD_SCROLL, winToScroll, numToScroll);
830 ** _tuiScrollBackward_command().
833 _tuiScrollBackward_command (char *arg, int fromTTY)
836 TuiWinInfoPtr winToScroll;
838 /* Make sure the curses mode is enabled. */
840 if (arg == (char *) NULL)
841 _parseScrollingArgs (arg, &winToScroll, (int *) NULL);
843 _parseScrollingArgs (arg, &winToScroll, &numToScroll);
844 tui_scroll (BACKWARD_SCROLL, winToScroll, numToScroll);
849 ** _tuiScrollLeft_command().
852 _tuiScrollLeft_command (char *arg, int fromTTY)
855 TuiWinInfoPtr winToScroll;
857 /* Make sure the curses mode is enabled. */
859 _parseScrollingArgs (arg, &winToScroll, &numToScroll);
860 tui_scroll (LEFT_SCROLL, winToScroll, numToScroll);
865 ** _tuiScrollRight_command().
868 _tuiScrollRight_command (char *arg, int fromTTY)
871 TuiWinInfoPtr winToScroll;
873 /* Make sure the curses mode is enabled. */
875 _parseScrollingArgs (arg, &winToScroll, &numToScroll);
876 tui_scroll (RIGHT_SCROLL, winToScroll, numToScroll);
882 ** Set focus to the window named by 'arg'
885 _tuiSetFocus (char *arg, int fromTTY)
887 if (arg != (char *) NULL)
889 char *bufPtr = (char *) xstrdup (arg);
891 TuiWinInfoPtr winInfo = (TuiWinInfoPtr) NULL;
893 for (i = 0; (i < strlen (bufPtr)); i++)
894 bufPtr[i] = toupper (arg[i]);
896 if (subset_compare (bufPtr, "NEXT"))
897 winInfo = tuiNextWin (tuiWinWithFocus ());
898 else if (subset_compare (bufPtr, "PREV"))
899 winInfo = tuiPrevWin (tuiWinWithFocus ());
901 winInfo = partialWinByName (bufPtr);
903 if (winInfo == (TuiWinInfoPtr) NULL || !winInfo->generic.isVisible)
904 warning ("Invalid window specified. \n\
905 The window name specified must be valid and visible.\n");
908 tuiSetWinFocusTo (winInfo);
909 keypad (cmdWin->generic.handle, (winInfo != cmdWin));
912 if (dataWin && dataWin->generic.isVisible)
913 tuiRefreshDataWin ();
915 printf_filtered ("Focus set to %s window.\n",
916 winName ((TuiGenWinInfoPtr) tuiWinWithFocus ()));
919 warning ("Incorrect Number of Arguments.\n%s", FOCUS_USAGE);
925 ** _tuiSetFocus_command()
928 _tuiSetFocus_command (char *arg, int fromTTY)
930 /* Make sure the curses mode is enabled. */
932 _tuiSetFocus (arg, fromTTY);
937 ** _tuiAllWindowsInfo().
940 _tuiAllWindowsInfo (char *arg, int fromTTY)
943 TuiWinInfoPtr winWithFocus = tuiWinWithFocus ();
945 for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
946 if (winList[type] && winList[type]->generic.isVisible)
948 if (winWithFocus == winList[type])
949 printf_filtered (" %s\t(%d lines) <has focus>\n",
950 winName (&winList[type]->generic),
951 winList[type]->generic.height);
953 printf_filtered (" %s\t(%d lines)\n",
954 winName (&winList[type]->generic),
955 winList[type]->generic.height);
959 } /* _tuiAllWindowsInfo */
963 ** _tuiRefreshAll_command().
966 _tuiRefreshAll_command (char *arg, int fromTTY)
968 /* Make sure the curses mode is enabled. */
976 ** _tuiSetWinTabWidth_command().
977 ** Set the height of the specified window.
980 _tuiSetTabWidth_command (char *arg, int fromTTY)
982 /* Make sure the curses mode is enabled. */
984 if (arg != (char *) NULL)
990 tuiSetDefaultTabLen (ts);
992 warning ("Tab widths greater than 0 must be specified.\n");
996 } /* _tuiSetTabWidth_command */
1000 ** _tuiSetWinHeight().
1001 ** Set the height of the specified window.
1004 _tuiSetWinHeight (char *arg, int fromTTY)
1006 /* Make sure the curses mode is enabled. */
1008 if (arg != (char *) NULL)
1010 char *buf = xstrdup (arg);
1012 char *wname = (char *) NULL;
1014 TuiWinInfoPtr winInfo;
1017 bufPtr = strchr (bufPtr, ' ');
1018 if (bufPtr != (char *) NULL)
1023 ** Validate the window name
1025 for (i = 0; i < strlen (wname); i++)
1026 wname[i] = toupper (wname[i]);
1027 winInfo = partialWinByName (wname);
1029 if (winInfo == (TuiWinInfoPtr) NULL || !winInfo->generic.isVisible)
1030 warning ("Invalid window specified. \n\
1031 The window name specified must be valid and visible.\n");
1034 /* Process the size */
1035 while (*(++bufPtr) == ' ')
1038 if (*bufPtr != (char) 0)
1041 int fixedSize = TRUE;
1044 if (*bufPtr == '+' || *bufPtr == '-')
1051 inputNo = atoi (bufPtr);
1057 newHeight = inputNo;
1059 newHeight = winInfo->generic.height + inputNo;
1061 ** Now change the window's height, and adjust all
1062 ** other windows around it
1064 if (_tuiAdjustWinHeights (winInfo,
1065 newHeight) == TUI_FAILURE)
1066 warning ("Invalid window height specified.\n%s",
1069 tui_update_gdb_sizes ();
1072 warning ("Invalid window height specified.\n%s",
1078 printf_filtered (WIN_HEIGHT_USAGE);
1080 if (buf != (char *) NULL)
1084 printf_filtered (WIN_HEIGHT_USAGE);
1087 } /* _tuiSetWinHeight */
1090 ** _tuiSetWinHeight_command().
1091 ** Set the height of the specified window, with va_list.
1094 _tuiSetWinHeight_command (char *arg, int fromTTY)
1096 /* Make sure the curses mode is enabled. */
1098 _tuiSetWinHeight (arg, fromTTY);
1103 ** _tuiXDBsetWinHeight().
1104 ** XDB Compatibility command for setting the window height. This will
1105 ** increase or decrease the command window by the specified amount.
1108 _tuiXDBsetWinHeight (char *arg, int fromTTY)
1110 /* Make sure the curses mode is enabled. */
1112 if (arg != (char *) NULL)
1114 int inputNo = atoi (arg);
1117 { /* Add 1 for the locator */
1118 int newHeight = termHeight () - (inputNo + 1);
1120 if (!_newHeightOk (winList[CMD_WIN], newHeight) ||
1121 _tuiAdjustWinHeights (winList[CMD_WIN],
1122 newHeight) == TUI_FAILURE)
1123 warning ("Invalid window height specified.\n%s",
1124 XDBWIN_HEIGHT_USAGE);
1127 warning ("Invalid window height specified.\n%s",
1128 XDBWIN_HEIGHT_USAGE);
1131 warning ("Invalid window height specified.\n%s", XDBWIN_HEIGHT_USAGE);
1134 } /* _tuiXDBsetWinHeight */
1137 ** _tuiSetWinHeight_command().
1138 ** Set the height of the specified window, with va_list.
1141 _tuiXDBsetWinHeight_command (char *arg, int fromTTY)
1143 _tuiXDBsetWinHeight (arg, fromTTY);
1148 ** _tuiAdjustWinHeights().
1149 ** Function to adjust all window heights around the primary
1152 _tuiAdjustWinHeights (TuiWinInfoPtr primaryWinInfo, int newHeight)
1154 TuiStatus status = TUI_FAILURE;
1156 if (_newHeightOk (primaryWinInfo, newHeight))
1158 status = TUI_SUCCESS;
1159 if (newHeight != primaryWinInfo->generic.height)
1162 TuiWinInfoPtr winInfo;
1163 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
1164 TuiLayoutType curLayout = currentLayout ();
1166 diff = (newHeight - primaryWinInfo->generic.height) * (-1);
1167 if (curLayout == SRC_COMMAND || curLayout == DISASSEM_COMMAND)
1169 TuiWinInfoPtr srcWinInfo;
1171 _makeInvisibleAndSetNewHeight (primaryWinInfo, newHeight);
1172 if (primaryWinInfo->generic.type == CMD_WIN)
1174 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[0];
1175 srcWinInfo = winInfo;
1179 winInfo = winList[CMD_WIN];
1180 srcWinInfo = primaryWinInfo;
1182 _makeInvisibleAndSetNewHeight (winInfo,
1183 winInfo->generic.height + diff);
1184 cmdWin->generic.origin.y = locator->origin.y + 1;
1185 _makeVisibleWithNewHeight (winInfo);
1186 _makeVisibleWithNewHeight (primaryWinInfo);
1187 if (srcWinInfo->generic.contentSize <= 0)
1188 tuiEraseSourceContent (srcWinInfo, EMPTY_SOURCE_PROMPT);
1192 TuiWinInfoPtr firstWin, secondWin;
1194 if (curLayout == SRC_DISASSEM_COMMAND)
1197 secondWin = disassemWin;
1202 secondWin = (TuiWinInfoPtr) (sourceWindows ())->list[0];
1204 if (primaryWinInfo == cmdWin)
1206 ** Split the change in height accross the 1st & 2nd windows
1207 ** adjusting them as well.
1209 int firstSplitDiff = diff / 2; /* subtract the locator */
1210 int secondSplitDiff = firstSplitDiff;
1214 if (firstWin->generic.height >
1215 secondWin->generic.height)
1228 /* make sure that the minimum hieghts are honored */
1229 while ((firstWin->generic.height + firstSplitDiff) < 3)
1234 while ((secondWin->generic.height + secondSplitDiff) < 3)
1239 _makeInvisibleAndSetNewHeight (
1241 firstWin->generic.height + firstSplitDiff);
1242 secondWin->generic.origin.y = firstWin->generic.height - 1;
1243 _makeInvisibleAndSetNewHeight (
1244 secondWin, secondWin->generic.height + secondSplitDiff);
1245 cmdWin->generic.origin.y = locator->origin.y + 1;
1246 _makeInvisibleAndSetNewHeight (cmdWin, newHeight);
1250 if ((cmdWin->generic.height + diff) < 1)
1252 ** If there is no way to increase the command window
1253 ** take real estate from the 1st or 2nd window.
1255 if ((cmdWin->generic.height + diff) < 1)
1258 for (i = cmdWin->generic.height + diff;
1260 if (primaryWinInfo == firstWin)
1261 secondWin->generic.height--;
1263 firstWin->generic.height--;
1266 if (primaryWinInfo == firstWin)
1267 _makeInvisibleAndSetNewHeight (firstWin, newHeight);
1269 _makeInvisibleAndSetNewHeight (
1271 firstWin->generic.height);
1272 secondWin->generic.origin.y = firstWin->generic.height - 1;
1273 if (primaryWinInfo == secondWin)
1274 _makeInvisibleAndSetNewHeight (secondWin, newHeight);
1276 _makeInvisibleAndSetNewHeight (
1277 secondWin, secondWin->generic.height);
1278 cmdWin->generic.origin.y = locator->origin.y + 1;
1279 if ((cmdWin->generic.height + diff) < 1)
1280 _makeInvisibleAndSetNewHeight (cmdWin, 1);
1282 _makeInvisibleAndSetNewHeight (
1283 cmdWin, cmdWin->generic.height + diff);
1285 _makeVisibleWithNewHeight (cmdWin);
1286 _makeVisibleWithNewHeight (secondWin);
1287 _makeVisibleWithNewHeight (firstWin);
1288 if (firstWin->generic.contentSize <= 0)
1289 tuiEraseSourceContent (firstWin, EMPTY_SOURCE_PROMPT);
1290 if (secondWin->generic.contentSize <= 0)
1291 tuiEraseSourceContent (secondWin, EMPTY_SOURCE_PROMPT);
1297 } /* _tuiAdjustWinHeights */
1301 ** _makeInvisibleAndSetNewHeight().
1302 ** Function make the target window (and auxillary windows associated
1303 ** with the targer) invisible, and set the new height and location.
1306 _makeInvisibleAndSetNewHeight (TuiWinInfoPtr winInfo, int height)
1309 TuiGenWinInfoPtr genWinInfo;
1312 m_beInvisible (&winInfo->generic);
1313 winInfo->generic.height = height;
1315 winInfo->generic.viewportHeight = height - 1;
1317 winInfo->generic.viewportHeight = height;
1318 if (winInfo != cmdWin)
1319 winInfo->generic.viewportHeight--;
1321 /* Now deal with the auxillary windows associated with winInfo */
1322 switch (winInfo->generic.type)
1326 genWinInfo = winInfo->detail.sourceInfo.executionInfo;
1327 m_beInvisible (genWinInfo);
1328 genWinInfo->height = height;
1329 genWinInfo->origin.y = winInfo->generic.origin.y;
1331 genWinInfo->viewportHeight = height - 1;
1333 genWinInfo->viewportHeight = height;
1334 if (winInfo != cmdWin)
1335 genWinInfo->viewportHeight--;
1337 if (m_hasLocator (winInfo))
1339 genWinInfo = locatorWinInfoPtr ();
1340 m_beInvisible (genWinInfo);
1341 genWinInfo->origin.y = winInfo->generic.origin.y + height;
1345 /* delete all data item windows */
1346 for (i = 0; i < winInfo->generic.contentSize; i++)
1348 genWinInfo = (TuiGenWinInfoPtr) & ((TuiWinElementPtr)
1349 winInfo->generic.content[i])->whichElement.dataWindow;
1350 tuiDelwin (genWinInfo->handle);
1351 genWinInfo->handle = (WINDOW *) NULL;
1361 ** _makeVisibleWithNewHeight().
1362 ** Function to make the windows with new heights visible.
1363 ** This means re-creating the windows' content since the window
1364 ** had to be destroyed to be made invisible.
1367 _makeVisibleWithNewHeight (TuiWinInfoPtr winInfo)
1371 m_beVisible (&winInfo->generic);
1372 checkAndDisplayHighlightIfNeeded (winInfo);
1373 switch (winInfo->generic.type)
1377 freeWinContent (winInfo->detail.sourceInfo.executionInfo);
1378 m_beVisible (winInfo->detail.sourceInfo.executionInfo);
1379 if (winInfo->generic.content != (OpaquePtr) NULL)
1381 TuiLineOrAddress lineOrAddr;
1382 struct symtab_and_line cursal
1383 = get_current_source_symtab_and_line ();
1385 if (winInfo->generic.type == SRC_WIN)
1387 winInfo->detail.sourceInfo.startLineOrAddr.lineNo;
1390 winInfo->detail.sourceInfo.startLineOrAddr.addr;
1391 freeWinContent (&winInfo->generic);
1392 tuiUpdateSourceWindow (winInfo,
1393 cursal.symtab, lineOrAddr, TRUE);
1395 else if (deprecated_selected_frame != (struct frame_info *) NULL)
1397 TuiLineOrAddress line;
1398 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
1401 s = find_pc_symtab (get_frame_pc (deprecated_selected_frame));
1402 if (winInfo->generic.type == SRC_WIN)
1403 line.lineNo = cursal.line;
1406 find_line_pc (s, cursal.line, &line.addr);
1408 tuiUpdateSourceWindow (winInfo, s, line, TRUE);
1410 if (m_hasLocator (winInfo))
1412 m_beVisible (locatorWinInfoPtr ());
1413 tui_show_locator_content ();
1417 tuiDisplayAllData ();
1420 winInfo->detail.commandInfo.curLine = 0;
1421 winInfo->detail.commandInfo.curch = 0;
1422 wmove (winInfo->generic.handle,
1423 winInfo->detail.commandInfo.curLine,
1424 winInfo->detail.commandInfo.curch);
1431 } /* _makeVisibleWithNewHeight */
1435 _newHeightOk (TuiWinInfoPtr primaryWinInfo, int newHeight)
1437 int ok = (newHeight < termHeight ());
1442 TuiLayoutType curLayout = currentLayout ();
1444 diff = (newHeight - primaryWinInfo->generic.height) * (-1);
1445 if (curLayout == SRC_COMMAND || curLayout == DISASSEM_COMMAND)
1447 ok = ((primaryWinInfo->generic.type == CMD_WIN &&
1448 newHeight <= (termHeight () - 4) &&
1449 newHeight >= MIN_CMD_WIN_HEIGHT) ||
1450 (primaryWinInfo->generic.type != CMD_WIN &&
1451 newHeight <= (termHeight () - 2) &&
1452 newHeight >= MIN_WIN_HEIGHT));
1454 { /* check the total height */
1455 TuiWinInfoPtr winInfo;
1457 if (primaryWinInfo == cmdWin)
1458 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[0];
1462 (winInfo->generic.height + diff)) <= termHeight ());
1467 int curTotalHeight, totalHeight, minHeight = 0;
1468 TuiWinInfoPtr firstWin, secondWin;
1470 if (curLayout == SRC_DISASSEM_COMMAND)
1473 secondWin = disassemWin;
1478 secondWin = (TuiWinInfoPtr) (sourceWindows ())->list[0];
1481 ** We could simply add all the heights to obtain the same result
1482 ** but below is more explicit since we subtract 1 for the
1483 ** line that the first and second windows share, and add one
1486 totalHeight = curTotalHeight =
1487 (firstWin->generic.height + secondWin->generic.height - 1)
1488 + cmdWin->generic.height + 1 /*locator */ ;
1489 if (primaryWinInfo == cmdWin)
1491 /* locator included since first & second win share a line */
1492 ok = ((firstWin->generic.height +
1493 secondWin->generic.height + diff) >=
1494 (MIN_WIN_HEIGHT * 2) &&
1495 newHeight >= MIN_CMD_WIN_HEIGHT);
1498 totalHeight = newHeight + (firstWin->generic.height +
1499 secondWin->generic.height + diff);
1500 minHeight = MIN_CMD_WIN_HEIGHT;
1505 minHeight = MIN_WIN_HEIGHT;
1507 ** First see if we can increase/decrease the command
1508 ** window. And make sure that the command window is
1511 ok = ((cmdWin->generic.height + diff) > 0);
1514 ** Looks like we have to increase/decrease one of
1515 ** the other windows
1517 if (primaryWinInfo == firstWin)
1518 ok = (secondWin->generic.height + diff) >= minHeight;
1520 ok = (firstWin->generic.height + diff) >= minHeight;
1524 if (primaryWinInfo == firstWin)
1525 totalHeight = newHeight +
1526 secondWin->generic.height +
1527 cmdWin->generic.height + diff;
1529 totalHeight = newHeight +
1530 firstWin->generic.height +
1531 cmdWin->generic.height + diff;
1535 ** Now make sure that the proposed total height doesn't exceed
1536 ** the old total height.
1539 ok = (newHeight >= minHeight && totalHeight <= curTotalHeight);
1544 } /* _newHeightOk */
1548 ** _parseScrollingArgs().
1551 _parseScrollingArgs (char *arg, TuiWinInfoPtr * winToScroll, int *numToScroll)
1555 *winToScroll = tuiWinWithFocus ();
1558 ** First set up the default window to scroll, in case there is no
1561 if (arg != (char *) NULL)
1565 /* process the number of lines to scroll */
1566 buf = bufPtr = xstrdup (arg);
1567 if (isdigit (*bufPtr))
1572 bufPtr = strchr (bufPtr, ' ');
1573 if (bufPtr != (char *) NULL)
1577 *numToScroll = atoi (numStr);
1580 else if (numToScroll)
1581 *numToScroll = atoi (numStr);
1584 /* process the window name if one is specified */
1585 if (bufPtr != (char *) NULL)
1591 while (*(++bufPtr) == ' ')
1594 if (*bufPtr != (char) 0)
1599 /* Validate the window name */
1600 for (i = 0; i < strlen (wname); i++)
1601 wname[i] = toupper (wname[i]);
1602 *winToScroll = partialWinByName (wname);
1604 if (*winToScroll == (TuiWinInfoPtr) NULL ||
1605 !(*winToScroll)->generic.isVisible)
1606 warning ("Invalid window specified. \n\
1607 The window name specified must be valid and visible.\n");
1608 else if (*winToScroll == cmdWin)
1609 *winToScroll = (TuiWinInfoPtr) (sourceWindows ())->list[0];
1615 } /* _parseScrollingArgs */