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