Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI layout window management. |
080ce8c0 | 2 | |
42a4f53d | 3 | Copyright (C) 1998-2019 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 | |
080ce8c0 AC |
25 | #include "tui/tui.h" |
26 | #include "tui/tui-data.h" | |
27 | ||
389e7ddb TT |
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 | ||
9b30da15 SM |
37 | virtual ~tui_layout_base () = default; |
38 | ||
389e7ddb TT |
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 | /* The most recent space allocation. */ | |
68 | int x = 0; | |
69 | int y = 0; | |
70 | int width = 0; | |
71 | int height = 0; | |
72 | ||
73 | protected: | |
74 | ||
75 | tui_layout_base () = default; | |
76 | }; | |
77 | ||
78 | /* A TUI layout object that displays a single window. The window is | |
79 | given by name. */ | |
80 | class tui_layout_window : public tui_layout_base | |
81 | { | |
82 | public: | |
83 | ||
84 | explicit tui_layout_window (const char *name) | |
85 | : m_contents (name) | |
86 | { | |
87 | } | |
88 | ||
89 | DISABLE_COPY_AND_ASSIGN (tui_layout_window); | |
90 | ||
91 | std::unique_ptr<tui_layout_base> clone () const override; | |
92 | ||
93 | void apply (int x, int y, int width, int height) override; | |
94 | ||
95 | const char *get_name () const override | |
96 | { | |
97 | return m_contents.c_str (); | |
98 | } | |
99 | ||
100 | bool adjust_size (const char *name, int new_height) override | |
101 | { | |
102 | return false; | |
103 | } | |
104 | ||
105 | bool top_boxed_p () const override; | |
106 | ||
107 | bool bottom_boxed_p () const override; | |
108 | ||
109 | protected: | |
110 | ||
111 | void get_sizes (int *min_height, int *max_height) override; | |
112 | ||
113 | private: | |
114 | ||
115 | /* Type of content to display. */ | |
116 | std::string m_contents; | |
117 | ||
118 | /* When a layout is applied, this is updated to point to the window | |
119 | object. */ | |
120 | tui_gen_win_info *m_window = nullptr; | |
121 | }; | |
122 | ||
123 | /* A TUI layout that holds other layouts. */ | |
124 | class tui_layout_split : public tui_layout_base | |
125 | { | |
126 | public: | |
127 | ||
128 | tui_layout_split () = default; | |
129 | ||
130 | DISABLE_COPY_AND_ASSIGN (tui_layout_split); | |
131 | ||
132 | /* Add a new split layout to this layout. WEIGHT is the desired | |
133 | size, which is relative to the other weights given in this | |
134 | layout. */ | |
135 | tui_layout_split *add_split (int weight); | |
136 | ||
137 | /* Add a new window to this layout. NAME is the name of the window | |
138 | to add. WEIGHT is the desired size, which is relative to the | |
139 | other weights given in this layout. */ | |
140 | void add_window (const char *name, int weight); | |
141 | ||
142 | std::unique_ptr<tui_layout_base> clone () const override; | |
143 | ||
144 | void apply (int x, int y, int width, int height) override; | |
145 | ||
146 | bool adjust_size (const char *name, int new_height) override; | |
147 | ||
148 | bool top_boxed_p () const override; | |
149 | ||
150 | bool bottom_boxed_p () const override; | |
151 | ||
152 | protected: | |
153 | ||
154 | void get_sizes (int *min_height, int *max_height) override; | |
155 | ||
156 | private: | |
157 | ||
158 | /* Set the weights from the current heights. */ | |
159 | void set_weights_from_heights (); | |
160 | ||
161 | struct split | |
162 | { | |
163 | /* The requested weight. */ | |
164 | int weight; | |
165 | /* The layout. */ | |
166 | std::unique_ptr<tui_layout_base> layout; | |
167 | }; | |
168 | ||
169 | /* The splits. */ | |
170 | std::vector<split> m_splits; | |
171 | ||
172 | /* True if this layout has already been applied at least once. */ | |
173 | bool m_applied = false; | |
174 | }; | |
175 | ||
080ce8c0 | 176 | extern void tui_add_win_to_layout (enum tui_win_type); |
b7fbad91 | 177 | extern void tui_set_layout (enum tui_layout_type); |
c906108c | 178 | |
2192a9d3 TT |
179 | /* Apply the current layout. */ |
180 | extern void tui_apply_current_layout (); | |
181 | ||
d4eeccfe TT |
182 | /* Adjust the window height of WIN to NEW_HEIGHT. */ |
183 | extern void tui_adjust_window_height (struct tui_win_info *win, | |
184 | int new_height); | |
185 | ||
1a5c2598 | 186 | #endif /* TUI_TUI_LAYOUT_H */ |