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