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