This commit was generated by cvs2svn to track changes on a CVS vendor
[deliverable/binutils-gdb.git] / gdb / tui / tuiGeneralWin.c
1 /* General window behavior.
2
3 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation,
4 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 /* FIXME: cagney/2002-02-28: The GDB coding standard indicates that
26 "defs.h" should be included first. Unfortunatly some systems
27 (currently Debian GNU/Linux) include the <stdbool.h> via <curses.h>
28 and they clash with "bfd.h"'s definiton of true/false. The correct
29 fix is to remove true/false from "bfd.h", however, until that
30 happens, hack around it by including "config.h" and <curses.h>
31 first. */
32
33 #include "config.h"
34 #ifdef HAVE_NCURSES_H
35 #include <ncurses.h>
36 #else
37 #ifdef HAVE_CURSES_H
38 #include <curses.h>
39 #endif
40 #endif
41
42 #include "defs.h"
43 #include "tui.h"
44 #include "tuiData.h"
45 #include "tuiGeneralWin.h"
46 #include "tuiWin.h"
47
48 /*
49 ** local support functions
50 */
51 static void _winResize (void);
52
53
54 /***********************
55 ** PUBLIC FUNCTIONS
56 ***********************/
57 /*
58 ** tuiRefreshWin()
59 ** Refresh the window
60 */
61 void
62 tuiRefreshWin (TuiGenWinInfoPtr winInfo)
63 {
64 if (winInfo->type == DATA_WIN && winInfo->contentSize > 0)
65 {
66 int i;
67
68 for (i = 0; (i < winInfo->contentSize); i++)
69 {
70 TuiGenWinInfoPtr dataItemWinPtr;
71
72 dataItemWinPtr = &((TuiWinContent)
73 winInfo->content)[i]->whichElement.dataWindow;
74 if (m_genWinPtrNotNull (dataItemWinPtr) &&
75 dataItemWinPtr->handle != (WINDOW *) NULL)
76 wrefresh (dataItemWinPtr->handle);
77 }
78 }
79 else if (winInfo->type == CMD_WIN)
80 {
81 /* Do nothing */
82 }
83 else
84 {
85 if (winInfo->handle != (WINDOW *) NULL)
86 wrefresh (winInfo->handle);
87 }
88
89 return;
90 } /* tuiRefreshWin */
91
92
93 /*
94 ** tuiDelwin()
95 ** Function to delete the curses window, checking for null
96 */
97 void
98 tuiDelwin (WINDOW * window)
99 {
100 if (window != (WINDOW *) NULL)
101 delwin (window);
102
103 return;
104 } /* tuiDelwin */
105
106
107 /* Draw a border arround the window. */
108 void
109 boxWin (TuiGenWinInfoPtr winInfo, int highlightFlag)
110 {
111 if (winInfo && winInfo->handle)
112 {
113 WINDOW *win;
114 int attrs;
115
116 win = winInfo->handle;
117 if (highlightFlag == HILITE)
118 attrs = tui_active_border_attrs;
119 else
120 attrs = tui_border_attrs;
121
122 wattron (win, attrs);
123 wborder (win, tui_border_vline, tui_border_vline,
124 tui_border_hline, tui_border_hline,
125 tui_border_ulcorner, tui_border_urcorner,
126 tui_border_llcorner, tui_border_lrcorner);
127 wattroff (win, attrs);
128 }
129 }
130
131
132 /*
133 ** unhighlightWin().
134 */
135 void
136 unhighlightWin (TuiWinInfoPtr winInfo)
137 {
138 if (m_winPtrNotNull (winInfo) && winInfo->generic.handle != (WINDOW *) NULL)
139 {
140 boxWin ((TuiGenWinInfoPtr) winInfo, NO_HILITE);
141 wrefresh (winInfo->generic.handle);
142 m_setWinHighlightOff (winInfo);
143 }
144 } /* unhighlightWin */
145
146
147 /*
148 ** highlightWin().
149 */
150 void
151 highlightWin (TuiWinInfoPtr winInfo)
152 {
153 if (m_winPtrNotNull (winInfo) &&
154 winInfo->canHighlight && winInfo->generic.handle != (WINDOW *) NULL)
155 {
156 boxWin ((TuiGenWinInfoPtr) winInfo, HILITE);
157 wrefresh (winInfo->generic.handle);
158 m_setWinHighlightOn (winInfo);
159 }
160 } /* highlightWin */
161
162
163 /*
164 ** checkAndDisplayHighlightIfNecessay
165 */
166 void
167 checkAndDisplayHighlightIfNeeded (TuiWinInfoPtr winInfo)
168 {
169 if (m_winPtrNotNull (winInfo) && winInfo->generic.type != CMD_WIN)
170 {
171 if (winInfo->isHighlighted)
172 highlightWin (winInfo);
173 else
174 unhighlightWin (winInfo);
175
176 }
177 return;
178 } /* checkAndDisplayHighlightIfNeeded */
179
180
181 /*
182 ** makeWindow().
183 */
184 void
185 makeWindow (TuiGenWinInfoPtr winInfo, int boxIt)
186 {
187 WINDOW *handle;
188
189 handle = newwin (winInfo->height,
190 winInfo->width,
191 winInfo->origin.y,
192 winInfo->origin.x);
193 winInfo->handle = handle;
194 if (handle != (WINDOW *) NULL)
195 {
196 if (boxIt == BOX_WINDOW)
197 boxWin (winInfo, NO_HILITE);
198 winInfo->isVisible = TRUE;
199 scrollok (handle, TRUE);
200 tuiRefreshWin (winInfo);
201
202 #ifndef FOR_TEST
203 if ( /*!m_WinIsAuxillary(winInfo->type) && */
204 (winInfo->type != CMD_WIN) &&
205 (winInfo->content == (OpaquePtr) NULL))
206 {
207 mvwaddstr (handle, 1, 1, winName (winInfo));
208 tuiRefreshWin (winInfo);
209 }
210 #endif /*FOR_TEST */
211 }
212
213 return;
214 } /* makeWindow */
215
216
217 /*
218 ** tuiClearWin().
219 ** Clear the window of all contents without calling wclear.
220 */
221 void
222 tuiClearWin (TuiGenWinInfoPtr winInfo)
223 {
224 if (m_genWinPtrNotNull (winInfo) && winInfo->handle != (WINDOW *) NULL)
225 {
226 int curRow, curCol;
227
228 for (curRow = 0; (curRow < winInfo->height); curRow++)
229 for (curCol = 0; (curCol < winInfo->width); curCol++)
230 mvwaddch (winInfo->handle, curRow, curCol, ' ');
231
232 tuiRefreshWin (winInfo);
233 }
234
235 return;
236 } /* tuiClearWin */
237
238
239 /*
240 ** makeVisible().
241 ** We can't really make windows visible, or invisible. So we
242 ** have to delete the entire window when making it visible,
243 ** and create it again when making it visible.
244 */
245 void
246 makeVisible (TuiGenWinInfoPtr winInfo, int visible)
247 {
248 /* Don't tear down/recreate command window */
249 if (winInfo->type == CMD_WIN)
250 return;
251
252 if (visible)
253 {
254 if (!winInfo->isVisible)
255 {
256 makeWindow (
257 winInfo,
258 (winInfo->type != CMD_WIN && !m_winIsAuxillary (winInfo->type)));
259 winInfo->isVisible = TRUE;
260 }
261 tuiRefreshWin (winInfo);
262 }
263 else if (!visible &&
264 winInfo->isVisible && winInfo->handle != (WINDOW *) NULL)
265 {
266 winInfo->isVisible = FALSE;
267 tuiClearWin (winInfo);
268 tuiDelwin (winInfo->handle);
269 winInfo->handle = (WINDOW *) NULL;
270 }
271
272 return;
273 } /* makeVisible */
274
275
276 /*
277 ** makeAllVisible().
278 ** Makes all windows invisible (except the command and locator windows)
279 */
280 void
281 makeAllVisible (int visible)
282 {
283 int i;
284
285 for (i = 0; i < MAX_MAJOR_WINDOWS; i++)
286 {
287 if (m_winPtrNotNull (winList[i]) &&
288 ((winList[i])->generic.type) != CMD_WIN)
289 {
290 if (m_winIsSourceType ((winList[i])->generic.type))
291 makeVisible ((winList[i])->detail.sourceInfo.executionInfo,
292 visible);
293 makeVisible ((TuiGenWinInfoPtr) winList[i], visible);
294 }
295 }
296
297 return;
298 } /* makeAllVisible */
299
300
301 /*
302 ** scrollWinForward
303 */
304 void
305 scrollWinForward (TuiGenWinInfoPtr winInfo, int numLines)
306 {
307 if (winInfo->content != (OpaquePtr) NULL &&
308 winInfo->lastVisibleLine < winInfo->contentSize - 1)
309 {
310 int i, firstLine, newLastLine;
311
312 firstLine = winInfo->lastVisibleLine - winInfo->viewportHeight + 1;
313 if (winInfo->lastVisibleLine + numLines > winInfo->contentSize)
314 newLastLine = winInfo->contentSize - 1;
315 else
316 newLastLine = winInfo->lastVisibleLine + numLines - 1;
317
318 for (i = (newLastLine - winInfo->viewportHeight);
319 (i <= newLastLine); i++)
320 {
321 TuiWinElementPtr line;
322 int lineHeight;
323
324 line = (TuiWinElementPtr) winInfo->content[i];
325 if (line->highlight)
326 wstandout (winInfo->handle);
327 mvwaddstr (winInfo->handle,
328 i - (newLastLine - winInfo->viewportHeight),
329 1,
330 displayableWinContentOf (winInfo, line));
331 if (line->highlight)
332 wstandend (winInfo->handle);
333 lineHeight = winElementHeight (winInfo, line);
334 newLastLine += (lineHeight - 1);
335 }
336 winInfo->lastVisibleLine = newLastLine;
337 }
338
339 return;
340 } /* scrollWinForward */
341
342
343 /*
344 ** scrollWinBackward
345 */
346 void
347 scrollWinBackward (TuiGenWinInfoPtr winInfo, int numLines)
348 {
349 if (winInfo->content != (OpaquePtr) NULL &&
350 (winInfo->lastVisibleLine - winInfo->viewportHeight) > 0)
351 {
352 int i, newLastLine, firstLine;
353
354 firstLine = winInfo->lastVisibleLine - winInfo->viewportHeight + 1;
355 if ((firstLine - numLines) < 0)
356 newLastLine = winInfo->viewportHeight - 1;
357 else
358 newLastLine = winInfo->lastVisibleLine - numLines + 1;
359
360 for (i = newLastLine - winInfo->viewportHeight; (i <= newLastLine); i++)
361 {
362 TuiWinElementPtr line;
363 int lineHeight;
364
365 line = (TuiWinElementPtr) winInfo->content[i];
366 if (line->highlight)
367 wstandout (winInfo->handle);
368 mvwaddstr (winInfo->handle,
369 i - (newLastLine - winInfo->viewportHeight),
370 1,
371 displayableWinContentOf (winInfo, line));
372 if (line->highlight)
373 wstandend (winInfo->handle);
374 lineHeight = winElementHeight (winInfo, line);
375 newLastLine += (lineHeight - 1);
376 }
377 winInfo->lastVisibleLine = newLastLine;
378 }
379
380 return;
381 } /* scrollWinBackward */
382
383
384 /*
385 ** refreshAll().
386 ** Function to refresh all the windows currently displayed
387 */
388 void
389 refreshAll (TuiWinInfoPtr * list)
390 {
391 TuiWinType type;
392 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
393
394 for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
395 {
396 if (list[type] && list[type]->generic.isVisible)
397 {
398 if (type == SRC_WIN || type == DISASSEM_WIN)
399 {
400 touchwin (list[type]->detail.sourceInfo.executionInfo->handle);
401 tuiRefreshWin (list[type]->detail.sourceInfo.executionInfo);
402 }
403 touchwin (list[type]->generic.handle);
404 tuiRefreshWin (&list[type]->generic);
405 }
406 }
407 if (locator->isVisible)
408 {
409 touchwin (locator->handle);
410 tuiRefreshWin (locator);
411 }
412
413 return;
414 } /* refreshAll */
415
416
417 /*********************************
418 ** Local Static Functions
419 *********************************/
This page took 0.037262 seconds and 4 git commands to generate.