Commit | Line | Data |
---|---|---|
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 | 44 | int |
eaf9738b | 45 | tui_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 SS |
58 | |
59 | ||
6ba8e26f AC |
60 | /* Function to delete all the item windows in the data window. This |
61 | is usually done when the data window is scrolled. */ | |
c906108c | 62 | void |
6ba8e26f | 63 | tui_delete_data_content_windows (void) |
c906108c | 64 | { |
21e1c91e | 65 | for (auto &&win : TUI_DATA_WIN->regs_content) |
c906108c | 66 | { |
21e1c91e TT |
67 | tui_delete_win (win->handle); |
68 | win->handle = NULL; | |
69 | win->is_visible = false; | |
c906108c | 70 | } |
6ba8e26f | 71 | } |
c906108c SS |
72 | |
73 | ||
74 | void | |
a121b7c1 | 75 | tui_erase_data_content (const char *prompt) |
c906108c | 76 | { |
cb2ce893 | 77 | werase (TUI_DATA_WIN->handle); |
6d012f14 | 78 | tui_check_and_display_highlight_if_needed (TUI_DATA_WIN); |
63a33118 | 79 | if (prompt != NULL) |
c906108c | 80 | { |
cb2ce893 | 81 | int half_width = (TUI_DATA_WIN->width - 2) / 2; |
6ba8e26f | 82 | int x_pos; |
c906108c | 83 | |
6ba8e26f AC |
84 | if (strlen (prompt) >= half_width) |
85 | x_pos = 1; | |
c906108c | 86 | else |
6ba8e26f | 87 | x_pos = half_width - strlen (prompt); |
cb2ce893 TT |
88 | mvwaddstr (TUI_DATA_WIN->handle, |
89 | (TUI_DATA_WIN->height / 2), | |
6ba8e26f | 90 | x_pos, |
7a6e7fcc | 91 | (char *) prompt); |
c906108c | 92 | } |
cb2ce893 | 93 | wrefresh (TUI_DATA_WIN->handle); |
edae1ccf | 94 | } |
c906108c SS |
95 | |
96 | ||
edae1ccf AC |
97 | /* This function displays the data that is in the data window's |
98 | content. It does not set the content. */ | |
c906108c | 99 | void |
edae1ccf | 100 | tui_display_all_data (void) |
c906108c | 101 | { |
21e1c91e | 102 | if (TUI_DATA_WIN->regs_content.empty ()) |
edae1ccf | 103 | tui_erase_data_content (NO_DATA_STRING); |
c906108c SS |
104 | else |
105 | { | |
63a33118 | 106 | tui_erase_data_content (NULL); |
6ba8e26f | 107 | tui_delete_data_content_windows (); |
6d012f14 | 108 | tui_check_and_display_highlight_if_needed (TUI_DATA_WIN); |
55fb0713 | 109 | tui_display_registers_from (0); |
c906108c | 110 | } |
edae1ccf | 111 | } |
c906108c SS |
112 | |
113 | ||
6ba8e26f AC |
114 | /* Function to display the data starting at line, line_no, in the data |
115 | window. */ | |
c906108c | 116 | void |
6ba8e26f | 117 | tui_display_data_from_line (int line_no) |
c906108c | 118 | { |
6ba8e26f | 119 | int _line_no = line_no; |
c906108c | 120 | |
6ba8e26f AC |
121 | if (line_no < 0) |
122 | _line_no = 0; | |
c906108c | 123 | |
6d012f14 | 124 | tui_check_and_display_highlight_if_needed (TUI_DATA_WIN); |
c906108c | 125 | |
115ac53b | 126 | tui_display_registers_from_line (_line_no, TRUE); |
6ba8e26f | 127 | } |
c906108c SS |
128 | |
129 | ||
1cc6d956 | 130 | /* Display data starting at element element_no. */ |
c906108c | 131 | void |
6ba8e26f | 132 | tui_display_data_from (int element_no, int reuse_windows) |
c906108c | 133 | { |
6ba8e26f | 134 | int first_line = (-1); |
c906108c | 135 | |
21e1c91e | 136 | if (element_no < TUI_DATA_WIN->regs_content.size ()) |
6ba8e26f | 137 | first_line = tui_line_from_reg_element_no (element_no); |
c906108c | 138 | else |
1cc6d956 | 139 | { /* Calculate the first_line from the element number. */ |
c906108c SS |
140 | } |
141 | ||
6ba8e26f | 142 | if (first_line >= 0) |
c906108c | 143 | { |
63a33118 | 144 | tui_erase_data_content (NULL); |
6ba8e26f AC |
145 | if (!reuse_windows) |
146 | tui_delete_data_content_windows (); | |
147 | tui_display_data_from_line (first_line); | |
c906108c | 148 | } |
6ba8e26f | 149 | } |
c906108c SS |
150 | |
151 | ||
edae1ccf | 152 | /* Function to redisplay the contents of the data window. */ |
c906108c | 153 | void |
1825f487 | 154 | tui_data_window::refresh_all () |
c906108c | 155 | { |
63a33118 | 156 | tui_erase_data_content (NULL); |
21e1c91e | 157 | if (!regs_content.empty ()) |
c906108c | 158 | { |
eaf9738b | 159 | int first_element = first_data_item_displayed (); |
c906108c | 160 | |
1cc6d956 | 161 | if (first_element >= 0) /* Re-use existing windows. */ |
6ba8e26f | 162 | tui_display_data_from (first_element, TRUE); |
c906108c | 163 | } |
edae1ccf | 164 | } |
c906108c SS |
165 | |
166 | ||
1cc6d956 | 167 | /* Scroll the data window vertically forward or backward. */ |
c906108c | 168 | void |
c3bd716f | 169 | tui_data_window::do_scroll_vertical (int num_to_scroll) |
c906108c | 170 | { |
6ba8e26f AC |
171 | int first_element_no; |
172 | int first_line = (-1); | |
c906108c | 173 | |
eaf9738b | 174 | first_element_no = first_data_item_displayed (); |
21e1c91e | 175 | if (first_element_no < regs_content.size ()) |
6ba8e26f | 176 | first_line = tui_line_from_reg_element_no (first_element_no); |
c906108c | 177 | else |
1cc6d956 MS |
178 | { /* Calculate the first line from the element number which is in |
179 | the general data content. */ | |
c906108c SS |
180 | } |
181 | ||
6ba8e26f | 182 | if (first_line >= 0) |
c906108c | 183 | { |
c3bd716f | 184 | first_line += num_to_scroll; |
63a33118 | 185 | tui_erase_data_content (NULL); |
6ba8e26f AC |
186 | tui_delete_data_content_windows (); |
187 | tui_display_data_from_line (first_line); | |
c906108c | 188 | } |
6ba8e26f | 189 | } |
c906108c SS |
190 | |
191 | ||
192 | /***************************************** | |
193 | ** STATIC LOCAL FUNCTIONS ** | |
194 | ******************************************/ |