1 /* TUI layout window management.
3 Copyright (C) 1998-2020 Free Software Foundation, Inc.
5 Contributed by Hewlett-Packard Company.
7 This file is part of GDB.
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.
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.
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/>. */
22 #ifndef TUI_TUI_LAYOUT_H
23 #define TUI_TUI_LAYOUT_H
28 #include "tui/tui-data.h"
30 /* Values that can be returned when handling a request to adjust a
32 enum tui_adjust_result
34 /* Requested window was not found here. */
36 /* Window was found but not handled. */
38 /* Window was found and handled. */
42 /* The basic object in a TUI layout. This represents a single piece
43 of screen real estate. Subclasses determine the exact
49 DISABLE_COPY_AND_ASSIGN (tui_layout_base
);
51 virtual ~tui_layout_base () = default;
53 /* Clone this object. Ordinarily a layout is cloned before it is
54 used, so that any necessary modifications do not affect the
56 virtual std::unique_ptr
<tui_layout_base
> clone () const = 0;
58 /* Change the size and location of this layout. */
59 virtual void apply (int x
, int y
, int width
, int height
) = 0;
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;
65 /* True if the topmost item in this layout is boxed. */
66 virtual bool top_boxed_p () const = 0;
68 /* True if the bottommost item in this layout is boxed. */
69 virtual bool bottom_boxed_p () const = 0;
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
78 /* Adjust the size of the window named NAME to NEW_HEIGHT, updating
79 the sizes of the other windows around it. */
80 virtual tui_adjust_result
adjust_size (const char *name
, int new_height
) = 0;
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;
86 /* Replace the window named NAME in the layout with the window named
88 virtual void replace_window (const char *name
, const char *new_window
) = 0;
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;
94 /* The most recent space allocation. */
102 tui_layout_base () = default;
105 /* A TUI layout object that displays a single window. The window is
107 class tui_layout_window
: public tui_layout_base
111 explicit tui_layout_window (const char *name
)
116 DISABLE_COPY_AND_ASSIGN (tui_layout_window
);
118 std::unique_ptr
<tui_layout_base
> clone () const override
;
120 void apply (int x
, int y
, int width
, int height
) override
;
122 const char *get_name () const override
124 return m_contents
.c_str ();
127 tui_adjust_result
adjust_size (const char *name
, int new_height
) override
129 return m_contents
== name
? FOUND
: NOT_FOUND
;
132 bool top_boxed_p () const override
;
134 bool bottom_boxed_p () const override
;
136 void remove_windows (const char *name
) override
140 void replace_window (const char *name
, const char *new_window
) override
;
142 void specification (ui_file
*output
, int depth
) override
;
146 void get_sizes (bool height
, int *min_value
, int *max_value
) override
;
150 /* Type of content to display. */
151 std::string m_contents
;
153 /* When a layout is applied, this is updated to point to the window
155 tui_gen_win_info
*m_window
= nullptr;
158 /* A TUI layout that holds other layouts. */
159 class tui_layout_split
: public tui_layout_base
163 /* Create a new layout. If VERTICAL is true, then windows in this
164 layout will be arranged vertically. */
165 explicit tui_layout_split (bool vertical
= true)
166 : m_vertical (vertical
)
170 DISABLE_COPY_AND_ASSIGN (tui_layout_split
);
172 /* Add a new split layout to this layout. WEIGHT is the desired
173 size, which is relative to the other weights given in this
175 void add_split (std::unique_ptr
<tui_layout_split
> &&layout
, int weight
);
177 /* Add a new window to this layout. NAME is the name of the window
178 to add. WEIGHT is the desired size, which is relative to the
179 other weights given in this layout. */
180 void add_window (const char *name
, int weight
);
182 std::unique_ptr
<tui_layout_base
> clone () const override
;
184 void apply (int x
, int y
, int width
, int height
) override
;
186 tui_adjust_result
adjust_size (const char *name
, int new_height
) override
;
188 bool top_boxed_p () const override
;
190 bool bottom_boxed_p () const override
;
192 void remove_windows (const char *name
) override
;
194 void replace_window (const char *name
, const char *new_window
) override
;
196 void specification (ui_file
*output
, int depth
) override
;
200 void get_sizes (bool height
, int *min_value
, int *max_value
) override
;
204 /* Set the weights from the current heights. */
205 void set_weights_from_heights ();
209 /* The requested weight. */
212 std::unique_ptr
<tui_layout_base
> layout
;
216 std::vector
<split
> m_splits
;
218 /* True if the windows in this split are arranged vertically. */
221 /* True if this layout has already been applied at least once. */
222 bool m_applied
= false;
225 /* Add the specified window to the layout in a logical way. This
226 means setting up the most logical layout given the window to be
227 added. Only the source or disassembly window can be added this
229 extern void tui_add_win_to_layout (enum tui_win_type
);
231 /* Set the initial layout. */
232 extern void tui_set_initial_layout ();
234 /* Switch to the next layout. */
235 extern void tui_next_layout ();
237 /* Show the register window. Like "layout regs". */
238 extern void tui_regs_layout ();
240 /* Remove some windows from the layout, leaving only the focused
241 window and the command window; if no window has the focus, then
242 some other window is chosen to remain. */
243 extern void tui_remove_some_windows ();
245 /* Apply the current layout. */
246 extern void tui_apply_current_layout ();
248 /* Adjust the window height of WIN to NEW_HEIGHT. */
249 extern void tui_adjust_window_height (struct tui_win_info
*win
,
252 /* The type of a function that is used to create a TUI window. */
254 typedef std::function
<tui_gen_win_info
* (const char *name
)> window_factory
;
256 /* Register a new TUI window type. NAME is the name of the window
257 type. FACTORY is a function that can be called to instantiate the
260 extern void tui_register_window (const char *name
, window_factory
&&factory
);
262 #endif /* TUI_TUI_LAYOUT_H */
This page took 0.034889 seconds and 4 git commands to generate.