Merge branch 'mac-native-focus-ring' of https://github.com/vslavik/wxWidgets

Draw wxTextCtrl focus ring natively on Mac.

Add wxWindow::EnableVisibleFocus() to explicitly control the focus ring
visibility if necessary.

See https://github.com/wxWidgets/wxWidgets/pull/2037
This commit is contained in:
Vadim Zeitlin
2020-09-01 14:59:42 +02:00
10 changed files with 33 additions and 38 deletions

View File

@@ -460,10 +460,6 @@ void wxGridCellTextEditor::DoCreate(wxWindow* parent,
text->SetMargins(0, 0);
m_control = text;
#ifdef __WXOSX__
wxWidgetImpl* impl = m_control->GetPeer();
impl->SetNeedsFocusRect(false);
#endif
// set max length allowed in the textctrl, if the parameter was set
if ( m_maxChars != 0 )
{

View File

@@ -1590,7 +1590,6 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
v = [[wxNSTextScrollView alloc] initWithFrame:r];
wxNSTextViewControl* t = new wxNSTextViewControl( wxpeer, v, style );
c = t;
c->SetNeedsFocusRect( true );
t->SetStringValue(str);
}

View File

@@ -3849,10 +3849,6 @@ void wxWidgetCocoaImpl::DoNotifyFocusLost()
void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow)
{
wxWindow* thisWindow = GetWXPeer();
if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
{
thisWindow->MacInvalidateBorders();
}
if ( receivedFocus )
{
@@ -3925,6 +3921,11 @@ void wxWidgetCocoaImpl::SetFlipped(bool flipped)
#endif
void wxWidgetCocoaImpl::EnableFocusRing(bool enabled)
{
[m_osxView setFocusRingType:enabled ? NSFocusRingTypeExterior : NSFocusRingTypeNone];
}
void wxWidgetCocoaImpl::SetDrawingEnabled(bool enabled)
{
if ( [m_osxView window] == nil )

View File

@@ -642,10 +642,6 @@ void wxWidgetIPhoneImpl::InstallEventHandler( WXWidget control )
void wxWidgetIPhoneImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow)
{
wxWindow* thisWindow = GetWXPeer();
if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
{
thisWindow->MacInvalidateBorders();
}
if ( receivedFocus )
{

View File

@@ -938,9 +938,6 @@ void wxWindowMac::MacInvalidateBorders()
int outerBorder = MacGetLeftBorderSize() ;
if ( GetPeer()->NeedsFocusRect() )
outerBorder += 4 ;
if ( outerBorder == 0 )
return ;
@@ -1578,8 +1575,6 @@ void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(right
#if wxOSX_USE_COCOA_OR_CARBON
{
const bool hasFocus = GetPeer()->NeedsFocusRect() && HasFocus();
CGRect cgrect = CGRectMake( tx-1 , ty-1 , tw+2 ,
th+2 ) ;
@@ -1594,7 +1589,6 @@ void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(right
info.version = 0 ;
info.kind = 0 ;
info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
info.isFocused = hasFocus ;
if ( HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
{
@@ -1607,11 +1601,6 @@ void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(right
HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
}
}
if ( hasFocus )
{
HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
}
}
#endif // wxOSX_USE_COCOA_OR_CARBON
}
@@ -2182,6 +2171,11 @@ bool wxWindowMac::AcceptsFocus() const
return GetPeer()->CanFocus();
}
void wxWindowMac::EnableVisibleFocus(bool enabled)
{
GetPeer()->EnableFocusRing(enabled);
}
void wxWindowMac::MacSuperChangedPosition()
{
// only window-absolute structures have to be moved i.e. controls
@@ -2746,20 +2740,9 @@ void wxWidgetImpl::Init()
m_wantsUserKey = false;
m_wantsUserMouse = false;
m_wxPeer = NULL;
m_needsFocusRect = false;
m_needsFrame = true;
}
void wxWidgetImpl::SetNeedsFocusRect( bool needs )
{
m_needsFocusRect = needs;
}
bool wxWidgetImpl::NeedsFocusRect() const
{
return m_needsFocusRect;
}
void wxWidgetImpl::SetNeedsFrame( bool needs )
{
m_needsFrame = needs;