1 1.1 christos /* TUI data manipulation routines. 2 1.1 christos 3 1.11 christos Copyright (C) 1998-2024 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.12 christos #ifndef GDB_TUI_TUI_DATA_H 23 1.12 christos #define GDB_TUI_TUI_DATA_H 24 1.1 christos 25 1.9 christos #include "tui/tui.h" 26 1.11 christos #include "gdb_curses.h" 27 1.1 christos 28 1.9 christos /* A deleter that calls delwin. */ 29 1.9 christos struct curses_deleter 30 1.1 christos { 31 1.9 christos void operator() (WINDOW *win) const 32 1.9 christos { 33 1.9 christos delwin (win); 34 1.9 christos } 35 1.1 christos }; 36 1.1 christos 37 1.9 christos #define MIN_WIN_HEIGHT 3 38 1.5 christos 39 1.1 christos /* Generic window information. */ 40 1.9 christos struct tui_win_info 41 1.1 christos { 42 1.9 christos protected: 43 1.1 christos 44 1.9 christos tui_win_info () = default; 45 1.9 christos DISABLE_COPY_AND_ASSIGN (tui_win_info); 46 1.1 christos 47 1.9 christos /* This is called after the window is resized, and should update the 48 1.9 christos window's contents. */ 49 1.9 christos virtual void rerender (); 50 1.1 christos 51 1.12 christos /* Create the curses window. */ 52 1.12 christos 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.11 christos /* Return the width of the box. */ 92 1.11 christos int box_width () const 93 1.11 christos { 94 1.11 christos return can_box () ? 1 : 0; 95 1.11 christos } 96 1.11 christos 97 1.11 christos /* Return the size of the box. */ 98 1.11 christos int box_size () const 99 1.11 christos { 100 1.11 christos return 2 * box_width (); 101 1.11 christos } 102 1.11 christos 103 1.9 christos /* Resize this window. The parameters are used to set the window's 104 1.9 christos size and position. */ 105 1.9 christos virtual void resize (int height, int width, 106 1.9 christos int origin_x, int origin_y); 107 1.1 christos 108 1.9 christos /* Return true if this window is visible. */ 109 1.9 christos bool is_visible () const 110 1.9 christos { 111 1.10 christos return handle != nullptr && tui_active; 112 1.10 christos } 113 1.10 christos 114 1.10 christos /* Return true if this window can accept the focus. */ 115 1.10 christos virtual bool can_focus () const 116 1.10 christos { 117 1.10 christos return true; 118 1.9 christos } 119 1.1 christos 120 1.9 christos /* Called after the tab width has been changed. */ 121 1.9 christos virtual void update_tab_width () 122 1.9 christos { 123 1.9 christos } 124 1.1 christos 125 1.9 christos /* Set whether this window is highlighted. */ 126 1.9 christos void set_highlight (bool highlight) 127 1.9 christos { 128 1.9 christos is_highlighted = highlight; 129 1.9 christos } 130 1.1 christos 131 1.9 christos /* Methods to scroll the contents of this window. Note that they 132 1.9 christos are named with "_scroll" coming at the end because the more 133 1.9 christos obvious "scroll_forward" is defined as a macro in term.h. */ 134 1.9 christos void forward_scroll (int num_to_scroll); 135 1.9 christos void backward_scroll (int num_to_scroll); 136 1.9 christos void left_scroll (int num_to_scroll); 137 1.9 christos void right_scroll (int num_to_scroll); 138 1.1 christos 139 1.9 christos /* Return true if this window can be scrolled, false otherwise. */ 140 1.9 christos virtual bool can_scroll () const 141 1.9 christos { 142 1.9 christos return true; 143 1.9 christos } 144 1.1 christos 145 1.10 christos /* Called for each mouse click inside this window. Coordinates MOUSE_X 146 1.10 christos and MOUSE_Y are 0-based relative to the window, and MOUSE_BUTTON can 147 1.10 christos be 1 (left), 2 (middle), or 3 (right). */ 148 1.10 christos virtual void click (int mouse_x, int mouse_y, int mouse_button) 149 1.10 christos { 150 1.10 christos } 151 1.10 christos 152 1.9 christos void check_and_display_highlight_if_needed (); 153 1.1 christos 154 1.11 christos /* A helper function to change the title and then redraw the 155 1.11 christos surrounding box, if needed. */ 156 1.11 christos void set_title (std::string &&new_title); 157 1.11 christos 158 1.11 christos /* Return a reference to the current window title. */ 159 1.11 christos const std::string &title () const 160 1.11 christos { return m_title; } 161 1.11 christos 162 1.12 christos /* Clear the window, maybe draw the border, and then display string 163 1.11 christos STR centered in the window, abbreviated if necessary. */ 164 1.11 christos void center_string (const char *str); 165 1.11 christos 166 1.11 christos /* Display string STR in the window at the current cursor position, 167 1.11 christos abbreviated if necessary. */ 168 1.11 christos void display_string (const char *str) const; 169 1.11 christos 170 1.9 christos /* Window handle. */ 171 1.9 christos std::unique_ptr<WINDOW, curses_deleter> handle; 172 1.9 christos /* Window width. */ 173 1.9 christos int width = 0; 174 1.9 christos /* Window height. */ 175 1.9 christos int height = 0; 176 1.9 christos /* Origin of window. */ 177 1.9 christos int x = 0; 178 1.9 christos int y = 0; 179 1.9 christos 180 1.9 christos /* Is this window highlighted? */ 181 1.9 christos bool is_highlighted = false; 182 1.9 christos 183 1.9 christos protected: 184 1.9 christos 185 1.9 christos /* Scroll the contents vertically. This is only called via 186 1.9 christos forward_scroll and backward_scroll. */ 187 1.9 christos virtual void do_scroll_vertical (int num_to_scroll) = 0; 188 1.9 christos 189 1.9 christos /* Scroll the contents horizontally. This is only called via 190 1.9 christos left_scroll and right_scroll. */ 191 1.9 christos virtual void do_scroll_horizontal (int num_to_scroll) = 0; 192 1.11 christos 193 1.11 christos private: 194 1.11 christos /* Window title to display. */ 195 1.11 christos std::string m_title; 196 1.11 christos }; 197 1.11 christos 198 1.11 christos /* A TUI window that doesn't scroll. */ 199 1.11 christos 200 1.11 christos struct tui_noscroll_window : public virtual tui_win_info 201 1.11 christos { 202 1.11 christos public: 203 1.11 christos virtual bool can_scroll () const final override 204 1.11 christos { 205 1.11 christos return false; 206 1.11 christos } 207 1.11 christos 208 1.11 christos protected: 209 1.11 christos virtual void do_scroll_vertical (int num_to_scroll) final override 210 1.11 christos { 211 1.11 christos } 212 1.11 christos 213 1.11 christos /* Scroll the contents horizontally. This is only called via 214 1.11 christos left_scroll and right_scroll. */ 215 1.11 christos virtual void do_scroll_horizontal (int num_to_scroll) final override 216 1.11 christos { 217 1.11 christos } 218 1.11 christos }; 219 1.11 christos 220 1.11 christos /* A TUI window that cannot have focus. */ 221 1.11 christos 222 1.11 christos struct tui_nofocus_window : public virtual tui_win_info 223 1.11 christos { 224 1.11 christos public: 225 1.11 christos virtual bool can_focus () const final override 226 1.11 christos { 227 1.11 christos return false; 228 1.11 christos } 229 1.11 christos }; 230 1.11 christos 231 1.11 christos /* A TUI window that occupies a single line. */ 232 1.11 christos 233 1.11 christos struct tui_oneline_window : public virtual tui_win_info 234 1.11 christos { 235 1.11 christos int max_height () const final override 236 1.11 christos { 237 1.11 christos return 1; 238 1.11 christos } 239 1.11 christos 240 1.11 christos int min_height () const final override 241 1.11 christos { 242 1.11 christos return 1; 243 1.11 christos } 244 1.11 christos }; 245 1.11 christos 246 1.11 christos /* A TUI window that has no border. */ 247 1.11 christos 248 1.11 christos struct tui_nobox_window : public virtual tui_win_info 249 1.11 christos { 250 1.11 christos bool can_box () const final override 251 1.11 christos { 252 1.11 christos return false; 253 1.11 christos } 254 1.11 christos }; 255 1.11 christos 256 1.11 christos /* A TUI window that is always visible. */ 257 1.11 christos 258 1.11 christos struct tui_always_visible_window : public virtual tui_win_info 259 1.11 christos { 260 1.11 christos virtual void make_visible (bool visible) final override 261 1.11 christos { 262 1.11 christos } 263 1.1 christos }; 264 1.1 christos 265 1.9 christos /* Constant definitions. */ 266 1.9 christos #define SRC_NAME "src" 267 1.9 christos #define CMD_NAME "cmd" 268 1.9 christos #define DATA_NAME "regs" 269 1.9 christos #define DISASSEM_NAME "asm" 270 1.9 christos #define STATUS_NAME "status" 271 1.1 christos 272 1.1 christos /* Global Data. */ 273 1.8 christos extern struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS]; 274 1.1 christos 275 1.9 christos /* All the windows that are currently instantiated, in layout 276 1.9 christos order. */ 277 1.9 christos extern std::vector<tui_win_info *> tui_windows; 278 1.9 christos 279 1.9 christos /* Return a range adapter for iterating over TUI windows. */ 280 1.9 christos static inline std::vector<tui_win_info *> & 281 1.9 christos all_tui_windows () 282 1.9 christos { 283 1.9 christos return tui_windows; 284 1.9 christos } 285 1.1 christos 286 1.1 christos /* Data Manipulation Functions. */ 287 1.1 christos extern int tui_term_height (void); 288 1.1 christos extern void tui_set_term_height_to (int); 289 1.1 christos extern int tui_term_width (void); 290 1.1 christos extern void tui_set_term_width_to (int); 291 1.1 christos extern struct tui_win_info *tui_win_with_focus (void); 292 1.9 christos extern bool tui_win_resized (); 293 1.9 christos extern void tui_set_win_resized_to (bool); 294 1.1 christos 295 1.1 christos extern struct tui_win_info *tui_next_win (struct tui_win_info *); 296 1.1 christos extern struct tui_win_info *tui_prev_win (struct tui_win_info *); 297 1.1 christos 298 1.8 christos extern unsigned int tui_tab_width; 299 1.8 christos 300 1.12 christos #endif /* GDB_TUI_TUI_DATA_H */ 301