aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui/tuiGeneralWin.c
blob: 8ec54fe62c3b461cd54fb14059a59f7447b3cd50 (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
/* General window behavior.
   Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
   Contributed by Hewlett-Packard Company.

   This file is part of GDB.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */

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

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


/***********************
** PUBLIC FUNCTIONS
***********************/
/*
   ** tuiRefreshWin()
   **        Refresh the window
 */
void
tuiRefreshWin (TuiGenWinInfoPtr winInfo)
{
  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
tuiDelwin (WINDOW * window)
{
  if (window != (WINDOW *) NULL)
    delwin (window);

  return;
}				/* tuiDelwin */


/* Draw a border arround the window.  */
void
boxWin (TuiGenWinInfoPtr winInfo, int highlightFlag)
{
  if (winInfo && winInfo->handle)
    {
      WINDOW *win;
      int attrs;

      win = winInfo->handle;
      if (highlightFlag == HILITE)
        attrs = tui_active_border_attrs;
      else
        attrs = tui_border_attrs;

      wattron (win, attrs);
      wborder (win, tui_border_vline, tui_border_vline,
               tui_border_hline, tui_border_hline,
               tui_border_ulcorner, tui_border_urcorner,
               tui_border_llcorner, tui_border_lrcorner);
      wattroff (win, attrs);
    }
}


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


/*
   ** highlightWin().
 */
void
highlightWin (TuiWinInfoPtr winInfo)
{
  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
checkAndDisplayHighlightIfNeeded (TuiWinInfoPtr winInfo)
{
  if (m_winPtrNotNull (winInfo) && winInfo->generic.type != CMD_WIN)
    {
      if (winInfo->isHighlighted)
	highlightWin (winInfo);
      else
	unhighlightWin (winInfo);

    }
  return;
}				/* checkAndDisplayHighlightIfNeeded */


/*
   ** makeWindow().
 */
void
makeWindow (TuiGenWinInfoPtr winInfo, int boxIt)
{
  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
tuiClearWin (TuiGenWinInfoPtr winInfo)
{
  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
makeVisible (TuiGenWinInfoPtr winInfo, int visible)
{
  /* 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
makeAllVisible (int visible)
{
  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
scrollWinForward (TuiGenWinInfoPtr winInfo, int numLines)
{
  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
scrollWinBackward (TuiGenWinInfoPtr winInfo, int numLines)
{
  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
refreshAll (TuiWinInfoPtr * list)
{
  TuiWinType type;
  TuiGenWinInfoPtr locator = locatorWinInfoPtr ();

  for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
    {
      if (list[type] && 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
*********************************/