]>
Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI data manipulation routines. |
55fb0713 | 2 | |
1d506c26 | 3 | Copyright (C) 1998-2024 Free Software Foundation, Inc. |
55fb0713 | 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/>. */ |
f377b406 | 21 | |
1a5c2598 TT |
22 | #ifndef TUI_TUI_DATA_H |
23 | #define TUI_TUI_DATA_H | |
c906108c | 24 | |
fdb01f0c | 25 | #include "tui/tui.h" |
ef0f16cc | 26 | #include "gdb_curses.h" |
b73dd877 | 27 | #include "observable.h" |
85a427b2 | 28 | #include "gdbsupport/gdb-checked-static-cast.h" |
6a83354a | 29 | |
7523da63 TT |
30 | /* A deleter that calls delwin. */ |
31 | struct curses_deleter | |
32 | { | |
33 | void operator() (WINDOW *win) const | |
34 | { | |
35 | delwin (win); | |
36 | } | |
37 | }; | |
38 | ||
32c1e210 TT |
39 | #define MIN_WIN_HEIGHT 3 |
40 | ||
1cc6d956 | 41 | /* Generic window information. */ |
32c1e210 | 42 | struct tui_win_info |
2a8854a7 | 43 | { |
fb54fa76 TT |
44 | protected: |
45 | ||
32c1e210 TT |
46 | tui_win_info () = default; |
47 | DISABLE_COPY_AND_ASSIGN (tui_win_info); | |
ab313b35 | 48 | |
3df505f6 TT |
49 | /* This is called after the window is resized, and should update the |
50 | window's contents. */ | |
32c1e210 | 51 | virtual void rerender (); |
3df505f6 | 52 | |
ab0e1f1a TT |
53 | virtual void make_window (); |
54 | ||
fb54fa76 | 55 | public: |
32c1e210 TT |
56 | tui_win_info (tui_win_info &&) = default; |
57 | virtual ~tui_win_info () = default; | |
ab313b35 | 58 | |
5b81daba TT |
59 | /* Call to refresh this window. */ |
60 | virtual void refresh_window (); | |
61 | ||
48a3bd16 TT |
62 | /* Make this window visible or invisible. */ |
63 | virtual void make_visible (bool visible); | |
64 | ||
152f3f4b | 65 | /* Return the name of this type of window. */ |
1cdf9e33 | 66 | virtual const char *name () const = 0; |
152f3f4b | 67 | |
c8ec2f43 | 68 | /* Compute the maximum height of this window. */ |
32c1e210 | 69 | virtual int max_height () const; |
c8ec2f43 | 70 | |
dc7ff8a6 | 71 | /* Compute the minimum height of this window. */ |
32c1e210 TT |
72 | virtual int min_height () const |
73 | { | |
74 | return MIN_WIN_HEIGHT; | |
75 | } | |
dc7ff8a6 | 76 | |
7c043ba6 TT |
77 | /* Compute the maximum width of this window. */ |
78 | int max_width () const; | |
79 | ||
80 | /* Compute the minimum width of this window. */ | |
81 | int min_width () const | |
82 | { | |
83 | return 3; | |
84 | } | |
85 | ||
1431937b TT |
86 | /* Return true if this window can be boxed. */ |
87 | virtual bool can_box () const | |
88 | { | |
32c1e210 | 89 | return true; |
1431937b TT |
90 | } |
91 | ||
ff3c86a8 TV |
92 | /* Return the width of the box. */ |
93 | int box_width () const | |
94 | { | |
95 | return can_box () ? 1 : 0; | |
96 | } | |
97 | ||
98 | /* Return the size of the box. */ | |
99 | int box_size () const | |
100 | { | |
101 | return 2 * box_width (); | |
102 | } | |
103 | ||
ee556432 | 104 | /* Resize this window. The parameters are used to set the window's |
1e0c09ba | 105 | size and position. */ |
ee556432 TT |
106 | virtual void resize (int height, int width, |
107 | int origin_x, int origin_y); | |
d6ba6a11 | 108 | |
2d83e710 TT |
109 | /* Return true if this window is visible. */ |
110 | bool is_visible () const | |
111 | { | |
29db1eb3 | 112 | return handle != nullptr && tui_active; |
2d83e710 TT |
113 | } |
114 | ||
b551a89f TT |
115 | /* Return true if this window can accept the focus. */ |
116 | virtual bool can_focus () const | |
117 | { | |
118 | return true; | |
119 | } | |
120 | ||
45bbae5c | 121 | /* Disable output until the next call to doupdate. */ |
7134f2eb | 122 | void no_refresh () |
45bbae5c TT |
123 | { |
124 | if (handle != nullptr) | |
125 | wnoutrefresh (handle.get ()); | |
126 | } | |
127 | ||
d83f1fe6 TT |
128 | /* Called after the tab width has been changed. */ |
129 | virtual void update_tab_width () | |
130 | { | |
131 | } | |
132 | ||
30baf67b | 133 | /* Set whether this window is highlighted. */ |
214a5cbe TT |
134 | void set_highlight (bool highlight) |
135 | { | |
136 | is_highlighted = highlight; | |
137 | } | |
138 | ||
13446e05 TT |
139 | /* Methods to scroll the contents of this window. Note that they |
140 | are named with "_scroll" coming at the end because the more | |
141 | obvious "scroll_forward" is defined as a macro in term.h. */ | |
142 | void forward_scroll (int num_to_scroll); | |
143 | void backward_scroll (int num_to_scroll); | |
144 | void left_scroll (int num_to_scroll); | |
145 | void right_scroll (int num_to_scroll); | |
146 | ||
06210ce4 TT |
147 | /* Return true if this window can be scrolled, false otherwise. */ |
148 | virtual bool can_scroll () const | |
149 | { | |
150 | return true; | |
151 | } | |
152 | ||
1bace02a HD |
153 | /* Called for each mouse click inside this window. Coordinates MOUSE_X |
154 | and MOUSE_Y are 0-based relative to the window, and MOUSE_BUTTON can | |
155 | be 1 (left), 2 (middle), or 3 (right). */ | |
156 | virtual void click (int mouse_x, int mouse_y, int mouse_button) | |
157 | { | |
158 | } | |
159 | ||
b4ef5aeb TT |
160 | void check_and_display_highlight_if_needed (); |
161 | ||
9fe01a37 TT |
162 | /* A helper function to change the title and then redraw the |
163 | surrounding box, if needed. */ | |
6c1e84f5 AB |
164 | void set_title (std::string &&new_title); |
165 | ||
166 | /* Return a reference to the current window title. */ | |
167 | const std::string &title () const | |
168 | { return m_title; } | |
9fe01a37 | 169 | |
d1a912db TV |
170 | /* Display string STR in the window at position (Y,X), abbreviated if |
171 | necessary. */ | |
172 | void display_string (int y, int x, const char *str) const; | |
173 | ||
174 | /* Display string STR in the window at the current cursor position, | |
175 | abbreviated if necessary. */ | |
176 | void display_string (const char *str) const; | |
177 | ||
32c1e210 TT |
178 | /* Window handle. */ |
179 | std::unique_ptr<WINDOW, curses_deleter> handle; | |
180 | /* Window width. */ | |
181 | int width = 0; | |
182 | /* Window height. */ | |
183 | int height = 0; | |
184 | /* Origin of window. */ | |
185 | int x = 0; | |
186 | int y = 0; | |
187 | ||
33b906ab | 188 | /* Is this window highlighted? */ |
214a5cbe | 189 | bool is_highlighted = false; |
32c1e210 TT |
190 | |
191 | protected: | |
192 | ||
193 | /* Scroll the contents vertically. This is only called via | |
194 | forward_scroll and backward_scroll. */ | |
195 | virtual void do_scroll_vertical (int num_to_scroll) = 0; | |
196 | ||
197 | /* Scroll the contents horizontally. This is only called via | |
198 | left_scroll and right_scroll. */ | |
199 | virtual void do_scroll_horizontal (int num_to_scroll) = 0; | |
6c1e84f5 AB |
200 | |
201 | private: | |
202 | /* Window title to display. */ | |
203 | std::string m_title; | |
33b906ab TT |
204 | }; |
205 | ||
85a427b2 TV |
206 | /* A TUI window that doesn't scroll. */ |
207 | ||
208 | struct tui_noscroll_window : public virtual tui_win_info | |
209 | { | |
210 | public: | |
211 | virtual bool can_scroll () const final override | |
212 | { | |
213 | return false; | |
214 | } | |
215 | ||
216 | protected: | |
217 | virtual void do_scroll_vertical (int num_to_scroll) final override | |
218 | { | |
219 | } | |
220 | ||
221 | /* Scroll the contents horizontally. This is only called via | |
222 | left_scroll and right_scroll. */ | |
223 | virtual void do_scroll_horizontal (int num_to_scroll) final override | |
224 | { | |
225 | } | |
226 | }; | |
227 | ||
228 | /* A TUI window that cannot have focus. */ | |
229 | ||
230 | struct tui_nofocus_window : public virtual tui_win_info | |
231 | { | |
232 | public: | |
233 | virtual bool can_focus () const final override | |
234 | { | |
235 | return false; | |
236 | } | |
237 | }; | |
238 | ||
239 | /* A TUI window that occupies a single line. */ | |
240 | ||
241 | struct tui_oneline_window : public virtual tui_win_info | |
242 | { | |
243 | int max_height () const final override | |
244 | { | |
245 | return 1; | |
246 | } | |
247 | ||
248 | int min_height () const final override | |
249 | { | |
250 | return 1; | |
251 | } | |
252 | }; | |
253 | ||
254 | /* A TUI window that has no border. */ | |
255 | ||
256 | struct tui_nobox_window : public virtual tui_win_info | |
257 | { | |
258 | bool can_box () const final override | |
259 | { | |
260 | return false; | |
261 | } | |
262 | }; | |
263 | ||
264 | /* A TUI window that is not refreshed. */ | |
265 | ||
266 | struct tui_norefresh_window : public virtual tui_win_info | |
267 | { | |
268 | virtual void refresh_window () final override | |
269 | { | |
270 | } | |
271 | }; | |
272 | ||
273 | /* A TUI window that is always visible. */ | |
274 | ||
275 | struct tui_always_visible_window : public virtual tui_win_info | |
276 | { | |
277 | virtual void make_visible (bool visible) final override | |
278 | { | |
279 | } | |
280 | }; | |
281 | ||
32c1e210 TT |
282 | /* Constant definitions. */ |
283 | #define SRC_NAME "src" | |
284 | #define CMD_NAME "cmd" | |
285 | #define DATA_NAME "regs" | |
286 | #define DISASSEM_NAME "asm" | |
287 | #define STATUS_NAME "status" | |
c906108c | 288 | |
1cc6d956 | 289 | /* Global Data. */ |
7fa29be9 | 290 | extern struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS]; |
c906108c | 291 | |
85a427b2 TV |
292 | #define TUI_SRC_WIN \ |
293 | (gdb::checked_static_cast<tui_source_window *> (tui_win_list[SRC_WIN])) | |
294 | #define TUI_DISASM_WIN \ | |
295 | (gdb::checked_static_cast<tui_disasm_window *> (tui_win_list[DISASSEM_WIN])) | |
296 | #define TUI_DATA_WIN \ | |
297 | (gdb::checked_static_cast<tui_data_window *> (tui_win_list[DATA_WIN])) | |
298 | #define TUI_CMD_WIN \ | |
299 | (gdb::checked_static_cast<tui_cmd_window *> (tui_win_list[CMD_WIN])) | |
300 | #define TUI_STATUS_WIN \ | |
e0dd0e4d | 301 | (gdb::checked_static_cast<tui_status_window *> (tui_win_list[STATUS_WIN])) |
c906108c | 302 | |
7eed1a8e TT |
303 | /* All the windows that are currently instantiated, in layout |
304 | order. */ | |
305 | extern std::vector<tui_win_info *> tui_windows; | |
1ce3e844 | 306 | |
7eed1a8e TT |
307 | /* Return a range adapter for iterating over TUI windows. */ |
308 | static inline std::vector<tui_win_info *> & | |
309 | all_tui_windows () | |
1ce3e844 | 310 | { |
7eed1a8e TT |
311 | return tui_windows; |
312 | } | |
1ce3e844 | 313 | |
1cc6d956 | 314 | /* Data Manipulation Functions. */ |
dd1abb8c AC |
315 | extern int tui_term_height (void); |
316 | extern void tui_set_term_height_to (int); | |
317 | extern int tui_term_width (void); | |
318 | extern void tui_set_term_width_to (int); | |
dd1abb8c | 319 | extern struct tui_win_info *tui_win_with_focus (void); |
9abd8a65 TT |
320 | extern bool tui_win_resized (); |
321 | extern void tui_set_win_resized_to (bool); | |
dd1abb8c AC |
322 | |
323 | extern struct tui_win_info *tui_next_win (struct tui_win_info *); | |
324 | extern struct tui_win_info *tui_prev_win (struct tui_win_info *); | |
325 | ||
7806cea7 TT |
326 | extern unsigned int tui_tab_width; |
327 | ||
1a5c2598 | 328 | #endif /* TUI_TUI_DATA_H */ |