adding wrapping possibility for native tlws

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63969 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2010-04-13 20:24:59 +00:00
parent c96ce98975
commit 17e2694c59
11 changed files with 122 additions and 51 deletions

View File

@@ -1002,12 +1002,14 @@ class wxNonOwnedWindowCarbonImpl : public wxNonOwnedWindowImpl
{ {
public : public :
wxNonOwnedWindowCarbonImpl( wxNonOwnedWindow* nonownedwnd) ; wxNonOwnedWindowCarbonImpl( wxNonOwnedWindow* nonownedwnd) ;
wxNonOwnedWindowCarbonImpl(); wxNonOwnedWindowCarbonImpl();
virtual ~wxNonOwnedWindowCarbonImpl(); virtual ~wxNonOwnedWindowCarbonImpl();
virtual void WillBeDestroyed() ; virtual void WillBeDestroyed() ;
void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size, void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
long style, long extraStyle, const wxString& name ) ; long style, long extraStyle, const wxString& name ) ;
void Create( wxWindow* parent, WXWindow nativeWindow );
WXWindow GetWXWindow() const; WXWindow GetWXWindow() const;
void Raise(); void Raise();

View File

@@ -209,6 +209,7 @@ public :
virtual void WillBeDestroyed() ; virtual void WillBeDestroyed() ;
void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size, void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
long style, long extraStyle, const wxString& name ) ; long style, long extraStyle, const wxString& name ) ;
void Create( wxWindow* parent, WXWindow nativeWindow );
WXWindow GetWXWindow() const; WXWindow GetWXWindow() const;
void Raise(); void Raise();

View File

@@ -796,6 +796,8 @@ public :
// static creation methods, must be implemented by all toolkits // static creation methods, must be implemented by all toolkits
static wxNonOwnedWindowImpl* CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow native) ;
static wxNonOwnedWindowImpl* CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size, static wxNonOwnedWindowImpl* CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
long style, long extraStyle, const wxString& name ) ; long style, long extraStyle, const wxString& name ) ;

View File

@@ -55,6 +55,8 @@ public:
long style = 0, long style = 0,
const wxString& name = wxPanelNameStr); const wxString& name = wxPanelNameStr);
bool Create(wxWindow *parent, WXWindow nativeWindow);
virtual ~wxNonOwnedWindow(); virtual ~wxNonOwnedWindow();
virtual wxPoint GetClientAreaOrigin() const; virtual wxPoint GetClientAreaOrigin() const;
@@ -106,7 +108,7 @@ public:
virtual void HandleResizing( double timestampsec, wxRect* rect ); virtual void HandleResizing( double timestampsec, wxRect* rect );
virtual bool Destroy(); virtual bool Destroy();
protected: protected:
// common part of all ctors // common part of all ctors
void Init(); void Init();

View File

@@ -263,6 +263,8 @@ public:
virtual bool OSXHandleClicked( double timestampsec ); virtual bool OSXHandleClicked( double timestampsec );
virtual bool OSXHandleKeyEvent( wxKeyEvent& event ); virtual bool OSXHandleKeyEvent( wxKeyEvent& event );
bool IsNativeWindowWrapper() const { return m_isNativeWindowWrapper; }
protected: protected:
// For controls like radio buttons which are genuinely composite // For controls like radio buttons which are genuinely composite
wxList m_subControls; wxList m_subControls;
@@ -297,6 +299,8 @@ protected:
bool m_vScrollBarAlwaysShown; bool m_vScrollBarAlwaysShown;
wxWindow* m_growBox ; wxWindow* m_growBox ;
wxString m_label ; wxString m_label ;
bool m_isNativeWindowWrapper;
// set to true if we do a sharp clip at the content area of this window // set to true if we do a sharp clip at the content area of this window
// must be dynamic as eg a panel normally is not clipping precisely, but if // must be dynamic as eg a panel normally is not clipping precisely, but if

View File

