summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2012-08-22 23:04:34 +0200
committerMiklos Vajna <vmiklos@suse.cz>2012-08-23 13:11:38 +0000
commit5ae1369a87ddc0293f6a78ef368179b6f8e43495 (patch)
tree3ed81c4092dc9d0d87a7b5c614b868dd48867bed
parent3f88a4b00c6140c4294583cbaf75954486f5f5b6 (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/459 Reviewed-by: Miklos Vajna <vmiklos@suse.cz> Tested-by: Miklos Vajna <vmiklos@suse.cz>
-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 859cbd085710..7de0788e5879 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 ) :