Remove some TUI static allocations
[deliverable/binutils-gdb.git] / gdb / tui / tui-layout.c
1 /* TUI layout window management.
2
3 Copyright (C) 1998-2019 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 #include "defs.h"
23 #include "arch-utils.h"
24 #include "command.h"
25 #include "symtab.h"
26 #include "frame.h"
27 #include "source.h"
28 #include <ctype.h>
29
30 #include "tui/tui.h"
31 #include "tui/tui-data.h"
32 #include "tui/tui-windata.h"
33 #include "tui/tui-wingeneral.h"
34 #include "tui/tui-stack.h"
35 #include "tui/tui-regs.h"
36 #include "tui/tui-win.h"
37 #include "tui/tui-winsource.h"
38 #include "tui/tui-disasm.h"
39 #include "tui/tui-layout.h"
40 #include "gdb_curses.h"
41
42 /*******************************
43 ** Static Local Decls
44 ********************************/
45 static void show_layout (enum tui_layout_type);
46 static tui_gen_win_info *init_and_make_win (tui_gen_win_info *,
47 enum tui_win_type,
48 int, int, int, int, int);
49 static void show_source_or_disasm_and_command (enum tui_layout_type);
50 static struct tui_win_info *make_source_or_disasm_window (enum tui_win_type,
51 int, int);
52 static struct tui_win_info *make_command_window (int, int);
53 static struct tui_win_info *make_source_window (int, int);
54 static struct tui_win_info *make_disasm_window (int, int);
55 static void make_data_window (struct tui_win_info **, int, int);
56 static void show_source_command (void);
57 static void show_disasm_command (void);
58 static void show_source_disasm_command (void);
59 static void show_data (enum tui_layout_type);
60 static enum tui_layout_type next_layout (void);
61 static enum tui_layout_type prev_layout (void);
62 static void tui_layout_command (const char *, int);
63 static void extract_display_start_addr (struct gdbarch **, CORE_ADDR *);
64
65
66 /***************************************
67 ** DEFINITIONS
68 ***************************************/
69
70 #define LAYOUT_USAGE "Usage: layout prev | next | <layout_name> \n"
71
72 /* Show the screen layout defined. */
73 static void
74 show_layout (enum tui_layout_type layout)
75 {
76 enum tui_layout_type cur_layout = tui_current_layout ();
77
78 if (layout != cur_layout)
79 {
80 /* Since the new layout may cause changes in window size, we
81 should free the content and reallocate on next display of
82 source/asm. */
83 tui_free_all_source_wins_content ();
84 tui_clear_source_windows ();
85 if (layout == SRC_DATA_COMMAND
86 || layout == DISASSEM_DATA_COMMAND)
87 {
88 show_data (layout);
89 tui_refresh_all (tui_win_list);
90 }
91 else
92 {
93 /* First make the current layout be invisible. */
94 tui_make_all_invisible ();
95 tui_make_invisible (tui_locator_win_info_ptr ());
96
97 switch (layout)
98 {
99 /* Now show the new layout. */
100 case SRC_COMMAND:
101 show_source_command ();
102 tui_add_to_source_windows (TUI_SRC_WIN);
103 break;
104 case DISASSEM_COMMAND:
105 show_disasm_command ();
106 tui_add_to_source_windows (TUI_DISASM_WIN);
107 break;
108 case SRC_DISASSEM_COMMAND:
109 show_source_disasm_command ();
110 tui_add_to_source_windows (TUI_SRC_WIN);
111 tui_add_to_source_windows (TUI_DISASM_WIN);
112 break;
113 default:
114 break;
115 }
116 }
117 }
118 }
119
120
121 /* Function to set the layout to SRC_COMMAND, DISASSEM_COMMAND,
122 SRC_DISASSEM_COMMAND, SRC_DATA_COMMAND, or DISASSEM_DATA_COMMAND. */
123 enum tui_status
124 tui_set_layout (enum tui_layout_type layout_type)
125 {
126 enum tui_status status = TUI_SUCCESS;
127
128 if (layout_type != UNDEFINED_LAYOUT)
129 {
130 enum tui_layout_type cur_layout = tui_current_layout (),
131 new_layout = UNDEFINED_LAYOUT;
132 int regs_populate = FALSE;
133 struct gdbarch *gdbarch;
134 CORE_ADDR addr;
135 struct tui_win_info *win_with_focus = tui_win_with_focus ();
136 struct tui_layout_def *layout_def = tui_layout_def ();
137
138 extract_display_start_addr (&gdbarch, &addr);
139
140 new_layout = layout_type;
141
142 regs_populate = (new_layout == SRC_DATA_COMMAND
143 || new_layout == DISASSEM_DATA_COMMAND);
144 if (new_layout != cur_layout)
145 {
146 show_layout (new_layout);
147
148 /* Now determine where focus should be. */
149 if (win_with_focus != TUI_CMD_WIN)
150 {
151 switch (new_layout)
152 {
153 case SRC_COMMAND:
154 tui_set_win_focus_to (TUI_SRC_WIN);
155 layout_def->display_mode = SRC_WIN;
156 layout_def->split = FALSE;
157 break;
158 case DISASSEM_COMMAND:
159 /* The previous layout was not showing code.
160 This can happen if there is no source
161 available:
162
163 1. if the source file is in another dir OR
164 2. if target was compiled without -g
165 We still want to show the assembly though! */
166
167 tui_get_begin_asm_address (&gdbarch, &addr);
168 tui_set_win_focus_to (TUI_DISASM_WIN);
169 layout_def->display_mode = DISASSEM_WIN;
170 layout_def->split = FALSE;
171 break;
172 case SRC_DISASSEM_COMMAND:
173 /* The previous layout was not showing code.
174 This can happen if there is no source
175 available:
176
177 1. if the source file is in another dir OR
178 2. if target was compiled without -g
179 We still want to show the assembly though! */
180
181 tui_get_begin_asm_address (&gdbarch, &addr);
182 if (win_with_focus == TUI_SRC_WIN)
183 tui_set_win_focus_to (TUI_SRC_WIN);
184 else
185 tui_set_win_focus_to (TUI_DISASM_WIN);
186 layout_def->split = TRUE;
187 break;
188 case SRC_DATA_COMMAND:
189 if (win_with_focus != TUI_DATA_WIN)
190 tui_set_win_focus_to (TUI_SRC_WIN);
191 else
192 tui_set_win_focus_to (TUI_DATA_WIN);
193 layout_def->display_mode = SRC_WIN;
194 layout_def->split = FALSE;
195 break;
196 case DISASSEM_DATA_COMMAND:
197 /* The previous layout was not showing code.
198 This can happen if there is no source
199 available:
200
201 1. if the source file is in another dir OR
202 2. if target was compiled without -g
203 We still want to show the assembly though! */
204
205 tui_get_begin_asm_address (&gdbarch, &addr);
206 if (win_with_focus != TUI_DATA_WIN)
207 tui_set_win_focus_to (TUI_DISASM_WIN);
208 else
209 tui_set_win_focus_to (TUI_DATA_WIN);
210 layout_def->display_mode = DISASSEM_WIN;
211 layout_def->split = FALSE;
212 break;
213 default:
214 break;
215 }
216 }
217 /*
218 * Now update the window content.
219 */
220 if (!regs_populate
221 && (new_layout == SRC_DATA_COMMAND
222 || new_layout == DISASSEM_DATA_COMMAND))
223 tui_display_all_data ();
224
225 tui_update_source_windows_with_addr (gdbarch, addr);
226
227 if (regs_populate)
228 tui_show_registers (TUI_DATA_WIN->current_group);
229 }
230 }
231 else
232 status = TUI_FAILURE;
233
234 return status;
235 }
236
237 /* Add the specified window to the layout in a logical way. This
238 means setting up the most logical layout given the window to be
239 added. */
240 void
241 tui_add_win_to_layout (enum tui_win_type type)
242 {
243 enum tui_layout_type cur_layout = tui_current_layout ();
244
245 switch (type)
246 {
247 case SRC_WIN:
248 if (cur_layout != SRC_COMMAND
249 && cur_layout != SRC_DISASSEM_COMMAND
250 && cur_layout != SRC_DATA_COMMAND)
251 {
252 tui_clear_source_windows_detail ();
253 if (cur_layout == DISASSEM_DATA_COMMAND)
254 show_layout (SRC_DATA_COMMAND);
255 else
256 show_layout (SRC_COMMAND);
257 }
258 break;
259 case DISASSEM_WIN:
260 if (cur_layout != DISASSEM_COMMAND
261 && cur_layout != SRC_DISASSEM_COMMAND
262 && cur_layout != DISASSEM_DATA_COMMAND)
263 {
264 tui_clear_source_windows_detail ();
265 if (cur_layout == SRC_DATA_COMMAND)
266 show_layout (DISASSEM_DATA_COMMAND);
267 else
268 show_layout (DISASSEM_COMMAND);
269 }
270 break;
271 case DATA_WIN:
272 if (cur_layout != SRC_DATA_COMMAND
273 && cur_layout != DISASSEM_DATA_COMMAND)
274 {
275 if (cur_layout == DISASSEM_COMMAND)
276 show_layout (DISASSEM_DATA_COMMAND);
277 else
278 show_layout (SRC_DATA_COMMAND);
279 }
280 break;
281 default:
282 break;
283 }
284 }
285
286
287 /* Answer the height of a window. If it hasn't been created yet,
288 answer what the height of a window would be based upon its type and
289 the layout. */
290 int
291 tui_default_win_height (enum tui_win_type type,
292 enum tui_layout_type layout)
293 {
294 int h;
295
296 if (tui_win_list[type] != NULL)
297 h = tui_win_list[type]->height;
298 else
299 {
300 switch (layout)
301 {
302 case SRC_COMMAND:
303 case DISASSEM_COMMAND:
304 if (TUI_CMD_WIN == NULL)
305 h = tui_term_height () / 2;
306 else
307 h = tui_term_height () - TUI_CMD_WIN->height;
308 break;
309 case SRC_DISASSEM_COMMAND:
310 case SRC_DATA_COMMAND:
311 case DISASSEM_DATA_COMMAND:
312 if (TUI_CMD_WIN == NULL)
313 h = tui_term_height () / 3;
314 else
315 h = (tui_term_height () - TUI_CMD_WIN->height) / 2;
316 break;
317 default:
318 h = 0;
319 break;
320 }
321 }
322
323 return h;
324 }
325
326
327 /* Answer the height of a window. If it hasn't been created yet,
328 answer what the height of a window would be based upon its type and
329 the layout. */
330 int
331 tui_default_win_viewport_height (enum tui_win_type type,
332 enum tui_layout_type layout)
333 {
334 int h;
335
336 h = tui_default_win_height (type, layout);
337
338 if (tui_win_list[type] == TUI_CMD_WIN)
339 h -= 1;
340 else
341 h -= 2;
342
343 return h;
344 }
345
346 /* Complete possible layout names. TEXT is the complete text entered so
347 far, WORD is the word currently being completed. */
348
349 static void
350 layout_completer (struct cmd_list_element *ignore,
351 completion_tracker &tracker,
352 const char *text, const char *word)
353 {
354 static const char *layout_names [] =
355 { "src", "asm", "split", "regs", "next", "prev", NULL };
356
357 complete_on_enum (tracker, layout_names, text, word);
358 }
359
360 /* Function to initialize gdb commands, for tui window layout
361 manipulation. */
362
363 void
364 _initialize_tui_layout (void)
365 {
366 struct cmd_list_element *cmd;
367
368 cmd = add_com ("layout", class_tui, tui_layout_command, _("\
369 Change the layout of windows.\n\
370 Usage: layout prev | next | LAYOUT-NAME\n\
371 Layout names are:\n\
372 src : Displays source and command windows.\n\
373 asm : Displays disassembly and command windows.\n\
374 split : Displays source, disassembly and command windows.\n\
375 regs : Displays register window. If existing layout\n\
376 is source/command or assembly/command, the \n\
377 register window is displayed. If the\n\
378 source/assembly/command (split) is displayed, \n\
379 the register window is displayed with \n\
380 the window that has current logical focus."));
381 set_cmd_completer (cmd, layout_completer);
382 }
383
384
385 /*************************
386 ** STATIC LOCAL FUNCTIONS
387 **************************/
388
389
390 /* Function to set the layout to SRC, ASM, SPLIT, NEXT, PREV, DATA, or
391 REGS. */
392 enum tui_status
393 tui_set_layout_by_name (const char *layout_name)
394 {
395 enum tui_status status = TUI_SUCCESS;
396
397 if (layout_name != NULL)
398 {
399 int i;
400 enum tui_layout_type new_layout = UNDEFINED_LAYOUT;
401 enum tui_layout_type cur_layout = tui_current_layout ();
402
403 std::string copy = layout_name;
404 for (i = 0; i < copy.size (); i++)
405 copy[i] = toupper (copy[i]);
406 const char *buf_ptr = copy.c_str ();
407
408 /* First check for ambiguous input. */
409 if (strlen (buf_ptr) <= 1 && *buf_ptr == 'S')
410 {
411 warning (_("Ambiguous command input."));
412 status = TUI_FAILURE;
413 }
414 else
415 {
416 if (subset_compare (buf_ptr, "SRC"))
417 new_layout = SRC_COMMAND;
418 else if (subset_compare (buf_ptr, "ASM"))
419 new_layout = DISASSEM_COMMAND;
420 else if (subset_compare (buf_ptr, "SPLIT"))
421 new_layout = SRC_DISASSEM_COMMAND;
422 else if (subset_compare (buf_ptr, "REGS"))
423 {
424 if (cur_layout == SRC_COMMAND
425 || cur_layout == SRC_DATA_COMMAND)
426 new_layout = SRC_DATA_COMMAND;
427 else
428 new_layout = DISASSEM_DATA_COMMAND;
429 }
430 else if (subset_compare (buf_ptr, "NEXT"))
431 new_layout = next_layout ();
432 else if (subset_compare (buf_ptr, "PREV"))
433 new_layout = prev_layout ();
434 else
435 status = TUI_FAILURE;
436
437 if (status == TUI_SUCCESS)
438 {
439 /* Make sure the curses mode is enabled. */
440 tui_enable ();
441 tui_set_layout (new_layout);
442 }
443 }
444 }
445 else
446 status = TUI_FAILURE;
447
448 return status;
449 }
450
451
452 static void
453 extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p)
454 {
455 enum tui_layout_type cur_layout = tui_current_layout ();
456 struct gdbarch *gdbarch = get_current_arch ();
457 CORE_ADDR addr;
458 CORE_ADDR pc;
459 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
460
461 switch (cur_layout)
462 {
463 case SRC_COMMAND:
464 case SRC_DATA_COMMAND:
465 gdbarch = TUI_SRC_WIN->gdbarch;
466 find_line_pc (cursal.symtab,
467 TUI_SRC_WIN->start_line_or_addr.u.line_no,
468 &pc);
469 addr = pc;
470 break;
471 case DISASSEM_COMMAND:
472 case SRC_DISASSEM_COMMAND:
473 case DISASSEM_DATA_COMMAND:
474 gdbarch = TUI_DISASM_WIN->gdbarch;
475 addr = TUI_DISASM_WIN->start_line_or_addr.u.addr;
476 break;
477 default:
478 addr = 0;
479 break;
480 }
481
482 *gdbarch_p = gdbarch;
483 *addr_p = addr;
484 }
485
486
487 static void
488 tui_layout_command (const char *arg, int from_tty)
489 {
490 /* Switch to the selected layout. */
491 if (tui_set_layout_by_name (arg) != TUI_SUCCESS)
492 warning (_("Invalid layout specified.\n%s"), LAYOUT_USAGE);
493 }
494
495 /* Answer the previous layout to cycle to. */
496 static enum tui_layout_type
497 next_layout (void)
498 {
499 int new_layout;
500
501 new_layout = tui_current_layout ();
502 if (new_layout == UNDEFINED_LAYOUT)
503 new_layout = SRC_COMMAND;
504 else
505 {
506 new_layout++;
507 if (new_layout == UNDEFINED_LAYOUT)
508 new_layout = SRC_COMMAND;
509 }
510
511 return (enum tui_layout_type) new_layout;
512 }
513
514
515 /* Answer the next layout to cycle to. */
516 static enum tui_layout_type
517 prev_layout (void)
518 {
519 int new_layout;
520
521 new_layout = tui_current_layout ();
522 if (new_layout == SRC_COMMAND)
523 new_layout = DISASSEM_DATA_COMMAND;
524 else
525 {
526 new_layout--;
527 if (new_layout == UNDEFINED_LAYOUT)
528 new_layout = DISASSEM_DATA_COMMAND;
529 }
530
531 return (enum tui_layout_type) new_layout;
532 }
533
534
535
536 static struct tui_win_info *
537 make_command_window (int height, int origin_y)
538 {
539 struct tui_win_info *result
540 = (struct tui_win_info *) init_and_make_win (NULL,
541 CMD_WIN,
542 height,
543 tui_term_width (),
544 0,
545 origin_y,
546 DONT_BOX_WINDOW);
547 return result;
548 }
549
550
551 /* make_source_window().
552 */
553 static struct tui_win_info *
554 make_source_window (int height, int origin_y)
555 {
556 return make_source_or_disasm_window (SRC_WIN, height, origin_y);
557 } /* make_source_window */
558
559
560 /* make_disasm_window().
561 */
562 static struct tui_win_info *
563 make_disasm_window (int height, int origin_y)
564 {
565 return make_source_or_disasm_window (DISASSEM_WIN, height, origin_y);
566 } /* make_disasm_window */
567
568
569 static void
570 make_data_window (struct tui_win_info **win_info_ptr,
571 int height, int origin_y)
572 {
573 *win_info_ptr
574 = (struct tui_win_info *) init_and_make_win (*win_info_ptr,
575 DATA_WIN,
576 height,
577 tui_term_width (),
578 0,
579 origin_y,
580 BOX_WINDOW);
581 }
582
583
584
585 /* Show the Source/Command layout. */
586 static void
587 show_source_command (void)
588 {
589 show_source_or_disasm_and_command (SRC_COMMAND);
590 }
591
592
593 /* Show the Dissassem/Command layout. */
594 static void
595 show_disasm_command (void)
596 {
597 show_source_or_disasm_and_command (DISASSEM_COMMAND);
598 }
599
600
601 /* Show the Source/Disassem/Command layout. */
602 static void
603 show_source_disasm_command (void)
604 {
605 if (tui_current_layout () != SRC_DISASSEM_COMMAND)
606 {
607 int cmd_height, src_height, asm_height;
608
609 if (TUI_CMD_WIN != NULL)
610 cmd_height = TUI_CMD_WIN->height;
611 else
612 cmd_height = tui_term_height () / 3;
613
614 src_height = (tui_term_height () - cmd_height) / 2;
615 asm_height = tui_term_height () - (src_height + cmd_height);
616
617 if (TUI_SRC_WIN == NULL)
618 tui_win_list[SRC_WIN] = make_source_window (src_height, 0);
619 else
620 {
621 TUI_SRC_WIN->reset (TUI_SRC_WIN->type,
622 src_height,
623 TUI_SRC_WIN->width,
624 TUI_SRC_WIN->execution_info->width,
625 0);
626 TUI_SRC_WIN->execution_info->reset (EXEC_INFO_WIN,
627 src_height,
628 3,
629 0,
630 0);
631 tui_make_visible (TUI_SRC_WIN);
632 tui_make_visible (TUI_SRC_WIN->execution_info);
633 TUI_SRC_WIN->m_has_locator = false;
634 }
635
636 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
637
638 tui_show_source_content (TUI_SRC_WIN);
639 if (TUI_DISASM_WIN == NULL)
640 {
641 tui_win_list[DISASSEM_WIN]
642 = make_disasm_window (asm_height, src_height - 1);
643 locator
644 = init_and_make_win (locator,
645 LOCATOR_WIN,
646 2 /* 1 */ ,
647 tui_term_width (),
648 0,
649 (src_height + asm_height) - 1,
650 DONT_BOX_WINDOW);
651 }
652 else
653 {
654 locator->reset (LOCATOR_WIN,
655 2 /* 1 */ ,
656 tui_term_width (),
657 0,
658 (src_height + asm_height) - 1);
659 TUI_DISASM_WIN->m_has_locator = true;
660 TUI_DISASM_WIN->reset (TUI_DISASM_WIN->type,
661 asm_height,
662 TUI_DISASM_WIN->width,
663 TUI_DISASM_WIN->execution_info->width,
664 src_height - 1);
665 TUI_DISASM_WIN->execution_info->reset (EXEC_INFO_WIN,
666 asm_height,
667 3,
668 0,
669 src_height - 1);
670 tui_make_visible (TUI_DISASM_WIN);
671 tui_make_visible (TUI_DISASM_WIN->execution_info);
672 }
673 TUI_SRC_WIN->m_has_locator = false;
674 TUI_DISASM_WIN->m_has_locator = true;
675 tui_make_visible (locator);
676 tui_show_locator_content ();
677 tui_show_source_content (TUI_DISASM_WIN);
678
679 if (TUI_CMD_WIN == NULL)
680 tui_win_list[CMD_WIN]
681 = make_command_window (cmd_height, tui_term_height () - cmd_height);
682 else
683 {
684 TUI_CMD_WIN->reset (TUI_CMD_WIN->type,
685 TUI_CMD_WIN->height,
686 TUI_CMD_WIN->width,
687 0,
688 TUI_CMD_WIN->origin.y);
689 tui_make_visible (TUI_CMD_WIN);
690 }
691 TUI_CMD_WIN->refresh_window ();
692 tui_set_current_layout_to (SRC_DISASSEM_COMMAND);
693 }
694 }
695
696
697 /* Show the Source/Data/Command or the Dissassembly/Data/Command
698 layout. */
699 static void
700 show_data (enum tui_layout_type new_layout)
701 {
702 int total_height = (tui_term_height () - TUI_CMD_WIN->height);
703 int src_height, data_height;
704 enum tui_win_type win_type;
705 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
706
707
708 data_height = total_height / 2;
709 src_height = total_height - data_height;
710 tui_make_all_invisible ();
711 tui_make_invisible (locator);
712 make_data_window (&tui_win_list[DATA_WIN], data_height, 0);
713 if (new_layout == SRC_DATA_COMMAND)
714 win_type = SRC_WIN;
715 else
716 win_type = DISASSEM_WIN;
717
718 tui_source_window_base *base;
719 if (tui_win_list[win_type] == NULL)
720 {
721 if (win_type == SRC_WIN)
722 tui_win_list[win_type]
723 = make_source_window (src_height, data_height - 1);
724 else
725 tui_win_list[win_type]
726 = make_disasm_window (src_height, data_height - 1);
727 locator
728 = init_and_make_win (locator,
729 LOCATOR_WIN,
730 2 /* 1 */ ,
731 tui_term_width (),
732 0,
733 total_height - 1,
734 DONT_BOX_WINDOW);
735 base = (tui_source_window_base *) tui_win_list[win_type];
736 }
737 else
738 {
739 base = (tui_source_window_base *) tui_win_list[win_type];
740 tui_win_list[win_type]->reset (tui_win_list[win_type]->type,
741 src_height,
742 tui_win_list[win_type]->width,
743 base->execution_info->width,
744 data_height - 1);
745 base->execution_info->reset (EXEC_INFO_WIN,
746 src_height,
747 3,
748 0,
749 data_height - 1);
750 tui_make_visible (tui_win_list[win_type]);
751 tui_make_visible (base->execution_info);
752 locator->reset (LOCATOR_WIN,
753 2 /* 1 */ ,
754 tui_term_width (),
755 0,
756 total_height - 1);
757 }
758 base->m_has_locator = true;
759 tui_make_visible (locator);
760 tui_show_locator_content ();
761 tui_add_to_source_windows
762 ((tui_source_window_base *) tui_win_list[win_type]);
763 tui_set_current_layout_to (new_layout);
764 }
765
766 void
767 tui_gen_win_info::reset (enum tui_win_type win_type,
768 int height_, int width_,
769 int origin_x_, int origin_y_)
770 {
771 int h = height_;
772
773 gdb_assert (type == win_type);
774
775 width = width_;
776 height = h;
777 if (h > 1)
778 {
779 viewport_height = h - 1;
780 if (type != CMD_WIN)
781 viewport_height--;
782 }
783 else
784 viewport_height = 1;
785 origin.x = origin_x_;
786 origin.y = origin_y_;
787 }
788
789 /* init_and_make_win().
790 */
791 static tui_gen_win_info *
792 init_and_make_win (tui_gen_win_info *win_info,
793 enum tui_win_type win_type,
794 int height, int width,
795 int origin_x, int origin_y,
796 int box_it)
797 {
798 if (win_info == NULL)
799 {
800 if (tui_win_is_auxillary (win_type))
801 win_info = new tui_gen_win_info (win_type);
802 else
803 win_info = tui_alloc_win_info (win_type);
804 }
805
806 win_info->reset (win_type, height, width, origin_x, origin_y);
807 tui_make_window (win_info, box_it);
808
809 return win_info;
810 }
811
812
813 static struct tui_win_info *
814 make_source_or_disasm_window (enum tui_win_type type,
815 int height, int origin_y)
816 {
817 struct tui_gen_win_info *execution_info
818 = init_and_make_win (nullptr,
819 EXEC_INFO_WIN,
820 height,
821 3,
822 0,
823 origin_y,
824 DONT_BOX_WINDOW);
825
826 /* Now create the source window. */
827 struct tui_source_window_base *result
828 = ((struct tui_source_window_base *)
829 init_and_make_win (NULL,
830 type,
831 height,
832 tui_term_width () - execution_info->width,
833 execution_info->width,
834 origin_y,
835 BOX_WINDOW));
836 result->execution_info = execution_info;
837 return result;
838 }
839
840
841 /* Show the Source/Command or the Disassem layout. */
842 static void
843 show_source_or_disasm_and_command (enum tui_layout_type layout_type)
844 {
845 if (tui_current_layout () != layout_type)
846 {
847 struct tui_win_info **win_info_ptr;
848 int src_height, cmd_height;
849 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
850
851 if (TUI_CMD_WIN != NULL)
852 cmd_height = TUI_CMD_WIN->height;
853 else
854 cmd_height = tui_term_height () / 3;
855 src_height = tui_term_height () - cmd_height;
856
857 if (layout_type == SRC_COMMAND)
858 win_info_ptr = &tui_win_list[SRC_WIN];
859 else
860 win_info_ptr = &tui_win_list[DISASSEM_WIN];
861
862 tui_source_window_base *base;
863 if ((*win_info_ptr) == NULL)
864 {
865 if (layout_type == SRC_COMMAND)
866 *win_info_ptr = make_source_window (src_height - 1, 0);
867 else
868 *win_info_ptr = make_disasm_window (src_height - 1, 0);
869 locator
870 = init_and_make_win (locator,
871 LOCATOR_WIN,
872 2 /* 1 */ ,
873 tui_term_width (),
874 0,
875 src_height - 1,
876 DONT_BOX_WINDOW);
877 base = (tui_source_window_base *) *win_info_ptr;
878 }
879 else
880 {
881 base = (tui_source_window_base *) *win_info_ptr;
882 locator->reset (LOCATOR_WIN,
883 2 /* 1 */ ,
884 tui_term_width (),
885 0,
886 src_height - 1);
887 base->m_has_locator = true;
888 (*win_info_ptr)->reset ((*win_info_ptr)->type,
889 src_height - 1,
890 (*win_info_ptr)->width,
891 base->execution_info->width,
892 0);
893 base->execution_info->reset (EXEC_INFO_WIN,
894 src_height - 1,
895 3,
896 0,
897 0);
898 tui_make_visible (*win_info_ptr);
899 tui_make_visible (base->execution_info);
900 }
901
902 base->m_has_locator = true;
903 tui_make_visible (locator);
904 tui_show_locator_content ();
905 tui_show_source_content (*win_info_ptr);
906
907 if (TUI_CMD_WIN == NULL)
908 {
909 tui_win_list[CMD_WIN] = make_command_window (cmd_height,
910 src_height);
911 TUI_CMD_WIN->refresh_window ();
912 }
913 else
914 {
915 TUI_CMD_WIN->reset (TUI_CMD_WIN->type,
916 TUI_CMD_WIN->height,
917 TUI_CMD_WIN->width,
918 TUI_CMD_WIN->origin.x,
919 TUI_CMD_WIN->origin.y);
920 tui_make_visible (TUI_CMD_WIN);
921 }
922 tui_set_current_layout_to (layout_type);
923 }
924 }
This page took 0.050862 seconds and 4 git commands to generate.