Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI layout window management. |
080ce8c0 | 2 | |
88b9d363 | 3 | Copyright (C) 1998-2022 Free Software Foundation, Inc. |
080ce8c0 | 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_LAYOUT_H |
23 | #define TUI_TUI_LAYOUT_H | |
c906108c | 24 | |
ee325b61 TT |
25 | #include "ui-file.h" |
26 | ||
080ce8c0 AC |
27 | #include "tui/tui.h" |
28 | #include "tui/tui-data.h" | |
29 | ||
6bc56648 TT |
30 | /* Values that can be returned when handling a request to adjust a |
31 | window's size. */ | |
32 | enum tui_adjust_result | |
33 | { | |
34 | /* Requested window was not found here. */ | |
35 | NOT_FOUND, | |
36 | /* Window was found but not handled. */ | |
37 | FOUND, | |
38 | /* Window was found and handled. */ | |
39 | HANDLED | |
40 | }; | |
41 | ||
389e7ddb TT |
42 | /* The basic object in a TUI layout. This represents a single piece |
43 | of screen real estate. Subclasses determine the exact | |
44 | behavior. */ | |
45 | class tui_layout_base | |
46 | { | |
47 | public: | |
48 | ||
49 | DISABLE_COPY_AND_ASSIGN (tui_layout_base); | |
50 | ||
9b30da15 SM |
51 | virtual ~tui_layout_base () = default; |
52 | ||
389e7ddb TT |
53 | /* Clone this object. Ordinarily a layout is cloned before it is |
54 | used, so that any necessary modifications do not affect the | |
55 | "skeleton" layout. */ | |
56 | virtual std::unique_ptr<tui_layout_base> clone () const = 0; | |
57 | ||
58 | /* Change the size and location of this layout. */ | |
59 | virtual void apply (int x, int y, int width, int height) = 0; | |
60 | ||
7c043ba6 TT |
61 | /* Return the minimum and maximum height or width of this layout. |
62 | HEIGHT is true to fetch height, false to fetch width. */ | |
63 | virtual void get_sizes (bool height, int *min_value, int *max_value) = 0; | |
389e7ddb TT |
64 | |
65 | /* True if the topmost item in this layout is boxed. */ | |
66 | virtual bool top_boxed_p () const = 0; | |
67 | ||
68 | /* True if the bottommost item in this layout is boxed. */ | |
69 | virtual bool bottom_boxed_p () const = 0; | |
70 | ||
71 | /* Return the name of this layout's window, or nullptr if this | |
72 | layout does not represent a single window. */ | |
73 | virtual const char *get_name () const | |
74 | { | |
75 | return nullptr; | |
76 | } | |
77 | ||
78 | /* Adjust the size of the window named NAME to NEW_HEIGHT, updating | |
79 | the sizes of the other windows around it. */ | |
6bc56648 | 80 | virtual tui_adjust_result adjust_size (const char *name, int new_height) = 0; |
389e7ddb | 81 | |
5afe342e TT |
82 | /* Remove some windows from the layout, leaving the command window |
83 | and the window being passed in here. */ | |
84 | virtual void remove_windows (const char *name) = 0; | |
85 | ||
416eb92d TT |
86 | /* Replace the window named NAME in the layout with the window named |
87 | NEW_WINDOW. */ | |
88 | virtual void replace_window (const char *name, const char *new_window) = 0; | |
89 | ||
c22fef7e TT |
90 | /* Append the specification to this window to OUTPUT. DEPTH is the |
91 | depth of this layout in the hierarchy (zero-based). */ | |
92 | virtual void specification (ui_file *output, int depth) = 0; | |
ee325b61 | 93 | |
1cf23996 AB |
94 | /* Add all windows to the WINDOWS vector. */ |
95 | virtual void get_windows (std::vector<tui_win_info *> *windows) = 0; | |
96 | ||
389e7ddb TT |
97 | /* The most recent space allocation. */ |
98 | int x = 0; | |
99 | int y = 0; | |
100 | int width = 0; | |
101 | int height = 0; | |
102 | ||
103 | protected: | |
104 | ||
105 | tui_layout_base () = default; | |
106 | }; | |
107 | ||
108 | /* A TUI layout object that displays a single window. The window is | |
109 | given by name. */ | |
110 | class tui_layout_window : public tui_layout_base | |
111 | { | |
112 | public: | |
113 | ||
114 | explicit tui_layout_window (const char *name) | |
115 | : m_contents (name) | |
116 | { | |
117 | } | |
118 | ||
119 | DISABLE_COPY_AND_ASSIGN (tui_layout_window); | |
120 | ||
121 | std::unique_ptr<tui_layout_base> clone () const override; | |
122 | ||
123 | void apply (int x, int y, int width, int height) override; | |
124 | ||
125 | const char *get_name () const override | |
126 | { | |
127 | return m_contents.c_str (); | |
128 | } | |
129 | ||
6bc56648 | 130 | tui_adjust_result adjust_size (const char *name, int new_height) override |
389e7ddb | 131 | { |
6bc56648 | 132 | return m_contents == name ? FOUND : NOT_FOUND; |
389e7ddb TT |
133 | } |
134 | ||
135 | bool top_boxed_p () const override; | |
136 | ||
137 | bool bottom_boxed_p () const override; | |
138 | ||
5afe342e TT |
139 | void remove_windows (const char *name) override |
140 | { | |
141 | } | |
142 | ||
416eb92d TT |
143 | void replace_window (const char *name, const char *new_window) override; |
144 | ||
c22fef7e | 145 | void specification (ui_file *output, int depth) override; |
ee325b61 | 146 | |
1cf23996 AB |
147 | /* See tui_layout_base::get_windows. */ |
148 | void get_windows (std::vector<tui_win_info *> *windows) override | |
149 | { | |
150 | windows->push_back (m_window); | |
151 | } | |
152 | ||
389e7ddb TT |
153 | protected: |
154 | ||
7c043ba6 | 155 | void get_sizes (bool height, int *min_value, int *max_value) override; |
389e7ddb TT |
156 | |
157 | private: | |
158 | ||
159 | /* Type of content to display. */ | |
160 | std::string m_contents; | |
161 | ||
162 | /* When a layout is applied, this is updated to point to the window | |
163 | object. */ | |
32c1e210 | 164 | tui_win_info *m_window = nullptr; |
389e7ddb TT |
165 | }; |
166 | ||
167 | /* A TUI layout that holds other layouts. */ | |
168 | class tui_layout_split : public tui_layout_base | |
169 | { | |
170 | public: | |
171 | ||
7c043ba6 TT |
172 | /* Create a new layout. If VERTICAL is true, then windows in this |
173 | layout will be arranged vertically. */ | |
174 | explicit tui_layout_split (bool vertical = true) | |
175 | : m_vertical (vertical) | |
176 | { | |
177 | } | |
389e7ddb TT |
178 | |
179 | DISABLE_COPY_AND_ASSIGN (tui_layout_split); | |
180 | ||
181 | /* Add a new split layout to this layout. WEIGHT is the desired | |
182 | size, which is relative to the other weights given in this | |
183 | layout. */ | |
c22fef7e | 184 | void add_split (std::unique_ptr<tui_layout_split> &&layout, int weight); |
389e7ddb TT |
185 | |
186 | /* Add a new window to this layout. NAME is the name of the window | |
187 | to add. WEIGHT is the desired size, which is relative to the | |
188 | other weights given in this layout. */ | |
189 | void add_window (const char *name, int weight); | |
190 | ||
191 | std::unique_ptr<tui_layout_base> clone () const override; | |
192 | ||
193 | void apply (int x, int y, int width, int height) override; | |
194 | ||
6bc56648 | 195 | tui_adjust_result adjust_size (const char *name, int new_height) override; |
389e7ddb TT |
196 | |
197 | bool top_boxed_p () const override; | |
198 | ||
199 | bool bottom_boxed_p () const override; | |
200 | ||
5afe342e TT |
201 | void remove_windows (const char *name) override; |
202 | ||
416eb92d TT |
203 | void replace_window (const char *name, const char *new_window) override; |
204 | ||
c22fef7e | 205 | void specification (ui_file *output, int depth) override; |
ee325b61 | 206 | |
1cf23996 AB |
207 | /* See tui_layout_base::get_windows. */ |
208 | void get_windows (std::vector<tui_win_info *> *windows) override | |
209 | { | |
210 | for (auto &item : m_splits) | |
211 | item.layout->get_windows (windows); | |
212 | } | |
213 | ||
389e7ddb TT |
214 | protected: |
215 | ||
7c043ba6 | 216 | void get_sizes (bool height, int *min_value, int *max_value) override; |
389e7ddb TT |
217 | |
218 | private: | |
219 | ||
220 | /* Set the weights from the current heights. */ | |
221 | void set_weights_from_heights (); | |
222 | ||
223 | struct split | |
224 | { | |
225 | /* The requested weight. */ | |
226 | int weight; | |
227 | /* The layout. */ | |
228 | std::unique_ptr<tui_layout_base> layout; | |
229 | }; | |
230 | ||
231 | /* The splits. */ | |
232 | std::vector<split> m_splits; | |
233 | ||
7c043ba6 TT |
234 | /* True if the windows in this split are arranged vertically. */ |
235 | bool m_vertical; | |
236 | ||
389e7ddb TT |
237 | /* True if this layout has already been applied at least once. */ |
238 | bool m_applied = false; | |
239 | }; | |
240 | ||
59b8b5d2 TT |
241 | /* Add the specified window to the layout in a logical way. This |
242 | means setting up the most logical layout given the window to be | |
243 | added. Only the source or disassembly window can be added this | |
244 | way. */ | |
080ce8c0 | 245 | extern void tui_add_win_to_layout (enum tui_win_type); |
59b8b5d2 | 246 | |
416eb92d TT |
247 | /* Set the initial layout. */ |
248 | extern void tui_set_initial_layout (); | |
c906108c | 249 | |
427326a8 TT |
250 | /* Switch to the next layout. */ |
251 | extern void tui_next_layout (); | |
252 | ||
0dbc2fc7 TT |
253 | /* Show the register window. Like "layout regs". */ |
254 | extern void tui_regs_layout (); | |
255 | ||
5afe342e TT |
256 | /* Remove some windows from the layout, leaving only the focused |
257 | window and the command window; if no window has the focus, then | |
258 | some other window is chosen to remain. */ | |
259 | extern void tui_remove_some_windows (); | |
260 | ||
2192a9d3 TT |
261 | /* Apply the current layout. */ |
262 | extern void tui_apply_current_layout (); | |
263 | ||
d4eeccfe TT |
264 | /* Adjust the window height of WIN to NEW_HEIGHT. */ |
265 | extern void tui_adjust_window_height (struct tui_win_info *win, | |
266 | int new_height); | |
267 | ||
01b1af32 TT |
268 | /* The type of a function that is used to create a TUI window. */ |
269 | ||
32c1e210 | 270 | typedef std::function<tui_win_info * (const char *name)> window_factory; |
01b1af32 TT |
271 | |
272 | /* Register a new TUI window type. NAME is the name of the window | |
273 | type. FACTORY is a function that can be called to instantiate the | |
274 | window. */ | |
275 | ||
276 | extern void tui_register_window (const char *name, window_factory &&factory); | |
277 | ||
1a5c2598 | 278 | #endif /* TUI_TUI_LAYOUT_H */ |