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