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