diff options
-rw-r--r-- | src/misc_gui.cpp | 14 | ||||
-rw-r--r-- | src/osk_gui.cpp | 20 | ||||
-rw-r--r-- | src/querystring_gui.h | 9 | ||||
-rw-r--r-- | src/window.cpp | 5 |
4 files changed, 28 insertions, 20 deletions
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index c47f62998..a94e49a3b 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -719,6 +719,8 @@ HandleEditBoxResult QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key state = ES_HANDLED; + bool edited = false; + switch (keycode) { case WKC_ESC: return HEBR_CANCEL; @@ -728,7 +730,7 @@ HandleEditBoxResult QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key 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::HandleEditBoxKey(Window *w, int wid, uint16 key #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::HandleEditBoxKey(Window *w, int wid, uint16 key 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) diff --git a/src/osk_gui.cpp b/src/osk_gui.cpp index 5265d3e2d..a7b4848fc 100644 --- a/src/osk_gui.cpp +++ b/src/osk_gui.cpp @@ -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->parent->OnEditboxChanged(this->text_btn); - this->SetWidgetDirty(WID_OSK_TEXT); - if (this->parent != NULL) this->parent->SetWidgetDirty(this->text_btn); + this->parent->OnEditboxChanged(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); } }; diff --git a/src/querystring_gui.h b/src/querystring_gui.h index 8aea26d88..42facf70a 100644 --- a/src/querystring_gui.h +++ b/src/querystring_gui.h @@ -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. }; /** diff --git a/src/window.cpp b/src/window.cpp index 9705de0df..08f773337 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -2269,9 +2269,14 @@ EventState Window::HandleEditBoxKey(int wid, uint16 key, uint16 keycode) 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); |