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