diff --git a/src/group_gui.cpp b/src/group_gui.cpp index 3ec8668018..b8cc533775 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -440,8 +440,6 @@ public: virtual void OnClick(Point pt, int widget) { - if (widget != GRP_WIDGET_SORT_BY_DROPDOWN && widget != GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN) HideDropDownMenu(this); - switch(widget) { case GRP_WIDGET_SORT_BY_ORDER: // Flip sorting method ascending/descending this->vehicles.ToggleSortOrder(); diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 6a59e1a6c5..f4e52db4ab 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -925,7 +925,6 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow { virtual void OnClick(Point pt, int widget) { - if (widget != NSSW_CONNTYPE_BTN && widget != NSSW_LANGUAGE_BTN) HideDropDownMenu(this); this->field = widget; switch (widget) { case NSSW_CLOSE: // Close 'X' diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 43978edb27..b20d1c5565 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -839,7 +839,6 @@ public: virtual void OnClick(Point pt, int widget) { - if (this->widget[widget].type != WWT_DROPDOWN) HideDropDownMenu(this); switch (widget) { case ORDER_WIDGET_ORDER_LIST: { ResetObjectToPlace(); diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index 083f31f38f..42cd28d0f9 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -226,15 +226,8 @@ struct DropdownWindow : Window { void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width, bool auto_width, bool instant_close) { - bool is_dropdown_menu_shown = w->IsWidgetLowered(button); - DeleteWindowById(WC_DROPDOWN_MENU, 0); - if (is_dropdown_menu_shown) { - DeleteDropDownList(list); - return; - } - w->LowerWidget(button); w->InvalidateWidget(button); @@ -339,12 +332,6 @@ void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, u void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width) { - /* Don't create a new list if we're just closing an existing menu */ - if (w->IsWidgetLowered(button)) { - DeleteWindowById(WC_DROPDOWN_MENU, 0); - return; - } - uint result = 0; DropDownList *list = new DropDownList(); @@ -368,7 +355,7 @@ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int butt * Delete the drop-down menu from window \a pw * @param pw Parent window of the drop-down menu window */ -void HideDropDownMenu(Window *pw) +int HideDropDownMenu(Window *pw) { Window *w; FOR_ALL_WINDOWS_FROM_BACK(w) { @@ -377,9 +364,12 @@ void HideDropDownMenu(Window *pw) DropdownWindow *dw = dynamic_cast(w); if (pw->window_class == dw->parent_wnd_class && pw->window_number == dw->parent_wnd_num) { + int parent_button = dw->parent_button; delete dw; - break; + return parent_button; } } + + return -1; } diff --git a/src/widgets/dropdown_func.h b/src/widgets/dropdown_func.h index 03cb52d0c2..bd4e93a675 100644 --- a/src/widgets/dropdown_func.h +++ b/src/widgets/dropdown_func.h @@ -9,6 +9,6 @@ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width = 0); /* Hide drop down menu of a parent window */ -void HideDropDownMenu(Window *pw); +int HideDropDownMenu(Window *pw); #endif /* WIDGETS_DROPDOWN_FUNC_H */ diff --git a/src/window.cpp b/src/window.cpp index 50d93117a5..f5fed776d8 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -22,6 +22,7 @@ #include "tilehighlight_func.h" #include "network/network.h" #include "querystring_gui.h" +#include "widgets/dropdown_func.h" #include "table/sprites.h" @@ -188,6 +189,10 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, bool double_click) } } + /* Close any child drop down menus. If the button pressed was the drop down + * list's own button, then we should not process the click any further. */ + if (HideDropDownMenu(w) == widget) return; + if (w->desc_flags & WDF_STD_BTN) { if (widget == 0) { /* 'X' */ delete w;