summaryrefslogtreecommitdiff
path: root/src/widgets
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2009-02-01 22:32:07 +0000
committerpeter1138 <peter1138@openttd.org>2009-02-01 22:32:07 +0000
commitbce50498fc078f39b73b70a841c6d2776f997643 (patch)
tree11498b2611a021129b26fdd96527d3ab137b426e /src/widgets
parentbcb72d30d87223dbd6beccdc9f5046175da7b65f (diff)
downloadopenttd-bce50498fc078f39b73b70a841c6d2776f997643.tar.xz
(svn r15312) -Codechange: Handle closing of drop down menus when clicking in a window in a single place, instead of in the OnClick event for some windows. This standardises behaviour so that clicking anywhere in a window will close its drop down menu, which happened before for some windows but not all. In addition the dubious feature of hiding a drop down menu by opening the same menu has been removed. This only caused wasted CPU cycles as a whole new list was generated and then destroyed. Breathe.
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/dropdown.cpp20
-rw-r--r--src/widgets/dropdown_func.h2
2 files changed, 6 insertions, 16 deletions
diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp
index 083f31f38..42cd28d0f 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<DropdownWindow*>(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 03cb52d0c..bd4e93a67 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 */