Rearrange TUI data window code
[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 pertinent 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 /* Accessor for the locator win info. Answers a pointer to the static
162 locator win info struct. */
163 struct tui_locator_window *
164 tui_locator_win_info_ptr (void)
165 {
166 return &_locator;
167 }
168
169
170 /* Accessor for the term_height. */
171 int
172 tui_term_height (void)
173 {
174 return term_height;
175 }
176
177
178 /* Mutator for the term height. */
179 void
180 tui_set_term_height_to (int h)
181 {
182 term_height = h;
183 }
184
185
186 /* Accessor for the term_width. */
187 int
188 tui_term_width (void)
189 {
190 return term_width;
191 }
192
193
194 /* Mutator for the term_width. */
195 void
196 tui_set_term_width_to (int w)
197 {
198 term_width = w;
199 }
200
201
202 /* Accessor for the current layout. */
203 enum tui_layout_type
204 tui_current_layout (void)
205 {
206 return current_layout;
207 }
208
209
210 /* Mutator for the current layout. */
211 void
212 tui_set_current_layout_to (enum tui_layout_type new_layout)
213 {
214 current_layout = new_layout;
215 }
216
217
218 /*****************************
219 ** OTHER PUBLIC FUNCTIONS
220 *****************************/
221
222
223 /* Answer the next window in the list, cycling back to the top if
224 necessary. */
225 struct tui_win_info *
226 tui_next_win (struct tui_win_info *cur_win)
227 {
228 int type = cur_win->type;
229 struct tui_win_info *next_win = NULL;
230
231 if (cur_win->type == CMD_WIN)
232 type = SRC_WIN;
233 else
234 type = cur_win->type + 1;
235 while (type != cur_win->type && (next_win == NULL))
236 {
237 if (tui_win_list[type]
238 && tui_win_list[type]->is_visible)
239 next_win = tui_win_list[type];
240 else
241 {
242 if (type == CMD_WIN)
243 type = SRC_WIN;
244 else
245 type++;
246 }
247 }
248
249 return next_win;
250 }
251
252
253 /* Answer the prev window in the list, cycling back to the bottom if
254 necessary. */
255 struct tui_win_info *
256 tui_prev_win (struct tui_win_info *cur_win)
257 {
258 int type = cur_win->type;
259 struct tui_win_info *prev = NULL;
260
261 if (cur_win->type == SRC_WIN)
262 type = CMD_WIN;
263 else
264 type = cur_win->type - 1;
265 while (type != cur_win->type && (prev == NULL))
266 {
267 if (tui_win_list[type]
268 && tui_win_list[type]->is_visible)
269 prev = tui_win_list[type];
270 else
271 {
272 if (type == SRC_WIN)
273 type = CMD_WIN;
274 else
275 type--;
276 }
277 }
278
279 return prev;
280 }
281
282
283 /* Answer the window represented by name. */
284 struct tui_win_info *
285 tui_partial_win_by_name (const char *name)
286 {
287 if (name != NULL)
288 {
289 for (tui_win_info *item : all_tui_windows ())
290 {
291 const char *cur_name = item->name ();
292
293 if (strlen (name) <= strlen (cur_name)
294 && startswith (cur_name, name))
295 return item;
296 }
297 }
298
299 return NULL;
300 }
301
302
303 void
304 tui_initialize_static_data ()
305 {
306 tui_gen_win_info *win = tui_locator_win_info_ptr ();
307 win->width =
308 win->height =
309 win->origin.x =
310 win->origin.y =
311 win->viewport_height =
312 win->last_visible_line = 0;
313 win->handle = NULL;
314 win->is_visible = false;
315 win->title = 0;
316 }
317
318
319 tui_win_info::tui_win_info (enum tui_win_type type)
320 : tui_gen_win_info (type)
321 {
322 }
323
324 tui_source_window_base::tui_source_window_base (enum tui_win_type type)
325 : tui_win_info (type),
326 execution_info (new tui_exec_info_window ())
327 {
328 gdb_assert (type == SRC_WIN || type == DISASSEM_WIN);
329 start_line_or_addr.loa = LOA_ADDRESS;
330 start_line_or_addr.u.addr = 0;
331 }
332
333 tui_gen_win_info::~tui_gen_win_info ()
334 {
335 tui_delete_win (handle);
336 xfree (title);
337 }
338
339 tui_source_window_base::~tui_source_window_base ()
340 {
341 xfree (fullname);
342 delete execution_info;
343 }
344
345 /**********************************
346 ** LOCAL STATIC FUNCTIONS **
347 **********************************/
348
349
350 tui_data_item_window::~tui_data_item_window ()
351 {
352 xfree (value);
353 xfree (content);
354 }
This page took 0.04023 seconds and 4 git commands to generate.