Allow dcx::UI_DIALOG struct to be subclassed - step 3

Allow dcx::UI_DIALOG struct to be subclassed step 3. This step adds the destructor and makes sure the dialog is only deleted within the main dialog handler if the specific handler didn't return window_event_result::deleted.
This commit is contained in:
Chris Taylor 2016-10-04 16:09:21 +08:00
parent db665d8c33
commit 9631d319f6
2 changed files with 11 additions and 4 deletions

View file

@ -241,6 +241,8 @@ public:
template <typename T>
UI_DIALOG(short x, short y, short w, short h, enum dialog_flags flags, ui_subclass_subfunction_t<T> callback) :
UI_DIALOG(x, y, w, h, flags, reinterpret_cast<ui_subclass_subfunction_t<UI_DIALOG>>(callback), nullptr, nullptr) {}
~UI_DIALOG();
};
#define B1_JUST_PRESSED (event.type == EVENT_MOUSE_BUTTON_DOWN && event_mouse_get_button(event) == 0)

View file

@ -133,10 +133,9 @@ static window_event_result ui_dialog_handler(window *wind,const d_event &event,
}
case EVENT_WINDOW_CLOSE:
ui_gadget_delete_all(dlg);
selected_gadget = NULL;
delete dlg;
return window_event_result::ignored;
if (rval != window_event_result::deleted) // check if handler already deleted dialog (e.g. if UI_DIALOG was subclassed)
delete dlg;
return window_event_result::ignored; // free the window in any case (until UI_DIALOG is subclass of window)
default:
return window_event_result::ignored;
}
@ -194,6 +193,12 @@ void ui_dialog_set_current_canvas(UI_DIALOG *dlg)
gr_set_current_canvas(window_get_canvas(*dlg->wind));
}
UI_DIALOG::~UI_DIALOG()
{
ui_gadget_delete_all(this);
selected_gadget = NULL;
}
void ui_close_dialog( UI_DIALOG * dlg )
{
window_close(dlg->wind);