+2019-10-09 Tom Tromey <tom@tromey.com>
+
+ * tui/tui-wingeneral.h (tui_delete_win): Don't declare.
+ * tui/tui-stack.c (tui_locator_window::rerender): Update.
+ * tui/tui-command.c (tui_cmd_window::resize)
+ (tui_refresh_cmd_win): Update.
+ * tui/tui-win.c (tui_resize_all, tui_set_focus_command): Update.
+ * tui/tui.c (tui_rl_other_window, tui_enable): Update.
+ * tui/tui-data.c (~tui_gen_win_info): Remove.
+ * tui/tui-layout.c (tui_gen_win_info::resize): Update.
+ * tui/tui-io.c (update_cmdwin_start_line, tui_putc, tui_puts)
+ (tui_redisplay_readline, tui_mld_flush)
+ (tui_mld_erase_entire_line, tui_mld_getc, tui_getc): Update.
+ * tui/tui-regs.c (tui_data_window::delete_data_content_windows)
+ (tui_data_window::erase_data_content)
+ (tui_data_item_window::rerender)
+ (tui_data_item_window::refresh_window): Update.
+ * tui/tui-wingeneral.c (tui_gen_win_info::refresh_window)
+ (box_win, tui_gen_win_info::make_window)
+ (tui_gen_win_info::make_visible): Update.
+ (tui_delete_win): Remove.
+ * tui/tui-winsource.c
+ (tui_source_window_base::do_erase_source_content): Update.
+ (tui_show_source_line, tui_source_window_base::update_tab_width)
+ (tui_source_window_base::update_exec_info): Update.
+ * tui/tui-data.h (struct curses_deleter): New.
+ (struct tui_gen_win_info) <handle>: Now a unique_ptr.
+ (struct tui_gen_win_info) <~tui_gen_win_info>: Define.
+
2019-10-09 Tom Tromey <tom@tromey.com>
* tui/tui-wingeneral.h (struct tui_gen_win_info): Don't declare.
it. However we can at least move it and keep the old size if
wresize isn't available. */
#ifdef HAVE_WRESIZE
- wresize (handle, height, width);
+ wresize (handle.get (), height, width);
#endif
- mvwin (handle, origin.y, origin.x);
- wmove (handle, 0, 0);
+ mvwin (handle.get (), origin.y, origin.x);
+ wmove (handle.get (), 0, 0);
}
}
void
tui_refresh_cmd_win (void)
{
- WINDOW *w = TUI_CMD_WIN->handle;
+ WINDOW *w = TUI_CMD_WIN->handle.get ();
wrefresh (w);
{
}
-tui_gen_win_info::~tui_gen_win_info ()
-{
- tui_delete_win (handle);
-}
-
void
tui_win_info::rerender ()
{
int x, y;
};
+/* A deleter that calls delwin. */
+struct curses_deleter
+{
+ void operator() (WINDOW *win) const
+ {
+ delwin (win);
+ }
+};
+
/* Generic window information. */
struct tui_gen_win_info
{
public:
tui_gen_win_info (tui_gen_win_info &&) = default;
- virtual ~tui_gen_win_info ();
+ virtual ~tui_gen_win_info ()
+ {
+ }
/* Call to refresh this window. */
virtual void refresh_window ();
}
/* Window handle. */
- WINDOW *handle = nullptr;
+ std::unique_ptr<WINDOW, curses_deleter> handle;
/* Type of window. */
enum tui_win_type type;
/* Window width. */
static void
update_cmdwin_start_line ()
{
- TUI_CMD_WIN->start_line
- = getcury (TUI_CMD_WIN->handle);
+ TUI_CMD_WIN->start_line = getcury (TUI_CMD_WIN->handle.get ());
}
/* Print a character in the curses command window. The output is
static void
tui_putc (char c)
{
- WINDOW *w = TUI_CMD_WIN->handle;
-
- do_tui_putc (w, c);
+ do_tui_putc (TUI_CMD_WIN->handle.get (), c);
update_cmdwin_start_line ();
}
}
}
}
- if (TUI_CMD_WIN != nullptr && w == TUI_CMD_WIN->handle)
+ if (TUI_CMD_WIN != nullptr && w == TUI_CMD_WIN->handle.get ())
update_cmdwin_start_line ();
if (saw_nl)
wrefresh (w);
tui_puts (const char *string, WINDOW *w)
{
if (w == nullptr)
- w = TUI_CMD_WIN->handle;
+ w = TUI_CMD_WIN->handle.get ();
tui_puts_internal (w, string, nullptr);
}
c_pos = -1;
c_line = -1;
- w = TUI_CMD_WIN->handle;
+ w = TUI_CMD_WIN->handle.get ();
start_line = TUI_CMD_WIN->start_line;
wmove (w, start_line, 0);
prev_col = 0;
height = 1;
if (prompt != nullptr)
- tui_puts_internal (TUI_CMD_WIN->handle, prompt, &height);
+ tui_puts_internal (w, prompt, &height);
prev_col = getcurx (w);
for (in = 0; in <= rl_end; in++)
static void
tui_mld_flush (const struct match_list_displayer *displayer)
{
- wrefresh (TUI_CMD_WIN->handle);
+ wrefresh (TUI_CMD_WIN->handle.get ());
}
/* TUI version of displayer.erase_entire_line. */
static void
tui_mld_erase_entire_line (const struct match_list_displayer *displayer)
{
- WINDOW *w = TUI_CMD_WIN->handle;
+ WINDOW *w = TUI_CMD_WIN->handle.get ();
int cur_y = getcury (w);
wmove (w, cur_y, 0);
static int
tui_mld_getc (FILE *fp)
{
- WINDOW *w = TUI_CMD_WIN->handle;
+ WINDOW *w = TUI_CMD_WIN->handle.get ();
int c = gdb_wgetch (w);
return c;
int ch;
WINDOW *w;
- w = TUI_CMD_WIN->handle;
+ w = TUI_CMD_WIN->handle.get ();
#ifdef TUI_USE_PIPE_FOR_READLINE
/* Flush readline output. */
if (handle != nullptr)
{
#ifdef HAVE_WRESIZE
- wresize (handle, height, width);
- mvwin (handle, origin.y, origin.x);
- wmove (handle, 0, 0);
+ wresize (handle.get (), height, width);
+ mvwin (handle.get (), origin.y, origin.x);
+ wmove (handle.get (), 0, 0);
#else
- tui_delete_win (handle);
- handle = NULL;
+ handle.reset (nullptr);
#endif
}
tui_data_window::delete_data_content_windows ()
{
for (auto &&win : m_regs_content)
- {
- tui_delete_win (win.handle);
- win.handle = NULL;
- }
+ win.handle.reset (nullptr);
}
void
tui_data_window::erase_data_content (const char *prompt)
{
- werase (handle);
+ werase (handle.get ());
check_and_display_highlight_if_needed ();
if (prompt != NULL)
{
x_pos = 1;
else
x_pos = half_width - strlen (prompt);
- mvwaddstr (handle, (height / 2), x_pos, (char *) prompt);
+ mvwaddstr (handle.get (), (height / 2), x_pos, (char *) prompt);
}
- wrefresh (handle);
+ wrefresh (handle.get ());
}
/* See tui-regs.h. */
{
int i;
- scrollok (handle, FALSE);
+ scrollok (handle.get (), FALSE);
if (highlight)
/* We ignore the return value, casting it to void in order to avoid
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 code that causes the compiler to generate an unused-value
warning. */
- (void) wstandout (handle);
+ (void) wstandout (handle.get ());
- wmove (handle, 0, 0);
+ wmove (handle.get (), 0, 0);
for (i = 1; i < width; i++)
- waddch (handle, ' ');
- wmove (handle, 0, 0);
+ waddch (handle.get (), ' ');
+ wmove (handle.get (), 0, 0);
if (content)
- waddstr (handle, content.get ());
+ waddstr (handle.get (), content.get ());
if (highlight)
/* We ignore the return value, casting it to void in order to avoid
to ncurses 5.7 dated 2009-08-29, changing this macro to expand
to code that causes the compiler to generate an unused-value
warning. */
- (void) wstandend (handle);
+ (void) wstandend (handle.get ());
refresh_window ();
}
/* 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);
- wrefresh (handle);
+ touchwin (handle.get ());
+ wrefresh (handle.get ());
}
}
if (handle != NULL)
{
std::string string = make_status_line ();
- scrollok (handle, FALSE);
- wmove (handle, 0, 0);
+ scrollok (handle.get (), FALSE);
+ wmove (handle.get (), 0, 0);
/* We ignore the return value from wstandout and wstandend, casting
them to void in order to avoid a compiler warning. The warning
itself was introduced by a patch to ncurses 5.7 dated 2009-08-29,
changing these macro to expand to code that causes the compiler
to generate an unused-value warning. */
- (void) wstandout (handle);
- waddstr (handle, string.c_str ());
- wclrtoeol (handle);
- (void) wstandend (handle);
+ (void) wstandout (handle.get ());
+ waddstr (handle.get (), string.c_str ());
+ wclrtoeol (handle.get ());
+ (void) wstandend (handle.get ());
refresh_window ();
- wmove (handle, 0, 0);
+ wmove (handle.get (), 0, 0);
}
}
#endif
/* Turn keypad off while we resize. */
if (win_with_focus != TUI_CMD_WIN)
- keypad (TUI_CMD_WIN->handle, FALSE);
+ keypad (TUI_CMD_WIN->handle.get (), FALSE);
tui_update_gdb_sizes ();
tui_set_term_height_to (screenheight);
tui_set_term_width_to (screenwidth);
/* Turn keypad back on, unless focus is in the command
window. */
if (win_with_focus != TUI_CMD_WIN)
- keypad (TUI_CMD_WIN->handle, TRUE);
+ keypad (TUI_CMD_WIN->handle.get (), TRUE);
}
}
error (_("Window \"%s\" is not visible"), arg);
tui_set_win_focus_to (win_info);
- keypad (TUI_CMD_WIN->handle, (win_info != TUI_CMD_WIN));
+ keypad (TUI_CMD_WIN->handle.get (), win_info != TUI_CMD_WIN);
printf_filtered (_("Focus set to %s window.\n"),
tui_win_with_focus ()->name ());
}
tui_gen_win_info::refresh_window ()
{
if (handle != NULL)
- wrefresh (handle);
+ wrefresh (handle.get ());
}
-/* Function to delete the curses window, checking for NULL. */
-void
-tui_delete_win (WINDOW *window)
-{
- if (window != NULL)
- delwin (window);
-}
-
-
/* Draw a border arround the window. */
static void
box_win (struct tui_win_info *win_info,
WINDOW *win;
int attrs;
- win = win_info->handle;
+ win = win_info->handle.get ();
if (highlight_flag)
attrs = tui_active_border_attrs;
else
void
tui_gen_win_info::make_window ()
{
- handle = newwin (height, width, origin.y, origin.x);
+ handle.reset (newwin (height, width, origin.y, origin.x));
if (handle != NULL)
- scrollok (handle, TRUE);
+ scrollok (handle.get (), TRUE);
}
void
if (visible)
make_window ();
else
- {
- tui_delete_win (handle);
- handle = NULL;
- }
+ handle.reset (nullptr);
}
/* See tui-wingeneral.h. */
extern void tui_unhighlight_win (struct tui_win_info *);
extern void tui_highlight_win (struct tui_win_info *);
extern void tui_refresh_all ();
-extern void tui_delete_win (WINDOW *window);
#endif /* TUI_TUI_WINGENERAL_H */
content.clear ();
if (handle != NULL)
{
- werase (handle);
+ werase (handle.get ());
check_and_display_highlight_if_needed ();
if (strlen (str) >= half_width)
x_pos = 1;
else
x_pos = half_width - strlen (str);
- mvwaddstr (handle,
+ mvwaddstr (handle.get (),
(height / 2),
x_pos,
(char *) str);
line = &win_info->content[lineno - 1];
if (line->is_exec_point)
- tui_set_reverse_mode (win_info->handle, true);
+ tui_set_reverse_mode (win_info->handle.get (), true);
- wmove (win_info->handle, lineno, TUI_EXECINFO_SIZE);
- tui_puts (line->line.get (), win_info->handle);
+ wmove (win_info->handle.get (), lineno, TUI_EXECINFO_SIZE);
+ tui_puts (line->line.get (), win_info->handle.get ());
if (line->is_exec_point)
- tui_set_reverse_mode (win_info->handle, false);
+ tui_set_reverse_mode (win_info->handle.get (), false);
/* Clear to end of line but stop before the border. */
- x = getcurx (win_info->handle);
+ x = getcurx (win_info->handle.get ());
while (x + 1 < win_info->width)
{
- waddch (win_info->handle, ' ');
- x = getcurx (win_info->handle);
+ waddch (win_info->handle.get (), ' ');
+ x = getcurx (win_info->handle.get ());
}
}
void
tui_source_window_base::update_tab_width ()
{
- werase (handle);
+ werase (handle.get ());
rerender ();
}
if (src_element->is_exec_point)
element[TUI_EXEC_POS] = '>';
- mvwaddstr (handle, i + 1, 1, element);
+ mvwaddstr (handle.get (), i + 1, 1, element);
}
refresh_window ();
}
if (win_info)
{
tui_set_win_focus_to (win_info);
- keypad (TUI_CMD_WIN->handle, (win_info != TUI_CMD_WIN));
+ keypad (TUI_CMD_WIN->handle.get (), win_info != TUI_CMD_WIN);
}
return 0;
}
tui_show_frame_info (0);
tui_set_layout (SRC_COMMAND);
tui_set_win_focus_to (TUI_SRC_WIN);
- keypad (TUI_CMD_WIN->handle, TRUE);
- wrefresh (TUI_CMD_WIN->handle);
+ keypad (TUI_CMD_WIN->handle.get (), TRUE);
+ wrefresh (TUI_CMD_WIN->handle.get ());
tui_finish_init = 0;
}
else