From: Stefan Csomor <csomor@advancedconcepts.ch>
Date: Fri, 10 Oct 2008 19:01:32 +0000 (+0000)
Subject: moving embedding to common API
X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/c4825ef73a5f190b8f39c59df098c3f39fa4464b

moving embedding to common API

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56218 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---

diff --git a/include/wx/osx/carbon/private.h b/include/wx/osx/carbon/private.h
index 2e5d38c20b..3e35afa471 100644
--- a/include/wx/osx/carbon/private.h
+++ b/include/wx/osx/carbon/private.h
@@ -299,8 +299,6 @@ public :
 
     virtual WXWidget GetWXWidget() const { return (WXWidget) m_controlRef; }
 
-    virtual void SetReference( URefCon data );
-    
     virtual bool        IsVisible() const;
 
     virtual void        Raise();
diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h
index fa8075efe5..f46aeafa2f 100644
--- a/include/wx/osx/cocoa/private.h
+++ b/include/wx/osx/cocoa/private.h
@@ -160,6 +160,7 @@ public :
 
     void                SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true );
 
+    void                InstallEventHandler( WXWidget control = NULL );
 protected:
     WXWidget m_osxView;
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl)
diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h
index 15e0f81736..dec77345e5 100644
--- a/include/wx/osx/core/private.h
+++ b/include/wx/osx/core/private.h
@@ -235,6 +235,8 @@ public :
     // is the clicked event sent AFTER the state already changed, so no additional
     // state changing logic is required from the outside
     virtual bool        ButtonClickDidStateChange() = 0;
+    
+    virtual void        InstallEventHandler( WXWidget control = NULL ) = 0;
 
     // static methods for associating native controls and their implementations
 
diff --git a/src/osx/carbon/textctrl.cpp b/src/osx/carbon/textctrl.cpp
index 55fb6f4178..f385f45e06 100644
--- a/src/osx/carbon/textctrl.cpp
+++ b/src/osx/carbon/textctrl.cpp
@@ -1907,6 +1907,7 @@ wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl *wxPeer,
         MAC_WXHWND(wxPeer->GetParent()->MacGetTopLevelWindowRef()),
         &bounds, featureSet, &m_controlRef );
     verify_noerr( err );
+    SetControlReference( m_controlRef , (URefCon) wxPeer );
 
     DoCreate();
 
diff --git a/src/osx/carbon/window.cpp b/src/osx/carbon/window.cpp
index 21e9c4174a..2a2db6407c 100644
--- a/src/osx/carbon/window.cpp
+++ b/src/osx/carbon/window.cpp
@@ -841,22 +841,15 @@ void wxMacControl::Init()
     m_macControlEventHandler = NULL;
 }
 
-void wxMacControl::SetReference( URefCon data )
-{
-    SetControlReference( m_controlRef , data );
-}
-
 void wxMacControl::RemoveFromParent()
 {
     // nothing to do here for carbon
+    HIViewRemoveFromSuperview(m_controlRef);
 }
 
 void wxMacControl::Embed( wxWidgetImpl *parent )
 {
-    // copied from MacPostControlCreate
-    ControlRef container = (ControlRef) parent->GetWXWidget() ;
-    wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
-    ::EmbedControl( m_controlRef , container ) ;
+    HIViewAddSubview(parent->GetWXWidget(), m_controlRef);
 }
 
 void wxMacControl::SetNeedsDisplay( const wxRect* rect )
@@ -1388,6 +1381,13 @@ void wxMacControl::SetScrollThumb( wxInt32 WXUNUSED(pos), wxInt32 WXUNUSED(views
     // implemented in respective subclass
 }
 
+void wxMacControl::AddSubWidget( wxWidgetImpl* widget )
+{
+    ControlRef container = (ControlRef) GetWXWidget() ;
+    wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
+    ::EmbedControl( (ControlRef) widget->GetWXWidget() , container ) ;
+}
+
 //
 // Tab Control
 //
diff --git a/src/osx/cocoa/bmpbuttn.mm b/src/osx/cocoa/bmpbuttn.mm
index 3de4eafe5f..0c1f471a3e 100644
--- a/src/osx/cocoa/bmpbuttn.mm
+++ b/src/osx/cocoa/bmpbuttn.mm
@@ -31,15 +31,12 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer,
                                     long style, 
                                     long extraStyle) 
 {
-    NSView* sv = static_cast<NSView*>(wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
     
     [v setBezelStyle:NSRegularSquareBezelStyle];
     [v setImage:bitmap.GetNSImage() ];
     [v setButtonType:NSMomentaryPushInButton];
-    [sv addSubview:v];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
     [v setImplementation:c];
     return c;
diff --git a/src/osx/cocoa/button.mm b/src/osx/cocoa/button.mm
index ec39699324..bbf249361f 100644
--- a/src/osx/cocoa/button.mm
+++ b/src/osx/cocoa/button.mm
@@ -198,8 +198,6 @@ wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer,
                                     long style, 
                                     long extraStyle) 
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
     
@@ -213,7 +211,6 @@ wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer,
     }
     
     [v setButtonType:NSMomentaryPushInButton];
