1 /* General window behavior.
3 Copyright (C) 1998-2020 Free Software Foundation, Inc.
5 Contributed by Hewlett-Packard Company.
7 This file is part of GDB.
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.
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.
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/>. */
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"
31 #include "gdb_curses.h"
33 /* This is true if we're currently suppressing output, via
34 wnoutrefresh. This is needed in case we create a new window while
37 static bool suppress_output
;
41 tui_suppress_output::tui_suppress_output ()
42 : m_saved_suppress (suppress_output
)
44 suppress_output
= true;
46 for (const auto &win
: all_tui_windows ())
52 tui_suppress_output::~tui_suppress_output ()
54 suppress_output
= m_saved_suppress
;
58 for (const auto &win
: all_tui_windows ())
59 win
->refresh_window ();
65 tui_wrefresh (WINDOW
*win
)
74 tui_win_info::refresh_window ()
77 tui_wrefresh (handle
.get ());
80 /* Draw a border arround the window. */
82 box_win (struct tui_win_info
*win_info
,
88 win
= win_info
->handle
.get ();
90 attrs
= tui_active_border_attrs
;
92 attrs
= tui_border_attrs
;
94 /* tui_apply_style resets the style entirely, so be sure to call it
95 before applying ATTRS. */
97 tui_apply_style (win
, (highlight_flag
98 ? tui_active_border_style
.style ()
99 : tui_border_style
.style ()));
100 wattron (win
, attrs
);
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
);
107 box (win
, tui_border_vline
, tui_border_hline
);
109 if (!win_info
->title
.empty ())
111 /* Emit "+-TITLE-+" -- so 2 characters on the right and 2 on
113 int max_len
= win_info
->width
- 2 - 2;
115 if (win_info
->title
.size () <= max_len
)
116 mvwaddstr (win
, 0, 2, win_info
->title
.c_str ());
119 std::string truncated
120 = "..." + win_info
->title
.substr (win_info
->title
.size ()
122 mvwaddstr (win
, 0, 2, truncated
.c_str ());
125 wattroff (win
, attrs
);
126 tui_apply_style (win
, ui_file_style ());
131 tui_unhighlight_win (struct tui_win_info
*win_info
)
134 && win_info
->can_box ()
135 && win_info
->handle
!= NULL
)
137 box_win (win_info
, false);
138 win_info
->refresh_window ();
139 win_info
->set_highlight (false);
145 tui_highlight_win (struct tui_win_info
*win_info
)
148 && win_info
->can_box ()
149 && win_info
->handle
!= NULL
)
151 box_win (win_info
, true);
152 win_info
->refresh_window ();
153 win_info
->set_highlight (true);
158 tui_win_info::check_and_display_highlight_if_needed ()
163 tui_highlight_win (this);
165 tui_unhighlight_win (this);
170 tui_win_info::make_window ()
172 handle
.reset (newwin (height
, width
, y
, x
));
176 wnoutrefresh (handle
.get ());
177 scrollok (handle
.get (), TRUE
);
179 box_win (this, false);
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. */
187 tui_win_info::make_visible (bool visible
)
189 if (is_visible () == visible
)
195 handle
.reset (nullptr);
198 /* Function to refresh all the windows currently displayed. */
203 struct tui_locator_window
*locator
= tui_locator_win_info_ptr ();
205 for (tui_win_info
*win_info
: all_tui_windows ())
207 if (win_info
->is_visible ())
208 win_info
->refresh_window ();
210 if (locator
->is_visible ())
211 locator
->refresh_window ();