summaryrefslogtreecommitdiff
path: root/src/misc_gui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc_gui.cpp')
-rw-r--r--src/misc_gui.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index f7061d328..59b0282d5 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -759,20 +759,20 @@ struct TooltipsWindow : public Window
{
/* Always close tooltips when the cursor is not in our window. */
if (!_cursor.in_window) {
- delete this;
+ this->Close();
return;
}
/* We can show tooltips while dragging tools. These are shown as long as
* we are dragging the tool. Normal tooltips work with hover or rmb. */
switch (this->close_cond) {
- case TCC_RIGHT_CLICK: if (!_right_button_down) delete this; break;
- case TCC_HOVER: if (!_mouse_hovering) delete this; break;
+ case TCC_RIGHT_CLICK: if (!_right_button_down) this->Close(); break;
+ case TCC_HOVER: if (!_mouse_hovering) this->Close(); break;
case TCC_NONE: break;
case TCC_EXIT_VIEWPORT: {
Window *w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
- if (w == nullptr || IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y) == nullptr) delete this;
+ if (w == nullptr || IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y) == nullptr) this->Close();
break;
}
}
@@ -1090,18 +1090,19 @@ struct QueryStringWindow : public Window
FALLTHROUGH;
case WID_QS_CANCEL:
- delete this;
+ this->Close();
break;
}
}
- ~QueryStringWindow()
+ void Close() override
{
if (!this->editbox.handled && this->parent != nullptr) {
Window *parent = this->parent;
- this->parent = nullptr; // so parent doesn't try to delete us again
+ this->parent = nullptr; // so parent doesn't try to close us again
parent->OnQueryTextFinished(nullptr);
}
+ this->Window::Close();
}
};
@@ -1167,9 +1168,10 @@ struct QueryWindow : public Window {
this->InitNested(WN_CONFIRM_POPUP_QUERY);
}
- ~QueryWindow()
+ void Close() override
{
if (this->proc != nullptr) this->proc(this->parent, false);
+ this->Window::Close();
}
void FindWindowPlacementAndResize(int def_width, int def_height) override
@@ -1222,7 +1224,7 @@ struct QueryWindow : public Window {
Window *parent = this->parent;
/* Prevent the destructor calling the callback function */
this->proc = nullptr;
- delete this;
+ this->Close();
if (proc != nullptr) {
proc(parent, true);
proc = nullptr;
@@ -1230,7 +1232,7 @@ struct QueryWindow : public Window {
break;
}
case WID_Q_NO:
- delete this;
+ this->Close();
break;
}
}
@@ -1248,7 +1250,7 @@ struct QueryWindow : public Window {
FALLTHROUGH;
case WKC_ESC:
- delete this;
+ this->Close();
return ES_HANDLED;
}
return ES_NOT_HANDLED;
@@ -1289,13 +1291,13 @@ void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallback
{
if (parent == nullptr) parent = FindWindowById(WC_MAIN_WINDOW, 0);
- for (const Window *w : Window::Iterate()) {
+ for (Window *w : Window::Iterate()) {
if (w->window_class != WC_CONFIRM_POPUP_QUERY) continue;
- const QueryWindow *qw = (const QueryWindow *)w;
+ QueryWindow *qw = dynamic_cast<QueryWindow *>(w);
if (qw->parent != parent || qw->proc != callback) continue;
- delete qw;
+ qw->Close();
break;
}