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 <txtfrm.hxx>
26 #include <flyfrms.hxx>
27 #include <dflyobj.hxx>
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 
63  const Point& rRelAttr,
64  const Point& rRelPos )
65 {
66  // OD 2004-05-27 #i26791# - member <aRelPos> moved to <SwAnchoredObject>
67  OSL_ENSURE( rPoint != aRef || rRelAttr != GetCurrRelPos(), "SetRefPoint: no change" );
68  std::unique_ptr<SwFlyNotify> pNotify;
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  pNotify.reset(new SwFlyNotify( this ));
73  aRef = rPoint;
74  SetCurrRelPos( rRelAttr );
75  SwRectFnSet aRectFnSet(GetAnchorFrame());
76 
77  {
79  aRectFnSet.SetPos( aFrm, rPoint + rRelPos );
80  }
81 
82  // #i68520#
84  if( pNotify )
85  {
88  m_bInvalid = true;
89  Calc(getRootFrame()->GetCurrShell()->GetOut());
90  pNotify.reset();
91  }
92 }
93 
94 void SwFlyInContentFrame::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
95 {
96  bool bCallPrepare = false;
97  const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
98  if (RES_ATTRSET_CHG == nWhich && pNew)
99  {
100  if(pOld &&
101  (SfxItemState::SET == static_cast<const SwAttrSetChg*>(pNew)->GetChgSet()->
102  GetItemState(RES_SURROUND, false) ||
103  SfxItemState::SET == static_cast<const SwAttrSetChg*>(pNew)->GetChgSet()->
104  GetItemState(RES_FRMMACRO, false)) )
105  {
106  SwAttrSetChg aOld( *static_cast<const SwAttrSetChg*>(pOld) );
107  SwAttrSetChg aNew( *static_cast<const SwAttrSetChg*>(pNew) );
108 
109  aOld.ClearItem( RES_SURROUND );
110  aNew.ClearItem( RES_SURROUND );
111  aOld.ClearItem( RES_FRMMACRO );
112  aNew.ClearItem( RES_FRMMACRO );
113  if( aNew.Count() )
114  {
115  SwFlyFrame::Modify( &aOld, &aNew );
116  bCallPrepare = true;
117  }
118  }
119  else if( static_cast<const SwAttrSetChg*>(pNew)->GetChgSet()->Count())
120  {
121  SwFlyFrame::Modify( pOld, pNew );
122  bCallPrepare = true;
123  }
124  }
125  else if( nWhich != RES_SURROUND && RES_FRMMACRO != nWhich )
126  {
127  SwFlyFrame::Modify( pOld, pNew );
128  bCallPrepare = true;
129  }
130 
131  if ( bCallPrepare && GetAnchorFrame() )
133 }
134 
136 void SwFlyInContentFrame::Format( vcl::RenderContext* pRenderContext, const SwBorderAttrs *pAttrs )
137 {
138  if ( !getFrameArea().Height() )
139  {
140  Lock(); //don't format the anchor on the crook.
141  SwContentFrame *pContent = ContainsContent();
142  while ( pContent )
143  { pContent->Calc(pRenderContext);
144  pContent = pContent->GetNextContentFrame();
145  }
146  Unlock();
147  }
148  SwFlyFrame::Format( pRenderContext, pAttrs );
149 }
150 
157 {
158  if ( !isFrameAreaPositionValid() )
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 }
178 
180 {
181  if ( INVALID_POS == _nInvalid || INVALID_ALL == _nInvalid )
183 }
184 
186  PrepareHint eHint)
187 {
188  if ( eHint == PREP_FLY_ATTR_CHG )
190  else
191  AnchorFrame()->Prepare( eHint, static_cast<void const *>(&rRect) );
192 }
193 
195 {
196  Calc(getRootFrame()->GetCurrShell()->GetOut());
197  return GetCurrRelPos();
198 }
199 
202 {
203  SwPageFrame *pPage = FindPageFrame();
204  OSL_ENSURE( pPage, "Register Flys without pages?" );
205  ::RegistFlys( pPage, this );
206 }
207 
209 {
210  // OD 2004-01-19 #110582#
211  if ( !GetFormat()->GetDoc()->getIDocumentDrawModelAccess().IsVisibleLayerId( GetVirtDrawObj()->GetLayer() ) )
212  {
213  return;
214  }
215 
216  if ( !GetAnchorFrame() || IsLocked() || IsColLocked() || !FindPageFrame() )
217  return;
218 
219  Lock(); // The curtain falls
220 
221  //does the notification in the DTor
222  const SwFlyNotify aNotify( this );
223  SwBorderAttrAccess aAccess( SwFrame::GetCache(), this );
224  const SwBorderAttrs &rAttrs = *aAccess.Get();
225 
226  if ( IsClipped() )
227  {
228  setFrameAreaSizeValid(false);
230  }
231 
233  {
234  //Only stop, if the flag is set!!
235  if ( !isFrameAreaSizeValid() )
236  {
237  setFramePrintAreaValid(false);
238  }
239 
240  if ( !isFramePrintAreaValid() )
241  {
242  MakePrtArea( rAttrs );
243  m_bValidContentPos = false;
244  }
245 
246  if ( !isFrameAreaSizeValid() )
247  {
248  Format( getRootFrame()->GetCurrShell()->GetOut(), &rAttrs );
249  }
250 
251  if ( !isFrameAreaPositionValid() )
252  {
253  MakeObjPos();
254  }
255 
256  if ( !m_bValidContentPos )
257  MakeContentPos( rAttrs );
258 
259  // re-activate clipping of as-character anchored Writer fly frames
260  // depending on compatibility option <ClipAsCharacterAnchoredWriterFlyFrames>
261  if ( isFrameAreaPositionValid() &&
263  GetFormat()->getIDocumentSettingAccess().get( DocumentSettingId::CLIP_AS_CHARACTER_ANCHORED_WRITER_FLY_FRAME ) )
264  {
265  SwFrame* pFrame = AnchorFrame();
266  if ( getFrameArea().Left() == (pFrame->getFrameArea().Left()+pFrame->getFramePrintArea().Left()) &&
267  getFrameArea().Width() > pFrame->getFramePrintArea().Width() )
268  {
270  aFrm.Width( pFrame->getFramePrintArea().Width() );
271  setFramePrintAreaValid(false);
272  m_bWidthClipped = true;
273  }
274  }
275  }
276  Unlock();
277 }
278 
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SwVirtFlyDrawObj * GetVirtDrawObj() const
Definition: fly.cxx:2725
Base class of the Writer layout elements.
Definition: frame.hxx:295
virtual const SwFlyFrameFormat * GetFormat() const override
Definition: fly.cxx:2814
SwContentFrame * GetNextContentFrame() const
Definition: cntfrm.hxx:97
#define RES_ATTRSET_CHG
Definition: hintids.hxx:285
SwFlyInContentFrame(SwFlyFrameFormat *, SwFrame *, SwFrame *pAnchor)
Definition: flyincnt.cxx:31
bool IsColLocked() const
Definition: frame.hxx:862
void MakeContentPos(const SwBorderAttrs &rAttrs)
Definition: fly.cxx:1719
const SwFormatVertOrient & GetVertOrient(bool=true) const
Definition: fmtornt.hxx:106
const SwRect & getFramePrintArea() const
Definition: frame.hxx:176
#define RES_SURROUND
Definition: hintids.hxx:206
static SwCache & GetCache()
Definition: frame.hxx:500
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:34
virtual void Format(vcl::RenderContext *pRenderContext, const SwBorderAttrs *pAttrs=nullptr) override
Here the content gets formatted initially.
Definition: flyincnt.cxx:136
bool m_bWidthClipped
Definition: flyfrm.hxx:104
virtual SwFrameFormat & GetFrameFormat() override
Definition: fly.cxx:2744
Point const & GetRelPos() const
Definition: flyincnt.cxx:194
void SetCurrRelPos(Point _aRelPos)
const SwRect & getFrameArea() const
Definition: frame.hxx:175
void setX(long nX)
void Lock()
Definition: flyfrm.hxx:123
void setFramePrintAreaValid(bool bNew)
Definition: wsfrm.cxx:96
void setY(long nY)
virtual void ActionOnInvalidation(const InvalidationType _nInvalid) override
method to perform additional actions on an invalidation
Definition: flyincnt.cxx:179
SwFrame * AnchorFrame()
bool m_bInCnt
RndStdIds::FLY_AS_CHAR, anchored as character.
Definition: flyfrm.hxx:109
bool IsInDtor() const
Definition: frame.hxx:868
virtual void Modify(const SfxPoolItem *, const SfxPoolItem *) override
Definition: flyincnt.cxx:94
PrepareHint
Definition: swtypes.hxx:204
void MakePrtArea(const SwBorderAttrs &rAttrs)
Definition: fly.cxx:1704
SwPageFrame * FindPageFrame()
Definition: frame.hxx:658
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:260
const SwRect & GetObjRectWithSpaces() const
method to determine object area inclusive its spacing
bool isFramePrintAreaValid() const
Definition: frame.hxx:164
void UnlockModify()
Definition: calbck.hxx:217
void LockModify()
Definition: calbck.hxx:216
bool m_bValidContentPos
Definition: flyfrm.hxx:117
virtual const IDocumentDrawModelAccess & getIDocumentDrawModelAccess() override
Definition: fly.cxx:305
bool isFrameAreaPositionValid() const
Definition: frame.hxx:162
bool isFrameAreaSizeValid() const
Definition: frame.hxx:163
A page of the document layout.
Definition: pagefrm.hxx:40
long X() const
bool m_bInvalid
Definition: flyfrm.hxx:96
SwBorderAttrs * Get()
Definition: frmtool.cxx:2377
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:460
bool m_bHeightClipped
Definition: flyfrm.hxx:103
void setFrameAreaPositionValid(bool bNew)
Definition: wsfrm.cxx:80
sal_uInt16 Count() const
Definition: hints.hxx:245
void Left(const long nLeft)
Definition: swrect.hxx:193
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:185
void Width(long nNew)
Definition: swrect.hxx:185
virtual void Modify(const SfxPoolItem *, const SfxPoolItem *) override
Definition: fly.cxx:636
SwTwips GetPos() const
Definition: fmtornt.hxx:59
bool IsClipped() const
Definition: flyfrm.hxx:202
void setFrameAreaSizeValid(bool bNew)
Definition: wsfrm.cxx:88
void InvalidateObjRectWithSpaces() const
void SetPos(SwRect &rRect, const Point &rNew) const
Definition: frame.hxx:1381
virtual void MakeAll(vcl::RenderContext *pRenderContext) override
Definition: flyincnt.cxx:208
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:1192
bool IsVertical() const
Definition: frame.hxx:949
virtual void Calc(vcl::RenderContext *pRenderContext) const override
Definition: fly.cxx:2824
void ClearItem(sal_uInt16 nWhichL)
Definition: hints.cxx:128
virtual void MakeObjPos() override
Calculate object position.
Definition: flyincnt.cxx:156
virtual ~SwFlyInContentFrame() override
Definition: flyincnt.cxx:56
virtual void DestroyImpl() override
Definition: flyincnt.cxx:45
Left
const SwFrame * GetAnchorFrame() const
#define RES_FRMMACRO
Definition: hintids.hxx:213
virtual bool Prepare(const PrepareHint ePrep=PREP_CLEAR, const void *pVoid=nullptr, bool bNotify=true)
Definition: wsfrm.cxx:587
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:467
sal_uInt16 Which() const
SwRootFrame * getRootFrame()
Definition: frame.hxx:657
long Y() const