daily update
[deliverable/binutils-gdb.git] / gdb / tui / tui-layout.c
CommitLineData
f377b406 1/* TUI layout window management.
f33c6cbf 2
55fb0713
AC
3 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
4 Foundation, Inc.
f33c6cbf 5
f377b406 6 Contributed by Hewlett-Packard Company.
c906108c 7
f377b406
SC
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
c906108c
SS
24
25#include "defs.h"
26#include "command.h"
27#include "symtab.h"
28#include "frame.h"
52575520 29#include "source.h"
84b1e7c7 30#include <ctype.h>
c906108c 31
d7b2e967
AC
32#include "tui/tui.h"
33#include "tui/tui-data.h"
34#include "tui/tui-windata.h"
35#include "tui/tui-wingeneral.h"
36#include "tui/tui-stack.h"
37#include "tui/tui-regs.h"
38#include "tui/tui-win.h"
39#include "tui/tui-winsource.h"
40#include "tui/tui-disasm.h"
c906108c 41
96ec9981
DJ
42#ifdef HAVE_NCURSES_H
43#include <ncurses.h>
44#else
45#ifdef HAVE_CURSES_H
46#include <curses.h>
47#endif
48#endif
49
c906108c
SS
50/*******************************
51** Static Local Decls
52********************************/
c7037be1 53static void showLayout (TuiLayoutType);
f6dd1e70
KB
54static void _initGenWinInfo (TuiGenWinInfoPtr, TuiWinType, int, int, int, int);
55static void _initAndMakeWin (Opaque *, TuiWinType, int, int, int, int, int);
56static void _showSourceOrDisassemAndCommand (TuiLayoutType);
57static void _makeSourceOrDisassemWindow (TuiWinInfoPtr *, TuiWinType, int, int);
a14ed312
KB
58static void _makeCommandWindow (TuiWinInfoPtr *, int, int);
59static void _makeSourceWindow (TuiWinInfoPtr *, int, int);
f6dd1e70 60static void _makeDisassemWindow (TuiWinInfoPtr *, int, int);
a14ed312
KB
61static void _makeDataWindow (TuiWinInfoPtr *, int, int);
62static void _showSourceCommand (void);
63static void _showDisassemCommand (void);
64static void _showSourceDisassemCommand (void);
65static void _showData (TuiLayoutType);
66static TuiLayoutType _nextLayout (void);
67static TuiLayoutType _prevLayout (void);
68static void _tuiLayout_command (char *, int);
69static void _tuiToggleLayout_command (char *, int);
a14ed312 70static void _tuiToggleSplitLayout_command (char *, int);
c774cec6 71static CORE_ADDR _extractDisplayStartAddr (void);
a14ed312 72static void _tuiHandleXDBLayout (TuiLayoutDefPtr);
c906108c
SS
73
74
75/***************************************
76** DEFINITIONS
77***************************************/
78
79#define LAYOUT_USAGE "Usage: layout prev | next | <layout_name> \n"
80
c7037be1
SC
81/* Show the screen layout defined. */
82static void
eca6576c 83showLayout (TuiLayoutType layout)
c906108c
SS
84{
85 TuiLayoutType curLayout = currentLayout ();
86
87 if (layout != curLayout)
88 {
89 /*
c5aa993b
JM
90 ** Since the new layout may cause changes in window size, we
91 ** should free the content and reallocate on next display of
92 ** source/asm
93 */
c906108c
SS
94 freeAllSourceWinsContent ();
95 clearSourceWindows ();
96 if (layout == SRC_DATA_COMMAND || layout == DISASSEM_DATA_COMMAND)
97 {
98 _showData (layout);
99 refreshAll (winList);
100 }
101 else
102 {
103 /* First make the current layout be invisible */
104 m_allBeInvisible ();
105 m_beInvisible (locatorWinInfoPtr ());
106
107 switch (layout)
108 {
109 /* Now show the new layout */
110 case SRC_COMMAND:
111 _showSourceCommand ();
112 addToSourceWindows (srcWin);
113 break;
114 case DISASSEM_COMMAND:
115 _showDisassemCommand ();
116 addToSourceWindows (disassemWin);
117 break;
118 case SRC_DISASSEM_COMMAND:
119 _showSourceDisassemCommand ();
120 addToSourceWindows (srcWin);
121 addToSourceWindows (disassemWin);
122 break;
123 default:
124 break;
125 }
126 }
127 }
bc712bbf 128}
c906108c
SS
129
130
080ce8c0
AC
131/* Function to set the layout to SRC_COMMAND, DISASSEM_COMMAND,
132 SRC_DISASSEM_COMMAND, SRC_DATA_COMMAND, or DISASSEM_DATA_COMMAND.
133 If the layout is SRC_DATA_COMMAND, DISASSEM_DATA_COMMAND, or
134 UNDEFINED_LAYOUT, then the data window is populated according to
135 regsDisplayType. */
136enum tui_status
137tui_set_layout (enum tui_layout_type layoutType,
138 enum tui_register_display_type regsDisplayType)
c906108c
SS
139{
140 TuiStatus status = TUI_SUCCESS;
141
142 if (layoutType != UNDEFINED_LAYOUT || regsDisplayType != TUI_UNDEFINED_REGS)
143 {
144 TuiLayoutType curLayout = currentLayout (), newLayout = UNDEFINED_LAYOUT;
145 int regsPopulate = FALSE;
c774cec6 146 CORE_ADDR addr = _extractDisplayStartAddr ();
c906108c
SS
147 TuiWinInfoPtr newWinWithFocus = (TuiWinInfoPtr) NULL, winWithFocus = tuiWinWithFocus ();
148 TuiLayoutDefPtr layoutDef = tuiLayoutDef ();
149
150
151 if (layoutType == UNDEFINED_LAYOUT &&
152 regsDisplayType != TUI_UNDEFINED_REGS)
153 {
154 if (curLayout == SRC_DISASSEM_COMMAND)
155 newLayout = DISASSEM_DATA_COMMAND;
156 else if (curLayout == SRC_COMMAND || curLayout == SRC_DATA_COMMAND)
157 newLayout = SRC_DATA_COMMAND;
158 else if (curLayout == DISASSEM_COMMAND ||
159 curLayout == DISASSEM_DATA_COMMAND)
160 newLayout = DISASSEM_DATA_COMMAND;
161 }
162 else
163 newLayout = layoutType;
164
165 regsPopulate = (newLayout == SRC_DATA_COMMAND ||
166 newLayout == DISASSEM_DATA_COMMAND ||
167 regsDisplayType != TUI_UNDEFINED_REGS);
168 if (newLayout != curLayout || regsDisplayType != TUI_UNDEFINED_REGS)
169 {
170 if (newLayout != curLayout)
171 {
c906108c
SS
172 showLayout (newLayout);
173 /*
c5aa993b
JM
174 ** Now determine where focus should be
175 */
c906108c
SS
176 if (winWithFocus != cmdWin)
177 {
178 switch (newLayout)
179 {
180 case SRC_COMMAND:
181 tuiSetWinFocusTo (srcWin);
182 layoutDef->displayMode = SRC_WIN;
183 layoutDef->split = FALSE;
184 break;
185 case DISASSEM_COMMAND:
186 /* the previous layout was not showing
c5aa993b
JM
187 ** code. this can happen if there is no
188 ** source available:
189 ** 1. if the source file is in another dir OR
190 ** 2. if target was compiled without -g
191 ** We still want to show the assembly though!
192 */
65f05602 193 addr = tui_get_begin_asm_address ();
c906108c
SS
194 tuiSetWinFocusTo (disassemWin);
195 layoutDef->displayMode = DISASSEM_WIN;
196 layoutDef->split = FALSE;
197 break;
198 case SRC_DISASSEM_COMMAND:
199 /* the previous layout was not showing
c5aa993b
JM
200 ** code. this can happen if there is no
201 ** source available:
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 */
65f05602 206 addr = tui_get_begin_asm_address ();
c906108c
SS
207 if (winWithFocus == srcWin)
208 tuiSetWinFocusTo (srcWin);
209 else
210 tuiSetWinFocusTo (disassemWin);
211 layoutDef->split = TRUE;
212 break;
213 case SRC_DATA_COMMAND:
214 if (winWithFocus != dataWin)
215 tuiSetWinFocusTo (srcWin);
216 else
217 tuiSetWinFocusTo (dataWin);
218 layoutDef->displayMode = SRC_WIN;
219 layoutDef->split = FALSE;
220 break;
221 case DISASSEM_DATA_COMMAND:
222 /* the previous layout was not showing
c5aa993b
JM
223 ** code. this can happen if there is no
224 ** source available:
225 ** 1. if the source file is in another dir OR
226 ** 2. if target was compiled without -g
227 ** We still want to show the assembly though!
228 */
65f05602 229 addr = tui_get_begin_asm_address ();
c906108c
SS
230 if (winWithFocus != dataWin)
231 tuiSetWinFocusTo (disassemWin);
232 else
233 tuiSetWinFocusTo (dataWin);
234 layoutDef->displayMode = DISASSEM_WIN;
235 layoutDef->split = FALSE;
236 break;
237 default:
238 break;
239 }
240 }
241 if (newWinWithFocus != (TuiWinInfoPtr) NULL)
242 tuiSetWinFocusTo (newWinWithFocus);
243 /*
c5aa993b
JM
244 ** Now update the window content
245 */
c906108c
SS
246 if (!regsPopulate &&
247 (newLayout == SRC_DATA_COMMAND ||
248 newLayout == DISASSEM_DATA_COMMAND))
249 tuiDisplayAllData ();
250
251 tuiUpdateSourceWindowsWithAddr (addr);
252 }
253 if (regsPopulate)
254 {
255 layoutDef->regsDisplayType =
256 (regsDisplayType == TUI_UNDEFINED_REGS ?
257 TUI_GENERAL_REGS : regsDisplayType);
55fb0713 258 tui_show_registers (layoutDef->regsDisplayType);
c906108c
SS
259 }
260 }
261 }
262 else
263 status = TUI_FAILURE;
264
265 return status;
bc712bbf 266}
c906108c 267
080ce8c0
AC
268/* Add the specified window to the layout in a logical way. This
269 means setting up the most logical layout given the window to be
270 added. */
c906108c 271void
080ce8c0 272tui_add_win_to_layout (enum tui_win_type type)
c906108c
SS
273{
274 TuiLayoutType curLayout = currentLayout ();
275
276 switch (type)
277 {
278 case SRC_WIN:
279 if (curLayout != SRC_COMMAND &&
280 curLayout != SRC_DISASSEM_COMMAND &&
281 curLayout != SRC_DATA_COMMAND)
282 {
283 clearSourceWindowsDetail ();
284 if (curLayout == DISASSEM_DATA_COMMAND)
285 showLayout (SRC_DATA_COMMAND);
286 else
287 showLayout (SRC_COMMAND);
288 }
289 break;
290 case DISASSEM_WIN:
291 if (curLayout != DISASSEM_COMMAND &&
292 curLayout != SRC_DISASSEM_COMMAND &&
293 curLayout != DISASSEM_DATA_COMMAND)
294 {
295 clearSourceWindowsDetail ();
296 if (curLayout == SRC_DATA_COMMAND)
297 showLayout (DISASSEM_DATA_COMMAND);
298 else
299 showLayout (DISASSEM_COMMAND);
300 }
301 break;
302 case DATA_WIN:
303 if (curLayout != SRC_DATA_COMMAND &&
304 curLayout != DISASSEM_DATA_COMMAND)
305 {
306 if (curLayout == DISASSEM_COMMAND)
307 showLayout (DISASSEM_DATA_COMMAND);
308 else
309 showLayout (SRC_DATA_COMMAND);
310 }
311 break;
312 default:
313 break;
314 }
315
316 return;
317} /* tuiAddWinToLayout */
318
319
c906108c 320/*
c5aa993b
JM
321 ** tuiDefaultWinHeight().
322 ** Answer the height of a window. If it hasn't been created yet,
323 ** answer what the height of a window would be based upon its
324 ** type and the layout.
325 */
c906108c 326int
eca6576c 327tuiDefaultWinHeight (TuiWinType type, TuiLayoutType layout)
c906108c
SS
328{
329 int h;
330
331 if (winList[type] != (TuiWinInfoPtr) NULL)
332 h = winList[type]->generic.height;
333 else
334 {
335 switch (layout)
336 {
337 case SRC_COMMAND:
338 case DISASSEM_COMMAND:
339 if (m_winPtrIsNull (cmdWin))
340 h = termHeight () / 2;
341 else
342 h = termHeight () - cmdWin->generic.height;
343 break;
344 case SRC_DISASSEM_COMMAND:
345 case SRC_DATA_COMMAND:
346 case DISASSEM_DATA_COMMAND:
347 if (m_winPtrIsNull (cmdWin))
348 h = termHeight () / 3;
349 else
350 h = (termHeight () - cmdWin->generic.height) / 2;
351 break;
352 default:
353 h = 0;
354 break;
355 }
356 }
357
358 return h;
359} /* tuiDefaultWinHeight */
360
361
080ce8c0
AC
362/* Answer the height of a window. If it hasn't been created yet,
363 answer what the height of a window would be based upon its type and
364 the layout. */
c906108c 365int
080ce8c0
AC
366tui_default_win_viewport_height (enum tui_win_type type,
367 enum tui_layout_type layout)
c906108c
SS
368{
369 int h;
370
371 h = tuiDefaultWinHeight (type, layout);
372
373 if (winList[type] == cmdWin)
374 h -= 1;
375 else
376 h -= 2;
377
378 return h;
379} /* tuiDefaultWinViewportHeight */
380
381
382/*
c5aa993b
JM
383 ** _initialize_tuiLayout().
384 ** Function to initialize gdb commands, for tui window layout
385 ** manipulation.
386 */
c906108c 387void
fba45db2 388_initialize_tuiLayout (void)
c906108c 389{
41783295
SC
390 add_com ("layout", class_tui, _tuiLayout_command,
391 "Change the layout of windows.\n\
c906108c
SS
392Usage: layout prev | next | <layout_name> \n\
393Layout names are:\n\
394 src : Displays source and command windows.\n\
395 asm : Displays disassembly and command windows.\n\
396 split : Displays source, disassembly and command windows.\n\
397 regs : Displays register window. If existing layout\n\
398 is source/command or assembly/command, the \n\
399 register window is displayed. If the\n\
400 source/assembly/command (split) is displayed, \n\
401 the register window is displayed with \n\
402 the window that has current logical focus.\n");
41783295
SC
403 if (xdb_commands)
404 {
405 add_com ("td", class_tui, _tuiToggleLayout_command,
406 "Toggle between Source/Command and Disassembly/Command layouts.\n");
407 add_com ("ts", class_tui, _tuiToggleSplitLayout_command,
408 "Toggle between Source/Command or Disassembly/Command and \n\
c906108c 409Source/Disassembly/Command layouts.\n");
c906108c 410 }
41783295 411}
c906108c
SS
412
413
414/*************************
415** STATIC LOCAL FUNCTIONS
416**************************/
417
418
419/*
c5aa993b
JM
420 ** _tuiSetLayoutTo()
421 ** Function to set the layout to SRC, ASM, SPLIT, NEXT, PREV, DATA, REGS,
422 ** $REGS, $GREGS, $FREGS, $SREGS.
423 */
e8b915dc 424TuiStatus
080ce8c0 425tui_set_layout_for_display_command (const char *layoutName)
c906108c
SS
426{
427 TuiStatus status = TUI_SUCCESS;
428
429 if (layoutName != (char *) NULL)
430 {
431 register int i;
432 register char *bufPtr;
433 TuiLayoutType newLayout = UNDEFINED_LAYOUT;
434 TuiRegisterDisplayType dpyType = TUI_UNDEFINED_REGS;
435 TuiLayoutType curLayout = currentLayout ();
436
19eb139b 437 bufPtr = (char *) xstrdup (layoutName);
c906108c
SS
438 for (i = 0; (i < strlen (layoutName)); i++)
439 bufPtr[i] = toupper (bufPtr[i]);
440
441 /* First check for ambiguous input */
442 if (strlen (bufPtr) <= 1 && (*bufPtr == 'S' || *bufPtr == '$'))
443 {
444 warning ("Ambiguous command input.\n");
445 status = TUI_FAILURE;
446 }
447 else
448 {
0963fc96 449 if (subset_compare (bufPtr, "SRC"))
c906108c 450 newLayout = SRC_COMMAND;
0963fc96 451 else if (subset_compare (bufPtr, "ASM"))
c906108c 452 newLayout = DISASSEM_COMMAND;
0963fc96 453 else if (subset_compare (bufPtr, "SPLIT"))
c906108c 454 newLayout = SRC_DISASSEM_COMMAND;
0963fc96
SC
455 else if (subset_compare (bufPtr, "REGS") ||
456 subset_compare (bufPtr, TUI_GENERAL_SPECIAL_REGS_NAME) ||
457 subset_compare (bufPtr, TUI_GENERAL_REGS_NAME) ||
458 subset_compare (bufPtr, TUI_FLOAT_REGS_NAME) ||
459 subset_compare (bufPtr, TUI_SPECIAL_REGS_NAME))
c906108c
SS
460 {
461 if (curLayout == SRC_COMMAND || curLayout == SRC_DATA_COMMAND)
462 newLayout = SRC_DATA_COMMAND;
463 else
464 newLayout = DISASSEM_DATA_COMMAND;
465
466/* could ifdef out the following code. when compile with -z, there are null
467 pointer references that cause a core dump if 'layout regs' is the first
468 layout command issued by the user. HP has asked us to hook up this code
469 - edie epstein
470 */
0963fc96 471 if (subset_compare (bufPtr, TUI_FLOAT_REGS_NAME))
c906108c
SS
472 {
473 if (dataWin->detail.dataDisplayInfo.regsDisplayType !=
474 TUI_SFLOAT_REGS &&
475 dataWin->detail.dataDisplayInfo.regsDisplayType !=
476 TUI_DFLOAT_REGS)
477 dpyType = TUI_SFLOAT_REGS;
478 else
479 dpyType =
480 dataWin->detail.dataDisplayInfo.regsDisplayType;
481 }
0963fc96 482 else if (subset_compare (bufPtr,
c906108c
SS
483 TUI_GENERAL_SPECIAL_REGS_NAME))
484 dpyType = TUI_GENERAL_AND_SPECIAL_REGS;
0963fc96 485 else if (subset_compare (bufPtr, TUI_GENERAL_REGS_NAME))
c906108c 486 dpyType = TUI_GENERAL_REGS;
0963fc96 487 else if (subset_compare (bufPtr, TUI_SPECIAL_REGS_NAME))
c906108c 488 dpyType = TUI_SPECIAL_REGS;
84b1e7c7 489 else if (dataWin)
c906108c
SS
490 {
491 if (dataWin->detail.dataDisplayInfo.regsDisplayType !=
492 TUI_UNDEFINED_REGS)
493 dpyType =
494 dataWin->detail.dataDisplayInfo.regsDisplayType;
495 else
496 dpyType = TUI_GENERAL_REGS;
497 }
498
499/* end of potential ifdef
500 */
501
502/* if ifdefed out code above, then assume that the user wishes to display the
503 general purpose registers
504 */
505
506/* dpyType = TUI_GENERAL_REGS;
507 */
508 }
0963fc96 509 else if (subset_compare (bufPtr, "NEXT"))
c906108c 510 newLayout = _nextLayout ();
0963fc96 511 else if (subset_compare (bufPtr, "PREV"))
c906108c
SS
512 newLayout = _prevLayout ();
513 else
514 status = TUI_FAILURE;
b8c9b27d 515 xfree (bufPtr);
c906108c 516
080ce8c0 517 tui_set_layout (newLayout, dpyType);
c906108c
SS
518 }
519 }
520 else
521 status = TUI_FAILURE;
522
523 return status;
e8b915dc 524}
c906108c
SS
525
526
c774cec6 527static CORE_ADDR
c906108c 528_extractDisplayStartAddr (void)
c906108c
SS
529{
530 TuiLayoutType curLayout = currentLayout ();
c774cec6 531 CORE_ADDR addr;
84b1e7c7 532 CORE_ADDR pc;
52575520 533 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
c906108c
SS
534
535 switch (curLayout)
536 {
537 case SRC_COMMAND:
538 case SRC_DATA_COMMAND:
52575520 539 find_line_pc (cursal.symtab,
84b1e7c7
SC
540 srcWin->detail.sourceInfo.startLineOrAddr.lineNo,
541 &pc);
c774cec6 542 addr = pc;
c906108c
SS
543 break;
544 case DISASSEM_COMMAND:
545 case SRC_DISASSEM_COMMAND:
546 case DISASSEM_DATA_COMMAND:
547 addr = disassemWin->detail.sourceInfo.startLineOrAddr.addr;
548 break;
549 default:
c774cec6 550 addr = 0;
c906108c
SS
551 break;
552 }
553
554 return addr;
555} /* _extractDisplayStartAddr */
556
557
558static void
eca6576c 559_tuiHandleXDBLayout (TuiLayoutDefPtr layoutDef)
c906108c
SS
560{
561 if (layoutDef->split)
562 {
080ce8c0 563 tui_set_layout (SRC_DISASSEM_COMMAND, TUI_UNDEFINED_REGS);
c906108c
SS
564 tuiSetWinFocusTo (winList[layoutDef->displayMode]);
565 }
566 else
567 {
568 if (layoutDef->displayMode == SRC_WIN)
080ce8c0 569 tui_set_layout (SRC_COMMAND, TUI_UNDEFINED_REGS);
c906108c 570 else
080ce8c0 571 tui_set_layout (DISASSEM_DATA_COMMAND, layoutDef->regsDisplayType);
c906108c
SS
572 }
573
574
575 return;
576} /* _tuiHandleXDBLayout */
577
578
579static void
eca6576c 580_tuiToggleLayout_command (char *arg, int fromTTY)
c906108c
SS
581{
582 TuiLayoutDefPtr layoutDef = tuiLayoutDef ();
583
19eb139b
SC
584 /* Make sure the curses mode is enabled. */
585 tui_enable ();
c906108c
SS
586 if (layoutDef->displayMode == SRC_WIN)
587 layoutDef->displayMode = DISASSEM_WIN;
588 else
589 layoutDef->displayMode = SRC_WIN;
590
591 if (!layoutDef->split)
592 _tuiHandleXDBLayout (layoutDef);
593
e8b915dc 594}
c906108c
SS
595
596
597static void
eca6576c 598_tuiToggleSplitLayout_command (char *arg, int fromTTY)
c906108c
SS
599{
600 TuiLayoutDefPtr layoutDef = tuiLayoutDef ();
601
19eb139b
SC
602 /* Make sure the curses mode is enabled. */
603 tui_enable ();
c906108c
SS
604 layoutDef->split = (!layoutDef->split);
605 _tuiHandleXDBLayout (layoutDef);
606
e8b915dc 607}
c906108c
SS
608
609
610static void
eca6576c 611_tuiLayout_command (char *arg, int fromTTY)
c906108c 612{
19eb139b
SC
613 /* Make sure the curses mode is enabled. */
614 tui_enable ();
615
616 /* Switch to the selected layout. */
080ce8c0 617 if (tui_set_layout_for_display_command (arg) != TUI_SUCCESS)
84b1e7c7 618 warning ("Invalid layout specified.\n%s", LAYOUT_USAGE);
c906108c 619
e8b915dc 620}
c906108c
SS
621
622/*
c5aa993b
JM
623 ** _nextLayout().
624 ** Answer the previous layout to cycle to.
625 */
c906108c 626static TuiLayoutType
c906108c 627_nextLayout (void)
c906108c
SS
628{
629 TuiLayoutType newLayout;
630
631 newLayout = currentLayout ();
632 if (newLayout == UNDEFINED_LAYOUT)
633 newLayout = SRC_COMMAND;
634 else
635 {
636 newLayout++;
637 if (newLayout == UNDEFINED_LAYOUT)
638 newLayout = SRC_COMMAND;
639 }
640
641 return newLayout;
642} /* _nextLayout */
643
644
645/*
c5aa993b
JM
646 ** _prevLayout().
647 ** Answer the next layout to cycle to.
648 */
c906108c 649static TuiLayoutType
c906108c 650_prevLayout (void)
c906108c
SS
651{
652 TuiLayoutType newLayout;
653
654 newLayout = currentLayout ();
655 if (newLayout == SRC_COMMAND)
656 newLayout = DISASSEM_DATA_COMMAND;
657 else
658 {
659 newLayout--;
660 if (newLayout == UNDEFINED_LAYOUT)
661 newLayout = DISASSEM_DATA_COMMAND;
662 }
663
664 return newLayout;
665} /* _prevLayout */
666
667
668
669/*
c5aa993b
JM
670 ** _makeCommandWindow().
671 */
c906108c 672static void
eca6576c 673_makeCommandWindow (TuiWinInfoPtr * winInfoPtr, int height, int originY)
c906108c
SS
674{
675 _initAndMakeWin ((Opaque *) winInfoPtr,
676 CMD_WIN,
677 height,
678 termWidth (),
679 0,
680 originY,
681 DONT_BOX_WINDOW);
682
683 (*winInfoPtr)->canHighlight = FALSE;
684
685 return;
686} /* _makeCommandWindow */
687
688
689/*
c5aa993b
JM
690 ** _makeSourceWindow().
691 */
c906108c 692static void
eca6576c 693_makeSourceWindow (TuiWinInfoPtr * winInfoPtr, int height, int originY)
c906108c
SS
694{
695 _makeSourceOrDisassemWindow (winInfoPtr, SRC_WIN, height, originY);
696
697 return;
698} /* _makeSourceWindow */
699
700
701/*
c5aa993b
JM
702 ** _makeDisassemWindow().
703 */
c906108c 704static void
eca6576c 705_makeDisassemWindow (TuiWinInfoPtr * winInfoPtr, int height, int originY)
c906108c
SS
706{
707 _makeSourceOrDisassemWindow (winInfoPtr, DISASSEM_WIN, height, originY);
708
709 return;
710} /* _makeDisassemWindow */
711
712
713/*
c5aa993b
JM
714 ** _makeDataWindow().
715 */
c906108c 716static void
eca6576c 717_makeDataWindow (TuiWinInfoPtr * winInfoPtr, int height, int originY)
c906108c
SS
718{
719 _initAndMakeWin ((Opaque *) winInfoPtr,
720 DATA_WIN,
721 height,
722 termWidth (),
723 0,
724 originY,
725 BOX_WINDOW);
726
727 return;
728} /* _makeDataWindow */
729
730
731
732/*
c5aa993b
JM
733 ** _showSourceCommand().
734 ** Show the Source/Command layout
735 */
c906108c 736static void
c906108c 737_showSourceCommand (void)
c906108c
SS
738{
739 _showSourceOrDisassemAndCommand (SRC_COMMAND);
740
741 return;
742} /* _showSourceCommand */
743
744
745/*
c5aa993b
JM
746 ** _showDisassemCommand().
747 ** Show the Dissassem/Command layout
748 */
c906108c 749static void
c906108c 750_showDisassemCommand (void)
c906108c
SS
751{
752 _showSourceOrDisassemAndCommand (DISASSEM_COMMAND);
753
754 return;
755} /* _showDisassemCommand */
756
757
758/*
c5aa993b
JM
759 ** _showSourceDisassemCommand().
760 ** Show the Source/Disassem/Command layout
761 */
c906108c 762static void
c906108c 763_showSourceDisassemCommand (void)
c906108c 764{
c906108c
SS
765 if (currentLayout () != SRC_DISASSEM_COMMAND)
766 {
767 int cmdHeight, srcHeight, asmHeight;
768
769 if (m_winPtrNotNull (cmdWin))
770 cmdHeight = cmdWin->generic.height;
771 else
772 cmdHeight = termHeight () / 3;
773
774 srcHeight = (termHeight () - cmdHeight) / 2;
775 asmHeight = termHeight () - (srcHeight + cmdHeight);
776
777 if (m_winPtrIsNull (srcWin))
778 _makeSourceWindow (&srcWin, srcHeight, 0);
779 else
780 {
781 _initGenWinInfo (&srcWin->generic,
782 srcWin->generic.type,
783 srcHeight,
784 srcWin->generic.width,
785 srcWin->detail.sourceInfo.executionInfo->width,
786 0);
787 srcWin->canHighlight = TRUE;
788 _initGenWinInfo (srcWin->detail.sourceInfo.executionInfo,
789 EXEC_INFO_WIN,
790 srcHeight,
791 3,
792 0,
793 0);
794 m_beVisible (srcWin);
795 m_beVisible (srcWin->detail.sourceInfo.executionInfo);
796 srcWin->detail.sourceInfo.hasLocator = FALSE;;
797 }
798 if (m_winPtrNotNull (srcWin))
799 {
800 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
801
802 tuiShowSourceContent (srcWin);
803 if (m_winPtrIsNull (disassemWin))
804 {
805 _makeDisassemWindow (&disassemWin, asmHeight, srcHeight - 1);
806 _initAndMakeWin ((Opaque *) & locator,
807 LOCATOR_WIN,
808 2 /* 1 */ ,
809 termWidth (),
810 0,
811 (srcHeight + asmHeight) - 1,
812 DONT_BOX_WINDOW);
813 }
814 else
815 {
816 _initGenWinInfo (locator,
817 LOCATOR_WIN,
818 2 /* 1 */ ,
819 termWidth (),
820 0,
821 (srcHeight + asmHeight) - 1);
822 disassemWin->detail.sourceInfo.hasLocator = TRUE;
823 _initGenWinInfo (
824 &disassemWin->generic,
825 disassemWin->generic.type,
826 asmHeight,
827 disassemWin->generic.width,
828 disassemWin->detail.sourceInfo.executionInfo->width,
829 srcHeight - 1);
830 _initGenWinInfo (disassemWin->detail.sourceInfo.executionInfo,
831 EXEC_INFO_WIN,
832 asmHeight,
833 3,
834 0,
835 srcHeight - 1);
836 disassemWin->canHighlight = TRUE;
837 m_beVisible (disassemWin);
838 m_beVisible (disassemWin->detail.sourceInfo.executionInfo);
839 }
840 if (m_winPtrNotNull (disassemWin))
841 {
842 srcWin->detail.sourceInfo.hasLocator = FALSE;
843 disassemWin->detail.sourceInfo.hasLocator = TRUE;
844 m_beVisible (locator);
845 tuiShowLocatorContent ();
846 tuiShowSourceContent (disassemWin);
847
848 if (m_winPtrIsNull (cmdWin))
849 _makeCommandWindow (&cmdWin,
850 cmdHeight,
851 termHeight () - cmdHeight);
852 else
853 {
854 _initGenWinInfo (&cmdWin->generic,
855 cmdWin->generic.type,
856 cmdWin->generic.height,
857 cmdWin->generic.width,
858 0,
859 cmdWin->generic.origin.y);
860 cmdWin->canHighlight = FALSE;
861 m_beVisible (cmdWin);
862 }
863 if (m_winPtrNotNull (cmdWin))
864 tuiRefreshWin (&cmdWin->generic);
865 }
866 }
867 setCurrentLayoutTo (SRC_DISASSEM_COMMAND);
868 }
869
870 return;
871} /* _showSourceDisassemCommand */
872
873
874/*
c5aa993b
JM
875 ** _showData().
876 ** Show the Source/Data/Command or the Dissassembly/Data/Command layout
877 */
c906108c 878static void
eca6576c 879_showData (TuiLayoutType newLayout)
c906108c
SS
880{
881 int totalHeight = (termHeight () - cmdWin->generic.height);
882 int srcHeight, dataHeight;
883 TuiWinType winType;
884 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
885
886
887 dataHeight = totalHeight / 2;
888 srcHeight = totalHeight - dataHeight;
889 m_allBeInvisible ();
890 m_beInvisible (locator);
891 _makeDataWindow (&dataWin, dataHeight, 0);
892 dataWin->canHighlight = TRUE;
893 if (newLayout == SRC_DATA_COMMAND)
894 winType = SRC_WIN;
895 else
896 winType = DISASSEM_WIN;
897 if (m_winPtrIsNull (winList[winType]))
898 {
899 if (winType == SRC_WIN)
900 _makeSourceWindow (&winList[winType], srcHeight, dataHeight - 1);
901 else
902 _makeDisassemWindow (&winList[winType], srcHeight, dataHeight - 1);
903 _initAndMakeWin ((Opaque *) & locator,
904 LOCATOR_WIN,
905 2 /* 1 */ ,
906 termWidth (),
907 0,
908 totalHeight - 1,
909 DONT_BOX_WINDOW);
910 }
911 else
912 {
913 _initGenWinInfo (&winList[winType]->generic,
914 winList[winType]->generic.type,
915 srcHeight,
916 winList[winType]->generic.width,
917 winList[winType]->detail.sourceInfo.executionInfo->width,
918 dataHeight - 1);
919 _initGenWinInfo (winList[winType]->detail.sourceInfo.executionInfo,
920 EXEC_INFO_WIN,
921 srcHeight,
922 3,
923 0,
924 dataHeight - 1);
925 m_beVisible (winList[winType]);
926 m_beVisible (winList[winType]->detail.sourceInfo.executionInfo);
927 _initGenWinInfo (locator,
928 LOCATOR_WIN,
929 2 /* 1 */ ,
930 termWidth (),
931 0,
932 totalHeight - 1);
933 }
934 winList[winType]->detail.sourceInfo.hasLocator = TRUE;
935 m_beVisible (locator);
936 tuiShowLocatorContent ();
937 addToSourceWindows (winList[winType]);
938 setCurrentLayoutTo (newLayout);
939
940 return;
941} /* _showData */
942
943/*
c5aa993b
JM
944 ** _initGenWinInfo().
945 */
c906108c 946static void
eca6576c
SC
947_initGenWinInfo (TuiGenWinInfoPtr winInfo, TuiWinType type,
948 int height, int width, int originX, int originY)
c906108c
SS
949{
950 int h = height;
951
952 winInfo->type = type;
953 winInfo->width = width;
954 winInfo->height = h;
955 if (h > 1)
956 {
957 winInfo->viewportHeight = h - 1;
958 if (winInfo->type != CMD_WIN)
959 winInfo->viewportHeight--;
960 }
961 else
962 winInfo->viewportHeight = 1;
963 winInfo->origin.x = originX;
964 winInfo->origin.y = originY;
965
966 return;
967} /* _initGenWinInfo */
968
969/*
c5aa993b
JM
970 ** _initAndMakeWin().
971 */
c906108c 972static void
eca6576c
SC
973_initAndMakeWin (Opaque * winInfoPtr, TuiWinType winType,
974 int height, int width, int originX, int originY, int boxIt)
c906108c
SS
975{
976 Opaque opaqueWinInfo = *winInfoPtr;
977 TuiGenWinInfoPtr generic;
978
979 if (opaqueWinInfo == (Opaque) NULL)
980 {
981 if (m_winIsAuxillary (winType))
982 opaqueWinInfo = (Opaque) allocGenericWinInfo ();
983 else
984 opaqueWinInfo = (Opaque) allocWinInfo (winType);
985 }
986 if (m_winIsAuxillary (winType))
987 generic = (TuiGenWinInfoPtr) opaqueWinInfo;
988 else
989 generic = &((TuiWinInfoPtr) opaqueWinInfo)->generic;
990
991 if (opaqueWinInfo != (Opaque) NULL)
992 {
993 _initGenWinInfo (generic, winType, height, width, originX, originY);
994 if (!m_winIsAuxillary (winType))
995 {
996 if (generic->type == CMD_WIN)
997 ((TuiWinInfoPtr) opaqueWinInfo)->canHighlight = FALSE;
998 else
999 ((TuiWinInfoPtr) opaqueWinInfo)->canHighlight = TRUE;
1000 }
1001 makeWindow (generic, boxIt);
c906108c
SS
1002 }
1003 *winInfoPtr = opaqueWinInfo;
bc712bbf 1004}
c906108c
SS
1005
1006
1007/*
c5aa993b
JM
1008 ** _makeSourceOrDisassemWindow().
1009 */
c906108c 1010static void
eca6576c
SC
1011_makeSourceOrDisassemWindow (TuiWinInfoPtr * winInfoPtr, TuiWinType type,
1012 int height, int originY)
c906108c
SS
1013{
1014 TuiGenWinInfoPtr executionInfo = (TuiGenWinInfoPtr) NULL;
1015
1016 /*
c5aa993b
JM
1017 ** Create the exeuction info window.
1018 */
c906108c
SS
1019 if (type == SRC_WIN)
1020 executionInfo = sourceExecInfoWinPtr ();
1021 else
1022 executionInfo = disassemExecInfoWinPtr ();
1023 _initAndMakeWin ((Opaque *) & executionInfo,
1024 EXEC_INFO_WIN,
1025 height,
1026 3,
1027 0,
1028 originY,
1029 DONT_BOX_WINDOW);
1030 /*
c5aa993b
JM
1031 ** Now create the source window.
1032 */
c906108c
SS
1033 _initAndMakeWin ((Opaque *) winInfoPtr,
1034 type,
1035 height,
1036 termWidth () - executionInfo->width,
1037 executionInfo->width,
1038 originY,
1039 BOX_WINDOW);
1040
1041 (*winInfoPtr)->detail.sourceInfo.executionInfo = executionInfo;
1042
1043 return;
1044} /* _makeSourceOrDisassemWindow */
1045
1046
1047/*
c5aa993b
JM
1048 ** _showSourceOrDisassemAndCommand().
1049 ** Show the Source/Command or the Disassem layout
1050 */
c906108c 1051static void
eca6576c 1052_showSourceOrDisassemAndCommand (TuiLayoutType layoutType)
c906108c
SS
1053{
1054 if (currentLayout () != layoutType)
1055 {
1056 TuiWinInfoPtr *winInfoPtr;
c906108c
SS
1057 int srcHeight, cmdHeight;
1058 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
1059
1060 if (m_winPtrNotNull (cmdWin))
1061 cmdHeight = cmdWin->generic.height;
1062 else
1063 cmdHeight = termHeight () / 3;
1064 srcHeight = termHeight () - cmdHeight;
1065
1066
1067 if (layoutType == SRC_COMMAND)
1068 winInfoPtr = &srcWin;
1069 else
1070 winInfoPtr = &disassemWin;
1071
1072 if (m_winPtrIsNull (*winInfoPtr))
1073 {
1074 if (layoutType == SRC_COMMAND)
1075 _makeSourceWindow (winInfoPtr, srcHeight - 1, 0);
1076 else
1077 _makeDisassemWindow (winInfoPtr, srcHeight - 1, 0);
1078 _initAndMakeWin ((Opaque *) & locator,
1079 LOCATOR_WIN,
1080 2 /* 1 */ ,
1081 termWidth (),
1082 0,
1083 srcHeight - 1,
1084 DONT_BOX_WINDOW);
1085 }
1086 else
1087 {
1088 _initGenWinInfo (locator,
1089 LOCATOR_WIN,
1090 2 /* 1 */ ,
1091 termWidth (),
1092 0,
1093 srcHeight - 1);
1094 (*winInfoPtr)->detail.sourceInfo.hasLocator = TRUE;
1095 _initGenWinInfo (
1096 &(*winInfoPtr)->generic,
1097 (*winInfoPtr)->generic.type,
1098 srcHeight - 1,
1099 (*winInfoPtr)->generic.width,
1100 (*winInfoPtr)->detail.sourceInfo.executionInfo->width,
1101 0);
1102 _initGenWinInfo ((*winInfoPtr)->detail.sourceInfo.executionInfo,
1103 EXEC_INFO_WIN,
1104 srcHeight - 1,
1105 3,
1106 0,
1107 0);
1108 (*winInfoPtr)->canHighlight = TRUE;
1109 m_beVisible (*winInfoPtr);
1110 m_beVisible ((*winInfoPtr)->detail.sourceInfo.executionInfo);
1111 }
1112 if (m_winPtrNotNull (*winInfoPtr))
1113 {
1114 (*winInfoPtr)->detail.sourceInfo.hasLocator = TRUE;
1115 m_beVisible (locator);
1116 tuiShowLocatorContent ();
1117 tuiShowSourceContent (*winInfoPtr);
1118
1119 if (m_winPtrIsNull (cmdWin))
1120 {
1121 _makeCommandWindow (&cmdWin, cmdHeight, srcHeight);
1122 tuiRefreshWin (&cmdWin->generic);
1123 }
1124 else
1125 {
1126 _initGenWinInfo (&cmdWin->generic,
1127 cmdWin->generic.type,
1128 cmdWin->generic.height,
1129 cmdWin->generic.width,
1130 cmdWin->generic.origin.x,
1131 cmdWin->generic.origin.y);
1132 cmdWin->canHighlight = FALSE;
1133 m_beVisible (cmdWin);
1134 }
1135 }
1136 setCurrentLayoutTo (layoutType);
1137 }
1138
1139 return;
1140} /* _showSourceOrDisassemAndCommand */
This page took 0.442389 seconds and 4 git commands to generate.