1 /* TUI data manipulation routines.
3 Copyright (C) 1998-2023 Free Software Foundation, Inc.
5 Contributed by Hewlett-Packard Company.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "tui/tui-data.h"
26 #include "tui/tui-win.h"
27 #include "tui/tui-wingeneral.h"
28 #include "tui/tui-winsource.h"
29 #include "tui/tui-stack.h"
30 #include "gdb_curses.h"
33 struct tui_win_info
*tui_win_list
[MAX_MAJOR_WINDOWS
];
35 static int term_height
, term_width
;
36 static struct tui_win_info
*win_with_focus
= NULL
;
38 static bool win_resized
= false;
40 /* Answer a whether the terminal window has been resized or not. */
48 /* Set a whether the terminal window has been resized or not. */
50 tui_set_win_resized_to (bool resized
)
52 win_resized
= resized
;
56 /* Answer the window with the logical focus. */
58 tui_win_with_focus (void)
60 return win_with_focus
;
64 /* Set the logical focus to win_info. */
66 tui_set_win_focus_to (struct tui_win_info
*win_info
)
70 tui_unhighlight_win (win_with_focus
);
71 win_with_focus
= win_info
;
72 tui_highlight_win (win_info
);
73 tui_show_locator_content ();
78 /* Accessor for the term_height. */
80 tui_term_height (void)
86 /* Mutator for the term height. */
88 tui_set_term_height_to (int h
)
94 /* Accessor for the term_width. */
102 /* Mutator for the term_width. */
104 tui_set_term_width_to (int w
)
110 /* Answer the next window in the list, cycling back to the top if
112 struct tui_win_info
*
113 tui_next_win (struct tui_win_info
*cur_win
)
115 auto iter
= std::find (tui_windows
.begin (), tui_windows
.end (), cur_win
);
116 gdb_assert (iter
!= tui_windows
.end ());
118 gdb_assert (cur_win
->can_focus ());
119 /* This won't loop forever since we can't have just an un-focusable
124 if (iter
== tui_windows
.end ())
125 iter
= tui_windows
.begin ();
126 if ((*iter
)->can_focus ())
134 /* Answer the prev window in the list, cycling back to the bottom if
136 struct tui_win_info
*
137 tui_prev_win (struct tui_win_info
*cur_win
)
139 auto iter
= std::find (tui_windows
.rbegin (), tui_windows
.rend (), cur_win
);
140 gdb_assert (iter
!= tui_windows
.rend ());
142 gdb_assert (cur_win
->can_focus ());
143 /* This won't loop forever since we can't have just an un-focusable
148 if (iter
== tui_windows
.rend ())
149 iter
= tui_windows
.rbegin ();
150 if ((*iter
)->can_focus ())
157 /* See tui-data.h. */
160 tui_win_info::set_title (std::string
&&new_title
)
162 if (m_title
!= new_title
)
165 check_and_display_highlight_if_needed ();
169 /* See tui-data.h. */
172 tui_win_info::display_string (int y
, int x
, const char *str
) const
174 int n
= width
- box_width () - x
;
178 mvwaddnstr (handle
.get (), y
, x
, str
, n
);
181 /* See tui-data.h. */
184 tui_win_info::display_string (const char *str
) const
187 getyx (handle
.get (), y
, x
);
189 /* Avoid Wunused-but-set-variable. */
192 int n
= width
- box_width () - x
;
196 waddnstr (handle
.get (), str
, n
);
200 tui_win_info::rerender ()
202 check_and_display_highlight_if_needed ();