guard against an m_peer being NULL which is the case for a wxMenuBar, and here tools with introspection from python crash on OS X because they display all attributes in inheritance ...

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@52217 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2008-03-01 16:45:55 +00:00
parent c170f4aeec
commit f7a5176212

View File

@@ -946,6 +946,9 @@ wxMAC_DEFINE_PROC_GETTER( ControlActionUPP , wxMacLiveScrollbarActionProc ) ;
// implementation // implementation
// =========================================================================== // ===========================================================================
// note that we are now guarding against m_peer being NULL which happens if the real class used
// is a wxMenuBar, as in wx inheritance this also is a wxWindow
WX_DECLARE_HASH_MAP(ControlRef, wxWindowMac*, wxPointerHash, wxPointerEqual, MacControlMap); WX_DECLARE_HASH_MAP(ControlRef, wxWindowMac*, wxPointerHash, wxPointerEqual, MacControlMap);
static MacControlMap wxWinMacControlList; static MacControlMap wxWinMacControlList;
@@ -1109,7 +1112,10 @@ wxWindowMac::~wxWindowMac()
WXWidget wxWindowMac::GetHandle() const WXWidget wxWindowMac::GetHandle() const
{ {
if( m_peer )
return (WXWidget) m_peer->GetControlRef() ; return (WXWidget) m_peer->GetControlRef() ;
else
return NULL;
} }
void wxWindowMac::MacInstallEventHandler( WXWidget control ) void wxWindowMac::MacInstallEventHandler( WXWidget control )
@@ -1282,6 +1288,7 @@ void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant )
void wxWindowMac::MacUpdateControlFont() void wxWindowMac::MacUpdateControlFont()
{ {
if ( m_peer )
m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ; m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
// do not trigger refreshes upon invisible and possible partly created objects // do not trigger refreshes upon invisible and possible partly created objects
if ( MacIsReallyShown() ) if ( MacIsReallyShown() )
@@ -1331,6 +1338,8 @@ bool wxWindowMac::SetBackgroundColour(const wxColour& col )
void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush )
{ {
m_macBackgroundBrush = brush ; m_macBackgroundBrush = brush ;
if ( m_peer )
m_peer->SetBackground( brush ) ; m_peer->SetBackground( brush ) ;
} }
@@ -1350,6 +1359,7 @@ bool wxWindowMac::MacCanFocus() const
else else
{ {
UInt32 features = 0 ; UInt32 features = 0 ;
if ( m_peer )
m_peer->GetFeatures( &features ) ; m_peer->GetFeatures( &features ) ;
return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ; return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ;
@@ -1358,6 +1368,9 @@ bool wxWindowMac::MacCanFocus() const
void wxWindowMac::SetFocus() void wxWindowMac::SetFocus()
{ {
if ( m_peer == NULL )
return;
if ( !AcceptsFocus() ) if ( !AcceptsFocus() )
return ; return ;
@@ -1371,6 +1384,8 @@ void wxWindowMac::SetFocus()
wxLogTrace(_T("Focus"), _T("SetFocus(%p)"), wx_static_cast(void*, this)); wxLogTrace(_T("Focus"), _T("SetFocus(%p)"), wx_static_cast(void*, this));
OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ; OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ;
wxLogTrace(_T("Focus"), _T("m_peer->SetFocus received %d"), err);
if ( err == errCouldntSetFocus ) if ( err == errCouldntSetFocus )
return ; return ;
@@ -1498,7 +1513,8 @@ bool wxWindowMac::MacGetBoundsForControl(
// Get window size (not client size) // Get window size (not client size)
void wxWindowMac::DoGetSize(int *x, int *y) const void wxWindowMac::DoGetSize(int *x, int *y) const
{ {
Rect bounds ; Rect bounds = { 0,0,0,0 };
if( m_peer )
m_peer->GetRect( &bounds ) ; m_peer->GetRect( &bounds ) ;
if (x) if (x)
@@ -1510,7 +1526,8 @@ void wxWindowMac::DoGetSize(int *x, int *y) const
// get the position of the bounds of this window in client coordinates of its parent // get the position of the bounds of this window in client coordinates of its parent
void wxWindowMac::DoGetPosition(int *x, int *y) const void wxWindowMac::DoGetPosition(int *x, int *y) const
{ {
Rect bounds ; Rect bounds = { 0,0,0,0 };
if ( m_peer )
m_peer->GetRect( &bounds ) ; m_peer->GetRect( &bounds ) ;
int x1 = bounds.left ; int x1 = bounds.left ;
@@ -1710,7 +1727,7 @@ void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , in
{ {
RgnHandle rgn = NewRgn() ; RgnHandle rgn = NewRgn() ;
if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) if ( m_peer != NULL && m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
{ {
Rect structure, content ; Rect structure, content ;
@@ -1736,7 +1753,7 @@ wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const
wxSize sizeTotal = size; wxSize sizeTotal = size;
RgnHandle rgn = NewRgn() ; RgnHandle rgn = NewRgn() ;
if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) if ( m_peer != NULL && m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
{ {
Rect content, structure ; Rect content, structure ;
GetRegionBounds( rgn , &content ) ; GetRegionBounds( rgn , &content ) ;
@@ -1761,13 +1778,16 @@ void wxWindowMac::DoGetClientSize( int *x, int *y ) const
{ {
int ww, hh; int ww, hh;
Rect content = { 0,0,0,0 };
if ( m_peer )
{
RgnHandle rgn = NewRgn() ; RgnHandle rgn = NewRgn() ;
Rect content ;
if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
GetRegionBounds( rgn , &content ) ; GetRegionBounds( rgn , &content ) ;
else else
m_peer->GetRect( &content ) ; m_peer->GetRect( &content ) ;
DisposeRgn( rgn ) ; DisposeRgn( rgn ) ;
}
ww = content.right - content.left ; ww = content.right - content.left ;
hh = content.bottom - content.top ; hh = content.bottom - content.top ;
@@ -1989,7 +2009,7 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
if ( actualWidth != former_w || actualHeight != former_h ) if ( actualWidth != former_w || actualHeight != former_h )
doResize = true ; doResize = true ;
if ( doMove || doResize ) if ( m_peer != NULL && ( doMove || doResize ) )
{ {
// as the borders are drawn outside the native control, we adjust now // as the borders are drawn outside the native control, we adjust now
@@ -2034,7 +2054,7 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
wxSize wxWindowMac::DoGetBestSize() const wxSize wxWindowMac::DoGetBestSize() const
{ {
if ( m_macIsUserPane || IsTopLevel() ) if ( m_peer == NULL || m_macIsUserPane || IsTopLevel() )
return wxWindowBase::DoGetBestSize() ; return wxWindowBase::DoGetBestSize() ;
Rect bestsize = { 0 , 0 , 0 , 0 } ; Rect bestsize = { 0 , 0 , 0 , 0 } ;
@@ -2145,9 +2165,12 @@ void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
} }
wxPoint wxWindowMac::GetClientAreaOrigin() const wxPoint wxWindowMac::GetClientAreaOrigin() const
{
Rect content = { 0,0,0,0 };
if ( m_peer )
{ {
RgnHandle rgn = NewRgn() ; RgnHandle rgn = NewRgn() ;
Rect content ;
if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr ) if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
{ {
GetRegionBounds( rgn , &content ) ; GetRegionBounds( rgn , &content ) ;
@@ -2159,6 +2182,7 @@ wxPoint wxWindowMac::GetClientAreaOrigin() const
} }
DisposeRgn( rgn ) ; DisposeRgn( rgn ) ;
}
return wxPoint( content.left + MacGetLeftBorderSize() , content.top + MacGetTopBorderSize() ); return wxPoint( content.left + MacGetLeftBorderSize() , content.top + MacGetTopBorderSize() );
} }
@@ -2218,6 +2242,7 @@ bool wxWindowMac::Enable(bool enable)
if ( !wxWindowBase::Enable(enable) ) if ( !wxWindowBase::Enable(enable) )
return false; return false;
if ( m_peer )
m_peer->Enable( enable ) ; m_peer->Enable( enable ) ;
if ( former != MacIsReallyEnabled() ) if ( former != MacIsReallyEnabled() )
@@ -2331,12 +2356,18 @@ bool wxWindowMac::MacIsReallyShown()
bool wxWindowMac::MacIsReallyEnabled() bool wxWindowMac::MacIsReallyEnabled()
{ {
if ( m_peer )
return m_peer->IsEnabled() ; return m_peer->IsEnabled() ;
else
return false;
} }
bool wxWindowMac::MacIsReallyHilited() bool wxWindowMac::MacIsReallyHilited()
{ {
if ( m_peer )
return m_peer->IsActive(); return m_peer->IsActive();
else
return false;
} }
void wxWindowMac::MacFlashInvalidAreas() void wxWindowMac::MacFlashInvalidAreas()
@@ -2347,18 +2378,26 @@ void wxWindowMac::MacFlashInvalidAreas()
} }
int wxWindowMac::GetCharHeight() const int wxWindowMac::GetCharHeight() const
{
if ( m_peer )
{ {
wxClientDC dc( (wxWindow*)this ) ; wxClientDC dc( (wxWindow*)this ) ;
return dc.GetCharHeight() ; return dc.GetCharHeight() ;
} }
else
return 16; // an arbitrary amount, just to avoid problems with introspection on a wxMenuBar
}
int wxWindowMac::GetCharWidth() const int wxWindowMac::GetCharWidth() const
{
if ( m_peer )
{ {
wxClientDC dc( (wxWindow*)this ) ; wxClientDC dc( (wxWindow*)this ) ;
return dc.GetCharWidth() ; return dc.GetCharWidth() ;
} }
else
return 8; // an arbitrary amount, just to avoid problems with introspection on a wxMenuBar
}
void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y, void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
int *descent, int *externalLeading, const wxFont *theFont ) const int *descent, int *externalLeading, const wxFont *theFont ) const
@@ -2547,7 +2586,7 @@ void wxWindowMac::MacPaintGrowBox()
return ; return ;
#if wxMAC_USE_CORE_GRAPHICS #if wxMAC_USE_CORE_GRAPHICS
if ( MacHasScrollBarCorner() ) if ( m_peer != NULL && MacHasScrollBarCorner() )
{ {
Rect rect ; Rect rect ;
@@ -2579,7 +2618,7 @@ void wxWindowMac::MacPaintGrowBox()
void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin ) void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin )
{ {
if ( IsTopLevel() ) if ( m_peer == NULL || IsTopLevel() )
return ; return ;
Rect rect ; Rect rect ;
@@ -2731,6 +2770,7 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
int width , height ; int width , height ;
GetClientSize( &width , &height ) ; GetClientSize( &width , &height ) ;
if ( m_peer != NULL )
{ {
// note there currently is a bug in OSX which makes inefficient refreshes in case an entire control // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
// area is scrolled, this does not occur if width and height are 2 pixels less, // area is scrolled, this does not occur if width and height are 2 pixels less,
@@ -2852,7 +2892,7 @@ void wxWindowMac::OnSetFocus( wxFocusEvent& event )
//wxChildFocusEvent eventFocus(this); //wxChildFocusEvent eventFocus(this);
//(void)GetEventHandler()->ProcessEvent(eventFocus); //(void)GetEventHandler()->ProcessEvent(eventFocus);
if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() ) if ( m_peer != NULL && MacGetTopLevelWindow() && m_peer->NeedsFocusRect() )
{ {
#if wxMAC_USE_CORE_GRAPHICS #if wxMAC_USE_CORE_GRAPHICS
GetParent()->Refresh() ; GetParent()->Refresh() ;
@@ -2901,12 +2941,14 @@ void wxWindowMac::OnInternalIdle()
// Raise the window to the top of the Z order // Raise the window to the top of the Z order
void wxWindowMac::Raise() void wxWindowMac::Raise()
{ {
if( m_peer )
m_peer->SetZOrder( true , NULL ) ; m_peer->SetZOrder( true , NULL ) ;
} }
// Lower the window to the bottom of the Z order // Lower the window to the bottom of the Z order
void wxWindowMac::Lower() void wxWindowMac::Lower()
{ {
if ( m_peer )
m_peer->SetZOrder( false , NULL ) ; m_peer->SetZOrder( false , NULL ) ;
} }
@@ -2966,6 +3008,8 @@ void wxWindowMac::ClearBackground()
void wxWindowMac::Update() void wxWindowMac::Update()
{ {
if ( m_peer == NULL )
return ;
#if TARGET_API_MAC_OSX #if TARGET_API_MAC_OSX
wxTopLevelWindowMac* top = MacGetTopLevelWindow(); wxTopLevelWindowMac* top = MacGetTopLevelWindow();
if (top) if (top)
@@ -3029,6 +3073,9 @@ void wxWindowMac::MacUpdateClippedRects() const
if ( m_cachedClippedRectValid ) if ( m_cachedClippedRectValid )
return ; return ;
if ( m_peer == NULL )
return;
// includeOuterStructures is true if we try to draw somthing like a focus ring etc. // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
// also a window dc uses this, in this case we only clip in the hierarchy for hard // also a window dc uses this, in this case we only clip in the hierarchy for hard
// borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
@@ -3590,12 +3637,14 @@ bool wxWindowMac::Reparent(wxWindowBase *newParentBase)
return false; return false;
// copied from MacPostControlCreate // copied from MacPostControlCreate
if ( m_peer )
{
ControlRef container = (ControlRef) GetParent()->GetHandle() ; ControlRef container = (ControlRef) GetParent()->GetHandle() ;
wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
::EmbedControl( m_peer->GetControlRef() , container ) ; ::EmbedControl( m_peer->GetControlRef() , container ) ;
}
return true; return true;
} }