summaryrefslogtreecommitdiff
path: root/src/osk_gui.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-11-28 21:14:28 +0000
committerfrosch <frosch@openttd.org>2012-11-28 21:14:28 +0000
commit5dfd5e58ee58cc8205c430075ec1325aa9fda0ca (patch)
treedcd42222d5d1492237a22e24f0f85cffb93a4a16 /src/osk_gui.cpp
parentbfba90f8648cdb8b10ddd1322f46411761a9c29b (diff)
downloadopenttd-5dfd5e58ee58cc8205c430075ec1325aa9fda0ca.tar.xz
(svn r24774) -Fix: Invert the focus handling of the OSK. Keep the focus at the OSK and close it on losing focus. This makes the editbox in the OSK behave correctly.
Diffstat (limited to 'src/osk_gui.cpp')
-rw-r--r--src/osk_gui.cpp44
1 files changed, 19 insertions, 25 deletions
diff --git a/src/osk_gui.cpp b/src/osk_gui.cpp
index 0dc9aaded..ea66782e8 100644
--- a/src/osk_gui.cpp
+++ b/src/osk_gui.cpp
@@ -53,11 +53,13 @@ struct OskWindow : public Window {
this->caption = (par_wid->widget_data != STR_NULL) ? par_wid->widget_data : this->qs->caption;
this->text_btn = button;
this->text = &this->qs->text;
+ this->querystrings[WID_OSK_TEXT] = this->qs;
/* make a copy in case we need to reset later */
this->orig_str_buf = strdup(this->qs->text.buf);
this->InitNested(desc, 0);
+ this->SetFocusedWidget(WID_OSK_TEXT);
/* Not needed by default. */
this->DisableWidget(WID_OSK_SPECIAL);
@@ -105,13 +107,6 @@ struct OskWindow : public Window {
TC_BLACK);
}
- virtual void OnPaint()
- {
- this->DrawWidgets();
-
- this->qs->DrawEditBox(this, WID_OSK_TEXT);
- }
-
virtual void OnClick(Point pt, int widget, int click_count)
{
/* clicked a letter */
@@ -127,9 +122,6 @@ struct OskWindow : public Window {
this->UpdateOskState();
this->SetDirty();
}
- /* Return focus to the parent widget and window. */
- this->parent->SetFocusedWidget(this->text_btn);
- SetFocusedWindow(this->parent);
return;
}
@@ -195,9 +187,6 @@ struct OskWindow : public Window {
}
break;
}
- /* Return focus to the parent widget and window. */
- this->parent->SetFocusedWidget(this->text_btn);
- SetFocusedWindow(this->parent);
}
virtual void OnEditboxChanged(int widget)
@@ -207,24 +196,17 @@ struct OskWindow : public Window {
this->parent->SetWidgetDirty(this->text_btn);
}
- virtual void OnMouseLoop()
- {
- this->qs->HandleEditBox(this, WID_OSK_TEXT);
- /* make the caret of the parent window also blink */
- this->parent->SetWidgetDirty(this->text_btn);
- }
-
- /**
- * Some data on this window has become invalid.
- * @param data Information about the changed data.
- * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
- */
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{
if (!gui_scope) return;
this->SetWidgetDirty(WID_OSK_TEXT);
this->parent->SetWidgetDirty(this->text_btn);
}
+
+ virtual void OnFocusLost()
+ {
+ delete this;
+ }
};
static const int HALF_KEY_WIDTH = 7; // Width of 1/2 key in pixels.
@@ -448,3 +430,15 @@ void UpdateOSKOriginalText(const Window *parent, int button)
osk->SetDirty();
}
+
+/**
+ * Check whether the OSK is opened for a specific editbox.
+ * @parent w Window to check for
+ * @param button Editbox of \a w to check for
+ * @return true if the OSK is oppened for \a button.
+ */
+bool IsOSKOpenedFor(const Window *w, int button)
+{
+ OskWindow *osk = dynamic_cast<OskWindow *>(FindWindowById(WC_OSK, 0));
+ return osk != NULL && osk->parent == w && osk->text_btn == button;
+}