LibreOffice Module sw (master) 1
atrflyin.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 <doc.hxx>
22#include <IDocumentUndoRedo.hxx>
24#include <pam.hxx>
25#include <flyfrm.hxx>
26#include <ndtxt.hxx>
27#include <frmfmt.hxx>
28#include <fmtflcnt.hxx>
29#include <txtflcnt.hxx>
30#include <fmtanchr.hxx>
31#include <txtfrm.hxx>
32#include <flyfrms.hxx>
33#include <objectformatter.hxx>
34#include <calbck.hxx>
35#include <dcontact.hxx>
36#include <textboxhelper.hxx>
37#include <osl/diagnose.h>
38
41 m_pTextAttr( nullptr ),
42 m_pFormat( pFrameFormat )
43{
44}
45
46bool SwFormatFlyCnt::operator==( const SfxPoolItem& rAttr ) const
47{
48 assert(SfxPoolItem::operator==(rAttr));
49 return( m_pTextAttr && static_cast<const SwFormatFlyCnt&>(rAttr).m_pTextAttr &&
50 m_pTextAttr->GetStart() == static_cast<const SwFormatFlyCnt&>(rAttr).m_pTextAttr->GetStart() &&
51 m_pFormat == static_cast<const SwFormatFlyCnt&>(rAttr).GetFrameFormat() );
52}
53
55{
56 return new SwFormatFlyCnt( m_pFormat );
57}
58
60{
61 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwFormatFlyCnt"));
62 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
63 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("text-attr"), "%p", m_pTextAttr);
64 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("format"), "%p", m_pFormat);
65
67
68 (void)xmlTextWriterEndElement(pWriter);
69}
70
71SwTextFlyCnt::SwTextFlyCnt( SwFormatFlyCnt& rAttr, sal_Int32 nStartPos )
72 : SwTextAttr( rAttr, nStartPos )
73{
74 rAttr.m_pTextAttr = this;
75 SetHasDummyChar(true);
76}
77
105{
107 assert(pFormat);
108 // The FlyFrameFormat must be copied - CopyLayoutFormat
109 // (DocumentLayoutManager.cxx) creates the FlyFrameFormat and copies the
110 // content.
111
112 // disable undo while copying attribute
113 ::sw::UndoGuard const undoGuard(rDoc.GetIDocumentUndoRedo());
114 SwFormatAnchor aAnchor( pFormat->GetAnchor() );
115 if ((RndStdIds::FLY_AT_PAGE != aAnchor.GetAnchorId()) &&
116 (&rDoc != pFormat->GetDoc())) // different documents?
117 {
118 // JP 03.06.96: ensure that the copied anchor points to valid content!
119 // setting it to the correct position is done later.
120 SwNodeIndex aIdx( rDoc.GetNodes().GetEndOfExtras(), +2 );
121 SwContentNode* pCNd = aIdx.GetNode().GetContentNode();
122 if( !pCNd )
123 pCNd = rDoc.GetNodes().GoNext( &aIdx );
124
125 SwPosition pos(aIdx.GetNode());
126 aAnchor.SetAnchor( &pos );
127 }
128
129 SwFrameFormat* pNew = rDoc.getIDocumentLayoutAccess().CopyLayoutFormat( *pFormat, aAnchor, false, false );
130 const_cast<SwFormatFlyCnt&>(GetFlyCnt()).SetFlyFormat( pNew );
131}
132
139{
140 // for Undo, the new anchor must be known already!
141
142 SwDoc& rDoc = const_cast<SwDoc&>(pNode->GetDoc());
143
145 SwFormatAnchor aAnchor( pFormat->GetAnchor() );
146 SwNode *const pOldNode(aAnchor.GetAnchorNode());
147
148 std::optional<SwPosition> oPos;
149 if (!pOldNode || !pOldNode->GetNodes().IsDocNodes() ||
150 pOldNode != static_cast<SwNode const *>(pNode))
151 {
152 oPos.emplace( *pNode, GetStart() );
153 }
154 else
155 {
156 oPos.emplace( *pOldNode, pOldNode->GetContentNode(), GetStart() );
157 }
158
159 aAnchor.SetType( RndStdIds::FLY_AS_CHAR ); // default!
160 aAnchor.SetAnchor( &*oPos );
161
162 // in case of anchor change, delete all FlyFrames
163 // JP 25.04.95: if the Frames can be moved within SplitNode, they don't
164 // need to be deleted
165 if( ( !pNode->GetpSwpHints() || !pNode->GetpSwpHints()->IsInSplitNode() )
166 && RES_DRAWFRMFMT != pFormat->Which() )
167 pFormat->DelFrames();
168
169 // copy into a different document?
170 if( &rDoc != pFormat->GetDoc() )
171 {
172 // disable undo while copying attribute
173 ::sw::UndoGuard const undoGuard(rDoc.GetIDocumentUndoRedo());
174 SwFrameFormat* pNew = rDoc.getIDocumentLayoutAccess().CopyLayoutFormat( *pFormat, aAnchor, false, false );
175
176 ::sw::UndoGuard const undoGuardFormat(
177 pFormat->GetDoc()->GetIDocumentUndoRedo());
178 pFormat->GetDoc()->getIDocumentLayoutAccess().DelLayoutFormat( pFormat );
179 const_cast<SwFormatFlyCnt&>(GetFlyCnt()).SetFlyFormat( pNew );
180 }
181 else if( pNode->GetpSwpHints() &&
182 pNode->GetpSwpHints()->IsInSplitNode() &&
183 RES_DRAWFRMFMT != pFormat->Which() )
184 {
185 pFormat->LockModify();
186 pFormat->SetFormatAttr( aAnchor ); // only set the anchor
187 // tdf#91228 must notify the anchor nodes despite LockModify
188 assert(pOldNode);
189 pOldNode->RemoveAnchoredFly(pFormat);
190 oPos->GetNode().AddAnchoredFly(pFormat);
191 pFormat->UnlockModify();
192 }
193 else
194 {
195 assert(!pFormat->IsModifyLocked()); // need to notify anchor node
196 if (RES_DRAWFRMFMT == pFormat->Which())
197 {
198 if (SdrObject const*const pObj = pFormat->FindSdrObject())
199 { // tdf#123259 disconnect with *old* anchor position
200 static_cast<SwDrawContact*>(::GetUserCall(pObj))->DisconnectFromLayout(false);
201 }
202 }
203 pFormat->SetFormatAttr( aAnchor ); // only set the anchor
204
205 // If the draw format has a TextBox, then set its anchor as well.
206 if (SwFrameFormat* pTextBox
208 {
209 SwFormatAnchor aTextBoxAnchor(pTextBox->GetAnchor());
210 aTextBoxAnchor.SetAnchor(aAnchor.GetContentAnchor());
211
212 // SwFlyAtContentFrame::SwClientNotify() assumes the anchor has a matching layout frame, which
213 // may not be the case when we're in the process of a node split, so block
214 // notifications.
215 bool bIsInSplitNode = pNode->GetpSwpHints() && pNode->GetpSwpHints()->IsInSplitNode();
216 if (bIsInSplitNode)
217 {
218 pTextBox->LockModify();
219 }
220 else
221 {
222 // Otherwise delete fly frames on anchor change.
223 pTextBox->DelFrames();
224 }
225
226 pTextBox->SetFormatAttr(aTextBoxAnchor);
227
228 if (bIsInSplitNode)
229 {
230 pOldNode->RemoveAnchoredFly(pTextBox);
231 oPos->GetNode().AddAnchoredFly(pTextBox);
232 pTextBox->UnlockModify();
233 }
234 else
235 {
236 pTextBox->MakeFrames();
237 }
238 }
239 }
240
241 // The node may have several SwTextFrames - for every SwTextFrame a
242 // SwFlyInContentFrame is created.
243}
244
245
251{
252 SwFrameFormat* pFrameFormat = GetFlyCnt().GetFrameFormat();
253 if( RES_DRAWFRMFMT == pFrameFormat->Which() )
254 {
255 OSL_ENSURE( false, "SwTextFlyCnt::GetFlyFrame_: DrawInCnt-under construction!" );
256 return nullptr;
257 }
258
259 SwIterator<SwFlyFrame,SwFormat> aIter( *GetFlyCnt().m_pFormat );
260 assert(pCurrFrame->IsTextFrame());
261 SwFrame* pFrame = aIter.First();
262 if ( pFrame )
263 {
264 SwTextFrame *pFirst = const_cast<SwTextFrame*>(static_cast<const SwTextFrame*>(pCurrFrame));
265 while ( pFirst->IsFollow() )
266 pFirst = pFirst->FindMaster();
267 do
268 {
269 SwTextFrame *pTmp = pFirst;
270 do
271 { if( static_cast<SwFlyFrame*>(pFrame)->GetAnchorFrame() == static_cast<SwFrame*>(pTmp) )
272 {
273 if ( pTmp != pCurrFrame )
274 {
275 pTmp->RemoveFly( static_cast<SwFlyFrame*>(pFrame) );
276 const_cast<SwTextFrame*>(static_cast<const SwTextFrame*>(pCurrFrame))->AppendFly( static_cast<SwFlyFrame*>(pFrame) );
277 }
278 return static_cast<SwFlyInContentFrame*>(pFrame);
279 }
280 pTmp = pTmp->GetFollow();
281 } while ( pTmp );
282
283 pFrame = aIter.Next();
284
285 } while( pFrame );
286 }
287
288 // We did not find a matching FlyFrame, so create a new one.
289 // AppendFly() triggers a reformat of pCurrentFrame. However, the
290 // recursion is blocked by the lock mechanism in SwTextFrame::Format().
291 SwFrame* pCurrentFrame = const_cast<SwFrame*>(pCurrFrame);
292 SwFlyInContentFrame *pFly = new SwFlyInContentFrame(static_cast<SwFlyFrameFormat*>(pFrameFormat), pCurrentFrame, pCurrentFrame);
293 pCurrentFrame->AppendFly(pFly);
294 pFly->RegistFlys();
295
296 // We must ensure that the content of the FlyInCnt is fully formatted
297 // right after construction.
298 // #i26945# - Use new object formatter to format Writer
299 // fly frame and its content.
300 SwObjectFormatter::FormatObj( *pFly, const_cast<SwFrame*>(pCurrFrame),
301 pCurrFrame->FindPageFrame() );
302
303 return pFly;
304}
305
306/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual SwFrameFormat * CopyLayoutFormat(const SwFrameFormat &rSrc, const SwFormatAnchor &rNewAnchor, bool bSetTextFlyAtt, bool bMakeFrames)=0
virtual void DelLayoutFormat(SwFrameFormat *pFormat)=0
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
const SwFrame * GetAnchorFrame() const
SwTextFrame * FindMaster() const
Definition: flowfrm.cxx:762
Definition: doc.hxx:197
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:158
SwNodes & GetNodes()
Definition: doc.hxx:422
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:419
ContactObject for connection of formats as representatives of draw objects in SwClient and the object...
Definition: dcontact.hxx:305
general base class for all free-flowing frames
Definition: flyfrm.hxx:79
Flys that are anchored as a character in the content.
Definition: flyfrms.hxx:210
FlyAnchors.
Definition: fmtanchr.hxx:37
void SetAnchor(const SwPosition *pPos)
Definition: atrfrm.cxx:1593
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:1614
Format of a fly content.
Definition: fmtflcnt.hxx:33
virtual SwFormatFlyCnt * Clone(SfxItemPool *pPool=nullptr) const override
Definition: atrflyin.cxx:54
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: atrflyin.cxx:59
SwTextFlyCnt * m_pTextAttr
Definition: fmtflcnt.hxx:35
SwFrameFormat * m_pFormat
My Fly/DrawFrame-format.
Definition: fmtflcnt.hxx:36
SwFormatFlyCnt(SwFrameFormat *pFrameFormat)
Definition: atrflyin.cxx:39
virtual bool operator==(const SfxPoolItem &) const override
"Pure virtual methods" of SfxPoolItem.
Definition: atrflyin.cxx:46
SwFrameFormat * GetFrameFormat() const
Definition: fmtflcnt.hxx:45
const SwDoc * GetDoc() const
The document is set in SwAttrPool now, therefore you always can access it.
Definition: format.hxx:139
sal_uInt16 Which() const
for Querying of Writer-functions.
Definition: format.hxx:82
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:88
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:447
Style of a layout element.
Definition: frmfmt.hxx:72
virtual void DelFrames()
Destroys all Frames in aDepend (Frames are identified via dynamic_cast).
Definition: atrfrm.cxx:2733
SdrObject * FindSdrObject()
Definition: frmfmt.hxx:153
Base class of the Writer layout elements.
Definition: frame.hxx:315
void RemoveFly(SwFlyFrame *pToRemove)
Definition: fly.cxx:2429
bool IsTextFrame() const
Definition: frame.hxx:1240
void AppendFly(SwFlyFrame *pNew)
Definition: fly.cxx:2411
SwPageFrame * FindPageFrame()
Definition: frame.hxx:686
TElementType * Next()
Definition: calbck.hxx:380
TElementType * First()
Definition: calbck.hxx:372
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNode & GetNode() const
Definition: ndindex.hxx:123
Base class of the Writer document model elements.
Definition: node.hxx:98
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:706
void RemoveAnchoredFly(SwFrameFormat *)
Definition: node.cxx:2171
SwDoc & GetDoc()
Definition: node.hxx:233
SwContentNode * GetContentNode()
Definition: node.hxx:666
SwNode & GetEndOfExtras() const
This is the last EndNode of a special section.
Definition: ndarr.hxx:163
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc....
Definition: nodes.cxx:2555
SwContentNode * GoNext(SwNodeIndex *) const
Definition: nodes.cxx:1299
static bool FormatObj(SwAnchoredObject &_rAnchoredObj, SwFrame *_pAnchorFrame=nullptr, const SwPageFrame *_pPageFrame=nullptr)
method to format a given floating screen object
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_Int32 GetStart() const
Definition: txatbase.hxx:88
void SetHasDummyChar(const bool bFlag)
Definition: txatbase.hxx:78
static SwFrameFormat * getOtherTextBoxFormat(const SwFrameFormat *pFormat, sal_uInt16 nType, const SdrObject *pObject=nullptr)
If we have an associated TextFrame, then return that.
void SetAnchor(const SwTextNode *pNode)
SetAnchor() is called by SwTextNode::InsertHint() and sets the anchor position in the SwFlyFrameForma...
Definition: atrflyin.cxx:138
void CopyFlyFormat(SwDoc &rDoc)
An overview of how a new SwTextFlyCnt is created: MakeTextAttr() is called e.g.
Definition: atrflyin.cxx:104
SwFlyInContentFrame * GetFlyFrame_(const SwFrame *pCurrFrame)
GetFlyFrame_() is called during text formatting by SwTextFormatter and searches for the SwFlyFrame fo...
Definition: atrflyin.cxx:250
SwTextFlyCnt(SwFormatFlyCnt &rAttr, sal_Int32 nStart)
Definition: atrflyin.cxx:71
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:168
SwTextFrame * GetFollow()
Definition: txtfrm.hxx:889
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
SwpHints * GetpSwpHints()
Definition: ndtxt.hxx:252
bool IsInSplitNode() const
Definition: ndhints.hxx:206
SwContact * GetUserCall(const SdrObject *pObj)
Returns the UserCall if applicable from the group object.
Definition: dcontact.cxx:172
struct _xmlTextWriter * xmlTextWriterPtr
constexpr TypedWhichId< SwDrawFrameFormat > RES_DRAWFRMFMT(165)
constexpr TypedWhichId< SwFormatFlyCnt > RES_TXTATR_FLYCNT(58)
Marks a position in the document model.
Definition: pam.hxx:38
size_t pos