mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 18:40:29 +00:00
(svn r25411) -Add: Window::OnHotkey
This commit is contained in:
parent
1b8b1f3f6c
commit
6291383823
@ -86,7 +86,7 @@ char *_windows_file;
|
|||||||
/** Window description constructor. */
|
/** Window description constructor. */
|
||||||
WindowDesc::WindowDesc(WindowPosition def_pos, const char *ini_key, int16 def_width, int16 def_height,
|
WindowDesc::WindowDesc(WindowPosition def_pos, const char *ini_key, int16 def_width, int16 def_height,
|
||||||
WindowClass window_class, WindowClass parent_class, uint32 flags,
|
WindowClass window_class, WindowClass parent_class, uint32 flags,
|
||||||
const NWidgetPart *nwid_parts, int16 nwid_length) :
|
const NWidgetPart *nwid_parts, int16 nwid_length, HotkeyList *hotkeys) :
|
||||||
default_pos(def_pos),
|
default_pos(def_pos),
|
||||||
default_width(def_width),
|
default_width(def_width),
|
||||||
default_height(def_height),
|
default_height(def_height),
|
||||||
@ -96,6 +96,7 @@ WindowDesc::WindowDesc(WindowPosition def_pos, const char *ini_key, int16 def_wi
|
|||||||
flags(flags),
|
flags(flags),
|
||||||
nwid_parts(nwid_parts),
|
nwid_parts(nwid_parts),
|
||||||
nwid_length(nwid_length),
|
nwid_length(nwid_length),
|
||||||
|
hotkeys(hotkeys),
|
||||||
pref_sticky(false),
|
pref_sticky(false),
|
||||||
pref_width(0),
|
pref_width(0),
|
||||||
pref_height(0)
|
pref_height(0)
|
||||||
@ -468,6 +469,29 @@ void Window::SetWidgetDirty(byte widget_index) const
|
|||||||
this->nested_array[widget_index]->SetDirty(this);
|
this->nested_array[widget_index]->SetDirty(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A hotkey has been pressed.
|
||||||
|
* @param hotkey Hotkey index, by default a widget index of a button or editbox.
|
||||||
|
* @return #ES_HANDLED if the key press has been handled, and the hotkey is not unavailable for some reason.
|
||||||
|
*/
|
||||||
|
EventState Window::OnHotkey(int hotkey)
|
||||||
|
{
|
||||||
|
if (hotkey < 0) return ES_NOT_HANDLED;
|
||||||
|
|
||||||
|
NWidgetCore *nw = this->GetWidget<NWidgetCore>(hotkey);
|
||||||
|
if (nw == NULL || nw->IsDisabled()) return ES_NOT_HANDLED;
|
||||||
|
|
||||||
|
if (nw->type == WWT_EDITBOX) {
|
||||||
|
/* Focus editbox */
|
||||||
|
this->SetFocusedWidget(hotkey);
|
||||||
|
SetFocusedWindow(this);
|
||||||
|
} else {
|
||||||
|
/* Click button */
|
||||||
|
this->OnClick(Point(), hotkey, 1);
|
||||||
|
}
|
||||||
|
return ES_HANDLED;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do all things to make a button look clicked and mark it to be
|
* Do all things to make a button look clicked and mark it to be
|
||||||
* unclicked in a few ticks.
|
* unclicked in a few ticks.
|
||||||
@ -2456,12 +2480,22 @@ void HandleKeypress(uint32 raw_key)
|
|||||||
Window *w;
|
Window *w;
|
||||||
FOR_ALL_WINDOWS_FROM_FRONT(w) {
|
FOR_ALL_WINDOWS_FROM_FRONT(w) {
|
||||||
if (w->window_class == WC_MAIN_TOOLBAR) continue;
|
if (w->window_class == WC_MAIN_TOOLBAR) continue;
|
||||||
|
if (w->window_desc->hotkeys != NULL) {
|
||||||
|
int hotkey = w->window_desc->hotkeys->CheckMatch(keycode);
|
||||||
|
if (hotkey >= 0 && w->OnHotkey(hotkey) == ES_HANDLED) return;
|
||||||
|
}
|
||||||
if (w->OnKeyPress(key, keycode) == ES_HANDLED) return;
|
if (w->OnKeyPress(key, keycode) == ES_HANDLED) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
w = FindWindowById(WC_MAIN_TOOLBAR, 0);
|
w = FindWindowById(WC_MAIN_TOOLBAR, 0);
|
||||||
/* When there is no toolbar w is null, check for that */
|
/* When there is no toolbar w is null, check for that */
|
||||||
if (w != NULL && w->OnKeyPress(key, keycode) == ES_HANDLED) return;
|
if (w != NULL) {
|
||||||
|
if (w->window_desc->hotkeys != NULL) {
|
||||||
|
int hotkey = w->window_desc->hotkeys->CheckMatch(keycode);
|
||||||
|
if (hotkey >= 0 && w->OnHotkey(hotkey) == ES_HANDLED) return;
|
||||||
|
}
|
||||||
|
if (w->OnKeyPress(key, keycode) == ES_HANDLED) return;
|
||||||
|
}
|
||||||
|
|
||||||
HandleGlobalHotkeys(key, keycode);
|
HandleGlobalHotkeys(key, keycode);
|
||||||
}
|
}
|
||||||
|
@ -167,6 +167,8 @@ enum WindowPosition {
|
|||||||
|
|
||||||
Point GetToolbarAlignedWindowPosition(int window_width);
|
Point GetToolbarAlignedWindowPosition(int window_width);
|
||||||
|
|
||||||
|
struct HotkeyList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* High level window description
|
* High level window description
|
||||||
*/
|
*/
|
||||||
@ -174,7 +176,7 @@ struct WindowDesc : ZeroedMemoryAllocator {
|
|||||||
|
|
||||||
WindowDesc(WindowPosition default_pos, const char *ini_key, int16 def_width, int16 def_height,
|
WindowDesc(WindowPosition default_pos, const char *ini_key, int16 def_width, int16 def_height,
|
||||||
WindowClass window_class, WindowClass parent_class, uint32 flags,
|
WindowClass window_class, WindowClass parent_class, uint32 flags,
|
||||||
const NWidgetPart *nwid_parts, int16 nwid_length);
|
const NWidgetPart *nwid_parts, int16 nwid_length, HotkeyList *hotkeys = NULL);
|
||||||
|
|
||||||
~WindowDesc();
|
~WindowDesc();
|
||||||
|
|
||||||
@ -187,6 +189,7 @@ struct WindowDesc : ZeroedMemoryAllocator {
|
|||||||
uint32 flags; ///< Flags. @see WindowDefaultFlag
|
uint32 flags; ///< Flags. @see WindowDefaultFlag
|
||||||
const NWidgetPart *nwid_parts; ///< Nested widget parts describing the window.
|
const NWidgetPart *nwid_parts; ///< Nested widget parts describing the window.
|
||||||
int16 nwid_length; ///< Length of the #nwid_parts array.
|
int16 nwid_length; ///< Length of the #nwid_parts array.
|
||||||
|
HotkeyList *hotkeys; ///< Hotkeys for the window.
|
||||||
|
|
||||||
bool pref_sticky; ///< Preferred stickyness.
|
bool pref_sticky; ///< Preferred stickyness.
|
||||||
int16 pref_width; ///< User-preferred width of the window. Zero if unset.
|
int16 pref_width; ///< User-preferred width of the window. Zero if unset.
|
||||||
@ -598,6 +601,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual EventState OnKeyPress(uint16 key, uint16 keycode) { return ES_NOT_HANDLED; }
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode) { return ES_NOT_HANDLED; }
|
||||||
|
|
||||||
|
virtual EventState OnHotkey(int hotkey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The state of the control key has changed
|
* The state of the control key has changed
|
||||||
* @return #ES_HANDLED if the change has been handled and no other
|
* @return #ES_HANDLED if the change has been handled and no other
|
||||||
|
Loading…
Reference in New Issue
Block a user