1 /* TUI data manipulation routines.
2 
3    Copyright (C) 1998-2020 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
tui_win_resized()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
tui_set_win_resized_to(bool resized)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 *
tui_win_with_focus(void)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
tui_set_win_focus_to(struct tui_win_info * win_info)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
tui_term_height(void)78 tui_term_height (void)
79 {
80   return term_height;
81 }
82 
83 
84 /* Mutator for the term height.  */
85 void
tui_set_term_height_to(int h)86 tui_set_term_height_to (int h)
87 {
88   term_height = h;
89 }
90 
91 
92 /* Accessor for the term_width.  */
93 int
tui_term_width(void)94 tui_term_width (void)
95 {
96   return term_width;
97 }
98 
99 
100 /* Mutator for the term_width.  */
101 void
tui_set_term_width_to(int w)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 *
tui_next_win(struct tui_win_info * cur_win)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   ++iter;
117   if (iter == tui_windows.end ())
118     return tui_windows[0];
119   return *iter;
120 }
121 
122 
123 /* Answer the prev window in the list, cycling back to the bottom if
124    necessary.  */
125 struct tui_win_info *
tui_prev_win(struct tui_win_info * cur_win)126 tui_prev_win (struct tui_win_info *cur_win)
127 {
128   auto iter = std::find (tui_windows.begin (), tui_windows.end (), cur_win);
129   gdb_assert (iter != tui_windows.end ());
130 
131   if (iter == tui_windows.begin ())
132     return tui_windows.back ();
133   --iter;
134   return *iter;
135 }
136 
137 
138 void
rerender()139 tui_win_info::rerender ()
140 {
141   check_and_display_highlight_if_needed ();
142 }
143