Add wxWindow::DisableFocusFromKeyboard()

This allows to easily exclude a window from the TAB chain.

Closes https://github.com/wxWidgets/wxWidgets/pull/1516
This commit is contained in:
Tomay
2019-08-29 01:47:37 +01:00
committed by Vadim Zeitlin
parent e5fb5a290c
commit bbdd5b4984
3 changed files with 21 additions and 2 deletions

View File

@@ -728,7 +728,11 @@ public:
// can this window be given focus by keyboard navigation? if not, the
// only way to give it focus (provided it accepts it at all) is to
// click it
virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
virtual bool AcceptsFocusFromKeyboard() const
{ return !m_disableFocusFromKbd && AcceptsFocus(); }
// Disable any input focus from the keyboard
void DisableFocusFromKeyboard() { m_disableFocusFromKbd = true; }
// Can this window be focused right now, in its current state? This
@@ -1733,6 +1737,9 @@ protected:
bool m_inheritFgCol:1;
bool m_inheritFont:1;
// flag disabling accepting focus from keyboard
bool m_disableFocusFromKbd:1;
// window attributes
long m_windowStyle,
m_exStyle;
@@ -1929,7 +1936,6 @@ private:
// (i.e. not being updated) if it is positive
unsigned int m_freezeCount;
wxDECLARE_ABSTRACT_CLASS(wxWindowBase);
wxDECLARE_NO_COPY_CLASS(wxWindowBase);
wxDECLARE_EVENT_TABLE();

View File

@@ -487,6 +487,17 @@ public:
*/
virtual bool AcceptsFocusRecursively() const;
/**
Disable giving focus to this window using the keyboard navigation keys.
Pressing @c TAB key will skip this window if this function was called
on it, but it will still be possible to focus it by clicking on it with
a pointing device.
@since 3.1.4
*/
void DisableFocusFromKeyboard();
/**
Can this window itself have focus?
*/

View File

@@ -320,6 +320,8 @@ wxWindowBase::wxWindowBase()
m_containingSizer = NULL;
m_autoLayout = false;
m_disableFocusFromKbd = true;
#if wxUSE_DRAG_AND_DROP
m_dropTarget = NULL;
#endif // wxUSE_DRAG_AND_DROP