@@ -1134,7 +1134,7 @@ wxNonOwnedWindowCarbonImpl::~wxNonOwnedWindowCarbonImpl()
m_macEventHandler = NULL ; m_macEventHandler = NULL ;
} }
if ( m_macWindow ) if ( m_macWindow && !m_wxPeer->IsNativeWindowWrapper())
DisposeWindow( m_macWindow ); DisposeWindow( m_macWindow );
FullScreenData *data = (FullScreenData *) m_macFullScreenData ; FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
@@ -1192,30 +1192,37 @@ void wxNonOwnedWindowCarbonImpl::MacInstallTopLevelWindowEventHandler()
void wxNonOwnedWindowCarbonImpl::Create( void wxNonOwnedWindowCarbonImpl::Create(
wxWindow* parent, wxWindow* parent,
const wxPoint& pos, WXWindow nativeWindow )
const wxSize& size,
long style, long extraStyle,
const wxString& WXUNUSED(name) )
{ {
m_macWindow = nativeWindow;
}
void wxNonOwnedWindowCarbonImpl::Create(
wxWindow* parent,
const wxPoint& pos,
const wxSize& size,
long style, long extraStyle,
const wxString& WXUNUSED(name) )
{
OSStatus err = noErr ; OSStatus err = noErr ;
Rect theBoundsRect; Rect theBoundsRect;
int x = (int)pos.x; int x = (int)pos.x;
int y = (int)pos.y; int y = (int)pos.y;
int w = size.x; int w = size.x;
int h = size.y; int h = size.y;
::SetRect(&theBoundsRect, x, y , x + w, y + h); ::SetRect(&theBoundsRect, x, y , x + w, y + h);
// translate the window attributes in the appropriate window class and attributes // translate the window attributes in the appropriate window class and attributes
WindowClass wclass = 0; WindowClass wclass = 0;
WindowAttributes attr = kWindowNoAttributes ; WindowAttributes attr = kWindowNoAttributes ;
WindowGroupRef group = NULL ; WindowGroupRef group = NULL ;
bool activationScopeSet = false; bool activationScopeSet = false;
WindowActivationScope activationScope = kWindowActivationScopeNone; WindowActivationScope activationScope = kWindowActivationScopeNone;
if ( style & wxFRAME_TOOL_WINDOW ) if ( style & wxFRAME_TOOL_WINDOW )
{ {
if ( if (
@@ -1228,7 +1235,7 @@ void wxNonOwnedWindowCarbonImpl::Create(
wclass = kUtilityWindowClass; wclass = kUtilityWindowClass;
else else
wclass = kFloatingWindowClass ; wclass = kFloatingWindowClass ;
if ( ( style &wxTINY_CAPTION_VERT) ) if ( ( style &wxTINY_CAPTION_VERT) )
attr |= kWindowSideTitlebarAttribute ; attr |= kWindowSideTitlebarAttribute ;
} }
@@ -1287,81 +1294,81 @@ void wxNonOwnedWindowCarbonImpl::Create(
wclass = kPlainWindowClass ; wclass = kPlainWindowClass ;
} }
} }
if ( wclass != kPlainWindowClass ) if ( wclass != kPlainWindowClass )
{ {
if ( ( style & wxMINIMIZE_BOX ) ) if ( ( style & wxMINIMIZE_BOX ) )
attr |= kWindowCollapseBoxAttribute ; attr |= kWindowCollapseBoxAttribute ;
if ( ( style & wxMAXIMIZE_BOX ) ) if ( ( style & wxMAXIMIZE_BOX ) )
attr |= kWindowFullZoomAttribute ; attr |= kWindowFullZoomAttribute ;
if ( ( style & wxRESIZE_BORDER ) ) if ( ( style & wxRESIZE_BORDER ) )
attr |= kWindowResizableAttribute ; attr |= kWindowResizableAttribute ;
if ( ( style & wxCLOSE_BOX) ) if ( ( style & wxCLOSE_BOX) )
attr |= kWindowCloseBoxAttribute ; attr |= kWindowCloseBoxAttribute ;
} }
attr |= kWindowLiveResizeAttribute; attr |= kWindowLiveResizeAttribute;
if ( ( style &wxSTAY_ON_TOP) ) if ( ( style &wxSTAY_ON_TOP) )
group = GetWindowGroupOfClass(kUtilityWindowClass) ; group = GetWindowGroupOfClass(kUtilityWindowClass) ;
if ( ( style & wxFRAME_FLOAT_ON_PARENT ) ) if ( ( style & wxFRAME_FLOAT_ON_PARENT ) )
group = GetWindowGroupOfClass(kFloatingWindowClass) ; group = GetWindowGroupOfClass(kFloatingWindowClass) ;
if ( group == NULL && parent != NULL ) if ( group == NULL && parent != NULL )
{ {
WindowRef parenttlw = (WindowRef) parent->MacGetTopLevelWindowRef(); WindowRef parenttlw = (WindowRef) parent->MacGetTopLevelWindowRef();
if( parenttlw ) if( parenttlw )
group = GetWindowGroupParent( GetWindowGroup( parenttlw ) ); group = GetWindowGroupParent( GetWindowGroup( parenttlw ) );
} }
attr |= kWindowCompositingAttribute; attr |= kWindowCompositingAttribute;
#if 0 // TODO : decide on overall handling of high dpi screens (pixel vs userscale) #if 0 // TODO : decide on overall handling of high dpi screens (pixel vs userscale)
attr |= kWindowFrameworkScaledAttribute; attr |= kWindowFrameworkScaledAttribute;
#endif #endif
if ( ( style &wxFRAME_SHAPED) ) if ( ( style &wxFRAME_SHAPED) )
{ {
WindowDefSpec customWindowDefSpec; WindowDefSpec customWindowDefSpec;
customWindowDefSpec.defType = kWindowDefProcPtr; customWindowDefSpec.defType = kWindowDefProcPtr;
customWindowDefSpec.u.defProc = customWindowDefSpec.u.defProc =
#ifdef __LP64__ #ifdef __LP64__
(WindowDefUPP) wxShapedMacWindowDef; (WindowDefUPP) wxShapedMacWindowDef;
#else #else
NewWindowDefUPP(wxShapedMacWindowDef); NewWindowDefUPP(wxShapedMacWindowDef);
#endif #endif
err = ::CreateCustomWindow( &customWindowDefSpec, wclass, err = ::CreateCustomWindow( &customWindowDefSpec, wclass,
attr, &theBoundsRect, attr, &theBoundsRect,
(WindowRef*) &m_macWindow); (WindowRef*) &m_macWindow);
} }
else else
{ {
err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
} }
if ( err == noErr && m_macWindow != NULL && group != NULL ) if ( err == noErr && m_macWindow != NULL && group != NULL )
SetWindowGroup( (WindowRef) m_macWindow , group ) ; SetWindowGroup( (WindowRef) m_macWindow , group ) ;
wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") ); wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") );
// setup a separate group for each window, so that overlays can be handled easily // setup a separate group for each window, so that overlays can be handled easily
WindowGroupRef overlaygroup = NULL; WindowGroupRef overlaygroup = NULL;
verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrHideOnCollapse, &overlaygroup )); verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrHideOnCollapse, &overlaygroup ));
verify_noerr( SetWindowGroupParent( overlaygroup, GetWindowGroup( (WindowRef) m_macWindow ))); verify_noerr( SetWindowGroupParent( overlaygroup, GetWindowGroup( (WindowRef) m_macWindow )));
verify_noerr( SetWindowGroup( (WindowRef) m_macWindow , overlaygroup )); verify_noerr( SetWindowGroup( (WindowRef) m_macWindow , overlaygroup ));
if ( activationScopeSet ) if ( activationScopeSet )
{ {
verify_noerr( SetWindowActivationScope( (WindowRef) m_macWindow , activationScope )); verify_noerr( SetWindowActivationScope( (WindowRef) m_macWindow , activationScope ));
} }
// the create commands are only for content rect, // the create commands are only for content rect,
// so we have to set the size again as structure bounds // so we have to set the size again as structure bounds
SetWindowBounds( m_macWindow , kWindowStructureRgn , &theBoundsRect ) ; SetWindowBounds( m_macWindow , kWindowStructureRgn , &theBoundsRect ) ;
// Causes the inner part of the window not to be metal // Causes the inner part of the window not to be metal
// if the style is used before window creation. // if the style is used before window creation.
#if 0 // TARGET_API_MAC_OSX #if 0 // TARGET_API_MAC_OSX
@@ -1371,24 +1378,24 @@ void wxNonOwnedWindowCarbonImpl::Create(
MacSetMetalAppearance( true ) ; MacSetMetalAppearance( true ) ;
} }
#endif #endif
if ( m_macWindow != NULL ) if ( m_macWindow != NULL )
{ {
MacSetUnifiedAppearance( true ) ; MacSetUnifiedAppearance( true ) ;
} }
HIViewRef growBoxRef = 0 ; HIViewRef growBoxRef = 0 ;
err = HIViewFindByID( HIViewGetRoot( m_macWindow ), kHIViewWindowGrowBoxID, &growBoxRef ); err = HIViewFindByID( HIViewGetRoot( m_macWindow ), kHIViewWindowGrowBoxID, &growBoxRef );
if ( err == noErr && growBoxRef != 0 ) if ( err == noErr && growBoxRef != 0 )
HIGrowBoxViewSetTransparent( growBoxRef, true ) ; HIGrowBoxViewSetTransparent( growBoxRef, true ) ;
// the frame window event handler // the frame window event handler
InstallStandardEventHandler( GetWindowEventTarget(m_macWindow) ) ; InstallStandardEventHandler( GetWindowEventTarget(m_macWindow) ) ;
MacInstallTopLevelWindowEventHandler() ; MacInstallTopLevelWindowEventHandler() ;
if ( extraStyle & wxFRAME_EX_METAL) if ( extraStyle & wxFRAME_EX_METAL)
MacSetMetalAppearance(true); MacSetMetalAppearance(true);
if ( ( style &wxFRAME_SHAPED) ) if ( ( style &wxFRAME_SHAPED) )
{ {
// default shape matches the window size // default shape matches the window size
@@ -1689,3 +1696,11 @@ wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWind
now->Create( parent, pos, size, style , extraStyle, name ); now->Create( parent, pos, size, style , extraStyle, name );
return now; return now;
} }
wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow )
{
wxNonOwnedWindowCarbonImpl* now = new wxNonOwnedWindowCarbonImpl( wxpeer );
now->Create( parent, nativeWindow );
return now;
}

