summaryrefslogtreecommitdiff
path: root/src/window.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-11-14 22:50:35 +0000
committerfrosch <frosch@openttd.org>2012-11-14 22:50:35 +0000
commitf5d8ba5d7f90abc72db6c0470da383ecf82da487 (patch)
tree3dbbbbe18733005c5851251dac62314d871b2b30 /src/window.cpp
parentdcfb2af871b76a7b65fb959b2f4ebc2da2f9e4d3 (diff)
downloadopenttd-f5d8ba5d7f90abc72db6c0470da383ecf82da487.tar.xz
(svn r24742) -Codechange: Remove QueryStringBaseWindow and store QueryStrings per widget instead.
Diffstat (limited to 'src/window.cpp')
-rw-r--r--src/window.cpp37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/window.cpp b/src/window.cpp
index 8aa932859..665fabcf8 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -227,6 +227,28 @@ Scrollbar *Window::GetScrollbar(uint widnum)
return this->GetWidget<NWidgetScrollbar>(widnum);
}
+/**
+ * Return the querystring associated to a editbox.
+ * @param widnum Editbox widget index
+ * @return QueryString or NULL.
+ */
+const QueryString *Window::GetQueryString(uint widnum) const
+{
+ const SmallMap<int, QueryString*>::Pair *query = this->querystrings.Find(widnum);
+ return query != this->querystrings.End() ? query->second : NULL;
+}
+
+/**
+ * Return the querystring associated to a editbox.
+ * @param widnum Editbox widget index
+ * @return QueryString or NULL.
+ */
+QueryString *Window::GetQueryString(uint widnum)
+{
+ SmallMap<int, QueryString*>::Pair *query = this->querystrings.Find(widnum);
+ return query != this->querystrings.End() ? query->second : NULL;
+}
+
/**
* Set the window that has the focus
@@ -450,9 +472,8 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
case WWT_EDITBOX:
if (!focused_widget_changed) { // Only open the OSK window if clicking on an already focused edit box
/* Open the OSK window if clicked on an edit box */
- QueryStringBaseWindow *qs = dynamic_cast<QueryStringBaseWindow *>(w);
- if (qs != NULL) {
- ShowOnScreenKeyboard(qs, widget_index);
+ if (w->querystrings.Contains(widget_index)) {
+ ShowOnScreenKeyboard(w, widget_index);
}
}
break;
@@ -1622,12 +1643,8 @@ static void DecreaseWindowCounters()
}
/* Handle editboxes */
- for (uint i = 0; i < w->nested_array_size; i++) {
- NWidgetBase *nwid = w->nested_array[i];
- if (nwid != NULL && nwid->type == WWT_EDITBOX) {
- QueryString *query = dynamic_cast<QueryString*>(w);
- if (query != NULL) query->HandleEditBox(w, i);
- }
+ for (SmallMap<int, QueryString*>::Pair *it = w->querystrings.Begin(); it != w->querystrings.End(); ++it) {
+ it->second->HandleEditBox(w, it->first);
}
w->OnMouseLoop();
@@ -2245,7 +2262,7 @@ EventState Window::HandleEditBoxKey(int wid, uint16 key, uint16 keycode)
{
EventState state = ES_NOT_HANDLED;
- QueryString *query = dynamic_cast<QueryString*>(this);
+ QueryString *query = this->GetQueryString(wid);
if (query == NULL) return state;
switch (query->HandleEditBoxKey(this, wid, key, keycode, state)) {