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