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 /* Accessor for the locator win info. Answers a pointer to the static
162 locator win info struct. */
163 struct tui_locator_window
*
164 tui_locator_win_info_ptr (void)
170 /* Accessor for the term_height. */
172 tui_term_height (void)
178 /* Mutator for the term height. */
180 tui_set_term_height_to (int h
)
186 /* Accessor for the term_width. */
188 tui_term_width (void)
194 /* Mutator for the term_width. */
196 tui_set_term_width_to (int w
)
202 /* Accessor for the current layout. */
204 tui_current_layout (void)
206 return current_layout
;
210 /* Mutator for the current layout. */
212 tui_set_current_layout_to (enum tui_layout_type new_layout
)
214 current_layout
= new_layout
;
218 /*****************************
219 ** OTHER PUBLIC FUNCTIONS
220 *****************************/
223 /* Answer the next window in the list, cycling back to the top if
225 struct tui_win_info
*
226 tui_next_win (struct tui_win_info
*cur_win
)
228 int type
= cur_win
->type
;
229 struct tui_win_info
*next_win
= NULL
;
231 if (cur_win
->type
== CMD_WIN
)
234 type
= cur_win
->type
+ 1;
235 while (type
!= cur_win
->type
&& (next_win
== NULL
))
237 if (tui_win_list
[type
]
238 && tui_win_list
[type
]->is_visible
)
239 next_win
= tui_win_list
[type
];
253 /* Answer the prev window in the list, cycling back to the bottom if
255 struct tui_win_info
*
256 tui_prev_win (struct tui_win_info
*cur_win
)
258 int type
= cur_win
->type
;
259 struct tui_win_info
*prev
= NULL
;
261 if (cur_win
->type
== SRC_WIN
)
264 type
= cur_win
->type
- 1;
265 while (type
!= cur_win
->type
&& (prev
== NULL
))
267 if (tui_win_list
[type
]
268 && tui_win_list
[type
]->is_visible
)
269 prev
= tui_win_list
[type
];
283 /* Answer the window represented by name. */
284 struct tui_win_info
*
285 tui_partial_win_by_name (const char *name
)
289 for (tui_win_info
*item
: all_tui_windows ())
291 const char *cur_name
= item
->name ();
293 if (strlen (name
) <= strlen (cur_name
)
294 && startswith (cur_name
, name
))
304 tui_initialize_static_data ()
306 tui_gen_win_info
*win
= tui_locator_win_info_ptr ();
311 win
->viewport_height
=
312 win
->last_visible_line
= 0;
314 win
->is_visible
= false;
319 tui_win_info::tui_win_info (enum tui_win_type type
)
320 : tui_gen_win_info (type
)
324 tui_source_window_base::tui_source_window_base (enum tui_win_type type
)
325 : tui_win_info (type
),
326 execution_info (new tui_exec_info_window ())
328 gdb_assert (type
== SRC_WIN
|| type
== DISASSEM_WIN
);
329 start_line_or_addr
.loa
= LOA_ADDRESS
;
330 start_line_or_addr
.u
.addr
= 0;
333 tui_gen_win_info::~tui_gen_win_info ()
335 tui_delete_win (handle
);
339 tui_source_window_base::~tui_source_window_base ()
342 delete execution_info
;
345 /**********************************
346 ** LOCAL STATIC FUNCTIONS **
347 **********************************/
350 tui_data_item_window::~tui_data_item_window ()