-    [sv addSubview:v];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
     [v setImplementation:c];
     return c;
@@ -287,15 +284,12 @@ wxWidgetImplType* wxWidgetImpl::CreateDisclosureTriangle( wxWindowMac* wxpeer,
                                     long style, 
                                     long extraStyle) 
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
     [v setBezelStyle:NSDisclosureBezelStyle];
     [v setButtonType:NSOnOffButton];
     [v setTitle:wxCFStringRef( label).AsNSString()];
     [v setImagePosition:NSImageRight];
-    [sv addSubview:v];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
     [v setImplementation:c];
     return c;
diff --git a/src/osx/cocoa/checkbox.mm b/src/osx/cocoa/checkbox.mm
index 0bca191ba8..8e79189ed1 100644
--- a/src/osx/cocoa/checkbox.mm
+++ b/src/osx/cocoa/checkbox.mm
@@ -25,8 +25,6 @@ wxWidgetImplType* wxWidgetImpl::CreateCheckBox( wxWindowMac* wxpeer,
                                     long style, 
                                     long extraStyle) 
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
 
@@ -34,7 +32,6 @@ wxWidgetImplType* wxWidgetImpl::CreateCheckBox( wxWindowMac* wxpeer,
     if (style & wxCHK_3STATE)
         [v setAllowsMixedState:YES];
         
-    [sv addSubview:v];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
     [v setImplementation:c];
     return c;
diff --git a/src/osx/cocoa/choice.mm b/src/osx/cocoa/choice.mm
index 50d1bac332..cf583d5fee 100644
--- a/src/osx/cocoa/choice.mm
+++ b/src/osx/cocoa/choice.mm
@@ -91,11 +91,8 @@ wxWidgetImplType* wxWidgetImpl::CreateChoice( wxWindowMac* wxpeer,
                                     long style, 
                                     long extraStylew)
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSPopUpButton* v = [[wxNSPopUpButton alloc] initWithFrame:r pullsDown:NO];
-    [sv addSubview:v];
     [v setMenu: menu->GetHMenu()];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
     [v setImplementation:c];
diff --git a/src/osx/cocoa/gauge.mm b/src/osx/cocoa/gauge.mm
index 80ed675dc8..71b9043b0a 100644
--- a/src/osx/cocoa/gauge.mm
+++ b/src/osx/cocoa/gauge.mm
@@ -105,8 +105,6 @@ wxWidgetImplType* wxWidgetImpl::CreateGauge( wxWindowMac* wxpeer,
                                     long style, 
                                     long extraStyle)
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSProgressIndicator* v = [[wxNSProgressIndicator alloc] initWithFrame:r];
 
@@ -114,7 +112,6 @@ wxWidgetImplType* wxWidgetImpl::CreateGauge( wxWindowMac* wxpeer,
     [v setMaxValue: maximum];
     [v setIndeterminate:FALSE];
     [v setDoubleValue: (double) value];
-    [sv addSubview:v];
     wxWidgetCocoaImpl* c = new wxOSXGaugeCocoaImpl( wxpeer, v );
     [v setImplementation:c];
     return c;
diff --git a/src/osx/cocoa/glcanvas.mm b/src/osx/cocoa/glcanvas.mm
index df3bb0e424..0952fc18f3 100644
--- a/src/osx/cocoa/glcanvas.mm
+++ b/src/osx/cocoa/glcanvas.mm
@@ -291,11 +291,8 @@ bool wxGLCanvas::Create(wxWindow *parent,
         return false;
 
 /*
-    NSView* sv = (parent->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( this, pos , size ) ;
     wxNSCustomOpenGLView* v = [[wxNSCustomOpenGLView alloc] initWithFrame:r];
-    [sv addSubview:v];
     m_peer = new wxWidgetCocoaImpl( this, v );
     [v setImplementation:m_peer];
 
diff --git a/src/osx/cocoa/listbox.mm b/src/osx/cocoa/listbox.mm
index 2d43f9827f..5297c16508 100644
--- a/src/osx/cocoa/listbox.mm
+++ b/src/osx/cocoa/listbox.mm
@@ -473,8 +473,6 @@ wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer,
                                     long style, 
                                     long extraStyle)
 {
-    NSView* superv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     NSScrollView* scrollview = [[NSScrollView alloc] initWithFrame:r];
     
@@ -503,7 +501,6 @@ wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer,
     [tableview setColumnAutoresizingStyle:NSTableViewLastColumnOnlyAutoresizingStyle];
     wxNSTableDataSource* ds = [[ wxNSTableDataSource alloc] init];
     [tableview setDataSource:ds];
-    [superv addSubview:scrollview];
     wxListWidgetCocoaImpl* c = new wxListWidgetCocoaImpl( wxpeer, scrollview, tableview, ds );
     [tableview setImplementation:c];
     [ds setImplementation:c];
diff --git a/src/osx/cocoa/notebook.mm b/src/osx/cocoa/notebook.mm
index e085d76899..d4acf6b320 100644
--- a/src/osx/cocoa/notebook.mm
+++ b/src/osx/cocoa/notebook.mm
@@ -246,8 +246,6 @@ wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
     if ( !controller )
         controller =[[wxTabViewController alloc] init];
 
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     
     NSTabViewType tabstyle = NSTopTabsBezelBorder;
@@ -259,7 +257,6 @@ wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
         tabstyle = NSBottomTabsBezelBorder;
     
     wxNSTabView* v = [[wxNSTabView alloc] initWithFrame:r];
-    [sv addSubview:v];
     [v setTabViewType:tabstyle];
     wxWidgetCocoaImpl* c = new wxCocoaTabView( wxpeer, v );
     [v setImplementation:c];
diff --git a/src/osx/cocoa/radiobut.mm b/src/osx/cocoa/radiobut.mm
index 6ade4cba1c..681f6cf9c9 100644
--- a/src/osx/cocoa/radiobut.mm
+++ b/src/osx/cocoa/radiobut.mm
@@ -25,14 +25,11 @@ wxWidgetImplType* wxWidgetImpl::CreateRadioButton( wxWindowMac* wxpeer,
                                     long style, 
                                     long extraStyle) 
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
 
     [v setButtonType:NSRadioButton];    
         
-    [sv addSubview:v];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
     [v setImplementation:c];
     return c;
diff --git a/src/osx/cocoa/scrolbar.mm b/src/osx/cocoa/scrolbar.mm
index 5571d10c95..c3e7b73b6d 100644
--- a/src/osx/cocoa/scrolbar.mm
+++ b/src/osx/cocoa/scrolbar.mm
@@ -111,12 +111,9 @@ wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer,
                                     long style, 
                                     long extraStyle)
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSScroller* v = [[wxNSScroller alloc] initWithFrame:r];
 
-    [sv addSubview:v];
     wxWidgetCocoaImpl* c = new wxOSXScrollBarCocoaImpl( wxpeer, v );
     [v setImplementation:c];
     return c;
diff --git a/src/osx/cocoa/slider.mm b/src/osx/cocoa/slider.mm
index a80fb434d6..8fc664c26c 100644
--- a/src/osx/cocoa/slider.mm
+++ b/src/osx/cocoa/slider.mm
@@ -77,8 +77,6 @@ wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer,
                                     long style, 
                                     long extraStyle)
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSSlider* v = [[wxNSSlider alloc] initWithFrame:r];
 
@@ -99,7 +97,6 @@ wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer,
     [v setMinValue: minimum];
     [v setMaxValue: maximum];
     [v setFloatValue: (double) value];
-    [sv addSubview:v];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
     [v setImplementation:c];
     return c;
diff --git a/src/osx/cocoa/spinbutt.mm b/src/osx/cocoa/spinbutt.mm
index 9fbce04a93..436576b8b3 100644
--- a/src/osx/cocoa/spinbutt.mm
+++ b/src/osx/cocoa/spinbutt.mm
@@ -77,8 +77,6 @@ wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer,
                                     long style, 
                                     long extraStyle)
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSStepper* v = [[wxNSStepper alloc] initWithFrame:r];
 
@@ -89,7 +87,6 @@ wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer,
     if ( style & wxSP_WRAP )
         [v setValueWraps:YES];
     
-    [sv addSubview:v];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
     [v setImplementation:c];
     return c;
diff --git a/src/osx/cocoa/srchctrl.mm b/src/osx/cocoa/srchctrl.mm
index 0c33e98599..6cda0bfab5 100644
--- a/src/osx/cocoa/srchctrl.mm
+++ b/src/osx/cocoa/srchctrl.mm
@@ -171,11 +171,8 @@ wxWidgetImplType* wxWidgetImpl::CreateSearchControl( wxTextCtrl* wxpeer,
                                     long style, 
                                     long extraStyle)
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSSearchField* v = [[wxNSSearchField alloc] initWithFrame:r];
-    [sv addSubview:v];
     [[v cell] setSendsWholeSearchString:YES];
     // per wx default cancel is not shown
     [[v cell] setCancelButtonCell:nil];
diff --git a/src/osx/cocoa/statbox.mm b/src/osx/cocoa/statbox.mm
index f1e60f923c..3eca187518 100644
--- a/src/osx/cocoa/statbox.mm
+++ b/src/osx/cocoa/statbox.mm
@@ -44,11 +44,8 @@ wxWidgetImplType* wxWidgetImpl::CreateGroupBox( wxWindowMac* wxpeer,
                                     long style, 
                                     long extraStyle)
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSBox* v = [[wxNSBox alloc] initWithFrame:r];
-    [sv addSubview:v];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
     [v setImplementation:c];
     return c;
diff --git a/src/osx/cocoa/statline.mm b/src/osx/cocoa/statline.mm
index 6fc86cc2e2..f57c1bb28f 100644
--- a/src/osx/cocoa/statline.mm
+++ b/src/osx/cocoa/statline.mm
@@ -41,11 +41,8 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticLine( wxWindowMac* wxpeer,
                                     long style, 
                                     long extraStyle) 
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSBox* v = [[wxNSBox alloc] initWithFrame:r];
-    [sv addSubview:v];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
     [v setImplementation:c];
     return c;
diff --git a/src/osx/cocoa/stattext.mm b/src/osx/cocoa/stattext.mm
index a30082c990..973a7b2e9f 100644
--- a/src/osx/cocoa/stattext.mm
+++ b/src/osx/cocoa/stattext.mm
@@ -101,11 +101,8 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
                                     long style, 
                                     long extraStyle) 
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
-    [sv addSubview:v];
 
     [v setBezeled:NO];
     [v setEditable:NO];
diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm
index b5c896241e..6a2b2946de 100644
--- a/src/osx/cocoa/textctrl.mm
+++ b/src/osx/cocoa/textctrl.mm
@@ -136,11 +136,8 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
                                     long style, 
                                     long extraStyle)
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
-    [sv addSubview:v];
     
     if ( style & wxNO_BORDER )
     {
diff --git a/src/osx/cocoa/tglbtn.mm b/src/osx/cocoa/tglbtn.mm
index de93bd3bf0..5db9b8e456 100644
--- a/src/osx/cocoa/tglbtn.mm
+++ b/src/osx/cocoa/tglbtn.mm
@@ -34,14 +34,11 @@ wxWidgetImplType* wxWidgetImpl::CreateToggleButton( wxWindowMac* wxpeer,
                                     long style, 
                                     long extraStyle)
 {
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
     
     [v setBezelStyle:NSRoundedBezelStyle];    
     [v setButtonType:NSOnOffButton];
-    [sv addSubview:v];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
     [v setImplementation:c];
     return c;
@@ -56,14 +53,11 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapToggleButton( wxWindowMac* wxpeer,
                                     long style, 
                                     long extraStyle)
 {    
-    NSView* sv = (wxpeer->GetParent()->GetHandle() );
-    
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
     
     [v setBezelStyle:NSRegularSquareBezelStyle];
     [v setButtonType:NSOnOffButton];
-    [sv addSubview:v];
     wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
     [v setImplementation:c];
     return c;
diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm
index cc9a21066a..4594a4931d 100644
--- a/src/osx/cocoa/window.mm
+++ b/src/osx/cocoa/window.mm
@@ -718,6 +718,10 @@ void wxWidgetCocoaImpl::SetFont(wxFont const&, wxColour const&, long, bool)
     // TODO
 }
 
+void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
+{
+}
+
 //
 // Factory methods
 //
diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp
index b5baf1f009..3ad07ae4d2 100644
--- a/src/osx/window_osx.cpp
+++ b/src/osx/window_osx.cpp
@@ -274,19 +274,11 @@ void wxWindowMac::MacPostControlCreate(const wxPoint& WXUNUSED(pos), const wxSiz
 {
     wxASSERT_MSG( m_peer != NULL && m_peer->IsOk() , wxT("No valid mac control") ) ;
 
-#if wxOSX_USE_CARBON
-    m_peer->SetReference( (URefCon) this ) ;
-#endif
-
     GetParent()->AddChild( this );
 
-#if wxOSX_USE_CARBON
     m_peer->InstallEventHandler();
+    m_peer->Embed(GetParent()->GetPeer());
 
-    ControlRef container = (ControlRef) GetParent()->GetHandle() ;
-    wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
-    ::EmbedControl( m_peer->GetControlRef() , container ) ;
-#endif
     GetParent()->MacChildAdded() ;
 
     // adjust font, controlsize etc