Fix flushing bug in tui_puts_internal
[deliverable/binutils-gdb.git] / gdb / tui / tui-windata.c
CommitLineData
f377b406 1/* Data/register window display.
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-regs.h"
2c0b251b 27#include "tui/tui-windata.h"
6a83354a 28#include "gdb_curses.h"
4e8f7a8b 29
c906108c
SS
30
31/*****************************************
32** STATIC LOCAL FUNCTIONS FORWARD DECLS **
33******************************************/
34
35
36
37/*****************************************
38** PUBLIC FUNCTIONS **
39******************************************/
40
41
6ba8e26f
AC
42/* Answer the index first element displayed. If none are displayed,
43 then return (-1). */
c906108c 44int
eaf9738b 45tui_data_window::first_data_item_displayed ()
c906108c 46{
21e1c91e 47 for (int i = 0; i < regs_content.size (); i++)
c906108c 48 {
5b6fe301 49 struct tui_gen_win_info *data_item_win;
c906108c 50
21e1c91e 51 data_item_win = regs_content[i].get ();
eaf9738b
TT
52 if (data_item_win->handle != NULL && data_item_win->is_visible)
53 return i;
c906108c
SS
54 }
55
eaf9738b 56 return -1;
6ba8e26f 57}
c906108c 58
b4094625 59/* See tui-data.h. */
c906108c 60
c906108c 61void
b4094625 62tui_data_window::delete_data_content_windows ()
c906108c 63{
b4094625 64 for (auto &&win : regs_content)
c906108c 65 {
21e1c91e
TT
66 tui_delete_win (win->handle);
67 win->handle = NULL;
68 win->is_visible = false;
c906108c 69 }
6ba8e26f 70}
c906108c
SS
71
72
73void
f76d8b19 74tui_data_window::erase_data_content (const char *prompt)
c906108c 75{
f76d8b19
TT
76 werase (handle);
77 tui_check_and_display_highlight_if_needed (this);
63a33118 78 if (prompt != NULL)
c906108c 79 {
f76d8b19 80 int half_width = (width - 2) / 2;
6ba8e26f 81 int x_pos;
c906108c 82
6ba8e26f
AC
83 if (strlen (prompt) >= half_width)
84 x_pos = 1;
c906108c 85 else
6ba8e26f 86 x_pos = half_width - strlen (prompt);
f76d8b19 87 mvwaddstr (handle, (height / 2), x_pos, (char *) prompt);
c906108c 88 }
f76d8b19 89 wrefresh (handle);
edae1ccf 90}
c906108c 91
50daf268 92/* See tui-data.h. */
c906108c 93
c906108c 94void
50daf268 95tui_data_window::display_all_data ()
c906108c 96{
50daf268 97 if (regs_content.empty ())
f76d8b19 98 erase_data_content (NO_DATA_STRING);
c906108c
SS
99 else
100 {
f76d8b19 101 erase_data_content (NULL);
b4094625 102 delete_data_content_windows ();
50daf268 103 tui_check_and_display_highlight_if_needed (this);
517e9505 104 display_registers_from (0);
c906108c 105 }
edae1ccf 106}
c906108c
SS
107
108
edae1ccf 109/* Function to redisplay the contents of the data window. */
c906108c 110void
1825f487 111tui_data_window::refresh_all ()
c906108c 112{
f76d8b19 113 erase_data_content (NULL);
21e1c91e 114 if (!regs_content.empty ())
c906108c 115 {
eaf9738b 116 int first_element = first_data_item_displayed ();
c906108c 117
1cc6d956 118 if (first_element >= 0) /* Re-use existing windows. */
df5f8cab
TT
119 {
120 int first_line = (-1);
121
122 if (first_element < regs_content.size ())
123 first_line = line_from_reg_element_no (first_element);
124
125 if (first_line >= 0)
126 {
f76d8b19 127 erase_data_content (NULL);
517e9505 128 display_registers_from_line (first_line);
df5f8cab
TT
129 }
130 }
c906108c 131 }
edae1ccf 132}
c906108c
SS
133
134
1cc6d956 135/* Scroll the data window vertically forward or backward. */
c906108c 136void
c3bd716f 137tui_data_window::do_scroll_vertical (int num_to_scroll)
c906108c 138{
6ba8e26f
AC
139 int first_element_no;
140 int first_line = (-1);
c906108c 141
eaf9738b 142 first_element_no = first_data_item_displayed ();
21e1c91e 143 if (first_element_no < regs_content.size ())
3b23c5f2 144 first_line = line_from_reg_element_no (first_element_no);
c906108c 145 else
1cc6d956
MS
146 { /* Calculate the first line from the element number which is in
147 the general data content. */
c906108c
SS
148 }
149
6ba8e26f 150 if (first_line >= 0)
c906108c 151 {
c3bd716f 152 first_line += num_to_scroll;
f76d8b19 153 erase_data_content (NULL);
b4094625 154 delete_data_content_windows ();
517e9505 155 display_registers_from_line (first_line);
c906108c 156 }
6ba8e26f 157}
c906108c
SS
158
159
160/*****************************************
161** STATIC LOCAL FUNCTIONS **
162******************************************/
This page took 1.995713 seconds and 4 git commands to generate.