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