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