Allow TUI sub-layouts in "new-layout" command
[deliverable/binutils-gdb.git] / gdb / tui / tui-layout.h
1 /* TUI layout window management.
2
3 Copyright (C) 1998-2020 Free Software Foundation, Inc.
4
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
11 the Free Software Foundation; either version 3 of the License, or
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
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 #ifndef TUI_TUI_LAYOUT_H
23 #define TUI_TUI_LAYOUT_H
24
25 #include "ui-file.h"
26
27 #include "tui/tui.h"
28 #include "tui/tui-data.h"
29
30 /* The basic object in a TUI layout. This represents a single piece
31 of screen real estate. Subclasses determine the exact
32 behavior. */
33 class tui_layout_base
34 {
35 public:
36
37 DISABLE_COPY_AND_ASSIGN (tui_layout_base);
38
39 virtual ~tui_layout_base () = default;
40
41 /* Clone this object. Ordinarily a layout is cloned before it is
42 used, so that any necessary modifications do not affect the
43 "skeleton" layout. */
44 virtual std::unique_ptr<tui_layout_base> clone () const = 0;
45
46 /* Change the size and location of this layout. */
47 virtual void apply (int x, int y, int width, int height) = 0;
48
49 /* Return the minimum and maximum height of this layout. */
50 virtual void get_sizes (int *min_height, int *max_height) = 0;
51
52 /* True if the topmost item in this layout is boxed. */
53 virtual bool top_boxed_p () const = 0;
54
55 /* True if the bottommost item in this layout is boxed. */
56 virtual bool bottom_boxed_p () const = 0;
57
58 /* Return the name of this layout's window, or nullptr if this
59 layout does not represent a single window. */
60 virtual const char *get_name () const
61 {
62 return nullptr;
63 }
64
65 /* Adjust the size of the window named NAME to NEW_HEIGHT, updating
66 the sizes of the other windows around it. */
67 virtual bool adjust_size (const char *name, int new_height) = 0;
68
69 /* Remove some windows from the layout, leaving the command window
70 and the window being passed in here. */
71 virtual void remove_windows (const char *name) = 0;
72
73 /* Replace the window named NAME in the layout with the window named
74 NEW_WINDOW. */
75 virtual void replace_window (const char *name, const char *new_window) = 0;
76
77 /* Append the specification to this window to OUTPUT. DEPTH is the
78 depth of this layout in the hierarchy (zero-based). */
79 virtual void specification (ui_file *output, int depth) = 0;
80
81 /* The most recent space allocation. */
82 int x = 0;
83 int y = 0;
84 int width = 0;
85 int height = 0;
86
87 protected:
88
89 tui_layout_base () = default;
90 };
91
92 /* A TUI layout object that displays a single window. The window is
93 given by name. */
94 class tui_layout_window : public tui_layout_base
95 {
96 public:
97
98 explicit tui_layout_window (const char *name)
99 : m_contents (name)
100 {
101 }
102
103 DISABLE_COPY_AND_ASSIGN (tui_layout_window);
104
105 std::unique_ptr<tui_layout_base> clone () const override;
106
107 void apply (int x, int y, int width, int height) override;
108
109 const char *get_name () const override
110 {
111 return m_contents.c_str ();
112 }
113
114 bool adjust_size (const char *name, int new_height) override
115 {
116 return false;
117 }
118
119 bool top_boxed_p () const override;
120
121 bool bottom_boxed_p () const override;
122
123 void remove_windows (const char *name) override
124 {
125 }
126
127 void replace_window (const char *name, const char *new_window) override;
128
129 void specification (ui_file *output, int depth) override;
130
131 protected:
132
133 void get_sizes (int *min_height, int *max_height) override;
134
135 private:
136
137 /* Type of content to display. */
138 std::string m_contents;
139
140 /* When a layout is applied, this is updated to point to the window
141 object. */
142 tui_gen_win_info *m_window = nullptr;
143 };
144
145 /* A TUI layout that holds other layouts. */
146 class tui_layout_split : public tui_layout_base
147 {
148 public:
149
150 tui_layout_split () = default;
151
152 DISABLE_COPY_AND_ASSIGN (tui_layout_split);
153
154 /* Add a new split layout to this layout. WEIGHT is the desired
155 size, which is relative to the other weights given in this
156 layout. */
157 void add_split (std::unique_ptr<tui_layout_split> &&layout, int weight);
158
159 /* Add a new window to this layout. NAME is the name of the window
160 to add. WEIGHT is the desired size, which is relative to the
161 other weights given in this layout. */
162 void add_window (const char *name, int weight);
163
164 std::unique_ptr<tui_layout_base> clone () const override;
165
166 void apply (int x, int y, int width, int height) override;
167
168 bool adjust_size (const char *name, int new_height) override;
169
170 bool top_boxed_p () const override;
171
172 bool bottom_boxed_p () const override;
173
174 void remove_windows (const char *name) override;
175
176 void replace_window (const char *name, const char *new_window) override;
177
178 void specification (ui_file *output, int depth) override;
179
180 protected:
181
182 void get_sizes (int *min_height, int *max_height) override;
183
184 private:
185
186 /* Set the weights from the current heights. */
187 void set_weights_from_heights ();
188
189 struct split
190 {
191 /* The requested weight. */
192 int weight;
193 /* The layout. */
194 std::unique_ptr<tui_layout_base> layout;
195 };
196
197 /* The splits. */
198 std::vector<split> m_splits;
199
200 /* True if this layout has already been applied at least once. */
201 bool m_applied = false;
202 };
203
204 /* Add the specified window to the layout in a logical way. This
205 means setting up the most logical layout given the window to be
206 added. Only the source or disassembly window can be added this
207 way. */
208 extern void tui_add_win_to_layout (enum tui_win_type);
209
210 /* Set the initial layout. */
211 extern void tui_set_initial_layout ();
212
213 /* Switch to the next layout. */
214 extern void tui_next_layout ();
215
216 /* Show the register window. Like "layout regs". */
217 extern void tui_regs_layout ();
218
219 /* Remove some windows from the layout, leaving only the focused
220 window and the command window; if no window has the focus, then
221 some other window is chosen to remain. */
222 extern void tui_remove_some_windows ();
223
224 /* Apply the current layout. */
225 extern void tui_apply_current_layout ();
226
227 /* Adjust the window height of WIN to NEW_HEIGHT. */
228 extern void tui_adjust_window_height (struct tui_win_info *win,
229 int new_height);
230
231 #endif /* TUI_TUI_LAYOUT_H */
This page took 0.0363 seconds and 5 git commands to generate.