separate non-native key handling from IsUserPane

NSOpenGLView is needed under 10.14 as a native view, but it doesn’t have its own native key handling, therefore use the same code we have for non-native custom views.
This commit is contained in:
Stefan Csomor
2019-01-03 13:26:50 +01:00
parent 155a19a1a2
commit a29ea16ccd
5 changed files with 51 additions and 10 deletions

View File

@@ -50,6 +50,7 @@ class WXDLLIMPEXP_FWD_CORE wxDialog;
class WXDLLIMPEXP_CORE wxWidgetCocoaImpl : public wxWidgetImpl
{
public :
wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl, bool isUserPane, bool wantsUserKey ) ;
wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl = false, bool isUserPane = false ) ;
wxWidgetCocoaImpl() ;
~wxWidgetCocoaImpl();

View File

@@ -216,6 +216,7 @@ protected :
class WXDLLIMPEXP_CORE wxWidgetImpl : public wxObject
{
public :
wxWidgetImpl( wxWindowMac* peer , bool isRootControl, bool isUserPane, bool wantsUserKey );
wxWidgetImpl( wxWindowMac* peer , bool isRootControl = false, bool isUserPane = false );
wxWidgetImpl();
virtual ~wxWidgetImpl();
@@ -224,8 +225,12 @@ public :
bool IsRootControl() const { return m_isRootControl; }
// is a completely control that has all events handled in wx code, no built-ins
bool IsUserPane() const { return m_isUserPane; }
// we are doing keyboard handling in wx code, other events might be handled natively
virtual bool HasUserKeyHandling() const { return m_wantsUserKey; }
wxWindowMac* GetWXPeer() const { return m_wxPeer; }
bool IsOk() const { return GetWXWidget() != NULL; }
@@ -572,6 +577,7 @@ public :
protected :
bool m_isRootControl;
bool m_isUserPane;
bool m_wantsUserKey;
wxWindowMac* m_wxPeer;
bool m_needsFocusRect;
bool m_needsFrame;

View File

@@ -140,6 +140,15 @@ WXGLPixelFormat WXGLChoosePixelFormat(const int *GLAttrs,
return YES;
}
// for special keys
- (void)doCommandBySelector:(SEL)aSelector
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl)
impl->doCommandBySelector(aSelector, self, _cmd);
}
@end
bool wxGLCanvas::DoCreate(wxWindow *parent,
@@ -149,7 +158,6 @@ bool wxGLCanvas::DoCreate(wxWindow *parent,
long style,
const wxString& name)
{
DontCreatePeer();
if ( !wxWindow::Create(parent, id, pos, size, style, name) )
@@ -159,13 +167,12 @@ bool wxGLCanvas::DoCreate(wxWindow *parent,
NSRect r = wxOSXGetFrameForControl( this, pos , size ) ;
wxNSCustomOpenGLView* v = [[wxNSCustomOpenGLView alloc] initWithFrame:r];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( this, v );
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( this, v, false, false, true /* wants key events */ );
SetPeer(c);
MacPostControlCreate(pos, size) ;
return true;
}
wxGLCanvas::~wxGLCanvas()
{
if ( m_glFormat )

View File

@@ -897,7 +897,7 @@ static void SetDrawingEnabledIfFrozenRecursive(wxWidgetCocoaImpl *impl, bool ena
- (BOOL) canBecomeKeyView
{
wxWidgetCocoaImpl* viewimpl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if ( viewimpl && viewimpl->IsUserPane() && viewimpl->GetWXPeer() )
if ( viewimpl && viewimpl->HasUserKeyHandling() && viewimpl->GetWXPeer() )
return viewimpl->GetWXPeer()->AcceptsFocus();
return NO;
}
@@ -2101,7 +2101,7 @@ void wxCocoaGesturesImpl::TouchesEnded(NSEvent* event)
void wxWidgetCocoaImpl::insertText(NSString* text, WXWidget slf, void *_cmd)
{
bool result = false;
if ( IsUserPane() && !m_hasEditor && [text length] > 0)
if ( HasUserKeyHandling() && !m_hasEditor && [text length] > 0)
{
if ( m_lastKeyDownEvent!=NULL && [text isEqualToString:[m_lastKeyDownEvent characters]])
{
@@ -2190,7 +2190,7 @@ bool wxWidgetCocoaImpl::performKeyEquivalent(WX_NSEvent event, WXWidget slf, voi
bool wxWidgetCocoaImpl::acceptsFirstResponder(WXWidget slf, void *_cmd)
{
if ( IsUserPane() )
if ( HasUserKeyHandling() )
return m_wxPeer->AcceptsFocus();
else
{
@@ -2512,8 +2512,8 @@ void wxOSXCocoaClassAddWXMethods(Class c, wxOSXSkipOverrides skipFlags)
wxIMPLEMENT_DYNAMIC_CLASS(wxWidgetCocoaImpl , wxWidgetImpl);
wxWidgetCocoaImpl::wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl, bool isUserPane ) :
wxWidgetImpl( peer, isRootControl, isUserPane )
wxWidgetCocoaImpl::wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl, bool isUserPane, bool wantsKey ) :
wxWidgetImpl( peer, isRootControl, isUserPane, wantsKey )
{
Init();
m_osxView = w;
@@ -2528,6 +2528,23 @@ wxWidgetCocoaImpl::wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRoo
[m_osxView release];
}
wxWidgetCocoaImpl::wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl, bool isUserPane ) :
wxWidgetImpl( peer, isRootControl, isUserPane )
{
Init();
m_osxView = w;
// check if the user wants to create the control initially hidden
if ( !peer->IsShown() )
SetVisibility(false);
// gc aware handling
if ( m_osxView )
CFRetain(m_osxView);
[m_osxView release];
}
wxWidgetCocoaImpl::wxWidgetCocoaImpl()
{
Init();
@@ -3658,7 +3675,7 @@ bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event)
return true;
}
if ( IsUserPane() && [event type] == NSKeyDown)
if ( HasUserKeyHandling() && [event type] == NSKeyDown)
{
// Don't fire wxEVT_KEY_DOWN here in order to allow IME to intercept
// some key events. If the event is not handled by IME, either

View File

@@ -2223,7 +2223,7 @@ void wxWindowMac::MacRepositionScrollBars()
bool wxWindowMac::AcceptsFocus() const
{
if ( GetPeer() == NULL || GetPeer()->IsUserPane() )
if ( GetPeer() == NULL || GetPeer()->HasUserKeyHandling() )
return wxWindowBase::AcceptsFocus();
else
return GetPeer()->CanFocus();
@@ -2742,10 +2742,20 @@ void wxWidgetImpl::RemoveAssociation(WXWidget control)
wxIMPLEMENT_ABSTRACT_CLASS(wxWidgetImpl, wxObject);
wxWidgetImpl::wxWidgetImpl( wxWindowMac* peer , bool isRootControl, bool isUserPane )
{
Init();
m_isRootControl = isRootControl;
m_wantsUserKey = m_isUserPane = isUserPane;
m_wxPeer = peer;
m_shouldSendEvents = true;
}
wxWidgetImpl::wxWidgetImpl( wxWindowMac* peer , bool isRootControl, bool isUserPane, bool wantsUserKey )
{
Init();
m_isRootControl = isRootControl;
m_isUserPane = isUserPane;
m_wantsUserKey = wantsUserKey;
m_wxPeer = peer;
m_shouldSendEvents = true;
}