mirror of https://github.com/OpenTTD/OpenTTD
(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.
parent
2ab6fffccc
commit
ba3d7e70f2
|
@ -120,7 +120,7 @@ struct OskWindow : public Window {
|
||||||
|
|
||||||
if (!IsValidChar(c, this->qs->afilter)) return;
|
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)) {
|
if (HasBit(_keystate, KEYS_SHIFT)) {
|
||||||
ToggleBit(_keystate, KEYS_SHIFT);
|
ToggleBit(_keystate, KEYS_SHIFT);
|
||||||
|
@ -130,11 +130,9 @@ struct OskWindow : public Window {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool delete_this = false;
|
|
||||||
|
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case OSK_WIDGET_BACKSPACE:
|
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;
|
break;
|
||||||
|
|
||||||
case OSK_WIDGET_SPECIAL:
|
case OSK_WIDGET_SPECIAL:
|
||||||
|
@ -156,15 +154,15 @@ struct OskWindow : public Window {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OSK_WIDGET_SPACE:
|
case OSK_WIDGET_SPACE:
|
||||||
if (InsertTextBufferChar(&this->qs->text, ' ')) this->InvalidateWidget(OSK_WIDGET_TEXT);
|
if (InsertTextBufferChar(&this->qs->text, ' ')) this->InvalidateParent();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OSK_WIDGET_LEFT:
|
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;
|
break;
|
||||||
|
|
||||||
case OSK_WIDGET_RIGHT:
|
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;
|
break;
|
||||||
|
|
||||||
case OSK_WIDGET_OK:
|
case OSK_WIDGET_OK:
|
||||||
|
@ -176,7 +174,7 @@ struct OskWindow : public Window {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete_this = true;
|
delete this;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OSK_WIDGET_CANCEL:
|
case OSK_WIDGET_CANCEL:
|
||||||
|
@ -188,13 +186,20 @@ struct OskWindow : public Window {
|
||||||
strcpy(qs->text.buf, this->orig_str_buf);
|
strcpy(qs->text.buf, this->orig_str_buf);
|
||||||
UpdateTextBufferSize(&qs->text);
|
UpdateTextBufferSize(&qs->text);
|
||||||
MoveTextBufferPos(&qs->text, WKC_END);
|
MoveTextBufferPos(&qs->text, WKC_END);
|
||||||
delete_this = true;
|
this->InvalidateParent();
|
||||||
|
delete this;
|
||||||
}
|
}
|
||||||
break;
|
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 (this->parent != NULL) this->parent->InvalidateWidget(this->text_btn);
|
||||||
if (delete_this) delete this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnMouseLoop()
|
virtual void OnMouseLoop()
|
||||||
|
|
|
@ -68,6 +68,7 @@ struct QueryStringBaseWindow : public Window, public QueryString {
|
||||||
void HandleEditBox(int wid);
|
void HandleEditBox(int wid);
|
||||||
HandleEditBoxResult HandleEditBoxKey(int wid, uint16 key, uint16 keycode, EventState &state);
|
HandleEditBoxResult HandleEditBoxKey(int wid, uint16 key, uint16 keycode, EventState &state);
|
||||||
virtual void OnOpenOSKWindow(int wid);
|
virtual void OnOpenOSKWindow(int wid);
|
||||||
|
virtual void OnOSKInput(int wid) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button, int cancel, int ok);
|
void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button, int cancel, int ok);
|
||||||
|
|
Loading…
Reference in New Issue