Merge branch 'master' into merge-job
[deliverable/binutils-gdb.git] / gdb / tui / tui-wingeneral.c
CommitLineData
f377b406 1/* General window behavior.
f33c6cbf 2
b811d2c2 3 Copyright (C) 1998-2020 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"
a2a7af0c 25#include "tui/tui-io.h"
d7b2e967
AC
26#include "tui/tui-wingeneral.h"
27#include "tui/tui-win.h"
f2dda477 28#include "tui/tui-stack.h"
a2a7af0c 29#include "cli/cli-style.h"
f33c6cbf 30
6a83354a 31#include "gdb_curses.h"
4e8f7a8b 32
5b81daba
TT
33/* See tui-data.h. */
34
c906108c 35void
5b81daba 36tui_gen_win_info::refresh_window ()
c906108c 37{
5b81daba 38 if (handle != NULL)
7523da63 39 wrefresh (handle.get ());
5b81daba 40}
c906108c 41
af101512 42/* Draw a border arround the window. */
2c0b251b 43static void
ab0e1f1a 44box_win (struct tui_win_info *win_info,
072272ce 45 bool highlight_flag)
c906108c 46{
108e13ab
TT
47 WINDOW *win;
48 int attrs;
af101512 49
7523da63 50 win = win_info->handle.get ();
108e13ab
TT
51 if (highlight_flag)
52 attrs = tui_active_border_attrs;
53 else
54 attrs = tui_border_attrs;
af101512 55
a2a7af0c
TT
56 /* tui_apply_style resets the style entirely, so be sure to call it
57 before applying ATTRS. */
7c392d1d
TT
58 if (cli_styling)
59 tui_apply_style (win, (highlight_flag
60 ? tui_active_border_style.style ()
61 : tui_border_style.style ()));
108e13ab 62 wattron (win, attrs);
8b9cf735 63#ifdef HAVE_WBORDER
108e13ab
TT
64 wborder (win, tui_border_vline, tui_border_vline,
65 tui_border_hline, tui_border_hline,
66 tui_border_ulcorner, tui_border_urcorner,
67 tui_border_llcorner, tui_border_lrcorner);
8b9cf735 68#else
108e13ab 69 box (win, tui_border_vline, tui_border_hline);
8b9cf735 70#endif
108e13ab 71 if (!win_info->title.empty ())
8634b462
TT
72 {
73 /* Emit "+-TITLE-+" -- so 2 characters on the right and 2 on
74 the left. */
75 int max_len = win_info->width - 2 - 2;
76
77 if (win_info->title.size () <= max_len)
78 mvwaddstr (win, 0, 3, win_info->title.c_str ());
79 else
80 {
81 std::string truncated
82 = "..." + win_info->title.substr (win_info->title.size ()
83 - max_len + 3);
84 mvwaddstr (win, 0, 3, truncated.c_str ());
85 }
86 }
108e13ab 87 wattroff (win, attrs);
a2a7af0c 88 tui_apply_style (win, ui_file_style ());
af101512 89}
c906108c
SS
90
91
c906108c 92void
5b6fe301 93tui_unhighlight_win (struct tui_win_info *win_info)
c906108c 94{
e5908723 95 if (win_info != NULL
0b026263 96 && win_info->can_box ()
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 106void
5b6fe301 107tui_highlight_win (struct tui_win_info *win_info)
c906108c 108{
6d012f14 109 if (win_info != NULL
0b026263 110 && win_info->can_box ()
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 119void
b4ef5aeb 120tui_win_info::check_and_display_highlight_if_needed ()
c906108c 121{
0b026263 122 if (can_box ())
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 132void
ab0e1f1a 133tui_gen_win_info::make_window ()
c906108c 134{
fb3184d8 135 handle.reset (newwin (height, width, y, x));
cafb3438 136 if (handle != NULL)
7523da63 137 scrollok (handle.get (), TRUE);
bc712bbf 138}
c906108c 139
ab0e1f1a
TT
140void
141tui_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
151void
152tui_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
7523da63 160 handle.reset (nullptr);
ec7d9e56 161}
c906108c 162
3f3ffe54 163/* See tui-wingeneral.h. */
ec7d9e56 164
ec7d9e56
AC
165void
166tui_make_all_invisible (void)
167{
3f3ffe54
TT
168 for (tui_win_info *win_info : all_tui_windows ())
169 win_info->make_visible (false);
ec7d9e56
AC
170}
171
172/* Function to refresh all the windows currently displayed. */
c906108c 173
c906108c 174void
1ce3e844 175tui_refresh_all ()
c906108c 176{
3add462f 177 struct tui_locator_window *locator = tui_locator_win_info_ptr ();
c906108c 178
1ce3e844 179 for (tui_win_info *win_info : all_tui_windows ())
c906108c 180 {
2d83e710 181 if (win_info->is_visible ())
fd6c75ee 182 win_info->refresh_window ();
c906108c 183 }
2d83e710 184 if (locator->is_visible ())
fd6c75ee 185 locator->refresh_window ();
6ba8e26f 186}
This page took 2.048035 seconds and 4 git commands to generate.