changeset 11030:8ea72967ad79 draft

(svn r15370) -Codechange: add a callback to tell the parent of an OSK that the string has changed instead of only marking the text box dirty.
author rubidium <rubidium@openttd.org>
date Fri, 06 Feb 2009 11:57:25 +0000
parents 5bfb68c58fd3
children 8c0c440e51c6
files src/osk_gui.cpp src/querystring_gui.h
diffstat 2 files changed, 17 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/osk_gui.cpp
+++ b/src/osk_gui.cpp
@@ -120,7 +120,7 @@
 
 			if (!IsValidChar(c, this->qs->afilter)) return;
 
-			if (InsertTextBufferChar(&this->qs->text, c)) this->InvalidateWidget(OSK_WIDGET_TEXT);
+			if (InsertTextBufferChar(&this->qs->text, c)) this->InvalidateParent();
 
 			if (HasBit(_keystate, KEYS_SHIFT)) {
 				ToggleBit(_keystate, KEYS_SHIFT);
@@ -130,11 +130,9 @@
 			return;
 		}
 
-		bool delete_this = false;
-
 		switch (widget) {
 			case OSK_WIDGET_BACKSPACE:
-				if (DeleteTextBufferChar(&this->qs->text, WKC_BACKSPACE)) this->InvalidateWidget(OSK_WIDGET_TEXT);
+				if (DeleteTextBufferChar(&this->qs->text, WKC_BACKSPACE)) this->InvalidateParent();
 				break;
 
 			case OSK_WIDGET_SPECIAL:
@@ -156,15 +154,15 @@
 				break;
 
 			case OSK_WIDGET_SPACE:
-				if (InsertTextBufferChar(&this->qs->text, ' ')) this->InvalidateWidget(OSK_WIDGET_TEXT);
+				if (InsertTextBufferChar(&this->qs->text, ' ')) this->InvalidateParent();
 				break;
 
 			case OSK_WIDGET_LEFT:
-				if (MoveTextBufferPos(&this->qs->text, WKC_LEFT)) this->InvalidateWidget(OSK_WIDGET_TEXT);
+				if (MoveTextBufferPos(&this->qs->text, WKC_LEFT)) this->InvalidateParent();
 				break;
 
 			case OSK_WIDGET_RIGHT:
-				if (MoveTextBufferPos(&this->qs->text, WKC_RIGHT)) this->InvalidateWidget(OSK_WIDGET_TEXT);
+				if (MoveTextBufferPos(&this->qs->text, WKC_RIGHT)) this->InvalidateParent();
 				break;
 
 			case OSK_WIDGET_OK:
@@ -176,7 +174,7 @@
 						return;
 					}
 				}
-				delete_this = true;
+				delete this;
 				break;
 
 			case OSK_WIDGET_CANCEL:
@@ -188,13 +186,20 @@
 					strcpy(qs->text.buf, this->orig_str_buf);
 					UpdateTextBufferSize(&qs->text);
 					MoveTextBufferPos(&qs->text, WKC_END);
-					delete_this = true;
+					this->InvalidateParent();
+					delete this;
 				}
 				break;
 		}
-		/* make sure that the parent window's textbox also gets updated */
+	}
+
+	void InvalidateParent()
+	{
+		QueryStringBaseWindow *w = dynamic_cast<QueryStringBaseWindow*>(this->parent);
+		if (w != NULL) w->OnOSKInput(this->text_btn);
+
+		this->InvalidateWidget(OSK_WIDGET_TEXT);
 		if (this->parent != NULL) this->parent->InvalidateWidget(this->text_btn);
-		if (delete_this) delete this;
 	}
 
 	virtual void OnMouseLoop()
--- a/src/querystring_gui.h
+++ b/src/querystring_gui.h
@@ -68,6 +68,7 @@
 	void HandleEditBox(int wid);
 	HandleEditBoxResult HandleEditBoxKey(int wid, uint16 key, uint16 keycode, EventState &state);
 	virtual void OnOpenOSKWindow(int wid);
+	virtual void OnOSKInput(int wid) {}
 };
 
 void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button, int cancel, int ok);