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