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