1 /* General window behavior.
3 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation,
6 Contributed by Hewlett-Packard Company.
8 This file is part of GDB.
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.
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.
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. */
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>
45 #include "tuiGeneralWin.h"
49 ** local support functions
51 static void _winResize (void);
54 /***********************
56 ***********************/
62 tuiRefreshWin (TuiGenWinInfoPtr winInfo
)
64 if (winInfo
->type
== DATA_WIN
&& winInfo
->contentSize
> 0)
68 for (i
= 0; (i
< winInfo
->contentSize
); i
++)
70 TuiGenWinInfoPtr dataItemWinPtr
;
72 dataItemWinPtr
= &((TuiWinContent
)
73 winInfo
->content
)[i
]->whichElement
.dataWindow
;
74 if (m_genWinPtrNotNull (dataItemWinPtr
) &&
75 dataItemWinPtr
->handle
!= (WINDOW
*) NULL
)
76 wrefresh (dataItemWinPtr
->handle
);
79 else if (winInfo
->type
== CMD_WIN
)
85 if (winInfo
->handle
!= (WINDOW
*) NULL
)
86 wrefresh (winInfo
->handle
);
95 ** Function to delete the curses window, checking for null
98 tuiDelwin (WINDOW
* window
)
100 if (window
!= (WINDOW
*) NULL
)
107 /* Draw a border arround the window. */
109 boxWin (TuiGenWinInfoPtr winInfo
, int highlightFlag
)
111 if (winInfo
&& winInfo
->handle
)
116 win
= winInfo
->handle
;
117 if (highlightFlag
== HILITE
)
118 attrs
= tui_active_border_attrs
;
120 attrs
= tui_border_attrs
;
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
);
136 unhighlightWin (TuiWinInfoPtr winInfo
)
138 if (m_winPtrNotNull (winInfo
) && winInfo
->generic
.handle
!= (WINDOW
*) NULL
)
140 boxWin ((TuiGenWinInfoPtr
) winInfo
, NO_HILITE
);
141 wrefresh (winInfo
->generic
.handle
);
142 m_setWinHighlightOff (winInfo
);
144 } /* unhighlightWin */
151 highlightWin (TuiWinInfoPtr winInfo
)
153 if (m_winPtrNotNull (winInfo
) &&
154 winInfo
->canHighlight
&& winInfo
->generic
.handle
!= (WINDOW
*) NULL
)
156 boxWin ((TuiGenWinInfoPtr
) winInfo
, HILITE
);
157 wrefresh (winInfo
->generic
.handle
);
158 m_setWinHighlightOn (winInfo
);
164 ** checkAndDisplayHighlightIfNecessay
167 checkAndDisplayHighlightIfNeeded (TuiWinInfoPtr winInfo
)
169 if (m_winPtrNotNull (winInfo
) && winInfo
->generic
.type
!= CMD_WIN
)
171 if (winInfo
->isHighlighted
)
172 highlightWin (winInfo
);
174 unhighlightWin (winInfo
);
178 } /* checkAndDisplayHighlightIfNeeded */
185 makeWindow (TuiGenWinInfoPtr winInfo
, int boxIt
)
189 handle
= newwin (winInfo
->height
,
193 winInfo
->handle
= handle
;
194 if (handle
!= (WINDOW
*) NULL
)
196 if (boxIt
== BOX_WINDOW
)
197 boxWin (winInfo
, NO_HILITE
);
198 winInfo
->isVisible
= TRUE
;
199 scrollok (handle
, TRUE
);
200 tuiRefreshWin (winInfo
);
203 if ( /*!m_WinIsAuxillary(winInfo->type) && */
204 (winInfo
->type
!= CMD_WIN
) &&
205 (winInfo
->content
== (OpaquePtr
) NULL
))
207 mvwaddstr (handle
, 1, 1, winName (winInfo
));
208 tuiRefreshWin (winInfo
);
219 ** Clear the window of all contents without calling wclear.
222 tuiClearWin (TuiGenWinInfoPtr winInfo
)
224 if (m_genWinPtrNotNull (winInfo
) && winInfo
->handle
!= (WINDOW
*) NULL
)
228 for (curRow
= 0; (curRow
< winInfo
->height
); curRow
++)
229 for (curCol
= 0; (curCol
< winInfo
->width
); curCol
++)
230 mvwaddch (winInfo
->handle
, curRow
, curCol
, ' ');
232 tuiRefreshWin (winInfo
);
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.
246 makeVisible (TuiGenWinInfoPtr winInfo
, int visible
)
248 /* Don't tear down/recreate command window */
249 if (winInfo
->type
== CMD_WIN
)
254 if (!winInfo
->isVisible
)
258 (winInfo
->type
!= CMD_WIN
&& !m_winIsAuxillary (winInfo
->type
)));
259 winInfo
->isVisible
= TRUE
;
261 tuiRefreshWin (winInfo
);
264 winInfo
->isVisible
&& winInfo
->handle
!= (WINDOW
*) NULL
)
266 winInfo
->isVisible
= FALSE
;
267 tuiClearWin (winInfo
);
268 tuiDelwin (winInfo
->handle
);
269 winInfo
->handle
= (WINDOW
*) NULL
;
278 ** Makes all windows invisible (except the command and locator windows)
281 makeAllVisible (int visible
)
285 for (i
= 0; i
< MAX_MAJOR_WINDOWS
; i
++)
287 if (m_winPtrNotNull (winList
[i
]) &&
288 ((winList
[i
])->generic
.type
) != CMD_WIN
)
290 if (m_winIsSourceType ((winList
[i
])->generic
.type
))
291 makeVisible ((winList
[i
])->detail
.sourceInfo
.executionInfo
,
293 makeVisible ((TuiGenWinInfoPtr
) winList
[i
], visible
);
298 } /* makeAllVisible */
305 scrollWinForward (TuiGenWinInfoPtr winInfo
, int numLines
)
307 if (winInfo
->content
!= (OpaquePtr
) NULL
&&
308 winInfo
->lastVisibleLine
< winInfo
->contentSize
- 1)
310 int i
, firstLine
, newLastLine
;
312 firstLine
= winInfo
->lastVisibleLine
- winInfo
->viewportHeight
+ 1;
313 if (winInfo
->lastVisibleLine
+ numLines
> winInfo
->contentSize
)
314 newLastLine
= winInfo
->contentSize
- 1;
316 newLastLine
= winInfo
->lastVisibleLine
+ numLines
- 1;
318 for (i
= (newLastLine
- winInfo
->viewportHeight
);
319 (i
<= newLastLine
); i
++)
321 TuiWinElementPtr line
;
324 line
= (TuiWinElementPtr
) winInfo
->content
[i
];
326 wstandout (winInfo
->handle
);
327 mvwaddstr (winInfo
->handle
,
328 i
- (newLastLine
- winInfo
->viewportHeight
),
330 displayableWinContentOf (winInfo
, line
));
332 wstandend (winInfo
->handle
);
333 lineHeight
= winElementHeight (winInfo
, line
);
334 newLastLine
+= (lineHeight
- 1);
336 winInfo
->lastVisibleLine
= newLastLine
;
340 } /* scrollWinForward */
347 scrollWinBackward (TuiGenWinInfoPtr winInfo
, int numLines
)
349 if (winInfo
->content
!= (OpaquePtr
) NULL
&&
350 (winInfo
->lastVisibleLine
- winInfo
->viewportHeight
) > 0)
352 int i
, newLastLine
, firstLine
;
354 firstLine
= winInfo
->lastVisibleLine
- winInfo
->viewportHeight
+ 1;
355 if ((firstLine
- numLines
) < 0)
356 newLastLine
= winInfo
->viewportHeight
- 1;
358 newLastLine
= winInfo
->lastVisibleLine
- numLines
+ 1;
360 for (i
= newLastLine
- winInfo
->viewportHeight
; (i
<= newLastLine
); i
++)
362 TuiWinElementPtr line
;
365 line
= (TuiWinElementPtr
) winInfo
->content
[i
];
367 wstandout (winInfo
->handle
);
368 mvwaddstr (winInfo
->handle
,
369 i
- (newLastLine
- winInfo
->viewportHeight
),
371 displayableWinContentOf (winInfo
, line
));
373 wstandend (winInfo
->handle
);
374 lineHeight
= winElementHeight (winInfo
, line
);
375 newLastLine
+= (lineHeight
- 1);
377 winInfo
->lastVisibleLine
= newLastLine
;
381 } /* scrollWinBackward */
386 ** Function to refresh all the windows currently displayed
389 refreshAll (TuiWinInfoPtr
* list
)
392 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
394 for (type
= SRC_WIN
; (type
< MAX_MAJOR_WINDOWS
); type
++)
396 if (list
[type
] && list
[type
]->generic
.isVisible
)
398 if (type
== SRC_WIN
|| type
== DISASSEM_WIN
)
400 touchwin (list
[type
]->detail
.sourceInfo
.executionInfo
->handle
);
401 tuiRefreshWin (list
[type
]->detail
.sourceInfo
.executionInfo
);
403 touchwin (list
[type
]->generic
.handle
);
404 tuiRefreshWin (&list
[type
]->generic
);
407 if (locator
->isVisible
)
409 touchwin (locator
->handle
);
410 tuiRefreshWin (locator
);
417 /*********************************
418 ** Local Static Functions
419 *********************************/