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