22f841eb88c12bc1852eea0dd78cbb5a24a6d7ac
[external/binutils.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->can_highlight)
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   for (tui_win_info *win_info : all_tui_windows ())
216     win_info->make_visible (visible);
217 }
218
219 void
220 tui_make_all_visible (void)
221 {
222   make_all_visible (true);
223 }
224
225 void
226 tui_make_all_invisible (void)
227 {
228   make_all_visible (false);
229 }
230
231 /* See tui-data.h.  */
232
233 void
234 tui_win_info::refresh ()
235 {
236   touchwin (handle);
237   refresh_window ();
238 }
239
240 /* See tui-data.h.  */
241
242 void
243 tui_source_window_base::refresh ()
244 {
245   touchwin (execution_info->handle);
246   execution_info->refresh_window ();
247   tui_win_info::refresh ();
248 }
249
250 /* Function to refresh all the windows currently displayed.  */
251
252 void
253 tui_refresh_all ()
254 {
255   struct tui_locator_window *locator = tui_locator_win_info_ptr ();
256
257   for (tui_win_info *win_info : all_tui_windows ())
258     {
259       if (win_info->is_visible)
260         win_info->refresh ();
261     }
262   if (locator->is_visible)
263     {
264       touchwin (locator->handle);
265       locator->refresh_window ();
266     }
267 }
268
269
270 /*********************************
271 ** Local Static Functions
272 *********************************/