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 
32  SwFlyFrame( pFormat, pSib, pAnch )
33 {
34  m_bInCnt = true;
35  SwTwips nRel = pFormat->GetVertOrient().GetPos();
36  // OD 2004-05-27 #i26791# - member <aRelPos> moved to <SwAnchoredObject>
37  Point aRelPos;
38  if( pAnch && pAnch->IsVertical() )
39  aRelPos.setX(-nRel);
40  else
41  aRelPos.setY(nRel);
42  SetCurrRelPos( aRelPos );
43 }
44 
46 {
47  if ( !GetFormat()->GetDoc()->IsInDtor() && GetAnchorFrame() )
48  {
49  SwRect aTmp( GetObjRectWithSpaces() );
51  }
52 
54 }
55 
57 {
58 }
59 
60 // #i28701#
61 
62 void SwFlyInContentFrame::SetRefPoint( const Point& rPoint,
63  const Point& rRelAttr,
64  const Point& rRelPos )
65 {
66  // OD 2004-05-27 #i26791# - member <aRelPos> moved to <SwAnchoredObject>
67  OSL_ENSURE( rPoint != m_aRef || rRelAttr != GetCurrRelPos(), "SetRefPoint: no change" );
68  std::unique_ptr<SwFlyNotify, o3tl::default_delete<SwFlyNotify>> xNotify;
69  // No notify at a locked fly frame, if a fly frame is locked, there's
70  // already a SwFlyNotify object on the stack (MakeAll).
71  if( !IsLocked() )
72  xNotify.reset(new SwFlyNotify( this ));
73  m_aRef = rPoint;
74  SetCurrRelPos( rRelAttr );
75  SwRectFnSet aRectFnSet(GetAnchorFrame());
76 
77  {
79  aRectFnSet.SetPos( aFrm, rPoint + rRelPos );
80  }
81 
82  // #i68520#
84  if (xNotify)
85  {
88  m_bInvalid = true;
89  Calc(getRootFrame()->GetCurrShell()->GetOut());
90  xNotify.reset();
91  }
92 }
93 
94 void SwFlyInContentFrame::SwClientNotify(const SwModify& rMod, const SfxHint& rHint)
95 {
96  if (rHint.GetId() != SfxHintId::SwLegacyModify)
97  return;
98  auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
99  std::pair<std::unique_ptr<SwAttrSetChg>, std::unique_ptr<SwAttrSetChg>> aTweakedChgs;
100  std::pair<const SfxPoolItem*, const SfxPoolItem*> aSuperArgs(nullptr, nullptr);
101  switch(pLegacy->GetWhich())
102  {
103  case RES_ATTRSET_CHG:
104  {
105  auto pOldAttrSetChg = static_cast<const SwAttrSetChg*>(pLegacy->m_pOld);
106  auto pNewAttrSetChg = static_cast<const SwAttrSetChg*>(pLegacy->m_pNew);
107  if(pOldAttrSetChg
108  && pNewAttrSetChg
109  && ((SfxItemState::SET == pNewAttrSetChg->GetChgSet()->GetItemState(RES_SURROUND, false))
110  || (SfxItemState::SET == pNewAttrSetChg->GetChgSet()->GetItemState(RES_FRMMACRO, false))))
111  {
112  aTweakedChgs.second = std::make_unique<SwAttrSetChg>(*pOldAttrSetChg);
113  aTweakedChgs.second->ClearItem(RES_SURROUND);
114  aTweakedChgs.second->ClearItem(RES_FRMMACRO);
115  if(aTweakedChgs.second->Count())
116  {
117  aTweakedChgs.first = std::make_unique<SwAttrSetChg>(*pOldAttrSetChg);
118  aTweakedChgs.first->ClearItem(RES_SURROUND);
119  aTweakedChgs.first->ClearItem(RES_FRMMACRO);
120  aSuperArgs = std::pair<const SfxPoolItem*, const SfxPoolItem*>(aTweakedChgs.first.get(), aTweakedChgs.second.get());
121  }
122  } else if (pNewAttrSetChg && pNewAttrSetChg->GetChgSet()->Count())
123  aSuperArgs = std::pair<const SfxPoolItem*, const SfxPoolItem*>(pLegacy->m_pOld, pLegacy->m_pNew);
124  break;
125  }
126  case RES_SURROUND:
127  case RES_FRMMACRO:
128  break;
129  default:
130  aSuperArgs = std::pair<const SfxPoolItem*, const SfxPoolItem*>(pLegacy->m_pOld, pLegacy->m_pNew);
131  }
132  if(aSuperArgs.second)
133  {
134  SwFlyFrame::SwClientNotify(rMod, sw::LegacyModifyHint(aSuperArgs.first, aSuperArgs.second));
135  if(GetAnchorFrame())
137  }
138 }
139 
141 void SwFlyInContentFrame::Format( vcl::RenderContext* pRenderContext, const SwBorderAttrs *pAttrs )
142 {
143  if ( !getFrameArea().Height() )
144  {
145  Lock(); //don't format the anchor on the crook.
147  while ( pContent )
148  { pContent->Calc(pRenderContext);
149  pContent = pContent->GetNextContentFrame();
150  }
151  Unlock();
152  }
153  SwFlyFrame::Format( pRenderContext, pAttrs );
154 }
155 
162 {
163  if ( isFrameAreaPositionValid() )
164  return;
165 
167  SwFlyFrameFormat *pFormat = GetFormat();
168  const SwFormatVertOrient &rVert = pFormat->GetVertOrient();
169  //Update the current values in the format if needed, during this we of
170  //course must not send any Modify.
171  const bool bVert = GetAnchorFrame()->IsVertical();
172  SwTwips nOld = rVert.GetPos();
173  SwTwips nAct = bVert ? -GetCurrRelPos().X() : GetCurrRelPos().Y();
174  if( nAct != nOld )
175  {
176  SwFormatVertOrient aVert( rVert );
177  aVert.SetPos( nAct );
178  pFormat->LockModify();
179  pFormat->SetFormatAttr( aVert );
180  pFormat->UnlockModify();
181  }
182 }
183 
185 {
186  if ( INVALID_POS == _nInvalid || INVALID_ALL == _nInvalid )
188 }
189 
191  PrepareHint eHint)
192 {
195  else
196  AnchorFrame()->Prepare( eHint, static_cast<void const *>(&rRect) );
197 }
198 
200 {
201  Calc(getRootFrame()->GetCurrShell()->GetOut());
202  return GetCurrRelPos();
203 }
204 
207 {
208  SwPageFrame *pPage = FindPageFrame();
209  OSL_ENSURE( pPage, "Register Flys without pages?" );
210  ::RegistFlys( pPage, this );
211 }
212 
214 {
215  // OD 2004-01-19 #110582#
216  if ( !GetFormat()->GetDoc()->getIDocumentDrawModelAccess().IsVisibleLayerId( GetVirtDrawObj()->GetLayer() ) )
217  {
218  return;
219  }
220 
221  if ( !GetAnchorFrame() || IsLocked() || IsColLocked() || !FindPageFrame() )
222  return;
223 
224  Lock(); // The curtain falls
225 
226  //does the notification in the DTor
227  const SwFlyNotify aNotify( this );
228  SwBorderAttrAccess aAccess( SwFrame::GetCache(), this );
229  const SwBorderAttrs &rAttrs = *aAccess.Get();
230 
231  if ( IsClipped() )
232  {
233  setFrameAreaSizeValid(false);
235  }
236 
238  {
239  //Only stop, if the flag is set!!
240  if ( !isFrameAreaSizeValid() )
241  {
242  setFramePrintAreaValid(false);
243  }
244 
245  if ( !isFramePrintAreaValid() )
246  {
247  MakePrtArea( rAttrs );
248  m_bValidContentPos = false;
249  }
250 
251  if ( !isFrameAreaSizeValid() )
252  {
253  Format( getRootFrame()->GetCurrShell()->GetOut(), &rAttrs );
254  }
255 
256  if ( !isFrameAreaPositionValid() )
257  {
258  MakeObjPos();
259  }
260 
261  if ( !m_bValidContentPos )
262  MakeContentPos( rAttrs );
263 
264  // re-activate clipping of as-character anchored Writer fly frames
265  // depending on compatibility option <ClipAsCharacterAnchoredWriterFlyFrames>
266  if ( isFrameAreaPositionValid() &&
268  GetFormat()->getIDocumentSettingAccess().get( DocumentSettingId::CLIP_AS_CHARACTER_ANCHORED_WRITER_FLY_FRAME ) )
269  {
270  SwFrame* pFrame = AnchorFrame();
271  if ( getFrameArea().Left() == (pFrame->getFrameArea().Left()+pFrame->getFramePrintArea().Left()) &&
272  getFrameArea().Width() > pFrame->getFramePrintArea().Width() )
273  {
275  aFrm.Width( pFrame->getFramePrintArea().Width() );
276  setFramePrintAreaValid(false);
277  m_bWidthClipped = true;
278  }
279  }
280  }
281  Unlock();
282 }
283 
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SwVirtFlyDrawObj * GetVirtDrawObj() const
Definition: fly.cxx:2783
Base class of the Writer layout elements.
Definition: frame.hxx:313
constexpr TypedWhichId< SwFormatSurround > RES_SURROUND(101)
virtual void SwClientNotify(const SwModify &rMod, const SfxHint &rHint) override
Definition: fly.cxx:661
virtual const SwFlyFrameFormat * GetFormat() const override
Definition: fly.cxx:2877
SwContentFrame * GetNextContentFrame() const
Definition: cntfrm.hxx:115
SwFlyInContentFrame(SwFlyFrameFormat *, SwFrame *, SwFrame *pAnchor)
Definition: flyincnt.cxx:31
bool IsColLocked() const
Definition: frame.hxx:883
void MakeContentPos(const SwBorderAttrs &rAttrs)
Definition: fly.cxx:1767
const SwFormatVertOrient & GetVertOrient(bool=true) const
Definition: fmtornt.hxx:106
void Left(const tools::Long nLeft)
Definition: swrect.hxx:194
virtual bool Prepare(const PrepareHint ePrep=PrepareHint::Clear, const void *pVoid=nullptr, bool bNotify=true)
Definition: wsfrm.cxx:600
const SwRect & getFramePrintArea() const
Definition: frame.hxx:179
static SwCache & GetCache()
Definition: frame.hxx:520
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:141
SfxHintId GetId() const
bool m_bWidthClipped
Definition: flyfrm.hxx:123
virtual SwFrameFormat & GetFrameFormat() override
Definition: fly.cxx:2802
Point const & GetRelPos() const
Definition: flyincnt.cxx:199
void SetCurrRelPos(Point _aRelPos)
const SwRect & getFrameArea() const
Definition: frame.hxx:178
void Width(tools::Long nNew)
Definition: swrect.hxx:186
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:184
SwFrame * AnchorFrame()
bool m_bInCnt
RndStdIds::FLY_AS_CHAR, anchored as character.
Definition: flyfrm.hxx:128
bool IsInDtor() const
Definition: frame.hxx:889
PrepareHint
Definition: swtypes.hxx:193
void MakePrtArea(const SwBorderAttrs &rAttrs)
Definition: fly.cxx:1752
constexpr TypedWhichId< SvxMacroItem > RES_FRMMACRO(108)
SwPageFrame * FindPageFrame()
Definition: frame.hxx:679
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:610
virtual void DestroyImpl() override
Definition: fly.cxx:259
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:167
::rtl::Reference< Content > pContent
void UnlockModify()
Definition: calbck.hxx:204
void LockModify()
Definition: calbck.hxx:203
bool m_bValidContentPos
Definition: flyfrm.hxx:139
virtual const IDocumentDrawModelAccess & getIDocumentDrawModelAccess() override
Definition: fly.cxx:304
bool isFrameAreaPositionValid() const
Definition: frame.hxx:165
bool isFrameAreaSizeValid() const
Definition: frame.hxx:166
A page of the document layout.
Definition: pagefrm.hxx:57
tools::Long SwTwips
Definition: swtypes.hxx:50
bool m_bInvalid
Definition: flyfrm.hxx:115
SwBorderAttrs * Get()
Definition: frmtool.cxx:2630
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:450
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:190
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:1417
virtual void MakeAll(vcl::RenderContext *pRenderContext) override
Definition: flyincnt.cxx:213
void SetRefPoint(const Point &rPoint, const Point &rRelAttr, const Point &rRelPos)
Definition: flyincnt.cxx:62
virtual void Format(vcl::RenderContext *pRenderContext, const SwBorderAttrs *pAttrs=nullptr) override
"Formats" the Frame; Frame and PrtArea.
Definition: fly.cxx:1239
bool IsVertical() const
Definition: frame.hxx:970
virtual void Calc(vcl::RenderContext *pRenderContext) const override
Definition: fly.cxx:2887
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: flyincnt.cxx:94
void ClearItem(sal_uInt16 nWhichL)
Definition: hints.cxx:128
virtual void MakeObjPos() override
Calculate object position.
Definition: flyincnt.cxx:161
virtual ~SwFlyInContentFrame() override
Definition: flyincnt.cxx:56
virtual void DestroyImpl() override
Definition: flyincnt.cxx:45
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:67
InvalidationType
enumeration for the different invalidations #i28701#
Definition: frame.hxx:487
SwRootFrame * getRootFrame()
Definition: frame.hxx:678