[Libreoffice-commits] core.git: cui/source sw/inc sw/source

Jim Raykowski (via logerrit) logerrit at kemper.freedesktop.org
Tue Mar 2 21:49:46 UTC 2021


 cui/source/dialogs/hlmarkwn.cxx   |   48 +++++++++++++++++++++++++++++++++++++-
 cui/source/inc/hlmarkwn.hxx       |    2 -
 sw/inc/unotxdoc.hxx               |    5 +++
 sw/source/uibase/uno/unotxdoc.cxx |   47 +++++++++++++++++++++++--------------
 4 files changed, 81 insertions(+), 21 deletions(-)

New commits:
commit 5480d9237af1cf25ac464bf49ba364a757fcf6f5
Author:     Jim Raykowski <raykowj at gmail.com>
AuthorDate: Sun Jan 24 22:17:49 2021 -0900
Commit:     Jim Raykowski <raykowj at gmail.com>
CommitDate: Tue Mar 2 22:49:03 2021 +0100

    tdf#114567 tdf#138934 Hyperlink-Target in Doc Headings expand/collapse
    
    Provides parent child expand/collapse for Headings in the Hyperlink-
    Target in Document dialog target treeview
    
    Change-Id: I8cc57b4cbf3830cec76d64a0ef587e199c39e360
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109930
    Tested-by: Jenkins
    Reviewed-by: Jim Raykowski <raykowj at gmail.com>

diff --git a/cui/source/dialogs/hlmarkwn.cxx b/cui/source/dialogs/hlmarkwn.cxx
index 8996c0e6790c..cdc1039cab18 100644
--- a/cui/source/dialogs/hlmarkwn.cxx
+++ b/cui/source/dialogs/hlmarkwn.cxx
@@ -283,6 +283,9 @@ bool SvxHlinkDlgMarkWnd::RefreshFromDoc(const OUString& aURL)
 // Fill Tree-Control
 int SvxHlinkDlgMarkWnd::FillTree( const uno::Reference< container::XNameAccess >& xLinks, const weld::TreeIter* pParentEntry )
 {
+    // used to create the Headings outline parent children tree view relation
+    std::stack<std::pair<std::unique_ptr<weld::TreeIter>, const sal_Int32>> aHeadingsParentEntryStack;
+
     int nEntries=0;
     const uno::Sequence< OUString > aNames( xLinks->getElementNames() );
     const sal_Int32 nLinks = aNames.getLength();
@@ -331,7 +334,50 @@ int SvxHlinkDlgMarkWnd::FillTree( const uno::Reference< container::XNameAccess >
                 OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pData)));
 
                 std::unique_ptr<weld::TreeIter> xEntry(mxLbTree->make_iterator());
