Whoops, forgot to commit this yesterday:
[deliverable/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 #include "tuiWin.h"
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 /* Draw a border arround the window. */
88 void
89 boxWin (TuiGenWinInfoPtr winInfo, int highlightFlag)
90 {
91 if (winInfo && winInfo->handle)
92 {
93 WINDOW *win;
94 int attrs;
95
96 win = winInfo->handle;
97 if (highlightFlag == HILITE)
98 attrs = tui_active_border_attrs;
99 else
100 attrs = tui_border_attrs;
101
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);
108 }
109 }
110
111
112 /*
113 ** unhighlightWin().
114 */
115 void
116 unhighlightWin (TuiWinInfoPtr winInfo)
117 {
118 if (m_winPtrNotNull (winInfo) && winInfo->generic.handle != (WINDOW *) NULL)
119 {
120 boxWin ((TuiGenWinInfoPtr) winInfo, NO_HILITE);
121 wrefresh (winInfo->generic.handle);
122 m_setWinHighlightOff (winInfo);
123 }
124 } /* unhighlightWin */
125
126
127 /*
128 ** highlightWin().
129 */
130 void
131 highlightWin (TuiWinInfoPtr winInfo)
132 {
133 if (m_winPtrNotNull (winInfo) &&
134 winInfo->canHighlight && winInfo->generic.handle != (WINDOW *) NULL)
135 {
136 boxWin ((TuiGenWinInfoPtr) winInfo, HILITE);
137 wrefresh (winInfo->generic.handle);
138 m_setWinHighlightOn (winInfo);
139 }
140 } /* highlightWin */
141
142
143 /*
144 ** checkAndDisplayHighlightIfNecessay
145 */
146 void
147 checkAndDisplayHighlightIfNeeded (TuiWinInfoPtr winInfo)
148 {
149 if (m_winPtrNotNull (winInfo) && winInfo->generic.type != CMD_WIN)
150 {
151 if (winInfo->isHighlighted)
152 highlightWin (winInfo);
153 else
154 unhighlightWin (winInfo);
155
156 }
157 return;
158 } /* checkAndDisplayHighlightIfNeeded */
159
160
161 /*
162 ** makeWindow().
163 */
164 void
165 makeWindow (TuiGenWinInfoPtr winInfo, int boxIt)
166 {
167 WINDOW *handle;
168
169 handle = newwin (winInfo->height,
170 winInfo->width,
171 winInfo->origin.y,
172 winInfo->origin.x);
173 winInfo->handle = handle;
174 if (handle != (WINDOW *) NULL)
175 {
176 if (boxIt == BOX_WINDOW)
177 boxWin (winInfo, NO_HILITE);
178 winInfo->isVisible = TRUE;
179 scrollok (handle, TRUE);
180 tuiRefreshWin (winInfo);
181
182 #ifndef FOR_TEST
183 if ( /*!m_WinIsAuxillary(winInfo->type) && */
184 (winInfo->type != CMD_WIN) &&
185 (winInfo->content == (OpaquePtr) NULL))
186 {
187 mvwaddstr (handle, 1, 1, winName (winInfo));
188 tuiRefreshWin (winInfo);
189 }
190 #endif /*FOR_TEST */
191 }
192
193 return;
194 } /* makeWindow */
195
196
197 /*
198 ** tuiClearWin().
199 ** Clear the window of all contents without calling wclear.
200 */
201 void
202 tuiClearWin (TuiGenWinInfoPtr winInfo)
203 {
204 if (m_genWinPtrNotNull (winInfo) && winInfo->handle != (WINDOW *) NULL)
205 {
206 int curRow, curCol;
207
208 for (curRow = 0; (curRow < winInfo->height); curRow++)
209 for (curCol = 0; (curCol < winInfo->width); curCol++)
210 mvwaddch (winInfo->handle, curRow, curCol, ' ');
211
212 tuiRefreshWin (winInfo);
213 }
214
215 return;
216 } /* tuiClearWin */
217
218
219 /*
220 ** makeVisible().
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.
224 */
225 void
226 makeVisible (TuiGenWinInfoPtr winInfo, int visible)
227 {
228 /* Don't tear down/recreate command window */
229 if (winInfo->type == CMD_WIN)
230 return;
231
232 if (visible)
233 {
234 if (!winInfo->isVisible)
235 {
236 makeWindow (
237 winInfo,
238 (winInfo->type != CMD_WIN && !m_winIsAuxillary (winInfo->type)));
239 winInfo->isVisible = TRUE;
240 }
241 tuiRefreshWin (winInfo);
242 }
243 else if (!visible &&
244 winInfo->isVisible && winInfo->handle != (WINDOW *) NULL)
245 {
246 winInfo->isVisible = FALSE;
247 tuiClearWin (winInfo);
248 tuiDelwin (winInfo->handle);
249 winInfo->handle = (WINDOW *) NULL;
250 }
251
252 return;
253 } /* makeVisible */
254
255
256 /*
257 ** makeAllVisible().
258 ** Makes all windows invisible (except the command and locator windows)
259 */
260 void
261 makeAllVisible (int visible)
262 {
263 int i;
264
265 for (i = 0; i < MAX_MAJOR_WINDOWS; i++)
266 {
267 if (m_winPtrNotNull (winList[i]) &&
268 ((winList[i])->generic.type) != CMD_WIN)
269 {
270 if (m_winIsSourceType ((winList[i])->generic.type))
271 makeVisible ((winList[i])->detail.sourceInfo.executionInfo,
272 visible);
273 makeVisible ((TuiGenWinInfoPtr) winList[i], visible);
274 }
275 }
276
277 return;
278 } /* makeAllVisible */
279
280
281 /*
282 ** scrollWinForward
283 */
284 void
285 scrollWinForward (TuiGenWinInfoPtr winInfo, int numLines)
286 {
287 if (winInfo->content != (OpaquePtr) NULL &&
288 winInfo->lastVisibleLine < winInfo->contentSize - 1)
289 {
290 int i, firstLine, newLastLine;
291
292 firstLine = winInfo->lastVisibleLine - winInfo->viewportHeight + 1;
293 if (winInfo->lastVisibleLine + numLines > winInfo->contentSize)
294 newLastLine = winInfo->contentSize - 1;
295 else
296 newLastLine = winInfo->lastVisibleLine + numLines - 1;
297
298 for (i = (newLastLine - winInfo->viewportHeight);
299 (i <= newLastLine); i++)
300 {
301 TuiWinElementPtr line;
302 int lineHeight;
303
304 line = (TuiWinElementPtr) winInfo->content[i];
305 if (line->highlight)
306 wstandout (winInfo->handle);
307 mvwaddstr (winInfo->handle,
308 i - (newLastLine - winInfo->viewportHeight),
309 1,
310 displayableWinContentOf (winInfo, line));
311 if (line->highlight)
312 wstandend (winInfo->handle);
313 lineHeight = winElementHeight (winInfo, line);
314 newLastLine += (lineHeight - 1);
315 }
316 winInfo->lastVisibleLine = newLastLine;
317 }
318
319 return;
320 } /* scrollWinForward */
321
322
323 /*
324 ** scrollWinBackward
325 */
326 void
327 scrollWinBackward (TuiGenWinInfoPtr winInfo, int numLines)
328 {
329 if (winInfo->content != (OpaquePtr) NULL &&
330 (winInfo->lastVisibleLine - winInfo->viewportHeight) > 0)
331 {
332 int i, newLastLine, firstLine;
333
334 firstLine = winInfo->lastVisibleLine - winInfo->viewportHeight + 1;
335 if ((firstLine - numLines) < 0)
336 newLastLine = winInfo->viewportHeight - 1;
337 else
338 newLastLine = winInfo->lastVisibleLine - numLines + 1;
339
340 for (i = newLastLine - winInfo->viewportHeight; (i <= newLastLine); i++)
341 {
342 TuiWinElementPtr line;
343 int lineHeight;
344
345 line = (TuiWinElementPtr) winInfo->content[i];
346 if (line->highlight)
347 wstandout (winInfo->handle);
348 mvwaddstr (winInfo->handle,
349 i - (newLastLine - winInfo->viewportHeight),
350 1,
351 displayableWinContentOf (winInfo, line));
352 if (line->highlight)
353 wstandend (winInfo->handle);
354 lineHeight = winElementHeight (winInfo, line);
355 newLastLine += (lineHeight - 1);
356 }
357 winInfo->lastVisibleLine = newLastLine;
358 }
359
360 return;
361 } /* scrollWinBackward */
362
363
364 /*
365 ** refreshAll().
366 ** Function to refresh all the windows currently displayed
367 */
368 void
369 refreshAll (TuiWinInfoPtr * list)
370 {
371 TuiWinType type;
372 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
373
374 for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
375 {
376 if (list[type] && list[type]->generic.isVisible)
377 {
378 if (type == SRC_WIN || type == DISASSEM_WIN)
379 {
380 touchwin (list[type]->detail.sourceInfo.executionInfo->handle);
381 tuiRefreshWin (list[type]->detail.sourceInfo.executionInfo);
382 }
383 touchwin (list[type]->generic.handle);
384 tuiRefreshWin (&list[type]->generic);
385 }
386 }
387 if (locator->isVisible)
388 {
389 touchwin (locator->handle);
390 tuiRefreshWin (locator);
391 }
392
393 return;
394 } /* refreshAll */
395
396
397 /*********************************
398 ** Local Static Functions
399 *********************************/
This page took 0.036958 seconds and 4 git commands to generate.