Introduce function for directly updating GDB's screen dimensions
[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
AC
124/* Function to set the layout to SRC_COMMAND, DISASSEM_COMMAND,
125 SRC_DISASSEM_COMMAND, SRC_DATA_COMMAND, or DISASSEM_DATA_COMMAND.
126 If the layout is SRC_DATA_COMMAND, DISASSEM_DATA_COMMAND, or
127 UNDEFINED_LAYOUT, then the data window is populated according to
6d012f14 128 regs_display_type. */
080ce8c0 129enum tui_status
6ba8e26f 130tui_set_layout (enum tui_layout_type layout_type,
6d012f14 131 enum tui_register_display_type regs_display_type)
c906108c 132{
22940a24 133 enum tui_status status = TUI_SUCCESS;
c906108c 134
e5908723
MS
135 if (layout_type != UNDEFINED_LAYOUT
136 || regs_display_type != TUI_UNDEFINED_REGS)
c906108c 137 {
e5908723
MS
138 enum tui_layout_type cur_layout = tui_current_layout (),
139 new_layout = UNDEFINED_LAYOUT;
6ba8e26f 140 int regs_populate = FALSE;
13274fc3
UW
141 struct gdbarch *gdbarch;
142 CORE_ADDR addr;
5b6fe301
MS
143 struct tui_win_info *win_with_focus = tui_win_with_focus ();
144 struct tui_layout_def *layout_def = tui_layout_def ();
c906108c 145
13274fc3 146 extract_display_start_addr (&gdbarch, &addr);
c906108c 147
e5908723
MS
148 if (layout_type == UNDEFINED_LAYOUT
149 && regs_display_type != TUI_UNDEFINED_REGS)
c906108c 150 {
6ba8e26f
AC
151 if (cur_layout == SRC_DISASSEM_COMMAND)
152 new_layout = DISASSEM_DATA_COMMAND;
e5908723
MS
153 else if (cur_layout == SRC_COMMAND
154 || cur_layout == SRC_DATA_COMMAND)
6ba8e26f 155 new_layout = SRC_DATA_COMMAND;
e5908723
MS
156 else if (cur_layout == DISASSEM_COMMAND
157 || cur_layout == DISASSEM_DATA_COMMAND)
6ba8e26f 158 new_layout = DISASSEM_DATA_COMMAND;
c906108c
SS
159 }
160 else
6ba8e26f 161 new_layout = layout_type;
c906108c 162
e5908723
MS
163 regs_populate = (new_layout == SRC_DATA_COMMAND
164 || new_layout == DISASSEM_DATA_COMMAND
165 || regs_display_type != TUI_UNDEFINED_REGS);
166 if (new_layout != cur_layout
167 || regs_display_type != TUI_UNDEFINED_REGS)
c906108c 168 {
6ba8e26f 169 if (new_layout != cur_layout)
c906108c 170 {
6ba8e26f 171 show_layout (new_layout);
ef5eab5a
MS
172
173 /* Now determine where focus should be. */
6ba8e26f 174 if (win_with_focus != TUI_CMD_WIN)
c906108c 175 {
6ba8e26f 176 switch (new_layout)
c906108c
SS
177 {
178 case SRC_COMMAND:
6d012f14 179 tui_set_win_focus_to (TUI_SRC_WIN);
6ba8e26f
AC
180 layout_def->display_mode = SRC_WIN;
181 layout_def->split = FALSE;
c906108c
SS
182 break;
183 case DISASSEM_COMMAND:
ef5eab5a
MS
184 /* The previous layout was not showing code.
185 This can happen if there is no source
186 available:
187
188 1. if the source file is in another dir OR
189 2. if target was compiled without -g
190 We still want to show the assembly though! */
191
13274fc3 192 tui_get_begin_asm_address (&gdbarch, &addr);
6d012f14 193 tui_set_win_focus_to (TUI_DISASM_WIN);
6ba8e26f
AC
194 layout_def->display_mode = DISASSEM_WIN;
195 layout_def->split = FALSE;
c906108c
SS
196 break;
197 case SRC_DISASSEM_COMMAND:
ef5eab5a
MS
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
13274fc3 206 tui_get_begin_asm_address (&gdbarch, &addr);
6ba8e26f 207 if (win_with_focus == TUI_SRC_WIN)
6d012f14 208 tui_set_win_focus_to (TUI_SRC_WIN);
c906108c 209 else
6d012f14 210 tui_set_win_focus_to (TUI_DISASM_WIN);
6ba8e26f 211 layout_def->split = TRUE;
c906108c
SS
212 break;
213 case SRC_DATA_COMMAND:
6ba8e26f 214 if (win_with_focus != TUI_DATA_WIN)
6d012f14 215 tui_set_win_focus_to (TUI_SRC_WIN);
c906108c 216 else
6d012f14 217 tui_set_win_focus_to (TUI_DATA_WIN);
6ba8e26f
AC
218 layout_def->display_mode = SRC_WIN;
219 layout_def->split = FALSE;
c906108c
SS
220 break;
221 case DISASSEM_DATA_COMMAND:
ef5eab5a
MS
222 /* The previous layout was not showing code.
223 This can happen if there is no source
224 available:
225
226 1. if the source file is in another dir OR
227 2. if target was compiled without -g
228 We still want to show the assembly though! */
229
13274fc3 230 tui_get_begin_asm_address (&gdbarch, &addr);
6ba8e26f 231 if (win_with_focus != TUI_DATA_WIN)
6d012f14 232 tui_set_win_focus_to (TUI_DISASM_WIN);
c906108c 233 else
6d012f14 234 tui_set_win_focus_to (TUI_DATA_WIN);
6ba8e26f
AC
235 layout_def->display_mode = DISASSEM_WIN;
236 layout_def->split = FALSE;
c906108c
SS
237 break;
238 default:
239 break;
240 }
241 }
c906108c 242 /*
3e40160c 243 * Now update the window content.
c5aa993b 244 */
e5908723
MS
245 if (!regs_populate
246 && (new_layout == SRC_DATA_COMMAND
247 || new_layout == DISASSEM_DATA_COMMAND))
edae1ccf 248 tui_display_all_data ();
c906108c 249
13274fc3 250 tui_update_source_windows_with_addr (gdbarch, addr);
c906108c 251 }
6ba8e26f 252 if (regs_populate)
c906108c 253 {
10f59415 254 tui_show_registers (TUI_DATA_WIN->detail.data_display_info.current_group);
c906108c
SS
255 }
256 }
257 }
258 else
259 status = TUI_FAILURE;
260
261 return status;
bc712bbf 262}
c906108c 263
080ce8c0
AC
264/* Add the specified window to the layout in a logical way. This
265 means setting up the most logical layout given the window to be
266 added. */
c906108c 267void
080ce8c0 268tui_add_win_to_layout (enum tui_win_type type)
c906108c 269{
6ba8e26f 270 enum tui_layout_type cur_layout = tui_current_layout ();
c906108c
SS
271
272 switch (type)
273 {
274 case SRC_WIN:
e5908723
MS
275 if (cur_layout != SRC_COMMAND
276 && cur_layout != SRC_DISASSEM_COMMAND
277 && cur_layout != SRC_DATA_COMMAND)
c906108c 278 {
dd1abb8c 279 tui_clear_source_windows_detail ();
6ba8e26f
AC
280 if (cur_layout == DISASSEM_DATA_COMMAND)
281 show_layout (SRC_DATA_COMMAND);
c906108c 282 else
6ba8e26f 283 show_layout (SRC_COMMAND);
c906108c
SS
284 }
285 break;
286 case DISASSEM_WIN:
e5908723
MS
287 if (cur_layout != DISASSEM_COMMAND
288 && cur_layout != SRC_DISASSEM_COMMAND
289 && cur_layout != DISASSEM_DATA_COMMAND)
c906108c 290 {
dd1abb8c 291 tui_clear_source_windows_detail ();
6ba8e26f
AC
292 if (cur_layout == SRC_DATA_COMMAND)
293 show_layout (DISASSEM_DATA_COMMAND);
c906108c 294 else
6ba8e26f 295 show_layout (DISASSEM_COMMAND);
c906108c
SS
296 }
297 break;
298 case DATA_WIN:
e5908723
MS
299 if (cur_layout != SRC_DATA_COMMAND
300 && cur_layout != DISASSEM_DATA_COMMAND)
c906108c 301 {
6ba8e26f
AC
302 if (cur_layout == DISASSEM_COMMAND)
303 show_layout (DISASSEM_DATA_COMMAND);
c906108c 304 else
6ba8e26f 305 show_layout (SRC_DATA_COMMAND);
c906108c
SS
306 }
307 break;
308 default:
309 break;
310 }
6ba8e26f 311}
c906108c
SS
312
313
6ba8e26f
AC
314/* Answer the height of a window. If it hasn't been created yet,
315 answer what the height of a window would be based upon its type and
316 the layout. */
c906108c 317int
08ef48c5
MS
318tui_default_win_height (enum tui_win_type type,
319 enum tui_layout_type layout)
c906108c
SS
320{
321 int h;
322
6d012f14
AC
323 if (tui_win_list[type] != (struct tui_win_info *) NULL)
324 h = tui_win_list[type]->generic.height;
c906108c
SS
325 else
326 {
327 switch (layout)
328 {
329 case SRC_COMMAND:
330 case DISASSEM_COMMAND:
6d012f14 331 if (TUI_CMD_WIN == NULL)
dd1abb8c 332 h = tui_term_height () / 2;
c906108c 333 else
6d012f14 334 h = tui_term_height () - TUI_CMD_WIN->generic.height;
c906108c
SS
335 break;
336 case SRC_DISASSEM_COMMAND:
337 case SRC_DATA_COMMAND:
338 case DISASSEM_DATA_COMMAND:
6d012f14 339 if (TUI_CMD_WIN == NULL)
dd1abb8c 340 h = tui_term_height () / 3;
c906108c 341 else
6d012f14 342 h = (tui_term_height () - TUI_CMD_WIN->generic.height) / 2;
c906108c
SS
343 break;
344 default:
345 h = 0;
346 break;
347 }
348 }
349
350 return h;
6ba8e26f 351}
c906108c
SS
352
353
080ce8c0
AC
354/* Answer the height of a window. If it hasn't been created yet,
355 answer what the height of a window would be based upon its type and
356 the layout. */
c906108c 357int
080ce8c0
AC
358tui_default_win_viewport_height (enum tui_win_type type,
359 enum tui_layout_type layout)
c906108c
SS
360{
361 int h;
362
6ba8e26f 363 h = tui_default_win_height (type, layout);
c906108c 364
6d012f14 365 if (tui_win_list[type] == TUI_CMD_WIN)
c906108c
SS
366 h -= 1;
367 else
368 h -= 2;
369
370 return h;
6ba8e26f 371}
c906108c
SS
372
373
6ba8e26f
AC
374/* Function to initialize gdb commands, for tui window layout
375 manipulation. */
2c0b251b
PA
376
377/* Provide a prototype to silence -Wmissing-prototypes. */
378extern initialize_file_ftype _initialize_tui_layout;
379
c906108c 380void
6ba8e26f 381_initialize_tui_layout (void)
c906108c 382{
1bedd215
AC
383 add_com ("layout", class_tui, tui_layout_command, _("\
384Change the layout of windows.\n\
c906108c
SS
385Usage: layout prev | next | <layout_name> \n\
386Layout names are:\n\
387 src : Displays source and command windows.\n\
388 asm : Displays disassembly and command windows.\n\
389 split : Displays source, disassembly and command windows.\n\
390 regs : Displays register window. If existing layout\n\
391 is source/command or assembly/command, the \n\
392 register window is displayed. If the\n\
393 source/assembly/command (split) is displayed, \n\
394 the register window is displayed with \n\
1bedd215 395 the window that has current logical focus.\n"));
41783295 396}
c906108c
SS
397
398
399/*************************
400** STATIC LOCAL FUNCTIONS
401**************************/
402
403
6ba8e26f
AC
404/* Function to set the layout to SRC, ASM, SPLIT, NEXT, PREV, DATA,
405 REGS, $REGS, $GREGS, $FREGS, $SREGS. */
22940a24 406enum tui_status
6ba8e26f 407tui_set_layout_for_display_command (const char *layout_name)
c906108c 408{
22940a24 409 enum tui_status status = TUI_SUCCESS;
c906108c 410
6ba8e26f 411 if (layout_name != (char *) NULL)
c906108c 412 {
d02c80cd
AC
413 int i;
414 char *buf_ptr;
6ba8e26f
AC
415 enum tui_layout_type new_layout = UNDEFINED_LAYOUT;
416 enum tui_register_display_type dpy_type = TUI_UNDEFINED_REGS;
417 enum tui_layout_type cur_layout = tui_current_layout ();
c906108c 418
6ba8e26f
AC
419 buf_ptr = (char *) xstrdup (layout_name);
420 for (i = 0; (i < strlen (layout_name)); i++)
421 buf_ptr[i] = toupper (buf_ptr[i]);
c906108c 422
1cc6d956 423 /* First check for ambiguous input. */
e5908723
MS
424 if (strlen (buf_ptr) <= 1
425 && (*buf_ptr == 'S' || *buf_ptr == '$'))
c906108c 426 {
8a3fe4f8 427 warning (_("Ambiguous command input."));
c906108c
SS
428 status = TUI_FAILURE;
429 }
430 else
431 {
6ba8e26f
AC
432 if (subset_compare (buf_ptr, "SRC"))
433 new_layout = SRC_COMMAND;
434 else if (subset_compare (buf_ptr, "ASM"))
435 new_layout = DISASSEM_COMMAND;
436 else if (subset_compare (buf_ptr, "SPLIT"))
437 new_layout = SRC_DISASSEM_COMMAND;
e5908723
MS
438 else if (subset_compare (buf_ptr, "REGS")
439 || subset_compare (buf_ptr, TUI_GENERAL_SPECIAL_REGS_NAME)
440 || subset_compare (buf_ptr, TUI_GENERAL_REGS_NAME)
441 || subset_compare (buf_ptr, TUI_FLOAT_REGS_NAME)
442 || subset_compare (buf_ptr, TUI_SPECIAL_REGS_NAME))
c906108c 443 {
e5908723
MS
444 if (cur_layout == SRC_COMMAND
445 || cur_layout == SRC_DATA_COMMAND)
6ba8e26f 446 new_layout = SRC_DATA_COMMAND;
c906108c 447 else
6ba8e26f 448 new_layout = DISASSEM_DATA_COMMAND;
c906108c 449
1cc6d956
MS
450 /* Could ifdef out the following code. when compile with
451 -z, there are null pointer references that cause a
452 core dump if 'layout regs' is the first layout
453 command issued by the user. HP has asked us to hook
454 up this code. - edie epstein */
6ba8e26f 455 if (subset_compare (buf_ptr, TUI_FLOAT_REGS_NAME))
c906108c 456 {
9a2b4c1b
MS
457 if (TUI_DATA_WIN->detail.data_display_info.regs_display_type
458 != TUI_SFLOAT_REGS
459 && TUI_DATA_WIN->detail.data_display_info.regs_display_type
460 != TUI_DFLOAT_REGS)
6ba8e26f 461 dpy_type = TUI_SFLOAT_REGS;
c906108c 462 else
6ba8e26f 463 dpy_type =
6d012f14 464 TUI_DATA_WIN->detail.data_display_info.regs_display_type;
c906108c 465 }
6ba8e26f 466 else if (subset_compare (buf_ptr,
c906108c 467 TUI_GENERAL_SPECIAL_REGS_NAME))
6ba8e26f
AC
468 dpy_type = TUI_GENERAL_AND_SPECIAL_REGS;
469 else if (subset_compare (buf_ptr, TUI_GENERAL_REGS_NAME))
470 dpy_type = TUI_GENERAL_REGS;
471 else if (subset_compare (buf_ptr, TUI_SPECIAL_REGS_NAME))
472 dpy_type = TUI_SPECIAL_REGS;
6d012f14 473 else if (TUI_DATA_WIN)
c906108c 474 {
9a2b4c1b
MS
475 if (TUI_DATA_WIN->detail.data_display_info.regs_display_type
476 != TUI_UNDEFINED_REGS)
a743e542
MS
477 dpy_type
478 = TUI_DATA_WIN->detail.data_display_info.regs_display_type;
c906108c 479 else
6ba8e26f 480 dpy_type = TUI_GENERAL_REGS;
c906108c
SS
481 }
482
1cc6d956
MS
483 /* End of potential ifdef.
484 */
c906108c 485
1cc6d956
MS
486 /* If ifdefed out code above, then assume that the user
487 wishes to display the general purpose registers .
488 */
c906108c 489
1cc6d956 490 /* dpy_type = TUI_GENERAL_REGS; */
c906108c 491 }
6ba8e26f
AC
492 else if (subset_compare (buf_ptr, "NEXT"))
493 new_layout = next_layout ();
494 else if (subset_compare (buf_ptr, "PREV"))
495 new_layout = prev_layout ();
c906108c
SS
496 else
497 status = TUI_FAILURE;
c906108c 498
6ba8e26f 499 tui_set_layout (new_layout, dpy_type);
c906108c 500 }
3e40160c 501 xfree (buf_ptr);
c906108c
SS
502 }
503 else
504 status = TUI_FAILURE;
505
506 return status;
e8b915dc 507}
c906108c
SS
508
509
13274fc3
UW
510static void
511extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p)
c906108c 512{
6ba8e26f 513 enum tui_layout_type cur_layout = tui_current_layout ();
957b8b5a 514 struct gdbarch *gdbarch = get_current_arch ();
c774cec6 515 CORE_ADDR addr;
84b1e7c7 516 CORE_ADDR pc;
52575520 517 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
c906108c 518
6ba8e26f 519 switch (cur_layout)
c906108c
SS
520 {
521 case SRC_COMMAND:
522 case SRC_DATA_COMMAND:
13274fc3 523 gdbarch = TUI_SRC_WIN->detail.source_info.gdbarch;
52575520 524 find_line_pc (cursal.symtab,
362c05fe 525 TUI_SRC_WIN->detail.source_info.start_line_or_addr.u.line_no,
84b1e7c7 526 &pc);
c774cec6 527 addr = pc;
c906108c
SS
528 break;
529 case DISASSEM_COMMAND:
530 case SRC_DISASSEM_COMMAND:
531 case DISASSEM_DATA_COMMAND:
13274fc3 532 gdbarch = TUI_DISASM_WIN->detail.source_info.gdbarch;
362c05fe 533 addr = TUI_DISASM_WIN->detail.source_info.start_line_or_addr.u.addr;
c906108c
SS
534 break;
535 default:
c774cec6 536 addr = 0;
c906108c
SS
537 break;
538 }
539
13274fc3
UW
540 *gdbarch_p = gdbarch;
541 *addr_p = addr;
6ba8e26f 542}
c906108c
SS
543
544
c906108c 545static void
6ba8e26f 546tui_layout_command (char *arg, int from_tty)
c906108c 547{
19eb139b
SC
548 /* Make sure the curses mode is enabled. */
549 tui_enable ();
550
551 /* Switch to the selected layout. */
080ce8c0 552 if (tui_set_layout_for_display_command (arg) != TUI_SUCCESS)
8a3fe4f8 553 warning (_("Invalid layout specified.\n%s"), LAYOUT_USAGE);
c906108c 554
e8b915dc 555}
c906108c 556
6ba8e26f 557/* Answer the previous layout to cycle to. */
2a8854a7 558static enum tui_layout_type
6ba8e26f 559next_layout (void)
c906108c 560{
570dc176 561 int new_layout;
c906108c 562
6ba8e26f
AC
563 new_layout = tui_current_layout ();
564 if (new_layout == UNDEFINED_LAYOUT)
565 new_layout = SRC_COMMAND;
c906108c
SS
566 else
567 {
6ba8e26f
AC
568 new_layout++;
569 if (new_layout == UNDEFINED_LAYOUT)
570 new_layout = SRC_COMMAND;
c906108c
SS
571 }
572
570dc176 573 return (enum tui_layout_type) new_layout;
6ba8e26f 574}
c906108c
SS
575
576
6ba8e26f 577/* Answer the next layout to cycle to. */
2a8854a7 578static enum tui_layout_type
6ba8e26f 579prev_layout (void)
c906108c 580{
570dc176 581 int new_layout;
c906108c 582
6ba8e26f
AC
583 new_layout = tui_current_layout ();
584 if (new_layout == SRC_COMMAND)
585 new_layout = DISASSEM_DATA_COMMAND;
c906108c
SS
586 else
587 {
6ba8e26f
AC
588 new_layout--;
589 if (new_layout == UNDEFINED_LAYOUT)
590 new_layout = DISASSEM_DATA_COMMAND;
c906108c
SS
591 }
592
570dc176 593 return (enum tui_layout_type) new_layout;
6ba8e26f 594}
c906108c
SS
595
596
597
c906108c 598static void
08ef48c5
MS
599make_command_window (struct tui_win_info **win_info_ptr,
600 int height, int origin_y)
c906108c 601{
d5d6fca5
DJ
602 *win_info_ptr = init_and_make_win (*win_info_ptr,
603 CMD_WIN,
604 height,
605 tui_term_width (),
606 0,
607 origin_y,
608 DONT_BOX_WINDOW);
c906108c 609
6ba8e26f
AC
610 (*win_info_ptr)->can_highlight = FALSE;
611}
c906108c
SS
612
613
ef5eab5a 614/* make_source_window().
c5aa993b 615 */
c906108c 616static void
08ef48c5
MS
617make_source_window (struct tui_win_info **win_info_ptr,
618 int height, int origin_y)
c906108c 619{
6ba8e26f 620 make_source_or_disasm_window (win_info_ptr, SRC_WIN, height, origin_y);
c906108c
SS
621
622 return;
6ba8e26f 623} /* make_source_window */
c906108c
SS
624
625
ef5eab5a 626/* make_disasm_window().
c5aa993b 627 */
c906108c 628static void
08ef48c5
MS
629make_disasm_window (struct tui_win_info **win_info_ptr,
630 int height, int origin_y)
c906108c 631{
6ba8e26f 632 make_source_or_disasm_window (win_info_ptr, DISASSEM_WIN, height, origin_y);
c906108c
SS
633
634 return;
6ba8e26f 635} /* make_disasm_window */
c906108c
SS
636
637
c906108c 638static void
08ef48c5
MS
639make_data_window (struct tui_win_info **win_info_ptr,
640 int height, int origin_y)
c906108c 641{
d5d6fca5
DJ
642 *win_info_ptr = init_and_make_win (*win_info_ptr,
643 DATA_WIN,
644 height,
645 tui_term_width (),
646 0,
647 origin_y,
648 BOX_WINDOW);
6ba8e26f 649}
c906108c
SS
650
651
652
6ba8e26f 653/* Show the Source/Command layout. */
c906108c 654static void
6ba8e26f 655show_source_command (void)
c906108c 656{
6ba8e26f
AC
657 show_source_or_disasm_and_command (SRC_COMMAND);
658}
c906108c
SS
659
660
6ba8e26f 661/* Show the Dissassem/Command layout. */
c906108c 662static void
6ba8e26f 663show_disasm_command (void)
c906108c 664{
6ba8e26f
AC
665 show_source_or_disasm_and_command (DISASSEM_COMMAND);
666}
c906108c
SS
667
668
6ba8e26f 669/* Show the Source/Disassem/Command layout. */
c906108c 670static void
6ba8e26f 671show_source_disasm_command (void)
c906108c 672{
dd1abb8c 673 if (tui_current_layout () != SRC_DISASSEM_COMMAND)
c906108c 674 {
6ba8e26f 675 int cmd_height, src_height, asm_height;
c906108c 676
6d012f14 677 if (TUI_CMD_WIN != NULL)
6ba8e26f 678 cmd_height = TUI_CMD_WIN->generic.height;
c906108c 679 else
6ba8e26f 680 cmd_height = tui_term_height () / 3;
c906108c 681
6ba8e26f
AC
682 src_height = (tui_term_height () - cmd_height) / 2;
683 asm_height = tui_term_height () - (src_height + cmd_height);
c906108c 684
6d012f14 685 if (TUI_SRC_WIN == NULL)
6ba8e26f 686 make_source_window (&TUI_SRC_WIN, src_height, 0);
c906108c
SS
687 else
688 {
6ba8e26f 689 init_gen_win_info (&TUI_SRC_WIN->generic,
08ef48c5
MS
690 TUI_SRC_WIN->generic.type,
691 src_height,
692 TUI_SRC_WIN->generic.width,
693 TUI_SRC_WIN->detail.source_info.execution_info->width,
694 0);
6d012f14 695 TUI_SRC_WIN->can_highlight = TRUE;
6ba8e26f 696 init_gen_win_info (TUI_SRC_WIN->detail.source_info.execution_info,
08ef48c5
MS
697 EXEC_INFO_WIN,
698 src_height,
699 3,
700 0,
701 0);
6d012f14
AC
702 tui_make_visible (&TUI_SRC_WIN->generic);
703 tui_make_visible (TUI_SRC_WIN->detail.source_info.execution_info);
704 TUI_SRC_WIN->detail.source_info.has_locator = FALSE;;
c906108c 705 }
6d012f14 706 if (TUI_SRC_WIN != NULL)
c906108c 707 {
5b6fe301 708 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
c906108c 709
6d012f14
AC
710 tui_show_source_content (TUI_SRC_WIN);
711 if (TUI_DISASM_WIN == NULL)
c906108c 712 {
6ba8e26f 713 make_disasm_window (&TUI_DISASM_WIN, asm_height, src_height - 1);
d5d6fca5
DJ
714 locator = init_and_make_win (locator,
715 LOCATOR_WIN,
716 2 /* 1 */ ,
717 tui_term_width (),
718 0,
719 (src_height + asm_height) - 1,
720 DONT_BOX_WINDOW);
c906108c
SS
721 }
722 else
723 {
6ba8e26f 724 init_gen_win_info (locator,
08ef48c5
MS
725 LOCATOR_WIN,
726 2 /* 1 */ ,
727 tui_term_width (),
728 0,
729 (src_height + asm_height) - 1);
6d012f14 730 TUI_DISASM_WIN->detail.source_info.has_locator = TRUE;
08ef48c5
MS
731 init_gen_win_info (&TUI_DISASM_WIN->generic,
732 TUI_DISASM_WIN->generic.type,
733 asm_height,
734 TUI_DISASM_WIN->generic.width,
735 TUI_DISASM_WIN->detail.source_info.execution_info->width,
736 src_height - 1);
6ba8e26f 737 init_gen_win_info (TUI_DISASM_WIN->detail.source_info.execution_info,
08ef48c5
MS
738 EXEC_INFO_WIN,
739 asm_height,
740 3,
741 0,
742 src_height - 1);
6d012f14
AC
743 TUI_DISASM_WIN->can_highlight = TRUE;
744 tui_make_visible (&TUI_DISASM_WIN->generic);
745 tui_make_visible (TUI_DISASM_WIN->detail.source_info.execution_info);
c906108c 746 }
6d012f14 747 if (TUI_DISASM_WIN != NULL)
c906108c 748 {
6d012f14
AC
749 TUI_SRC_WIN->detail.source_info.has_locator = FALSE;
750 TUI_DISASM_WIN->detail.source_info.has_locator = TRUE;
ec7d9e56 751 tui_make_visible (locator);
47d3492a 752 tui_show_locator_content ();
6d012f14 753 tui_show_source_content (TUI_DISASM_WIN);
c906108c 754
6d012f14 755 if (TUI_CMD_WIN == NULL)
6ba8e26f 756 make_command_window (&TUI_CMD_WIN,
08ef48c5
MS
757 cmd_height,
758 tui_term_height () - cmd_height);
c906108c
SS
759 else
760 {
6ba8e26f 761 init_gen_win_info (&TUI_CMD_WIN->generic,
08ef48c5
MS
762 TUI_CMD_WIN->generic.type,
763 TUI_CMD_WIN->generic.height,
764 TUI_CMD_WIN->generic.width,
765 0,
766 TUI_CMD_WIN->generic.origin.y);
6d012f14
AC
767 TUI_CMD_WIN->can_highlight = FALSE;
768 tui_make_visible (&TUI_CMD_WIN->generic);
c906108c 769 }
6d012f14
AC
770 if (TUI_CMD_WIN != NULL)
771 tui_refresh_win (&TUI_CMD_WIN->generic);
c906108c
SS
772 }
773 }
dd1abb8c 774 tui_set_current_layout_to (SRC_DISASSEM_COMMAND);
c906108c 775 }
6ba8e26f 776}
c906108c
SS
777
778
6ba8e26f
AC
779/* Show the Source/Data/Command or the Dissassembly/Data/Command
780 layout. */
c906108c 781static void
6ba8e26f 782show_data (enum tui_layout_type new_layout)
c906108c 783{
6ba8e26f
AC
784 int total_height = (tui_term_height () - TUI_CMD_WIN->generic.height);
785 int src_height, data_height;
786 enum tui_win_type win_type;
5b6fe301 787 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
c906108c
SS
788
789
6ba8e26f
AC
790 data_height = total_height / 2;
791 src_height = total_height - data_height;
ec7d9e56
AC
792 tui_make_all_invisible ();
793 tui_make_invisible (locator);
6ba8e26f 794 make_data_window (&TUI_DATA_WIN, data_height, 0);
6d012f14 795 TUI_DATA_WIN->can_highlight = TRUE;
6ba8e26f
AC
796 if (new_layout == SRC_DATA_COMMAND)
797 win_type = SRC_WIN;
c906108c 798 else
6ba8e26f
AC
799 win_type = DISASSEM_WIN;
800 if (tui_win_list[win_type] == NULL)
c906108c 801 {
6ba8e26f
AC
802 if (win_type == SRC_WIN)
803 make_source_window (&tui_win_list[win_type], src_height, data_height - 1);
c906108c 804 else
6ba8e26f 805 make_disasm_window (&tui_win_list[win_type], src_height, data_height - 1);
d5d6fca5
DJ
806 locator = init_and_make_win (locator,
807 LOCATOR_WIN,
808 2 /* 1 */ ,
809 tui_term_width (),
810 0,
811 total_height - 1,
812 DONT_BOX_WINDOW);
c906108c
SS
813 }
814 else
815 {
6ba8e26f 816 init_gen_win_info (&tui_win_list[win_type]->generic,
08ef48c5
MS
817 tui_win_list[win_type]->generic.type,
818 src_height,
819 tui_win_list[win_type]->generic.width,
820 tui_win_list[win_type]->detail.source_info.execution_info->width,
821 data_height - 1);
6ba8e26f 822 init_gen_win_info (tui_win_list[win_type]->detail.source_info.execution_info,
08ef48c5
MS
823 EXEC_INFO_WIN,
824 src_height,
825 3,
826 0,
827 data_height - 1);
6ba8e26f
AC
828 tui_make_visible (&tui_win_list[win_type]->generic);
829 tui_make_visible (tui_win_list[win_type]->detail.source_info.execution_info);
830 init_gen_win_info (locator,
08ef48c5
MS
831 LOCATOR_WIN,
832 2 /* 1 */ ,
833 tui_term_width (),
834 0,
835 total_height - 1);
c906108c 836 }
6ba8e26f 837 tui_win_list[win_type]->detail.source_info.has_locator = TRUE;
ec7d9e56 838 tui_make_visible (locator);
47d3492a 839 tui_show_locator_content ();
6ba8e26f
AC
840 tui_add_to_source_windows (tui_win_list[win_type]);
841 tui_set_current_layout_to (new_layout);
842}
c906108c 843
ef5eab5a 844/* init_gen_win_info().
c5aa993b 845 */
c906108c 846static void
08ef48c5
MS
847init_gen_win_info (struct tui_gen_win_info *win_info,
848 enum tui_win_type type,
849 int height, int width,
850 int origin_x, int origin_y)
c906108c
SS
851{
852 int h = height;
853
6ba8e26f
AC
854 win_info->type = type;
855 win_info->width = width;
856 win_info->height = h;
c906108c
SS
857 if (h > 1)
858 {
6ba8e26f
AC
859 win_info->viewport_height = h - 1;
860 if (win_info->type != CMD_WIN)
861 win_info->viewport_height--;
c906108c
SS
862 }
863 else
6ba8e26f
AC
864 win_info->viewport_height = 1;
865 win_info->origin.x = origin_x;
866 win_info->origin.y = origin_y;
c906108c
SS
867
868 return;
6ba8e26f 869} /* init_gen_win_info */
c906108c 870
ef5eab5a 871/* init_and_make_win().
c5aa993b 872 */
d5d6fca5 873static void *
08ef48c5
MS
874init_and_make_win (void *opaque_win_info,
875 enum tui_win_type win_type,
876 int height, int width,
877 int origin_x, int origin_y,
d5d6fca5 878 int box_it)
c906108c 879{
5b6fe301 880 struct tui_gen_win_info *generic;
c906108c 881
6ba8e26f 882 if (opaque_win_info == NULL)
c906108c 883 {
6ba8e26f
AC
884 if (tui_win_is_auxillary (win_type))
885 opaque_win_info = (void *) tui_alloc_generic_win_info ();
c906108c 886 else
6ba8e26f 887 opaque_win_info = (void *) tui_alloc_win_info (win_type);
c906108c 888 }
6ba8e26f
AC
889 if (tui_win_is_auxillary (win_type))
890 generic = (struct tui_gen_win_info *) opaque_win_info;
c906108c 891 else
6ba8e26f 892 generic = &((struct tui_win_info *) opaque_win_info)->generic;
c906108c 893
6ba8e26f 894 if (opaque_win_info != NULL)
c906108c 895 {
6ba8e26f
AC
896 init_gen_win_info (generic, win_type, height, width, origin_x, origin_y);
897 if (!tui_win_is_auxillary (win_type))
c906108c
SS
898 {
899 if (generic->type == CMD_WIN)
6ba8e26f 900 ((struct tui_win_info *) opaque_win_info)->can_highlight = FALSE;
c906108c 901 else
6ba8e26f 902 ((struct tui_win_info *) opaque_win_info)->can_highlight = TRUE;
c906108c 903 }
6ba8e26f 904 tui_make_window (generic, box_it);
c906108c 905 }
d5d6fca5 906 return opaque_win_info;
bc712bbf 907}
c906108c
SS
908
909
c906108c 910static void
08ef48c5
MS
911make_source_or_disasm_window (struct tui_win_info **win_info_ptr,
912 enum tui_win_type type,
913 int height, int origin_y)
c906108c 914{
5b6fe301 915 struct tui_gen_win_info *execution_info = (struct tui_gen_win_info *) NULL;
c906108c 916
ef5eab5a 917 /* Create the exeuction info window. */
c906108c 918 if (type == SRC_WIN)
6d012f14 919 execution_info = tui_source_exec_info_win_ptr ();
c906108c 920 else
6d012f14 921 execution_info = tui_disassem_exec_info_win_ptr ();
d5d6fca5
DJ
922 execution_info = init_and_make_win (execution_info,
923 EXEC_INFO_WIN,
924 height,
925 3,
926 0,
927 origin_y,
928 DONT_BOX_WINDOW);
ef5eab5a
MS
929
930 /* Now create the source window. */
d5d6fca5
DJ
931 *win_info_ptr = init_and_make_win (*win_info_ptr,
932 type,
933 height,
934 tui_term_width () - execution_info->width,
935 execution_info->width,
936 origin_y,
937 BOX_WINDOW);
c906108c 938
6ba8e26f
AC
939 (*win_info_ptr)->detail.source_info.execution_info = execution_info;
940}
c906108c
SS
941
942
1cc6d956 943/* Show the Source/Command or the Disassem layout. */
c906108c 944static void
6ba8e26f 945show_source_or_disasm_and_command (enum tui_layout_type layout_type)
c906108c 946{
6ba8e26f 947 if (tui_current_layout () != layout_type)
c906108c 948 {
5b6fe301 949 struct tui_win_info **win_info_ptr;
6ba8e26f 950 int src_height, cmd_height;
5b6fe301 951 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
c906108c 952
6d012f14 953 if (TUI_CMD_WIN != NULL)
6ba8e26f 954 cmd_height = TUI_CMD_WIN->generic.height;
c906108c 955 else
6ba8e26f
AC
956 cmd_height = tui_term_height () / 3;
957 src_height = tui_term_height () - cmd_height;
c906108c 958
6ba8e26f
AC
959 if (layout_type == SRC_COMMAND)
960 win_info_ptr = &TUI_SRC_WIN;
c906108c 961 else
6ba8e26f 962 win_info_ptr = &TUI_DISASM_WIN;
c906108c 963
6ba8e26f 964 if ((*win_info_ptr) == NULL)
c906108c 965 {
6ba8e26f
AC
966 if (layout_type == SRC_COMMAND)
967 make_source_window (win_info_ptr, src_height - 1, 0);
c906108c 968 else
6ba8e26f 969 make_disasm_window (win_info_ptr, src_height - 1, 0);
d5d6fca5
DJ
970 locator = init_and_make_win (locator,
971 LOCATOR_WIN,
972 2 /* 1 */ ,
973 tui_term_width (),
974 0,
975 src_height - 1,
976 DONT_BOX_WINDOW);
c906108c
SS
977 }
978 else
979 {
6ba8e26f 980 init_gen_win_info (locator,
08ef48c5
MS
981 LOCATOR_WIN,
982 2 /* 1 */ ,
983 tui_term_width (),
984 0,
985 src_height - 1);
6ba8e26f 986 (*win_info_ptr)->detail.source_info.has_locator = TRUE;
08ef48c5
MS
987 init_gen_win_info (&(*win_info_ptr)->generic,
988 (*win_info_ptr)->generic.type,
989 src_height - 1,
990 (*win_info_ptr)->generic.width,
991 (*win_info_ptr)->detail.source_info.execution_info->width,
992 0);
6ba8e26f 993 init_gen_win_info ((*win_info_ptr)->detail.source_info.execution_info,
08ef48c5
MS
994 EXEC_INFO_WIN,
995 src_height - 1,
996 3,
997 0,
998 0);
6ba8e26f
AC
999 (*win_info_ptr)->can_highlight = TRUE;
1000 tui_make_visible (&(*win_info_ptr)->generic);
1001 tui_make_visible ((*win_info_ptr)->detail.source_info.execution_info);
c906108c 1002 }
6ba8e26f 1003 if ((*win_info_ptr) != NULL)
c906108c 1004 {
6ba8e26f 1005 (*win_info_ptr)->detail.source_info.has_locator = TRUE;
ec7d9e56 1006 tui_make_visible (locator);
47d3492a 1007 tui_show_locator_content ();
6ba8e26f 1008 tui_show_source_content (*win_info_ptr);
c906108c 1009
6d012f14 1010 if (TUI_CMD_WIN == NULL)
c906108c 1011 {
6ba8e26f 1012 make_command_window (&TUI_CMD_WIN, cmd_height, src_height);
6d012f14 1013 tui_refresh_win (&TUI_CMD_WIN->generic);
c906108c
SS
1014 }
1015 else
1016 {
6ba8e26f 1017 init_gen_win_info (&TUI_CMD_WIN->generic,
08ef48c5
MS
1018 TUI_CMD_WIN->generic.type,
1019 TUI_CMD_WIN->generic.height,
1020 TUI_CMD_WIN->generic.width,
1021 TUI_CMD_WIN->generic.origin.x,
1022 TUI_CMD_WIN->generic.origin.y);
6d012f14
AC
1023 TUI_CMD_WIN->can_highlight = FALSE;
1024 tui_make_visible (&TUI_CMD_WIN->generic);
c906108c
SS
1025 }
1026 }
6ba8e26f 1027 tui_set_current_layout_to (layout_type);
c906108c 1028 }
6ba8e26f 1029}
This page took 1.534346 seconds and 4 git commands to generate.