Don't derive tui_data_item_window from tui_gen_win_info

There's no deep reason that tui_data_item_window should derive from
tui_gen_win_info -- it currently uses a curses window to render, but
that isn't truly needed, and it adds some hacks to other parts of the
TUI.

This patch changes tui_data_item_window so that it doesn't have a base
class, and updates the register window.  This simplifies the code and
enables a subsequent cleanup.

gdb/ChangeLog
2020-07-01  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.c (tui_data_window::display_registers_from)
	(tui_data_window::display_registers_from)
	(tui_data_window::first_data_item_displayed)
	(tui_data_window::delete_data_content_windows): Update.
	(tui_data_window::refresh_window, tui_data_window::no_refresh):
	Remove.
	(tui_data_window::check_register_values): Update.
	(tui_data_item_window::rerender): Add parameters.  Update.
	(tui_data_item_window::refresh_window): Remove.
	* tui/tui-data.h (struct tui_gen_win_info) <no_refresh>: No longer
	virtual.
	* tui/tui-regs.h (struct tui_data_item_window): Don't derive from
	tui_gen_win_info.
	<refresh_window, max_height, min_height>: Remove.
	<rerender>: Add parameters.
	<x, y, visible>: New members.
	(struct tui_data_window) <refresh_window, no_refresh>: Remove.
	<m_item_width>: New member.
This commit is contained in:
Tom Tromey 2020-07-01 21:21:12 -06:00
parent 22b7b0412b
commit 7134f2eb92
4 changed files with 51 additions and 78 deletions

View File

@ -1,3 +1,24 @@
2020-07-01 Tom Tromey <tom@tromey.com>
* tui/tui-regs.c (tui_data_window::display_registers_from)
(tui_data_window::display_registers_from)
(tui_data_window::first_data_item_displayed)
(tui_data_window::delete_data_content_windows): Update.
(tui_data_window::refresh_window, tui_data_window::no_refresh):
Remove.
(tui_data_window::check_register_values): Update.
(tui_data_item_window::rerender): Add parameters. Update.
(tui_data_item_window::refresh_window): Remove.
* tui/tui-data.h (struct tui_gen_win_info) <no_refresh>: No longer
virtual.
* tui/tui-regs.h (struct tui_data_item_window): Don't derive from
tui_gen_win_info.
<refresh_window, max_height, min_height>: Remove.
<rerender>: Add parameters.
<x, y, visible>: New members.
(struct tui_data_window) <refresh_window, no_refresh>: Remove.
<m_item_width>: New member.
2020-07-01 Tom Tromey <tom@tromey.com> 2020-07-01 Tom Tromey <tom@tromey.com>
* tui/tui-regs.c (tui_data_window::show_register_group) * tui/tui-regs.c (tui_data_window::show_register_group)

View File

