1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SW_SOURCE_CORE_INC_FLYFRM_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_FLYFRM_HXX
26 #include <anchoredobject.hxx>
31 class SwFormatFrameSize
;
32 struct SwCursorMoveState
;
34 class SwVirtFlyDrawObj
;
36 namespace tools
{ class PolyPolygon
; }
41 class SwFlyAtContentFrame
;
44 /** search an anchor for paragraph bound frames starting from pOldAnch
46 needed for dragging of objects bound to a paragraph for showing an anchor
47 indicator as well as for changing the anchor.
49 implemented in layout/flycnt.cxx
51 const SwContentFrame
*FindAnchor( const SwFrame
*pOldAnch
, const Point
&rNew
,
52 const bool bBody
= false );
54 /** calculate rectangle in that the object can be moved or rather be resized */
55 bool CalcClipRect( const SdrObject
*pSdrObj
, SwRect
&rRect
, bool bMove
= true );
57 enum class SwFlyFrameInvFlags
: sal_uInt8
61 InvalidateSize
= 0x02,
64 SetCompletePaint
= 0x10,
65 InvalidateBrowseWidth
= 0x20,
66 ClearContourCache
= 0x40,
67 UpdateObjInSortedList
= 0x80,
71 template<> struct typed_flags
<SwFlyFrameInvFlags
> : is_typed_flags
<SwFlyFrameInvFlags
, 0x00ff> {};
75 /** general base class for all free-flowing frames
77 #i26791# - inherit also from <SwAnchoredFlyFrame>
79 class SW_DLLPUBLIC SwFlyFrame
: public SwLayoutFrame
, public SwAnchoredObject
81 // is allowed to lock, implemented in frmtool.cxx
82 friend void AppendObj(SwFrame
*const pFrame
, SwPageFrame
*const pPage
, SwFrameFormat
*const pFormat
, const SwFormatAnchor
& rAnch
);
83 friend void Notify( SwFlyFrame
*, SwPageFrame
*pOld
, const SwRect
&rOld
,
84 const SwRect
* pOldPrt
);
86 void InitDrawObj(SwFrame
const&); // these to methods are called in the
87 void FinitDrawObj(); // constructors
89 void UpdateAttr_( const SfxPoolItem
*, const SfxPoolItem
*, SwFlyFrameInvFlags
&,
90 SwAttrSetChg
*pa
= nullptr, SwAttrSetChg
*pb
= nullptr );
92 using SwLayoutFrame::CalcRel
;
95 // Predecessor/Successor for chaining with text flow
96 SwFlyFrame
*m_pPrevLink
, *m_pNextLink
;
97 static const SwFormatAnchor
* GetAnchorFromPoolItem(const SfxPoolItem
& rItem
);
100 // It must be possible to block Content-bound flys so that they will be not
101 // formatted; in this case MakeAll() returns immediately. This is necessary
102 // for page changes during formatting. In addition, it is needed during
103 // the constructor call of the root object since otherwise the anchor will
104 // be formatted before the root is anchored correctly to a shell and
105 // because too much would be formatted as a result.
107 // true if the background of NotifyDTor needs to be notified at the end
108 // of a MakeAll() call.
109 bool m_bNotifyBack
:1;
112 // Pos, PrtArea or SSize have been invalidated - they will be evaluated
113 // again immediately because they have to be valid _at all time_.
114 // The invalidation is tracked here so that LayAction knows about it and
115 // can handle it properly. Exceptions prove the rule.
118 // true if the proposed height of an attribute is a minimal height
119 // (this means that the frame can grow higher if needed)
120 bool m_bMinHeight
:1;
121 // true if the fly frame could not format position/size based on its
122 // attributes, e.g. because there was not enough space.
123 bool m_bHeightClipped
:1;
124 bool m_bWidthClipped
:1;
125 // If true then call only the format after adjusting the width (CheckClip);
126 // but the width will not be re-evaluated based on the attributes.
127 bool m_bFormatHeightOnly
:1;
129 bool m_bInCnt
:1; ///< RndStdIds::FLY_AS_CHAR, anchored as character
130 bool m_bAtCnt
:1; ///< RndStdIds::FLY_AT_PARA, anchored at paragraph
131 ///< or RndStdIds::FLY_AT_CHAR
132 bool m_bLayout
:1; ///< RndStdIds::FLY_AT_PAGE, RndStdIds::FLY_AT_FLY, at page or at frame
133 bool m_bAutoPosition
:1; ///< RndStdIds::FLY_AT_CHAR, anchored at character
134 bool m_bDeleted
:1; ///< Anchored to a tracked deletion
135 size_t m_nAuthor
; ///< Redline author index for colored crossing out
137 friend class SwNoTextFrame
; // is allowed to call NotifyBackground
139 Point m_aContentPos
; // content area's position relatively to Frame
140 bool m_bValidContentPos
;
142 virtual void Format( vcl::RenderContext
* pRenderContext
, const SwBorderAttrs
*pAttrs
= nullptr ) override
;
143 void MakePrtArea( const SwBorderAttrs
&rAttrs
);
144 void MakeContentPos( const SwBorderAttrs
&rAttrs
);
146 void Lock() { m_bLocked
= true; }
147 void Unlock() { m_bLocked
= false; }
149 Size
CalcRel( const SwFormatFrameSize
&rSz
) const;
151 SwFlyFrame( SwFlyFrameFormat
*, SwFrame
*, SwFrame
*pAnchor
, bool bFollow
= false );
153 virtual void DestroyImpl() override
;
154 virtual ~SwFlyFrame() override
;
156 /** method to assure that anchored object is registered at the correct
159 virtual void RegisterAtCorrectPage() override
;
160 virtual void RegisterAtPage(SwPageFrame
&) override
;
162 virtual bool SetObjTop_( const SwTwips _nTop
) override
;
163 virtual bool SetObjLeft_( const SwTwips _nLeft
) override
;
165 virtual SwRect
GetObjBoundRect() const override
;
166 virtual void SwClientNotify(const SwModify
& rMod
, const SfxHint
& rHint
) override
;
168 virtual const IDocumentDrawModelAccess
& getIDocumentDrawModelAccess( ) override
;
170 SwTwips
CalcContentHeight(const SwBorderAttrs
*pAttrs
, const SwTwips nMinHeight
, const SwTwips nUL
);
175 // get client information
176 virtual bool GetInfo( SfxPoolItem
& ) const override
;
177 virtual void PaintSwFrame( vcl::RenderContext
& rRenderContext
, SwRect
const&,
178 SwPrintData
const*const pPrintData
= nullptr ) const override
;
179 virtual Size
ChgSize( const Size
& aNewSize
) override
;
180 virtual bool GetModelPositionForViewPoint( SwPosition
*, Point
&,
181 SwCursorMoveState
* = nullptr, bool bTestBackground
= false ) const override
;
183 virtual void CheckDirection( bool bVert
) override
;
184 virtual void Cut() override
;
186 virtual void Paste( SwFrame
* pParent
, SwFrame
* pSibling
= nullptr ) override
;
189 SwTwips
Shrink_( SwTwips
, bool bTst
);
190 SwTwips
Grow_ ( SwTwips
, bool bTst
);
191 void Invalidate_( SwPageFrame
const *pPage
= nullptr );
193 bool FrameSizeChg( const SwFormatFrameSize
& );
195 SwFlyFrame
*GetPrevLink() const { return m_pPrevLink
; }
196 SwFlyFrame
*GetNextLink() const { return m_pNextLink
; }
198 static void ChainFrames( SwFlyFrame
*pMaster
, SwFlyFrame
*pFollow
);
199 static void UnchainFrames( SwFlyFrame
*pMaster
, SwFlyFrame
*pFollow
);
201 SwFlyFrame
*FindChainNeighbour( SwFrameFormat
const &rFormat
, SwFrame
*pAnch
= nullptr );
203 /// Is this fly allowed to split across pages? (Disabled by default.)
204 bool IsFlySplitAllowed() const;
207 const SwVirtFlyDrawObj
* GetVirtDrawObj() const;
208 SwVirtFlyDrawObj
*GetVirtDrawObj();
209 void NotifyDrawObj();
211 void ChgRelPos( const Point
&rAbsPos
);
212 bool IsInvalid() const { return m_bInvalid
; }
213 void Invalidate() const { const_cast<SwFlyFrame
*>(this)->m_bInvalid
= true; }
214 void Validate() const { const_cast<SwFlyFrame
*>(this)->m_bInvalid
= false; }
216 bool IsMinHeight() const { return m_bMinHeight
; }
217 bool IsLocked() const { return m_bLocked
; }
218 bool IsAutoPos() const { return m_bAutoPosition
; }
219 bool IsFlyInContentFrame() const { return m_bInCnt
; }
220 bool IsFlyFreeFrame() const { return m_bAtCnt
|| m_bLayout
; }
221 bool IsFlyLayFrame() const { return m_bLayout
; }
222 bool IsFlyAtContentFrame() const { return m_bAtCnt
; }
223 bool IsDeleted() const { return m_bDeleted
; }
224 void SetDeleted(bool bDeleted
) { m_bDeleted
= bDeleted
; }
225 void SetAuthor( size_t nAuthor
) { m_nAuthor
= nAuthor
; }
226 size_t GetAuthor() const { return m_nAuthor
; }
228 bool IsNotifyBack() const { return m_bNotifyBack
; }
229 void SetNotifyBack() { m_bNotifyBack
= true; }
230 void ResetNotifyBack() { m_bNotifyBack
= false; }
232 bool IsClipped() const { return m_bHeightClipped
|| m_bWidthClipped
; }
233 bool IsHeightClipped() const { return m_bHeightClipped
; }
235 bool IsLowerOf( const SwLayoutFrame
* pUpper
) const;
236 bool IsUpperOf( const SwFlyFrame
& _rLower
) const
238 return _rLower
.IsLowerOf( this );
241 SwFrame
*FindLastLower();
243 // #i13147# - add parameter <_bForPaint> to avoid load of
244 // the graphic during paint. Default value: false
245 bool GetContour( tools::PolyPolygon
& rContour
,
246 const bool _bForPaint
= false ) const;
248 // Paint on this shell (consider Preview, print flag, etc. recursively)?
249 static bool IsPaint( SdrObject
*pObj
, const SwViewShell
*pSh
);
251 /** SwFlyFrame::IsBackgroundTransparent
253 determines if background of fly frame has to be drawn transparently
255 definition found in /core/layout/paintfrm.cxx
257 @return true, if background color is transparent or an existing background
258 graphic is transparent.
260 bool IsBackgroundTransparent() const;
262 void Chain( SwFrame
* _pAnchor
);
266 void InsertColumns();
268 // #i26791# - pure virtual methods of base class <SwAnchoredObject>
269 virtual void MakeObjPos() override
;
270 virtual void InvalidateObjPos() override
;
272 virtual SwFrameFormat
& GetFrameFormat() override
;
273 virtual const SwFrameFormat
& GetFrameFormat() const override
;
275 virtual SwRect
GetObjRect() const override
;
277 /** method to determine if a format on the Writer fly frame is possible
280 refine 'IsFormatPossible'-conditions of method
281 <SwAnchoredObject::IsFormatPossible()> by:
282 format isn't possible, if Writer fly frame is locked resp. col-locked.
284 virtual bool IsFormatPossible() const override
;
285 static void GetAnchoredObjects( std::vector
<SwAnchoredObject
*>&, const SwFormat
& rFormat
);
287 // overwriting "SwFrameFormat *SwLayoutFrame::GetFormat" to provide the correct derived return type.
288 // (This is in order to skip on the otherwise necessary casting of the result to
289 // 'SwFlyFrameFormat *' after calls to this function. The casting is now done in this function.)
290 virtual const SwFlyFrameFormat
*GetFormat() const override
;
291 virtual SwFlyFrameFormat
*GetFormat() override
;
293 virtual void dumpAsXml(xmlTextWriterPtr writer
= nullptr) const override
;
295 virtual void Calc(vcl::RenderContext
* pRenderContext
) const override
;
297 const Point
& ContentPos() const { return m_aContentPos
; }
298 Point
& ContentPos() { return m_aContentPos
; }
300 void InvalidateContentPos();
302 void SelectionHasChanged(SwFEShell
* pShell
);
303 bool IsShowUnfloatButton(SwWrtShell
* pWrtSh
) const;
305 // For testing only (see uiwriter)
306 void ActiveUnfloatButton(SwWrtShell
* pWrtSh
);
308 virtual const SwFlyFrame
* DynCastFlyFrame() const override
;
309 virtual SwFlyFrame
* DynCastFlyFrame() override
;
311 SwFlyAtContentFrame
* DynCastFlyAtContentFrame();
314 void UpdateUnfloatButton(SwWrtShell
* pWrtSh
, bool bShow
) const;
315 void PaintDecorators() const;
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */