Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* General window behavior. |
f33c6cbf AC |
2 | |
3 | Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, | |
4 | Inc. | |
5 | ||
f377b406 SC |
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. */ | |
c906108c | 24 | |
f33c6cbf AC |
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 | ||
4e8f7a8b DJ |
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 | ||
c906108c SS |
42 | #include "defs.h" |
43 | #include "tui.h" | |
44 | #include "tuiData.h" | |
45 | #include "tuiGeneralWin.h" | |
af101512 | 46 | #include "tuiWin.h" |
c906108c SS |
47 | |
48 | /* | |
c5aa993b JM |
49 | ** local support functions |
50 | */ | |
a14ed312 | 51 | static void _winResize (void); |
c906108c SS |
52 | |
53 | ||
54 | /*********************** | |
55 | ** PUBLIC FUNCTIONS | |
56 | ***********************/ | |
57 | /* | |
c5aa993b JM |
58 | ** tuiRefreshWin() |
59 | ** Refresh the window | |
60 | */ | |
c906108c | 61 | void |
eca6576c | 62 | tuiRefreshWin (TuiGenWinInfoPtr winInfo) |
c906108c SS |
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 | /* | |
c5aa993b JM |
94 | ** tuiDelwin() |
95 | ** Function to delete the curses window, checking for null | |
96 | */ | |
c906108c | 97 | void |
eca6576c | 98 | tuiDelwin (WINDOW * window) |
c906108c SS |
99 | { |
100 | if (window != (WINDOW *) NULL) | |
101 | delwin (window); | |
102 | ||
103 | return; | |
104 | } /* tuiDelwin */ | |
105 | ||
106 | ||
af101512 | 107 | /* Draw a border arround the window. */ |
c906108c | 108 | void |
eca6576c | 109 | boxWin (TuiGenWinInfoPtr winInfo, int highlightFlag) |
c906108c | 110 | { |
af101512 | 111 | if (winInfo && winInfo->handle) |
c906108c | 112 | { |
af101512 SC |
113 | WINDOW *win; |
114 | int attrs; | |
115 | ||
116 | win = winInfo->handle; | |
c906108c | 117 | if (highlightFlag == HILITE) |
af101512 | 118 | attrs = tui_active_border_attrs; |
c906108c | 119 | else |
af101512 SC |
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); | |
c906108c | 128 | } |
af101512 | 129 | } |
c906108c SS |
130 | |
131 | ||
132 | /* | |
c5aa993b JM |
133 | ** unhighlightWin(). |
134 | */ | |
c906108c | 135 | void |
eca6576c | 136 | unhighlightWin (TuiWinInfoPtr winInfo) |
c906108c SS |
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 | /* | |
c5aa993b JM |
148 | ** highlightWin(). |
149 | */ | |
c906108c | 150 | void |
eca6576c | 151 | highlightWin (TuiWinInfoPtr winInfo) |
c906108c SS |
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 | /* | |
c5aa993b JM |
164 | ** checkAndDisplayHighlightIfNecessay |
165 | */ | |
c906108c | 166 | void |
eca6576c | 167 | checkAndDisplayHighlightIfNeeded (TuiWinInfoPtr winInfo) |
c906108c SS |
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 | /* | |
c5aa993b JM |
182 | ** makeWindow(). |
183 | */ | |
c906108c | 184 | void |
eca6576c | 185 | makeWindow (TuiGenWinInfoPtr winInfo, int boxIt) |
c906108c SS |
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 | } | |
c5aa993b | 210 | #endif /*FOR_TEST */ |
c906108c SS |
211 | } |
212 | ||
213 | return; | |
214 | } /* makeWindow */ | |
215 | ||
216 | ||
217 | /* | |
c5aa993b JM |
218 | ** tuiClearWin(). |
219 | ** Clear the window of all contents without calling wclear. | |
220 | */ | |
c906108c | 221 | void |
eca6576c | 222 | tuiClearWin (TuiGenWinInfoPtr winInfo) |
c906108c SS |
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 | /* | |
c5aa993b JM |
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 | */ | |
c906108c | 245 | void |
eca6576c | 246 | makeVisible (TuiGenWinInfoPtr winInfo, int visible) |
c906108c SS |
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 | /* | |
c5aa993b JM |
277 | ** makeAllVisible(). |
278 | ** Makes all windows invisible (except the command and locator windows) | |
279 | */ | |
c906108c | 280 | void |
eca6576c | 281 | makeAllVisible (int visible) |
c906108c SS |
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 | /* | |
c5aa993b JM |
302 | ** scrollWinForward |
303 | */ | |
c906108c | 304 | void |
eca6576c | 305 | scrollWinForward (TuiGenWinInfoPtr winInfo, int numLines) |
c906108c SS |
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 | /* | |
c5aa993b JM |
344 | ** scrollWinBackward |
345 | */ | |
c906108c | 346 | void |
eca6576c | 347 | scrollWinBackward (TuiGenWinInfoPtr winInfo, int numLines) |
c906108c SS |
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 | /* | |
c5aa993b JM |
385 | ** refreshAll(). |
386 | ** Function to refresh all the windows currently displayed | |
387 | */ | |
c906108c | 388 | void |
eca6576c | 389 | refreshAll (TuiWinInfoPtr * list) |
c906108c SS |
390 | { |
391 | TuiWinType type; | |
392 | TuiGenWinInfoPtr locator = locatorWinInfoPtr (); | |
393 | ||
394 | for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++) | |
395 | { | |
75fd9bc1 | 396 | if (list[type] && list[type]->generic.isVisible) |
c906108c SS |
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 | *********************************/ |