moving embedding to common API

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56218 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2008-10-10 19:01:32 +00:00
parent d0aff30277
commit c4825ef73a
25 changed files with 18 additions and 80 deletions

View File

@@ -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();

View File

@@ -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)

View File

@@ -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

View File

@@ -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();

View File

@@ -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
//

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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];

View File

@@ -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;

View File

@@ -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];

View File

@@ -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];

View File

@@ -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];

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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];

View File

@@ -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;

View File

@@ -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;

View File

@@ -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];

View File

@@ -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 )
{

View File

@@ -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;

View File

@@ -718,6 +718,10 @@ void wxWidgetCocoaImpl::SetFont(wxFont const&, wxColour const&, long, bool)
// TODO
}
void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
{
}
//
// Factory methods
//

View File

@@ -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