diff --git a/common/include/ui.h b/common/include/ui.h index f295af617..7f53850b4 100644 --- a/common/include/ui.h +++ b/common/include/ui.h @@ -299,7 +299,7 @@ window_event_result ui_button_do( UI_DIALOG *dlg, UI_GADGET_BUTTON * button, con window_event_result ui_listbox_do( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox, const d_event &event ); extern void ui_draw_listbox( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox ); -extern UI_GADGET_LISTBOX *ui_add_gadget_listbox(UI_DIALOG *dlg, short x, short y, short w, short h, short numitems, char **list); +std::unique_ptr ui_add_gadget_listbox(UI_DIALOG *dlg, short x, short y, short w, short h, short numitems, char **list); extern void ui_mega_process(); diff --git a/common/ui/file.cpp b/common/ui/file.cpp index a16ef3f18..17f2b2e10 100644 --- a/common/ui/file.cpp +++ b/common/ui/file.cpp @@ -125,8 +125,7 @@ struct browser char **filename_list; char **directory_list; UI_GADGET_BUTTON *button1, *button2, *help_button; - UI_GADGET_LISTBOX *listbox1; - UI_GADGET_LISTBOX *listbox2; + std::unique_ptr listbox1, listbox2; std::unique_ptr user_file; int num_files, num_dirs; char spaces[35]; @@ -166,10 +165,10 @@ static int browser_handler(UI_DIALOG *dlg,const d_event &event, browser *b) if (event.type == EVENT_UI_LISTBOX_MOVED) { - if ((ui_event_get_gadget(event) == b->listbox1) && (b->listbox1->current_item >= 0) && b->filename_list[b->listbox1->current_item]) + if ((ui_event_get_gadget(event) == b->listbox1.get()) && (b->listbox1->current_item >= 0) && b->filename_list[b->listbox1->current_item]) ui_inputbox_set_text(b->user_file.get(), b->filename_list[b->listbox1->current_item]); - if ((ui_event_get_gadget(event) == b->listbox2) && (b->listbox2->current_item >= 0) && b->directory_list[b->listbox2->current_item]) + if ((ui_event_get_gadget(event) == b->listbox2.get()) && (b->listbox2->current_item >= 0) && b->directory_list[b->listbox2->current_item]) ui_inputbox_set_text(b->user_file.get(), b->directory_list[b->listbox2->current_item]); rval = 1; @@ -179,7 +178,7 @@ static int browser_handler(UI_DIALOG *dlg,const d_event &event, browser *b) { char *p; - if (ui_event_get_gadget(event) == b->listbox2) + if (ui_event_get_gadget(event) == b->listbox2.get()) strcpy(b->user_file->text, b->directory_list[b->listbox2->current_item]); strncpy(b->filename, b->view_dir, PATH_MAX); @@ -254,8 +253,8 @@ static int browser_handler(UI_DIALOG *dlg,const d_event &event, browser *b) return 1; } - ui_listbox_change(dlg, b->listbox1, b->num_files, b->filename_list); - ui_listbox_change(dlg, b->listbox2, b->num_dirs, b->directory_list); + ui_listbox_change(dlg, b->listbox1.get(), b->num_files, b->filename_list); + ui_listbox_change(dlg, b->listbox2.get(), b->num_dirs, b->directory_list); //i = TICKER; //while ( TICKER < i+2 ); diff --git a/common/ui/gadget.cpp b/common/ui/gadget.cpp index d03bd29d6..100e2fc06 100644 --- a/common/ui/gadget.cpp +++ b/common/ui/gadget.cpp @@ -96,8 +96,6 @@ void ui_gadget_delete_all( UI_DIALOG * dlg ) delete static_cast(tmp); break; case UI_GADGET_LISTBOX::s_kind: - delete static_cast(tmp); - break; case UI_GADGET_SCROLLBAR::s_kind: case UI_GADGET_RADIO::s_kind: case UI_GADGET_CHECKBOX::s_kind: diff --git a/common/ui/listbox.cpp b/common/ui/listbox.cpp index 98fc1e5b9..77bd17da1 100644 --- a/common/ui/listbox.cpp +++ b/common/ui/listbox.cpp @@ -120,7 +120,7 @@ static void gr_draw_sunken_border( short x1, short y1, short x2, short y2 ) } -UI_GADGET_LISTBOX * ui_add_gadget_listbox(UI_DIALOG *dlg, short x, short y, short w, short h, short numitems, char **list) +std::unique_ptr ui_add_gadget_listbox(UI_DIALOG *dlg, short x, short y, short w, short h, short numitems, char **list) { int tw, th, taw, i; gr_get_string_size("*", &tw, &th, &taw ); @@ -128,8 +128,7 @@ UI_GADGET_LISTBOX * ui_add_gadget_listbox(UI_DIALOG *dlg, short x, short y, shor i = h / th; h = i * th; - auto listbox = ui_gadget_add( dlg, x, y, x+w-1, y+h-1 ); - + std::unique_ptr listbox{ui_gadget_add( dlg, x, y, x+w-1, y+h-1 )}; listbox->list = list; listbox->width = w; listbox->height = h; @@ -142,12 +141,9 @@ UI_GADGET_LISTBOX * ui_add_gadget_listbox(UI_DIALOG *dlg, short x, short y, shor listbox->dragging = 0; listbox->selected_item = -1; listbox->moved = 1; - listbox->scrollbar = ui_add_gadget_scrollbar( dlg, x+w+3, y, 0, h, 0, numitems-i, 0, i ); - listbox->scrollbar->parent = listbox; - + listbox->scrollbar->parent = listbox.get(); return listbox; - } window_event_result ui_listbox_do( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox,const d_event &event )