1 /* TUI data manipulation routines.
3 Copyright (C) 1998-2019 Free Software Foundation, Inc.
5 Contributed by Hewlett-Packard Company.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "tui/tui-data.h"
26 #include "tui/tui-wingeneral.h"
27 #include "gdb_curses.h"
29 /****************************
30 ** GLOBAL DECLARATIONS
31 ****************************/
32 struct tui_win_info
*tui_win_list
[MAX_MAJOR_WINDOWS
];
34 /***************************
36 ****************************/
37 static enum tui_layout_type current_layout
= UNDEFINED_LAYOUT
;
38 static int term_height
, term_width
;
39 static struct tui_locator_window _locator
;
40 static std::vector
<tui_source_window_base
*> source_windows
;
41 static struct tui_win_info
*win_with_focus
= NULL
;
42 static struct tui_layout_def layout_def
= {
43 SRC_WIN
, /* DISPLAY_MODE */
46 static int win_resized
= FALSE
;
49 /*********************************
51 **********************************/
54 tui_win_is_auxiliary (enum tui_win_type win_type
)
56 return (win_type
> MAX_MAJOR_WINDOWS
);
59 /******************************************
60 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
61 ******************************************/
63 /* Answer a whether the terminal window has been resized or not. */
65 tui_win_resized (void)
71 /* Set a whether the terminal window has been resized or not. */
73 tui_set_win_resized_to (int resized
)
75 win_resized
= resized
;
79 /* Answer a pointer to the current layout definition. */
80 struct tui_layout_def
*
87 /* Answer the window with the logical focus. */
89 tui_win_with_focus (void)
91 return win_with_focus
;
95 /* Set the window that has the logical focus. */
97 tui_set_win_with_focus (struct tui_win_info
*win_info
)
99 win_with_focus
= win_info
;
103 /* Accessor for the current source window. Usually there is only one
104 source window (either source or disassembly), but both can be
105 displayed at the same time. */
106 std::vector
<tui_source_window_base
*> &
107 tui_source_windows ()
109 return source_windows
;
113 /* Clear the list of source windows. Usually there is only one source
114 window (either source or disassembly), but both can be displayed at
117 tui_clear_source_windows ()
119 source_windows
.clear ();
123 /* Clear the pertinent detail in the source windows. */
125 tui_clear_source_windows_detail ()
127 for (tui_source_window_base
*win
: tui_source_windows ())
128 win
->clear_detail ();
132 /* Add a window to the list of source windows. Usually there is only
133 one source window (either source or disassembly), but both can be
134 displayed at the same time. */
136 tui_add_to_source_windows (struct tui_source_window_base
*win_info
)
138 if (source_windows
.size () < 2)
139 source_windows
.push_back (win_info
);
142 /* See tui-data.h. */
145 tui_source_window_base::clear_detail ()
148 start_line_or_addr
.loa
= LOA_ADDRESS
;
149 start_line_or_addr
.u
.addr
= 0;
150 horizontal_offset
= 0;
153 /* See tui-data.h. */
156 tui_cmd_window::clear_detail ()
158 wmove (handle
, 0, 0);
161 /* See tui-data.h. */
164 tui_data_window::clear_detail ()
166 regs_content
.clear ();
167 regs_column_count
= 1;
168 display_regs
= false;
171 /* Accessor for the locator win info. Answers a pointer to the static
172 locator win info struct. */
173 struct tui_locator_window
*
174 tui_locator_win_info_ptr (void)
180 /* Accessor for the term_height. */
182 tui_term_height (void)
188 /* Mutator for the term height. */
190 tui_set_term_height_to (int h
)
196 /* Accessor for the term_width. */
198 tui_term_width (void)
204 /* Mutator for the term_width. */
206 tui_set_term_width_to (int w
)
212 /* Accessor for the current layout. */
214 tui_current_layout (void)
216 return current_layout
;
220 /* Mutator for the current layout. */
222 tui_set_current_layout_to (enum tui_layout_type new_layout
)
224 current_layout
= new_layout
;
228 /*****************************
229 ** OTHER PUBLIC FUNCTIONS
230 *****************************/
233 /* Answer the next window in the list, cycling back to the top if
235 struct tui_win_info
*
236 tui_next_win (struct tui_win_info
*cur_win
)
238 int type
= cur_win
->type
;
239 struct tui_win_info
*next_win
= NULL
;
241 if (cur_win
->type
== CMD_WIN
)
244 type
= cur_win
->type
+ 1;
245 while (type
!= cur_win
->type
&& (next_win
== NULL
))
247 if (tui_win_list
[type
]
248 && tui_win_list
[type
]->is_visible
)
249 next_win
= tui_win_list
[type
];
263 /* Answer the prev window in the list, cycling back to the bottom if
265 struct tui_win_info
*
266 tui_prev_win (struct tui_win_info
*cur_win
)
268 int type
= cur_win
->type
;
269 struct tui_win_info
*prev
= NULL
;
271 if (cur_win
->type
== SRC_WIN
)
274 type
= cur_win
->type
- 1;
275 while (type
!= cur_win
->type
&& (prev
== NULL
))
277 if (tui_win_list
[type
]
278 && tui_win_list
[type
]->is_visible
)
279 prev
= tui_win_list
[type
];
293 /* Answer the window represented by name. */
294 struct tui_win_info
*
295 tui_partial_win_by_name (const char *name
)
299 for (tui_win_info
*item
: all_tui_windows ())
301 const char *cur_name
= item
->name ();
303 if (strlen (name
) <= strlen (cur_name
)
304 && startswith (cur_name
, name
))
314 tui_initialize_static_data ()
316 tui_gen_win_info
*win
= tui_locator_win_info_ptr ();
321 win
->viewport_height
=
322 win
->last_visible_line
= 0;
324 win
->is_visible
= false;
329 tui_win_info::tui_win_info (enum tui_win_type type
)
330 : tui_gen_win_info (type
)
334 tui_source_window_base::tui_source_window_base (enum tui_win_type type
)
335 : tui_win_info (type
)
337 gdb_assert (type
== SRC_WIN
|| type
== DISASSEM_WIN
);
338 start_line_or_addr
.loa
= LOA_ADDRESS
;
339 start_line_or_addr
.u
.addr
= 0;
342 tui_gen_win_info::~tui_gen_win_info ()
344 tui_delete_win (handle
);
348 tui_source_window_base::~tui_source_window_base ()
351 delete execution_info
;
354 /**********************************
355 ** LOCAL STATIC FUNCTIONS **
356 **********************************/
359 tui_data_item_window::~tui_data_item_window ()