LibreOffice Module sw (master) 1
flyincnt.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 <doc.hxx>
21#include <frmtool.hxx>
22#include <hints.hxx>
23#include <fmtornt.hxx>
24#include <rootfrm.hxx>
25#include <flyfrms.hxx>
26#include <dflyobj.hxx>
29#include <osl/diagnose.h>
30#include <o3tl/deleter.hxx>
31
33 SwFlyFrame( pFormat, pSib, pAnch )
34{
35 m_bInCnt = true;
36 SwTwips nRel = pFormat->GetVertOrient().GetPos();
37 // OD 2004-05-27 #i26791# - member <aRelPos> moved to <SwAnchoredObject>
38 Point aRelPos;
39 if( pAnch && pAnch->IsVertical() )
40 aRelPos.setX(-nRel);
41 else
42 aRelPos.setY(nRel);
43 SetCurrRelPos( aRelPos );
44}
45
47{
48 if ( !GetFormat()->GetDoc()->IsInDtor() && GetAnchorFrame() )
49 {
52 }
53
55}
56
58{
59}
60
61// #i28701#
62
64 const Point& rRelAttr,
65 const Point& rRelPos )
66{
67 // OD 2004-05-27 #i26791# - member <aRelPos> moved to <SwAnchoredObject>
68 OSL_ENSURE( rPoint != m_aRef || rRelAttr != GetCurrRelPos(), "SetRefPoint: no change" );
69 std::unique_ptr<SwFlyNotify, o3tl::default_delete<SwFlyNotify>> xNotify;
70 // No notify at a locked fly frame, if a fly frame is locked, there's
71 // already a SwFlyNotify object on the stack (MakeAll).
72 if( !IsLocked() )
73 xNotify.reset(new SwFlyNotify( this ));
74 m_aRef = rPoint;
75 SetCurrRelPos( rRelAttr );
76 SwRectFnSet aRectFnSet(GetAnchorFrame());
77
78 {
80 aRectFnSet.SetPos( aFrm, rPoint + rRelPos );
81 }
82
83 // #i68520#
85 if (xNotify)
86 {
89 m_bInvalid = true;
90 Calc(getRootFrame()->GetCurrShell()->GetOut());
91 xNotify.reset();
92 }
93}
94
96{
97 if (rHint.GetId() != SfxHintId::SwLegacyModify)
98 return;
99 auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
100 std::pair<std::unique_ptr<SwAttrSetChg>, std::unique_ptr<SwAttrSetChg>> aTweakedChgs;
101 std::pair<const SfxPoolItem*, const SfxPoolItem*> aSuperArgs(nullptr, nullptr);
102 switch(pLegacy->GetWhich())
103 {
104 case RES_ATTRSET_CHG:
105 {
106 auto pOldAttrSetChg = static_cast<const SwAttrSetChg*>(pLegacy->m_pOld);
107 auto pNewAttrSetChg = static_cast<const SwAttrSetChg*>(pLegacy->m_pNew);
108 if(pOldAttrSetChg
109 && pNewAttrSetChg
110 && ((SfxItemState::SET == pNewAttrSetChg->GetChgSet()->GetItemState(RES_SURROUND, false))
111 || (SfxItemState::SET == pNewAttrSetChg->GetChgSet()->GetItemState(RES_FRMMACRO, false))))
112 {
113 aTweakedChgs.second = std::make_unique<SwAttrSetChg>(*pOldAttrSetChg);
114 aTweakedChgs.second->ClearItem(RES_SURROUND);
115 aTweakedChgs.second->ClearItem(RES_FRMMACRO);
116 if(aTweakedChgs.second->Count())
117 {
118 aTweakedChgs.first = std::make_unique<SwAttrSetChg>(*pOldAttrSetChg);
119 aTweakedChgs.first->ClearItem(RES_SURROUND);
120 aTweakedChgs.first->ClearItem(RES_FRMMACRO);
121 aSuperArgs = std::pair<const SfxPoolItem*, const SfxPoolItem*>(aTweakedChgs.first.get(), aTweakedChgs.second.get());
122 }
123 } else if (pNewAttrSetChg && pNewAttrSetChg->GetChgSet()->Count())
124 aSuperArgs = std::pair<const SfxPoolItem*, const SfxPoolItem*>(pLegacy->m_pOld, pLegacy->m_pNew);
125 break;
126 }
127 case RES_SURROUND:
128 case RES_FRMMACRO:
129 break;
130 default:
131 aSuperArgs = std::pair<const SfxPoolItem*, const SfxPoolItem*>(pLegacy->m_pOld, pLegacy->m_pNew);
132 }
133 if(aSuperArgs.second)
134 {
135 SwFlyFrame::SwClientNotify(rMod, sw::LegacyModifyHint(aSuperArgs.first, aSuperArgs.second));
136 if(GetAnchorFrame())
138 }
139}
140
143{
144 if ( !getFrameArea().Height() )
145 {
146 Lock(); //don't format the anchor on the crook.
147 SwContentFrame *pContent = ContainsContent();
148 while ( pContent )
149 { pContent->Calc(pRenderContext);
150 pContent = pContent->GetNextContentFrame();
151 }
152 Unlock();
153 }
154 SwFlyFrame::Format( pRenderContext, pAttrs );
155}
156
163{
165 return;
166
168 SwFlyFrameFormat *pFormat = GetFormat();
169 const SwFormatVertOrient &rVert = pFormat->GetVertOrient();
170 //Update the current values in the format if needed, during this we of
171 //course must not send any Modify.
172 const bool bVert = GetAnchorFrame()->IsVertical();
173 SwTwips nOld = rVert.GetPos();
174 SwTwips nAct = bVert ? -GetCurrRelPos().X() : GetCurrRelPos().Y();
175 if( nAct != nOld )
176 {
177 SwFormatVertOrient aVert( rVert );
178 aVert.SetPos( nAct );
179 pFormat->LockModify();
180 pFormat->SetFormatAttr( aVert );
181 pFormat->UnlockModify();
182 }
183}
184
186{
187 if ( INVALID_POS == _nInvalid || INVALID_ALL == _nInvalid )
189}
190
192 PrepareHint eHint)
193{
196 else
197 AnchorFrame()->Prepare( eHint, static_cast<void const *>(&rRect) );
198}
199
201{
202 Calc(getRootFrame()->GetCurrShell()->GetOut());
203 return GetCurrRelPos();
204}
205
208{
209 SwPageFrame *pPage = FindPageFrame();
210 OSL_ENSURE( pPage, "Register Flys without pages?" );
211 ::RegistFlys( pPage, this );
212}
213
215{
216 // OD 2004-01-19 #110582#
217 if ( !GetFormat()->GetDoc()->getIDocumentDrawModelAccess().IsVisibleLayerId( GetVirtDrawObj()->GetLayer() ) )
218 {
219 return;
220 }
221
222 if ( !GetAnchorFrame() || IsLocked() || IsColLocked() || !FindPageFrame() )
223 return;
224
225 Lock(); // The curtain falls
226
227 //does the notification in the DTor
228 const SwFlyNotify aNotify( this );
229 SwBorderAttrAccess aAccess( SwFrame::GetCache(), this );
230 const SwBorderAttrs &rAttrs = *aAccess.Get();
231
232 if ( IsClipped() )
233 {
236 }
237
239 {
240 //Only stop, if the flag is set!!
241 if ( !isFrameAreaSizeValid() )
242 {
244 }
245
246 if ( !isFramePrintAreaValid() )
247 {
248 MakePrtArea( rAttrs );
249 m_bValidContentPos = false;
250 }
251
252 if ( !isFrameAreaSizeValid() )
253 {
254 Format( getRootFrame()->GetCurrShell()->GetOut(), &rAttrs );
255 }
256
258 {
259 MakeObjPos();
260 }
261
262 if ( !m_bValidContentPos )
263 MakeContentPos( rAttrs );
264
265 // re-activate clipping of as-character anchored Writer fly frames
266 // depending on compatibility option <ClipAsCharacterAnchoredWriterFlyFrames>
270 {
271 SwFrame* pFrame = AnchorFrame();
272 if ( getFrameArea().Left() == (pFrame->getFrameArea().Left()+pFrame->getFramePrintArea().Left()) &&
273 getFrameArea().Width() > pFrame->getFramePrintArea().Width() )
274 {
276 aFrm.Width( pFrame->getFramePrintArea().Width() );
278 m_bWidthClipped = true;
279 }
280 }
281 }
282 Unlock();
283}
284
285/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ CLIP_AS_CHARACTER_ANCHORED_WRITER_FLY_FRAME
constexpr tools::Long Y() const
void setX(tools::Long nX)
void setY(tools::Long nY)
constexpr tools::Long X() const
SfxHintId GetId() const
const SwFrame * GetAnchorFrame() const
SwFrame * AnchorFrame()
void SetCurrRelPos(Point _aRelPos)
const SwRect & GetObjRectWithSpaces() const
method to determine object area inclusive its spacing
void InvalidateObjRectWithSpaces() const
const Point & GetCurrRelPos() const
SwBorderAttrs * Get()
Definition: frmtool.cxx:2696
SwContentFrame is the layout for content nodes: a common base class for text (paragraph) and non-text...
Definition: cntfrm.hxx:59
SwContentFrame * GetNextContentFrame() const
Definition: cntfrm.hxx:120
general base class for all free-flowing frames
Definition: flyfrm.hxx:79
const SwVirtFlyDrawObj * GetVirtDrawObj() const
Definition: fly.cxx:3025
virtual void DestroyImpl() override
Definition: fly.cxx:327
void MakeContentPos(const SwBorderAttrs &rAttrs)
Definition: fly.cxx:1940
virtual const SwFlyFrameFormat * GetFormat() const override
Definition: fly.cxx:3119
virtual SwFrameFormat & GetFrameFormat() override
Definition: fly.cxx:3044
virtual void SwClientNotify(const SwModify &rMod, const SfxHint &rHint) override
Definition: fly.cxx:765
bool m_bWidthClipped
Definition: flyfrm.hxx:123
bool IsLocked() const
Definition: flyfrm.hxx:215
void Lock()
Definition: flyfrm.hxx:145
virtual void Format(vcl::RenderContext *pRenderContext, const SwBorderAttrs *pAttrs=nullptr) override
"Formats" the Frame; Frame and PrtArea.
Definition: fly.cxx:1358
void MakePrtArea(const SwBorderAttrs &rAttrs)
Definition: fly.cxx:1925
bool m_bInCnt
RndStdIds::FLY_AS_CHAR, anchored as character.
Definition: flyfrm.hxx:128
void Unlock()
Definition: flyfrm.hxx:146
virtual const IDocumentDrawModelAccess & getIDocumentDrawModelAccess() override
Definition: fly.cxx:374
virtual void Calc(vcl::RenderContext *pRenderContext) const override
Definition: fly.cxx:3156
bool m_bValidContentPos
Definition: flyfrm.hxx:139
bool m_bHeightClipped
Definition: flyfrm.hxx:122
bool IsClipped() const
Definition: flyfrm.hxx:230
bool m_bInvalid
Definition: flyfrm.hxx:115
virtual void NotifyBackground(SwPageFrame *pPage, const SwRect &rRect, PrepareHint eHint) override
method to trigger notification of 'background'
Definition: flyincnt.cxx:191
virtual ~SwFlyInContentFrame() override
Definition: flyincnt.cxx:57
SwFlyInContentFrame(SwFlyFrameFormat *, SwFrame *, SwFrame *pAnchor)
Definition: flyincnt.cxx:32
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: flyincnt.cxx:95
virtual void ActionOnInvalidation(const InvalidationType _nInvalid) override
method to perform additional actions on an invalidation
Definition: flyincnt.cxx:185
virtual void MakeObjPos() override
Calculate object position.
Definition: flyincnt.cxx:162
Point const & GetRelPos() const
Definition: flyincnt.cxx:200
virtual void MakeAll(vcl::RenderContext *pRenderContext) override
Definition: flyincnt.cxx:214
void SetRefPoint(const Point &rPoint, const Point &rRelAttr, const Point &rRelPos)
Definition: flyincnt.cxx:63
virtual void DestroyImpl() override
Definition: flyincnt.cxx:46
virtual void Format(vcl::RenderContext *pRenderContext, const SwBorderAttrs *pAttrs=nullptr) override
Here the content gets formatted initially.
Definition: flyincnt.cxx:142
Defines the vertical position of a fly frame.
Definition: fmtornt.hxx:37
SwTwips GetPos() const
Definition: fmtornt.hxx:62
void SetPos(SwTwips nNew)
Definition: fmtornt.hxx:63
const SwFormatVertOrient & GetVertOrient(bool=true) const
Definition: fmtornt.hxx:113
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:447
const SwRect & getFrameArea() const
Definition: frame.hxx:179
bool isFrameAreaPositionValid() const
Definition: frame.hxx:166
const SwRect & getFramePrintArea() const
Definition: frame.hxx:180
void setFramePrintAreaValid(bool bNew)
Definition: wsfrm.cxx:102
void setFrameAreaPositionValid(bool bNew)
Definition: wsfrm.cxx:86
bool isFramePrintAreaValid() const
Definition: frame.hxx:168
bool isFrameAreaSizeValid() const
Definition: frame.hxx:167
void setFrameAreaSizeValid(bool bNew)
Definition: wsfrm.cxx:94
Base class of the Writer layout elements.
Definition: frame.hxx:315
virtual bool Prepare(const PrepareHint ePrep=PrepareHint::Clear, const void *pVoid=nullptr, bool bNotify=true)
Definition: wsfrm.cxx:608
bool IsInDtor() const
Definition: frame.hxx:898
bool IsColLocked() const
Definition: frame.hxx:892
InvalidationType
enumeration for the different invalidations #i28701#
Definition: frame.hxx:491
@ INVALID_POS
Definition: frame.hxx:492
@ INVALID_ALL
Definition: frame.hxx:492
virtual void Calc(vcl::RenderContext *pRenderContext) const
Definition: trvlfrm.cxx:1799
static SwCache & GetCache()
Definition: frame.hxx:523
bool IsVertical() const
Definition: frame.hxx:979
void InvalidatePage(const SwPageFrame *pPage=nullptr) const
Invalidates the page in which the Frame is currently placed.
Definition: wsfrm.cxx:618
SwRootFrame * getRootFrame()
Definition: frame.hxx:685
SwPageFrame * FindPageFrame()
Definition: frame.hxx:686
const SwContentFrame * ContainsContent() const
Checks if the frame contains one or more ContentFrame's anywhere in his subsidiary structure; if so t...
Definition: findfrm.cxx:72
A page of the document layout.
Definition: pagefrm.hxx:60
void SetPos(SwRect &rRect, const Point &rNew) const
Definition: frame.hxx:1425
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void Left(const tools::Long nLeft)
Definition: swrect.hxx:197
void Width(tools::Long nNew)
Definition: swrect.hxx:189
constexpr TypedWhichId< SwAttrSetChg > RES_ATTRSET_CHG(169)
constexpr TypedWhichId< SvxMacroItem > RES_FRMMACRO(114)
constexpr TypedWhichId< SwFormatSurround > RES_SURROUND(107)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
tools::Long SwTwips
Definition: swtypes.hxx:51
PrepareHint
Definition: swtypes.hxx:206
@ FlyFrameAttributesChanged
Left