Changeset - r19776:433be3248044
[Not reviewed]
master
0 7 0
frosch - 12 years ago 2012-11-13 21:46:54
frosch@openttd.org
(svn r24731) -Codechange: Remove OnOpenOSKWindow and instead specify OK and CANCEL buttons via QueryString members.
7 files changed with 20 insertions and 49 deletions:
0 comments (0 inline, 0 general)
src/misc_gui.cpp
Show inline comments
 
@@ -824,11 +824,6 @@ HandleEditBoxResult QueryStringBaseWindo
 
	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 QueryS
 
		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 QueryS
 
		return state;
 
	}
 

	
 
	virtual void OnOpenOSKWindow(int wid)
 
	{
 
		ShowOnScreenKeyboard(this, wid, WID_QS_CANCEL, WID_QS_OK);
 
	}
 

	
 
	~QueryStringWindow()
 
	{
 
		if (!this->handled && this->parent != NULL) {
src/network/network_chat_gui.cpp
Show inline comments
 
@@ -299,6 +299,8 @@ struct NetworkChatWindow : public QueryS
 
	{
 
		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 QueryS
 
		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.
src/network/network_gui.cpp
Show inline comments
 
@@ -2123,6 +2123,8 @@ struct NetworkCompanyPasswordWindow : pu
 
		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 : pu
 
		}
 
		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[] = {
src/osk_gui.cpp
Show inline comments
 
@@ -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);
 
}
 

	
 
/**
src/querystring_gui.h
Show inline comments
 
@@ -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 Wi
 
	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 */
src/signs_gui.cpp
Show inline comments
 
@@ -446,6 +446,8 @@ struct SignWindow : QueryStringBaseWindo
 
	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 : QueryStringBaseWindo
 
		}
 
		return state;
 
	}
 

	
 
	virtual void OnOpenOSKWindow(int wid)
 
	{
 
		ShowOnScreenKeyboard(this, wid, WID_QES_CANCEL, WID_QES_OK);
 
	}
 
};
 

	
 
static const NWidgetPart _nested_query_sign_edit_widgets[] = {
src/window.cpp
Show inline comments
 
@@ -452,7 +452,7 @@ static void DispatchLeftClickEvent(Windo
 
				/* 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;
0 comments (0 inline, 0 general)