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