View File

@@ -188,7 +188,13 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
OSStatus err = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef, &cgContext) ; OSStatus err = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef, &cgContext) ;
if ( err != noErr ) if ( err != noErr )
{ {
wxFAIL_MSG("Unable to retrieve CGContextRef"); // for non-composite drawing, since we don't support it ourselves, send it through the
// the default handler
// CallNextEventHandler( handler,event ) ;
// result = noErr ;
if ( allocatedRgn )
CFRelease( allocatedRgn ) ;
break;
} }
thisWindow->MacSetCGContextRef( cgContext ) ; thisWindow->MacSetCGContextRef( cgContext ) ;
@@ -1515,6 +1521,8 @@ wxWidgetImplType* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
} }
// the root control level handler // the root control level handler
contentview->InstallEventHandler() ; if ( !now->IsNativeWindowWrapper() )
contentview->InstallEventHandler() ;
return contentview; return contentview;
} }

View File

@@ -361,14 +361,20 @@ wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl()
wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl() wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl()
{ {
[m_macWindow setImplementation:nil]; if ( !m_wxPeer->IsNativeWindowWrapper() )
[m_macWindow setDelegate:nil]; {
[m_macWindow release]; [m_macWindow setImplementation:nil];
[m_macWindow setDelegate:nil];
[m_macWindow release];
}
} }
void wxNonOwnedWindowCocoaImpl::WillBeDestroyed() void wxNonOwnedWindowCocoaImpl::WillBeDestroyed()
{ {
[m_macWindow setDelegate:nil]; if ( !m_wxPeer->IsNativeWindowWrapper() )
{
[m_macWindow setDelegate:nil];
}
} }
void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), const wxPoint& pos, const wxSize& size, void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), const wxPoint& pos, const wxSize& size,
@@ -493,6 +499,10 @@ long style, long extraStyle, const wxString& WXUNUSED(name) )
} }
} }
void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow )
{
m_macWindow = nativeWindow;
}
WXWindow wxNonOwnedWindowCocoaImpl::GetWXWindow() const WXWindow wxNonOwnedWindowCocoaImpl::GetWXWindow() const
{ {
@@ -787,6 +797,13 @@ bool wxNonOwnedWindowCocoaImpl::IsModified() const
return [m_macWindow isDocumentEdited]; return [m_macWindow isDocumentEdited];
} }
wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow)
{
wxNonOwnedWindowCocoaImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
now->Create( parent, nativeWindow );
return now;
}
wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size, wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
long style, long extraStyle, const wxString& name ) long style, long extraStyle, const wxString& name )
{ {

View File

@@ -2084,10 +2084,18 @@ wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* WX
wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now ) wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
{ {
NSWindow* tlw = now->GetWXWindow(); NSWindow* tlw = now->GetWXWindow();
wxNSView* v = [[wxNSView alloc] initWithFrame:[[tlw contentView] frame]];
wxWidgetCocoaImpl* c = NULL;
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( now, v, true ); if ( now->IsNativeWindowWrapper() )
c->InstallEventHandler(); {
[tlw setContentView:v]; c = new wxWidgetCocoaImpl( now, [tlw contentView], true );
}
else
{
wxNSView* v = [[wxNSView alloc] initWithFrame:[[tlw contentView] frame]];
c = new wxWidgetCocoaImpl( now, v, true );
c->InstallEventHandler();
[tlw setContentView:v];
}
return c; return c;
} }

View File

@@ -98,6 +98,7 @@ wxNonOwnedWindow *wxNonOwnedWindow::s_macDeactivateWindow = NULL;
void wxNonOwnedWindow::Init() void wxNonOwnedWindow::Init()
{ {
m_nowpeer = NULL; m_nowpeer = NULL;
m_isNativeWindowWrapper = false;
} }
bool wxNonOwnedWindow::Create(wxWindow *parent, bool wxNonOwnedWindow::Create(wxWindow *parent,
@@ -107,9 +108,6 @@ bool wxNonOwnedWindow::Create(wxWindow *parent,
long style, long style,
const wxString& name) const wxString& name)
{ {
// init our fields
Init();
m_windowStyle = style; m_windowStyle = style;
SetName( name ); SetName( name );
@@ -150,6 +148,19 @@ bool wxNonOwnedWindow::Create(wxWindow *parent,
return true; return true;
} }
bool wxNonOwnedWindow::Create(wxWindow *parent, WXWindow nativeWindow)
{
m_nowpeer = wxNonOwnedWindowImpl::CreateNonOwnedWindow(this, parent, nativeWindow );
m_isNativeWindowWrapper = true;
wxAssociateWindowWithWXWindow( m_nowpeer->GetWXWindow() , this ) ;
m_peer = wxWidgetImpl::CreateContentView(this);
if ( parent )
parent->AddChild(this);
return true;
}
wxNonOwnedWindow::~wxNonOwnedWindow() wxNonOwnedWindow::~wxNonOwnedWindow()
{ {
SendDestroyEvent(); SendDestroyEvent();

View File

@@ -206,6 +206,7 @@ void wxWindowMac::Init()
m_macIsUserPane = true; m_macIsUserPane = true;
m_clipChildren = false ; m_clipChildren = false ;
m_cachedClippedRectValid = false ; m_cachedClippedRectValid = false ;
m_isNativeWindowWrapper = false;
} }
wxWindowMac::~wxWindowMac() wxWindowMac::~wxWindowMac()