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