aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui/tuiGeneralWin.c
blob: 061ecc1564fe20c0211aaea9f3b4b7da9fc59de0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
/*
   ** TuiGeneralWin.c
   ** This module supports general window behavior
 */

#include "defs.h"
#include "tui.h"
#include "tuiData.h"
#include "tuiGeneralWin.h"


/*
   ** local support functions
 */
static void _winResize (void);


/***********************
** PUBLIC FUNCTIONS
***********************/
/*
   ** tuiRefreshWin()
   **        Refresh the window
 */
void
#ifdef __STDC__
tuiRefreshWin (
		TuiGenWinInfoPtr winInfo)
#else
tuiRefreshWin (winInfo)
     TuiGenWinInfoPtr winInfo;
#endif
{
  if (winInfo->type == DATA_WIN && winInfo->contentSize > 0)
    {
      int i;

      for (i = 0; (i < winInfo->contentSize); i++)
	{
	  TuiGenWinInfoPtr dataItemWinPtr;

	  dataItemWinPtr = &((TuiWinContent)
			     winInfo->content)[i]->whichElement.dataWindow;
	  if (m_genWinPtrNotNull (dataItemWinPtr) &&
	      dataItemWinPtr->handle != (WINDOW *) NULL)
	    wrefresh (dataItemWinPtr->handle);
	}
    }
  else if (winInfo->type == CMD_WIN)
    {
      /* Do nothing */
    }
  else
    {
      if (winInfo->handle != (WINDOW *) NULL)
	wrefresh (winInfo->handle);
    }

  return;
}				/* tuiRefreshWin */


/*
   ** tuiDelwin()
   **        Function to delete the curses window, checking for null
 */
void
#ifdef __STDC__
tuiDelwin (
	    WINDOW * window)
#else
tuiDelwin (window)
     WINDOW *window;
#endif
{
  if (window != (WINDOW *) NULL)
    delwin (window);

  return;
}				/* tuiDelwin */


/*
   ** boxWin().
 */
void
#ifdef __STDC__
boxWin (
	 TuiGenWinInfoPtr winInfo,
	 int highlightFlag)
#else
boxWin (winInfo, highlightFlag)
     TuiGenWinInfoPtr winInfo;
     int highlightFlag;
#endif
{
  if (m_genWinPtrNotNull (winInfo) && winInfo->handle != (WINDOW *) NULL)
    {
      if (highlightFlag == HILITE)
	box (winInfo->handle, '|', '-');
      else
	{
/*            wattron(winInfo->handle, A_DIM); */
	  box (winInfo->handle, ':', '.');
/*            wattroff(winInfo->handle, A_DIM); */
	}
    }

  return;
}				/* boxWin */


/*
   ** unhighlightWin().
 */
void
#ifdef __STDC__
unhighlightWin (
		 TuiWinInfoPtr winInfo)
#else
unhighlightWin (winInfo)
     TuiWinInfoPtr winInfo;
#endif
{
  if (m_winPtrNotNull (winInfo) && winInfo->generic.handle != (WINDOW *) NULL)
    {
      boxWin ((TuiGenWinInfoPtr) winInfo, NO_HILITE);
      wrefresh (winInfo->generic.handle);
      m_setWinHighlightOff (winInfo);
    }
}				/* unhighlightWin */


/*
   ** highlightWin().
 */
void
#ifdef __STDC__
highlightWin (
	       TuiWinInfoPtr winInfo)
#else
highlightWin (winInfo)
     TuiWinInfoPtr winInfo;
#endif
{
  if (m_winPtrNotNull (winInfo) &&
      winInfo->canHighlight && winInfo->generic.handle != (WINDOW *) NULL)
    {
      boxWin ((TuiGenWinInfoPtr) winInfo, HILITE);
      wrefresh (winInfo->generic.handle);
      m_setWinHighlightOn (winInfo);
    }
}				/* highlightWin */


/*
   ** checkAndDisplayHighlightIfNecessay
 */
void
#ifdef __STDC__
checkAndDisplayHighlightIfNeeded (
				   TuiWinInfoPtr winInfo)
#else
checkAndDisplayHighlightIfNeeded (winInfo)
     TuiWinInfoPtr winInfo;
