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  if ( (!rPaM.GetPoint()->nNode.GetNode().IsTextNode()
565  && (eType != MarkType::UNO_BOOKMARK
566  // SwXTextRange can be on table node or plain start node (FLY_AT_FLY)
567  || !rPaM.GetPoint()->nNode.GetNode().IsStartNode()))
568  || (!rPaM.GetMark()->nNode.GetNode().IsTextNode()
569  && (eType != MarkType::UNO_BOOKMARK
570  || !rPaM.GetMark()->nNode.GetNode().IsStartNode())))
571  {
572  SAL_WARN("sw.core", "MarkManager::makeMark(..)"
573  " - refusing to create mark on non-textnode");
574  return nullptr;
575  }
576  // There should only be one CrossRefBookmark per Textnode per Type
578  && (lcl_FindMarkAtPos(m_vBookmarks, *rPaM.Start(), eType) != m_vBookmarks.end()))
579  { // this can happen via UNO API
580  SAL_WARN("sw.core", "MarkManager::makeMark(..)"
581  " - refusing to create duplicate CrossRefBookmark");
582  return nullptr;
583  }
584 
586  && (eMode == InsertMode::New
587  ? *rPaM.GetPoint() != *rPaM.GetMark()
588  // CopyText: pam covers CH_TXT_ATR_FORMELEMENT
589  : (rPaM.GetPoint()->nNode != rPaM.GetMark()->nNode
590  || rPaM.Start()->nContent.GetIndex() + 1 != rPaM.End()->nContent.GetIndex())))
591  {
592  SAL_WARN("sw.core", "MarkManager::makeMark(..)"
593  " - invalid range on point fieldmark");
594  return nullptr;
595  }
596 
597  if ((eType == MarkType::TEXT_FIELDMARK || eType == MarkType::DATE_FIELDMARK)
599  || (pSepPos && rPaM.GetPoint()->nNode.GetNode().StartOfSectionNode() != pSepPos->nNode.GetNode().StartOfSectionNode())))
600  {
601  SAL_WARN("sw.core", "MarkManager::makeMark(..)"
602  " - invalid range on fieldmark, different nodes array sections");
603  return nullptr;
604  }
605 
606  if ((eType == MarkType::TEXT_FIELDMARK || eType == MarkType::DATE_FIELDMARK)
607  // can't check for Copy - it asserts - but it's also obviously unnecessary
608  && eMode == InsertMode::New
610  {
611  SAL_WARN("sw.core", "MarkManager::makeMark(..)"
612  " - invalid range on fieldmark, overlaps existing fieldmark or meta-field");
613  return nullptr;
614  }
615 
616  // create mark
617  std::unique_ptr<::sw::mark::MarkBase> pMark;
618  switch(eType)
619  {
621  pMark = std::make_unique<TextFieldmark>(rPaM, rName);
622  break;
624  pMark = std::make_unique<CheckboxFieldmark>(rPaM);
625  break;
627  pMark = std::make_unique<DropDownFieldmark>(rPaM);
628  break;
630  pMark = std::make_unique<DateFieldmark>(rPaM);
631  break;
633  pMark = std::make_unique<NavigatorReminder>(rPaM);
634  break;
636  pMark = std::make_unique<Bookmark>(rPaM, vcl::KeyCode(), rName);
637  break;
639  pMark = std::make_unique<DdeBookmark>(rPaM);
640  break;
642  pMark = std::make_unique<CrossRefHeadingBookmark>(rPaM, vcl::KeyCode(), rName);
643  break;
645  pMark = std::make_unique<CrossRefNumItemBookmark>(rPaM, vcl::KeyCode(), rName);
646  break;
648  pMark = std::make_unique<UnoMark>(rPaM);
649  break;
651  pMark = std::make_unique<AnnotationMark>( rPaM, rName );
652  break;
653  }
654  assert(pMark && "MarkManager::makeMark(..) - Mark was not created.");
655 
656  if(pMark->GetMarkPos() != pMark->GetMarkStart())
657  pMark->Swap();
658 
659  // for performance reasons, we trust UnoMarks to have a (generated) unique name
661  pMark->SetName( getUniqueMarkName( pMark->GetName() ) );
662 
663  // insert any dummy chars before inserting into sorted vectors
664  pMark->InitDoc(m_pDoc, eMode, pSepPos);
665 
666  // register mark
667  lcl_InsertMarkSorted(m_vAllMarks, pMark.get());
668  switch(eType)
669  {
673  lcl_InsertMarkSorted(m_vBookmarks, pMark.get());
674  break;
679  lcl_InsertMarkSorted(m_vFieldmarks, pMark.get());
680  break;
682  lcl_InsertMarkSorted( m_vAnnotationMarks, pMark.get() );
683  break;
687  // no special array for these
688  break;
689  }
690  SAL_INFO("sw.core", "--- makeType ---");
691  SAL_INFO("sw.core", "Marks");
692  lcl_DebugMarks(m_vAllMarks);
693  SAL_INFO("sw.core", "Bookmarks");
694  lcl_DebugMarks(m_vBookmarks);
695  SAL_INFO("sw.core", "Fieldmarks");
696  lcl_DebugMarks(m_vFieldmarks);
697 
698  return pMark.release();
699  }
700 
702  const SwPaM& rPaM,
703  const OUString& rName,
704  const OUString& rType,
705  SwPosition const*const pSepPos)
706  {
707 
708  // Disable undo, because we handle it using SwUndoInsTextFieldmark
709  bool bUndoIsEnabled = m_pDoc->GetIDocumentUndoRedo().DoesUndo();
711 
712  sw::mark::IMark* pMark = nullptr;
713  if(rType == ODF_FORMDATE)
714  {
715  pMark = makeMark(rPaM, rName,
718  pSepPos);
719  }
720  else
721  {
722  pMark = makeMark(rPaM, rName,
725  pSepPos);
726  }
727  sw::mark::IFieldmark* pFieldMark = dynamic_cast<sw::mark::IFieldmark*>( pMark );
728  if (pFieldMark)
729  pFieldMark->SetFieldname( rType );
730 
731  if (bUndoIsEnabled)
732  {
733  m_pDoc->GetIDocumentUndoRedo().DoUndo(bUndoIsEnabled);
734  if (pFieldMark)
735  m_pDoc->GetIDocumentUndoRedo().AppendUndo(std::make_unique<SwUndoInsTextFieldmark>(*pFieldMark));
736  }
737 
738  return pFieldMark;
739  }
740 
742  const SwPaM& rPaM,
743  const OUString& rName,
744  const OUString& rType)
745  {
746  // Disable undo, because we handle it using SwUndoInsNoTextFieldmark
747  bool bUndoIsEnabled = m_pDoc->GetIDocumentUndoRedo().DoesUndo();
749 
750  bool bEnableSetModified = m_pDoc->getIDocumentState().IsEnableSetModified();
752 
753  sw::mark::IMark* pMark = nullptr;
754  if(rType == ODF_FORMCHECKBOX)
755  {
756  pMark = makeMark( rPaM, rName,
759  }
760  else if(rType == ODF_FORMDROPDOWN)
761  {
762  pMark = makeMark( rPaM, rName,
765  }
766  else if(rType == ODF_FORMDATE)
767  {
768  pMark = makeMark( rPaM, rName,
771  }
772 
773  sw::mark::IFieldmark* pFieldMark = dynamic_cast<sw::mark::IFieldmark*>( pMark );
774  if (pFieldMark)
775  pFieldMark->SetFieldname( rType );
776 
777  if (bUndoIsEnabled)
778  {
779  m_pDoc->GetIDocumentUndoRedo().DoUndo(bUndoIsEnabled);
780  if (pFieldMark)
781  m_pDoc->GetIDocumentUndoRedo().AppendUndo(std::make_unique<SwUndoInsNoTextFieldmark>(*pFieldMark));
782  }
783 
784  m_pDoc->getIDocumentState().SetEnableSetModified(bEnableSetModified);
786 
787  return pFieldMark;
788  }
789 
791  const SwTextNode& rTextNode,
792  const IDocumentMarkAccess::MarkType eType )
793  {
794  SwPosition aPos(rTextNode);
795  aPos.nContent.Assign(&const_cast<SwTextNode&>(rTextNode), 0);
796  auto const ppExistingMark = lcl_FindMarkAtPos(m_vBookmarks, aPos, eType);
797  if(ppExistingMark != m_vBookmarks.end())
798  return *ppExistingMark;
799  const SwPaM aPaM(aPos);
800  return makeMark(aPaM, OUString(), eType, sw::mark::InsertMode::New);
801  }
802 
804  const SwPaM& rPaM,
805  const OUString& rName )
806  {
809  }
810 
812  ::sw::mark::IMark* const io_pMark,
813  const SwPaM& rPaM)
814  {
815  assert(io_pMark->GetMarkPos().GetDoc() == m_pDoc &&
816  "<MarkManager::repositionMark(..)>"
817  " - Mark is not in my doc.");
818  MarkBase* const pMarkBase = dynamic_cast< MarkBase* >(io_pMark);
819  if (!pMarkBase)
820  return;
821 
822  pMarkBase->InvalidateFrames();
823 
824  pMarkBase->SetMarkPos(*(rPaM.GetPoint()));
825  if(rPaM.HasMark())
826  pMarkBase->SetOtherMarkPos(*(rPaM.GetMark()));
827  else
828  pMarkBase->ClearOtherMarkPos();
829 
830  if(pMarkBase->GetMarkPos() != pMarkBase->GetMarkStart())
831  pMarkBase->Swap();
832 
833  pMarkBase->InvalidateFrames();
834 
835  sortMarks();
836  }
837 
839  ::sw::mark::IMark* io_pMark,
840  const OUString& rNewName )
841  {
842  assert(io_pMark->GetMarkPos().GetDoc() == m_pDoc &&
843  "<MarkManager::renameMark(..)>"
844  " - Mark is not in my doc.");
845  if ( io_pMark->GetName() == rNewName )
846  return true;
847  if (lcl_FindMarkByName(rNewName, m_vAllMarks.begin(), m_vAllMarks.end()) != m_vAllMarks.end())
848  return false;
849  if (::sw::mark::MarkBase* pMarkBase = dynamic_cast< ::sw::mark::MarkBase* >(io_pMark))
850  {
851  const OUString sOldName(pMarkBase->GetName());
852  pMarkBase->SetName(rNewName);
853 
854  if (dynamic_cast< ::sw::mark::Bookmark* >(io_pMark))
855  {
857  {
859  std::make_unique<SwUndoRenameBookmark>(sOldName, rNewName, m_pDoc));
860  }
862  }
863  }
864  return true;
865  }
866 
868  const SwNodeIndex& rOldNode,
869  const SwPosition& rNewPos,
870  const sal_Int32 nOffset)
871  {
872  const SwNode* const pOldNode = &rOldNode.GetNode();
873  SwPosition aNewPos(rNewPos);
874  aNewPos.nContent += nOffset;
875  bool isSortingNeeded = false;
876 
877  for (auto ppMark = m_vAllMarks.begin();
878  ppMark != m_vAllMarks.end();
879  ++ppMark)
880  {
881  ::sw::mark::MarkBase *const pMark = *ppMark;
882  // correction of non-existent non-MarkBase instances cannot be done
883  assert(pMark);
884  // is on position ??
885  bool bChangedPos = false;
886  if(&pMark->GetMarkPos().nNode.GetNode() == pOldNode)
887  {
888  pMark->SetMarkPos(aNewPos);
889  bChangedPos = true;
890  isSortingNeeded = true;
891  }
892  bool bChangedOPos = false;
893  if (pMark->IsExpanded() &&
894  &pMark->GetOtherMarkPos().nNode.GetNode() == pOldNode)
895  {
896  // shift the OtherMark to aNewPos
897  pMark->SetOtherMarkPos(aNewPos);
898  bChangedOPos= true;
899  isSortingNeeded = true;
900  }
901  // illegal selection? collapse the mark and restore sorting later
902  isSortingNeeded |= lcl_FixCorrectedMark(bChangedPos, bChangedOPos, pMark);
903  }
904 
905  // restore sorting if needed
906  if(isSortingNeeded)
907  sortMarks();
908 
909  SAL_INFO("sw.core", "correctMarksAbsolute");
910  lcl_DebugMarks(m_vAllMarks);
911  }
912 
913  void MarkManager::correctMarksRelative(const SwNodeIndex& rOldNode, const SwPosition& rNewPos, const sal_Int32 nOffset)
914  {
915  const SwNode* const pOldNode = &rOldNode.GetNode();
916  SwPosition aNewPos(rNewPos);
917  aNewPos.nContent += nOffset;
918  bool isSortingNeeded = false;
919 
920  for (auto ppMark = m_vAllMarks.begin();
921  ppMark != m_vAllMarks.end();
922  ++ppMark)
923  {
924  // is on position ??
925  bool bChangedPos = false, bChangedOPos = false;
926  ::sw::mark::MarkBase* const pMark = *ppMark;
927  // correction of non-existent non-MarkBase instances cannot be done
928  assert(pMark);
929  if(&pMark->GetMarkPos().nNode.GetNode() == pOldNode)
930  {
931  SwPosition aNewPosRel(aNewPos);
932  if (dynamic_cast< ::sw::mark::CrossRefBookmark *>(pMark))
933  {
934  // ensure that cross ref bookmark always starts at 0
935  aNewPosRel.nContent = 0; // HACK for WW8 import
936  isSortingNeeded = true; // and sort them to be safe...
937  }
938  aNewPosRel.nContent += pMark->GetMarkPos().nContent.GetIndex();
939  pMark->SetMarkPos(aNewPosRel);
940  bChangedPos = true;
941  }
942  if(pMark->IsExpanded() &&
943  &pMark->GetOtherMarkPos().nNode.GetNode() == pOldNode)
944  {
945  SwPosition aNewPosRel(aNewPos);
946  aNewPosRel.nContent += pMark->GetOtherMarkPos().nContent.GetIndex();
947  pMark->SetOtherMarkPos(aNewPosRel);
948  bChangedOPos = true;
949  }
950  // illegal selection? collapse the mark and restore sorting later
951  isSortingNeeded |= lcl_FixCorrectedMark(bChangedPos, bChangedOPos, pMark);
952  }
953 
954  // restore sorting if needed
955  if(isSortingNeeded)
956  sortMarks();
957 
958  SAL_INFO("sw.core", "correctMarksRelative");
959  lcl_DebugMarks(m_vAllMarks);
960  }
961 
962  static bool isDeleteMark(
963  ::sw::mark::MarkBase const*const pMark,
964  SwNodeIndex const& rStt,
965  SwNodeIndex const& rEnd,
966  SwIndex const*const pSttIdx,
967  SwIndex const*const pEndIdx,
968  bool & rbIsPosInRange,
969  bool & rbIsOtherPosInRange)
970  {
971  assert(pMark);
972  // navigator marks should not be moved
973  // TODO: Check if this might make them invalid
975  {
976  return false;
977  }
978 
979  // on position ??
980  rbIsPosInRange = lcl_GreaterThan(pMark->GetMarkPos(), rStt, pSttIdx)
981  && lcl_Lower(pMark->GetMarkPos(), rEnd, pEndIdx);
982  rbIsOtherPosInRange = 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  && ( ( rbIsOtherPosInRange
988  && pMark->GetMarkPos().nNode == rEnd
989  && pMark->GetMarkPos().nContent == *pEndIdx )
990  || ( rbIsPosInRange
991  && pMark->IsExpanded()
992  && pMark->GetOtherMarkPos().nNode == rEnd
993  && pMark->GetOtherMarkPos().nContent == *pEndIdx ) ) )
994  {
995  rbIsPosInRange = true;
996  rbIsOtherPosInRange = true;
997  }
998 
999  if (rbIsPosInRange
1000  && (rbIsOtherPosInRange
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 = rbIsOtherPosInRange
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  return bDeleteMark;
1028  }
1029  return false;
1030  }
1031 
1032  bool MarkManager::isBookmarkDeleted(SwPaM const& rPaM) const
1033  {
1034  SwPosition const& rStart(*rPaM.Start());
1035  SwPosition const& rEnd(*rPaM.End());
1036  for (auto ppMark = m_vBookmarks.begin();
1037  ppMark != m_vBookmarks.end();
1038  ++ppMark)
1039  {
1040  bool bIsPosInRange(false);
1041  bool bIsOtherPosInRange(false);
1042  bool const bDeleteMark = isDeleteMark(*ppMark,
1043  rStart.nNode, rEnd.nNode, &rStart.nContent, &rEnd.nContent,
1044  bIsPosInRange, bIsOtherPosInRange);
1045  if (bDeleteMark
1047  {
1048  return true;
1049  }
1050  }
1051  return false;
1052  }
1053 
1055  const SwNodeIndex& rStt,
1056  const SwNodeIndex& rEnd,
1057  std::vector<SaveBookmark>* pSaveBkmk,
1058  const SwIndex* pSttIdx,
1059  const SwIndex* pEndIdx )
1060  {
1061  std::vector<const_iterator_t> vMarksToDelete;
1062  bool bIsSortingNeeded = false;
1063 
1064  // boolean indicating, if at least one mark has been moved while collecting marks for deletion
1065  bool bMarksMoved = false;
1066  // have marks in the range been skipped instead of deleted
1067  bool bMarksSkipDeletion = false;
1068 
1069  // copy all bookmarks in the move area to a vector storing all position data as offset
1070  // reassignment is performed after the move
1071  for (auto ppMark = m_vAllMarks.begin();
1072  ppMark != m_vAllMarks.end();
1073  ++ppMark)
1074  {
1075  ::sw::mark::MarkBase *const pMark = *ppMark;
1076  bool bIsPosInRange(false);
1077  bool bIsOtherPosInRange(false);
1078  bool const bDeleteMark = isDeleteMark(pMark, rStt, rEnd, pSttIdx, pEndIdx, bIsPosInRange, bIsOtherPosInRange);
1079 
1080  if ( bIsPosInRange
1081  && ( bIsOtherPosInRange
1082  || !pMark->IsExpanded() ) )
1083  {
1084  if ( bDeleteMark )
1085  {
1086  if ( pSaveBkmk )
1087  {
1088  pSaveBkmk->push_back( SaveBookmark( *pMark, rStt, pSttIdx ) );
1089  }
1090  vMarksToDelete.emplace_back(ppMark);
1091  }
1092  else
1093  {
1094  bMarksSkipDeletion = true;
1095  }
1096  }
1097  else if ( bIsPosInRange != bIsOtherPosInRange )
1098  {
1099  // the bookmark is partially in the range
1100  // move position of that is in the range out of it
1101 
1102  std::unique_ptr< SwPosition > pNewPos;
1103  {
1104  if ( pEndIdx != nullptr )
1105  {
1106  pNewPos = std::make_unique< SwPosition >( rEnd, *pEndIdx );
1107  }
1108  else
1109  {
1110  pNewPos =
1111  lcl_FindExpelPosition( rStt, rEnd, bIsPosInRange ? pMark->GetOtherMarkPos() : pMark->GetMarkPos() );
1112  }
1113  }
1114 
1115  bool bMoveMark = true;
1116  {
1117  switch ( IDocumentMarkAccess::GetType( *pMark ) )
1118  {
1121  // no move of cross-reference bookmarks, if move occurs inside a certain node
1122  bMoveMark = pMark->GetMarkPos().nNode != pNewPos->nNode;
1123  break;
1125  // no move of annotation marks, if method is called to collect deleted marks
1126  bMoveMark = pSaveBkmk == nullptr;
1127  break;
1128  default:
1129  bMoveMark = true;
1130  break;
1131  }
1132  }
1133  if ( bMoveMark )
1134  {
1135  if ( bIsPosInRange )
1136  pMark->SetMarkPos(*pNewPos);
1137  else
1138  pMark->SetOtherMarkPos(*pNewPos);
1139  bMarksMoved = true;
1140 
1141  // illegal selection? collapse the mark and restore sorting later
1142  bIsSortingNeeded |= lcl_FixCorrectedMark( bIsPosInRange, bIsOtherPosInRange, pMark );
1143  }
1144  }
1145  }
1146 
1147  {
1148  // fdo#61016 delay the deletion of the fieldmark characters
1149  // to prevent that from deleting the marks on that position
1150  // which would invalidate the iterators in vMarksToDelete
1151  std::vector< std::unique_ptr<ILazyDeleter> > vDelay;
1152  vDelay.reserve(vMarksToDelete.size());
1153 
1154  // If needed, sort mark containers containing subsets of the marks
1155  // in order to assure sorting. The sorting is critical for the
1156  // deletion of a mark as it is searched in these container for
1157  // deletion.
1158  if ( !vMarksToDelete.empty() && bMarksMoved )
1159  {
1160  sortSubsetMarks();
1161  }
1162  // we just remembered the iterators to delete, so we do not need to search
1163  // for the shared_ptr<> (the entry in m_vAllMarks) again
1164  // reverse iteration, since erasing an entry invalidates iterators
1165  // behind it (the iterators in vMarksToDelete are sorted)
1166  for ( std::vector< const_iterator_t >::reverse_iterator pppMark = vMarksToDelete.rbegin();
1167  pppMark != vMarksToDelete.rend();
1168  ++pppMark )
1169  {
1170  vDelay.push_back(deleteMark(*pppMark));
1171  }
1172  } // scope to kill vDelay
1173 
1174  // also need to sort if both marks were moved and not-deleted because
1175  // the not-deleted marks could be in wrong order vs. the moved ones
1176  if (bIsSortingNeeded || (bMarksMoved && bMarksSkipDeletion))
1177  {
1178  sortMarks();
1179  }
1180 
1181  SAL_INFO("sw.core", "deleteMarks");
1182  lcl_DebugMarks(m_vAllMarks);
1183  }
1184 
1185  namespace {
1186 
1187  struct LazyFieldmarkDeleter : public IDocumentMarkAccess::ILazyDeleter
1188  {
1189  std::unique_ptr<Fieldmark> m_pFieldmark;
1191  LazyFieldmarkDeleter(Fieldmark* pMark, SwDoc *const pDoc)
1192  : m_pFieldmark(pMark), m_pDoc(pDoc)
1193  {
1194  assert(m_pFieldmark);
1195  }
1196  virtual ~LazyFieldmarkDeleter() override
1197  {
1198  // note: because of the call chain from SwUndoDelete, the field
1199  // command *cannot* be deleted here as it would create a separate
1200  // SwUndoDelete that's interleaved with the SwHistory of the outer
1201  // one - only delete the CH_TXT_ATR_FIELD*!
1202  m_pFieldmark->ReleaseDoc(m_pDoc);
1203  }
1204  };
1205 
1206  }
1207 
1208  std::unique_ptr<IDocumentMarkAccess::ILazyDeleter>
1210  {
1211  std::unique_ptr<ILazyDeleter> ret;
1212  if (ppMark.get() == m_vAllMarks.end())
1213  return ret;
1214  IMark* pMark = *ppMark;
1215 
1216  switch(IDocumentMarkAccess::GetType(*pMark))
1217  {
1221  {
1222  auto const ppBookmark = lcl_FindMark(m_vBookmarks, *ppMark.get());
1223  if ( ppBookmark != m_vBookmarks.end() )
1224  {
1225  m_vBookmarks.erase(ppBookmark);
1226  }
1227  else
1228  {
1229  assert(false &&
1230  "<MarkManager::deleteMark(..)> - Bookmark not found in Bookmark container.");
1231  }
1232  }
1233  break;
1234 
1239  {
1240  auto const ppFieldmark = lcl_FindMark(m_vFieldmarks, *ppMark.get());
1241  if ( ppFieldmark != m_vFieldmarks.end() )
1242  {
1243  if(m_pLastActiveFieldmark == *ppFieldmark)
1245 
1246  m_vFieldmarks.erase(ppFieldmark);
1247  ret.reset(new LazyFieldmarkDeleter(dynamic_cast<Fieldmark*>(pMark), m_pDoc));
1248  }
1249  else
1250  {
1251  assert(false &&
1252  "<MarkManager::deleteMark(..)> - Fieldmark not found in Fieldmark container.");
1253  }
1254  }
1255  break;
1256 
1258  {
1259  auto const ppAnnotationMark = lcl_FindMark(m_vAnnotationMarks, *ppMark.get());
1260  assert(ppAnnotationMark != m_vAnnotationMarks.end() &&
1261  "<MarkManager::deleteMark(..)> - Annotation Mark not found in Annotation Mark container.");
1262  m_vAnnotationMarks.erase(ppAnnotationMark);
1263  }
1264  break;
1265 
1269  // no special marks container
1270  break;
1271  }
1272  DdeBookmark* const pDdeBookmark = dynamic_cast<DdeBookmark*>(pMark);
1273  if (pDdeBookmark)
1274  pDdeBookmark->DeregisterFromDoc(m_pDoc);
1275  //Effective STL Item 27, get a non-const iterator aI at the same
1276  //position as const iterator ppMark was
1277  auto aI = m_vAllMarks.begin();
1278  std::advance(aI, std::distance<container_t::const_iterator>(aI, ppMark.get()));
1279 
1280  m_vAllMarks.erase(aI);
1281  // If we don't have a lazy deleter
1282  if (!ret)
1283  // delete after we remove from the list, because the destructor can
1284  // recursively call into this method.
1285  delete pMark;
1286  return ret;
1287  }
1288 
1289  void MarkManager::deleteMark(const IMark* const pMark)
1290  {
1291  assert(pMark->GetMarkPos().GetDoc() == m_pDoc &&
1292  "<MarkManager::deleteMark(..)>"
1293  " - Mark is not in my doc.");
1294  // finds the last Mark that is starting before pMark
1295  // (pMarkLow < pMark)
1296  auto [it, endIt] = equal_range(
1297  m_vAllMarks.begin(),
1298  m_vAllMarks.end(),
1299  pMark->GetMarkStart(),
1300  CompareIMarkStartsBefore());
1301  for ( ; it != endIt; ++it)
1302  if (*it == pMark)
1303  {
1304  deleteMark(iterator(it));
1305  break;
1306  }
1307  }
1308 
1310  {
1312  m_vFieldmarks.clear();
1313  m_vBookmarks.clear();
1314  m_vAnnotationMarks.clear();
1315  for (const auto & p : m_vAllMarks)
1316  delete p;
1317  m_vAllMarks.clear();
1318  }
1319 
1321  {
1322  auto const ret = lcl_FindMarkByName(rName, m_vAllMarks.begin(), m_vAllMarks.end());
1323  return IDocumentMarkAccess::iterator(ret);
1324  }
1325 
1327  {
1328  auto const ret = lcl_FindMarkByName(rName, m_vBookmarks.begin(), m_vBookmarks.end());
1329  return IDocumentMarkAccess::iterator(ret);
1330  }
1331 
1333  { return m_vAllMarks.begin(); }
1334 
1336  { return m_vAllMarks.end(); }
1337 
1339  { return m_vAllMarks.size(); }
1340 
1342  { return m_vBookmarks.begin(); }
1343 
1345  { return m_vBookmarks.end(); }
1346 
1348  { return m_vBookmarks.size(); }
1349 
1350  // finds the first that is starting after
1352  {
1353  return std::upper_bound(
1354  m_vBookmarks.begin(),
1355  m_vBookmarks.end(),
1356  rPos,
1357  CompareIMarkStartsAfter());
1358  }
1359 
1361  {
1362  auto const pFieldmark = find_if(
1363  m_vFieldmarks.begin(),
1364  m_vFieldmarks.end(),
1365  [&rPos] (::sw::mark::MarkBase const*const pMark) {
1366  return pMark->GetMarkStart() == rPos
1367  // end position includes the CH_TXT_ATR_FIELDEND
1368  || (pMark->GetMarkEnd().nContent.GetIndex() == rPos.nContent.GetIndex() + 1
1369  && pMark->GetMarkEnd().nNode == rPos.nNode);
1370  } );
1371  return (pFieldmark == m_vFieldmarks.end())
1372  ? nullptr
1373  : dynamic_cast<IFieldmark*>(*pFieldmark);
1374  }
1375 
1377  {
1378  auto itFieldmark = find_if(
1379  m_vFieldmarks.begin(),
1380  m_vFieldmarks.end(),
1381  [&rPos] (const ::sw::mark::MarkBase *const pMark) { return pMark->IsCoveringPosition(rPos); } );
1382  if (itFieldmark == m_vFieldmarks.end())
1383  return nullptr;
1384  auto pFieldmark(*itFieldmark);
1385  for ( ; itFieldmark != m_vFieldmarks.end()
1386  && (**itFieldmark).IsCoveringPosition(rPos); ++itFieldmark)
1387  { // find the innermost fieldmark
1388  if (pFieldmark->GetMarkStart() < (**itFieldmark).GetMarkStart()
1389  || (**itFieldmark).GetMarkEnd() < pFieldmark->GetMarkEnd())
1390  {
1391  pFieldmark = *itFieldmark;
1392  }
1393  }
1394  return dynamic_cast<IFieldmark*>(pFieldmark);
1395  }
1396 
1398  {
1399  auto const pFieldmark = dynamic_cast<Fieldmark*>(getFieldmarkAt(rPos));
1400  if (!pFieldmark)
1401  return;
1402 
1403  deleteMark(lcl_FindMark(m_vAllMarks, pFieldmark));
1404  }
1405 
1407  {
1408  bool bActualChange = false;
1409  if(rNewType == ODF_FORMDROPDOWN)
1410  {
1411  if (!dynamic_cast<::sw::mark::DropDownFieldmark*>(pFieldmark))
1412  bActualChange = true;
1413  if (!dynamic_cast<::sw::mark::CheckboxFieldmark*>(pFieldmark)) // only allowed converting between checkbox <-> dropdown
1414  return nullptr;
1415  }
1416  else if(rNewType == ODF_FORMCHECKBOX)
1417  {
1418  if (!dynamic_cast<::sw::mark::CheckboxFieldmark*>(pFieldmark))
1419  bActualChange = true;
1420  if (!dynamic_cast<::sw::mark::DropDownFieldmark*>(pFieldmark)) // only allowed converting between checkbox <-> dropdown
1421  return nullptr;
1422  }
1423  else if(rNewType == ODF_FORMDATE)
1424  {
1425  if (!dynamic_cast<::sw::mark::DateFieldmark*>(pFieldmark))
1426  bActualChange = true;
1427  if (!dynamic_cast<::sw::mark::TextFieldmark*>(pFieldmark)) // only allowed converting between date field <-> text field
1428  return nullptr;
1429  }
1430 
1431  if (!bActualChange)
1432  return nullptr;
1433 
1434  // Store attributes needed to create the new fieldmark
1435  OUString sName = pFieldmark->GetName();
1436  SwPaM aPaM(pFieldmark->GetMarkPos());
1437 
1438  // Remove the old fieldmark and create a new one with the new type
1439  if(aPaM.GetPoint()->nContent > 0 && (rNewType == ODF_FORMDROPDOWN || rNewType == ODF_FORMCHECKBOX))
1440  {
1441  --aPaM.GetPoint()->nContent;
1442  SwPosition aNewPos (aPaM.GetPoint()->nNode, aPaM.GetPoint()->nContent);
1443  deleteFieldmarkAt(aNewPos);
1444  return makeNoTextFieldBookmark(aPaM, sName, rNewType);
1445  }
1446  else if(rNewType == ODF_FORMDATE)
1447  {
1448  SwPosition aPos (aPaM.GetPoint()->nNode, aPaM.GetPoint()->nContent);
1449  SwPaM aNewPaM(pFieldmark->GetMarkStart(), pFieldmark->GetMarkEnd());
1450  deleteFieldmarkAt(aPos);
1451  // HACK: hard-code the separator position here at the start because
1452  // writerfilter put it in the wrong place (at the end) on attach()
1453  SwPosition const sepPos(*aNewPaM.Start());
1454  return makeFieldBookmark(aNewPaM, sName, rNewType, &sepPos);
1455  }
1456  return nullptr;
1457  }
1458 
1460  {
1461  SwView* pSwView = dynamic_cast<SwView *>(rCursorShell.GetSfxViewShell());
1462  if(!pSwView)
1463  return;
1464 
1465  SwEditWin& rEditWin = pSwView->GetEditWin();
1466  SwPosition aPos(*rCursorShell.GetCursor()->GetPoint());
1467  IFieldmark* pFieldBM = getFieldmarkFor(aPos);
1468  FieldmarkWithDropDownButton* pNewActiveFieldmark = nullptr;
1469  if ((!pFieldBM || (pFieldBM->GetFieldname() != ODF_FORMDROPDOWN && pFieldBM->GetFieldname() != ODF_FORMDATE))
1470  && aPos.nContent.GetIndex() > 0 )
1471  {
1472  --aPos.nContent;
1473  pFieldBM = getFieldmarkFor(aPos);
1474  }
1475 
1476  if ( pFieldBM && (pFieldBM->GetFieldname() == ODF_FORMDROPDOWN ||
1477  pFieldBM->GetFieldname() == ODF_FORMDATE))
1478  {
1479  if (m_pLastActiveFieldmark != pFieldBM)
1480  {
1481  FieldmarkWithDropDownButton& rFormField = dynamic_cast<FieldmarkWithDropDownButton&>(*pFieldBM);
1482  pNewActiveFieldmark = &rFormField;
1483  }
1484  else
1485  {
1486  pNewActiveFieldmark = m_pLastActiveFieldmark;
1487  }
1488  }
1489 
1490  if(pNewActiveFieldmark != m_pLastActiveFieldmark)
1491  {
1493  m_pLastActiveFieldmark = pNewActiveFieldmark;
1494  if(pNewActiveFieldmark)
1495  pNewActiveFieldmark->ShowButton(&rEditWin);
1496  }
1497  }
1498 
1500  {
1503 
1504  m_pLastActiveFieldmark = nullptr;
1505  }
1506 
1508  {
1509  IFieldmark *pMark = getFieldmarkAt(rPos);
1510  if (!pMark || pMark->GetFieldname() != ODF_FORMDROPDOWN)
1511  return nullptr;
1512  return pMark;
1513  }
1514 
1515  std::vector<IFieldmark*> MarkManager::getDropDownsFor(const SwPaM &rPaM) const
1516  {
1517  std::vector<IFieldmark*> aRet;
1518 
1519  for (auto aI = m_vFieldmarks.begin(),
1520  aEnd = m_vFieldmarks.end(); aI != aEnd; ++aI)
1521  {
1522  ::sw::mark::IMark* pI = *aI;
1523  const SwPosition &rStart = pI->GetMarkPos();
1524  if (!rPaM.ContainsPosition(rStart))
1525  continue;
1526 
1527  IFieldmark *pMark = dynamic_cast<IFieldmark*>(pI);
1528  if (!pMark || pMark->GetFieldname() != ODF_FORMDROPDOWN)
1529  continue;
1530 
1531  aRet.push_back(pMark);
1532  }
1533 
1534  return aRet;
1535  }
1536 
1538  { return dynamic_cast<IFieldmark*>(lcl_getMarkAfter(m_vFieldmarks, rPos)); }
1539 
1541  { return dynamic_cast<IFieldmark*>(lcl_getMarkBefore(m_vFieldmarks, rPos)); }
1542 
1544  {
1545  return m_vAnnotationMarks.begin();
1546  }
1547 
1549  {
1550  return m_vAnnotationMarks.end();
1551  }
1552 
1554  {
1555  return m_vAnnotationMarks.size();
1556  }
1557 
1559  {
1560  auto const ret = lcl_FindMarkByName( rName, m_vAnnotationMarks.begin(), m_vAnnotationMarks.end() );
1561  return IDocumentMarkAccess::iterator(ret);
1562  }
1563 
1565  {
1566  auto const pAnnotationMark = find_if(
1567  m_vAnnotationMarks.begin(),
1568  m_vAnnotationMarks.end(),
1569  [&rPos] (const ::sw::mark::MarkBase *const pMark) { return pMark->IsCoveringPosition(rPos); } );
1570  if (pAnnotationMark == m_vAnnotationMarks.end())
1571  return nullptr;
1572  return *pAnnotationMark;
1573  }
1574 
1575  // finds the first that is starting after
1577  {
1578  return std::upper_bound(
1579  m_vAnnotationMarks.begin(),
1580  m_vAnnotationMarks.end(),
1581  rPos,
1582  CompareIMarkStartsAfter());
1583  }
1584 
1585  OUString MarkManager::getUniqueMarkName(const OUString& rName) const
1586  {
1587  OSL_ENSURE(rName.getLength(),
1588  "<MarkManager::getUniqueMarkName(..)> - a name should be proposed");
1589  if( m_pDoc->IsInMailMerge())
1590  {
1591  OUString newName = rName + "MailMergeMark"
1592  + OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM )), RTL_TEXTENCODING_ASCII_US )
1593  + OUString::number( m_vAllMarks.size() + 1 );
1594  return newName;
1595  }
1596 
1597  if (lcl_FindMarkByName(rName, m_vAllMarks.begin(), m_vAllMarks.end()) == m_vAllMarks.end())
1598  {
1599  return rName;
1600  }
1601  OUString sTmp;
1602 
1603  // try the name "<rName>XXX" (where XXX is a number starting from 1) unless there is
1604  // an unused name. Due to performance-reasons (especially in mailmerge-scenarios) there
1605  // is a map m_aMarkBasenameMapUniqueOffset which holds the next possible offset (XXX) for
1606  // rName (so there is no need to test for nCnt-values smaller than the offset).
1607  sal_Int32 nCnt = 1;
1608  MarkBasenameMapUniqueOffset_t::const_iterator aIter = m_aMarkBasenameMapUniqueOffset.find(rName);
1609  if(aIter != m_aMarkBasenameMapUniqueOffset.end()) nCnt = aIter->second;
1610  while(nCnt < SAL_MAX_INT32)
1611  {
1612  sTmp = rName + OUString::number(nCnt);
1613  nCnt++;
1614  if (lcl_FindMarkByName(sTmp, m_vAllMarks.begin(), m_vAllMarks.end()) == m_vAllMarks.end())
1615  {
1616  break;
1617  }
1618  }
1619  m_aMarkBasenameMapUniqueOffset[rName] = nCnt;
1620 
1621  return sTmp;
1622  }
1623 
1625  {
1626  const_cast< MarkManager* >(this)->sortMarks();
1627  }
1628 
1630  {
1631  sort(m_vBookmarks.begin(), m_vBookmarks.end(), &lcl_MarkOrderingByStart);
1632  sort(m_vFieldmarks.begin(), m_vFieldmarks.end(), &lcl_MarkOrderingByStart);
1633  sort(m_vAnnotationMarks.begin(), m_vAnnotationMarks.end(), &lcl_MarkOrderingByStart);
1634  }
1635 
1637  {
1638  sort(m_vAllMarks.begin(), m_vAllMarks.end(), &lcl_MarkOrderingByStart);
1639  sortSubsetMarks();
1640  }
1641 
1643 {
1644  struct
1645  {
1646  const char* pName;
1647  const container_t* pContainer;
1648  } aContainers[] =
1649  {
1650  // UNO marks are only part of all marks.
1651  {"allmarks", &m_vAllMarks},
1652  {"bookmarks", &m_vBookmarks},
1653  {"fieldmarks", &m_vFieldmarks},
1654  {"annotationmarks", &m_vAnnotationMarks}
1655  };
1656 
1657  xmlTextWriterStartElement(pWriter, BAD_CAST("MarkManager"));
1658  for (const auto & rContainer : aContainers)
1659  {
1660  if (!rContainer.pContainer->empty())
1661  {
1662  xmlTextWriterStartElement(pWriter, BAD_CAST(rContainer.pName));
1663  for (auto it = rContainer.pContainer->begin(); it != rContainer.pContainer->end(); ++it)
1664  (*it)->dumpAsXml(pWriter);
1665  xmlTextWriterEndElement(pWriter);
1666  }
1667  }
1668  xmlTextWriterEndElement(pWriter);
1669 }
1670 
1671 } // namespace ::sw::mark
1672 
1673 namespace
1674 {
1675  bool lcl_Greater( const SwPosition& rPos, const SwNodeIndex& rNdIdx, const SwIndex* pIdx )
1676  {
1677  return rPos.nNode > rNdIdx || ( pIdx && rPos.nNode == rNdIdx && rPos.nContent > pIdx->GetIndex() );
1678  }
1679 }
1680 
1681 // IDocumentMarkAccess for SwDoc
1683  { return static_cast< IDocumentMarkAccess* >(mpMarkManager.get()); }
1684 
1686  { return static_cast< IDocumentMarkAccess* >(mpMarkManager.get()); }
1687 
1688 SaveBookmark::SaveBookmark(
1689  const IMark& rBkmk,
1690  const SwNodeIndex & rMvPos,
1691  const SwIndex* pIdx)
1692  : m_aName(rBkmk.GetName())
1693  , m_bHidden(false)
1694  , m_aCode()
1695  , m_eOrigBkmType(IDocumentMarkAccess::GetType(rBkmk))
1696 {
1697  const IBookmark* const pBookmark = dynamic_cast< const IBookmark* >(&rBkmk);
1698  if(pBookmark)
1699  {
1700  m_aShortName = pBookmark->GetShortName();
1701  m_aCode = pBookmark->GetKeyCode();
1702  m_bHidden = pBookmark->IsHidden();
1703  m_aHideCondition = pBookmark->GetHideCondition();
1704 
1705  ::sfx2::Metadatable const*const pMetadatable(
1706  dynamic_cast< ::sfx2::Metadatable const* >(pBookmark));
1707  if (pMetadatable)
1708  {
1709  m_pMetadataUndo = pMetadatable->CreateUndo();
1710  }
1711  }
1712  m_nNode1 = rBkmk.GetMarkPos().nNode.GetIndex();
1714 
1715  m_nNode1 -= rMvPos.GetIndex();
1716  if(pIdx && !m_nNode1)
1717  m_nContent1 -= pIdx->GetIndex();
1718 
1719  if(rBkmk.IsExpanded())
1720  {
1721  m_nNode2 = rBkmk.GetOtherMarkPos().nNode.GetIndex();
1723 
1724  m_nNode2 -= rMvPos.GetIndex();
1725  if(pIdx && !m_nNode2)
1726  m_nContent2 -= pIdx->GetIndex();
1727  }
1728  else
1729  {
1730  m_nNode2 = ULONG_MAX;
1731  m_nContent2 = -1;
1732  }
1733 }
1734 
1736  SwDoc* pDoc,
1737  const SwNodeIndex& rNewPos,
1738  const SwIndex* pIdx)
1739 {
1740  SwPaM aPam(rNewPos.GetNode());
1741  if(pIdx)
1742  aPam.GetPoint()->nContent = *pIdx;
1743 
1744  if(ULONG_MAX != m_nNode2)
1745  {
1746  aPam.SetMark();
1747 
1748  aPam.GetMark()->nNode += m_nNode2;
1749  if(pIdx && !m_nNode2)
1750  aPam.GetMark()->nContent += m_nContent2;
1751  else
1752  aPam.GetMark()->nContent.Assign(aPam.GetContentNode(false), m_nContent2);
1753  }
1754 
1755  aPam.GetPoint()->nNode += m_nNode1;
1756 
1757  if(pIdx && !m_nNode1)
1758  aPam.GetPoint()->nContent += m_nContent1;
1759  else
1760  aPam.GetPoint()->nContent.Assign(aPam.GetContentNode(), m_nContent1);
1761 
1762  if(!(!aPam.HasMark()
1763  || CheckNodesRange(aPam.GetPoint()->nNode, aPam.GetMark()->nNode, true)))
1764  return;
1765 
1766  ::sw::mark::IBookmark* const pBookmark = dynamic_cast<::sw::mark::IBookmark*>(
1767  pDoc->getIDocumentMarkAccess()->makeMark(aPam, m_aName,
1769  if(!pBookmark)
1770  return;
1771 
1772  pBookmark->SetKeyCode(m_aCode);
1773  pBookmark->SetShortName(m_aShortName);
1774  pBookmark->Hide(m_bHidden);
1775  pBookmark->SetHideCondition(m_aHideCondition);
1776 
1777  if (m_pMetadataUndo)
1778  {
1779  ::sfx2::Metadatable * const pMeta(
1780  dynamic_cast< ::sfx2::Metadatable* >(pBookmark));
1781  assert(pMeta && "metadata undo, but not metadatable?");
1782  if (pMeta)
1783  {
1785  }
1786  }
1787 }
1788 
1789 // DelBookmarks
1790 
1792  const SwNodeIndex& rStt,
1793  const SwNodeIndex& rEnd,
1794  std::vector<SaveBookmark> * pSaveBkmk,
1795  const SwIndex* pSttIdx,
1796  const SwIndex* pEndIdx)
1797 {
1798  // illegal range ??
1799  if(rStt.GetIndex() > rEnd.GetIndex()
1800  || (rStt == rEnd && (!pSttIdx || !pEndIdx || pSttIdx->GetIndex() >= pEndIdx->GetIndex())))
1801  return;
1802  SwDoc* const pDoc = rStt.GetNode().GetDoc();
1803 
1804  pDoc->getIDocumentMarkAccess()->deleteMarks(rStt, rEnd, pSaveBkmk, pSttIdx, pEndIdx);
1805 
1806  // Copy all Redlines which are in the move area into an array
1807  // which holds all position information as offset.
1808  // Assignment happens after moving.
1810  for(SwRangeRedline* pRedl : rTable)
1811  {
1812  // Is at position?
1813  SwPosition *const pRStt = pRedl->Start();
1814  SwPosition *const pREnd = pRedl->End();
1815 
1816  if( lcl_Greater( *pRStt, rStt, pSttIdx ) && lcl_Lower( *pRStt, rEnd, pEndIdx ))
1817  {
1818  pRStt->nNode = rEnd;
1819  if( pEndIdx )
1820  pRStt->nContent = *pEndIdx;
1821  else
1822  {
1823  bool bStt = true;
1824  SwContentNode* pCNd = pRStt->nNode.GetNode().GetContentNode();
1825  if( !pCNd )
1826  pCNd = pDoc->GetNodes().GoNext( &pRStt->nNode );
1827  if (!pCNd)
1828  {
1829  bStt = false;
1830  pRStt->nNode = rStt;
1831  pCNd = SwNodes::GoPrevious( &pRStt->nNode );
1832  if( !pCNd )
1833  {
1834  pRStt->nNode = pREnd->nNode;
1835  pCNd = pRStt->nNode.GetNode().GetContentNode();
1836  }
1837  }
1838  pRStt->nContent.Assign( pCNd, bStt ? 0 : pCNd->Len() );
1839  }
1840  }
1841  if( lcl_Greater( *pREnd, rStt, pSttIdx ) && lcl_Lower( *pREnd, rEnd, pEndIdx ))
1842  {
1843  pREnd->nNode = rStt;
1844  if( pSttIdx )
1845  pREnd->nContent = *pSttIdx;
1846  else
1847  {
1848  bool bStt = false;
1849  SwContentNode* pCNd = pREnd->nNode.GetNode().GetContentNode();
1850  if( !pCNd )
1851  pCNd = SwNodes::GoPrevious( &pREnd->nNode );
1852  if( !pCNd )
1853  {
1854  bStt = true;
1855  pREnd->nNode = rEnd;
1856  pCNd = pDoc->GetNodes().GoNext( &pREnd->nNode );
1857  if( !pCNd )
1858  {
1859  pREnd->nNode = pRStt->nNode;
1860  pCNd = pREnd->nNode.GetNode().GetContentNode();
1861  }
1862  }
1863  pREnd->nContent.Assign( pCNd, bStt ? 0 : pCNd->Len() );
1864  }
1865  }
1866  }
1867 }
1868 
1869 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sw::mark::IMark * getAnnotationMarkFor(const SwPosition &rPos) const override
Definition: docbm.cxx:1564
virtual sal_Int32 Len() const
Definition: node.cxx:1223
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:1576
virtual sal_Int32 getAllMarksCount() const override
returns the number of marks.
Definition: docbm.cxx:1338
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:1791
sw::mark::FieldmarkWithDropDownButton * m_pLastActiveFieldmark
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:189
OUString m_aName
virtual const_iterator_t findFirstBookmarkStartsAfter(const SwPosition &rPos) const override
Finds the first mark that is starting after.
Definition: docbm.cxx:1351
sal_uLong m_nNode2
Definition: mvsave.hxx:66
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:275
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:1585
sal_Int64 n
Provides access to the marks of a document.
Definition: doc.hxx:184
#define ODF_FORMCHECKBOX
void SetInDoc(SwDoc *pDoc, const SwNodeIndex &, const SwIndex *pIdx=nullptr)
Definition: docbm.cxx:1735
virtual const SwPosition & GetMarkPos() const =0
SwPosition FindFieldSep(IFieldmark const &rMark)
return position of the CH_TXT_ATR_FIELDSEP for rMark
Definition: bookmrk.cxx:57
virtual ::sw::mark::IFieldmark * getFieldmarkAfter(const SwPosition &rPos) const override
Definition: docbm.cxx:1537
static SwContentNode * GoPrevious(SwNodeIndex *)
Definition: nodes.cxx:1300
SwNode & GetNode() const
Definition: ndindex.hxx:119
SwEditWin & GetEditWin()
Definition: view.hxx:401
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:1332
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1682
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:1543
SfxViewShell * GetSfxViewShell() const
Definition: viewsh.hxx:442
virtual ::sw::mark::IFieldmark * getFieldmarkFor(const SwPosition &rPos) const override
Definition: docbm.cxx:1376
Fieldmark with a drop down button (e.g. this button opens the date picker for a date field) ...
Definition: bookmrk.hxx:266
virtual sw::mark::IFieldmark * makeNoTextFieldBookmark(const SwPaM &rPaM, const OUString &rName, const OUString &rType) override
Definition: docbm.cxx:741
virtual bool IsExpanded() const override
Definition: bookmrk.hxx:74
SwDoc * m_pDoc
Definition: docbm.cxx:1190
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:1344
virtual const OUString & GetHideCondition() const =0
virtual const OUString & GetName() const override
Definition: bookmrk.hxx:49
virtual void clearAllMarks() override
Clear (deletes) all marks.
Definition: docbm.cxx:1309
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:178
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
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:1360
sal_Int32 m_nContent1
Definition: mvsave.hxx:67
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.
bool IsStartNode() const
Definition: node.hxx:624
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: docbm.cxx:1642
sal_uLong m_nNode1
Definition: mvsave.hxx:65
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:256
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:790
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:1054
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
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
struct _xmlTextWriter * xmlTextWriterPtr
virtual void Hide(bool hide)=0
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:1553
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.
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:131
virtual const_iterator_t getAnnotationMarksEnd() const override
Definition: docbm.cxx:1548
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:206
std::vector< sw::mark::MarkBase * > container_t
virtual void assureSortedMarkContainers() const override
Definition: docbm.cxx:1624
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:1320
SwDoc * GetDoc()
Definition: node.hxx:702
virtual std::unique_ptr< ILazyDeleter > deleteMark(const const_iterator_t &ppMark) override
Deletes a mark.
Definition: docbm.cxx:1209
virtual const OUString & GetShortName() const =0
virtual auto InvalidateFrames() -> void
Definition: bookmrk.cxx:352
virtual bool renameMark(::sw::mark::IMark *io_pMark, const OUString &rNewName) override
Renames an existing Mark, if possible.
Definition: docbm.cxx:838
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:33
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:69
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:1189
virtual void SetHideCondition(const OUString &)=0
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:1335
virtual const_iterator_t findAnnotationMark(const OUString &rName) const override
Definition: docbm.cxx:1558
const SwPosition * Start() const
Definition: pam.hxx:212
void SetMark(const sw::mark::IMark *pMark)
Definition: index.cxx:222
static bool isDeleteMark(::sw::mark::MarkBase const *const pMark, SwNodeIndex const &rStt, SwNodeIndex const &rEnd, SwIndex const *const pSttIdx, SwIndex const *const pEndIdx, bool &rbIsPosInRange, bool &rbIsOtherPosInRange)
Definition: docbm.cxx:962
virtual sw::mark::IMark * makeAnnotationMark(const SwPaM &rPaM, const OUString &rName) override
Definition: docbm.cxx:803
virtual SwPosition & GetOtherMarkPos() const override
Definition: bookmrk.hxx:51
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:334
virtual sal_Int32 getBookmarksCount() const override
returns the number of IBookmarks.
Definition: docbm.cxx:1347
virtual bool isBookmarkDeleted(SwPaM const &rPaM) const override
check if the selection would delete a BOOKMARK
Definition: docbm.cxx:1032
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:867
virtual void NotifyCursorUpdate(const SwCursorShell &rCursorShell) override
Definition: docbm.cxx:1459
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:701
#define SAL_INFO(area, stream)
sal_Int32 GetIndex() const
Definition: index.hxx:91
OString DateTimeToOString(const DateTime &rDateTime)
virtual SwPosition & GetMarkPos() const override
Definition: bookmrk.hxx:47
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:1326
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:913
IDocumentMarkAccess::MarkType m_eOrigBkmType
Definition: mvsave.hxx:64
virtual void SetMarkPos(const SwPosition &rNewPos)
Definition: bookmrk.cxx:280
void * p
iterator & operator+=(difference_type)
Definition: docbm.cxx:136
virtual ::sw::mark::IFieldmark * getFieldmarkBefore(const SwPosition &rPos) const override
Definition: docbm.cxx:1540
virtual ::sw::mark::IFieldmark * getDropDownFor(const SwPosition &rPos) const override
Definition: docbm.cxx:1507
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:1397
virtual std::vector< ::sw::mark::IFieldmark * > getDropDownsFor(const SwPaM &rPaM) const override
Definition: docbm.cxx:1515
#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:1406
#define SAL_WARN(area, stream)
virtual void ClearFieldActivation() override
Definition: docbm.cxx:1499
vcl::KeyCode m_aCode
Definition: mvsave.hxx:63
virtual void DeregisterFromDoc(SwDoc *const pDoc)
Definition: bookmrk.cxx:373
virtual const SwPosition & GetMarkStart() const =0
::sw::mark::IMark * operator*() const
Definition: docbm.cxx:91
sal_Int32 m_nContent2
Definition: mvsave.hxx:68
InsertMode
Definition: IMark.hxx:31
virtual void SetOtherMarkPos(const SwPosition &rNewPos)
Definition: bookmrk.cxx:286
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:1341
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:811
void RestoreMetadata(std::shared_ptr< MetadatableUndo > const &i_pUndo)
SwContentNode * GoNext(SwNodeIndex *) const
Definition: nodes.cxx:1283
virtual bool IsHidden() const =0
OUString m_aHideCondition
Definition: mvsave.hxx:62
Definition: view.hxx:144
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:844
#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