Move content_in_use to tui_source_window class
[deliverable/binutils-gdb.git] / gdb / tui / tui-data.c
CommitLineData
f377b406 1/* TUI data manipulation routines.
f33c6cbf 2
42a4f53d 3 Copyright (C) 1998-2019 Free Software Foundation, Inc.
f33c6cbf 4
f377b406
SC
5 Contributed by Hewlett-Packard Company.
6
7 This file is part of GDB.
8
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
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
f377b406
SC
12 (at your option) any later version.
13
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.
18
19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 21
96ec9981
DJ
22#include "defs.h"
23#include "symtab.h"
d7b2e967
AC
24#include "tui/tui.h"
25#include "tui/tui-data.h"
26#include "tui/tui-wingeneral.h"
6a83354a 27#include "gdb_curses.h"
4e8f7a8b 28
c906108c
SS
29/****************************
30** GLOBAL DECLARATIONS
31****************************/
7fa29be9 32struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS];
c906108c 33
c906108c
SS
34/***************************
35** Private data
36****************************/
6ba8e26f
AC
37static enum tui_layout_type current_layout = UNDEFINED_LAYOUT;
38static int term_height, term_width;
3add462f 39static struct tui_locator_window _locator;
ad54d15b 40static std::vector<tui_source_window_base *> source_windows;
e65b5245 41static struct tui_win_info *win_with_focus = NULL;
08ef48c5
MS
42static struct tui_layout_def layout_def = {
43 SRC_WIN, /* DISPLAY_MODE */
bd7db367 44};
08ef48c5 45
6ba8e26f 46static int win_resized = FALSE;
c906108c
SS
47
48
c906108c
SS
49/*********************************
50** PUBLIC FUNCTIONS
51**********************************/
52
6d012f14 53int
6658b1bf 54tui_win_is_auxiliary (enum tui_win_type win_type)
6d012f14
AC
55{
56 return (win_type > MAX_MAJOR_WINDOWS);
57}
58
c906108c
SS
59/******************************************
60** ACCESSORS & MUTATORS FOR PRIVATE DATA
61******************************************/
62
1cc6d956 63/* Answer a whether the terminal window has been resized or not. */
c906108c 64int
dd1abb8c 65tui_win_resized (void)
c906108c 66{
6ba8e26f 67 return win_resized;
dd1abb8c 68}
c906108c
SS
69
70
1cc6d956 71/* Set a whether the terminal window has been resized or not. */
c906108c 72void
dd1abb8c 73tui_set_win_resized_to (int resized)
c906108c 74{
6ba8e26f 75 win_resized = resized;
dd1abb8c 76}
c906108c
SS
77
78
1cc6d956 79/* Answer a pointer to the current layout definition. */
2a8854a7 80struct tui_layout_def *
dd1abb8c 81tui_layout_def (void)
c906108c 82{
6ba8e26f 83 return &layout_def;
dd1abb8c 84}
c906108c
SS
85
86
1cc6d956 87/* Answer the window with the logical focus. */
2a8854a7 88struct tui_win_info *
dd1abb8c 89tui_win_with_focus (void)
c906108c 90{
6ba8e26f 91 return win_with_focus;
dd1abb8c 92}
c906108c
SS
93
94
1cc6d956 95/* Set the window that has the logical focus. */
c906108c 96void
5b6fe301 97tui_set_win_with_focus (struct tui_win_info *win_info)
c906108c 98{
6ba8e26f 99 win_with_focus = win_info;
dd1abb8c 100}
c906108c
SS
101
102
6ba8e26f
AC
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. */
ad54d15b 106std::vector<tui_source_window_base *> &
b4eb2452 107tui_source_windows ()
c906108c 108{
b4eb2452 109 return source_windows;
dd1abb8c 110}
c906108c
SS
111
112
dd1abb8c
AC
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
115 the same time. */
c906108c 116void
b4eb2452 117tui_clear_source_windows ()
c906108c 118{
b4eb2452 119 source_windows.clear ();
dd1abb8c 120}
c906108c
SS
121
122
ae2b5380 123/* Clear the pertinent detail in the source windows. */
c906108c 124void
b4eb2452 125tui_clear_source_windows_detail ()
c906108c 126{
ad54d15b 127 for (tui_source_window_base *win : tui_source_windows ())
7778b912 128 win->clear_detail ();
dd1abb8c 129}
c906108c
SS
130
131
dd1abb8c
AC
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. */
c906108c 135void
ad54d15b 136tui_add_to_source_windows (struct tui_source_window_base *win_info)
c906108c 137{
b4eb2452
TT
138 if (source_windows.size () < 2)
139 source_windows.push_back (win_info);
dd1abb8c 140}
c906108c 141
8761a91b
TT
142/* See tui-data.h. */
143
144void
5cf82909 145tui_source_window_base::clear_detail ()
8761a91b 146{
e6e41501
TT
147 gdbarch = NULL;
148 start_line_or_addr.loa = LOA_ADDRESS;
149 start_line_or_addr.u.addr = 0;
150 horizontal_offset = 0;
8761a91b
TT
151}
152
153/* See tui-data.h. */
154
155void
156tui_cmd_window::clear_detail ()
157{
cb2ce893 158 wmove (handle, 0, 0);
8761a91b
TT
159}
160
161/* See tui-data.h. */
162
163void
164tui_data_window::clear_detail ()
165{
21e1c91e 166 regs_content.clear ();
238eb706 167 regs_column_count = 1;
ceb13a13 168 display_regs = false;
8761a91b 169}
c906108c 170
dd1abb8c
AC
171/* Accessor for the locator win info. Answers a pointer to the static
172 locator win info struct. */
3add462f 173struct tui_locator_window *
dd1abb8c 174tui_locator_win_info_ptr (void)
c906108c
SS
175{
176 return &_locator;
2a8854a7 177}
c906108c
SS
178
179
6ba8e26f 180/* Accessor for the term_height. */
c906108c 181int
dd1abb8c 182tui_term_height (void)
c906108c 183{
6ba8e26f 184 return term_height;
dd1abb8c 185}
c906108c
SS
186
187
1cc6d956 188/* Mutator for the term height. */
c906108c 189void
dd1abb8c 190tui_set_term_height_to (int h)
c906108c 191{
6ba8e26f 192 term_height = h;
dd1abb8c 193}
c906108c
SS
194
195
1cc6d956 196/* Accessor for the term_width. */
c906108c 197int
dd1abb8c 198tui_term_width (void)
c906108c 199{
6ba8e26f 200 return term_width;
dd1abb8c 201}
c906108c
SS
202
203
6ba8e26f 204/* Mutator for the term_width. */
c906108c 205void
dd1abb8c 206tui_set_term_width_to (int w)
c906108c 207{
6ba8e26f 208 term_width = w;
dd1abb8c 209}
c906108c
SS
210
211
1cc6d956 212/* Accessor for the current layout. */
2a8854a7 213enum tui_layout_type
dd1abb8c 214tui_current_layout (void)
c906108c 215{
6ba8e26f 216 return current_layout;
dd1abb8c 217}
c906108c
SS
218
219
dd1abb8c 220/* Mutator for the current layout. */
c906108c 221void
6ba8e26f 222tui_set_current_layout_to (enum tui_layout_type new_layout)
c906108c 223{
6ba8e26f 224 current_layout = new_layout;
dd1abb8c 225}
c906108c
SS
226
227
c906108c
SS
228/*****************************
229** OTHER PUBLIC FUNCTIONS
230*****************************/
231
232
dd1abb8c
AC
233/* Answer the next window in the list, cycling back to the top if
234 necessary. */
2a8854a7 235struct tui_win_info *
5b6fe301 236tui_next_win (struct tui_win_info *cur_win)
c906108c 237{
cb2ce893 238 int type = cur_win->type;
e65b5245 239 struct tui_win_info *next_win = NULL;
c906108c 240
cb2ce893 241 if (cur_win->type == CMD_WIN)
c906108c
SS
242 type = SRC_WIN;
243 else
cb2ce893
TT
244 type = cur_win->type + 1;
245 while (type != cur_win->type && (next_win == NULL))
c906108c 246 {
e5908723 247 if (tui_win_list[type]
cb2ce893 248 && tui_win_list[type]->is_visible)
6ba8e26f 249 next_win = tui_win_list[type];
c906108c
SS
250 else
251 {
252 if (type == CMD_WIN)
253 type = SRC_WIN;
254 else
255 type++;
256 }
257 }
258
6ba8e26f
AC
259 return next_win;
260}
c906108c
SS
261
262
dd1abb8c
AC
263/* Answer the prev window in the list, cycling back to the bottom if
264 necessary. */
2a8854a7 265struct tui_win_info *
5b6fe301 266tui_prev_win (struct tui_win_info *cur_win)
c906108c 267{
cb2ce893 268 int type = cur_win->type;
e65b5245 269 struct tui_win_info *prev = NULL;
c906108c 270
cb2ce893 271 if (cur_win->type == SRC_WIN)
c906108c
SS
272 type = CMD_WIN;
273 else
cb2ce893
TT
274 type = cur_win->type - 1;
275 while (type != cur_win->type && (prev == NULL))
c906108c 276 {
37715c4c 277 if (tui_win_list[type]
cb2ce893 278 && tui_win_list[type]->is_visible)
6d012f14 279 prev = tui_win_list[type];
c906108c
SS
280 else
281 {
282 if (type == SRC_WIN)
283 type = CMD_WIN;
284 else
285 type--;
286 }
287 }
288
289 return prev;
cb50eddd 290}
c906108c
SS
291
292
1cc6d956 293/* Answer the window represented by name. */
2a8854a7 294struct tui_win_info *
a121b7c1 295tui_partial_win_by_name (const char *name)
c906108c 296{
63a33118 297 if (name != NULL)
c906108c 298 {
1ce3e844 299 for (tui_win_info *item : all_tui_windows ())
c906108c 300 {
1ce3e844
TT
301 const char *cur_name = item->name ();
302
303 if (strlen (name) <= strlen (cur_name)
304 && startswith (cur_name, name))
305 return item;
c906108c
SS
306 }
307 }
308
1ce3e844 309 return NULL;
6ba8e26f 310}
c906108c
SS
311
312
c906108c 313void
31ca4723 314tui_initialize_static_data ()
c906108c 315{
31ca4723 316 tui_gen_win_info *win = tui_locator_win_info_ptr ();
c906108c
SS
317 win->width =
318 win->height =
319 win->origin.x =
320 win->origin.y =
6d012f14 321 win->viewport_height =
6d012f14 322 win->last_visible_line = 0;
e65b5245 323 win->handle = NULL;
56122977 324 win->is_visible = false;
bc6b7f04
SC
325 win->title = 0;
326}
c906108c
SS
327
328
33b906ab 329tui_win_info::tui_win_info (enum tui_win_type type)
cb2ce893 330 : tui_gen_win_info (type)
c906108c 331{
6ba8e26f 332}
c906108c 333
5cf82909 334tui_source_window_base::tui_source_window_base (enum tui_win_type type)
33b906ab
TT
335 : tui_win_info (type)
336{
337 gdb_assert (type == SRC_WIN || type == DISASSEM_WIN);
e6e41501
TT
338 start_line_or_addr.loa = LOA_ADDRESS;
339 start_line_or_addr.u.addr = 0;
33b906ab
TT
340}
341
f936bca2 342tui_gen_win_info::~tui_gen_win_info ()
c906108c 343{
c2fc64f5 344 tui_delete_win (handle);
f936bca2
TT
345 xfree (title);
346}
347
348tui_source_window_base::~tui_source_window_base ()
349{
350 xfree (fullname);
351 delete execution_info;
ee1d42d6 352}
c906108c 353
c906108c
SS
354/**********************************
355** LOCAL STATIC FUNCTIONS **
356**********************************/
357
358
41bcff7f
TT
359tui_data_item_window::~tui_data_item_window ()
360{
41bcff7f
TT
361 xfree (value);
362 xfree (content);
363}
This page took 2.934711 seconds and 4 git commands to generate.