diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index 18267fda31..bd4f07ff81 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -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(); diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index af0657ce8f..ba3a9e70dd 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -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; diff --git a/src/osx/cocoa/glcanvas.mm b/src/osx/cocoa/glcanvas.mm index de9ff18901..74bb5a9386 100644 --- a/src/osx/cocoa/glcanvas.mm +++ b/src/osx/cocoa/glcanvas.mm @@ -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 ) diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 45cfdd7c37..eba0c50235 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -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 diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index be965a4890..f6b8dde4b0 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -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; }