Automatic date update in version.in
[binutils-gdb.git] / gdb / tui / tui-data.c
blobf5a98233ea0af71a139a3acec2d4d8c317c4641e
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/>. */
22 #include "defs.h"
23 #include "symtab.h"
24 #include "tui/tui.h"
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"
31 #include <algorithm>
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. */
41 bool
42 tui_win_resized ()
44 return win_resized;
48 /* Set a whether the terminal window has been resized or not. */
49 void
50 tui_set_win_resized_to (bool resized)
52 win_resized = resized;
56 /* Answer the window with the logical focus. */
57 struct tui_win_info *
58 tui_win_with_focus (void)
60 return win_with_focus;
64 /* Set the logical focus to win_info. */
65 void
66 tui_set_win_focus_to (struct tui_win_info *win_info)
68 if (win_info != NULL)
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. */
79 int
80 tui_term_height (void)
82 return term_height;
86 /* Mutator for the term height. */
87 void
88 tui_set_term_height_to (int h)
90 term_height = h;
94 /* Accessor for the term_width. */
95 int
96 tui_term_width (void)
98 return term_width;
102 /* Mutator for the term_width. */
103 void
104 tui_set_term_width_to (int w)
106 term_width = w;
110 /* Answer the next window in the list, cycling back to the top if
111 necessary. */
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
120 window. */
121 while (true)
123 ++iter;
124 if (iter == tui_windows.end ())
125 iter = tui_windows.begin ();
126 if ((*iter)->can_focus ())
127 break;
130 return *iter;
134 /* Answer the prev window in the list, cycling back to the bottom if
135 necessary. */
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
144 window. */
145 while (true)
147 ++iter;
148 if (iter == tui_windows.rend ())
149 iter = tui_windows.rbegin ();
150 if ((*iter)->can_focus ())
151 break;
154 return *iter;
157 /* See tui-data.h. */
159 void
160 tui_win_info::set_title (std::string &&new_title)
162 if (m_title != new_title)
164 m_title = new_title;
165 check_and_display_highlight_if_needed ();
169 /* See tui-data.h. */
171 void
172 tui_win_info::display_string (int y, int x, const char *str) const
174 int n = width - box_width () - x;
175 if (n <= 0)
176 return;
178 mvwaddnstr (handle.get (), y, x, str, n);
181 /* See tui-data.h. */
183 void
184 tui_win_info::display_string (const char *str) const
186 int y, x;
187 getyx (handle.get (), y, x);
189 /* Avoid Wunused-but-set-variable. */
190 (void) y;
192 int n = width - box_width () - x;
193 if (n <= 0)
194 return;
196 waddnstr (handle.get (), str, n);
199 void
200 tui_win_info::rerender ()
202 check_and_display_highlight_if_needed ();