#endif
{
  if (m_winPtrNotNull (winInfo) && winInfo->generic.type != CMD_WIN)
    {
      if (winInfo->isHighlighted)
	highlightWin (winInfo);
      else
	unhighlightWin (winInfo);

    }
  return;
}				/* checkAndDisplayHighlightIfNeeded */


/*
   ** makeWindow().
 */
void
#ifdef __STDC__
makeWindow (
	     TuiGenWinInfoPtr winInfo,
	     int boxIt)
#else
makeWindow (winInfo, boxIt)
     TuiGenWinInfoPtr winInfo;
     int boxIt;
#endif
{
  WINDOW *handle;

  handle = newwin (winInfo->height,
		   winInfo->width,
		   winInfo->origin.y,
		   winInfo->origin.x);
  winInfo->handle = handle;
  if (handle != (WINDOW *) NULL)
    {
      if (boxIt == BOX_WINDOW)
	boxWin (winInfo, NO_HILITE);
      winInfo->isVisible = TRUE;
      scrollok (handle, TRUE);
      tuiRefreshWin (winInfo);

#ifndef FOR_TEST
      if (			/*!m_WinIsAuxillary(winInfo->type) && */
	   (winInfo->type != CMD_WIN) &&
	   (winInfo->content == (OpaquePtr) NULL))
	{
	  mvwaddstr (handle, 1, 1, winName (winInfo));
	  tuiRefreshWin (winInfo);
	}
#endif /*FOR_TEST */
    }

  return;
}				/* makeWindow */


/*
   ** tuiClearWin().
   **        Clear the window of all contents without calling wclear.
 */
void
#ifdef __STDC__
tuiClearWin (
	      TuiGenWinInfoPtr winInfo)
#else
tuiClearWin (winInfo)
     TuiGenWinInfoPtr winInfo;
#endif
{
  if (m_genWinPtrNotNull (winInfo) && winInfo->handle != (WINDOW *) NULL)
    {
      int curRow, curCol;

      for (curRow = 0; (curRow < winInfo->height); curRow++)
	for (curCol = 0; (curCol < winInfo->width); curCol++)
	  mvwaddch (winInfo->handle, curRow, curCol, ' ');

      tuiRefreshWin (winInfo);
    }

  return;
}				/* tuiClearWin */


/*
   ** makeVisible().
   **        We can't really make windows visible, or invisible.  So we
   **        have to delete the entire window when making it visible,
   **        and create it again when making it visible.
 */
void
#ifdef __STDC__
makeVisible (
	      TuiGenWinInfoPtr winInfo,
	      int visible)
#else
makeVisible (winInfo, visible)
     TuiGenWinInfoPtr winInfo;
     int visible;
#endif
{
  /* Don't tear down/recreate command window */
  if (winInfo->type == CMD_WIN)
    return;

  if (visible)
    {
      if (!winInfo->isVisible)
	{
	  makeWindow (
		       winInfo,
	   (winInfo->type != CMD_WIN && !m_winIsAuxillary (winInfo->type)));
	  winInfo->isVisible = TRUE;
	}
      tuiRefreshWin (winInfo);
    }
  else if (!visible &&
	   winInfo->isVisible && winInfo->handle != (WINDOW *) NULL)
    {
      winInfo->isVisible = FALSE;
      tuiClearWin (winInfo);
      tuiDelwin (winInfo->handle);
      winInfo->handle = (WINDOW *) NULL;
    }

  return;
}				/* makeVisible */


/*
   ** makeAllVisible().
   **        Makes all windows invisible (except the command and locator windows)
 */
void
#ifdef __STDC__
makeAllVisible (
		 int visible)
#else
makeAllVisible (visible)
     int visible;
#endif
{
  int i;

  for (i = 0; i < MAX_MAJOR_WINDOWS; i++)
    {
      if (m_winPtrNotNull (winList[i]) &&
	  ((winList[i])->generic.type) != CMD_WIN)
	{
	  if (m_winIsSourceType ((winList[i])->generic.type))
	    makeVisible ((winList[i])->detail.sourceInfo.executionInfo,
			 visible);
	  makeVisible ((TuiGenWinInfoPtr) winList[i], visible);
	}
    }

  return;
}				/* makeAllVisible */


