LibreOffice Module sw (master)  1
unoobj2.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 <sal/config.h>
21 
24 #include <o3tl/safeint.hxx>
25 #include <svl/listener.hxx>
26 #include <svx/svdobj.hxx>
27 #include <vcl/svapp.hxx>
28 
29 #include <anchoredobject.hxx>
30 #include <swtypes.hxx>
31 #include <hintids.hxx>
32 #include <IMark.hxx>
33 #include <frmfmt.hxx>
34 #include <doc.hxx>
35 #include <IDocumentUndoRedo.hxx>
37 #include <IDocumentMarkAccess.hxx>
38 #include <textboxhelper.hxx>
39 #include <ndtxt.hxx>
40 #include <unocrsr.hxx>
41 #include <swundo.hxx>
42 #include <rootfrm.hxx>
43 #include <ftnidx.hxx>
44 #include <pam.hxx>
45 #include <swtblfmt.hxx>
46 #include <docsh.hxx>
47 #include <pagedesc.hxx>
48 #include <cntfrm.hxx>
49 #include <unoparaframeenum.hxx>
50 #include <unofootnote.hxx>
51 #include <unotextbodyhf.hxx>
52 #include <unotextrange.hxx>
53 #include <unoparagraph.hxx>
54 #include <unomap.hxx>
55 #include <unoport.hxx>
56 #include <unocrsrhelper.hxx>
57 #include <unotbl.hxx>
58 #include <fmtanchr.hxx>
59 #include <flypos.hxx>
60 #include <txtftn.hxx>
61 #include <fmtftn.hxx>
62 #include <fmtcntnt.hxx>
63 #include <com/sun/star/text/XTextDocument.hpp>
64 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
65 #include <unoframe.hxx>
66 #include <fmthdft.hxx>
67 #include <fmtflcnt.hxx>
68 #include <vector>
69 #include <sortedobjs.hxx>
70 #include <frameformats.hxx>
71 #include <algorithm>
72 #include <iterator>
73 
74 using namespace ::com::sun::star;
75 
76 namespace sw {
77 
78 void DeepCopyPaM(SwPaM const & rSource, SwPaM & rTarget)
79 {
80  rTarget = rSource;
81 
82  if (rSource.GetNext() == &rSource)
83  return;
84 
85  SwPaM *pPam = const_cast<SwPaM*>(rSource.GetNext());
86  do
87  {
88  // create new PaM
89  SwPaM *const pNew = new SwPaM(*pPam, nullptr);
90  // insert into ring
91  pNew->MoveTo(&rTarget);
92  pPam = pPam->GetNext();
93  }
94  while (pPam != &rSource);
95 }
96 
97 } // namespace sw
98 
99 namespace {
100 
101 struct FrameClientSortListLess
102 {
103  bool operator() (FrameClientSortListEntry const& r1,
104  FrameClientSortListEntry const& r2) const
105  {
106  return (r1.nIndex < r2.nIndex)
107  || ((r1.nIndex == r2.nIndex) && (r1.nOrder < r2.nOrder));
108  }
109 };
110 
111  void lcl_CollectFrameAtNodeWithLayout(const SwContentFrame* pCFrame,
112  FrameClientSortList_t& rFrames,
113  const RndStdIds nAnchorType)
114  {
115  auto pObjs = pCFrame->GetDrawObjs();
116  if(!pObjs)
117  return;
118  for(const auto pAnchoredObj : *pObjs)
119  {
120  SwFrameFormat& rFormat = pAnchoredObj->GetFrameFormat();
121  // Filter out textboxes, which are not interesting at a UNO level.
123  continue;
124  if(rFormat.GetAnchor().GetAnchorId() == nAnchorType)
125  {
126  const auto nIdx =
128  const auto nOrder = rFormat.GetAnchor().GetOrder();
129  FrameClientSortListEntry entry(nIdx, nOrder, std::make_shared<sw::FrameClient>(&rFormat));
130  rFrames.push_back(entry);
131  }
132  }
133  }
134 }
135 
136 
137 void CollectFrameAtNode( const SwNodeIndex& rIdx,
138  FrameClientSortList_t& rFrames,
139  const bool bAtCharAnchoredObjs )
140 {
141  // _bAtCharAnchoredObjs:
142  // <true>: at-character anchored objects are collected
143  // <false>: at-paragraph anchored objects are collected
144 
145  // search all borders, images, and OLEs that are connected to the paragraph
146  SwDoc& rDoc = rIdx.GetNode().GetDoc();
147 
148  const auto nChkType = bAtCharAnchoredObjs ? RndStdIds::FLY_AT_CHAR : RndStdIds::FLY_AT_PARA;
149  const SwContentFrame* pCFrame;
150  const SwContentNode* pCNd;
152  nullptr != (pCNd = rIdx.GetNode().GetContentNode()) &&
153  nullptr != (pCFrame = pCNd->getLayoutFrame( rDoc.getIDocumentLayoutAccess().GetCurrentLayout())) )
154  {
155  lcl_CollectFrameAtNodeWithLayout(pCFrame, rFrames, nChkType);
156  }
157  else
158  {
159  const SwFrameFormats& rFormats = *rDoc.GetSpzFrameFormats();
160  const size_t nSize = rFormats.size();
161  for ( size_t i = 0; i < nSize; i++)
162  {
163  const SwFrameFormat* pFormat = rFormats[ i ];
164  const SwFormatAnchor& rAnchor = pFormat->GetAnchor();
165  const SwPosition* pAnchorPos;
166  if( rAnchor.GetAnchorId() == nChkType &&
167  nullptr != (pAnchorPos = rAnchor.GetContentAnchor()) &&
168  pAnchorPos->nNode == rIdx )
169  {
170 
171  // OD 2004-05-07 #i28701# - determine insert position for
172  // sorted <rFrameArr>
173  const sal_Int32 nIndex = pAnchorPos->nContent.GetIndex();
174  sal_uInt32 nOrder = rAnchor.GetOrder();
175 
176  FrameClientSortListEntry entry(nIndex, nOrder, std::make_shared<sw::FrameClient>(const_cast<SwFrameFormat*>(pFormat)));
177  rFrames.push_back(entry);
178  }
179  }
180  std::sort(rFrames.begin(), rFrames.end(), FrameClientSortListLess());
181  }
182 }
183 
185  : m_pDoc(pDoc)
186 {
188  if (pRootFrame)
189  {
190  pRootFrame->StartAllAction();
191  }
192 }
193 
194 UnoActionContext::~UnoActionContext() COVERITY_NOEXCEPT_FALSE
195 {
196  // Doc may already have been removed here
197  if (m_pDoc)
198  {
200  if (pRootFrame)
201  {
202  pRootFrame->EndAllAction();
203  }
204  }
205 }
206 
207 static void lcl_RemoveImpl(SwDoc *const pDoc)
208 {
209  assert(pDoc);
210  SwRootFrame *const pRootFrame = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
211  if (pRootFrame)
212  {
213  pRootFrame->UnoRemoveAllActions();
214  }
215 }
216 
218  : m_pDoc(pDoc)
219 {
221 }
222 
224 {
225  SwTableNode *const pTableNode = rCursor.GetNode().FindTableNode();
226  return (pTableNode && !pTableNode->GetTable().IsNewModel())
227  ? &rCursor.GetDoc()
228  : nullptr;
229 }
230 
232  : m_pDoc(lcl_IsNewStyleTable(rCursor))
233 {
234  // this insanity is only necessary for old-style tables
235  // because SwRootFrame::MakeTableCursors() creates the table cursor for these
236  if (m_pDoc)
237  {
239  }
240 }
241 
243 {
244  if (m_pDoc)
245  {
247  if (pRootFrame)
248  {
249  pRootFrame->UnoRestoreAllActions();
250  }
251  }
252 }
253 
255  const SfxItemSet& rSet,
256  const SetAttrMode nAttrMode, const bool bTableMode)
257 {
258  const SetAttrMode nFlags = nAttrMode | SetAttrMode::APICALL;
259  SwDoc& rDoc = rPam.GetDoc();
260  //StartEndAction
261  UnoActionContext aAction(&rDoc);
262  if (rPam.GetNext() != &rPam) // Ring of Cursors
263  {
265 
266  for(SwPaM& rCurrent : rPam.GetRingContainer())
267  {
268  if (rCurrent.HasMark() &&
269  ( bTableMode ||
270  (*rCurrent.GetPoint() != *rCurrent.GetMark()) ))
271  {
272  rDoc.getIDocumentContentOperations().InsertItemSet(rCurrent, rSet, nFlags);
273  }
274  }
275 
277  }
278  else
279  {
280  rDoc.getIDocumentContentOperations().InsertItemSet( rPam, rSet, nFlags );
281  }
282 
283  if( rSet.GetItemState( RES_PARATR_OUTLINELEVEL, false ) >= SfxItemState::DEFAULT )
284  {
285  SwTextNode * pTmpNode = rPam.GetNode().GetTextNode();
286  if ( pTmpNode )
287  {
288  rPam.GetDoc().GetNodes().UpdateOutlineNode( *pTmpNode );
289  }
290  }
291 }
292 
293 // #i63870#
294 // split third parameter <bCurrentAttrOnly> into new parameters <bOnlyTextAttr>
295 // and <bGetFromChrFormat> to get better control about resulting <SfxItemSet>
297  SfxItemSet & rSet, const bool bOnlyTextAttr, const bool bGetFromChrFormat)
298 {
299  static const sal_uLong nMaxLookup = 1000;
300  SfxItemSet aSet( *rSet.GetPool(), rSet.GetRanges() );
301  SfxItemSet *pSet = &rSet;
302  for(SwPaM& rCurrent : rPam.GetRingContainer())
303  {
304  SwPosition const & rStart( *rCurrent.Start() );
305  SwPosition const & rEnd( *rCurrent.End() );
306  const sal_uLong nSttNd = rStart.nNode.GetIndex();
307  const sal_uLong nEndNd = rEnd .nNode.GetIndex();
308 
309  if (nEndNd - nSttNd >= nMaxLookup)
310  {
311  rSet.ClearItem();
312  rSet.InvalidateAllItems();
313  return;// uno::Any();
314  }
315 
316  // the first node inserts the values into the get set
317  // all other nodes merge their values into the get set
318  for (sal_uLong n = nSttNd; n <= nEndNd; ++n)
319  {
320  SwNode *const pNd = rPam.GetDoc().GetNodes()[ n ];
321  switch (pNd->GetNodeType())
322  {
323  case SwNodeType::Text:
324  {
325  const sal_Int32 nStart = (n == nSttNd)
326  ? rStart.nContent.GetIndex() : 0;
327  const sal_Int32 nEnd = (n == nEndNd)
328  ? rEnd.nContent.GetIndex()
329  : pNd->GetTextNode()->GetText().getLength();
330  pNd->GetTextNode()->GetParaAttr(*pSet, nStart, nEnd, bOnlyTextAttr, bGetFromChrFormat);
331  }
332  break;
333 
334  case SwNodeType::Grf:
335  case SwNodeType::Ole:
336  static_cast<SwContentNode*>(pNd)->GetAttr( *pSet );
337  break;
338 
339  default:
340  continue; // skip this node
341  }
342 
343  if (pSet != &rSet)
344  {
345  rSet.MergeValues( aSet );
346  }
347  else
348  {
349  pSet = &aSet;
350  }
351 
352  if (aSet.Count())
353  {
354  aSet.ClearItem();
355  }
356  }
357  }
358 }
359 
360 namespace {
361 
362 struct SwXParagraphEnumerationImpl final : public SwXParagraphEnumeration
363 {
364  uno::Reference< text::XText > const m_xParentText;
365  const CursorType m_eCursorType;
369  SwStartNode const*const m_pOwnStartNode;
370  SwTable const*const m_pOwnTable;
371  const sal_uLong m_nEndIndex;
372  sal_Int32 m_nFirstParaStart;
373  sal_Int32 m_nLastParaEnd;
374  bool m_bFirstParagraph;
375  uno::Reference< text::XTextContent > m_xNextPara;
376  sw::UnoCursorPointer m_pCursor;
377 
378  SwXParagraphEnumerationImpl(
379  uno::Reference< text::XText > const& xParent,
380  const std::shared_ptr<SwUnoCursor>& pCursor,
381  const CursorType eType,
382  SwStartNode const*const pStartNode, SwTable const*const pTable)
383  : m_xParentText( xParent )
384  , m_eCursorType( eType )
385  // remember table and start node for later travelling
386  // (used in export of tables in tables)
387  , m_pOwnStartNode( pStartNode )
388  // for import of tables in tables we have to remember the actual
389  // table and start node of the current position in the enumeration.
390  , m_pOwnTable( pTable )
391  , m_nEndIndex( pCursor->End()->nNode.GetIndex() )
392  , m_nFirstParaStart( -1 )
393  , m_nLastParaEnd( -1 )
394  , m_bFirstParagraph( true )
395  , m_pCursor(pCursor)
396  {
397  OSL_ENSURE(m_xParentText.is(), "SwXParagraphEnumeration: no parent?");
398  assert( !((CursorType::SelectionInTable == eType)
399  || (CursorType::TableText == eType))
400  || (m_pOwnTable && m_pOwnStartNode));
401 
402  if ((CursorType::Selection == m_eCursorType) ||
403  (CursorType::SelectionInTable == m_eCursorType))
404  {
405  SwUnoCursor & rCursor = GetCursor();
406  rCursor.Normalize();
407  m_nFirstParaStart = rCursor.GetPoint()->nContent.GetIndex();
408  m_nLastParaEnd = rCursor.GetMark()->nContent.GetIndex();
409  rCursor.DeleteMark();
410  }
411  }
412 
413  virtual ~SwXParagraphEnumerationImpl() override
414  { m_pCursor.reset(nullptr); }
415  virtual void SAL_CALL release() noexcept override
416  {
417  SolarMutexGuard g;
418  OWeakObject::release();
419  }
420 
421  // XServiceInfo
422  virtual OUString SAL_CALL getImplementationName() override
423  { return "SwXParagraphEnumeration"; }
424  virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName) override
425  { return cppu::supportsService(this, rServiceName); };
426  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
427  { return {"com.sun.star.text.ParagraphEnumeration"}; };
428 
429  // XEnumeration
430  virtual sal_Bool SAL_CALL hasMoreElements() override;
431  virtual css::uno::Any SAL_CALL nextElement() override;
432 
433  SwUnoCursor& GetCursor()
434  { return *m_pCursor; }
438  uno::Reference< text::XTextContent > NextElement_Impl();
439 
444  bool IgnoreLastElement(SwUnoCursor& rCursor, bool bMovedFromTable);
445 };
446 
447 }
448 
450  uno::Reference< text::XText > const& xParent,
451  const std::shared_ptr<SwUnoCursor>& pCursor,
452  const CursorType eType,
453  SwTableBox const*const pTableBox)
454 {
455  SwStartNode const* pStartNode(nullptr);
456  SwTable const* pTable(nullptr);
457  assert((eType == CursorType::TableText) == (pTableBox != nullptr));
458  switch (eType)
459  {
461  {
462  pStartNode = pTableBox->GetSttNd();
463  pTable = & pStartNode->FindTableNode()->GetTable();
464  break;
465  }
467  {
468  SwTableNode const*const pTableNode(
469  pCursor->GetPoint()->nNode.GetNode().FindTableNode());
470  pStartNode = pTableNode;
471  pTable = & pTableNode->GetTable();
472  break;
473  }
474  default:
475  break;
476  }
477  return new SwXParagraphEnumerationImpl(xParent, pCursor, eType, pStartNode, pTable);
478 }
479 
480 sal_Bool SAL_CALL
481 SwXParagraphEnumerationImpl::hasMoreElements()
482 {
483  SolarMutexGuard aGuard;
484  return m_bFirstParagraph || m_xNextPara.is();
485 }
486 
488 static SwTableNode *
490  SwTableNode *const pTableNode, SwTable const*const pOwnTable)
491 {
492  // find top-most table in current context (section) level
493 
494  SwTableNode * pLast = pTableNode;
495  for (SwTableNode* pTmp = pLast;
496  pTmp != nullptr && &pTmp->GetTable() != pOwnTable; /* we must not go up higher than the own table! */
497  pTmp = pTmp->StartOfSectionNode()->FindTableNode() )
498  {
499  pLast = pTmp;
500  }
501  return pLast;
502 }
503 
504 static bool
506  SwUnoCursor const*const pUnoCursor, SwStartNode const*const pOwnStartNode)
507 {
508  // returns true if the cursor is in the section (or in a sub section!)
509  // represented by pOwnStartNode
510 
511  bool bRes = true;
512  if (pUnoCursor && pOwnStartNode)
513  {
514  const SwEndNode * pOwnEndNode = pOwnStartNode->EndOfSectionNode();
515  bRes = pOwnStartNode->GetIndex() <= pUnoCursor->Start()->nNode.GetIndex() &&
516  pUnoCursor->End()->nNode.GetIndex() <= pOwnEndNode->GetIndex();
517  }
518  return bRes;
519 }
520 
521 bool SwXParagraphEnumerationImpl::IgnoreLastElement(SwUnoCursor& rCursor, bool bMovedFromTable)
522 {
523  // Ignore the last element of a selection enumeration if this is a stub
524  // paragraph (directly after table, selection ends at paragraph start).
525 
526  if (rCursor.Start()->nNode.GetIndex() != m_nEndIndex)
527  return false;
528 
529  if (m_eCursorType != CursorType::Selection)
530  return false;
531 
532  if (!bMovedFromTable)
533  return false;
534 
535  return m_nLastParaEnd == 0;
536 }
537 
538 uno::Reference< text::XTextContent >
539 SwXParagraphEnumerationImpl::NextElement_Impl()
540 {
541  SwUnoCursor& rUnoCursor = GetCursor();
542 
543  // check for exceeding selections
544  if (!m_bFirstParagraph &&
545  ((CursorType::Selection == m_eCursorType) ||
546  (CursorType::SelectionInTable == m_eCursorType)))
547  {
548  SwPosition* pStart = rUnoCursor.Start();
549  auto aNewCursor(rUnoCursor.GetDoc().CreateUnoCursor(*pStart));
550  // one may also go into tables here
551  if (CursorType::SelectionInTable != m_eCursorType)
552  {
553  aNewCursor->SetRemainInSection( false );
554  }
555 
556  // os 2005-01-14: This part is only necessary to detect movements out
557  // of a selection; if there is no selection we don't have to care
558  SwTableNode *const pTableNode = aNewCursor->GetNode().FindTableNode();
559  bool bMovedFromTable = false;
560  if (CursorType::SelectionInTable != m_eCursorType && pTableNode)
561  {
562  aNewCursor->GetPoint()->nNode = pTableNode->EndOfSectionIndex();
563  aNewCursor->Move(fnMoveForward, GoInNode);
564  bMovedFromTable = true;
565  }
566  else
567  {
568  aNewCursor->MovePara(GoNextPara, fnParaStart);
569  }
570  if (m_nEndIndex < aNewCursor->Start()->nNode.GetIndex())
571  {
572  return nullptr;
573  }
574 
575  if (IgnoreLastElement(*aNewCursor, bMovedFromTable))
576  {
577  return nullptr;
578  }
579  }
580 
581  bool bInTable = false;
582  if (!m_bFirstParagraph)
583  {
584  rUnoCursor.SetRemainInSection( false );
585  // what to do if already in a table?
586  SwTableNode * pTableNode = rUnoCursor.GetNode().FindTableNode();
587  pTableNode = lcl_FindTopLevelTable( pTableNode, m_pOwnTable );
588  if (pTableNode && (&pTableNode->GetTable() != m_pOwnTable))
589  {
590  // this is a foreign table: go to end
591  rUnoCursor.GetPoint()->nNode = pTableNode->EndOfSectionIndex();
592  if (!rUnoCursor.Move(fnMoveForward, GoInNode))
593  {
594  return nullptr;
595  }
596  bInTable = true;
597  }
598  }
599 
600  uno::Reference< text::XTextContent > xRef;
601  // the cursor must remain in the current section or a subsection
602  // before AND after the movement...
603  if (lcl_CursorIsInSection( &rUnoCursor, m_pOwnStartNode ) &&
604  (m_bFirstParagraph || bInTable ||
605  (rUnoCursor.MovePara(GoNextPara, fnParaStart) &&
606  lcl_CursorIsInSection( &rUnoCursor, m_pOwnStartNode ))))
607  {
608  if (m_eCursorType == CursorType::Selection || m_eCursorType == CursorType::SelectionInTable)
609  {
610  // This is a selection, check if the cursor would go past the end
611  // of the selection.
612  if (rUnoCursor.Start()->nNode.GetIndex() > m_nEndIndex)
613  return nullptr;
614  }
615 
616  SwPosition* pStart = rUnoCursor.Start();
617  const sal_Int32 nFirstContent =
618  m_bFirstParagraph ? m_nFirstParaStart : -1;
619  const sal_Int32 nLastContent =
620  (m_nEndIndex == pStart->nNode.GetIndex()) ? m_nLastParaEnd : -1;
621 
622  // position in a table, or in a simple paragraph?
623  SwTableNode * pTableNode = rUnoCursor.GetNode().FindTableNode();
624  pTableNode = lcl_FindTopLevelTable( pTableNode, m_pOwnTable );
625  if (/*CursorType::TableText != eCursorType && CursorType::SelectionInTable != eCursorType && */
626  pTableNode && (&pTableNode->GetTable() != m_pOwnTable))
627  {
628  // this is a foreign table
629  SwFrameFormat* pTableFormat = pTableNode->GetTable().GetFrameFormat();
630  xRef = SwXTextTable::CreateXTextTable(pTableFormat);
631  }
632  else
633  {
634  text::XText *const pText = m_xParentText.get();
635  xRef = SwXParagraph::CreateXParagraph(rUnoCursor.GetDoc(),
636  pStart->nNode.GetNode().GetTextNode(),
637  static_cast<SwXText*>(pText), nFirstContent, nLastContent);
638  }
639  }
640 
641  return xRef;
642 }
643 
644 uno::Any SAL_CALL SwXParagraphEnumerationImpl::nextElement()
645 {
646  SolarMutexGuard aGuard;
647  if (m_bFirstParagraph)
648  {
649  m_xNextPara = NextElement_Impl();
650  m_bFirstParagraph = false;
651  }
652  const uno::Reference< text::XTextContent > xRef = m_xNextPara;
653  if (!xRef.is())
654  {
655  throw container::NoSuchElementException();
656  }
657  m_xNextPara = NextElement_Impl();
658 
659  uno::Any aRet;
660  aRet <<= xRef;
661  return aRet;
662 }
663 
665  : public SvtListener
666 {
667 public:
671  uno::Reference<text::XText> m_xParentText;
673  const ::sw::mark::IMark* m_pMark;
674 
675  Impl(SwDoc& rDoc, const enum RangePosition eRange,
676  SwFrameFormat* const pTableOrSectionFormat,
677  const uno::Reference<text::XText>& xParent = nullptr)
678  : m_rPropSet(*aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR))
679  , m_eRangePosition(eRange)
680  , m_rDoc(rDoc)
681  , m_xParentText(xParent)
682  , m_pTableOrSectionFormat(pTableOrSectionFormat)
683  , m_pMark(nullptr)
684  {
685  if (m_pTableOrSectionFormat)
686  {
687  assert(m_eRangePosition == RANGE_IS_TABLE || m_eRangePosition == RANGE_IS_SECTION);
688  StartListening(pTableOrSectionFormat->GetNotifier());
689  }
690  else
691  {
692  assert(m_eRangePosition != RANGE_IS_TABLE && m_eRangePosition != RANGE_IS_SECTION);
693  }
694  }
695 
696  virtual ~Impl() override
697  {
698  // Impl owns the bookmark; delete it here: SolarMutex is locked
699  Invalidate();
700  }
701 
702  void Invalidate()
703  {
704  if (m_pMark)
705  {
706  m_rDoc.getIDocumentMarkAccess()->deleteMark(m_pMark);
707  m_pMark = nullptr;
708  }
709  m_pTableOrSectionFormat = nullptr;
710  EndListeningAll();
711  }
712 
713  const ::sw::mark::IMark* GetBookmark() const { return m_pMark; }
714  void SetMark(::sw::mark::IMark& rMark)
715  {
716  EndListeningAll();
717  m_pTableOrSectionFormat = nullptr;
718  m_pMark = &rMark;
719  StartListening(rMark.GetNotifier());
720  }
721 
722 protected:
723  virtual void Notify(const SfxHint&) override;
724 };
725 
727 {
728  if(rHint.GetId() == SfxHintId::Dying)
729  {
730  EndListeningAll();
731  m_pTableOrSectionFormat = nullptr;
732  m_pMark = nullptr;
733  }
734 }
735 
736 SwXTextRange::SwXTextRange(SwPaM const & rPam,
737  const uno::Reference< text::XText > & xParent,
738  const enum RangePosition eRange)
739  : m_pImpl( new SwXTextRange::Impl(rPam.GetDoc(), eRange, nullptr, xParent) )
740 {
741  SetPositions(rPam);
742 }
743 
745  : m_pImpl(
746  new SwXTextRange::Impl(*rTableFormat.GetDoc(), RANGE_IS_TABLE, &rTableFormat) )
747 {
748  SwTable *const pTable = SwTable::FindTable( &rTableFormat );
749  SwTableNode *const pTableNode = pTable->GetTableNode();
750  SwPosition aPosition( *pTableNode );
751  SwPaM aPam( aPosition );
752 
753  SetPositions( aPam );
754 }
755 
757  : m_pImpl(
758  new SwXTextRange::Impl(*rSectionFormat.GetDoc(), RANGE_IS_SECTION, &rSectionFormat) )
759 {
760  // no SetPositions here for now
761 }
762 
764 {
765 }
766 
768 {
769  return m_pImpl->m_rDoc;
770 }
771 
773 {
774  return m_pImpl->m_rDoc;
775 }
776 
778 {
779  m_pImpl->Invalidate();
780 }
781 
783 {
784  m_pImpl->Invalidate();
785  IDocumentMarkAccess* const pMA = m_pImpl->m_rDoc.getIDocumentMarkAccess();
787  m_pImpl->SetMark(*pMark);
788 }
789 
790 static void DeleteTable(SwDoc & rDoc, SwTable& rTable)
791 {
792  SwSelBoxes aSelBoxes;
793  for (auto& rBox : rTable.GetTabSortBoxes())
794  {
795  aSelBoxes.insert(rBox);
796  }
797  // note: if the table is the content in the section, this will create
798  // a new text node - that's desirable here
800 }
801 
803  const OUString& rText, const bool bForceExpandHints)
804 {
805  if (RANGE_IS_TABLE == m_pImpl->m_eRangePosition)
806  {
807  // setString on table not allowed
808  throw uno::RuntimeException("not possible for table");
809  }
810 
811  const SwPosition aPos(GetDoc().GetNodes().GetEndOfContent());
812  SwCursor aCursor(aPos, nullptr);
813 
814  UnoActionContext aAction(& m_pImpl->m_rDoc);
815 
816  if (RANGE_IS_SECTION == m_pImpl->m_eRangePosition)
817  {
818  SwSectionNode const* pSectionNode = m_pImpl->m_pTableOrSectionFormat ?
819  static_cast<SwSectionFormat const*>(m_pImpl->m_pTableOrSectionFormat)->GetSectionNode() :
820  nullptr;
821  if (!pSectionNode)
822  {
823  throw uno::RuntimeException("disposed?");
824  }
825  m_pImpl->m_rDoc.GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT, nullptr);
826  SwNodeIndex const start(*pSectionNode);
827  SwNodeIndex const end(*start.GetNode().EndOfSectionNode());
828 
829  // delete tables at start
830  for (SwNodeIndex i = start; i < end; )
831  {
832  SwNode & rNode(i.GetNode());
833  if (rNode.IsSectionNode())
834  {
835  ++i;
836  continue;
837  }
838  else if (SwTableNode *const pTableNode = rNode.GetTableNode())
839  {
840  DeleteTable(m_pImpl->m_rDoc, pTableNode->GetTable());
841  // where does that leave index? presumably behind?
842  }
843  else
844  {
845  assert(rNode.IsTextNode());
846  break;
847  }
848  }
849  // delete tables at end
850  for (SwNodeIndex i = end; start <= i; )
851  {
852  --i;
853  SwNode & rNode(i.GetNode());
854  if (rNode.IsEndNode())
855  {
856  if (SwTableNode *const pTableNode = rNode.StartOfSectionNode()->GetTableNode())
857  {
858  DeleteTable(m_pImpl->m_rDoc, pTableNode->GetTable());
859  }
860  else
861  {
862  assert(rNode.StartOfSectionNode()->IsSectionNode());
863  continue;
864  }
865  }
866  else
867  {
868  assert(rNode.IsTextNode());
869  break;
870  }
871  }
872  // now there should be a text node at the start and end of it!
873  *aCursor.GetPoint() = SwPosition(start);
874  aCursor.Move( fnMoveForward, GoInContent );
875  assert(aCursor.GetPoint()->nNode <= end);
876  aCursor.SetMark();
877  *aCursor.GetPoint() = SwPosition(end);
878  aCursor.Move( fnMoveBackward, GoInContent );
879  assert(start <= aCursor.GetPoint()->nNode);
880  }
881  else
882  {
883  if (!GetPositions(aCursor))
884  return;
885  m_pImpl->m_rDoc.GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT, nullptr);
886  }
887 
888  if (aCursor.HasMark())
889  {
890  m_pImpl->m_rDoc.getIDocumentContentOperations().DeleteAndJoin(aCursor);
891  }
892 
893  if (!rText.isEmpty())
894  {
896  m_pImpl->m_rDoc, aCursor, rText, bForceExpandHints);
897 
898  SwUnoCursorHelper::SelectPam(aCursor, true);
899  aCursor.Left(rText.getLength());
900  }
901  SetPositions(aCursor);
902  m_pImpl->m_rDoc.GetIDocumentUndoRedo().EndUndo(SwUndoId::INSERT, nullptr);
903 }
904 
905 const uno::Sequence< sal_Int8 > & SwXTextRange::getUnoTunnelId()
906 {
907  static const UnoTunnelIdInit theSwXTextRangeUnoTunnelId;
908  return theSwXTextRangeUnoTunnelId.getSeq();
909 }
910 
911 // XUnoTunnel
912 sal_Int64 SAL_CALL
913 SwXTextRange::getSomething(const uno::Sequence< sal_Int8 >& rId)
914 {
915  return ::sw::UnoTunnelImpl<SwXTextRange>(rId, this);
916 }
917 
918 OUString SAL_CALL
920 {
921  return "SwXTextRange";
922 }
923 
924 sal_Bool SAL_CALL SwXTextRange::supportsService(const OUString& rServiceName)
925 {
926  return cppu::supportsService(this, rServiceName);
927 }
928 
929 uno::Sequence< OUString > SAL_CALL
931 {
932  return {
933  "com.sun.star.text.TextRange",
934  "com.sun.star.style.CharacterProperties",
935  "com.sun.star.style.CharacterPropertiesAsian",
936  "com.sun.star.style.CharacterPropertiesComplex",
937  "com.sun.star.style.ParagraphProperties",
938  "com.sun.star.style.ParagraphPropertiesAsian",
939  "com.sun.star.style.ParagraphPropertiesComplex"
940  };
941 }
942 
943 uno::Reference< text::XText > SAL_CALL
945 {
946  SolarMutexGuard aGuard;
947 
948  if (!m_pImpl->m_xParentText.is() && m_pImpl->m_pTableOrSectionFormat)
949  {
950  std::optional<SwPosition> oPosition;
951  if (m_pImpl->m_eRangePosition == RANGE_IS_TABLE)
952  {
953  SwTable const*const pTable = SwTable::FindTable( m_pImpl->m_pTableOrSectionFormat );
954  SwTableNode const*const pTableNode = pTable->GetTableNode();
955  oPosition.emplace(*pTableNode);
956  }
957  else
958  {
959  assert(m_pImpl->m_eRangePosition == RANGE_IS_SECTION);
960  auto const pSectFormat(static_cast<SwSectionFormat const*>(m_pImpl->m_pTableOrSectionFormat));
961  oPosition.emplace(pSectFormat->GetContent().GetContentIdx()->GetNode());
962  }
963  m_pImpl->m_xParentText =
964  ::sw::CreateParentXText(m_pImpl->m_rDoc, *oPosition);
965  }
966  OSL_ENSURE(m_pImpl->m_xParentText.is(), "SwXTextRange::getText: no text");
967  return m_pImpl->m_xParentText;
968 }
969 
970 uno::Reference< text::XTextRange > SAL_CALL
972 {
973  SolarMutexGuard aGuard;
974 
975  uno::Reference< text::XTextRange > xRet;
976  ::sw::mark::IMark const * const pBkmk = m_pImpl->GetBookmark();
977  if (!m_pImpl->m_xParentText.is())
978  {
979  getText();
980  }
981  if(pBkmk)
982  {
983  SwPaM aPam(pBkmk->GetMarkStart());
984  xRet = new SwXTextRange(aPam, m_pImpl->m_xParentText);
985  }
986  else if (RANGE_IS_TABLE == m_pImpl->m_eRangePosition)
987  {
988  // start and end are this, if it's a table
989  xRet = this;
990  }
991  else if (RANGE_IS_SECTION == m_pImpl->m_eRangePosition
992  && m_pImpl->m_pTableOrSectionFormat)
993  {
994  auto const pSectFormat(static_cast<SwSectionFormat const*>(m_pImpl->m_pTableOrSectionFormat));
995  SwPaM aPaM(*pSectFormat->GetContent().GetContentIdx());
996  aPaM.Move( fnMoveForward, GoInContent );
997  assert(aPaM.GetPoint()->nNode < *pSectFormat->GetContent().GetContentIdx()->GetNode().EndOfSectionNode());
998  xRet = new SwXTextRange(aPaM, m_pImpl->m_xParentText);
999  }
1000  else
1001  {
1002  throw uno::RuntimeException("disposed?");
1003  }
1004  return xRet;
1005 }
1006 
1007 uno::Reference< text::XTextRange > SAL_CALL
1009 {
1010  SolarMutexGuard aGuard;
1011 
1012  uno::Reference< text::XTextRange > xRet;
1013  ::sw::mark::IMark const * const pBkmk = m_pImpl->GetBookmark();
1014  if (!m_pImpl->m_xParentText.is())
1015  {
1016  getText();
1017  }
1018  if(pBkmk)
1019  {
1020  SwPaM aPam(pBkmk->GetMarkEnd());
1021  xRet = new SwXTextRange(aPam, m_pImpl->m_xParentText);
1022  }
1023  else if (RANGE_IS_TABLE == m_pImpl->m_eRangePosition)
1024  {
1025  // start and end are this, if it's a table
1026  xRet = this;
1027  }
1028  else if (RANGE_IS_SECTION == m_pImpl->m_eRangePosition
1029  && m_pImpl->m_pTableOrSectionFormat)
1030  {
1031  auto const pSectFormat(static_cast<SwSectionFormat const*>(m_pImpl->m_pTableOrSectionFormat));
1032  SwPaM aPaM(*pSectFormat->GetContent().GetContentIdx()->GetNode().EndOfSectionNode());
1033  aPaM.Move( fnMoveBackward, GoInContent );
1034  assert(*pSectFormat->GetContent().GetContentIdx() < aPaM.GetPoint()->nNode);
1035  xRet = new SwXTextRange(aPaM, m_pImpl->m_xParentText);
1036  }
1037  else
1038  {
1039  throw uno::RuntimeException("disposed?");
1040  }
1041  return xRet;
1042 }
1043 
1044 OUString SAL_CALL SwXTextRange::getString()
1045 {
1046  SolarMutexGuard aGuard;
1047 
1048  OUString sRet;
1049  // for tables there is no bookmark, thus also no text
1050  // one could export the table as ASCII here maybe?
1051  SwPaM aPaM(GetDoc().GetNodes());
1053  {
1055  }
1056  return sRet;
1057 }
1058 
1059 void SAL_CALL SwXTextRange::setString(const OUString& rString)
1060 {
1061  SolarMutexGuard aGuard;
1062 
1063  DeleteAndInsert(rString, false);
1064 }
1065 
1066 bool SwXTextRange::GetPositions(SwPaM& rToFill, ::sw::TextRangeMode const eMode) const
1067 {
1068  if (RANGE_IS_SECTION == m_pImpl->m_eRangePosition
1070  {
1071  if (auto const pSectFormat = static_cast<SwSectionFormat const*>(m_pImpl->m_pTableOrSectionFormat))
1072  {
1073  SwNodeIndex const*const pSectionNode(pSectFormat->GetContent().GetContentIdx());
1074  assert(pSectionNode);
1075  assert(pSectionNode->GetNodes().IsDocNodes());
1076  rToFill.GetPoint()->nNode = *pSectionNode;
1077  ++rToFill.GetPoint()->nNode;
1078  rToFill.GetPoint()->nContent.Assign(rToFill.GetPoint()->nNode.GetNode().GetContentNode(), 0);
1079  rToFill.SetMark();
1080  rToFill.GetMark()->nNode = *pSectionNode->GetNode().EndOfSectionNode();
1081  --rToFill.GetMark()->nNode;
1082  rToFill.GetMark()->nContent.Assign(rToFill.GetMark()->nNode.GetNode().GetContentNode(),
1083  rToFill.GetMark()->nNode.GetNode().GetContentNode() ? rToFill.GetMark()->nNode.GetNode().GetContentNode()->Len() : 0);
1084  return true;
1085  }
1086  }
1087  ::sw::mark::IMark const * const pBkmk = m_pImpl->GetBookmark();
1088  if(pBkmk)
1089  {
1090  *rToFill.GetPoint() = pBkmk->GetMarkPos();
1091  if(pBkmk->IsExpanded())
1092  {
1093  rToFill.SetMark();
1094  *rToFill.GetMark() = pBkmk->GetOtherMarkPos();
1095  }
1096  else
1097  {
1098  rToFill.DeleteMark();
1099  }
1100  return true;
1101  }
1102  return false;
1103 }
1104 
1105 namespace sw {
1106 
1108  const uno::Reference<text::XTextRange> & xTextRange,
1109  ::sw::TextRangeMode const eMode)
1110 {
1111  bool bRet = false;
1112 
1113  uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
1114  SwXTextRange* pRange = nullptr;
1115  OTextCursorHelper* pCursor = nullptr;
1116  SwXTextPortion* pPortion = nullptr;
1117  SwXText* pText = nullptr;
1118  SwXParagraph* pPara = nullptr;
1119  if(xRangeTunnel.is())
1120  {
1121  pRange = ::sw::UnoTunnelGetImplementation<SwXTextRange>(xRangeTunnel);
1122  pCursor =
1123  ::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xRangeTunnel);
1124  pPortion=
1125  ::sw::UnoTunnelGetImplementation<SwXTextPortion>(xRangeTunnel);
1126  pText = ::sw::UnoTunnelGetImplementation<SwXText>(xRangeTunnel);
1127  pPara = ::sw::UnoTunnelGetImplementation<SwXParagraph>(xRangeTunnel);
1128  }
1129 
1130  // if it's a text then create a temporary cursor there and re-use
1131  // the pCursor variable
1132  // #i108489#: Reference in outside scope to keep cursor alive
1133  uno::Reference< text::XTextCursor > xTextCursor;
1134  if (pText)
1135  {
1136  xTextCursor.set( pText->CreateCursor() );
1137  xTextCursor->gotoEnd(true);
1138  pCursor =
1139  comphelper::getUnoTunnelImplementation<OTextCursorHelper>(xTextCursor);
1140  }
1141  if(pRange && &pRange->GetDoc() == &rToFill.GetDoc())
1142  {
1143  bRet = pRange->GetPositions(rToFill, eMode);
1144  }
1145  else
1146  {
1147  if (pPara)
1148  {
1149  bRet = pPara->SelectPaM(rToFill);
1150  }
1151  else
1152  {
1153  SwDoc* const pDoc = pCursor ? pCursor->GetDoc()
1154  : (pPortion ? &pPortion->GetCursor().GetDoc() : nullptr);
1155  const SwPaM* const pUnoCursor = pCursor ? pCursor->GetPaM()
1156  : (pPortion ? &pPortion->GetCursor() : nullptr);
1157  if (pUnoCursor && pDoc == &rToFill.GetDoc())
1158  {
1159  OSL_ENSURE(!pUnoCursor->IsMultiSelection(),
1160  "what to do about rings?");
1161  bRet = true;
1162  *rToFill.GetPoint() = *pUnoCursor->GetPoint();
1163  if (pUnoCursor->HasMark())
1164  {
1165  rToFill.SetMark();
1166  *rToFill.GetMark() = *pUnoCursor->GetMark();
1167  }
1168  else
1169  rToFill.DeleteMark();
1170  }
1171  }
1172  }
1173  return bRet;
1174 }
1175 
1176 static bool
1177 lcl_IsStartNodeInFormat(const bool bHeader, SwStartNode const *const pSttNode,
1178  SwFrameFormat const*const pFrameFormat, SwFrameFormat*& rpFormat)
1179 {
1180  bool bRet = false;
1181  const SfxItemSet& rSet = pFrameFormat->GetAttrSet();
1182  const SfxPoolItem* pItem;
1183  if (SfxItemState::SET == rSet.GetItemState(
1184  bHeader ? sal_uInt16(RES_HEADER) : sal_uInt16(RES_FOOTER),
1185  true, &pItem))
1186  {
1187  SfxPoolItem *const pItemNonConst(const_cast<SfxPoolItem *>(pItem));
1188  SwFrameFormat *const pHeadFootFormat = bHeader ?
1189  static_cast<SwFormatHeader*>(pItemNonConst)->GetHeaderFormat() :
1190  static_cast<SwFormatFooter*>(pItemNonConst)->GetFooterFormat();
1191  if (pHeadFootFormat)
1192  {
1193  const SwFormatContent& rFlyContent = pHeadFootFormat->GetContent();
1194  const SwNode& rNode = rFlyContent.GetContentIdx()->GetNode();
1195  SwStartNode const*const pCurSttNode = rNode.FindSttNodeByType(
1196  bHeader ? SwHeaderStartNode : SwFooterStartNode);
1197  if (pCurSttNode && (pCurSttNode == pSttNode))
1198  {
1199  rpFormat = pHeadFootFormat;
1200  bRet = true;
1201  }
1202  }
1203  }
1204  return bRet;
1205 }
1206 
1207 } // namespace sw
1208 
1209 uno::Reference< text::XTextRange >
1211  SwDoc & rDoc, const SwPosition& rPos, const SwPosition *const pMark)
1212 {
1213  const uno::Reference<text::XText> xParentText(
1214  ::sw::CreateParentXText(rDoc, rPos));
1215  const auto pNewCursor(rDoc.CreateUnoCursor(rPos));
1216  if(pMark)
1217  {
1218  pNewCursor->SetMark();
1219  *pNewCursor->GetMark() = *pMark;
1220  }
1221  const bool isCell( dynamic_cast<SwXCell*>(xParentText.get()) );
1222  const uno::Reference< text::XTextRange > xRet(
1223  new SwXTextRange(*pNewCursor, xParentText,
1224  isCell ? RANGE_IN_CELL : RANGE_IN_TEXT) );
1225  return xRet;
1226 }
1227 
1228 namespace sw {
1229 
1230 uno::Reference< text::XText >
1231 CreateParentXText(SwDoc & rDoc, const SwPosition& rPos)
1232 {
1233  uno::Reference< text::XText > xParentText;
1234  SwStartNode* pSttNode = rPos.nNode.GetNode().StartOfSectionNode();
1235  while(pSttNode && pSttNode->IsSectionNode())
1236  {
1237  pSttNode = pSttNode->StartOfSectionNode();
1238  }
1239  SwStartNodeType eType = pSttNode ? pSttNode->GetStartNodeType() : SwNormalStartNode;
1240  switch(eType)
1241  {
1242  case SwTableBoxStartNode:
1243  {
1244  SwTableNode const*const pTableNode = pSttNode->FindTableNode();
1245  SwFrameFormat *const pTableFormat =
1246  pTableNode->GetTable().GetFrameFormat();
1247  SwTableBox *const pBox = pSttNode->GetTableBox();
1248 
1249  xParentText = pBox
1250  ? SwXCell::CreateXCell( pTableFormat, pBox )
1251  : new SwXCell( pTableFormat, *pSttNode );
1252  }
1253  break;
1254  case SwFlyStartNode:
1255  {
1256  SwFrameFormat *const pFormat = pSttNode->GetFlyFormat();
1257  if (nullptr != pFormat)
1258  {
1259  xParentText.set(SwXTextFrame::CreateXTextFrame(rDoc, pFormat),
1260  uno::UNO_QUERY);
1261  }
1262  }
1263  break;
1264  case SwHeaderStartNode:
1265  case SwFooterStartNode:
1266  {
1267  const bool bHeader = (SwHeaderStartNode == eType);
1268  const size_t nPDescCount = rDoc.GetPageDescCnt();
1269  for(size_t i = 0; i < nPDescCount; i++)
1270  {
1271  const SwPageDesc& rDesc = rDoc.GetPageDesc( i );
1272 
1273  const SwFrameFormat* pFrameFormatMaster = &rDesc.GetMaster();
1274  const SwFrameFormat* pFrameFormatLeft = &rDesc.GetLeft();
1275  const SwFrameFormat* pFrameFormatFirstMaster = &rDesc.GetFirstMaster();
1276  const SwFrameFormat* pFrameFormatFirstLeft = &rDesc.GetFirstLeft();
1277 
1278  SwFrameFormat* pHeadFootFormat = nullptr;
1279  if (!lcl_IsStartNodeInFormat(bHeader, pSttNode, pFrameFormatMaster,
1280  pHeadFootFormat))
1281  {
1282  if (!lcl_IsStartNodeInFormat(bHeader, pSttNode, pFrameFormatLeft,
1283  pHeadFootFormat))
1284  {
1285  if (!lcl_IsStartNodeInFormat(bHeader, pSttNode, pFrameFormatFirstMaster,
1286  pHeadFootFormat))
1287  {
1288  lcl_IsStartNodeInFormat(bHeader, pSttNode, pFrameFormatFirstLeft, pHeadFootFormat);
1289  }
1290  }
1291  }
1292 
1293  if (pHeadFootFormat)
1294  {
1296  *pHeadFootFormat, bHeader);
1297  }
1298  }
1299  }
1300  break;
1301  case SwFootnoteStartNode:
1302  {
1303  const size_t nFootnoteCnt = rDoc.GetFootnoteIdxs().size();
1304  for (size_t n = 0; n < nFootnoteCnt; ++n )
1305  {
1306  const SwTextFootnote* pTextFootnote = rDoc.GetFootnoteIdxs()[ n ];
1307  const SwFormatFootnote& rFootnote = pTextFootnote->GetFootnote();
1308  pTextFootnote = rFootnote.GetTextFootnote();
1309 
1310  if (pSttNode == pTextFootnote->GetStartNode()->GetNode().
1311  FindSttNodeByType(SwFootnoteStartNode))
1312  {
1313  xParentText.set(SwXFootnote::CreateXFootnote(rDoc,
1314  &const_cast<SwFormatFootnote&>(rFootnote)), uno::UNO_QUERY);
1315  break;
1316  }
1317  }
1318  }
1319  break;
1320  default:
1321  {
1322  // then it is the body text
1323  const uno::Reference<frame::XModel> xModel =
1324  rDoc.GetDocShell()->GetBaseModel();
1325  const uno::Reference< text::XTextDocument > xDoc(
1326  xModel, uno::UNO_QUERY);
1327  xParentText = xDoc->getText();
1328  }
1329  }
1330  OSL_ENSURE(xParentText.is(), "no parent text?");
1331  return xParentText;
1332 }
1333 
1334 } // namespace sw
1335 
1336 uno::Reference< container::XEnumeration > SAL_CALL
1337 SwXTextRange::createContentEnumeration(const OUString& rServiceName)
1338 {
1339  SolarMutexGuard g;
1340 
1341  if ( rServiceName != "com.sun.star.text.TextContent" )
1342  {
1343  throw uno::RuntimeException("unsupported service");
1344  }
1345 
1346  if (!m_pImpl->GetBookmark())
1347  {
1348  throw uno::RuntimeException("range has no mark (table?)");
1349  }
1350  const SwPosition aPos(GetDoc().GetNodes().GetEndOfContent());
1351  const auto pNewCursor(m_pImpl->m_rDoc.CreateUnoCursor(aPos));
1352  if (!GetPositions(*pNewCursor))
1353  {
1354  throw uno::RuntimeException("range has no positions");
1355  }
1356 
1358 }
1359 
1360 uno::Reference< container::XEnumeration > SAL_CALL
1362 {
1363  SolarMutexGuard g;
1364 
1365  if (!m_pImpl->GetBookmark())
1366  {
1367  throw uno::RuntimeException("range has no mark (table?)");
1368  }
1369  const SwPosition aPos(GetDoc().GetNodes().GetEndOfContent());
1370  auto pNewCursor(m_pImpl->m_rDoc.CreateUnoCursor(aPos));
1371  if (!GetPositions(*pNewCursor))
1372  {
1373  throw uno::RuntimeException("range has no positions");
1374  }
1375  if (!m_pImpl->m_xParentText.is())
1376  {
1377  getText();
1378  }
1379 
1380  const CursorType eSetType = (RANGE_IN_CELL == m_pImpl->m_eRangePosition)
1382  return SwXParagraphEnumeration::Create(m_pImpl->m_xParentText, pNewCursor, eSetType);
1383 }
1384 
1386 {
1388 }
1389 
1391 {
1392  return true;
1393 }
1394 
1395 uno::Sequence< OUString > SAL_CALL
1397 {
1398  uno::Sequence<OUString> aRet { "com.sun.star.text.TextContent" };
1399  return aRet;
1400 }
1401 
1402 uno::Reference< beans::XPropertySetInfo > SAL_CALL
1404 {
1405  SolarMutexGuard aGuard;
1406 
1407  static uno::Reference< beans::XPropertySetInfo > xRef =
1408  m_pImpl->m_rPropSet.getPropertySetInfo();
1409  return xRef;
1410 }
1411 
1412 void SAL_CALL
1414  const OUString& rPropertyName, const uno::Any& rValue)
1415 {
1416  SolarMutexGuard aGuard;
1417 
1418  if (!m_pImpl->GetBookmark())
1419  {
1420  throw uno::RuntimeException("range has no mark (table?)");
1421  }
1422  SwPaM aPaM(GetDoc().GetNodes());
1423  GetPositions(aPaM);
1424  SwUnoCursorHelper::SetPropertyValue(aPaM, m_pImpl->m_rPropSet,
1425  rPropertyName, rValue);
1426 }
1427 
1428 uno::Any SAL_CALL
1429 SwXTextRange::getPropertyValue(const OUString& rPropertyName)
1430 {
1431  SolarMutexGuard aGuard;
1432 
1433  if (!m_pImpl->GetBookmark())
1434  {
1435  throw uno::RuntimeException("range has no mark (table?)");
1436  }
1437  SwPaM aPaM(GetDoc().GetNodes());
1438  GetPositions(aPaM);
1439  return SwUnoCursorHelper::GetPropertyValue(aPaM, m_pImpl->m_rPropSet,
1440  rPropertyName);
1441 }
1442 
1443 void SAL_CALL
1445  const OUString& /*rPropertyName*/,
1446  const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
1447 {
1448  OSL_FAIL("SwXTextRange::addPropertyChangeListener(): not implemented");
1449 }
1450 
1451 void SAL_CALL
1453  const OUString& /*rPropertyName*/,
1454  const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
1455 {
1456  OSL_FAIL("SwXTextRange::removePropertyChangeListener(): not implemented");
1457 }
1458 
1459 void SAL_CALL
1461  const OUString& /*rPropertyName*/,
1462  const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
1463 {
1464  OSL_FAIL("SwXTextRange::addVetoableChangeListener(): not implemented");
1465 }
1466 
1467 void SAL_CALL
1469  const OUString& /*rPropertyName*/,
1470  const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
1471 {
1472  OSL_FAIL("SwXTextRange::removeVetoableChangeListener(): not implemented");
1473 }
1474 
1475 beans::PropertyState SAL_CALL
1476 SwXTextRange::getPropertyState(const OUString& rPropertyName)
1477 {
1478  SolarMutexGuard aGuard;
1479 
1480  if (!m_pImpl->GetBookmark())
1481  {
1482  throw uno::RuntimeException("range has no mark (table?)");
1483  }
1484  SwPaM aPaM(GetDoc().GetNodes());
1485  GetPositions(aPaM);
1486  return SwUnoCursorHelper::GetPropertyState(aPaM, m_pImpl->m_rPropSet,
1487  rPropertyName);
1488 }
1489 
1490 uno::Sequence< beans::PropertyState > SAL_CALL
1491 SwXTextRange::getPropertyStates(const uno::Sequence< OUString >& rPropertyName)
1492 {
1493  SolarMutexGuard g;
1494 
1495  if (!m_pImpl->GetBookmark())
1496  {
1497  throw uno::RuntimeException("range has no mark (table?)");
1498  }
1499  SwPaM aPaM(GetDoc().GetNodes());
1500  GetPositions(aPaM);
1501  return SwUnoCursorHelper::GetPropertyStates(aPaM, m_pImpl->m_rPropSet,
1502  rPropertyName);
1503 }
1504 
1505 void SAL_CALL SwXTextRange::setPropertyToDefault(const OUString& rPropertyName)
1506 {
1507  SolarMutexGuard aGuard;
1508 
1509  if (!m_pImpl->GetBookmark())
1510  {
1511  throw uno::RuntimeException("range has no mark (table?)");
1512  }
1513  SwPaM aPaM(GetDoc().GetNodes());
1514  GetPositions(aPaM);
1516  rPropertyName);
1517 }
1518 
1519 uno::Any SAL_CALL
1520 SwXTextRange::getPropertyDefault(const OUString& rPropertyName)
1521 {
1522  SolarMutexGuard aGuard;
1523 
1524  if (!m_pImpl->GetBookmark())
1525  {
1526  throw uno::RuntimeException("range has no mark (table?)");
1527  }
1528  SwPaM aPaM(GetDoc().GetNodes());
1529  GetPositions(aPaM);
1530  return SwUnoCursorHelper::GetPropertyDefault(aPaM, m_pImpl->m_rPropSet,
1531  rPropertyName);
1532 }
1533 
1534 void SAL_CALL
1536  const OUString& rRedlineType,
1537  const uno::Sequence< beans::PropertyValue >& rRedlineProperties )
1538 {
1539  SolarMutexGuard aGuard;
1540 
1541  if (!m_pImpl->GetBookmark())
1542  {
1543  throw uno::RuntimeException("range has no mark (table?)");
1544  }
1545  SwPaM aPaM(GetDoc().GetNodes());
1547  SwUnoCursorHelper::makeRedline( aPaM, rRedlineType, rRedlineProperties );
1548 }
1549 
1550 namespace {
1551 
1552 struct SwXTextRangesImpl final : public SwXTextRanges
1553 {
1554 
1555  // XUnoTunnel
1556  virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& rIdentifier) override;
1557 
1558  // XServiceInfo
1559  virtual OUString SAL_CALL getImplementationName() override
1560  { return "SwXTextRanges"; };
1561  virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName) override
1562  { return cppu::supportsService(this, rServiceName); };
1563  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
1564  { return { "com.sun.star.text.TextRanges" }; };
1565 
1566  // XElementAccess
1567  virtual css::uno::Type SAL_CALL getElementType() override
1569  virtual sal_Bool SAL_CALL hasElements() override
1570  { return getCount() > 0; };
1571  // XIndexAccess
1572  virtual sal_Int32 SAL_CALL getCount() override;
1573  virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override;
1574 
1575  explicit SwXTextRangesImpl(SwPaM *const pPaM)
1576  {
1577  if (pPaM)
1578  {
1579  m_pUnoCursor.reset(pPaM->GetDoc().CreateUnoCursor(*pPaM->GetPoint()));
1580  ::sw::DeepCopyPaM(*pPaM, *GetCursor());
1581  }
1582  MakeRanges();
1583  }
1584  virtual void SAL_CALL release() noexcept override
1585  {
1586  SolarMutexGuard g;
1587  OWeakObject::release();
1588  }
1589  virtual SwUnoCursor* GetCursor() override
1590  { return &(*m_pUnoCursor); };
1591  void MakeRanges();
1592  std::vector< uno::Reference< text::XTextRange > > m_Ranges;
1593  sw::UnoCursorPointer m_pUnoCursor;
1594 };
1595 
1596 }
1597 
1598 void SwXTextRangesImpl::MakeRanges()
1599 {
1600  if (!GetCursor())
1601  return;
1602 
1603  for(SwPaM& rTmpCursor : GetCursor()->GetRingContainer())
1604  {
1605  const uno::Reference< text::XTextRange > xRange(
1607  rTmpCursor.GetDoc(),
1608  *rTmpCursor.GetPoint(), rTmpCursor.GetMark()));
1609  if (xRange.is())
1610  {
1611  m_Ranges.push_back(xRange);
1612  }
1613  }
1614 }
1615 
1617  { return new SwXTextRangesImpl(pPaM); }
1618 
1619 const uno::Sequence< sal_Int8 > & SwXTextRanges::getUnoTunnelId()
1620 {
1621  static const UnoTunnelIdInit theSwXTextRangesUnoTunnelId;
1622  return theSwXTextRangesUnoTunnelId.getSeq();
1623 }
1624 
1625 sal_Int64 SAL_CALL
1626 SwXTextRangesImpl::getSomething(const uno::Sequence< sal_Int8 >& rId)
1627 {
1628  return ::sw::UnoTunnelImpl<SwXTextRanges>(rId, this);
1629 }
1630 
1631 /*
1632  * Text positions
1633  * Up to the first access to a text position, only a SwCursor is stored.
1634  * Afterwards, an array with uno::Reference<XTextPosition> will be created.
1635  */
1636 
1637 sal_Int32 SAL_CALL SwXTextRangesImpl::getCount()
1638 {
1639  SolarMutexGuard aGuard;
1640  return static_cast<sal_Int32>(m_Ranges.size());
1641 }
1642 
1643 uno::Any SAL_CALL SwXTextRangesImpl::getByIndex(sal_Int32 nIndex)
1644 {
1645  SolarMutexGuard aGuard;
1646  if ((nIndex < 0) || (o3tl::make_unsigned(nIndex) >= m_Ranges.size()))
1647  throw lang::IndexOutOfBoundsException();
1648  uno::Any ret;
1649  ret <<= m_Ranges.at(nIndex);
1650  return ret;
1651 }
1652 
1653 void SwUnoCursorHelper::SetString(SwCursor & rCursor, const OUString& rString)
1654 {
1655  // Start/EndAction
1656  SwDoc& rDoc = rCursor.GetDoc();
1657  UnoActionContext aAction(&rDoc);
1659  if (rCursor.HasMark())
1660  {
1662  }
1663  if (!rString.isEmpty())
1664  {
1665  const bool bSuccess( SwUnoCursorHelper::DocInsertStringSplitCR(
1666  rDoc, rCursor, rString, false ) );
1667  OSL_ENSURE( bSuccess, "DocInsertStringSplitCR" );
1668  SwUnoCursorHelper::SelectPam(rCursor, true);
1669  rCursor.Left(rString.getLength());
1670  }
1672 }
1673 
1674 namespace {
1675 
1676 struct SwXParaFrameEnumerationImpl final : public SwXParaFrameEnumeration
1677 {
1678  // XServiceInfo
1679  virtual OUString SAL_CALL getImplementationName() override
1680  { return "SwXParaFrameEnumeration"; };
1681  virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override
1682  { return cppu::supportsService(this, rServiceName); };
1683  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
1684  { return {"com.sun.star.util.ContentEnumeration"}; };
1685 
1686  // XEnumeration
1687  virtual sal_Bool SAL_CALL hasMoreElements() override;
1688  virtual css::uno::Any SAL_CALL nextElement() override;
1689 
1690  SwXParaFrameEnumerationImpl(const SwPaM& rPaM, const enum ParaFrameMode eParaFrameMode, SwFrameFormat* const pFormat);
1691  virtual void SAL_CALL release() noexcept override
1692  {
1693  SolarMutexGuard g;
1694  OWeakObject::release();
1695  }
1696  SwUnoCursor& GetCursor()
1697  { return *m_pUnoCursor; }
1698  void PurgeFrameClients()
1699  {
1700  if(!m_pUnoCursor)
1701  {
1702  m_vFrames.clear();
1703  m_xNextObject = nullptr;
1704  }
1705  else
1706  {
1707  // removing orphaned Clients
1708  const auto iter = std::remove_if(m_vFrames.begin(), m_vFrames.end(),
1709  [] (std::shared_ptr<sw::FrameClient>& rEntry) -> bool { return !rEntry->GetRegisteredIn(); });
1710  m_vFrames.erase(iter, m_vFrames.end());
1711  }
1712  }
1713  void FillFrame();
1714  bool CreateNextObject();
1715  uno::Reference< text::XTextContent > m_xNextObject;
1716  FrameClientList_t m_vFrames;
1717  ::sw::UnoCursorPointer m_pUnoCursor;
1718 };
1719 
1720 }
1721 
1723  { return new SwXParaFrameEnumerationImpl(rPaM, eParaFrameMode, pFormat); }
1724 
1725 SwXParaFrameEnumerationImpl::SwXParaFrameEnumerationImpl(
1726  const SwPaM& rPaM, const enum ParaFrameMode eParaFrameMode,
1727  SwFrameFormat* const pFormat)
1728  : m_pUnoCursor(rPaM.GetDoc().CreateUnoCursor(*rPaM.GetPoint()))
1729 {
1730  if (rPaM.HasMark())
1731  {
1732  GetCursor().SetMark();
1733  *GetCursor().GetMark() = *rPaM.GetMark();
1734  }
1735  if (PARAFRAME_PORTION_PARAGRAPH == eParaFrameMode)
1736  {
1737  FrameClientSortList_t vFrames;
1738  ::CollectFrameAtNode(rPaM.GetPoint()->nNode, vFrames, false);
1739  std::transform(vFrames.begin(), vFrames.end(),
1740  std::back_inserter(m_vFrames),
1741  [] (const FrameClientSortListEntry& rEntry) { return rEntry.pFrameClient; });
1742  }
1743  else if (pFormat)
1744  {
1745  m_vFrames.push_back(std::make_shared<sw::FrameClient>(pFormat));
1746  }
1747  else if ((PARAFRAME_PORTION_CHAR == eParaFrameMode) ||
1748  (PARAFRAME_PORTION_TEXTRANGE == eParaFrameMode))
1749  {
1750  if (PARAFRAME_PORTION_TEXTRANGE == eParaFrameMode)
1751  {
1752  //get all frames that are bound at paragraph or at character
1753  for(const auto& pFlyFrame : rPaM.GetDoc().GetAllFlyFormats(&GetCursor(), false, true))
1754  {
1755  const auto pFrameFormat = const_cast<SwFrameFormat*>(&pFlyFrame->GetFormat());
1756  m_vFrames.push_back(std::make_shared<sw::FrameClient>(pFrameFormat));
1757  }
1758  }
1759  FillFrame();
1760  }
1761 }
1762 
1763 // Search for a FLYCNT text attribute at the cursor point and fill the frame
1764 // into the array
1765 void SwXParaFrameEnumerationImpl::FillFrame()
1766 {
1767  if(!m_pUnoCursor->GetNode().IsTextNode())
1768  return;
1769  // search for objects at the cursor - anchored at/as char
1770  const auto pTextAttr = m_pUnoCursor->GetNode().GetTextNode()->GetTextAttrForCharAt(
1771  m_pUnoCursor->GetPoint()->nContent.GetIndex(), RES_TXTATR_FLYCNT);
1772  if(!pTextAttr)
1773  return;
1774  const SwFormatFlyCnt& rFlyCnt = pTextAttr->GetFlyCnt();
1775  SwFrameFormat* const pFrameFormat = rFlyCnt.GetFrameFormat();
1776  m_vFrames.push_back(std::make_shared<sw::FrameClient>(pFrameFormat));
1777 }
1778 
1779 bool SwXParaFrameEnumerationImpl::CreateNextObject()
1780 {
1781  if (m_vFrames.empty())
1782  return false;
1783 
1784  SwFrameFormat* const pFormat = static_cast<SwFrameFormat*>(
1785  m_vFrames.front()->GetRegisteredIn());
1786  m_vFrames.pop_front();
1787  // the format should be valid here, otherwise the client
1788  // would have been removed by PurgeFrameClients
1789  // check for a shape first
1790  if(pFormat->Which() == RES_DRAWFRMFMT)
1791  {
1792  SdrObject* pObject(nullptr);
1793  pFormat->CallSwClientNotify(sw::FindSdrObjectHint(pObject));
1794  if(pObject)
1795  m_xNextObject.set(pObject->getUnoShape(), uno::UNO_QUERY);
1796  }
1797  else
1798  {
1799  const SwNodeIndex* pIdx = pFormat->GetContent().GetContentIdx();
1800  OSL_ENSURE(pIdx, "where is the index?");
1801  SwNode const*const pNd =
1802  m_pUnoCursor->GetDoc().GetNodes()[ pIdx->GetIndex() + 1 ];
1803 
1804  if (!pNd->IsNoTextNode())
1805  {
1806  m_xNextObject.set(SwXTextFrame::CreateXTextFrame(
1807  *pFormat->GetDoc(), pFormat));
1808  }
1809  else if (pNd->IsGrfNode())
1810  {
1812  *pFormat->GetDoc(), pFormat));
1813  }
1814  else
1815  {
1816  assert(pNd->IsOLENode());
1818  *pFormat->GetDoc(), pFormat));
1819  }
1820  }
1821  return m_xNextObject.is();
1822 }
1823 
1824 sal_Bool SAL_CALL
1825 SwXParaFrameEnumerationImpl::hasMoreElements()
1826 {
1827  SolarMutexGuard aGuard;
1828  PurgeFrameClients();
1829  return m_xNextObject.is() || CreateNextObject();
1830 }
1831 
1832 uno::Any SAL_CALL SwXParaFrameEnumerationImpl::nextElement()
1833 {
1834  SolarMutexGuard aGuard;
1835  PurgeFrameClients();
1836  if (!m_xNextObject.is() && !m_vFrames.empty())
1837  CreateNextObject();
1838  if (!m_xNextObject.is())
1839  throw container::NoSuchElementException();
1840  uno::Any aRet;
1841  aRet <<= m_xNextObject;
1842  m_xNextObject = nullptr;
1843  return aRet;
1844 }
1845 
1846 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwStartNode * FindSttNodeByType(SwStartNodeType eTyp)
Definition: node.cxx:764
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:683
Starts a section of nodes in the document model.
Definition: node.hxx:312
bool MovePara(SwWhichPara, SwMoveFnCollection const &)
Definition: swcrsr.cxx:2295
std::shared_ptr< SwUnoCursor > CreateUnoCursor(const SwPosition &rPos, bool bTableCursor=false)
Definition: doc.cxx:1775
virtual sal_Int32 Len() const
Definition: node.cxx:1246
static rtl::Reference< SwXTextRanges > Create(SwPaM *const pCursor)
Definition: unoobj2.cxx:1616
void DeleteMark()
Definition: pam.hxx:177
static css::uno::Reference< css::text::XTextTable > CreateXTextTable(SwFrameFormat *pFrameFormat)
Definition: unotbl.cxx:2006
sal_uLong GetIndex() const
Definition: node.hxx:291
uno::Reference< text::XText > m_xParentText
Definition: unoobj2.cxx:671
static void DeleteTable(SwDoc &rDoc, SwTable &rTable)
Definition: unoobj2.cxx:790
SwNode & GetNode(bool bPoint=true) const
Definition: pam.hxx:223
sal_Int32 nIndex
bool GoInContent(SwPaM &rPam, SwMoveFnCollection const &fnMove)
Definition: pam.cxx:970
virtual const SwDoc * GetDoc() const =0
const SwSortedObjs * GetDrawObjs() const
Definition: frame.hxx:563
Marks a position in the document model.
Definition: pam.hxx:35
bool IsSectionNode() const
Definition: node.hxx:645
bool IsMultiSelection() const
Definition: pam.hxx:272
bool IsGrfNode() const
Definition: node.hxx:657
SwFrameFormat & GetLeft()
Definition: pagedesc.hxx:239
#define PROPERTY_MAP_TEXT_CURSOR
Definition: unomap.hxx:27
SwTableBox * GetTableBox() const
If node is in a table return the respective table box.
Definition: node.cxx:754
CursorType
const OUString & GetText() const
Definition: ndtxt.hxx:215
virtual const SwRootFrame * GetCurrentLayout() const =0
static css::uno::Reference< css::text::XText > CreateXHeadFootText(SwFrameFormat &rHeadFootFormat, const bool bIsHeader)
Definition: unotext.cxx:2533
~UnoActionContext() COVERITY_NOEXCEPT_FALSE
Definition: unoobj2.cxx:194
static rtl::Reference< SwXCell > CreateXCell(SwFrameFormat *pTableFormat, SwTableBox *pBox, SwTable *pTable=nullptr)
Definition: unotbl.cxx:1133
SwDocShell * GetDocShell()
Definition: doc.hxx:1352
constexpr TypedWhichId< SwFormatHeader > RES_HEADER(96)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unoobj2.cxx:930
SwNodeIndex nNode
Definition: pam.hxx:37
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &rIdentifier) override
Definition: unoobj2.cxx:913
virtual void InsertItemSet(const SwPaM &rRg, const SfxItemSet &, const SetAttrMode nFlags=SetAttrMode::DEFAULT, SwRootFrame const *pLayout=nullptr)=0
std::deque< FrameClientSortListEntry > FrameClientSortList_t
sal_uIntPtr sal_uLong
virtual void SAL_CALL removeVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &xListener) override
Definition: unoobj2.cxx:1468
static css::uno::Reference< css::text::XTextContent > CreateXParagraph(SwDoc &rDoc, SwTextNode *pTextNode, css::uno::Reference< css::text::XText > const &xParentText=nullptr, const sal_Int32 nSelStart=-1, const sal_Int32 nSelEnd=-1)
void Invalidate()
Definition: unoobj2.cxx:777
const SwPosition * GetMark() const
Definition: pam.hxx:209
SwFrameFormat & GetFirstMaster()
Definition: pagedesc.hxx:240
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1213
sal_Int64 n
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Closes undo block.
Provides access to the marks of a document.
const WhichRangesContainer & GetRanges() const
bool Left(sal_uInt16 nCnt)
Definition: swcrsr.hxx:172
Definition: doc.hxx:188
SwMoveFnCollection const & fnParaStart
Definition: paminit.cxx:46
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
Definition: unoobj2.cxx:1008
constexpr TypedWhichId< SwFormatFlyCnt > RES_TXTATR_FLYCNT(57)
virtual const SwPosition & GetMarkPos() const =0
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
UnoActionContext(SwDoc *const pDoc)
Definition: unoobj2.cxx:184
SwNode & GetNode() const
Definition: ndindex.hxx:119
Impl(SwDoc &rDoc, const enum RangePosition eRange, SwFrameFormat *const pTableOrSectionFormat, const uno::Reference< text::XText > &xParent=nullptr)
Definition: unoobj2.cxx:675
Content, content of frame (header, footer, fly).
Definition: fmtcntnt.hxx:31
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1794
Dialog to specify the properties of date form field.
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:144
virtual bool DeleteAndJoin(SwPaM &, const bool bForceJoinNext=false)=0
complete delete of a given PaM
css::uno::Any GetPropertyDefault(SwPaM const &rPaM, const SfxItemPropertySet &rPropSet, std::u16string_view rPropertyName)
Definition: unoobj.cxx:2024
virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates(const css::uno::Sequence< OUString > &rPropertyNames) override
Definition: unoobj2.cxx:1491
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:315
EmbeddedObjectRef * pObject
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
bool SelectPaM(SwPaM &rPaM)
make rPaM select the paragraph
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:203
void MoveTo(value_type *pDestRing)
Removes this item from its current ring container and adds it to another ring container.
Definition: ring.hxx:135
const SwFrameFormats * GetSpzFrameFormats() const
Definition: doc.hxx:744
SfxHintId GetId() const
SwPosFlyFrames GetAllFlyFormats(const SwPaM *, bool bDrawAlso, bool bAsCharAlso=false) const
Returns positions of all FlyFrames in the document.
Definition: doclay.cxx:505
constexpr TypedWhichId< SwFlyFrameFormat > RES_FLYFRMFMT(156)
void SetString(SwCursor &rCursor, const OUString &rString)
Definition: unoobj2.cxx:1653
const SwTextFootnote * GetTextFootnote() const
Definition: fmtftn.hxx:83
const SwDoc & GetDoc() const
Definition: unoobj2.cxx:767
SwTableNode * GetTableNode()
Definition: node.hxx:600
constexpr TypedWhichId< SwDrawFrameFormat > RES_DRAWFRMFMT(159)
void SetRemainInSection(bool bFlag)
Definition: unocrsr.hxx:65
SwNodeType GetNodeType() const
Definition: node.hxx:145
void GetCursorAttr(SwPaM &rPam, SfxItemSet &rSet, const bool bOnlyTextAttr=false, const bool bGetFromChrFormat=true)
Definition: unoobj2.cxx:296
void UnoRestoreAllActions()
Definition: pagechg.cxx:1961
SwIndex nContent
Definition: pam.hxx:38
static void lcl_RemoveImpl(SwDoc *const pDoc)
Definition: unoobj2.cxx:207
Footer, for pageformats Client of FrameFormat describing the footer.
Definition: fmthdft.hxx:64
bool GetPositions(SwPaM &rToFill,::sw::TextRangeMode eMode=::sw::TextRangeMode::RequireTextNode) const
Definition: unoobj2.cxx:1066
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.
constexpr TypedWhichId< SfxUInt16Item > RES_PARATR_OUTLINELEVEL(79)
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
TextRangeMode
static bool isTextBox(const SwFrameFormat *pFormat, sal_uInt16 nType)
Is the frame format a text box?
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
virtual void SAL_CALL setPropertyToDefault(const OUString &rPropertyName) override
Definition: unoobj2.cxx:1505
const SwTable & GetTable() const
Definition: node.hxx:499
void GetTextFromPam(SwPaM &rPam, OUString &rBuffer, SwRootFrame const *pLayout=nullptr)
Definition: unoobj.cxx:126
static SwTableNode * lcl_FindTopLevelTable(SwTableNode *const pTableNode, SwTable const *const pOwnTable)
! compare to SwShellTableCursor::FillRects() in viscrs.cxx
Definition: unoobj2.cxx:489
size_type size() const
const ::sw::mark::IMark * GetBookmark() const
Definition: unoobj2.cxx:713
SwPaM * GetNext()
Definition: pam.hxx:264
void Normalize(bool bPointFirst=true)
Normalizes PaM, i.e.
Definition: pam.cxx:541
Specific frame formats (frames, DrawObjects).
void SelectPam(SwPaM &rPam, const bool bExpand)
Definition: unoobj.cxx:111
bool IsOLENode() const
Definition: node.hxx:653
static bool lcl_CursorIsInSection(SwUnoCursor const *const pUnoCursor, SwStartNode const *const pOwnStartNode)
Definition: unoobj2.cxx:505
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
Definition: unoobj2.cxx:924
void SetPropertyToDefault(SwPaM &rPaM, const SfxItemPropertySet &rPropSet, std::u16string_view rPropertyName)
Definition: unoobj.cxx:1985
virtual std::unique_ptr< ILazyDeleter > deleteMark(const IDocumentMarkAccess::const_iterator_t &ppMark)=0
Deletes a mark.
SwTableSortBoxes & GetTabSortBoxes()
Definition: swtable.hxx:261
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: unoobj2.cxx:944
void EndListeningAll()
virtual void SAL_CALL makeRedline(const OUString &rRedlineType, const css::uno::Sequence< css::beans::PropertyValue > &RedlineProperties) override
Definition: unoobj2.cxx:1535
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
void DeleteAndInsert(const OUString &rText, const bool bForceExpandHints)
Definition: unoobj2.cxx:802
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:504
SwXTextRange(SwPaM const &rPam, const css::uno::Reference< css::text::XText > &xParent, const enum RangePosition eRange=RANGE_IN_TEXT)
static SwTable * FindTable(SwFrameFormat const *const pFormat)
Definition: swtable.cxx:1869
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
Definition: unoobj2.cxx:1429
virtual css::beans::PropertyState SAL_CALL getPropertyState(const OUString &rPropertyName) override
Definition: unoobj2.cxx:1476
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
Style of a layout element.
Definition: frmfmt.hxx:58
void UpdateOutlineNode(SwNode &rNd)
Update all Nodes - Rule/Format-Change.
Definition: ndnum.cxx:39
virtual SwUndoId StartUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Opens undo block.
void SetMark(::sw::mark::IMark &rMark)
Definition: unoobj2.cxx:714
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:81
int i
bool GoInNode(SwPaM &rPam, SwMoveFnCollection const &fnMove)
Definition: pam.cxx:961
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:132
SwDoc & GetDoc()
Definition: node.hxx:212
const SwPosition * GetPoint() const
Definition: pam.hxx:207
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:206
RndStdIds GetAnchorId() const
Definition: fmtanchr.hxx:65
const SwPageDesc & GetPageDesc(const size_t i) const
Definition: doc.hxx:881
const SfxItemPropertySet & m_rPropSet
Definition: unoobj2.cxx:668
const SwPosition * GetContentAnchor() const
Definition: fmtanchr.hxx:67
virtual void SAL_CALL setString(const OUString &rString) override
Definition: unoobj2.cxx:1059
bool GetParaAttr(SfxItemSet &rSet, sal_Int32 nStt, sal_Int32 nEnd, const bool bOnlyTextAttr=false, const bool bGetFromChrFormat=true, const bool bMergeIndentValuesOfNumRule=false, SwRootFrame const *pLayout=nullptr) const
Query the attributes of textnode over the range.
Definition: thints.cxx:2055
void CollectFrameAtNode(const SwNodeIndex &rIdx, FrameClientSortList_t &rFrames, const bool bAtCharAnchoredObjs)
Definition: unoobj2.cxx:137
SetAttrMode
Definition: swtypes.hxx:132
SwContentNode * GetContentNode()
Definition: node.hxx:616
FlyAnchors.
Definition: fmtanchr.hxx:34
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
Definition: pam.hxx:205
std::deque< std::shared_ptr< sw::FrameClient > > FrameClientList_t
UnoActionRemoveContext(SwDoc *const pDoc)
Definition: unoobj2.cxx:217
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
virtual void SAL_CALL addPropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: unoobj2.cxx:1444
size_t GetPageDescCnt() const
Definition: doc.hxx:880
unsigned char sal_Bool
virtual css::uno::Reference< css::text::XTextCursor > CreateCursor()
Definition: unotext.cxx:177
css::uno::Reference< css::frame::XModel3 > GetBaseModel() const
virtual sal_Bool SAL_CALL hasElements() override
Definition: unoobj2.cxx:1390
bool IsNoTextNode() const
Definition: node.hxx:649
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
Definition: unoobj2.cxx:971
virtual void SAL_CALL addVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &xListener) override
Definition: unoobj2.cxx:1460
Marks a node in the document model.
Definition: ndindex.hxx:31
virtual ~Impl() override
Definition: unoobj2.cxx:696
css::uno::Type const & get()
static SwDoc * lcl_IsNewStyleTable(SwUnoTableCursor const &rCursor)
Definition: unoobj2.cxx:223
ring_container GetRingContainer()
Definition: ring.hxx:240
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createContentEnumeration(const OUString &rServiceName) override
Definition: unoobj2.cxx:1337
void MergeValues(const SfxItemSet &rSet)
SwStartNodeType GetStartNodeType() const
Definition: node.hxx:329
const SwDoc * GetDoc() const
The document is set in SwAttrPool now, therefore you always can access it.
Definition: format.hxx:123
bool StartListening(SvtBroadcaster &rBroadcaster)
virtual ~SwXTextRange() override
Definition: unoobj2.cxx:763
SfxItemPool * GetPool() const
const SwFormatFootnote & GetFootnote() const
Definition: txatbase.hxx:204
virtual void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue) override
Definition: unoobj2.cxx:1413
virtual void SAL_CALL removePropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: unoobj2.cxx:1452
virtual css::uno::Type SAL_CALL getElementType() override
Definition: unoobj2.cxx:1385
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:405
enumrange< T >::Iterator end(enumrange< T >)
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:111
const SwPosition * Start() const
Definition: pam.hxx:212
bool XTextRangeToSwPaM(SwUnoInternalPaM &rToFill, const uno::Reference< text::XTextRange > &xTextRange,::sw::TextRangeMode const eMode)
Definition: unoobj2.cxx:1107
enum RangePosition m_eRangePosition
Definition: unoobj2.cxx:669
const SwNodeIndex * GetContentIdx() const
Definition: fmtcntnt.hxx:46
virtual OUString SAL_CALL getImplementationName() override
Definition: unoobj2.cxx:919
SvtBroadcaster & GetNotifier()
Definition: calbck.hxx:99
virtual const SwPaM * GetPaM() const =0
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: unoobj2.cxx:1403
sal_uInt16 Which() const
for Querying of Writer-functions.
Definition: format.hxx:82
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: unoobj2.cxx:905
css::uno::Any GetPropertyValue(SwPaM &rPaM, const SfxItemPropertySet &rPropSet, std::u16string_view rPropertyName)
Definition: unoobj.cxx:1704
SwFrameFormat & GetMaster()
Definition: pagedesc.hxx:238
sal_uLong EndOfSectionIndex() const
Definition: node.hxx:678
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
const SwFrameFormat * m_pTableOrSectionFormat
Definition: unoobj2.cxx:672
const SwStartNode * GetSttNd() const
Definition: swtable.hxx:448
ParaFrameMode
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
void reset(std::shared_ptr< SwUnoCursor > pNew)
Definition: unocrsr.hxx:157
void UnoRemoveAllActions()
Certain UNO Actions (e.g.
Definition: pagechg.cxx:1926
sal_uInt32 GetOrder() const
Definition: fmtanchr.hxx:69
css::uno::Sequence< css::beans::PropertyState > GetPropertyStates(SwPaM &rPaM, const SfxItemPropertySet &rPropSet, const css::uno::Sequence< OUString > &rPropertyNames, const SwGetPropertyStatesCaller eCaller=SW_PROPERTY_STATE_CALLER_DEFAULT)
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:59
SwFrameFormat & GetFirstLeft()
Definition: pagedesc.hxx:241
static bool lcl_IsStartNodeInFormat(const bool bHeader, SwStartNode const *const pSttNode, SwFrameFormat const *const pFrameFormat, SwFrameFormat *&rpFormat)
Definition: unoobj2.cxx:1177
sal_Int32 GetIndex() const
Definition: index.hxx:91
void SetPropertyValue(SwPaM &rPaM, const SfxItemPropertySet &rPropSet, const OUString &rPropertyName, const css::uno::Any &rValue, const SetAttrMode nAttrMode=SetAttrMode::DEFAULT)
SwNodes & GetNodes()
Definition: doc.hxx:409
SwUnoCursor & GetCursor() const
Definition: unoport.hxx:229
const SwPosition * End() const
Definition: pam.hxx:217
virtual css::uno::Sequence< OUString > SAL_CALL getAvailableServiceNames() override
Definition: unoobj2.cxx:1396
const ::sw::mark::IMark * m_pMark
Definition: unoobj2.cxx:673
bool GoNextPara(SwPaM &rPam, SwMoveFnCollection const &aPosPara)
Definition: pam.cxx:1044
static SW_DLLPUBLIC css::uno::Reference< css::text::XTextFrame > CreateXTextFrame(SwDoc &rDoc, SwFrameFormat *pFrameFormat)
Definition: unoframe.cxx:3184
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:395
SwUnoPropertyMapProvider aSwMapProvider
Definition: unomap1.cxx:87
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: unoobj2.cxx:1619
static rtl::Reference< SwXParaFrameEnumeration > Create(const SwPaM &rPaM, const enum ParaFrameMode eParaFrameMode, SwFrameFormat *const pFormat=nullptr)
Definition: unoobj2.cxx:1722
void makeRedline(SwPaM const &rPaM, std::u16string_view rRedlineType, const uno::Sequence< beans::PropertyValue > &rRedlineProperties)
virtual const SwPosition & GetMarkEnd() const =0
static css::uno::Reference< css::text::XFootnote > CreateXFootnote(SwDoc &rDoc, SwFormatFootnote *pFootnoteFormat, bool isEndnote=false)
Definition: unoftn.cxx:144
Header, for PageFormats Client of FrameFormat describing the header.
Definition: fmthdft.hxx:33
virtual void Notify(const SfxHint &) override
Definition: unoobj2.cxx:726
Format of a fly content.
Definition: fmtflcnt.hxx:32
SwStartNodeType
Definition: ndtyp.hxx:50
const SwFormatContent & GetContent(bool=true) const
Definition: fmtcntnt.hxx:55
virtual void CallSwClientNotify(const SfxHint &rHint) const override
Definition: calbck.cxx:326
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:58
~UnoActionRemoveContext() COVERITY_NOEXCEPT_FALSE
Definition: unoobj2.cxx:242
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:357
void SetCursorAttr(SwPaM &rPam, const SfxItemSet &rSet, const SetAttrMode nAttrMode, const bool bTableMode=false)
Definition: unoobj2.cxx:254
constexpr TypedWhichId< SwFormatFooter > RES_FOOTER(97)
SwNodeIndex * GetStartNode() const
Definition: txtftn.hxx:41
SwFootnoteIdxs & GetFootnoteIdxs()
Definition: doc.hxx:634
::sw::UnoImplPtr< Impl > m_pImpl
SwFrameFormat * GetFrameFormat() const
Definition: fmtflcnt.hxx:45
Reference< XModel > xModel
RndStdIds
void InvalidateAllItems()
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: unoobj2.cxx:1361
size_t size() const
SwDoc & GetDoc() const
Definition: pam.hxx:243
bool DocInsertStringSplitCR(SwDoc &rDoc, const SwPaM &rNewCursor, const OUString &rText, const bool bForceExpandHints)
static css::uno::Reference< css::text::XTextContent > CreateXTextEmbeddedObject(SwDoc &rDoc, SwFrameFormat *pFrameFormat)
Definition: unoframe.cxx:3473
virtual const SwPosition & GetMarkStart() const =0
Ends a section of nodes in the document model.
Definition: node.hxx:342
virtual SwUnoCursor * GetCursor()=0
void StartAllAction()
Set up Start-/EndAction for all Shells on an as high as possible (Shell section) level.
Definition: pagechg.cxx:1892
static css::uno::Reference< css::text::XTextContent > CreateXTextGraphicObject(SwDoc &rDoc, SwFrameFormat *pFrameFormat)
Definition: unoframe.cxx:3426
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:478
css::beans::PropertyState GetPropertyState(SwPaM &rPaM, const SfxItemPropertySet &rPropSet, const OUString &rPropertyName)
Definition: unoobj.cxx:1952
const SwAttrSet & GetAttrSet() const
For querying the attribute array.
Definition: format.hxx:120
static css::uno::Reference< css::text::XTextRange > CreateXTextRange(SwDoc &rDoc, const SwPosition &rPos, const SwPosition *const pMark)
Definition: unoobj2.cxx:1210
static rtl::Reference< SwXParagraphEnumeration > Create(css::uno::Reference< css::text::XText > const &xParent, const std::shared_ptr< SwUnoCursor > &pCursor, const CursorType eType, SwTableBox const *const pTableBox=nullptr)
Definition: unoobj2.cxx:449
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
std::pair< const_iterator, bool > insert(Value &&x)
void EndAllAction(bool bVirDev=false)
Definition: pagechg.cxx:1904
const css::uno::Sequence< sal_Int8 > & getSeq() const
virtual css::uno::Any SAL_CALL getPropertyDefault(const OUString &rPropertyName) override
Definition: unoobj2.cxx:1520
bool IsNewModel() const
Definition: swtable.hxx:187
virtual bool IsExpanded() const =0
void DeepCopyPaM(SwPaM const &rSource, SwPaM &rTarget)
Definition: unoobj2.cxx:78
bool DeleteRowCol(const SwSelBoxes &rBoxes, RowColMode eMode=RowColMode::DeleteRow)
Definition: ndtbl.cxx:1954
void SetPositions(SwPaM const &rPam)
Definition: unoobj2.cxx:782
virtual OUString SAL_CALL getString() override
Definition: unoobj2.cxx:1044
SwFrameFormat * GetFlyFormat() const
If node is in a fly return the respective format.
Definition: node.cxx:719
uno::Reference< text::XText > CreateParentXText(SwDoc &rDoc, const SwPosition &rPos)
Definition: unoobj2.cxx:1231
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:850
virtual const SwPosition & GetOtherMarkPos() const =0
SwTableNode * GetTableNode() const
Definition: swtable.cxx:1876
Base class of the Writer document model elements.
Definition: node.hxx:80