mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 23:50:25 +00:00
(svn r13151) -Codechange: use an enum instead of bool as return type of OnKeyPress/OnCTRLStateChange to make it obvious what the return values mean.
This commit is contained in:
parent
c1713c9ab7
commit
f5681547ef
@ -121,16 +121,16 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
const uint8 i = keycode - '1';
|
const uint8 i = keycode - '1';
|
||||||
if (i < 9 && i < this->bridges->list_length) {
|
if (i < 9 && i < this->bridges->list_length) {
|
||||||
/* Build the requested bridge */
|
/* Build the requested bridge */
|
||||||
this->BuildBridge(i);
|
this->BuildBridge(i);
|
||||||
delete this;
|
delete this;
|
||||||
return false;
|
return ES_HANDLED;
|
||||||
}
|
}
|
||||||
return true;
|
return ES_NOT_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnClick(Point pt, int widget)
|
virtual void OnClick(Point pt, int widget)
|
||||||
|
@ -126,7 +126,7 @@ struct IConsoleWindow : Window
|
|||||||
if (HandleCaret(&_iconsole_cmdline)) this->SetDirty();
|
if (HandleCaret(&_iconsole_cmdline)) this->SetDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
case WKC_UP:
|
case WKC_UP:
|
||||||
@ -230,10 +230,10 @@ struct IConsoleWindow : Window
|
|||||||
IConsoleResetHistoryPos();
|
IConsoleResetHistoryPos();
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return ES_NOT_HANDLED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return ES_HANDLED;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -961,14 +961,14 @@ struct DepotWindow : Window {
|
|||||||
ResizeDepotButtons(this);
|
ResizeDepotButtons(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnCTRLStateChange()
|
virtual EventState OnCTRLStateChange()
|
||||||
{
|
{
|
||||||
if (this->sel != INVALID_VEHICLE) {
|
if (this->sel != INVALID_VEHICLE) {
|
||||||
_cursor.vehchain = _ctrl_pressed;
|
_cursor.vehchain = _ctrl_pressed;
|
||||||
this->InvalidateWidget(DEPOT_WIDGET_MATRIX);
|
this->InvalidateWidget(DEPOT_WIDGET_MATRIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return ES_HANDLED;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -470,17 +470,17 @@ struct GenerateLandscapeWindow : public QueryStringBaseWindow {
|
|||||||
this->HandleEditBox(GLAND_RANDOM_EDITBOX);
|
this->HandleEditBox(GLAND_RANDOM_EDITBOX);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
bool cont;
|
EventState state;
|
||||||
this->HandleEditBoxKey(GLAND_RANDOM_EDITBOX, key, keycode, cont);
|
this->HandleEditBoxKey(GLAND_RANDOM_EDITBOX, key, keycode, state);
|
||||||
/* the seed is unsigned, therefore atoi cannot be used.
|
/* the seed is unsigned, therefore atoi cannot be used.
|
||||||
* As 2^32 - 1 (MAX_UVALUE(uint32)) is a 'magic' value
|
* As 2^32 - 1 (MAX_UVALUE(uint32)) is a 'magic' value
|
||||||
* (use random seed) it should not be possible to be
|
* (use random seed) it should not be possible to be
|
||||||
* entered into the input field; the generate seed
|
* entered into the input field; the generate seed
|
||||||
* button can be used instead. */
|
* button can be used instead. */
|
||||||
_patches_newgame.generation_seed = minu(strtoul(this->edit_str_buf, NULL, sizeof(this->edit_str_buf) - 1), MAX_UVALUE(uint32) - 1);
|
_patches_newgame.generation_seed = minu(strtoul(this->edit_str_buf, NULL, sizeof(this->edit_str_buf) - 1), MAX_UVALUE(uint32) - 1);
|
||||||
return cont;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnDropdownSelect(int widget, int index)
|
virtual void OnDropdownSelect(int widget, int index)
|
||||||
|
@ -239,34 +239,34 @@ struct MainWindow : Window
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
case 'Q' | WKC_CTRL:
|
case 'Q' | WKC_CTRL:
|
||||||
case 'Q' | WKC_META:
|
case 'Q' | WKC_META:
|
||||||
HandleExitGameRequest();
|
HandleExitGameRequest();
|
||||||
return true;
|
return ES_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable all key shortcuts, except quit shortcuts when
|
/* Disable all key shortcuts, except quit shortcuts when
|
||||||
* generating the world, otherwise they create threading
|
* generating the world, otherwise they create threading
|
||||||
* problem during the generating, resulting in random
|
* problem during the generating, resulting in random
|
||||||
* assertions that are hard to trigger and debug */
|
* assertions that are hard to trigger and debug */
|
||||||
if (IsGeneratingWorld()) return true;
|
if (IsGeneratingWorld()) return ES_NOT_HANDLED;
|
||||||
|
|
||||||
if (keycode == WKC_BACKQUOTE) {
|
if (keycode == WKC_BACKQUOTE) {
|
||||||
IConsoleSwitch();
|
IConsoleSwitch();
|
||||||
return false;
|
return ES_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keycode == ('B' | WKC_CTRL)) {
|
if (keycode == ('B' | WKC_CTRL)) {
|
||||||
extern bool _draw_bounding_boxes;
|
extern bool _draw_bounding_boxes;
|
||||||
_draw_bounding_boxes = !_draw_bounding_boxes;
|
_draw_bounding_boxes = !_draw_bounding_boxes;
|
||||||
MarkWholeScreenDirty();
|
MarkWholeScreenDirty();
|
||||||
return false;
|
return ES_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_game_mode == GM_MENU) return true;
|
if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
|
||||||
|
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
case 'C':
|
case 'C':
|
||||||
@ -372,9 +372,9 @@ struct MainWindow : Window
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default: return true;
|
default: return ES_NOT_HANDLED;
|
||||||
}
|
}
|
||||||
return false;
|
return ES_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnScroll(Point delta)
|
virtual void OnScroll(Point delta)
|
||||||
|
@ -412,11 +412,11 @@ public:
|
|||||||
_switch_mode_errorstr = INVALID_STRING_ID;
|
_switch_mode_errorstr = INVALID_STRING_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
if (keycode != WKC_SPACE) return true;
|
if (keycode != WKC_SPACE) return ES_NOT_HANDLED;
|
||||||
delete this;
|
delete this;
|
||||||
return false;
|
return ES_HANDLED;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -883,9 +883,9 @@ bool HandleCaret(Textbuf *tb)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, bool &cont)
|
int QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, Window::EventState &state)
|
||||||
{
|
{
|
||||||
cont = false;
|
state = Window::ES_HANDLED;
|
||||||
|
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
case WKC_ESC: return 2;
|
case WKC_ESC: return 2;
|
||||||
@ -913,7 +913,7 @@ int QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode
|
|||||||
if (IsValidChar(key, this->afilter)) {
|
if (IsValidChar(key, this->afilter)) {
|
||||||
if (InsertTextBufferChar(&this->text, key)) w->InvalidateWidget(wid);
|
if (InsertTextBufferChar(&this->text, key)) w->InvalidateWidget(wid);
|
||||||
} else { // key wasn't caught. Continue only if standard entry specified
|
} else { // key wasn't caught. Continue only if standard entry specified
|
||||||
cont = (this->afilter == CS_ALPHANUMERAL);
|
state = (this->afilter == CS_ALPHANUMERAL) ? Window::ES_HANDLED : Window::ES_NOT_HANDLED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -963,9 +963,9 @@ void QueryString::DrawEditBox(Window *w, int wid)
|
|||||||
_cur_dpi = old_dpi;
|
_cur_dpi = old_dpi;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QueryStringBaseWindow::HandleEditBoxKey(int wid, uint16 key, uint16 keycode, bool &cont)
|
int QueryStringBaseWindow::HandleEditBoxKey(int wid, uint16 key, uint16 keycode, EventState &state)
|
||||||
{
|
{
|
||||||
return this->QueryString::HandleEditBoxKey(this, wid, key, keycode, cont);
|
return this->QueryString::HandleEditBoxKey(this, wid, key, keycode, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueryStringBaseWindow::HandleEditBox(int wid)
|
void QueryStringBaseWindow::HandleEditBox(int wid)
|
||||||
@ -1038,15 +1038,15 @@ struct QueryStringWindow : public QueryStringBaseWindow
|
|||||||
this->HandleEditBox(QUERY_STR_WIDGET_TEXT);
|
this->HandleEditBox(QUERY_STR_WIDGET_TEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
bool cont;
|
EventState state;
|
||||||
switch (this->HandleEditBoxKey(QUERY_STR_WIDGET_TEXT, key, keycode, cont)) {
|
switch (this->HandleEditBoxKey(QUERY_STR_WIDGET_TEXT, key, keycode, state)) {
|
||||||
case 1: this->OnOk(); // Enter pressed, confirms change
|
case 1: this->OnOk(); // Enter pressed, confirms change
|
||||||
/* FALL THROUGH */
|
/* FALL THROUGH */
|
||||||
case 2: delete this; break; // ESC pressed, closes window, abandons changes
|
case 2: delete this; break; // ESC pressed, closes window, abandons changes
|
||||||
}
|
}
|
||||||
return cont;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
~QueryStringWindow()
|
~QueryStringWindow()
|
||||||
@ -1174,7 +1174,7 @@ struct QueryWindow : public Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
/* ESC closes the window, Enter confirms the action */
|
/* ESC closes the window, Enter confirms the action */
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
@ -1187,9 +1187,9 @@ struct QueryWindow : public Window {
|
|||||||
/* Fallthrough */
|
/* Fallthrough */
|
||||||
case WKC_ESC:
|
case WKC_ESC:
|
||||||
delete this;
|
delete this;
|
||||||
return false;
|
return ES_HANDLED;
|
||||||
}
|
}
|
||||||
return true;
|
return ES_NOT_HANDLED;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1523,20 +1523,20 @@ struct SaveLoadWindow : public QueryStringBaseWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
if (keycode == WKC_ESC) {
|
if (keycode == WKC_ESC) {
|
||||||
delete this;
|
delete this;
|
||||||
return false;
|
return ES_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cont = true;
|
EventState state = ES_NOT_HANDLED;
|
||||||
if ((_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) &&
|
if ((_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) &&
|
||||||
this->HandleEditBoxKey(10, key, keycode, cont) == 1) { // Press Enter
|
this->HandleEditBoxKey(10, key, keycode, state) == 1) { // Press Enter
|
||||||
this->HandleButtonClick(12);
|
this->HandleButtonClick(12);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cont;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnTimeout()
|
virtual void OnTimeout()
|
||||||
|
@ -543,9 +543,9 @@ struct NetworkGameWindow : public QueryStringBaseWindow {
|
|||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
bool cont = true;
|
EventState state = ES_NOT_HANDLED;
|
||||||
if (this->field != NGWW_PLAYER) {
|
if (this->field != NGWW_PLAYER) {
|
||||||
if (this->server != NULL) {
|
if (this->server != NULL) {
|
||||||
if (keycode == WKC_DELETE) { // Press 'delete' to remove servers
|
if (keycode == WKC_DELETE) { // Press 'delete' to remove servers
|
||||||
@ -554,10 +554,10 @@ struct NetworkGameWindow : public QueryStringBaseWindow {
|
|||||||
this->server = NULL;
|
this->server = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cont;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->HandleEditBoxKey(NGWW_PLAYER, keycode, key, cont) == 1) return cont; // enter pressed
|
if (this->HandleEditBoxKey(NGWW_PLAYER, keycode, key, state) == 1) return state; // enter pressed
|
||||||
|
|
||||||
/* The name is only allowed when it starts with a letter! */
|
/* The name is only allowed when it starts with a letter! */
|
||||||
if (StrEmpty(this->edit_str_buf) && this->edit_str_buf[0] != ' ') {
|
if (StrEmpty(this->edit_str_buf) && this->edit_str_buf[0] != ' ') {
|
||||||
@ -565,7 +565,7 @@ struct NetworkGameWindow : public QueryStringBaseWindow {
|
|||||||
} else {
|
} else {
|
||||||
ttd_strlcpy(_network_player_name, "Player", lengthof(_network_player_name));
|
ttd_strlcpy(_network_player_name, "Player", lengthof(_network_player_name));
|
||||||
}
|
}
|
||||||
return cont;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnQueryTextFinished(char *str)
|
virtual void OnQueryTextFinished(char *str)
|
||||||
@ -892,16 +892,16 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow {
|
|||||||
if (this->field == NSSW_GAMENAME) this->HandleEditBox(NSSW_GAMENAME);
|
if (this->field == NSSW_GAMENAME) this->HandleEditBox(NSSW_GAMENAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
bool cont = true;
|
EventState state = ES_NOT_HANDLED;
|
||||||
if (this->field == NSSW_GAMENAME) {
|
if (this->field == NSSW_GAMENAME) {
|
||||||
if (this->HandleEditBoxKey(NSSW_GAMENAME, key, keycode, cont) == 1) return cont; // enter pressed
|
if (this->HandleEditBoxKey(NSSW_GAMENAME, key, keycode, state) == 1) return state; // enter pressed
|
||||||
|
|
||||||
ttd_strlcpy(_network_server_name, this->text.buf, sizeof(_network_server_name));
|
ttd_strlcpy(_network_server_name, this->text.buf, sizeof(_network_server_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
return cont;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnQueryTextFinished(char *str)
|
virtual void OnQueryTextFinished(char *str)
|
||||||
@ -1878,21 +1878,21 @@ struct NetworkChatWindow : public QueryStringBaseWindow {
|
|||||||
this->HandleEditBox(2);
|
this->HandleEditBox(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
bool cont = true;
|
EventState state = ES_NOT_HANDLED;
|
||||||
if (keycode == WKC_TAB) {
|
if (keycode == WKC_TAB) {
|
||||||
ChatTabCompletion();
|
ChatTabCompletion();
|
||||||
} else {
|
} else {
|
||||||
_chat_tab_completion_active = false;
|
_chat_tab_completion_active = false;
|
||||||
switch (this->HandleEditBoxKey(2, key, keycode, cont)) {
|
switch (this->HandleEditBoxKey(2, key, keycode, state)) {
|
||||||
case 1: /* Return */
|
case 1: /* Return */
|
||||||
SendChat(this->text.buf, this->dtype, this->dest);
|
SendChat(this->text.buf, this->dtype, this->dest);
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
case 2: /* Escape */ delete this; break;
|
case 2: /* Escape */ delete this; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cont;
|
return state;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1985,10 +1985,10 @@ struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow {
|
|||||||
this->HandleEditBox(4);
|
this->HandleEditBox(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
bool cont;
|
EventState state;
|
||||||
switch (this->HandleEditBoxKey(4, key, keycode, cont)) {
|
switch (this->HandleEditBoxKey(4, key, keycode, state)) {
|
||||||
case 1: // Return
|
case 1: // Return
|
||||||
this->OnOk();
|
this->OnOk();
|
||||||
/* FALL THROUGH */
|
/* FALL THROUGH */
|
||||||
@ -1997,7 +1997,7 @@ struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow {
|
|||||||
delete this;
|
delete this;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return cont;
|
return state;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -308,14 +308,14 @@ struct NewsWindow : Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
if (keycode == WKC_SPACE) {
|
if (keycode == WKC_SPACE) {
|
||||||
/* Don't continue. */
|
/* Don't continue. */
|
||||||
delete this;
|
delete this;
|
||||||
return false;
|
return ES_HANDLED;
|
||||||
}
|
}
|
||||||
return true;
|
return ES_NOT_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnInvalidateData(int data)
|
virtual void OnInvalidateData(int data)
|
||||||
|
@ -926,7 +926,7 @@ public:
|
|||||||
ResetObjectToPlace();
|
ResetObjectToPlace();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
static const KeyToEvent keytoevent[] = {
|
static const KeyToEvent keytoevent[] = {
|
||||||
{'D', OrderClick_Skip},
|
{'D', OrderClick_Skip},
|
||||||
@ -939,15 +939,15 @@ public:
|
|||||||
//('?', OrderClick_Service},
|
//('?', OrderClick_Service},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this->vehicle->owner != _local_player) return true;
|
if (this->vehicle->owner != _local_player) return ES_NOT_HANDLED;
|
||||||
|
|
||||||
for (uint i = 0; i < lengthof(keytoevent); i++) {
|
for (uint i = 0; i < lengthof(keytoevent); i++) {
|
||||||
if (keycode == keytoevent[i].keycode) {
|
if (keycode == keytoevent[i].keycode) {
|
||||||
keytoevent[i].proc(this, -1);
|
keytoevent[i].proc(this, -1);
|
||||||
return false;
|
return ES_HANDLED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return ES_NOT_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnPlaceObject(Point pt, TileIndex tile)
|
virtual void OnPlaceObject(Point pt, TileIndex tile)
|
||||||
|
@ -17,7 +17,7 @@ struct QueryString {
|
|||||||
|
|
||||||
void DrawEditBox(Window *w, int wid);
|
void DrawEditBox(Window *w, int wid);
|
||||||
void HandleEditBox(Window *w, int wid);
|
void HandleEditBox(Window *w, int wid);
|
||||||
int HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, bool &cont);
|
int HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, Window::EventState &state);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct QueryStringBaseWindow : public Window, public QueryString {
|
struct QueryStringBaseWindow : public Window, public QueryString {
|
||||||
@ -30,7 +30,7 @@ struct QueryStringBaseWindow : public Window, public QueryString {
|
|||||||
|
|
||||||
void DrawEditBox(int wid);
|
void DrawEditBox(int wid);
|
||||||
void HandleEditBox(int wid);
|
void HandleEditBox(int wid);
|
||||||
int HandleEditBoxKey(int wid, uint16 key, uint16 keycode, bool &cont);
|
int HandleEditBoxKey(int wid, uint16 key, uint16 keycode, EventState &state);
|
||||||
};
|
};
|
||||||
|
|
||||||
void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button, int cancel, int ok);
|
void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button, int cancel, int ok);
|
||||||
|
@ -255,10 +255,10 @@ struct SignWindow : QueryStringBaseWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
bool cont = true;
|
EventState state = ES_NOT_HANDLED;
|
||||||
switch (this->HandleEditBoxKey(QUERY_EDIT_SIGN_WIDGET_TEXT, key, keycode, cont)) {
|
switch (this->HandleEditBoxKey(QUERY_EDIT_SIGN_WIDGET_TEXT, key, keycode, state)) {
|
||||||
case 1: // Enter pressed, confirms change
|
case 1: // Enter pressed, confirms change
|
||||||
RenameSign(this->cur_sign, this->text.buf);
|
RenameSign(this->cur_sign, this->text.buf);
|
||||||
/* FALL THROUGH */
|
/* FALL THROUGH */
|
||||||
@ -267,7 +267,7 @@ struct SignWindow : QueryStringBaseWindow {
|
|||||||
delete this;
|
delete this;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return cont;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnMouseLoop()
|
virtual void OnMouseLoop()
|
||||||
|
@ -68,7 +68,7 @@ void Window::OnPaint()
|
|||||||
this->HandleWindowEvent(&e);
|
this->HandleWindowEvent(&e);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::OnKeyPress(uint16 key, uint16 keycode)
|
Window::EventState Window::OnKeyPress(uint16 key, uint16 keycode)
|
||||||
{
|
{
|
||||||
WindowEvent e;
|
WindowEvent e;
|
||||||
e.event = WE_KEYPRESS;
|
e.event = WE_KEYPRESS;
|
||||||
@ -77,17 +77,17 @@ bool Window::OnKeyPress(uint16 key, uint16 keycode)
|
|||||||
e.we.keypress.cont = true;
|
e.we.keypress.cont = true;
|
||||||
this->HandleWindowEvent(&e);
|
this->HandleWindowEvent(&e);
|
||||||
|
|
||||||
return e.we.keypress.cont;
|
return e.we.keypress.cont ? ES_NOT_HANDLED : ES_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::OnCTRLStateChange()
|
Window::EventState Window::OnCTRLStateChange()
|
||||||
{
|
{
|
||||||
WindowEvent e;
|
WindowEvent e;
|
||||||
e.event = WE_CTRL_CHANGED;
|
e.event = WE_CTRL_CHANGED;
|
||||||
e.we.ctrl.cont = true;
|
e.we.ctrl.cont = true;
|
||||||
this->HandleWindowEvent(&e);
|
this->HandleWindowEvent(&e);
|
||||||
|
|
||||||
return e.we.ctrl.cont;
|
return e.we.ctrl.cont ? ES_NOT_HANDLED : ES_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::OnClick(Point pt, int widget)
|
void Window::OnClick(Point pt, int widget)
|
||||||
@ -1802,8 +1802,7 @@ void HandleKeypress(uint32 raw_key)
|
|||||||
w->window_class != WC_COMPANY_PASSWORD_WINDOW) {
|
w->window_class != WC_COMPANY_PASSWORD_WINDOW) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
;
|
if (w->OnKeyPress(key, keycode) == Window::ES_HANDLED) return;
|
||||||
if (!w->OnKeyPress(key, keycode)) return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
|
Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
|
||||||
@ -1819,7 +1818,7 @@ void HandleCtrlChanged()
|
|||||||
/* Call the event, start with the uppermost window. */
|
/* Call the event, start with the uppermost window. */
|
||||||
for (Window* const *wz = _last_z_window; wz != _z_windows;) {
|
for (Window* const *wz = _last_z_window; wz != _z_windows;) {
|
||||||
Window *w = *--wz;
|
Window *w = *--wz;
|
||||||
if (!w->OnCTRLStateChange()) break;
|
if (w->OnCTRLStateChange() == Window::ES_HANDLED) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,6 +266,11 @@ struct ViewportData : ViewPort {
|
|||||||
* Data structure for an opened window
|
* Data structure for an opened window
|
||||||
*/
|
*/
|
||||||
struct Window : ZeroedMemoryAllocator {
|
struct Window : ZeroedMemoryAllocator {
|
||||||
|
enum EventState {
|
||||||
|
ES_HANDLED,
|
||||||
|
ES_NOT_HANDLED,
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WindowProc *wndproc; ///< Event handler function for the window. Do not use directly, call HandleWindowEvent() instead.
|
WindowProc *wndproc; ///< Event handler function for the window. Do not use directly, call HandleWindowEvent() instead.
|
||||||
void HandleWindowEvent(WindowEvent *e);
|
void HandleWindowEvent(WindowEvent *e);
|
||||||
@ -345,17 +350,17 @@ public:
|
|||||||
* A key has been pressed.
|
* A key has been pressed.
|
||||||
* @param key the Unicode value of the key.
|
* @param key the Unicode value of the key.
|
||||||
* @param keycode the untranslated key code including shift state.
|
* @param keycode the untranslated key code including shift state.
|
||||||
* @return true if the key press has been handled and no other
|
* @return ES_HANDLED if the key press has been handled and no other
|
||||||
* window should receive the event.
|
* window should receive the event.
|
||||||
*/
|
*/
|
||||||
virtual bool OnKeyPress(uint16 key, uint16 keycode);
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The state of the control key has changed
|
* The state of the control key has changed
|
||||||
* @return true if the change has been handled and no other
|
* @return ES_HANDLED if the change has been handled and no other
|
||||||
* window should receive the event.
|
* window should receive the event.
|
||||||
*/
|
*/
|
||||||
virtual bool OnCTRLStateChange();
|
virtual EventState OnCTRLStateChange();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user