summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/misc_gui.cpp12
-rw-r--r--src/network/network_chat_gui.cpp7
-rw-r--r--src/network/network_gui.cpp7
-rw-r--r--src/osk_gui.cpp22
-rw-r--r--src/querystring_gui.h12
-rw-r--r--src/signs_gui.cpp7
-rw-r--r--src/window.cpp2
7 files changed, 20 insertions, 49 deletions
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index 97d218d71..f3f8f5190 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -824,11 +824,6 @@ HandleEditBoxResult QueryStringBaseWindow::HandleEditBoxKey(int wid, uint16 key,
return result;
}
-void QueryStringBaseWindow::OnOpenOSKWindow(int wid)
-{
- ShowOnScreenKeyboard(this, wid, -1, -1);
-}
-
/** Class for the string query window. */
struct QueryStringWindow : public QueryStringBaseWindow
{
@@ -849,6 +844,8 @@ struct QueryStringWindow : public QueryStringBaseWindow
if ((flags & QSF_ACCEPT_UNCHANGED) == 0) this->orig = strdup(this->edit_str_buf);
this->caption = caption;
+ this->cancel_button = WID_QS_CANCEL;
+ this->ok_button = WID_QS_OK;
this->afilter = afilter;
this->flags = flags;
this->text.Initialize(this->edit_str_buf, max_bytes, max_chars);
@@ -917,11 +914,6 @@ struct QueryStringWindow : public QueryStringBaseWindow
return state;
}
- virtual void OnOpenOSKWindow(int wid)
- {
- ShowOnScreenKeyboard(this, wid, WID_QS_CANCEL, WID_QS_OK);
- }
-
~QueryStringWindow()
{
if (!this->handled && this->parent != NULL) {
diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp
index a6a63703d..4c1551347 100644
--- a/src/network/network_chat_gui.cpp
+++ b/src/network/network_chat_gui.cpp
@@ -299,6 +299,8 @@ struct NetworkChatWindow : public QueryStringBaseWindow {
{
this->dtype = type;
this->dest = dest;
+ this->cancel_button = WID_NC_CLOSE;
+ this->ok_button = WID_NC_SENDBUTTON;
this->afilter = CS_ALPHANUMERAL;
this->text.Initialize(this->edit_str_buf, this->edit_str_size);
@@ -521,11 +523,6 @@ struct NetworkChatWindow : public QueryStringBaseWindow {
return state;
}
- virtual void OnOpenOSKWindow(int wid)
- {
- ShowOnScreenKeyboard(this, wid, WID_NC_CLOSE, WID_NC_SENDBUTTON);
- }
-
/**
* Some data on this window has become invalid.
* @param data Information about the changed data.
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 0174497bd..94c2e3805 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -2123,6 +2123,8 @@ struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow {
this->InitNested(desc, 0);
this->parent = parent;
+ this->cancel_button = WID_NCP_CANCEL;
+ this->ok_button = WID_NCP_OK;
this->afilter = CS_ALPHANUMERAL;
this->text.Initialize(this->edit_str_buf, this->edit_str_size);
this->SetFocusedWidget(WID_NCP_PASSWORD);
@@ -2171,11 +2173,6 @@ struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow {
}
return state;
}
-
- virtual void OnOpenOSKWindow(int wid)
- {
- ShowOnScreenKeyboard(this, wid, WID_NCP_CANCEL, WID_NCP_OK);
- }
};
static const NWidgetPart _nested_network_company_password_window_widgets[] = {
diff --git a/src/osk_gui.cpp b/src/osk_gui.cpp
index 2b1ebf75d..2dadb88cd 100644
--- a/src/osk_gui.cpp
+++ b/src/osk_gui.cpp
@@ -36,13 +36,11 @@ struct OskWindow : public Window {
StringID caption; ///< the caption for this window.
QueryString *qs; ///< text-input
int text_btn; ///< widget number of parent's text field
- int ok_btn; ///< widget number of parent's ok button (-1 when ok shouldn't be passed on)
- int cancel_btn; ///< widget number of parent's cancel button (-1 when cancel shouldn't be passed on; text will be reverted to original)
Textbuf *text; ///< pointer to parent's textbuffer (to update caret position)
char *orig_str_buf; ///< Original string.
bool shift; ///< Is the shift effectively pressed?
- OskWindow(const WindowDesc *desc, QueryStringBaseWindow *parent, int button, int cancel, int ok) : Window()
+ OskWindow(const WindowDesc *desc, QueryStringBaseWindow *parent, int button) : Window()
{
this->parent = parent;
assert(parent != NULL);
@@ -53,8 +51,6 @@ struct OskWindow : public Window {
this->qs = parent;
this->text_btn = button;
- this->cancel_btn = cancel;
- this->ok_btn = ok;
this->text = &parent->text;
/* make a copy in case we need to reset later */
@@ -177,8 +173,8 @@ struct OskWindow : public Window {
case WID_OSK_OK:
if (this->qs->orig == NULL || strcmp(this->qs->text.buf, this->qs->orig) != 0) {
/* pass information by simulating a button press on parent window */
- if (this->ok_btn >= 0) {
- this->parent->OnClick(pt, this->ok_btn, 1);
+ if (this->qs->ok_button >= 0) {
+ this->parent->OnClick(pt, this->qs->ok_button, 1);
/* Window gets deleted when the parent window removes itself. */
return;
}
@@ -187,8 +183,8 @@ struct OskWindow : public Window {
break;
case WID_OSK_CANCEL:
- if (this->cancel_btn >= 0) { // pass a cancel event to the parent window
- this->parent->OnClick(pt, this->cancel_btn, 1);
+ if (this->qs->cancel_button >= 0) { // pass a cancel event to the parent window
+ this->parent->OnClick(pt, this->qs->cancel_button, 1);
/* Window gets deleted when the parent window removes itself. */
return;
} else { // or reset to original string
@@ -428,17 +424,13 @@ void GetKeyboardLayout()
* Show the on-screen keyboard (osk) associated with a given textbox
* @param parent pointer to the Window where this keyboard originated from
* @param button widget number of parent's textbox
- * @param cancel widget number of parent's cancel button (-1 if cancel events
- * should not be passed)
- * @param ok widget number of parent's ok button (-1 if ok events should not
- * be passed)
*/
-void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button, int cancel, int ok)
+void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button)
{
DeleteWindowById(WC_OSK, 0);
GetKeyboardLayout();
- new OskWindow(&_osk_desc, parent, button, cancel, ok);
+ new OskWindow(&_osk_desc, parent, button);
}
/**
diff --git a/src/querystring_gui.h b/src/querystring_gui.h
index 5c1156546..554d6ccb2 100644
--- a/src/querystring_gui.h
+++ b/src/querystring_gui.h
@@ -32,6 +32,8 @@ enum HandleEditBoxResult
*/
struct QueryString {
StringID caption;
+ int ok_button; ///< Widget button of parent window to simulate when pressing OK in OSK.
+ int cancel_button; ///< Widget button of parent window to simulate when pressing CANCEL in OSK.
Textbuf text;
const char *orig;
CharSetFilter afilter;
@@ -40,7 +42,7 @@ struct QueryString {
/**
* Make sure everything gets initialized properly.
*/
- QueryString() : orig(NULL)
+ QueryString() : ok_button(-1), cancel_button(-1), orig(NULL)
{
}
@@ -79,19 +81,13 @@ struct QueryStringBaseWindow : public Window, public QueryString {
HandleEditBoxResult HandleEditBoxKey(int wid, uint16 key, uint16 keycode, EventState &state);
/**
- * Callback for when the OSK window is opened.
- * @param wid The widget the OSK is opened of.
- */
- virtual void OnOpenOSKWindow(int wid);
-
- /**
* Callback for when on input has been entered with the OSK.
* @param wid The widget the OSK was attached to.
*/
virtual void OnOSKInput(int wid) {}
};
-void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button, int cancel, int ok);
+void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button);
void UpdateOSKOriginalText(const QueryStringBaseWindow *parent, int button);
#endif /* QUERYSTRING_GUI_H */
diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp
index 1089a2f87..1cb5e8621 100644
--- a/src/signs_gui.cpp
+++ b/src/signs_gui.cpp
@@ -446,6 +446,8 @@ struct SignWindow : QueryStringBaseWindow, SignList {
SignWindow(const WindowDesc *desc, const Sign *si) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
{
this->caption = STR_EDIT_SIGN_CAPTION;
+ this->cancel_button = WID_QES_CANCEL;
+ this->ok_button = WID_QES_OK;
this->afilter = CS_ALPHANUMERAL;
this->InitNested(desc, WN_QUERY_STRING_SIGN);
@@ -562,11 +564,6 @@ struct SignWindow : QueryStringBaseWindow, SignList {
}
return state;
}
-
- virtual void OnOpenOSKWindow(int wid)
- {
- ShowOnScreenKeyboard(this, wid, WID_QES_CANCEL, WID_QES_OK);
- }
};
static const NWidgetPart _nested_query_sign_edit_widgets[] = {
diff --git a/src/window.cpp b/src/window.cpp
index 0ef7f8007..b7741be30 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -452,7 +452,7 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
/* Open the OSK window if clicked on an edit box */
QueryStringBaseWindow *qs = dynamic_cast<QueryStringBaseWindow *>(w);
if (qs != NULL) {
- qs->OnOpenOSKWindow(widget_index);
+ ShowOnScreenKeyboard(qs, widget_index);
}
}
break;