LibreOffice Module sw (master)  1
doclay.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 <hintids.hxx>
21 #include <sot/exchange.hxx>
22 #include <svx/svdpage.hxx>
23 #include <editeng/keepitem.hxx>
24 #include <editeng/ulspitem.hxx>
25 #include <editeng/lrspitem.hxx>
26 #include <editeng/boxitem.hxx>
27 #include <editeng/shaditem.hxx>
28 #include <editeng/protitem.hxx>
29 #include <editeng/opaqitem.hxx>
30 #include <svx/svdouno.hxx>
31 #include <editeng/frmdiritem.hxx>
32 #include <swmodule.hxx>
33 #include <modcfg.hxx>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/embed/XEmbeddedObject.hpp>
36 #include <SwStyleNameMapper.hxx>
37 #include <drawdoc.hxx>
38 #include <fchrfmt.hxx>
39 #include <frmatr.hxx>
40 #include <txatbase.hxx>
41 #include <fmtfld.hxx>
42 #include <fmtornt.hxx>
43 #include <fmtcntnt.hxx>
44 #include <fmtanchr.hxx>
45 #include <fmtfsize.hxx>
46 #include <fmtsrnd.hxx>
47 #include <fmtflcnt.hxx>
48 #include <frmfmt.hxx>
49 #include <pam.hxx>
50 #include <ndtxt.hxx>
51 #include <ndnotxt.hxx>
52 #include <ndole.hxx>
53 #include <doc.hxx>
54 #include <IDocumentUndoRedo.hxx>
59 #include <IDocumentState.hxx>
62 #include <rootfrm.hxx>
63 #include <pagefrm.hxx>
64 #include <cntfrm.hxx>
65 #include <txtfrm.hxx>
66 #include <notxtfrm.hxx>
67 #include <flyfrm.hxx>
68 #include <dflyobj.hxx>
69 #include <dcontact.hxx>
70 #include <swundo.hxx>
71 #include <flypos.hxx>
72 #include <UndoInsert.hxx>
73 #include <expfld.hxx>
74 #include <poolfmt.hxx>
75 #include <docary.hxx>
76 #include <swtable.hxx>
77 #include <tblsel.hxx>
78 #include <txtftn.hxx>
79 #include <ftnidx.hxx>
80 #include <ftninfo.hxx>
81 #include <pagedesc.hxx>
82 #include <strings.hrc>
83 #include <frameformats.hxx>
84 #include <tools/datetimeutils.hxx>
85 
86 #include <sortedobjs.hxx>
87 
88 #include <string_view>
89 #include <vector>
90 
91 using namespace ::com::sun::star;
92 
93 #define DEF_FLY_WIDTH 2268 // Default width for FlyFrames (2268 == 4cm)
94 
95 static bool lcl_IsItemSet(const SwContentNode & rNode, sal_uInt16 which)
96 {
97  bool bResult = false;
98 
99  if (SfxItemState::SET == rNode.GetSwAttrSet().GetItemState(which))
100  bResult = true;
101 
102  return bResult;
103 }
104 
105 SdrObject* SwDoc::CloneSdrObj( const SdrObject& rObj, bool bMoveWithinDoc,
106  bool bInsInPage )
107 {
108  // #i52858# - method name changed
110  if( !pPg )
111  {
114  }
115 
116  // TTTT Clone directly to target SdrModel
117  SdrObject *pObj(rObj.CloneSdrObject(*getIDocumentDrawModelAccess().GetDrawModel()));
118 
119  if( bMoveWithinDoc && SdrInventor::FmForm == pObj->GetObjInventor() )
120  {
121  // We need to preserve the Name for Controls
122  uno::Reference< awt::XControlModel > xModel = static_cast<SdrUnoObj*>(pObj)->GetUnoControlModel();
123  uno::Any aVal;
124  uno::Reference< beans::XPropertySet > xSet(xModel, uno::UNO_QUERY);
125  const OUString sName("Name");
126  if( xSet.is() )
127  aVal = xSet->getPropertyValue( sName );
128  if( bInsInPage )
129  pPg->InsertObjectThenMakeNameUnique( pObj );
130  if( xSet.is() )
131  xSet->setPropertyValue( sName, aVal );
132  }
133  else if( bInsInPage )
134  pPg->InsertObjectThenMakeNameUnique( pObj );
135 
136  // For drawing objects: set layer of cloned object to invisible layer
137  SdrLayerID nLayerIdForClone = rObj.GetLayer();
138  if ( dynamic_cast<const SwFlyDrawObj*>( pObj) == nullptr &&
139  dynamic_cast<const SwVirtFlyDrawObj*>( pObj) == nullptr &&
140  typeid(SdrObject) != typeid(pObj) )
141  {
142  if ( getIDocumentDrawModelAccess().IsVisibleLayerId( nLayerIdForClone ) )
143  {
144  nLayerIdForClone = getIDocumentDrawModelAccess().GetInvisibleLayerIdByVisibleOne( nLayerIdForClone );
145  }
146  }
147  pObj->SetLayer( nLayerIdForClone );
148 
149  return pObj;
150 }
151 
153  const SwContentNode& rNode,
154  RndStdIds eRequestId,
155  const SfxItemSet* pFlySet,
156  SwFrameFormat* pFrameFormat )
157 {
158  if( !pFrameFormat )
160 
161  OUString sName;
162  if( !mbInReading )
163  switch( rNode.GetNodeType() )
164  {
165  case SwNodeType::Grf: sName = GetUniqueGrfName(); break;
166  case SwNodeType::Ole: sName = GetUniqueOLEName(); break;
167  default: sName = GetUniqueFrameName(); break;
168  }
169  SwFlyFrameFormat* pFormat = MakeFlyFrameFormat( sName, pFrameFormat );
170 
171  // Create content and connect to the format.
172  // Create ContentNode and put it into the autotext selection.
173  SwNodeRange aRange( GetNodes().GetEndOfAutotext(), -1,
174  GetNodes().GetEndOfAutotext() );
175  GetNodes().SectionDown( &aRange, SwFlyStartNode );
176 
177  pFormat->SetFormatAttr( SwFormatContent( rNode.StartOfSectionNode() ));
178 
179  const SwFormatAnchor* pAnchor = nullptr;
180  if( pFlySet )
181  {
182  pFlySet->GetItemState( RES_ANCHOR, false,
183  reinterpret_cast<const SfxPoolItem**>(&pAnchor) );
184  if( SfxItemState::SET == pFlySet->GetItemState( RES_CNTNT, false ))
185  {
186  SfxItemSet aTmpSet( *pFlySet );
187  aTmpSet.ClearItem( RES_CNTNT );
188  pFormat->SetFormatAttr( aTmpSet );
189  }
190  else
191  pFormat->SetFormatAttr( *pFlySet );
192  }
193 
194  // Anchor not yet set?
195  RndStdIds eAnchorId;
196  // #i107811# Assure that at-page anchored fly frames have a page num or a
197  // content anchor set.
198  if ( !pAnchor ||
199  ( RndStdIds::FLY_AT_PAGE != pAnchor->GetAnchorId() &&
200  !pAnchor->GetContentAnchor() ) ||
201  ( RndStdIds::FLY_AT_PAGE == pAnchor->GetAnchorId() &&
202  !pAnchor->GetContentAnchor() &&
203  pAnchor->GetPageNum() == 0 ) )
204  {
205  // set it again, needed for Undo
206  SwFormatAnchor aAnch( pFormat->GetAnchor() );
207  if (pAnchor && (RndStdIds::FLY_AT_FLY == pAnchor->GetAnchorId()))
208  {
209  SwPosition aPos( *rAnchPos.nNode.GetNode().FindFlyStartNode() );
210  aAnch.SetAnchor( &aPos );
211  eAnchorId = RndStdIds::FLY_AT_FLY;
212  }
213  else
214  {
215  if( eRequestId != aAnch.GetAnchorId() &&
216  SfxItemState::SET != pFormat->GetItemState( RES_ANCHOR ) )
217  {
218  aAnch.SetType( eRequestId );
219  }
220 
221  eAnchorId = aAnch.GetAnchorId();
222  if ( RndStdIds::FLY_AT_PAGE != eAnchorId || !pAnchor || aAnch.GetPageNum() == 0)
223  {
224  aAnch.SetAnchor( &rAnchPos );
225  }
226  }
227  pFormat->SetFormatAttr( aAnch );
228  }
229  else
230  eAnchorId = pFormat->GetAnchor().GetAnchorId();
231 
232  if ( RndStdIds::FLY_AS_CHAR == eAnchorId )
233  {
234  const sal_Int32 nStt = rAnchPos.nContent.GetIndex();
235  SwTextNode * pTextNode = rAnchPos.nNode.GetNode().GetTextNode();
236 
237  OSL_ENSURE(pTextNode!= nullptr, "There should be a SwTextNode!");
238 
239  if (pTextNode != nullptr)
240  {
241  SwFormatFlyCnt aFormat( pFormat );
242  // may fail if there's no space left or header/ftr
243  if (!pTextNode->InsertItem(aFormat, nStt, nStt))
244  { // pFormat is dead now
245  return nullptr;
246  }
247  }
248  }
249 
250  if( SfxItemState::SET != pFormat->GetAttrSet().GetItemState( RES_FRM_SIZE ))
251  {
253  const SwNoTextNode* pNoTextNode = rNode.GetNoTextNode();
254  if( pNoTextNode )
255  {
256  // Set size
257  Size aSize( pNoTextNode->GetTwipSize() );
258  if( MINFLY > aSize.Width() )
259  aSize.setWidth( DEF_FLY_WIDTH );
260  aFormatSize.SetWidth( aSize.Width() );
261  if( aSize.Height() )
262  {
263  aFormatSize.SetHeight( aSize.Height() );
264  aFormatSize.SetHeightSizeType( SwFrameSize::Fixed );
265  }
266  }
267  pFormat->SetFormatAttr( aFormatSize );
268  }
269 
270  // Set up frames
271  if( getIDocumentLayoutAccess().GetCurrentViewShell() )
272  pFormat->MakeFrames(); // ???
273 
274  if (GetIDocumentUndoRedo().DoesUndo())
275  {
276  sal_uLong nNodeIdx = rAnchPos.nNode.GetIndex();
277  const sal_Int32 nCntIdx = rAnchPos.nContent.GetIndex();
279  std::make_unique<SwUndoInsLayFormat>( pFormat, nNodeIdx, nCntIdx ));
280  }
281 
283  return pFormat;
284 }
285 
287  const SwPosition* pAnchorPos,
288  const SfxItemSet* pFlySet,
289  SwFrameFormat* pFrameFormat, bool bCalledFromShell )
290 {
291  SwFlyFrameFormat* pFormat = nullptr;
292  if ( !pAnchorPos && (RndStdIds::FLY_AT_PAGE != eAnchorType) )
293  {
294  const SwFormatAnchor* pAnch;
295  if( (pFlySet && SfxItemState::SET == pFlySet->GetItemState(
296  RES_ANCHOR, false, reinterpret_cast<const SfxPoolItem**>(&pAnch) )) ||
297  ( pFrameFormat && SfxItemState::SET == pFrameFormat->GetItemState(
298  RES_ANCHOR, true, reinterpret_cast<const SfxPoolItem**>(&pAnch) )) )
299  {
300  if ( RndStdIds::FLY_AT_PAGE != pAnch->GetAnchorId() )
301  {
302  pAnchorPos = pAnch->GetContentAnchor();
303  }
304  }
305  }
306 
307  if (pAnchorPos)
308  {
309  if( !pFrameFormat )
311 
312  sal_uInt16 nCollId = static_cast<sal_uInt16>(
314 
315  /* If there is no adjust item in the paragraph style for the content node of the new fly section
316  propagate an existing adjust item at the anchor to the new content node. */
317  SwContentNode * pNewTextNd = GetNodes().MakeTextNode
318  (SwNodeIndex( GetNodes().GetEndOfAutotext()),
319  getIDocumentStylePoolAccess().GetTextCollFromPool( nCollId ));
320  SwContentNode * pAnchorNode = pAnchorPos->nNode.GetNode().GetContentNode();
321  // pAnchorNode from cursor must be valid, unless a whole table is selected (in which
322  // case the node is not a content node, and pAnchorNode is nullptr). In the latter case,
323  // bCalledFromShell is false.
324  assert(!bCalledFromShell || pAnchorNode);
325 
326  const SfxPoolItem * pItem = nullptr;
327 
328  if (bCalledFromShell && !lcl_IsItemSet(*pNewTextNd, RES_PARATR_ADJUST) &&
329  SfxItemState::SET == pAnchorNode->GetSwAttrSet().
330  GetItemState(RES_PARATR_ADJUST, true, &pItem))
331  {
332  pNewTextNd->SetAttr(*pItem);
333  }
334 
335  pFormat = MakeFlySection_( *pAnchorPos, *pNewTextNd,
336  eAnchorType, pFlySet, pFrameFormat );
337  }
338  return pFormat;
339 }
340 
342  const SwSelBoxes* pSelBoxes,
343  SwFrameFormat *pParent )
344 {
345  const SwFormatAnchor& rAnch = rSet.Get( RES_ANCHOR );
346 
348 
349  SwFlyFrameFormat* pFormat = MakeFlySection( rAnch.GetAnchorId(), rPam.GetPoint(),
350  &rSet, pParent );
351 
352  // If content is selected, it becomes the new frame's content.
353  // Namely, it is moved into the NodeArray's appropriate section.
354 
355  if( pFormat )
356  {
357  do { // middle check loop
358  const SwFormatContent &rContent = pFormat->GetContent();
359  OSL_ENSURE( rContent.GetContentIdx(), "No content prepared." );
360  SwNodeIndex aIndex( *(rContent.GetContentIdx()), 1 );
361  SwContentNode *pNode = aIndex.GetNode().GetContentNode();
362 
363  // Attention: Do not create an index on the stack, or we
364  // cannot delete ContentNode in the end!
365  SwPosition aPos( aIndex );
366  aPos.nContent.Assign( pNode, 0 );
367 
368  if( pSelBoxes && !pSelBoxes->empty() )
369  {
370  // Table selection
371  // Copy parts of a table: create a table with the same width as the
372  // original one and move (copy and delete) the selected boxes.
373  // The size is corrected on a percentage basis.
374 
375  SwTableNode* pTableNd = const_cast<SwTableNode*>((*pSelBoxes)[0]->
376  GetSttNd()->FindTableNode());
377  if( !pTableNd )
378  break;
379 
380  SwTable& rTable = pTableNd->GetTable();
381 
382  // Did we select the whole table?
383  if( pSelBoxes->size() == rTable.GetTabSortBoxes().size() )
384  {
385  // move the whole table
386  SwNodeRange aRg( *pTableNd, 0, *pTableNd->EndOfSectionNode(), 1 );
387 
388  // If we move the whole table and it is located within a
389  // FlyFrame, the we create a TextNode after it.
390  // So that this FlyFrame is preserved.
391  if( aRg.aEnd.GetNode().IsEndNode() )
392  GetNodes().MakeTextNode( aRg.aStart,
394 
396  }
397  else
398  {
399  rTable.MakeCopy(*this, aPos, *pSelBoxes);
400  // Don't delete a part of a table with row span!!
401  // You could delete the content instead -> ToDo
402  //rTable.DeleteSel( this, *pSelBoxes, 0, 0, true, true );
403  }
404 
405  // If the table is within the frame, then copy without the following TextNode
406  aIndex = rContent.GetContentIdx()->GetNode().EndOfSectionIndex() - 1;
407  OSL_ENSURE( aIndex.GetNode().GetTextNode(),
408  "a TextNode should be here" );
409  aPos.nContent.Assign( nullptr, 0 ); // Deregister index!
410  GetNodes().Delete( aIndex );
411 
412  // This is a hack: whilst FlyFrames/Headers/Footers are not undoable we delete all Undo objects
413  if( GetIDocumentUndoRedo().DoesUndo() )
414  {
416  }
417  }
418  else
419  {
420  // copy all Pams and then delete all
421  bool bOldFlag = mbCopyIsMove;
422  bool const bOldUndo = GetIDocumentUndoRedo().DoesUndo();
423  bool const bOldRedlineMove(getIDocumentRedlineAccess().IsRedlineMove());
424  mbCopyIsMove = true;
425  GetIDocumentUndoRedo().DoUndo(false);
427  for(const SwPaM& rTmp : rPam.GetRingContainer())
428  {
429  if( rTmp.HasMark() &&
430  *rTmp.GetPoint() != *rTmp.GetMark() )
431  {
432  // aPos is the newly created fly section, so definitely outside rPam, it's pointless to check that again.
433  getIDocumentContentOperations().CopyRange(*const_cast<SwPaM*>(&rTmp), aPos, SwCopyFlags::IsMoveToFly);
434  }
435  }
436  getIDocumentRedlineAccess().SetRedlineMove(bOldRedlineMove);
437  mbCopyIsMove = bOldFlag;
438  GetIDocumentUndoRedo().DoUndo(bOldUndo);
439 
440  for(const SwPaM& rTmp : rPam.GetRingContainer())
441  {
442  if( rTmp.HasMark() &&
443  *rTmp.GetPoint() != *rTmp.GetMark() )
444  {
445  getIDocumentContentOperations().DeleteAndJoin( *const_cast<SwPaM*>(&rTmp) );
446  }
447  }
448  }
449  } while( false );
450  }
451 
453 
455 
456  return pFormat;
457 }
458 
459 
460 /*
461  * paragraph frames - o.k. if the PaM includes the paragraph from the beginning
462  * to the beginning of the next paragraph at least
463  * frames at character - o.k. if the PaM starts at least at the same position
464  * as the frame
465  */
466 static bool lcl_TstFlyRange( const SwPaM* pPam, const SwPosition* pFlyPos,
467  RndStdIds nAnchorId )
468 {
469  bool bOk = false;
470  const SwPaM* pTmp = pPam;
471  do {
472  const sal_uInt32 nFlyIndex = pFlyPos->nNode.GetIndex();
473  const SwPosition* pPaMStart = pTmp->Start();
474  const SwPosition* pPaMEnd = pTmp->End();
475  const sal_uInt32 nPamStartIndex = pPaMStart->nNode.GetIndex();
476  const sal_uInt32 nPamEndIndex = pPaMEnd->nNode.GetIndex();
477  if (RndStdIds::FLY_AT_PARA == nAnchorId)
478  bOk = (nPamStartIndex < nFlyIndex && nPamEndIndex > nFlyIndex) ||
479  (((nPamStartIndex == nFlyIndex) && (pPaMStart->nContent.GetIndex() == 0)) &&
480  (nPamEndIndex > nFlyIndex));
481  else
482  {
483  const sal_Int32 nFlyContentIndex = pFlyPos->nContent.GetIndex();
484  const sal_Int32 nPamEndContentIndex = pPaMEnd->nContent.GetIndex();
485  bOk = (nPamStartIndex < nFlyIndex &&
486  (( nPamEndIndex > nFlyIndex )||
487  ((nPamEndIndex == nFlyIndex) &&
488  (nPamEndContentIndex > nFlyContentIndex))) )
489  ||
490  (((nPamStartIndex == nFlyIndex) &&
491  (pPaMStart->nContent.GetIndex() <= nFlyContentIndex)) &&
492  ((nPamEndIndex > nFlyIndex) ||
493  (nPamEndContentIndex > nFlyContentIndex )));
494  }
495 
496  if( bOk )
497  break;
498  pTmp = pTmp->GetNext();
499  } while( pPam != pTmp );
500  return bOk;
501 }
502 
503 SwPosFlyFrames SwDoc::GetAllFlyFormats( const SwPaM* pCmpRange, bool bDrawAlso,
504  bool bAsCharAlso ) const
505 {
506  SwPosFlyFrames aRetval;
507 
508  // collect all anchored somehow to paragraphs
509  for( auto pFly : *GetSpzFrameFormats() )
510  {
511  bool bDrawFormat = bDrawAlso && RES_DRAWFRMFMT == pFly->Which();
512  bool bFlyFormat = RES_FLYFRMFMT == pFly->Which();
513  if( bFlyFormat || bDrawFormat )
514  {
515  const SwFormatAnchor& rAnchor = pFly->GetAnchor();
516  SwPosition const*const pAPos = rAnchor.GetContentAnchor();
517  if (pAPos &&
518  ((RndStdIds::FLY_AT_PARA == rAnchor.GetAnchorId()) ||
519  (RndStdIds::FLY_AT_FLY == rAnchor.GetAnchorId()) ||
520  (RndStdIds::FLY_AT_CHAR == rAnchor.GetAnchorId()) ||
521  ((RndStdIds::FLY_AS_CHAR == rAnchor.GetAnchorId()) && bAsCharAlso)))
522  {
523  if( pCmpRange &&
524  !lcl_TstFlyRange( pCmpRange, pAPos, rAnchor.GetAnchorId() ))
525  continue; // not a valid FlyFrame
526  aRetval.insert(std::make_shared<SwPosFlyFrame>(pAPos->nNode, pFly, aRetval.size()));
527  }
528  }
529  }
530 
531  // If we don't have a layout we can't get page anchored FlyFrames.
532  // Also, page anchored FlyFrames are only returned if no range is specified.
533  if( !getIDocumentLayoutAccess().GetCurrentViewShell() || pCmpRange )
534  {
535  return aRetval;
536  }
537 
538  const SwPageFrame *pPage = static_cast<const SwPageFrame*>(getIDocumentLayoutAccess().GetCurrentLayout()->GetLower());
539  while( pPage )
540  {
541  if( pPage->GetSortedObjs() )
542  {
543  const SwSortedObjs &rObjs = *pPage->GetSortedObjs();
544  for(SwAnchoredObject* pAnchoredObj : rObjs)
545  {
546  SwFrameFormat *pFly;
547  if ( dynamic_cast<const SwFlyFrame*>( pAnchoredObj) != nullptr )
548  pFly = &(pAnchoredObj->GetFrameFormat());
549  else if ( bDrawAlso )
550  pFly = &(pAnchoredObj->GetFrameFormat());
551  else
552  continue;
553 
554  const SwFormatAnchor& rAnchor = pFly->GetAnchor();
555  if ((RndStdIds::FLY_AT_PARA != rAnchor.GetAnchorId()) &&
556  (RndStdIds::FLY_AT_FLY != rAnchor.GetAnchorId()) &&
557  (RndStdIds::FLY_AT_CHAR != rAnchor.GetAnchorId()))
558  {
559  const SwContentFrame * pContentFrame = pPage->FindFirstBodyContent();
560  if ( !pContentFrame )
561  {
562  // Oops! An empty page.
563  // In order not to lose the whole frame (RTF) we
564  // look for the last Content before the page.
565  const SwPageFrame *pPrv = static_cast<const SwPageFrame*>(pPage->GetPrev());
566  while ( !pContentFrame && pPrv )
567  {
568  pContentFrame = pPrv->FindFirstBodyContent();
569  pPrv = static_cast<const SwPageFrame*>(pPrv->GetPrev());
570  }
571  }
572  if ( pContentFrame )
573  {
574  SwNodeIndex aIdx( pContentFrame->IsTextFrame()
575  ? *static_cast<SwTextFrame const*>(pContentFrame)->GetTextNodeFirst()
576  : *static_cast<SwNoTextFrame const*>(pContentFrame)->GetNode() );
577  aRetval.insert(std::make_shared<SwPosFlyFrame>(aIdx, pFly, aRetval.size()));
578  }
579  }
580  }
581  }
582  pPage = static_cast<const SwPageFrame*>(pPage->GetNext());
583  }
584 
585  return aRetval;
586 }
587 
588 /* #i6447# changed behaviour if lcl_CpyAttr:
589 
590  If the old item set contains the item to set (no inheritance) copy the item
591  into the new set.
592 
593  If the old item set contains the item by inheritance and the new set
594  contains the item, too:
595  If the two items differ copy the item from the old set to the new set.
596 
597  Otherwise the new set will not be changed.
598 */
599 static void lcl_CpyAttr( SfxItemSet &rNewSet, const SfxItemSet &rOldSet, sal_uInt16 nWhich )
600 {
601  const SfxPoolItem *pOldItem = nullptr;
602 
603  rOldSet.GetItemState( nWhich, false, &pOldItem);
604  if (pOldItem != nullptr)
605  rNewSet.Put( *pOldItem );
606  else
607  {
608  pOldItem = rOldSet.GetItem( nWhich );
609  if (pOldItem != nullptr)
610  {
611  const SfxPoolItem *pNewItem = rNewSet.GetItem( nWhich );
612  if (pNewItem != nullptr)
613  {
614  if (*pOldItem != *pNewItem)
615  rNewSet.Put( *pOldItem );
616  }
617  else {
618  OSL_FAIL("What am I doing here?");
619  }
620  }
621  else {
622  OSL_FAIL("What am I doing here?");
623  }
624  }
625 
626 }
627 
628 static SwFlyFrameFormat *
629 lcl_InsertLabel(SwDoc & rDoc, SwTextFormatColls *const pTextFormatCollTable,
630  SwUndoInsertLabel *const pUndo,
631  SwLabelType const eType, std::u16string_view rText, std::u16string_view rSeparator,
632  const OUString& rNumberingSeparator,
633  const bool bBefore, const sal_uInt16 nId, const sal_uLong nNdIdx,
634  const OUString& rCharacterStyle,
635  const bool bCpyBrd )
636 {
637  ::sw::UndoGuard const undoGuard(rDoc.GetIDocumentUndoRedo());
638 
639  bool bTable = false; // To save some code.
640 
641  // Get the field first, because we retrieve the TextColl via the field's name
642  OSL_ENSURE( nId == USHRT_MAX || nId < rDoc.getIDocumentFieldsAccess().GetFieldTypes()->size(),
643  "FieldType index out of bounds." );
644  SwFieldType *pType = (nId != USHRT_MAX) ? (*rDoc.getIDocumentFieldsAccess().GetFieldTypes())[nId].get() : nullptr;
645  OSL_ENSURE(!pType || pType->Which() == SwFieldIds::SetExp, "wrong Id for Label");
646 
647  SwTextFormatColl * pColl = nullptr;
648  if( pType )
649  {
650  for( auto i = pTextFormatCollTable->size(); i; )
651  {
652  if( (*pTextFormatCollTable)[ --i ]->GetName()==pType->GetName() )
653  {
654  pColl = (*pTextFormatCollTable)[i];
655  break;
656  }
657  }
658  OSL_ENSURE( pColl, "no text collection found" );
659  }
660 
661  if( !pColl )
662  {
664  }
665 
666  SwTextNode *pNew = nullptr;
667  SwFlyFrameFormat* pNewFormat = nullptr;
668 
669  switch ( eType )
670  {
671  case SwLabelType::Table:
672  bTable = true;
673  [[fallthrough]];
674  case SwLabelType::Fly:
675  // At the FlySection's Beginning/End insert the corresponding Node with its Field.
676  // The Frame is created automatically.
677  {
678  SwStartNode *pSttNd = rDoc.GetNodes()[nNdIdx]->GetStartNode();
679  OSL_ENSURE( pSttNd, "No StartNode in InsertLabel." );
680  sal_uLong nNode;
681  if( bBefore )
682  {
683  nNode = pSttNd->GetIndex();
684  if( !bTable )
685  ++nNode;
686  }
687  else
688  {
689  nNode = pSttNd->EndOfSectionIndex();
690  if( bTable )
691  ++nNode;
692  }
693 
694  if( pUndo )
695  pUndo->SetNodePos( nNode );
696 
697  // Create Node for labeling paragraph.
698  SwNodeIndex aIdx( rDoc.GetNodes(), nNode );
699  pNew = rDoc.GetNodes().MakeTextNode( aIdx, pColl );
700  }
701  break;
702 
703  case SwLabelType::Object:
704  {
705  // Destroy Frame,
706  // insert new Frame,
707  // insert the corresponding Node with Field into the new Frame,
708  // insert the old Frame with the Object (Picture/OLE) paragraph-bound into the new Frame,
709  // create Frames.
710 
711  // Get the FlyFrame's Format and decouple the Layout.
712  SwFrameFormat *pOldFormat = rDoc.GetNodes()[nNdIdx]->GetFlyFormat();
713  OSL_ENSURE( pOldFormat, "Couldn't find the Fly's Format." );
714  // #i115719#
715  // <title> and <description> attributes are lost when calling <DelFrames()>.
716  // Thus, keep them and restore them after the calling <MakeFrames()>
717  const bool bIsSwFlyFrameFormatInstance( dynamic_cast<SwFlyFrameFormat*>(pOldFormat) != nullptr );
718  const OUString sTitle( bIsSwFlyFrameFormatInstance
719  ? static_cast<SwFlyFrameFormat*>(pOldFormat)->GetObjTitle()
720  : OUString() );
721  const OUString sDescription( bIsSwFlyFrameFormatInstance
722  ? static_cast<SwFlyFrameFormat*>(pOldFormat)->GetObjDescription()
723  : OUString() );
724  pOldFormat->DelFrames();
725 
726  pNewFormat = rDoc.MakeFlyFrameFormat( rDoc.GetUniqueFrameName(),
728 
729  /* #i6447#: Only the selected items are copied from the old
730  format. */
731  std::unique_ptr<SfxItemSet> pNewSet = pNewFormat->GetAttrSet().Clone();
732 
733  // Copy only the set attributes.
734  // The others should apply from the Templates.
735  lcl_CpyAttr( *pNewSet, pOldFormat->GetAttrSet(), RES_PRINT );
736  lcl_CpyAttr( *pNewSet, pOldFormat->GetAttrSet(), RES_OPAQUE );
737  lcl_CpyAttr( *pNewSet, pOldFormat->GetAttrSet(), RES_PROTECT );
738  lcl_CpyAttr( *pNewSet, pOldFormat->GetAttrSet(), RES_SURROUND );
739  lcl_CpyAttr( *pNewSet, pOldFormat->GetAttrSet(), RES_VERT_ORIENT );
740  lcl_CpyAttr( *pNewSet, pOldFormat->GetAttrSet(), RES_HORI_ORIENT );
741  lcl_CpyAttr( *pNewSet, pOldFormat->GetAttrSet(), RES_LR_SPACE );
742  lcl_CpyAttr( *pNewSet, pOldFormat->GetAttrSet(), RES_UL_SPACE );
743  lcl_CpyAttr( *pNewSet, pOldFormat->GetAttrSet(), RES_BACKGROUND );
744  if( bCpyBrd )
745  {
746  // If there's no BoxItem at graphic, but the new Format has one, then set the
747  // default item in the new Set. Because the graphic's size has never changed!
748  const SfxPoolItem *pItem;
749  if( SfxItemState::SET == pOldFormat->GetAttrSet().
750  GetItemState( RES_BOX, true, &pItem ))
751  pNewSet->Put( *pItem );
752  else if( SfxItemState::SET == pNewFormat->GetAttrSet().
753  GetItemState( RES_BOX ))
754  pNewSet->Put( *GetDfltAttr( RES_BOX ) );
755 
756  if( SfxItemState::SET == pOldFormat->GetAttrSet().
757  GetItemState( RES_SHADOW, true, &pItem ))
758  pNewSet->Put( *pItem );
759  else if( SfxItemState::SET == pNewFormat->GetAttrSet().
760  GetItemState( RES_SHADOW ))
761  pNewSet->Put( *GetDfltAttr( RES_SHADOW ) );
762  }
763  else
764  {
765  // Hard-set the attributes, because they could come from the Template
766  // and then size calculations could not be correct anymore.
767  pNewSet->Put( SvxBoxItem(RES_BOX) );
768  pNewSet->Put( SvxShadowItem(RES_SHADOW) );
769  }
770 
771  // Always transfer the anchor, which is a hard attribute anyways.
772  pNewSet->Put( pOldFormat->GetAnchor() );
773 
774  // The new one should be changeable in its height.
775  std::unique_ptr<SwFormatFrameSize> aFrameSize(pOldFormat->GetFrameSize().Clone());
776  aFrameSize->SetHeightSizeType( SwFrameSize::Minimum );
777  pNewSet->Put( std::move(aFrameSize) );
778 
779  SwStartNode* pSttNd = rDoc.GetNodes().MakeTextSection(
781  SwFlyStartNode, pColl );
782  pNewSet->Put( SwFormatContent( pSttNd ));
783 
784  pNewFormat->SetFormatAttr( *pNewSet );
785 
786  // InContents need to be treated in a special way:
787  // The TextAttribute needs to be destroyed.
788  // Unfortunately, this also destroys the Format next to the Frames.
789  // To avoid this, we disconnect the attribute from the Format.
790 
791  const SwFormatAnchor& rAnchor = pNewFormat->GetAnchor();
792  if ( RndStdIds::FLY_AS_CHAR == rAnchor.GetAnchorId() )
793  {
794  const SwPosition *pPos = rAnchor.GetContentAnchor();
795  SwTextNode *pTextNode = pPos->nNode.GetNode().GetTextNode();
796  OSL_ENSURE( pTextNode->HasHints(), "Missing FlyInCnt-Hint." );
797  const sal_Int32 nIdx = pPos->nContent.GetIndex();
798  SwTextAttr * const pHint =
799  pTextNode->GetTextAttrForCharAt(nIdx, RES_TXTATR_FLYCNT);
800 
801  assert(pHint && "Missing Hint.");
802 
803  OSL_ENSURE( pHint->Which() == RES_TXTATR_FLYCNT,
804  "Missing FlyInCnt-Hint." );
805  OSL_ENSURE( pHint->GetFlyCnt().GetFrameFormat() == pOldFormat,
806  "Wrong TextFlyCnt-Hint." );
807 
808  const_cast<SwFormatFlyCnt&>(pHint->GetFlyCnt()).SetFlyFormat(
809  pNewFormat );
810  }
811 
812  // The old one should not have a flow and it should be adjusted to above and
813  // middle.
814  // Also, the width should be 100% and it should also adjust the height, if changed.
815  pNewSet->ClearItem();
816 
817  pNewSet->Put( SwFormatSurround( css::text::WrapTextMode_NONE ) );
818  pNewSet->Put( SvxOpaqueItem( RES_OPAQUE, true ) );
819 
820  sal_Int16 eVert = bBefore ? text::VertOrientation::BOTTOM : text::VertOrientation::TOP;
821  pNewSet->Put( SwFormatVertOrient( 0, eVert ) );
822  pNewSet->Put( SwFormatHoriOrient( 0, text::HoriOrientation::CENTER ) );
823 
824  aFrameSize.reset(pOldFormat->GetFrameSize().Clone());
825 
826  SwOLENode* pOleNode = rDoc.GetNodes()[nNdIdx + 1]->GetOLENode();
827  bool isMath = false;
828  if(pOleNode)
829  {
830  svt::EmbeddedObjectRef& xRef = pOleNode->GetOLEObj().GetObject();
831  if(xRef.is())
832  {
833  SvGlobalName aCLSID( xRef->getClassID() );
834  isMath = ( SotExchange::IsMath( aCLSID ) != 0 );
835  }
836  }
837  aFrameSize->SetWidthPercent(isMath ? 0 : 100);
838  aFrameSize->SetHeightPercent(SwFormatFrameSize::SYNCED);
839  pNewSet->Put( std::move(aFrameSize) );
840 
841  // Hard-set the attributes, because they could come from the Template
842  // and then size calculations could not be correct anymore.
843  if( bCpyBrd )
844  {
845  pNewSet->Put( SvxBoxItem(RES_BOX) );
846  pNewSet->Put( SvxShadowItem(RES_SHADOW) );
847  }
848  pNewSet->Put( SvxLRSpaceItem(RES_LR_SPACE) );
849  pNewSet->Put( SvxULSpaceItem(RES_UL_SPACE) );
850 
851  // The old one is paragraph-bound to the paragraph in the new one.
852  SwFormatAnchor aAnch( RndStdIds::FLY_AT_PARA );
853  SwNodeIndex aAnchIdx( *pNewFormat->GetContent().GetContentIdx(), 1 );
854  pNew = aAnchIdx.GetNode().GetTextNode();
855  SwPosition aPos( aAnchIdx );
856  aAnch.SetAnchor( &aPos );
857  pNewSet->Put( aAnch );
858 
859  if( pUndo )
860  pUndo->SetFlys( *pOldFormat, *pNewSet, *pNewFormat );
861  else
862  pOldFormat->SetFormatAttr( *pNewSet );
863 
864  pNewSet.reset();
865 
866  // Have only the FlyFrames created.
867  // We leave this to established methods (especially for InCntFlys).
868  pNewFormat->MakeFrames();
869  // #i115719#
870  if ( bIsSwFlyFrameFormatInstance )
871  {
872  static_cast<SwFlyFrameFormat*>(pOldFormat)->SetObjTitle( sTitle );
873  static_cast<SwFlyFrameFormat*>(pOldFormat)->SetObjDescription( sDescription );
874  }
875  }
876  break;
877 
878  default:
879  OSL_ENSURE(false, "unknown LabelType?");
880  }
881  OSL_ENSURE( pNew, "No Label inserted" );
882  if( pNew )
883  {
884  // #i61007# order of captions
885  bool bOrderNumberingFirst = SW_MOD()->GetModuleConfig()->IsCaptionOrderNumberingFirst();
886  // Work up OUString
887  OUString aText;
888  if( bOrderNumberingFirst )
889  {
890  aText = rNumberingSeparator;
891  }
892  if( pType)
893  {
894  aText += pType->GetName();
895  if( !bOrderNumberingFirst )
896  aText += " ";
897  }
898  sal_Int32 nIdx = aText.getLength();
899  if( !rText.empty() )
900  {
901  aText += rSeparator;
902  }
903  const sal_Int32 nSepIdx = aText.getLength();
904  aText += rText;
905 
906  // Insert string
907  SwIndex aIdx( pNew, 0 );
908  pNew->InsertText( aText, aIdx );
909 
910  // Insert field
911  if(pType)
912  {
913  SwSetExpField aField( static_cast<SwSetExpFieldType*>(pType), OUString(), SVX_NUM_ARABIC);
914  if( bOrderNumberingFirst )
915  nIdx = 0;
916  SwFormatField aFormat( aField );
917  pNew->InsertItem( aFormat, nIdx, nIdx );
918  if(!rCharacterStyle.isEmpty())
919  {
920  SwCharFormat* pCharFormat = rDoc.FindCharFormatByName(rCharacterStyle);
921  if( !pCharFormat )
922  {
923  const sal_uInt16 nMyId = SwStyleNameMapper::GetPoolIdFromUIName(rCharacterStyle, SwGetPoolIdFromName::ChrFmt);
924  pCharFormat = rDoc.getIDocumentStylePoolAccess().GetCharFormatFromPool( nMyId );
925  }
926  if (pCharFormat)
927  {
928  SwFormatCharFormat aCharFormat( pCharFormat );
929  pNew->InsertItem( aCharFormat, 0,
930  nSepIdx + 1, SetAttrMode::DONTEXPAND );
931  }
932  }
933  }
934 
935  if ( bTable )
936  {
937  if ( bBefore )
938  {
939  if ( !pNew->GetSwAttrSet().GetKeep().GetValue() )
940  pNew->SetAttr( SvxFormatKeepItem( true, RES_KEEP ) );
941  }
942  else
943  {
944  SwTableNode *const pNd =
945  rDoc.GetNodes()[nNdIdx]->GetStartNode()->GetTableNode();
946  SwTable &rTable = pNd->GetTable();
947  if ( !rTable.GetFrameFormat()->GetKeep().GetValue() )
949  if ( pUndo )
950  pUndo->SetUndoKeep();
951  }
952  }
954  }
955 
956  return pNewFormat;
957 }
958 
961  SwLabelType const eType, OUString const& rText, OUString const& rSeparator,
962  OUString const& rNumberingSeparator,
963  bool const bBefore, sal_uInt16 const nId, sal_uLong const nNdIdx,
964  OUString const& rCharacterStyle,
965  bool const bCpyBrd )
966 {
967  std::unique_ptr<SwUndoInsertLabel> pUndo;
968  if (GetIDocumentUndoRedo().DoesUndo())
969  {
970  pUndo.reset(new SwUndoInsertLabel(
971  eType, rText, rSeparator, rNumberingSeparator,
972  bBefore, nId, rCharacterStyle, bCpyBrd, this ));
973  }
974 
975  SwFlyFrameFormat *const pNewFormat = lcl_InsertLabel(*this, mpTextFormatCollTable.get(), pUndo.get(),
976  eType, rText, rSeparator, rNumberingSeparator, bBefore,
977  nId, nNdIdx, rCharacterStyle, bCpyBrd);
978 
979  if (pUndo)
980  {
981  GetIDocumentUndoRedo().AppendUndo(std::move(pUndo));
982  }
983  else
984  {
986  }
987 
988  return pNewFormat;
989 }
990 
991 static SwFlyFrameFormat *
992 lcl_InsertDrawLabel( SwDoc & rDoc, SwTextFormatColls *const pTextFormatCollTable,
993  SwUndoInsertLabel *const pUndo, SwDrawFrameFormat *const pOldFormat,
994  OUString const& rText,
995  const OUString& rSeparator,
996  const OUString& rNumberSeparator,
997  const sal_uInt16 nId,
998  const OUString& rCharacterStyle,
999  SdrObject& rSdrObj )
1000 {
1001  ::sw::UndoGuard const undoGuard(rDoc.GetIDocumentUndoRedo());
1002  ::sw::DrawUndoGuard const drawUndoGuard(rDoc.GetIDocumentUndoRedo());
1003 
1004  // Because we get by the TextColl's name, we need to create the field first.
1005  OSL_ENSURE( nId == USHRT_MAX || nId < rDoc.getIDocumentFieldsAccess().GetFieldTypes()->size(),
1006  "FieldType index out of bounds" );
1007  SwFieldType *pType = nId != USHRT_MAX ? (*rDoc.getIDocumentFieldsAccess().GetFieldTypes())[nId].get() : nullptr;
1008  OSL_ENSURE( !pType || pType->Which() == SwFieldIds::SetExp, "Wrong label id" );
1009 
1010  SwTextFormatColl *pColl = nullptr;
1011  if( pType )
1012  {
1013  for( auto i = pTextFormatCollTable->size(); i; )
1014  {
1015  if( (*pTextFormatCollTable)[ --i ]->GetName()==pType->GetName() )
1016  {
1017  pColl = (*pTextFormatCollTable)[i];
1018  break;
1019  }
1020  }
1021  OSL_ENSURE( pColl, "no text collection found" );
1022  }
1023 
1024  if( !pColl )
1025  {
1027  }
1028 
1029  SwTextNode* pNew = nullptr;
1030  SwFlyFrameFormat* pNewFormat = nullptr;
1031 
1032  // Destroy Frame,
1033  // insert new Frame,
1034  // insert the corresponding Node with Field into the new Frame,
1035  // insert the old Frame with the Object (Picture/OLE) paragraph-bound into the new Frame,
1036  // create Frames.
1037 
1038  // Keep layer ID of drawing object before removing
1039  // its frames.
1040  // Note: The layer ID is passed to the undo and have to be the correct value.
1041  // Removing the frames of the drawing object changes its layer.
1042  const SdrLayerID nLayerId = rSdrObj.GetLayer();
1043 
1044  pOldFormat->DelFrames();
1045 
1046  // InContents need to be treated in a special way:
1047  // The TextAttribute needs to be destroyed.
1048  // Unfortunately, this also destroys the Format next to the Frames.
1049  // To avoid this, we disconnect the attribute from the Format.
1050  std::unique_ptr<SfxItemSet> pNewSet = pOldFormat->GetAttrSet().Clone( false );
1051 
1052  // Protect the Frame's size and position
1053  if ( rSdrObj.IsMoveProtect() || rSdrObj.IsResizeProtect() )
1054  {
1055  SvxProtectItem aProtect(RES_PROTECT);
1056  aProtect.SetContentProtect( false );
1057  aProtect.SetPosProtect( rSdrObj.IsMoveProtect() );
1058  aProtect.SetSizeProtect( rSdrObj.IsResizeProtect() );
1059  pNewSet->Put( aProtect );
1060  }
1061 
1062  // Take over the text wrap
1063  lcl_CpyAttr( *pNewSet, pOldFormat->GetAttrSet(), RES_SURROUND );
1064 
1065  // Send the frame to the back, if needed.
1066  // Consider the 'invisible' hell layer.
1067  if ( rDoc.getIDocumentDrawModelAccess().GetHellId() != nLayerId &&
1068  rDoc.getIDocumentDrawModelAccess().GetInvisibleHellId() != nLayerId )
1069  {
1070  SvxOpaqueItem aOpaque( RES_OPAQUE );
1071  aOpaque.SetValue( true );
1072  pNewSet->Put( aOpaque );
1073  }
1074 
1075  // Take over position
1076  // #i26791# - use directly drawing object's positioning attributes
1077  pNewSet->Put( pOldFormat->GetHoriOrient() );
1078  pNewSet->Put( pOldFormat->GetVertOrient() );
1079 
1080  pNewSet->Put( pOldFormat->GetAnchor() );
1081 
1082  // The new one should be variable in its height!
1083  Size aSz( rSdrObj.GetCurrentBoundRect().GetSize() );
1084  SwFormatFrameSize aFrameSize( SwFrameSize::Minimum, aSz.Width(), aSz.Height() );
1085  pNewSet->Put( aFrameSize );
1086 
1087  // Apply the margin to the new Frame.
1088  // Don't set a border, use the one from the Template.
1089  pNewSet->Put( pOldFormat->GetLRSpace() );
1090  pNewSet->Put( pOldFormat->GetULSpace() );
1091 
1092  SwStartNode* pSttNd =
1093  rDoc.GetNodes().MakeTextSection(
1095  SwFlyStartNode, pColl );
1096 
1097  pNewFormat = rDoc.MakeFlyFrameFormat( rDoc.GetUniqueFrameName(),
1099 
1100  // Set border and shadow to default if the template contains any.
1101  if( SfxItemState::SET == pNewFormat->GetAttrSet().GetItemState( RES_BOX ))
1102  pNewSet->Put( *GetDfltAttr( RES_BOX ) );
1103 
1104  if( SfxItemState::SET == pNewFormat->GetAttrSet().GetItemState(RES_SHADOW))
1105  pNewSet->Put( *GetDfltAttr( RES_SHADOW ) );
1106 
1107  pNewFormat->SetFormatAttr( SwFormatContent( pSttNd ));
1108  pNewFormat->SetFormatAttr( *pNewSet );
1109 
1110  const SwFormatAnchor& rAnchor = pNewFormat->GetAnchor();
1111  if ( RndStdIds::FLY_AS_CHAR == rAnchor.GetAnchorId() )
1112  {
1113  const SwPosition *pPos = rAnchor.GetContentAnchor();
1114  SwTextNode *pTextNode = pPos->nNode.GetNode().GetTextNode();
1115  OSL_ENSURE( pTextNode->HasHints(), "Missing FlyInCnt-Hint." );
1116  const sal_Int32 nIdx = pPos->nContent.GetIndex();
1117  SwTextAttr * const pHint =
1118  pTextNode->GetTextAttrForCharAt( nIdx, RES_TXTATR_FLYCNT );
1119 
1120  assert(pHint && "Missing Hint.");
1121 
1122 #if OSL_DEBUG_LEVEL > 0
1123  OSL_ENSURE( pHint->Which() == RES_TXTATR_FLYCNT,
1124  "Missing FlyInCnt-Hint." );
1125  OSL_ENSURE( pHint->GetFlyCnt().
1126  GetFrameFormat() == static_cast<SwFrameFormat*>(pOldFormat),
1127  "Wrong TextFlyCnt-Hint." );
1128 #endif
1129  const_cast<SwFormatFlyCnt&>(pHint->GetFlyCnt()).SetFlyFormat( pNewFormat );
1130  }
1131 
1132  // The old one should not have a flow
1133  // and it should be adjusted to above and middle.
1134  pNewSet->ClearItem();
1135 
1136  pNewSet->Put( SwFormatSurround( css::text::WrapTextMode_NONE ) );
1137  if (nLayerId == rDoc.getIDocumentDrawModelAccess().GetHellId())
1138  {
1139  // Consider drawing objects in the 'invisible' hell layer
1140  rSdrObj.SetLayer( rDoc.getIDocumentDrawModelAccess().GetHeavenId() );
1141  }
1142  else if (nLayerId == rDoc.getIDocumentDrawModelAccess().GetInvisibleHellId())
1143  {
1145  }
1146  pNewSet->Put( SvxLRSpaceItem( RES_LR_SPACE ) );
1147  pNewSet->Put( SvxULSpaceItem( RES_UL_SPACE ) );
1148 
1149  // #i26791# - set position of the drawing object, which is labeled.
1150  pNewSet->Put( SwFormatVertOrient( 0, text::VertOrientation::TOP, text::RelOrientation::FRAME ) );
1151  pNewSet->Put( SwFormatHoriOrient( 0, text::HoriOrientation::CENTER, text::RelOrientation::FRAME ) );
1152 
1153  // The old one is paragraph-bound to the new one's paragraph.
1154  SwFormatAnchor aAnch( RndStdIds::FLY_AT_PARA );
1155  SwNodeIndex aAnchIdx( *pNewFormat->GetContent().GetContentIdx(), 1 );
1156  pNew = aAnchIdx.GetNode().GetTextNode();
1157  SwPosition aPos( aAnchIdx );
1158  aAnch.SetAnchor( &aPos );
1159  pNewSet->Put( aAnch );
1160 
1161  if( pUndo )
1162  {
1163  pUndo->SetFlys( *pOldFormat, *pNewSet, *pNewFormat );
1164  // #i26791# - position no longer needed
1165  pUndo->SetDrawObj( nLayerId );
1166  }
1167  else
1168  pOldFormat->SetFormatAttr( *pNewSet );
1169 
1170  pNewSet.reset();
1171 
1172  // Have only the FlyFrames created.
1173  // We leave this to established methods (especially for InCntFlys).
1174  pNewFormat->MakeFrames();
1175 
1176  OSL_ENSURE( pNew, "No Label inserted" );
1177 
1178  if( pNew )
1179  {
1180  //#i61007# order of captions
1181  bool bOrderNumberingFirst = SW_MOD()->GetModuleConfig()->IsCaptionOrderNumberingFirst();
1182 
1183  // prepare string
1184  OUString aText;
1185  if( bOrderNumberingFirst )
1186  {
1187  aText = rNumberSeparator;
1188  }
1189  if ( pType )
1190  {
1191  aText += pType->GetName();
1192  if( !bOrderNumberingFirst )
1193  aText += " ";
1194  }
1195  sal_Int32 nIdx = aText.getLength();
1196  aText += rSeparator;
1197  const sal_Int32 nSepIdx = aText.getLength();
1198  aText += rText;
1199 
1200  // insert text
1201  SwIndex aIdx( pNew, 0 );
1202  pNew->InsertText( aText, aIdx );
1203 
1204  // insert field
1205  if ( pType )
1206  {
1207  SwSetExpField aField( static_cast<SwSetExpFieldType*>(pType), OUString(), SVX_NUM_ARABIC );
1208  if( bOrderNumberingFirst )
1209  nIdx = 0;
1210  SwFormatField aFormat( aField );
1211  pNew->InsertItem( aFormat, nIdx, nIdx );
1212  if ( !rCharacterStyle.isEmpty() )
1213  {
1214  SwCharFormat * pCharFormat = rDoc.FindCharFormatByName(rCharacterStyle);
1215  if ( !pCharFormat )
1216  {
1217  const sal_uInt16 nMyId = SwStyleNameMapper::GetPoolIdFromUIName( rCharacterStyle, SwGetPoolIdFromName::ChrFmt );
1218  pCharFormat = rDoc.getIDocumentStylePoolAccess().GetCharFormatFromPool( nMyId );
1219  }
1220  if ( pCharFormat )
1221  {
1222  SwFormatCharFormat aCharFormat( pCharFormat );
1223  pNew->InsertItem( aCharFormat, 0, nSepIdx + 1,
1225  }
1226  }
1227  }
1228  }
1229 
1230  return pNewFormat;
1231 }
1232 
1234  OUString const& rText,
1235  OUString const& rSeparator,
1236  OUString const& rNumberSeparator,
1237  sal_uInt16 const nId,
1238  OUString const& rCharacterStyle,
1239  SdrObject& rSdrObj )
1240 {
1241  SwDrawContact *const pContact =
1242  static_cast<SwDrawContact*>(GetUserCall( &rSdrObj ));
1243  if (!pContact)
1244  return nullptr;
1245  OSL_ENSURE( RES_DRAWFRMFMT == pContact->GetFormat()->Which(),
1246  "InsertDrawLabel(): not a DrawFrameFormat" );
1247 
1248  SwDrawFrameFormat* pOldFormat = static_cast<SwDrawFrameFormat *>(pContact->GetFormat());
1249  if (!pOldFormat)
1250  return nullptr;
1251 
1252  std::unique_ptr<SwUndoInsertLabel> pUndo;
1254  {
1256  pUndo.reset(new SwUndoInsertLabel(
1257  SwLabelType::Draw, rText, rSeparator, rNumberSeparator, false,
1258  nId, rCharacterStyle, false, this ));
1259  }
1260 
1261  SwFlyFrameFormat *const pNewFormat = lcl_InsertDrawLabel(
1262  *this, mpTextFormatCollTable.get(), pUndo.get(), pOldFormat,
1263  rText, rSeparator, rNumberSeparator, nId, rCharacterStyle, rSdrObj);
1264 
1265  if (pUndo)
1266  {
1267  GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) );
1268  }
1269  else
1270  {
1272  }
1273 
1274  return pNewFormat;
1275 }
1276 
1277 static void lcl_collectUsedNums(std::vector<unsigned int>& rSetFlags, sal_Int32 nNmLen, const OUString& rName, std::u16string_view rCmpName)
1278 {
1279  if (rName.startsWith(rCmpName))
1280  {
1281  // Only get and set the Flag
1282  const sal_Int32 nNum = rName.copy(nNmLen).toInt32() - 1;
1283  if (nNum >= 0)
1284  rSetFlags.push_back(nNum);
1285  }
1286 }
1287 
1288 static void lcl_collectUsedNums(std::vector<unsigned int>& rSetFlags, sal_Int32 nNmLen, const SdrObject& rObj, const OUString& rCmpName)
1289 {
1290  OUString sName = rObj.GetName();
1291  lcl_collectUsedNums(rSetFlags, nNmLen, sName, rCmpName);
1292  // tdf#122487 take groups into account, iterate and recurse through their
1293  // contents for name collision check
1294  if (!rObj.IsGroupObject())
1295  return;
1296 
1297  const SdrObjList* pSub(rObj.GetSubList());
1298  assert(pSub && "IsGroupObject is implemented as GetSubList != nullptr");
1299  const size_t nCount = pSub->GetObjCount();
1300  for (size_t i = 0; i < nCount; ++i)
1301  {
1302  SdrObject* pObj = pSub->GetObj(i);
1303  if (!pObj)
1304  continue;
1305  lcl_collectUsedNums(rSetFlags, nNmLen, *pObj, rCmpName);
1306  }
1307 }
1308 
1309 namespace
1310 {
1311  int first_available_number(std::vector<unsigned int>& numbers)
1312  {
1313  std::sort(numbers.begin(), numbers.end());
1314  auto last = std::unique(numbers.begin(), numbers.end());
1315  numbers.erase(last, numbers.end());
1316 
1317  for (size_t i = 0; i < numbers.size(); ++i)
1318  {
1319  if (numbers[i] != i)
1320  return i;
1321  }
1322 
1323  return numbers.size();
1324  }
1325 }
1326 
1327 static OUString lcl_GetUniqueFlyName(const SwDoc& rDoc, const char* pDefStrId, sal_uInt16 eType)
1328 {
1329  assert(eType >= RES_FMT_BEGIN && eType < RES_FMT_END);
1330  if (rDoc.IsInMailMerge())
1331  {
1332  OUString newName = "MailMergeFly"
1333  + OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM )), RTL_TEXTENCODING_ASCII_US )
1334  + OUString::number( rDoc.GetSpzFrameFormats()->size() + 1 );
1335  return newName;
1336  }
1337 
1338  OUString aName(SwResId(pDefStrId));
1339  sal_Int32 nNmLen = aName.getLength();
1340 
1341  const SwFrameFormats& rFormats = *rDoc.GetSpzFrameFormats();
1342 
1343  std::vector<unsigned int> aUsedNums;
1344  aUsedNums.reserve(rFormats.size());
1345 
1346  for( SwFrameFormats::size_type n = 0; n < rFormats.size(); ++n )
1347  {
1348  const SwFrameFormat* pFlyFormat = rFormats[ n ];
1349  if (eType != pFlyFormat->Which())
1350  continue;
1351  if (eType == RES_DRAWFRMFMT)
1352  {
1353  const SdrObject *pObj = pFlyFormat->FindSdrObject();
1354  if (pObj)
1355  lcl_collectUsedNums(aUsedNums, nNmLen, *pObj, aName);
1356  }
1357 
1358  OUString sName = pFlyFormat->GetName();
1359  lcl_collectUsedNums(aUsedNums, nNmLen, sName, aName);
1360  }
1361 
1362  // All numbers are flagged accordingly, so determine the right one
1363  SwFrameFormats::size_type nNum = first_available_number(aUsedNums) + 1;
1364  return aName + OUString::number(nNum);
1365 }
1366 
1367 OUString SwDoc::GetUniqueGrfName() const
1368 {
1369  return lcl_GetUniqueFlyName(*this, STR_GRAPHIC_DEFNAME, RES_FLYFRMFMT);
1370 }
1371 
1372 OUString SwDoc::GetUniqueOLEName() const
1373 {
1374  return lcl_GetUniqueFlyName(*this, STR_OBJECT_DEFNAME, RES_FLYFRMFMT);
1375 }
1376 
1378 {
1379  return lcl_GetUniqueFlyName(*this, STR_FRAME_DEFNAME, RES_FLYFRMFMT);
1380 }
1381 
1383 {
1384  return lcl_GetUniqueFlyName(*this, STR_SHAPE_DEFNAME, RES_DRAWFRMFMT);
1385 }
1386 
1388 {
1389  return lcl_GetUniqueFlyName(*this, "DrawObject", RES_DRAWFRMFMT);
1390 }
1391 
1392 const SwFlyFrameFormat* SwDoc::FindFlyByName( const OUString& rName, SwNodeType nNdTyp ) const
1393 {
1394  auto range = GetSpzFrameFormats()->rangeFind( RES_FLYFRMFMT, rName );
1395  for( auto it = range.first; it != range.second; it++ )
1396  {
1397  const SwFrameFormat* pFlyFormat = *it;
1398  if( RES_FLYFRMFMT != pFlyFormat->Which() || pFlyFormat->GetName() != rName )
1399  continue;
1400  const SwNodeIndex* pIdx = pFlyFormat->GetContent().GetContentIdx();
1401  if( pIdx && pIdx->GetNode().GetNodes().IsDocNodes() )
1402  {
1403  if( nNdTyp != SwNodeType::NONE )
1404  {
1405  // query for the right NodeType
1406  const SwNode* pNd = GetNodes()[ pIdx->GetIndex()+1 ];
1407  if( nNdTyp == SwNodeType::Text
1408  ? !pNd->IsNoTextNode()
1409  : nNdTyp == pNd->GetNodeType() )
1410  return static_cast<const SwFlyFrameFormat*>(pFlyFormat);
1411  }
1412  else
1413  return static_cast<const SwFlyFrameFormat*>(pFlyFormat);
1414  }
1415  }
1416  return nullptr;
1417 }
1418 
1419 void SwDoc::SetFlyName( SwFlyFrameFormat& rFormat, const OUString& rName )
1420 {
1421  OUString sName( rName );
1422  if( sName.isEmpty() || FindFlyByName( sName ) )
1423  {
1424  const char* pTyp = STR_FRAME_DEFNAME;
1425  const SwNodeIndex* pIdx = rFormat.GetContent().GetContentIdx();
1426  if( pIdx && pIdx->GetNode().GetNodes().IsDocNodes() )
1427  {
1428  switch( GetNodes()[ pIdx->GetIndex() + 1 ]->GetNodeType() )
1429  {
1430  case SwNodeType::Grf:
1431  pTyp = STR_GRAPHIC_DEFNAME;
1432  break;
1433  case SwNodeType::Ole:
1434  pTyp = STR_OBJECT_DEFNAME;
1435  break;
1436  default: break;
1437  }
1438  }
1439  sName = lcl_GetUniqueFlyName(*this, pTyp, RES_FLYFRMFMT);
1440  }
1441  rFormat.SetName( sName, true );
1443 }
1444 
1446 {
1447  sal_Int32 n, nFlyNum = 0, nGrfNum = 0, nOLENum = 0;
1448 
1449  const OUString sFlyNm(SwResId(STR_FRAME_DEFNAME));
1450  const OUString sGrfNm(SwResId(STR_GRAPHIC_DEFNAME));
1451  const OUString sOLENm(SwResId(STR_OBJECT_DEFNAME));
1452 
1453  n = GetSpzFrameFormats()->size();
1454  if( 255 < n )
1455  n = 255;
1457  aArr.reserve( n );
1458  SwFrameFormat* pFlyFormat;
1459  bool bContainsAtPageObjWithContentAnchor = false;
1460 
1461  for( n = GetSpzFrameFormats()->size(); n; )
1462  {
1463  pFlyFormat = (*GetSpzFrameFormats())[ --n ];
1464  if( RES_FLYFRMFMT == pFlyFormat->Which() )
1465  {
1466  const OUString& aNm = pFlyFormat->GetName();
1467  if ( !aNm.isEmpty() )
1468  {
1469  sal_Int32 *pNum = nullptr;
1470  sal_Int32 nLen = 0;
1471  if ( aNm.startsWith(sGrfNm) )
1472  {
1473  nLen = sGrfNm.getLength();
1474  pNum = &nGrfNum;
1475  }
1476  else if( aNm.startsWith(sFlyNm) )
1477  {
1478  nLen = sFlyNm.getLength();
1479  pNum = &nFlyNum;
1480  }
1481  else if( aNm.startsWith(sOLENm) )
1482  {
1483  nLen = sOLENm.getLength();
1484  pNum = &nOLENum;
1485  }
1486 
1487  if ( pNum )
1488  {
1489  const sal_Int32 nNewLen = aNm.copy( nLen ).toInt32();
1490  if (*pNum < nNewLen)
1491  *pNum = nNewLen;
1492  }
1493  }
1494  else
1495  // we want to set that afterwards
1496  aArr.push_back( pFlyFormat );
1497 
1498  }
1499  if ( !bContainsAtPageObjWithContentAnchor )
1500  {
1501  const SwFormatAnchor& rAnchor = pFlyFormat->GetAnchor();
1502  if ( (RndStdIds::FLY_AT_PAGE == rAnchor.GetAnchorId()) &&
1503  rAnchor.GetContentAnchor() )
1504  {
1505  bContainsAtPageObjWithContentAnchor = true;
1506  }
1507  }
1508  }
1509  SetContainsAtPageObjWithContentAnchor( bContainsAtPageObjWithContentAnchor );
1510 
1511  for( n = aArr.size(); n; )
1512  {
1513  pFlyFormat = aArr[ --n ];
1514  const SwNodeIndex* pIdx = pFlyFormat->GetContent().GetContentIdx();
1515  if( pIdx && pIdx->GetNode().GetNodes().IsDocNodes() )
1516  {
1517  switch( GetNodes()[ pIdx->GetIndex() + 1 ]->GetNodeType() )
1518  {
1519  case SwNodeType::Grf:
1520  pFlyFormat->SetName( sGrfNm + OUString::number( ++nGrfNum ));
1521  break;
1522  case SwNodeType::Ole:
1523  pFlyFormat->SetName( sOLENm + OUString::number( ++nOLENum ));
1524  break;
1525  default:
1526  pFlyFormat->SetName( sFlyNm + OUString::number( ++nFlyNum ));
1527  break;
1528  }
1529  }
1530  }
1531  aArr.clear();
1532 
1533  if( GetFootnoteIdxs().empty() )
1534  return;
1535 
1537  // #i52775# Chapter footnotes did not get updated correctly.
1538  // Calling UpdateAllFootnote() instead of UpdateFootnote() solves this problem,
1539  // but I do not dare to call UpdateAllFootnote() in all cases: Safety first.
1540  if ( FTNNUM_CHAPTER == GetFootnoteInfo().m_eNum )
1541  {
1543  }
1544  else
1545  {
1546  SwNodeIndex aTmp( GetNodes() );
1547  GetFootnoteIdxs().UpdateFootnote( aTmp );
1548  }
1549 }
1550 
1551 bool SwDoc::IsInHeaderFooter( const SwNodeIndex& rIdx ) const
1552 {
1553  // That can also be a Fly in a Fly in the Header.
1554  // Is also used by sw3io, to determine if a Redline object is
1555  // in the Header or Footer.
1556  // Because Redlines are also attached to Start and EndNode,
1557  // the Index must not necessarily be from a ContentNode.
1558  SwNode* pNd = &rIdx.GetNode();
1559  const SwNode* pFlyNd = pNd->FindFlyStartNode();
1560  while( pFlyNd )
1561  {
1562  // get up by using the Anchor
1563 #if OSL_DEBUG_LEVEL > 0
1564  std::vector<const SwFrameFormat*> checkFormats;
1565  for( auto pFormat : *GetSpzFrameFormats() )
1566  {
1567  const SwNodeIndex* pIdx = pFormat->GetContent().GetContentIdx();
1568  if( pIdx && pFlyNd == &pIdx->GetNode() )
1569  checkFormats.push_back( pFormat );
1570  }
1571 #endif
1572  std::vector<SwFrameFormat*> const*const pFlys(pFlyNd->GetAnchoredFlys());
1573  bool bFound(false);
1574  for (size_t i = 0; pFlys && i < pFlys->size(); ++i)
1575  {
1576  const SwFrameFormat *const pFormat = (*pFlys)[i];
1577  const SwNodeIndex* pIdx = pFormat->GetContent().GetContentIdx();
1578  if( pIdx && pFlyNd == &pIdx->GetNode() )
1579  {
1580 #if OSL_DEBUG_LEVEL > 0
1581  auto checkPos = std::find(
1582  checkFormats.begin(), checkFormats.end(), pFormat );
1583  assert( checkPos != checkFormats.end());
1584  checkFormats.erase( checkPos );
1585 #endif
1586  const SwFormatAnchor& rAnchor = pFormat->GetAnchor();
1587  if ((RndStdIds::FLY_AT_PAGE == rAnchor.GetAnchorId()) ||
1588  !rAnchor.GetContentAnchor() )
1589  {
1590  return false;
1591  }
1592 
1593  pNd = &rAnchor.GetContentAnchor()->nNode.GetNode();
1594  pFlyNd = pNd->FindFlyStartNode();
1595  bFound = true;
1596  break;
1597  }
1598  }
1599  if (!bFound)
1600  {
1601  OSL_ENSURE(mbInReading, "Found a FlySection but not a Format!");
1602  return false;
1603  }
1604  }
1605 
1606  return nullptr != pNd->FindHeaderStartNode() ||
1607  nullptr != pNd->FindFooterStartNode();
1608 }
1609 
1611  const Point* pPt ) const
1612 {
1613  SvxFrameDirection nRet = SvxFrameDirection::Unknown;
1614 
1615  SwContentNode *pNd = rPos.nNode.GetNode().GetContentNode();
1616 
1617  // #i42921# - use new method <SwContentNode::GetTextDirection(..)>
1618  if ( pNd )
1619  {
1620  nRet = pNd->GetTextDirection( rPos, pPt );
1621  }
1622  if ( nRet == SvxFrameDirection::Unknown )
1623  {
1624  const SvxFrameDirectionItem* pItem = nullptr;
1625  if( pNd )
1626  {
1627  // Are we in a FlyFrame? Then look at that for the correct attribute
1628  const SwFrameFormat* pFlyFormat = pNd->GetFlyFormat();
1629  while( pFlyFormat )
1630  {
1631  pItem = &pFlyFormat->GetFrameDir();
1632  if( SvxFrameDirection::Environment == pItem->GetValue() )
1633  {
1634  pItem = nullptr;
1635  const SwFormatAnchor* pAnchor = &pFlyFormat->GetAnchor();
1636  if ((RndStdIds::FLY_AT_PAGE != pAnchor->GetAnchorId()) &&
1637  pAnchor->GetContentAnchor())
1638  {
1639  pFlyFormat = pAnchor->GetContentAnchor()->nNode.
1640  GetNode().GetFlyFormat();
1641  }
1642  else
1643  pFlyFormat = nullptr;
1644  }
1645  else
1646  pFlyFormat = nullptr;
1647  }
1648 
1649  if( !pItem )
1650  {
1651  const SwPageDesc* pPgDsc = pNd->FindPageDesc();
1652  if( pPgDsc )
1653  pItem = &pPgDsc->GetMaster().GetFrameDir();
1654  }
1655  }
1656  if( !pItem )
1657  pItem = &GetAttrPool().GetDefaultItem( RES_FRAMEDIR );
1658  nRet = pItem->GetValue();
1659  }
1660  return nRet;
1661 }
1662 
1663 bool SwDoc::IsInVerticalText( const SwPosition& rPos ) const
1664 {
1665  const SvxFrameDirection nDir = GetTextDirection( rPos );
1666  return SvxFrameDirection::Vertical_RL_TB == nDir || SvxFrameDirection::Vertical_LR_TB == nDir;
1667 }
1668 
1670 {
1673  if(pStart)
1674  {
1675  for(const SwViewShell& rShell : pStart->GetRingContainer())
1676  {
1677  if(rShell.GetLayout())
1678  aAllLayouts.insert(rShell.GetLayout());
1679  }
1680  }
1681  return aAllLayouts;
1682 }
1683 
1684 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual SwCharFormat * GetCharFormatFromPool(sal_uInt16 nId)=0
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:240
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:685
Starts a section of nodes in the document model.
Definition: node.hxx:311
constexpr TypedWhichId< SvxProtectItem > RES_PROTECT(100)
std::set< SwPosFlyFramePtr, SwPosFlyFrameCmp > SwPosFlyFrames
Definition: flypos.hxx:51
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:151
constexpr TypedWhichId< SvxFrameDirectionItem > RES_FRAMEDIR(120)
Subgroup labels.
Definition: poolfmt.hxx:344
OUString GetUniqueGrfName() const
Definition: doclay.cxx:1367
constexpr TypedWhichId< SwFormatSurround > RES_SURROUND(101)
bool IsInMailMerge() const
Definition: doc.hxx:961
sal_uLong GetIndex() const
Definition: node.hxx:290
SwNode & GetEndOfAutotext() const
Section for all Flys/Header/Footers.
Definition: ndarr.hxx:156
OUString GetUniqueOLEName() const
Definition: doclay.cxx:1372
const SwStartNode * FindHeaderStartNode() const
Definition: node.hxx:202
SwLabelType
Definition: swtypes.hxx:87
Represents the style of a paragraph.
Definition: fmtcol.hxx:56
Marks a position in the document model.
Definition: pam.hxx:35
virtual const tools::Rectangle & GetCurrentBoundRect() const
void SetNodePos(sal_uLong nNd)
Definition: UndoInsert.hxx:213
SwContentNode * GetNode(SwPaM &rPam, bool &rbFirst, SwMoveFnCollection const &fnMove, bool const bInReadOnly, SwRootFrame const *const i_pLayout)
This function returns the next node in direction of search.
Definition: pam.cxx:817
OUString GetUniqueDrawObjectName() const
Definition: doclay.cxx:1387
constexpr TypedWhichId< SvxPrintItem > RES_PRINT(98)
void reserve(size_type nSize)
Definition: docary.hxx:99
SwCharFormat * FindCharFormatByName(std::u16string_view rName) const
Definition: doc.hxx:772
void SetHeight(tools::Long n)
void setWidth(tools::Long nWidth)
const SwOLEObj & GetOLEObj() const
Definition: ndole.hxx:112
const SwStartNode * FindFooterStartNode() const
Definition: node.hxx:204
virtual const SwRootFrame * GetCurrentLayout() const =0
virtual bool get(DocumentSettingId id) const override
Return the specified document setting.
virtual bool SetAttr(const SfxPoolItem &) override
overriding to handle change of certain paragraph attributes
Definition: ndtxt.cxx:4866
constexpr TypedWhichId< SvxFormatKeepItem > RES_KEEP(110)
const SwFormatVertOrient & GetVertOrient(bool=true) const
Definition: fmtornt.hxx:106
SwNodeIndex nNode
Definition: pam.hxx:37
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
SdrObject * CloneSdrObj(const SdrObject &, bool bMoveWithinDoc=false, bool bInsInPage=true)
Definition: doclay.cxx:105
sal_uInt16 GetPageNum() const
Definition: fmtanchr.hxx:66
virtual Size GetTwipSize() const =0
#define MINFLY
Definition: swtypes.hxx:65
virtual void SetModified()=0
Must be called manually at changes of format.
sal_uIntPtr sal_uLong
constexpr OUStringLiteral last
virtual SdrLayerID GetHeavenId() const =0
const SvxFrameDirectionItem & GetFrameDir(bool=true) const
Definition: frmatr.hxx:94
const SwPageDesc * FindPageDesc(size_t *pPgDescNdIdx=nullptr) const
Search PageDesc with which this node is formatted.
Definition: node.cxx:472
static SwFlyFrameFormat * lcl_InsertLabel(SwDoc &rDoc, SwTextFormatColls *const pTextFormatCollTable, SwUndoInsertLabel *const pUndo, SwLabelType const eType, std::u16string_view rText, std::u16string_view rSeparator, const OUString &rNumberingSeparator, const bool bBefore, const sal_uInt16 nId, const sal_uLong nNdIdx, const OUString &rCharacterStyle, const bool bCpyBrd)
Definition: doclay.cxx:629
sal_Int64 n
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Closes undo block.
Definition: doc.hxx:186
OUString GetUniqueFrameName() const
Definition: doclay.cxx:1377
constexpr TypedWhichId< SwFormatFlyCnt > RES_TXTATR_FLYCNT(57)
SwFlyFrameFormat * MakeFlySection_(const SwPosition &rAnchPos, const SwContentNode &rNode, RndStdIds eRequestId, const SfxItemSet *pFlyAttrSet, SwFrameFormat *)
Definition: doclay.cxx:152
SwNode & GetNode() const
Definition: ndindex.hxx:119
OUString newName(std::u16string_view aNewPrefix, const OUString &aOldPrefix, std::u16string_view old_Name)
Content, content of frame (header, footer, fly).
Definition: fmtcntnt.hxx:31
SvxFrameDirection
constexpr TypedWhichId< SvxOpaqueItem > RES_OPAQUE(99)
SvxFrameDirection GetTextDirection(const SwPosition &rPos, const Point *pPt=nullptr) const
Definition: doclay.cxx:1610
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:144
sal_uInt16 Which() const
Definition: txatbase.hxx:110
SwContentFrame * FindFirstBodyContent()
Definition: pagefrm.hxx:334
virtual bool DeleteAndJoin(SwPaM &, const bool bForceJoinNext=false)=0
complete delete of a given PaM
virtual SwFrameFormat * GetFrameFormatFromPool(sal_uInt16 nId)=0
Return required automatic format.
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:315
SwContact * GetUserCall(const SdrObject *pObj)
Returns the UserCall if applicable from the group object.
Definition: dcontact.cxx:171
static void lcl_collectUsedNums(std::vector< unsigned int > &rSetFlags, sal_Int32 nNmLen, const OUString &rName, std::u16string_view rCmpName)
Definition: doclay.cxx:1277
static SwFlyFrameFormat * lcl_InsertDrawLabel(SwDoc &rDoc, SwTextFormatColls *const pTextFormatCollTable, SwUndoInsertLabel *const pUndo, SwDrawFrameFormat *const pOldFormat, OUString const &rText, const OUString &rSeparator, const OUString &rNumberSeparator, const sal_uInt16 nId, const OUString &rCharacterStyle, SdrObject &rSdrObj)
Definition: doclay.cxx:992
virtual SdrObjList * GetSubList() const
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:203
bool mbInReading
Definition: doc.hxx:304
const SwFrameFormats * GetSpzFrameFormats() const
Definition: doc.hxx:743
SwPosFlyFrames GetAllFlyFormats(const SwPaM *, bool bDrawAlso, bool bAsCharAlso=false) const
Returns positions of all FlyFrames in the document.
Definition: doclay.cxx:503
Value in Var-direction gives minimum (can be exceeded but not be less).
bool IsInHeaderFooter(const SwNodeIndex &rIdx) const
Definition: doclay.cxx:1551
SwFlyFrameFormat * MakeFlyFrameFormat(const OUString &rFormatName, SwFrameFormat *pDerivedFrom)
Create the formats.
Definition: docfmt.cxx:740
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
Definition: doc.cxx:155
bool mbCopyIsMove
Definition: doc.hxx:303
SwTextAttr * GetTextAttrForCharAt(const sal_Int32 nIndex, const sal_uInt16 nWhich=RES_TXTATR_END) const
get the text attribute at position nIndex which owns the dummy character CH_TXTATR_* at that position...
Definition: ndtxt.cxx:3020
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:357
void Delete(const SwNodeIndex &rPos, sal_uLong nNodes=1)
delete nodes
Definition: nodes.cxx:1072
constexpr TypedWhichId< SwFormatVertOrient > RES_VERT_ORIENT(102)
virtual SdrPage * AllocPage(bool bMasterPage) override
Create a new page (SdPage) and return a pointer to it back.
Definition: drawdoc.cxx:96
wrapper class for the positioning of Writer fly frames and drawing objects
SwFlyFrameFormat * MakeFlySection(RndStdIds eAnchorType, const SwPosition *pAnchorPos, const SfxItemSet *pSet=nullptr, SwFrameFormat *pParent=nullptr, bool bCalledFromShell=false)
Definition: doclay.cxx:286
SwNodeType GetNodeType() const
Definition: node.hxx:144
constexpr TypedWhichId< SwFormatHoriOrient > RES_HORI_ORIENT(103)
SwIndex nContent
Definition: pam.hxx:38
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
Unsorted, undeleting SwFrameFormat vector.
Definition: docary.hxx:177
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:426
const SwTextFormatColl * GetDfltTextFormatColl() const
Definition: doc.hxx:777
bool IsInVerticalText(const SwPosition &rPos) const
Definition: doclay.cxx:1663
svt::EmbeddedObjectRef & GetObject()
Definition: ndole.cxx:967
const OUString & GetName() const
Definition: format.hxx:132
int nCount
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
virtual void DelAllUndoObj()=0
Delete all Undo actions.
SVX_NUM_ARABIC
virtual void SetName(const OUString &rNewName, bool bBroadcast=false) override
Definition: atrfrm.cxx:2470
bool IsTextFrame() const
Definition: frame.hxx:1215
virtual void DoUndo(bool const bDoUndo)=0
Enable/Disable Undo.
static SW_DLLPUBLIC sal_uInt16 GetPoolIdFromUIName(const OUString &rName, SwGetPoolIdFromName)
SwFlyFrameFormat * MakeFlyAndMove(const SwPaM &rPam, const SfxItemSet &rSet, const SwSelBoxes *pSelBoxes, SwFrameFormat *pParent)
Definition: doclay.cxx:341
std::vector< SwFrameFormat * > const * GetAnchoredFlys() const
Definition: node.hxx:296
SwTextAttr * InsertItem(SfxPoolItem &rAttr, const sal_Int32 nStart, const sal_Int32 nEnd, const SetAttrMode nMode=SetAttrMode::DEFAULT)
create new text attribute from rAttr and insert it
Definition: thints.cxx:1270
const SwTable & GetTable() const
Definition: node.hxx:500
const SvxFormatKeepItem & GetKeep(bool=true) const
Definition: frmatr.hxx:86
const SfxPoolItem * GetDfltAttr(sal_uInt16 nWhich)
Get the default attribute from corresponding default attribute table.
Definition: hints.cxx:153
void SetFlyName(SwFlyFrameFormat &rFormat, const OUString &rName)
Definition: doclay.cxx:1419
o3tl::sorted_vector< SwRootFrame * > GetAllLayouts()
Definition: doclay.cxx:1669
static sal_uInt16 IsMath(const SvGlobalName &rName)
size_type size() const
#define DEF_FLY_WIDTH
Definition: doclay.cxx:93
Other stuff.
Definition: poolfmt.hxx:351
virtual bool DoesUndo() const =0
Is Undo enabled?
void SetDrawObj(SdrLayerID nLayerId)
Definition: unins.cxx:1033
virtual std::unique_ptr< SfxItemSet > Clone(bool bItems=true, SfxItemPool *pToPool=nullptr) const override
Definition: swatrset.cxx:147
const char * sName
SwPaM * GetNext()
Definition: pam.hxx:264
const SvxFormatKeepItem & GetKeep(bool=true) const
Definition: frmatr.hxx:56
Specific frame formats (frames, DrawObjects).
void SetContainsAtPageObjWithContentAnchor(const bool bFlag)
Definition: doc.hxx:567
MakeFlyAndMove.
virtual SdrLayerID GetInvisibleHellId() const =0
static bool lcl_IsItemSet(const SwContentNode &rNode, sal_uInt16 which)
Definition: doclay.cxx:95
SwStartNode * MakeTextSection(const SwNodeIndex &rWhere, SwStartNodeType eSttNdTyp, SwTextFormatColl *pColl)
Definition: nodes.cxx:1884
SwTableSortBoxes & GetTabSortBoxes()
Definition: swtable.hxx:261
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
std::unique_ptr< SwTextFormatColls > mpTextFormatCollTable
Definition: doc.hxx:243
virtual void SetLayer(SdrLayerID nLayer)
virtual void InsertPage(SdrPage *pPage, sal_uInt16 nPos=0xFFFF) override
virtual void AppendUndo(std::unique_ptr< SwUndo > pUndo)=0
Add new Undo action.
virtual void ClearRedo()=0
Delete all Redo actions.
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
const SwFlyFrameFormat * FindFlyByName(const OUString &rName, SwNodeType nNdTyp=SwNodeType::NONE) const
Definition: doclay.cxx:1392
Style of a layout element.
Definition: frmfmt.hxx:58
static OUString lcl_GetUniqueFlyName(const SwDoc &rDoc, const char *pDefStrId, sal_uInt16 eType)
Definition: doclay.cxx:1327
virtual SwUndoId StartUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Opens undo block.
SwNodeType
Definition: ndtyp.hxx:28
#define SW_MOD()
Definition: swmodule.hxx:255
void SectionDown(SwNodeRange *pRange, SwStartNodeType=SwNormalStartNode)
create a start/end section pair
Definition: nodes.cxx:899
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SwSortedObjs * GetSortedObjs() const
Definition: pagefrm.hxx:116
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:81
int i
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:131
const SwPosition * GetPoint() const
Definition: pam.hxx:207
virtual bool CopyRange(SwPaM &rPam, SwPosition &rPos, SwCopyFlags flags) const =0
Copy a selected content range to a position.
SwFrameFormat * GetFormat()
Definition: dcontact.hxx:112
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:206
RndStdIds GetAnchorId() const
Definition: fmtanchr.hxx:65
const SwFormatHoriOrient & GetHoriOrient(bool=true) const
Definition: fmtornt.hxx:108
const SwPosition * GetContentAnchor() const
Definition: fmtanchr.hxx:67
Text body.
Definition: poolfmt.hxx:250
static bool lcl_TstFlyRange(const SwPaM *pPam, const SwPosition *pFlyPos, RndStdIds nAnchorId)
Definition: doclay.cxx:466
SwContentNode * GetContentNode()
Definition: node.hxx:618
FlyAnchors.
Definition: fmtanchr.hxx:34
const SvxPageUsage aArr[]
SwNoTextNode * GetNoTextNode()
Definition: ndnotxt.hxx:96
const SdrPage * GetPage(sal_uInt16 nPgNum) const
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
virtual void DelFrames()
Destroys all Frames in aDepend (Frames are identified via dynamic_cast).
Definition: atrfrm.cxx:2643
Marks a character position inside a document model node.
Definition: index.hxx:33
size_t size() const
Definition: docary.hxx:84
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:394
bool IsNoTextNode() const
Definition: node.hxx:651
bool IsGroupObject() const
SwFrame * GetPrev()
Definition: frame.hxx:660
size
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
Definition: format.cxx:401
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:696
virtual const SwFieldTypes * GetFieldTypes() const =0
ring_container GetRingContainer()
Definition: ring.hxx:240
bool IsResizeProtect() const
OUString SwResId(const char *pId)
Definition: swmodule.cxx:166
void InsertObjectThenMakeNameUnique(SdrObject *pObj)
bool empty() const
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
SwFlyFrameFormat * InsertLabel(const SwLabelType eType, const OUString &rText, const OUString &rSeparator, const OUString &rNumberingSeparator, const bool bBefore, const sal_uInt16 nId, const sal_uLong nIdx, const OUString &rCharacterStyle, const bool bCpyBrd)
Definition: doclay.cxx:960
void SetFlys(SwFrameFormat &rOldFly, SfxItemSet const &rChgSet, SwFrameFormat &rNewFly)
Definition: unins.cxx:1018
A page of the document layout.
Definition: pagefrm.hxx:41
virtual bool MoveNodeRange(SwNodeRange &, SwNodeIndex &, SwMoveFlags)=0
virtual SwFormatFrameSize * Clone(SfxItemPool *pPool=nullptr) const override
Definition: atrfrm.cxx:246
Frame cannot be moved in Var-direction.
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:405
OUString GetName() const
Size GetSize() const
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
constexpr TypedWhichId< SwFormatContent > RES_CNTNT(95)
void SetWidth(tools::Long n)
void push_back(Value const &rVal)
Definition: docary.hxx:98
virtual SdrLayerID GetHellId() const =0
virtual void SetRedlineMove(bool bFlag)=0
virtual SdrLayerID GetLayer() const
OUString GetUniqueShapeName() const
Definition: doclay.cxx:1382
const SwNodeIndex * GetContentIdx() const
Definition: fmtcntnt.hxx:46
SvxFrameDirection GetTextDirection(const SwPosition &rPos, const Point *pPt) const
determines the text direction for a certain position.
Definition: node.cxx:2056
virtual SdrLayerID GetInvisibleLayerIdByVisibleOne(SdrLayerID _nVisibleLayerId)=0
method to determine, if the corresponding invisible layer ID for a visible one.
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:463
sal_uInt16 Which() const
for Querying of Writer-functions.
Definition: format.hxx:97
void UpdateFootnote(const SwNodeIndex &rStt)
Definition: ftnidx.cxx:60
static void SetUniqueSeqRefNo(SwDoc &rDoc)
Set a unique sequential reference number for every footnote in the document.
Definition: atrftn.cxx:557
OUString InsertText(const OUString &rStr, const SwIndex &rIdx, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
insert text content
Definition: ndtxt.cxx:2245
SwFrameFormat & GetMaster()
Definition: pagedesc.hxx:216
sal_uLong EndOfSectionIndex() const
Definition: node.hxx:680
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
virtual void DelFrames() override
DrawObjects are removed from the arrays at the layout.
Definition: atrfrm.cxx:3397
const SvxULSpaceItem & GetULSpace(bool=true) const
Definition: frmatr.hxx:76
void SetSizeProtect(bool bNew)
virtual void MakeFrames() override
Creates the views.
Definition: atrfrm.cxx:2876
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:335
constexpr sal_uInt16 RES_FMT_BEGIN(RES_UNKNOWNATR_END)
SwFlyFrameFormat * InsertDrawLabel(const OUString &rText, const OUString &rSeparator, const OUString &rNumberSeparator, const sal_uInt16 nId, const OUString &rCharacterStyle, SdrObject &rObj)
Definition: doclay.cxx:1233
virtual bool SetAttr(const SfxPoolItem &)
made virtual
Definition: node.cxx:1558
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(105)
void SetPosProtect(bool bNew)
std::deque< AttacherIndex_Impl > aIndex
constexpr sal_uInt16 RES_FMT_END(159)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
virtual SdrLayerID GetInvisibleHeavenId() const =0
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:254
OUString aName
sal_Int32 GetIndex() const
Definition: index.hxx:91
OString DateTimeToOString(const DateTime &rDateTime)
virtual SwDrawModel * GetOrCreateDrawModel()=0
SwNodes & GetNodes()
Definition: doc.hxx:407
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
const SwPosition * End() const
Definition: pam.hxx:217
virtual SdrObject * CloneSdrObject(SdrModel &rTargetModel) const
::sw::DocumentSettingManager & GetDocumentSettingManager()
Definition: doc.cxx:186
bool MakeCopy(SwDoc &, const SwPosition &, const SwSelBoxes &, bool bCpyName=false) const
Definition: tblrwcl.cxx:2045
SwFrame * GetLower()
Definition: findfrm.cxx:170
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(91)
constexpr TypedWhichId< SwDrawFrameFormat > RES_DRAWFRMFMT(157)
constexpr TypedWhichId< SvxBoxItem > RES_BOX(106)
Format of a fly content.
Definition: fmtflcnt.hxx:32
const SwFormatFrameSize & GetFrameSize(bool=true) const
Definition: fmtfsize.hxx:104
constexpr TypedWhichId< SwFlyFrameFormat > RES_FLYFRMFMT(154)
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:717
const SwFormatContent & GetContent(bool=true) const
Definition: fmtcntnt.hxx:55
const SwStartNode * FindFlyStartNode() const
Definition: node.hxx:198
SwFootnoteIdxs & GetFootnoteIdxs()
Definition: doc.hxx:632
SwFrameFormat * GetFrameFormat() const
Definition: fmtflcnt.hxx:45
Reference< XModel > xModel
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc...
Definition: nodes.cxx:2320
RndStdIds
size_t size() const
void SetContentProtect(bool bNew)
SwFrameFormatsBase::size_type size_type
const SwAttrSet & GetAttrSet() const
For querying the attribute array.
Definition: format.hxx:137
Frame is variable in Var-direction.
std::pair< const_iterator, bool > insert(Value &&x)
static void lcl_CpyAttr(SfxItemSet &rNewSet, const SfxItemSet &rOldSet, sal_uInt16 nWhich)
Definition: doclay.cxx:599
void UpdateAllFootnote()
Definition: ftnidx.cxx:267
std::pair< const_range_iterator, const_range_iterator > rangeFind(sal_uInt16 type, const OUString &name) const
Definition: docfmt.cxx:2070
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
class for collecting anchored objects
Definition: sortedobjs.hxx:48
void SetHeightSizeType(SwFrameSize eSize)
Definition: fmtfsize.hxx:81
SwFrameFormat * GetFlyFormat() const
If node is in a fly return the respective format.
Definition: node.cxx:717
SdrObject * FindSdrObject()
Definition: frmfmt.hxx:138
constexpr TypedWhichId< SvxULSpaceItem > RES_UL_SPACE(92)
const SwFootnoteInfo & GetFootnoteInfo() const
Definition: doc.hxx:628
constexpr TypedWhichId< SvxAdjustItem > RES_PARATR_ADJUST(64)
constexpr TypedWhichId< SvxShadowItem > RES_SHADOW(107)
void SetAllUniqueFlyNames()
Definition: doclay.cxx:1445
bool IsMoveProtect() const
constexpr TypedWhichId< SwFormatAnchor > RES_ANCHOR(104)
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1319
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:846
bool HasHints() const
Definition: ndtxt.hxx:221
SwTextNode * MakeTextNode(const SwNodeIndex &rWhere, SwTextFormatColl *pColl, bool bNewFrames=true)
Implementations of "Make...Node" are in the given .cxx-files.
Definition: ndtxt.cxx:104
void SetAnchor(const SwPosition *pPos)
Definition: atrfrm.cxx:1493
const SwFormatFlyCnt & GetFlyCnt() const
Definition: txatbase.hxx:206
SwFrame * GetNext()
Definition: frame.hxx:659
const SvxLRSpaceItem & GetLRSpace(bool=true) const
Definition: frmatr.hxx:74
Base class of the Writer document model elements.
Definition: node.hxx:79