summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Le Ray <sebastien-libreoffice@orniz.org>2011-05-03 11:02:12 +0200
committerJan Holesovsky <kendy@suse.cz>2011-05-03 11:02:12 +0200
commit01fc4319e9668d0d5feeda2de71fdb5444c21c67 (patch)
tree373fa314c381271152054c145378fe33cfbe0867
parent12a958aa15dbc408932ba6d14da5a8021aeea754 (diff)
Use page bounding box for layout computations.
A lot of layout methods were using duplicate code to invalidate areas. This led to graphical glitches with 4 borders large shadow.
-rw-r--r--sw/source/core/inc/frmtool.hxx2
-rw-r--r--sw/source/core/inc/pagefrm.hxx13
-rw-r--r--sw/source/core/layout/layact.cxx63
-rw-r--r--sw/source/core/layout/pagechg.cxx5
-rw-r--r--sw/source/core/layout/paintfrm.cxx72
-rw-r--r--sw/source/core/view/pagepreviewlayout.cxx3
-rw-r--r--sw/source/core/view/viewsh.cxx2
7 files changed, 91 insertions, 69 deletions
diff --git a/sw/source/core/inc/frmtool.hxx b/sw/source/core/inc/frmtool.hxx
index b2577b42ba..98cbb54e11 100644
--- a/sw/source/core/inc/frmtool.hxx
+++ b/sw/source/core/inc/frmtool.hxx
@@ -72,7 +72,7 @@ void MA_FASTCALL DrawGraphic( const SvxBrushItem *, OutputDevice *,
// - method to align rectangle
// Created declaration here to avoid <extern> declarations
-void MA_FASTCALL SwAlignRect( SwRect &rRect, ViewShell *pSh );
+void MA_FASTCALL SwAlignRect( SwRect &rRect, const ViewShell *pSh );
// - method to align graphic rectangle
// Created declaration here to avoid <extern> declarations
diff --git a/sw/source/core/inc/pagefrm.hxx b/sw/source/core/inc/pagefrm.hxx
index c940f2640f..15dfed5528 100644
--- a/sw/source/core/inc/pagefrm.hxx
+++ b/sw/source/core/inc/pagefrm.hxx
@@ -114,7 +114,7 @@ class SwPageFrm: public SwFtnBossFrm
*/
static void GetHorizontalShadowRect( const SwRect& _rPageRect,
- ViewShell* _pViewShell,
+ const ViewShell* _pViewShell,
SwRect& _orBottomShadowRect,
bool bPaintLeftShadow,
bool bPaintRightShadow,
@@ -246,6 +246,8 @@ public:
inline void ValidateWordCount() const;
inline sal_Bool IsInvalid() const;
inline sal_Bool IsInvalidFly() const;
+ sal_Bool IsRightShadowNeeded() const;
+ sal_Bool IsLeftShadowNeeded() const;
sal_Bool IsInvalidFlyLayout() const { return bInvalidFlyLayout; }
sal_Bool IsInvalidFlyCntnt() const { return bInvalidFlyCntnt; }
sal_Bool IsInvalidFlyInCnt() const { return bInvalidFlyInCnt; }
@@ -307,7 +309,7 @@ public:
shadow with & position).
*/
static void PaintBorderAndShadow( const SwRect& _rPageRect,
- ViewShell* _pViewShell,
+ const ViewShell* _pViewShell,
bool bPaintLeftShadow,
bool bPaintRightShadow,
bool bRightSidebar );
@@ -330,9 +332,12 @@ public:
rectangle for the given page rectangle
*/
static void GetBorderAndShadowBoundRect( const SwRect& _rPageRect,
- ViewShell* _pViewShell,
+ const ViewShell* _pViewShell,
SwRect& _orBorderAndShadowBoundRect,
- const bool bRightSidebar );
+ const bool bLeftShadow,
+ const bool bRightShadow,
+ const bool bRightSidebar
+ );
static void PaintNotesSidebar(const SwRect& _rPageRect, ViewShell* _pViewShell, sal_uInt16 nPageNum, bool bRight);
static void PaintNotesSidebarArrows(const Point &aMiddleFirst, const Point &aMiddleSecond, ViewShell* _pViewShell, const Color aColorUp, const Color aColorDown);
diff --git a/sw/source/core/layout/layact.cxx b/sw/source/core/layout/layact.cxx
index 2275076a4e..a00165a563 100644
--- a/sw/source/core/layout/layact.cxx
+++ b/sw/source/core/layout/layact.cxx
@@ -1424,30 +1424,15 @@ sal_Bool SwLayAction::FormatLayout( SwLayoutFrm *pLay, sal_Bool bAddRect )
if ( pLay->IsPageFrm() )
{
SwPageFrm* pPageFrm = static_cast<SwPageFrm*>(pLay);
- const int nShadowWidth =
- pImp->GetShell()->GetOut()->PixelToLogic( Size( pPageFrm->ShadowPxWidth(), 0 ) ).Width();
+ const ViewShell *pSh = pLay->getRootFrm()->GetCurrShell();
- //mod #i6193# added sidebar width
- const SwPostItMgr* pPostItMgr = pImp->GetShell()->GetPostItMgr();
- const int nSidebarWidth = pPostItMgr && pPostItMgr->HasNotes() && pPostItMgr->ShowNotes() ? pPostItMgr->GetSidebarWidth() + pPostItMgr->GetSidebarBorderWidth() : 0;
- switch ( pPageFrm->SidebarPosition() )
+ if(pSh)
{
- case sw::sidebarwindows::SIDEBAR_LEFT:
- {
- aPaint.Left( aPaint.Left() - nSidebarWidth);
- aPaint.Right( aPaint.Right() + nShadowWidth);
- }
- break;
- case sw::sidebarwindows::SIDEBAR_RIGHT:
- {
- aPaint.Right( aPaint.Right() + nShadowWidth + nSidebarWidth);
- }
- break;
- case sw::sidebarwindows::SIDEBAR_NONE:
- // nothing to do
- break;
+ SwPageFrm::GetBorderAndShadowBoundRect(aPaint, pSh, aPaint,
+ pPageFrm->IsLeftShadowNeeded(), pPageFrm->IsRightShadowNeeded(),
+ pPageFrm->SidebarPosition() == sw::sidebarwindows::SIDEBAR_RIGHT);
}
- aPaint.Bottom( aPaint.Bottom() + nShadowWidth );
+
}
sal_Bool bPageInBrowseMode = pLay->IsPageFrm();
@@ -1499,38 +1484,46 @@ sal_Bool SwLayAction::FormatLayout( SwLayoutFrm *pLay, sal_Bool bAddRect )
const bool bLeftToRightViewLayout = pRoot->IsLeftToRightViewLayout();
const bool bPrev = bLeftToRightViewLayout ? pLay->GetPrev() : pLay->GetNext();
const bool bNext = bLeftToRightViewLayout ? pLay->GetNext() : pLay->GetPrev();
+ SwPageFrm* pPageFrm = static_cast<SwPageFrm*>(pLay);
+ const ViewShell *pSh = pLay->getRootFrm()->GetCurrShell();
+ SwRect aPageRect( pLay->Frm() );
+
+ if(pSh)
+ {
+ SwPageFrm::GetBorderAndShadowBoundRect(aPageRect, pSh,
+ aPageRect, pPageFrm->IsLeftShadowNeeded(), pPageFrm->IsRightShadowNeeded(),
+ pPageFrm->SidebarPosition() == sw::sidebarwindows::SIDEBAR_RIGHT);
+ }
if ( bPrev )
{
// top
- SwRect aSpaceToPrevPage( pLay->Frm() );
- const SwTwips nTop = aSpaceToPrevPage.Top() - nHalfDocBorder;
- if ( nTop >= 0 )
- aSpaceToPrevPage.Top( nTop );
+ SwRect aSpaceToPrevPage( aPageRect );
aSpaceToPrevPage.Bottom( pLay->Frm().Top() );
- pImp->GetShell()->AddPaintRect( aSpaceToPrevPage );
+ if(aSpaceToPrevPage.Height() > 0 && aSpaceToPrevPage.Width() > 0)
+ pImp->GetShell()->AddPaintRect( aSpaceToPrevPage );
// left
- aSpaceToPrevPage = pLay->Frm();
- const SwTwips nLeft = aSpaceToPrevPage.Left() - nHalfDocBorder;
- if ( nLeft >= 0 )
- aSpaceToPrevPage.Left( nLeft );
+ aSpaceToPrevPage = aPageRect;
aSpaceToPrevPage.Right( pLay->Frm().Left() );
- pImp->GetShell()->AddPaintRect( aSpaceToPrevPage );
+ if(aSpaceToPrevPage.Height() > 0 && aSpaceToPrevPage.Width() > 0)
+ pImp->GetShell()->AddPaintRect( aSpaceToPrevPage );
}
if ( bNext )
{
// bottom
- SwRect aSpaceToNextPage( pLay->Frm() );
+ SwRect aSpaceToNextPage( aPageRect );
aSpaceToNextPage.Bottom( aSpaceToNextPage.Bottom() + nHalfDocBorder );
aSpaceToNextPage.Top( pLay->Frm().Bottom() );
- pImp->GetShell()->AddPaintRect( aSpaceToNextPage );
+ if(aSpaceToNextPage.Height() > 0 && aSpaceToNextPage.Width() > 0)
+ pImp->GetShell()->AddPaintRect( aSpaceToNextPage );
// right
- aSpaceToNextPage = pLay->Frm();
+ aSpaceToNextPage = aPageRect;
aSpaceToNextPage.Right( aSpaceToNextPage.Right() + nHalfDocBorder );
aSpaceToNextPage.Left( pLay->Frm().Right() );
- pImp->GetShell()->AddPaintRect( aSpaceToNextPage );
+ if(aSpaceToNextPage.Height() > 0 && aSpaceToNextPage.Width() > 0)
+ pImp->GetShell()->AddPaintRect( aSpaceToNextPage );
}
}
}
diff --git a/sw/source/core/layout/pagechg.cxx b/sw/source/core/layout/pagechg.cxx
index d0e13eb655..f810f2fe7e 100644
--- a/sw/source/core/layout/pagechg.cxx
+++ b/sw/source/core/layout/pagechg.cxx
@@ -310,7 +310,7 @@ SwPageFrm::~SwPageFrm()
// including border and shadow area.
const bool bRightSidebar = (SidebarPosition() == sw::sidebarwindows::SIDEBAR_RIGHT);
SwRect aRetoucheRect;
- SwPageFrm::GetBorderAndShadowBoundRect( Frm(), pSh, aRetoucheRect, bRightSidebar );
+ SwPageFrm::GetBorderAndShadowBoundRect( Frm(), pSh, aRetoucheRect, IsLeftShadowNeeded(), IsRightShadowNeeded(), bRightSidebar );
pSh->AddPaintRect( aRetoucheRect );
}
}
@@ -674,7 +674,8 @@ void SwPageFrm::_UpdateAttr( const SfxPoolItem *pOld, const SfxPoolItem *pNew,
// page frame for determine 'old' rectangle - it's used for invalidating.
const bool bRightSidebar = (SidebarPosition() == sw::sidebarwindows::SIDEBAR_RIGHT);
SwRect aOldRectWithBorderAndShadow;
- SwPageFrm::GetBorderAndShadowBoundRect( aOldPageFrmRect, pSh, aOldRectWithBorderAndShadow, bRightSidebar );
+ SwPageFrm::GetBorderAndShadowBoundRect( aOldPageFrmRect, pSh, aOldRectWithBorderAndShadow,
+ IsLeftShadowNeeded(), IsRightShadowNeeded(), bRightSidebar );
pSh->InvalidateWindows( aOldRectWithBorderAndShadow );
}
rInvFlags |= 0x03;
diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx
index 7bc434bc11..e9637bedc9 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -1038,7 +1038,7 @@ void SwSubsRects::PaintSubsidiary( OutputDevice *pOut,
// OD 29.04.2003 #107169# - correction: adjust rectangle on pixel level in order
// to assure, that the border 'leaves its original pixel', if it has to.
// No prior adjustments for odd relation between pixel and twip.
-void MA_FASTCALL SwAlignRect( SwRect &rRect, ViewShell *pSh )
+void MA_FASTCALL SwAlignRect( SwRect &rRect, const ViewShell *pSh )
{
if( !rRect.HasArea() )
return;
@@ -2839,8 +2839,6 @@ SwRootFrm::Paint(SwRect const& rRect, SwPrintData const*const pPrintData) const
if ( bBookMode && pPage->GetPrev() && static_cast<const SwPageFrm*>(pPage->GetPrev())->IsEmptyPage() )
pPage = static_cast<const SwPageFrm*>(pPage->GetPrev());
- const bool bLTR = IsLeftToRightViewLayout();
-
// #i68597#
const bool bGridPainting(pSh->GetWin() && pSh->Imp()->HasDrawView() && pSh->Imp()->GetDrawView()->IsGridVisible());
@@ -2849,22 +2847,15 @@ SwRootFrm::Paint(SwRect const& rRect, SwPrintData const*const pPrintData) const
while ( pPage )
// <--
{
- // Paint right shadow in single page mode, or if we're on last page of
- // the doc, or if ???Lower()??? or if we're on a page with no right
- // sibling (OnRightPage should be renamed as OnEvenPage since it does
- // not take reading direction into account)
- const bool bPaintRightShadow = !bBookMode || (!pPage->GetNext()) || (pPage == Lower()) || (!bLTR && !pPage->OnRightPage()) || (bLTR && pPage->OnRightPage());
- // Have a full bottom shadow on side by side pages.
- // TODO Do not draw full shadow if our sibling hasn't the
- // same orientation
- const bool bPaintLeftShadow = !(bBookMode && pPage->GetPrev() &&
- ((!bLTR && !pPage->OnRightPage()) || (bLTR && pPage->OnRightPage())));
+ const bool bPaintRightShadow = pPage->IsRightShadowNeeded();
+ const bool bPaintLeftShadow = pPage->IsLeftShadowNeeded();
const bool bRightSidebar = pPage->SidebarPosition() == sw::sidebarwindows::SIDEBAR_RIGHT;
if ( !pPage->IsEmptyPage() )
{
SwRect aPaintRect;
- SwPageFrm::GetBorderAndShadowBoundRect( pPage->Frm(), pSh, aPaintRect, bRightSidebar );
+ SwPageFrm::GetBorderAndShadowBoundRect( pPage->Frm(), pSh, aPaintRect,
+ bPaintLeftShadow, bPaintRightShadow, bRightSidebar );
if ( aRect.IsOver( aPaintRect ) )
// <--
@@ -3017,7 +3008,8 @@ SwRootFrm::Paint(SwRect const& rRect, SwPrintData const*const pPrintData) const
const SwPageFrm& rFormatPage = pPage->GetFormatPage();
aEmptyPageRect.SSize() = rFormatPage.Frm().SSize();
- SwPageFrm::GetBorderAndShadowBoundRect( aEmptyPageRect, pSh, aPaintRect, bRightSidebar );
+ SwPageFrm::GetBorderAndShadowBoundRect( aEmptyPageRect, pSh, aPaintRect,
+ bPaintLeftShadow, bPaintRightShadow, bRightSidebar );
aPaintRect._Intersection( aRect );
if ( aRect.IsOver( aEmptyPageRect ) )
@@ -5216,6 +5208,31 @@ void SwPageFrm::PaintMarginArea( const SwRect& _rOutputRect,
const sal_Int8 SwPageFrm::mnShadowPxWidth = 9;
+sal_Bool SwPageFrm::IsRightShadowNeeded() const
+{
+ const ViewShell *pSh = getRootFrm()->GetCurrShell();
+ const bool bIsLTR = getRootFrm()->IsLeftToRightViewLayout();
+
+ // We paint the right shadow if we're not in book mode
+ // or if we've no sibling or are the last page of the "row"
+ return !pSh || (!pSh->GetViewOptions()->IsViewLayoutBookMode()) || !GetNext()
+ || (this == Lower()) || (bIsLTR && OnRightPage())
+ || (!bIsLTR && !OnRightPage());
+
+}
+
+sal_Bool SwPageFrm::IsLeftShadowNeeded() const
+{
+ const ViewShell *pSh = getRootFrm()->GetCurrShell();
+ const bool bIsLTR = getRootFrm()->IsLeftToRightViewLayout();
+
+ // We paint the left shadow if we're not in book mode
+ // or if we've no sibling or are the last page of the "row"
+ return !pSh || (!pSh->GetViewOptions()->IsViewLayoutBookMode()) || !GetPrev()
+ || (bIsLTR && !OnRightPage())
+ || (!bIsLTR && OnRightPage());
+}
+
/** determine rectangle for bottom page shadow
OD 12.02.2003 for #i9719# and #105645#
@@ -5223,7 +5240,7 @@ const sal_Int8 SwPageFrm::mnShadowPxWidth = 9;
@author OD
*/
/*static*/ void SwPageFrm::GetHorizontalShadowRect( const SwRect& _rPageRect,
- ViewShell* _pViewShell,
+ const ViewShell* _pViewShell,
SwRect& _orHorizontalShadowRect,
bool bPaintLeftShadow,
bool bPaintRightShadow,
@@ -5261,7 +5278,7 @@ const sal_Int8 SwPageFrm::mnShadowPxWidth = 9;
@author OD
*/
/*static*/ void SwPageFrm::PaintBorderAndShadow( const SwRect& _rPageRect,
- ViewShell* _pViewShell,
+ const ViewShell* _pViewShell,
bool bPaintLeftShadow,
bool bPaintRightShadow,
bool bRightSidebar )
@@ -5339,7 +5356,7 @@ const sal_Int8 SwPageFrm::mnShadowPxWidth = 9;
SwPageFrm::GetHorizontalShadowRect( _rPageRect, _pViewShell, aPaintRect, bPaintLeftShadow, bPaintRightShadow, bRightSidebar );
- // paint right shadow
+ // Right shadow & corners
if ( bPaintRightShadow )
{
pOut->DrawBitmapEx( pOut->PixelToLogic( Point( aPaintRect.Right() + 1, aPagePxRect.Bottom() + 1 - (aPageBottomRightShadow.GetSizePixel().Height() - mnShadowPxWidth) ) ),
@@ -5351,7 +5368,7 @@ const sal_Int8 SwPageFrm::mnShadowPxWidth = 9;
pOut->DrawBitmapEx( pOut->PixelToLogic( Point( aPaintRect.Right() + mnShadowPxWidth, aPagePxRect.Top() + mnShadowPxWidth - 1) ), aPageRightShadow );
}
- // paint top & bottom shadow
+ // Left shadows and corners
if(bPaintLeftShadow)
{
const long lLeft = aPaintRect.Left() - aPageBottomLeftShadow.GetSizePixel().Width();
@@ -5362,6 +5379,7 @@ const sal_Int8 SwPageFrm::mnShadowPxWidth = 9;
aPageLeftShadow.Scale( 1, aPagePxRect.Height() - 2 * (mnShadowPxWidth - 1) );
pOut->DrawBitmapEx( pOut->PixelToLogic( Point( lLeft, aPagePxRect.Top() + mnShadowPxWidth - 1) ), aPageLeftShadow );
}
+
BitmapEx aPageBottomShadow = aPageBottomShadowBase;
aPageBottomShadow.Scale( aPaintRect.Width(), 1 );
pOut->DrawBitmapEx( pOut->PixelToLogic( Point( aPaintRect.Left(), aPagePxRect.Bottom() + 1 ) ), aPageBottomShadow);
@@ -5494,24 +5512,28 @@ const sal_Int8 SwPageFrm::mnShadowPxWidth = 9;
author OD
*/
/*static*/ void SwPageFrm::GetBorderAndShadowBoundRect( const SwRect& _rPageRect,
- ViewShell* _pViewShell,
+ const ViewShell* _pViewShell,
SwRect& _orBorderAndShadowBoundRect,
- bool bRightSidebar )
+ bool bLeftShadow,
+ bool bRightShadow,
+ bool bRightSidebar
+ )
{
SwRect aAlignedPageRect( _rPageRect );
::SwAlignRect( aAlignedPageRect, _pViewShell );
SwRect aPagePxRect =
_pViewShell->GetOut()->LogicToPixel( aAlignedPageRect.SVRect() );
aPagePxRect.Bottom( aPagePxRect.Bottom() + mnShadowPxWidth + 1 );
- aPagePxRect.Top( aPagePxRect.Top() - mnShadowPxWidth );
+ aPagePxRect.Top( aPagePxRect.Top() - mnShadowPxWidth - 1 );
SwRect aTmpRect;
- // Always ask for full shadow
+ // Always ask for full shadow since we want a bounding rect
+ // including at least the page frame
SwPageFrm::GetHorizontalShadowRect( _rPageRect, _pViewShell, aTmpRect, false, false, bRightSidebar );
- aPagePxRect.Left( aTmpRect.Left() - mnShadowPxWidth);
- aPagePxRect.Right( aTmpRect.Right() + mnShadowPxWidth + 1);
+ if(bLeftShadow) aPagePxRect.Left( aTmpRect.Left() - mnShadowPxWidth - 1);
+ if(bRightShadow) aPagePxRect.Right( aTmpRect.Right() + mnShadowPxWidth + 1);
_orBorderAndShadowBoundRect = _pViewShell->GetOut()->PixelToLogic( aPagePxRect.SVRect() );
}
diff --git a/sw/source/core/view/pagepreviewlayout.cxx b/sw/source/core/view/pagepreviewlayout.cxx
index 64828eb83a..ade1164024 100644
--- a/sw/source/core/view/pagepreviewlayout.cxx
+++ b/sw/source/core/view/pagepreviewlayout.cxx
@@ -1073,7 +1073,8 @@ bool SwPagePreviewLayout::Paint( const Rectangle _aOutRect ) const
// #i80691# paint page border and shadow
{
SwRect aPageBorderRect;
- SwPageFrm::GetBorderAndShadowBoundRect( SwRect( aPageRect ), &mrParentViewShell, aPageBorderRect, true );
+ SwPageFrm::GetBorderAndShadowBoundRect( SwRect( aPageRect ), &mrParentViewShell, aPageBorderRect,
+ (*aPageIter)->pPage->IsLeftShadowNeeded(), (*aPageIter)->pPage->IsRightShadowNeeded(), true );
const Region aDLRegion(aPageBorderRect.SVRect());
mrParentViewShell.DLPrePaint2(aDLRegion);
SwPageFrm::PaintBorderAndShadow( aPageRect, &mrParentViewShell, true, false, true );
diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx
index 9ee2eb6fd5..bbb846ea68 100644
--- a/sw/source/core/view/viewsh.cxx
+++ b/sw/source/core/view/viewsh.cxx
@@ -1012,7 +1012,7 @@ void ViewShell::VisPortChgd( const SwRect &rRect)
{
SwRect aShadowRect;
SwPageFrm::GetBorderAndShadowBoundRect(aPageRect, this,
- aShadowRect, aSidebarPos == sw::sidebarwindows::SIDEBAR_RIGHT);
+ aShadowRect, pPage->IsLeftShadowNeeded(), pPage->IsRightShadowNeeded(), aSidebarPos == sw::sidebarwindows::SIDEBAR_RIGHT);
nPageLeft = aShadowRect.Left();
nPageRight = aShadowRect.Right();
}