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 arround 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#ifdef HAVE_WBORDER
102 wborder (win, tui_border_vline, tui_border_vline,
106#else
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);
127}
128
129
130void
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
144void
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
157void
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
169void
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. */
186void
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
200void
202{
203 for (tui_win_info *win_info : all_tui_windows ())
204 {
205 if (win_info->is_visible ())
206 win_info->refresh_window ();
207 }
208}
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
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)
std::string title
Definition tui-data.h:160
bool is_visible() const
Definition tui-data.h:97
virtual void make_window()
std::unique_ptr< WINDOW, curses_deleter > handle
Definition tui-data.h:150
bool is_highlighted
Definition tui-data.h:163
virtual void refresh_window()
static std::vector< tui_win_info * > & all_tui_windows()
Definition tui-data.h:198
void tui_apply_style(WINDOW *w, ui_file_style style)
Definition tui-io.c:296
chtype tui_border_hline
Definition tui-win.c:250
chtype tui_border_ulcorner
Definition tui-win.c:251
int tui_border_attrs
Definition tui-win.c:256
chtype tui_border_lrcorner
Definition tui-win.c:254
chtype tui_border_vline
Definition tui-win.c:249
chtype tui_border_llcorner
Definition tui-win.c:253
int tui_active_border_attrs
Definition tui-win.c:257
chtype tui_border_urcorner
Definition tui-win.c:252
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)