calculating vis regions as rects (faster for Quartz) and caching the results for all implementations

fixing the background erase event always to have a wxWindowDC (had a wxClientDC in non-toplevel cases before, leading to a off-by-border error when erasing)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33220 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2005-03-31 17:25:53 +00:00
parent a45ff29798
commit 5c840e5ba4

View File

@@ -222,6 +222,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
{ {
if ( thisWindow->GetPeer()->IsCompositing() == false ) if ( thisWindow->GetPeer()->IsCompositing() == false )
{ {
/*
if ( thisWindow->GetPeer()->IsRootControl() == false ) if ( thisWindow->GetPeer()->IsRootControl() == false )
{ {
GetControlBounds( thisWindow->GetPeer()->GetControlRef() , &controlBounds ) ; GetControlBounds( thisWindow->GetPeer()->GetControlRef() , &controlBounds ) ;
@@ -230,6 +231,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
{ {
thisWindow->GetPeer()->GetRect( &controlBounds ) ; thisWindow->GetPeer()->GetRect( &controlBounds ) ;
} }
*/
allocatedRgn = NewRgn() ; allocatedRgn = NewRgn() ;
CopyRgn( updateRgn , allocatedRgn ) ; CopyRgn( updateRgn , allocatedRgn ) ;
OffsetRgn( allocatedRgn , -controlBounds.left , -controlBounds.top ) ; OffsetRgn( allocatedRgn , -controlBounds.left , -controlBounds.top ) ;
@@ -749,6 +751,7 @@ void wxWindowMac::Init()
m_cgContextRef = NULL ; m_cgContextRef = NULL ;
#endif #endif
m_clipChildren = false ; m_clipChildren = false ;
m_cachedClippedRectValid = false ;
// we need a valid font for the encodings // we need a valid font for the encodings
wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
} }
@@ -1342,10 +1345,14 @@ void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
if ( !IsTopLevel() ) if ( !IsTopLevel() )
{ {
wxMacControl::Convert( &pt , MacGetTopLevelWindow()->m_peer , m_peer ) ; wxTopLevelWindowMac* top = MacGetTopLevelWindow();
if (top)
{
wxMacControl::Convert( &pt , top->m_peer , m_peer ) ;
pt.x += MacGetLeftBorderSize() ; pt.x += MacGetLeftBorderSize() ;
pt.y += MacGetTopBorderSize() ; pt.y += MacGetTopBorderSize() ;
} }
}
if ( x ) *x = (int) pt.x ; if ( x ) *x = (int) pt.x ;
if ( y ) *y = (int) pt.y ; if ( y ) *y = (int) pt.y ;
@@ -1742,6 +1749,7 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
MacInvalidateBorders() ; MacInvalidateBorders() ;
m_cachedClippedRectValid = false ;
m_peer->SetRect( &r ) ; m_peer->SetRect( &r ) ;
if ( doMove ) if ( doMove )
@@ -2726,18 +2734,49 @@ wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
} }
return win ; return win ;
} }
wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
const wxRect& wxWindowMac::MacGetClippedRect() const
{ {
MacUpdateClippedRects() ;
return m_cachedClippedRect ;
}
const wxRect&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
{
MacUpdateClippedRects() ;
return m_cachedClippedRectWithOuterStructure ;
}
const wxRegion& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
{
static wxRegion emptyrgn ;
if ( !m_isBeingDeleted && MacIsReallyShown() /*m_peer->IsVisible() */ )
{
MacUpdateClippedRects() ;
if ( includeOuterStructures )
return m_cachedClippedRegionWithOuterStructure ;
else
return m_cachedClippedRegion ;
}
else
{
return emptyrgn ;
}
}
void wxWindowMac::MacUpdateClippedRects() const
{
if ( m_cachedClippedRectValid )
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
// to add focus borders everywhere // to add focus borders everywhere
Rect r ; Rect r ;
RgnHandle visRgn = NewRgn() ; Rect rIncludingOuterStructures ;
RgnHandle tempRgn = NewRgn() ;
if ( !m_isBeingDeleted && MacIsReallyShown() /*m_peer->IsVisible() */ )
{
m_peer->GetRect( &r ) ; m_peer->GetRect( &r ) ;
r.left -= MacGetLeftBorderSize() ; r.left -= MacGetLeftBorderSize() ;
r.top -= MacGetTopBorderSize() ; r.top -= MacGetTopBorderSize() ;
@@ -2749,14 +2788,13 @@ wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
r.left = 0 ; r.left = 0 ;
r.top = 0 ; r.top = 0 ;
if ( includeOuterStructures ) rIncludingOuterStructures = r ;
InsetRect( &r , -4 , -4 ) ; InsetRect( &rIncludingOuterStructures , -4 , -4 ) ;
RectRgn( visRgn , &r ) ;
if ( !IsTopLevel() ) if ( !IsTopLevel() )
{ {
wxWindow* child = this ; const wxWindow* child = this ;
wxWindow* parent = child->GetParent() ; const wxWindow* parent = child->GetParent() ;
while( parent ) while( parent )
{ {
int x , y ; int x , y ;
@@ -2778,30 +2816,38 @@ wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
parent->MacWindowToRootWindow( &x, &y ) ; parent->MacWindowToRootWindow( &x, &y ) ;
MacRootWindowToWindow( &x , &y ) ; MacRootWindowToWindow( &x , &y ) ;
if ( !includeOuterStructures || ( Rect rparent = {
parent->MacClipChildren() || y + parent->MacGetTopBorderSize() , x + parent->MacGetLeftBorderSize() ,
( parent->GetParent() && parent->GetParent()->MacClipGrandChildren() ) y + size.y - parent->MacGetBottomBorderSize() ,
) ) x + size.x - parent->MacGetRightBorderSize() } ;
{
SetRectRgn( tempRgn ,
x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
x + size.x - parent->MacGetRightBorderSize(),
y + size.y - parent->MacGetBottomBorderSize()) ;
SectRgn( visRgn , tempRgn , visRgn ) ; // the content will always be clipped
SectRect( &r , &rparent , &r ) ;
// the structure only at 'hard' borders
if ( parent->MacClipChildren() ||
( parent->GetParent() && parent->GetParent()->MacClipGrandChildren() ) )
{
SectRect( &rIncludingOuterStructures , &rparent , &rIncludingOuterStructures ) ;
} }
if ( parent->IsTopLevel() ) if ( parent->IsTopLevel() )
break ; break ;
child = parent ; child = parent ;
parent = child->GetParent() ; parent = child->GetParent() ;
} }
} }
}
wxRegion vis = visRgn ; m_cachedClippedRect = wxRect( r.left , r.top , r.right - r.left , r.bottom - r.top ) ;
DisposeRgn( visRgn ) ; m_cachedClippedRectWithOuterStructure = wxRect(
DisposeRgn( tempRgn ) ; rIncludingOuterStructures.left , rIncludingOuterStructures.top ,
return vis ; rIncludingOuterStructures.right - rIncludingOuterStructures.left ,
rIncludingOuterStructures.bottom - rIncludingOuterStructures.top ) ;
m_cachedClippedRegionWithOuterStructure = wxRegion( m_cachedClippedRectWithOuterStructure ) ;
m_cachedClippedRegion = wxRegion( m_cachedClippedRect ) ;
m_cachedClippedRectValid = true ;
} }
/* /*
@@ -2830,12 +2876,12 @@ bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
// for all the others only their client area, otherwise they // for all the others only their client area, otherwise they
// might be drawing with full alpha and eg put blue into // might be drawing with full alpha and eg put blue into
// the grow-box area of a scrolled window (scroll sample) // the grow-box area of a scrolled window (scroll sample)
wxDC* dc ; wxDC* dc = new wxWindowDC(this);
if ( IsTopLevel() ) if ( IsTopLevel() )
dc = new wxWindowDC(this);
else
dc = new wxClientDC(this);
dc->SetClippingRegion(wxRegion(updatergn)); dc->SetClippingRegion(wxRegion(updatergn));
else
dc->SetClippingRegion(wxRegion(newupdate));
wxEraseEvent eevent( GetId(), dc ); wxEraseEvent eevent( GetId(), dc );
eevent.SetEventObject( this ); eevent.SetEventObject( this );
GetEventHandler()->ProcessEvent( eevent ); GetEventHandler()->ProcessEvent( eevent );
@@ -3055,6 +3101,7 @@ bool wxWindowMac::AcceptsFocus() const
void wxWindowMac::MacSuperChangedPosition() void wxWindowMac::MacSuperChangedPosition()
{ {
m_cachedClippedRectValid = false ;
// only window-absolute structures have to be moved i.e. controls // only window-absolute structures have to be moved i.e. controls
wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); wxWindowList::compatibility_iterator node = GetChildren().GetFirst();