-                mxLbTree->insert(pParentEntry, -1, &aStrDisplayname, &sId, nullptr, nullptr, false, xEntry.get());
+                if (pParentEntry)
+                {
+                    OUString sContentType = mxLbTree->get_text(*pParentEntry);
+                    if (sContentType == "Headings")
+                    {
+                        if (aHeadingsParentEntryStack.empty())
+                            aHeadingsParentEntryStack.push(
+                                        std::pair(mxLbTree->make_iterator(pParentEntry), -1));
+
+                        // get the headings name to display
+                        aAny = xTarget->getPropertyValue("ActualOutlineName");
+                        OUString sActualOutlineName;
+                        aAny >>= sActualOutlineName;
+
+                        // get the headings outline level
+                        aAny = xTarget->getPropertyValue("OutlineLevel");
+                        sal_Int32 nOutlineLevel;
+                        aAny >>= nOutlineLevel;
+
+                        // pop until the top of stack entry has an outline level less than
+                        // the to be inserted heading outline level
+                        while (nOutlineLevel <= aHeadingsParentEntryStack.top().second)
+                            aHeadingsParentEntryStack.pop();
+
+                        mxLbTree->insert(aHeadingsParentEntryStack.top().first.get(), -1,
+                                         &sActualOutlineName, &sId, nullptr, nullptr, false,
+                                         xEntry.get());
+
+                        // push if the inserted entry is a child
+                        if (nOutlineLevel > aHeadingsParentEntryStack.top().second)
+                            aHeadingsParentEntryStack.push(
+                                        std::pair(std::move(xEntry), nOutlineLevel));
+                    }
+                    else
+                    {
+                        mxLbTree->insert(pParentEntry, -1, &aStrDisplayname, &sId, nullptr,
+                                         nullptr, false, xEntry.get());
+                    }
+                }
+                else
+                {
+                    mxLbTree->insert(pParentEntry, -1, &aStrDisplayname, &sId, nullptr, nullptr,
+                                     false, xEntry.get());
+                }
 
                 try
                 {
diff --git a/cui/source/inc/hlmarkwn.hxx b/cui/source/inc/hlmarkwn.hxx
index 9552bc10097c..d88dddab208d 100644
--- a/cui/source/inc/hlmarkwn.hxx
+++ b/cui/source/inc/hlmarkwn.hxx
@@ -30,8 +30,6 @@ class SvxHyperlinkTabPageBase;
 class SvxHlinkDlgMarkWnd : public weld::GenericDialogController
 {
 private:
-    friend class SvxHlmarkTreeLBox;
-
     SvxHyperlinkTabPageBase* mpParent;
 
     sal_uInt16          mnError;
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index df6309d7125e..4dbb35b01ec8 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -558,9 +558,12 @@ class SwXOutlineTarget final : public cppu::WeakImplHelper
 {
     const SfxItemPropertySet*   m_pPropSet;
     OUString                    m_sOutlineText;
+    OUString                    m_sActualText;
+    const sal_Int32             m_nOutlineLevel;
 
 public:
-    SwXOutlineTarget(const OUString& rOutlineText);
+    SwXOutlineTarget(const OUString& rOutlineText, const rtl::OUString &rActualText,
+                     const sal_Int32 nOutlineLevel);
     virtual ~SwXOutlineTarget() override;
 
     //XPropertySet
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index ec2b23aeb6fc..ea00f9a18f25 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -162,6 +162,8 @@
 
 #include <svx/svdpage.hxx>
 
+#include <IDocumentOutlineNodes.hxx>
+
 #define TWIPS_PER_PIXEL 15
 
 using namespace ::com::sun::star;
@@ -1022,10 +1024,11 @@ static sal_uInt32 lcl_Any_To_ULONG(const Any& rValue, bool& bException)
     return nRet;
 }
 
-static OUString lcl_CreateOutlineString( size_t nIndex,
-            const SwOutlineNodes& rOutlineNodes, const SwNumRule* pOutlRule)
+static OUString lcl_CreateOutlineString(const size_t nIndex, const SwDoc* pDoc)
 {
     OUStringBuffer sEntry;
+    const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
+    const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
     const SwTextNode * pTextNd = rOutlineNodes[ nIndex ]->GetTextNode();
     SwNumberTree::tNumberVector aNumVector = pTextNd->GetNumberVector();
     if( pOutlRule && pTextNd->GetNumRule())
@@ -1039,8 +1042,9 @@ static OUString lcl_CreateOutlineString( size_t nIndex,
             sEntry.append(OUString::number( nVal ));
             sEntry.append(".");
         }
-    sEntry.append( rOutlineNodes[ nIndex ]->
-                    GetTextNode()->GetExpandText(nullptr) );
+    OUString sOutlineText = pDoc->getIDocumentOutlineNodes().getOutlineText(
+                nIndex, pDoc->GetDocShell()->GetWrtShell()->GetLayout(), false);
+    sEntry.append(sOutlineText);
     return sEntry.makeStringAndClear();
 }
 
@@ -4047,11 +4051,14 @@ Any SwXLinkNameAccessWrapper::getByName(const OUString& rName)
 
                     for (size_t i = 0; i < nOutlineCount && !bFound; ++i)
                     {
-                        const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
-                        const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
-                        if(sParam == lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule))
+                        if(sParam == lcl_CreateOutlineString(i, pDoc))
                         {
-                            Reference< XPropertySet >  xOutline = new SwXOutlineTarget(sParam);
+                            OUString sOutlineText =
+                                    pDoc->getIDocumentOutlineNodes().getOutlineText(
+                                        i, pDoc->GetDocShell()->GetWrtShell()->GetLayout());
+                            sal_Int32 nOutlineLevel = pDoc->getIDocumentOutlineNodes().getOutlineLevel(i);
+                            Reference<XPropertySet> xOutline =
+                                    new SwXOutlineTarget(sParam, sOutlineText, nOutlineLevel);
                             aRet <<= xOutline;
                             bFound = true;
                         }
@@ -4107,10 +4114,9 @@ Sequence< OUString > SwXLinkNameAccessWrapper::getElementNames()
             const size_t nOutlineCount = rOutlineNodes.size();
             aRet.realloc(nOutlineCount);
             OUString* pResArr = aRet.getArray();
-            const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
             for (size_t i = 0; i < nOutlineCount; ++i)
             {
-                OUString sEntry = lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule) + "|outline";
+                OUString sEntry = lcl_CreateOutlineString(i, pDoc) + "|outline";
                 pResArr[i] = sEntry;
             }
         }
@@ -4165,10 +4171,7 @@ sal_Bool SwXLinkNameAccessWrapper::hasByName(const OUString& rName)
 
                     for (size_t i = 0; i < nOutlineCount && !bRet; ++i)
                     {
-                        const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
-                        const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
-                        if(sParam ==
-                            lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule))
+                        if(sParam == lcl_CreateOutlineString(i, pDoc))
                         {
                             bRet = true;
                         }
@@ -4314,9 +4317,12 @@ Sequence< OUString > SwXLinkNameAccessWrapper::getSupportedServiceNames()
     return aRet;
 }
 
-SwXOutlineTarget::SwXOutlineTarget(const OUString& rOutlineText) :
+SwXOutlineTarget::SwXOutlineTarget(const OUString& rOutlineText, const OUString& rActualText,
+                                   const sal_Int32 nOutlineLevel) :
     m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
-    m_sOutlineText(rOutlineText)
+    m_sOutlineText(rOutlineText),
+    m_sActualText(rActualText),
+    m_nOutlineLevel(nOutlineLevel)
 {
 }
 
@@ -4338,9 +4344,16 @@ void SwXOutlineTarget::setPropertyValue(
 
 Any SwXOutlineTarget::getPropertyValue(const OUString& rPropertyName)
 {
-    if(rPropertyName != UNO_LINK_DISPLAY_NAME)
+    if (rPropertyName != UNO_LINK_DISPLAY_NAME && rPropertyName != "ActualOutlineName" &&
+            rPropertyName != "OutlineLevel")
         throw UnknownPropertyException(rPropertyName);
 
+    if (rPropertyName == "ActualOutlineName")
+        return Any(m_sActualText);
+
+    if (rPropertyName == "OutlineLevel")
+        return Any(m_nOutlineLevel);
+
     return Any(m_sOutlineText);
 }
 


More information about the Libreoffice-commits mailing list