summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorAshod Nakashian <ashodnakashian@yahoo.com>2015-10-30 13:58:47 -0400
committerCaolán McNamara <caolanm@redhat.com>2015-11-10 11:51:58 +0000
commit40f3a942448facb900b422d30f64b75d7cac7f0f (patch)
tree7240b0ed0481f93af893739d7895d92f2d7121ec /sw
parentcec647c42a07091d946723cdf711aa3b56d0b6cf (diff)
tdf#39080 Hide Whitespace improvements
Moved the page resizing from SwLayoutFrm::Format to SwPageFrm::MakeAll and calculated the new page height more accurately based on the content (stolen from the browser-mode height calculation, to be refactored). This fixes issues with repagination with certain contents. Removed unnecessary ToggleLayoutMode calls and prevented clicking between pages in single-view mode to jump the cursor. Change-Id: I5662dd26efff66d6e95b8fd4dcf8564588adbbb7 Reviewed-on: https://gerrit.libreoffice.org/19699 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/core/inc/pagefrm.hxx3
-rw-r--r--sw/source/core/layout/calcmove.cxx92
-rw-r--r--sw/source/core/layout/wsfrm.cxx13
-rw-r--r--sw/source/uibase/docvw/edtwin.cxx15
-rw-r--r--sw/source/uibase/uiview/view0.cxx5
-rw-r--r--sw/source/uibase/uno/unomod.cxx2
6 files changed, 107 insertions, 23 deletions
diff --git a/sw/source/core/inc/pagefrm.hxx b/sw/source/core/inc/pagefrm.hxx
index ad148519cf00..0d08e005eb78 100644
--- a/sw/source/core/inc/pagefrm.hxx
+++ b/sw/source/core/inc/pagefrm.hxx
@@ -110,6 +110,9 @@ protected:
virtual void Modify( const SfxPoolItem*, const SfxPoolItem* ) override;
virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
+ /// Calculate the content height of a page (without columns).
+ size_t GetContentHeight();
+
public:
DECL_FIXEDMEMPOOL_NEWDEL(SwPageFrm)
diff --git a/sw/source/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx
index 1ef7373faf68..d0d7c15fc044 100644
--- a/sw/source/core/layout/calcmove.cxx
+++ b/sw/source/core/layout/calcmove.cxx
@@ -608,7 +608,7 @@ void SwFrm::MakePos()
}
// #i28701# - new type <SwSortedObjs>
-static void lcl_CheckObjects( SwSortedObjs* pSortedObjs, SwFrm* pFrm, long& rBot )
+static void lcl_CheckObjects( SwSortedObjs* pSortedObjs, const SwFrm* pFrm, long& rBot )
{
// And then there can be paragraph anchored frames that sit below their paragraph.
long nMax = 0;
@@ -638,6 +638,64 @@ static void lcl_CheckObjects( SwSortedObjs* pSortedObjs, SwFrm* pFrm, long& rBot
rBot = std::max( rBot, nMax );
}
+//TODO: This should really be const, but Undersize modifies the flag.
+size_t SwPageFrm::GetContentHeight()
+{
+ // In pages without columns, the content defines the size.
+ long nBot = Frm().Top();
+ SwFrm *pFrm = Lower();
+ while (pFrm)
+ {
+ long nTmp = 0;
+ SwFrm *pCnt = static_cast<SwLayoutFrm*>(pFrm)->ContainsAny();
+ while (pCnt && (pCnt->GetUpper() == pFrm ||
+ static_cast<SwLayoutFrm*>(pFrm)->IsAnLower(pCnt)))
+ {
+ nTmp += pCnt->Frm().Height();
+ if (pCnt->IsTextFrm() &&
+ static_cast<SwTextFrm*>(pCnt)->IsUndersized())
+ nTmp += static_cast<SwTextFrm*>(pCnt)->GetParHeight()
+ - pCnt->Prt().Height();
+ else if (pCnt->IsSctFrm() &&
+ static_cast<SwSectionFrm*>(pCnt)->IsUndersized())
+ nTmp += static_cast<SwSectionFrm*>(pCnt)->Undersize();
+ pCnt = pCnt->FindNext();
+ }
+ // OD 29.10.2002 #97265# - consider invalid body frame properties
+ if (pFrm->IsBodyFrm() &&
+ (!pFrm->GetValidSizeFlag() ||
+ !pFrm->GetValidPrtAreaFlag()) &&
+ (pFrm->Frm().Height() < pFrm->Prt().Height())
+ )
+ {
+ nTmp = std::min(nTmp, pFrm->Frm().Height());
+ }
+ else
+ {
+ // OD 30.10.2002 #97265# - assert invalid lower property
+ OSL_ENSURE(!(pFrm->Frm().Height() < pFrm->Prt().Height()),
+ "SwPageFrm::GetContentHeight(): Lower with frame height < printing height");
+ nTmp += pFrm->Frm().Height() - pFrm->Prt().Height();
+ }
+ if (!pFrm->IsBodyFrm())
+ nTmp = std::min(nTmp, pFrm->Frm().Height());
+ nBot += nTmp;
+ // Here we check whether paragraph anchored objects
+ // protrude outside the Body/FootnoteCont.
+ if (m_pSortedObjs && !pFrm->IsHeaderFrm() &&
+ !pFrm->IsFooterFrm())
+ lcl_CheckObjects(m_pSortedObjs, pFrm, nBot);
+ pFrm = pFrm->GetNext();
+ }
+
+ // And the page anchored ones
+ if (m_pSortedObjs)
+ lcl_CheckObjects(m_pSortedObjs, this, nBot);
+ nBot -= Frm().Top();
+
+ return nBot;
+}
+
void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext)
{
PROTOCOL_ENTER( this, PROT_MAKEALL, 0, nullptr )
@@ -764,6 +822,38 @@ void SwPageFrm::MakeAll(vcl::RenderContext* pRenderContext)
Prt().Height( Frm().Height() - (nTop + nBottom) );
mbValidSize = mbValidPrtArea = true;
}
+ else if (pSh && pSh->GetViewOptions()->IsWhitespaceHidden())
+ {
+ auto height = Frm().Height();
+ SwLayoutFrm *pBody = FindBodyCont();
+ if ( pBody && pBody->Lower() && pBody->Lower()->IsColumnFrm() )
+ {
+ // Columns have a fixed height
+ height = pAttrs->GetSize().Height();
+ }
+ else
+ {
+ height = GetContentHeight();
+ }
+
+ if (height > 0)
+ {
+ ChgSize(Size(Frm().Width(), height));
+ Prt().Top(0);
+ Prt().Height(height);
+
+ mbValidSize = mbValidPrtArea = true;
+ }
+ else
+ {
+ // Fallback to default formatting.
+ // This is especially relevant when
+ // loading a doc with Hide Whitespace
+ // is enabled--frame heights are zero.
+ Frm().SSize(pAttrs->GetSize());
+ Format(pRenderContext, pAttrs);
+ }
+ }
else
{ // Set FixSize. For pages, this is not done from Upper, but from
// the attribute.
diff --git a/sw/source/core/layout/wsfrm.cxx b/sw/source/core/layout/wsfrm.cxx
index 81827714315b..896e82a830ce 100644
--- a/sw/source/core/layout/wsfrm.cxx
+++ b/sw/source/core/layout/wsfrm.cxx
@@ -2933,14 +2933,11 @@ void SwLayoutFrm::Format( vcl::RenderContext* /*pRenderContext*/, const SwBorder
if ( mbValidPrtArea && mbValidSize )
return;
- SwViewShell *pSh = getRootFrm()->GetCurrShell();
- const bool hideWS = (pSh && pSh->GetViewOptions()->IsWhitespaceHidden());
- const long hideWSBorderSize = (pSh ? pSh->GetViewOptions()->GetDocumentBorder() : 0);
const sal_uInt16 nLeft = (sal_uInt16)pAttrs->CalcLeft(this);
- const sal_uInt16 nUpper = hideWS ? hideWSBorderSize : pAttrs->CalcTop();
+ const sal_uInt16 nUpper = pAttrs->CalcTop();
const sal_uInt16 nRight = (sal_uInt16)pAttrs->CalcRight(this);
- const sal_uInt16 nLower = hideWS ? hideWSBorderSize : pAttrs->CalcBottom();
+ const sal_uInt16 nLower = pAttrs->CalcBottom();
bool bVert = IsVertical() && !IsPageFrm();
SwRectFn fnRect = bVert ? ( IsVertLR() ? fnRectVertL2R : fnRectVert ) : fnRectHori;
@@ -3009,12 +3006,6 @@ void SwLayoutFrm::Format( vcl::RenderContext* /*pRenderContext*/, const SwBorder
MakePos();
} while ( !mbValidSize );
}
- else if (hideWS)
- {
- const auto newHeight = InnerHeight() + nUpper + nLower;
- ChgSize(Size(Frm().Width(), newHeight));
- mbValidSize = true;
- }
else
mbValidSize = true;
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index 502620f5c1c9..498771aa7d95 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -2880,14 +2880,17 @@ void SwEditWin::MouseButtonDown(const MouseEvent& _rMEvt)
}
// Toggle Hide-Whitespace if between pages.
- if (_rMEvt.GetClicks() >= 2 &&
- rSh.GetViewOptions()->CanHideWhitespace() &&
+ if (rSh.GetViewOptions()->CanHideWhitespace() &&
rSh.GetLayout()->IsBetweenPages(aDocPos))
{
- SwViewOption aOpt(*rSh.GetViewOptions());
- aOpt.SetHideWhitespaceMode(!aOpt.IsHideWhitespaceMode());
- rSh.ApplyViewOptions(aOpt);
- m_rView.GetDocShell()->ToggleLayoutMode(&m_rView);
+ if (_rMEvt.GetClicks() >= 2)
+ {
+ SwViewOption aOpt(*rSh.GetViewOptions());
+ aOpt.SetHideWhitespaceMode(!aOpt.IsHideWhitespaceMode());
+ rSh.ApplyViewOptions(aOpt);
+ }
+
+ return;
}
}
diff --git a/sw/source/uibase/uiview/view0.cxx b/sw/source/uibase/uiview/view0.cxx
index 49c666e9d1f7..c762faa60e13 100644
--- a/sw/source/uibase/uiview/view0.cxx
+++ b/sw/source/uibase/uiview/view0.cxx
@@ -368,7 +368,6 @@ void SwView::ExecViewOptions(SfxRequest &rReq)
int eState = STATE_TOGGLE;
bool bSet = false;
bool bBrowseModeChanged = false;
- bool bHideWhitespaceModeChanged = false;
const SfxItemSet *pArgs = rReq.GetArgs();
sal_uInt16 nSlot = rReq.GetSlot();
@@ -454,7 +453,7 @@ void SwView::ExecViewOptions(SfxRequest &rReq)
case FN_VIEW_HIDE_WHITESPACE:
if ( STATE_TOGGLE == eState )
bFlag = !pOpt->IsHideWhitespaceMode();
- bHideWhitespaceModeChanged = (bFlag != pOpt->IsHideWhitespaceMode());
+
pOpt->SetHideWhitespaceMode(bFlag);
break;
@@ -578,7 +577,7 @@ void SwView::ExecViewOptions(SfxRequest &rReq)
if( !(*rSh.GetViewOptions() == *pOpt ))
{
rSh.ApplyViewOptions( *pOpt );
- if( bBrowseModeChanged || bHideWhitespaceModeChanged )
+ if( bBrowseModeChanged )
{
GetDocShell()->ToggleLayoutMode(this);
}
diff --git a/sw/source/uibase/uno/unomod.cxx b/sw/source/uibase/uno/unomod.cxx
index 15aef1f25db7..31114c711d52 100644
--- a/sw/source/uibase/uno/unomod.cxx
+++ b/sw/source/uibase/uno/unomod.cxx
@@ -733,8 +733,6 @@ void SwXViewSettings::_setSingleValue( const comphelper::PropertyInfo & rInfo, c
// must be set in mpViewOption as this will overwrite settings in _post!
if(mpViewOption)
mpViewOption->SetHideWhitespaceMode(bVal);
-
- pView->GetDocShell()->ToggleLayoutMode(pView);
}
}
}