Rename common to gdbsupport
[deliverable/binutils-gdb.git] / gdb / tui / tui-wingeneral.c
1 /* General window behavior.
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 "tui/tui.h"
24 #include "tui/tui-data.h"
25 #include "tui/tui-wingeneral.h"
26 #include "tui/tui-win.h"
27
28 #include "gdb_curses.h"
29
30 /***********************
31 ** PUBLIC FUNCTIONS
32 ***********************/
33
34 /* See tui-data.h. */
35
36 void
37 tui_gen_win_info::refresh_window ()
38 {
39 if (handle != NULL)
40 wrefresh (handle);
41 }
42
43 /* See tui-data.h. */
44
45 void
46 tui_data_window::refresh_window ()
47 {
48 if (!regs_content.empty ())
49 {
50 for (auto &&win : regs_content)
51 {
52 if (win != NULL && win->handle != NULL)
53 wrefresh (win->handle);
54 }
55 }
56 else
57 tui_gen_win_info::refresh_window ();
58 }
59
60 /* Function to delete the curses window, checking for NULL. */
61 void
62 tui_delete_win (WINDOW *window)
63 {
64 if (window != NULL)
65 delwin (window);
66 }
67
68
69 /* Draw a border arround the window. */
70 static void
71 box_win (struct tui_gen_win_info *win_info,
72 int highlight_flag)
73 {
74 if (win_info && win_info->handle)
75 {
76 WINDOW *win;
77 int attrs;
78
79 win = win_info->handle;
80 if (highlight_flag == HILITE)
81 attrs = tui_active_border_attrs;
82 else
83 attrs = tui_border_attrs;
84
85 wattron (win, attrs);
86 #ifdef HAVE_WBORDER
87 wborder (win, tui_border_vline, tui_border_vline,
88 tui_border_hline, tui_border_hline,
89 tui_border_ulcorner, tui_border_urcorner,
90 tui_border_llcorner, tui_border_lrcorner);
91 #else
92 box (win, tui_border_vline, tui_border_hline);
93 #endif
94 if (win_info->title)
95 mvwaddstr (win, 0, 3, win_info->title);
96 wattroff (win, attrs);
97 }
98 }
99
100
101 void
102 tui_unhighlight_win (struct tui_win_info *win_info)
103 {
104 if (win_info != NULL
105 && win_info->can_highlight
106 && win_info->handle != NULL)
107 {
108 box_win (win_info, NO_HILITE);
109 wrefresh (win_info->handle);
110 win_info->set_highlight (false);
111 }
112 }
113
114
115 void
116 tui_highlight_win (struct tui_win_info *win_info)
117 {
118 if (win_info != NULL
119 && win_info->can_highlight
120 && win_info->handle != NULL)
121 {
122 box_win (win_info, HILITE);
123 wrefresh (win_info->handle);
124 win_info->set_highlight (true);
125 }
126 }
127
128 void
129 tui_check_and_display_highlight_if_needed (struct tui_win_info *win_info)
130 {
131 if (win_info != NULL && win_info->type != CMD_WIN)
132 {
133 if (win_info->is_highlighted)
134 tui_highlight_win (win_info);
135 else
136 tui_unhighlight_win (win_info);
137
138 }
139 return;
140 }
141
142
143 void
144 tui_make_window (struct tui_gen_win_info *win_info, enum tui_box box_it)
145 {
146 WINDOW *handle;
147
148 handle = newwin (win_info->height,
149 win_info->width,
150 win_info->origin.y,
151 win_info->origin.x);
152 win_info->handle = handle;
153 if (handle != NULL)
154 {
155 if (box_it == BOX_WINDOW)
156 box_win (win_info, NO_HILITE);
157 win_info->is_visible = true;
158 scrollok (handle, TRUE);
159 }
160 }
161
162
163 /* We can't really make windows visible, or invisible. So we have to
164 delete the entire window when making it visible, and create it
165 again when making it visible. */
166 void
167 tui_gen_win_info::make_visible (bool visible)
168 {
169 if (visible)
170 {
171 if (!is_visible)
172 {
173 tui_make_window (this, (tui_win_is_auxiliary (type)
174 ? DONT_BOX_WINDOW : BOX_WINDOW));
175 is_visible = true;
176 }
177 }
178 else if (!visible
179 && is_visible
180 && handle != NULL)
181 {
182 is_visible = false;
183 tui_delete_win (handle);
184 handle = NULL;
185 }
186 }
187
188 void
189 tui_make_visible (struct tui_gen_win_info *win_info)
190 {
191 win_info->make_visible (true);
192 }
193
194 void
195 tui_make_invisible (struct tui_gen_win_info *win_info)
196 {
197 win_info->make_visible (false);
198 }
199
200 /* See tui-data.h. */
201
202 void
203 tui_source_window_base::make_visible (bool visible)
204 {
205 if (execution_info != nullptr)
206 execution_info->make_visible (visible);
207 tui_win_info::make_visible (visible);
208 }
209
210 /* Makes all windows invisible (except the command and locator
211 windows). */
212 static void
213 make_all_visible (bool visible)
214 {
215 int i;
216
217 for (i = 0; i < MAX_MAJOR_WINDOWS; i++)
218 {
219 if (tui_win_list[i] != NULL)
220 tui_win_list[i]->make_visible (visible);
221 }
222
223 return;
224 }
225
226 void
227 tui_make_all_visible (void)
228 {
229 make_all_visible (true);
230 }
231
232 void
233 tui_make_all_invisible (void)
234 {
235 make_all_visible (false);
236 }
237
238 /* See tui-data.h. */
239
240 void
241 tui_win_info::refresh ()
242 {
243 touchwin (handle);
244 refresh_window ();
245 }
246
247 /* See tui-data.h. */
248
249 void
250 tui_source_window_base::refresh ()
251 {
252 touchwin (execution_info->handle);
253 execution_info->refresh_window ();
254 tui_win_info::refresh ();
255 }
256
257 /* Function to refresh all the windows currently displayed. */
258
259 void
260 tui_refresh_all (struct tui_win_info **list)
261 {
262 int type;
263 struct tui_locator_window *locator = tui_locator_win_info_ptr ();
264
265 for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
266 {
267 if (list[type] && list[type]->is_visible)
268 list[type]->refresh ();
269 }
270 if (locator->is_visible)
271 {
272 touchwin (locator->handle);
273 locator->refresh_window ();
274 }
275 }
276
277
278 /*********************************
279 ** Local Static Functions
280 *********************************/
This page took 0.03514 seconds and 4 git commands to generate.