dae4255ada2009e0cd3fdd68baffc20881d3782a
[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 /* See tui-data.h. */
34
35 void
36 tui_gen_win_info::refresh_window ()
37 {
38 if (handle != NULL)
39 wrefresh (handle.get ());
40 }
41
42 /* Draw a border arround the window. */
43 static void
44 box_win (struct tui_win_info *win_info,
45 bool highlight_flag)
46 {
47 WINDOW *win;
48 int attrs;
49
50 win = win_info->handle.get ();
51 if (highlight_flag)
52 attrs = tui_active_border_attrs;
53 else
54 attrs = tui_border_attrs;
55
56 /* tui_apply_style resets the style entirely, so be sure to call it
57 before applying ATTRS. */
58 tui_apply_style (win, (highlight_flag
59 ? tui_active_border_style.style ()
60 : tui_border_style.style ()));
61 wattron (win, attrs);
62 #ifdef HAVE_WBORDER
63 wborder (win, tui_border_vline, tui_border_vline,
64 tui_border_hline, tui_border_hline,
65 tui_border_ulcorner, tui_border_urcorner,
66 tui_border_llcorner, tui_border_lrcorner);
67 #else
68 box (win, tui_border_vline, tui_border_hline);
69 #endif
70 if (!win_info->title.empty ())
71 {
72 /* Emit "+-TITLE-+" -- so 2 characters on the right and 2 on
73 the left. */
74 int max_len = win_info->width - 2 - 2;
75
76 if (win_info->title.size () <= max_len)
77 mvwaddstr (win, 0, 3, win_info->title.c_str ());
78 else
79 {
80 std::string truncated
81 = "..." + win_info->title.substr (win_info->title.size ()
82 - max_len + 3);
83 mvwaddstr (win, 0, 3, truncated.c_str ());
84 }
85 }
86 wattroff (win, attrs);
87 tui_apply_style (win, ui_file_style ());
88 }
89
90
91 void
92 tui_unhighlight_win (struct tui_win_info *win_info)
93 {
94 if (win_info != NULL
95 && win_info->can_box ()
96 && win_info->handle != NULL)
97 {
98 box_win (win_info, false);
99 win_info->refresh_window ();
100 win_info->set_highlight (false);
101 }
102 }
103
104
105 void
106 tui_highlight_win (struct tui_win_info *win_info)
107 {
108 if (win_info != NULL
109 && win_info->can_box ()
110 && win_info->handle != NULL)
111 {
112 box_win (win_info, true);
113 win_info->refresh_window ();
114 win_info->set_highlight (true);
115 }
116 }
117
118 void
119 tui_win_info::check_and_display_highlight_if_needed ()
120 {
121 if (can_box ())
122 {
123 if (is_highlighted)
124 tui_highlight_win (this);
125 else
126 tui_unhighlight_win (this);
127 }
128 }
129
130
131 void
132 tui_gen_win_info::make_window ()
133 {
134 handle.reset (newwin (height, width, y, x));
135 if (handle != NULL)
136 scrollok (handle.get (), TRUE);
137 }
138
139 void
140 tui_win_info::make_window ()
141 {
142 tui_gen_win_info::make_window ();
143 if (handle != NULL && can_box ())
144 box_win (this, false);
145 }
146
147 /* We can't really make windows visible, or invisible. So we have to
148 delete the entire window when making it visible, and create it
149 again when making it visible. */
150 void
151 tui_gen_win_info::make_visible (bool visible)
152 {
153 if (is_visible () == visible)
154 return;
155
156 if (visible)
157 make_window ();
158 else
159 handle.reset (nullptr);
160 }
161
162 /* See tui-wingeneral.h. */
163
164 void
165 tui_make_all_invisible (void)
166 {
167 for (tui_win_info *win_info : all_tui_windows ())
168 win_info->make_visible (false);
169 }
170
171 /* Function to refresh all the windows currently displayed. */
172
173 void
174 tui_refresh_all ()
175 {
176 struct tui_locator_window *locator = tui_locator_win_info_ptr ();
177
178 for (tui_win_info *win_info : all_tui_windows ())
179 {
180 if (win_info->is_visible ())
181 win_info->refresh_window ();
182 }
183 if (locator->is_visible ())
184 locator->refresh_window ();
185 }
This page took 0.033181 seconds and 3 git commands to generate.