From f93fe544c5707b9d3e3296e6e77a342331ac1a85 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Thu, 21 May 2015 18:51:08 +0200 Subject: [PATCH] Allow wxPG to take focus on the entire area even if wxPG is not a standalone control. By default, to prevent wxPG from stealing focus from other controls, focus is moved to the grid only if it was already in one of its child controls. When newly introduced wxPG_EX_ALWAYS_ALLOW_FOCUS flag is set then wxPG can take focus on the entire grid area (on canvas) even if focus is moved from another control. Default wxPG behavior remains unchanged because wxPG_EX_ALWAYS_ALLOW_FOCUS flag must be explicitly set with wxPropertyGrid::SetExtraStyle function. Closes #16993. (cherry picked from commit 7394dd8e1f37003eec31c2c937e50ddcf44cee9f) --- include/wx/propgrid/propgrid.h | 12 +++++++++++- src/propgrid/manager.cpp | 2 +- src/propgrid/propgrid.cpp | 32 +++++++++++++++++++++----------- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/include/wx/propgrid/propgrid.h b/include/wx/propgrid/propgrid.h index 9b12b2eb71..1c7ac2a4cb 100644 --- a/include/wx/propgrid/propgrid.h +++ b/include/wx/propgrid/propgrid.h @@ -311,8 +311,18 @@ wxPG_EX_NO_TOOLBAR_DIVIDER = 0x08000000, /** Show a separator below the toolbar. */ -wxPG_EX_TOOLBAR_SEPARATOR = 0x10000000 +wxPG_EX_TOOLBAR_SEPARATOR = 0x10000000, +#if wxABI_VERSION >= 30003 +/** Allows to take focus on the entire area (on canvas) + even if wxPropertyGrid is not a standalone control. +*/ +wxPG_EX_ALWAYS_ALLOW_FOCUS = 0x00100000, +#endif // 3.0.3+ + +/** A mask which can be used to filter (out) all extra styles. +*/ +wxPG_EX_WINDOW_STYLE_MASK = 0x1FFFF000 }; #if wxPG_COMPATIBILITY_1_4 diff --git a/src/propgrid/manager.cpp b/src/propgrid/manager.cpp index ed0f5108fd..bca4605835 100644 --- a/src/propgrid/manager.cpp +++ b/src/propgrid/manager.cpp @@ -670,7 +670,7 @@ bool wxPropertyGridManager::SetFont( const wxFont& font ) void wxPropertyGridManager::SetExtraStyle( long exStyle ) { wxWindow::SetExtraStyle( exStyle ); - m_pPropGrid->SetExtraStyle( exStyle & 0xFFFFF000 ); + m_pPropGrid->SetExtraStyle( exStyle & wxPG_EX_WINDOW_STYLE_MASK ); #if wxUSE_TOOLBAR if ( (exStyle & wxPG_EX_NO_FLAT_TOOLBAR) && m_pToolbar ) RecreateControls(); diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 20c823d163..c3d4278bd8 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -4650,21 +4650,31 @@ void wxPropertyGrid::SetVirtualWidth( int width ) void wxPropertyGrid::SetFocusOnCanvas() { - // To prevent wxPropertyGrid from stealing focus from other controls, - // only move focus to the grid if it was already in one if its child - // controls. - wxWindow* focus = wxWindow::FindFocus(); - if ( focus ) + // By default, to prevent wxPropertyGrid from stealing focus from + // other controls, only move focus to the grid if it was already + // in one of its child controls. + // If wxPG_EX_ALWAYS_ALLOW_FOCUS flag is set then wxPropertyGrid + // can take focus on the entire grid area (canvas) even if focus + // is moved from another control. + if ( HasExtraStyle(wxPG_EX_ALWAYS_ALLOW_FOCUS) ) { - wxWindow* parent = focus->GetParent(); - while ( parent ) + SetFocus(); + } + else + { + wxWindow* focus = wxWindow::FindFocus(); + if ( focus ) { - if ( parent == this ) + wxWindow* parent = focus->GetParent(); + while ( parent ) { - SetFocus(); - break; + if ( parent == this ) + { + SetFocus(); + break; + } + parent = parent->GetParent(); } - parent = parent->GetParent(); } }