* tuiWin.c, tui.c, tuiCommand.c: Use ansi prototype.
[binutils-gdb.git] / gdb / tui / tuiGeneralWin.c
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. */
21
22 #include "defs.h"
23 #include "tui.h"
24 #include "tuiData.h"
25 #include "tuiGeneralWin.h"
26
27
28 /*
29 ** local support functions
30 */
31 static void _winResize (void);
32
33
34 /***********************
35 ** PUBLIC FUNCTIONS
36 ***********************/
37 /*
38 ** tuiRefreshWin()
39 ** Refresh the window
40 */
41 void
42 tuiRefreshWin (TuiGenWinInfoPtr winInfo)
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 /*
74 ** tuiDelwin()
75 ** Function to delete the curses window, checking for null
76 */
77 void
78 tuiDelwin (WINDOW * window)
79 {
80 if (window != (WINDOW *) NULL)
81 delwin (window);
82
83 return;
84 } /* tuiDelwin */
85
86
87 /*
88 ** boxWin().
89 */
90 void
91 boxWin (TuiGenWinInfoPtr winInfo, int highlightFlag)
92 {
93 if (m_genWinPtrNotNull (winInfo) && winInfo->handle != (WINDOW *) NULL)
94 {
95 if (highlightFlag == HILITE)
96 box (winInfo->handle, '|', '-');
97 else
98 {
99 /* wattron(winInfo->handle, A_DIM); */
100 box (winInfo->handle, ':', '.');
101 /* wattroff(winInfo->handle, A_DIM); */
102 }
103 }
104
105 return;
106 } /* boxWin */
107
108
109 /*
110 ** unhighlightWin().
111 */
112 void
113 unhighlightWin (TuiWinInfoPtr winInfo)
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 /*
125 ** highlightWin().
126 */
127 void
128 highlightWin (TuiWinInfoPtr winInfo)
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 /*
141 ** checkAndDisplayHighlightIfNecessay
142 */
143 void
144 checkAndDisplayHighlightIfNeeded (TuiWinInfoPtr winInfo)
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 /*
159 ** makeWindow().
160 */
161 void
162 makeWindow (TuiGenWinInfoPtr winInfo, int boxIt)
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 }
187 #endif /*FOR_TEST */
188 }
189
190 return;
191 } /* makeWindow */
192
193
194 /*
195 ** tuiClearWin().
196 ** Clear the window of all contents without calling wclear.
197 */
198 void
199 tuiClearWin (TuiGenWinInfoPtr winInfo)
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 /*
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 */
222 void
223 makeVisible (TuiGenWinInfoPtr winInfo, int visible)
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 /*
254 ** makeAllVisible().
255 ** Makes all windows invisible (except the command and locator windows)
256 */
257 void
258 makeAllVisible (int visible)
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 /*
279 ** scrollWinForward
280 */
281 void
282 scrollWinForward (TuiGenWinInfoPtr winInfo, int numLines)
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 /*
321 ** scrollWinBackward
322 */
323 void
324 scrollWinBackward (TuiGenWinInfoPtr winInfo, int numLines)
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 /*
362 ** refreshAll().
363 ** Function to refresh all the windows currently displayed
364 */
365 void
366 refreshAll (TuiWinInfoPtr * list)
367 {
368 TuiWinType type;
369 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
370
371 for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
372 {
373 if (list[type]->generic.isVisible)
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 *********************************/