(svn r24743) -Change: Unify the behaviour of ESC in filter editboxes.

pull/155/head
frosch 12 years ago
parent 18dcd2e6a4
commit 7b3d6cc31f

@ -418,6 +418,7 @@ public:
this->GetWidget<NWidgetStacked>(WID_NCL_SEL_ALL_UPDATE)->SetDisplayedPlane(select_all); this->GetWidget<NWidgetStacked>(WID_NCL_SEL_ALL_UPDATE)->SetDisplayedPlane(select_all);
this->querystrings[WID_NCL_FILTER] = &this->filter_editbox; this->querystrings[WID_NCL_FILTER] = &this->filter_editbox;
this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
this->filter_editbox.afilter = CS_ALPHANUMERAL; this->filter_editbox.afilter = CS_ALPHANUMERAL;
this->SetFocusedWidget(WID_NCL_FILTER); this->SetFocusedWidget(WID_NCL_FILTER);

@ -639,6 +639,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
this->FinishInitNested(desc, WN_GAME_OPTIONS_NEWGRF_STATE); this->FinishInitNested(desc, WN_GAME_OPTIONS_NEWGRF_STATE);
this->querystrings[WID_NS_FILTER] = &this->filter_editbox; this->querystrings[WID_NS_FILTER] = &this->filter_editbox;
this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
this->SetFocusedWidget(WID_NS_FILTER); this->SetFocusedWidget(WID_NS_FILTER);
this->avails.SetListing(this->last_sorting); this->avails.SetListing(this->last_sorting);

@ -31,6 +31,11 @@ enum HandleEditBoxResult
* Data stored about a string that can be modified in the GUI * Data stored about a string that can be modified in the GUI
*/ */
struct QueryString { struct QueryString {
/* Special actions when hitting ENTER or ESC. (only keyboard, not OSK) */
static const int ACTION_NOTHING = -1; ///< Nothing.
static const int ACTION_DESELECT = -2; ///< Deselect editbox.
static const int ACTION_CLEAR = -3; ///< Clear editbox.
StringID caption; StringID caption;
int ok_button; ///< Widget button of parent window to simulate when pressing OK in OSK. 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. int cancel_button; ///< Widget button of parent window to simulate when pressing CANCEL in OSK.
@ -44,7 +49,7 @@ struct QueryString {
* @param size Maximum size in bytes. * @param size Maximum size in bytes.
* @param chars Maximum size in chars. * @param chars Maximum size in chars.
*/ */
QueryString(uint16 size, uint16 chars = UINT16_MAX) : ok_button(-1), cancel_button(-1), text(size, chars), orig(NULL) QueryString(uint16 size, uint16 chars = UINT16_MAX) : ok_button(ACTION_NOTHING), cancel_button(ACTION_DESELECT), text(size, chars), orig(NULL)
{ {
} }

@ -2004,6 +2004,7 @@ struct GameSettingsWindow : Window {
this->FinishInitNested(desc, WN_GAME_OPTIONS_GAME_SETTINGS); this->FinishInitNested(desc, WN_GAME_OPTIONS_GAME_SETTINGS);
this->querystrings[WID_GS_FILTER] = &this->filter_editbox; this->querystrings[WID_GS_FILTER] = &this->filter_editbox;
this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
this->SetFocusedWidget(WID_GS_FILTER); this->SetFocusedWidget(WID_GS_FILTER);
this->InvalidateData(); this->InvalidateData();

@ -159,7 +159,7 @@ struct SignListWindow : Window, SignList {
/* Initialize the text edit widget */ /* Initialize the text edit widget */
this->querystrings[WID_SIL_FILTER_TEXT] = &this->filter_editbox; this->querystrings[WID_SIL_FILTER_TEXT] = &this->filter_editbox;
this->filter_editbox.ok_button = WID_SIL_FILTER_ENTER_BTN; this->filter_editbox.ok_button = WID_SIL_FILTER_ENTER_BTN;
this->filter_editbox.cancel_button = WID_SIL_FILTER_CLEAR_BTN; this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
this->filter_editbox.afilter = CS_ALPHANUMERAL; this->filter_editbox.afilter = CS_ALPHANUMERAL;
/* Initialize the filtering variables */ /* Initialize the filtering variables */

@ -2265,6 +2265,8 @@ EventState Window::HandleEditBoxKey(int wid, uint16 key, uint16 keycode)
QueryString *query = this->GetQueryString(wid); QueryString *query = this->GetQueryString(wid);
if (query == NULL) return state; if (query == NULL) return state;
int action = QueryString::ACTION_NOTHING;
switch (query->HandleEditBoxKey(this, wid, key, keycode, state)) { switch (query->HandleEditBoxKey(this, wid, key, keycode, state)) {
case HEBR_EDITING: case HEBR_EDITING:
this->OnEditboxChanged(wid); this->OnEditboxChanged(wid);
@ -2273,6 +2275,8 @@ EventState Window::HandleEditBoxKey(int wid, uint16 key, uint16 keycode)
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);
} else {
action = query->ok_button;
} }
break; break;
@ -2280,13 +2284,28 @@ EventState Window::HandleEditBoxKey(int wid, uint16 key, uint16 keycode)
if (query->cancel_button >= 0) { if (query->cancel_button >= 0) {
this->OnClick(Point(), query->cancel_button, 1); this->OnClick(Point(), query->cancel_button, 1);
} else { } else {
this->UnfocusFocusedWidget(); action = query->cancel_button;
} }
break; break;
default: break; default: break;
} }
switch (action) {
case QueryString::ACTION_DESELECT:
this->UnfocusFocusedWidget();
break;
case QueryString::ACTION_CLEAR:
query->text.DeleteAll();
this->SetWidgetDirty(wid);
this->OnEditboxChanged(wid);
break;
default:
break;
}
return state; return state;
} }

Loading…
Cancel
Save