]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/tui/tui-layout.h
Change return type of tui_layout_base::adjust_size
[thirdparty/binutils-gdb.git] / gdb / tui / tui-layout.h
CommitLineData
f377b406 1/* TUI layout window management.
080ce8c0 2
b811d2c2 3 Copyright (C) 1998-2020 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. */
32enum 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. */
45class tui_layout_base
46{
47public:
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
61 /* Return the minimum and maximum height of this layout. */
62 virtual void get_sizes (int *min_height, int *max_height) = 0;
63
64 /* True if the topmost item in this layout is boxed. */
65 virtual bool top_boxed_p () const = 0;
66
67 /* True if the bottommost item in this layout is boxed. */
68 virtual bool bottom_boxed_p () const = 0;
69
70 /* Return the name of this layout's window, or nullptr if this
71 layout does not represent a single window. */
72 virtual const char *get_name () const
73 {
74 return nullptr;
75 }
76
77 /* Adjust the size of the window named NAME to NEW_HEIGHT, updating
78 the sizes of the other windows around it. */
6bc56648 79 virtual tui_adjust_result adjust_size (const char *name, int new_height) = 0;
389e7ddb 80
5afe342e
TT
81 /* Remove some windows from the layout, leaving the command window
82 and the window being passed in here. */
83 virtual void remove_windows (const char *name) = 0;
84
416eb92d
TT
85 /* Replace the window named NAME in the layout with the window named
86 NEW_WINDOW. */
87 virtual void replace_window (const char *name, const char *new_window) = 0;
88
c22fef7e
TT
89 /* Append the specification to this window to OUTPUT. DEPTH is the
90 depth of this layout in the hierarchy (zero-based). */
91 virtual void specification (ui_file *output, int depth) = 0;
ee325b61 92
389e7ddb
TT
93 /* The most recent space allocation. */
94 int x = 0;
95 int y = 0;
96 int width = 0;
97 int height = 0;
98
99protected:
100
101 tui_layout_base () = default;
102};
103
104/* A TUI layout object that displays a single window. The window is
105 given by name. */
106class tui_layout_window : public tui_layout_base
107{
108public:
109
110 explicit tui_layout_window (const char *name)
111 : m_contents (name)
112 {
113 }
114
115 DISABLE_COPY_AND_ASSIGN (tui_layout_window);
116
117 std::unique_ptr<tui_layout_base> clone () const override;
118
119 void apply (int x, int y, int width, int height) override;
120
121 const char *get_name () const override
122 {
123 return m_contents.c_str ();
124 }
125
6bc56648 126 tui_adjust_result adjust_size (const char *name, int new_height) override
389e7ddb 127 {
6bc56648 128 return m_contents == name ? FOUND : NOT_FOUND;
389e7ddb
TT
129 }
130
131 bool top_boxed_p () const override;
132
133 bool bottom_boxed_p () const override;
134
5afe342e
TT
135 void remove_windows (const char *name) override
136 {
137 }
138
416eb92d
TT
139 void replace_window (const char *name, const char *new_window) override;
140
c22fef7e 141 void specification (ui_file *output, int depth) override;
ee325b61 142
389e7ddb
TT
143protected:
144
145 void get_sizes (int *min_height, int *max_height) override;
146
147private:
148
149 /* Type of content to display. */
150 std::string m_contents;
151
152 /* When a layout is applied, this is updated to point to the window
153 object. */
154 tui_gen_win_info *m_window = nullptr;
155};
156
157/* A TUI layout that holds other layouts. */
158class tui_layout_split : public tui_layout_base
159{
160public:
161
162 tui_layout_split () = default;
163
164 DISABLE_COPY_AND_ASSIGN (tui_layout_split);
165
166 /* Add a new split layout to this layout. WEIGHT is the desired
167 size, which is relative to the other weights given in this
168 layout. */
c22fef7e 169 void add_split (std::unique_ptr<tui_layout_split> &&layout, int weight);
389e7ddb
TT
170
171 /* Add a new window to this layout. NAME is the name of the window
172 to add. WEIGHT is the desired size, which is relative to the
173 other weights given in this layout. */
174 void add_window (const char *name, int weight);
175
176 std::unique_ptr<tui_layout_base> clone () const override;
177
178 void apply (int x, int y, int width, int height) override;
179
6bc56648 180 tui_adjust_result adjust_size (const char *name, int new_height) override;
389e7ddb
TT
181
182 bool top_boxed_p () const override;
183
184 bool bottom_boxed_p () const override;
185
5afe342e
TT
186 void remove_windows (const char *name) override;
187
416eb92d
TT
188 void replace_window (const char *name, const char *new_window) override;
189
c22fef7e 190 void specification (ui_file *output, int depth) override;
ee325b61 191
389e7ddb
TT
192protected:
193
194 void get_sizes (int *min_height, int *max_height) override;
195
196private:
197
198 /* Set the weights from the current heights. */
199 void set_weights_from_heights ();
200
201 struct split
202 {
203 /* The requested weight. */
204 int weight;
205 /* The layout. */
206 std::unique_ptr<tui_layout_base> layout;
207 };
208
209 /* The splits. */
210 std::vector<split> m_splits;
211
212 /* True if this layout has already been applied at least once. */
213 bool m_applied = false;
214};
215
59b8b5d2
TT
216/* Add the specified window to the layout in a logical way. This
217 means setting up the most logical layout given the window to be
218 added. Only the source or disassembly window can be added this
219 way. */
080ce8c0 220extern void tui_add_win_to_layout (enum tui_win_type);
59b8b5d2 221
416eb92d
TT
222/* Set the initial layout. */
223extern void tui_set_initial_layout ();
c906108c 224
427326a8
TT
225/* Switch to the next layout. */
226extern void tui_next_layout ();
227
0dbc2fc7
TT
228/* Show the register window. Like "layout regs". */
229extern void tui_regs_layout ();
230
5afe342e
TT
231/* Remove some windows from the layout, leaving only the focused
232 window and the command window; if no window has the focus, then
233 some other window is chosen to remain. */
234extern void tui_remove_some_windows ();
235
2192a9d3
TT
236/* Apply the current layout. */
237extern void tui_apply_current_layout ();
238
d4eeccfe
TT
239/* Adjust the window height of WIN to NEW_HEIGHT. */
240extern void tui_adjust_window_height (struct tui_win_info *win,
241 int new_height);
242
1a5c2598 243#endif /* TUI_TUI_LAYOUT_H */