LibreOffice Module sw (master)  1
docbm.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <memory>
21 #include <utility>
22 
23 #include <MarkManager.hxx>
24 #include <bookmrk.hxx>
25 #include <crossrefbookmark.hxx>
26 #include <crsrsh.hxx>
27 #include <annotationmark.hxx>
28 #include <doc.hxx>
30 #include <IDocumentState.hxx>
31 #include <IDocumentUndoRedo.hxx>
32 #include <docary.hxx>
33 #include <xmloff/odffields.hxx>
34 #include <mvsave.hxx>
35 #include <ndtxt.hxx>
36 #include <node.hxx>
37 #include <pam.hxx>
38 #include <redline.hxx>
39 #include <rolbck.hxx>
40 #include <rtl/ustring.hxx>
41 #include <sal/types.h>
42 #include <sal/log.hxx>
43 #include <UndoBookmark.hxx>
44 #include <tools/datetimeutils.hxx>
45 #include <view.hxx>
46 
47 #include <libxml/xmlstring.h>
48 #include <libxml/xmlwriter.h>
49 
50 using namespace ::sw::mark;
51 
52 std::vector<::sw::mark::MarkBase*>::const_iterator const&
54 {
55  return *m_pIter;
56 }
57 
58 IDocumentMarkAccess::iterator::iterator(std::vector<::sw::mark::MarkBase*>::const_iterator const& rIter)
59  : m_pIter(new std::vector<::sw::mark::MarkBase*>::const_iterator(rIter))
60 {
61 }
62 
64  : m_pIter(new std::vector<::sw::mark::MarkBase*>::const_iterator(*rOther.m_pIter))
65 {
66 }
67 
69 {
70  m_pIter.reset(new std::vector<::sw::mark::MarkBase*>::const_iterator(*rOther.m_pIter));
71  return *this;
72 }
73 
75  : m_pIter(std::move(rOther.m_pIter))
76 {
77 }
78 
80 {
81  m_pIter = std::move(rOther.m_pIter);
82  return *this;
83 }
84 
86 {
87 }
88 
89 // ARGH why does it *need* to return const& ?
90 ::sw::mark::IMark* /*const&*/
92 {
93  return static_cast<sw::mark::IMark*>(**m_pIter);
94 }
95 
97 {
98  ++(*m_pIter);
99  return *this;
100 }
102 {
103  iterator tmp(*this);
104  ++(*m_pIter);
105  return tmp;
106 }
107 
109 {
110  return *m_pIter == *rOther.m_pIter;
111 }
112 
114 {
115  return *m_pIter != *rOther.m_pIter;
116 }
117 
119  : m_pIter(new std::vector<::sw::mark::MarkBase*>::const_iterator())
120 {
121 }
122 
124 {
125  --(*m_pIter);
126  return *this;
127 }
128 
130 {
131  iterator tmp(*this);
132  --(*m_pIter);
133  return tmp;
134 }
135 
137 {
138  (*m_pIter) += n;
139  return *this;
140 }
141 
143 {
144  return iterator(*m_pIter + n);
145 }
146 
148 {
149  (*m_pIter) -= n;
150  return *this;
151 }
152 
154 {
155  return iterator(*m_pIter - n);
156 }
157 
159 {
160  return *m_pIter - *rOther.m_pIter;
161 }
162 
164 {
165  return static_cast<sw::mark::IMark*>((*m_pIter)[n]);
166 }
167 
169 {
170  return *m_pIter < *rOther.m_pIter;
171 }
173 {
174  return *m_pIter > *rOther.m_pIter;
175 }
177 {
178  return *m_pIter <= *rOther.m_pIter;
179 }
181 {
182  return *m_pIter >= *rOther.m_pIter;
183 }
184 
185 
186 namespace
187 {
188  bool lcl_GreaterThan( const SwPosition& rPos, const SwNodeIndex& rNdIdx, const SwIndex* pIdx )
189  {
190  return pIdx != nullptr
191  ? ( rPos.nNode > rNdIdx
192  || ( rPos.nNode == rNdIdx
193  && rPos.nContent >= pIdx->GetIndex() ) )
194  : rPos.nNode >= rNdIdx;
195  }
196 
197  bool lcl_Lower( const SwPosition& rPos, const SwNodeIndex& rNdIdx, const SwIndex* pIdx )
198  {
199  return rPos.nNode < rNdIdx
200  || ( pIdx != nullptr
201  && rPos.nNode == rNdIdx
202  && rPos.nContent < pIdx->GetIndex() );
203  }
204 
205  bool lcl_MarkOrderingByStart(const ::sw::mark::MarkBase *const pFirst,
206  const ::sw::mark::MarkBase *const pSecond)
207  {
208  auto const& rFirstStart(pFirst->GetMarkStart());
209  auto const& rSecondStart(pSecond->GetMarkStart());
210  if (rFirstStart.nNode != rSecondStart.nNode)
211  {
212  return rFirstStart.nNode < rSecondStart.nNode;
213  }
214  const sal_Int32 nFirstContent = rFirstStart.nContent.GetIndex();
215  const sal_Int32 nSecondContent = rSecondStart.nContent.GetIndex();
216  if (nFirstContent != 0 || nSecondContent != 0)
217  {
218  return nFirstContent < nSecondContent;
219  }
220  auto *const pCRFirst (dynamic_cast<::sw::mark::CrossRefBookmark const*>(pFirst));
221  auto *const pCRSecond(dynamic_cast<::sw::mark::CrossRefBookmark const*>(pSecond));
222  if ((pCRFirst == nullptr) == (pCRSecond == nullptr))
223  {
224  return false; // equal
225  }
226  return pCRFirst != nullptr; // cross-ref sorts *before*
227  }
228 
229  bool lcl_MarkOrderingByEnd(const ::sw::mark::MarkBase *const pFirst,
230  const ::sw::mark::MarkBase *const pSecond)
231  {
232  return pFirst->GetMarkEnd() < pSecond->GetMarkEnd();
233  }
234 
235  void lcl_InsertMarkSorted(MarkManager::container_t& io_vMarks,
236  ::sw::mark::MarkBase *const pMark)
237  {
238  io_vMarks.insert(
239  lower_bound(
240  io_vMarks.begin(),
241  io_vMarks.end(),
242  pMark,
243  &lcl_MarkOrderingByStart),
244  pMark);
245  }
246 
247  std::unique_ptr<SwPosition> lcl_PositionFromContentNode(
248  SwContentNode * const pContentNode,
249  const bool bAtEnd)
250  {
251  std::unique_ptr<SwPosition> pResult(new SwPosition(*pContentNode));
252  pResult->nContent.Assign(pContentNode, bAtEnd ? pContentNode->Len() : 0);
253  return pResult;
254  }
255 
256  // return a position at the begin of rEnd, if it is a ContentNode
257  // else set it to the begin of the Node after rEnd, if there is one
258  // else set it to the end of the node before rStt
259  // else set it to the ContentNode of the Pos outside the Range
260  std::unique_ptr<SwPosition> lcl_FindExpelPosition(
261  const SwNodeIndex& rStt,
262  const SwNodeIndex& rEnd,
263  const SwPosition& rOtherPosition)
264  {
265  SwContentNode * pNode = rEnd.GetNode().GetContentNode();
266  bool bPosAtEndOfNode = false;
267  if ( pNode == nullptr)
268  {
269  SwNodeIndex aEnd = rEnd;
270  pNode = rEnd.GetNodes().GoNext( &aEnd );
271  bPosAtEndOfNode = false;
272  }
273  if ( pNode == nullptr )
274  {
275  SwNodeIndex aStt = rStt;
276  pNode = SwNodes::GoPrevious(&aStt);
277  bPosAtEndOfNode = true;
278  }
279  if ( pNode != nullptr )
280  {
281  return lcl_PositionFromContentNode( pNode, bPosAtEndOfNode );
282  }
283 
284  return std::make_unique<SwPosition>(rOtherPosition);
285  }
286 
287  struct CompareIMarkStartsBefore
288  {
289  bool operator()(SwPosition const& rPos,
290  const sw::mark::IMark* pMark)
291  {
292  return rPos < pMark->GetMarkStart();
293  }
294  bool operator()(const sw::mark::IMark* pMark,
295  SwPosition const& rPos)
296  {
297  return pMark->GetMarkStart() < rPos;
298  }
299  };
300 
301  // Apple llvm-g++ 4.2.1 with _GLIBCXX_DEBUG won't eat boost::bind for this
302  // Neither will MSVC 2008 with _DEBUG
303  struct CompareIMarkStartsAfter
304  {
305  bool operator()(SwPosition const& rPos,
306  const sw::mark::IMark* pMark)
307  {
308  return pMark->GetMarkStart() > rPos;
309  }
310  };
311 
312 
313  IMark* lcl_getMarkAfter(const MarkManager::container_t& rMarks, const SwPosition& rPos)
314  {
315  auto const pMarkAfter = upper_bound(
316  rMarks.begin(),
317  rMarks.end(),
318  rPos,
319  CompareIMarkStartsAfter());
320  if(pMarkAfter == rMarks.end())
321  return nullptr;
322  return *pMarkAfter;
323  };
324 
325  IMark* lcl_getMarkBefore(const MarkManager::container_t& rMarks, const SwPosition& rPos)
326  {
327  // candidates from which to choose the mark before
328  MarkManager::container_t vCandidates;
329  // no need to consider marks starting after rPos
330  auto const pCandidatesEnd = upper_bound(
331  rMarks.begin(),
332  rMarks.end(),
333  rPos,
334  CompareIMarkStartsAfter());
335  vCandidates.reserve(pCandidatesEnd - rMarks.begin());
336  // only marks ending before are candidates
337  remove_copy_if(
338  rMarks.begin(),
339  pCandidatesEnd,
340  back_inserter(vCandidates),
341  [&rPos] (const ::sw::mark::MarkBase *const pMark) { return !(pMark->GetMarkEnd() < rPos); } );
342  // no candidate left => we are in front of the first mark or there are none
343  if(vCandidates.empty()) return nullptr;
344  // return the highest (last) candidate using mark end ordering
345  return *max_element(vCandidates.begin(), vCandidates.end(), &lcl_MarkOrderingByEnd);
346  }
347 
348  bool lcl_FixCorrectedMark(
349  const bool bChangedPos,
350  const bool bChangedOPos,
351  MarkBase* io_pMark )
352  {
354  {
355  // annotation marks are allowed to span a table cell range.
356  // but trigger sorting to be save
357  return true;
358  }
359 
360  if ( ( bChangedPos || bChangedOPos )
361  && io_pMark->IsExpanded()
362  && io_pMark->GetOtherMarkPos().nNode.GetNode().FindTableBoxStartNode() !=
363  io_pMark->GetMarkPos().nNode.GetNode().FindTableBoxStartNode() )
364  {
365  if ( !bChangedOPos )
366  {
367  io_pMark->SetMarkPos( io_pMark->GetOtherMarkPos() );
368  }
369  io_pMark->ClearOtherMarkPos();
370  DdeBookmark * const pDdeBkmk = dynamic_cast< DdeBookmark*>(io_pMark);
371  if ( pDdeBkmk != nullptr
372  && pDdeBkmk->IsServer() )
373  {
374  pDdeBkmk->SetRefObject(nullptr);
375  }
376  return true;
377  }
378  return false;
379  }
380 
381  bool lcl_MarkEqualByStart(const ::sw::mark::MarkBase *const pFirst,
382  const ::sw::mark::MarkBase *const pSecond)
383  {
384  return !lcl_MarkOrderingByStart(pFirst, pSecond) &&
385  !lcl_MarkOrderingByStart(pSecond, pFirst);
386  }
387 
388  MarkManager::container_t::const_iterator lcl_FindMark(
389  MarkManager::container_t& rMarks,
390  const ::sw::mark::MarkBase *const pMarkToFind)
391  {
392  auto ppCurrentMark = lower_bound(
393  rMarks.begin(), rMarks.end(),
394  pMarkToFind, &lcl_MarkOrderingByStart);
395  // since there are usually not too many marks on the same start
396  // position, we are not doing a bisect search for the upper bound
397  // but instead start to iterate from pMarkLow directly
398  while (ppCurrentMark != rMarks.end() && lcl_MarkEqualByStart(*ppCurrentMark, pMarkToFind))
399  {
400  if(*ppCurrentMark == pMarkToFind)
401  {
402  return MarkManager::container_t::const_iterator(std::move(ppCurrentMark));
403  }
404  ++ppCurrentMark;
405  }
406  // reached a mark starting on a later start pos or the end of the
407  // vector => not found
408  return rMarks.end();
409  };
410 
411  MarkManager::container_t::const_iterator lcl_FindMarkAtPos(
412  MarkManager::container_t& rMarks,
413  const SwPosition& rPos,
414  const IDocumentMarkAccess::MarkType eType)
415  {
416  for (auto ppCurrentMark = lower_bound(
417  rMarks.begin(), rMarks.end(),
418  rPos,
419  CompareIMarkStartsBefore());
420  ppCurrentMark != rMarks.end();
421  ++ppCurrentMark)
422  {
423  // Once we reach a mark starting after the target pos
424  // we do not need to continue
425  if((*ppCurrentMark)->GetMarkStart() > rPos)
426  break;
427  if(IDocumentMarkAccess::GetType(**ppCurrentMark) == eType)
428  {
429  return MarkManager::container_t::const_iterator(std::move(ppCurrentMark));
430  }
431  }
432  // reached a mark starting on a later start pos or the end of the
433  // vector => not found
434  return rMarks.end();
435  };
436 
437  MarkManager::container_t::const_iterator lcl_FindMarkByName(
438  const OUString& rName,
439  const MarkManager::container_t::const_iterator& ppMarksBegin,
440  const MarkManager::container_t::const_iterator& ppMarksEnd)
441  {
442  return find_if(
443  ppMarksBegin,
444  ppMarksEnd,
445  [&rName] (::sw::mark::MarkBase const*const pMark) { return pMark->GetName() == rName; } );
446  }
447 
448  void lcl_DebugMarks(MarkManager::container_t const& rMarks)
449  {
450 #if OSL_DEBUG_LEVEL > 0
451  SAL_INFO("sw.core", rMarks.size() << " Marks");
452  for (auto ppMark = rMarks.begin();
453  ppMark != rMarks.end();
454  ++ppMark)
455  {
456  IMark* pMark = *ppMark;
457  const SwPosition* const pStPos = &pMark->GetMarkStart();
458  const SwPosition* const pEndPos = &pMark->GetMarkEnd();
459  SAL_INFO("sw.core",
460  pStPos->nNode.GetIndex() << "," <<
461  pStPos->nContent.GetIndex() << " " <<
462  pEndPos->nNode.GetIndex() << "," <<
463  pEndPos->nContent.GetIndex() << " " <<
464  typeid(*pMark).name() << " " <<
465  pMark->GetName());
466  }
467 #else
468  (void) rMarks;
469 #endif
470  assert(std::is_sorted(rMarks.begin(), rMarks.end(), lcl_MarkOrderingByStart));
471  };
472 }
473 
475 {
476  const std::type_info* const pMarkTypeInfo = &typeid(rBkmk);
477  // not using dynamic_cast<> here for performance
478  if(*pMarkTypeInfo == typeid(UnoMark))
479  return MarkType::UNO_BOOKMARK;
480  else if(*pMarkTypeInfo == typeid(DdeBookmark))
481  return MarkType::DDE_BOOKMARK;
482  else if(*pMarkTypeInfo == typeid(Bookmark))
483  return MarkType::BOOKMARK;
484  else if(*pMarkTypeInfo == typeid(CrossRefHeadingBookmark))
486  else if(*pMarkTypeInfo == typeid(CrossRefNumItemBookmark))
488  else if(*pMarkTypeInfo == typeid(AnnotationMark))
490  else if(*pMarkTypeInfo == typeid(TextFieldmark))
492  else if(*pMarkTypeInfo == typeid(CheckboxFieldmark))
494  else if(*pMarkTypeInfo == typeid(DropDownFieldmark))
496  else if(*pMarkTypeInfo == typeid(DateFieldmark))
498  else if(*pMarkTypeInfo == typeid(NavigatorReminder))
500  else
501  {
502  assert(false && "IDocumentMarkAccess::GetType(..)"
503  " - unknown MarkType. This needs to be fixed!");
504  return MarkType::UNO_BOOKMARK;
505  }
506 }
507 
509 {
510  return "__RefHeading__";
511 }
512 
514 {
515  return rPaM.Start()->nNode.GetNode().IsTextNode() &&
516  rPaM.Start()->nContent.GetIndex() == 0 &&
517  ( !rPaM.HasMark() ||
518  ( rPaM.GetMark()->nNode == rPaM.GetPoint()->nNode &&
519  rPaM.End()->nContent.GetIndex() == rPaM.End()->nNode.GetNode().GetTextNode()->Len() ) );
520 }
521 
523 {
524  if (GetType(rMark) != MarkType::TEXT_FIELDMARK)
525  {
526  return; // TODO FORMDATE has no command?
527  }
528  SwPaM pam(sw::mark::FindFieldSep(rMark), rMark.GetMarkStart());
529  ++pam.GetPoint()->nContent; // skip CH_TXT_ATR_FIELDSTART
530  pam.GetDoc()->getIDocumentContentOperations().DeleteAndJoin(pam);
531 }
532 
533 namespace sw::mark
534 {
535  MarkManager::MarkManager(SwDoc& rDoc)
536  : m_vAllMarks()
537  , m_vBookmarks()
538  , m_vFieldmarks()
539  , m_vAnnotationMarks()
540  , m_pDoc(&rDoc)
541  , m_pLastActiveFieldmark(nullptr)
542  { }
543 
545  const OUString& rName,
546  const IDocumentMarkAccess::MarkType eType,
547  sw::mark::InsertMode const eMode,
548  SwPosition const*const pSepPos)
549  {
550 #if OSL_DEBUG_LEVEL > 0
551  {
552  const SwPosition* const pPos1 = rPaM.GetPoint();
553  const SwPosition* pPos2 = pPos1;
554  if(rPaM.HasMark())
555  pPos2 = rPaM.GetMark();
556  SAL_INFO("sw.core",
557  rName << " " <<
558  pPos1->nNode.GetIndex() << "," <<
559  pPos1->nContent.GetIndex() << " " <<
560  pPos2->nNode.GetIndex() << "," <<
561  pPos2->nContent.GetIndex());
562  }
563 #endif
564  // There should only be one CrossRefBookmark per Textnode per Type
566  && (lcl_FindMarkAtPos(m_vBookmarks, *rPaM.Start(), eType) != m_vBookmarks.end()))
567  { // this can happen via UNO API
568  SAL_WARN("sw.core", "MarkManager::makeMark(..)"
569  " - refusing to create duplicate CrossRefBookmark");
570  return nullptr;
571  }
572 
574  && (eMode == InsertMode::New
575  ? *rPaM.GetPoint() != *rPaM.GetMark()
576  // CopyText: pam covers CH_TXT_ATR_FORMELEMENT
577  : (rPaM.GetPoint()->nNode != rPaM.GetMark()->nNode
578  || rPaM.Start()->nContent.GetIndex() + 1 != rPaM.End()->nContent.GetIndex())))
579  {
580  SAL_WARN("sw.core", "MarkManager::makeMark(..)"
581  " - invalid range on point fieldmark");
582  return nullptr;
583  }
584 
585  if ((eType == MarkType::TEXT_FIELDMARK || eType == MarkType::DATE_FIELDMARK)
587  || (pSepPos && rPaM.GetPoint()->nNode.GetNode().StartOfSectionNode() != pSepPos->nNode.GetNode().StartOfSectionNode())))
588  {
589  SAL_WARN("sw.core", "MarkManager::makeMark(..)"
590  " - invalid range on fieldmark, different nodes array sections");
591  return nullptr;
592  }
593 
594  if ((eType == MarkType::TEXT_FIELDMARK || eType == MarkType::DATE_FIELDMARK)
595  // can't check for Copy - it asserts - but it's also obviously unnecessary
596  && eMode == InsertMode::New
598  {
599  SAL_WARN("sw.core", "MarkManager::makeMark(..)"
600  " - invalid range on fieldmark, overlaps existing fieldmark or meta-field");
601  return nullptr;
602  }
603 
604  // create mark
605  std::unique_ptr<::sw::mark::MarkBase> pMark;
606  switch(eType)
607  {
609  pMark = std::make_unique<TextFieldmark>(rPaM, rName);
610  break;
612  pMark = std::make_unique<CheckboxFieldmark>(rPaM);
613  break;
615  pMark = std::make_unique<DropDownFieldmark>(rPaM);
616  break;
618  pMark = std::make_unique<DateFieldmark>(rPaM);
619  break;
621  pMark = std::make_unique<NavigatorReminder>(rPaM);
622  break;
624  pMark = std::make_unique<Bookmark>(rPaM, vcl::KeyCode(), rName);
625  break;
627  pMark = std::make_unique<DdeBookmark>(rPaM);
628  break;
630  pMark = std::make_unique<CrossRefHeadingBookmark>(rPaM, vcl::KeyCode(), rName);
631  break;
633  pMark = std::make_unique<CrossRefNumItemBookmark>(rPaM, vcl::KeyCode(), rName);
634  break;
636  pMark = std::make_unique<UnoMark>(rPaM);
637  break;
639  pMark = std::make_unique<AnnotationMark>( rPaM, rName );
640  break;
641  }
642  assert(pMark.get() &&
643  "MarkManager::makeMark(..)"
644  " - Mark was not created.");
645 
646  if(pMark->GetMarkPos() != pMark->GetMarkStart())
647  pMark->Swap();
648 
649  // for performance reasons, we trust UnoMarks to have a (generated) unique name
651  pMark->SetName( getUniqueMarkName( pMark->GetName() ) );
652 
653  // insert any dummy chars before inserting into sorted vectors
654  pMark->InitDoc(m_pDoc, eMode, pSepPos);
655 
656  // register mark
657  lcl_InsertMarkSorted(m_vAllMarks, pMark.get());
658  switch(eType)
659  {
663  lcl_InsertMarkSorted(m_vBookmarks, pMark.get());
664  break;
669  lcl_InsertMarkSorted(m_vFieldmarks, pMark.get());
670  break;
672  lcl_InsertMarkSorted( m_vAnnotationMarks, pMark.get() );
673  break;
677  // no special array for these
678  break;
679  }
680  SAL_INFO("sw.core", "--- makeType ---");
681  SAL_INFO("sw.core", "Marks");
682  lcl_DebugMarks(m_vAllMarks);
683  SAL_INFO("sw.core", "Bookmarks");
684  lcl_DebugMarks(m_vBookmarks);
685  SAL_INFO("sw.core", "Fieldmarks");
686  lcl_DebugMarks(m_vFieldmarks);
687 
688  return pMark.release();
689  }
690 
692  const SwPaM& rPaM,
693  const OUString& rName,
694  const OUString& rType,
695  SwPosition const*const pSepPos)
696  {
697 
698  // Disable undo, because we handle it using SwUndoInsTextFieldmark
699  bool bUndoIsEnabled = m_pDoc->GetIDocumentUndoRedo().DoesUndo();
701 
702  sw::mark::IMark* pMark = nullptr;
703  if(rType == ODF_FORMDATE)
704  {
705  pMark = makeMark(rPaM, rName,
708  pSepPos);
709  }
710  else
711  {
712  pMark = makeMark(rPaM, rName,
715  pSepPos);
716  }
717  sw::mark::IFieldmark* pFieldMark = dynamic_cast<sw::mark::IFieldmark*>( pMark );
718  if (pFieldMark)
719  pFieldMark->SetFieldname( rType );
720 
721  if (bUndoIsEnabled)
722  {
723  m_pDoc->GetIDocumentUndoRedo().DoUndo(bUndoIsEnabled);
724  if (pFieldMark)
725  m_pDoc->GetIDocumentUndoRedo().AppendUndo(std::make_unique<SwUndoInsTextFieldmark>(*pFieldMark));
726  }
727 
728  return pFieldMark;
729  }
730 
732  const SwPaM& rPaM,
733  const OUString& rName,
734  const OUString& rType)
735  {
736  // Disable undo, because we handle it using SwUndoInsNoTextFieldmark
737  bool bUndoIsEnabled = m_pDoc->GetIDocumentUndoRedo().DoesUndo();
739 
740  bool bEnableSetModified = m_pDoc->getIDocumentState().IsEnableSetModified();
742 
743  sw::mark::IMark* pMark = nullptr;
744  if(rType == ODF_FORMCHECKBOX)
745  {
746  pMark = makeMark( rPaM, rName,
749  }
750  else if(rType == ODF_FORMDROPDOWN)
751  {
752  pMark = makeMark( rPaM, rName,
755  }
756  else if(rType == ODF_FORMDATE)
757  {
758  pMark = makeMark( rPaM, rName,
761  }
762 
763  sw::mark::IFieldmark* pFieldMark = dynamic_cast<sw::mark::IFieldmark*>( pMark );
764  if (pFieldMark)
765  pFieldMark->SetFieldname( rType );
766 
767  if (bUndoIsEnabled)
768  {
769  m_pDoc->GetIDocumentUndoRedo().DoUndo(bUndoIsEnabled);
770  if (pFieldMark)
771  m_pDoc->GetIDocumentUndoRedo().AppendUndo(std::make_unique<SwUndoInsNoTextFieldmark>(*pFieldMark));
772  }
773 
774  m_pDoc->getIDocumentState().SetEnableSetModified(bEnableSetModified);
776 
777  return pFieldMark;
778  }
779 
781  const SwTextNode& rTextNode,
782  const IDocumentMarkAccess::MarkType eType )
783  {
784  SwPosition aPos(rTextNode);
785  aPos.nContent.Assign(&const_cast<SwTextNode&>(rTextNode), 0);
786  auto const ppExistingMark = lcl_FindMarkAtPos(m_vBookmarks, aPos, eType);
787  if(ppExistingMark != m_vBookmarks.end())
788  return *ppExistingMark;
789  const SwPaM aPaM(aPos);
790  return makeMark(aPaM, OUString(), eType, sw::mark::InsertMode::New);
791  }
792 
794  const SwPaM& rPaM,
795  const OUString& rName )
796  {
799  }
800 
802  ::sw::mark::IMark* const io_pMark,
803  const SwPaM& rPaM)
804  {
805  assert(io_pMark->GetMarkPos().GetDoc() == m_pDoc &&
806  "<MarkManager::repositionMark(..)>"
807  " - Mark is not in my doc.");
808  MarkBase* const pMarkBase = dynamic_cast< MarkBase* >(io_pMark);
809  if (!pMarkBase)
810  return;
811 
812  pMarkBase->SetMarkPos(*(rPaM.GetPoint()));
813  if(rPaM.HasMark())
814  pMarkBase->SetOtherMarkPos(*(rPaM.GetMark()));
815  else
816  pMarkBase->ClearOtherMarkPos();
817 
818  if(pMarkBase->GetMarkPos() != pMarkBase->GetMarkStart())
819  pMarkBase->Swap();
820 
821  sortMarks();
822  }
823 
825  ::sw::mark::IMark* io_pMark,
826  const OUString& rNewName )
827  {
828  assert(io_pMark->GetMarkPos().GetDoc() == m_pDoc &&
829  "<MarkManager::renameMark(..)>"
830  " - Mark is not in my doc.");
831  if ( io_pMark->GetName() == rNewName )
832  return true;
833  if (lcl_FindMarkByName(rNewName, m_vAllMarks.begin(), m_vAllMarks.end()) != m_vAllMarks.end())
834  return false;
835  if (::sw::mark::MarkBase* pMarkBase = dynamic_cast< ::sw::mark::MarkBase* >(io_pMark))
836  {
837  const OUString sOldName(pMarkBase->GetName());
838  pMarkBase->SetName(rNewName);
839 
840  if (dynamic_cast< ::sw::mark::Bookmark* >(io_pMark))
841  {
843  {
845  std::make_unique<SwUndoRenameBookmark>(sOldName, rNewName, m_pDoc));
846  }
848  }
849  }
850  return true;
851  }
852 
854  const SwNodeIndex& rOldNode,
855  const SwPosition& rNewPos,
856  const sal_Int32 nOffset)
857  {
858  const SwNode* const pOldNode = &rOldNode.GetNode();
859  SwPosition aNewPos(rNewPos);
860  aNewPos.nContent += nOffset;
861  bool isSortingNeeded = false;
862 
863  for (auto ppMark = m_vAllMarks.begin();
864  ppMark != m_vAllMarks.end();
865  ++ppMark)
866  {
867  ::sw::mark::MarkBase *const pMark = *ppMark;
868  // correction of non-existent non-MarkBase instances cannot be done
869  assert(pMark);
870  // is on position ??
871  bool bChangedPos = false;
872  if(&pMark->GetMarkPos().nNode.GetNode() == pOldNode)
873  {
874  pMark->SetMarkPos(aNewPos);
875  bChangedPos = true;
876  isSortingNeeded = true;
877  }
878  bool bChangedOPos = false;
879  if (pMark->IsExpanded() &&
880  &pMark->GetOtherMarkPos().nNode.GetNode() == pOldNode)
881  {
882  // shift the OtherMark to aNewPos
883  pMark->SetOtherMarkPos(aNewPos);
884  bChangedOPos= true;
885  isSortingNeeded = true;
886  }
887  // illegal selection? collapse the mark and restore sorting later
888  isSortingNeeded |= lcl_FixCorrectedMark(bChangedPos, bChangedOPos, pMark);
889  }
890 
891  // restore sorting if needed
892  if(isSortingNeeded)
893  sortMarks();
894 
895  SAL_INFO("sw.core", "correctMarksAbsolute");
896  lcl_DebugMarks(m_vAllMarks);
897  }
898 
899  void MarkManager::correctMarksRelative(const SwNodeIndex& rOldNode, const SwPosition& rNewPos, const sal_Int32 nOffset)
900  {
901  const SwNode* const pOldNode = &rOldNode.GetNode();
902  SwPosition aNewPos(rNewPos);
903  aNewPos.nContent += nOffset;
904  bool isSortingNeeded = false;
905 
906  for (auto ppMark = m_vAllMarks.begin();
907  ppMark != m_vAllMarks.end();
908  ++ppMark)
909  {
910  // is on position ??
911  bool bChangedPos = false, bChangedOPos = false;
912  ::sw::mark::MarkBase* const pMark = *ppMark;
913  // correction of non-existent non-MarkBase instances cannot be done
914  assert(pMark);
915  if(&pMark->GetMarkPos().nNode.GetNode() == pOldNode)
916  {
917  SwPosition aNewPosRel(aNewPos);
918  if (dynamic_cast< ::sw::mark::CrossRefBookmark *>(pMark))
919  {
920  // ensure that cross ref bookmark always starts at 0
921  aNewPosRel.nContent = 0; // HACK for WW8 import
922  isSortingNeeded = true; // and sort them to be safe...
923  }
924  aNewPosRel.nContent += pMark->GetMarkPos().nContent.GetIndex();
925  pMark->SetMarkPos(aNewPosRel);
926  bChangedPos = true;
927  }
928  if(pMark->IsExpanded() &&
929  &pMark->GetOtherMarkPos().nNode.GetNode() == pOldNode)
930  {
931  SwPosition aNewPosRel(aNewPos);
932  aNewPosRel.nContent += pMark->GetOtherMarkPos().nContent.GetIndex();
933  pMark->SetOtherMarkPos(aNewPosRel);
934  bChangedOPos = true;
935  }
936  // illegal selection? collapse the mark and restore sorting later
937  isSortingNeeded |= lcl_FixCorrectedMark(bChangedPos, bChangedOPos, pMark);
938  }
939 
940  // restore sorting if needed
941  if(isSortingNeeded)
942  sortMarks();
943 
944  SAL_INFO("sw.core", "correctMarksRelative");
945  lcl_DebugMarks(m_vAllMarks);
946  }
947 
949  const SwNodeIndex& rStt,
950  const SwNodeIndex& rEnd,
951  std::vector<SaveBookmark>* pSaveBkmk,
952  const SwIndex* pSttIdx,
953  const SwIndex* pEndIdx )
954  {
955  std::vector<const_iterator_t> vMarksToDelete;
956  bool bIsSortingNeeded = false;
957 
958  // boolean indicating, if at least one mark has been moved while collecting marks for deletion
959  bool bMarksMoved = false;
960  // have marks in the range been skipped instead of deleted
961  bool bMarksSkipDeletion = false;
962 
963  // copy all bookmarks in the move area to a vector storing all position data as offset
964  // reassignment is performed after the move
965  for (auto ppMark = m_vAllMarks.begin();
966  ppMark != m_vAllMarks.end();
967  ++ppMark)
968  {
969  // navigator marks should not be moved
970  // TODO: Check if this might make them invalid
972  continue;
973 
974  ::sw::mark::MarkBase *const pMark = *ppMark;
975 
976  if (!pMark)
977  continue;
978 
979  // on position ??
980  bool bIsPosInRange = lcl_GreaterThan(pMark->GetMarkPos(), rStt, pSttIdx)
981  && lcl_Lower(pMark->GetMarkPos(), rEnd, pEndIdx);
982  bool bIsOtherPosInRange = pMark->IsExpanded()
983  && lcl_GreaterThan(pMark->GetOtherMarkPos(), rStt, pSttIdx)
984  && lcl_Lower(pMark->GetOtherMarkPos(), rEnd, pEndIdx);
985  // special case: completely in range, touching the end?
986  if ( pEndIdx != nullptr
987  && ( ( bIsOtherPosInRange
988  && pMark->GetMarkPos().nNode == rEnd
989  && pMark->GetMarkPos().nContent == *pEndIdx )
990  || ( bIsPosInRange
991  && pMark->IsExpanded()
992  && pMark->GetOtherMarkPos().nNode == rEnd
993  && pMark->GetOtherMarkPos().nContent == *pEndIdx ) ) )
994  {
995  bIsPosInRange = true;
996  bIsOtherPosInRange = true;
997  }
998 
999  if ( bIsPosInRange
1000  && ( bIsOtherPosInRange
1001  || !pMark->IsExpanded() ) )
1002  {
1003  // completely in range
1004 
1005  bool bDeleteMark = true;
1006  {
1007  switch ( IDocumentMarkAccess::GetType( *pMark ) )
1008  {
1011  // no delete of cross-reference bookmarks, if range is inside one paragraph
1012  bDeleteMark = rStt != rEnd;
1013  break;
1015  // no delete of UNO mark, if it is not expanded and only touches the start of the range
1016  bDeleteMark = bIsOtherPosInRange
1017  || pMark->IsExpanded()
1018  || pSttIdx == nullptr
1019  || !( pMark->GetMarkPos().nNode == rStt
1020  && pMark->GetMarkPos().nContent == *pSttIdx );
1021  break;
1022  default:
1023  bDeleteMark = true;
1024  break;
1025  }
1026  }
1027 
1028  if ( bDeleteMark )
1029  {
1030  if ( pSaveBkmk )
1031  {
1032  pSaveBkmk->push_back( SaveBookmark( *pMark, rStt, pSttIdx ) );
1033  }
1034  vMarksToDelete.emplace_back(ppMark);
1035  }
1036  else
1037  {
1038  bMarksSkipDeletion = true;
1039  }
1040  }
1041  else if ( bIsPosInRange != bIsOtherPosInRange )
1042  {
1043  // the bookmark is partially in the range
1044  // move position of that is in the range out of it
1045 
1046  std::unique_ptr< SwPosition > pNewPos;
1047  {
1048  if ( pEndIdx != nullptr )
1049  {
1050  pNewPos = std::make_unique< SwPosition >( rEnd, *pEndIdx );
1051  }
1052  else
1053  {
1054  pNewPos =
1055  lcl_FindExpelPosition( rStt, rEnd, bIsPosInRange ? pMark->GetOtherMarkPos() : pMark->GetMarkPos() );
1056  }
1057  }
1058 
1059  bool bMoveMark = true;
1060  {
1061  switch ( IDocumentMarkAccess::GetType( *pMark ) )
1062  {
1065  // no move of cross-reference bookmarks, if move occurs inside a certain node
1066  bMoveMark = pMark->GetMarkPos().nNode != pNewPos->nNode;
1067  break;
1069  // no move of annotation marks, if method is called to collect deleted marks
1070  bMoveMark = pSaveBkmk == nullptr;
1071  break;
1072  default:
1073  bMoveMark = true;
1074  break;
1075  }
1076  }
1077  if ( bMoveMark )
1078  {
1079  if ( bIsPosInRange )
1080  pMark->SetMarkPos(*pNewPos);
1081  else
1082  pMark->SetOtherMarkPos(*pNewPos);
1083  bMarksMoved = true;
1084 
1085  // illegal selection? collapse the mark and restore sorting later
1086  bIsSortingNeeded |= lcl_FixCorrectedMark( bIsPosInRange, bIsOtherPosInRange, pMark );
1087  }
1088  }
1089  }
1090 
1091  {
1092  // fdo#61016 delay the deletion of the fieldmark characters
1093  // to prevent that from deleting the marks on that position
1094  // which would invalidate the iterators in vMarksToDelete
1095  std::vector< std::unique_ptr<ILazyDeleter> > vDelay;
1096  vDelay.reserve(vMarksToDelete.size());
1097 
1098  // If needed, sort mark containers containing subsets of the marks
1099  // in order to assure sorting. The sorting is critical for the
1100  // deletion of a mark as it is searched in these container for
1101  // deletion.
1102  if ( !vMarksToDelete.empty() && bMarksMoved )
1103  {
1104  sortSubsetMarks();
1105  }
1106  // we just remembered the iterators to delete, so we do not need to search
1107  // for the shared_ptr<> (the entry in m_vAllMarks) again
1108  // reverse iteration, since erasing an entry invalidates iterators
1109  // behind it (the iterators in vMarksToDelete are sorted)
1110  for ( std::vector< const_iterator_t >::reverse_iterator pppMark = vMarksToDelete.rbegin();
1111  pppMark != vMarksToDelete.rend();
1112  ++pppMark )
1113  {
1114  vDelay.push_back(deleteMark(*pppMark));
1115  }
1116  } // scope to kill vDelay
1117 
1118  // also need to sort if both marks were moved and not-deleted because
1119  // the not-deleted marks could be in wrong order vs. the moved ones
1120  if (bIsSortingNeeded || (bMarksMoved && bMarksSkipDeletion))
1121  {
1122  sortMarks();
1123  }
1124 
1125  SAL_INFO("sw.core", "deleteMarks");
1126  lcl_DebugMarks(m_vAllMarks);
1127  }
1128 
1129  namespace {
1130 
1131  struct LazyFieldmarkDeleter : public IDocumentMarkAccess::ILazyDeleter
1132  {
1133  std::unique_ptr<Fieldmark> m_pFieldmark;
1135  LazyFieldmarkDeleter(Fieldmark* pMark, SwDoc *const pDoc)
1136  : m_pFieldmark(pMark), m_pDoc(pDoc)
1137  {
1138  assert(m_pFieldmark);
1139  }
1140  virtual ~LazyFieldmarkDeleter() override
1141  {
1142  // note: because of the call chain from SwUndoDelete, the field
1143  // command *cannot* be deleted here as it would create a separate
1144  // SwUndoDelete that's interleaved with the SwHistory of the outer
1145  // one - only delete the CH_TXT_ATR_FIELD*!
1146  m_pFieldmark->ReleaseDoc(m_pDoc);
1147  }
1148  };
1149 
1150  }
1151 
1152  std::unique_ptr<IDocumentMarkAccess::ILazyDeleter>
1154  {
1155  std::unique_ptr<ILazyDeleter> ret;
1156  if (ppMark.get() == m_vAllMarks.end())
1157  return ret;
1158  IMark* pMark = *ppMark;
1159 
1160  switch(IDocumentMarkAccess::GetType(*pMark))
1161  {
1165  {
1166  auto const ppBookmark = lcl_FindMark(m_vBookmarks, *ppMark.get());
1167  if ( ppBookmark != m_vBookmarks.end() )
1168  {
1169  m_vBookmarks.erase(ppBookmark);
1170  }
1171  else
1172  {
1173  assert(false &&
1174  "<MarkManager::deleteMark(..)> - Bookmark not found in Bookmark container.");
1175  }
1176  }
1177  break;
1178 
1183  {
1184  auto const ppFieldmark = lcl_FindMark(m_vFieldmarks, *ppMark.get());
1185  if ( ppFieldmark != m_vFieldmarks.end() )
1186  {
1187  if(m_pLastActiveFieldmark == *ppFieldmark)
1189 
1190  m_vFieldmarks.erase(ppFieldmark);
1191  ret.reset(new LazyFieldmarkDeleter(dynamic_cast<Fieldmark*>(pMark), m_pDoc));
1192  }
1193  else
1194  {
1195  assert(false &&
1196  "<MarkManager::deleteMark(..)> - Fieldmark not found in Fieldmark container.");
1197  }
1198  }
1199  break;
1200 
1202  {
1203  auto const ppAnnotationMark = lcl_FindMark(m_vAnnotationMarks, *ppMark.get());
1204  assert(ppAnnotationMark != m_vAnnotationMarks.end() &&
1205  "<MarkManager::deleteMark(..)> - Annotation Mark not found in Annotation Mark container.");
1206  m_vAnnotationMarks.erase(ppAnnotationMark);
1207  }
1208  break;
1209 
1213  // no special marks container
1214  break;
1215  }
1216  DdeBookmark* const pDdeBookmark = dynamic_cast<DdeBookmark*>(pMark);
1217  if (pDdeBookmark)
1218  pDdeBookmark->DeregisterFromDoc(m_pDoc);
1219  //Effective STL Item 27, get a non-const iterator aI at the same
1220  //position as const iterator ppMark was
1221  auto aI = m_vAllMarks.begin();
1222  std::advance(aI, std::distance<container_t::const_iterator>(aI, ppMark.get()));
1223 
1224  m_vAllMarks.erase(aI);
1225  // If we don't have a lazy deleter
1226  if (!ret)
1227  // delete after we remove from the list, because the destructor can
1228  // recursively call into this method.
1229  delete pMark;
1230  return ret;
1231  }
1232 
1233  void MarkManager::deleteMark(const IMark* const pMark)
1234  {
1235  assert(pMark->GetMarkPos().GetDoc() == m_pDoc &&
1236  "<MarkManager::deleteMark(..)>"
1237  " - Mark is not in my doc.");
1238  // finds the last Mark that is starting before pMark
1239  // (pMarkLow < pMark)
1240  auto [it, endIt] = equal_range(
1241  m_vAllMarks.begin(),
1242  m_vAllMarks.end(),
1243  pMark->GetMarkStart(),
1244  CompareIMarkStartsBefore());
1245  for ( ; it != endIt; ++it)
1246  if (*it == pMark)
1247  {
1248  deleteMark(iterator(it));
1249  break;
1250  }
1251  }
1252 
1254  {
1256  m_vFieldmarks.clear();
1257  m_vBookmarks.clear();
1258  m_vAnnotationMarks.clear();
1259  for (const auto & p : m_vAllMarks)
1260  delete p;
1261  m_vAllMarks.clear();
1262  }
1263 
1265  {
1266  auto const ret = lcl_FindMarkByName(rName, m_vAllMarks.begin(), m_vAllMarks.end());
1267  return IDocumentMarkAccess::iterator(ret);
1268  }
1269 
1271  {
1272  auto const ret = lcl_FindMarkByName(rName, m_vBookmarks.begin(), m_vBookmarks.end());
1273  return IDocumentMarkAccess::iterator(ret);
1274  }
1275 
1277  { return m_vAllMarks.begin(); }
1278 
1280  { return m_vAllMarks.end(); }
1281 
1283  { return m_vAllMarks.size(); }
1284 
1286  { return m_vBookmarks.begin(); }
1287 
1289  { return m_vBookmarks.end(); }
1290 
1292  { return m_vBookmarks.size(); }
1293 
1294  // finds the first that is starting after
1296  {
1297  return std::upper_bound(
1298  m_vBookmarks.begin(),
1299  m_vBookmarks.end(),
1300  rPos,
1301  CompareIMarkStartsAfter());
1302  }
1303 
1305  {
1306  auto const pFieldmark = find_if(
1307  m_vFieldmarks.begin(),
1308  m_vFieldmarks.end(),
1309  [&rPos] (::sw::mark::MarkBase const*const pMark) {
1310  return pMark->GetMarkStart() == rPos
1311  // end position includes the CH_TXT_ATR_FIELDEND
1312  || (pMark->GetMarkEnd().nContent.GetIndex() == rPos.nContent.GetIndex() + 1
1313  && pMark->GetMarkEnd().nNode == rPos.nNode);
1314  } );
1315  return (pFieldmark == m_vFieldmarks.end())
1316  ? nullptr
1317  : dynamic_cast<IFieldmark*>(*pFieldmark);
1318  }
1319 
1321  {
1322  auto itFieldmark = find_if(
1323  m_vFieldmarks.begin(),
1324  m_vFieldmarks.end(),
1325  [&rPos] (const ::sw::mark::MarkBase *const pMark) { return pMark->IsCoveringPosition(rPos); } );
1326  if (itFieldmark == m_vFieldmarks.end())
1327  return nullptr;
1328  auto pFieldmark(*itFieldmark);
1329  for ( ; itFieldmark != m_vFieldmarks.end()
1330  && (**itFieldmark).IsCoveringPosition(rPos); ++itFieldmark)
1331  { // find the innermost fieldmark
1332  if (pFieldmark->GetMarkStart() < (**itFieldmark).GetMarkStart()
1333  || (**itFieldmark).GetMarkEnd() < pFieldmark->GetMarkEnd())
1334  {
1335  pFieldmark = *itFieldmark;
1336  }
1337  }
1338  return dynamic_cast<IFieldmark*>(pFieldmark);
1339  }
1340 
1342  {
1343  auto const pFieldmark = dynamic_cast<Fieldmark*>(getFieldmarkAt(rPos));
1344  if (!pFieldmark)
1345  return;
1346 
1347  deleteMark(lcl_FindMark(m_vAllMarks, pFieldmark));
1348  }
1349 
1351  {
1352  bool bActualChange = false;
1353  if(rNewType == ODF_FORMDROPDOWN)
1354  {
1355  if (!dynamic_cast<::sw::mark::DropDownFieldmark*>(pFieldmark))
1356  bActualChange = true;
1357  if (!dynamic_cast<::sw::mark::CheckboxFieldmark*>(pFieldmark)) // only allowed converting between checkbox <-> dropdown
1358  return nullptr;
1359  }
1360  else if(rNewType == ODF_FORMCHECKBOX)
1361  {
1362  if (!dynamic_cast<::sw::mark::CheckboxFieldmark*>(pFieldmark))
1363  bActualChange = true;
1364  if (!dynamic_cast<::sw::mark::DropDownFieldmark*>(pFieldmark)) // only allowed converting between checkbox <-> dropdown
1365  return nullptr;
1366  }
1367  else if(rNewType == ODF_FORMDATE)
1368  {
1369  if (!dynamic_cast<::sw::mark::DateFieldmark*>(pFieldmark))
1370  bActualChange = true;
1371  if (!dynamic_cast<::sw::mark::TextFieldmark*>(pFieldmark)) // only allowed converting between date field <-> text field
1372  return nullptr;
1373  }
1374 
1375  if (!bActualChange)
1376  return nullptr;
1377 
1378  // Store attributes needed to create the new fieldmark
1379  OUString sName = pFieldmark->GetName();
1380  SwPaM aPaM(pFieldmark->GetMarkPos());
1381 
1382  // Remove the old fieldmark and create a new one with the new type
1383  if(aPaM.GetPoint()->nContent > 0 && (rNewType == ODF_FORMDROPDOWN || rNewType == ODF_FORMCHECKBOX))
1384  {
1385  --aPaM.GetPoint()->nContent;
1386  SwPosition aNewPos (aPaM.GetPoint()->nNode, aPaM.GetPoint()->nContent);
1387  deleteFieldmarkAt(aNewPos);
1388  return makeNoTextFieldBookmark(aPaM, sName, rNewType);
1389  }
1390  else if(rNewType == ODF_FORMDATE)
1391  {
1392  SwPosition aPos (aPaM.GetPoint()->nNode, aPaM.GetPoint()->nContent);
1393  SwPaM aNewPaM(pFieldmark->GetMarkStart(), pFieldmark->GetMarkEnd());
1394  deleteFieldmarkAt(aPos);
1395  // HACK: hard-code the separator position here at the start because
1396  // writerfilter put it in the wrong place (at the end) on attach()
1397  SwPosition const sepPos(*aNewPaM.Start());
1398  return makeFieldBookmark(aNewPaM, sName, rNewType, &sepPos);
1399  }
1400  return nullptr;
1401  }
1402 
1404  {
1405  SwView* pSwView = dynamic_cast<SwView *>(rCursorShell.GetSfxViewShell());
1406  if(!pSwView)
1407  return;
1408 
1409  SwEditWin& rEditWin = pSwView->GetEditWin();
1410  SwPosition aPos(*rCursorShell.GetCursor()->GetPoint());
1411  IFieldmark* pFieldBM = getFieldmarkFor(aPos);
1412  FieldmarkWithDropDownButton* pNewActiveFieldmark = nullptr;
1413  if ((!pFieldBM || (pFieldBM->GetFieldname() != ODF_FORMDROPDOWN && pFieldBM->GetFieldname() != ODF_FORMDATE))
1414  && aPos.nContent.GetIndex() > 0 )
1415  {
1416  --aPos.nContent;
1417  pFieldBM = getFieldmarkFor(aPos);
1418  }
1419 
1420  if ( pFieldBM && (pFieldBM->GetFieldname() == ODF_FORMDROPDOWN ||
1421  pFieldBM->GetFieldname() == ODF_FORMDATE))
1422  {
1423  if (m_pLastActiveFieldmark != pFieldBM)
1424  {
1425  FieldmarkWithDropDownButton& rFormField = dynamic_cast<FieldmarkWithDropDownButton&>(*pFieldBM);
1426  rFormField.ShowButton(&rEditWin);
1427  pNewActiveFieldmark = &rFormField;
1428  }
1429  else
1430  {
1431  pNewActiveFieldmark = m_pLastActiveFieldmark;
1432  }
1433  }
1434 
1435  if(pNewActiveFieldmark != m_pLastActiveFieldmark)
1436  {
1438  m_pLastActiveFieldmark = pNewActiveFieldmark;
1439  }
1440  }
1441 
1443  {
1446 
1447  m_pLastActiveFieldmark = nullptr;
1448  }
1449 
1451  {
1452  IFieldmark *pMark = getFieldmarkAt(rPos);
1453  if (!pMark || pMark->GetFieldname() != ODF_FORMDROPDOWN)
1454  return nullptr;
1455  return pMark;
1456  }
1457 
1458  std::vector<IFieldmark*> MarkManager::getDropDownsFor(const SwPaM &rPaM) const
1459  {
1460  std::vector<IFieldmark*> aRet;
1461 
1462  for (auto aI = m_vFieldmarks.begin(),
1463  aEnd = m_vFieldmarks.end(); aI != aEnd; ++aI)
1464  {
1465  ::sw::mark::IMark* pI = *aI;
1466  const SwPosition &rStart = pI->GetMarkPos();
1467  if (!rPaM.ContainsPosition(rStart))
1468  continue;
1469 
1470  IFieldmark *pMark = dynamic_cast<IFieldmark*>(pI);
1471  if (!pMark || pMark->GetFieldname() != ODF_FORMDROPDOWN)
1472  continue;
1473 
1474  aRet.push_back(pMark);
1475  }
1476 
1477  return aRet;
1478  }
1479 
1481  { return dynamic_cast<IFieldmark*>(lcl_getMarkAfter(m_vFieldmarks, rPos)); }
1482 
1484  { return dynamic_cast<IFieldmark*>(lcl_getMarkBefore(m_vFieldmarks, rPos)); }
1485 
1487  {
1488  return m_vAnnotationMarks.begin();
1489  }
1490 
1492  {
1493  return m_vAnnotationMarks.end();
1494  }
1495 
1497  {
1498  return m_vAnnotationMarks.size();
1499  }
1500 
1502  {
1503  auto const ret = lcl_FindMarkByName( rName, m_vAnnotationMarks.begin(), m_vAnnotationMarks.end() );
1504  return IDocumentMarkAccess::iterator(ret);
1505  }
1506 
1508  {
1509  auto const pAnnotationMark = find_if(
1510  m_vAnnotationMarks.begin(),
1511  m_vAnnotationMarks.end(),
1512  [&rPos] (const ::sw::mark::MarkBase *const pMark) { return pMark->IsCoveringPosition(rPos); } );
1513  if (pAnnotationMark == m_vAnnotationMarks.end())
1514  return nullptr;
1515  return *pAnnotationMark;
1516  }
1517 
1518  // finds the first that is starting after
1520  {
1521  return std::upper_bound(
1522  m_vAnnotationMarks.begin(),
1523  m_vAnnotationMarks.end(),
1524  rPos,
1525  CompareIMarkStartsAfter());
1526  }
1527 
1528  OUString MarkManager::getUniqueMarkName(const OUString& rName) const
1529  {
1530  OSL_ENSURE(rName.getLength(),
1531  "<MarkManager::getUniqueMarkName(..)> - a name should be proposed");
1532  if( m_pDoc->IsInMailMerge())
1533  {
1534  OUString newName = rName + "MailMergeMark"
1535  + OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM )), RTL_TEXTENCODING_ASCII_US )
1536  + OUString::number( m_vAllMarks.size() + 1 );
1537  return newName;
1538  }
1539 
1540  if (lcl_FindMarkByName(rName, m_vAllMarks.begin(), m_vAllMarks.end()) == m_vAllMarks.end())
1541  {
1542  return rName;
1543  }
1544  OUString sTmp;
1545 
1546  // try the name "<rName>XXX" (where XXX is a number starting from 1) unless there is
1547  // an unused name. Due to performance-reasons (especially in mailmerge-scenarios) there
1548  // is a map m_aMarkBasenameMapUniqueOffset which holds the next possible offset (XXX) for
1549  // rName (so there is no need to test for nCnt-values smaller than the offset).
1550  sal_Int32 nCnt = 1;
1551  MarkBasenameMapUniqueOffset_t::const_iterator aIter = m_aMarkBasenameMapUniqueOffset.find(rName);
1552  if(aIter != m_aMarkBasenameMapUniqueOffset.end()) nCnt = aIter->second;
1553  while(nCnt < SAL_MAX_INT32)
1554  {
1555  sTmp = rName + OUString::number(nCnt);
1556  nCnt++;
1557  if (lcl_FindMarkByName(sTmp, m_vAllMarks.begin(), m_vAllMarks.end()) == m_vAllMarks.end())
1558  {
1559  break;
1560  }
1561  }
1562  m_aMarkBasenameMapUniqueOffset[rName] = nCnt;
1563 
1564  return sTmp;
1565  }
1566 
1568  {
1569  const_cast< MarkManager* >(this)->sortMarks();
1570  }
1571 
1573  {
1574  sort(m_vBookmarks.begin(), m_vBookmarks.end(), &lcl_MarkOrderingByStart);
1575  sort(m_vFieldmarks.begin(), m_vFieldmarks.end(), &lcl_MarkOrderingByStart);
1576  sort(m_vAnnotationMarks.begin(), m_vAnnotationMarks.end(), &lcl_MarkOrderingByStart);
1577  }
1578 
1580  {
1581  sort(m_vAllMarks.begin(), m_vAllMarks.end(), &lcl_MarkOrderingByStart);
1582  sortSubsetMarks();
1583  }
1584 
1586 {
1587  struct
1588  {
1589  const char* pName;
1590  const container_t* pContainer;
1591  } aContainers[] =
1592  {
1593  // UNO marks are only part of all marks.
1594  {"allmarks", &m_vAllMarks},
1595  {"bookmarks", &m_vBookmarks},
1596  {"fieldmarks", &m_vFieldmarks},
1597  {"annotationmarks", &m_vAnnotationMarks}
1598  };
1599 
1600  xmlTextWriterStartElement(pWriter, BAD_CAST("MarkManager"));
1601  for (const auto & rContainer : aContainers)
1602  {
1603  if (!rContainer.pContainer->empty())
1604  {
1605  xmlTextWriterStartElement(pWriter, BAD_CAST(rContainer.pName));
1606  for (auto it = rContainer.pContainer->begin(); it != rContainer.pContainer->end(); ++it)
1607  (*it)->dumpAsXml(pWriter);
1608  xmlTextWriterEndElement(pWriter);
1609  }
1610  }
1611  xmlTextWriterEndElement(pWriter);
1612 }
1613 
1614 } // namespace ::sw::mark
1615 
1616 namespace
1617 {
1618  bool lcl_Greater( const SwPosition& rPos, const SwNodeIndex& rNdIdx, const SwIndex* pIdx )
1619  {
1620  return rPos.nNode > rNdIdx || ( pIdx && rPos.nNode == rNdIdx && rPos.nContent > pIdx->GetIndex() );
1621  }
1622 }
1623 
1624 // IDocumentMarkAccess for SwDoc
1626  { return static_cast< IDocumentMarkAccess* >(mpMarkManager.get()); }
1627 
1629  { return static_cast< IDocumentMarkAccess* >(mpMarkManager.get()); }
1630 
1631 SaveBookmark::SaveBookmark(
1632  const IMark& rBkmk,
1633  const SwNodeIndex & rMvPos,
1634  const SwIndex* pIdx)
1635  : m_aName(rBkmk.GetName())
1636  , m_aShortName()
1637  , m_aCode()
1638  , m_eOrigBkmType(IDocumentMarkAccess::GetType(rBkmk))
1639 {
1640  const IBookmark* const pBookmark = dynamic_cast< const IBookmark* >(&rBkmk);
1641  if(pBookmark)
1642  {
1643  m_aShortName = pBookmark->GetShortName();
1644  m_aCode = pBookmark->GetKeyCode();
1645 
1646  ::sfx2::Metadatable const*const pMetadatable(
1647  dynamic_cast< ::sfx2::Metadatable const* >(pBookmark));
1648  if (pMetadatable)
1649  {
1650  m_pMetadataUndo = pMetadatable->CreateUndo();
1651  }
1652  }
1653  m_nNode1 = rBkmk.GetMarkPos().nNode.GetIndex();
1655 
1656  m_nNode1 -= rMvPos.GetIndex();
1657  if(pIdx && !m_nNode1)
1658  m_nContent1 -= pIdx->GetIndex();
1659 
1660  if(rBkmk.IsExpanded())
1661  {
1662  m_nNode2 = rBkmk.GetOtherMarkPos().nNode.GetIndex();
1664 
1665  m_nNode2 -= rMvPos.GetIndex();
1666  if(pIdx && !m_nNode2)
1667  m_nContent2 -= pIdx->GetIndex();
1668  }
1669  else
1670  {
1671  m_nNode2 = ULONG_MAX;
1672  m_nContent2 = -1;
1673  }
1674 }
1675 
1677  SwDoc* pDoc,
1678  const SwNodeIndex& rNewPos,
1679  const SwIndex* pIdx)
1680 {
1681  SwPaM aPam(rNewPos.GetNode());
1682  if(pIdx)
1683  aPam.GetPoint()->nContent = *pIdx;
1684 
1685  if(ULONG_MAX != m_nNode2)
1686  {
1687  aPam.SetMark();
1688 
1689  aPam.GetMark()->nNode += m_nNode2;
1690  if(pIdx && !m_nNode2)
1691  aPam.GetMark()->nContent += m_nContent2;
1692  else
1693  aPam.GetMark()->nContent.Assign(aPam.GetContentNode(false), m_nContent2);
1694  }
1695 
1696  aPam.GetPoint()->nNode += m_nNode1;
1697 
1698  if(pIdx && !m_nNode1)
1699  aPam.GetPoint()->nContent += m_nContent1;
1700  else
1701  aPam.GetPoint()->nContent.Assign(aPam.GetContentNode(), m_nContent1);
1702 
1703  if(!aPam.HasMark()
1704  || CheckNodesRange(aPam.GetPoint()->nNode, aPam.GetMark()->nNode, true))
1705  {
1706  ::sw::mark::IBookmark* const pBookmark = dynamic_cast<::sw::mark::IBookmark*>(
1707  pDoc->getIDocumentMarkAccess()->makeMark(aPam, m_aName,
1709  if(pBookmark)
1710  {
1711  pBookmark->SetKeyCode(m_aCode);
1712  pBookmark->SetShortName(m_aShortName);
1713  if (m_pMetadataUndo)
1714  {
1715  ::sfx2::Metadatable * const pMeta(
1716  dynamic_cast< ::sfx2::Metadatable* >(pBookmark));
1717  assert(pMeta && "metadata undo, but not metadatable?");
1718  if (pMeta)
1719  {
1721  }
1722  }
1723  }
1724  }
1725 }
1726 
1727 // DelBookmarks
1728 
1730  const SwNodeIndex& rStt,
1731  const SwNodeIndex& rEnd,
1732  std::vector<SaveBookmark> * pSaveBkmk,
1733  const SwIndex* pSttIdx,
1734  const SwIndex* pEndIdx)
1735 {
1736  // illegal range ??
1737  if(rStt.GetIndex() > rEnd.GetIndex()
1738  || (rStt == rEnd && (!pSttIdx || !pEndIdx || pSttIdx->GetIndex() >= pEndIdx->GetIndex())))
1739  return;
1740  SwDoc* const pDoc = rStt.GetNode().GetDoc();
1741 
1742  pDoc->getIDocumentMarkAccess()->deleteMarks(rStt, rEnd, pSaveBkmk, pSttIdx, pEndIdx);
1743 
1744  // Copy all Redlines which are in the move area into an array
1745  // which holds all position information as offset.
1746  // Assignment happens after moving.
1748  for(SwRangeRedline* pRedl : rTable)
1749  {
1750  // Is at position?
1751  SwPosition *const pRStt = pRedl->Start();
1752  SwPosition *const pREnd = pRedl->End();
1753 
1754  if( lcl_Greater( *pRStt, rStt, pSttIdx ) && lcl_Lower( *pRStt, rEnd, pEndIdx ))
1755  {
1756  pRStt->nNode = rEnd;
1757  if( pEndIdx )
1758  pRStt->nContent = *pEndIdx;
1759  else
1760  {
1761  bool bStt = true;
1762  SwContentNode* pCNd = pRStt->nNode.GetNode().GetContentNode();
1763  if( !pCNd && nullptr == ( pCNd = pDoc->GetNodes().GoNext( &pRStt->nNode )) )
1764  {
1765  bStt = false;
1766  pRStt->nNode = rStt;
1767  if( nullptr == ( pCNd = SwNodes::GoPrevious( &pRStt->nNode )) )
1768  {
1769  pRStt->nNode = pREnd->nNode;
1770  pCNd = pRStt->nNode.GetNode().GetContentNode();
1771  }
1772  }
1773  pRStt->nContent.Assign( pCNd, bStt ? 0 : pCNd->Len() );
1774  }
1775  }
1776  if( lcl_Greater( *pREnd, rStt, pSttIdx ) && lcl_Lower( *pREnd, rEnd, pEndIdx ))
1777  {
1778  pREnd->nNode = rStt;
1779  if( pSttIdx )
1780  pREnd->nContent = *pSttIdx;
1781  else
1782  {
1783  bool bStt = false;
1784  SwContentNode* pCNd = pREnd->nNode.GetNode().GetContentNode();
1785  if( !pCNd && nullptr == ( pCNd = SwNodes::GoPrevious( &pREnd->nNode )) )
1786  {
1787  bStt = true;
1788  pREnd->nNode = rEnd;
1789  if( nullptr == ( pCNd = pDoc->GetNodes().GoNext( &pREnd->nNode )) )
1790  {
1791  pREnd->nNode = pRStt->nNode;
1792  pCNd = pREnd->nNode.GetNode().GetContentNode();
1793  }
1794  }
1795  pREnd->nContent.Assign( pCNd, bStt ? 0 : pCNd->Len() );
1796  }
1797  }
1798  }
1799 }
1800 
1801 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sw::mark::IMark * getAnnotationMarkFor(const SwPosition &rPos) const override
Definition: docbm.cxx:1507
virtual sal_Int32 Len() const
Definition: node.cxx:1180
virtual void ShowButton(SwEditWin *pEditWin)=0
bool IsInMailMerge() const
Definition: doc.hxx:957
virtual const_iterator_t findFirstAnnotationStartsAfter(const SwPosition &rPos) const override
Finds the first mark that is starting after.
Definition: docbm.cxx:1519
virtual sal_Int32 getAllMarksCount() const override
returns the number of marks.
Definition: docbm.cxx:1282
virtual const OUString & GetName() const =0
Marks a position in the document model.
Definition: pam.hxx:35
void DelBookmarks(const SwNodeIndex &rStt, const SwNodeIndex &rEnd, std::vector< SaveBookmark > *pSaveBkmk, const SwIndex *pSttIdx, const SwIndex *pEndIdx)
Definition: docbm.cxx:1729
sw::mark::FieldmarkWithDropDownButton * m_pLastActiveFieldmark
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:188
virtual const_iterator_t findFirstBookmarkStartsAfter(const SwPosition &rPos) const override
Finds the first mark that is starting after.
Definition: docbm.cxx:1295
sal_uLong m_nNode2
Definition: mvsave.hxx:64
virtual void SetFieldname(const OUString &rFieldname)=0
To avoid recursive calls of deleteMark, the removal of dummy characters of fieldmarks has to be delay...
SwNodeIndex nNode
Definition: pam.hxx:37
wrapper iterator: wraps iterator of implementation while hiding MarkBase class; only IMark instances ...
virtual sal_Int32 Len() const override
Definition: ndtxt.cxx:273
virtual void SetModified()=0
Must be called manually at changes of format.
std::unique_ptr< std::vector<::sw::mark::MarkBase * >::const_iterator > m_pIter
static SW_DLLPUBLIC MarkType GetType(const ::sw::mark::IMark &rMark)
Returns the MarkType used to create the mark.
Definition: docbm.cxx:474
container_t m_vFieldmarks
const SwPosition * GetMark() const
Definition: pam.hxx:209
OUString getUniqueMarkName(const OUString &rName) const
Definition: docbm.cxx:1528
sal_Int64 n
Provides access to the marks of a document.
Definition: doc.hxx:185
#define ODF_FORMCHECKBOX
void SetInDoc(SwDoc *pDoc, const SwNodeIndex &, const SwIndex *pIdx=nullptr)
Definition: docbm.cxx:1676
virtual const SwPosition & GetMarkPos() const =0
SwPosition FindFieldSep(IFieldmark const &rMark)
return position of the CH_TXT_ATR_FIELDSEP for rMark
Definition: bookmrk.cxx:50
virtual ::sw::mark::IFieldmark * getFieldmarkAfter(const SwPosition &rPos) const override
Definition: docbm.cxx:1480
static SwContentNode * GoPrevious(SwNodeIndex *)
Definition: nodes.cxx:1294
SwNode & GetNode() const
Definition: ndindex.hxx:119
SwEditWin & GetEditWin()
Definition: view.hxx:403
virtual const_iterator_t getAllMarksBegin() const override
returns a STL-like random access iterator to the begin of the sequence of marks.
Definition: docbm.cxx:1276
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1625
Dialog to specify the properties of date form field.
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:143
virtual const_iterator_t getAnnotationMarksBegin() const override
Definition: docbm.cxx:1486
IDocumentMarkAccess::MarkType const m_eOrigBkmType
Definition: mvsave.hxx:62
SfxViewShell * GetSfxViewShell() const
Definition: viewsh.hxx:444
virtual ::sw::mark::IFieldmark * getFieldmarkFor(const SwPosition &rPos) const override
Definition: docbm.cxx:1320
Fieldmark with a drop down button (e.g. this button opens the date picker for a date field) ...
Definition: bookmrk.hxx:273
virtual sw::mark::IFieldmark * makeNoTextFieldBookmark(const SwPaM &rPaM, const OUString &rName, const OUString &rType) override
Definition: docbm.cxx:731
virtual bool IsExpanded() const override
Definition: bookmrk.hxx:83
SwDoc * m_pDoc
Definition: docbm.cxx:1134
virtual const_iterator_t getBookmarksEnd() const override
returns a STL-like random access iterator to the end of the sequence of IBookmarks.
Definition: docbm.cxx:1288
virtual const OUString & GetName() const override
Definition: bookmrk.hxx:58
virtual void clearAllMarks() override
Clear (deletes) all marks.
Definition: docbm.cxx:1253
static SW_DLLPUBLIC OUString GetCrossRefHeadingBookmarkNamePrefix()
Definition: docbm.cxx:508
static SW_DLLPUBLIC bool IsLegalPaMForCrossRefHeadingBookmark(const SwPaM &rPaM)
Definition: docbm.cxx:513
bool operator==(iterator const &rOther) const
Definition: docbm.cxx:108
SwIndex nContent
Definition: pam.hxx:38
container_t m_vBookmarks
SwDoc * GetDoc() const
Returns the document this position is in.
Definition: pam.cxx:176
virtual ::sw::mark::IFieldmark * getFieldmarkAt(const SwPosition &rPos) const override
get Fieldmark for CH_TXT_ATR_FIELDSTART/CH_TXT_ATR_FIELDEND at rPos
Definition: docbm.cxx:1304
sal_Int32 m_nContent1
Definition: mvsave.hxx:65
virtual ::sw::mark::IMark * makeMark(const SwPaM &rPaM, const OUString &rProposedName, MarkType eMark,::sw::mark::InsertMode eMode, SwPosition const *pSepPos=nullptr)=0
Generates a new mark in the document for a certain selection.
iterator & operator-=(difference_type)
Definition: docbm.cxx:147
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
virtual void DoUndo(bool const bDoUndo)=0
Enable/Disable Undo.
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: docbm.cxx:1585
sal_uLong m_nNode1
Definition: mvsave.hxx:63
bool CheckNodesRange(const SwNodeIndex &rStt, const SwNodeIndex &rEnd, bool bChkSection)
Check if the given range is inside one of the defined top-level sections.
Definition: pam.cxx:250
virtual bool IsEnableSetModified() const =0
virtual ::sw::mark::IMark * getMarkForTextNode(const SwTextNode &rTextNode, IDocumentMarkAccess::MarkType eMark) override
Returns a mark in the document for a paragraph.
Definition: docbm.cxx:780
bool operator!=(iterator const &rOther) const
Definition: docbm.cxx:113
virtual void deleteMarks(const SwNodeIndex &rStt, const SwNodeIndex &rEnd, std::vector< ::sw::mark::SaveBookmark > *pSaveBkmk, const SwIndex *pSttIdx, const SwIndex *pEndIdx) override
Deletes marks in a range.
Definition: docbm.cxx:948
virtual bool DoesUndo() const =0
Is Undo enabled?
virtual void SetKeyCode(const vcl::KeyCode &)=0
const char * sName
virtual void SetShortName(const OUString &)=0
bool ContainsPosition(const SwPosition &rPos) const
Definition: pam.hxx:257
OUString m_aName
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
struct _xmlTextWriter * xmlTextWriterPtr
virtual void AppendUndo(std::unique_ptr< SwUndo > pUndo)=0
Add new Undo action.
sal_uInt16 char * pName
virtual sal_Int32 getAnnotationMarksCount() const override
Definition: docbm.cxx:1496
virtual ::sw::mark::IMark * makeMark(const SwPaM &rPaM, const OUString &rName, IDocumentMarkAccess::MarkType eMark, sw::mark::InsertMode eMode, SwPosition const *pSepPos=nullptr) override
Definition: docbm.cxx:544
container_t m_vAnnotationMarks
#define SAL_MAX_INT32
OUString m_aShortName
Definition: mvsave.hxx:60
virtual void deleteMarks(const SwNodeIndex &rStt, const SwNodeIndex &rEnd, std::vector< ::sw::mark::SaveBookmark > *pSaveBkmk, const SwIndex *pSttIdx, const SwIndex *pEndIdx)=0
Deletes marks in a range.
OUString const m_aName
Definition: mvsave.hxx:59
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:131
virtual const_iterator_t getAnnotationMarksEnd() const override
Definition: docbm.cxx:1491
const SwPosition * GetPoint() const
Definition: pam.hxx:207
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:58
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:198
std::vector< sw::mark::MarkBase * > container_t
virtual void assureSortedMarkContainers() const override
Definition: docbm.cxx:1567
MarkBasenameMapUniqueOffset_t m_aMarkBasenameMapUniqueOffset
SwContentNode * GetContentNode()
Definition: node.hxx:615
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
Definition: pam.hxx:205
virtual const_iterator_t findMark(const OUString &rName) const override
Finds a mark by name.
Definition: docbm.cxx:1264
SwDoc * GetDoc()
Definition: node.hxx:702
virtual std::unique_ptr< ILazyDeleter > deleteMark(const const_iterator_t &ppMark) override
Deletes a mark.
Definition: docbm.cxx:1153
virtual const OUString & GetShortName() const =0
virtual bool renameMark(::sw::mark::IMark *io_pMark, const OUString &rNewName) override
Renames an existing Mark, if possible.
Definition: docbm.cxx:824
iterator operator-(difference_type) const
Definition: docbm.cxx:153
iterator operator+(difference_type) const
Definition: docbm.cxx:142
Marks a character position inside a document model node.
Definition: index.hxx:37
virtual bool IsCoveringPosition(const SwPosition &rPos) const =0
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:393
std::shared_ptr< MetadatableUndo > CreateUndo() const
std::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndo
Definition: mvsave.hxx:67
Marks a node in the document model.
Definition: ndindex.hxx:31
virtual const vcl::KeyCode & GetKeyCode() const =0
OUString newName(const OUString &aNewPrefix, const OUString &aOldPrefix, const OUString &old_Name)
std::unique_ptr< Fieldmark > m_pFieldmark
Definition: docbm.cxx:1133
iterator & operator=(iterator const &rOther)
Definition: docbm.cxx:68
virtual const_iterator_t getAllMarksEnd() const override
returns a STL-like random access iterator to the end of the sequence of marks.
Definition: docbm.cxx:1279
virtual const_iterator_t findAnnotationMark(const OUString &rName) const override
Definition: docbm.cxx:1501
const SwPosition * Start() const
Definition: pam.hxx:212
void SetMark(const sw::mark::IMark *pMark)
Definition: index.cxx:214
virtual sw::mark::IMark * makeAnnotationMark(const SwPaM &rPaM, const OUString &rName) override
Definition: docbm.cxx:793
virtual SwPosition & GetOtherMarkPos() const override
Definition: bookmrk.hxx:60
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:334
virtual sal_Int32 getBookmarksCount() const override
returns the number of IBookmarks.
Definition: docbm.cxx:1291
bool operator<=(iterator const &rOther) const
Definition: docbm.cxx:176
virtual void correctMarksAbsolute(const SwNodeIndex &rOldNode, const SwPosition &rNewPos, const sal_Int32 nOffset) override
Corrects marks (absolute) This method ignores the previous position of the mark in the paragraph...
Definition: docbm.cxx:853
virtual void NotifyCursorUpdate(const SwCursorShell &rCursorShell) override
Definition: docbm.cxx:1403
const SwNodes & GetNodes() const
Definition: ndindex.hxx:156
virtual sw::mark::IFieldmark * makeFieldBookmark(const SwPaM &rPaM, const OUString &rName, const OUString &rType, SwPosition const *pSepPos=nullptr) override
Definition: docbm.cxx:691
#define SAL_INFO(area, stream)
sal_Int32 GetIndex() const
Definition: index.hxx:95
OString DateTimeToOString(const DateTime &rDateTime)
virtual SwPosition & GetMarkPos() const override
Definition: bookmrk.hxx:56
SwNodes & GetNodes()
Definition: doc.hxx:403
bool operator>(iterator const &rOther) const
Definition: docbm.cxx:172
virtual const_iterator_t findBookmark(const OUString &rName) const override
Finds a bookmark by name.
Definition: docbm.cxx:1270
const SwPosition * End() const
Definition: pam.hxx:217
virtual void correctMarksRelative(const SwNodeIndex &rOldNode, const SwPosition &rNewPos, const sal_Int32 nOffset) override
Corrects marks (relative) This method uses the previous position of the mark in the paragraph as offs...
Definition: docbm.cxx:899
virtual void SetMarkPos(const SwPosition &rNewPos)
Definition: bookmrk.cxx:267
void * p
iterator & operator+=(difference_type)
Definition: docbm.cxx:136
virtual ::sw::mark::IFieldmark * getFieldmarkBefore(const SwPosition &rPos) const override
Definition: docbm.cxx:1483
virtual ::sw::mark::IFieldmark * getDropDownFor(const SwPosition &rPos) const override
Definition: docbm.cxx:1450
virtual const SwPosition & GetMarkEnd() const =0
static void DeleteFieldmarkCommand(::sw::mark::IFieldmark const &rMark)
Definition: docbm.cxx:522
virtual void deleteFieldmarkAt(const SwPosition &rPos) override
Definition: docbm.cxx:1341
virtual std::vector< ::sw::mark::IFieldmark * > getDropDownsFor(const SwPaM &rPaM) const override
Definition: docbm.cxx:1458
#define ODF_FORMDATE
virtual void SetEnableSetModified(bool bEnableSetModified)=0
virtual OUString GetFieldname() const =0
virtual ::sw::mark::IFieldmark * changeFormFieldmarkType(::sw::mark::IFieldmark *pFieldmark, const OUString &rNewType) override
Definition: docbm.cxx:1350
#define SAL_WARN(area, stream)
virtual void ClearFieldActivation() override
Definition: docbm.cxx:1442
vcl::KeyCode m_aCode
Definition: mvsave.hxx:61
virtual void DeregisterFromDoc(SwDoc *const pDoc)
Definition: bookmrk.cxx:356
virtual const SwPosition & GetMarkStart() const =0
::sw::mark::IMark * operator*() const
Definition: docbm.cxx:91
sal_Int32 m_nContent2
Definition: mvsave.hxx:66
InsertMode
Definition: IMark.hxx:31
virtual void SetOtherMarkPos(const SwPosition &rNewPos)
Definition: bookmrk.cxx:273
virtual const SwRedlineTable & GetRedlineTable() const =0
virtual const_iterator_t getBookmarksBegin() const override
returns a STL-like random access iterator to the begin of the sequence the IBookmarks.
Definition: docbm.cxx:1285
bool IsFieldmarkOverlap(SwPaM const &rPaM)
check if rPaM is valid range of new fieldmark
bool operator<(iterator const &rOther) const
Definition: docbm.cxx:168
bool operator>=(iterator const &rOther) const
Definition: docbm.cxx:180
virtual bool IsExpanded() const =0
std::vector<::sw::mark::MarkBase * >::const_iterator const & get() const
Definition: docbm.cxx:53
bool IsTextNode() const
Definition: node.hxx:636
value_type operator[](difference_type) const
Definition: docbm.cxx:163
virtual void repositionMark(::sw::mark::IMark *io_pMark, const SwPaM &rPaM) override
Moves an existing mark to a new selection and performs needed updates.
Definition: docbm.cxx:801
void RestoreMetadata(std::shared_ptr< MetadatableUndo > const &i_pUndo)
SwContentNode * GoNext(SwNodeIndex *) const
Definition: nodes.cxx:1277
Definition: view.hxx:146
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:842
#define ODF_FORMDROPDOWN
virtual const SwPosition & GetOtherMarkPos() const =0
Base class of the Writer document model elements.
Definition: node.hxx:79
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo