[Libreoffice-commits] .: Branch 'libreoffice-3-6' - sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Aug 23 06:11:57 PDT 2012


 sw/source/core/unocore/unocoll.cxx |   74 ++++++++++++++++++++++++++++++-------
 1 file changed, 60 insertions(+), 14 deletions(-)

New commits:
commit 5ae1369a87ddc0293f6a78ef368179b6f8e43495
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed Aug 22 23:04:34 2012 +0200

    fdo#51514: SwXBookmarks: only consider real bookmarks:
    
    Since CWS swrefactormarks2 the SwXBookmarks collection handles not only
    bookmarks but at least cross-ref marks as well, which then bother users
    when they show up in the Insert->Hyperlink dialog; remove non-bookmarks
    again.
    (regression from df6d312ca537402463e4eb0530f22b956600fc02)
    
    Change-Id: I6a64ba8a43468dd3ce1569e944371d3ef71f8824
    (cherry picked from commit 45be3ac8151d63ccb61879f876696704542a4ce7)
    Reviewed-on: https://gerrit.libreoffice.org/459
    Reviewed-by: Miklos Vajna <vmiklos at suse.cz>
    Tested-by: Miklos Vajna <vmiklos at suse.cz>

diff --git a/sw/source/core/unocore/unocoll.cxx b/sw/source/core/unocore/unocoll.cxx
index 859cbd0..7de0788 100644
--- a/sw/source/core/unocore/unocoll.cxx
+++ b/sw/source/core/unocore/unocoll.cxx
@@ -86,6 +86,7 @@
 #include <vbahelper/vbaaccesshelper.hxx>
 #include <basic/basmgr.hxx>
 #include <comphelper/processfactory.hxx>
+#include <comphelper/sequenceasvector.hxx>
 
 using ::rtl::OUString;
 using namespace ::com::sun::star;
@@ -1644,7 +1645,20 @@ sal_Int32 SwXBookmarks::getCount(void)
     SolarMutexGuard aGuard;
     if(!IsValid())
         throw uno::RuntimeException();
-    return GetDoc()->getIDocumentMarkAccess()->getBookmarksCount();
+
+    sal_Int32 count(0);
+    IDocumentMarkAccess* const pMarkAccess = GetDoc()->getIDocumentMarkAccess();
+    for (IDocumentMarkAccess::const_iterator_t ppMark =
+            pMarkAccess->getBookmarksBegin();
+         ppMark != pMarkAccess->getBookmarksEnd(); ++ppMark)
+    {
+        if (IDocumentMarkAccess::BOOKMARK ==
+                IDocumentMarkAccess::GetType(**ppMark))
+        {
+            ++count; // only count real bookmarks
+        }
+    }
+    return count;
 }
 
 uno::Any SwXBookmarks::getByIndex(sal_Int32 nIndex)
@@ -1657,12 +1671,26 @@ uno::Any SwXBookmarks::getByIndex(sal_Int32 nIndex)
     if(nIndex < 0 || nIndex >= pMarkAccess->getBookmarksCount())
         throw IndexOutOfBoundsException();
 
-    uno::Any aRet;
-    ::sw::mark::IMark* pBkmk = pMarkAccess->getBookmarksBegin()[nIndex].get();
-    const uno::Reference< text::XTextContent > xRef =
-        SwXBookmark::CreateXBookmark(*GetDoc(), *pBkmk);
-    aRet <<= xRef;
-    return aRet;
+    sal_Int32 count(0);
+    for (IDocumentMarkAccess::const_iterator_t ppMark =
+            pMarkAccess->getBookmarksBegin();
+         ppMark != pMarkAccess->getBookmarksEnd(); ++ppMark)
+    {
+        if (IDocumentMarkAccess::BOOKMARK ==
+                IDocumentMarkAccess::GetType(**ppMark))
+        {
+            if (count == nIndex)
+            {
+                uno::Any aRet;
+                const uno::Reference< text::XTextContent > xRef =
+                    SwXBookmark::CreateXBookmark(*GetDoc(), **ppMark);
+                aRet <<= xRef;
+                return aRet;
+            }
+            ++count; // only count real bookmarks
+        }
+    }
+    throw IndexOutOfBoundsException();
 }
 
 uno::Any SwXBookmarks::getByName(const rtl::OUString& rName)
@@ -1691,13 +1719,19 @@ uno::Sequence< OUString > SwXBookmarks::getElementNames(void)
     if(!IsValid())
         throw uno::RuntimeException();
 
+    ::comphelper::SequenceAsVector< ::rtl::OUString > ret;
     IDocumentMarkAccess* const pMarkAccess = GetDoc()->getIDocumentMarkAccess();
-    uno::Sequence<OUString> aSeq(pMarkAccess->getBookmarksCount());
-    sal_Int32 nCnt = 0;
-    for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getBookmarksBegin();
-        ppMark != pMarkAccess->getBookmarksEnd();)
-        aSeq[nCnt++] = (*ppMark++)->GetName();
-    return aSeq;
+    for (IDocumentMarkAccess::const_iterator_t ppMark =
+            pMarkAccess->getBookmarksBegin();
+         ppMark != pMarkAccess->getBookmarksEnd(); ++ppMark)
+    {
+        if (IDocumentMarkAccess::BOOKMARK ==
+                IDocumentMarkAccess::GetType(**ppMark))
+        {
+            ret.push_back((*ppMark)->GetName()); // only add real bookmarks
+        }
+    }
+    return ret.getAsConstList();
 }
 
 sal_Bool SwXBookmarks::hasByName(const OUString& rName)
@@ -1723,7 +1757,19 @@ sal_Bool SwXBookmarks::hasElements(void)
     SolarMutexGuard aGuard;
     if(!IsValid())
         throw uno::RuntimeException();
-    return GetDoc()->getIDocumentMarkAccess()->getBookmarksCount() != 0;
+
+    IDocumentMarkAccess* const pMarkAccess = GetDoc()->getIDocumentMarkAccess();
+    for (IDocumentMarkAccess::const_iterator_t ppMark =
+            pMarkAccess->getBookmarksBegin();
+         ppMark != pMarkAccess->getBookmarksEnd(); ++ppMark)
+    {
+        if (IDocumentMarkAccess::BOOKMARK ==
+                IDocumentMarkAccess::GetType(**ppMark))
+        {
+            return true;
+        }
+    }
+    return false;
 }
 
 SwXNumberingRulesCollection::SwXNumberingRulesCollection( SwDoc* _pDoc ) :


More information about the Libreoffice-commits mailing list