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