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 .
19 #ifndef INCLUDED_SW_INC_FRMFMT_HXX
20 #define INCLUDED_SW_INC_FRMFMT_HXX
23 #include <com/sun/star/text/PositionLayoutDir.hpp>
24 #include <cppuhelper/weakref.hxx>
25 #include <tools/gen.hxx>
27 #include "hintids.hxx"
32 class SwFlyDrawContact
;
33 class SwAnchoredObject
;
44 class DocumentLayoutManager
;
45 // This is cheating: we are not really decoupling much with this hint.
46 // SwDrawFrameFormat should probably bookkeep its SdrObject (and
47 // SwDrawFrameFormat too) as members
48 struct SW_DLLPUBLIC FindSdrObjectHint final
: SfxHint
50 SdrObject
*& m_rpObject
;
51 FindSdrObjectHint(SdrObject
*& rpObject
) : m_rpObject(rpObject
) {};
52 virtual ~FindSdrObjectHint() override
;
57 /// Style of a layout element.
58 class SW_DLLPUBLIC SwFrameFormat
62 friend class SwPageDesc
; ///< Is allowed to call protected CTor.
63 friend class ::sw::DocumentLayoutManager
; ///< Is allowed to call protected CTor.
64 friend class SwFrameFormats
; ///< Is allowed to update the list backref.
65 friend class SwTextBoxHelper
;
66 friend class SwUndoFlyBase
; ///< calls SetOtherTextBoxFormat
68 css::uno::WeakReference
<css::uno::XInterface
> m_wXObject
;
70 // DrawingLayer FillAttributes in a preprocessed form for primitive usage
71 drawinglayer::attribute::SdrAllFillAttributesHelperPtr maFillAttributes
;
73 // The assigned SwFrmFmt list.
74 SwFrameFormats
*m_ffList
;
76 SwFrameFormat
*m_pOtherTextBoxFormat
;
80 change_name(const OUString
&rName
) : mName(rName
) {}
81 void operator()(SwFormat
*pFormat
) { pFormat
->m_aFormatName
= mName
; }
82 const OUString
&mName
;
88 const char* pFormatNm
,
89 SwFrameFormat
*pDrvdFrame
,
90 sal_uInt16 nFormatWhich
= RES_FRMFMT
,
91 const sal_uInt16
* pWhichRange
= nullptr);
95 const OUString
&rFormatNm
,
96 SwFrameFormat
*pDrvdFrame
,
97 sal_uInt16 nFormatWhich
= RES_FRMFMT
,
98 const sal_uInt16
* pWhichRange
= nullptr);
100 virtual void Modify( const SfxPoolItem
* pOld
, const SfxPoolItem
* pNewValue
) override
;
102 SwFrameFormat
* GetOtherTextBoxFormat() const { return m_pOtherTextBoxFormat
; }
103 void SetOtherTextBoxFormat( SwFrameFormat
*pFormat
);
106 virtual ~SwFrameFormat() override
;
108 SwFrameFormat(SwFrameFormat
const &) = default;
109 SwFrameFormat(SwFrameFormat
&&) = default;
110 SwFrameFormat
& operator =(SwFrameFormat
const &) = default;
111 SwFrameFormat
& operator =(SwFrameFormat
&&) = default;
113 /// Destroys all Frames in aDepend (Frames are identified via dynamic_cast).
114 virtual void DelFrames();
116 /// Creates the views.
117 virtual void MakeFrames();
119 virtual Graphic
MakeGraphic( ImageMap
* pMap
= nullptr );
121 /** @return the IMapObject defined at format (Fly)
122 in the ImageMap at position Point.
123 rPoint - test on DocPosition.
124 pFly - optional FlyFrame, in case it is already known. */
125 IMapObject
* GetIMapObject( const Point
& rPoint
,
126 const SwFlyFrame
*pFly
= nullptr ) const;
128 /** @return the real size of the frame - or an empty rectangle
130 If pPoint is given, look for the frame closest to it. */
131 SwRect
FindLayoutRect( const bool bPrtArea
= false,
132 const Point
* pPoint
= nullptr ) const;
134 /** @return the SdrObject, that is connected to the ContactObject.
135 Only DrawFrameFormats are connected to the "real SdrObject". FlyFrameFormats
136 are connected to a Master and all FlyFrames has the "real SdrObject".
137 "Real SdrObject" has position and a Z-order. */
138 SdrObject
* FindSdrObject()
140 SdrObject
* pObject(nullptr);
141 CallSwClientNotify(sw::FindSdrObjectHint(pObject
));
144 const SdrObject
*FindSdrObject() const
145 { return const_cast<SwFrameFormat
*>(this)->FindSdrObject(); }
147 SdrObject
*FindRealSdrObject();
148 const SdrObject
*FindRealSdrObject() const
149 { return const_cast<SwFrameFormat
*>(this)->FindRealSdrObject(); }
151 bool IsLowerOf( const SwFrameFormat
& rFormat
) const;
160 virtual SwFrameFormat::tLayoutDir
GetLayoutDir() const;
161 virtual void SetLayoutDir( const SwFrameFormat::tLayoutDir _eLayoutDir
);
163 virtual sal_Int16
GetPositionLayoutDir() const;
164 virtual void SetPositionLayoutDir( const sal_Int16 _nPositionLayoutDir
);
166 virtual OUString
GetDescription() const;
168 SAL_DLLPRIVATE
css::uno::WeakReference
<css::uno::XInterface
> const& GetXObject() const
169 { return m_wXObject
; }
170 SAL_DLLPRIVATE
void SetXObject(css::uno::Reference
<css::uno::XInterface
> const& xObject
)
171 { m_wXObject
= xObject
; }
173 void RegisterToFormat( SwFormat
& rFormat
);
175 // Access to DrawingLayer FillAttributes in a preprocessed form for primitive usage
176 virtual drawinglayer::attribute::SdrAllFillAttributesHelperPtr
getSdrAllFillAttributesHelper() const override
;
177 virtual bool supportsFullDrawingLayerFillAttributeSet() const override
;
179 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
181 virtual void SetName( const OUString
& rNewName
, bool bBroadcast
=false ) override
;
182 void MoveTableBox(SwTableBox
& rTableBox
, const SwFrameFormat
* pOldFormat
);
185 // The FlyFrame-Format
187 class SW_DLLPUBLIC SwFlyFrameFormat final
: public SwFrameFormat
193 /** Both not existent.
194 it stores the previous position of Prt rectangle from RequestObjectResize
195 so it can be used to move frames of non-resizable objects to align them correctly
196 when they get borders (this is done in SwWrtShell::CalcAndGetScale) */
197 Point m_aLastFlyFramePrtRectPos
;
198 std::unique_ptr
<SwFlyDrawContact
> m_pContact
;
200 SwFlyFrameFormat( const SwFlyFrameFormat
&rCpy
) = delete;
201 SwFlyFrameFormat
&operator=( const SwFlyFrameFormat
&rCpy
) = delete;
203 SwFlyFrameFormat( SwAttrPool
& rPool
, const OUString
&rFormatNm
, SwFrameFormat
*pDrvdFrame
);
206 virtual ~SwFlyFrameFormat() override
;
208 /// Creates the views.
209 virtual void MakeFrames() override
;
211 SwFlyFrame
* GetFrame( const Point
* pDocPos
= nullptr ) const;
213 SwAnchoredObject
* GetAnchoredObj() const;
215 virtual Graphic
MakeGraphic( ImageMap
* pMap
= nullptr ) override
;
217 virtual bool GetInfo( SfxPoolItem
& rInfo
) const override
;
219 OUString
GetObjTitle() const;
220 void SetObjTitle( const OUString
& rTitle
, bool bBroadcast
= false );
221 OUString
GetObjDescription() const;
222 void SetObjDescription( const OUString
& rDescription
, bool bBroadcast
= false );
224 /** SwFlyFrameFormat::IsBackgroundTransparent
226 Override virtual method and its default implementation,
227 because format of fly frame provides transparent backgrounds.
228 Method determines, if background of fly frame is transparent.
230 @return true, if background color is transparent, but not "no fill"
231 or an existing background graphic is transparent.
233 virtual bool IsBackgroundTransparent() const override
;
235 /** SwFlyFrameFormat::IsBackgroundBrushInherited
237 Method to determine, if the brush for drawing the
238 background is "inherited" from its parent/grandparent.
239 This is the case, if no background graphic is set and the background
240 color is "no fill"/"auto fill"
242 @return true, if background brush is "inherited" from parent/grandparent
244 bool IsBackgroundBrushInherited() const;
246 const Point
& GetLastFlyFramePrtRectPos() const { return m_aLastFlyFramePrtRectPos
; }
247 void SetLastFlyFramePrtRectPos( const Point
&rPoint
) { m_aLastFlyFramePrtRectPos
= rPoint
; }
249 SwFlyDrawContact
* GetOrCreateContact();
252 //The DrawFrame-Format
255 class SwDrawFrameFormat
;
261 enum class DrawFrameFormatHintId
{
269 POST_RESTORE_FLY_ANCHOR
,
271 struct DrawFrameFormatHint final
: SfxHint
273 DrawFrameFormatHintId m_eId
;
274 DrawFrameFormatHint(DrawFrameFormatHintId eId
) : m_eId(eId
) {};
275 virtual ~DrawFrameFormatHint() override
;
277 struct CheckDrawFrameFormatLayerHint final
: SfxHint
279 bool* m_bCheckControlLayer
;
280 CheckDrawFrameFormatLayerHint(bool* bCheckControlLayer
) : m_bCheckControlLayer(bCheckControlLayer
) {};
281 virtual ~CheckDrawFrameFormatLayerHint() override
;
283 struct ContactChangedHint final
: SfxHint
285 SdrObject
** m_ppObject
;
286 ContactChangedHint(SdrObject
** ppObject
) : m_ppObject(ppObject
) {};
287 virtual ~ContactChangedHint() override
;
289 struct DrawFormatLayoutCopyHint final
: SfxHint
291 SwDrawFrameFormat
& m_rDestFormat
;
293 DrawFormatLayoutCopyHint(SwDrawFrameFormat
& rDestFormat
, SwDoc
& rDestDoc
) : m_rDestFormat(rDestFormat
), m_rDestDoc(rDestDoc
) {};
294 virtual ~DrawFormatLayoutCopyHint() override
;
296 enum class WW8AnchorConv
305 struct WW8AnchorConvResult final
307 WW8AnchorConv m_eHoriConv
;
308 WW8AnchorConv m_eVertConv
;
311 WW8AnchorConvResult(WW8AnchorConv eHoriConv
, WW8AnchorConv eVertConv
) : m_eHoriConv(eHoriConv
), m_eVertConv(eVertConv
), m_bConverted(false) {};
313 struct SW_DLLPUBLIC WW8AnchorConvHint final
: SfxHint
315 WW8AnchorConvResult
& m_rResult
;
316 WW8AnchorConvHint(WW8AnchorConvResult
& rResult
) : m_rResult(rResult
) {};
317 virtual ~WW8AnchorConvHint() override
;
319 struct RestoreFlyAnchorHint final
: SfxHint
322 RestoreFlyAnchorHint(Point aPos
) : m_aPos(aPos
) {};
323 virtual ~RestoreFlyAnchorHint() override
;
325 struct CreatePortionHint final
: SfxHint
327 SwDrawContact
** m_ppContact
;
328 CreatePortionHint(SwDrawContact
** ppContact
) : m_ppContact(ppContact
) {};
329 virtual ~CreatePortionHint() override
;
331 struct CollectTextObjectsHint final
: SfxHint
333 std::list
<SdrTextObj
*>& m_rTextObjects
;
334 CollectTextObjectsHint(std::list
<SdrTextObj
*>& rTextObjects
) : m_rTextObjects(rTextObjects
) {};
335 virtual ~CollectTextObjectsHint() override
;
337 struct GetZOrderHint final
: SfxHint
339 sal_uInt32
& m_rnZOrder
;
340 GetZOrderHint(sal_uInt32
& rnZOrder
) : m_rnZOrder(rnZOrder
) {};
341 virtual ~GetZOrderHint() override
;
343 struct GetObjectConnectedHint final
: SfxHint
345 bool& m_risConnected
;
346 const SwRootFrame
* m_pRoot
;
347 GetObjectConnectedHint(bool& risConnected
, const SwRootFrame
* pRoot
) : m_risConnected(risConnected
), m_pRoot(pRoot
) {};
348 virtual ~GetObjectConnectedHint() override
;
352 class SW_DLLPUBLIC SwDrawFrameFormat
: public SwFrameFormat
356 mutable const SdrObject
* m_pSdrObjectCached
;
357 mutable OUString m_sSdrObjectCachedComment
;
359 SwDrawFrameFormat( const SwDrawFrameFormat
&rCpy
) = delete;
360 SwDrawFrameFormat
&operator=( const SwDrawFrameFormat
&rCpy
) = delete;
362 SwFrameFormat::tLayoutDir meLayoutDir
;
364 sal_Int16 mnPositionLayoutDir
;
369 SwDrawFrameFormat( SwAttrPool
& rPool
, const OUString
&rFormatNm
,
370 SwFrameFormat
*pDrvdFrame
)
371 : SwFrameFormat( rPool
, rFormatNm
, pDrvdFrame
, RES_DRAWFRMFMT
),
372 m_pSdrObjectCached(nullptr),
373 meLayoutDir( SwFrameFormat::HORI_L2R
),
375 mnPositionLayoutDir( css::text::PositionLayoutDir::PositionInLayoutDirOfAnchor
),
377 mbPosAttrSet( false )
381 virtual ~SwDrawFrameFormat() override
;
383 /** DrawObjects are removed from the arrays at the layout.
384 The DrawObjects are marked as deleted. */
385 virtual void DelFrames() override
;
387 /** Register DrawObjects in the arrays at layout.
388 Reset delete marks. */
389 virtual void MakeFrames() override
;
391 virtual Graphic
MakeGraphic( ImageMap
* pMap
= nullptr ) override
;
393 virtual SwFrameFormat::tLayoutDir
GetLayoutDir() const override
;
394 virtual void SetLayoutDir( const SwFrameFormat::tLayoutDir _eLayoutDir
) override
;
396 virtual sal_Int16
GetPositionLayoutDir() const override
;
397 virtual void SetPositionLayoutDir( const sal_Int16 _nPositionLayoutDir
) override
;
399 bool IsPosAttrSet() const { return mbPosAttrSet
; }
400 void PosAttrSet() { mbPosAttrSet
= true; }
402 virtual OUString
GetDescription() const override
;
407 SW_DLLPUBLIC
bool IsFlyFrameFormatInHeader(const SwFrameFormat
& rFormat
);
409 void CheckAnchoredFlyConsistency(SwDoc
const& rDoc
);
415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */