Remove tui_gen_win_info
[deliverable/binutils-gdb.git] / gdb / tui / tui-wingeneral.c
1 /* General window behavior.
2
3 Copyright (C) 1998-2020 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-io.h"
26 #include "tui/tui-wingeneral.h"
27 #include "tui/tui-win.h"
28 #include "tui/tui-stack.h"
29 #include "cli/cli-style.h"
30
31 #include "gdb_curses.h"
32
33 /* This is true if we're currently suppressing output, via
34 wnoutrefresh. This is needed in case we create a new window while
35 in this mode. */
36
37 static bool suppress_output;
38
39 /* See tui-data.h. */
40
41 tui_suppress_output::tui_suppress_output ()
42 : m_saved_suppress (suppress_output)
43 {
44 suppress_output = true;
45
46 for (const auto &win : all_tui_windows ())
47 win->no_refresh ();
48 }
49
50 /* See tui-data.h. */
51
52 tui_suppress_output::~tui_suppress_output ()
53 {
54 suppress_output = m_saved_suppress;
55 if (!suppress_output)
56 doupdate ();
57
58 for (const auto &win : all_tui_windows ())
59 win->refresh_window ();
60 }
61
62 /* See tui-data.h. */
63
64 void
65 tui_wrefresh (WINDOW *win)
66 {
67 if (!suppress_output)
68 wrefresh (win);
69 }
70
71 /* See tui-data.h. */
72
73 void
74 tui_win_info::refresh_window ()
75 {
76 if (handle != NULL)
77 tui_wrefresh (handle.get ());
78 }
79
80 /* Draw a border arround the window. */
81 static void
82 box_win (struct tui_win_info *win_info,
83 bool highlight_flag)
84 {
85 WINDOW *win;
86 int attrs;
87
88 win = win_info->handle.get ();
89 if (highlight_flag)
90 attrs = tui_active_border_attrs;
91 else
92 attrs = tui_border_attrs;
93
94 /* tui_apply_style resets the style entirely, so be sure to call it
95 before applying ATTRS. */
96 if (cli_styling)
97 tui_apply_style (win, (highlight_flag
98 ? tui_active_border_style.style ()
99 : tui_border_style.style ()));
100 wattron (win, attrs);
101 #ifdef HAVE_WBORDER
102 wborder (win, tui_border_vline, tui_border_vline,
103 tui_border_hline, tui_border_hline,
104 tui_border_ulcorner, tui_border_urcorner,
105 tui_border_llcorner, tui_border_lrcorner);
106 #else
107 box (win, tui_border_vline, tui_border_hline);
108 #endif
109 if (!win_info->title.empty ())
110 {
111 /* Emit "+-TITLE-+" -- so 2 characters on the right and 2 on
112 the left. */
113 int max_len = win_info->width - 2 - 2;
114
115 if (win_info->title.size () <= max_len)
116 mvwaddstr (win, 0, 2, win_info->title.c_str ());
117 else
118 {
119 std::string truncated
120 = "..." + win_info->title.substr (win_info->title.size ()
121 - max_len + 3);
122 mvwaddstr (win, 0, 2, truncated.c_str ());
123 }
124 }
125 wattroff (win, attrs);
126 tui_apply_style (win, ui_file_style ());
127 }
128
129
130 void
131 tui_unhighlight_win (struct tui_win_info *win_info)
132 {
133 if (win_info != NULL
134 && win_info->can_box ()
135 && win_info->handle != NULL)
136 {
137 box_win (win_info, false);
138 win_info->refresh_window ();
139 win_info->set_highlight (false);
140 }
141 }
142
143
144 void
145 tui_highlight_win (struct tui_win_info *win_info)
146 {
147 if (win_info != NULL
148 && win_info->can_box ()
149 && win_info->handle != NULL)
150 {
151 box_win (win_info, true);
152 win_info->refresh_window ();
153 win_info->set_highlight (true);
154 }
155 }
156
157 void
158 tui_win_info::check_and_display_highlight_if_needed ()
159 {
160 if (can_box ())
161 {
162 if (is_highlighted)
163 tui_highlight_win (this);
164 else
165 tui_unhighlight_win (this);
166 }
167 }
168
169 void
170 tui_win_info::make_window ()
171 {
172 handle.reset (newwin (height, width, y, x));
173 if (handle != NULL)
174 {
175 if (suppress_output)
176 wnoutrefresh (handle.get ());
177 scrollok (handle.get (), TRUE);
178 if (can_box ())
179 box_win (this, false);
180 }
181 }
182
183 /* We can't really make windows visible, or invisible. So we have to
184 delete the entire window when making it visible, and create it
185 again when making it visible. */
186 void
187 tui_win_info::make_visible (bool visible)
188 {
189 if (is_visible () == visible)
190 return;
191
192 if (visible)
193 make_window ();
194 else
195 handle.reset (nullptr);
196 }
197
198 /* Function to refresh all the windows currently displayed. */
199
200 void
201 tui_refresh_all ()
202 {
203 struct tui_locator_window *locator = tui_locator_win_info_ptr ();
204
205 for (tui_win_info *win_info : all_tui_windows ())
206 {
207 if (win_info->is_visible ())
208 win_info->refresh_window ();
209 }
210 if (locator->is_visible ())
211 locator->refresh_window ();
212 }
This page took 0.033838 seconds and 4 git commands to generate.