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::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
94 {
95  bool bCallPrepare = false;
96  const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
97  if (RES_ATTRSET_CHG == nWhich && pNew)
98  {
99  if(pOld &&
100  (SfxItemState::SET == static_cast<const SwAttrSetChg*>(pNew)->GetChgSet()->
101  GetItemState(RES_SURROUND, false) ||
102  SfxItemState::SET == static_cast<const SwAttrSetChg*>(pNew)->GetChgSet()->
103  GetItemState(RES_FRMMACRO, false)) )
104  {
105  SwAttrSetChg aOld( *static_cast<const SwAttrSetChg*>(pOld) );
106  SwAttrSetChg aNew( *static_cast<const SwAttrSetChg*>(pNew) );
107 
108  aOld.ClearItem( RES_SURROUND );
109  aNew.ClearItem( RES_SURROUND );
110  aOld.ClearItem( RES_FRMMACRO );
111  aNew.ClearItem( RES_FRMMACRO );
112  if( aNew.Count() )
113  {
114  SwFlyFrame::Modify( &aOld, &aNew );
115  bCallPrepare = true;
116  }
117  }
118  else if( static_cast<const SwAttrSetChg*>(pNew)->GetChgSet()->Count())
119  {
120  SwFlyFrame::Modify( pOld, pNew );
121  bCallPrepare = true;
122  }
123  }
124  else if( nWhich != RES_SURROUND && RES_FRMMACRO != nWhich )
125  {
126  SwFlyFrame::Modify( pOld, pNew );
127  bCallPrepare = true;
128  }
129 
130  if ( bCallPrepare && GetAnchorFrame() )
132 }
133 
135 void SwFlyInContentFrame::Format( vcl::RenderContext* pRenderContext, const SwBorderAttrs *pAttrs )
136 {
137  if ( !getFrameArea().Height() )
138  {
139  Lock(); //don't format the anchor on the crook.
141  while ( pContent )
142  { pContent->Calc(pRenderContext);
143  pContent = pContent->GetNextContentFrame();
144  }
145  Unlock();
146  }
147  SwFlyFrame::Format( pRenderContext, pAttrs );
148 }
149 
156 {
157  if ( isFrameAreaPositionValid() )
158  return;
159 
161  SwFlyFrameFormat *pFormat = GetFormat();
162  const SwFormatVertOrient &rVert = pFormat->GetVertOrient();
163  //Update the current values in the format if needed, during this we of
164  //course must not send any Modify.
165  const bool bVert = GetAnchorFrame()->IsVertical();
166  SwTwips nOld = rVert.GetPos();
167  SwTwips nAct = bVert ? -GetCurrRelPos().X() : GetCurrRelPos().Y();
168  if( nAct != nOld )
169  {
170  SwFormatVertOrient aVert( rVert );
171  aVert.SetPos( nAct );
172  pFormat->LockModify();
173  pFormat->SetFormatAttr( aVert );
174  pFormat->UnlockModify();
175  }
176 }
177 
179 {
180  if ( INVALID_POS == _nInvalid || INVALID_ALL == _nInvalid )
182 }
183 
185  PrepareHint eHint)
186 {
189  else
190  AnchorFrame()->Prepare( eHint, static_cast<void const *>(&rRect) );
191 }
192 
194 {
195  Calc(getRootFrame()->GetCurrShell()->GetOut());
196  return GetCurrRelPos();
197 }
198 
201 {
202  SwPageFrame *pPage = FindPageFrame();
203  OSL_ENSURE( pPage, "Register Flys without pages?" );
204  ::RegistFlys( pPage, this );
205 }
206 
208 {
209  // OD 2004-01-19 #110582#
210  if ( !GetFormat()->GetDoc()->getIDocumentDrawModelAccess().IsVisibleLayerId( GetVirtDrawObj()->GetLayer() ) )
211  {
212  return;
213  }
214 
215  if ( !GetAnchorFrame() || IsLocked() || IsColLocked() || !FindPageFrame() )
216  return;
217 
218  Lock(); // The curtain falls
219 
220  //does the notification in the DTor
221  const SwFlyNotify aNotify( this );
222  SwBorderAttrAccess aAccess( SwFrame::GetCache(), this );
223  const SwBorderAttrs &rAttrs = *aAccess.Get();
224 
225  if ( IsClipped() )
226  {
227  setFrameAreaSizeValid(false);
229  }
230 
232  {
233  //Only stop, if the flag is set!!
234  if ( !isFrameAreaSizeValid() )
235  {
236  setFramePrintAreaValid(false);
237  }
238 
239  if ( !isFramePrintAreaValid() )
240  {
241  MakePrtArea( rAttrs );
242  m_bValidContentPos = false;
243  }
244 
245  if ( !isFrameAreaSizeValid() )
246  {
247  Format( getRootFrame()->GetCurrShell()->GetOut(), &rAttrs );
248  }
249 
250  if ( !isFrameAreaPositionValid() )
251  {
252  MakeObjPos();
253  }
254 
255  if ( !m_bValidContentPos )
256  MakeContentPos( rAttrs );
257 
258  // re-activate clipping of as-character anchored Writer fly frames
259  // depending on compatibility option <ClipAsCharacterAnchoredWriterFlyFrames>
260  if ( isFrameAreaPositionValid() &&
262  GetFormat()->getIDocumentSettingAccess().get( DocumentSettingId::CLIP_AS_CHARACTER_ANCHORED_WRITER_FLY_FRAME ) )
263  {
264  SwFrame* pFrame = AnchorFrame();
265  if ( getFrameArea().Left() == (pFrame->getFrameArea().Left()+pFrame->getFramePrintArea().Left()) &&
266  getFrameArea().Width() > pFrame->getFramePrintArea().Width() )
267  {
269  aFrm.Width( pFrame->getFramePrintArea().Width() );
270  setFramePrintAreaValid(false);
271  m_bWidthClipped = true;
272  }
273  }
274  }
275  Unlock();
276 }
277 
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SwVirtFlyDrawObj * GetVirtDrawObj() const
Definition: fly.cxx:2722
Base class of the Writer layout elements.
Definition: frame.hxx:297
constexpr TypedWhichId< SwFormatSurround > RES_SURROUND(101)
virtual const SwFlyFrameFormat * GetFormat() const override
Definition: fly.cxx:2811
SwContentFrame * GetNextContentFrame() const
Definition: cntfrm.hxx:98
SwFlyInContentFrame(SwFlyFrameFormat *, SwFrame *, SwFrame *pAnchor)
Definition: flyincnt.cxx:30
bool IsColLocked() const
Definition: frame.hxx:864
void MakeContentPos(const SwBorderAttrs &rAttrs)
Definition: fly.cxx:1705
const SwFormatVertOrient & GetVertOrient(bool=true) const
Definition: fmtornt.hxx:106
virtual bool Prepare(const PrepareHint ePrep=PrepareHint::Clear, const void *pVoid=nullptr, bool bNotify=true)
Definition: wsfrm.cxx:587
const SwRect & getFramePrintArea() const
Definition: frame.hxx:178
static SwCache & GetCache()
Definition: frame.hxx:502
void Unlock()
Definition: flyfrm.hxx:124
long SwTwips
Definition: swtypes.hxx:49
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:135
bool m_bWidthClipped
Definition: flyfrm.hxx:104
virtual SwFrameFormat & GetFrameFormat() override
Definition: fly.cxx:2741
Point const & GetRelPos() const
Definition: flyincnt.cxx:193
void SetCurrRelPos(Point _aRelPos)
const SwRect & getFrameArea() const
Definition: frame.hxx:177
constexpr TypedWhichId< SwAttrSetChg > RES_ATTRSET_CHG(161)
void Lock()
Definition: flyfrm.hxx:123
void setFramePrintAreaValid(bool bNew)
Definition: wsfrm.cxx:97
virtual void ActionOnInvalidation(const InvalidationType _nInvalid) override
method to perform additional actions on an invalidation
Definition: flyincnt.cxx:178
SwFrame * AnchorFrame()
bool m_bInCnt
RndStdIds::FLY_AS_CHAR, anchored as character.
Definition: flyfrm.hxx:109
bool IsInDtor() const
Definition: frame.hxx:870
virtual void Modify(const SfxPoolItem *, const SfxPoolItem *) override
Definition: flyincnt.cxx:93
PrepareHint
Definition: swtypes.hxx:196
void MakePrtArea(const SwBorderAttrs &rAttrs)
Definition: fly.cxx:1690
constexpr TypedWhichId< SvxMacroItem > RES_FRMMACRO(108)
SwPageFrame * FindPageFrame()
Definition: frame.hxx:660
Count
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:597
virtual void DestroyImpl() override
Definition: fly.cxx:257
const SwRect & GetObjRectWithSpaces() const
method to determine object area inclusive its spacing
bool isFramePrintAreaValid() const
Definition: frame.hxx:166
::rtl::Reference< Content > pContent
void UnlockModify()
Definition: calbck.hxx:216
void LockModify()
Definition: calbck.hxx:215
bool m_bValidContentPos
Definition: flyfrm.hxx:117
virtual const IDocumentDrawModelAccess & getIDocumentDrawModelAccess() override
Definition: fly.cxx:302
bool isFrameAreaPositionValid() const
Definition: frame.hxx:164
bool isFrameAreaSizeValid() const
Definition: frame.hxx:165
A page of the document layout.
Definition: pagefrm.hxx:41
bool m_bInvalid
Definition: flyfrm.hxx:96
SwBorderAttrs * Get()
Definition: frmtool.cxx:2560
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:460
bool m_bHeightClipped
Definition: flyfrm.hxx:103
void setFrameAreaPositionValid(bool bNew)
Definition: wsfrm.cxx:81
sal_uInt16 Count() const
Definition: hints.hxx:245
void Left(const long nLeft)
Definition: swrect.hxx:195
const Point & GetCurrRelPos() const
general base class for all free-flowing frames
Definition: flyfrm.hxx:60
bool IsLocked() const
Definition: flyfrm.hxx:191
virtual void NotifyBackground(SwPageFrame *pPage, const SwRect &rRect, PrepareHint eHint) override
method to trigger notification of 'background'
Definition: flyincnt.cxx:184
void Width(long nNew)
Definition: swrect.hxx:187
virtual void Modify(const SfxPoolItem *, const SfxPoolItem *) override
Definition: fly.cxx:627
SwTwips GetPos() const
Definition: fmtornt.hxx:59
bool IsClipped() const
Definition: flyfrm.hxx:202
void setFrameAreaSizeValid(bool bNew)
Definition: wsfrm.cxx:89
void InvalidateObjRectWithSpaces() const
void SetPos(SwRect &rRect, const Point &rNew) const
Definition: frame.hxx:1398
virtual void MakeAll(vcl::RenderContext *pRenderContext) override
Definition: flyincnt.cxx:207
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:1181
bool IsVertical() const
Definition: frame.hxx:951
virtual void Calc(vcl::RenderContext *pRenderContext) const override
Definition: fly.cxx:2821
void ClearItem(sal_uInt16 nWhichL)
Definition: hints.cxx:128
virtual void MakeObjPos() override
Calculate object position.
Definition: flyincnt.cxx:155
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:66
InvalidationType
enumeration for the different invalidations #i28701#
Definition: frame.hxx:469
sal_uInt16 Which() const
SwRootFrame * getRootFrame()
Definition: frame.hxx:659