Simplify tui_show_disassem
[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"
5104fe36 27#include "tui/tui-winsource.h"
6a83354a 28#include "gdb_curses.h"
4e8f7a8b 29
c906108c
SS
30/****************************
31** GLOBAL DECLARATIONS
32****************************/
7fa29be9 33struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS];
c906108c 34
c906108c
SS
35/***************************
36** Private data
37****************************/
6ba8e26f 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 42
6ba8e26f 43static int win_resized = FALSE;
c906108c
SS
44
45
c906108c
SS
46/*********************************
47** PUBLIC FUNCTIONS
48**********************************/
49
6d012f14 50int
6658b1bf 51tui_win_is_auxiliary (enum tui_win_type win_type)
6d012f14
AC
52{
53 return (win_type > MAX_MAJOR_WINDOWS);
54}
55
c906108c
SS
56/******************************************
57** ACCESSORS & MUTATORS FOR PRIVATE DATA
58******************************************/
59
1cc6d956 60/* Answer a whether the terminal window has been resized or not. */
c906108c 61int
dd1abb8c 62tui_win_resized (void)
c906108c 63{
6ba8e26f 64 return win_resized;
dd1abb8c 65}
c906108c
SS
66
67
1cc6d956 68/* Set a whether the terminal window has been resized or not. */
c906108c 69void
dd1abb8c 70tui_set_win_resized_to (int resized)
c906108c 71{
6ba8e26f 72 win_resized = resized;
dd1abb8c 73}
c906108c
SS
74
75
1cc6d956 76/* Answer the window with the logical focus. */
2a8854a7 77struct tui_win_info *
dd1abb8c 78tui_win_with_focus (void)
c906108c 79{
6ba8e26f 80 return win_with_focus;
dd1abb8c 81}
c906108c
SS
82
83
1cc6d956 84/* Set the window that has the logical focus. */
c906108c 85void
5b6fe301 86tui_set_win_with_focus (struct tui_win_info *win_info)
c906108c 87{
6ba8e26f 88 win_with_focus = win_info;
dd1abb8c 89}
c906108c
SS
90
91
6ba8e26f
AC
92/* Accessor for the current source window. Usually there is only one
93 source window (either source or disassembly), but both can be
94 displayed at the same time. */
ad54d15b 95std::vector<tui_source_window_base *> &
b4eb2452 96tui_source_windows ()
c906108c 97{
b4eb2452 98 return source_windows;
dd1abb8c 99}
c906108c
SS
100
101
dd1abb8c
AC
102/* Clear the list of source windows. Usually there is only one source
103 window (either source or disassembly), but both can be displayed at
104 the same time. */
c906108c 105void
b4eb2452 106tui_clear_source_windows ()
c906108c 107{
b4eb2452 108 source_windows.clear ();
dd1abb8c 109}
c906108c
SS
110
111
ae2b5380 112/* Clear the pertinent detail in the source windows. */
c906108c 113void
b4eb2452 114tui_clear_source_windows_detail ()
c906108c 115{
ad54d15b 116 for (tui_source_window_base *win : tui_source_windows ())
7778b912 117 win->clear_detail ();
dd1abb8c 118}
c906108c
SS
119
120
dd1abb8c
AC
121/* Add a window to the list of source windows. Usually there is only
122 one source window (either source or disassembly), but both can be
123 displayed at the same time. */
c906108c 124void
ad54d15b 125tui_add_to_source_windows (struct tui_source_window_base *win_info)
c906108c 126{
b4eb2452
TT
127 if (source_windows.size () < 2)
128 source_windows.push_back (win_info);
dd1abb8c 129}
c906108c 130
dd1abb8c
AC
131/* Accessor for the locator win info. Answers a pointer to the static
132 locator win info struct. */
3add462f 133struct tui_locator_window *
dd1abb8c 134tui_locator_win_info_ptr (void)
c906108c
SS
135{
136 return &_locator;
2a8854a7 137}
c906108c
SS
138
139
6ba8e26f 140/* Accessor for the term_height. */
c906108c 141int
dd1abb8c 142tui_term_height (void)
c906108c 143{
6ba8e26f 144 return term_height;
dd1abb8c 145}
c906108c
SS
146
147
1cc6d956 148/* Mutator for the term height. */
c906108c 149void
dd1abb8c 150tui_set_term_height_to (int h)
c906108c 151{
6ba8e26f 152 term_height = h;
dd1abb8c 153}
c906108c
SS
154
155
1cc6d956 156/* Accessor for the term_width. */
c906108c 157int
dd1abb8c 158tui_term_width (void)
c906108c 159{
6ba8e26f 160 return term_width;
dd1abb8c 161}
c906108c
SS
162
163
6ba8e26f 164/* Mutator for the term_width. */
c906108c 165void
dd1abb8c 166tui_set_term_width_to (int w)
c906108c 167{
6ba8e26f 168 term_width = w;
dd1abb8c 169}
c906108c
SS
170
171
c906108c
SS
172/*****************************
173** OTHER PUBLIC FUNCTIONS
174*****************************/
175
176
dd1abb8c
AC
177/* Answer the next window in the list, cycling back to the top if
178 necessary. */
2a8854a7 179struct tui_win_info *
5b6fe301 180tui_next_win (struct tui_win_info *cur_win)
c906108c 181{
cb2ce893 182 int type = cur_win->type;
e65b5245 183 struct tui_win_info *next_win = NULL;
c906108c 184
cb2ce893 185 if (cur_win->type == CMD_WIN)
c906108c
SS
186 type = SRC_WIN;
187 else
cb2ce893
TT
188 type = cur_win->type + 1;
189 while (type != cur_win->type && (next_win == NULL))
c906108c 190 {
e5908723 191 if (tui_win_list[type]
cb2ce893 192 && tui_win_list[type]->is_visible)
6ba8e26f 193 next_win = tui_win_list[type];
c906108c
SS
194 else
195 {
196 if (type == CMD_WIN)
197 type = SRC_WIN;
198 else
199 type++;
200 }
201 }
202
6ba8e26f
AC
203 return next_win;
204}
c906108c
SS
205
206
dd1abb8c
AC
207/* Answer the prev window in the list, cycling back to the bottom if
208 necessary. */
2a8854a7 209struct tui_win_info *
5b6fe301 210tui_prev_win (struct tui_win_info *cur_win)
c906108c 211{
cb2ce893 212 int type = cur_win->type;
e65b5245 213 struct tui_win_info *prev = NULL;
c906108c 214
cb2ce893 215 if (cur_win->type == SRC_WIN)
c906108c
SS
216 type = CMD_WIN;
217 else
cb2ce893
TT
218 type = cur_win->type - 1;
219 while (type != cur_win->type && (prev == NULL))
c906108c 220 {
37715c4c 221 if (tui_win_list[type]
cb2ce893 222 && tui_win_list[type]->is_visible)
6d012f14 223 prev = tui_win_list[type];
c906108c
SS
224 else
225 {
226 if (type == SRC_WIN)
227 type = CMD_WIN;
228 else
229 type--;
230 }
231 }
232
233 return prev;
cb50eddd 234}
c906108c
SS
235
236
1cc6d956 237/* Answer the window represented by name. */
2a8854a7 238struct tui_win_info *
a121b7c1 239tui_partial_win_by_name (const char *name)
c906108c 240{
63a33118 241 if (name != NULL)
c906108c 242 {
1ce3e844 243 for (tui_win_info *item : all_tui_windows ())
c906108c 244 {
1ce3e844
TT
245 const char *cur_name = item->name ();
246
247 if (strlen (name) <= strlen (cur_name)
248 && startswith (cur_name, name))
249 return item;
c906108c
SS
250 }
251 }
252
1ce3e844 253 return NULL;
6ba8e26f 254}
c906108c
SS
255
256
c906108c 257void
31ca4723 258tui_initialize_static_data ()
c906108c 259{
31ca4723 260 tui_gen_win_info *win = tui_locator_win_info_ptr ();
c906108c
SS
261 win->width =
262 win->height =
263 win->origin.x =
264 win->origin.y =
6d012f14 265 win->viewport_height =
6d012f14 266 win->last_visible_line = 0;
e65b5245 267 win->handle = NULL;
56122977 268 win->is_visible = false;
bc6b7f04
SC
269 win->title = 0;
270}
c906108c
SS
271
272
33b906ab 273tui_win_info::tui_win_info (enum tui_win_type type)
cb2ce893 274 : tui_gen_win_info (type)
c906108c 275{
6ba8e26f 276}
c906108c 277
f936bca2 278tui_gen_win_info::~tui_gen_win_info ()
c906108c 279{
c2fc64f5 280 tui_delete_win (handle);
f936bca2
TT
281 xfree (title);
282}
This page took 1.973988 seconds and 4 git commands to generate.