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