* tuiWin.c, tui.c, tuiCommand.c: Use ansi prototype.
[external/binutils.git] / gdb / tui / tuiDataWin.c
1 /* Data/register window display.
2    Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3    Contributed by Hewlett-Packard Company.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place - Suite 330,
20    Boston, MA 02111-1307, USA.  */
21
22 #include "defs.h"
23 #include "tui.h"
24 #include "tuiData.h"
25 #include "tuiRegs.h"
26
27
28 /*****************************************
29 ** STATIC LOCAL FUNCTIONS FORWARD DECLS    **
30 ******************************************/
31
32
33
34 /*****************************************
35 ** PUBLIC FUNCTIONS                        **
36 ******************************************/
37
38
39 /*
40    ** tuiFirstDataItemDisplayed()
41    **    Answer the index first element displayed.
42    **    If none are displayed, then return (-1).
43  */
44 int
45 tuiFirstDataItemDisplayed (void)
46 {
47   int elementNo = (-1);
48   int i;
49
50   for (i = 0; (i < dataWin->generic.contentSize && elementNo < 0); i++)
51     {
52       TuiGenWinInfoPtr dataItemWin;
53
54       dataItemWin = &((TuiWinContent)
55                       dataWin->generic.content)[i]->whichElement.dataWindow;
56       if (dataItemWin->handle != (WINDOW *) NULL && dataItemWin->isVisible)
57         elementNo = i;
58     }
59
60   return elementNo;
61 }                               /* tuiFirstDataItemDisplayed */
62
63
64 /*
65    ** tuiFirstDataElementNoInLine()
66    **        Answer the index of the first element in lineNo.  If lineNo is
67    **        past the data area (-1) is returned.
68  */
69 int
70 tuiFirstDataElementNoInLine (int lineNo)
71 {
72   int firstElementNo = (-1);
73
74   /*
75      ** First see if there is a register on lineNo, and if so, set the
76      ** first element number
77    */
78   if ((firstElementNo = tuiFirstRegElementNoInLine (lineNo)) == -1)
79     {                           /*
80                                    ** Looking at the general data, the 1st element on lineNo
81                                  */
82     }
83
84   return firstElementNo;
85 }                               /* tuiFirstDataElementNoInLine */
86
87
88 /*
89    ** tuiDeleteDataContentWindows()
90    **        Function to delete all the item windows in the data window.
91    **        This is usually done when the data window is scrolled.
92  */
93 void
94 tuiDeleteDataContentWindows (void)
95 {
96   int i;
97   TuiGenWinInfoPtr dataItemWinPtr;
98
99   for (i = 0; (i < dataWin->generic.contentSize); i++)
100     {
101       dataItemWinPtr = &((TuiWinContent)
102                       dataWin->generic.content)[i]->whichElement.dataWindow;
103       tuiDelwin (dataItemWinPtr->handle);
104       dataItemWinPtr->handle = (WINDOW *) NULL;
105       dataItemWinPtr->isVisible = FALSE;
106     }
107
108   return;
109 }                               /* tuiDeleteDataContentWindows */
110
111
112 void
113 tuiEraseDataContent (char *prompt)
114 {
115   werase (dataWin->generic.handle);
116   checkAndDisplayHighlightIfNeeded (dataWin);
117   if (prompt != (char *) NULL)
118     {
119       int halfWidth = (dataWin->generic.width - 2) / 2;
120       int xPos;
121
122       if (strlen (prompt) >= halfWidth)
123         xPos = 1;
124       else
125         xPos = halfWidth - strlen (prompt);
126       mvwaddstr (dataWin->generic.handle,
127                  (dataWin->generic.height / 2),
128                  xPos,
129                  prompt);
130     }
131   wrefresh (dataWin->generic.handle);
132
133   return;
134 }                               /* tuiEraseDataContent */
135
136
137 /*
138    ** tuiDisplayAllData().
139    **        This function displays the data that is in the data window's
140    **        content.  It does not set the content.
141  */
142 void
143 tuiDisplayAllData (void)
144 {
145   if (dataWin->generic.contentSize <= 0)
146     tuiEraseDataContent (NO_DATA_STRING);
147   else
148     {
149       tuiEraseDataContent ((char *) NULL);
150       tuiDeleteDataContentWindows ();
151       checkAndDisplayHighlightIfNeeded (dataWin);
152       tuiDisplayRegistersFrom (0);
153       /*
154          ** Then display the other data
155        */
156       if (dataWin->detail.dataDisplayInfo.dataContent !=
157           (TuiWinContent) NULL &&
158           dataWin->detail.dataDisplayInfo.dataContentCount > 0)
159         {
160         }
161     }
162   return;
163 }                               /* tuiDisplayAllData */
164
165
166 /*
167    ** tuiDisplayDataFromLine()
168    **        Function to display the data starting at line, lineNo, in the
169    **        data window.
170  */
171 void
172 tuiDisplayDataFromLine (int lineNo)
173 {
174   int _lineNo = lineNo;
175
176   if (lineNo < 0)
177     _lineNo = 0;
178
179   checkAndDisplayHighlightIfNeeded (dataWin);
180
181   /* there is no general data, force regs to display (if there are any) */
182   if (dataWin->detail.dataDisplayInfo.dataContentCount <= 0)
183     tuiDisplayRegistersFromLine (_lineNo, TRUE);
184   else
185     {
186       int elementNo, startLineNo;
187       int regsLastLine = tuiLastRegsLineNo ();
188
189
190       /* display regs if we can */
191       if (tuiDisplayRegistersFromLine (_lineNo, FALSE) < 0)
192         {                       /*
193                                    ** _lineNo is past the regs display, so calc where the
194                                    ** start data element is
195                                  */
196           if (regsLastLine < _lineNo)
197             {                   /* figure out how many lines each element is to obtain
198                                    the start elementNo */
199             }
200         }
201       else
202         {                       /*
203                                    ** calculate the starting element of the data display, given
204                                    ** regsLastLine and how many lines each element is, up to
205                                    ** _lineNo
206                                  */
207         }
208       /* Now display the data , starting at elementNo */
209     }
210
211   return;
212 }                               /* tuiDisplayDataFromLine */
213
214
215 /*
216    ** tuiDisplayDataFrom()
217    **        Display data starting at element elementNo
218  */
219 void
220 tuiDisplayDataFrom (int elementNo, int reuseWindows)
221 {
222   int firstLine = (-1);
223
224   if (elementNo < dataWin->detail.dataDisplayInfo.regsContentCount)
225     firstLine = tuiLineFromRegElementNo (elementNo);
226   else
227     {                           /* calculate the firstLine from the element number */
228     }
229
230   if (firstLine >= 0)
231     {
232       tuiEraseDataContent ((char *) NULL);
233       if (!reuseWindows)
234         tuiDeleteDataContentWindows ();
235       tuiDisplayDataFromLine (firstLine);
236     }
237
238   return;
239 }                               /* tuiDisplayDataFrom */
240
241
242 /*
243    ** tuiRefreshDataWin()
244    **        Function to redisplay the contents of the data window.
245  */
246 void
247 tuiRefreshDataWin (void)
248 {
249   tuiEraseDataContent ((char *) NULL);
250   if (dataWin->generic.contentSize > 0)
251     {
252       int firstElement = tuiFirstDataItemDisplayed ();
253
254       if (firstElement >= 0)    /* re-use existing windows */
255         tuiDisplayDataFrom (firstElement, TRUE);
256     }
257
258   return;
259 }                               /* tuiRefreshDataWin */
260
261
262 /*
263    ** tuiCheckDataValues().
264    **        Function to check the data values and hilite any that have changed
265  */
266 void
267 tuiCheckDataValues (struct frame_info *frame)
268 {
269   tuiCheckRegisterValues (frame);
270
271   /* Now check any other data values that there are */
272   if (m_winPtrNotNull (dataWin) && dataWin->generic.isVisible)
273     {
274       int i;
275
276       for (i = 0; dataWin->detail.dataDisplayInfo.dataContentCount; i++)
277         {
278 #ifdef LATER
279           TuiDataElementPtr dataElementPtr;
280           TuiGenWinInfoPtr dataItemWinPtr;
281           Opaque newValue;
282
283           dataItemPtr = &dataWin->detail.dataDisplayInfo.
284             dataContent[i]->whichElement.dataWindow;
285           dataElementPtr = &((TuiWinContent)
286                              dataItemWinPtr->content)[0]->whichElement.data;
287           if value
288             has changed (dataElementPtr, frame, &newValue)
289             {
290               dataElementPtr->value = newValue;
291               update the display with the new value, hiliting it.
292             }
293 #endif
294         }
295     }
296 }                               /* tuiCheckDataValues */
297
298
299 /*
300    ** tui_vCheckDataValues().
301    **        Function to check the data values and hilite any that have
302    **        changed with args in a va_list
303  */
304 void
305 tui_vCheckDataValues (va_list args)
306 {
307   struct frame_info *frame = va_arg (args, struct frame_info *);
308
309   tuiCheckDataValues (frame);
310
311   return;
312 }                               /* tui_vCheckDataValues */
313
314
315 /*
316    ** tuiVerticalDataScroll()
317    **        Scroll the data window vertically forward or backward.
318  */
319 void
320 tuiVerticalDataScroll (TuiScrollDirection scrollDirection, int numToScroll)
321 {
322   int firstElementNo;
323   int firstLine = (-1);
324
325   firstElementNo = tuiFirstDataItemDisplayed ();
326   if (firstElementNo < dataWin->detail.dataDisplayInfo.regsContentCount)
327     firstLine = tuiLineFromRegElementNo (firstElementNo);
328   else
329     {                           /* calculate the first line from the element number which is in
330                                    ** the general data content
331                                  */
332     }
333
334   if (firstLine >= 0)
335     {
336       int lastElementNo, lastLine;
337
338       if (scrollDirection == FORWARD_SCROLL)
339         firstLine += numToScroll;
340       else
341         firstLine -= numToScroll;
342       tuiEraseDataContent ((char *) NULL);
343       tuiDeleteDataContentWindows ();
344       tuiDisplayDataFromLine (firstLine);
345     }
346
347   return;
348 }                               /* tuiVerticalDataScroll */
349
350
351 /*****************************************
352 ** STATIC LOCAL FUNCTIONS               **
353 ******************************************/