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  {
50  SwRect aTmp( GetObjRectWithSpaces() );
52  }
53 
55 }
56 
58 {
59 }
60 
61 // #i28701#
62 
63 void SwFlyInContentFrame::SetRefPoint( const Point& rPoint,
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 
95 void SwFlyInContentFrame::SwClientNotify(const SwModify& rMod, const SfxHint& rHint)
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 
142 void SwFlyInContentFrame::Format( vcl::RenderContext* pRenderContext, const SwBorderAttrs *pAttrs )
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 {
164  if ( isFrameAreaPositionValid() )
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  {
234  setFrameAreaSizeValid(false);
236  }
237 
239  {
240  //Only stop, if the flag is set!!
241  if ( !isFrameAreaSizeValid() )
242  {
243  setFramePrintAreaValid(false);
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 
257  if ( !isFrameAreaPositionValid() )
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>
267  if ( isFrameAreaPositionValid() &&
269  GetFormat()->getIDocumentSettingAccess().get( DocumentSettingId::CLIP_AS_CHARACTER_ANCHORED_WRITER_FLY_FRAME ) )
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() );
277  setFramePrintAreaValid(false);
278  m_bWidthClipped = true;
279  }
280  }
281  }
282  Unlock();
283 }
284 
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SwVirtFlyDrawObj * GetVirtDrawObj() const
Definition: fly.cxx:2799
Base class of the Writer layout elements.
Definition: frame.hxx:314
constexpr TypedWhichId< SwFormatSurround > RES_SURROUND(101)
virtual void SwClientNotify(const SwModify &rMod, const SfxHint &rHint) override
Definition: fly.cxx:668
virtual const SwFlyFrameFormat * GetFormat() const override
Definition: fly.cxx:2893
SwContentFrame * GetNextContentFrame() const
Definition: cntfrm.hxx:115
SwFlyInContentFrame(SwFlyFrameFormat *, SwFrame *, SwFrame *pAnchor)
Definition: flyincnt.cxx:32
bool IsColLocked() const
Definition: frame.hxx:886
void MakeContentPos(const SwBorderAttrs &rAttrs)
Definition: fly.cxx:1777
const SwFormatVertOrient & GetVertOrient(bool=true) const
Definition: fmtornt.hxx:106
void Left(const tools::Long nLeft)
Definition: swrect.hxx:197
virtual bool Prepare(const PrepareHint ePrep=PrepareHint::Clear, const void *pVoid=nullptr, bool bNotify=true)
Definition: wsfrm.cxx:597
const SwRect & getFramePrintArea() const
Definition: frame.hxx:180
static SwCache & GetCache()
Definition: frame.hxx:521
void Unlock()
Definition: flyfrm.hxx:146
virtual void Calc(vcl::RenderContext *pRenderContext) const
Definition: trvlfrm.cxx:1788
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
virtual void Format(vcl::RenderContext *pRenderContext, const SwBorderAttrs *pAttrs=nullptr) override
Here the content gets formatted initially.
Definition: flyincnt.cxx:142
SfxHintId GetId() const
bool m_bWidthClipped
Definition: flyfrm.hxx:123
virtual SwFrameFormat & GetFrameFormat() override
Definition: fly.cxx:2818
Point const & GetRelPos() const
Definition: flyincnt.cxx:200
void SetCurrRelPos(Point _aRelPos)
const SwRect & getFrameArea() const
Definition: frame.hxx:179
void Width(tools::Long nNew)
Definition: swrect.hxx:189
void Lock()
Definition: flyfrm.hxx:145
void setFramePrintAreaValid(bool bNew)
Definition: wsfrm.cxx:100
virtual void ActionOnInvalidation(const InvalidationType _nInvalid) override
method to perform additional actions on an invalidation
Definition: flyincnt.cxx:185
SwFrame * AnchorFrame()
bool m_bInCnt
RndStdIds::FLY_AS_CHAR, anchored as character.
Definition: flyfrm.hxx:128
bool IsInDtor() const
Definition: frame.hxx:892
PrepareHint
Definition: swtypes.hxx:193
void MakePrtArea(const SwBorderAttrs &rAttrs)
Definition: fly.cxx:1762
constexpr TypedWhichId< SvxMacroItem > RES_FRMMACRO(108)
SwPageFrame * FindPageFrame()
Definition: frame.hxx:680
void SetPos(SwTwips nNew)
Definition: fmtornt.hxx:60
void InvalidatePage(const SwPageFrame *pPage=nullptr) const
Invalidates the page in which the Frame is currently placed.
Definition: wsfrm.cxx:607
virtual void DestroyImpl() override
Definition: fly.cxx:260
constexpr TypedWhichId< SwAttrSetChg > RES_ATTRSET_CHG(163)
const SwRect & GetObjRectWithSpaces() const
method to determine object area inclusive its spacing
bool isFramePrintAreaValid() const
Definition: frame.hxx:168
void UnlockModify()
Definition: calbck.hxx:209
void LockModify()
Definition: calbck.hxx:208
bool m_bValidContentPos
Definition: flyfrm.hxx:139
virtual const IDocumentDrawModelAccess & getIDocumentDrawModelAccess() override
Definition: fly.cxx:307
bool isFrameAreaPositionValid() const
Definition: frame.hxx:166
bool isFrameAreaSizeValid() const
Definition: frame.hxx:167
A page of the document layout.
Definition: pagefrm.hxx:57
tools::Long SwTwips
Definition: swtypes.hxx:51
bool m_bInvalid
Definition: flyfrm.hxx:115
SwBorderAttrs * Get()
Definition: frmtool.cxx:2681
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:448
bool m_bHeightClipped
Definition: flyfrm.hxx:122
void setFrameAreaPositionValid(bool bNew)
Definition: wsfrm.cxx:84
const Point & GetCurrRelPos() const
general base class for all free-flowing frames
Definition: flyfrm.hxx:78
bool IsLocked() const
Definition: flyfrm.hxx:213
virtual void NotifyBackground(SwPageFrame *pPage, const SwRect &rRect, PrepareHint eHint) override
method to trigger notification of 'background'
Definition: flyincnt.cxx:191
SwTwips GetPos() const
Definition: fmtornt.hxx:59
bool IsClipped() const
Definition: flyfrm.hxx:228
void setFrameAreaSizeValid(bool bNew)
Definition: wsfrm.cxx:92
void InvalidateObjRectWithSpaces() const
void SetPos(SwRect &rRect, const Point &rNew) const
Definition: frame.hxx:1419
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 Format(vcl::RenderContext *pRenderContext, const SwBorderAttrs *pAttrs=nullptr) override
"Formats" the Frame; Frame and PrtArea.
Definition: fly.cxx:1249
bool IsVertical() const
Definition: frame.hxx:973
virtual void Calc(vcl::RenderContext *pRenderContext) const override
Definition: fly.cxx:2903
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: flyincnt.cxx:95
void ClearItem(sal_uInt16 nWhichL)
Definition: hints.cxx:128
virtual void MakeObjPos() override
Calculate object position.
Definition: flyincnt.cxx:162
virtual ~SwFlyInContentFrame() override
Definition: flyincnt.cxx:57
virtual void DestroyImpl() override
Definition: flyincnt.cxx:46
Left
const SwFrame * GetAnchorFrame() const
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:70
InvalidationType
enumeration for the different invalidations #i28701#
Definition: frame.hxx:488
SwRootFrame * getRootFrame()
Definition: frame.hxx:679