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 goup 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 SwPosition
& GetContentAnchor() const
154 assert( GetAnchorFormat().GetContentAnchor() );
155 return *(GetAnchorFormat().GetContentAnchor());
158 /** get data collection of anchored objects, handled by with contact */
159 virtual void GetAnchoredObjs( std::vector
<SwAnchoredObject
*>& _roAnchoredObjs
) const = 0;
161 /** get minimum order number of anchored objects handled by with contact
164 sal_uInt32
GetMinOrdNum() const;
166 /** get maximum order number of anchored objects handled by with contact
169 sal_uInt32
GetMaxOrdNum() const;
172 /** ContactObject for connection between frames (or their formats respectively)
173 in SwClient and the drawobjects of Drawing (SdrObjUserCall). */
175 class SW_DLLPUBLIC SwFlyDrawContact final
: public SwContact
178 typedef std::unique_ptr
< SwFlyDrawObj
, SdrObjectFreeOp
> SwFlyDrawObjPtr
;
180 SwFlyDrawObjPtr mpMasterObj
;
181 void SwClientNotify(const SwModify
&, const SfxHint
& rHint
) override
;
182 sal_uInt32
GetOrdNumForNewRef(const SwFlyFrame
* pFly
, SwFrame
const& rAnchorFrame
);
186 /// Creates DrawObject and registers it with the Model.
187 SwFlyDrawContact(SwFlyFrameFormat
* pToRegisterIn
, SdrModel
& rTargetModel
);
188 static SwVirtFlyDrawObj
* CreateNewRef(SwFlyFrame
* pFly
, SwFlyFrameFormat
* pFormat
, SwFrame
const& rAnchorFrame
);
189 virtual ~SwFlyDrawContact() override
;
191 virtual const SwAnchoredObject
* GetAnchoredObj( const SdrObject
* _pSdrObj
) const override
;
192 virtual SwAnchoredObject
* GetAnchoredObj( SdrObject
* _pSdrObj
) override
;
194 virtual const SdrObject
* GetMaster() const override
195 { return const_cast<SwFlyDrawContact
*>(this)->GetMaster(); };
196 virtual SdrObject
* GetMaster() override
;
198 /** override methods to control Writer fly frames,
199 which are linked, and to assure that all objects anchored at/inside the
200 Writer fly frame are also made visible/invisible. */
201 virtual void MoveObjToVisibleLayer( SdrObject
* _pDrawObj
) override
;
202 virtual void MoveObjToInvisibleLayer( SdrObject
* _pDrawObj
) override
;
204 /** get data collection of anchored objects handled by with contact */
205 virtual void GetAnchoredObjs( std::vector
<SwAnchoredObject
*>& _roAnchoredObjs
) const override
;
208 /** new class for re-direct methods calls at a 'virtual'
209 drawing object to its referenced object.
210 For example, if an SdrObject is anchored in a header, then later pages will have a SwDrawVirtObj
212 class SwDrawVirtObj final
: public SdrVirtObj
215 // data for connection to writer layout
216 /** anchored drawing object instance for the
217 'virtual' drawing object */
218 SwAnchoredDrawObject maAnchoredDrawObj
;
220 /** writer-drawing contact object the 'virtual' drawing object is controlled by.
221 This object is also the <UserCall> of the drawing object, if it's
222 inserted into the drawing layer. */
223 SwDrawContact
& mrDrawContact
;
225 /** AW: Need own sdr::contact::ViewContact since AnchorPos from parent is
226 not used but something own (top left of new SnapRect minus top left
227 of original SnapRect) */
228 virtual std::unique_ptr
<sdr::contact::ViewContact
> CreateObjectSpecificViewContact() override
;
230 // protected destructor
231 virtual ~SwDrawVirtObj() override
;
237 SwDrawContact
& _rDrawContact
);
239 SwDrawVirtObj(SdrModel
& rSdrModel
, SwDrawVirtObj
const & rSource
);
242 virtual Point
GetOffset() const override
;
244 virtual SwDrawVirtObj
* CloneSdrObject(SdrModel
& rTargetModel
) const override
;
246 /// connection to writer layout
247 const SwAnchoredObject
& GetAnchoredObj() const { return maAnchoredDrawObj
; }
248 SwAnchoredObject
& AnchoredObj() { return maAnchoredDrawObj
; }
249 const SwFrame
* GetAnchorFrame() const;
250 SwFrame
* AnchorFrame();
251 void RemoveFromWriterLayout();
253 /// connection to drawing layer
254 void AddToDrawingPage(SwFrame
const& rAnchorFrame
);
255 void RemoveFromDrawingPage();
257 /** is 'virtual' drawing object connected to writer layout and
258 / to drawing layer. */
259 bool IsConnected() const;
261 virtual void NbcSetAnchorPos(const Point
& rPnt
) override
;
263 /// All overridden methods which need to use the offset
264 virtual void RecalcBoundRect() override
;
265 virtual ::basegfx::B2DPolyPolygon
TakeXorPoly() const override
;
266 virtual ::basegfx::B2DPolyPolygon
TakeContour() const override
;
267 virtual void AddToHdlList(SdrHdlList
& rHdlList
) const override
;
268 virtual void NbcMove(const Size
& rSiz
) override
;
269 virtual void NbcResize(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
) override
;
270 virtual void NbcRotate(const Point
& rRef
, Degree100 nAngle
, double sn
, double cs
) override
;
271 virtual void NbcMirror(const Point
& rRef1
, const Point
& rRef2
) override
;
272 virtual void NbcShear(const Point
& rRef
, Degree100 nAngle
, double tn
, bool bVShear
) override
;
273 virtual void Move(const Size
& rSiz
) override
;
274 virtual void Resize(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
, bool bUnsetRelative
= true) override
;
275 virtual void Rotate(const Point
& rRef
, Degree100 nAngle
, double sn
, double cs
) override
;
276 virtual void Mirror(const Point
& rRef1
, const Point
& rRef2
) override
;
277 virtual void Shear(const Point
& rRef
, Degree100 nAngle
, double tn
, bool bVShear
) override
;
278 virtual void RecalcSnapRect() override
;
279 virtual const tools::Rectangle
& GetSnapRect() const override
;
280 virtual void SetSnapRect(const tools::Rectangle
& rRect
) override
;
281 virtual void NbcSetSnapRect(const tools::Rectangle
& rRect
) override
;
282 virtual const tools::Rectangle
& GetLogicRect() const override
;
283 virtual void SetLogicRect(const tools::Rectangle
& rRect
) override
;
284 virtual void NbcSetLogicRect(const tools::Rectangle
& rRect
) override
;
285 virtual Point
GetSnapPoint(sal_uInt32 i
) const override
;
286 virtual Point
GetPoint(sal_uInt32 i
) const override
;
287 virtual void NbcSetPoint(const Point
& rPnt
, sal_uInt32 i
) override
;
289 virtual bool HasTextEdit() const override
;
291 virtual SdrLayerID
GetLayer() const override
;
292 virtual void NbcSetLayer(SdrLayerID nLayer
) override
;
293 virtual void SetLayer(SdrLayerID nLayer
) override
;
295 virtual void SetBoundRectDirty() override
;
296 virtual const tools::Rectangle
& GetCurrentBoundRect() const override
;
297 virtual const tools::Rectangle
& GetLastBoundRect() const override
;
300 bool CheckControlLayer( const SdrObject
*pObj
);
302 /** ContactObject for connection of formats as representatives of draw objects
303 in SwClient and the objects themselves in Drawing (SDrObjUserCall). */
305 typedef std::unique_ptr
< SwDrawVirtObj
, SdrObjectFreeOp
> SwDrawVirtObjPtr
;
307 class SAL_DLLPUBLIC_RTTI SwDrawContact final
: public SwContact
310 /** anchored drawing object instance for the
311 'master' drawing object */
312 SwAnchoredDrawObject maAnchoredDrawObj
;
314 /** container for 'virtual' drawing object supporting drawing objects in headers/footers. */
315 std::vector
< SwDrawVirtObjPtr
> maDrawVirtObjs
;
317 /** boolean indicating set 'master' drawing
318 object has been cleared. */
319 bool mbMasterObjCleared
: 1;
321 /** internal flag to indicate that disconnect
322 from layout is in progress */
323 bool mbDisconnectInProgress
: 1;
325 /** Needed data for handling of nested <SdrObjUserCall> events in
326 method <Changed_(..)> */
327 bool mbUserCallActive
: 1;
328 /** event type, which is handled for <mpSdrObjHandledByCurrentUserCall>.
329 Note: value only valid, if <mbUserCallActive> is true. */
330 SdrUserCallType meEventTypeOfCurrentUserCall
;
332 friend class NestedUserCallHdl
;
335 void RemoveAllVirtObjs();
337 void InvalidateObjs_( const bool _bUpdateSortedObjsList
= false );
339 SwDrawContact( const SwDrawContact
& ) = delete;
340 SwDrawContact
& operator=( const SwDrawContact
& ) = delete;
342 virtual void SwClientNotify(const SwModify
&, const SfxHint
& rHint
) override
;
346 SwDrawContact( SwFrameFormat
*pToRegisterIn
, SdrObject
*pObj
);
347 virtual ~SwDrawContact() override
;
349 virtual const SwAnchoredObject
* GetAnchoredObj( const SdrObject
* _pSdrObj
) const override
;
350 virtual SwAnchoredObject
* GetAnchoredObj( SdrObject
* _pSdrObj
) override
;
352 virtual const SdrObject
* GetMaster() const override
353 { return const_cast<SwDrawContact
*>(this)->GetMaster(); };
354 virtual SdrObject
* GetMaster() override
;
356 const SwFrame
* GetAnchorFrame( const SdrObject
* _pDrawObj
= nullptr ) const;
357 SwFrame
* GetAnchorFrame( SdrObject
const * _pDrawObj
= nullptr );
359 const SwPageFrame
* GetPageFrame() const
361 return maAnchoredDrawObj
.GetPageFrame();
363 SwPageFrame
* GetPageFrame()
365 return maAnchoredDrawObj
.GetPageFrame();
368 SwPageFrame
* FindPage( const SwRect
&rRect
);
370 /** Inserts SdrObject in the arrays of the layout ((SwPageFrame and SwFrame).
371 The anchor is determined according to the attribute SwFormatAnchor.
372 If required the object gets unregistered with the old anchor. */
373 void ConnectToLayout( const SwFormatAnchor
*pAnch
= nullptr );
374 /** method to insert 'master' drawing object
376 void InsertMasterIntoDrawPage();
378 void DisconnectFromLayout( bool _bMoveMasterToInvisibleLayer
= true );
379 /** disconnect for a dedicated drawing object -
380 could be 'master' or 'virtual'. */
381 void DisconnectObjFromLayout( SdrObject
* _pDrawObj
);
382 /** method to remove 'master' drawing object
384 To be used by the undo for delete of object. Call it after method
385 <DisconnectFromLayout( bool = true )> is already performed.
386 Note: <DisconnectFromLayout( bool )> no longer removes the 'master'
387 drawing object from drawing page. */
388 void RemoveMasterFromDrawPage();
390 /** get drawing object ('master' or 'virtual')
392 SdrObject
* GetDrawObjectByAnchorFrame( const SwFrame
& _rAnchorFrame
);
394 /// Virtual methods of SdrObjUserCall.
395 virtual void Changed(const SdrObject
& rObj
, SdrUserCallType eType
, const tools::Rectangle
& rOldBoundRect
) override
;
397 /** Used by Changed() and by UndoDraw.
398 Notifies paragraphs that have to get out of the way. */
399 void Changed_(const SdrObject
& rObj
, SdrUserCallType eType
, const tools::Rectangle
* pOldBoundRect
);
401 /// Moves all SW-connections to new Master)
402 void ChangeMasterObject( SdrObject
*pNewMaster
);
404 SwDrawVirtObj
* AddVirtObj(SwFrame
const& rAnchorFrame
);
406 void NotifyBackgroundOfAllVirtObjs( const tools::Rectangle
* pOldBoundRect
);
408 /** get data collection of anchored objects, handled by with contact */
410 static void GetTextObjectsFromFormat( std::list
<SdrTextObj
*>&, SwDoc
& );
411 virtual void GetAnchoredObjs( std::vector
<SwAnchoredObject
*>& _roAnchoredObjs
) const override
;
416 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */