Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* General window behavior. |
f33c6cbf | 2 | |
42a4f53d | 3 | Copyright (C) 1998-2019 Free Software Foundation, Inc. |
f33c6cbf | 4 | |
f377b406 SC |
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 | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
f377b406 SC |
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 | |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c | 21 | |
96ec9981 | 22 | #include "defs.h" |
d7b2e967 AC |
23 | #include "tui/tui.h" |
24 | #include "tui/tui-data.h" | |
25 | #include "tui/tui-wingeneral.h" | |
26 | #include "tui/tui-win.h" | |
f2dda477 | 27 | #include "tui/tui-stack.h" |
f33c6cbf | 28 | |
6a83354a | 29 | #include "gdb_curses.h" |
4e8f7a8b | 30 | |
5b81daba TT |
31 | /* See tui-data.h. */ |
32 | ||
c906108c | 33 | void |
5b81daba | 34 | tui_gen_win_info::refresh_window () |
c906108c | 35 | { |
5b81daba | 36 | if (handle != NULL) |
772f3f03 | 37 | wrefresh (handle); |
5b81daba | 38 | } |
c906108c | 39 | |
1cc6d956 | 40 | /* Function to delete the curses window, checking for NULL. */ |
c906108c | 41 | void |
5b6fe301 | 42 | tui_delete_win (WINDOW *window) |
c906108c | 43 | { |
cafb3438 | 44 | if (window != NULL) |
c906108c | 45 | delwin (window); |
ec7d9e56 | 46 | } |
c906108c SS |
47 | |
48 | ||
af101512 | 49 | /* Draw a border arround the window. */ |
2c0b251b | 50 | static void |
ab0e1f1a | 51 | box_win (struct tui_win_info *win_info, |
072272ce | 52 | bool highlight_flag) |
c906108c | 53 | { |
108e13ab TT |
54 | WINDOW *win; |
55 | int attrs; | |
af101512 | 56 | |
108e13ab TT |
57 | win = win_info->handle; |
58 | if (highlight_flag) | |
59 | attrs = tui_active_border_attrs; | |
60 | else | |
61 | attrs = tui_border_attrs; | |
af101512 | 62 | |
108e13ab | 63 | wattron (win, attrs); |
8b9cf735 | 64 | #ifdef HAVE_WBORDER |
108e13ab TT |
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); | |
8b9cf735 | 69 | #else |
108e13ab | 70 | box (win, tui_border_vline, tui_border_hline); |
8b9cf735 | 71 | #endif |
108e13ab | 72 | if (!win_info->title.empty ()) |
8634b462 TT |
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 | } | |
108e13ab | 88 | wattroff (win, attrs); |
af101512 | 89 | } |
c906108c SS |
90 | |
91 | ||
c906108c | 92 | void |
5b6fe301 | 93 | tui_unhighlight_win (struct tui_win_info *win_info) |
c906108c | 94 | { |
e5908723 | 95 | if (win_info != NULL |
bbc228ee | 96 | && win_info->can_highlight |
cb2ce893 | 97 | && win_info->handle != NULL) |
c906108c | 98 | { |
072272ce | 99 | box_win (win_info, false); |
cf82af05 | 100 | win_info->refresh_window (); |
214a5cbe | 101 | win_info->set_highlight (false); |
c906108c | 102 | } |
ec7d9e56 | 103 | } |
c906108c SS |
104 | |
105 | ||
c906108c | 106 | void |
5b6fe301 | 107 | tui_highlight_win (struct tui_win_info *win_info) |
c906108c | 108 | { |
6d012f14 AC |
109 | if (win_info != NULL |
110 | && win_info->can_highlight | |
cb2ce893 | 111 | && win_info->handle != NULL) |
c906108c | 112 | { |
072272ce | 113 | box_win (win_info, true); |
cf82af05 | 114 | win_info->refresh_window (); |
214a5cbe | 115 | win_info->set_highlight (true); |
c906108c | 116 | } |
ec7d9e56 | 117 | } |
c906108c | 118 | |
c906108c | 119 | void |
b4ef5aeb | 120 | tui_win_info::check_and_display_highlight_if_needed () |
c906108c | 121 | { |
b4ef5aeb | 122 | if (can_highlight) |
c906108c | 123 | { |
b4ef5aeb TT |
124 | if (is_highlighted) |
125 | tui_highlight_win (this); | |
c906108c | 126 | else |
b4ef5aeb | 127 | tui_unhighlight_win (this); |
c906108c | 128 | } |
ec7d9e56 | 129 | } |
c906108c SS |
130 | |
131 | ||
c906108c | 132 | void |
ab0e1f1a | 133 | tui_gen_win_info::make_window () |
c906108c | 134 | { |
ab0e1f1a | 135 | handle = newwin (height, width, origin.y, origin.x); |
cafb3438 | 136 | if (handle != NULL) |
ab0e1f1a | 137 | scrollok (handle, TRUE); |
bc712bbf | 138 | } |
c906108c | 139 | |
ab0e1f1a TT |
140 | void |
141 | tui_win_info::make_window () | |
142 | { | |
143 | tui_gen_win_info::make_window (); | |
144 | if (handle != NULL && can_box ()) | |
072272ce | 145 | box_win (this, false); |
ab0e1f1a | 146 | } |
c906108c | 147 | |
ec7d9e56 AC |
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. */ | |
48a3bd16 TT |
151 | void |
152 | tui_gen_win_info::make_visible (bool visible) | |
c906108c | 153 | { |
2d83e710 | 154 | if (is_visible () == visible) |
8e3cfd09 | 155 | return; |
8e3cfd09 | 156 | |
c906108c | 157 | if (visible) |
ab0e1f1a | 158 | make_window (); |
8e3cfd09 | 159 | else |
c906108c | 160 | { |
48a3bd16 TT |
161 | tui_delete_win (handle); |
162 | handle = NULL; | |
c906108c | 163 | } |
ec7d9e56 | 164 | } |
c906108c | 165 | |
3f3ffe54 | 166 | /* See tui-wingeneral.h. */ |
ec7d9e56 | 167 | |
ec7d9e56 AC |
168 | void |
169 | tui_make_all_invisible (void) | |
170 | { | |
3f3ffe54 TT |
171 | for (tui_win_info *win_info : all_tui_windows ()) |
172 | win_info->make_visible (false); | |
ec7d9e56 AC |
173 | } |
174 | ||
175 | /* Function to refresh all the windows currently displayed. */ | |
c906108c | 176 | |
c906108c | 177 | void |
1ce3e844 | 178 | tui_refresh_all () |
c906108c | 179 | { |
3add462f | 180 | struct tui_locator_window *locator = tui_locator_win_info_ptr (); |
c906108c | 181 | |
1ce3e844 | 182 | for (tui_win_info *win_info : all_tui_windows ()) |
c906108c | 183 | { |
2d83e710 | 184 | if (win_info->is_visible ()) |
fd6c75ee | 185 | win_info->refresh_window (); |
c906108c | 186 | } |
2d83e710 | 187 | if (locator->is_visible ()) |
fd6c75ee | 188 | locator->refresh_window (); |
6ba8e26f | 189 | } |