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