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 <osl/diagnose.h>
31 #include <svx/svdouno.hxx>
32 #include <editeng/frmdiritem.hxx>
33 #include <istype.hxx>
34 #include <swmodule.hxx>
35 #include <modcfg.hxx>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/embed/XEmbeddedObject.hpp>
38 #include <SwStyleNameMapper.hxx>
39 #include <drawdoc.hxx>
40 #include <fchrfmt.hxx>
41 #include <frmatr.hxx>
42 #include <txatbase.hxx>
43 #include <fmtfld.hxx>
44 #include <fmtornt.hxx>
45 #include <fmtcntnt.hxx>
46 #include <fmtanchr.hxx>
47 #include <fmtfsize.hxx>
48 #include <fmtsrnd.hxx>
49 #include <fmtflcnt.hxx>
50 #include <frmfmt.hxx>
51 #include <pam.hxx>
52 #include <ndtxt.hxx>
53 #include <ndnotxt.hxx>
54 #include <ndole.hxx>
55 #include <doc.hxx>
56 #include <IDocumentUndoRedo.hxx>
61 #include <IDocumentState.hxx>
64 #include <rootfrm.hxx>
65 #include <pagefrm.hxx>
66 #include <cntfrm.hxx>
67 #include <txtfrm.hxx>
68 #include <notxtfrm.hxx>
69 #include <dflyobj.hxx>
70 #include <dcontact.hxx>
71 #include <swundo.hxx>
72 #include <flypos.hxx>
73 #include <UndoInsert.hxx>
74 #include <expfld.hxx>
75 #include <poolfmt.hxx>
76 #include <docary.hxx>
77 #include <swtable.hxx>
78 #include <tblsel.hxx>
79 #include <txtftn.hxx>
80 #include <ftnidx.hxx>
81 #include <ftninfo.hxx>
82 #include <pagedesc.hxx>
83 #include <strings.hrc>
84 #include <frameformats.hxx>
85 #include <tools/datetimeutils.hxx>
86 #include <comphelper/string.hxx>
87 #include <o3tl/string_view.hxx>
88 
89 #include <sortedobjs.hxx>
90 
91 #include <string_view>
92 #include <vector>
93 
94 using namespace ::com::sun::star;
95 
96 #define DEF_FLY_WIDTH 2268 // Default width for FlyFrames (2268 == 4cm)
97 
98 static bool lcl_IsItemSet(const SwContentNode & rNode, sal_uInt16 which)
99 {
100  bool bResult = false;
101 
102  if (SfxItemState::SET == rNode.GetSwAttrSet().GetItemState(which))
103  bResult = true;
104 
105  return bResult;
106 }
107 
108 SdrObject* SwDoc::CloneSdrObj( const SdrObject& rObj, bool bMoveWithinDoc,
109  bool bInsInPage )
110 {
111  // #i52858# - method name changed
113  if( !pPg )
114  {
115  auto pNewPage = getIDocumentDrawModelAccess().GetDrawModel()->AllocPage( false );
116  getIDocumentDrawModelAccess().GetDrawModel()->InsertPage( pNewPage.get() );
117  pPg = pNewPage.get();
118  }
119 
120  // TTTT Clone directly to target SdrModel
121  SdrObject *pObj(rObj.CloneSdrObject(*getIDocumentDrawModelAccess().GetDrawModel()));
122 
123  if( bMoveWithinDoc && SdrInventor::FmForm == pObj->GetObjInventor() )
124  {
125  // We need to preserve the Name for Controls
126  uno::Reference< awt::XControlModel > xModel = static_cast<SdrUnoObj*>(pObj)->GetUnoControlModel();
127  uno::Any aVal;
128  uno::Reference< beans::XPropertySet > xSet(xModel, uno::UNO_QUERY);
129  static const OUStringLiteral sName(u"Name");
130  if( xSet.is() )
131  aVal = xSet->getPropertyValue( sName );
132  if( bInsInPage )
133  pPg->InsertObjectThenMakeNameUnique( pObj );
134  if( xSet.is() )
135  xSet->setPropertyValue( sName, aVal );
136  }
137  else if( bInsInPage )
138  pPg->InsertObjectThenMakeNameUnique( pObj );
139 
140  // For drawing objects: set layer of cloned object to invisible layer
141  SdrLayerID nLayerIdForClone = rObj.GetLayer();
142  if ( dynamic_cast<const SwFlyDrawObj*>( pObj) == nullptr &&
143  dynamic_cast<const SwVirtFlyDrawObj*>( pObj) == nullptr &&
144  !isType<SdrObject>(pObj) )
145  {
146  if ( getIDocumentDrawModelAccess().IsVisibleLayerId( nLayerIdForClone ) )
147  {
148  nLayerIdForClone = getIDocumentDrawModelAccess().GetInvisibleLayerIdByVisibleOne( nLayerIdForClone );
149  }
150  }
151  pObj->SetLayer( nLayerIdForClone );
152 
153  return pObj;
154 }
155 
157  const SwContentNode& rNode,
158  RndStdIds eRequestId,
159  const SfxItemSet* pFlySet,
160  SwFrameFormat* pFrameFormat )
161 {
162  if( !pFrameFormat )
164 
165  OUString sName;
166  if( !mbInReading )
167  switch( rNode.GetNodeType() )
168  {
169  case SwNodeType::Grf: sName = GetUniqueGrfName(); break;
170  case SwNodeType::Ole: sName = GetUniqueOLEName(); break;
171  default: sName = GetUniqueFrameName(); break;
172  }
173  SwFlyFrameFormat* pFormat = MakeFlyFrameFormat( sName, pFrameFormat );
174 
175  // Create content and connect to the format.
176  // Create ContentNode and put it into the autotext selection.
177  SwNodeRange aRange( GetNodes().GetEndOfAutotext(), SwNodeOffset(-1),
178  GetNodes().GetEndOfAutotext() );
179  GetNodes().SectionDown( &aRange, SwFlyStartNode );
180 
181  pFormat->SetFormatAttr( SwFormatContent( rNode.StartOfSectionNode() ));
182 
183  const SwFormatAnchor* pAnchor = nullptr;
184  if( pFlySet )
185  {
186  pAnchor = pFlySet->GetItemIfSet( RES_ANCHOR, false );
187  if( SfxItemState::SET == pFlySet->GetItemState( RES_CNTNT, false ))
188  {
189  SfxItemSet aTmpSet( *pFlySet );
190  aTmpSet.ClearItem( RES_CNTNT );
191  pFormat->SetFormatAttr( aTmpSet );
192  }
193  else
194  pFormat->SetFormatAttr( *pFlySet );
195  }
196 
197  // Anchor not yet set?
198  RndStdIds eAnchorId;
199  // #i107811# Assure that at-page anchored fly frames have a page num or a
200  // content anchor set.
201  if ( !pAnchor ||
202  ( RndStdIds::FLY_AT_PAGE != pAnchor->GetAnchorId() &&
203  !pAnchor->GetContentAnchor() ) ||
204  ( RndStdIds::FLY_AT_PAGE == pAnchor->GetAnchorId() &&
205  !pAnchor->GetContentAnchor() &&
206  pAnchor->GetPageNum() == 0 ) )
207  {
208  // set it again, needed for Undo
209  SwFormatAnchor aAnch( pFormat->GetAnchor() );
210  if (pAnchor && (RndStdIds::FLY_AT_FLY == pAnchor->GetAnchorId()))
211  {
212  SwPosition aPos( *rAnchPos.nNode.GetNode().FindFlyStartNode() );
213  aAnch.SetAnchor( &aPos );
214  eAnchorId = RndStdIds::FLY_AT_FLY;
215  }
216  else
217  {
218  if( eRequestId != aAnch.GetAnchorId() &&
219  SfxItemState::SET != pFormat->GetItemState( RES_ANCHOR ) )
220  {
221  aAnch.SetType( eRequestId );
222  }
223 
224  eAnchorId = aAnch.GetAnchorId();
225  if ( RndStdIds::FLY_AT_PAGE != eAnchorId || !pAnchor || aAnch.GetPageNum() == 0)
226  {
227  aAnch.SetAnchor( &rAnchPos );
228  }
229  }
230  pFormat->SetFormatAttr( aAnch );
231  }
232  else
233  eAnchorId = pFormat->GetAnchor().GetAnchorId();
234 
235  if ( RndStdIds::FLY_AS_CHAR == eAnchorId )
236  {
237  const sal_Int32 nStt = rAnchPos.nContent.GetIndex();
238  SwTextNode * pTextNode = rAnchPos.nNode.GetNode().GetTextNode();
239 
240  OSL_ENSURE(pTextNode!= nullptr, "There should be a SwTextNode!");
241 
242  if (pTextNode != nullptr)
243  {
244  SwFormatFlyCnt aFormat( pFormat );
245  // may fail if there's no space left or header/ftr
246  if (!pTextNode->InsertItem(aFormat, nStt, nStt))
247  { // pFormat is dead now
248  return nullptr;
249  }
250  }
251  }
252 
253  if( SfxItemState::SET != pFormat->GetAttrSet().GetItemState( RES_FRM_SIZE ))
254  {
256  const SwNoTextNode* pNoTextNode = rNode.GetNoTextNode();
257  if( pNoTextNode )
258  {
259  // Set size
260  Size aSize( pNoTextNode->GetTwipSize() );
261  if( MINFLY > aSize.Width() )
262  aSize.setWidth( DEF_FLY_WIDTH );
263  aFormatSize.SetWidth( aSize.Width() );
264  if( aSize.Height() )
265  {
266  aFormatSize.SetHeight( aSize.Height() );
267  aFormatSize.SetHeightSizeType( SwFrameSize::Fixed );
268  }
269  }
270  pFormat->SetFormatAttr( aFormatSize );
271  }
272 
273  // Set up frames
274  if( getIDocumentLayoutAccess().GetCurrentViewShell() )
275  pFormat->MakeFrames(); // ???
276 
277  if (GetIDocumentUndoRedo().DoesUndo())
278  {
279  SwNodeOffset nNodeIdx = rAnchPos.nNode.GetIndex();
280  const sal_Int32 nCntIdx = rAnchPos.nContent.GetIndex();
282  std::make_unique<SwUndoInsLayFormat>( pFormat, nNodeIdx, nCntIdx ));
283  }
284 
286  return pFormat;
287 }
288 
290  const SwPosition* pAnchorPos,
291  const SfxItemSet* pFlySet,
292  SwFrameFormat* pFrameFormat, bool bCalledFromShell )
293 {
294  SwFlyFrameFormat* pFormat = nullptr;
295  if ( !pAnchorPos && (RndStdIds::FLY_AT_PAGE != eAnchorType) )
296  {
297  const SwFormatAnchor* pAnch;
298  if( (pFlySet && (pAnch = pFlySet->GetItemIfSet( RES_ANCHOR, false ))) ||
299  ( pFrameFormat && (pAnch = pFrameFormat->GetItemIfSet(RES_ANCHOR)) ) )
300  {
301  if ( RndStdIds::FLY_AT_PAGE != pAnch->GetAnchorId() )
302  {
303  pAnchorPos = pAnch->GetContentAnchor();
304  }
305  }
306  }
307 
308  if (pAnchorPos)
309  {
310  if( !pFrameFormat )
312 
313  sal_uInt16 nCollId = o3tl::narrowing<sal_uInt16>(
315 
316  /* If there is no adjust item in the paragraph style for the content node of the new fly section
317  propagate an existing adjust item at the anchor to the new content node. */
318  SwContentNode * pNewTextNd = GetNodes().MakeTextNode
319  (SwNodeIndex( GetNodes().GetEndOfAutotext()),
320  getIDocumentStylePoolAccess().GetTextCollFromPool( nCollId ));
321  SwContentNode * pAnchorNode = pAnchorPos->nNode.GetNode().GetContentNode();
322  // pAnchorNode from cursor must be valid, unless a whole table is selected (in which
323  // case the node is not a content node, and pAnchorNode is nullptr). In the latter case,
324  // bCalledFromShell is false.
325  assert(!bCalledFromShell || pAnchorNode);
326 
327  const SfxPoolItem * pItem = nullptr;
328 
329  if (bCalledFromShell && !lcl_IsItemSet(*pNewTextNd, RES_PARATR_ADJUST) &&
330  SfxItemState::SET == pAnchorNode->GetSwAttrSet().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, SwNodeOffset(0), *pTableNd->EndOfSectionNode(), SwNodeOffset(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 SwNodeOffset nFlyIndex = pFlyPos->nNode.GetIndex();
473  const SwPosition* pPaMStart = pTmp->Start();
474  const SwPosition* pPaMEnd = pTmp->End();
475  const SwNodeOffset nPamStartIndex = pPaMStart->nNode.GetIndex();
476  const SwNodeOffset 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 ( pAnchoredObj->DynCastFlyFrame() != 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 SwNodeOffset 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  SwNodeOffset 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  auto pOldFlyFrameFormat = dynamic_cast<SwFlyFrameFormat*>(pOldFormat);
718  const OUString sTitle( pOldFlyFrameFormat
719  ? pOldFlyFrameFormat->GetObjTitle()
720  : OUString() );
721  const OUString sDescription( pOldFlyFrameFormat
722  ? pOldFlyFrameFormat->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 ( pOldFlyFrameFormat )
871  {
872  pOldFlyFrameFormat->SetObjTitle( sTitle );
873  pOldFlyFrameFormat->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, SwNodeOffset 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, std::u16string_view rName, std::u16string_view rCmpName)
1278 {
1279  if (o3tl::starts_with(rName, rCmpName))
1280  {
1281  // Only get and set the Flag
1282  const sal_Int32 nNum = o3tl::toInt32(rName.substr(nNmLen)) - 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, TranslateId 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, TranslateId(nullptr, "DrawObject"), RES_DRAWFRMFMT);
1390 }
1391 
1392 const SwFlyFrameFormat* SwDoc::FindFlyByName( const OUString& rName, SwNodeType nNdTyp ) const
1393 {
1394  auto it = GetSpzFrameFormats()->findByTypeAndName( RES_FLYFRMFMT, rName );
1395  if( it == GetSpzFrameFormats()->typeAndNameEnd() )
1396  return nullptr;
1397 
1398  const SwFrameFormat* pFlyFormat = *it;
1399  assert( RES_FLYFRMFMT == pFlyFormat->Which() && pFlyFormat->GetName() == rName );
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  return nullptr;
1416 }
1417 
1418 void SwDoc::SetFlyName( SwFlyFrameFormat& rFormat, const OUString& rName )
1419 {
1420  OUString sName( rName );
1421  if( sName.isEmpty() || FindFlyByName( sName ) )
1422  {
1423  TranslateId pTyp = STR_FRAME_DEFNAME;
1424  const SwNodeIndex* pIdx = rFormat.GetContent().GetContentIdx();
1425  if( pIdx && pIdx->GetNode().GetNodes().IsDocNodes() )
1426  {
1427  switch( GetNodes()[ pIdx->GetIndex() + 1 ]->GetNodeType() )
1428  {
1429  case SwNodeType::Grf:
1430  pTyp = STR_GRAPHIC_DEFNAME;
1431  break;
1432  case SwNodeType::Ole:
1433  pTyp = STR_OBJECT_DEFNAME;
1434  break;
1435  default: break;
1436  }
1437  }
1438  sName = lcl_GetUniqueFlyName(*this, pTyp, RES_FLYFRMFMT);
1439  }
1440  rFormat.SetName( sName, true );
1442 }
1443 
1445 {
1446  sal_Int32 n, nFlyNum = 0, nGrfNum = 0, nOLENum = 0;
1447 
1448  const OUString sFlyNm(SwResId(STR_FRAME_DEFNAME));
1449  const OUString sGrfNm(SwResId(STR_GRAPHIC_DEFNAME));
1450  const OUString sOLENm(SwResId(STR_OBJECT_DEFNAME));
1451 
1452  n = GetSpzFrameFormats()->size();
1453  if( 255 < n )
1454  n = 255;
1456  aArr.reserve( n );
1457  SwFrameFormat* pFlyFormat;
1458  bool bContainsAtPageObjWithContentAnchor = false;
1459 
1460  for( n = GetSpzFrameFormats()->size(); n; )
1461  {
1462  pFlyFormat = (*GetSpzFrameFormats())[ --n ];
1463  if( RES_FLYFRMFMT == pFlyFormat->Which() )
1464  {
1465  const OUString& aNm = pFlyFormat->GetName();
1466  if ( !aNm.isEmpty() )
1467  {
1468  sal_Int32 *pNum = nullptr;
1469  sal_Int32 nLen = 0;
1470  if ( aNm.startsWith(sGrfNm) )
1471  {
1472  nLen = sGrfNm.getLength();
1473  pNum = &nGrfNum;
1474  }
1475  else if( aNm.startsWith(sFlyNm) )
1476  {
1477  nLen = sFlyNm.getLength();
1478  pNum = &nFlyNum;
1479  }
1480  else if( aNm.startsWith(sOLENm) )
1481  {
1482  nLen = sOLENm.getLength();
1483  pNum = &nOLENum;
1484  }
1485 
1486  if ( pNum )
1487  {
1488  const sal_Int32 nNewLen = o3tl::toInt32(aNm.subView( nLen ));
1489  if (*pNum < nNewLen)
1490  *pNum = nNewLen;
1491  }
1492  }
1493  else
1494  // we want to set that afterwards
1495  aArr.push_back( pFlyFormat );
1496 
1497  }
1498  if ( !bContainsAtPageObjWithContentAnchor )
1499  {
1500  const SwFormatAnchor& rAnchor = pFlyFormat->GetAnchor();
1501  if ( (RndStdIds::FLY_AT_PAGE == rAnchor.GetAnchorId()) &&
1502  rAnchor.GetContentAnchor() )
1503  {
1504  bContainsAtPageObjWithContentAnchor = true;
1505  }
1506  }
1507  }
1508  SetContainsAtPageObjWithContentAnchor( bContainsAtPageObjWithContentAnchor );
1509 
1510  for( n = aArr.size(); n; )
1511  {
1512  pFlyFormat = aArr[ --n ];
1513  const SwNodeIndex* pIdx = pFlyFormat->GetContent().GetContentIdx();
1514  if( pIdx && pIdx->GetNode().GetNodes().IsDocNodes() )
1515  {
1516  switch( GetNodes()[ pIdx->GetIndex() + 1 ]->GetNodeType() )
1517  {
1518  case SwNodeType::Grf:
1519  pFlyFormat->SetName( sGrfNm + OUString::number( ++nGrfNum ));
1520  break;
1521  case SwNodeType::Ole:
1522  pFlyFormat->SetName( sOLENm + OUString::number( ++nOLENum ));
1523  break;
1524  default:
1525  pFlyFormat->SetName( sFlyNm + OUString::number( ++nFlyNum ));
1526  break;
1527  }
1528  }
1529  }
1530  aArr.clear();
1531 
1532  if( GetFootnoteIdxs().empty() )
1533  return;
1534 
1536  // #i52775# Chapter footnotes did not get updated correctly.
1537  // Calling UpdateAllFootnote() instead of UpdateFootnote() solves this problem,
1538  // but I do not dare to call UpdateAllFootnote() in all cases: Safety first.
1539  if ( FTNNUM_CHAPTER == GetFootnoteInfo().m_eNum )
1540  {
1542  }
1543  else
1544  {
1545  SwNodeIndex aTmp( GetNodes() );
1546  GetFootnoteIdxs().UpdateFootnote( aTmp );
1547  }
1548 }
1549 
1550 bool SwDoc::IsInHeaderFooter( const SwNodeIndex& rIdx ) const
1551 {
1552  // That can also be a Fly in a Fly in the Header.
1553  // Is also used by sw3io, to determine if a Redline object is
1554  // in the Header or Footer.
1555  // Because Redlines are also attached to Start and EndNode,
1556  // the Index must not necessarily be from a ContentNode.
1557  SwNode* pNd = &rIdx.GetNode();
1558  const SwNode* pFlyNd = pNd->FindFlyStartNode();
1559  while( pFlyNd )
1560  {
1561  // get up by using the Anchor
1562 #if OSL_DEBUG_LEVEL > 0
1563  std::vector<const SwFrameFormat*> checkFormats;
1564  for( auto pFormat : *GetSpzFrameFormats() )
1565  {
1566  const SwNodeIndex* pIdx = pFormat->GetContent().GetContentIdx();
1567  if( pIdx && pFlyNd == &pIdx->GetNode() )
1568  checkFormats.push_back( pFormat );
1569  }
1570 #endif
1571  std::vector<SwFrameFormat*> const & rFlys(pFlyNd->GetAnchoredFlys());
1572  bool bFound(false);
1573  for (size_t i = 0; i < rFlys.size(); ++i)
1574  {
1575  const SwFrameFormat *const pFormat = rFlys[i];
1576  const SwNodeIndex* pIdx = pFormat->GetContent().GetContentIdx();
1577  if( pIdx && pFlyNd == &pIdx->GetNode() )
1578  {
1579 #if OSL_DEBUG_LEVEL > 0
1580  auto checkPos = std::find(
1581  checkFormats.begin(), checkFormats.end(), pFormat );
1582  assert( checkPos != checkFormats.end());
1583  checkFormats.erase( checkPos );
1584 #endif
1585  const SwFormatAnchor& rAnchor = pFormat->GetAnchor();
1586  if ((RndStdIds::FLY_AT_PAGE == rAnchor.GetAnchorId()) ||
1587  !rAnchor.GetContentAnchor() )
1588  {
1589  return false;
1590  }
1591 
1592  pNd = &rAnchor.GetContentAnchor()->nNode.GetNode();
1593  pFlyNd = pNd->FindFlyStartNode();
1594  bFound = true;
1595  break;
1596  }
1597  }
1598  if (!bFound)
1599  {
1600  OSL_ENSURE(mbInReading, "Found a FlySection but not a Format!");
1601  return false;
1602  }
1603  }
1604 
1605  return nullptr != pNd->FindHeaderStartNode() ||
1606  nullptr != pNd->FindFooterStartNode();
1607 }
1608 
1610  const Point* pPt ) const
1611 {
1612  SvxFrameDirection nRet = SvxFrameDirection::Unknown;
1613 
1614  SwContentNode *pNd = rPos.nNode.GetNode().GetContentNode();
1615 
1616  // #i42921# - use new method <SwContentNode::GetTextDirection(..)>
1617  if ( pNd )
1618  {
1619  nRet = pNd->GetTextDirection( rPos, pPt );
1620  }
1621  if ( nRet == SvxFrameDirection::Unknown )
1622  {
1623  const SvxFrameDirectionItem* pItem = nullptr;
1624  if( pNd )
1625  {
1626  // Are we in a FlyFrame? Then look at that for the correct attribute
1627  const SwFrameFormat* pFlyFormat = pNd->GetFlyFormat();
1628  while( pFlyFormat )
1629  {
1630  pItem = &pFlyFormat->GetFrameDir();
1631  if( SvxFrameDirection::Environment == pItem->GetValue() )
1632  {
1633  pItem = nullptr;
1634  const SwFormatAnchor* pAnchor = &pFlyFormat->GetAnchor();
1635  if ((RndStdIds::FLY_AT_PAGE != pAnchor->GetAnchorId()) &&
1636  pAnchor->GetContentAnchor())
1637  {
1638  pFlyFormat = pAnchor->GetContentAnchor()->nNode.
1639  GetNode().GetFlyFormat();
1640  }
1641  else
1642  pFlyFormat = nullptr;
1643  }
1644  else
1645  pFlyFormat = nullptr;
1646  }
1647 
1648  if( !pItem )
1649  {
1650  const SwPageDesc* pPgDsc = pNd->FindPageDesc();
1651  if( pPgDsc )
1652  pItem = &pPgDsc->GetMaster().GetFrameDir();
1653  }
1654  }
1655  if( !pItem )
1656  pItem = &GetAttrPool().GetDefaultItem( RES_FRAMEDIR );
1657  nRet = pItem->GetValue();
1658  }
1659  return nRet;
1660 }
1661 
1662 bool SwDoc::IsInVerticalText( const SwPosition& rPos ) const
1663 {
1664  const SvxFrameDirection nDir = GetTextDirection( rPos );
1665  return SvxFrameDirection::Vertical_RL_TB == nDir || SvxFrameDirection::Vertical_LR_TB == nDir;
1666 }
1667 
1669 {
1672  if(pStart)
1673  {
1674  for(const SwViewShell& rShell : pStart->GetRingContainer())
1675  {
1676  if(rShell.GetLayout())
1677  aAllLayouts.insert(rShell.GetLayout());
1678  }
1679  }
1680  return aAllLayouts;
1681 }
1682 
1683 /* 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:241
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:692
Starts a section of nodes in the document model.
Definition: node.hxx:313
constexpr TypedWhichId< SvxProtectItem > RES_PROTECT(100)
std::set< SwPosFlyFramePtr, SwPosFlyFrameCmp > SwPosFlyFrames
Definition: flypos.hxx:51
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:159
constexpr TypedWhichId< SvxFrameDirectionItem > RES_FRAMEDIR(120)
Subgroup labels.
Definition: poolfmt.hxx:345
OUString GetUniqueGrfName() const
Definition: doclay.cxx:1367
constexpr TypedWhichId< SwFormatSurround > RES_SURROUND(101)
bool IsInMailMerge() const
Definition: doc.hxx:959
SwNode & GetEndOfAutotext() const
Section for all Flys/Header/Footers.
Definition: ndarr.hxx:155
OUString GetUniqueOLEName() const
Definition: doclay.cxx:1372
SwNodeOffset EndOfSectionIndex() const
Definition: node.hxx:687
const SwStartNode * FindHeaderStartNode() const
Definition: node.hxx:204
SwLabelType
Definition: swtypes.hxx:84
Represents the style of a paragraph.
Definition: fmtcol.hxx:56
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
Marks a position in the document model.
Definition: pam.hxx:36
virtual const tools::Rectangle & GetCurrentBoundRect() const
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:821
OUString GetUniqueDrawObjectName() const
Definition: doclay.cxx:1387
constexpr TypedWhichId< SvxPrintItem > RES_PRINT(98)
void reserve(size_type nSize)
Definition: docary.hxx:102
void SetHeight(tools::Long n)
void setWidth(tools::Long nWidth)
const SwOLEObj & GetOLEObj() const
Definition: ndole.hxx:115
const SwStartNode * FindFooterStartNode() const
Definition: node.hxx:206
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:4885
void SetNodePos(SwNodeOffset nNd)
Definition: UndoInsert.hxx:216
constexpr TypedWhichId< SvxFormatKeepItem > RES_KEEP(110)
const SwFormatVertOrient & GetVertOrient(bool=true) const
Definition: fmtornt.hxx:106
SwNodeIndex nNode
Definition: pam.hxx:38
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
SdrObject * CloneSdrObj(const SdrObject &, bool bMoveWithinDoc=false, bool bInsInPage=true)
Definition: doclay.cxx:108
virtual rtl::Reference< SdrPage > AllocPage(bool bMasterPage) override
Create a new page (SdPage) and return a pointer to it back.
Definition: drawdoc.cxx:97
sal_uInt16 GetPageNum() const
Definition: fmtanchr.hxx:66
virtual Size GetTwipSize() const =0
#define MINFLY
Definition: swtypes.hxx:61
virtual void SetModified()=0
Must be called manually at changes of format.
constexpr OUStringLiteral last
virtual SdrLayerID GetHeavenId() const =0
const SvxFrameDirectionItem & GetFrameDir(bool=true) const
Definition: frmatr.hxx:94
sal_Int64 n
virtual SwUndoId EndUndo(SwUndoId const eUndoId, SwRewriter const *const pRewriter)=0
Closes undo block.
Definition: doc.hxx:187
OUString GetUniqueFrameName() const
Definition: doclay.cxx:1377
SwFlyFrameFormat * MakeFlySection_(const SwPosition &rAnchPos, const SwContentNode &rNode, RndStdIds eRequestId, const SfxItemSet *pFlyAttrSet, SwFrameFormat *)
Definition: doclay.cxx:156
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:1609
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:144
sal_uInt16 Which() const
Definition: txatbase.hxx:116
SwContentFrame * FindFirstBodyContent()
Definition: pagefrm.hxx:350
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:172
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:204
bool mbInReading
Definition: doc.hxx:305
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:1550
constexpr TypedWhichId< SwFlyFrameFormat > RES_FLYFRMFMT(156)
SwFlyFrameFormat * MakeFlyFrameFormat(const OUString &rFormatName, SwFrameFormat *pDerivedFrom)
Create the formats.
Definition: docfmt.cxx:751
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
Definition: doc.cxx:155
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
bool mbCopyIsMove
Definition: doc.hxx:304
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:3068
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:164
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:357
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
Templatized version of GetItemState() to directly return the correct type.
Definition: format.hxx:111
constexpr TypedWhichId< SwFormatVertOrient > RES_VERT_ORIENT(102)
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:289
constexpr TypedWhichId< SwDrawFrameFormat > RES_DRAWFRMFMT(159)
SwNodeType GetNodeType() const
Definition: node.hxx:146
constexpr TypedWhichId< SwFormatHoriOrient > RES_HORI_ORIENT(103)
SwIndex nContent
Definition: pam.hxx:39
Unsorted, undeleting SwFrameFormat vector.
Definition: docary.hxx:177
A wrapper around SfxPoolItem to store the start position of (usually) a text portion, with an optional end.
Definition: txatbase.hxx:43
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:426
const SwTextFormatColl * GetDfltTextFormatColl() const
Definition: doc.hxx:775
bool IsInVerticalText(const SwPosition &rPos) const
Definition: doclay.cxx:1662
svt::EmbeddedObjectRef & GetObject()
Definition: ndole.cxx:990
const OUString & GetName() const
Definition: format.hxx:131
int nCount
virtual void DelAllUndoObj()=0
Delete all Undo actions.
SVX_NUM_ARABIC
virtual void SetName(const OUString &rNewName, bool bBroadcast=false) override
Definition: atrfrm.cxx:2560
bool IsTextFrame() const
Definition: frame.hxx:1234
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
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:1300
const SwTable & GetTable() const
Definition: node.hxx:506
std::vector< SwFrameFormat * > const & GetAnchoredFlys() const
Definition: node.hxx:298
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:1418
o3tl::sorted_vector< SwRootFrame * > GetAllLayouts()
Definition: doclay.cxx:1668
SwNodeOffset GetIndex() const
Definition: ndindex.hxx:152
static sal_uInt16 IsMath(const SvGlobalName &rName)
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 SwNodeOffset nNdIdx, const OUString &rCharacterStyle, const bool bCpyBrd)
Definition: doclay.cxx:629
size_type size() const
#define DEF_FLY_WIDTH
Definition: doclay.cxx:96
Other stuff.
Definition: poolfmt.hxx:352
virtual bool DoesUndo() const =0
Is Undo enabled?
void SetDrawObj(SdrLayerID nLayerId)
Definition: unins.cxx:1040
virtual std::unique_ptr< SfxItemSet > Clone(bool bItems=true, SfxItemPool *pToPool=nullptr) const override
Definition: swatrset.cxx:111
const char * sName
SwPaM * GetNext()
Definition: pam.hxx:265
const SvxFormatKeepItem & GetKeep(bool=true) const
Definition: frmatr.hxx:56
Specific frame formats (frames, DrawObjects).
void SetContainsAtPageObjWithContentAnchor(const bool bFlag)
Definition: doc.hxx:568
MakeFlyAndMove.
virtual SdrLayerID GetInvisibleHellId() const =0
static bool lcl_IsItemSet(const SwContentNode &rNode, sal_uInt16 which)
Definition: doclay.cxx:98
SwStartNode * MakeTextSection(const SwNodeIndex &rWhere, SwStartNodeType eSttNdTyp, SwTextFormatColl *pColl)
Definition: nodes.cxx:1896
SwTableSortBoxes & GetTabSortBoxes()
Definition: swtable.hxx:262
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:137
std::unique_ptr< SwTextFormatColls > mpTextFormatCollTable
Definition: doc.hxx:244
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:59
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:912
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SwSortedObjs * GetSortedObjs() const
Definition: pagefrm.hxx:132
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:81
int i
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:133
const SwPosition * GetPoint() const
Definition: pam.hxx:208
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
constexpr TypedWhichId< SwFormatFlyCnt > RES_TXTATR_FLYCNT(58)
Text body.
Definition: poolfmt.hxx:251
static bool lcl_TstFlyRange(const SwPaM *pPam, const SwPosition *pFlyPos, RndStdIds nAnchorId)
Definition: doclay.cxx:466
SwContentNode * GetContentNode()
Definition: node.hxx:625
SwNodeOffset GetIndex() const
Definition: node.hxx:292
FlyAnchors.
Definition: fmtanchr.hxx:34
const SvxPageUsage aArr[]
SwNoTextNode * GetNoTextNode()
Definition: ndnotxt.hxx:95
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:2694
Marks a character position inside a document model node.
Definition: index.hxx:33
float u
size_t size() const
Definition: docary.hxx:87
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:394
ByTypeAndName::const_iterator findByTypeAndName(sal_uInt16 type, const OUString &name) const
Definition: docfmt.cxx:2085
bool IsNoTextNode() const
Definition: node.hxx:658
bool IsGroupObject() const
SwFrame * GetPrev()
Definition: frame.hxx:677
size
Layout frame for SwNoTextNode, i.e. graphics and OLE nodes (including charts).
Definition: ndnotxt.hxx:29
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
Definition: format.cxx:386
Marks a node in the document model.
Definition: ndindex.hxx:30
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:703
virtual const SwFieldTypes * GetFieldTypes() const =0
ring_container GetRingContainer()
Definition: ring.hxx:240
bool IsResizeProtect() const
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
void InsertObjectThenMakeNameUnique(SdrObject *pObj)
bool empty() const
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
static void lcl_collectUsedNums(std::vector< unsigned int > &rSetFlags, sal_Int32 nNmLen, std::u16string_view rName, std::u16string_view rCmpName)
Definition: doclay.cxx:1277
Represents the style of a text portion.
Definition: charfmt.hxx:26
void SetFlys(SwFrameFormat &rOldFly, SfxItemSet const &rChgSet, SwFrameFormat &rNewFly)
Definition: unins.cxx:1025
A page of the document layout.
Definition: pagefrm.hxx:57
virtual bool MoveNodeRange(SwNodeRange &, SwNodeIndex &, SwMoveFlags)=0
virtual SwFormatFrameSize * Clone(SfxItemPool *pPool=nullptr) const override
Definition: atrfrm.cxx:254
Frame cannot be moved in Var-direction.
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:405
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:112
const SwPosition * Start() const
Definition: pam.hxx:213
constexpr TypedWhichId< SwFormatContent > RES_CNTNT(95)
void SetWidth(tools::Long n)
void push_back(Value const &rVal)
Definition: docary.hxx:101
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:2032
SwFlyFrameFormat * InsertLabel(const SwLabelType eType, const OUString &rText, const OUString &rSeparator, const OUString &rNumberingSeparator, const bool bBefore, const sal_uInt16 nId, const SwNodeOffset nIdx, const OUString &rCharacterStyle, const bool bCpyBrd)
Definition: doclay.cxx:960
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:448
sal_uInt16 Which() const
for Querying of Writer-functions.
Definition: format.hxx:82
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:559
const SwPageDesc * FindPageDesc(SwNodeOffset *pPgDescNdIdx=nullptr) const
Search PageDesc with which this node is formatted.
Definition: node.cxx:475
OUString InsertText(const OUString &rStr, const SwIndex &rIdx, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
insert text content
Definition: ndtxt.cxx:2297
SwCharFormat * FindCharFormatByName(const OUString &rName) const
Definition: doc.hxx:770
SwFrameFormat & GetMaster()
Definition: pagedesc.hxx:238
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
virtual void DelFrames() override
DrawObjects are removed from the arrays at the layout.
Definition: atrfrm.cxx:3463
const SvxULSpaceItem & GetULSpace(bool=true) const
Definition: frmatr.hxx:76
void SetSizeProtect(bool bNew)
virtual void MakeFrames() override
Creates the views.
Definition: atrfrm.cxx:2927
constexpr Size GetSize() const
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
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(105)
void SetPosProtect(bool bNew)
std::deque< AttacherIndex_Impl > aIndex
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.
OUString aName
sal_Int32 GetIndex() const
Definition: index.hxx:91
OString DateTimeToOString(const DateTime &rDateTime)
virtual SwDrawModel * GetOrCreateDrawModel()=0
SwNodes & GetNodes()
Definition: doc.hxx:408
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
const SwPosition * End() const
Definition: pam.hxx:218
virtual SdrObject * CloneSdrObject(SdrModel &rTargetModel) const
::sw::DocumentSettingManager & GetDocumentSettingManager()
Definition: doc.cxx:186
constexpr sal_uInt16 RES_FMT_END(161)
void Delete(const SwNodeIndex &rPos, SwNodeOffset nNodes=SwNodeOffset(1))
delete nodes
Definition: nodes.cxx:1085
SwFrame * GetLower()
Definition: findfrm.cxx:194
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(91)
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
Definition: nodeoffset.hxx:16
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
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:724
const SwFormatContent & GetContent(bool=true) const
Definition: fmtcntnt.hxx:55
const SwStartNode * FindFlyStartNode() const
Definition: node.hxx:200
SwFootnoteIdxs & GetFootnoteIdxs()
Definition: doc.hxx:633
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:2380
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:136
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
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
virtual bool DeleteAndJoin(SwPaM &)=0
complete delete of a given PaM
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:719
const OUString & GetName() const
SdrObject * FindSdrObject()
Definition: frmfmt.hxx:140
constexpr TypedWhichId< SvxULSpaceItem > RES_UL_SPACE(92)
const SwFootnoteInfo & GetFootnoteInfo() const
Definition: doc.hxx:629
constexpr TypedWhichId< SvxAdjustItem > RES_PARATR_ADJUST(64)
constexpr TypedWhichId< SvxShadowItem > RES_SHADOW(107)
bool MakeCopy(SwDoc &, const SwPosition &, const SwSelBoxes &, bool bCpyName=false, const OUString &rStyleName="") const
Definition: tblrwcl.cxx:2060
void SetAllUniqueFlyNames()
Definition: doclay.cxx:1444
bool IsMoveProtect() const
constexpr TypedWhichId< SwFormatAnchor > RES_ANCHOR(104)
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1318
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:864
bool HasHints() const
Definition: ndtxt.hxx:228
static OUString lcl_GetUniqueFlyName(const SwDoc &rDoc, TranslateId pDefStrId, sal_uInt16 eType)
Definition: doclay.cxx:1327
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:1585
const SwFormatFlyCnt & GetFlyCnt() const
Definition: txatbase.hxx:226
SwFrame * GetNext()
Definition: frame.hxx:676
const SvxLRSpaceItem & GetLRSpace(bool=true) const
Definition: frmatr.hxx:74
Base class of the Writer document model elements.
Definition: node.hxx:81