Remove struct tui_layout_def
[deliverable/binutils-gdb.git] / gdb / tui / tui-data.c
1 /* TUI data manipulation routines.
2
3 Copyright (C) 1998-2019 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 #include "defs.h"
23 #include "symtab.h"
24 #include "tui/tui.h"
25 #include "tui/tui-data.h"
26 #include "tui/tui-wingeneral.h"
27 #include "tui/tui-winsource.h"
28 #include "gdb_curses.h"
29
30 /****************************
31 ** GLOBAL DECLARATIONS
32 ****************************/
33 struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS];
34
35 /***************************
36 ** Private data
37 ****************************/
38 static enum tui_layout_type current_layout = UNDEFINED_LAYOUT;
39 static int term_height, term_width;
40 static struct tui_locator_window _locator;
41 static std::vector<tui_source_window_base *> source_windows;
42 static struct tui_win_info *win_with_focus = NULL;
43
44 static int win_resized = FALSE;
45
46
47 /*********************************
48 ** PUBLIC FUNCTIONS
49 **********************************/
50
51 int
52 tui_win_is_auxiliary (enum tui_win_type win_type)
53 {
54 return (win_type > MAX_MAJOR_WINDOWS);
55 }
56
57 /******************************************
58 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
59 ******************************************/
60
61 /* Answer a whether the terminal window has been resized or not. */
62 int
63 tui_win_resized (void)
64 {
65 return win_resized;
66 }
67
68
69 /* Set a whether the terminal window has been resized or not. */
70 void
71 tui_set_win_resized_to (int resized)
72 {
73 win_resized = resized;
74 }
75
76
77 /* Answer the window with the logical focus. */
78 struct tui_win_info *
79 tui_win_with_focus (void)
80 {
81 return win_with_focus;
82 }
83
84
85 /* Set the window that has the logical focus. */
86 void
87 tui_set_win_with_focus (struct tui_win_info *win_info)
88 {
89 win_with_focus = win_info;
90 }
91
92
93 /* Accessor for the current source window. Usually there is only one
94 source window (either source or disassembly), but both can be
95 displayed at the same time. */
96 std::vector<tui_source_window_base *> &
97 tui_source_windows ()
98 {
99 return source_windows;
100 }
101
102
103 /* Clear the list of source windows. Usually there is only one source
104 window (either source or disassembly), but both can be displayed at
105 the same time. */
106 void
107 tui_clear_source_windows ()
108 {
109 source_windows.clear ();
110 }
111
112
113 /* Clear the pertinent detail in the source windows. */
114 void
115 tui_clear_source_windows_detail ()
116 {
117 for (tui_source_window_base *win : tui_source_windows ())
118 win->clear_detail ();
119 }
120
121
122 /* Add a window to the list of source windows. Usually there is only
123 one source window (either source or disassembly), but both can be
124 displayed at the same time. */
125 void
126 tui_add_to_source_windows (struct tui_source_window_base *win_info)
127 {
128 if (source_windows.size () < 2)
129 source_windows.push_back (win_info);
130 }
131
132 /* Accessor for the locator win info. Answers a pointer to the static
133 locator win info struct. */
134 struct tui_locator_window *
135 tui_locator_win_info_ptr (void)
136 {
137 return &_locator;
138 }
139
140
141 /* Accessor for the term_height. */
142 int
143 tui_term_height (void)
144 {
145 return term_height;
146 }
147
148
149 /* Mutator for the term height. */
150 void
151 tui_set_term_height_to (int h)
152 {
153 term_height = h;
154 }
155
156
157 /* Accessor for the term_width. */
158 int
159 tui_term_width (void)
160 {
161 return term_width;
162 }
163
164
165 /* Mutator for the term_width. */
166 void
167 tui_set_term_width_to (int w)
168 {
169 term_width = w;
170 }
171
172
173 /* Accessor for the current layout. */
174 enum tui_layout_type
175 tui_current_layout (void)
176 {
177 return current_layout;
178 }
179
180
181 /* Mutator for the current layout. */
182 void
183 tui_set_current_layout_to (enum tui_layout_type new_layout)
184 {
185 current_layout = new_layout;
186 }
187
188
189 /*****************************
190 ** OTHER PUBLIC FUNCTIONS
191 *****************************/
192
193
194 /* Answer the next window in the list, cycling back to the top if
195 necessary. */
196 struct tui_win_info *
197 tui_next_win (struct tui_win_info *cur_win)
198 {
199 int type = cur_win->type;
200 struct tui_win_info *next_win = NULL;
201
202 if (cur_win->type == CMD_WIN)
203 type = SRC_WIN;
204 else
205 type = cur_win->type + 1;
206 while (type != cur_win->type && (next_win == NULL))
207 {
208 if (tui_win_list[type]
209 && tui_win_list[type]->is_visible)
210 next_win = tui_win_list[type];
211 else
212 {
213 if (type == CMD_WIN)
214 type = SRC_WIN;
215 else
216 type++;
217 }
218 }
219
220 return next_win;
221 }
222
223
224 /* Answer the prev window in the list, cycling back to the bottom if
225 necessary. */
226 struct tui_win_info *
227 tui_prev_win (struct tui_win_info *cur_win)
228 {
229 int type = cur_win->type;
230 struct tui_win_info *prev = NULL;
231
232 if (cur_win->type == SRC_WIN)
233 type = CMD_WIN;
234 else
235 type = cur_win->type - 1;
236 while (type != cur_win->type && (prev == NULL))
237 {
238 if (tui_win_list[type]
239 && tui_win_list[type]->is_visible)
240 prev = tui_win_list[type];
241 else
242 {
243 if (type == SRC_WIN)
244 type = CMD_WIN;
245 else
246 type--;
247 }
248 }
249
250 return prev;
251 }
252
253
254 /* Answer the window represented by name. */
255 struct tui_win_info *
256 tui_partial_win_by_name (const char *name)
257 {
258 if (name != NULL)
259 {
260 for (tui_win_info *item : all_tui_windows ())
261 {
262 const char *cur_name = item->name ();
263
264 if (strlen (name) <= strlen (cur_name)
265 && startswith (cur_name, name))
266 return item;
267 }
268 }
269
270 return NULL;
271 }
272
273
274 void
275 tui_initialize_static_data ()
276 {
277 tui_gen_win_info *win = tui_locator_win_info_ptr ();
278 win->width =
279 win->height =
280 win->origin.x =
281 win->origin.y =
282 win->viewport_height =
283 win->last_visible_line = 0;
284 win->handle = NULL;
285 win->is_visible = false;
286 win->title = 0;
287 }
288
289
290 tui_win_info::tui_win_info (enum tui_win_type type)
291 : tui_gen_win_info (type)
292 {
293 }
294
295 tui_gen_win_info::~tui_gen_win_info ()
296 {
297 tui_delete_win (handle);
298 xfree (title);
299 }
This page took 0.047732 seconds and 4 git commands to generate.