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