Files
libreoffice/vcl/source/window/clipping.cxx

710 lines
21 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <vcl/window.hxx>
#include <sal/types.h>
#include <salobj.hxx>
#include <window.h>
void Window::InitClipRegion()
{
DBG_TESTSOLARMUTEX();
Region aRegion;
// Put back backed up background
if ( mpWindowImpl->mpFrameData->mpFirstBackWin )
ImplInvalidateAllOverlapBackgrounds();
if ( mpWindowImpl->mbInPaint )
aRegion = *(mpWindowImpl->mpPaintRegion);
else
{
aRegion = *(ImplGetWinChildClipRegion());
// --- RTL -- only this region is in frame coordinates, so re-mirror it
// the mpWindowImpl->mpPaintRegion above is already correct (see ImplCallPaint()) !
if( ImplIsAntiparallel() )
ReMirror ( aRegion );
}
if ( mbClipRegion )
aRegion.Intersect( ImplPixelToDevicePixel( maRegion ) );
if ( aRegion.IsEmpty() )
mbOutputClipped = true;
else
{
mbOutputClipped = false;
SelectClipRegion( aRegion );
}
mbClipRegionSet = true;
mbInitClipRegion = false;
}
void Window::SetParentClipMode( sal_uInt16 nMode )
{
if ( mpWindowImpl->mpBorderWindow )
mpWindowImpl->mpBorderWindow->SetParentClipMode( nMode );
else
{
if ( !ImplIsOverlapWindow() )
{
mpWindowImpl->mnParentClipMode = nMode;
if ( nMode & PARENTCLIPMODE_CLIP )
mpWindowImpl->mpParent->mpWindowImpl->mbClipChildren = true;
}
}
}
sal_uInt16 Window::GetParentClipMode() const
{
if ( mpWindowImpl->mpBorderWindow )
return mpWindowImpl->mpBorderWindow->GetParentClipMode();
else
return mpWindowImpl->mnParentClipMode;
}
void Window::ExpandPaintClipRegion( const Region& rRegion )
{
if( mpWindowImpl->mpPaintRegion )
{
Region aPixRegion = LogicToPixel( rRegion );
Region aDevPixRegion = ImplPixelToDevicePixel( aPixRegion );
Region aWinChildRegion = *ImplGetWinChildClipRegion();
// --- RTL -- only this region is in frame coordinates, so re-mirror it
if( ImplIsAntiparallel() )
{
const OutputDevice *pOutDev = GetOutDev();
pOutDev->ReMirror( aWinChildRegion );
}
aDevPixRegion.Intersect( aWinChildRegion );
if( ! aDevPixRegion.IsEmpty() )
{
mpWindowImpl->mpPaintRegion->Union( aDevPixRegion );
mbInitClipRegion = true;
}
}
}
Region Window::GetWindowClipRegionPixel( sal_uInt16 nFlags ) const
{
Region aWinClipRegion;
if ( nFlags & WINDOW_GETCLIPREGION_NOCHILDREN )
{
if ( mpWindowImpl->mbInitWinClipRegion )
((Window*)this)->ImplInitWinClipRegion();
aWinClipRegion = mpWindowImpl->maWinClipRegion;
}
else
{
Region* pWinChildClipRegion = ((Window*)this)->ImplGetWinChildClipRegion();
aWinClipRegion = *pWinChildClipRegion;
// --- RTL --- remirror clip region before passing it to somebody
if( ImplIsAntiparallel() )
{
const OutputDevice *pOutDev = GetOutDev();
pOutDev->ReMirror( aWinClipRegion );
}
}
if ( nFlags & WINDOW_GETCLIPREGION_NULL )
{
Rectangle aWinRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) );
Region aWinRegion( aWinRect );
if ( aWinRegion == aWinClipRegion )
aWinClipRegion.SetNull();
}
aWinClipRegion.Move( -mnOutOffX, -mnOutOffY );
return aWinClipRegion;
}
Region Window::GetActiveClipRegion() const
{
Region aRegion(true);
if ( mpWindowImpl->mbInPaint )
{
aRegion = *(mpWindowImpl->mpPaintRegion);
aRegion.Move( -mnOutOffX, -mnOutOffY );
}
if ( mbClipRegion )
aRegion.Intersect( maRegion );
return PixelToLogic( aRegion );
}
void Window::ClipToPaintRegion(Rectangle& rDstRect)
{
const Region aPaintRgn(GetPaintRegion());
if (!aPaintRgn.IsNull())
rDstRect.Intersection(LogicToPixel(aPaintRgn.GetBoundRect()));
}
void Window::EnableClipSiblings( bool bClipSiblings )
{
if ( mpWindowImpl->mpBorderWindow )
mpWindowImpl->mpBorderWindow->EnableClipSiblings( bClipSiblings );
mpWindowImpl->mbClipSiblings = bClipSiblings;
}
void Window::ImplClipBoundaries( Region& rRegion, bool bThis, bool bOverlaps )
{
if ( bThis )
ImplIntersectWindowClipRegion( rRegion );
else if ( ImplIsOverlapWindow() )
{
// clip to frame if required
if ( !mpWindowImpl->mbFrame )
rRegion.Intersect( Rectangle( Point( 0, 0 ), Size( mpWindowImpl->mpFrameWindow->mnOutWidth, mpWindowImpl->mpFrameWindow->mnOutHeight ) ) );
if ( bOverlaps && !rRegion.IsEmpty() )
{
// Clip Overlap Siblings
Window* pStartOverlapWindow = this;
while ( !pStartOverlapWindow->mpWindowImpl->mbFrame )
{
Window* pOverlapWindow = pStartOverlapWindow->mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpFirstOverlap;
while ( pOverlapWindow && (pOverlapWindow != pStartOverlapWindow) )
{
pOverlapWindow->ImplExcludeOverlapWindows2( rRegion );
pOverlapWindow = pOverlapWindow->mpWindowImpl->mpNext;
}
pStartOverlapWindow = pStartOverlapWindow->mpWindowImpl->mpOverlapWindow;
}
// Clip Child Overlap Windows
ImplExcludeOverlapWindows( rRegion );
}
}
else
ImplGetParent()->ImplIntersectWindowClipRegion( rRegion );
}
bool Window::ImplClipChildren( Region& rRegion )
{
bool bOtherClip = false;
Window* pWindow = mpWindowImpl->mpFirstChild;
while ( pWindow )
{
if ( pWindow->mpWindowImpl->mbReallyVisible )
{
// read-out ParentClipMode-Flags
sal_uInt16 nClipMode = pWindow->GetParentClipMode();
if ( !(nClipMode & PARENTCLIPMODE_NOCLIP) &&
((nClipMode & PARENTCLIPMODE_CLIP) || (GetStyle() & WB_CLIPCHILDREN)) )
pWindow->ImplExcludeWindowRegion( rRegion );
else
bOtherClip = true;
}
pWindow = pWindow->mpWindowImpl->mpNext;
}
return bOtherClip;
}
void Window::ImplClipAllChildren( Region& rRegion )
{
Window* pWindow = mpWindowImpl->mpFirstChild;
while ( pWindow )
{
if ( pWindow->mpWindowImpl->mbReallyVisible )
pWindow->ImplExcludeWindowRegion( rRegion );
pWindow = pWindow->mpWindowImpl->mpNext;
}
}
void Window::ImplClipSiblings( Region& rRegion )
{
Window* pWindow = ImplGetParent()->mpWindowImpl->mpFirstChild;
while ( pWindow )
{
if ( pWindow == this )
break;
if ( pWindow->mpWindowImpl->mbReallyVisible )
pWindow->ImplExcludeWindowRegion( rRegion );
pWindow = pWindow->mpWindowImpl->mpNext;
}
}
void Window::ImplInitWinClipRegion()
{
// Build Window Region
mpWindowImpl->maWinClipRegion = Rectangle( Point( mnOutOffX, mnOutOffY ),
Size( mnOutWidth, mnOutHeight ) );
if ( mpWindowImpl->mbWinRegion )
mpWindowImpl->maWinClipRegion.Intersect( ImplPixelToDevicePixel( mpWindowImpl->maWinRegion ) );
// ClipSiblings
if ( mpWindowImpl->mbClipSiblings && !ImplIsOverlapWindow() )
ImplClipSiblings( mpWindowImpl->maWinClipRegion );
// Clip Parent Boundaries
ImplClipBoundaries( mpWindowImpl->maWinClipRegion, false, true );
// Clip Children
if ( (GetStyle() & WB_CLIPCHILDREN) || mpWindowImpl->mbClipChildren )
mpWindowImpl->mbInitChildRegion = true;
mpWindowImpl->mbInitWinClipRegion = false;
}
void Window::ImplInitWinChildClipRegion()
{
if ( !mpWindowImpl->mpFirstChild )
{
if ( mpWindowImpl->mpChildClipRegion )
{
delete mpWindowImpl->mpChildClipRegion;
mpWindowImpl->mpChildClipRegion = NULL;
}
}
else
{
if ( !mpWindowImpl->mpChildClipRegion )
mpWindowImpl->mpChildClipRegion = new Region( mpWindowImpl->maWinClipRegion );
else
*mpWindowImpl->mpChildClipRegion = mpWindowImpl->maWinClipRegion;
ImplClipChildren( *mpWindowImpl->mpChildClipRegion );
}
mpWindowImpl->mbInitChildRegion = false;
}
Region* Window::ImplGetWinChildClipRegion()
{
if ( mpWindowImpl->mbInitWinClipRegion )
ImplInitWinClipRegion();
if ( mpWindowImpl->mbInitChildRegion )
ImplInitWinChildClipRegion();
if ( mpWindowImpl->mpChildClipRegion )
return mpWindowImpl->mpChildClipRegion;
else
return &mpWindowImpl->maWinClipRegion;
}
bool Window::ImplSysObjClip( const Region* pOldRegion )
{
bool bUpdate = true;
if ( mpWindowImpl->mpSysObj )
{
bool bVisibleState = mpWindowImpl->mbReallyVisible;
if ( bVisibleState )
{
Region* pWinChildClipRegion = ImplGetWinChildClipRegion();
if ( !pWinChildClipRegion->IsEmpty() )
{
if ( pOldRegion )
{
Region aNewRegion = *pWinChildClipRegion;
pWinChildClipRegion->Intersect( *pOldRegion );
bUpdate = aNewRegion == *pWinChildClipRegion;
}
if ( mpWindowImpl->mpFrameData->mpFirstBackWin )
ImplInvalidateAllOverlapBackgrounds();
Region aRegion = *pWinChildClipRegion;
Rectangle aWinRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) );
Region aWinRectRegion( aWinRect );
sal_uInt16 nClipFlags = mpWindowImpl->mpSysObj->GetClipRegionType();
if ( aRegion == aWinRectRegion )
mpWindowImpl->mpSysObj->ResetClipRegion();
else
{
if ( nClipFlags & SAL_OBJECT_CLIP_EXCLUDERECTS )
{
aWinRectRegion.Exclude( aRegion );
aRegion = aWinRectRegion;
}
if ( !(nClipFlags & SAL_OBJECT_CLIP_ABSOLUTE) )
aRegion.Move( -mnOutOffX, -mnOutOffY );
// set/update clip region
RectangleVector aRectangles;
aRegion.GetRegionRectangles(aRectangles);
mpWindowImpl->mpSysObj->BeginSetClipRegion(aRectangles.size());
for(RectangleVector::const_iterator aRectIter(aRectangles.begin()); aRectIter != aRectangles.end(); ++aRectIter)
{
mpWindowImpl->mpSysObj->UnionClipRegion(
aRectIter->Left(),
aRectIter->Top(),
aRectIter->GetWidth(), // orig nWidth was ((R - L) + 1), same as GetWidth does
aRectIter->GetHeight()); // same for height
}
mpWindowImpl->mpSysObj->EndSetClipRegion();
}
}
else
bVisibleState = false;
}
// update visible status
mpWindowImpl->mpSysObj->Show( bVisibleState );
}
return bUpdate;
}
void Window::ImplUpdateSysObjChildrenClip()
{
if ( mpWindowImpl->mpSysObj && mpWindowImpl->mbInitWinClipRegion )
ImplSysObjClip( NULL );
Window* pWindow = mpWindowImpl->mpFirstChild;
while ( pWindow )
{
pWindow->ImplUpdateSysObjChildrenClip();
pWindow = pWindow->mpWindowImpl->mpNext;
}
}
void Window::ImplUpdateSysObjOverlapsClip()
{
ImplUpdateSysObjChildrenClip();
Window* pWindow = mpWindowImpl->mpFirstOverlap;
while ( pWindow )
{
pWindow->ImplUpdateSysObjOverlapsClip();
pWindow = pWindow->mpWindowImpl->mpNext;
}
}
void Window::ImplUpdateSysObjClip()
{
if ( !ImplIsOverlapWindow() )
{
ImplUpdateSysObjChildrenClip();
// siblings should recalculate their clip region
if ( mpWindowImpl->mbClipSiblings )
{
Window* pWindow = mpWindowImpl->mpNext;
while ( pWindow )
{
pWindow->ImplUpdateSysObjChildrenClip();
pWindow = pWindow->mpWindowImpl->mpNext;
}
}
}
else
mpWindowImpl->mpFrameWindow->ImplUpdateSysObjOverlapsClip();
}
bool Window::ImplSetClipFlagChildren( bool bSysObjOnlySmaller )
{
bool bUpdate = true;
if ( mpWindowImpl->mpSysObj )
{
Region* pOldRegion = NULL;
if ( bSysObjOnlySmaller && !mpWindowImpl->mbInitWinClipRegion )
pOldRegion = new Region( mpWindowImpl->maWinClipRegion );
mbInitClipRegion = true;
mpWindowImpl->mbInitWinClipRegion = true;
Window* pWindow = mpWindowImpl->mpFirstChild;
while ( pWindow )
{
if ( !pWindow->ImplSetClipFlagChildren( bSysObjOnlySmaller ) )
bUpdate = false;
pWindow = pWindow->mpWindowImpl->mpNext;
}
if ( !ImplSysObjClip( pOldRegion ) )
{
mbInitClipRegion = true;
mpWindowImpl->mbInitWinClipRegion = true;
bUpdate = false;
}
delete pOldRegion;
}
else
{
mbInitClipRegion = true;
mpWindowImpl->mbInitWinClipRegion = true;
Window* pWindow = mpWindowImpl->mpFirstChild;
while ( pWindow )
{
if ( !pWindow->ImplSetClipFlagChildren( bSysObjOnlySmaller ) )
bUpdate = false;
pWindow = pWindow->mpWindowImpl->mpNext;
}
}
return bUpdate;
}
bool Window::ImplSetClipFlagOverlapWindows( bool bSysObjOnlySmaller )
{
bool bUpdate = ImplSetClipFlagChildren( bSysObjOnlySmaller );
Window* pWindow = mpWindowImpl->mpFirstOverlap;
while ( pWindow )
{
if ( !pWindow->ImplSetClipFlagOverlapWindows( bSysObjOnlySmaller ) )
bUpdate = false;
pWindow = pWindow->mpWindowImpl->mpNext;
}
return bUpdate;
}
bool Window::ImplSetClipFlag( bool bSysObjOnlySmaller )
{
if ( !ImplIsOverlapWindow() )
{
bool bUpdate = ImplSetClipFlagChildren( bSysObjOnlySmaller );
Window* pParent = ImplGetParent();
if ( pParent &&
((pParent->GetStyle() & WB_CLIPCHILDREN) || (mpWindowImpl->mnParentClipMode & PARENTCLIPMODE_CLIP)) )
{
pParent->mbInitClipRegion = true;
pParent->mpWindowImpl->mbInitChildRegion = true;
}
// siblings should recalculate their clip region
if ( mpWindowImpl->mbClipSiblings )
{
Window* pWindow = mpWindowImpl->mpNext;
while ( pWindow )
{
if ( !pWindow->ImplSetClipFlagChildren( bSysObjOnlySmaller ) )
bUpdate = false;
pWindow = pWindow->mpWindowImpl->mpNext;
}
}
return bUpdate;
}
else
return mpWindowImpl->mpFrameWindow->ImplSetClipFlagOverlapWindows( bSysObjOnlySmaller );
}
void Window::ImplIntersectWindowClipRegion( Region& rRegion )
{
if ( mpWindowImpl->mbInitWinClipRegion )
ImplInitWinClipRegion();
rRegion.Intersect( mpWindowImpl->maWinClipRegion );
}
void Window::ImplIntersectWindowRegion( Region& rRegion )
{
rRegion.Intersect( Rectangle( Point( mnOutOffX, mnOutOffY ),
Size( mnOutWidth, mnOutHeight ) ) );
if ( mpWindowImpl->mbWinRegion )
rRegion.Intersect( ImplPixelToDevicePixel( mpWindowImpl->maWinRegion ) );
}
void Window::ImplExcludeWindowRegion( Region& rRegion )
{
if ( mpWindowImpl->mbWinRegion )
{
Point aPoint( mnOutOffX, mnOutOffY );
Region aRegion( Rectangle( aPoint,
Size( mnOutWidth, mnOutHeight ) ) );
aRegion.Intersect( ImplPixelToDevicePixel( mpWindowImpl->maWinRegion ) );
rRegion.Exclude( aRegion );
}
else
{
Point aPoint( mnOutOffX, mnOutOffY );
rRegion.Exclude( Rectangle( aPoint,
Size( mnOutWidth, mnOutHeight ) ) );
}
}
void Window::ImplExcludeOverlapWindows( Region& rRegion )
{
Window* pWindow = mpWindowImpl->mpFirstOverlap;
while ( pWindow )
{
if ( pWindow->mpWindowImpl->mbReallyVisible )
{
pWindow->ImplExcludeWindowRegion( rRegion );
pWindow->ImplExcludeOverlapWindows( rRegion );
}
pWindow = pWindow->mpWindowImpl->mpNext;
}
}
void Window::ImplExcludeOverlapWindows2( Region& rRegion )
{
if ( mpWindowImpl->mbReallyVisible )
ImplExcludeWindowRegion( rRegion );
ImplExcludeOverlapWindows( rRegion );
}
void Window::ImplIntersectAndUnionOverlapWindows( const Region& rInterRegion, Region& rRegion )
{
Window* pWindow = mpWindowImpl->mpFirstOverlap;
while ( pWindow )
{
if ( pWindow->mpWindowImpl->mbReallyVisible )
{
Region aTempRegion( rInterRegion );
pWindow->ImplIntersectWindowRegion( aTempRegion );
rRegion.Union( aTempRegion );
pWindow->ImplIntersectAndUnionOverlapWindows( rInterRegion, rRegion );
}
pWindow = pWindow->mpWindowImpl->mpNext;
}
}
void Window::ImplIntersectAndUnionOverlapWindows2( const Region& rInterRegion, Region& rRegion )
{
if ( mpWindowImpl->mbReallyVisible )
{
Region aTempRegion( rInterRegion );
ImplIntersectWindowRegion( aTempRegion );
rRegion.Union( aTempRegion );
}
ImplIntersectAndUnionOverlapWindows( rInterRegion, rRegion );
}
void Window::ImplCalcOverlapRegionOverlaps( const Region& rInterRegion, Region& rRegion )
{
// Clip Overlap Siblings
Window* pStartOverlapWindow;
if ( !ImplIsOverlapWindow() )
pStartOverlapWindow = mpWindowImpl->mpOverlapWindow;
else
pStartOverlapWindow = this;
while ( !pStartOverlapWindow->mpWindowImpl->mbFrame )
{
Window* pOverlapWindow = pStartOverlapWindow->mpWindowImpl->mpOverlapWindow->mpWindowImpl->mpFirstOverlap;
while ( pOverlapWindow && (pOverlapWindow != pStartOverlapWindow) )
{
pOverlapWindow->ImplIntersectAndUnionOverlapWindows2( rInterRegion, rRegion );
pOverlapWindow = pOverlapWindow->mpWindowImpl->mpNext;
}
pStartOverlapWindow = pStartOverlapWindow->mpWindowImpl->mpOverlapWindow;
}
// Clip Child Overlap Windows
if ( !ImplIsOverlapWindow() )
mpWindowImpl->mpOverlapWindow->ImplIntersectAndUnionOverlapWindows( rInterRegion, rRegion );
else
ImplIntersectAndUnionOverlapWindows( rInterRegion, rRegion );
}
void Window::ImplCalcOverlapRegion( const Rectangle& rSourceRect, Region& rRegion,
bool bChildren, bool bParent, bool bSiblings )
{
Region aRegion( rSourceRect );
if ( mpWindowImpl->mbWinRegion )
rRegion.Intersect( ImplPixelToDevicePixel( mpWindowImpl->maWinRegion ) );
Region aTempRegion;
Window* pWindow;
ImplCalcOverlapRegionOverlaps( aRegion, rRegion );
// Parent-Boundaries
if ( bParent )
{
pWindow = this;
if ( !ImplIsOverlapWindow() )
{
pWindow = ImplGetParent();
do
{
aTempRegion = aRegion;
pWindow->ImplExcludeWindowRegion( aTempRegion );
rRegion.Union( aTempRegion );
if ( pWindow->ImplIsOverlapWindow() )
break;
pWindow = pWindow->ImplGetParent();
}
while ( pWindow );
}
if ( pWindow && !pWindow->mpWindowImpl->mbFrame )
{
aTempRegion = aRegion;
aTempRegion.Exclude( Rectangle( Point( 0, 0 ), Size( mpWindowImpl->mpFrameWindow->mnOutWidth, mpWindowImpl->mpFrameWindow->mnOutHeight ) ) );
rRegion.Union( aTempRegion );
}
}
// Siblings
if ( bSiblings && !ImplIsOverlapWindow() )
{
pWindow = mpWindowImpl->mpParent->mpWindowImpl->mpFirstChild;
do
{
if ( pWindow->mpWindowImpl->mbReallyVisible && (pWindow != this) )
{
aTempRegion = aRegion;
pWindow->ImplIntersectWindowRegion( aTempRegion );
rRegion.Union( aTempRegion );
}
pWindow = pWindow->mpWindowImpl->mpNext;
}
while ( pWindow );
}
if ( bChildren )
{
pWindow = mpWindowImpl->mpFirstChild;
while ( pWindow )
{
if ( pWindow->mpWindowImpl->mbReallyVisible )
{
aTempRegion = aRegion;
pWindow->ImplIntersectWindowRegion( aTempRegion );
rRegion.Union( aTempRegion );
}
pWindow = pWindow->mpWindowImpl->mpNext;
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */