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