/*
   ** scrollWinForward
 */
void
#ifdef __STDC__
scrollWinForward (
		   TuiGenWinInfoPtr winInfo,
		   int numLines)
#else
scrollWinForward (winInfo, numLines)
     TuiGenWinInfoPtr winInfo;
     int numLines;
#endif
{
  if (winInfo->content != (OpaquePtr) NULL &&
      winInfo->lastVisibleLine < winInfo->contentSize - 1)
    {
      int i, firstLine, newLastLine;

      firstLine = winInfo->lastVisibleLine - winInfo->viewportHeight + 1;
      if (winInfo->lastVisibleLine + numLines > winInfo->contentSize)
	newLastLine = winInfo->contentSize - 1;
      else
	newLastLine = winInfo->lastVisibleLine + numLines - 1;

      for (i = (newLastLine - winInfo->viewportHeight);
	   (i <= newLastLine); i++)
	{
	  TuiWinElementPtr line;
	  int lineHeight;

	  line = (TuiWinElementPtr) winInfo->content[i];
	  if (line->highlight)
	    wstandout (winInfo->handle);
	  mvwaddstr (winInfo->handle,
		     i - (newLastLine - winInfo->viewportHeight),
		     1,
		     displayableWinContentOf (winInfo, line));
	  if (line->highlight)
	    wstandend (winInfo->handle);
	  lineHeight = winElementHeight (winInfo, line);
	  newLastLine += (lineHeight - 1);
	}
      winInfo->lastVisibleLine = newLastLine;
    }

  return;
}				/* scrollWinForward */


/*
   ** scrollWinBackward
 */
void
#ifdef __STDC__
scrollWinBackward (
		    TuiGenWinInfoPtr winInfo,
		    int numLines)
#else
scrollWinBackward (winInfo, numLines)
     TuiGenWinInfoPtr winInfo;
     int numLines;
#endif
{
  if (winInfo->content != (OpaquePtr) NULL &&
      (winInfo->lastVisibleLine - winInfo->viewportHeight) > 0)
    {
      int i, newLastLine, firstLine;

      firstLine = winInfo->lastVisibleLine - winInfo->viewportHeight + 1;
      if ((firstLine - numLines) < 0)
	newLastLine = winInfo->viewportHeight - 1;
      else
	newLastLine = winInfo->lastVisibleLine - numLines + 1;

      for (i = newLastLine - winInfo->viewportHeight; (i <= newLastLine); i++)
	{
	  TuiWinElementPtr line;
	  int lineHeight;

	  line = (TuiWinElementPtr) winInfo->content[i];
	  if (line->highlight)
	    wstandout (winInfo->handle);
	  mvwaddstr (winInfo->handle,
		     i - (newLastLine - winInfo->viewportHeight),
		     1,
		     displayableWinContentOf (winInfo, line));
	  if (line->highlight)
	    wstandend (winInfo->handle);
	  lineHeight = winElementHeight (winInfo, line);
	  newLastLine += (lineHeight - 1);
	}
      winInfo->lastVisibleLine = newLastLine;
    }

  return;
}				/* scrollWinBackward */


/*
   ** refreshAll().
   **        Function to refresh all the windows currently displayed
 */
void
#ifdef __STDC__
refreshAll (
	     TuiWinInfoPtr * list)
#else
refreshAll (list)
     TuiWinInfoPtr *list;
#endif
{
  TuiWinType type;
  TuiGenWinInfoPtr locator = locatorWinInfoPtr ();

  for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
    {
      if (list[type]->generic.isVisible)
	{
	  if (type == SRC_WIN || type == DISASSEM_WIN)
	    {
	      touchwin (list[type]->detail.sourceInfo.executionInfo->handle);
	      tuiRefreshWin (list[type]->detail.sourceInfo.executionInfo);
	    }
	  touchwin (list[type]->generic.handle);
	  tuiRefreshWin (&list[type]->generic);
	}
    }
  if (locator->isVisible)
    {
      touchwin (locator->handle);
      tuiRefreshWin (locator);
    }

  return;
}				/* refreshAll */


/*********************************
** Local Static Functions
*********************************/