mirror of https://github.com/OpenTTD/OpenTTD
(svn r24772) -Codechange: Call Window::OnEditboxChanged only when the content changes, not when only moving the cursor.
parent
4c0671f65a
commit
155a9d784c
|
@ -719,6 +719,8 @@ HandleEditBoxResult QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key
|
||||||
|
|
||||||
state = ES_HANDLED;
|
state = ES_HANDLED;
|
||||||
|
|
||||||
|
bool edited = false;
|
||||||
|
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
case WKC_ESC: return HEBR_CANCEL;
|
case WKC_ESC: return HEBR_CANCEL;
|
||||||
|
|
||||||
|
@ -728,7 +730,7 @@ HandleEditBoxResult QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key
|
||||||
case (WKC_META | 'V'):
|
case (WKC_META | 'V'):
|
||||||
#endif
|
#endif
|
||||||
case (WKC_CTRL | 'V'):
|
case (WKC_CTRL | 'V'):
|
||||||
if (this->text.InsertClipboard()) w->SetWidgetDirty(wid);
|
edited = this->text.InsertClipboard();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef WITH_COCOA
|
#ifdef WITH_COCOA
|
||||||
|
@ -736,22 +738,22 @@ HandleEditBoxResult QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key
|
||||||
#endif
|
#endif
|
||||||
case (WKC_CTRL | 'U'):
|
case (WKC_CTRL | 'U'):
|
||||||
this->text.DeleteAll();
|
this->text.DeleteAll();
|
||||||
w->SetWidgetDirty(wid);
|
edited = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WKC_BACKSPACE: case WKC_DELETE:
|
case WKC_BACKSPACE: case WKC_DELETE:
|
||||||
case WKC_CTRL | WKC_BACKSPACE: case WKC_CTRL | 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;
|
break;
|
||||||
|
|
||||||
case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME:
|
case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME:
|
||||||
case WKC_CTRL | WKC_LEFT: case WKC_CTRL | WKC_RIGHT:
|
case WKC_CTRL | WKC_LEFT: case WKC_CTRL | WKC_RIGHT:
|
||||||
if (this->text.MovePos(keycode)) w->SetWidgetDirty(wid);
|
this->text.MovePos(keycode);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (IsValidChar(key, this->afilter)) {
|
if (IsValidChar(key, this->afilter)) {
|
||||||
if (this->text.InsertChar(key)) w->SetWidgetDirty(wid);
|
edited = this->text.InsertChar(key);
|
||||||
} else {
|
} else {
|
||||||
state = ES_NOT_HANDLED;
|
state = ES_NOT_HANDLED;
|
||||||
}
|
}
|
||||||
|
@ -760,7 +762,7 @@ HandleEditBoxResult QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key
|
||||||
Window *osk = FindWindowById(WC_OSK, 0);
|
Window *osk = FindWindowById(WC_OSK, 0);
|
||||||
if (osk != NULL && osk->parent == w) osk->InvalidateData();
|
if (osk != NULL && osk->parent == w) osk->InvalidateData();
|
||||||
|
|
||||||
return HEBR_EDITING;
|
return edited ? HEBR_EDITING : HEBR_CURSOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueryString::HandleEditBox(Window *w, int wid)
|
void QueryString::HandleEditBox(Window *w, int wid)
|
||||||
|
|
|
@ -120,7 +120,7 @@ struct OskWindow : public Window {
|
||||||
|
|
||||||
if (!IsValidChar(c, this->qs->afilter)) return;
|
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)) {
|
if (HasBit(_keystate, KEYS_SHIFT)) {
|
||||||
ToggleBit(_keystate, KEYS_SHIFT);
|
ToggleBit(_keystate, KEYS_SHIFT);
|
||||||
|
@ -135,7 +135,7 @@ struct OskWindow : public Window {
|
||||||
|
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_OSK_BACKSPACE:
|
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;
|
break;
|
||||||
|
|
||||||
case WID_OSK_SPECIAL:
|
case WID_OSK_SPECIAL:
|
||||||
|
@ -159,15 +159,15 @@ struct OskWindow : public Window {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_OSK_SPACE:
|
case WID_OSK_SPACE:
|
||||||
if (this->qs->text.InsertChar(' ')) this->InvalidateParent();
|
if (this->qs->text.InsertChar(' ')) this->OnEditboxChanged(WID_OSK_TEXT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_OSK_LEFT:
|
case WID_OSK_LEFT:
|
||||||
if (this->qs->text.MovePos(WKC_LEFT)) this->InvalidateParent();
|
if (this->qs->text.MovePos(WKC_LEFT)) this->InvalidateData();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_OSK_RIGHT:
|
case WID_OSK_RIGHT:
|
||||||
if (this->qs->text.MovePos(WKC_RIGHT)) this->InvalidateParent();
|
if (this->qs->text.MovePos(WKC_RIGHT)) this->InvalidateData();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_OSK_OK:
|
case WID_OSK_OK:
|
||||||
|
@ -190,7 +190,7 @@ struct OskWindow : public Window {
|
||||||
} else { // or reset to original string
|
} else { // or reset to original string
|
||||||
qs->text.Assign(this->orig_str_buf);
|
qs->text.Assign(this->orig_str_buf);
|
||||||
qs->text.MovePos(WKC_END);
|
qs->text.MovePos(WKC_END);
|
||||||
this->InvalidateParent();
|
this->OnEditboxChanged(WID_OSK_TEXT);
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -200,12 +200,11 @@ struct OskWindow : public Window {
|
||||||
SetFocusedWindow(this->parent);
|
SetFocusedWindow(this->parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InvalidateParent()
|
virtual void OnEditboxChanged(int widget)
|
||||||
{
|
{
|
||||||
this->parent->OnEditboxChanged(this->text_btn);
|
|
||||||
|
|
||||||
this->SetWidgetDirty(WID_OSK_TEXT);
|
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()
|
virtual void OnMouseLoop()
|
||||||
|
@ -224,6 +223,7 @@ struct OskWindow : public Window {
|
||||||
{
|
{
|
||||||
if (!gui_scope) return;
|
if (!gui_scope) return;
|
||||||
this->SetWidgetDirty(WID_OSK_TEXT);
|
this->SetWidgetDirty(WID_OSK_TEXT);
|
||||||
|
this->parent->SetWidgetDirty(this->text_btn);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,11 @@
|
||||||
*/
|
*/
|
||||||
enum HandleEditBoxResult
|
enum HandleEditBoxResult
|
||||||
{
|
{
|
||||||
HEBR_EDITING = 0, // Other key pressed.
|
HEBR_EDITING, ///< Editbox content changed.
|
||||||
HEBR_CONFIRM, // Return or enter key pressed.
|
HEBR_CURSOR, ///< Non-text change, e.g. cursor position.
|
||||||
HEBR_CANCEL, // Escape key pressed.
|
HEBR_CONFIRM, ///< Return or enter key pressed.
|
||||||
HEBR_NOT_FOCUSED, // Edit box widget not focused.
|
HEBR_CANCEL, ///< Escape key pressed.
|
||||||
|
HEBR_NOT_FOCUSED, ///< Edit box widget not focused.
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2269,9 +2269,14 @@ EventState Window::HandleEditBoxKey(int wid, uint16 key, uint16 keycode)
|
||||||
|
|
||||||
switch (query->HandleEditBoxKey(this, wid, key, keycode, state)) {
|
switch (query->HandleEditBoxKey(this, wid, key, keycode, state)) {
|
||||||
case HEBR_EDITING:
|
case HEBR_EDITING:
|
||||||
|
this->SetWidgetDirty(wid);
|
||||||
this->OnEditboxChanged(wid);
|
this->OnEditboxChanged(wid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case HEBR_CURSOR:
|
||||||
|
this->SetWidgetDirty(wid);
|
||||||
|
break;
|
||||||
|
|
||||||
case HEBR_CONFIRM:
|
case HEBR_CONFIRM:
|
||||||
if (query->ok_button >= 0) {
|
if (query->ok_button >= 0) {
|
||||||
this->OnClick(Point(), query->ok_button, 1);
|
this->OnClick(Point(), query->ok_button, 1);
|
||||||
|
|
Loading…
Reference in New Issue