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