From 1d363bbd5d0d1f901fb8f8bc180db834f10da219 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 20 Dec 2014 04:36:10 +0000 Subject: [PATCH] Return unique_ptr from ui_add_gadget_scrollbar --- common/include/ui.h | 6 +++--- common/ui/gadget.cpp | 2 -- common/ui/listbox.cpp | 4 ++-- common/ui/scroll.cpp | 8 ++++---- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/common/include/ui.h b/common/include/ui.h index 2186cc00b..f295af617 100644 --- a/common/include/ui.h +++ b/common/include/ui.h @@ -191,11 +191,11 @@ struct UI_GADGET_LISTBOX : UI_GADGET int current_item; int selected_item; int old_current_item; - fix64 last_scrolled; int dragging; int textheight; - UI_GADGET_SCROLLBAR * scrollbar; int moved; + std::unique_ptr scrollbar; + fix64 last_scrolled; }; enum dialog_flags @@ -305,7 +305,7 @@ extern void ui_mega_process(); extern void ui_get_button_size( const char * text, int * width, int * height ); -extern UI_GADGET_SCROLLBAR * ui_add_gadget_scrollbar( UI_DIALOG * dlg, short x, short y, short w, short h, int start, int stop, int position, int window_size ); +std::unique_ptr ui_add_gadget_scrollbar(UI_DIALOG * dlg, short x, short y, short w, short h, int start, int stop, int position, int window_size); window_event_result ui_scrollbar_do( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar, const d_event &event ); extern void ui_draw_scrollbar( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar ); diff --git a/common/ui/gadget.cpp b/common/ui/gadget.cpp index aa6979336..d03bd29d6 100644 --- a/common/ui/gadget.cpp +++ b/common/ui/gadget.cpp @@ -99,8 +99,6 @@ void ui_gadget_delete_all( UI_DIALOG * dlg ) delete static_cast(tmp); break; case UI_GADGET_SCROLLBAR::s_kind: - delete static_cast(tmp); - break; case UI_GADGET_RADIO::s_kind: case UI_GADGET_CHECKBOX::s_kind: case UI_GADGET_INPUTBOX::s_kind: diff --git a/common/ui/listbox.cpp b/common/ui/listbox.cpp index 2c5d48863..98fc1e5b9 100644 --- a/common/ui/listbox.cpp +++ b/common/ui/listbox.cpp @@ -186,7 +186,7 @@ window_event_result ui_listbox_do( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox,c listbox->old_first_item = listbox->first_item; - if (GADGET_PRESSED(listbox->scrollbar)) + if (GADGET_PRESSED(listbox->scrollbar.get())) { listbox->moved = 1; @@ -396,7 +396,7 @@ void ui_listbox_change(UI_DIALOG *, UI_GADGET_LISTBOX *listbox, short numitems, listbox->current_item = listbox->old_current_item = 0; listbox->moved = 0; - scrollbar = listbox->scrollbar; + scrollbar = listbox->scrollbar.get(); start=0; stop= numitems - listbox->num_items_displayed; diff --git a/common/ui/scroll.cpp b/common/ui/scroll.cpp index 8f0768521..5882739f9 100644 --- a/common/ui/scroll.cpp +++ b/common/ui/scroll.cpp @@ -50,7 +50,7 @@ void ui_draw_scrollbar( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar ) ui_draw_box_out(0, scrollbar->fake_position, scrollbar->width-1, scrollbar->fake_position+scrollbar->fake_size-1 ); } -UI_GADGET_SCROLLBAR * ui_add_gadget_scrollbar( UI_DIALOG * dlg, short x, short y, short w, short h, int start, int stop, int position, int window_size ) +std::unique_ptr ui_add_gadget_scrollbar(UI_DIALOG * dlg, short x, short y, short w, short h, int start, int stop, int position, int window_size) { int tw, th, taw; @@ -65,13 +65,13 @@ UI_GADGET_SCROLLBAR * ui_add_gadget_scrollbar( UI_DIALOG * dlg, short x, short y if (stop < start ) stop = start; - auto scrollbar = ui_gadget_add( dlg, x, y+w, x+w-1, y+h-w-1 ); + std::unique_ptr scrollbar{ui_gadget_add(dlg, x, y+w, x+w-1, y+h-w-1)}; scrollbar->up_button = ui_add_gadget_button( dlg, x, y, w, w, up, NULL ); - scrollbar->up_button->parent = scrollbar; + scrollbar->up_button->parent = scrollbar.get(); scrollbar->down_button =ui_add_gadget_button( dlg, x, y+h-w, w, w, down, NULL ); - scrollbar->down_button->parent = scrollbar; + scrollbar->down_button->parent = scrollbar.get(); scrollbar->horz = 0; scrollbar->width = scrollbar->x2-scrollbar->x1+1;