aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui/tui-windata.c
blob: 722d0a5e26e29bf04e3a41da97f103cfee79c764 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* Data/register window display.

   Copyright (C) 1998-2019 Free Software Foundation, Inc.

   Contributed by Hewlett-Packard Company.

   This file is part of GDB.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#include "defs.h"
#include "tui/tui.h"
#include "tui/tui-data.h"
#include "tui/tui-wingeneral.h"
#include "tui/tui-regs.h"
#include "tui/tui-windata.h"
#include "gdb_curses.h"


/*****************************************
** STATIC LOCAL FUNCTIONS FORWARD DECLS    **
******************************************/



/*****************************************
** PUBLIC FUNCTIONS                        **
******************************************/


/* Answer the index first element displayed.  If none are displayed,
   then return (-1).  */
int
tui_data_window::first_data_item_displayed ()
{
  for (int i = 0; i < regs_content.size (); i++)
    {
      struct tui_gen_win_info *data_item_win;

      data_item_win = regs_content[i].get ();
      if (data_item_win->handle != NULL && data_item_win->is_visible)
	return i;
    }

  return -1;
}


/* Function to delete all the item windows in the data window.  This
   is usually done when the data window is scrolled.  */
void
tui_delete_data_content_windows (void)
{
  for (auto &&win : TUI_DATA_WIN->regs_content)
    {
      tui_delete_win (win->handle);
      win->handle = NULL;
      win->is_visible = false;
    }
}


void
tui_erase_data_content (const char *prompt)
{
  werase (TUI_DATA_WIN->handle);
  tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
  if (prompt != NULL)
    {
      int half_width = (TUI_DATA_WIN->width - 2) / 2;
      int x_pos;

      if (strlen (prompt) >= half_width)
	x_pos = 1;
      else
	x_pos = half_width - strlen (prompt);
      mvwaddstr (TUI_DATA_WIN->handle,
		 (TUI_DATA_WIN->height / 2),
		 x_pos,
		 (char *) prompt);
    }
  wrefresh (TUI_DATA_WIN->handle);
}


/* This function displays the data that is in the data window's
   content.  It does not set the content.  */
void
tui_display_all_data (void)
{
  if (TUI_DATA_WIN->regs_content.empty ())
    tui_erase_data_content (NO_DATA_STRING);
  else
    {
      tui_erase_data_content (NULL);
      tui_delete_data_content_windows ();
      tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
      tui_display_registers_from (0);
    }
}


/* Function to redisplay the contents of the data window.  */
void
tui_data_window::refresh_all ()
{
  tui_erase_data_content (NULL);
  if (!regs_content.empty ())
    {
      int first_element = first_data_item_displayed ();

      if (first_element >= 0)	/* Re-use existing windows.  */
	{
	  int first_line = (-1);

	  if (first_element < regs_content.size ())
	    first_line = line_from_reg_element_no (first_element);

	  if (first_line >= 0)
	    {
	      tui_erase_data_content (NULL);
	      tui_display_registers_from_line (first_line);
	    }
	}
    }
}


/* Scroll the data window vertically forward or backward.  */
void
tui_data_window::do_scroll_vertical (int num_to_scroll)
{
  int first_element_no;
  int first_line = (-1);

  first_element_no = first_data_item_displayed ();
  if (first_element_no < regs_content.size ())
    first_line = line_from_reg_element_no (first_element_no);
  else
    { /* Calculate the first line from the element number which is in
        the general data content.  */
    }

  if (first_line >= 0)
    {
      first_line += num_to_scroll;
      tui_erase_data_content (NULL);
      tui_delete_data_content_windows ();
      tui_display_registers_from_line (first_line);
    }
}


/*****************************************
** STATIC LOCAL FUNCTIONS               **
******************************************/