Introduce TUI window iterator
[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 "gdb_curses.h"
28
29 /****************************
30 ** GLOBAL DECLARATIONS
31 ****************************/
32 struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS];
33
34 /***************************
35 ** Private data
36 ****************************/
37 static enum tui_layout_type current_layout = UNDEFINED_LAYOUT;
38 static int term_height, term_width;
39 static struct tui_locator_window _locator;
40 static std::vector<tui_source_window_base *> source_windows;
41 static struct tui_win_info *win_with_focus = NULL;
42 static struct tui_layout_def layout_def = {
43 SRC_WIN, /* DISPLAY_MODE */
44 };
45
46 static int win_resized = FALSE;
47
48
49 /*********************************
50 ** PUBLIC FUNCTIONS
51 **********************************/
52
53 int
54 tui_win_is_auxiliary (enum tui_win_type win_type)
55 {
56 return (win_type > MAX_MAJOR_WINDOWS);
57 }
58
59 /******************************************
60 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
61 ******************************************/
62
63 /* Answer a whether the terminal window has been resized or not. */
64 int
65 tui_win_resized (void)
66 {
67 return win_resized;
68 }
69
70
71 /* Set a whether the terminal window has been resized or not. */
72 void
73 tui_set_win_resized_to (int resized)
74 {
75 win_resized = resized;
76 }
77
78
79 /* Answer a pointer to the current layout definition. */
80 struct tui_layout_def *
81 tui_layout_def (void)
82 {
83 return &layout_def;
84 }
85
86
87 /* Answer the window with the logical focus. */
88 struct tui_win_info *
89 tui_win_with_focus (void)
90 {
91 return win_with_focus;
92 }
93
94
95 /* Set the window that has the logical focus. */
96 void
97 tui_set_win_with_focus (struct tui_win_info *win_info)
98 {
99 win_with_focus = win_info;
100 }
101
102
103 /* Accessor for the current source window. Usually there is only one
104 source window (either source or disassembly), but both can be
105 displayed at the same time. */
106 std::vector<tui_source_window_base *> &
107 tui_source_windows ()
108 {
109 return source_windows;
110 }
111
112
113 /* Clear the list of source windows. Usually there is only one source
114 window (either source or disassembly), but both can be displayed at
115 the same time. */
116 void
117 tui_clear_source_windows ()
118 {
119 source_windows.clear ();
120 }
121
122
123 /* Clear the pertinant detail in the source windows. */
124 void
125 tui_clear_source_windows_detail ()
126 {
127 for (tui_source_window_base *win : tui_source_windows ())
128 win->clear_detail ();
129 }
130
131
132 /* Add a window to the list of source windows. Usually there is only
133 one source window (either source or disassembly), but both can be
134 displayed at the same time. */
135 void
136 tui_add_to_source_windows (struct tui_source_window_base *win_info)
137 {
138 if (source_windows.size () < 2)
139 source_windows.push_back (win_info);
140 }
141
142 /* See tui-data.h. */
143
144 void
145 tui_source_window_base::clear_detail ()
146 {
147 gdbarch = NULL;
148 start_line_or_addr.loa = LOA_ADDRESS;
149 start_line_or_addr.u.addr = 0;
150 horizontal_offset = 0;
151 }
152
153 /* See tui-data.h. */
154
155 void
156 tui_cmd_window::clear_detail ()
157 {
158 wmove (handle, 0, 0);
159 }
160
161 /* See tui-data.h. */
162
163 void
164 tui_data_window::clear_detail ()
165 {
166 regs_content.clear ();
167 regs_column_count = 1;
168 display_regs = false;
169 }
170
171 /* Accessor for the locator win info. Answers a pointer to the static
172 locator win info struct. */
173 struct tui_locator_window *
174 tui_locator_win_info_ptr (void)
175 {
176 return &_locator;
177 }
178
179
180 /* Accessor for the term_height. */
181 int
182 tui_term_height (void)
183 {
184 return term_height;
185 }
186
187
188 /* Mutator for the term height. */
189 void
190 tui_set_term_height_to (int h)
191 {
192 term_height = h;
193 }
194
195
196 /* Accessor for the term_width. */
197 int
198 tui_term_width (void)
199 {
200 return term_width;
201 }
202
203
204 /* Mutator for the term_width. */
205 void
206 tui_set_term_width_to (int w)
207 {
208 term_width = w;
209 }
210
211
212 /* Accessor for the current layout. */
213 enum tui_layout_type
214 tui_current_layout (void)
215 {
216 return current_layout;
217 }
218
219
220 /* Mutator for the current layout. */
221 void
222 tui_set_current_layout_to (enum tui_layout_type new_layout)
223 {
224 current_layout = new_layout;
225 }
226
227
228 /*****************************
229 ** OTHER PUBLIC FUNCTIONS
230 *****************************/
231
232
233 /* Answer the next window in the list, cycling back to the top if
234 necessary. */
235 struct tui_win_info *
236 tui_next_win (struct tui_win_info *cur_win)
237 {
238 int type = cur_win->type;
239 struct tui_win_info *next_win = NULL;
240
241 if (cur_win->type == CMD_WIN)
242 type = SRC_WIN;
243 else
244 type = cur_win->type + 1;
245 while (type != cur_win->type && (next_win == NULL))
246 {
247 if (tui_win_list[type]
248 && tui_win_list[type]->is_visible)
249 next_win = tui_win_list[type];
250 else
251 {
252 if (type == CMD_WIN)
253 type = SRC_WIN;
254 else
255 type++;
256 }
257 }
258
259 return next_win;
260 }
261
262
263 /* Answer the prev window in the list, cycling back to the bottom if
264 necessary. */
265 struct tui_win_info *
266 tui_prev_win (struct tui_win_info *cur_win)
267 {
268 int type = cur_win->type;
269 struct tui_win_info *prev = NULL;
270
271 if (cur_win->type == SRC_WIN)
272 type = CMD_WIN;
273 else
274 type = cur_win->type - 1;
275 while (type != cur_win->type && (prev == NULL))
276 {
277 if (tui_win_list[type]
278 && tui_win_list[type]->is_visible)
279 prev = tui_win_list[type];
280 else
281 {
282 if (type == SRC_WIN)
283 type = CMD_WIN;
284 else
285 type--;
286 }
287 }
288
289 return prev;
290 }
291
292
293 /* Answer the window represented by name. */
294 struct tui_win_info *
295 tui_partial_win_by_name (const char *name)
296 {
297 if (name != NULL)
298 {
299 for (tui_win_info *item : all_tui_windows ())
300 {
301 const char *cur_name = item->name ();
302
303 if (strlen (name) <= strlen (cur_name)
304 && startswith (cur_name, name))
305 return item;
306 }
307 }
308
309 return NULL;
310 }
311
312
313 void
314 tui_initialize_static_data ()
315 {
316 tui_gen_win_info *win = tui_locator_win_info_ptr ();
317 win->width =
318 win->height =
319 win->origin.x =
320 win->origin.y =
321 win->viewport_height =
322 win->last_visible_line = 0;
323 win->handle = NULL;
324 win->content_in_use = FALSE;
325 win->is_visible = false;
326 win->title = 0;
327 }
328
329
330 tui_win_info::tui_win_info (enum tui_win_type type)
331 : tui_gen_win_info (type)
332 {
333 }
334
335 tui_source_window_base::tui_source_window_base (enum tui_win_type type)
336 : tui_win_info (type)
337 {
338 gdb_assert (type == SRC_WIN || type == DISASSEM_WIN);
339 start_line_or_addr.loa = LOA_ADDRESS;
340 start_line_or_addr.u.addr = 0;
341 }
342
343 tui_gen_win_info::~tui_gen_win_info ()
344 {
345 tui_delete_win (handle);
346 xfree (title);
347 }
348
349 tui_source_window_base::~tui_source_window_base ()
350 {
351 xfree (fullname);
352 delete execution_info;
353 }
354
355 /**********************************
356 ** LOCAL STATIC FUNCTIONS **
357 **********************************/
358
359
360 tui_data_item_window::~tui_data_item_window ()
361 {
362 xfree (value);
363 xfree (content);
364 }
This page took 0.038374 seconds and 5 git commands to generate.