summaryrefslogtreecommitdiff
path: root/sw/source/uibase/wrtsh
diff options
context:
space:
mode:
authorJim Raykowski <raykowj@gmail.com>2020-07-27 17:52:41 -0800
committerMike Kaganski <mike.kaganski@collabora.com>2020-07-30 12:03:56 +0200
commit835cd06a047717dfe5e0f117959f3c042e13b21b (patch)
tree74a334fb89d401370e9dcd51d5a3c4ad93edcc64 /sw/source/uibase/wrtsh
parentb2686de46250d0c8d14365a2af8428387baa0c24 (diff)
tdf#38093 Writer outline folding - outline visibility and on canvas ui
Patch 2/6 Outline content visibility and on canvas collapse/expand control button implementations. Change-Id: I8481125b102d2f07bfcfce91e1379d8e786a7aa2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99653 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sw/source/uibase/wrtsh')
-rw-r--r--sw/source/uibase/wrtsh/wrtsh1.cxx120
1 files changed, 120 insertions, 0 deletions
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx
index 444db135021d..2c208eb2d592 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -100,6 +100,9 @@
#include <comphelper/lok.hxx>
#include <memory>
+#include <frmtool.hxx>
+#include <viewopt.hxx>
+
using namespace sw::mark;
using namespace com::sun::star;
namespace {
@@ -1989,5 +1992,122 @@ void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, const SfxRequest& rReq)
pFormat->Broadcast( SwFormatFieldHint( nullptr, SwFormatFieldHintWhich::FOCUS, &GetView() ) );
}
}
+bool SwWrtShell::IsOutlineContentFolded(const size_t nPos)
+{
+ const SwNodes& rNodes = GetDoc()->GetNodes();
+ const SwOutlineNodes& rOutlineNodes = rNodes.GetOutLineNds();
+
+ assert(nPos < rOutlineNodes.size());
+
+ SwNode* pOutlineNode = rOutlineNodes[nPos];
+ if (pOutlineNode->IsEndNode())
+ return false;
+
+ bool bOutlineContentVisibleAttr = false;
+ if (pOutlineNode->GetTextNode()->GetAttrOutlineContentVisible(bOutlineContentVisibleAttr))
+ return !bOutlineContentVisibleAttr;
+
+ return false;
+}
+
+void SwWrtShell::ToggleOutlineContentVisibility(SwNode* pNd, bool bForceFold)
+{
+ SwOutlineNodes::size_type nPos;
+ if (GetNodes().GetOutLineNds().Seek_Entry(pNd, &nPos))
+ ToggleOutlineContentVisibility(nPos, bForceFold);
+}
+
+void SwWrtShell::ToggleOutlineContentVisibility(size_t nPos, bool bForceFold)
+{
+ const SwNodes& rNodes = GetNodes();
+ const SwOutlineNodes& rOutlineNodes = rNodes.GetOutLineNds();
+
+ assert(nPos < rOutlineNodes.size());
+
+ SwNode* pSttNd = rOutlineNodes[nPos];
+ if (pSttNd->IsEndNode())
+ return;
+
+ SwNode* pEndNd = &rNodes.GetEndOfContent();
+ if (rOutlineNodes.size() > nPos + 1)
+ pEndNd = rOutlineNodes[nPos + 1];
+
+ if (pSttNd->GetTableBox() || pSttNd->GetIndex() < rNodes.GetEndOfExtras().GetIndex())
+ {
+ // limit folding to within table box
+ if (pSttNd->EndOfSectionIndex() < pEndNd->GetIndex() )
+ pEndNd = pSttNd->EndOfSectionNode();
+ }
+ // if pSttNd isn't in table but pEndNd is, skip over all outline nodes in table
+ else if (pEndNd->GetTableBox())
+ {
+ pEndNd = &rNodes.GetEndOfContent();
+ for (size_t nOutlinePos = nPos + 2; nOutlinePos < rOutlineNodes.size(); nOutlinePos++)
+ {
+ if (!(rOutlineNodes[nOutlinePos]->GetTableBox()))
+ {
+ pEndNd = rOutlineNodes[nOutlinePos];
+ break;
+ }
+ }
+ }
+
+ if (IsOutlineContentFolded(nPos) && !bForceFold)
+ {
+ // unfold
+ SwNodeIndex aIdx(*pSttNd, +1);
+ MakeFrames(GetDoc(), aIdx, *pEndNd);
+
+ pSttNd->GetTextNode()->SetAttrOutlineContentVisible(true);
+
+ if (GetViewOptions()->IsShowOutlineContentVisibilityButton())
+ {
+ // remove fold button if focus is not on outline frame control window
+ SwContentFrame* pFrame = pSttNd->GetTextNode()->getLayoutFrame(nullptr);
+ if (pFrame && !pFrame->IsInDtor())
+ {
+ SwFrameControlPtr pOutlineFrameControl = GetView().GetEditWin().GetFrameControlsManager().GetControl(FrameControlType::Outline, pFrame);
+ if (pOutlineFrameControl && pOutlineFrameControl->GetWindow() && !pOutlineFrameControl->GetWindow()->HasFocus())
+ GetView().GetEditWin().GetFrameControlsManager().RemoveControlsByType(FrameControlType::Outline, pFrame);
+ }
+
+ // fold revealed outline nodes that have collapsed content
+ while (aIdx != *pEndNd)
+ {
+ SwNode* pTmpNd = &aIdx.GetNode();
+ if (pTmpNd->IsTextNode() && pTmpNd->GetTextNode()->IsOutline())
+ {
+ SwTextNode* pTmpTextNd = pTmpNd->GetTextNode();
+ bool bOutlineContentVisibleAttr = true;
+ if (pTmpTextNd->GetAttrOutlineContentVisible(bOutlineContentVisibleAttr) &&
+ !bOutlineContentVisibleAttr)
+ {
+ SwOutlineNodes::size_type iPos;
+ if (rOutlineNodes.Seek_Entry(pTmpTextNd, &iPos))
+ {
+ if (pTmpTextNd->getLayoutFrame(nullptr))
+ ToggleOutlineContentVisibility(iPos, true);
+ }
+ }
+ }
+ aIdx++;
+ }
+ }
+ }
+ else
+ {
+ // fold
+ for (SwNodeIndex aIdx(*pSttNd, +1); &aIdx.GetNode() != pEndNd; aIdx++)
+ {
+ SwNode* pNd = &aIdx.GetNode();
+ if (pNd->IsContentNode())
+ pNd->GetContentNode()->DelFrames(nullptr);
+ else if (pNd->IsTableNode())
+ pNd->GetTableNode()->DelFrames(nullptr);
+ }
+ pSttNd->GetTextNode()->SetAttrOutlineContentVisible(false);
+ }
+ GetView().GetEditWin().Invalidate();
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */