Move source window common to code to tui-winsource.[ch]
[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 /* Function to delete the curses window, checking for NULL. */
47 void
48 tui_delete_win (WINDOW *window)
49 {
50 if (window != NULL)
51 delwin (window);
52 }
53
54
55 /* Draw a border arround the window. */
56 static void
57 box_win (struct tui_gen_win_info *win_info,
58 int highlight_flag)
59 {
60 if (win_info && win_info->handle)
61 {
62 WINDOW *win;
63 int attrs;
64
65 win = win_info->handle;
66 if (highlight_flag == HILITE)
67 attrs = tui_active_border_attrs;
68 else
69 attrs = tui_border_attrs;
70
71 wattron (win, attrs);
72 #ifdef HAVE_WBORDER
73 wborder (win, tui_border_vline, tui_border_vline,
74 tui_border_hline, tui_border_hline,
75 tui_border_ulcorner, tui_border_urcorner,
76 tui_border_llcorner, tui_border_lrcorner);
77 #else
78 box (win, tui_border_vline, tui_border_hline);
79 #endif
80 if (win_info->title)
81 mvwaddstr (win, 0, 3, win_info->title);
82 wattroff (win, attrs);
83 }
84 }
85
86
87 void
88 tui_unhighlight_win (struct tui_win_info *win_info)
89 {
90 if (win_info != NULL
91 && win_info->can_highlight
92 && win_info->handle != NULL)
93 {
94 box_win (win_info, NO_HILITE);
95 win_info->refresh_window ();
96 win_info->set_highlight (false);
97 }
98 }
99
100
101 void
102 tui_highlight_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, HILITE);
109 win_info->refresh_window ();
110 win_info->set_highlight (true);
111 }
112 }
113
114 void
115 tui_check_and_display_highlight_if_needed (struct tui_win_info *win_info)
116 {
117 if (win_info != NULL && win_info->can_highlight)
118 {
119 if (win_info->is_highlighted)
120 tui_highlight_win (win_info);
121 else
122 tui_unhighlight_win (win_info);
123
124 }
125 return;
126 }
127
128
129 void
130 tui_make_window (struct tui_gen_win_info *win_info, enum tui_box box_it)
131 {
132 WINDOW *handle;
133
134 handle = newwin (win_info->height,
135 win_info->width,
136 win_info->origin.y,
137 win_info->origin.x);
138 win_info->handle = handle;
139 if (handle != NULL)
140 {
141 if (box_it == BOX_WINDOW)
142 box_win (win_info, NO_HILITE);
143 win_info->is_visible = true;
144 scrollok (handle, TRUE);
145 }
146 }
147
148
149 /* We can't really make windows visible, or invisible. So we have to
150 delete the entire window when making it visible, and create it
151 again when making it visible. */
152 void
153 tui_gen_win_info::make_visible (bool visible)
154 {
155 if (is_visible == visible)
156 return;
157 is_visible = visible;
158
159 if (visible)
160 tui_make_window (this, (tui_win_is_auxiliary (type)
161 ? DONT_BOX_WINDOW : BOX_WINDOW));
162 else
163 {
164 tui_delete_win (handle);
165 handle = NULL;
166 }
167 }
168
169 /* Makes all windows invisible (except the command and locator
170 windows). */
171 static void
172 make_all_visible (bool visible)
173 {
174 for (tui_win_info *win_info : all_tui_windows ())
175 win_info->make_visible (visible);
176 }
177
178 void
179 tui_make_all_visible (void)
180 {
181 make_all_visible (true);
182 }
183
184 void
185 tui_make_all_invisible (void)
186 {
187 make_all_visible (false);
188 }
189
190 /* Function to refresh all the windows currently displayed. */
191
192 void
193 tui_refresh_all ()
194 {
195 struct tui_locator_window *locator = tui_locator_win_info_ptr ();
196
197 for (tui_win_info *win_info : all_tui_windows ())
198 {
199 if (win_info->is_visible)
200 win_info->refresh_window ();
201 }
202 if (locator->is_visible)
203 locator->refresh_window ();
204 }
205
206
207 /*********************************
208 ** Local Static Functions
209 *********************************/
This page took 0.03969 seconds and 4 git commands to generate.