Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI data manipulation routines. |
f33c6cbf | 2 | |
42a4f53d | 3 | Copyright (C) 1998-2019 Free Software Foundation, Inc. |
f33c6cbf | 4 | |
f377b406 SC |
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 | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
f377b406 SC |
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 | |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c | 21 | |
96ec9981 DJ |
22 | #include "defs.h" |
23 | #include "symtab.h" | |
d7b2e967 AC |
24 | #include "tui/tui.h" |
25 | #include "tui/tui-data.h" | |
26 | #include "tui/tui-wingeneral.h" | |
5104fe36 | 27 | #include "tui/tui-winsource.h" |
6a83354a | 28 | #include "gdb_curses.h" |
4e8f7a8b | 29 | |
7fa29be9 | 30 | struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS]; |
c906108c | 31 | |
6ba8e26f | 32 | static int term_height, term_width; |
e65b5245 | 33 | static struct tui_win_info *win_with_focus = NULL; |
08ef48c5 | 34 | |
9abd8a65 | 35 | static bool win_resized = false; |
c906108c | 36 | |
1cc6d956 | 37 | /* Answer a whether the terminal window has been resized or not. */ |
9abd8a65 TT |
38 | bool |
39 | tui_win_resized () | |
c906108c | 40 | { |
6ba8e26f | 41 | return win_resized; |
dd1abb8c | 42 | } |
c906108c SS |
43 | |
44 | ||
1cc6d956 | 45 | /* Set a whether the terminal window has been resized or not. */ |
c906108c | 46 | void |
9abd8a65 | 47 | tui_set_win_resized_to (bool resized) |
c906108c | 48 | { |
6ba8e26f | 49 | win_resized = resized; |
dd1abb8c | 50 | } |
c906108c SS |
51 | |
52 | ||
1cc6d956 | 53 | /* Answer the window with the logical focus. */ |
2a8854a7 | 54 | struct tui_win_info * |
dd1abb8c | 55 | tui_win_with_focus (void) |
c906108c | 56 | { |
6ba8e26f | 57 | return win_with_focus; |
dd1abb8c | 58 | } |
c906108c SS |
59 | |
60 | ||
1cc6d956 | 61 | /* Set the window that has the logical focus. */ |
c906108c | 62 | void |
5b6fe301 | 63 | tui_set_win_with_focus (struct tui_win_info *win_info) |
c906108c | 64 | { |
6ba8e26f | 65 | win_with_focus = win_info; |
dd1abb8c | 66 | } |
c906108c SS |
67 | |
68 | ||
6ba8e26f | 69 | /* Accessor for the term_height. */ |
c906108c | 70 | int |
dd1abb8c | 71 | tui_term_height (void) |
c906108c | 72 | { |
6ba8e26f | 73 | return term_height; |
dd1abb8c | 74 | } |
c906108c SS |
75 | |
76 | ||
1cc6d956 | 77 | /* Mutator for the term height. */ |
c906108c | 78 | void |
dd1abb8c | 79 | tui_set_term_height_to (int h) |
c906108c | 80 | { |
6ba8e26f | 81 | term_height = h; |
dd1abb8c | 82 | } |
c906108c SS |
83 | |
84 | ||
1cc6d956 | 85 | /* Accessor for the term_width. */ |
c906108c | 86 | int |
dd1abb8c | 87 | tui_term_width (void) |
c906108c | 88 | { |
6ba8e26f | 89 | return term_width; |
dd1abb8c | 90 | } |
c906108c SS |
91 | |
92 | ||
6ba8e26f | 93 | /* Mutator for the term_width. */ |
c906108c | 94 | void |
dd1abb8c | 95 | tui_set_term_width_to (int w) |
c906108c | 96 | { |
6ba8e26f | 97 | term_width = w; |
dd1abb8c | 98 | } |
c906108c SS |
99 | |
100 | ||
dd1abb8c AC |
101 | /* Answer the next window in the list, cycling back to the top if |
102 | necessary. */ | |
2a8854a7 | 103 | struct tui_win_info * |
5b6fe301 | 104 | tui_next_win (struct tui_win_info *cur_win) |
c906108c | 105 | { |
cb2ce893 | 106 | int type = cur_win->type; |
e65b5245 | 107 | struct tui_win_info *next_win = NULL; |
c906108c | 108 | |
cb2ce893 | 109 | if (cur_win->type == CMD_WIN) |
c906108c SS |
110 | type = SRC_WIN; |
111 | else | |
cb2ce893 TT |
112 | type = cur_win->type + 1; |
113 | while (type != cur_win->type && (next_win == NULL)) | |
c906108c | 114 | { |
e5908723 | 115 | if (tui_win_list[type] |
2d83e710 | 116 | && tui_win_list[type]->is_visible ()) |
6ba8e26f | 117 | next_win = tui_win_list[type]; |
c906108c SS |
118 | else |
119 | { | |
120 | if (type == CMD_WIN) | |
121 | type = SRC_WIN; | |
122 | else | |
123 | type++; | |
124 | } | |
125 | } | |
126 | ||
6ba8e26f AC |
127 | return next_win; |
128 | } | |
c906108c SS |
129 | |
130 | ||
dd1abb8c AC |
131 | /* Answer the prev window in the list, cycling back to the bottom if |
132 | necessary. */ | |
2a8854a7 | 133 | struct tui_win_info * |
5b6fe301 | 134 | tui_prev_win (struct tui_win_info *cur_win) |
c906108c | 135 | { |
cb2ce893 | 136 | int type = cur_win->type; |
e65b5245 | 137 | struct tui_win_info *prev = NULL; |
c906108c | 138 | |
cb2ce893 | 139 | if (cur_win->type == SRC_WIN) |
c906108c SS |
140 | type = CMD_WIN; |
141 | else | |
cb2ce893 TT |
142 | type = cur_win->type - 1; |
143 | while (type != cur_win->type && (prev == NULL)) | |
c906108c | 144 | { |
37715c4c | 145 | if (tui_win_list[type] |
2d83e710 | 146 | && tui_win_list[type]->is_visible ()) |
6d012f14 | 147 | prev = tui_win_list[type]; |
c906108c SS |
148 | else |
149 | { | |
150 | if (type == SRC_WIN) | |
151 | type = CMD_WIN; | |
152 | else | |
153 | type--; | |
154 | } | |
155 | } | |
156 | ||
157 | return prev; | |
cb50eddd | 158 | } |
c906108c SS |
159 | |
160 | ||
1cc6d956 | 161 | /* Answer the window represented by name. */ |
2a8854a7 | 162 | struct tui_win_info * |
a121b7c1 | 163 | tui_partial_win_by_name (const char *name) |
c906108c | 164 | { |
63a33118 | 165 | if (name != NULL) |
c906108c | 166 | { |
1ce3e844 | 167 | for (tui_win_info *item : all_tui_windows ()) |
c906108c | 168 | { |
1ce3e844 TT |
169 | const char *cur_name = item->name (); |
170 | ||
171 | if (strlen (name) <= strlen (cur_name) | |
172 | && startswith (cur_name, name)) | |
173 | return item; | |
c906108c SS |
174 | } |
175 | } | |
176 | ||
1ce3e844 | 177 | return NULL; |
6ba8e26f | 178 | } |
c906108c | 179 | |
fede5273 TT |
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 | |
2d83e710 | 188 | && !tui_win_list[win_type]->is_visible ()) |
fede5273 TT |
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 | } | |
c906108c | 202 | |
33b906ab | 203 | tui_win_info::tui_win_info (enum tui_win_type type) |
cb2ce893 | 204 | : tui_gen_win_info (type) |
c906108c | 205 | { |
6ba8e26f | 206 | } |
c906108c | 207 | |
f936bca2 | 208 | tui_gen_win_info::~tui_gen_win_info () |
c906108c | 209 | { |
c2fc64f5 | 210 | tui_delete_win (handle); |
f936bca2 | 211 | } |
3df505f6 TT |
212 | |
213 | void | |
214 | tui_win_info::rerender () | |
215 | { | |
216 | check_and_display_highlight_if_needed (); | |
217 | } |