summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2012-08-22 23:04:34 +0200
committerBjörn Michaelsen <bjoern.michaelsen@canonical.com>2012-08-26 22:43:53 +0000
commitd781d21f09542873266c97a9483fa1c6e9549889 (patch)
tree1f422cc6c06d8be922a997847146c1779de7c02f
parenta2d8a3364fac34d14c6f82cf65004a07e91640b7 (diff)
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/461 Reviewed-by: Björn Michaelsen <bjoern.michaelsen@canonical.com> Tested-by: Björn Michaelsen <bjoern.michaelsen@canonical.com>
-rw-r--r--sw/source/core/unocore/unocoll.cxx74
1 files changed, 60 insertions, 14 deletions
diff --git a/sw/source/core/unocore/unocoll.cxx b/sw/source/core/unocore/unocoll.cxx
index 36de7ef19a30..9bcfb36b8834 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;
@@ -1631,7 +1632,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)
@@ -1644,12 +1658,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)
@@ -1678,13 +1706,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)
@@ -1710,7 +1744,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 ) :