mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r24735) -Codechange: Move HandleEditBoxKey to Window class.
This commit is contained in:
parent
2c22fe98dd
commit
fc2b12acca
|
@ -811,33 +811,6 @@ void QueryString::DrawEditBox(const Window *w, int wid) const
|
||||||
_cur_dpi = old_dpi;
|
_cur_dpi = old_dpi;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventState QueryStringBaseWindow::HandleEditBoxKey(int wid, uint16 key, uint16 keycode)
|
|
||||||
{
|
|
||||||
EventState state = ES_NOT_HANDLED;
|
|
||||||
switch (this->QueryString::HandleEditBoxKey(this, wid, key, keycode, state)) {
|
|
||||||
case HEBR_EDITING:
|
|
||||||
this->OnEditboxChanged(wid);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HEBR_CONFIRM:
|
|
||||||
if (this->ok_button >= 0) {
|
|
||||||
this->OnClick(Point(), this->ok_button, 1);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HEBR_CANCEL:
|
|
||||||
if (this->cancel_button >= 0) {
|
|
||||||
this->OnClick(Point(), this->cancel_button, 1);
|
|
||||||
} else {
|
|
||||||
this->UnfocusFocusedWidget();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Class for the string query window. */
|
/** Class for the string query window. */
|
||||||
struct QueryStringWindow : public QueryStringBaseWindow
|
struct QueryStringWindow : public QueryStringBaseWindow
|
||||||
{
|
{
|
||||||
|
|
|
@ -77,8 +77,6 @@ struct QueryStringBaseWindow : public Window, public QueryString {
|
||||||
{
|
{
|
||||||
free(this->edit_str_buf);
|
free(this->edit_str_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
EventState HandleEditBoxKey(int wid, uint16 key, uint16 keycode);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button);
|
void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button);
|
||||||
|
|
|
@ -2233,6 +2233,46 @@ static bool MaybeBringWindowToFront(Window *w)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process keypress for editbox widget.
|
||||||
|
* @param wid Editbox widget.
|
||||||
|
* @param key the Unicode value of the key.
|
||||||
|
* @param keycode the untranslated key code including shift state.
|
||||||
|
* @return #ES_HANDLED if the key press has been handled and no other
|
||||||
|
* window should receive the event.
|
||||||
|
*/
|
||||||
|
EventState Window::HandleEditBoxKey(int wid, uint16 key, uint16 keycode)
|
||||||
|
{
|
||||||
|
EventState state = ES_NOT_HANDLED;
|
||||||
|
|
||||||
|
QueryString *query = dynamic_cast<QueryString*>(this);
|
||||||
|
if (query == NULL) return state;
|
||||||
|
|
||||||
|
switch (query->HandleEditBoxKey(this, wid, key, keycode, state)) {
|
||||||
|
case HEBR_EDITING:
|
||||||
|
this->OnEditboxChanged(wid);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HEBR_CONFIRM:
|
||||||
|
if (query->ok_button >= 0) {
|
||||||
|
this->OnClick(Point(), query->ok_button, 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HEBR_CANCEL:
|
||||||
|
if (query->cancel_button >= 0) {
|
||||||
|
this->OnClick(Point(), query->cancel_button, 1);
|
||||||
|
} else {
|
||||||
|
this->UnfocusFocusedWidget();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle keyboard input.
|
* Handle keyboard input.
|
||||||
* @param raw_key Lower 8 bits contain the ASCII character, the higher 16 bits the keycode
|
* @param raw_key Lower 8 bits contain the ASCII character, the higher 16 bits the keycode
|
||||||
|
@ -2267,8 +2307,7 @@ void HandleKeypress(uint32 raw_key)
|
||||||
if (_focused_window->window_class == WC_CONSOLE) {
|
if (_focused_window->window_class == WC_CONSOLE) {
|
||||||
if (_focused_window->OnKeyPress(key, keycode) == ES_HANDLED) return;
|
if (_focused_window->OnKeyPress(key, keycode) == ES_HANDLED) return;
|
||||||
} else {
|
} else {
|
||||||
QueryStringBaseWindow *query = dynamic_cast<QueryStringBaseWindow*>(_focused_window);
|
if (_focused_window->HandleEditBoxKey(_focused_window->nested_focus->index, key, keycode) == ES_HANDLED) return;
|
||||||
if (query != NULL && query->HandleEditBoxKey(_focused_window->nested_focus->index, key, keycode) == ES_HANDLED) return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -458,6 +458,8 @@ public:
|
||||||
void UnfocusFocusedWidget();
|
void UnfocusFocusedWidget();
|
||||||
bool SetFocusedWidget(byte widget_index);
|
bool SetFocusedWidget(byte widget_index);
|
||||||
|
|
||||||
|
EventState HandleEditBoxKey(int wid, uint16 key, uint16 keycode);
|
||||||
|
|
||||||
void HandleButtonClick(byte widget);
|
void HandleButtonClick(byte widget);
|
||||||
int GetRowFromWidget(int clickpos, int widget, int padding, int line_height = -1) const;
|
int GetRowFromWidget(int clickpos, int widget, int padding, int line_height = -1) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue