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