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