Change tui_make_window to be a method
[platform/upstream/binutils.git] / gdb / tui / tui-data.c
1 /* TUI data manipulation routines.
2
3    Copyright (C) 1998-2019 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-wingeneral.h"
27 #include "tui/tui-winsource.h"
28 #include "gdb_curses.h"
29
30 /****************************
31 ** GLOBAL DECLARATIONS
32 ****************************/
33 struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS];
34
35 /***************************
36 ** Private data
37 ****************************/
38 static int term_height, term_width;
39 static struct tui_win_info *win_with_focus = NULL;
40
41 static int win_resized = FALSE;
42
43
44 /*********************************
45 ** PUBLIC FUNCTIONS
46 **********************************/
47
48 int
49 tui_win_is_auxiliary (enum tui_win_type win_type)
50 {
51   return (win_type > MAX_MAJOR_WINDOWS);
52 }
53
54 /******************************************
55 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
56 ******************************************/
57
58 /* Answer a whether the terminal window has been resized or not.  */
59 int
60 tui_win_resized (void)
61 {
62   return win_resized;
63 }
64
65
66 /* Set a whether the terminal window has been resized or not.  */
67 void
68 tui_set_win_resized_to (int resized)
69 {
70   win_resized = resized;
71 }
72
73
74 /* Answer the window with the logical focus.  */
75 struct tui_win_info *
76 tui_win_with_focus (void)
77 {
78   return win_with_focus;
79 }
80
81
82 /* Set the window that has the logical focus.  */
83 void
84 tui_set_win_with_focus (struct tui_win_info *win_info)
85 {
86   win_with_focus = win_info;
87 }
88
89
90 /* Clear the pertinent detail in the source windows.  */
91 void
92 tui_clear_source_windows_detail ()
93 {
94   for (tui_source_window_base *win : tui_source_windows ())
95     win->clear_detail ();
96 }
97
98
99 /* Accessor for the term_height.  */
100 int
101 tui_term_height (void)
102 {
103   return term_height;
104 }
105
106
107 /* Mutator for the term height.  */
108 void
109 tui_set_term_height_to (int h)
110 {
111   term_height = h;
112 }
113
114
115 /* Accessor for the term_width.  */
116 int
117 tui_term_width (void)
118 {
119   return term_width;
120 }
121
122
123 /* Mutator for the term_width.  */
124 void
125 tui_set_term_width_to (int w)
126 {
127   term_width = w;
128 }
129
130
131 /*****************************
132 ** OTHER PUBLIC FUNCTIONS
133 *****************************/
134
135
136 /* Answer the next window in the list, cycling back to the top if
137    necessary.  */
138 struct tui_win_info *
139 tui_next_win (struct tui_win_info *cur_win)
140 {
141   int type = cur_win->type;
142   struct tui_win_info *next_win = NULL;
143
144   if (cur_win->type == CMD_WIN)
145     type = SRC_WIN;
146   else
147     type = cur_win->type + 1;
148   while (type != cur_win->type && (next_win == NULL))
149     {
150       if (tui_win_list[type]
151           && tui_win_list[type]->is_visible ())
152         next_win = tui_win_list[type];
153       else
154         {
155           if (type == CMD_WIN)
156             type = SRC_WIN;
157           else
158             type++;
159         }
160     }
161
162   return next_win;
163 }
164
165
166 /* Answer the prev window in the list, cycling back to the bottom if
167    necessary.  */
168 struct tui_win_info *
169 tui_prev_win (struct tui_win_info *cur_win)
170 {
171   int type = cur_win->type;
172   struct tui_win_info *prev = NULL;
173
174   if (cur_win->type == SRC_WIN)
175     type = CMD_WIN;
176   else
177     type = cur_win->type - 1;
178   while (type != cur_win->type && (prev == NULL))
179     {
180       if (tui_win_list[type]
181           && tui_win_list[type]->is_visible ())
182         prev = tui_win_list[type];
183       else
184         {
185           if (type == SRC_WIN)
186             type = CMD_WIN;
187           else
188             type--;
189         }
190     }
191
192   return prev;
193 }
194
195
196 /* Answer the window represented by name.  */
197 struct tui_win_info *
198 tui_partial_win_by_name (const char *name)
199 {
200   if (name != NULL)
201     {
202       for (tui_win_info *item : all_tui_windows ())
203         {
204           const char *cur_name = item->name ();
205
206           if (strlen (name) <= strlen (cur_name)
207               && startswith (cur_name, name))
208             return item;
209         }
210     }
211
212   return NULL;
213 }
214
215 /* See tui-data.h.  */
216
217 void
218 tui_delete_invisible_windows ()
219 {
220   for (int win_type = SRC_WIN; (win_type < MAX_MAJOR_WINDOWS); win_type++)
221     {
222       if (tui_win_list[win_type] != NULL
223           && !tui_win_list[win_type]->is_visible ())
224         {
225           /* This should always be made visible before a call to this
226              function.  */
227           gdb_assert (win_type != CMD_WIN);
228
229           if (win_with_focus == tui_win_list[win_type])
230             win_with_focus = nullptr;
231
232           delete tui_win_list[win_type];
233           tui_win_list[win_type] = NULL;
234         }
235     }
236 }
237
238 tui_win_info::tui_win_info (enum tui_win_type type)
239   : tui_gen_win_info (type)
240 {
241 }
242
243 tui_gen_win_info::~tui_gen_win_info ()
244 {
245   tui_delete_win (handle);
246 }
247
248 void
249 tui_win_info::rerender ()
250 {
251   check_and_display_highlight_if_needed ();
252 }