Home | History | Annotate | Line # | Download | only in tui
tui-data.h revision 1.9
      1  1.1  christos /* TUI data manipulation routines.
      2  1.1  christos 
      3  1.9  christos    Copyright (C) 1998-2020 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.8  christos #ifndef TUI_TUI_DATA_H
     23  1.8  christos #define TUI_TUI_DATA_H
     24  1.1  christos 
     25  1.9  christos #include "tui/tui.h"
     26  1.1  christos #include "gdb_curses.h"	/* For WINDOW.  */
     27  1.9  christos #include "observable.h"
     28  1.1  christos 
     29  1.9  christos /* A deleter that calls delwin.  */
     30  1.9  christos struct curses_deleter
     31  1.1  christos {
     32  1.9  christos   void operator() (WINDOW *win) const
     33  1.9  christos   {
     34  1.9  christos     delwin (win);
     35  1.9  christos   }
     36  1.1  christos };
     37  1.1  christos 
     38  1.9  christos #define MIN_WIN_HEIGHT          3
     39  1.5  christos 
     40  1.1  christos /* Generic window information.  */
     41  1.9  christos struct tui_win_info
     42  1.1  christos {
     43  1.9  christos protected:
     44  1.1  christos 
     45  1.9  christos   tui_win_info () = default;
     46  1.9  christos   DISABLE_COPY_AND_ASSIGN (tui_win_info);
     47  1.1  christos 
     48  1.9  christos   /* This is called after the window is resized, and should update the
     49  1.9  christos      window's contents.  */
     50  1.9  christos   virtual void rerender ();
     51  1.1  christos 
     52  1.9  christos   virtual void make_window ();
     53  1.1  christos 
     54  1.9  christos public:
     55  1.9  christos   tui_win_info (tui_win_info &&) = default;
     56  1.9  christos   virtual ~tui_win_info () = default;
     57  1.1  christos 
     58  1.9  christos   /* Call to refresh this window.  */
     59  1.9  christos   virtual void refresh_window ();
     60  1.1  christos 
     61  1.9  christos   /* Make this window visible or invisible.  */
     62  1.9  christos   virtual void make_visible (bool visible);
     63  1.1  christos 
     64  1.9  christos   /* Return the name of this type of window.  */
     65  1.9  christos   virtual const char *name () const = 0;
     66  1.1  christos 
     67  1.9  christos   /* Compute the maximum height of this window.  */
     68  1.9  christos   virtual int max_height () const;
     69  1.1  christos 
     70  1.9  christos   /* Compute the minimum height of this window.  */
     71  1.9  christos   virtual int min_height () const
     72  1.9  christos   {
     73  1.9  christos     return MIN_WIN_HEIGHT;
     74  1.9  christos   }
     75  1.1  christos 
     76  1.9  christos   /* Compute the maximum width of this window.  */
     77  1.9  christos   int max_width () const;
     78  1.1  christos 
     79  1.9  christos   /* Compute the minimum width of this window.  */
     80  1.9  christos   int min_width () const
     81  1.9  christos   {
     82  1.9  christos     return 3;
     83  1.9  christos   }
     84  1.1  christos 
     85  1.9  christos   /* Return true if this window can be boxed.  */
     86  1.9  christos   virtual bool can_box () const
     87  1.9  christos   {
     88  1.9  christos     return true;
     89  1.9  christos   }
     90  1.1  christos 
     91  1.9  christos   /* Resize this window.  The parameters are used to set the window's
     92  1.9  christos      size and position.  */
     93  1.9  christos   virtual void resize (int height, int width,
     94  1.9  christos 		       int origin_x, int origin_y);
     95  1.1  christos 
     96  1.9  christos   /* Return true if this window is visible.  */
     97  1.9  christos   bool is_visible () const
     98  1.9  christos   {
     99  1.9  christos     return handle != nullptr;
    100  1.9  christos   }
    101  1.1  christos 
    102  1.9  christos   /* Disable output until the next call to doupdate.  */
    103  1.9  christos   void no_refresh ()
    104  1.9  christos   {
    105  1.9  christos     if (handle != nullptr)
    106  1.9  christos       wnoutrefresh (handle.get ());
    107  1.9  christos   }
    108  1.1  christos 
    109  1.9  christos   /* Called after the tab width has been changed.  */
    110  1.9  christos   virtual void update_tab_width ()
    111  1.9  christos   {
    112  1.9  christos   }
    113  1.1  christos 
    114  1.9  christos   /* Set whether this window is highlighted.  */
    115  1.9  christos   void set_highlight (bool highlight)
    116  1.9  christos   {
    117  1.9  christos     is_highlighted = highlight;
    118  1.9  christos   }
    119  1.1  christos 
    120  1.9  christos   /* Methods to scroll the contents of this window.  Note that they
    121  1.9  christos      are named with "_scroll" coming at the end because the more
    122  1.9  christos      obvious "scroll_forward" is defined as a macro in term.h.  */
    123  1.9  christos   void forward_scroll (int num_to_scroll);
    124  1.9  christos   void backward_scroll (int num_to_scroll);
    125  1.9  christos   void left_scroll (int num_to_scroll);
    126  1.9  christos   void right_scroll (int num_to_scroll);
    127  1.1  christos 
    128  1.9  christos   /* Return true if this window can be scrolled, false otherwise.  */
    129  1.9  christos   virtual bool can_scroll () const
    130  1.9  christos   {
    131  1.9  christos     return true;
    132  1.9  christos   }
    133  1.1  christos 
    134  1.9  christos   void check_and_display_highlight_if_needed ();
    135  1.1  christos 
    136  1.9  christos   /* Window handle.  */
    137  1.9  christos   std::unique_ptr<WINDOW, curses_deleter> handle;
    138  1.9  christos   /* Window width.  */
    139  1.9  christos   int width = 0;
    140  1.9  christos   /* Window height.  */
    141  1.9  christos   int height = 0;
    142  1.9  christos   /* Origin of window.  */
    143  1.9  christos   int x = 0;
    144  1.9  christos   int y = 0;
    145  1.9  christos 
    146  1.9  christos   /* Window title to display.  */
    147  1.9  christos   std::string title;
    148  1.9  christos 
    149  1.9  christos   /* Is this window highlighted?  */
    150  1.9  christos   bool is_highlighted = false;
    151  1.9  christos 
    152  1.9  christos protected:
    153  1.9  christos 
    154  1.9  christos   /* Scroll the contents vertically.  This is only called via
    155  1.9  christos      forward_scroll and backward_scroll.  */
    156  1.9  christos   virtual void do_scroll_vertical (int num_to_scroll) = 0;
    157  1.9  christos 
    158  1.9  christos   /* Scroll the contents horizontally.  This is only called via
    159  1.9  christos      left_scroll and right_scroll.  */
    160  1.9  christos   virtual void do_scroll_horizontal (int num_to_scroll) = 0;
    161  1.1  christos };
    162  1.1  christos 
    163  1.9  christos /* Constant definitions.  */
    164  1.9  christos #define SRC_NAME                "src"
    165  1.9  christos #define CMD_NAME                "cmd"
    166  1.9  christos #define DATA_NAME               "regs"
    167  1.9  christos #define DISASSEM_NAME           "asm"
    168  1.9  christos #define STATUS_NAME		"status"
    169  1.1  christos 
    170  1.1  christos /* Global Data.  */
    171  1.8  christos extern struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS];
    172  1.1  christos 
    173  1.9  christos #define TUI_SRC_WIN     ((tui_source_window *) tui_win_list[SRC_WIN])
    174  1.9  christos #define TUI_DISASM_WIN	((tui_disasm_window *) tui_win_list[DISASSEM_WIN])
    175  1.9  christos #define TUI_DATA_WIN    ((tui_data_window *) tui_win_list[DATA_WIN])
    176  1.9  christos #define TUI_CMD_WIN     ((tui_cmd_window *) tui_win_list[CMD_WIN])
    177  1.9  christos 
    178  1.9  christos /* All the windows that are currently instantiated, in layout
    179  1.9  christos    order.  */
    180  1.9  christos extern std::vector<tui_win_info *> tui_windows;
    181  1.9  christos 
    182  1.9  christos /* Return a range adapter for iterating over TUI windows.  */
    183  1.9  christos static inline std::vector<tui_win_info *> &
    184  1.9  christos all_tui_windows ()
    185  1.9  christos {
    186  1.9  christos   return tui_windows;
    187  1.9  christos }
    188  1.1  christos 
    189  1.1  christos /* Data Manipulation Functions.  */
    190  1.1  christos extern int tui_term_height (void);
    191  1.1  christos extern void tui_set_term_height_to (int);
    192  1.1  christos extern int tui_term_width (void);
    193  1.1  christos extern void tui_set_term_width_to (int);
    194  1.9  christos extern struct tui_locator_window *tui_locator_win_info_ptr (void);
    195  1.1  christos extern struct tui_win_info *tui_win_with_focus (void);
    196  1.9  christos extern bool tui_win_resized ();
    197  1.9  christos extern void tui_set_win_resized_to (bool);
    198  1.1  christos 
    199  1.1  christos extern struct tui_win_info *tui_next_win (struct tui_win_info *);
    200  1.1  christos extern struct tui_win_info *tui_prev_win (struct tui_win_info *);
    201  1.1  christos 
    202  1.8  christos extern unsigned int tui_tab_width;
    203  1.8  christos 
    204  1.8  christos #endif /* TUI_TUI_DATA_H */
    205