2004-02-07 Andrew Cagney <cagney@redhat.com>
[external/binutils.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 #ifdef HAVE_NCURSES_H       
32 #include <ncurses.h>
33 #else
34 #ifdef HAVE_CURSES_H
35 #include <curses.h>
36 #endif
37 #endif
38
39
40 /*****************************************
41 ** STATIC LOCAL FUNCTIONS FORWARD DECLS    **
42 ******************************************/
43
44
45
46 /*****************************************
47 ** PUBLIC FUNCTIONS                        **
48 ******************************************/
49
50
51 /*
52    ** tuiFirstDataItemDisplayed()
53    **    Answer the index first element displayed.
54    **    If none are displayed, then return (-1).
55  */
56 int
57 tuiFirstDataItemDisplayed (void)
58 {
59   int elementNo = (-1);
60   int i;
61
62   for (i = 0; (i < dataWin->generic.contentSize && elementNo < 0); i++)
63     {
64       struct tui_gen_win_info * dataItemWin;
65
66       dataItemWin = &((tui_win_content)
67                       dataWin->generic.content)[i]->whichElement.dataWindow;
68       if (dataItemWin->handle != (WINDOW *) NULL && dataItemWin->isVisible)
69         elementNo = i;
70     }
71
72   return elementNo;
73 }                               /* tuiFirstDataItemDisplayed */
74
75
76 /*
77    ** tuiFirstDataElementNoInLine()
78    **        Answer the index of the first element in lineNo.  If lineNo is
79    **        past the data area (-1) is returned.
80  */
81 int
82 tuiFirstDataElementNoInLine (int lineNo)
83 {
84   int firstElementNo = (-1);
85
86   /*
87      ** First see if there is a register on lineNo, and if so, set the
88      ** first element number
89    */
90   if ((firstElementNo = tui_first_reg_element_no_inline (lineNo)) == -1)
91     {                           /*
92                                    ** Looking at the general data, the 1st element on lineNo
93                                  */
94     }
95
96   return firstElementNo;
97 }                               /* tuiFirstDataElementNoInLine */
98
99
100 /*
101    ** tuiDeleteDataContentWindows()
102    **        Function to delete all the item windows in the data window.
103    **        This is usually done when the data window is scrolled.
104  */
105 void
106 tuiDeleteDataContentWindows (void)
107 {
108   int i;
109   struct tui_gen_win_info * dataItemWinPtr;
110
111   for (i = 0; (i < dataWin->generic.contentSize); i++)
112     {
113       dataItemWinPtr = &((tui_win_content)
114                       dataWin->generic.content)[i]->whichElement.dataWindow;
115       tui_delete_win (dataItemWinPtr->handle);
116       dataItemWinPtr->handle = (WINDOW *) NULL;
117       dataItemWinPtr->isVisible = FALSE;
118     }
119
120   return;
121 }                               /* tuiDeleteDataContentWindows */
122
123
124 void
125 tui_erase_data_content (char *prompt)
126 {
127   werase (dataWin->generic.handle);
128   tui_check_and_display_highlight_if_needed (dataWin);
129   if (prompt != (char *) NULL)
130     {
131       int halfWidth = (dataWin->generic.width - 2) / 2;
132       int xPos;
133
134       if (strlen (prompt) >= halfWidth)
135         xPos = 1;
136       else
137         xPos = halfWidth - strlen (prompt);
138       mvwaddstr (dataWin->generic.handle,
139                  (dataWin->generic.height / 2),
140                  xPos,
141                  prompt);
142     }
143   wrefresh (dataWin->generic.handle);
144 }
145
146
147 /* This function displays the data that is in the data window's
148    content.  It does not set the content.  */
149 void
150 tui_display_all_data (void)
151 {
152   if (dataWin->generic.contentSize <= 0)
153     tui_erase_data_content (NO_DATA_STRING);
154   else
155     {
156       tui_erase_data_content ((char *) NULL);
157       tuiDeleteDataContentWindows ();
158       tui_check_and_display_highlight_if_needed (dataWin);
159       tui_display_registers_from (0);
160       /*
161          ** Then display the other data
162        */
163       if (dataWin->detail.dataDisplayInfo.dataContent !=
164           (tui_win_content) NULL &&
165           dataWin->detail.dataDisplayInfo.dataContentCount > 0)
166         {
167         }
168     }
169 }
170
171
172 /*
173    ** tuiDisplayDataFromLine()
174    **        Function to display the data starting at line, lineNo, in the
175    **        data window.
176  */
177 void
178 tuiDisplayDataFromLine (int lineNo)
179 {
180   int _lineNo = lineNo;
181
182   if (lineNo < 0)
183     _lineNo = 0;
184
185   tui_check_and_display_highlight_if_needed (dataWin);
186
187   /* there is no general data, force regs to display (if there are any) */
188   if (dataWin->detail.dataDisplayInfo.dataContentCount <= 0)
189     tui_display_registers_from_line (_lineNo, TRUE);
190   else
191     {
192       int elementNo, startLineNo;
193       int regsLastLine = tui_last_regs_line_no ();
194
195
196       /* display regs if we can */
197       if (tui_display_registers_from_line (_lineNo, FALSE) < 0)
198         {                       /*
199                                    ** _lineNo is past the regs display, so calc where the
200                                    ** start data element is
201                                  */
202           if (regsLastLine < _lineNo)
203             {                   /* figure out how many lines each element is to obtain
204                                    the start elementNo */
205             }
206         }
207       else
208         {                       /*
209                                    ** calculate the starting element of the data display, given
210                                    ** regsLastLine and how many lines each element is, up to
211                                    ** _lineNo
212                                  */
213         }
214       /* Now display the data , starting at elementNo */
215     }
216
217   return;
218 }                               /* tuiDisplayDataFromLine */
219
220
221 /*
222    ** tuiDisplayDataFrom()
223    **        Display data starting at element elementNo
224  */
225 void
226 tuiDisplayDataFrom (int elementNo, int reuseWindows)
227 {
228   int firstLine = (-1);
229
230   if (elementNo < dataWin->detail.dataDisplayInfo.regsContentCount)
231     firstLine = tui_line_from_reg_element_no (elementNo);
232   else
233     {                           /* calculate the firstLine from the element number */
234     }
235
236   if (firstLine >= 0)
237     {
238       tui_erase_data_content ((char *) NULL);
239       if (!reuseWindows)
240         tuiDeleteDataContentWindows ();
241       tuiDisplayDataFromLine (firstLine);
242     }
243
244   return;
245 }                               /* tuiDisplayDataFrom */
246
247
248 /* Function to redisplay the contents of the data window.  */
249 void
250 tui_refresh_data_win (void)
251 {
252   tui_erase_data_content ((char *) NULL);
253   if (dataWin->generic.contentSize > 0)
254     {
255       int firstElement = tuiFirstDataItemDisplayed ();
256
257       if (firstElement >= 0)    /* re-use existing windows */
258         tuiDisplayDataFrom (firstElement, TRUE);
259     }
260 }
261
262
263 /* Function to check the data values and hilite any that have changed.  */
264 void
265 tui_check_data_values (struct frame_info *frame)
266 {
267   tui_check_register_values (frame);
268
269   /* Now check any other data values that there are */
270   if (m_winPtrNotNull (dataWin) && dataWin->generic.isVisible)
271     {
272       int i;
273
274       for (i = 0; dataWin->detail.dataDisplayInfo.dataContentCount; i++)
275         {
276 #ifdef LATER
277           TuiDataElementPtr dataElementPtr;
278           struct tui_gen_win_info * dataItemWinPtr;
279           Opaque newValue;
280
281           dataItemPtr = &dataWin->detail.dataDisplayInfo.
282             dataContent[i]->whichElement.dataWindow;
283           dataElementPtr = &((tui_win_content)
284                              dataItemWinPtr->content)[0]->whichElement.data;
285           if value
286             has changed (dataElementPtr, frame, &newValue)
287             {
288               dataElementPtr->value = newValue;
289               update the display with the new value, hiliting it.
290             }
291 #endif
292         }
293     }
294 }
295
296
297 /* Scroll the data window vertically forward or backward.   */
298 void
299 tui_vertical_data_scroll (enum tui_scroll_direction scrollDirection, int numToScroll)
300 {
301   int firstElementNo;
302   int firstLine = (-1);
303
304   firstElementNo = tuiFirstDataItemDisplayed ();
305   if (firstElementNo < dataWin->detail.dataDisplayInfo.regsContentCount)
306     firstLine = tui_line_from_reg_element_no (firstElementNo);
307   else
308     {                           /* calculate the first line from the element number which is in
309                                    ** the general data content
310                                  */
311     }
312
313   if (firstLine >= 0)
314     {
315       int lastElementNo, lastLine;
316
317       if (scrollDirection == FORWARD_SCROLL)
318         firstLine += numToScroll;
319       else
320         firstLine -= numToScroll;
321       tui_erase_data_content ((char *) NULL);
322       tuiDeleteDataContentWindows ();
323       tuiDisplayDataFromLine (firstLine);
324     }
325
326   return;
327 }                               /* tuiVerticalDataScroll */
328
329
330 /*****************************************
331 ** STATIC LOCAL FUNCTIONS               **
332 ******************************************/