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