2007-08-14 Michael Snyder <msnyder@access-company.com>
[binutils-gdb.git] / gdb / tui / tui-windata.c
1 /* Data/register window display.
2
3 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007
4 Free Software Foundation, Inc.
5
6 Contributed by Hewlett-Packard Company.
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, USA. */
24
25 #include "defs.h"
26 #include "tui/tui.h"
27 #include "tui/tui-data.h"
28 #include "tui/tui-wingeneral.h"
29 #include "tui/tui-regs.h"
30
31 #include "gdb_string.h"
32 #include "gdb_curses.h"
33
34
35 /*****************************************
36 ** STATIC LOCAL FUNCTIONS FORWARD DECLS **
37 ******************************************/
38
39
40
41 /*****************************************
42 ** PUBLIC FUNCTIONS **
43 ******************************************/
44
45
46 /* Answer the index first element displayed. If none are displayed,
47 then return (-1). */
48 int
49 tui_first_data_item_displayed (void)
50 {
51 int element_no = (-1);
52 int i;
53
54 for (i = 0; (i < TUI_DATA_WIN->generic.content_size && element_no < 0); i++)
55 {
56 struct tui_gen_win_info *data_item_win;
57
58 data_item_win = &((tui_win_content)
59 TUI_DATA_WIN->generic.content)[i]->which_element.data_window;
60 if (data_item_win->handle != (WINDOW *) NULL && data_item_win->is_visible)
61 element_no = i;
62 }
63
64 return element_no;
65 }
66
67
68 /* Answer the index of the first element in line_no. If line_no is
69 past the data area (-1) is returned. */
70 int
71 tui_first_data_element_no_in_line (int line_no)
72 {
73 int first_element_no = (-1);
74
75 /*
76 ** First see if there is a register on line_no, and if so, set the
77 ** first element number.
78 */
79 if ((first_element_no = tui_first_reg_element_no_inline (line_no)) == -1)
80 { /*
81 ** Looking at the general data, the 1st element on line_no.
82 */
83 }
84
85 return first_element_no;
86 }
87
88
89 /* Function to delete all the item windows in the data window. This
90 is usually done when the data window is scrolled. */
91 void
92 tui_delete_data_content_windows (void)
93 {
94 int i;
95 struct tui_gen_win_info *data_item_win_ptr;
96
97 for (i = 0; (i < TUI_DATA_WIN->generic.content_size); i++)
98 {
99 data_item_win_ptr = &((tui_win_content)
100 TUI_DATA_WIN->generic.content)[i]->which_element.data_window;
101 tui_delete_win (data_item_win_ptr->handle);
102 data_item_win_ptr->handle = (WINDOW *) NULL;
103 data_item_win_ptr->is_visible = FALSE;
104 }
105 }
106
107
108 void
109 tui_erase_data_content (char *prompt)
110 {
111 werase (TUI_DATA_WIN->generic.handle);
112 tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
113 if (prompt != (char *) NULL)
114 {
115 int half_width = (TUI_DATA_WIN->generic.width - 2) / 2;
116 int x_pos;
117
118 if (strlen (prompt) >= half_width)
119 x_pos = 1;
120 else
121 x_pos = half_width - strlen (prompt);
122 mvwaddstr (TUI_DATA_WIN->generic.handle,
123 (TUI_DATA_WIN->generic.height / 2),
124 x_pos,
125 prompt);
126 }
127 wrefresh (TUI_DATA_WIN->generic.handle);
128 }
129
130
131 /* This function displays the data that is in the data window's
132 content. It does not set the content. */
133 void
134 tui_display_all_data (void)
135 {
136 if (TUI_DATA_WIN->generic.content_size <= 0)
137 tui_erase_data_content (NO_DATA_STRING);
138 else
139 {
140 tui_erase_data_content ((char *) NULL);
141 tui_delete_data_content_windows ();
142 tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
143 tui_display_registers_from (0);
144 /*
145 ** Then display the other data.
146 */
147 if (TUI_DATA_WIN->detail.data_display_info.data_content !=
148 (tui_win_content) NULL &&
149 TUI_DATA_WIN->detail.data_display_info.data_content_count > 0)
150 {
151 }
152 }
153 }
154
155
156 /* Function to display the data starting at line, line_no, in the data
157 window. */
158 void
159 tui_display_data_from_line (int line_no)
160 {
161 int _line_no = line_no;
162
163 if (line_no < 0)
164 _line_no = 0;
165
166 tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
167
168 /* There is no general data, force regs to display (if there are
169 any). */
170 if (TUI_DATA_WIN->detail.data_display_info.data_content_count <= 0)
171 tui_display_registers_from_line (_line_no, TRUE);
172 else
173 {
174 int element_no, start_line_no;
175 int regs_last_line = tui_last_regs_line_no ();
176
177
178 /* Display regs if we can. */
179 if (tui_display_registers_from_line (_line_no, FALSE) < 0)
180 { /*
181 ** _line_no is past the regs display, so calc where the
182 ** start data element is.
183 */
184 if (regs_last_line < _line_no)
185 { /* Figure out how many lines each element is to obtain
186 the start element_no. */
187 }
188 }
189 else
190 { /*
191 ** Calculate the starting element of the data display,
192 ** given regs_last_line and how many lines each element
193 ** is, up to _line_no.
194 */
195 }
196 /* Now display the data , starting at element_no. */
197 }
198 }
199
200
201 /* Display data starting at element element_no. */
202 void
203 tui_display_data_from (int element_no, int reuse_windows)
204 {
205 int first_line = (-1);
206
207 if (element_no < TUI_DATA_WIN->detail.data_display_info.regs_content_count)
208 first_line = tui_line_from_reg_element_no (element_no);
209 else
210 { /* Calculate the first_line from the element number. */
211 }
212
213 if (first_line >= 0)
214 {
215 tui_erase_data_content ((char *) NULL);
216 if (!reuse_windows)
217 tui_delete_data_content_windows ();
218 tui_display_data_from_line (first_line);
219 }
220 }
221
222
223 /* Function to redisplay the contents of the data window. */
224 void
225 tui_refresh_data_win (void)
226 {
227 tui_erase_data_content ((char *) NULL);
228 if (TUI_DATA_WIN->generic.content_size > 0)
229 {
230 int first_element = tui_first_data_item_displayed ();
231
232 if (first_element >= 0) /* Re-use existing windows. */
233 tui_display_data_from (first_element, TRUE);
234 }
235 }
236
237
238 /* Function to check the data values and hilite any that have
239 changed. */
240 void
241 tui_check_data_values (struct frame_info *frame)
242 {
243 tui_check_register_values (frame);
244
245 /* Now check any other data values that there are. */
246 if (TUI_DATA_WIN != NULL && TUI_DATA_WIN->generic.is_visible)
247 {
248 int i;
249
250 for (i = 0; TUI_DATA_WIN->detail.data_display_info.data_content_count; i++)
251 {
252 #ifdef LATER
253 tui_data_element_ptr data_element_ptr;
254 struct tui_gen_win_info *data_item_win_ptr;
255 Opaque new_value;
256
257 data_item_ptr = &TUI_DATA_WIN->detail.data_display_info.
258 data_content[i]->which_element.data_window;
259 data_element_ptr = &((tui_win_content)
260 data_item_win_ptr->content)[0]->which_element.data;
261 if value
262 has changed (data_element_ptr, frame, &new_value)
263 {
264 data_element_ptr->value = new_value;
265 update the display with the new value, hiliting it.
266 }
267 #endif
268 }
269 }
270 }
271
272
273 /* Scroll the data window vertically forward or backward. */
274 void
275 tui_vertical_data_scroll (enum tui_scroll_direction scroll_direction, int num_to_scroll)
276 {
277 int first_element_no;
278 int first_line = (-1);
279
280 first_element_no = tui_first_data_item_displayed ();
281 if (first_element_no < TUI_DATA_WIN->detail.data_display_info.regs_content_count)
282 first_line = tui_line_from_reg_element_no (first_element_no);
283 else
284 { /* Calculate the first line from the element number which is in
285 the general data content. */
286 }
287
288 if (first_line >= 0)
289 {
290 int last_element_no, last_line;
291
292 if (scroll_direction == FORWARD_SCROLL)
293 first_line += num_to_scroll;
294 else
295 first_line -= num_to_scroll;
296 tui_erase_data_content ((char *) NULL);
297 tui_delete_data_content_windows ();
298 tui_display_data_from_line (first_line);
299 }
300 }
301
302
303 /*****************************************
304 ** STATIC LOCAL FUNCTIONS **
305 ******************************************/