522bb9acebd173f4d35769e77f9f95440b07350b
[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 struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS];
31
32 static int term_height, term_width;
33 static struct tui_win_info *win_with_focus = NULL;
34
35 static bool win_resized = false;
36
37 /* Answer a whether the terminal window has been resized or not. */
38 bool
39 tui_win_resized ()
40 {
41 return win_resized;
42 }
43
44
45 /* Set a whether the terminal window has been resized or not. */
46 void
47 tui_set_win_resized_to (bool resized)
48 {
49 win_resized = resized;
50 }
51
52
53 /* Answer the window with the logical focus. */
54 struct tui_win_info *
55 tui_win_with_focus (void)
56 {
57 return win_with_focus;
58 }
59
60
61 /* Set the window that has the logical focus. */
62 void
63 tui_set_win_with_focus (struct tui_win_info *win_info)
64 {
65 win_with_focus = win_info;
66 }
67
68
69 /* Accessor for the term_height. */
70 int
71 tui_term_height (void)
72 {
73 return term_height;
74 }
75
76
77 /* Mutator for the term height. */
78 void
79 tui_set_term_height_to (int h)
80 {
81 term_height = h;
82 }
83
84
85 /* Accessor for the term_width. */
86 int
87 tui_term_width (void)
88 {
89 return term_width;
90 }
91
92
93 /* Mutator for the term_width. */
94 void
95 tui_set_term_width_to (int w)
96 {
97 term_width = w;
98 }
99
100
101 /* Answer the next window in the list, cycling back to the top if
102 necessary. */
103 struct tui_win_info *
104 tui_next_win (struct tui_win_info *cur_win)
105 {
106 int type = cur_win->type;
107 struct tui_win_info *next_win = NULL;
108
109 if (cur_win->type == CMD_WIN)
110 type = SRC_WIN;
111 else
112 type = cur_win->type + 1;
113 while (type != cur_win->type && (next_win == NULL))
114 {
115 if (tui_win_list[type]
116 && tui_win_list[type]->is_visible ())
117 next_win = tui_win_list[type];
118 else
119 {
120 if (type == CMD_WIN)
121 type = SRC_WIN;
122 else
123 type++;
124 }
125 }
126
127 return next_win;
128 }
129
130
131 /* Answer the prev window in the list, cycling back to the bottom if
132 necessary. */
133 struct tui_win_info *
134 tui_prev_win (struct tui_win_info *cur_win)
135 {
136 int type = cur_win->type;
137 struct tui_win_info *prev = NULL;
138
139 if (cur_win->type == SRC_WIN)
140 type = CMD_WIN;
141 else
142 type = cur_win->type - 1;
143 while (type != cur_win->type && (prev == NULL))
144 {
145 if (tui_win_list[type]
146 && tui_win_list[type]->is_visible ())
147 prev = tui_win_list[type];
148 else
149 {
150 if (type == SRC_WIN)
151 type = CMD_WIN;
152 else
153 type--;
154 }
155 }
156
157 return prev;
158 }
159
160
161 /* Answer the window represented by name. */
162 struct tui_win_info *
163 tui_partial_win_by_name (const char *name)
164 {
165 if (name != NULL)
166 {
167 for (tui_win_info *item : all_tui_windows ())
168 {
169 const char *cur_name = item->name ();
170
171 if (strlen (name) <= strlen (cur_name)
172 && startswith (cur_name, name))
173 return item;
174 }
175 }
176
177 return NULL;
178 }
179
180 /* See tui-data.h. */
181
182 void
183 tui_delete_invisible_windows ()
184 {
185 for (int win_type = SRC_WIN; (win_type < MAX_MAJOR_WINDOWS); win_type++)
186 {
187 if (tui_win_list[win_type] != NULL
188 && !tui_win_list[win_type]->is_visible ())
189 {
190 /* This should always be made visible before a call to this
191 function. */
192 gdb_assert (win_type != CMD_WIN);
193
194 if (win_with_focus == tui_win_list[win_type])
195 win_with_focus = nullptr;
196
197 delete tui_win_list[win_type];
198 tui_win_list[win_type] = NULL;
199 }
200 }
201 }
202
203 tui_win_info::tui_win_info (enum tui_win_type type)
204 : tui_gen_win_info (type)
205 {
206 }
207
208 void
209 tui_win_info::rerender ()
210 {
211 check_and_display_highlight_if_needed ();
212 }
This page took 0.033483 seconds and 4 git commands to generate.