GDB (xrefs)
Loading...
Searching...
No Matches
tui-wingeneral.c
Go to the documentation of this file.
1/* General window behavior.
2
3 Copyright (C) 1998-2023 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
37static bool suppress_output;
38
39/* See tui-data.h. */
40
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
53{
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
71/* See tui-data.h. */
72
73void
75{
76 if (handle != NULL)
77 tui_wrefresh (handle.get ());
78}
79
80/* Draw a border around the window. */
81static void
82box_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)
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
100 wattron (win, attrs);
101 wborder (win, tui_border_vline, tui_border_vline,
105 if (!win_info->title ().empty ())
106 {
107 /* Emit "+-TITLE-+" -- so 2 characters on the right and 2 on
108 the left. */
109 int max_len = win_info->width - 2 - 2;
110
111 if (win_info->title ().size () <= max_len)
112 mvwaddstr (win, 0, 2, win_info->title ().c_str ());
113 else
114 {
115 std::string truncated
116 = "..." + win_info->title ().substr (win_info->title ().size ()
117 - max_len + 3);
118 mvwaddstr (win, 0, 2, truncated.c_str ());
119 }
120 }
121 wattroff (win, attrs);
123}
124
125
126void
128{
129 if (win_info != NULL
130 && win_info->can_box ()
131 && win_info->handle != NULL)
132 {
133 box_win (win_info, false);
134 win_info->refresh_window ();
135 win_info->set_highlight (false);
136 }
137}
138
139
140void
142{
143 if (win_info != NULL
144 && win_info->can_box ()
145 && win_info->handle != NULL)
146 {
147 box_win (win_info, true);
148 win_info->refresh_window ();
149 win_info->set_highlight (true);
150 }
151}
152
153void
155{
156 if (can_box ())
157 {
158 if (is_highlighted)
159 tui_highlight_win (this);
160 else
161 tui_unhighlight_win (this);
162 }
163}
164
165void
167{
168 handle.reset (newwin (height, width, y, x));
169 if (handle != NULL)
170 {
171 if (suppress_output)
172 wnoutrefresh (handle.get ());
173 scrollok (handle.get (), TRUE);
174 if (can_box ())
175 box_win (this, false);
176 }
177}
178
179/* We can't really make windows visible, or invisible. So we have to
180 delete the entire window when making it visible, and create it
181 again when making it visible. */
182void
184{
185 if (is_visible () == visible)
186 return;
187
188 if (visible)
189 make_window ();
190 else
191 handle.reset (nullptr);
192}
193
194/* Function to refresh all the windows currently displayed. */
195
196void
198{
199 for (tui_win_info *win_info : all_tui_windows ())
200 {
201 if (win_info->is_visible ())
202 win_info->refresh_window ();
203 }
204}
ui_file_style style() const
Definition cli-style.c:169
bool cli_styling
Definition cli-style.c:33
cli_style_option tui_active_border_style
cli_style_option tui_border_style
const std::string & title() const
Definition tui-data.h:154
void check_and_display_highlight_if_needed()
virtual bool can_box() const
Definition tui-data.h:86
void set_highlight(bool highlight)
Definition tui-data.h:121
virtual void make_visible(bool visible)
bool is_visible() const
Definition tui-data.h:97
virtual void make_window()
std::unique_ptr< WINDOW, curses_deleter > handle
Definition tui-data.h:158
bool is_highlighted
Definition tui-data.h:168
virtual void refresh_window()
static std::vector< tui_win_info * > & all_tui_windows()
Definition tui-data.h:207
void tui_apply_style(WINDOW *w, ui_file_style style)
Definition tui-io.c:297
chtype tui_border_hline
Definition tui-win.c:217
chtype tui_border_ulcorner
Definition tui-win.c:218
int tui_border_attrs
Definition tui-win.c:223
chtype tui_border_lrcorner
Definition tui-win.c:221
chtype tui_border_vline
Definition tui-win.c:216
chtype tui_border_llcorner
Definition tui-win.c:220
int tui_active_border_attrs
Definition tui-win.c:224
chtype tui_border_urcorner
Definition tui-win.c:219
void tui_unhighlight_win(struct tui_win_info *win_info)
void tui_wrefresh(WINDOW *win)
static void box_win(struct tui_win_info *win_info, bool highlight_flag)
void tui_refresh_all()
static bool suppress_output
void tui_highlight_win(struct tui_win_info *win_info)