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