#define wxMAC_DEBUG_REDRAW 0
#endif
+wxWidgetImplType* kOSXNoWidgetImpl = (wxWidgetImplType*) -1L;
+
// ===========================================================================
// implementation
// ===========================================================================
m_vScrollBarAlwaysShown = false;
m_growBox = NULL ;
- m_macIsUserPane = true;
m_clipChildren = false ;
m_cachedClippedRectValid = false ;
m_isNativeWindowWrapper = false;
wxDELETE(m_dropTarget);
#endif
- delete m_peer ;
+ delete GetPeer() ;
}
WXWidget wxWindowMac::GetHandle() const
{
- if ( m_peer )
- return (WXWidget) m_peer->GetWXWidget() ;
+ if ( GetPeer() )
+ return (WXWidget) GetPeer()->GetWXWidget() ;
return NULL;
}
+wxOSXWidgetImpl* wxWindowMac::GetPeer() const
+{
+ return m_peer == kOSXNoWidgetImpl ? NULL : m_peer ;
+}
+
+void wxWindowMac::DontCreatePeer()
+{
+ m_peer = kOSXNoWidgetImpl;
+}
+
+void wxWindowMac::SetWrappingPeer(wxOSXWidgetImpl* wrapper)
+{
+ wxOSXWidgetImpl* inner = GetPeer();
+ wxASSERT_MSG( inner != NULL && inner->IsOk(), "missing or incomplete inner peer" );
+ wxASSERT_MSG( wrapper != NULL && wrapper->IsOk(), "missing or incomplete wrapper" );
+
+ if ( !(inner != NULL && inner->IsOk() && wrapper != NULL && wrapper->IsOk()) )
+ return;
+
+ inner->RemoveFromParent();
+ wrapper->InstallEventHandler();
+ wrapper->Embed(inner);
+ m_peer = wrapper;
+}
+
void wxWindowMac::SetPeer(wxOSXWidgetImpl* peer)
{
- wxDELETE(m_peer);
- // todo event check handlers
+ if ( GetPeer() )
+ {
+ GetPeer()->RemoveFromParent();
+ wxDELETE(m_peer);
+ }
+
m_peer = peer;
+
+ if ( GetPeer() && !GetPeer()->IsRootControl())
+ {
+ wxASSERT_MSG( GetPeer()->IsOk() , wxT("The native control must exist already") ) ;
+
+ if (!GetParent()->GetChildren().Find((wxWindow*)this))
+ GetParent()->AddChild( this );
+
+ GetPeer()->InstallEventHandler();
+ GetPeer()->Embed(GetParent()->GetPeer());
+
+ GetParent()->MacChildAdded() ;
+
+ // adjust font, controlsize etc
+ DoSetWindowVariant( m_windowVariant ) ;
+
+ GetPeer()->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ;
+
+ // for controls we want to use best size for wxDefaultSize params )
+ if ( !GetPeer()->IsUserPane() )
+ SetInitialSize(GetMinSize());
+
+ SetCursor( *wxSTANDARD_CURSOR ) ;
+ }
+}
+
+#if WXWIN_COMPATIBILITY_2_8
+
+bool wxWindowMac::MacIsUserPane()
+{
+ return GetPeer() == NULL || GetPeer()->IsUserPane();
+}
+
+#endif
+
+bool wxWindowMac::MacIsUserPane() const
+{
+ return GetPeer() == NULL || GetPeer()->IsUserPane();
}
// ---------------------------------------------------------------------------
m_windowVariant = parent->GetWindowVariant() ;
- if ( m_macIsUserPane )
+ if ( m_peer != kOSXNoWidgetImpl )
{
- m_peer = wxWidgetImpl::CreateUserPane( this, parent, id, pos, size , style, GetExtraStyle() );
+ SetPeer(wxWidgetImpl::CreateUserPane( this, parent, id, pos, size , style, GetExtraStyle() ));
MacPostControlCreate(pos, size) ;
}
void wxWindowMac::MacPostControlCreate(const wxPoint& WXUNUSED(pos), const wxSize& size)
{
- wxASSERT_MSG( m_peer != NULL && m_peer->IsOk() , wxT("No valid mac control") ) ;
+ // todo remove if refactoring works correctly
+#if 0
+ wxASSERT_MSG( GetPeer() != NULL && GetPeer()->IsOk() , wxT("No valid mac control") ) ;
- GetParent()->AddChild( this );
+ if (!GetParent()->GetChildren().Find((wxWindow*)this))
+ GetParent()->AddChild( this );
- m_peer->InstallEventHandler();
- m_peer->Embed(GetParent()->GetPeer());
+ GetPeer()->InstallEventHandler();
+ GetPeer()->Embed(GetParent()->GetPeer());
GetParent()->MacChildAdded() ;
// adjust font, controlsize etc
DoSetWindowVariant( m_windowVariant ) ;
- m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ;
+ GetPeer()->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ;
// for controls we want to use best size for wxDefaultSize params )
- if ( !m_macIsUserPane )
+ if ( !GetPeer()->IsUserPane() )
SetInitialSize(size);
SetCursor( *wxSTANDARD_CURSOR ) ;
+#endif
}
void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant )
{
// Don't assert, in case we set the window variant before
// the window is created
- // wxASSERT( m_peer->Ok() ) ;
+ // wxASSERT( GetPeer()->Ok() ) ;
m_windowVariant = variant ;
- if (m_peer == NULL || !m_peer->IsOk())
+ if (GetPeer() == NULL || !GetPeer()->IsOk())
return;
- m_peer->SetControlSize( variant );
+ GetPeer()->SetControlSize( variant );
#if wxOSX_USE_CARBON
ControlSize size ;
wxFAIL_MSG(wxT("unexpected window variant"));
break ;
}
- m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag, &size ) ;
+ GetPeer()->SetData<ControlSize>(kControlEntireControl, kControlSizeTag, &size ) ;
#endif
void wxWindowMac::MacUpdateControlFont()
{
- if ( m_peer )
- m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
+ if ( GetPeer() )
+ GetPeer()->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
// do not trigger refreshes upon invisible and possible partly created objects
if ( IsShownOnScreen() )
if ( !wxWindowBase::SetBackgroundStyle(style) )
return false;
- if ( m_peer )
- m_peer->SetBackgroundStyle(style);
+ if ( GetPeer() )
+ GetPeer()->SetBackgroundStyle(style);
return true;
}
if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol )
return false ;
- if ( m_peer )
- m_peer->SetBackgroundColour( col ) ;
+ if ( GetPeer() )
+ GetPeer()->SetBackgroundColour( col ) ;
return true ;
}
if ( former == this )
return ;
- m_peer->SetFocus() ;
+ GetPeer()->SetFocus() ;
}
void wxWindowMac::DoCaptureMouse()
{
wxApp::s_captureWindow = (wxWindow*) this ;
- m_peer->CaptureMouse() ;
+ GetPeer()->CaptureMouse() ;
}
wxWindow * wxWindowBase::GetCapture()
{
wxApp::s_captureWindow = NULL ;
- m_peer->ReleaseMouse() ;
+ GetPeer()->ReleaseMouse() ;
}
#if wxUSE_DRAG_AND_DROP
void wxWindowMac::DoGetSize(int *x, int *y) const
{
int width, height;
- m_peer->GetSize( width, height );
+ GetPeer()->GetSize( width, height );
if (x)
*x = width + MacGetLeftBorderSize() + MacGetRightBorderSize() ;
{
int x1, y1;
- m_peer->GetPosition( x1, y1 ) ;
+ GetPeer()->GetPosition( x1, y1 ) ;
// get the wx window position from the native one
x1 -= MacGetLeftBorderSize() ;
{
pt.x -= MacGetLeftBorderSize() ;
pt.y -= MacGetTopBorderSize() ;
- wxWidgetImpl::Convert( &pt , m_peer , top->m_peer ) ;
+ wxWidgetImpl::Convert( &pt , GetPeer() , top->GetPeer() ) ;
}
}
wxNonOwnedWindow* top = MacGetTopLevelWindow();
if (top)
{
- wxWidgetImpl::Convert( &pt , top->m_peer , m_peer ) ;
+ wxWidgetImpl::Convert( &pt , top->GetPeer() , GetPeer() ) ;
pt.x += MacGetLeftBorderSize() ;
pt.y += MacGetTopBorderSize() ;
}
int left, top;
int outerwidth, outerheight;
- m_peer->GetContentArea( left, top, innerwidth, innerheight );
- m_peer->GetSize( outerwidth, outerheight );
+ GetPeer()->GetContentArea( left, top, innerwidth, innerheight );
+ GetPeer()->GetSize( outerwidth, outerheight );
sizeTotal.x += outerwidth-innerwidth;
sizeTotal.y += outerheight-innerheight;
int left, top;
- m_peer->GetContentArea( left, top, ww, hh );
+ GetPeer()->GetContentArea( left, top, ww, hh );
#if wxUSE_SCROLLBAR
if (m_hScrollBar && m_hScrollBar->IsShown() )
hh -= m_hScrollBar->GetSize().y ;
if ( m_tooltip )
m_tooltip->SetWindow(this);
- if (m_peer)
- m_peer->SetToolTip(tooltip);
+ if (GetPeer())
+ GetPeer()->SetToolTip(tooltip);
}
#endif
void wxWindowMac::MacInvalidateBorders()
{
- if ( m_peer == NULL )
+ if ( GetPeer() == NULL )
return ;
bool vis = IsShownOnScreen() ;
int outerBorder = MacGetLeftBorderSize() ;
- if ( m_peer->NeedsFocusRect() )
+ if ( GetPeer()->NeedsFocusRect() )
outerBorder += 4 ;
if ( outerBorder == 0 )
int tx,ty,tw,th;
- m_peer->GetSize( tw, th );
- m_peer->GetPosition( tx, ty );
+ GetPeer()->GetSize( tw, th );
+ GetPeer()->GetPosition( tx, ty );
wxRect leftupdate( tx-outerBorder,ty,outerBorder,th );
wxRect rightupdate( tx+tw, ty, outerBorder, th );
wxRect bottomupdate( tx-outerBorder, ty + th, tw + 2 * outerBorder, outerBorder );
if (GetParent()) {
- GetParent()->m_peer->SetNeedsDisplay(&leftupdate);
- GetParent()->m_peer->SetNeedsDisplay(&rightupdate);
- GetParent()->m_peer->SetNeedsDisplay(&topupdate);
- GetParent()->m_peer->SetNeedsDisplay(&bottomupdate);
+ GetParent()->GetPeer()->SetNeedsDisplay(&leftupdate);
+ GetParent()->GetPeer()->SetNeedsDisplay(&rightupdate);
+ GetParent()->GetPeer()->SetNeedsDisplay(&topupdate);
+ GetParent()->GetPeer()->SetNeedsDisplay(&bottomupdate);
}
}
m_cachedClippedRectValid = false ;
- m_peer->Move( bounds.x, bounds.y, bounds.width, bounds.height);
+ GetPeer()->Move( bounds.x, bounds.y, bounds.width, bounds.height);
wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
wxSize wxWindowMac::DoGetBestSize() const
{
- if ( m_macIsUserPane || IsTopLevel() )
+ if ( GetPeer() == NULL || GetPeer()->IsUserPane() || IsTopLevel() )
{
return wxWindowBase::DoGetBestSize() ;
}
{
wxRect r ;
- m_peer->GetBestRect(&r);
+ GetPeer()->GetBestRect(&r);
if ( r.GetWidth() == 0 && r.GetHeight() == 0 )
{
wxPoint wxWindowMac::GetClientAreaOrigin() const
{
int left,top,width,height;
- m_peer->GetContentArea( left , top , width , height);
+ GetPeer()->GetContentArea( left , top , width , height);
return wxPoint( left + MacGetLeftBorderSize() , top + MacGetTopBorderSize() );
}
float wxWindowMac::GetContentScaleFactor() const
{
- return m_peer->GetContentScaleFactor();
+ return GetPeer()->GetContentScaleFactor();
}
void wxWindowMac::SetLabel(const wxString& title)
InvalidateBestSize();
- if ( m_peer && m_peer->IsOk() )
- m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ;
+ if ( GetPeer() && GetPeer()->IsOk() )
+ GetPeer()->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ;
// do not trigger refreshes upon invisible and possible partly created objects
if ( IsShownOnScreen() )
if ( !wxWindowBase::Show(show) )
return false;
- if ( m_peer )
- m_peer->SetVisibility( show ) ;
+ if ( GetPeer() )
+ GetPeer()->SetVisibility( show ) ;
#ifdef __WXOSX_IPHONE__
// only when there's no native event support
unsigned timeout)
{
if ( effect == wxSHOW_EFFECT_NONE ||
- !m_peer || !m_peer->ShowWithEffect(show, effect, timeout) )
+ !GetPeer() || !GetPeer()->ShowWithEffect(show, effect, timeout) )
return Show(show);
return true;
void wxWindowMac::DoEnable(bool enable)
{
- m_peer->Enable( enable ) ;
+ GetPeer()->Enable( enable ) ;
MacInvalidateBorders();
}
void wxWindowMac::MacEnabledStateChanged()
{
- OnEnabled( m_peer->IsEnabled() );
+ OnEnabled( GetPeer()->IsEnabled() );
}
//
bool wxWindowMac::MacIsReallyEnabled()
{
- return m_peer->IsEnabled() ;
+ return GetPeer()->IsEnabled() ;
}
bool wxWindowMac::MacIsReallyHilited()
{
#if wxOSX_USE_CARBON
- return m_peer->IsActive();
+ return GetPeer()->IsActive();
#else
return true; // TODO
#endif
void wxWindowMac::Refresh(bool WXUNUSED(eraseBack), const wxRect *rect)
{
- if ( m_peer == NULL )
+ if ( GetPeer() == NULL )
return ;
if ( !IsShownOnScreen() )
return ;
- m_peer->SetNeedsDisplay( rect ) ;
+ GetPeer()->SetNeedsDisplay( rect ) ;
}
void wxWindowMac::DoFreeze()
{
#if wxOSX_USE_CARBON
- if ( m_peer && m_peer->IsOk() )
- m_peer->SetDrawingEnabled( false ) ;
+ if ( GetPeer() && GetPeer()->IsOk() )
+ GetPeer()->SetDrawingEnabled( false ) ;
#endif
}
void wxWindowMac::DoThaw()
{
#if wxOSX_USE_CARBON
- if ( m_peer && m_peer->IsOk() )
+ if ( GetPeer() && GetPeer()->IsOk() )
{
- m_peer->SetDrawingEnabled( true ) ;
- m_peer->InvalidateWithChildren() ;
+ GetPeer()->SetDrawingEnabled( true ) ;
+ GetPeer()->InvalidateWithChildren() ;
}
#endif
}
int tx,ty,tw,th;
- m_peer->GetSize( tw, th );
- m_peer->GetPosition( tx, ty );
+ GetPeer()->GetSize( tw, th );
+ GetPeer()->GetPosition( tx, ty );
Rect rect = { ty,tx, ty+th, tx+tw };
if ( IsTopLevel() )
return ;
- bool hasFocus = m_peer->NeedsFocusRect() && HasFocus();
+ bool hasFocus = GetPeer()->NeedsFocusRect() && HasFocus();
// back to the surrounding frame rectangle
int tx,ty,tw,th;
- m_peer->GetSize( tw, th );
- m_peer->GetPosition( tx, ty );
+ GetPeer()->GetSize( tw, th );
+ GetPeer()->GetPosition( tx, ty );
Rect rect = { ty,tx, ty+th, tx+tw };
CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ;
wxASSERT( cgContext ) ;
- if ( m_peer->NeedsFrame() )
+ if ( GetPeer()->NeedsFrame() )
{
HIThemeFrameDrawInfo info ;
memset( &info, 0 , sizeof(info) ) ;
// as the native control might be not a 0/0 wx window coordinates, we have to offset
scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
- m_peer->ScrollRect( &scrollrect, dx, dy );
+ GetPeer()->ScrollRect( &scrollrect, dx, dy );
}
wxWindowMac *child;
// Raise the window to the top of the Z order
void wxWindowMac::Raise()
{
- m_peer->Raise();
+ GetPeer()->Raise();
}
// Lower the window to the bottom of the Z order
void wxWindowMac::Lower()
{
- m_peer->Lower();
+ GetPeer()->Lower();
}
// static wxWindow *gs_lastWhich = NULL;
int tx,ty,tw,th;
- m_peer->GetSize( tw, th );
- m_peer->GetPosition( tx, ty );
+ GetPeer()->GetSize( tw, th );
+ GetPeer()->GetPosition( tx, ty );
Rect r = { ty,tx, ty+th, tx+tw };
bool wxWindowMac::AcceptsFocus() const
{
- if ( MacIsUserPane() )
+ if ( GetPeer() == NULL || GetPeer()->IsUserPane() )
return wxWindowBase::AcceptsFocus();
else
- return m_peer->CanFocus();
+ return GetPeer()->CanFocus();
}
void wxWindowMac::MacSuperChangedPosition()
SInt32 border = 0 ;
- if ( m_peer && m_peer->NeedsFrame() )
+ if ( GetPeer() && GetPeer()->NeedsFrame() )
{
if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER))
{
// the wx borders are all symmetric in mac themes
long border = MacGetWXBorderSize() ;
- if ( m_peer )
+ if ( GetPeer() )
{
int left, top, right, bottom;
- m_peer->GetLayoutInset( left, top, right, bottom );
+ GetPeer()->GetLayoutInset( left, top, right, bottom );
border -= left;
}
// the wx borders are all symmetric in mac themes
long border = MacGetWXBorderSize() ;
- if ( m_peer )
+ if ( GetPeer() )
{
int left, top, right, bottom;
- m_peer->GetLayoutInset( left, top, right, bottom );
+ GetPeer()->GetLayoutInset( left, top, right, bottom );
border -= right;
}
// the wx borders are all symmetric in mac themes
long border = MacGetWXBorderSize() ;
- if ( m_peer )
+ if ( GetPeer() )
{
int left, top, right, bottom;
- m_peer->GetLayoutInset( left, top, right, bottom );
+ GetPeer()->GetLayoutInset( left, top, right, bottom );
border -= top;
}
// the wx borders are all symmetric in mac themes
long border = MacGetWXBorderSize() ;
- if ( m_peer )
+ if ( GetPeer() )
{
int left, top, right, bottom;
- m_peer->GetLayoutInset( left, top, right, bottom );
+ GetPeer()->GetLayoutInset( left, top, right, bottom );
border -= bottom;
}
if ( !wxWindowBase::Reparent(newParent) )
return false;
- m_peer->RemoveFromParent();
- m_peer->Embed( GetParent()->GetPeer() );
+ GetPeer()->RemoveFromParent();
+ GetPeer()->Embed( GetParent()->GetPeer() );
MacChildAdded();
return true;
bool wxWindowMac::IsShownOnScreen() const
{
- if ( m_peer && m_peer->IsOk() )
+ if ( GetPeer() && GetPeer()->IsOk() )
{
- bool peerVis = m_peer->IsVisible();
+ bool peerVis = GetPeer()->IsVisible();
bool wxVis = wxWindowBase::IsShownOnScreen();
if( peerVis != wxVis )
{
return wxVis;
}
- return m_peer->IsVisible();
+ return GetPeer()->IsVisible();
}
return wxWindowBase::IsShownOnScreen();
}