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