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