Remove tui_delete_invisible_windows and tui_make_all_invisible
[deliverable/binutils-gdb.git] / gdb / tui / tui-wingeneral.c
CommitLineData
f377b406 1/* General window behavior.
f33c6cbf 2
b811d2c2 3 Copyright (C) 1998-2020 Free Software Foundation, Inc.
f33c6cbf 4
f377b406
SC
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
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
f377b406
SC
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
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 21
96ec9981 22#include "defs.h"
d7b2e967
AC
23#include "tui/tui.h"
24#include "tui/tui-data.h"
a2a7af0c 25#include "tui/tui-io.h"
d7b2e967
AC
26#include "tui/tui-wingeneral.h"
27#include "tui/tui-win.h"
f2dda477 28#include "tui/tui-stack.h"
a2a7af0c 29#include "cli/cli-style.h"
f33c6cbf 30
6a83354a 31#include "gdb_curses.h"
4e8f7a8b 32
45bbae5c
TT
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
37static bool suppress_output;
38
39/* See tui-data.h. */
40
41tui_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
52tui_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
64void
65tui_wrefresh (WINDOW *win)
66{
67 if (!suppress_output)
68 wrefresh (win);
69}
70
5b81daba
TT
71/* See tui-data.h. */
72
c906108c 73void
5b81daba 74tui_gen_win_info::refresh_window ()
c906108c 75{
5b81daba 76 if (handle != NULL)
45bbae5c 77 tui_wrefresh (handle.get ());
5b81daba 78}
c906108c 79
af101512 80/* Draw a border arround the window. */
2c0b251b 81static void
ab0e1f1a 82box_win (struct tui_win_info *win_info,
072272ce 83 bool highlight_flag)
c906108c 84{
108e13ab
TT
85 WINDOW *win;
86 int attrs;
af101512 87
7523da63 88 win = win_info->handle.get ();
108e13ab
TT
89 if (highlight_flag)
90 attrs = tui_active_border_attrs;
91 else
92 attrs = tui_border_attrs;
af101512 93
a2a7af0c
TT
94 /* tui_apply_style resets the style entirely, so be sure to call it
95 before applying ATTRS. */
7c392d1d
TT
96 if (cli_styling)
97 tui_apply_style (win, (highlight_flag
98 ? tui_active_border_style.style ()
99 : tui_border_style.style ()));
108e13ab 100 wattron (win, attrs);
8b9cf735 101#ifdef HAVE_WBORDER
108e13ab
TT
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);
8b9cf735 106#else
108e13ab 107 box (win, tui_border_vline, tui_border_hline);
8b9cf735 108#endif
108e13ab 109 if (!win_info->title.empty ())
8634b462
TT
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)
9a6d629c 116 mvwaddstr (win, 0, 2, win_info->title.c_str ());
8634b462
TT
117 else
118 {
119 std::string truncated
120 = "..." + win_info->title.substr (win_info->title.size ()
121 - max_len + 3);
9a6d629c 122 mvwaddstr (win, 0, 2, truncated.c_str ());
8634b462
TT
123 }
124 }
108e13ab 125 wattroff (win, attrs);
a2a7af0c 126 tui_apply_style (win, ui_file_style ());
af101512 127}
c906108c
SS
128
129
c906108c 130void
5b6fe301 131tui_unhighlight_win (struct tui_win_info *win_info)
c906108c 132{
e5908723 133 if (win_info != NULL
0b026263 134 && win_info->can_box ()
cb2ce893 135 && win_info->handle != NULL)
c906108c 136 {
072272ce 137 box_win (win_info, false);
cf82af05 138 win_info->refresh_window ();
214a5cbe 139 win_info->set_highlight (false);
c906108c 140 }
ec7d9e56 141}
c906108c
SS
142
143
c906108c 144void
5b6fe301 145tui_highlight_win (struct tui_win_info *win_info)
c906108c 146{
6d012f14 147 if (win_info != NULL
0b026263 148 && win_info->can_box ()
cb2ce893 149 && win_info->handle != NULL)
c906108c 150 {
072272ce 151 box_win (win_info, true);
cf82af05 152 win_info->refresh_window ();
214a5cbe 153 win_info->set_highlight (true);
c906108c 154 }
ec7d9e56 155}
c906108c 156
c906108c 157void
b4ef5aeb 158tui_win_info::check_and_display_highlight_if_needed ()
c906108c 159{
0b026263 160 if (can_box ())
c906108c 161 {
b4ef5aeb
TT
162 if (is_highlighted)
163 tui_highlight_win (this);
c906108c 164 else
b4ef5aeb 165 tui_unhighlight_win (this);
c906108c 166 }
ec7d9e56 167}
c906108c
SS
168
169
c906108c 170void
ab0e1f1a 171tui_gen_win_info::make_window ()
c906108c 172{
fb3184d8 173 handle.reset (newwin (height, width, y, x));
cafb3438 174 if (handle != NULL)
45bbae5c
TT
175 {
176 if (suppress_output)
177 wnoutrefresh (handle.get ());
178 scrollok (handle.get (), TRUE);
179 }
bc712bbf 180}
c906108c 181
ab0e1f1a
TT
182void
183tui_win_info::make_window ()
184{
185 tui_gen_win_info::make_window ();
186 if (handle != NULL && can_box ())
072272ce 187 box_win (this, false);
ab0e1f1a 188}
c906108c 189
ec7d9e56
AC
190/* We can't really make windows visible, or invisible. So we have to
191 delete the entire window when making it visible, and create it
192 again when making it visible. */
48a3bd16
TT
193void
194tui_gen_win_info::make_visible (bool visible)
c906108c 195{
2d83e710 196 if (is_visible () == visible)
8e3cfd09 197 return;
8e3cfd09 198
c906108c 199 if (visible)
ab0e1f1a 200 make_window ();
8e3cfd09 201 else
7523da63 202 handle.reset (nullptr);
ec7d9e56 203}
c906108c 204
ec7d9e56 205/* Function to refresh all the windows currently displayed. */
c906108c 206
c906108c 207void
1ce3e844 208tui_refresh_all ()
c906108c 209{
3add462f 210 struct tui_locator_window *locator = tui_locator_win_info_ptr ();
c906108c 211
1ce3e844 212 for (tui_win_info *win_info : all_tui_windows ())
c906108c 213 {
2d83e710 214 if (win_info->is_visible ())
fd6c75ee 215 win_info->refresh_window ();
c906108c 216 }
2d83e710 217 if (locator->is_visible ())
fd6c75ee 218 locator->refresh_window ();
6ba8e26f 219}
This page took 2.474874 seconds and 4 git commands to generate.