summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/core/crsr/crbm.cxx12
-rw-r--r--sw/source/core/doc/docbm.cxx58
-rw-r--r--sw/source/core/inc/MarkManager.hxx3
-rw-r--r--sw/source/core/unocore/unoportenum.cxx14
-rw-r--r--sw/source/filter/writer/writer.cxx10
5 files changed, 66 insertions, 31 deletions
diff --git a/sw/source/core/crsr/crbm.cxx b/sw/source/core/crsr/crbm.cxx
index a63c191d3b7f..5aed657911e7 100644
--- a/sw/source/core/crsr/crbm.cxx
+++ b/sw/source/core/crsr/crbm.cxx
@@ -204,11 +204,7 @@ bool SwCursorShell::GoNextBookmark()
IDocumentMarkAccess* pMarkAccess = getIDocumentMarkAccess();
IDocumentMarkAccess::container_t vCandidates;
remove_copy_if(
- upper_bound( // finds the first that is starting after
- pMarkAccess->getBookmarksBegin(),
- pMarkAccess->getBookmarksEnd(),
- *GetCursor()->GetPoint(),
- sw::mark::CompareIMarkStartsAfter()),
+ pMarkAccess->findFirstBookmarkStartsAfter(*GetCursor()->GetPoint()),
pMarkAccess->getBookmarksEnd(),
back_inserter(vCandidates),
&lcl_IsInvisibleBookmark);
@@ -244,11 +240,7 @@ bool SwCursorShell::GoPrevBookmark()
IDocumentMarkAccess::container_t vCandidates;
remove_copy_if(
pMarkAccess->getBookmarksBegin(),
- upper_bound(
- pMarkAccess->getBookmarksBegin(),
- pMarkAccess->getBookmarksEnd(),
- *GetCursor()->GetPoint(),
- sw::mark::CompareIMarkStartsAfter()),
+ pMarkAccess->findFirstBookmarkStartsAfter(*GetCursor()->GetPoint()),
back_inserter(vCandidates),
&lcl_IsInvisibleBookmark);
sort(
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index 6b28d7a54e7e..5f856cf4de0c 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -159,13 +159,34 @@ namespace
return std::make_unique<SwPosition>(rOtherPosition);
}
+ struct CompareIMarkStartsBefore
+ {
+ bool operator()(std::shared_ptr<sw::mark::IMark> const& pMark,
+ SwPosition const& rPos)
+ {
+ return pMark->StartsBefore(rPos);
+ }
+ };
+
+ // Apple llvm-g++ 4.2.1 with _GLIBCXX_DEBUG won't eat boost::bind for this
+ // Neither will MSVC 2008 with _DEBUG
+ struct CompareIMarkStartsAfter
+ {
+ bool operator()(SwPosition const& rPos,
+ std::shared_ptr<sw::mark::IMark> const& pMark)
+ {
+ return pMark->StartsAfter(rPos);
+ }
+ };
+
+
IMark* lcl_getMarkAfter(const IDocumentMarkAccess::container_t& rMarks, const SwPosition& rPos)
{
IDocumentMarkAccess::const_iterator_t pMarkAfter = upper_bound(
rMarks.begin(),
rMarks.end(),
rPos,
- sw::mark::CompareIMarkStartsAfter());
+ CompareIMarkStartsAfter());
if(pMarkAfter == rMarks.end()) return nullptr;
return pMarkAfter->get();
};
@@ -179,7 +200,7 @@ namespace
rMarks.begin(),
rMarks.end(),
rPos,
- sw::mark::CompareIMarkStartsAfter());
+ CompareIMarkStartsAfter());
vCandidates.reserve(pCandidatesEnd - rMarks.begin());
// only marks ending before are candidates
remove_copy_if(
@@ -264,7 +285,7 @@ namespace
for(IDocumentMarkAccess::iterator_t ppCurrentMark = lower_bound(
rMarks.begin(), rMarks.end(),
rPos,
- sw::mark::CompareIMarkStartsBefore());
+ CompareIMarkStartsBefore());
ppCurrentMark != rMarks.end();
++ppCurrentMark)
{
@@ -1022,7 +1043,7 @@ namespace sw { namespace mark
m_vAllMarks.begin(),
m_vAllMarks.end(),
pMark->GetMarkStart(),
- sw::mark::CompareIMarkStartsBefore());
+ CompareIMarkStartsBefore());
for ( ; it != m_vAllMarks.end(); ++it)
if (pMark->StartsBefore((*it)->GetMarkStart()))
break;
@@ -1061,6 +1082,16 @@ namespace sw { namespace mark
return lcl_FindMarkByName(rName, m_vBookmarks.begin(), m_vBookmarks.end());
}
+ // find the first Mark that does not start before
+ IDocumentMarkAccess::const_iterator_t MarkManager::findFirstMarkStartsBefore(const SwPosition& rPos) const
+ {
+ return std::lower_bound(
+ m_vAllMarks.begin(),
+ m_vAllMarks.end(),
+ rPos,
+ CompareIMarkStartsBefore());
+ }
+
IDocumentMarkAccess::const_iterator_t MarkManager::getAllMarksBegin() const
{ return m_vAllMarks.begin(); }
@@ -1079,6 +1110,16 @@ namespace sw { namespace mark
sal_Int32 MarkManager::getBookmarksCount() const
{ return m_vBookmarks.size(); }
+ // finds the first that is starting after
+ IDocumentMarkAccess::const_iterator_t MarkManager::findFirstBookmarkStartsAfter(const SwPosition& rPos) const
+ {
+ return std::upper_bound(
+ m_vBookmarks.begin(),
+ m_vBookmarks.end(),
+ rPos,
+ CompareIMarkStartsAfter());
+ }
+
IFieldmark* MarkManager::getFieldmarkFor(const SwPosition& rPos) const
{
const_iterator_t pFieldmark = find_if(
@@ -1245,6 +1286,15 @@ namespace sw { namespace mark
return pAnnotationMark->get();
}
+ // finds the first that is starting after
+ IDocumentMarkAccess::const_iterator_t MarkManager::findFirstAnnotationStartsAfter(const SwPosition& rPos) const
+ {
+ return std::upper_bound(
+ m_vAnnotationMarks.begin(),
+ m_vAnnotationMarks.end(),
+ rPos,
+ CompareIMarkStartsAfter());
+ }
OUString MarkManager::getUniqueMarkName(const OUString& rName) const
{
diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx
index fd0d19bf174d..2e794656cf6f 100644
--- a/sw/source/core/inc/MarkManager.hxx
+++ b/sw/source/core/inc/MarkManager.hxx
@@ -74,12 +74,14 @@ namespace sw {
virtual const_iterator_t getAllMarksEnd() const override;
virtual sal_Int32 getAllMarksCount() const override;
virtual const_iterator_t findMark(const OUString& rName) const override;
+ virtual const_iterator_t findFirstMarkStartsBefore(const SwPosition& rPos) const override;
// bookmarks
virtual const_iterator_t getBookmarksBegin() const override;
virtual const_iterator_t getBookmarksEnd() const override;
virtual sal_Int32 getBookmarksCount() const override;
virtual const_iterator_t findBookmark(const OUString& rName) const override;
+ virtual const_iterator_t findFirstBookmarkStartsAfter(const SwPosition& rPos) const override;
// Fieldmarks
virtual ::sw::mark::IFieldmark* getFieldmarkFor(const SwPosition& rPos) const override;
@@ -103,6 +105,7 @@ namespace sw {
virtual sal_Int32 getAnnotationMarksCount() const override;
virtual const_iterator_t findAnnotationMark( const OUString& rName ) const override;
virtual sw::mark::IMark* getAnnotationMarkFor(const SwPosition& rPos) const override;
+ virtual const_iterator_t findFirstAnnotationStartsAfter(const SwPosition& rPos) const override;
virtual void assureSortedMarkContainers() const override;
diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx
index 8c4f1201ac19..3c3f7d1f9404 100644
--- a/sw/source/core/unocore/unoportenum.cxx
+++ b/sw/source/core/unocore/unoportenum.cxx
@@ -186,11 +186,8 @@ namespace
// no need to consider marks starting after aEndOfPara
SwPosition aEndOfPara(*rUnoCursor.GetPoint());
aEndOfPara.nContent = aEndOfPara.nNode.GetNode().GetTextNode()->Len();
- const IDocumentMarkAccess::const_iterator_t pCandidatesEnd = upper_bound(
- pMarkAccess->getBookmarksBegin(),
- pMarkAccess->getBookmarksEnd(),
- aEndOfPara,
- sw::mark::CompareIMarkStartsAfter()); // finds the first that starts after
+ const IDocumentMarkAccess::const_iterator_t pCandidatesEnd =
+ pMarkAccess->findFirstBookmarkStartsAfter(aEndOfPara);
// search for all bookmarks that start or end in this paragraph
for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getBookmarksBegin();
@@ -270,11 +267,8 @@ namespace
// no need to consider annotation marks starting after aEndOfPara
SwPosition aEndOfPara(*rUnoCursor.GetPoint());
aEndOfPara.nContent = aEndOfPara.nNode.GetNode().GetTextNode()->Len();
- const IDocumentMarkAccess::const_iterator_t pCandidatesEnd = upper_bound(
- pMarkAccess->getAnnotationMarksBegin(),
- pMarkAccess->getAnnotationMarksEnd(),
- aEndOfPara,
- sw::mark::CompareIMarkStartsAfter()); // finds the first that starts after
+ const IDocumentMarkAccess::const_iterator_t pCandidatesEnd =
+ pMarkAccess->findFirstAnnotationStartsAfter(aEndOfPara);
// search for all annotation marks that have its start position in this paragraph
const SwNodeIndex nOwnNode = rUnoCursor.GetPoint()->nNode;
diff --git a/sw/source/filter/writer/writer.cxx b/sw/source/filter/writer/writer.cxx
index c374d261ce65..aa5c9eab397c 100644
--- a/sw/source/filter/writer/writer.cxx
+++ b/sw/source/filter/writer/writer.cxx
@@ -183,13 +183,9 @@ bool Writer::CopyNextPam( SwPaM ** ppPam )
sal_Int32 Writer::FindPos_Bkmk(const SwPosition& rPos) const
{
const IDocumentMarkAccess* const pMarkAccess = m_pDoc->getIDocumentMarkAccess();
- const IDocumentMarkAccess::const_iterator_t ppBkmk = std::lower_bound(
- pMarkAccess->getAllMarksBegin(),
- pMarkAccess->getAllMarksEnd(),
- rPos,
- sw::mark::CompareIMarkStartsBefore()); // find the first Mark that does not start before
- if(ppBkmk != pMarkAccess->getAllMarksEnd())
- return ppBkmk - pMarkAccess->getAllMarksBegin();
+ const IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->findFirstBookmarkStartsAfter(rPos);
+ if(ppBkmk != pMarkAccess->getBookmarksEnd())
+ return ppBkmk - pMarkAccess->getBookmarksBegin();
return -1;
}