]>
Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI data manipulation routines. |
f33c6cbf | 2 | |
1d506c26 | 3 | Copyright (C) 1998-2024 Free Software Foundation, Inc. |
f33c6cbf | 4 | |
f377b406 SC |
5 | Contributed by Hewlett-Packard Company. |
6 | ||
7 | This file is part of GDB. | |
8 | ||
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 | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
f377b406 SC |
12 | (at your option) any later version. |
13 | ||
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. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c | 21 | |
96ec9981 DJ |
22 | #include "defs.h" |
23 | #include "symtab.h" | |
d7b2e967 AC |
24 | #include "tui/tui.h" |
25 | #include "tui/tui-data.h" | |
935c78c0 | 26 | #include "tui/tui-win.h" |
d7b2e967 | 27 | #include "tui/tui-wingeneral.h" |
5104fe36 | 28 | #include "tui/tui-winsource.h" |
cf2ef009 | 29 | #include "tui/tui-status.h" |
6a83354a | 30 | #include "gdb_curses.h" |
eb9c8874 | 31 | #include <algorithm> |
4e8f7a8b | 32 | |
7fa29be9 | 33 | struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS]; |
c906108c | 34 | |
6ba8e26f | 35 | static int term_height, term_width; |
e65b5245 | 36 | static struct tui_win_info *win_with_focus = NULL; |
08ef48c5 | 37 | |
9abd8a65 | 38 | static bool win_resized = false; |
c906108c | 39 | |
1cc6d956 | 40 | /* Answer a whether the terminal window has been resized or not. */ |
9abd8a65 TT |
41 | bool |
42 | tui_win_resized () | |
c906108c | 43 | { |
6ba8e26f | 44 | return win_resized; |
dd1abb8c | 45 | } |
c906108c SS |
46 | |
47 | ||
1cc6d956 | 48 | /* Set a whether the terminal window has been resized or not. */ |
c906108c | 49 | void |
9abd8a65 | 50 | tui_set_win_resized_to (bool resized) |
c906108c | 51 | { |
6ba8e26f | 52 | win_resized = resized; |
dd1abb8c | 53 | } |
c906108c SS |
54 | |
55 | ||
1cc6d956 | 56 | /* Answer the window with the logical focus. */ |
2a8854a7 | 57 | struct tui_win_info * |
dd1abb8c | 58 | tui_win_with_focus (void) |
c906108c | 59 | { |
6ba8e26f | 60 | return win_with_focus; |
dd1abb8c | 61 | } |
c906108c SS |
62 | |
63 | ||
935c78c0 | 64 | /* Set the logical focus to win_info. */ |
c906108c | 65 | void |
935c78c0 | 66 | tui_set_win_focus_to (struct tui_win_info *win_info) |
c906108c | 67 | { |
935c78c0 TT |
68 | if (win_info != NULL) |
69 | { | |
70 | tui_unhighlight_win (win_with_focus); | |
71 | win_with_focus = win_info; | |
72 | tui_highlight_win (win_info); | |
e0dd0e4d | 73 | tui_show_status_content (); |
935c78c0 | 74 | } |
dd1abb8c | 75 | } |
c906108c SS |
76 | |
77 | ||
6ba8e26f | 78 | /* Accessor for the term_height. */ |
c906108c | 79 | int |
dd1abb8c | 80 | tui_term_height (void) |
c906108c | 81 | { |
6ba8e26f | 82 | return term_height; |
dd1abb8c | 83 | } |
c906108c SS |
84 | |
85 | ||
1cc6d956 | 86 | /* Mutator for the term height. */ |
c906108c | 87 | void |
dd1abb8c | 88 | tui_set_term_height_to (int h) |
c906108c | 89 | { |
6ba8e26f | 90 | term_height = h; |
dd1abb8c | 91 | } |
c906108c SS |
92 | |
93 | ||
1cc6d956 | 94 | /* Accessor for the term_width. */ |
c906108c | 95 | int |
dd1abb8c | 96 | tui_term_width (void) |
c906108c | 97 | { |
6ba8e26f | 98 | return term_width; |
dd1abb8c | 99 | } |
c906108c SS |
100 | |
101 | ||
6ba8e26f | 102 | /* Mutator for the term_width. */ |
c906108c | 103 | void |
dd1abb8c | 104 | tui_set_term_width_to (int w) |
c906108c | 105 | { |
6ba8e26f | 106 | term_width = w; |
dd1abb8c | 107 | } |
c906108c SS |
108 | |
109 | ||
dd1abb8c AC |
110 | /* Answer the next window in the list, cycling back to the top if |
111 | necessary. */ | |
2a8854a7 | 112 | struct tui_win_info * |
5b6fe301 | 113 | tui_next_win (struct tui_win_info *cur_win) |
c906108c | 114 | { |
eb9c8874 TT |
115 | auto iter = std::find (tui_windows.begin (), tui_windows.end (), cur_win); |
116 | gdb_assert (iter != tui_windows.end ()); | |
c906108c | 117 | |
b551a89f TT |
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) | |
122 | { | |
123 | ++iter; | |
124 | if (iter == tui_windows.end ()) | |
125 | iter = tui_windows.begin (); | |
126 | if ((*iter)->can_focus ()) | |
127 | break; | |
128 | } | |
129 | ||
eb9c8874 | 130 | return *iter; |
6ba8e26f | 131 | } |
c906108c SS |
132 | |
133 | ||
dd1abb8c AC |
134 | /* Answer the prev window in the list, cycling back to the bottom if |
135 | necessary. */ | |
2a8854a7 | 136 | struct tui_win_info * |
5b6fe301 | 137 | tui_prev_win (struct tui_win_info *cur_win) |
c906108c | 138 | { |
b551a89f TT |
139 | auto iter = std::find (tui_windows.rbegin (), tui_windows.rend (), cur_win); |
140 | gdb_assert (iter != tui_windows.rend ()); | |
141 | ||
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) | |
146 | { | |
147 | ++iter; | |
148 | if (iter == tui_windows.rend ()) | |
149 | iter = tui_windows.rbegin (); | |
150 | if ((*iter)->can_focus ()) | |
151 | break; | |
152 | } | |
c906108c | 153 | |
eb9c8874 | 154 | return *iter; |
cb50eddd | 155 | } |
c906108c | 156 | |
9fe01a37 TT |
157 | /* See tui-data.h. */ |
158 | ||
159 | void | |
6c1e84f5 | 160 | tui_win_info::set_title (std::string &&new_title) |
9fe01a37 | 161 | { |
6c1e84f5 | 162 | if (m_title != new_title) |
9fe01a37 | 163 | { |
6c1e84f5 | 164 | m_title = new_title; |
9fe01a37 TT |
165 | check_and_display_highlight_if_needed (); |
166 | } | |
167 | } | |
c906108c | 168 | |
d1a912db TV |
169 | /* See tui-data.h. */ |
170 | ||
171 | void | |
172 | tui_win_info::display_string (int y, int x, const char *str) const | |
173 | { | |
174 | int n = width - box_width () - x; | |
175 | if (n <= 0) | |
176 | return; | |
177 | ||
178 | mvwaddnstr (handle.get (), y, x, str, n); | |
179 | } | |
180 | ||
181 | /* See tui-data.h. */ | |
182 | ||
183 | void | |
184 | tui_win_info::display_string (const char *str) const | |
185 | { | |
186 | int y, x; | |
187 | getyx (handle.get (), y, x); | |
188 | ||
189 | /* Avoid Wunused-but-set-variable. */ | |
190 | (void) y; | |
191 | ||
192 | int n = width - box_width () - x; | |
193 | if (n <= 0) | |
194 | return; | |
195 | ||
196 | waddnstr (handle.get (), str, n); | |
197 | } | |
198 | ||
3df505f6 TT |
199 | void |
200 | tui_win_info::rerender () | |
201 | { | |
202 | check_and_display_highlight_if_needed (); | |
203 | } |