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