@ -102,7 +102,7 @@ public:
} }
/* Disable output until the next call to doupdate. */ /* Disable output until the next call to doupdate. */
virtual void no_refresh () void no_refresh ()
{ {
if (handle != nullptr) if (handle != nullptr)
wnoutrefresh (handle.get ()); wnoutrefresh (handle.get ());

View File

@ -272,8 +272,6 @@ tui_data_window::show_register_group (struct reggroup *group,
void void
tui_data_window::display_registers_from (int start_element_no) tui_data_window::display_registers_from (int start_element_no)
{ {
int j, item_win_width, cur_y;
int max_len = 0; int max_len = 0;
for (auto &&data_item_win : m_regs_content) for (auto &&data_item_win : m_regs_content)
{ {
@ -282,26 +280,28 @@ tui_data_window::display_registers_from (int start_element_no)
if (len > max_len) if (len > max_len)
max_len = len; max_len = len;
} }
item_win_width = max_len + 1; m_item_width = max_len + 1;
int i = start_element_no; int i = start_element_no;
m_regs_column_count = (width - 2) / item_win_width; m_regs_column_count = (width - 2) / m_item_width;
if (m_regs_column_count == 0) if (m_regs_column_count == 0)
m_regs_column_count = 1; m_regs_column_count = 1;
item_win_width = (width - 2) / m_regs_column_count; m_item_width = (width - 2) / m_regs_column_count;
/* Now create each data "sub" window, and write the display into /* Now create each data "sub" window, and write the display into
it. */ it. */
cur_y = 1; int cur_y = 1;
while (i < m_regs_content.size () && cur_y <= height - 2) while (i < m_regs_content.size () && cur_y <= height - 2)
{ {
for (j = 0; for (int j = 0;
j < m_regs_column_count && i < m_regs_content.size (); j < m_regs_column_count && i < m_regs_content.size ();
j++) j++)
{ {
/* Create the window if necessary. */ /* Create the window if necessary. */
m_regs_content[i].resize (1, item_win_width, m_regs_content[i].x = (m_item_width * j) + 1;
x + (item_win_width * j) + 1, y + cur_y); m_regs_content[i].y = cur_y;
m_regs_content[i].visible = true;
m_regs_content[i].rerender (handle.get (), m_item_width);
i++; /* Next register. */ i++; /* Next register. */
} }
cur_y++; /* Next row. */ cur_y++; /* Next row. */
@ -372,10 +372,7 @@ tui_data_window::first_data_item_displayed ()
{ {
for (int i = 0; i < m_regs_content.size (); i++) for (int i = 0; i < m_regs_content.size (); i++)
{ {
struct tui_gen_win_info *data_item_win; if (m_regs_content[i].visible)
data_item_win = &m_regs_content[i];
if (data_item_win->is_visible ())
return i; return i;
} }
@ -387,8 +384,8 @@ tui_data_window::first_data_item_displayed ()
void void
tui_data_window::delete_data_content_windows () tui_data_window::delete_data_content_windows ()
{ {
for (auto &&win : m_regs_content) for (auto &win : m_regs_content)
win.handle.reset (nullptr); win.visible = false;
} }
@ -451,24 +448,6 @@ tui_data_window::do_scroll_vertical (int num_to_scroll)
} }
} }
/* See tui-regs.h. */
void
tui_data_window::refresh_window ()
{
tui_gen_win_info::refresh_window ();
for (auto &&win : m_regs_content)
win.refresh_window ();
}
void
tui_data_window::no_refresh ()
{
tui_gen_win_info::no_refresh ();
for (auto &&win : m_regs_content)
win.no_refresh ();
}
/* This function check all displayed registers for changes in values, /* This function check all displayed registers for changes in values,
given a particular frame. If the values have changed, they are given a particular frame. If the values have changed, they are
updated with the new value and highlighted. */ updated with the new value and highlighted. */
@ -490,32 +469,28 @@ tui_data_window::check_register_values (struct frame_info *frame)
&data_item_win.highlight); &data_item_win.highlight);
if (data_item_win.highlight || was_hilighted) if (data_item_win.highlight || was_hilighted)
data_item_win.rerender (); data_item_win.rerender (handle.get (), m_item_width);
} }
} }
tui_wrefresh (handle.get ());
} }
/* Display a register in a window. If hilite is TRUE, then the value /* Display a register in a window. If hilite is TRUE, then the value
will be displayed in reverse video. */ will be displayed in reverse video. */
void void
tui_data_item_window::rerender () tui_data_item_window::rerender (WINDOW *handle, int field_width)
{ {
int i;
scrollok (handle.get (), FALSE);
if (highlight) if (highlight)
/* We ignore the return value, casting it to void in order to avoid /* We ignore the return value, casting it to void in order to avoid
a compiler warning. The warning itself was introduced by a patch a compiler warning. The warning itself was introduced by a patch
to ncurses 5.7 dated 2009-08-29, changing this macro to expand to ncurses 5.7 dated 2009-08-29, changing this macro to expand
to code that causes the compiler to generate an unused-value to code that causes the compiler to generate an unused-value
warning. */ warning. */
(void) wstandout (handle.get ()); (void) wstandout (handle);
wmove (handle.get (), 0, 0); mvwaddnstr (handle, y, x, content.c_str (), field_width - 1);
for (i = 1; i < width; i++) waddstr (handle, n_spaces (field_width - content.size ()));
waddch (handle.get (), ' ');
wmove (handle.get (), 0, 0);
waddstr (handle.get (), content.c_str ());
if (highlight) if (highlight)
/* We ignore the return value, casting it to void in order to avoid /* We ignore the return value, casting it to void in order to avoid
@ -523,21 +498,7 @@ tui_data_item_window::rerender ()
to ncurses 5.7 dated 2009-08-29, changing this macro to expand to ncurses 5.7 dated 2009-08-29, changing this macro to expand
to code that causes the compiler to generate an unused-value to code that causes the compiler to generate an unused-value
warning. */ warning. */
(void) wstandend (handle.get ()); (void) wstandend (handle);
refresh_window ();
}
void
tui_data_item_window::refresh_window ()
{
if (handle != nullptr)
{
/* This seems to be needed because the data items are nested
windows, which according to the ncurses man pages aren't well
supported. */
touchwin (handle.get ());
tui_wrefresh (handle.get ());
}
} }
/* Helper for "tui reg next", wraps a call to REGGROUP_NEXT, but adds wrap /* Helper for "tui reg next", wraps a call to REGGROUP_NEXT, but adds wrap

View File

@ -26,7 +26,7 @@
/* A data item window. */ /* A data item window. */
struct tui_data_item_window : public tui_gen_win_info struct tui_data_item_window
{ {
tui_data_item_window () = default; tui_data_item_window () = default;
@ -34,23 +34,15 @@ struct tui_data_item_window : public tui_gen_win_info
tui_data_item_window (tui_data_item_window &&) = default; tui_data_item_window (tui_data_item_window &&) = default;
void rerender () override; void rerender (WINDOW *handle, int field_width);
void refresh_window () override;
int max_height () const override
{
return 1;
}
int min_height () const override
{
return 1;
}
/* Location. */
int x = 0;
int y = 0;
/* The register number. */ /* The register number. */
int regno = -1; int regno = -1;
bool highlight = false; bool highlight = false;
bool visible = false;
std::string content; std::string content;
}; };
@ -61,10 +53,6 @@ struct tui_data_window : public tui_win_info
DISABLE_COPY_AND_ASSIGN (tui_data_window); DISABLE_COPY_AND_ASSIGN (tui_data_window);
void refresh_window () override;
void no_refresh () override;
const char *name () const override const char *name () const override
{ {
return DATA_NAME; return DATA_NAME;
@ -138,6 +126,9 @@ private:
std::vector<tui_data_item_window> m_regs_content; std::vector<tui_data_item_window> m_regs_content;
int m_regs_column_count = 0; int m_regs_column_count = 0;
struct reggroup *m_current_group = nullptr; struct reggroup *m_current_group = nullptr;
/* Width of each register's display area. */
int m_item_width = 0;
}; };
#endif /* TUI_TUI_REGS_H */ #endif /* TUI_TUI_REGS_H */