tui-data.h revision 1.10 1 1.1 christos /* TUI data manipulation routines.
2 1.1 christos
3 1.10 christos Copyright (C) 1998-2023 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.1 christos #include "gdb_curses.h" /* For WINDOW. */
27 1.9 christos #include "observable.h"
28 1.1 christos
29 1.9 christos /* A deleter that calls delwin. */
30 1.9 christos struct curses_deleter
31 1.1 christos {
32 1.9 christos void operator() (WINDOW *win) const
33 1.9 christos {
34 1.9 christos delwin (win);
35 1.9 christos }
36 1.1 christos };
37 1.1 christos
38 1.9 christos #define MIN_WIN_HEIGHT 3
39 1.5 christos
40 1.1 christos /* Generic window information. */
41 1.9 christos struct tui_win_info
42 1.1 christos {
43 1.9 christos protected:
44 1.1 christos
45 1.9 christos tui_win_info () = default;
46 1.9 christos DISABLE_COPY_AND_ASSIGN (tui_win_info);
47 1.1 christos
48 1.9 christos /* This is called after the window is resized, and should update the
49 1.9 christos window's contents. */
50 1.9 christos virtual void rerender ();
51 1.1 christos
52 1.9 christos virtual void make_window ();
53 1.1 christos
54 1.9 christos public:
55 1.9 christos tui_win_info (tui_win_info &&) = default;
56 1.9 christos virtual ~tui_win_info () = default;
57 1.1 christos
58 1.9 christos /* Call to refresh this window. */
59 1.9 christos virtual void refresh_window ();
60 1.1 christos
61 1.9 christos /* Make this window visible or invisible. */
62 1.9 christos virtual void make_visible (bool visible);
63 1.1 christos
64 1.9 christos /* Return the name of this type of window. */
65 1.9 christos virtual const char *name () const = 0;
66 1.1 christos
67 1.9 christos /* Compute the maximum height of this window. */
68 1.9 christos virtual int max_height () const;
69 1.1 christos
70 1.9 christos /* Compute the minimum height of this window. */
71 1.9 christos virtual int min_height () const
72 1.9 christos {
73 1.9 christos return MIN_WIN_HEIGHT;
74 1.9 christos }
75 1.1 christos
76 1.9 christos /* Compute the maximum width of this window. */
77 1.9 christos int max_width () const;
78 1.1 christos
79 1.9 christos /* Compute the minimum width of this window. */
80 1.9 christos int min_width () const
81 1.9 christos {
82 1.9 christos return 3;
83 1.9 christos }
84 1.1 christos
85 1.9 christos /* Return true if this window can be boxed. */
86 1.9 christos virtual bool can_box () const
87 1.9 christos {
88 1.9 christos return true;
89 1.9 christos }
90 1.1 christos
91 1.9 christos /* Resize this window. The parameters are used to set the window's
92 1.9 christos size and position. */
93 1.9 christos virtual void resize (int height, int width,
94 1.9 christos int origin_x, int origin_y);
95 1.1 christos
96 1.9 christos /* Return true if this window is visible. */
97 1.9 christos bool is_visible () const
98 1.9 christos {
99 1.10 christos return handle != nullptr && tui_active;
100 1.10 christos }
101 1.10 christos
102 1.10 christos /* Return true if this window can accept the focus. */
103 1.10 christos virtual bool can_focus () const
104 1.10 christos {
105 1.10 christos return true;
106 1.9 christos }
107 1.1 christos
108 1.9 christos /* Disable output until the next call to doupdate. */
109 1.9 christos void no_refresh ()
110 1.9 christos {
111 1.9 christos if (handle != nullptr)
112 1.9 christos wnoutrefresh (handle.get ());
113 1.9 christos }
114 1.1 christos
115 1.9 christos /* Called after the tab width has been changed. */
116 1.9 christos virtual void update_tab_width ()
117 1.9 christos {
118 1.9 christos }
119 1.1 christos
120 1.9 christos /* Set whether this window is highlighted. */
121 1.9 christos void set_highlight (bool highlight)
122 1.9 christos {
123 1.9 christos is_highlighted = highlight;
124 1.9 christos }
125 1.1 christos
126 1.9 christos /* Methods to scroll the contents of this window. Note that they
127 1.9 christos are named with "_scroll" coming at the end because the more
128 1.9 christos obvious "scroll_forward" is defined as a macro in term.h. */
129 1.9 christos void forward_scroll (int num_to_scroll);
130 1.9 christos void backward_scroll (int num_to_scroll);
131 1.9 christos void left_scroll (int num_to_scroll);
132 1.9 christos void right_scroll (int num_to_scroll);
133 1.1 christos
134 1.9 christos /* Return true if this window can be scrolled, false otherwise. */
135 1.9 christos virtual bool can_scroll () const
136 1.9 christos {
137 1.9 christos return true;
138 1.9 christos }
139 1.1 christos
140 1.10 christos /* Called for each mouse click inside this window. Coordinates MOUSE_X
141 1.10 christos and MOUSE_Y are 0-based relative to the window, and MOUSE_BUTTON can
142 1.10 christos be 1 (left), 2 (middle), or 3 (right). */
143 1.10 christos virtual void click (int mouse_x, int mouse_y, int mouse_button)
144 1.10 christos {
145 1.10 christos }
146 1.10 christos
147 1.9 christos void check_and_display_highlight_if_needed ();
148 1.1 christos
149 1.9 christos /* Window handle. */
150 1.9 christos std::unique_ptr<WINDOW, curses_deleter> handle;
151 1.9 christos /* Window width. */
152 1.9 christos int width = 0;
153 1.9 christos /* Window height. */
154 1.9 christos int height = 0;
155 1.9 christos /* Origin of window. */
156 1.9 christos int x = 0;
157 1.9 christos int y = 0;
158 1.9 christos
159 1.9 christos /* Window title to display. */
160 1.9 christos std::string title;
161 1.9 christos
162 1.9 christos /* Is this window highlighted? */
163 1.9 christos bool is_highlighted = false;
164 1.9 christos
165 1.9 christos protected:
166 1.9 christos
167 1.9 christos /* Scroll the contents vertically. This is only called via
168 1.9 christos forward_scroll and backward_scroll. */
169 1.9 christos virtual void do_scroll_vertical (int num_to_scroll) = 0;
170 1.9 christos
171 1.9 christos /* Scroll the contents horizontally. This is only called via
172 1.9 christos left_scroll and right_scroll. */
173 1.9 christos virtual void do_scroll_horizontal (int num_to_scroll) = 0;
174 1.1 christos };
175 1.1 christos
176 1.9 christos /* Constant definitions. */
177 1.9 christos #define SRC_NAME "src"
178 1.9 christos #define CMD_NAME "cmd"
179 1.9 christos #define DATA_NAME "regs"
180 1.9 christos #define DISASSEM_NAME "asm"
181 1.9 christos #define STATUS_NAME "status"
182 1.1 christos
183 1.1 christos /* Global Data. */
184 1.8 christos extern struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS];
185 1.1 christos
186 1.9 christos #define TUI_SRC_WIN ((tui_source_window *) tui_win_list[SRC_WIN])
187 1.9 christos #define TUI_DISASM_WIN ((tui_disasm_window *) tui_win_list[DISASSEM_WIN])
188 1.9 christos #define TUI_DATA_WIN ((tui_data_window *) tui_win_list[DATA_WIN])
189 1.9 christos #define TUI_CMD_WIN ((tui_cmd_window *) tui_win_list[CMD_WIN])
190 1.10 christos #define TUI_STATUS_WIN ((tui_locator_window *) tui_win_list[STATUS_WIN])
191 1.9 christos
192 1.9 christos /* All the windows that are currently instantiated, in layout
193 1.9 christos order. */
194 1.9 christos extern std::vector<tui_win_info *> tui_windows;
195 1.9 christos
196 1.9 christos /* Return a range adapter for iterating over TUI windows. */
197 1.9 christos static inline std::vector<tui_win_info *> &
198 1.9 christos all_tui_windows ()
199 1.9 christos {
200 1.9 christos return tui_windows;
201 1.9 christos }
202 1.1 christos
203 1.1 christos /* Data Manipulation Functions. */
204 1.1 christos extern int tui_term_height (void);
205 1.1 christos extern void tui_set_term_height_to (int);
206 1.1 christos extern int tui_term_width (void);
207 1.1 christos extern void tui_set_term_width_to (int);
208 1.1 christos extern struct tui_win_info *tui_win_with_focus (void);
209 1.9 christos extern bool tui_win_resized ();
210 1.9 christos extern void tui_set_win_resized_to (bool);
211 1.1 christos
212 1.1 christos extern struct tui_win_info *tui_next_win (struct tui_win_info *);
213 1.1 christos extern struct tui_win_info *tui_prev_win (struct tui_win_info *);
214 1.1 christos
215 1.8 christos extern unsigned int tui_tab_width;
216 1.8 christos
217 1.8 christos #endif /* TUI_TUI_DATA_H */
218