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