1 /* General window behavior.
2 Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Hewlett-Packard Company.
5 This file is part of GDB.
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.
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.
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. */
25 #include "tuiGeneralWin.h"
29 ** local support functions
31 static void _winResize (void);
34 /***********************
36 ***********************/
42 tuiRefreshWin (TuiGenWinInfoPtr winInfo
)
44 if (winInfo
->type
== DATA_WIN
&& winInfo
->contentSize
> 0)
48 for (i
= 0; (i
< winInfo
->contentSize
); i
++)
50 TuiGenWinInfoPtr dataItemWinPtr
;
52 dataItemWinPtr
= &((TuiWinContent
)
53 winInfo
->content
)[i
]->whichElement
.dataWindow
;
54 if (m_genWinPtrNotNull (dataItemWinPtr
) &&
55 dataItemWinPtr
->handle
!= (WINDOW
*) NULL
)
56 wrefresh (dataItemWinPtr
->handle
);
59 else if (winInfo
->type
== CMD_WIN
)
65 if (winInfo
->handle
!= (WINDOW
*) NULL
)
66 wrefresh (winInfo
->handle
);
75 ** Function to delete the curses window, checking for null
78 tuiDelwin (WINDOW
* window
)
80 if (window
!= (WINDOW
*) NULL
)
87 /* Draw a border arround the window. */
89 boxWin (TuiGenWinInfoPtr winInfo
, int highlightFlag
)
91 if (winInfo
&& winInfo
->handle
)
96 win
= winInfo
->handle
;
97 if (highlightFlag
== HILITE
)
98 attrs
= tui_active_border_attrs
;
100 attrs
= tui_border_attrs
;
102 wattron (win
, attrs
);
103 wborder (win
, tui_border_vline
, tui_border_vline
,
104 tui_border_hline
, tui_border_hline
,
105 tui_border_ulcorner
, tui_border_urcorner
,
106 tui_border_llcorner
, tui_border_lrcorner
);
107 wattroff (win
, attrs
);
116 unhighlightWin (TuiWinInfoPtr winInfo
)
118 if (m_winPtrNotNull (winInfo
) && winInfo
->generic
.handle
!= (WINDOW
*) NULL
)
120 boxWin ((TuiGenWinInfoPtr
) winInfo
, NO_HILITE
);
121 wrefresh (winInfo
->generic
.handle
);
122 m_setWinHighlightOff (winInfo
);
124 } /* unhighlightWin */
131 highlightWin (TuiWinInfoPtr winInfo
)
133 if (m_winPtrNotNull (winInfo
) &&
134 winInfo
->canHighlight
&& winInfo
->generic
.handle
!= (WINDOW
*) NULL
)
136 boxWin ((TuiGenWinInfoPtr
) winInfo
, HILITE
);
137 wrefresh (winInfo
->generic
.handle
);
138 m_setWinHighlightOn (winInfo
);
144 ** checkAndDisplayHighlightIfNecessay
147 checkAndDisplayHighlightIfNeeded (TuiWinInfoPtr winInfo
)
149 if (m_winPtrNotNull (winInfo
) && winInfo
->generic
.type
!= CMD_WIN
)
151 if (winInfo
->isHighlighted
)
152 highlightWin (winInfo
);
154 unhighlightWin (winInfo
);
158 } /* checkAndDisplayHighlightIfNeeded */
165 makeWindow (TuiGenWinInfoPtr winInfo
, int boxIt
)
169 handle
= newwin (winInfo
->height
,
173 winInfo
->handle
= handle
;
174 if (handle
!= (WINDOW
*) NULL
)
176 if (boxIt
== BOX_WINDOW
)
177 boxWin (winInfo
, NO_HILITE
);
178 winInfo
->isVisible
= TRUE
;
179 scrollok (handle
, TRUE
);
180 tuiRefreshWin (winInfo
);
183 if ( /*!m_WinIsAuxillary(winInfo->type) && */
184 (winInfo
->type
!= CMD_WIN
) &&
185 (winInfo
->content
== (OpaquePtr
) NULL
))
187 mvwaddstr (handle
, 1, 1, winName (winInfo
));
188 tuiRefreshWin (winInfo
);
199 ** Clear the window of all contents without calling wclear.
202 tuiClearWin (TuiGenWinInfoPtr winInfo
)
204 if (m_genWinPtrNotNull (winInfo
) && winInfo
->handle
!= (WINDOW
*) NULL
)
208 for (curRow
= 0; (curRow
< winInfo
->height
); curRow
++)
209 for (curCol
= 0; (curCol
< winInfo
->width
); curCol
++)
210 mvwaddch (winInfo
->handle
, curRow
, curCol
, ' ');
212 tuiRefreshWin (winInfo
);
221 ** We can't really make windows visible, or invisible. So we
222 ** have to delete the entire window when making it visible,
223 ** and create it again when making it visible.
226 makeVisible (TuiGenWinInfoPtr winInfo
, int visible
)
228 /* Don't tear down/recreate command window */
229 if (winInfo
->type
== CMD_WIN
)
234 if (!winInfo
->isVisible
)
238 (winInfo
->type
!= CMD_WIN
&& !m_winIsAuxillary (winInfo
->type
)));
239 winInfo
->isVisible
= TRUE
;
241 tuiRefreshWin (winInfo
);
244 winInfo
->isVisible
&& winInfo
->handle
!= (WINDOW
*) NULL
)
246 winInfo
->isVisible
= FALSE
;
247 tuiClearWin (winInfo
);
248 tuiDelwin (winInfo
->handle
);
249 winInfo
->handle
= (WINDOW
*) NULL
;
258 ** Makes all windows invisible (except the command and locator windows)
261 makeAllVisible (int visible
)
265 for (i
= 0; i
< MAX_MAJOR_WINDOWS
; i
++)
267 if (m_winPtrNotNull (winList
[i
]) &&
268 ((winList
[i
])->generic
.type
) != CMD_WIN
)
270 if (m_winIsSourceType ((winList
[i
])->generic
.type
))
271 makeVisible ((winList
[i
])->detail
.sourceInfo
.executionInfo
,
273 makeVisible ((TuiGenWinInfoPtr
) winList
[i
], visible
);
278 } /* makeAllVisible */
285 scrollWinForward (TuiGenWinInfoPtr winInfo
, int numLines
)
287 if (winInfo
->content
!= (OpaquePtr
) NULL
&&
288 winInfo
->lastVisibleLine
< winInfo
->contentSize
- 1)
290 int i
, firstLine
, newLastLine
;
292 firstLine
= winInfo
->lastVisibleLine
- winInfo
->viewportHeight
+ 1;
293 if (winInfo
->lastVisibleLine
+ numLines
> winInfo
->contentSize
)
294 newLastLine
= winInfo
->contentSize
- 1;
296 newLastLine
= winInfo
->lastVisibleLine
+ numLines
- 1;
298 for (i
= (newLastLine
- winInfo
->viewportHeight
);
299 (i
<= newLastLine
); i
++)
301 TuiWinElementPtr line
;
304 line
= (TuiWinElementPtr
) winInfo
->content
[i
];
306 wstandout (winInfo
->handle
);
307 mvwaddstr (winInfo
->handle
,
308 i
- (newLastLine
- winInfo
->viewportHeight
),
310 displayableWinContentOf (winInfo
, line
));
312 wstandend (winInfo
->handle
);
313 lineHeight
= winElementHeight (winInfo
, line
);
314 newLastLine
+= (lineHeight
- 1);
316 winInfo
->lastVisibleLine
= newLastLine
;
320 } /* scrollWinForward */
327 scrollWinBackward (TuiGenWinInfoPtr winInfo
, int numLines
)
329 if (winInfo
->content
!= (OpaquePtr
) NULL
&&
330 (winInfo
->lastVisibleLine
- winInfo
->viewportHeight
) > 0)
332 int i
, newLastLine
, firstLine
;
334 firstLine
= winInfo
->lastVisibleLine
- winInfo
->viewportHeight
+ 1;
335 if ((firstLine
- numLines
) < 0)
336 newLastLine
= winInfo
->viewportHeight
- 1;
338 newLastLine
= winInfo
->lastVisibleLine
- numLines
+ 1;
340 for (i
= newLastLine
- winInfo
->viewportHeight
; (i
<= newLastLine
); i
++)
342 TuiWinElementPtr line
;
345 line
= (TuiWinElementPtr
) winInfo
->content
[i
];
347 wstandout (winInfo
->handle
);
348 mvwaddstr (winInfo
->handle
,
349 i
- (newLastLine
- winInfo
->viewportHeight
),
351 displayableWinContentOf (winInfo
, line
));
353 wstandend (winInfo
->handle
);
354 lineHeight
= winElementHeight (winInfo
, line
);
355 newLastLine
+= (lineHeight
- 1);
357 winInfo
->lastVisibleLine
= newLastLine
;
361 } /* scrollWinBackward */
366 ** Function to refresh all the windows currently displayed
369 refreshAll (TuiWinInfoPtr
* list
)
372 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
374 for (type
= SRC_WIN
; (type
< MAX_MAJOR_WINDOWS
); type
++)
376 if (list
[type
] && list
[type
]->generic
.isVisible
)
378 if (type
== SRC_WIN
|| type
== DISASSEM_WIN
)
380 touchwin (list
[type
]->detail
.sourceInfo
.executionInfo
->handle
);
381 tuiRefreshWin (list
[type
]->detail
.sourceInfo
.executionInfo
);
383 touchwin (list
[type
]->generic
.handle
);
384 tuiRefreshWin (&list
[type
]->generic
);
387 if (locator
->isVisible
)
389 touchwin (locator
->handle
);
390 tuiRefreshWin (locator
);
397 /*********************************
398 ** Local Static Functions
399 *********************************/