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>
28 template<class T
> class FrameFormats
;
32 #include "hintids.hxx"
35 #include "textboxhelper.hxx"
41 class SwAnchoredObject
;
42 class SwDrawFrameFormat
;
43 class SwFlyDrawContact
;
45 class SwFlyFrameFormat
;
52 class DocumentLayoutManager
;
53 // This is cheating: we are not really decoupling much with this hint.
54 // SwDrawFrameFormat should probably bookkeep its SdrObject (and
55 // SwDrawFrameFormat too) as members
56 struct SW_DLLPUBLIC FindSdrObjectHint final
: SfxHint
58 SdrObject
*& m_rpObject
;
59 FindSdrObjectHint(SdrObject
*& rpObject
)
60 : SfxHint(SfxHintId::SwFindSdrObject
), m_rpObject(rpObject
) {};
61 virtual ~FindSdrObjectHint() override
;
63 template<class T
> class FrameFormats
;
69 /// Style of a layout element.
70 class SW_DLLPUBLIC SwFrameFormat
74 friend class SwPageDesc
; ///< Is allowed to call protected CTor.
75 friend class ::sw::DocumentLayoutManager
; ///< Is allowed to call protected CTor.
76 friend class sw::FrameFormats
<SwTableFormat
*>; ///< Is allowed to update the list backref.
77 friend class sw::FrameFormats
<sw::SpzFrameFormat
*>; ///< Is allowed to update the list backref.
78 friend class sw::FrameFormats
<SwFrameFormat
*>; ///< Is allowed to update the list backref.
79 friend class SwTextBoxHelper
;
80 friend class SwUndoFlyBase
; ///< calls SetOtherTextBoxFormat
82 css::uno::WeakReference
<css::uno::XInterface
> m_wXObject
;
84 // DrawingLayer FillAttributes in a preprocessed form for primitive usage
85 drawinglayer::attribute::SdrAllFillAttributesHelperPtr maFillAttributes
;
87 // The assigned SwFrmFmt list.
88 SwFormatsBase
* m_ffList
;
90 std::shared_ptr
< SwTextBoxNode
> m_pOtherTextBoxFormats
;
94 change_name(const OUString
&rName
) : mName(rName
) {}
95 void operator()(SwFormat
*pFormat
) { pFormat
->m_aFormatName
= mName
; }
96 const OUString
&mName
;
102 const char* pFormatNm
,
103 SwFrameFormat
*pDrvdFrame
,
104 sal_uInt16 nFormatWhich
= RES_FRMFMT
,
105 const WhichRangesContainer
& pWhichRange
= aFrameFormatSetRange
);
109 const OUString
&rFormatNm
,
110 SwFrameFormat
*pDrvdFrame
,
111 sal_uInt16 nFormatWhich
= RES_FRMFMT
,
112 const WhichRangesContainer
& pWhichRange
= aFrameFormatSetRange
);
114 virtual void SwClientNotify(const SwModify
&, const SfxHint
&) override
;
118 const std::shared_ptr
< SwTextBoxNode
>& GetOtherTextBoxFormats() const { return m_pOtherTextBoxFormats
; };
119 void SetOtherTextBoxFormats(const std::shared_ptr
<SwTextBoxNode
>& rNew
) { m_pOtherTextBoxFormats
= rNew
; };
121 virtual ~SwFrameFormat() override
;
123 SwFrameFormat(SwFrameFormat
const &) = default;
124 SwFrameFormat(SwFrameFormat
&&) = default;
125 SwFrameFormat
& operator =(SwFrameFormat
const &) = default;
126 SwFrameFormat
& operator =(SwFrameFormat
&&) = default;
128 /// Destroys all Frames in aDepend (Frames are identified via dynamic_cast).
129 virtual void DelFrames();
131 /// Creates the views.
132 virtual void MakeFrames();
134 virtual Graphic
MakeGraphic( ImageMap
* pMap
= nullptr, const sal_uInt32 nMaximumQuadraticPixels
= 500000, const std::optional
<Size
>& rTargetDPI
= std::nullopt
);
136 /** @return the IMapObject defined at format (Fly)
137 in the ImageMap at position Point.
138 rPoint - test on DocPosition.
139 pFly - optional FlyFrame, in case it is already known. */
140 IMapObject
* GetIMapObject( const Point
& rPoint
,
141 const SwFlyFrame
*pFly
= nullptr ) const;
143 /** @return the real size of the frame - or an empty rectangle
145 If pPoint is given, look for the frame closest to it. */
146 SwRect
FindLayoutRect( const bool bPrtArea
= false,
147 const Point
* pPoint
= nullptr ) const;
149 /** @return the SdrObject, that is connected to the ContactObject.
150 Only DrawFrameFormats are connected to the "real SdrObject". FlyFrameFormats
151 are connected to a Master and all FlyFrames has the "real SdrObject".
152 "Real SdrObject" has position and a Z-order. */
153 SdrObject
* FindSdrObject()
155 SdrObject
* pObject(nullptr);
156 CallSwClientNotify(sw::FindSdrObjectHint(pObject
));
159 const SdrObject
*FindSdrObject() const
160 { return const_cast<SwFrameFormat
*>(this)->FindSdrObject(); }
162 SdrObject
*FindRealSdrObject();
163 const SdrObject
*FindRealSdrObject() const
164 { return const_cast<SwFrameFormat
*>(this)->FindRealSdrObject(); }
166 bool IsLowerOf( const SwFrameFormat
& rFormat
) const;
175 virtual SwFrameFormat::tLayoutDir
GetLayoutDir() const;
176 virtual void SetLayoutDir( const SwFrameFormat::tLayoutDir _eLayoutDir
);
178 virtual sal_Int16
GetPositionLayoutDir() const;
179 virtual void SetPositionLayoutDir( const sal_Int16 _nPositionLayoutDir
);
181 virtual OUString
GetDescription() const;
183 SAL_DLLPRIVATE
css::uno::WeakReference
<css::uno::XInterface
> const& GetXObject() const
184 { return m_wXObject
; }
185 SAL_DLLPRIVATE
void SetXObject(css::uno::Reference
<css::uno::XInterface
> const& xObject
)
186 { m_wXObject
= xObject
; }
188 void RegisterToFormat( SwFormat
& rFormat
);
190 // Access to DrawingLayer FillAttributes in a preprocessed form for primitive usage
191 virtual drawinglayer::attribute::SdrAllFillAttributesHelperPtr
getSdrAllFillAttributesHelper() const override
;
192 virtual bool supportsFullDrawingLayerFillAttributeSet() const override
;
194 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
196 virtual void SetFormatName( const OUString
& rNewName
, bool bBroadcast
=false ) override
;
197 void MoveTableBox(SwTableBox
& rTableBox
, const SwFrameFormat
* pOldFormat
);
198 virtual bool IsVisible() const;
203 class SW_DLLPUBLIC SpzFrameFormat
: public SwFrameFormat
{
204 friend ::SwDrawFrameFormat
;
205 friend ::SwFlyFrameFormat
;
208 const OUString
& rFormatName
,
209 SwFrameFormat
* pDerivedFrame
,
210 sal_uInt16 nFormatWhich
)
211 : SwFrameFormat(rPool
, rFormatName
, pDerivedFrame
, nFormatWhich
)
213 assert(nFormatWhich
== RES_DRAWFRMFMT
|| nFormatWhich
== RES_FLYFRMFMT
);
217 // The FlyFrame-Format
219 class SW_DLLPUBLIC SwFlyFrameFormat final
: public sw::SpzFrameFormat
224 /// A tooltip has priority over an SwFormatURL and is not persisted to files.
227 /** Both not existent.
228 it stores the previous position of Prt rectangle from RequestObjectResize
229 so it can be used to move frames of non-resizable objects to align them correctly
230 when they get borders (this is done in SwWrtShell::CalcAndGetScale) */
231 Point m_aLastFlyFramePrtRectPos
;
232 std::unique_ptr
<SwFlyDrawContact
> m_pContact
;
234 SwFlyFrameFormat( const SwFlyFrameFormat
&rCpy
) = delete;
235 SwFlyFrameFormat
&operator=( const SwFlyFrameFormat
&rCpy
) = delete;
237 SwFlyFrameFormat( SwAttrPool
& rPool
, const OUString
&rFormatNm
, SwFrameFormat
*pDrvdFrame
);
240 virtual ~SwFlyFrameFormat() override
;
242 /// Creates the views.
243 virtual void MakeFrames() override
;
245 SwFlyFrame
* GetFrame( const Point
* pDocPos
= nullptr ) const;
247 SwAnchoredObject
* GetAnchoredObj() const;
249 virtual Graphic
MakeGraphic( ImageMap
* pMap
= nullptr, const sal_uInt32 nMaximumQuadraticPixels
= 500000, const std::optional
<Size
>& rTargetDPI
= std::nullopt
) override
;
251 OUString
GetObjTitle() const;
252 void SetObjTitle( const OUString
& rTitle
, bool bBroadcast
= false );
254 const OUString
& GetObjTooltip() const;
255 void SetObjTooltip(const OUString
& rTooltip
);
257 OUString
GetObjDescription() const;
258 void SetObjDescription( const OUString
& rDescription
, bool bBroadcast
= false );
260 bool IsDecorative() const;
261 void SetObjDecorative(bool isDecorative
);
263 /** SwFlyFrameFormat::IsBackgroundTransparent
265 Override virtual method and its default implementation,
266 because format of fly frame provides transparent backgrounds.
267 Method determines, if background of fly frame is transparent.
269 @return true, if background color is transparent, but not "no fill"
270 or an existing background graphic is transparent.
272 virtual bool IsBackgroundTransparent() const override
;
274 /** SwFlyFrameFormat::IsBackgroundBrushInherited
276 Method to determine, if the brush for drawing the
277 background is "inherited" from its parent/grandparent.
278 This is the case, if no background graphic is set and the background
279 color is "no fill"/"auto fill"
281 @return true, if background brush is "inherited" from parent/grandparent
283 bool IsBackgroundBrushInherited() const;
285 const Point
& GetLastFlyFramePrtRectPos() const { return m_aLastFlyFramePrtRectPos
; }
286 void SetLastFlyFramePrtRectPos( const Point
&rPoint
) { m_aLastFlyFramePrtRectPos
= rPoint
; }
288 SwFlyDrawContact
* GetOrCreateContact();
291 //The DrawFrame-Format
294 class SwDrawFrameFormat
;
300 enum class DrawFrameFormatHintId
{
308 POST_RESTORE_FLY_ANCHOR
,
310 struct DrawFrameFormatHint final
: SfxHint
312 DrawFrameFormatHintId m_eId
;
313 DrawFrameFormatHint(DrawFrameFormatHintId eId
)
314 : SfxHint(SfxHintId::SwDrawFrameFormat
), m_eId(eId
) {};
315 virtual ~DrawFrameFormatHint() override
;
317 struct CheckDrawFrameFormatLayerHint final
: SfxHint
319 bool* m_bCheckControlLayer
;
320 CheckDrawFrameFormatLayerHint(bool* bCheckControlLayer
)
321 : SfxHint(SfxHintId::SwCheckDrawFrameFormatLayer
),
322 m_bCheckControlLayer(bCheckControlLayer
) {};
323 virtual ~CheckDrawFrameFormatLayerHint() override
;
325 struct ContactChangedHint final
: SfxHint
327 SdrObject
** m_ppObject
;
328 ContactChangedHint(SdrObject
** ppObject
)
329 : SfxHint(SfxHintId::SwContactChanged
),
330 m_ppObject(ppObject
) {};
331 virtual ~ContactChangedHint() override
;
333 struct DrawFormatLayoutCopyHint final
: SfxHint
335 SwDrawFrameFormat
& m_rDestFormat
;
337 DrawFormatLayoutCopyHint(SwDrawFrameFormat
& rDestFormat
, SwDoc
& rDestDoc
)
338 : SfxHint(SfxHintId::SwDrawFormatLayoutCopy
),
339 m_rDestFormat(rDestFormat
), m_rDestDoc(rDestDoc
) {};
340 virtual ~DrawFormatLayoutCopyHint() override
;
342 enum class WW8AnchorConv
351 struct WW8AnchorConvResult final
353 WW8AnchorConv m_eHoriConv
;
354 WW8AnchorConv m_eVertConv
;
357 WW8AnchorConvResult(WW8AnchorConv eHoriConv
, WW8AnchorConv eVertConv
) : m_eHoriConv(eHoriConv
), m_eVertConv(eVertConv
), m_bConverted(false) {};
359 struct SW_DLLPUBLIC WW8AnchorConvHint final
: SfxHint
361 WW8AnchorConvResult
& m_rResult
;
362 WW8AnchorConvHint(WW8AnchorConvResult
& rResult
)
363 : SfxHint(SfxHintId::SwWW8AnchorConv
),
364 m_rResult(rResult
) {};
365 virtual ~WW8AnchorConvHint() override
;
367 struct RestoreFlyAnchorHint final
: SfxHint
370 RestoreFlyAnchorHint(Point aPos
)
371 : SfxHint(SfxHintId::SwRestoreFlyAnchor
),
373 virtual ~RestoreFlyAnchorHint() override
;
375 struct CreatePortionHint final
: SfxHint
377 SwDrawContact
** m_ppContact
;
378 CreatePortionHint(SwDrawContact
** ppContact
)
379 : SfxHint(SfxHintId::SwCreatePortion
),
380 m_ppContact(ppContact
) {};
381 virtual ~CreatePortionHint() override
;
383 struct CollectTextObjectsHint final
: SfxHint
385 std::list
<SdrTextObj
*>& m_rTextObjects
;
386 CollectTextObjectsHint(std::list
<SdrTextObj
*>& rTextObjects
)
387 : SfxHint(SfxHintId::SwCollectTextObjects
),
388 m_rTextObjects(rTextObjects
) {};
389 virtual ~CollectTextObjectsHint() override
;
391 struct GetZOrderHint final
: SfxHint
393 sal_uInt32
& m_rnZOrder
;
394 GetZOrderHint(sal_uInt32
& rnZOrder
)
395 : SfxHint(SfxHintId::SwGetZOrder
),
396 m_rnZOrder(rnZOrder
) {};
397 virtual ~GetZOrderHint() override
;
399 struct GetObjectConnectedHint final
: SfxHint
401 bool& m_risConnected
;
402 const SwRootFrame
* m_pRoot
;
403 GetObjectConnectedHint(bool& risConnected
, const SwRootFrame
* pRoot
)
404 : SfxHint(SfxHintId::SwGetObjectConnected
),
405 m_risConnected(risConnected
), m_pRoot(pRoot
) {};
406 virtual ~GetObjectConnectedHint() override
;
410 class SW_DLLPUBLIC SwDrawFrameFormat final
: public sw::SpzFrameFormat
414 mutable const SdrObject
* m_pSdrObjectCached
;
415 mutable OUString m_sSdrObjectCachedComment
;
417 SwDrawFrameFormat( const SwDrawFrameFormat
&rCpy
) = delete;
418 SwDrawFrameFormat
&operator=( const SwDrawFrameFormat
&rCpy
) = delete;
420 SwFrameFormat::tLayoutDir meLayoutDir
;
422 sal_Int16 mnPositionLayoutDir
;
426 SwDrawFrameFormat(SwAttrPool
& rPool
, const OUString
& rFormatName
, SwFrameFormat
* pDerivedFrame
)
427 : sw::SpzFrameFormat(rPool
, rFormatName
, pDerivedFrame
, RES_DRAWFRMFMT
),
428 m_pSdrObjectCached(nullptr),
429 meLayoutDir(SwFrameFormat::HORI_L2R
),
430 mnPositionLayoutDir(css::text::PositionLayoutDir::PositionInLayoutDirOfAnchor
),
435 virtual ~SwDrawFrameFormat() override
;
437 /** DrawObjects are removed from the arrays at the layout.
438 The DrawObjects are marked as deleted. */
439 virtual void DelFrames() override
;
441 /** Register DrawObjects in the arrays at layout.
442 Reset delete marks. */
443 virtual void MakeFrames() override
;
445 virtual Graphic
MakeGraphic( ImageMap
* pMap
= nullptr, const sal_uInt32 nMaximumQuadraticPixels
= 500000, const std::optional
<Size
>& rTargetDPI
= std::nullopt
) override
;
447 virtual SwFrameFormat::tLayoutDir
GetLayoutDir() const override
;
448 virtual void SetLayoutDir( const SwFrameFormat::tLayoutDir _eLayoutDir
) override
;
450 virtual sal_Int16
GetPositionLayoutDir() const override
;
451 virtual void SetPositionLayoutDir( const sal_Int16 _nPositionLayoutDir
) override
;
453 bool IsPosAttrSet() const { return mbPosAttrSet
; }
454 void PosAttrSet() { mbPosAttrSet
= true; }
456 virtual OUString
GetDescription() const override
;
461 SW_DLLPUBLIC
bool IsFlyFrameFormatInHeader(const SwFrameFormat
& rFormat
);
463 void CheckAnchoredFlyConsistency(SwDoc
const& rDoc
);
469 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */