aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui/tui-windata.c
blob: 47d777a16a3c4f85e5970e5183559882697e7ce8 (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
/* 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;
}

/* See tui-data.h.  */

void
tui_data_window::delete_data_content_windows ()
{
  for (auto &&win : regs_content)
    {
      tui_delete_win (win->handle);
      win->handle = NULL;
      win->is_visible = false;
    }
}


void
tui_data_window::erase_data_content (const char *prompt)
{
  werase (handle);
  tui_check_and_display_highlight_if_needed (this);
  if (prompt != NULL)
    {
      int half_width = (width - 2) / 2;
      int x_pos;

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

/* See tui-data.h.  */

void
tui_data_window::display_all_data ()
{
  if (regs_content.empty ())
    erase_data_content (NO_DATA_STRING);
  else
    {
      erase_data_content (NULL);
      delete_data_content_windows ();
      tui_check_and_display_highlight_if_needed (this);
      tui_display_registers_from (0);
    }
}


/* Function to redisplay the contents of the data window.  */
void
tui_data_window::refresh_all ()
{
  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)
	    {
	      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;
      erase_data_content (NULL);
      delete_data_content_windows ();
      tui_display_registers_from_line (first_line);
    }
}


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