Home | History | Annotate | Line # | Download | only in tui
tui-win.c revision 1.1.1.1
      1  1.1  christos /* TUI window generic functions.
      2  1.1  christos 
      3  1.1  christos    Copyright (C) 1998-2014 Free Software Foundation, Inc.
      4  1.1  christos 
      5  1.1  christos    Contributed by Hewlett-Packard Company.
      6  1.1  christos 
      7  1.1  christos    This file is part of GDB.
      8  1.1  christos 
      9  1.1  christos    This program is free software; you can redistribute it and/or modify
     10  1.1  christos    it under the terms of the GNU General Public License as published by
     11  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     12  1.1  christos    (at your option) any later version.
     13  1.1  christos 
     14  1.1  christos    This program is distributed in the hope that it will be useful,
     15  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     16  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17  1.1  christos    GNU General Public License for more details.
     18  1.1  christos 
     19  1.1  christos    You should have received a copy of the GNU General Public License
     20  1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     21  1.1  christos 
     22  1.1  christos /* This module contains procedures for handling tui window functions
     23  1.1  christos    like resize, scrolling, scrolling, changing focus, etc.
     24  1.1  christos 
     25  1.1  christos    Author: Susan B. Macchia  */
     26  1.1  christos 
     27  1.1  christos #include "defs.h"
     28  1.1  christos #include "command.h"
     29  1.1  christos #include "symtab.h"
     30  1.1  christos #include "breakpoint.h"
     31  1.1  christos #include "frame.h"
     32  1.1  christos #include "cli/cli-cmds.h"
     33  1.1  christos #include "top.h"
     34  1.1  christos #include "source.h"
     35  1.1  christos 
     36  1.1  christos #include "tui/tui.h"
     37  1.1  christos #include "tui/tui-data.h"
     38  1.1  christos #include "tui/tui-wingeneral.h"
     39  1.1  christos #include "tui/tui-stack.h"
     40  1.1  christos #include "tui/tui-regs.h"
     41  1.1  christos #include "tui/tui-disasm.h"
     42  1.1  christos #include "tui/tui-source.h"
     43  1.1  christos #include "tui/tui-winsource.h"
     44  1.1  christos #include "tui/tui-windata.h"
     45  1.1  christos #include "tui/tui-win.h"
     46  1.1  christos 
     47  1.1  christos #include "gdb_curses.h"
     48  1.1  christos 
     49  1.1  christos #include <string.h>
     50  1.1  christos #include <ctype.h>
     51  1.1  christos #include "readline/readline.h"
     52  1.1  christos 
     53  1.1  christos #include <signal.h>
     54  1.1  christos 
     55  1.1  christos /*******************************
     56  1.1  christos ** Static Local Decls
     57  1.1  christos ********************************/
     58  1.1  christos static void make_visible_with_new_height (struct tui_win_info *);
     59  1.1  christos static void make_invisible_and_set_new_height (struct tui_win_info *,
     60  1.1  christos 					       int);
     61  1.1  christos static enum tui_status tui_adjust_win_heights (struct tui_win_info *,
     62  1.1  christos 					       int);
     63  1.1  christos static int new_height_ok (struct tui_win_info *, int);
     64  1.1  christos static void tui_set_tab_width_command (char *, int);
     65  1.1  christos static void tui_refresh_all_command (char *, int);
     66  1.1  christos static void tui_set_win_height_command (char *, int);
     67  1.1  christos static void tui_xdb_set_win_height_command (char *, int);
     68  1.1  christos static void tui_all_windows_info (char *, int);
     69  1.1  christos static void tui_set_focus_command (char *, int);
     70  1.1  christos static void tui_scroll_forward_command (char *, int);
     71  1.1  christos static void tui_scroll_backward_command (char *, int);
     72  1.1  christos static void tui_scroll_left_command (char *, int);
     73  1.1  christos static void tui_scroll_right_command (char *, int);
     74  1.1  christos static void parse_scrolling_args (char *,
     75  1.1  christos 				  struct tui_win_info **,
     76  1.1  christos 				  int *);
     77  1.1  christos 
     78  1.1  christos 
     79  1.1  christos /***************************************
     80  1.1  christos ** DEFINITIONS
     81  1.1  christos ***************************************/
     82  1.1  christos #define WIN_HEIGHT_USAGE    "Usage: winheight <win_name> [+ | -] <#lines>\n"
     83  1.1  christos #define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n"
     84  1.1  christos #define FOCUS_USAGE         "Usage: focus {<win> | next | prev}\n"
     85  1.1  christos 
     86  1.1  christos /***************************************
     87  1.1  christos ** PUBLIC FUNCTIONS
     88  1.1  christos ***************************************/
     89  1.1  christos 
     90  1.1  christos #ifndef ACS_LRCORNER
     91  1.1  christos #  define ACS_LRCORNER '+'
     92  1.1  christos #endif
     93  1.1  christos #ifndef ACS_LLCORNER
     94  1.1  christos #  define ACS_LLCORNER '+'
     95  1.1  christos #endif
     96  1.1  christos #ifndef ACS_ULCORNER
     97  1.1  christos #  define ACS_ULCORNER '+'
     98  1.1  christos #endif
     99  1.1  christos #ifndef ACS_URCORNER
    100  1.1  christos #  define ACS_URCORNER '+'
    101  1.1  christos #endif
    102  1.1  christos #ifndef ACS_HLINE
    103  1.1  christos #  define ACS_HLINE '-'
    104  1.1  christos #endif
    105  1.1  christos #ifndef ACS_VLINE
    106  1.1  christos #  define ACS_VLINE '|'
    107  1.1  christos #endif
    108  1.1  christos 
    109  1.1  christos /* Possible values for tui-border-kind variable.  */
    110  1.1  christos static const char *const tui_border_kind_enums[] = {
    111  1.1  christos   "space",
    112  1.1  christos   "ascii",
    113  1.1  christos   "acs",
    114  1.1  christos   NULL
    115  1.1  christos };
    116  1.1  christos 
    117  1.1  christos /* Possible values for tui-border-mode and tui-active-border-mode.  */
    118  1.1  christos static const char *const tui_border_mode_enums[] = {
    119  1.1  christos   "normal",
    120  1.1  christos   "standout",
    121  1.1  christos   "reverse",
    122  1.1  christos   "half",
    123  1.1  christos   "half-standout",
    124  1.1  christos   "bold",
    125  1.1  christos   "bold-standout",
    126  1.1  christos   NULL
    127  1.1  christos };
    128  1.1  christos 
    129  1.1  christos struct tui_translate
    130  1.1  christos {
    131  1.1  christos   const char *name;
    132  1.1  christos   int value;
    133  1.1  christos };
    134  1.1  christos 
    135  1.1  christos /* Translation table for border-mode variables.
    136  1.1  christos    The list of values must be terminated by a NULL.
    137  1.1  christos    After the NULL value, an entry defines the default.  */
    138  1.1  christos struct tui_translate tui_border_mode_translate[] = {
    139  1.1  christos   { "normal",		A_NORMAL },
    140  1.1  christos   { "standout",		A_STANDOUT },
    141  1.1  christos   { "reverse",		A_REVERSE },
    142  1.1  christos   { "half",		A_DIM },
    143  1.1  christos   { "half-standout",	A_DIM | A_STANDOUT },
    144  1.1  christos   { "bold",		A_BOLD },
    145  1.1  christos   { "bold-standout",	A_BOLD | A_STANDOUT },
    146  1.1  christos   { 0, 0 },
    147  1.1  christos   { "normal",		A_NORMAL }
    148  1.1  christos };
    149  1.1  christos 
    150  1.1  christos /* Translation tables for border-kind, one for each border
    151  1.1  christos    character (see wborder, border curses operations).
    152  1.1  christos    -1 is used to indicate the ACS because ACS characters
    153  1.1  christos    are determined at run time by curses (depends on terminal).  */
    154  1.1  christos struct tui_translate tui_border_kind_translate_vline[] = {
    155  1.1  christos   { "space",    ' ' },
    156  1.1  christos   { "ascii",    '|' },
    157  1.1  christos   { "acs",      -1 },
    158  1.1  christos   { 0, 0 },
    159  1.1  christos   { "ascii",    '|' }
    160  1.1  christos };
    161  1.1  christos 
    162  1.1  christos struct tui_translate tui_border_kind_translate_hline[] = {
    163  1.1  christos   { "space",    ' ' },
    164  1.1  christos   { "ascii",    '-' },
    165  1.1  christos   { "acs",      -1 },
    166  1.1  christos   { 0, 0 },
    167  1.1  christos   { "ascii",    '-' }
    168  1.1  christos };
    169  1.1  christos 
    170  1.1  christos struct tui_translate tui_border_kind_translate_ulcorner[] = {
    171  1.1  christos   { "space",    ' ' },
    172  1.1  christos   { "ascii",    '+' },
    173  1.1  christos   { "acs",      -1 },
    174  1.1  christos   { 0, 0 },
    175  1.1  christos   { "ascii",    '+' }
    176  1.1  christos };
    177  1.1  christos 
    178  1.1  christos struct tui_translate tui_border_kind_translate_urcorner[] = {
    179  1.1  christos   { "space",    ' ' },
    180  1.1  christos   { "ascii",    '+' },
    181  1.1  christos   { "acs",      -1 },
    182  1.1  christos   { 0, 0 },
    183  1.1  christos   { "ascii",    '+' }
    184  1.1  christos };
    185  1.1  christos 
    186  1.1  christos struct tui_translate tui_border_kind_translate_llcorner[] = {
    187  1.1  christos   { "space",    ' ' },
    188  1.1  christos   { "ascii",    '+' },
    189  1.1  christos   { "acs",      -1 },
    190  1.1  christos   { 0, 0 },
    191  1.1  christos   { "ascii",    '+' }
    192  1.1  christos };
    193  1.1  christos 
    194  1.1  christos struct tui_translate tui_border_kind_translate_lrcorner[] = {
    195  1.1  christos   { "space",    ' ' },
    196  1.1  christos   { "ascii",    '+' },
    197  1.1  christos   { "acs",      -1 },
    198  1.1  christos   { 0, 0 },
    199  1.1  christos   { "ascii",    '+' }
    200  1.1  christos };
    201  1.1  christos 
    202  1.1  christos 
    203  1.1  christos /* Tui configuration variables controlled with set/show command.  */
    204  1.1  christos const char *tui_active_border_mode = "bold-standout";
    205  1.1  christos static void
    206  1.1  christos show_tui_active_border_mode (struct ui_file *file,
    207  1.1  christos 			     int from_tty,
    208  1.1  christos 			     struct cmd_list_element *c,
    209  1.1  christos 			     const char *value)
    210  1.1  christos {
    211  1.1  christos   fprintf_filtered (file, _("\
    212  1.1  christos The attribute mode to use for the active TUI window border is \"%s\".\n"),
    213  1.1  christos 		    value);
    214  1.1  christos }
    215  1.1  christos 
    216  1.1  christos const char *tui_border_mode = "normal";
    217  1.1  christos static void
    218  1.1  christos show_tui_border_mode (struct ui_file *file,
    219  1.1  christos 		      int from_tty,
    220  1.1  christos 		      struct cmd_list_element *c,
    221  1.1  christos 		      const char *value)
    222  1.1  christos {
    223  1.1  christos   fprintf_filtered (file, _("\
    224  1.1  christos The attribute mode to use for the TUI window borders is \"%s\".\n"),
    225  1.1  christos 		    value);
    226  1.1  christos }
    227  1.1  christos 
    228  1.1  christos const char *tui_border_kind = "acs";
    229  1.1  christos static void
    230  1.1  christos show_tui_border_kind (struct ui_file *file,
    231  1.1  christos 		      int from_tty,
    232  1.1  christos 		      struct cmd_list_element *c,
    233  1.1  christos 		      const char *value)
    234  1.1  christos {
    235  1.1  christos   fprintf_filtered (file, _("The kind of border for TUI windows is \"%s\".\n"),
    236  1.1  christos 		    value);
    237  1.1  christos }
    238  1.1  christos 
    239  1.1  christos 
    240  1.1  christos /* Tui internal configuration variables.  These variables are updated
    241  1.1  christos    by tui_update_variables to reflect the tui configuration
    242  1.1  christos    variables.  */
    243  1.1  christos chtype tui_border_vline;
    244  1.1  christos chtype tui_border_hline;
    245  1.1  christos chtype tui_border_ulcorner;
    246  1.1  christos chtype tui_border_urcorner;
    247  1.1  christos chtype tui_border_llcorner;
    248  1.1  christos chtype tui_border_lrcorner;
    249  1.1  christos 
    250  1.1  christos int tui_border_attrs;
    251  1.1  christos int tui_active_border_attrs;
    252  1.1  christos 
    253  1.1  christos /* Identify the item in the translation table.
    254  1.1  christos    When the item is not recognized, use the default entry.  */
    255  1.1  christos static struct tui_translate *
    256  1.1  christos translate (const char *name, struct tui_translate *table)
    257  1.1  christos {
    258  1.1  christos   while (table->name)
    259  1.1  christos     {
    260  1.1  christos       if (name && strcmp (table->name, name) == 0)
    261  1.1  christos         return table;
    262  1.1  christos       table++;
    263  1.1  christos     }
    264  1.1  christos 
    265  1.1  christos   /* Not found, return default entry.  */
    266  1.1  christos   table++;
    267  1.1  christos   return table;
    268  1.1  christos }
    269  1.1  christos 
    270  1.1  christos /* Update the tui internal configuration according to gdb settings.
    271  1.1  christos    Returns 1 if the configuration has changed and the screen should
    272  1.1  christos    be redrawn.  */
    273  1.1  christos int
    274  1.1  christos tui_update_variables (void)
    275  1.1  christos {
    276  1.1  christos   int need_redraw = 0;
    277  1.1  christos   struct tui_translate *entry;
    278  1.1  christos 
    279  1.1  christos   entry = translate (tui_border_mode, tui_border_mode_translate);
    280  1.1  christos   if (tui_border_attrs != entry->value)
    281  1.1  christos     {
    282  1.1  christos       tui_border_attrs = entry->value;
    283  1.1  christos       need_redraw = 1;
    284  1.1  christos     }
    285  1.1  christos   entry = translate (tui_active_border_mode, tui_border_mode_translate);
    286  1.1  christos   if (tui_active_border_attrs != entry->value)
    287  1.1  christos     {
    288  1.1  christos       tui_active_border_attrs = entry->value;
    289  1.1  christos       need_redraw = 1;
    290  1.1  christos     }
    291  1.1  christos 
    292  1.1  christos   /* If one corner changes, all characters are changed.
    293  1.1  christos      Only check the first one.  The ACS characters are determined at
    294  1.1  christos      run time by curses terminal management.  */
    295  1.1  christos   entry = translate (tui_border_kind, tui_border_kind_translate_lrcorner);
    296  1.1  christos   if (tui_border_lrcorner != (chtype) entry->value)
    297  1.1  christos     {
    298  1.1  christos       tui_border_lrcorner = (entry->value < 0) ? ACS_LRCORNER : entry->value;
    299  1.1  christos       need_redraw = 1;
    300  1.1  christos     }
    301  1.1  christos   entry = translate (tui_border_kind, tui_border_kind_translate_llcorner);
    302  1.1  christos   tui_border_llcorner = (entry->value < 0) ? ACS_LLCORNER : entry->value;
    303  1.1  christos 
    304  1.1  christos   entry = translate (tui_border_kind, tui_border_kind_translate_ulcorner);
    305  1.1  christos   tui_border_ulcorner = (entry->value < 0) ? ACS_ULCORNER : entry->value;
    306  1.1  christos 
    307  1.1  christos   entry = translate (tui_border_kind, tui_border_kind_translate_urcorner);
    308  1.1  christos   tui_border_urcorner = (entry->value < 0) ? ACS_URCORNER : entry->value;
    309  1.1  christos 
    310  1.1  christos   entry = translate (tui_border_kind, tui_border_kind_translate_hline);
    311  1.1  christos   tui_border_hline = (entry->value < 0) ? ACS_HLINE : entry->value;
    312  1.1  christos 
    313  1.1  christos   entry = translate (tui_border_kind, tui_border_kind_translate_vline);
    314  1.1  christos   tui_border_vline = (entry->value < 0) ? ACS_VLINE : entry->value;
    315  1.1  christos 
    316  1.1  christos   return need_redraw;
    317  1.1  christos }
    318  1.1  christos 
    319  1.1  christos static void
    320  1.1  christos set_tui_cmd (char *args, int from_tty)
    321  1.1  christos {
    322  1.1  christos }
    323  1.1  christos 
    324  1.1  christos static void
    325  1.1  christos show_tui_cmd (char *args, int from_tty)
    326  1.1  christos {
    327  1.1  christos }
    328  1.1  christos 
    329  1.1  christos static struct cmd_list_element *tuilist;
    330  1.1  christos 
    331  1.1  christos static void
    332  1.1  christos tui_command (char *args, int from_tty)
    333  1.1  christos {
    334  1.1  christos   printf_unfiltered (_("\"tui\" must be followed by the name of a "
    335  1.1  christos                      "tui command.\n"));
    336  1.1  christos   help_list (tuilist, "tui ", -1, gdb_stdout);
    337  1.1  christos }
    338  1.1  christos 
    339  1.1  christos struct cmd_list_element **
    340  1.1  christos tui_get_cmd_list (void)
    341  1.1  christos {
    342  1.1  christos   if (tuilist == 0)
    343  1.1  christos     add_prefix_cmd ("tui", class_tui, tui_command,
    344  1.1  christos                     _("Text User Interface commands."),
    345  1.1  christos                     &tuilist, "tui ", 0, &cmdlist);
    346  1.1  christos   return &tuilist;
    347  1.1  christos }
    348  1.1  christos 
    349  1.1  christos /* Function to initialize gdb commands, for tui window
    350  1.1  christos    manipulation.  */
    351  1.1  christos 
    352  1.1  christos /* Provide a prototype to silence -Wmissing-prototypes.  */
    353  1.1  christos extern initialize_file_ftype _initialize_tui_win;
    354  1.1  christos 
    355  1.1  christos void
    356  1.1  christos _initialize_tui_win (void)
    357  1.1  christos {
    358  1.1  christos   static struct cmd_list_element *tui_setlist;
    359  1.1  christos   static struct cmd_list_element *tui_showlist;
    360  1.1  christos 
    361  1.1  christos   /* Define the classes of commands.
    362  1.1  christos      They will appear in the help list in the reverse of this order.  */
    363  1.1  christos   add_prefix_cmd ("tui", class_tui, set_tui_cmd,
    364  1.1  christos                   _("TUI configuration variables"),
    365  1.1  christos 		  &tui_setlist, "set tui ",
    366  1.1  christos 		  0 /* allow-unknown */, &setlist);
    367  1.1  christos   add_prefix_cmd ("tui", class_tui, show_tui_cmd,
    368  1.1  christos                   _("TUI configuration variables"),
    369  1.1  christos 		  &tui_showlist, "show tui ",
    370  1.1  christos 		  0 /* allow-unknown */, &showlist);
    371  1.1  christos 
    372  1.1  christos   add_com ("refresh", class_tui, tui_refresh_all_command,
    373  1.1  christos            _("Refresh the terminal display.\n"));
    374  1.1  christos   if (xdb_commands)
    375  1.1  christos     add_com_alias ("U", "refresh", class_tui, 0);
    376  1.1  christos   add_com ("tabset", class_tui, tui_set_tab_width_command, _("\
    377  1.1  christos Set the width (in characters) of tab stops.\n\
    378  1.1  christos Usage: tabset <n>\n"));
    379  1.1  christos   add_com ("winheight", class_tui, tui_set_win_height_command, _("\
    380  1.1  christos Set the height of a specified window.\n\
    381  1.1  christos Usage: winheight <win_name> [+ | -] <#lines>\n\
    382  1.1  christos Window names are:\n\
    383  1.1  christos src  : the source window\n\
    384  1.1  christos cmd  : the command window\n\
    385  1.1  christos asm  : the disassembly window\n\
    386  1.1  christos regs : the register display\n"));
    387  1.1  christos   add_com_alias ("wh", "winheight", class_tui, 0);
    388  1.1  christos   add_info ("win", tui_all_windows_info,
    389  1.1  christos 	    _("List of all displayed windows.\n"));
    390  1.1  christos   add_com ("focus", class_tui, tui_set_focus_command, _("\
    391  1.1  christos Set focus to named window or next/prev window.\n\
    392  1.1  christos Usage: focus {<win> | next | prev}\n\
    393  1.1  christos Valid Window names are:\n\
    394  1.1  christos src  : the source window\n\
    395  1.1  christos asm  : the disassembly window\n\
    396  1.1  christos regs : the register display\n\
    397  1.1  christos cmd  : the command window\n"));
    398  1.1  christos   add_com_alias ("fs", "focus", class_tui, 0);
    399  1.1  christos   add_com ("+", class_tui, tui_scroll_forward_command, _("\
    400  1.1  christos Scroll window forward.\n\
    401  1.1  christos Usage: + [win] [n]\n"));
    402  1.1  christos   add_com ("-", class_tui, tui_scroll_backward_command, _("\
    403  1.1  christos Scroll window backward.\n\
    404  1.1  christos Usage: - [win] [n]\n"));
    405  1.1  christos   add_com ("<", class_tui, tui_scroll_left_command, _("\
    406  1.1  christos Scroll window forward.\n\
    407  1.1  christos Usage: < [win] [n]\n"));
    408  1.1  christos   add_com (">", class_tui, tui_scroll_right_command, _("\
    409  1.1  christos Scroll window backward.\n\
    410  1.1  christos Usage: > [win] [n]\n"));
    411  1.1  christos   if (xdb_commands)
    412  1.1  christos     add_com ("w", class_xdb, tui_xdb_set_win_height_command, _("\
    413  1.1  christos XDB compatibility command for setting the height of a command window.\n\
    414  1.1  christos Usage: w <#lines>\n"));
    415  1.1  christos 
    416  1.1  christos   /* Define the tui control variables.  */
    417  1.1  christos   add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums,
    418  1.1  christos 			&tui_border_kind, _("\
    419  1.1  christos Set the kind of border for TUI windows."), _("\
    420  1.1  christos Show the kind of border for TUI windows."), _("\
    421  1.1  christos This variable controls the border of TUI windows:\n\
    422  1.1  christos space           use a white space\n\
    423  1.1  christos ascii           use ascii characters + - | for the border\n\
    424  1.1  christos acs             use the Alternate Character Set"),
    425  1.1  christos 			NULL,
    426  1.1  christos 			show_tui_border_kind,
    427  1.1  christos 			&tui_setlist, &tui_showlist);
    428  1.1  christos 
    429  1.1  christos   add_setshow_enum_cmd ("border-mode", no_class, tui_border_mode_enums,
    430  1.1  christos 			&tui_border_mode, _("\
    431  1.1  christos Set the attribute mode to use for the TUI window borders."), _("\
    432  1.1  christos Show the attribute mode to use for the TUI window borders."), _("\
    433  1.1  christos This variable controls the attributes to use for the window borders:\n\
    434  1.1  christos normal          normal display\n\
    435  1.1  christos standout        use highlight mode of terminal\n\
    436  1.1  christos reverse         use reverse video mode\n\
    437  1.1  christos half            use half bright\n\
    438  1.1  christos half-standout   use half bright and standout mode\n\
    439  1.1  christos bold            use extra bright or bold\n\
    440  1.1  christos bold-standout   use extra bright or bold with standout mode"),
    441  1.1  christos 			NULL,
    442  1.1  christos 			show_tui_border_mode,
    443  1.1  christos 			&tui_setlist, &tui_showlist);
    444  1.1  christos 
    445  1.1  christos   add_setshow_enum_cmd ("active-border-mode", no_class, tui_border_mode_enums,
    446  1.1  christos 			&tui_active_border_mode, _("\
    447  1.1  christos Set the attribute mode to use for the active TUI window border."), _("\
    448  1.1  christos Show the attribute mode to use for the active TUI window border."), _("\
    449  1.1  christos This variable controls the attributes to use for the active window border:\n\
    450  1.1  christos normal          normal display\n\
    451  1.1  christos standout        use highlight mode of terminal\n\
    452  1.1  christos reverse         use reverse video mode\n\
    453  1.1  christos half            use half bright\n\
    454  1.1  christos half-standout   use half bright and standout mode\n\
    455  1.1  christos bold            use extra bright or bold\n\
    456  1.1  christos bold-standout   use extra bright or bold with standout mode"),
    457  1.1  christos 			NULL,
    458  1.1  christos 			show_tui_active_border_mode,
    459  1.1  christos 			&tui_setlist, &tui_showlist);
    460  1.1  christos }
    461  1.1  christos 
    462  1.1  christos /* Update gdb's knowledge of the terminal size.  */
    463  1.1  christos void
    464  1.1  christos tui_update_gdb_sizes (void)
    465  1.1  christos {
    466  1.1  christos   char cmd[50];
    467  1.1  christos 
    468  1.1  christos   /* Set to TUI command window dimension or use readline values.  */
    469  1.1  christos   xsnprintf (cmd, sizeof (cmd), "set width %d",
    470  1.1  christos            tui_active ? TUI_CMD_WIN->generic.width : tui_term_width());
    471  1.1  christos   execute_command (cmd, 0);
    472  1.1  christos   xsnprintf (cmd, sizeof (cmd), "set height %d",
    473  1.1  christos            tui_active ? TUI_CMD_WIN->generic.height : tui_term_height());
    474  1.1  christos   execute_command (cmd, 0);
    475  1.1  christos }
    476  1.1  christos 
    477  1.1  christos 
    478  1.1  christos /* Set the logical focus to win_info.  */
    479  1.1  christos void
    480  1.1  christos tui_set_win_focus_to (struct tui_win_info *win_info)
    481  1.1  christos {
    482  1.1  christos   if (win_info != NULL)
    483  1.1  christos     {
    484  1.1  christos       struct tui_win_info *win_with_focus = tui_win_with_focus ();
    485  1.1  christos 
    486  1.1  christos       if (win_with_focus != NULL
    487  1.1  christos 	  && win_with_focus->generic.type != CMD_WIN)
    488  1.1  christos 	tui_unhighlight_win (win_with_focus);
    489  1.1  christos       tui_set_win_with_focus (win_info);
    490  1.1  christos       if (win_info->generic.type != CMD_WIN)
    491  1.1  christos 	tui_highlight_win (win_info);
    492  1.1  christos     }
    493  1.1  christos }
    494  1.1  christos 
    495  1.1  christos 
    496  1.1  christos void
    497  1.1  christos tui_scroll_forward (struct tui_win_info *win_to_scroll,
    498  1.1  christos 		    int num_to_scroll)
    499  1.1  christos {
    500  1.1  christos   if (win_to_scroll != TUI_CMD_WIN)
    501  1.1  christos     {
    502  1.1  christos       int _num_to_scroll = num_to_scroll;
    503  1.1  christos 
    504  1.1  christos       if (num_to_scroll == 0)
    505  1.1  christos 	_num_to_scroll = win_to_scroll->generic.height - 3;
    506  1.1  christos 
    507  1.1  christos       /* If we are scrolling the source or disassembly window, do a
    508  1.1  christos          "psuedo" scroll since not all of the source is in memory,
    509  1.1  christos          only what is in the viewport.  If win_to_scroll is the
    510  1.1  christos          command window do nothing since the term should handle
    511  1.1  christos          it.  */
    512  1.1  christos       if (win_to_scroll == TUI_SRC_WIN)
    513  1.1  christos 	tui_vertical_source_scroll (FORWARD_SCROLL, _num_to_scroll);
    514  1.1  christos       else if (win_to_scroll == TUI_DISASM_WIN)
    515  1.1  christos 	tui_vertical_disassem_scroll (FORWARD_SCROLL, _num_to_scroll);
    516  1.1  christos       else if (win_to_scroll == TUI_DATA_WIN)
    517  1.1  christos 	tui_vertical_data_scroll (FORWARD_SCROLL, _num_to_scroll);
    518  1.1  christos     }
    519  1.1  christos }
    520  1.1  christos 
    521  1.1  christos void
    522  1.1  christos tui_scroll_backward (struct tui_win_info *win_to_scroll,
    523  1.1  christos 		     int num_to_scroll)
    524  1.1  christos {
    525  1.1  christos   if (win_to_scroll != TUI_CMD_WIN)
    526  1.1  christos     {
    527  1.1  christos       int _num_to_scroll = num_to_scroll;
    528  1.1  christos 
    529  1.1  christos       if (num_to_scroll == 0)
    530  1.1  christos 	_num_to_scroll = win_to_scroll->generic.height - 3;
    531  1.1  christos 
    532  1.1  christos       /* If we are scrolling the source or disassembly window, do a
    533  1.1  christos          "psuedo" scroll since not all of the source is in memory,
    534  1.1  christos          only what is in the viewport.  If win_to_scroll is the
    535  1.1  christos          command window do nothing since the term should handle
    536  1.1  christos          it.  */
    537  1.1  christos       if (win_to_scroll == TUI_SRC_WIN)
    538  1.1  christos 	tui_vertical_source_scroll (BACKWARD_SCROLL, _num_to_scroll);
    539  1.1  christos       else if (win_to_scroll == TUI_DISASM_WIN)
    540  1.1  christos 	tui_vertical_disassem_scroll (BACKWARD_SCROLL, _num_to_scroll);
    541  1.1  christos       else if (win_to_scroll == TUI_DATA_WIN)
    542  1.1  christos 	tui_vertical_data_scroll (BACKWARD_SCROLL, _num_to_scroll);
    543  1.1  christos     }
    544  1.1  christos }
    545  1.1  christos 
    546  1.1  christos 
    547  1.1  christos void
    548  1.1  christos tui_scroll_left (struct tui_win_info *win_to_scroll,
    549  1.1  christos 		 int num_to_scroll)
    550  1.1  christos {
    551  1.1  christos   if (win_to_scroll != TUI_CMD_WIN)
    552  1.1  christos     {
    553  1.1  christos       int _num_to_scroll = num_to_scroll;
    554  1.1  christos 
    555  1.1  christos       if (_num_to_scroll == 0)
    556  1.1  christos 	_num_to_scroll = 1;
    557  1.1  christos 
    558  1.1  christos       /* If we are scrolling the source or disassembly window, do a
    559  1.1  christos          "psuedo" scroll since not all of the source is in memory,
    560  1.1  christos          only what is in the viewport. If win_to_scroll is the command
    561  1.1  christos          window do nothing since the term should handle it.  */
    562  1.1  christos       if (win_to_scroll == TUI_SRC_WIN
    563  1.1  christos 	  || win_to_scroll == TUI_DISASM_WIN)
    564  1.1  christos 	tui_horizontal_source_scroll (win_to_scroll, LEFT_SCROLL,
    565  1.1  christos 				      _num_to_scroll);
    566  1.1  christos     }
    567  1.1  christos }
    568  1.1  christos 
    569  1.1  christos 
    570  1.1  christos void
    571  1.1  christos tui_scroll_right (struct tui_win_info *win_to_scroll,
    572  1.1  christos 		  int num_to_scroll)
    573  1.1  christos {
    574  1.1  christos   if (win_to_scroll != TUI_CMD_WIN)
    575  1.1  christos     {
    576  1.1  christos       int _num_to_scroll = num_to_scroll;
    577  1.1  christos 
    578  1.1  christos       if (_num_to_scroll == 0)
    579  1.1  christos 	_num_to_scroll = 1;
    580  1.1  christos 
    581  1.1  christos       /* If we are scrolling the source or disassembly window, do a
    582  1.1  christos          "psuedo" scroll since not all of the source is in memory,
    583  1.1  christos          only what is in the viewport. If win_to_scroll is the command
    584  1.1  christos          window do nothing since the term should handle it.  */
    585  1.1  christos       if (win_to_scroll == TUI_SRC_WIN
    586  1.1  christos 	  || win_to_scroll == TUI_DISASM_WIN)
    587  1.1  christos 	tui_horizontal_source_scroll (win_to_scroll, RIGHT_SCROLL,
    588  1.1  christos 				      _num_to_scroll);
    589  1.1  christos     }
    590  1.1  christos }
    591  1.1  christos 
    592  1.1  christos 
    593  1.1  christos /* Scroll a window.  Arguments are passed through a va_list.  */
    594  1.1  christos void
    595  1.1  christos tui_scroll (enum tui_scroll_direction direction,
    596  1.1  christos 	    struct tui_win_info *win_to_scroll,
    597  1.1  christos 	    int num_to_scroll)
    598  1.1  christos {
    599  1.1  christos   switch (direction)
    600  1.1  christos     {
    601  1.1  christos     case FORWARD_SCROLL:
    602  1.1  christos       tui_scroll_forward (win_to_scroll, num_to_scroll);
    603  1.1  christos       break;
    604  1.1  christos     case BACKWARD_SCROLL:
    605  1.1  christos       tui_scroll_backward (win_to_scroll, num_to_scroll);
    606  1.1  christos       break;
    607  1.1  christos     case LEFT_SCROLL:
    608  1.1  christos       tui_scroll_left (win_to_scroll, num_to_scroll);
    609  1.1  christos       break;
    610  1.1  christos     case RIGHT_SCROLL:
    611  1.1  christos       tui_scroll_right (win_to_scroll, num_to_scroll);
    612  1.1  christos       break;
    613  1.1  christos     default:
    614  1.1  christos       break;
    615  1.1  christos     }
    616  1.1  christos }
    617  1.1  christos 
    618  1.1  christos 
    619  1.1  christos void
    620  1.1  christos tui_refresh_all_win (void)
    621  1.1  christos {
    622  1.1  christos   enum tui_win_type type;
    623  1.1  christos 
    624  1.1  christos   clearok (curscr, TRUE);
    625  1.1  christos   tui_refresh_all (tui_win_list);
    626  1.1  christos   for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++)
    627  1.1  christos     {
    628  1.1  christos       if (tui_win_list[type]
    629  1.1  christos 	  && tui_win_list[type]->generic.is_visible)
    630  1.1  christos 	{
    631  1.1  christos 	  switch (type)
    632  1.1  christos 	    {
    633  1.1  christos 	    case SRC_WIN:
    634  1.1  christos 	    case DISASSEM_WIN:
    635  1.1  christos 	      tui_show_source_content (tui_win_list[type]);
    636  1.1  christos 	      tui_check_and_display_highlight_if_needed (tui_win_list[type]);
    637  1.1  christos 	      tui_erase_exec_info_content (tui_win_list[type]);
    638  1.1  christos 	      tui_update_exec_info (tui_win_list[type]);
    639  1.1  christos 	      break;
    640  1.1  christos 	    case DATA_WIN:
    641  1.1  christos 	      tui_refresh_data_win ();
    642  1.1  christos 	      break;
    643  1.1  christos 	    default:
    644  1.1  christos 	      break;
    645  1.1  christos 	    }
    646  1.1  christos 	}
    647  1.1  christos     }
    648  1.1  christos   tui_show_locator_content ();
    649  1.1  christos }
    650  1.1  christos 
    651  1.1  christos 
    652  1.1  christos /* Resize all the windows based on the terminal size.  This function
    653  1.1  christos    gets called from within the readline sinwinch handler.  */
    654  1.1  christos void
    655  1.1  christos tui_resize_all (void)
    656  1.1  christos {
    657  1.1  christos   int height_diff, width_diff;
    658  1.1  christos   int screenheight, screenwidth;
    659  1.1  christos 
    660  1.1  christos   rl_get_screen_size (&screenheight, &screenwidth);
    661  1.1  christos   width_diff = screenwidth - tui_term_width ();
    662  1.1  christos   height_diff = screenheight - tui_term_height ();
    663  1.1  christos   if (height_diff || width_diff)
    664  1.1  christos     {
    665  1.1  christos       enum tui_layout_type cur_layout = tui_current_layout ();
    666  1.1  christos       struct tui_win_info *win_with_focus = tui_win_with_focus ();
    667  1.1  christos       struct tui_win_info *first_win;
    668  1.1  christos       struct tui_win_info *second_win;
    669  1.1  christos       struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
    670  1.1  christos       enum tui_win_type win_type;
    671  1.1  christos       int new_height, split_diff, cmd_split_diff, num_wins_displayed = 2;
    672  1.1  christos 
    673  1.1  christos #ifdef HAVE_RESIZE_TERM
    674  1.1  christos       resize_term (screenheight, screenwidth);
    675  1.1  christos #endif
    676  1.1  christos       /* Turn keypad off while we resize.  */
    677  1.1  christos       if (win_with_focus != TUI_CMD_WIN)
    678  1.1  christos 	keypad (TUI_CMD_WIN->generic.handle, FALSE);
    679  1.1  christos       tui_update_gdb_sizes ();
    680  1.1  christos       tui_set_term_height_to (screenheight);
    681  1.1  christos       tui_set_term_width_to (screenwidth);
    682  1.1  christos       if (cur_layout == SRC_DISASSEM_COMMAND
    683  1.1  christos 	  || cur_layout == SRC_DATA_COMMAND
    684  1.1  christos 	  || cur_layout == DISASSEM_DATA_COMMAND)
    685  1.1  christos 	num_wins_displayed++;
    686  1.1  christos       split_diff = height_diff / num_wins_displayed;
    687  1.1  christos       cmd_split_diff = split_diff;
    688  1.1  christos       if (height_diff % num_wins_displayed)
    689  1.1  christos 	{
    690  1.1  christos 	  if (height_diff < 0)
    691  1.1  christos 	    cmd_split_diff--;
    692  1.1  christos 	  else
    693  1.1  christos            cmd_split_diff++;
    694  1.1  christos        }
    695  1.1  christos       /* Now adjust each window.  */
    696  1.1  christos       /* erase + clearok are used instead of a straightforward clear as
    697  1.1  christos          AIX 5.3 does not define clear.  */
    698  1.1  christos       erase ();
    699  1.1  christos       clearok (curscr, TRUE);
    700  1.1  christos       refresh ();
    701  1.1  christos       switch (cur_layout)
    702  1.1  christos        {
    703  1.1  christos 	case SRC_COMMAND:
    704  1.1  christos 	case DISASSEM_COMMAND:
    705  1.1  christos 	  first_win = (struct tui_win_info *) (tui_source_windows ())->list[0];
    706  1.1  christos 	  first_win->generic.width += width_diff;
    707  1.1  christos 	  locator->width += width_diff;
    708  1.1  christos 	  /* Check for invalid heights.  */
    709  1.1  christos 	  if (height_diff == 0)
    710  1.1  christos 	    new_height = first_win->generic.height;
    711  1.1  christos 	  else if ((first_win->generic.height + split_diff) >=
    712  1.1  christos 		   (screenheight - MIN_CMD_WIN_HEIGHT - 1))
    713  1.1  christos 	    new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1;
    714  1.1  christos 	  else if ((first_win->generic.height + split_diff) <= 0)
    715  1.1  christos 	    new_height = MIN_WIN_HEIGHT;
    716  1.1  christos 	  else
    717  1.1  christos 	    new_height = first_win->generic.height + split_diff;
    718  1.1  christos 
    719  1.1  christos 	  locator->origin.y = new_height + 1;
    720  1.1  christos 	  make_invisible_and_set_new_height (first_win, new_height);
    721  1.1  christos 	  TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
    722  1.1  christos 	  TUI_CMD_WIN->generic.width += width_diff;
    723  1.1  christos 	  new_height = screenheight - TUI_CMD_WIN->generic.origin.y;
    724  1.1  christos 	  make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);
    725  1.1  christos 	  make_visible_with_new_height (first_win);
    726  1.1  christos 	  make_visible_with_new_height (TUI_CMD_WIN);
    727  1.1  christos 	  if (first_win->generic.content_size <= 0)
    728  1.1  christos 	    tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
    729  1.1  christos 	  break;
    730  1.1  christos 	default:
    731  1.1  christos 	  if (cur_layout == SRC_DISASSEM_COMMAND)
    732  1.1  christos 	    {
    733  1.1  christos 	      first_win = TUI_SRC_WIN;
    734  1.1  christos 	      first_win->generic.width += width_diff;
    735  1.1  christos 	      second_win = TUI_DISASM_WIN;
    736  1.1  christos 	      second_win->generic.width += width_diff;
    737  1.1  christos 	    }
    738  1.1  christos 	  else
    739  1.1  christos 	    {
    740  1.1  christos 	      first_win = TUI_DATA_WIN;
    741  1.1  christos 	      first_win->generic.width += width_diff;
    742  1.1  christos 	      second_win = (struct tui_win_info *)
    743  1.1  christos 		(tui_source_windows ())->list[0];
    744  1.1  christos 	      second_win->generic.width += width_diff;
    745  1.1  christos 	    }
    746  1.1  christos 	  /* Change the first window's height/width.  */
    747  1.1  christos 	  /* Check for invalid heights.  */
    748  1.1  christos 	  if (height_diff == 0)
    749  1.1  christos 	    new_height = first_win->generic.height;
    750  1.1  christos 	  else if ((first_win->generic.height +
    751  1.1  christos 		    second_win->generic.height + (split_diff * 2)) >=
    752  1.1  christos 		   (screenheight - MIN_CMD_WIN_HEIGHT - 1))
    753  1.1  christos 	    new_height = (screenheight - MIN_CMD_WIN_HEIGHT - 1) / 2;
    754  1.1  christos 	  else if ((first_win->generic.height + split_diff) <= 0)
    755  1.1  christos 	    new_height = MIN_WIN_HEIGHT;
    756  1.1  christos 	  else
    757  1.1  christos 	    new_height = first_win->generic.height + split_diff;
    758  1.1  christos 	  make_invisible_and_set_new_height (first_win, new_height);
    759  1.1  christos 
    760  1.1  christos 	  locator->width += width_diff;
    761  1.1  christos 
    762  1.1  christos 	  /* Change the second window's height/width.  */
    763  1.1  christos 	  /* Check for invalid heights.  */
    764  1.1  christos 	  if (height_diff == 0)
    765  1.1  christos 	    new_height = second_win->generic.height;
    766  1.1  christos 	  else if ((first_win->generic.height +
    767  1.1  christos 		    second_win->generic.height + (split_diff * 2)) >=
    768  1.1  christos 		   (screenheight - MIN_CMD_WIN_HEIGHT - 1))
    769  1.1  christos 	    {
    770  1.1  christos 	      new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1;
    771  1.1  christos 	      if (new_height % 2)
    772  1.1  christos 		new_height = (new_height / 2) + 1;
    773  1.1  christos 	      else
    774  1.1  christos 		new_height /= 2;
    775  1.1  christos 	    }
    776  1.1  christos 	  else if ((second_win->generic.height + split_diff) <= 0)
    777  1.1  christos 	    new_height = MIN_WIN_HEIGHT;
    778  1.1  christos 	  else
    779  1.1  christos 	    new_height = second_win->generic.height + split_diff;
    780  1.1  christos 	  second_win->generic.origin.y = first_win->generic.height - 1;
    781  1.1  christos 	  make_invisible_and_set_new_height (second_win, new_height);
    782  1.1  christos 
    783  1.1  christos 	  /* Change the command window's height/width.  */
    784  1.1  christos 	  TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
    785  1.1  christos 	  make_invisible_and_set_new_height (TUI_CMD_WIN,
    786  1.1  christos 					     TUI_CMD_WIN->generic.height
    787  1.1  christos 					     + cmd_split_diff);
    788  1.1  christos 	  make_visible_with_new_height (first_win);
    789  1.1  christos 	  make_visible_with_new_height (second_win);
    790  1.1  christos 	  make_visible_with_new_height (TUI_CMD_WIN);
    791  1.1  christos 	  if (first_win->generic.content_size <= 0)
    792  1.1  christos 	    tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
    793  1.1  christos 	  if (second_win->generic.content_size <= 0)
    794  1.1  christos 	    tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
    795  1.1  christos 	  break;
    796  1.1  christos 	}
    797  1.1  christos       /* Now remove all invisible windows, and their content so that
    798  1.1  christos          they get created again when called for with the new size.  */
    799  1.1  christos       for (win_type = SRC_WIN; (win_type < MAX_MAJOR_WINDOWS); win_type++)
    800  1.1  christos 	{
    801  1.1  christos 	  if (win_type != CMD_WIN
    802  1.1  christos 	      && (tui_win_list[win_type] != NULL)
    803  1.1  christos 	      && !tui_win_list[win_type]->generic.is_visible)
    804  1.1  christos 	    {
    805  1.1  christos 	      tui_free_window (tui_win_list[win_type]);
    806  1.1  christos 	      tui_win_list[win_type] = (struct tui_win_info *) NULL;
    807  1.1  christos 	    }
    808  1.1  christos 	}
    809  1.1  christos       /* Turn keypad back on, unless focus is in the command
    810  1.1  christos 	 window.  */
    811  1.1  christos       if (win_with_focus != TUI_CMD_WIN)
    812  1.1  christos 	keypad (TUI_CMD_WIN->generic.handle, TRUE);
    813  1.1  christos     }
    814  1.1  christos }
    815  1.1  christos 
    816  1.1  christos #ifdef SIGWINCH
    817  1.1  christos /* SIGWINCH signal handler for the tui.  This signal handler is always
    818  1.1  christos    called, even when the readline package clears signals because it is
    819  1.1  christos    set as the old_sigwinch() (TUI only).  */
    820  1.1  christos static void
    821  1.1  christos tui_sigwinch_handler (int signal)
    822  1.1  christos {
    823  1.1  christos   /* Say that a resize was done so that the readline can do it later
    824  1.1  christos      when appropriate.  */
    825  1.1  christos   tui_set_win_resized_to (TRUE);
    826  1.1  christos }
    827  1.1  christos #endif
    828  1.1  christos 
    829  1.1  christos /* Initializes SIGWINCH signal handler for the tui.  */
    830  1.1  christos void
    831  1.1  christos tui_initialize_win (void)
    832  1.1  christos {
    833  1.1  christos #ifdef SIGWINCH
    834  1.1  christos #ifdef HAVE_SIGACTION
    835  1.1  christos   struct sigaction old_winch;
    836  1.1  christos 
    837  1.1  christos   memset (&old_winch, 0, sizeof (old_winch));
    838  1.1  christos   old_winch.sa_handler = &tui_sigwinch_handler;
    839  1.1  christos   sigaction (SIGWINCH, &old_winch, NULL);
    840  1.1  christos #else
    841  1.1  christos   signal (SIGWINCH, &tui_sigwinch_handler);
    842  1.1  christos #endif
    843  1.1  christos #endif
    844  1.1  christos }
    845  1.1  christos 
    846  1.1  christos 
    847  1.1  christos /*************************
    848  1.1  christos ** STATIC LOCAL FUNCTIONS
    849  1.1  christos **************************/
    850  1.1  christos 
    851  1.1  christos 
    852  1.1  christos static void
    853  1.1  christos tui_scroll_forward_command (char *arg, int from_tty)
    854  1.1  christos {
    855  1.1  christos   int num_to_scroll = 1;
    856  1.1  christos   struct tui_win_info *win_to_scroll;
    857  1.1  christos 
    858  1.1  christos   /* Make sure the curses mode is enabled.  */
    859  1.1  christos   tui_enable ();
    860  1.1  christos   if (arg == (char *) NULL)
    861  1.1  christos     parse_scrolling_args (arg, &win_to_scroll, (int *) NULL);
    862  1.1  christos   else
    863  1.1  christos     parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
    864  1.1  christos   tui_scroll (FORWARD_SCROLL, win_to_scroll, num_to_scroll);
    865  1.1  christos }
    866  1.1  christos 
    867  1.1  christos 
    868  1.1  christos static void
    869  1.1  christos tui_scroll_backward_command (char *arg, int from_tty)
    870  1.1  christos {
    871  1.1  christos   int num_to_scroll = 1;
    872  1.1  christos   struct tui_win_info *win_to_scroll;
    873  1.1  christos 
    874  1.1  christos   /* Make sure the curses mode is enabled.  */
    875  1.1  christos   tui_enable ();
    876  1.1  christos   if (arg == (char *) NULL)
    877  1.1  christos     parse_scrolling_args (arg, &win_to_scroll, (int *) NULL);
    878  1.1  christos   else
    879  1.1  christos     parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
    880  1.1  christos   tui_scroll (BACKWARD_SCROLL, win_to_scroll, num_to_scroll);
    881  1.1  christos }
    882  1.1  christos 
    883  1.1  christos 
    884  1.1  christos static void
    885  1.1  christos tui_scroll_left_command (char *arg, int from_tty)
    886  1.1  christos {
    887  1.1  christos   int num_to_scroll;
    888  1.1  christos   struct tui_win_info *win_to_scroll;
    889  1.1  christos 
    890  1.1  christos   /* Make sure the curses mode is enabled.  */
    891  1.1  christos   tui_enable ();
    892  1.1  christos   parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
    893  1.1  christos   tui_scroll (LEFT_SCROLL, win_to_scroll, num_to_scroll);
    894  1.1  christos }
    895  1.1  christos 
    896  1.1  christos 
    897  1.1  christos static void
    898  1.1  christos tui_scroll_right_command (char *arg, int from_tty)
    899  1.1  christos {
    900  1.1  christos   int num_to_scroll;
    901  1.1  christos   struct tui_win_info *win_to_scroll;
    902  1.1  christos 
    903  1.1  christos   /* Make sure the curses mode is enabled.  */
    904  1.1  christos   tui_enable ();
    905  1.1  christos   parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
    906  1.1  christos   tui_scroll (RIGHT_SCROLL, win_to_scroll, num_to_scroll);
    907  1.1  christos }
    908  1.1  christos 
    909  1.1  christos 
    910  1.1  christos /* Set focus to the window named by 'arg'.  */
    911  1.1  christos static void
    912  1.1  christos tui_set_focus (char *arg, int from_tty)
    913  1.1  christos {
    914  1.1  christos   if (arg != (char *) NULL)
    915  1.1  christos     {
    916  1.1  christos       char *buf_ptr = (char *) xstrdup (arg);
    917  1.1  christos       int i;
    918  1.1  christos       struct tui_win_info *win_info = (struct tui_win_info *) NULL;
    919  1.1  christos 
    920  1.1  christos       for (i = 0; (i < strlen (buf_ptr)); i++)
    921  1.1  christos 	buf_ptr[i] = toupper (arg[i]);
    922  1.1  christos 
    923  1.1  christos       if (subset_compare (buf_ptr, "NEXT"))
    924  1.1  christos 	win_info = tui_next_win (tui_win_with_focus ());
    925  1.1  christos       else if (subset_compare (buf_ptr, "PREV"))
    926  1.1  christos 	win_info = tui_prev_win (tui_win_with_focus ());
    927  1.1  christos       else
    928  1.1  christos 	win_info = tui_partial_win_by_name (buf_ptr);
    929  1.1  christos 
    930  1.1  christos       if (win_info == (struct tui_win_info *) NULL
    931  1.1  christos 	  || !win_info->generic.is_visible)
    932  1.1  christos 	warning (_("Invalid window specified. \n\
    933  1.1  christos The window name specified must be valid and visible.\n"));
    934  1.1  christos       else
    935  1.1  christos 	{
    936  1.1  christos 	  tui_set_win_focus_to (win_info);
    937  1.1  christos 	  keypad (TUI_CMD_WIN->generic.handle, (win_info != TUI_CMD_WIN));
    938  1.1  christos 	}
    939  1.1  christos 
    940  1.1  christos       if (TUI_DATA_WIN && TUI_DATA_WIN->generic.is_visible)
    941  1.1  christos 	tui_refresh_data_win ();
    942  1.1  christos       xfree (buf_ptr);
    943  1.1  christos       printf_filtered (_("Focus set to %s window.\n"),
    944  1.1  christos 		       tui_win_name ((struct tui_gen_win_info *)
    945  1.1  christos 				     tui_win_with_focus ()));
    946  1.1  christos     }
    947  1.1  christos   else
    948  1.1  christos     warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE);
    949  1.1  christos }
    950  1.1  christos 
    951  1.1  christos static void
    952  1.1  christos tui_set_focus_command (char *arg, int from_tty)
    953  1.1  christos {
    954  1.1  christos   /* Make sure the curses mode is enabled.  */
    955  1.1  christos   tui_enable ();
    956  1.1  christos   tui_set_focus (arg, from_tty);
    957  1.1  christos }
    958  1.1  christos 
    959  1.1  christos 
    960  1.1  christos static void
    961  1.1  christos tui_all_windows_info (char *arg, int from_tty)
    962  1.1  christos {
    963  1.1  christos   enum tui_win_type type;
    964  1.1  christos   struct tui_win_info *win_with_focus = tui_win_with_focus ();
    965  1.1  christos 
    966  1.1  christos   for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
    967  1.1  christos     if (tui_win_list[type]
    968  1.1  christos 	&& tui_win_list[type]->generic.is_visible)
    969  1.1  christos       {
    970  1.1  christos 	if (win_with_focus == tui_win_list[type])
    971  1.1  christos 	  printf_filtered ("        %s\t(%d lines)  <has focus>\n",
    972  1.1  christos 			   tui_win_name (&tui_win_list[type]->generic),
    973  1.1  christos 			   tui_win_list[type]->generic.height);
    974  1.1  christos 	else
    975  1.1  christos 	  printf_filtered ("        %s\t(%d lines)\n",
    976  1.1  christos 			   tui_win_name (&tui_win_list[type]->generic),
    977  1.1  christos 			   tui_win_list[type]->generic.height);
    978  1.1  christos       }
    979  1.1  christos }
    980  1.1  christos 
    981  1.1  christos 
    982  1.1  christos static void
    983  1.1  christos tui_refresh_all_command (char *arg, int from_tty)
    984  1.1  christos {
    985  1.1  christos   /* Make sure the curses mode is enabled.  */
    986  1.1  christos   tui_enable ();
    987  1.1  christos 
    988  1.1  christos   tui_refresh_all_win ();
    989  1.1  christos }
    990  1.1  christos 
    991  1.1  christos 
    992  1.1  christos /* Set the height of the specified window.  */
    993  1.1  christos static void
    994  1.1  christos tui_set_tab_width_command (char *arg, int from_tty)
    995  1.1  christos {
    996  1.1  christos   /* Make sure the curses mode is enabled.  */
    997  1.1  christos   tui_enable ();
    998  1.1  christos   if (arg != (char *) NULL)
    999  1.1  christos     {
   1000  1.1  christos       int ts;
   1001  1.1  christos 
   1002  1.1  christos       ts = atoi (arg);
   1003  1.1  christos       if (ts > 0)
   1004  1.1  christos 	tui_set_default_tab_len (ts);
   1005  1.1  christos       else
   1006  1.1  christos 	warning (_("Tab widths greater than 0 must be specified."));
   1007  1.1  christos     }
   1008  1.1  christos }
   1009  1.1  christos 
   1010  1.1  christos 
   1011  1.1  christos /* Set the height of the specified window.  */
   1012  1.1  christos static void
   1013  1.1  christos tui_set_win_height (char *arg, int from_tty)
   1014  1.1  christos {
   1015  1.1  christos   /* Make sure the curses mode is enabled.  */
   1016  1.1  christos   tui_enable ();
   1017  1.1  christos   if (arg != (char *) NULL)
   1018  1.1  christos     {
   1019  1.1  christos       char *buf = xstrdup (arg);
   1020  1.1  christos       char *buf_ptr = buf;
   1021  1.1  christos       char *wname = (char *) NULL;
   1022  1.1  christos       int new_height, i;
   1023  1.1  christos       struct tui_win_info *win_info;
   1024  1.1  christos 
   1025  1.1  christos       wname = buf_ptr;
   1026  1.1  christos       buf_ptr = strchr (buf_ptr, ' ');
   1027  1.1  christos       if (buf_ptr != (char *) NULL)
   1028  1.1  christos 	{
   1029  1.1  christos 	  *buf_ptr = (char) 0;
   1030  1.1  christos 
   1031  1.1  christos 	  /* Validate the window name.  */
   1032  1.1  christos 	  for (i = 0; i < strlen (wname); i++)
   1033  1.1  christos 	    wname[i] = toupper (wname[i]);
   1034  1.1  christos 	  win_info = tui_partial_win_by_name (wname);
   1035  1.1  christos 
   1036  1.1  christos 	  if (win_info == (struct tui_win_info *) NULL
   1037  1.1  christos 	      || !win_info->generic.is_visible)
   1038  1.1  christos 	    warning (_("Invalid window specified. \n\
   1039  1.1  christos The window name specified must be valid and visible.\n"));
   1040  1.1  christos 	  else
   1041  1.1  christos 	    {
   1042  1.1  christos 	      /* Process the size.  */
   1043  1.1  christos 	      while (*(++buf_ptr) == ' ')
   1044  1.1  christos 		;
   1045  1.1  christos 
   1046  1.1  christos 	      if (*buf_ptr != (char) 0)
   1047  1.1  christos 		{
   1048  1.1  christos 		  int negate = FALSE;
   1049  1.1  christos 		  int fixed_size = TRUE;
   1050  1.1  christos 		  int input_no;;
   1051  1.1  christos 
   1052  1.1  christos 		  if (*buf_ptr == '+' || *buf_ptr == '-')
   1053  1.1  christos 		    {
   1054  1.1  christos 		      if (*buf_ptr == '-')
   1055  1.1  christos 			negate = TRUE;
   1056  1.1  christos 		      fixed_size = FALSE;
   1057  1.1  christos 		      buf_ptr++;
   1058  1.1  christos 		    }
   1059  1.1  christos 		  input_no = atoi (buf_ptr);
   1060  1.1  christos 		  if (input_no > 0)
   1061  1.1  christos 		    {
   1062  1.1  christos 		      if (negate)
   1063  1.1  christos 			input_no *= (-1);
   1064  1.1  christos 		      if (fixed_size)
   1065  1.1  christos 			new_height = input_no;
   1066  1.1  christos 		      else
   1067  1.1  christos 			new_height = win_info->generic.height + input_no;
   1068  1.1  christos 
   1069  1.1  christos 		      /* Now change the window's height, and adjust
   1070  1.1  christos 		         all other windows around it.  */
   1071  1.1  christos 		      if (tui_adjust_win_heights (win_info,
   1072  1.1  christos 						new_height) == TUI_FAILURE)
   1073  1.1  christos 			warning (_("Invalid window height specified.\n%s"),
   1074  1.1  christos 				 WIN_HEIGHT_USAGE);
   1075  1.1  christos 		      else
   1076  1.1  christos                         tui_update_gdb_sizes ();
   1077  1.1  christos 		    }
   1078  1.1  christos 		  else
   1079  1.1  christos 		    warning (_("Invalid window height specified.\n%s"),
   1080  1.1  christos 			     WIN_HEIGHT_USAGE);
   1081  1.1  christos 		}
   1082  1.1  christos 	    }
   1083  1.1  christos 	}
   1084  1.1  christos       else
   1085  1.1  christos 	printf_filtered (WIN_HEIGHT_USAGE);
   1086  1.1  christos 
   1087  1.1  christos       if (buf != (char *) NULL)
   1088  1.1  christos 	xfree (buf);
   1089  1.1  christos     }
   1090  1.1  christos   else
   1091  1.1  christos     printf_filtered (WIN_HEIGHT_USAGE);
   1092  1.1  christos }
   1093  1.1  christos 
   1094  1.1  christos /* Set the height of the specified window, with va_list.  */
   1095  1.1  christos static void
   1096  1.1  christos tui_set_win_height_command (char *arg, int from_tty)
   1097  1.1  christos {
   1098  1.1  christos   /* Make sure the curses mode is enabled.  */
   1099  1.1  christos   tui_enable ();
   1100  1.1  christos   tui_set_win_height (arg, from_tty);
   1101  1.1  christos }
   1102  1.1  christos 
   1103  1.1  christos 
   1104  1.1  christos /* XDB Compatibility command for setting the window height.  This will
   1105  1.1  christos    increase or decrease the command window by the specified
   1106  1.1  christos    amount.  */
   1107  1.1  christos static void
   1108  1.1  christos tui_xdb_set_win_height (char *arg, int from_tty)
   1109  1.1  christos {
   1110  1.1  christos   /* Make sure the curses mode is enabled.  */
   1111  1.1  christos   tui_enable ();
   1112  1.1  christos   if (arg != (char *) NULL)
   1113  1.1  christos     {
   1114  1.1  christos       int input_no = atoi (arg);
   1115  1.1  christos 
   1116  1.1  christos       if (input_no > 0)
   1117  1.1  christos 	{			/* Add 1 for the locator.  */
   1118  1.1  christos 	  int new_height = tui_term_height () - (input_no + 1);
   1119  1.1  christos 
   1120  1.1  christos 	  if (!new_height_ok (tui_win_list[CMD_WIN], new_height)
   1121  1.1  christos 	      || tui_adjust_win_heights (tui_win_list[CMD_WIN],
   1122  1.1  christos 					 new_height) == TUI_FAILURE)
   1123  1.1  christos 	    warning (_("Invalid window height specified.\n%s"),
   1124  1.1  christos 		     XDBWIN_HEIGHT_USAGE);
   1125  1.1  christos 	}
   1126  1.1  christos       else
   1127  1.1  christos 	warning (_("Invalid window height specified.\n%s"),
   1128  1.1  christos 		 XDBWIN_HEIGHT_USAGE);
   1129  1.1  christos     }
   1130  1.1  christos   else
   1131  1.1  christos     warning (_("Invalid window height specified.\n%s"), XDBWIN_HEIGHT_USAGE);
   1132  1.1  christos }
   1133  1.1  christos 
   1134  1.1  christos /* Set the height of the specified window, with va_list.  */
   1135  1.1  christos static void
   1136  1.1  christos tui_xdb_set_win_height_command (char *arg, int from_tty)
   1137  1.1  christos {
   1138  1.1  christos   tui_xdb_set_win_height (arg, from_tty);
   1139  1.1  christos }
   1140  1.1  christos 
   1141  1.1  christos 
   1142  1.1  christos /* Function to adjust all window heights around the primary.   */
   1143  1.1  christos static enum tui_status
   1144  1.1  christos tui_adjust_win_heights (struct tui_win_info *primary_win_info,
   1145  1.1  christos 			int new_height)
   1146  1.1  christos {
   1147  1.1  christos   enum tui_status status = TUI_FAILURE;
   1148  1.1  christos 
   1149  1.1  christos   if (new_height_ok (primary_win_info, new_height))
   1150  1.1  christos     {
   1151  1.1  christos       status = TUI_SUCCESS;
   1152  1.1  christos       if (new_height != primary_win_info->generic.height)
   1153  1.1  christos 	{
   1154  1.1  christos 	  int diff;
   1155  1.1  christos 	  struct tui_win_info *win_info;
   1156  1.1  christos 	  struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
   1157  1.1  christos 	  enum tui_layout_type cur_layout = tui_current_layout ();
   1158  1.1  christos 
   1159  1.1  christos 	  diff = (new_height - primary_win_info->generic.height) * (-1);
   1160  1.1  christos 	  if (cur_layout == SRC_COMMAND
   1161  1.1  christos 	      || cur_layout == DISASSEM_COMMAND)
   1162  1.1  christos 	    {
   1163  1.1  christos 	      struct tui_win_info *src_win_info;
   1164  1.1  christos 
   1165  1.1  christos 	      make_invisible_and_set_new_height (primary_win_info, new_height);
   1166  1.1  christos 	      if (primary_win_info->generic.type == CMD_WIN)
   1167  1.1  christos 		{
   1168  1.1  christos 		  win_info = (tui_source_windows ())->list[0];
   1169  1.1  christos 		  src_win_info = win_info;
   1170  1.1  christos 		}
   1171  1.1  christos 	      else
   1172  1.1  christos 		{
   1173  1.1  christos 		  win_info = tui_win_list[CMD_WIN];
   1174  1.1  christos 		  src_win_info = primary_win_info;
   1175  1.1  christos 		}
   1176  1.1  christos 	      make_invisible_and_set_new_height (win_info,
   1177  1.1  christos 					     win_info->generic.height + diff);
   1178  1.1  christos 	      TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
   1179  1.1  christos 	      make_visible_with_new_height (win_info);
   1180  1.1  christos 	      make_visible_with_new_height (primary_win_info);
   1181  1.1  christos 	      if (src_win_info->generic.content_size <= 0)
   1182  1.1  christos 		tui_erase_source_content (src_win_info, EMPTY_SOURCE_PROMPT);
   1183  1.1  christos 	    }
   1184  1.1  christos 	  else
   1185  1.1  christos 	    {
   1186  1.1  christos 	      struct tui_win_info *first_win;
   1187  1.1  christos 	      struct tui_win_info *second_win;
   1188  1.1  christos 
   1189  1.1  christos 	      if (cur_layout == SRC_DISASSEM_COMMAND)
   1190  1.1  christos 		{
   1191  1.1  christos 		  first_win = TUI_SRC_WIN;
   1192  1.1  christos 		  second_win = TUI_DISASM_WIN;
   1193  1.1  christos 		}
   1194  1.1  christos 	      else
   1195  1.1  christos 		{
   1196  1.1  christos 		  first_win = TUI_DATA_WIN;
   1197  1.1  christos 		  second_win = (tui_source_windows ())->list[0];
   1198  1.1  christos 		}
   1199  1.1  christos 	      if (primary_win_info == TUI_CMD_WIN)
   1200  1.1  christos 		{ /* Split the change in height accross the 1st & 2nd
   1201  1.1  christos 		     windows, adjusting them as well.  */
   1202  1.1  christos 		  /* Subtract the locator.  */
   1203  1.1  christos 		  int first_split_diff = diff / 2;
   1204  1.1  christos 		  int second_split_diff = first_split_diff;
   1205  1.1  christos 
   1206  1.1  christos 		  if (diff % 2)
   1207  1.1  christos 		    {
   1208  1.1  christos 		      if (first_win->generic.height >
   1209  1.1  christos 			  second_win->generic.height)
   1210  1.1  christos 			if (diff < 0)
   1211  1.1  christos 			  first_split_diff--;
   1212  1.1  christos 			else
   1213  1.1  christos 			  first_split_diff++;
   1214  1.1  christos 		      else
   1215  1.1  christos 			{
   1216  1.1  christos 			  if (diff < 0)
   1217  1.1  christos 			    second_split_diff--;
   1218  1.1  christos 			  else
   1219  1.1  christos 			    second_split_diff++;
   1220  1.1  christos 			}
   1221  1.1  christos 		    }
   1222  1.1  christos 		  /* Make sure that the minimum hieghts are
   1223  1.1  christos 		     honored.  */
   1224  1.1  christos 		  while ((first_win->generic.height + first_split_diff) < 3)
   1225  1.1  christos 		    {
   1226  1.1  christos 		      first_split_diff++;
   1227  1.1  christos 		      second_split_diff--;
   1228  1.1  christos 		    }
   1229  1.1  christos 		  while ((second_win->generic.height + second_split_diff) < 3)
   1230  1.1  christos 		    {
   1231  1.1  christos 		      second_split_diff++;
   1232  1.1  christos 		      first_split_diff--;
   1233  1.1  christos 		    }
   1234  1.1  christos 		  make_invisible_and_set_new_height (
   1235  1.1  christos 						  first_win,
   1236  1.1  christos 				 first_win->generic.height + first_split_diff);
   1237  1.1  christos 		  second_win->generic.origin.y = first_win->generic.height - 1;
   1238  1.1  christos 		  make_invisible_and_set_new_height (second_win,
   1239  1.1  christos 						     second_win->generic.height
   1240  1.1  christos 						     + second_split_diff);
   1241  1.1  christos 		  TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
   1242  1.1  christos 		  make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);
   1243  1.1  christos 		}
   1244  1.1  christos 	      else
   1245  1.1  christos 		{
   1246  1.1  christos 		  if ((TUI_CMD_WIN->generic.height + diff) < 1)
   1247  1.1  christos 		    { /* If there is no way to increase the command
   1248  1.1  christos 			 window take real estate from the 1st or 2nd
   1249  1.1  christos 			 window.  */
   1250  1.1  christos 		      if ((TUI_CMD_WIN->generic.height + diff) < 1)
   1251  1.1  christos 			{
   1252  1.1  christos 			  int i;
   1253  1.1  christos 
   1254  1.1  christos 			  for (i = TUI_CMD_WIN->generic.height + diff;
   1255  1.1  christos 			       (i < 1); i++)
   1256  1.1  christos 			    if (primary_win_info == first_win)
   1257  1.1  christos 			      second_win->generic.height--;
   1258  1.1  christos 			    else
   1259  1.1  christos 			      first_win->generic.height--;
   1260  1.1  christos 			}
   1261  1.1  christos 		    }
   1262  1.1  christos 		  if (primary_win_info == first_win)
   1263  1.1  christos 		    make_invisible_and_set_new_height (first_win, new_height);
   1264  1.1  christos 		  else
   1265  1.1  christos 		    make_invisible_and_set_new_height (
   1266  1.1  christos 						    first_win,
   1267  1.1  christos 						  first_win->generic.height);
   1268  1.1  christos 		  second_win->generic.origin.y = first_win->generic.height - 1;
   1269  1.1  christos 		  if (primary_win_info == second_win)
   1270  1.1  christos 		    make_invisible_and_set_new_height (second_win, new_height);
   1271  1.1  christos 		  else
   1272  1.1  christos 		    make_invisible_and_set_new_height (
   1273  1.1  christos 				      second_win, second_win->generic.height);
   1274  1.1  christos 		  TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
   1275  1.1  christos 		  if ((TUI_CMD_WIN->generic.height + diff) < 1)
   1276  1.1  christos 		    make_invisible_and_set_new_height (TUI_CMD_WIN, 1);
   1277  1.1  christos 		  else
   1278  1.1  christos 		    make_invisible_and_set_new_height (TUI_CMD_WIN,
   1279  1.1  christos 						       TUI_CMD_WIN->generic.height + diff);
   1280  1.1  christos 		}
   1281  1.1  christos 	      make_visible_with_new_height (TUI_CMD_WIN);
   1282  1.1  christos 	      make_visible_with_new_height (second_win);
   1283  1.1  christos 	      make_visible_with_new_height (first_win);
   1284  1.1  christos 	      if (first_win->generic.content_size <= 0)
   1285  1.1  christos 		tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
   1286  1.1  christos 	      if (second_win->generic.content_size <= 0)
   1287  1.1  christos 		tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
   1288  1.1  christos 	    }
   1289  1.1  christos 	}
   1290  1.1  christos     }
   1291  1.1  christos 
   1292  1.1  christos   return status;
   1293  1.1  christos }
   1294  1.1  christos 
   1295  1.1  christos 
   1296  1.1  christos /* Function make the target window (and auxillary windows associated
   1297  1.1  christos    with the targer) invisible, and set the new height and
   1298  1.1  christos    location.  */
   1299  1.1  christos static void
   1300  1.1  christos make_invisible_and_set_new_height (struct tui_win_info *win_info,
   1301  1.1  christos 				   int height)
   1302  1.1  christos {
   1303  1.1  christos   int i;
   1304  1.1  christos   struct tui_gen_win_info *gen_win_info;
   1305  1.1  christos 
   1306  1.1  christos   tui_make_invisible (&win_info->generic);
   1307  1.1  christos   win_info->generic.height = height;
   1308  1.1  christos   if (height > 1)
   1309  1.1  christos     win_info->generic.viewport_height = height - 1;
   1310  1.1  christos   else
   1311  1.1  christos     win_info->generic.viewport_height = height;
   1312  1.1  christos   if (win_info != TUI_CMD_WIN)
   1313  1.1  christos     win_info->generic.viewport_height--;
   1314  1.1  christos 
   1315  1.1  christos   /* Now deal with the auxillary windows associated with win_info.  */
   1316  1.1  christos   switch (win_info->generic.type)
   1317  1.1  christos     {
   1318  1.1  christos     case SRC_WIN:
   1319  1.1  christos     case DISASSEM_WIN:
   1320  1.1  christos       gen_win_info = win_info->detail.source_info.execution_info;
   1321  1.1  christos       tui_make_invisible (gen_win_info);
   1322  1.1  christos       gen_win_info->height = height;
   1323  1.1  christos       gen_win_info->origin.y = win_info->generic.origin.y;
   1324  1.1  christos       if (height > 1)
   1325  1.1  christos 	gen_win_info->viewport_height = height - 1;
   1326  1.1  christos       else
   1327  1.1  christos 	gen_win_info->viewport_height = height;
   1328  1.1  christos       if (win_info != TUI_CMD_WIN)
   1329  1.1  christos 	gen_win_info->viewport_height--;
   1330  1.1  christos 
   1331  1.1  christos       if (tui_win_has_locator (win_info))
   1332  1.1  christos 	{
   1333  1.1  christos 	  gen_win_info = tui_locator_win_info_ptr ();
   1334  1.1  christos 	  tui_make_invisible (gen_win_info);
   1335  1.1  christos 	  gen_win_info->origin.y = win_info->generic.origin.y + height;
   1336  1.1  christos 	}
   1337  1.1  christos       break;
   1338  1.1  christos     case DATA_WIN:
   1339  1.1  christos       /* Delete all data item windows.  */
   1340  1.1  christos       for (i = 0; i < win_info->generic.content_size; i++)
   1341  1.1  christos 	{
   1342  1.1  christos 	  gen_win_info = (struct tui_gen_win_info *)
   1343  1.1  christos 	    &((struct tui_win_element *)
   1344  1.1  christos 	      win_info->generic.content[i])->which_element.data_window;
   1345  1.1  christos 	  tui_delete_win (gen_win_info->handle);
   1346  1.1  christos 	  gen_win_info->handle = (WINDOW *) NULL;
   1347  1.1  christos 	}
   1348  1.1  christos       break;
   1349  1.1  christos     default:
   1350  1.1  christos       break;
   1351  1.1  christos     }
   1352  1.1  christos }
   1353  1.1  christos 
   1354  1.1  christos 
   1355  1.1  christos /* Function to make the windows with new heights visible.  This means
   1356  1.1  christos    re-creating the windows' content since the window had to be
   1357  1.1  christos    destroyed to be made invisible.  */
   1358  1.1  christos static void
   1359  1.1  christos make_visible_with_new_height (struct tui_win_info *win_info)
   1360  1.1  christos {
   1361  1.1  christos   struct symtab *s;
   1362  1.1  christos 
   1363  1.1  christos   tui_make_visible (&win_info->generic);
   1364  1.1  christos   tui_check_and_display_highlight_if_needed (win_info);
   1365  1.1  christos   switch (win_info->generic.type)
   1366  1.1  christos     {
   1367  1.1  christos     case SRC_WIN:
   1368  1.1  christos     case DISASSEM_WIN:
   1369  1.1  christos       tui_free_win_content (win_info->detail.source_info.execution_info);
   1370  1.1  christos       tui_make_visible (win_info->detail.source_info.execution_info);
   1371  1.1  christos       if (win_info->generic.content != NULL)
   1372  1.1  christos 	{
   1373  1.1  christos 	  struct gdbarch *gdbarch = win_info->detail.source_info.gdbarch;
   1374  1.1  christos 	  struct tui_line_or_address line_or_addr;
   1375  1.1  christos 	  struct symtab_and_line cursal
   1376  1.1  christos 	    = get_current_source_symtab_and_line ();
   1377  1.1  christos 
   1378  1.1  christos 	  line_or_addr = win_info->detail.source_info.start_line_or_addr;
   1379  1.1  christos 	  tui_free_win_content (&win_info->generic);
   1380  1.1  christos 	  tui_update_source_window (win_info, gdbarch,
   1381  1.1  christos 				    cursal.symtab, line_or_addr, TRUE);
   1382  1.1  christos 	}
   1383  1.1  christos       else if (deprecated_safe_get_selected_frame () != NULL)
   1384  1.1  christos 	{
   1385  1.1  christos 	  struct tui_line_or_address line;
   1386  1.1  christos 	  struct symtab_and_line cursal
   1387  1.1  christos 	    = get_current_source_symtab_and_line ();
   1388  1.1  christos 	  struct frame_info *frame = deprecated_safe_get_selected_frame ();
   1389  1.1  christos 	  struct gdbarch *gdbarch = get_frame_arch (frame);
   1390  1.1  christos 
   1391  1.1  christos 	  s = find_pc_symtab (get_frame_pc (frame));
   1392  1.1  christos 	  if (win_info->generic.type == SRC_WIN)
   1393  1.1  christos 	    {
   1394  1.1  christos 	      line.loa = LOA_LINE;
   1395  1.1  christos 	      line.u.line_no = cursal.line;
   1396  1.1  christos 	    }
   1397  1.1  christos 	  else
   1398  1.1  christos 	    {
   1399  1.1  christos 	      line.loa = LOA_ADDRESS;
   1400  1.1  christos 	      find_line_pc (s, cursal.line, &line.u.addr);
   1401  1.1  christos 	    }
   1402  1.1  christos 	  tui_update_source_window (win_info, gdbarch, s, line, TRUE);
   1403  1.1  christos 	}
   1404  1.1  christos       if (tui_win_has_locator (win_info))
   1405  1.1  christos 	{
   1406  1.1  christos 	  tui_make_visible (tui_locator_win_info_ptr ());
   1407  1.1  christos 	  tui_show_locator_content ();
   1408  1.1  christos 	}
   1409  1.1  christos       break;
   1410  1.1  christos     case DATA_WIN:
   1411  1.1  christos       tui_display_all_data ();
   1412  1.1  christos       break;
   1413  1.1  christos     case CMD_WIN:
   1414  1.1  christos       win_info->detail.command_info.cur_line = 0;
   1415  1.1  christos       win_info->detail.command_info.curch = 0;
   1416  1.1  christos #ifdef HAVE_WRESIZE
   1417  1.1  christos       wresize (TUI_CMD_WIN->generic.handle,
   1418  1.1  christos 	       TUI_CMD_WIN->generic.height,
   1419  1.1  christos 	       TUI_CMD_WIN->generic.width);
   1420  1.1  christos #endif
   1421  1.1  christos       mvwin (TUI_CMD_WIN->generic.handle,
   1422  1.1  christos 	     TUI_CMD_WIN->generic.origin.y,
   1423  1.1  christos 	     TUI_CMD_WIN->generic.origin.x);
   1424  1.1  christos       wmove (win_info->generic.handle,
   1425  1.1  christos 	     win_info->detail.command_info.cur_line,
   1426  1.1  christos 	     win_info->detail.command_info.curch);
   1427  1.1  christos       break;
   1428  1.1  christos     default:
   1429  1.1  christos       break;
   1430  1.1  christos     }
   1431  1.1  christos }
   1432  1.1  christos 
   1433  1.1  christos 
   1434  1.1  christos static int
   1435  1.1  christos new_height_ok (struct tui_win_info *primary_win_info,
   1436  1.1  christos 	       int new_height)
   1437  1.1  christos {
   1438  1.1  christos   int ok = (new_height < tui_term_height ());
   1439  1.1  christos 
   1440  1.1  christos   if (ok)
   1441  1.1  christos     {
   1442  1.1  christos       int diff;
   1443  1.1  christos       enum tui_layout_type cur_layout = tui_current_layout ();
   1444  1.1  christos 
   1445  1.1  christos       diff = (new_height - primary_win_info->generic.height) * (-1);
   1446  1.1  christos       if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND)
   1447  1.1  christos 	{
   1448  1.1  christos 	  ok = ((primary_win_info->generic.type == CMD_WIN
   1449  1.1  christos 		 && new_height <= (tui_term_height () - 4)
   1450  1.1  christos 		 && new_height >= MIN_CMD_WIN_HEIGHT)
   1451  1.1  christos 		|| (primary_win_info->generic.type != CMD_WIN
   1452  1.1  christos 		    && new_height <= (tui_term_height () - 2)
   1453  1.1  christos 		    && new_height >= MIN_WIN_HEIGHT));
   1454  1.1  christos 	  if (ok)
   1455  1.1  christos 	    {			/* Check the total height.  */
   1456  1.1  christos 	      struct tui_win_info *win_info;
   1457  1.1  christos 
   1458  1.1  christos 	      if (primary_win_info == TUI_CMD_WIN)
   1459  1.1  christos 		win_info = (tui_source_windows ())->list[0];
   1460  1.1  christos 	      else
   1461  1.1  christos 		win_info = TUI_CMD_WIN;
   1462  1.1  christos 	      ok = ((new_height +
   1463  1.1  christos 		     (win_info->generic.height + diff)) <= tui_term_height ());
   1464  1.1  christos 	    }
   1465  1.1  christos 	}
   1466  1.1  christos       else
   1467  1.1  christos 	{
   1468  1.1  christos 	  int cur_total_height, total_height, min_height = 0;
   1469  1.1  christos 	  struct tui_win_info *first_win;
   1470  1.1  christos 	  struct tui_win_info *second_win;
   1471  1.1  christos 
   1472  1.1  christos 	  if (cur_layout == SRC_DISASSEM_COMMAND)
   1473  1.1  christos 	    {
   1474  1.1  christos 	      first_win = TUI_SRC_WIN;
   1475  1.1  christos 	      second_win = TUI_DISASM_WIN;
   1476  1.1  christos 	    }
   1477  1.1  christos 	  else
   1478  1.1  christos 	    {
   1479  1.1  christos 	      first_win = TUI_DATA_WIN;
   1480  1.1  christos 	      second_win = (tui_source_windows ())->list[0];
   1481  1.1  christos 	    }
   1482  1.1  christos 	  /* We could simply add all the heights to obtain the same
   1483  1.1  christos 	     result but below is more explicit since we subtract 1 for
   1484  1.1  christos 	     the line that the first and second windows share, and add
   1485  1.1  christos 	     one for the locator.  */
   1486  1.1  christos 	  total_height = cur_total_height =
   1487  1.1  christos 	    (first_win->generic.height + second_win->generic.height - 1)
   1488  1.1  christos 	    + TUI_CMD_WIN->generic.height + 1;	/* Locator. */
   1489  1.1  christos 	  if (primary_win_info == TUI_CMD_WIN)
   1490  1.1  christos 	    {
   1491  1.1  christos 	      /* Locator included since first & second win share a line.  */
   1492  1.1  christos 	      ok = ((first_win->generic.height +
   1493  1.1  christos 		     second_win->generic.height + diff) >=
   1494  1.1  christos 		    (MIN_WIN_HEIGHT * 2)
   1495  1.1  christos 		    && new_height >= MIN_CMD_WIN_HEIGHT);
   1496  1.1  christos 	      if (ok)
   1497  1.1  christos 		{
   1498  1.1  christos 		  total_height = new_height +
   1499  1.1  christos 		    (first_win->generic.height +
   1500  1.1  christos 		     second_win->generic.height + diff);
   1501  1.1  christos 		  min_height = MIN_CMD_WIN_HEIGHT;
   1502  1.1  christos 		}
   1503  1.1  christos 	    }
   1504  1.1  christos 	  else
   1505  1.1  christos 	    {
   1506  1.1  christos 	      min_height = MIN_WIN_HEIGHT;
   1507  1.1  christos 
   1508  1.1  christos 	      /* First see if we can increase/decrease the command
   1509  1.1  christos 	         window.  And make sure that the command window is at
   1510  1.1  christos 	         least 1 line.  */
   1511  1.1  christos 	      ok = ((TUI_CMD_WIN->generic.height + diff) > 0);
   1512  1.1  christos 	      if (!ok)
   1513  1.1  christos 		{ /* Looks like we have to increase/decrease one of
   1514  1.1  christos 		     the other windows.  */
   1515  1.1  christos 		  if (primary_win_info == first_win)
   1516  1.1  christos 		    ok = (second_win->generic.height + diff) >= min_height;
   1517  1.1  christos 		  else
   1518  1.1  christos 		    ok = (first_win->generic.height + diff) >= min_height;
   1519  1.1  christos 		}
   1520  1.1  christos 	      if (ok)
   1521  1.1  christos 		{
   1522  1.1  christos 		  if (primary_win_info == first_win)
   1523  1.1  christos 		    total_height = new_height +
   1524  1.1  christos 		      second_win->generic.height +
   1525  1.1  christos 		      TUI_CMD_WIN->generic.height + diff;
   1526  1.1  christos 		  else
   1527  1.1  christos 		    total_height = new_height +
   1528  1.1  christos 		      first_win->generic.height +
   1529  1.1  christos 		      TUI_CMD_WIN->generic.height + diff;
   1530  1.1  christos 		}
   1531  1.1  christos 	    }
   1532  1.1  christos 	  /* Now make sure that the proposed total height doesn't
   1533  1.1  christos 	     exceed the old total height.  */
   1534  1.1  christos 	  if (ok)
   1535  1.1  christos 	    ok = (new_height >= min_height
   1536  1.1  christos 		  && total_height <= cur_total_height);
   1537  1.1  christos 	}
   1538  1.1  christos     }
   1539  1.1  christos 
   1540  1.1  christos   return ok;
   1541  1.1  christos }
   1542  1.1  christos 
   1543  1.1  christos 
   1544  1.1  christos static void
   1545  1.1  christos parse_scrolling_args (char *arg,
   1546  1.1  christos 		      struct tui_win_info **win_to_scroll,
   1547  1.1  christos 		      int *num_to_scroll)
   1548  1.1  christos {
   1549  1.1  christos   if (num_to_scroll)
   1550  1.1  christos     *num_to_scroll = 0;
   1551  1.1  christos   *win_to_scroll = tui_win_with_focus ();
   1552  1.1  christos 
   1553  1.1  christos   /* First set up the default window to scroll, in case there is no
   1554  1.1  christos      window name arg.  */
   1555  1.1  christos   if (arg != (char *) NULL)
   1556  1.1  christos     {
   1557  1.1  christos       char *buf, *buf_ptr;
   1558  1.1  christos 
   1559  1.1  christos       /* Process the number of lines to scroll.  */
   1560  1.1  christos       buf = buf_ptr = xstrdup (arg);
   1561  1.1  christos       if (isdigit (*buf_ptr))
   1562  1.1  christos 	{
   1563  1.1  christos 	  char *num_str;
   1564  1.1  christos 
   1565  1.1  christos 	  num_str = buf_ptr;
   1566  1.1  christos 	  buf_ptr = strchr (buf_ptr, ' ');
   1567  1.1  christos 	  if (buf_ptr != (char *) NULL)
   1568  1.1  christos 	    {
   1569  1.1  christos 	      *buf_ptr = (char) 0;
   1570  1.1  christos 	      if (num_to_scroll)
   1571  1.1  christos 		*num_to_scroll = atoi (num_str);
   1572  1.1  christos 	      buf_ptr++;
   1573  1.1  christos 	    }
   1574  1.1  christos 	  else if (num_to_scroll)
   1575  1.1  christos 	    *num_to_scroll = atoi (num_str);
   1576  1.1  christos 	}
   1577  1.1  christos 
   1578  1.1  christos       /* Process the window name if one is specified.  */
   1579  1.1  christos       if (buf_ptr != (char *) NULL)
   1580  1.1  christos 	{
   1581  1.1  christos 	  char *wname;
   1582  1.1  christos 	  int i;
   1583  1.1  christos 
   1584  1.1  christos 	  if (*buf_ptr == ' ')
   1585  1.1  christos 	    while (*(++buf_ptr) == ' ')
   1586  1.1  christos 	      ;
   1587  1.1  christos 
   1588  1.1  christos 	  if (*buf_ptr != (char) 0)
   1589  1.1  christos 	    {
   1590  1.1  christos 	      wname = buf_ptr;
   1591  1.1  christos 
   1592  1.1  christos 	      /* Validate the window name.  */
   1593  1.1  christos 	      for (i = 0; i < strlen (wname); i++)
   1594  1.1  christos 		wname[i] = toupper (wname[i]);
   1595  1.1  christos 	    }
   1596  1.1  christos 	  else
   1597  1.1  christos 	    wname = "?";
   1598  1.1  christos 
   1599  1.1  christos 	  *win_to_scroll = tui_partial_win_by_name (wname);
   1600  1.1  christos 
   1601  1.1  christos 	  if (*win_to_scroll == (struct tui_win_info *) NULL
   1602  1.1  christos 	      || !(*win_to_scroll)->generic.is_visible)
   1603  1.1  christos 	    error (_("Invalid window specified. \n\
   1604  1.1  christos The window name specified must be valid and visible.\n"));
   1605  1.1  christos 	  else if (*win_to_scroll == TUI_CMD_WIN)
   1606  1.1  christos 	    *win_to_scroll = (tui_source_windows ())->list[0];
   1607  1.1  christos 	}
   1608  1.1  christos       xfree (buf);
   1609  1.1  christos     }
   1610  1.1  christos }
   1611