Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / tui / tui-data.c
1 /* TUI data manipulation routines.
2
3 Copyright (C) 1998-2022 Free Software Foundation, Inc.
4
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
11 the Free Software Foundation; either version 3 of the License, or
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
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 #include "defs.h"
23 #include "symtab.h"
24 #include "tui/tui.h"
25 #include "tui/tui-data.h"
26 #include "tui/tui-win.h"
27 #include "tui/tui-wingeneral.h"
28 #include "tui/tui-winsource.h"
29 #include "gdb_curses.h"
30 #include <algorithm>
31
32 struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS];
33
34 static int term_height, term_width;
35 static struct tui_win_info *win_with_focus = NULL;
36
37 static bool win_resized = false;
38
39 /* Answer a whether the terminal window has been resized or not. */
40 bool
41 tui_win_resized ()
42 {
43 return win_resized;
44 }
45
46
47 /* Set a whether the terminal window has been resized or not. */
48 void
49 tui_set_win_resized_to (bool resized)
50 {
51 win_resized = resized;
52 }
53
54
55 /* Answer the window with the logical focus. */
56 struct tui_win_info *
57 tui_win_with_focus (void)
58 {
59 return win_with_focus;
60 }
61
62
63 /* Set the logical focus to win_info. */
64 void
65 tui_set_win_focus_to (struct tui_win_info *win_info)
66 {
67 if (win_info != NULL)
68 {
69 tui_unhighlight_win (win_with_focus);
70 win_with_focus = win_info;
71 tui_highlight_win (win_info);
72 }
73 }
74
75
76 /* Accessor for the term_height. */
77 int
78 tui_term_height (void)
79 {
80 return term_height;
81 }
82
83
84 /* Mutator for the term height. */
85 void
86 tui_set_term_height_to (int h)
87 {
88 term_height = h;
89 }
90
91
92 /* Accessor for the term_width. */
93 int
94 tui_term_width (void)
95 {
96 return term_width;
97 }
98
99
100 /* Mutator for the term_width. */
101 void
102 tui_set_term_width_to (int w)
103 {
104 term_width = w;
105 }
106
107
108 /* Answer the next window in the list, cycling back to the top if
109 necessary. */
110 struct tui_win_info *
111 tui_next_win (struct tui_win_info *cur_win)
112 {
113 auto iter = std::find (tui_windows.begin (), tui_windows.end (), cur_win);
114 gdb_assert (iter != tui_windows.end ());
115
116 gdb_assert (cur_win->can_focus ());
117 /* This won't loop forever since we can't have just an un-focusable
118 window. */
119 while (true)
120 {
121 ++iter;
122 if (iter == tui_windows.end ())
123 iter = tui_windows.begin ();
124 if ((*iter)->can_focus ())
125 break;
126 }
127
128 return *iter;
129 }
130
131
132 /* Answer the prev window in the list, cycling back to the bottom if
133 necessary. */
134 struct tui_win_info *
135 tui_prev_win (struct tui_win_info *cur_win)
136 {
137 auto iter = std::find (tui_windows.rbegin (), tui_windows.rend (), cur_win);
138 gdb_assert (iter != tui_windows.rend ());
139
140 gdb_assert (cur_win->can_focus ());
141 /* This won't loop forever since we can't have just an un-focusable
142 window. */
143 while (true)
144 {
145 ++iter;
146 if (iter == tui_windows.rend ())
147 iter = tui_windows.rbegin ();
148 if ((*iter)->can_focus ())
149 break;
150 }
151
152 return *iter;
153 }
154
155
156 void
157 tui_win_info::rerender ()
158 {
159 check_and_display_highlight_if_needed ();
160 }
This page took 0.032255 seconds and 4 git commands to generate.