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