Changeset - r19817:11d26f5e68c7
[Not reviewed]
master
0 4 0
frosch - 12 years ago 2012-11-28 20:54:56
frosch@openttd.org
(svn r24772) -Codechange: Call Window::OnEditboxChanged only when the content changes, not when only moving the cursor.
4 files changed with 28 insertions and 20 deletions:
0 comments (0 inline, 0 general)
src/misc_gui.cpp
Show inline comments
 
@@ -719,6 +719,8 @@ HandleEditBoxResult QueryString::HandleE
 

	
 
	state = ES_HANDLED;
 

	
 
	bool edited = false;
 

	
 
	switch (keycode) {
 
		case WKC_ESC: return HEBR_CANCEL;
 

	
 
@@ -728,7 +730,7 @@ HandleEditBoxResult QueryString::HandleE
 
		case (WKC_META | 'V'):
 
#endif
 
		case (WKC_CTRL | 'V'):
 
			if (this->text.InsertClipboard()) w->SetWidgetDirty(wid);
 
			edited = this->text.InsertClipboard();
 
			break;
 

	
 
#ifdef WITH_COCOA
 
@@ -736,22 +738,22 @@ HandleEditBoxResult QueryString::HandleE
 
#endif
 
		case (WKC_CTRL | 'U'):
 
			this->text.DeleteAll();
 
			w->SetWidgetDirty(wid);
 
			edited = true;
 
			break;
 

	
 
		case WKC_BACKSPACE: case WKC_DELETE:
 
		case WKC_CTRL | WKC_BACKSPACE: case WKC_CTRL | WKC_DELETE:
 
			if (this->text.DeleteChar(keycode)) w->SetWidgetDirty(wid);
 
			edited = this->text.DeleteChar(keycode);
 
			break;
 

	
 
		case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME:
 
		case WKC_CTRL | WKC_LEFT: case WKC_CTRL | WKC_RIGHT:
 
			if (this->text.MovePos(keycode)) w->SetWidgetDirty(wid);
 
			this->text.MovePos(keycode);
 
			break;
 

	
 
		default:
 
			if (IsValidChar(key, this->afilter)) {
 
				if (this->text.InsertChar(key)) w->SetWidgetDirty(wid);
 
				edited = this->text.InsertChar(key);
 
			} else {
 
				state = ES_NOT_HANDLED;
 
			}
 
@@ -760,7 +762,7 @@ HandleEditBoxResult QueryString::HandleE
 
	Window *osk = FindWindowById(WC_OSK, 0);
 
	if (osk != NULL && osk->parent == w) osk->InvalidateData();
 

	
 
	return HEBR_EDITING;
 
	return edited ? HEBR_EDITING : HEBR_CURSOR;
 
}
 

	
 
void QueryString::HandleEditBox(Window *w, int wid)
src/osk_gui.cpp
Show inline comments
 
@@ -120,7 +120,7 @@ struct OskWindow : public Window {
 

	
 
			if (!IsValidChar(c, this->qs->afilter)) return;
 

	
 
			if (this->qs->text.InsertChar(c)) this->InvalidateParent();
 
			if (this->qs->text.InsertChar(c)) this->OnEditboxChanged(WID_OSK_TEXT);
 

	
 
			if (HasBit(_keystate, KEYS_SHIFT)) {
 
				ToggleBit(_keystate, KEYS_SHIFT);
 
@@ -135,7 +135,7 @@ struct OskWindow : public Window {
 

	
 
		switch (widget) {
 
			case WID_OSK_BACKSPACE:
 
				if (this->qs->text.DeleteChar(WKC_BACKSPACE)) this->InvalidateParent();
 
				if (this->qs->text.DeleteChar(WKC_BACKSPACE)) this->OnEditboxChanged(WID_OSK_TEXT);
 
				break;
 

	
 
			case WID_OSK_SPECIAL:
 
@@ -159,15 +159,15 @@ struct OskWindow : public Window {
 
				break;
 

	
 
			case WID_OSK_SPACE:
 
				if (this->qs->text.InsertChar(' ')) this->InvalidateParent();
 
				if (this->qs->text.InsertChar(' ')) this->OnEditboxChanged(WID_OSK_TEXT);
 
				break;
 

	
 
			case WID_OSK_LEFT:
 
				if (this->qs->text.MovePos(WKC_LEFT)) this->InvalidateParent();
 
				if (this->qs->text.MovePos(WKC_LEFT)) this->InvalidateData();
 
				break;
 

	
 
			case WID_OSK_RIGHT:
 
				if (this->qs->text.MovePos(WKC_RIGHT)) this->InvalidateParent();
 
				if (this->qs->text.MovePos(WKC_RIGHT)) this->InvalidateData();
 
				break;
 

	
 
			case WID_OSK_OK:
 
@@ -190,7 +190,7 @@ struct OskWindow : public Window {
 
				} else { // or reset to original string
 
					qs->text.Assign(this->orig_str_buf);
 
					qs->text.MovePos(WKC_END);
 
					this->InvalidateParent();
 
					this->OnEditboxChanged(WID_OSK_TEXT);
 
					delete this;
 
				}
 
				break;
 
@@ -200,12 +200,11 @@ struct OskWindow : public Window {
 
		SetFocusedWindow(this->parent);
 
	}
 

	
 
	void InvalidateParent()
 
	virtual void OnEditboxChanged(int widget)
 
	{
 
		this->SetWidgetDirty(WID_OSK_TEXT);
 
		this->parent->OnEditboxChanged(this->text_btn);
 

	
 
		this->SetWidgetDirty(WID_OSK_TEXT);
 
		if (this->parent != NULL) this->parent->SetWidgetDirty(this->text_btn);
 
		this->parent->SetWidgetDirty(this->text_btn);
 
	}
 

	
 
	virtual void OnMouseLoop()
 
@@ -224,6 +223,7 @@ struct OskWindow : public Window {
 
	{
 
		if (!gui_scope) return;
 
		this->SetWidgetDirty(WID_OSK_TEXT);
 
		this->parent->SetWidgetDirty(this->text_btn);
 
	}
 
};
 

	
src/querystring_gui.h
Show inline comments
 
@@ -21,10 +21,11 @@
 
 */
 
enum HandleEditBoxResult
 
{
 
	HEBR_EDITING = 0, // Other key pressed.
 
	HEBR_CONFIRM,     // Return or enter key pressed.
 
	HEBR_CANCEL,      // Escape key pressed.
 
	HEBR_NOT_FOCUSED, // Edit box widget not focused.
 
	HEBR_EDITING,     ///< Editbox content changed.
 
	HEBR_CURSOR,      ///< Non-text change, e.g. cursor position.
 
	HEBR_CONFIRM,     ///< Return or enter key pressed.
 
	HEBR_CANCEL,      ///< Escape key pressed.
 
	HEBR_NOT_FOCUSED, ///< Edit box widget not focused.
 
};
 

	
 
/**
src/window.cpp
Show inline comments
 
@@ -2269,9 +2269,14 @@ EventState Window::HandleEditBoxKey(int 
 

	
 
	switch (query->HandleEditBoxKey(this, wid, key, keycode, state)) {
 
		case HEBR_EDITING:
 
			this->SetWidgetDirty(wid);
 
			this->OnEditboxChanged(wid);
 
			break;
 

	
 
		case HEBR_CURSOR:
 
			this->SetWidgetDirty(wid);
 
			break;
 

	
 
		case HEBR_CONFIRM:
 
			if (query->ok_button >= 0) {
 
				this->OnClick(Point(), query->ok_button, 1);
0 comments (0 inline, 0 general)