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