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_DCONTACT_HXX
20 #define INCLUDED_SW_INC_DCONTACT_HXX
22 #include <svx/svdobj.hxx>
23 #include <svx/svdovirt.hxx>
24 #include "fmtanchr.hxx"
31 #include "anchoreddrawobject.hxx"
36 class SwVirtFlyDrawObj
;
44 /** The other way round: Search format for given object.
45 If object is a SwVirtFlyDrawObj the format will be obtained from it.
46 If not it is a simple DrawObject. It has a UserCall which
47 is client of the format we are looking for.
48 Implementation in dcontact.cxx. */
49 SW_DLLPUBLIC SwFrameFormat
*FindFrameFormat( SdrObject
*pObj
);
50 inline const SwFrameFormat
*FindFrameFormat( const SdrObject
*pObj
)
51 { return ::FindFrameFormat( const_cast<SdrObject
*>(pObj
) ); }
52 bool HasWrap( const SdrObject
* pObj
);
54 void setContextWritingMode( SdrObject
* pObj
, SwFrame
const * pAnchor
);
56 /// @return BoundRect plus distance.
57 SwRect
GetBoundRectOfAnchoredObj( const SdrObject
* pObj
);
59 /// @return UserCall of group object (if applicable).
60 SwContact
* GetUserCall( const SdrObject
* );
62 /// @return TRUE if the SrdObject is a Marquee object.
63 bool IsMarqueeTextObj( const SdrObject
& rObj
);
65 /// Base class for the following contact objects (frame + draw objects).
66 class SAL_DLLPUBLIC_RTTI SwContact
: public SdrObjUserCall
, public SwClient
68 /** boolean, indicating destruction of contact object
69 important note: boolean has to be set at the beginning of each destructor
70 in the subclasses using method <SetInDTOR()>. */
73 /** method to move object to visible/invisible layer
75 Implementation for the public method <MoveObjToVisibleLayer(..)>
76 and <MoveObjToInvisibleLayer(..)>
77 If object is in invisible respectively visible layer, it's moved to
78 the corresponding visible respectively invisible layers.
79 For group object the members are individually moved to the corresponding
80 layer, because <SdrObjGroup::GetLayer()> does return 0, if members
81 aren't on the same layer as the group object, and
82 <SdrObjGroup::SetLayer(..)|NbcSetLayer(..)> sets also the layer of
86 input parameter - boolean indicating, if object has to be moved to
87 visible (== true) or invisible (== false) layer.
90 input parameter, which will be changed - drawing object, which will
93 void MoveObjToLayer( const bool _bToVisible
,
94 SdrObject
* _pDrawObj
);
98 virtual void SwClientNotify(const SwModify
&, const SfxHint
& rHint
) override
;
102 /// For reader. Only the connection is created.
103 SwContact( SwFrameFormat
*pToRegisterIn
);
104 virtual ~SwContact() override
;
106 virtual const SwAnchoredObject
* GetAnchoredObj( const SdrObject
* _pSdrObj
) const = 0;
107 virtual SwAnchoredObject
* GetAnchoredObj( SdrObject
* _pSdrObj
) = 0;
109 virtual const SdrObject
*GetMaster() const = 0;
110 virtual SdrObject
*GetMaster() = 0;
112 SwFrameFormat
*GetFormat() { return static_cast<SwFrameFormat
*>(GetRegisteredIn()); }
113 const SwFrameFormat
*GetFormat() const
114 { return static_cast<const SwFrameFormat
*>(GetRegisteredIn()); }
116 bool IsInDTOR() const { return mbInDTOR
;}
118 /** method to move drawing object to corresponding visible layer
120 uses method <MoveObjToLayer(..)>
123 drawing object, which will be moved to the visible layer
125 virtual void MoveObjToVisibleLayer( SdrObject
* _pDrawObj
);
127 /** method to move drawing object to corresponding invisible layer
129 uses method <MoveObjToLayer(..)>
132 drawing object, which will be moved to the visible layer
134 virtual void MoveObjToInvisibleLayer( SdrObject
* _pDrawObj
);
136 /** some virtual helper methods for information
137 about the object (Writer fly frame resp. drawing object) */
138 const SwFormatAnchor
& GetAnchorFormat() const
140 assert( GetFormat() );
142 return GetFormat()->GetAnchor();
145 RndStdIds
GetAnchorId() const { return GetAnchorFormat().GetAnchorId(); }
146 bool ObjAnchoredAtPage() const { return GetAnchorId() == RndStdIds::FLY_AT_PAGE
; }
147 bool ObjAnchoredAtFly() const { return GetAnchorId() == RndStdIds::FLY_AT_FLY
; }
148 bool ObjAnchoredAtPara() const { return GetAnchorId() == RndStdIds::FLY_AT_PARA
; }
149 bool ObjAnchoredAtChar() const { return GetAnchorId() == RndStdIds::FLY_AT_CHAR
; }
150 bool ObjAnchoredAsChar() const { return GetAnchorId() == RndStdIds::FLY_AS_CHAR
; }
152 const SwNode
& GetAnchorNode() const
154 const SwNode
* pNode
= GetAnchorFormat().GetAnchorNode();
159 /** get data collection of anchored objects, handled by with contact */
160 virtual void GetAnchoredObjs( std::vector
<SwAnchoredObject
*>& _roAnchoredObjs
) const = 0;
162 /** get minimum order number of anchored objects handled by with contact
165 sal_uInt32
GetMinOrdNum() const;
167 /** get maximum order number of anchored objects handled by with contact
170 sal_uInt32
GetMaxOrdNum() const;
173 /** ContactObject for connection between frames (or their formats respectively)
174 in SwClient and the drawobjects of Drawing (SdrObjUserCall). */
176 class SW_DLLPUBLIC SwFlyDrawContact final
: public SwContact
179 rtl::Reference
<SwFlyDrawObj
> mpMasterObj
;
180 void SwClientNotify(const SwModify
&, const SfxHint
& rHint
) override
;
181 sal_uInt32
GetOrdNumForNewRef(const SwFlyFrame
* pFly
, SwFrame
const& rAnchorFrame
);
185 /// Creates DrawObject and registers it with the Model.
186 SwFlyDrawContact(SwFlyFrameFormat
* pToRegisterIn
, SdrModel
& rTargetModel
);
187 static SwVirtFlyDrawObj
* CreateNewRef(SwFlyFrame
* pFly
, SwFlyFrameFormat
* pFormat
, SwFrame
const& rAnchorFrame
);
188 virtual ~SwFlyDrawContact() override
;
190 virtual const SwAnchoredObject
* GetAnchoredObj( const SdrObject
* _pSdrObj
) const override
;
191 virtual SwAnchoredObject
* GetAnchoredObj( SdrObject
* _pSdrObj
) override
;
193 virtual const SdrObject
* GetMaster() const override
194 { return const_cast<SwFlyDrawContact
*>(this)->GetMaster(); };
195 virtual SdrObject
* GetMaster() override
;
197 /** override methods to control Writer fly frames,
198 which are linked, and to assure that all objects anchored at/inside the
199 Writer fly frame are also made visible/invisible. */
200 virtual void MoveObjToVisibleLayer( SdrObject
* _pDrawObj
) override
;
201 virtual void MoveObjToInvisibleLayer( SdrObject
* _pDrawObj
) override
;
203 /** get data collection of anchored objects handled by with contact */
204 virtual void GetAnchoredObjs( std::vector
<SwAnchoredObject
*>& _roAnchoredObjs
) const override
;
207 /** new class for re-direct methods calls at a 'virtual'
208 drawing object to its referenced object.
209 For example, if an SdrObject is anchored in a header, then later pages will have a SwDrawVirtObj
211 class SwDrawVirtObj final
: public SdrVirtObj
214 // data for connection to writer layout
215 /** anchored drawing object instance for the
216 'virtual' drawing object */
217 SwAnchoredDrawObject maAnchoredDrawObj
;
219 /** writer-drawing contact object the 'virtual' drawing object is controlled by.
220 This object is also the <UserCall> of the drawing object, if it's
221 inserted into the drawing layer. */
222 SwDrawContact
& mrDrawContact
;
224 /** AW: Need own sdr::contact::ViewContact since AnchorPos from parent is
225 not used but something own (top left of new SnapRect minus top left
226 of original SnapRect) */
227 virtual std::unique_ptr
<sdr::contact::ViewContact
> CreateObjectSpecificViewContact() override
;
229 // protected destructor
230 virtual ~SwDrawVirtObj() override
;
236 SwDrawContact
& _rDrawContact
);
238 SwDrawVirtObj(SdrModel
& rSdrModel
, SwDrawVirtObj
const & rSource
);
241 virtual Point
GetOffset() const override
;
243 virtual rtl::Reference
<SdrObject
> CloneSdrObject(SdrModel
& rTargetModel
) const override
;
245 /// connection to writer layout
246 const SwAnchoredObject
& GetAnchoredObj() const { return maAnchoredDrawObj
; }
247 SwAnchoredObject
& AnchoredObj() { return maAnchoredDrawObj
; }
248 const SwFrame
* GetAnchorFrame() const;
249 SwFrame
* AnchorFrame();
250 void RemoveFromWriterLayout();
252 /// connection to drawing layer
253 void AddToDrawingPage(SwFrame
const& rAnchorFrame
);
254 void RemoveFromDrawingPage();
256 /** is 'virtual' drawing object connected to writer layout and
257 / to drawing layer. */
258 bool IsConnected() const;
260 virtual void NbcSetAnchorPos(const Point
& rPnt
) override
;
262 /// All overridden methods which need to use the offset
263 virtual void RecalcBoundRect() override
;
264 virtual ::basegfx::B2DPolyPolygon
TakeXorPoly() const override
;
265 virtual ::basegfx::B2DPolyPolygon
TakeContour() const override
;
266 virtual void AddToHdlList(SdrHdlList
& rHdlList
) const override
;
267 virtual void NbcMove(const Size
& rSiz
) override
;
268 virtual void NbcResize(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
) override
;
269 virtual void NbcRotate(const Point
& rRef
, Degree100 nAngle
, double sn
, double cs
) override
;
270 virtual void NbcMirror(const Point
& rRef1
, const Point
& rRef2
) override
;
271 virtual void NbcShear(const Point
& rRef
, Degree100 nAngle
, double tn
, bool bVShear
) override
;
272 virtual void Move(const Size
& rSiz
) override
;
273 virtual void Resize(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
, bool bUnsetRelative
= true) override
;
274 virtual void Rotate(const Point
& rRef
, Degree100 nAngle
, double sn
, double cs
) override
;
275 virtual void Mirror(const Point
& rRef1
, const Point
& rRef2
) override
;
276 virtual void Shear(const Point
& rRef
, Degree100 nAngle
, double tn
, bool bVShear
) override
;
277 virtual void RecalcSnapRect() override
;
278 virtual const tools::Rectangle
& GetSnapRect() const override
;
279 virtual void SetSnapRect(const tools::Rectangle
& rRect
) override
;
280 virtual void NbcSetSnapRect(const tools::Rectangle
& rRect
) override
;
281 virtual const tools::Rectangle
& GetLogicRect() const override
;
282 virtual void SetLogicRect(const tools::Rectangle
& rRect
) override
;
283 virtual void NbcSetLogicRect(const tools::Rectangle
& rRect
) override
;
284 virtual Point
GetSnapPoint(sal_uInt32 i
) const override
;
285 virtual Point
GetPoint(sal_uInt32 i
) const override
;
286 virtual void NbcSetPoint(const Point
& rPnt
, sal_uInt32 i
) override
;
288 virtual bool HasTextEdit() const override
;
290 virtual SdrLayerID
GetLayer() const override
;
291 virtual void NbcSetLayer(SdrLayerID nLayer
) override
;
292 virtual void SetLayer(SdrLayerID nLayer
) override
;
294 virtual void SetBoundRectDirty() override
;
295 virtual const tools::Rectangle
& GetCurrentBoundRect() const override
;
296 virtual const tools::Rectangle
& GetLastBoundRect() const override
;
299 bool CheckControlLayer( const SdrObject
*pObj
);
301 /** ContactObject for connection of formats as representatives of draw objects
302 in SwClient and the objects themselves in Drawing (SDrObjUserCall). */
304 class SAL_DLLPUBLIC_RTTI SwDrawContact final
: public SwContact
307 /** anchored drawing object instance for the
308 'master' drawing object */
309 SwAnchoredDrawObject maAnchoredDrawObj
;
311 /** container for 'virtual' drawing object supporting drawing objects in headers/footers. */
312 std::vector
< rtl::Reference
<SwDrawVirtObj
> > maDrawVirtObjs
;
314 /** boolean indicating set 'master' drawing
315 object has been cleared. */
316 bool mbMasterObjCleared
: 1;
318 /** internal flag to indicate that disconnect
319 from layout is in progress */
320 bool mbDisconnectInProgress
: 1;
322 /** Needed data for handling of nested <SdrObjUserCall> events in
323 method <Changed_(..)> */
324 bool mbUserCallActive
: 1;
325 /** event type, which is handled for <mpSdrObjHandledByCurrentUserCall>.
326 Note: value only valid, if <mbUserCallActive> is true. */
327 SdrUserCallType meEventTypeOfCurrentUserCall
;
329 friend class NestedUserCallHdl
;
332 void InvalidateObjs_( const bool _bUpdateSortedObjsList
= false );
334 SwDrawContact( const SwDrawContact
& ) = delete;
335 SwDrawContact
& operator=( const SwDrawContact
& ) = delete;
337 virtual void SwClientNotify(const SwModify
&, const SfxHint
& rHint
) override
;
341 SwDrawContact( SwFrameFormat
*pToRegisterIn
, SdrObject
*pObj
);
342 virtual ~SwDrawContact() override
;
344 virtual const SwAnchoredObject
* GetAnchoredObj( const SdrObject
* _pSdrObj
) const override
;
345 virtual SwAnchoredObject
* GetAnchoredObj( SdrObject
* _pSdrObj
) override
;
347 virtual const SdrObject
* GetMaster() const override
348 { return const_cast<SwDrawContact
*>(this)->GetMaster(); };
349 virtual SdrObject
* GetMaster() override
;
351 const SwFrame
* GetAnchorFrame( const SdrObject
* _pDrawObj
= nullptr ) const;
352 SwFrame
* GetAnchorFrame( SdrObject
const * _pDrawObj
= nullptr );
354 const SwPageFrame
* GetPageFrame() const
356 return maAnchoredDrawObj
.GetPageFrame();
358 SwPageFrame
* GetPageFrame()
360 return maAnchoredDrawObj
.GetPageFrame();
363 SwPageFrame
* FindPage( const SwRect
&rRect
);
365 /** Inserts SdrObject in the arrays of the layout ((SwPageFrame and SwFrame).
366 The anchor is determined according to the attribute SwFormatAnchor.
367 If required the object gets unregistered with the old anchor. */
368 void ConnectToLayout( const SwFormatAnchor
*pAnch
= nullptr );
369 /** method to insert 'master' drawing object
371 void InsertMasterIntoDrawPage();
373 void DisconnectFromLayout( bool _bMoveMasterToInvisibleLayer
= true );
374 /** disconnect for a dedicated drawing object -
375 could be 'master' or 'virtual'. */
376 void DisconnectObjFromLayout( SdrObject
* _pDrawObj
);
377 /** method to remove 'master' drawing object
379 To be used by the undo for delete of object. Call it after method
380 <DisconnectFromLayout( bool = true )> is already performed.
381 Note: <DisconnectFromLayout( bool )> no longer removes the 'master'
382 drawing object from drawing page. */
383 void RemoveMasterFromDrawPage();
385 void RemoveAllVirtObjs();
387 /** get drawing object ('master' or 'virtual')
389 SdrObject
* GetDrawObjectByAnchorFrame( const SwFrame
& _rAnchorFrame
);
391 /// Virtual methods of SdrObjUserCall.
392 virtual void Changed(const SdrObject
& rObj
, SdrUserCallType eType
, const tools::Rectangle
& rOldBoundRect
) override
;
393 virtual void const* GetPDFAnchorStructureElementKey(SdrObject
const& rObj
) override
;
395 /** Used by Changed() and by UndoDraw.
396 Notifies paragraphs that have to get out of the way. */
397 void Changed_(const SdrObject
& rObj
, SdrUserCallType eType
, const tools::Rectangle
* pOldBoundRect
);
399 /// Moves all SW-connections to new Master)
400 void ChangeMasterObject( SdrObject
*pNewMaster
);
402 SwDrawVirtObj
* AddVirtObj(SwFrame
const& rAnchorFrame
);
404 void NotifyBackgroundOfAllVirtObjs( const tools::Rectangle
* pOldBoundRect
);
406 /** get data collection of anchored objects, handled by with contact */
408 static void GetTextObjectsFromFormat( std::list
<SdrTextObj
*>&, SwDoc
& );
409 virtual void GetAnchoredObjs( std::vector
<SwAnchoredObject
*>& _roAnchoredObjs
) const override
;
414 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */