* tui.c (tui_enable): Use tuiSetLayout instead of showLayout and
[deliverable/binutils-gdb.git] / gdb / tui / tuiWin.c
CommitLineData
f377b406 1/* TUI window generic functions.
f33c6cbf
AC
2
3 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation,
4 Inc.
5
f377b406 6 Contributed by Hewlett-Packard Company.
c906108c 7
f377b406
SC
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
24
25/* This module contains procedures for handling tui window functions
26 like resize, scrolling, scrolling, changing focus, etc.
27
28 Author: Susan B. Macchia */
c906108c 29
f33c6cbf
AC
30/* FIXME: cagney/2002-02-28: The GDB coding standard indicates that
31 "defs.h" should be included first. Unfortunatly some systems
32 (currently Debian GNU/Linux) include the <stdbool.h> via <curses.h>
33 and they clash with "bfd.h"'s definiton of true/false. The correct
34 fix is to remove true/false from "bfd.h", however, until that
35 happens, hack around it by including "config.h" and <curses.h>
36 first. */
37
4e8f7a8b
DJ
38#include "config.h"
39#ifdef HAVE_NCURSES_H
40#include <ncurses.h>
41#else
42#ifdef HAVE_CURSES_H
43#include <curses.h>
44#endif
45#endif
46
c906108c 47#include <string.h>
84b1e7c7 48#include <ctype.h>
c906108c
SS
49#include "defs.h"
50#include "command.h"
51#include "symtab.h"
52#include "breakpoint.h"
53#include "frame.h"
41783295 54#include "cli/cli-cmds.h"
c906108c
SS
55
56#include "tui.h"
57#include "tuiData.h"
58#include "tuiGeneralWin.h"
59#include "tuiStack.h"
84b1e7c7
SC
60#include "tuiRegs.h"
61#include "tuiDisassem.h"
62#include "tuiSource.h"
c906108c
SS
63#include "tuiSourceWin.h"
64#include "tuiDataWin.h"
65
66/*******************************
67** External Declarations
68********************************/
69extern void init_page_info ();
70
71/*******************************
72** Static Local Decls
73********************************/
a14ed312
KB
74static void _makeVisibleWithNewHeight (TuiWinInfoPtr);
75static void _makeInvisibleAndSetNewHeight (TuiWinInfoPtr, int);
76static TuiStatus _tuiAdjustWinHeights (TuiWinInfoPtr, int);
77static int _newHeightOk (TuiWinInfoPtr, int);
78static void _tuiSetTabWidth_command (char *, int);
79static void _tuiRefreshAll_command (char *, int);
80static void _tuiSetWinHeight_command (char *, int);
81static void _tuiXDBsetWinHeight_command (char *, int);
82static void _tuiAllWindowsInfo (char *, int);
83static void _tuiSetFocus_command (char *, int);
84static void _tuiScrollForward_command (char *, int);
85static void _tuiScrollBackward_command (char *, int);
86static void _tuiScrollLeft_command (char *, int);
87static void _tuiScrollRight_command (char *, int);
88static void _parseScrollingArgs (char *, TuiWinInfoPtr *, int *);
c906108c
SS
89
90
91/***************************************
92** DEFINITIONS
93***************************************/
94#define WIN_HEIGHT_USAGE "Usage: winheight <win_name> [+ | -] <#lines>\n"
95#define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n"
96#define FOCUS_USAGE "Usage: focus {<win> | next | prev}\n"
97
98/***************************************
99** PUBLIC FUNCTIONS
100***************************************/
101
af101512
SC
102/* Possible values for tui-border-kind variable. */
103static const char *tui_border_kind_enums[] = {
104 "space",
105 "ascii",
106 "acs",
107 NULL
108};
109
110/* Possible values for tui-border-mode and tui-active-border-mode. */
111static const char *tui_border_mode_enums[] = {
112 "normal",
113 "standout",
114 "reverse",
115 "half",
116 "half-standout",
117 "bold",
118 "bold-standout",
119 NULL
120};
121
122struct tui_translate
123{
124 const char *name;
125 int value;
126};
127
128/* Translation table for border-mode variables.
129 The list of values must be terminated by a NULL.
130 After the NULL value, an entry defines the default. */
131struct tui_translate tui_border_mode_translate[] = {
132 { "normal", A_NORMAL },
133 { "standout", A_STANDOUT },
134 { "reverse", A_REVERSE },
135 { "half", A_DIM },
136 { "half-standout", A_DIM | A_STANDOUT },
137 { "bold", A_BOLD },
138 { "bold-standout", A_BOLD | A_STANDOUT },
139 { 0, 0 },
140 { "normal", A_NORMAL }
141};
142
143/* Translation tables for border-kind, one for each border
144 character (see wborder, border curses operations).
145 -1 is used to indicate the ACS because ACS characters
146 are determined at run time by curses (depends on terminal). */
147struct tui_translate tui_border_kind_translate_vline[] = {
148 { "space", ' ' },
149 { "ascii", '|' },
150 { "acs", -1 },
151 { 0, 0 },
152 { "ascii", '|' }
153};
154
155struct tui_translate tui_border_kind_translate_hline[] = {
156 { "space", ' ' },
157 { "ascii", '-' },
158 { "acs", -1 },
159 { 0, 0 },
160 { "ascii", '-' }
161};
162
163struct tui_translate tui_border_kind_translate_ulcorner[] = {
164 { "space", ' ' },
165 { "ascii", '+' },
166 { "acs", -1 },
167 { 0, 0 },
168 { "ascii", '+' }
169};
170
171struct tui_translate tui_border_kind_translate_urcorner[] = {
172 { "space", ' ' },
173 { "ascii", '+' },
174 { "acs", -1 },
175 { 0, 0 },
176 { "ascii", '+' }
177};
178
179struct tui_translate tui_border_kind_translate_llcorner[] = {
180 { "space", ' ' },
181 { "ascii", '+' },
182 { "acs", -1 },
183 { 0, 0 },
184 { "ascii", '+' }
185};
186
187struct tui_translate tui_border_kind_translate_lrcorner[] = {
188 { "space", ' ' },
189 { "ascii", '+' },
190 { "acs", -1 },
191 { 0, 0 },
192 { "ascii", '+' }
193};
194
195
196/* Tui configuration variables controlled with set/show command. */
197const char *tui_active_border_mode = "bold-standout";
198const char *tui_border_mode = "normal";
199const char *tui_border_kind = "acs";
200
201/* Tui internal configuration variables. These variables are
202 updated by tui_update_variables to reflect the tui configuration
203 variables. */
204chtype tui_border_vline;
205chtype tui_border_hline;
206chtype tui_border_ulcorner;
207chtype tui_border_urcorner;
208chtype tui_border_llcorner;
209chtype tui_border_lrcorner;
210
211int tui_border_attrs;
212int tui_active_border_attrs;
213
214/* Identify the item in the translation table.
215 When the item is not recognized, use the default entry. */
216static struct tui_translate *
217translate (const char *name, struct tui_translate *table)
218{
219 while (table->name)
220 {
221 if (name && strcmp (table->name, name) == 0)
222 return table;
223 table++;
224 }
225
226 /* Not found, return default entry. */
227 table++;
228 return table;
229}
230
231/* Update the tui internal configuration according to gdb settings.
232 Returns 1 if the configuration has changed and the screen should
233 be redrawn. */
234int
235tui_update_variables ()
236{
237 int need_redraw = 0;
238 struct tui_translate *entry;
239
240 entry = translate (tui_border_mode, tui_border_mode_translate);
241 if (tui_border_attrs != entry->value)
242 {
243 tui_border_attrs = entry->value;
244 need_redraw = 1;
245 }
246 entry = translate (tui_active_border_mode, tui_border_mode_translate);
247 if (tui_active_border_attrs != entry->value)
248 {
249 tui_active_border_attrs = entry->value;
250 need_redraw = 1;
251 }
252
253 /* If one corner changes, all characters are changed.
254 Only check the first one. The ACS characters are determined at
255 run time by curses terminal management. */
256 entry = translate (tui_border_kind, tui_border_kind_translate_lrcorner);
257 if (tui_border_lrcorner != (chtype) entry->value)
258 {
259 tui_border_lrcorner = (entry->value < 0) ? ACS_LRCORNER : entry->value;
260 need_redraw = 1;
261 }
262 entry = translate (tui_border_kind, tui_border_kind_translate_llcorner);
263 tui_border_llcorner = (entry->value < 0) ? ACS_LLCORNER : entry->value;
264
265 entry = translate (tui_border_kind, tui_border_kind_translate_ulcorner);
266 tui_border_ulcorner = (entry->value < 0) ? ACS_ULCORNER : entry->value;
267
268 entry = translate (tui_border_kind, tui_border_kind_translate_urcorner);
269 tui_border_urcorner = (entry->value < 0) ? ACS_URCORNER : entry->value;
270
271 entry = translate (tui_border_kind, tui_border_kind_translate_hline);
272 tui_border_hline = (entry->value < 0) ? ACS_HLINE : entry->value;
273
274 entry = translate (tui_border_kind, tui_border_kind_translate_vline);
275 tui_border_vline = (entry->value < 0) ? ACS_VLINE : entry->value;
276
277 return need_redraw;
278}
279
c9684879
SC
280static void
281set_tui_cmd (char *args, int from_tty)
282{
283}
284
285static void
286show_tui_cmd (char *args, int from_tty)
287{
288}
af101512 289
c906108c 290/*
c5aa993b
JM
291 ** _initialize_tuiWin().
292 ** Function to initialize gdb commands, for tui window manipulation.
293 */
c906108c 294void
fba45db2 295_initialize_tuiWin (void)
c906108c 296{
af101512 297 struct cmd_list_element *c;
c9684879
SC
298 static struct cmd_list_element *tui_setlist;
299 static struct cmd_list_element *tui_showlist;
af101512 300
41783295
SC
301 /* Define the classes of commands.
302 They will appear in the help list in the reverse of this order. */
e00d1dc8 303 add_cmd ("tui", class_tui, NULL,
41783295
SC
304 "Text User Interface commands.",
305 &cmdlist);
306
c9684879
SC
307 add_prefix_cmd ("tui", class_tui, set_tui_cmd,
308 "TUI configuration variables",
309 &tui_setlist, "set tui ",
310 0/*allow-unknown*/, &setlist);
311 add_prefix_cmd ("tui", class_tui, show_tui_cmd,
312 "TUI configuration variables",
313 &tui_showlist, "show tui ",
314 0/*allow-unknown*/, &showlist);
315
41783295
SC
316 add_com ("refresh", class_tui, _tuiRefreshAll_command,
317 "Refresh the terminal display.\n");
318 if (xdb_commands)
319 add_com_alias ("U", "refresh", class_tui, 0);
320 add_com ("tabset", class_tui, _tuiSetTabWidth_command,
321 "Set the width (in characters) of tab stops.\n\
c906108c 322Usage: tabset <n>\n");
41783295
SC
323 add_com ("winheight", class_tui, _tuiSetWinHeight_command,
324 "Set the height of a specified window.\n\
c906108c
SS
325Usage: winheight <win_name> [+ | -] <#lines>\n\
326Window names are:\n\
327src : the source window\n\
328cmd : the command window\n\
329asm : the disassembly window\n\
330regs : the register display\n");
41783295
SC
331 add_com_alias ("wh", "winheight", class_tui, 0);
332 add_info ("win", _tuiAllWindowsInfo,
333 "List of all displayed windows.\n");
334 add_com ("focus", class_tui, _tuiSetFocus_command,
335 "Set focus to named window or next/prev window.\n\
c906108c
SS
336Usage: focus {<win> | next | prev}\n\
337Valid Window names are:\n\
338src : the source window\n\
339asm : the disassembly window\n\
340regs : the register display\n\
341cmd : the command window\n");
41783295
SC
342 add_com_alias ("fs", "focus", class_tui, 0);
343 add_com ("+", class_tui, _tuiScrollForward_command,
344 "Scroll window forward.\nUsage: + [win] [n]\n");
345 add_com ("-", class_tui, _tuiScrollBackward_command,
346 "Scroll window backward.\nUsage: - [win] [n]\n");
347 add_com ("<", class_tui, _tuiScrollLeft_command,
348 "Scroll window forward.\nUsage: < [win] [n]\n");
349 add_com (">", class_tui, _tuiScrollRight_command,
350 "Scroll window backward.\nUsage: > [win] [n]\n");
351 if (xdb_commands)
352 add_com ("w", class_xdb, _tuiXDBsetWinHeight_command,
353 "XDB compatibility command for setting the height of a command window.\n\
c906108c 354Usage: w <#lines>\n");
af101512
SC
355
356 /* Define the tui control variables. */
357 c = add_set_enum_cmd
c9684879 358 ("border-kind", no_class,
c6f60bcd 359 tui_border_kind_enums, &tui_border_kind,
af101512
SC
360 "Set the kind of border for TUI windows.\n"
361 "This variable controls the border of TUI windows:\n"
362 "space use a white space\n"
363 "ascii use ascii characters + - | for the border\n"
364 "acs use the Alternate Character Set\n",
c9684879
SC
365 &tui_setlist);
366 add_show_from_set (c, &tui_showlist);
af101512
SC
367
368 c = add_set_enum_cmd
c9684879 369 ("border-mode", no_class,
c6f60bcd 370 tui_border_mode_enums, &tui_border_mode,
af101512
SC
371 "Set the attribute mode to use for the TUI window borders.\n"
372 "This variable controls the attributes to use for the window borders:\n"
373 "normal normal display\n"
374 "standout use highlight mode of terminal\n"
375 "reverse use reverse video mode\n"
376 "half use half bright\n"
377 "half-standout use half bright and standout mode\n"
378 "bold use extra bright or bold\n"
379 "bold-standout use extra bright or bold with standout mode\n",
c9684879
SC
380 &tui_setlist);
381 add_show_from_set (c, &tui_showlist);
af101512
SC
382
383 c = add_set_enum_cmd
c9684879 384 ("active-border-mode", no_class,
c6f60bcd 385 tui_border_mode_enums, &tui_active_border_mode,
af101512
SC
386 "Set the attribute mode to use for the active TUI window border.\n"
387 "This variable controls the attributes to use for the active window border:\n"
388 "normal normal display\n"
389 "standout use highlight mode of terminal\n"
390 "reverse use reverse video mode\n"
391 "half use half bright\n"
392 "half-standout use half bright and standout mode\n"
393 "bold use extra bright or bold\n"
394 "bold-standout use extra bright or bold with standout mode\n",
c9684879
SC
395 &tui_setlist);
396 add_show_from_set (c, &tui_showlist);
41783295 397}
c906108c
SS
398
399
c906108c 400/*
c5aa993b
JM
401 ** tuiSetWinFocusTo
402 ** Set the logical focus to winInfo
403 */
c906108c 404void
eca6576c 405tuiSetWinFocusTo (TuiWinInfoPtr winInfo)
c906108c
SS
406{
407 if (m_winPtrNotNull (winInfo))
408 {
409 TuiWinInfoPtr winWithFocus = tuiWinWithFocus ();
410
411 if (m_winPtrNotNull (winWithFocus) &&
412 winWithFocus->generic.type != CMD_WIN)
413 unhighlightWin (winWithFocus);
414 tuiSetWinWithFocus (winInfo);
415 if (winInfo->generic.type != CMD_WIN)
416 highlightWin (winInfo);
417 }
418
419 return;
420} /* tuiSetWinFocusTo */
421
422
c906108c 423/*
c5aa993b
JM
424 ** tuiScrollForward().
425 */
c906108c 426void
eca6576c 427tuiScrollForward (TuiWinInfoPtr winToScroll, int numToScroll)
c906108c
SS
428{
429 if (winToScroll != cmdWin)
430 {
431 int _numToScroll = numToScroll;
432
433 if (numToScroll == 0)
434 _numToScroll = winToScroll->generic.height - 3;
435 /*
c5aa993b
JM
436 ** If we are scrolling the source or disassembly window, do a
437 ** "psuedo" scroll since not all of the source is in memory,
438 ** only what is in the viewport. If winToScroll is the
439 ** command window do nothing since the term should handle it.
440 */
c906108c
SS
441 if (winToScroll == srcWin)
442 tuiVerticalSourceScroll (FORWARD_SCROLL, _numToScroll);
443 else if (winToScroll == disassemWin)
444 tuiVerticalDisassemScroll (FORWARD_SCROLL, _numToScroll);
445 else if (winToScroll == dataWin)
446 tuiVerticalDataScroll (FORWARD_SCROLL, _numToScroll);
447 }
448
449 return;
450} /* tuiScrollForward */
451
452
453/*
c5aa993b
JM
454 ** tuiScrollBackward().
455 */
c906108c 456void
eca6576c 457tuiScrollBackward (TuiWinInfoPtr winToScroll, int numToScroll)
c906108c
SS
458{
459 if (winToScroll != cmdWin)
460 {
461 int _numToScroll = numToScroll;
462
463 if (numToScroll == 0)
464 _numToScroll = winToScroll->generic.height - 3;
465 /*
c5aa993b
JM
466 ** If we are scrolling the source or disassembly window, do a
467 ** "psuedo" scroll since not all of the source is in memory,
468 ** only what is in the viewport. If winToScroll is the
469 ** command window do nothing since the term should handle it.
470 */
c906108c
SS
471 if (winToScroll == srcWin)
472 tuiVerticalSourceScroll (BACKWARD_SCROLL, _numToScroll);
473 else if (winToScroll == disassemWin)
474 tuiVerticalDisassemScroll (BACKWARD_SCROLL, _numToScroll);
475 else if (winToScroll == dataWin)
476 tuiVerticalDataScroll (BACKWARD_SCROLL, _numToScroll);
477 }
478 return;
479} /* tuiScrollBackward */
480
481
482/*
c5aa993b
JM
483 ** tuiScrollLeft().
484 */
c906108c 485void
eca6576c 486tuiScrollLeft (TuiWinInfoPtr winToScroll, int numToScroll)
c906108c
SS
487{
488 if (winToScroll != cmdWin)
489 {
490 int _numToScroll = numToScroll;
491
492 if (_numToScroll == 0)
493 _numToScroll = 1;
494 /*
c5aa993b
JM
495 ** If we are scrolling the source or disassembly window, do a
496 ** "psuedo" scroll since not all of the source is in memory,
497 ** only what is in the viewport. If winToScroll is the
498 ** command window do nothing since the term should handle it.
499 */
c906108c
SS
500 if (winToScroll == srcWin || winToScroll == disassemWin)
501 tuiHorizontalSourceScroll (winToScroll, LEFT_SCROLL, _numToScroll);
502 }
503 return;
504} /* tuiScrollLeft */
505
506
507/*
c5aa993b
JM
508 ** tuiScrollRight().
509 */
c906108c 510void
eca6576c 511tuiScrollRight (TuiWinInfoPtr winToScroll, int numToScroll)
c906108c
SS
512{
513 if (winToScroll != cmdWin)
514 {
515 int _numToScroll = numToScroll;
516
517 if (_numToScroll == 0)
518 _numToScroll = 1;
519 /*
c5aa993b
JM
520 ** If we are scrolling the source or disassembly window, do a
521 ** "psuedo" scroll since not all of the source is in memory,
522 ** only what is in the viewport. If winToScroll is the
523 ** command window do nothing since the term should handle it.
524 */
c906108c
SS
525 if (winToScroll == srcWin || winToScroll == disassemWin)
526 tuiHorizontalSourceScroll (winToScroll, RIGHT_SCROLL, _numToScroll);
527 }
528 return;
529} /* tuiScrollRight */
530
531
532/*
e8b915dc 533 ** tui_scroll().
c5aa993b
JM
534 ** Scroll a window. Arguments are passed through a va_list.
535 */
c906108c 536void
e8b915dc
SC
537tui_scroll (TuiScrollDirection direction,
538 TuiWinInfoPtr winToScroll,
539 int numToScroll)
c906108c 540{
c906108c
SS
541 switch (direction)
542 {
543 case FORWARD_SCROLL:
544 tuiScrollForward (winToScroll, numToScroll);
545 break;
546 case BACKWARD_SCROLL:
547 tuiScrollBackward (winToScroll, numToScroll);
548 break;
549 case LEFT_SCROLL:
550 tuiScrollLeft (winToScroll, numToScroll);
551 break;
552 case RIGHT_SCROLL:
553 tuiScrollRight (winToScroll, numToScroll);
554 break;
555 default:
556 break;
557 }
e8b915dc 558}
c906108c
SS
559
560
561/*
c5aa993b
JM
562 ** tuiRefreshAll().
563 */
c906108c 564void
c906108c 565tuiRefreshAll (void)
c906108c
SS
566{
567 TuiWinType type;
568
3e266828 569 clearok (curscr, TRUE);
c906108c
SS
570 refreshAll (winList);
571 for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++)
572 {
75fd9bc1 573 if (winList[type] && winList[type]->generic.isVisible)
c906108c
SS
574 {
575 switch (type)
576 {
577 case SRC_WIN:
578 case DISASSEM_WIN:
c906108c
SS
579 tuiShowSourceContent (winList[type]);
580 checkAndDisplayHighlightIfNeeded (winList[type]);
581 tuiEraseExecInfoContent (winList[type]);
582 tuiUpdateExecInfo (winList[type]);
583 break;
584 case DATA_WIN:
585 tuiRefreshDataWin ();
586 break;
587 default:
588 break;
589 }
590 }
591 }
c906108c 592 tuiShowLocatorContent ();
bc712bbf 593}
c906108c
SS
594
595
596/*
c5aa993b
JM
597 ** tuiResizeAll().
598 ** Resize all the windows based on the the terminal size. This
599 ** function gets called from within the readline sinwinch handler.
600 */
c906108c 601void
c906108c 602tuiResizeAll (void)
c906108c
SS
603{
604 int heightDiff, widthDiff;
c5aa993b 605 extern int screenheight, screenwidth; /* in readline */
c906108c
SS
606
607 widthDiff = screenwidth - termWidth ();
608 heightDiff = screenheight - termHeight ();
609 if (heightDiff || widthDiff)
610 {
611 TuiLayoutType curLayout = currentLayout ();
612 TuiWinInfoPtr winWithFocus = tuiWinWithFocus ();
613 TuiWinInfoPtr firstWin, secondWin;
614 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
615 TuiWinType winType;
bc712bbf 616 int newHeight, splitDiff, cmdSplitDiff, numWinsDisplayed = 2;
c906108c
SS
617
618 /* turn keypad off while we resize */
619 if (winWithFocus != cmdWin)
620 keypad (cmdWin->generic.handle, FALSE);
621 init_page_info ();
622 setTermHeightTo (screenheight);
623 setTermWidthTo (screenwidth);
624 if (curLayout == SRC_DISASSEM_COMMAND ||
625 curLayout == SRC_DATA_COMMAND || curLayout == DISASSEM_DATA_COMMAND)
626 numWinsDisplayed++;
627 splitDiff = heightDiff / numWinsDisplayed;
628 cmdSplitDiff = splitDiff;
629 if (heightDiff % numWinsDisplayed)
630 {
631 if (heightDiff < 0)
632 cmdSplitDiff--;
633 else
634 cmdSplitDiff++;
635 }
636 /* now adjust each window */
637 clear ();
638 refresh ();
639 switch (curLayout)
640 {
641 case SRC_COMMAND:
642 case DISASSEM_COMMAND:
643 firstWin = (TuiWinInfoPtr) (sourceWindows ())->list[0];
644 firstWin->generic.width += widthDiff;
645 locator->width += widthDiff;
646 /* check for invalid heights */
647 if (heightDiff == 0)
648 newHeight = firstWin->generic.height;
649 else if ((firstWin->generic.height + splitDiff) >=
650 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
651 newHeight = screenheight - MIN_CMD_WIN_HEIGHT - 1;
652 else if ((firstWin->generic.height + splitDiff) <= 0)
653 newHeight = MIN_WIN_HEIGHT;
654 else
655 newHeight = firstWin->generic.height + splitDiff;
656
657 _makeInvisibleAndSetNewHeight (firstWin, newHeight);
658 cmdWin->generic.origin.y = locator->origin.y + 1;
659 cmdWin->generic.width += widthDiff;
660 newHeight = screenheight - cmdWin->generic.origin.y;
661 _makeInvisibleAndSetNewHeight (cmdWin, newHeight);
662 _makeVisibleWithNewHeight (firstWin);
663 _makeVisibleWithNewHeight (cmdWin);
664 if (firstWin->generic.contentSize <= 0)
665 tuiEraseSourceContent (firstWin, EMPTY_SOURCE_PROMPT);
666 break;
667 default:
668 if (curLayout == SRC_DISASSEM_COMMAND)
669 {
670 firstWin = srcWin;
671 firstWin->generic.width += widthDiff;
672 secondWin = disassemWin;
673 secondWin->generic.width += widthDiff;
674 }
675 else
676 {
677 firstWin = dataWin;
678 firstWin->generic.width += widthDiff;
679 secondWin = (TuiWinInfoPtr) (sourceWindows ())->list[0];
680 secondWin->generic.width += widthDiff;
681 }
682 /* Change the first window's height/width */
683 /* check for invalid heights */
684 if (heightDiff == 0)
685 newHeight = firstWin->generic.height;
686 else if ((firstWin->generic.height +
687 secondWin->generic.height + (splitDiff * 2)) >=
688 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
689 newHeight = (screenheight - MIN_CMD_WIN_HEIGHT - 1) / 2;
690 else if ((firstWin->generic.height + splitDiff) <= 0)
691 newHeight = MIN_WIN_HEIGHT;
692 else
693 newHeight = firstWin->generic.height + splitDiff;
694 _makeInvisibleAndSetNewHeight (firstWin, newHeight);
695
696 if (firstWin == dataWin && widthDiff != 0)
697 firstWin->detail.dataDisplayInfo.regsColumnCount =
698 tuiCalculateRegsColumnCount (
699 firstWin->detail.dataDisplayInfo.regsDisplayType);
700 locator->width += widthDiff;
701
702 /* Change the second window's height/width */
703 /* check for invalid heights */
704 if (heightDiff == 0)
705 newHeight = secondWin->generic.height;
706 else if ((firstWin->generic.height +
707 secondWin->generic.height + (splitDiff * 2)) >=
708 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
709 {
710 newHeight = screenheight - MIN_CMD_WIN_HEIGHT - 1;
711 if (newHeight % 2)
712 newHeight = (newHeight / 2) + 1;
713 else
714 newHeight /= 2;
715 }
716 else if ((secondWin->generic.height + splitDiff) <= 0)
717 newHeight = MIN_WIN_HEIGHT;
718 else
719 newHeight = secondWin->generic.height + splitDiff;
720 secondWin->generic.origin.y = firstWin->generic.height - 1;
721 _makeInvisibleAndSetNewHeight (secondWin, newHeight);
722
723 /* Change the command window's height/width */
724 cmdWin->generic.origin.y = locator->origin.y + 1;
725 _makeInvisibleAndSetNewHeight (
726 cmdWin, cmdWin->generic.height + cmdSplitDiff);
727 _makeVisibleWithNewHeight (firstWin);
728 _makeVisibleWithNewHeight (secondWin);
729 _makeVisibleWithNewHeight (cmdWin);
730 if (firstWin->generic.contentSize <= 0)
731 tuiEraseSourceContent (firstWin, EMPTY_SOURCE_PROMPT);
732 if (secondWin->generic.contentSize <= 0)
733 tuiEraseSourceContent (secondWin, EMPTY_SOURCE_PROMPT);
734 break;
735 }
736 /*
c5aa993b
JM
737 ** Now remove all invisible windows, and their content so that they get
738 ** created again when called for with the new size
739 */
c906108c
SS
740 for (winType = SRC_WIN; (winType < MAX_MAJOR_WINDOWS); winType++)
741 {
742 if (winType != CMD_WIN && m_winPtrNotNull (winList[winType]) &&
743 !winList[winType]->generic.isVisible)
744 {
745 freeWindow (winList[winType]);
746 winList[winType] = (TuiWinInfoPtr) NULL;
747 }
748 }
749 tuiSetWinResizedTo (TRUE);
750 /* turn keypad back on, unless focus is in the command window */
751 if (winWithFocus != cmdWin)
752 keypad (cmdWin->generic.handle, TRUE);
753 }
754 return;
755} /* tuiResizeAll */
756
757
758/*
c5aa993b
JM
759 ** tuiSigwinchHandler()
760 ** SIGWINCH signal handler for the tui. This signal handler is
761 ** always called, even when the readline package clears signals
762 ** because it is set as the old_sigwinch() (TUI only)
763 */
c906108c 764void
eca6576c 765tuiSigwinchHandler (int signal)
c906108c
SS
766{
767 /*
c5aa993b
JM
768 ** Say that a resize was done so that the readline can do it
769 ** later when appropriate.
770 */
c906108c
SS
771 tuiSetWinResizedTo (TRUE);
772
773 return;
774} /* tuiSigwinchHandler */
775
776
777
778/*************************
779** STATIC LOCAL FUNCTIONS
780**************************/
781
782
783/*
c5aa993b
JM
784 ** _tuiScrollForward_command().
785 */
c906108c 786static void
eca6576c 787_tuiScrollForward_command (char *arg, int fromTTY)
c906108c
SS
788{
789 int numToScroll = 1;
790 TuiWinInfoPtr winToScroll;
791
1854bb21
SC
792 /* Make sure the curses mode is enabled. */
793 tui_enable ();
c906108c
SS
794 if (arg == (char *) NULL)
795 _parseScrollingArgs (arg, &winToScroll, (int *) NULL);
796 else
797 _parseScrollingArgs (arg, &winToScroll, &numToScroll);
e8b915dc
SC
798 tui_scroll (FORWARD_SCROLL, winToScroll, numToScroll);
799}
c906108c
SS
800
801
802/*
c5aa993b
JM
803 ** _tuiScrollBackward_command().
804 */
c906108c 805static void
eca6576c 806_tuiScrollBackward_command (char *arg, int fromTTY)
c906108c
SS
807{
808 int numToScroll = 1;
809 TuiWinInfoPtr winToScroll;
810
1854bb21
SC
811 /* Make sure the curses mode is enabled. */
812 tui_enable ();
c906108c
SS
813 if (arg == (char *) NULL)
814 _parseScrollingArgs (arg, &winToScroll, (int *) NULL);
815 else
816 _parseScrollingArgs (arg, &winToScroll, &numToScroll);
e8b915dc
SC
817 tui_scroll (BACKWARD_SCROLL, winToScroll, numToScroll);
818}
c906108c
SS
819
820
821/*
c5aa993b
JM
822 ** _tuiScrollLeft_command().
823 */
c906108c 824static void
eca6576c 825_tuiScrollLeft_command (char *arg, int fromTTY)
c906108c
SS
826{
827 int numToScroll;
828 TuiWinInfoPtr winToScroll;
829
1854bb21
SC
830 /* Make sure the curses mode is enabled. */
831 tui_enable ();
c906108c 832 _parseScrollingArgs (arg, &winToScroll, &numToScroll);
e8b915dc
SC
833 tui_scroll (LEFT_SCROLL, winToScroll, numToScroll);
834}
c906108c
SS
835
836
837/*
c5aa993b
JM
838 ** _tuiScrollRight_command().
839 */
c906108c 840static void
eca6576c 841_tuiScrollRight_command (char *arg, int fromTTY)
c906108c
SS
842{
843 int numToScroll;
844 TuiWinInfoPtr winToScroll;
845
1854bb21
SC
846 /* Make sure the curses mode is enabled. */
847 tui_enable ();
c906108c 848 _parseScrollingArgs (arg, &winToScroll, &numToScroll);
e8b915dc
SC
849 tui_scroll (RIGHT_SCROLL, winToScroll, numToScroll);
850}
c906108c
SS
851
852
853/*
c5aa993b
JM
854 ** _tuiSetFocus().
855 ** Set focus to the window named by 'arg'
856 */
c906108c 857static void
eca6576c 858_tuiSetFocus (char *arg, int fromTTY)
c906108c
SS
859{
860 if (arg != (char *) NULL)
861 {
1854bb21 862 char *bufPtr = (char *) xstrdup (arg);
c906108c
SS
863 int i;
864 TuiWinInfoPtr winInfo = (TuiWinInfoPtr) NULL;
865
866 for (i = 0; (i < strlen (bufPtr)); i++)
867 bufPtr[i] = toupper (arg[i]);
868
0963fc96 869 if (subset_compare (bufPtr, "NEXT"))
c906108c 870 winInfo = tuiNextWin (tuiWinWithFocus ());
0963fc96 871 else if (subset_compare (bufPtr, "PREV"))
c906108c
SS
872 winInfo = tuiPrevWin (tuiWinWithFocus ());
873 else
874 winInfo = partialWinByName (bufPtr);
875
876 if (winInfo == (TuiWinInfoPtr) NULL || !winInfo->generic.isVisible)
877 warning ("Invalid window specified. \n\
878The window name specified must be valid and visible.\n");
879 else
880 {
881 tuiSetWinFocusTo (winInfo);
882 keypad (cmdWin->generic.handle, (winInfo != cmdWin));
883 }
884
75fd9bc1 885 if (dataWin && dataWin->generic.isVisible)
c906108c
SS
886 tuiRefreshDataWin ();
887 tuiFree (bufPtr);
888 printf_filtered ("Focus set to %s window.\n",
889 winName ((TuiGenWinInfoPtr) tuiWinWithFocus ()));
890 }
891 else
892 warning ("Incorrect Number of Arguments.\n%s", FOCUS_USAGE);
893
894 return;
895} /* _tuiSetFocus */
896
c906108c 897/*
c5aa993b
JM
898 ** _tuiSetFocus_command()
899 */
c906108c 900static void
eca6576c 901_tuiSetFocus_command (char *arg, int fromTTY)
c906108c 902{
1854bb21
SC
903 /* Make sure the curses mode is enabled. */
904 tui_enable ();
e8b915dc
SC
905 _tuiSetFocus (arg, fromTTY);
906}
c906108c
SS
907
908
909/*
c5aa993b
JM
910 ** _tuiAllWindowsInfo().
911 */
c906108c 912static void
eca6576c 913_tuiAllWindowsInfo (char *arg, int fromTTY)
c906108c
SS
914{
915 TuiWinType type;
916 TuiWinInfoPtr winWithFocus = tuiWinWithFocus ();
917
918 for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
919 if (winList[type]->generic.isVisible)
920 {
921 if (winWithFocus == winList[type])
922 printf_filtered (" %s\t(%d lines) <has focus>\n",
923 winName (&winList[type]->generic),
924 winList[type]->generic.height);
925 else
926 printf_filtered (" %s\t(%d lines)\n",
927 winName (&winList[type]->generic),
928 winList[type]->generic.height);
929 }
930
931 return;
932} /* _tuiAllWindowsInfo */
933
934
935/*
c5aa993b
JM
936 ** _tuiRefreshAll_command().
937 */
c906108c 938static void
eca6576c 939_tuiRefreshAll_command (char *arg, int fromTTY)
c906108c 940{
1854bb21
SC
941 /* Make sure the curses mode is enabled. */
942 tui_enable ();
943
e8b915dc 944 tuiRefreshAll ();
c906108c
SS
945}
946
947
948/*
c5aa993b
JM
949 ** _tuiSetWinTabWidth_command().
950 ** Set the height of the specified window.
951 */
c906108c 952static void
eca6576c 953_tuiSetTabWidth_command (char *arg, int fromTTY)
c906108c 954{
1854bb21
SC
955 /* Make sure the curses mode is enabled. */
956 tui_enable ();
c906108c
SS
957 if (arg != (char *) NULL)
958 {
959 int ts;
960
961 ts = atoi (arg);
962 if (ts > 0)
963 tuiSetDefaultTabLen (ts);
964 else
965 warning ("Tab widths greater than 0 must be specified.\n");
966 }
967
968 return;
969} /* _tuiSetTabWidth_command */
970
971
972/*
c5aa993b
JM
973 ** _tuiSetWinHeight().
974 ** Set the height of the specified window.
975 */
c906108c 976static void
eca6576c 977_tuiSetWinHeight (char *arg, int fromTTY)
c906108c 978{
1854bb21
SC
979 /* Make sure the curses mode is enabled. */
980 tui_enable ();
c906108c
SS
981 if (arg != (char *) NULL)
982 {
1854bb21 983 char *buf = xstrdup (arg);
c906108c
SS
984 char *bufPtr = buf;
985 char *wname = (char *) NULL;
986 int newHeight, i;
987 TuiWinInfoPtr winInfo;
988
989 wname = bufPtr;
990 bufPtr = strchr (bufPtr, ' ');
991 if (bufPtr != (char *) NULL)
992 {
993 *bufPtr = (char) 0;
994
995 /*
c5aa993b
JM
996 ** Validate the window name
997 */
c906108c
SS
998 for (i = 0; i < strlen (wname); i++)
999 wname[i] = toupper (wname[i]);
1000 winInfo = partialWinByName (wname);
1001
1002 if (winInfo == (TuiWinInfoPtr) NULL || !winInfo->generic.isVisible)
1003 warning ("Invalid window specified. \n\
1004The window name specified must be valid and visible.\n");
1005 else
1006 {
1007 /* Process the size */
1008 while (*(++bufPtr) == ' ')
1009 ;
1010
1011 if (*bufPtr != (char) 0)
1012 {
1013 int negate = FALSE;
1014 int fixedSize = TRUE;
1015 int inputNo;;
1016
1017 if (*bufPtr == '+' || *bufPtr == '-')
1018 {
1019 if (*bufPtr == '-')
1020 negate = TRUE;
1021 fixedSize = FALSE;
1022 bufPtr++;
1023 }
1024 inputNo = atoi (bufPtr);
1025 if (inputNo > 0)
1026 {
1027 if (negate)
1028 inputNo *= (-1);
1029 if (fixedSize)
1030 newHeight = inputNo;
1031 else
1032 newHeight = winInfo->generic.height + inputNo;
1033 /*
c5aa993b
JM
1034 ** Now change the window's height, and adjust all
1035 ** other windows around it
1036 */
c906108c
SS
1037 if (_tuiAdjustWinHeights (winInfo,
1038 newHeight) == TUI_FAILURE)
1039 warning ("Invalid window height specified.\n%s",
1040 WIN_HEIGHT_USAGE);
1041 else
1042 init_page_info ();
1043 }
1044 else
1045 warning ("Invalid window height specified.\n%s",
1046 WIN_HEIGHT_USAGE);
1047 }
1048 }
1049 }
1050 else
1051 printf_filtered (WIN_HEIGHT_USAGE);
1052
1053 if (buf != (char *) NULL)
1054 tuiFree (buf);
1055 }
1056 else
1057 printf_filtered (WIN_HEIGHT_USAGE);
1058
1059 return;
1060} /* _tuiSetWinHeight */
1061
c906108c 1062/*
c5aa993b
JM
1063 ** _tuiSetWinHeight_command().
1064 ** Set the height of the specified window, with va_list.
1065 */
c906108c 1066static void
eca6576c 1067_tuiSetWinHeight_command (char *arg, int fromTTY)
c906108c 1068{
1854bb21
SC
1069 /* Make sure the curses mode is enabled. */
1070 tui_enable ();
e8b915dc
SC
1071 _tuiSetWinHeight (arg, fromTTY);
1072}
c906108c
SS
1073
1074
1075/*
c5aa993b
JM
1076 ** _tuiXDBsetWinHeight().
1077 ** XDB Compatibility command for setting the window height. This will
1078 ** increase or decrease the command window by the specified amount.
1079 */
c906108c 1080static void
eca6576c 1081_tuiXDBsetWinHeight (char *arg, int fromTTY)
c906108c 1082{
1854bb21
SC
1083 /* Make sure the curses mode is enabled. */
1084 tui_enable ();
c906108c
SS
1085 if (arg != (char *) NULL)
1086 {
1087 int inputNo = atoi (arg);
1088
1089 if (inputNo > 0)
1090 { /* Add 1 for the locator */
1091 int newHeight = termHeight () - (inputNo + 1);
1092
1093 if (!_newHeightOk (winList[CMD_WIN], newHeight) ||
1094 _tuiAdjustWinHeights (winList[CMD_WIN],
1095 newHeight) == TUI_FAILURE)
1096 warning ("Invalid window height specified.\n%s",
1097 XDBWIN_HEIGHT_USAGE);
1098 }
1099 else
1100 warning ("Invalid window height specified.\n%s",
1101 XDBWIN_HEIGHT_USAGE);
1102 }
1103 else
1104 warning ("Invalid window height specified.\n%s", XDBWIN_HEIGHT_USAGE);
1105
1106 return;
1107} /* _tuiXDBsetWinHeight */
1108
c906108c 1109/*
c5aa993b
JM
1110 ** _tuiSetWinHeight_command().
1111 ** Set the height of the specified window, with va_list.
1112 */
c906108c 1113static void
eca6576c 1114_tuiXDBsetWinHeight_command (char *arg, int fromTTY)
c906108c 1115{
e8b915dc
SC
1116 _tuiXDBsetWinHeight (arg, fromTTY);
1117}
c906108c
SS
1118
1119
1120/*
c5aa993b
JM
1121 ** _tuiAdjustWinHeights().
1122 ** Function to adjust all window heights around the primary
1123 */
c906108c 1124static TuiStatus
eca6576c 1125_tuiAdjustWinHeights (TuiWinInfoPtr primaryWinInfo, int newHeight)
c906108c
SS
1126{
1127 TuiStatus status = TUI_FAILURE;
1128
1129 if (_newHeightOk (primaryWinInfo, newHeight))
1130 {
1131 status = TUI_SUCCESS;
1132 if (newHeight != primaryWinInfo->generic.height)
1133 {
bc712bbf 1134 int diff;
c906108c
SS
1135 TuiWinInfoPtr winInfo;
1136 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
1137 TuiLayoutType curLayout = currentLayout ();
1138
1139 diff = (newHeight - primaryWinInfo->generic.height) * (-1);
1140 if (curLayout == SRC_COMMAND || curLayout == DISASSEM_COMMAND)
1141 {
1142 TuiWinInfoPtr srcWinInfo;
1143
1144 _makeInvisibleAndSetNewHeight (primaryWinInfo, newHeight);
1145 if (primaryWinInfo->generic.type == CMD_WIN)
1146 {
1147 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[0];
1148 srcWinInfo = winInfo;
1149 }
1150 else
1151 {
1152 winInfo = winList[CMD_WIN];
1153 srcWinInfo = primaryWinInfo;
1154 }
1155 _makeInvisibleAndSetNewHeight (winInfo,
1156 winInfo->generic.height + diff);
1157 cmdWin->generic.origin.y = locator->origin.y + 1;
1158 _makeVisibleWithNewHeight (winInfo);
1159 _makeVisibleWithNewHeight (primaryWinInfo);
1160 if (srcWinInfo->generic.contentSize <= 0)
1161 tuiEraseSourceContent (srcWinInfo, EMPTY_SOURCE_PROMPT);
1162 }
1163 else
1164 {
1165 TuiWinInfoPtr firstWin, secondWin;
1166
1167 if (curLayout == SRC_DISASSEM_COMMAND)
1168 {
1169 firstWin = srcWin;
1170 secondWin = disassemWin;
1171 }
1172 else
1173 {
1174 firstWin = dataWin;
1175 secondWin = (TuiWinInfoPtr) (sourceWindows ())->list[0];
1176 }
1177 if (primaryWinInfo == cmdWin)
1178 { /*
c5aa993b
JM
1179 ** Split the change in height accross the 1st & 2nd windows
1180 ** adjusting them as well.
1181 */
c906108c
SS
1182 int firstSplitDiff = diff / 2; /* subtract the locator */
1183 int secondSplitDiff = firstSplitDiff;
1184
1185 if (diff % 2)
1186 {
1187 if (firstWin->generic.height >
1188 secondWin->generic.height)
1189 if (diff < 0)
1190 firstSplitDiff--;
1191 else
1192 firstSplitDiff++;
1193 else
1194 {
1195 if (diff < 0)
1196 secondSplitDiff--;
1197 else
1198 secondSplitDiff++;
1199 }
1200 }
1201 /* make sure that the minimum hieghts are honored */
1202 while ((firstWin->generic.height + firstSplitDiff) < 3)
1203 {
1204 firstSplitDiff++;
1205 secondSplitDiff--;
1206 }
1207 while ((secondWin->generic.height + secondSplitDiff) < 3)
1208 {
1209 secondSplitDiff++;
1210 firstSplitDiff--;
1211 }
1212 _makeInvisibleAndSetNewHeight (
1213 firstWin,
1214 firstWin->generic.height + firstSplitDiff);
1215 secondWin->generic.origin.y = firstWin->generic.height - 1;
1216 _makeInvisibleAndSetNewHeight (
1217 secondWin, secondWin->generic.height + secondSplitDiff);
1218 cmdWin->generic.origin.y = locator->origin.y + 1;
1219 _makeInvisibleAndSetNewHeight (cmdWin, newHeight);
1220 }
1221 else
1222 {
1223 if ((cmdWin->generic.height + diff) < 1)
1224 { /*
c5aa993b
JM
1225 ** If there is no way to increase the command window
1226 ** take real estate from the 1st or 2nd window.
1227 */
c906108c
SS
1228 if ((cmdWin->generic.height + diff) < 1)
1229 {
1230 int i;
1231 for (i = cmdWin->generic.height + diff;
1232 (i < 1); i++)
1233 if (primaryWinInfo == firstWin)
1234 secondWin->generic.height--;
1235 else
1236 firstWin->generic.height--;
1237 }
1238 }
1239 if (primaryWinInfo == firstWin)
1240 _makeInvisibleAndSetNewHeight (firstWin, newHeight);
1241 else
1242 _makeInvisibleAndSetNewHeight (
1243 firstWin,
1244 firstWin->generic.height);
1245 secondWin->generic.origin.y = firstWin->generic.height - 1;
1246 if (primaryWinInfo == secondWin)
1247 _makeInvisibleAndSetNewHeight (secondWin, newHeight);
1248 else
1249 _makeInvisibleAndSetNewHeight (
1250 secondWin, secondWin->generic.height);
1251 cmdWin->generic.origin.y = locator->origin.y + 1;
1252 if ((cmdWin->generic.height + diff) < 1)
1253 _makeInvisibleAndSetNewHeight (cmdWin, 1);
1254 else
1255 _makeInvisibleAndSetNewHeight (
1256 cmdWin, cmdWin->generic.height + diff);
1257 }
1258 _makeVisibleWithNewHeight (cmdWin);
1259 _makeVisibleWithNewHeight (secondWin);
1260 _makeVisibleWithNewHeight (firstWin);
1261 if (firstWin->generic.contentSize <= 0)
1262 tuiEraseSourceContent (firstWin, EMPTY_SOURCE_PROMPT);
1263 if (secondWin->generic.contentSize <= 0)
1264 tuiEraseSourceContent (secondWin, EMPTY_SOURCE_PROMPT);
1265 }
1266 }
1267 }
1268
1269 return status;
1270} /* _tuiAdjustWinHeights */
1271
1272
1273/*
c5aa993b
JM
1274 ** _makeInvisibleAndSetNewHeight().
1275 ** Function make the target window (and auxillary windows associated
1276 ** with the targer) invisible, and set the new height and location.
1277 */
c906108c 1278static void
eca6576c 1279_makeInvisibleAndSetNewHeight (TuiWinInfoPtr winInfo, int height)
c906108c
SS
1280{
1281 int i;
c906108c
SS
1282 TuiGenWinInfoPtr genWinInfo;
1283
1284
1285 m_beInvisible (&winInfo->generic);
1286 winInfo->generic.height = height;
1287 if (height > 1)
1288 winInfo->generic.viewportHeight = height - 1;
1289 else
1290 winInfo->generic.viewportHeight = height;
1291 if (winInfo != cmdWin)
1292 winInfo->generic.viewportHeight--;
1293
1294 /* Now deal with the auxillary windows associated with winInfo */
1295 switch (winInfo->generic.type)
1296 {
1297 case SRC_WIN:
1298 case DISASSEM_WIN:
1299 genWinInfo = winInfo->detail.sourceInfo.executionInfo;
1300 m_beInvisible (genWinInfo);
1301 genWinInfo->height = height;
1302 genWinInfo->origin.y = winInfo->generic.origin.y;
1303 if (height > 1)
1304 genWinInfo->viewportHeight = height - 1;
1305 else
1306 genWinInfo->viewportHeight = height;
1307 if (winInfo != cmdWin)
1308 genWinInfo->viewportHeight--;
1309
1310 if (m_hasLocator (winInfo))
1311 {
1312 genWinInfo = locatorWinInfoPtr ();
1313 m_beInvisible (genWinInfo);
1314 genWinInfo->origin.y = winInfo->generic.origin.y + height;
1315 }
1316 break;
1317 case DATA_WIN:
1318 /* delete all data item windows */
1319 for (i = 0; i < winInfo->generic.contentSize; i++)
1320 {
1321 genWinInfo = (TuiGenWinInfoPtr) & ((TuiWinElementPtr)
1322 winInfo->generic.content[i])->whichElement.dataWindow;
1323 tuiDelwin (genWinInfo->handle);
1324 genWinInfo->handle = (WINDOW *) NULL;
1325 }
1326 break;
1327 default:
1328 break;
1329 }
bc712bbf 1330}
c906108c
SS
1331
1332
1333/*
c5aa993b
JM
1334 ** _makeVisibleWithNewHeight().
1335 ** Function to make the windows with new heights visible.
1336 ** This means re-creating the windows' content since the window
1337 ** had to be destroyed to be made invisible.
1338 */
c906108c 1339static void
eca6576c 1340_makeVisibleWithNewHeight (TuiWinInfoPtr winInfo)
c906108c 1341{
c906108c
SS
1342 struct symtab *s;
1343
1344 m_beVisible (&winInfo->generic);
1345 checkAndDisplayHighlightIfNeeded (winInfo);
1346 switch (winInfo->generic.type)
1347 {
1348 case SRC_WIN:
1349 case DISASSEM_WIN:
1350 freeWinContent (winInfo->detail.sourceInfo.executionInfo);
1351 m_beVisible (winInfo->detail.sourceInfo.executionInfo);
1352 if (winInfo->generic.content != (OpaquePtr) NULL)
1353 {
1354 TuiLineOrAddress lineOrAddr;
1355
1356 if (winInfo->generic.type == SRC_WIN)
1357 lineOrAddr.lineNo =
1358 winInfo->detail.sourceInfo.startLineOrAddr.lineNo;
1359 else
1360 lineOrAddr.addr =
1361 winInfo->detail.sourceInfo.startLineOrAddr.addr;
1362 freeWinContent (&winInfo->generic);
1363 tuiUpdateSourceWindow (winInfo,
a4b99e53 1364 current_source_symtab, lineOrAddr, TRUE);
c906108c
SS
1365 }
1366 else if (selected_frame != (struct frame_info *) NULL)
1367 {
a4b99e53 1368 TuiLineOrAddress line;
c906108c
SS
1369 extern int current_source_line;
1370
1371 s = find_pc_symtab (selected_frame->pc);
1372 if (winInfo->generic.type == SRC_WIN)
a4b99e53 1373 line.lineNo = current_source_line;
c906108c 1374 else
84b1e7c7 1375 {
a4b99e53 1376 find_line_pc (s, current_source_line, &line.addr);
84b1e7c7 1377 }
c906108c
SS
1378 tuiUpdateSourceWindow (winInfo, s, line, TRUE);
1379 }
1380 if (m_hasLocator (winInfo))
1381 {
1382 m_beVisible (locatorWinInfoPtr ());
c906108c
SS
1383 tuiShowLocatorContent ();
1384 }
1385 break;
1386 case DATA_WIN:
1387 tuiDisplayAllData ();
1388 break;
1389 case CMD_WIN:
1390 winInfo->detail.commandInfo.curLine = 0;
1391 winInfo->detail.commandInfo.curch = 0;
1392 wmove (winInfo->generic.handle,
1393 winInfo->detail.commandInfo.curLine,
1394 winInfo->detail.commandInfo.curch);
1395 break;
1396 default:
1397 break;
1398 }
1399
1400 return;
1401} /* _makeVisibleWithNewHeight */
1402
1403
1404static int
eca6576c 1405_newHeightOk (TuiWinInfoPtr primaryWinInfo, int newHeight)
c906108c
SS
1406{
1407 int ok = (newHeight < termHeight ());
1408
1409 if (ok)
1410 {
bc712bbf 1411 int diff;
c906108c
SS
1412 TuiLayoutType curLayout = currentLayout ();
1413
1414 diff = (newHeight - primaryWinInfo->generic.height) * (-1);
1415 if (curLayout == SRC_COMMAND || curLayout == DISASSEM_COMMAND)
1416 {
1417 ok = ((primaryWinInfo->generic.type == CMD_WIN &&
1418 newHeight <= (termHeight () - 4) &&
1419 newHeight >= MIN_CMD_WIN_HEIGHT) ||
1420 (primaryWinInfo->generic.type != CMD_WIN &&
1421 newHeight <= (termHeight () - 2) &&
1422 newHeight >= MIN_WIN_HEIGHT));
1423 if (ok)
1424 { /* check the total height */
1425 TuiWinInfoPtr winInfo;
1426
1427 if (primaryWinInfo == cmdWin)
1428 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[0];
1429 else
1430 winInfo = cmdWin;
1431 ok = ((newHeight +
1432 (winInfo->generic.height + diff)) <= termHeight ());
1433 }
1434 }
1435 else
1436 {
1437 int curTotalHeight, totalHeight, minHeight;
1438 TuiWinInfoPtr firstWin, secondWin;
1439
1440 if (curLayout == SRC_DISASSEM_COMMAND)
1441 {
1442 firstWin = srcWin;
1443 secondWin = disassemWin;
1444 }
1445 else
1446 {
1447 firstWin = dataWin;
1448 secondWin = (TuiWinInfoPtr) (sourceWindows ())->list[0];
1449 }
1450 /*
c5aa993b
JM
1451 ** We could simply add all the heights to obtain the same result
1452 ** but below is more explicit since we subtract 1 for the
1453 ** line that the first and second windows share, and add one
1454 ** for the locator.
1455 */
c906108c
SS
1456 curTotalHeight =
1457 (firstWin->generic.height + secondWin->generic.height - 1)
c5aa993b 1458 + cmdWin->generic.height + 1 /*locator */ ;
c906108c
SS
1459 if (primaryWinInfo == cmdWin)
1460 {
1461 /* locator included since first & second win share a line */
1462 ok = ((firstWin->generic.height +
1463 secondWin->generic.height + diff) >=
1464 (MIN_WIN_HEIGHT * 2) &&
1465 newHeight >= MIN_CMD_WIN_HEIGHT);
1466 if (ok)
1467 {
1468 totalHeight = newHeight + (firstWin->generic.height +
1469 secondWin->generic.height + diff);
1470 minHeight = MIN_CMD_WIN_HEIGHT;
1471 }
1472 }
1473 else
1474 {
1475 minHeight = MIN_WIN_HEIGHT;
1476 /*
c5aa993b
JM
1477 ** First see if we can increase/decrease the command
1478 ** window. And make sure that the command window is
1479 ** at least 1 line
1480 */
c906108c
SS
1481 ok = ((cmdWin->generic.height + diff) > 0);
1482 if (!ok)
1483 { /*
c5aa993b
JM
1484 ** Looks like we have to increase/decrease one of
1485 ** the other windows
1486 */
c906108c
SS
1487 if (primaryWinInfo == firstWin)
1488 ok = (secondWin->generic.height + diff) >= minHeight;
1489 else
1490 ok = (firstWin->generic.height + diff) >= minHeight;
1491 }
1492 if (ok)
1493 {
1494 if (primaryWinInfo == firstWin)
1495 totalHeight = newHeight +
1496 secondWin->generic.height +
1497 cmdWin->generic.height + diff;
1498 else
1499 totalHeight = newHeight +
1500 firstWin->generic.height +
1501 cmdWin->generic.height + diff;
1502 }
1503 }
1504 /*
c5aa993b
JM
1505 ** Now make sure that the proposed total height doesn't exceed
1506 ** the old total height.
1507 */
c906108c
SS
1508 if (ok)
1509 ok = (newHeight >= minHeight && totalHeight <= curTotalHeight);
1510 }
1511 }
1512
1513 return ok;
1514} /* _newHeightOk */
1515
1516
1517/*
c5aa993b
JM
1518 ** _parseScrollingArgs().
1519 */
c906108c 1520static void
eca6576c 1521_parseScrollingArgs (char *arg, TuiWinInfoPtr * winToScroll, int *numToScroll)
c906108c
SS
1522{
1523 if (numToScroll)
1524 *numToScroll = 0;
1525 *winToScroll = tuiWinWithFocus ();
1526
1527 /*
c5aa993b
JM
1528 ** First set up the default window to scroll, in case there is no
1529 ** window name arg
1530 */
c906108c
SS
1531 if (arg != (char *) NULL)
1532 {
1533 char *buf, *bufPtr;
1534
1535 /* process the number of lines to scroll */
1854bb21 1536 buf = bufPtr = xstrdup (arg);
c906108c
SS
1537 if (isdigit (*bufPtr))
1538 {
1539 char *numStr;
1540
1541 numStr = bufPtr;
1542 bufPtr = strchr (bufPtr, ' ');
1543 if (bufPtr != (char *) NULL)
1544 {
1545 *bufPtr = (char) 0;
1546 if (numToScroll)
1547 *numToScroll = atoi (numStr);
1548 bufPtr++;
1549 }
1550 else if (numToScroll)
1551 *numToScroll = atoi (numStr);
1552 }
1553
1554 /* process the window name if one is specified */
1555 if (bufPtr != (char *) NULL)
1556 {
1557 char *wname;
1558 int i;
1559
1560 if (*bufPtr == ' ')
1561 while (*(++bufPtr) == ' ')
1562 ;
1563
1564 if (*bufPtr != (char) 0)
1565 wname = bufPtr;
a4b99e53
SC
1566 else
1567 wname = "?";
1568
c906108c
SS
1569 /* Validate the window name */
1570 for (i = 0; i < strlen (wname); i++)
1571 wname[i] = toupper (wname[i]);
1572 *winToScroll = partialWinByName (wname);
1573
1574 if (*winToScroll == (TuiWinInfoPtr) NULL ||
1575 !(*winToScroll)->generic.isVisible)
1576 warning ("Invalid window specified. \n\
1577The window name specified must be valid and visible.\n");
1578 else if (*winToScroll == cmdWin)
1579 *winToScroll = (TuiWinInfoPtr) (sourceWindows ())->list[0];
1580 }
1581 tuiFree (buf);
1582 }
1583
1584 return;
1585} /* _parseScrollingArgs */
This page took 0.313402 seconds and 4 git commands to generate.