* tuiWin.c: Add missing includes.
[deliverable/binutils-gdb.git] / gdb / tui / tuiWin.c
1 /* TUI window generic functions.
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 /* This module contains procedures for handling tui window functions
23 like resize, scrolling, scrolling, changing focus, etc.
24
25 Author: Susan B. Macchia */
26
27 #include <string.h>
28 #include <ctype.h>
29 #include "defs.h"
30 #include "command.h"
31 #include "symtab.h"
32 #include "breakpoint.h"
33 #include "frame.h"
34
35 #include "tui.h"
36 #include "tuiData.h"
37 #include "tuiGeneralWin.h"
38 #include "tuiStack.h"
39 #include "tuiRegs.h"
40 #include "tuiDisassem.h"
41 #include "tuiSource.h"
42 #include "tuiSourceWin.h"
43 #include "tuiDataWin.h"
44
45 /*******************************
46 ** External Declarations
47 ********************************/
48 extern void init_page_info ();
49
50 /*******************************
51 ** Static Local Decls
52 ********************************/
53 static void _makeVisibleWithNewHeight (TuiWinInfoPtr);
54 static void _makeInvisibleAndSetNewHeight (TuiWinInfoPtr, int);
55 static TuiStatus _tuiAdjustWinHeights (TuiWinInfoPtr, int);
56 static int _newHeightOk (TuiWinInfoPtr, int);
57 static void _tuiSetTabWidth_command (char *, int);
58 static void _tuiRefreshAll_command (char *, int);
59 static void _tuiSetWinHeight_command (char *, int);
60 static void _tuiXDBsetWinHeight_command (char *, int);
61 static void _tuiAllWindowsInfo (char *, int);
62 static void _tuiSetFocus_command (char *, int);
63 static void _tuiScrollForward_command (char *, int);
64 static void _tuiScrollBackward_command (char *, int);
65 static void _tuiScrollLeft_command (char *, int);
66 static void _tuiScrollRight_command (char *, int);
67 static void _parseScrollingArgs (char *, TuiWinInfoPtr *, int *);
68
69
70 /***************************************
71 ** DEFINITIONS
72 ***************************************/
73 #define WIN_HEIGHT_USAGE "Usage: winheight <win_name> [+ | -] <#lines>\n"
74 #define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n"
75 #define FOCUS_USAGE "Usage: focus {<win> | next | prev}\n"
76
77 /***************************************
78 ** PUBLIC FUNCTIONS
79 ***************************************/
80
81 /*
82 ** _initialize_tuiWin().
83 ** Function to initialize gdb commands, for tui window manipulation.
84 */
85 void
86 _initialize_tuiWin (void)
87 {
88 if (tui_version)
89 {
90 add_com ("refresh", class_tui, _tuiRefreshAll_command,
91 "Refresh the terminal display.\n");
92 if (xdb_commands)
93 add_com_alias ("U", "refresh", class_tui, 0);
94 add_com ("tabset", class_tui, _tuiSetTabWidth_command,
95 "Set the width (in characters) of tab stops.\n\
96 Usage: tabset <n>\n");
97 add_com ("winheight", class_tui, _tuiSetWinHeight_command,
98 "Set the height of a specified window.\n\
99 Usage: winheight <win_name> [+ | -] <#lines>\n\
100 Window names are:\n\
101 src : the source window\n\
102 cmd : the command window\n\
103 asm : the disassembly window\n\
104 regs : the register display\n");
105 add_com_alias ("wh", "winheight", class_tui, 0);
106 add_info ("win", _tuiAllWindowsInfo,
107 "List of all displayed windows.\n");
108 add_com ("focus", class_tui, _tuiSetFocus_command,
109 "Set focus to named window or next/prev window.\n\
110 Usage: focus {<win> | next | prev}\n\
111 Valid Window names are:\n\
112 src : the source window\n\
113 asm : the disassembly window\n\
114 regs : the register display\n\
115 cmd : the command window\n");
116 add_com_alias ("fs", "focus", class_tui, 0);
117 add_com ("+", class_tui, _tuiScrollForward_command,
118 "Scroll window forward.\nUsage: + [win] [n]\n");
119 add_com ("-", class_tui, _tuiScrollBackward_command,
120 "Scroll window backward.\nUsage: - [win] [n]\n");
121 add_com ("<", class_tui, _tuiScrollLeft_command,
122 "Scroll window forward.\nUsage: < [win] [n]\n");
123 add_com (">", class_tui, _tuiScrollRight_command,
124 "Scroll window backward.\nUsage: > [win] [n]\n");
125 if (xdb_commands)
126 add_com ("w", class_xdb, _tuiXDBsetWinHeight_command,
127 "XDB compatibility command for setting the height of a command window.\n\
128 Usage: w <#lines>\n");
129 }
130
131 return;
132 } /* _intialize_tuiWin */
133
134
135 /*
136 ** tuiClearWinFocusFrom
137 ** Clear the logical focus from winInfo
138 */
139 void
140 tuiClearWinFocusFrom (TuiWinInfoPtr winInfo)
141 {
142 if (m_winPtrNotNull (winInfo))
143 {
144 if (winInfo->generic.type != CMD_WIN)
145 unhighlightWin (winInfo);
146 tuiSetWinWithFocus ((TuiWinInfoPtr) NULL);
147 }
148
149 return;
150 } /* tuiClearWinFocusFrom */
151
152
153 /*
154 ** tuiClearWinFocus().
155 ** Clear the window that has focus.
156 */
157 void
158 tuiClearWinFocus (void)
159 {
160 tuiClearWinFocusFrom (tuiWinWithFocus ());
161
162 return;
163 } /* tuiClearWinFocus */
164
165
166 /*
167 ** tuiSetWinFocusTo
168 ** Set the logical focus to winInfo
169 */
170 void
171 tuiSetWinFocusTo (TuiWinInfoPtr winInfo)
172 {
173 if (m_winPtrNotNull (winInfo))
174 {
175 TuiWinInfoPtr winWithFocus = tuiWinWithFocus ();
176
177 if (m_winPtrNotNull (winWithFocus) &&
178 winWithFocus->generic.type != CMD_WIN)
179 unhighlightWin (winWithFocus);
180 tuiSetWinWithFocus (winInfo);
181 if (winInfo->generic.type != CMD_WIN)
182 highlightWin (winInfo);
183 }
184
185 return;
186 } /* tuiSetWinFocusTo */
187
188
189 char *
190 tuiStrDup (char *str)
191 {
192 char *newStr = (char *) NULL;
193
194 if (str != (char *) NULL)
195 {
196 newStr = (char *) xmalloc (strlen (str) + 1);
197 strcpy (newStr, str);
198 }
199
200 return newStr;
201 } /* tuiStrDup */
202
203
204 /*
205 ** tuiScrollForward().
206 */
207 void
208 tuiScrollForward (TuiWinInfoPtr winToScroll, int numToScroll)
209 {
210 if (winToScroll != cmdWin)
211 {
212 int _numToScroll = numToScroll;
213
214 if (numToScroll == 0)
215 _numToScroll = winToScroll->generic.height - 3;
216 /*
217 ** If we are scrolling the source or disassembly window, do a
218 ** "psuedo" scroll since not all of the source is in memory,
219 ** only what is in the viewport. If winToScroll is the
220 ** command window do nothing since the term should handle it.
221 */
222 if (winToScroll == srcWin)
223 tuiVerticalSourceScroll (FORWARD_SCROLL, _numToScroll);
224 else if (winToScroll == disassemWin)
225 tuiVerticalDisassemScroll (FORWARD_SCROLL, _numToScroll);
226 else if (winToScroll == dataWin)
227 tuiVerticalDataScroll (FORWARD_SCROLL, _numToScroll);
228 }
229
230 return;
231 } /* tuiScrollForward */
232
233
234 /*
235 ** tuiScrollBackward().
236 */
237 void
238 tuiScrollBackward (TuiWinInfoPtr winToScroll, int numToScroll)
239 {
240 if (winToScroll != cmdWin)
241 {
242 int _numToScroll = numToScroll;
243
244 if (numToScroll == 0)
245 _numToScroll = winToScroll->generic.height - 3;
246 /*
247 ** If we are scrolling the source or disassembly window, do a
248 ** "psuedo" scroll since not all of the source is in memory,
249 ** only what is in the viewport. If winToScroll is the
250 ** command window do nothing since the term should handle it.
251 */
252 if (winToScroll == srcWin)
253 tuiVerticalSourceScroll (BACKWARD_SCROLL, _numToScroll);
254 else if (winToScroll == disassemWin)
255 tuiVerticalDisassemScroll (BACKWARD_SCROLL, _numToScroll);
256 else if (winToScroll == dataWin)
257 tuiVerticalDataScroll (BACKWARD_SCROLL, _numToScroll);
258 }
259 return;
260 } /* tuiScrollBackward */
261
262
263 /*
264 ** tuiScrollLeft().
265 */
266 void
267 tuiScrollLeft (TuiWinInfoPtr winToScroll, int numToScroll)
268 {
269 if (winToScroll != cmdWin)
270 {
271 int _numToScroll = numToScroll;
272
273 if (_numToScroll == 0)
274 _numToScroll = 1;
275 /*
276 ** If we are scrolling the source or disassembly window, do a
277 ** "psuedo" scroll since not all of the source is in memory,
278 ** only what is in the viewport. If winToScroll is the
279 ** command window do nothing since the term should handle it.
280 */
281 if (winToScroll == srcWin || winToScroll == disassemWin)
282 tuiHorizontalSourceScroll (winToScroll, LEFT_SCROLL, _numToScroll);
283 }
284 return;
285 } /* tuiScrollLeft */
286
287
288 /*
289 ** tuiScrollRight().
290 */
291 void
292 tuiScrollRight (TuiWinInfoPtr winToScroll, int numToScroll)
293 {
294 if (winToScroll != cmdWin)
295 {
296 int _numToScroll = numToScroll;
297
298 if (_numToScroll == 0)
299 _numToScroll = 1;
300 /*
301 ** If we are scrolling the source or disassembly window, do a
302 ** "psuedo" scroll since not all of the source is in memory,
303 ** only what is in the viewport. If winToScroll is the
304 ** command window do nothing since the term should handle it.
305 */
306 if (winToScroll == srcWin || winToScroll == disassemWin)
307 tuiHorizontalSourceScroll (winToScroll, RIGHT_SCROLL, _numToScroll);
308 }
309 return;
310 } /* tuiScrollRight */
311
312
313 /*
314 ** tui_vScroll().
315 ** Scroll a window. Arguments are passed through a va_list.
316 */
317 void
318 tui_vScroll (va_list args)
319 {
320 TuiScrollDirection direction = va_arg (args, TuiScrollDirection);
321 TuiWinInfoPtr winToScroll = va_arg (args, TuiWinInfoPtr);
322 int numToScroll = va_arg (args, int);
323
324 switch (direction)
325 {
326 case FORWARD_SCROLL:
327 tuiScrollForward (winToScroll, numToScroll);
328 break;
329 case BACKWARD_SCROLL:
330 tuiScrollBackward (winToScroll, numToScroll);
331 break;
332 case LEFT_SCROLL:
333 tuiScrollLeft (winToScroll, numToScroll);
334 break;
335 case RIGHT_SCROLL:
336 tuiScrollRight (winToScroll, numToScroll);
337 break;
338 default:
339 break;
340 }
341
342 return;
343 } /* tui_vScroll */
344
345
346 /*
347 ** tuiRefreshAll().
348 */
349 void
350 tuiRefreshAll (void)
351 {
352 TuiWinType type;
353
354 refreshAll (winList);
355 for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++)
356 {
357 if (winList[type] && winList[type]->generic.isVisible)
358 {
359 switch (type)
360 {
361 case SRC_WIN:
362 case DISASSEM_WIN:
363 tuiClearWin (&winList[type]->generic);
364 if (winList[type]->detail.sourceInfo.hasLocator)
365 tuiClearLocatorDisplay ();
366 tuiShowSourceContent (winList[type]);
367 checkAndDisplayHighlightIfNeeded (winList[type]);
368 tuiEraseExecInfoContent (winList[type]);
369 tuiUpdateExecInfo (winList[type]);
370 break;
371 case DATA_WIN:
372 tuiRefreshDataWin ();
373 break;
374 default:
375 break;
376 }
377 }
378 }
379 tuiClearLocatorDisplay ();
380 tuiShowLocatorContent ();
381
382 return;
383 } /* tuiRefreshAll */
384
385
386 /*
387 ** tuiResizeAll().
388 ** Resize all the windows based on the the terminal size. This
389 ** function gets called from within the readline sinwinch handler.
390 */
391 void
392 tuiResizeAll (void)
393 {
394 int heightDiff, widthDiff;
395 extern int screenheight, screenwidth; /* in readline */
396
397 widthDiff = screenwidth - termWidth ();
398 heightDiff = screenheight - termHeight ();
399 if (heightDiff || widthDiff)
400 {
401 TuiLayoutType curLayout = currentLayout ();
402 TuiWinInfoPtr winWithFocus = tuiWinWithFocus ();
403 TuiWinInfoPtr firstWin, secondWin;
404 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
405 TuiWinType winType;
406 int i, newHeight, splitDiff, cmdSplitDiff, numWinsDisplayed = 2;
407
408 /* turn keypad off while we resize */
409 if (winWithFocus != cmdWin)
410 keypad (cmdWin->generic.handle, FALSE);
411 init_page_info ();
412 setTermHeightTo (screenheight);
413 setTermWidthTo (screenwidth);
414 if (curLayout == SRC_DISASSEM_COMMAND ||
415 curLayout == SRC_DATA_COMMAND || curLayout == DISASSEM_DATA_COMMAND)
416 numWinsDisplayed++;
417 splitDiff = heightDiff / numWinsDisplayed;
418 cmdSplitDiff = splitDiff;
419 if (heightDiff % numWinsDisplayed)
420 {
421 if (heightDiff < 0)
422 cmdSplitDiff--;
423 else
424 cmdSplitDiff++;
425 }
426 /* now adjust each window */
427 clear ();
428 refresh ();
429 switch (curLayout)
430 {
431 case SRC_COMMAND:
432 case DISASSEM_COMMAND:
433 firstWin = (TuiWinInfoPtr) (sourceWindows ())->list[0];
434 firstWin->generic.width += widthDiff;
435 locator->width += widthDiff;
436 /* check for invalid heights */
437 if (heightDiff == 0)
438 newHeight = firstWin->generic.height;
439 else if ((firstWin->generic.height + splitDiff) >=
440 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
441 newHeight = screenheight - MIN_CMD_WIN_HEIGHT - 1;
442 else if ((firstWin->generic.height + splitDiff) <= 0)
443 newHeight = MIN_WIN_HEIGHT;
444 else
445 newHeight = firstWin->generic.height + splitDiff;
446
447 _makeInvisibleAndSetNewHeight (firstWin, newHeight);
448 cmdWin->generic.origin.y = locator->origin.y + 1;
449 cmdWin->generic.width += widthDiff;
450 newHeight = screenheight - cmdWin->generic.origin.y;
451 _makeInvisibleAndSetNewHeight (cmdWin, newHeight);
452 _makeVisibleWithNewHeight (firstWin);
453 _makeVisibleWithNewHeight (cmdWin);
454 if (firstWin->generic.contentSize <= 0)
455 tuiEraseSourceContent (firstWin, EMPTY_SOURCE_PROMPT);
456 break;
457 default:
458 if (curLayout == SRC_DISASSEM_COMMAND)
459 {
460 firstWin = srcWin;
461 firstWin->generic.width += widthDiff;
462 secondWin = disassemWin;
463 secondWin->generic.width += widthDiff;
464 }
465 else
466 {
467 firstWin = dataWin;
468 firstWin->generic.width += widthDiff;
469 secondWin = (TuiWinInfoPtr) (sourceWindows ())->list[0];
470 secondWin->generic.width += widthDiff;
471 }
472 /* Change the first window's height/width */
473 /* check for invalid heights */
474 if (heightDiff == 0)
475 newHeight = firstWin->generic.height;
476 else if ((firstWin->generic.height +
477 secondWin->generic.height + (splitDiff * 2)) >=
478 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
479 newHeight = (screenheight - MIN_CMD_WIN_HEIGHT - 1) / 2;
480 else if ((firstWin->generic.height + splitDiff) <= 0)
481 newHeight = MIN_WIN_HEIGHT;
482 else
483 newHeight = firstWin->generic.height + splitDiff;
484 _makeInvisibleAndSetNewHeight (firstWin, newHeight);
485
486 if (firstWin == dataWin && widthDiff != 0)
487 firstWin->detail.dataDisplayInfo.regsColumnCount =
488 tuiCalculateRegsColumnCount (
489 firstWin->detail.dataDisplayInfo.regsDisplayType);
490 locator->width += widthDiff;
491
492 /* Change the second window's height/width */
493 /* check for invalid heights */
494 if (heightDiff == 0)
495 newHeight = secondWin->generic.height;
496 else if ((firstWin->generic.height +
497 secondWin->generic.height + (splitDiff * 2)) >=
498 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
499 {
500 newHeight = screenheight - MIN_CMD_WIN_HEIGHT - 1;
501 if (newHeight % 2)
502 newHeight = (newHeight / 2) + 1;
503 else
504 newHeight /= 2;
505 }
506 else if ((secondWin->generic.height + splitDiff) <= 0)
507 newHeight = MIN_WIN_HEIGHT;
508 else
509 newHeight = secondWin->generic.height + splitDiff;
510 secondWin->generic.origin.y = firstWin->generic.height - 1;
511 _makeInvisibleAndSetNewHeight (secondWin, newHeight);
512
513 /* Change the command window's height/width */
514 cmdWin->generic.origin.y = locator->origin.y + 1;
515 _makeInvisibleAndSetNewHeight (
516 cmdWin, cmdWin->generic.height + cmdSplitDiff);
517 _makeVisibleWithNewHeight (firstWin);
518 _makeVisibleWithNewHeight (secondWin);
519 _makeVisibleWithNewHeight (cmdWin);
520 if (firstWin->generic.contentSize <= 0)
521 tuiEraseSourceContent (firstWin, EMPTY_SOURCE_PROMPT);
522 if (secondWin->generic.contentSize <= 0)
523 tuiEraseSourceContent (secondWin, EMPTY_SOURCE_PROMPT);
524 break;
525 }
526 /*
527 ** Now remove all invisible windows, and their content so that they get
528 ** created again when called for with the new size
529 */
530 for (winType = SRC_WIN; (winType < MAX_MAJOR_WINDOWS); winType++)
531 {
532 if (winType != CMD_WIN && m_winPtrNotNull (winList[winType]) &&
533 !winList[winType]->generic.isVisible)
534 {
535 freeWindow (winList[winType]);
536 winList[winType] = (TuiWinInfoPtr) NULL;
537 }
538 }
539 tuiSetWinResizedTo (TRUE);
540 /* turn keypad back on, unless focus is in the command window */
541 if (winWithFocus != cmdWin)
542 keypad (cmdWin->generic.handle, TRUE);
543 }
544 return;
545 } /* tuiResizeAll */
546
547
548 /*
549 ** tuiSigwinchHandler()
550 ** SIGWINCH signal handler for the tui. This signal handler is
551 ** always called, even when the readline package clears signals
552 ** because it is set as the old_sigwinch() (TUI only)
553 */
554 void
555 tuiSigwinchHandler (int signal)
556 {
557 /*
558 ** Say that a resize was done so that the readline can do it
559 ** later when appropriate.
560 */
561 tuiSetWinResizedTo (TRUE);
562
563 return;
564 } /* tuiSigwinchHandler */
565
566
567
568 /*************************
569 ** STATIC LOCAL FUNCTIONS
570 **************************/
571
572
573 /*
574 ** _tuiScrollForward_command().
575 */
576 static void
577 _tuiScrollForward_command (char *arg, int fromTTY)
578 {
579 int numToScroll = 1;
580 TuiWinInfoPtr winToScroll;
581
582 if (arg == (char *) NULL)
583 _parseScrollingArgs (arg, &winToScroll, (int *) NULL);
584 else
585 _parseScrollingArgs (arg, &winToScroll, &numToScroll);
586 tuiDo ((TuiOpaqueFuncPtr) tui_vScroll,
587 FORWARD_SCROLL,
588 winToScroll,
589 numToScroll);
590
591 return;
592 } /* _tuiScrollForward_command */
593
594
595 /*
596 ** _tuiScrollBackward_command().
597 */
598 static void
599 _tuiScrollBackward_command (char *arg, int fromTTY)
600 {
601 int numToScroll = 1;
602 TuiWinInfoPtr winToScroll;
603
604 if (arg == (char *) NULL)
605 _parseScrollingArgs (arg, &winToScroll, (int *) NULL);
606 else
607 _parseScrollingArgs (arg, &winToScroll, &numToScroll);
608 tuiDo ((TuiOpaqueFuncPtr) tui_vScroll,
609 BACKWARD_SCROLL,
610 winToScroll,
611 numToScroll);
612
613 return;
614 } /* _tuiScrollBackward_command */
615
616
617 /*
618 ** _tuiScrollLeft_command().
619 */
620 static void
621 _tuiScrollLeft_command (char *arg, int fromTTY)
622 {
623 int numToScroll;
624 TuiWinInfoPtr winToScroll;
625
626 _parseScrollingArgs (arg, &winToScroll, &numToScroll);
627 tuiDo ((TuiOpaqueFuncPtr) tui_vScroll,
628 LEFT_SCROLL,
629 winToScroll,
630 numToScroll);
631
632 return;
633 } /* _tuiScrollLeft_command */
634
635
636 /*
637 ** _tuiScrollRight_command().
638 */
639 static void
640 _tuiScrollRight_command (char *arg, int fromTTY)
641 {
642 int numToScroll;
643 TuiWinInfoPtr winToScroll;
644
645 _parseScrollingArgs (arg, &winToScroll, &numToScroll);
646 tuiDo ((TuiOpaqueFuncPtr) tui_vScroll,
647 RIGHT_SCROLL,
648 winToScroll,
649 numToScroll);
650
651 return;
652 } /* _tuiScrollRight_command */
653
654
655 /*
656 ** _tuiSetFocus().
657 ** Set focus to the window named by 'arg'
658 */
659 static void
660 _tuiSetFocus (char *arg, int fromTTY)
661 {
662 if (arg != (char *) NULL)
663 {
664 char *bufPtr = (char *) tuiStrDup (arg);
665 int i;
666 TuiWinInfoPtr winInfo = (TuiWinInfoPtr) NULL;
667
668 for (i = 0; (i < strlen (bufPtr)); i++)
669 bufPtr[i] = toupper (arg[i]);
670
671 if (subset_compare (bufPtr, "NEXT"))
672 winInfo = tuiNextWin (tuiWinWithFocus ());
673 else if (subset_compare (bufPtr, "PREV"))
674 winInfo = tuiPrevWin (tuiWinWithFocus ());
675 else
676 winInfo = partialWinByName (bufPtr);
677
678 if (winInfo == (TuiWinInfoPtr) NULL || !winInfo->generic.isVisible)
679 warning ("Invalid window specified. \n\
680 The window name specified must be valid and visible.\n");
681 else
682 {
683 tuiSetWinFocusTo (winInfo);
684 keypad (cmdWin->generic.handle, (winInfo != cmdWin));
685 }
686
687 if (dataWin && dataWin->generic.isVisible)
688 tuiRefreshDataWin ();
689 tuiFree (bufPtr);
690 printf_filtered ("Focus set to %s window.\n",
691 winName ((TuiGenWinInfoPtr) tuiWinWithFocus ()));
692 }
693 else
694 warning ("Incorrect Number of Arguments.\n%s", FOCUS_USAGE);
695
696 return;
697 } /* _tuiSetFocus */
698
699
700 /*
701 ** _tui_vSetFocus()
702 */
703 static void
704 _tui_vSetFocus (va_list args)
705 {
706 char *arg = va_arg (args, char *);
707 int fromTTY = va_arg (args, int);
708
709 _tuiSetFocus (arg, fromTTY);
710
711 return;
712 } /* tui_vSetFocus */
713
714
715 /*
716 ** _tuiSetFocus_command()
717 */
718 static void
719 _tuiSetFocus_command (char *arg, int fromTTY)
720 {
721 tuiDo ((TuiOpaqueFuncPtr) _tui_vSetFocus, arg, fromTTY);
722
723 return;
724 } /* tui_SetFocus */
725
726
727 /*
728 ** _tuiAllWindowsInfo().
729 */
730 static void
731 _tuiAllWindowsInfo (char *arg, int fromTTY)
732 {
733 TuiWinType type;
734 TuiWinInfoPtr winWithFocus = tuiWinWithFocus ();
735
736 for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
737 if (winList[type]->generic.isVisible)
738 {
739 if (winWithFocus == winList[type])
740 printf_filtered (" %s\t(%d lines) <has focus>\n",
741 winName (&winList[type]->generic),
742 winList[type]->generic.height);
743 else
744 printf_filtered (" %s\t(%d lines)\n",
745 winName (&winList[type]->generic),
746 winList[type]->generic.height);
747 }
748
749 return;
750 } /* _tuiAllWindowsInfo */
751
752
753 /*
754 ** _tuiRefreshAll_command().
755 */
756 static void
757 _tuiRefreshAll_command (char *arg, int fromTTY)
758 {
759 tuiDo ((TuiOpaqueFuncPtr) tuiRefreshAll);
760 }
761
762
763 /*
764 ** _tuiSetWinTabWidth_command().
765 ** Set the height of the specified window.
766 */
767 static void
768 _tuiSetTabWidth_command (char *arg, int fromTTY)
769 {
770 if (arg != (char *) NULL)
771 {
772 int ts;
773
774 ts = atoi (arg);
775 if (ts > 0)
776 tuiSetDefaultTabLen (ts);
777 else
778 warning ("Tab widths greater than 0 must be specified.\n");
779 }
780
781 return;
782 } /* _tuiSetTabWidth_command */
783
784
785 /*
786 ** _tuiSetWinHeight().
787 ** Set the height of the specified window.
788 */
789 static void
790 _tuiSetWinHeight (char *arg, int fromTTY)
791 {
792 if (arg != (char *) NULL)
793 {
794 char *buf = tuiStrDup (arg);
795 char *bufPtr = buf;
796 char *wname = (char *) NULL;
797 int newHeight, i;
798 TuiWinInfoPtr winInfo;
799
800 wname = bufPtr;
801 bufPtr = strchr (bufPtr, ' ');
802 if (bufPtr != (char *) NULL)
803 {
804 *bufPtr = (char) 0;
805
806 /*
807 ** Validate the window name
808 */
809 for (i = 0; i < strlen (wname); i++)
810 wname[i] = toupper (wname[i]);
811 winInfo = partialWinByName (wname);
812
813 if (winInfo == (TuiWinInfoPtr) NULL || !winInfo->generic.isVisible)
814 warning ("Invalid window specified. \n\
815 The window name specified must be valid and visible.\n");
816 else
817 {
818 /* Process the size */
819 while (*(++bufPtr) == ' ')
820 ;
821
822 if (*bufPtr != (char) 0)
823 {
824 int negate = FALSE;
825 int fixedSize = TRUE;
826 int inputNo;;
827
828 if (*bufPtr == '+' || *bufPtr == '-')
829 {
830 if (*bufPtr == '-')
831 negate = TRUE;
832 fixedSize = FALSE;
833 bufPtr++;
834 }
835 inputNo = atoi (bufPtr);
836 if (inputNo > 0)
837 {
838 if (negate)
839 inputNo *= (-1);
840 if (fixedSize)
841 newHeight = inputNo;
842 else
843 newHeight = winInfo->generic.height + inputNo;
844 /*
845 ** Now change the window's height, and adjust all
846 ** other windows around it
847 */
848 if (_tuiAdjustWinHeights (winInfo,
849 newHeight) == TUI_FAILURE)
850 warning ("Invalid window height specified.\n%s",
851 WIN_HEIGHT_USAGE);
852 else
853 init_page_info ();
854 }
855 else
856 warning ("Invalid window height specified.\n%s",
857 WIN_HEIGHT_USAGE);
858 }
859 }
860 }
861 else
862 printf_filtered (WIN_HEIGHT_USAGE);
863
864 if (buf != (char *) NULL)
865 tuiFree (buf);
866 }
867 else
868 printf_filtered (WIN_HEIGHT_USAGE);
869
870 return;
871 } /* _tuiSetWinHeight */
872
873
874 /*
875 ** _tui_vSetWinHeight().
876 ** Set the height of the specified window, with va_list.
877 */
878 static void
879 _tui_vSetWinHeight (va_list args)
880 {
881 char *arg = va_arg (args, char *);
882 int fromTTY = va_arg (args, int);
883
884 _tuiSetWinHeight (arg, fromTTY);
885
886 return;
887 } /* _tui_vSetWinHeight */
888
889
890 /*
891 ** _tuiSetWinHeight_command().
892 ** Set the height of the specified window, with va_list.
893 */
894 static void
895 _tuiSetWinHeight_command (char *arg, int fromTTY)
896 {
897 tuiDo ((TuiOpaqueFuncPtr) _tui_vSetWinHeight, arg, fromTTY);
898
899 return;
900 } /* _tuiSetWinHeight_command */
901
902
903 /*
904 ** _tuiXDBsetWinHeight().
905 ** XDB Compatibility command for setting the window height. This will
906 ** increase or decrease the command window by the specified amount.
907 */
908 static void
909 _tuiXDBsetWinHeight (char *arg, int fromTTY)
910 {
911 if (arg != (char *) NULL)
912 {
913 int inputNo = atoi (arg);
914
915 if (inputNo > 0)
916 { /* Add 1 for the locator */
917 int newHeight = termHeight () - (inputNo + 1);
918
919 if (!_newHeightOk (winList[CMD_WIN], newHeight) ||
920 _tuiAdjustWinHeights (winList[CMD_WIN],
921 newHeight) == TUI_FAILURE)
922 warning ("Invalid window height specified.\n%s",
923 XDBWIN_HEIGHT_USAGE);
924 }
925 else
926 warning ("Invalid window height specified.\n%s",
927 XDBWIN_HEIGHT_USAGE);
928 }
929 else
930 warning ("Invalid window height specified.\n%s", XDBWIN_HEIGHT_USAGE);
931
932 return;
933 } /* _tuiXDBsetWinHeight */
934
935
936 /*
937 ** _tui_vXDBsetWinHeight().
938 ** Set the height of the specified window, with va_list.
939 */
940 static void
941 _tui_vXDBsetWinHeight (va_list args)
942 {
943 char *arg = va_arg (args, char *);
944 int fromTTY = va_arg (args, int);
945
946 _tuiXDBsetWinHeight (arg, fromTTY);
947
948 return;
949 } /* _tui_vXDBsetWinHeight */
950
951
952 /*
953 ** _tuiSetWinHeight_command().
954 ** Set the height of the specified window, with va_list.
955 */
956 static void
957 _tuiXDBsetWinHeight_command (char *arg, int fromTTY)
958 {
959 tuiDo ((TuiOpaqueFuncPtr) _tui_vXDBsetWinHeight, arg, fromTTY);
960
961 return;
962 } /* _tuiXDBsetWinHeight_command */
963
964
965 /*
966 ** _tuiAdjustWinHeights().
967 ** Function to adjust all window heights around the primary
968 */
969 static TuiStatus
970 _tuiAdjustWinHeights (TuiWinInfoPtr primaryWinInfo, int newHeight)
971 {
972 TuiStatus status = TUI_FAILURE;
973
974 if (_newHeightOk (primaryWinInfo, newHeight))
975 {
976 status = TUI_SUCCESS;
977 if (newHeight != primaryWinInfo->generic.height)
978 {
979 int i, diff;
980 TuiWinInfoPtr winInfo;
981 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
982 TuiLayoutType curLayout = currentLayout ();
983
984 diff = (newHeight - primaryWinInfo->generic.height) * (-1);
985 if (curLayout == SRC_COMMAND || curLayout == DISASSEM_COMMAND)
986 {
987 TuiWinInfoPtr srcWinInfo;
988
989 _makeInvisibleAndSetNewHeight (primaryWinInfo, newHeight);
990 if (primaryWinInfo->generic.type == CMD_WIN)
991 {
992 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[0];
993 srcWinInfo = winInfo;
994 }
995 else
996 {
997 winInfo = winList[CMD_WIN];
998 srcWinInfo = primaryWinInfo;
999 }
1000 _makeInvisibleAndSetNewHeight (winInfo,
1001 winInfo->generic.height + diff);
1002 cmdWin->generic.origin.y = locator->origin.y + 1;
1003 _makeVisibleWithNewHeight (winInfo);
1004 _makeVisibleWithNewHeight (primaryWinInfo);
1005 if (srcWinInfo->generic.contentSize <= 0)
1006 tuiEraseSourceContent (srcWinInfo, EMPTY_SOURCE_PROMPT);
1007 }
1008 else
1009 {
1010 TuiWinInfoPtr firstWin, secondWin;
1011
1012 if (curLayout == SRC_DISASSEM_COMMAND)
1013 {
1014 firstWin = srcWin;
1015 secondWin = disassemWin;
1016 }
1017 else
1018 {
1019 firstWin = dataWin;
1020 secondWin = (TuiWinInfoPtr) (sourceWindows ())->list[0];
1021 }
1022 if (primaryWinInfo == cmdWin)
1023 { /*
1024 ** Split the change in height accross the 1st & 2nd windows
1025 ** adjusting them as well.
1026 */
1027 int firstSplitDiff = diff / 2; /* subtract the locator */
1028 int secondSplitDiff = firstSplitDiff;
1029
1030 if (diff % 2)
1031 {
1032 if (firstWin->generic.height >
1033 secondWin->generic.height)
1034 if (diff < 0)
1035 firstSplitDiff--;
1036 else
1037 firstSplitDiff++;
1038 else
1039 {
1040 if (diff < 0)
1041 secondSplitDiff--;
1042 else
1043 secondSplitDiff++;
1044 }
1045 }
1046 /* make sure that the minimum hieghts are honored */
1047 while ((firstWin->generic.height + firstSplitDiff) < 3)
1048 {
1049 firstSplitDiff++;
1050 secondSplitDiff--;
1051 }
1052 while ((secondWin->generic.height + secondSplitDiff) < 3)
1053 {
1054 secondSplitDiff++;
1055 firstSplitDiff--;
1056 }
1057 _makeInvisibleAndSetNewHeight (
1058 firstWin,
1059 firstWin->generic.height + firstSplitDiff);
1060 secondWin->generic.origin.y = firstWin->generic.height - 1;
1061 _makeInvisibleAndSetNewHeight (
1062 secondWin, secondWin->generic.height + secondSplitDiff);
1063 cmdWin->generic.origin.y = locator->origin.y + 1;
1064 _makeInvisibleAndSetNewHeight (cmdWin, newHeight);
1065 }
1066 else
1067 {
1068 if ((cmdWin->generic.height + diff) < 1)
1069 { /*
1070 ** If there is no way to increase the command window
1071 ** take real estate from the 1st or 2nd window.
1072 */
1073 if ((cmdWin->generic.height + diff) < 1)
1074 {
1075 int i;
1076 for (i = cmdWin->generic.height + diff;
1077 (i < 1); i++)
1078 if (primaryWinInfo == firstWin)
1079 secondWin->generic.height--;
1080 else
1081 firstWin->generic.height--;
1082 }
1083 }
1084 if (primaryWinInfo == firstWin)
1085 _makeInvisibleAndSetNewHeight (firstWin, newHeight);
1086 else
1087 _makeInvisibleAndSetNewHeight (
1088 firstWin,
1089 firstWin->generic.height);
1090 secondWin->generic.origin.y = firstWin->generic.height - 1;
1091 if (primaryWinInfo == secondWin)
1092 _makeInvisibleAndSetNewHeight (secondWin, newHeight);
1093 else
1094 _makeInvisibleAndSetNewHeight (
1095 secondWin, secondWin->generic.height);
1096 cmdWin->generic.origin.y = locator->origin.y + 1;
1097 if ((cmdWin->generic.height + diff) < 1)
1098 _makeInvisibleAndSetNewHeight (cmdWin, 1);
1099 else
1100 _makeInvisibleAndSetNewHeight (
1101 cmdWin, cmdWin->generic.height + diff);
1102 }
1103 _makeVisibleWithNewHeight (cmdWin);
1104 _makeVisibleWithNewHeight (secondWin);
1105 _makeVisibleWithNewHeight (firstWin);
1106 if (firstWin->generic.contentSize <= 0)
1107 tuiEraseSourceContent (firstWin, EMPTY_SOURCE_PROMPT);
1108 if (secondWin->generic.contentSize <= 0)
1109 tuiEraseSourceContent (secondWin, EMPTY_SOURCE_PROMPT);
1110 }
1111 }
1112 }
1113
1114 return status;
1115 } /* _tuiAdjustWinHeights */
1116
1117
1118 /*
1119 ** _makeInvisibleAndSetNewHeight().
1120 ** Function make the target window (and auxillary windows associated
1121 ** with the targer) invisible, and set the new height and location.
1122 */
1123 static void
1124 _makeInvisibleAndSetNewHeight (TuiWinInfoPtr winInfo, int height)
1125 {
1126 int i;
1127 struct symtab *s;
1128 TuiGenWinInfoPtr genWinInfo;
1129
1130
1131 m_beInvisible (&winInfo->generic);
1132 winInfo->generic.height = height;
1133 if (height > 1)
1134 winInfo->generic.viewportHeight = height - 1;
1135 else
1136 winInfo->generic.viewportHeight = height;
1137 if (winInfo != cmdWin)
1138 winInfo->generic.viewportHeight--;
1139
1140 /* Now deal with the auxillary windows associated with winInfo */
1141 switch (winInfo->generic.type)
1142 {
1143 case SRC_WIN:
1144 case DISASSEM_WIN:
1145 genWinInfo = winInfo->detail.sourceInfo.executionInfo;
1146 m_beInvisible (genWinInfo);
1147 genWinInfo->height = height;
1148 genWinInfo->origin.y = winInfo->generic.origin.y;
1149 if (height > 1)
1150 genWinInfo->viewportHeight = height - 1;
1151 else
1152 genWinInfo->viewportHeight = height;
1153 if (winInfo != cmdWin)
1154 genWinInfo->viewportHeight--;
1155
1156 if (m_hasLocator (winInfo))
1157 {
1158 genWinInfo = locatorWinInfoPtr ();
1159 m_beInvisible (genWinInfo);
1160 genWinInfo->origin.y = winInfo->generic.origin.y + height;
1161 }
1162 break;
1163 case DATA_WIN:
1164 /* delete all data item windows */
1165 for (i = 0; i < winInfo->generic.contentSize; i++)
1166 {
1167 genWinInfo = (TuiGenWinInfoPtr) & ((TuiWinElementPtr)
1168 winInfo->generic.content[i])->whichElement.dataWindow;
1169 tuiDelwin (genWinInfo->handle);
1170 genWinInfo->handle = (WINDOW *) NULL;
1171 }
1172 break;
1173 default:
1174 break;
1175 }
1176
1177 return;
1178 } /* _makeInvisibleAndSetNewHeight */
1179
1180
1181 /*
1182 ** _makeVisibleWithNewHeight().
1183 ** Function to make the windows with new heights visible.
1184 ** This means re-creating the windows' content since the window
1185 ** had to be destroyed to be made invisible.
1186 */
1187 static void
1188 _makeVisibleWithNewHeight (TuiWinInfoPtr winInfo)
1189 {
1190 int i;
1191 struct symtab *s;
1192
1193 m_beVisible (&winInfo->generic);
1194 checkAndDisplayHighlightIfNeeded (winInfo);
1195 switch (winInfo->generic.type)
1196 {
1197 case SRC_WIN:
1198 case DISASSEM_WIN:
1199 freeWinContent (winInfo->detail.sourceInfo.executionInfo);
1200 m_beVisible (winInfo->detail.sourceInfo.executionInfo);
1201 if (winInfo->generic.content != (OpaquePtr) NULL)
1202 {
1203 TuiLineOrAddress lineOrAddr;
1204
1205 if (winInfo->generic.type == SRC_WIN)
1206 lineOrAddr.lineNo =
1207 winInfo->detail.sourceInfo.startLineOrAddr.lineNo;
1208 else
1209 lineOrAddr.addr =
1210 winInfo->detail.sourceInfo.startLineOrAddr.addr;
1211 freeWinContent (&winInfo->generic);
1212 tuiUpdateSourceWindow (winInfo,
1213 current_source_symtab,
1214 ((winInfo->generic.type == SRC_WIN) ?
1215 (Opaque) lineOrAddr.lineNo :
1216 lineOrAddr.addr),
1217 TRUE);
1218 }
1219 else if (selected_frame != (struct frame_info *) NULL)
1220 {
1221 Opaque line = 0;
1222 extern int current_source_line;
1223
1224 s = find_pc_symtab (selected_frame->pc);
1225 if (winInfo->generic.type == SRC_WIN)
1226 line = (Opaque) current_source_line;
1227 else
1228 {
1229 CORE_ADDR pc;
1230
1231 find_line_pc (s, current_source_line, &pc);
1232 line = (Opaque) pc;
1233 }
1234 tuiUpdateSourceWindow (winInfo, s, line, TRUE);
1235 }
1236 if (m_hasLocator (winInfo))
1237 {
1238 m_beVisible (locatorWinInfoPtr ());
1239 tuiClearLocatorDisplay ();
1240 tuiShowLocatorContent ();
1241 }
1242 break;
1243 case DATA_WIN:
1244 tuiDisplayAllData ();
1245 break;
1246 case CMD_WIN:
1247 winInfo->detail.commandInfo.curLine = 0;
1248 winInfo->detail.commandInfo.curch = 0;
1249 wmove (winInfo->generic.handle,
1250 winInfo->detail.commandInfo.curLine,
1251 winInfo->detail.commandInfo.curch);
1252 break;
1253 default:
1254 break;
1255 }
1256
1257 return;
1258 } /* _makeVisibleWithNewHeight */
1259
1260
1261 static int
1262 _newHeightOk (TuiWinInfoPtr primaryWinInfo, int newHeight)
1263 {
1264 int ok = (newHeight < termHeight ());
1265
1266 if (ok)
1267 {
1268 int diff, curHeight;
1269 TuiLayoutType curLayout = currentLayout ();
1270
1271 diff = (newHeight - primaryWinInfo->generic.height) * (-1);
1272 if (curLayout == SRC_COMMAND || curLayout == DISASSEM_COMMAND)
1273 {
1274 ok = ((primaryWinInfo->generic.type == CMD_WIN &&
1275 newHeight <= (termHeight () - 4) &&
1276 newHeight >= MIN_CMD_WIN_HEIGHT) ||
1277 (primaryWinInfo->generic.type != CMD_WIN &&
1278 newHeight <= (termHeight () - 2) &&
1279 newHeight >= MIN_WIN_HEIGHT));
1280 if (ok)
1281 { /* check the total height */
1282 TuiWinInfoPtr winInfo;
1283
1284 if (primaryWinInfo == cmdWin)
1285 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[0];
1286 else
1287 winInfo = cmdWin;
1288 ok = ((newHeight +
1289 (winInfo->generic.height + diff)) <= termHeight ());
1290 }
1291 }
1292 else
1293 {
1294 int curTotalHeight, totalHeight, minHeight;
1295 TuiWinInfoPtr firstWin, secondWin;
1296
1297 if (curLayout == SRC_DISASSEM_COMMAND)
1298 {
1299 firstWin = srcWin;
1300 secondWin = disassemWin;
1301 }
1302 else
1303 {
1304 firstWin = dataWin;
1305 secondWin = (TuiWinInfoPtr) (sourceWindows ())->list[0];
1306 }
1307 /*
1308 ** We could simply add all the heights to obtain the same result
1309 ** but below is more explicit since we subtract 1 for the
1310 ** line that the first and second windows share, and add one
1311 ** for the locator.
1312 */
1313 curTotalHeight =
1314 (firstWin->generic.height + secondWin->generic.height - 1)
1315 + cmdWin->generic.height + 1 /*locator */ ;
1316 if (primaryWinInfo == cmdWin)
1317 {
1318 /* locator included since first & second win share a line */
1319 ok = ((firstWin->generic.height +
1320 secondWin->generic.height + diff) >=
1321 (MIN_WIN_HEIGHT * 2) &&
1322 newHeight >= MIN_CMD_WIN_HEIGHT);
1323 if (ok)
1324 {
1325 totalHeight = newHeight + (firstWin->generic.height +
1326 secondWin->generic.height + diff);
1327 minHeight = MIN_CMD_WIN_HEIGHT;
1328 }
1329 }
1330 else
1331 {
1332 minHeight = MIN_WIN_HEIGHT;
1333 /*
1334 ** First see if we can increase/decrease the command
1335 ** window. And make sure that the command window is
1336 ** at least 1 line
1337 */
1338 ok = ((cmdWin->generic.height + diff) > 0);
1339 if (!ok)
1340 { /*
1341 ** Looks like we have to increase/decrease one of
1342 ** the other windows
1343 */
1344 if (primaryWinInfo == firstWin)
1345 ok = (secondWin->generic.height + diff) >= minHeight;
1346 else
1347 ok = (firstWin->generic.height + diff) >= minHeight;
1348 }
1349 if (ok)
1350 {
1351 if (primaryWinInfo == firstWin)
1352 totalHeight = newHeight +
1353 secondWin->generic.height +
1354 cmdWin->generic.height + diff;
1355 else
1356 totalHeight = newHeight +
1357 firstWin->generic.height +
1358 cmdWin->generic.height + diff;
1359 }
1360 }
1361 /*
1362 ** Now make sure that the proposed total height doesn't exceed
1363 ** the old total height.
1364 */
1365 if (ok)
1366 ok = (newHeight >= minHeight && totalHeight <= curTotalHeight);
1367 }
1368 }
1369
1370 return ok;
1371 } /* _newHeightOk */
1372
1373
1374 /*
1375 ** _parseScrollingArgs().
1376 */
1377 static void
1378 _parseScrollingArgs (char *arg, TuiWinInfoPtr * winToScroll, int *numToScroll)
1379 {
1380 if (numToScroll)
1381 *numToScroll = 0;
1382 *winToScroll = tuiWinWithFocus ();
1383
1384 /*
1385 ** First set up the default window to scroll, in case there is no
1386 ** window name arg
1387 */
1388 if (arg != (char *) NULL)
1389 {
1390 char *buf, *bufPtr;
1391
1392 /* process the number of lines to scroll */
1393 buf = bufPtr = tuiStrDup (arg);
1394 if (isdigit (*bufPtr))
1395 {
1396 char *numStr;
1397
1398 numStr = bufPtr;
1399 bufPtr = strchr (bufPtr, ' ');
1400 if (bufPtr != (char *) NULL)
1401 {
1402 *bufPtr = (char) 0;
1403 if (numToScroll)
1404 *numToScroll = atoi (numStr);
1405 bufPtr++;
1406 }
1407 else if (numToScroll)
1408 *numToScroll = atoi (numStr);
1409 }
1410
1411 /* process the window name if one is specified */
1412 if (bufPtr != (char *) NULL)
1413 {
1414 char *wname;
1415 int i;
1416
1417 if (*bufPtr == ' ')
1418 while (*(++bufPtr) == ' ')
1419 ;
1420
1421 if (*bufPtr != (char) 0)
1422 wname = bufPtr;
1423
1424 /* Validate the window name */
1425 for (i = 0; i < strlen (wname); i++)
1426 wname[i] = toupper (wname[i]);
1427 *winToScroll = partialWinByName (wname);
1428
1429 if (*winToScroll == (TuiWinInfoPtr) NULL ||
1430 !(*winToScroll)->generic.isVisible)
1431 warning ("Invalid window specified. \n\
1432 The window name specified must be valid and visible.\n");
1433 else if (*winToScroll == cmdWin)
1434 *winToScroll = (TuiWinInfoPtr) (sourceWindows ())->list[0];
1435 }
1436 tuiFree (buf);
1437 }
1438
1439 return;
1440 } /* _parseScrollingArgs */
This page took 0.057217 seconds and 5 git commands to generate.