Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / dcontact.hxx
blobe9eb91a6b3881df1cb8838140b8bc3a236f5d9a8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <swtypes.hxx>
25 #include <fmtanchr.hxx>
26 #include <frmfmt.hxx>
27 #include <list>
28 #include <memory>
30 #include "calbck.hxx"
31 #include <anchoreddrawobject.hxx>
33 class SfxPoolItem;
34 class SwFrameFormat;
35 class SwFlyFrameFormat;
36 class SwFlyFrame;
37 class SwFrame;
38 class SwPageFrame;
39 class SwVirtFlyDrawObj;
40 class SwFormatAnchor;
41 class SwFlyDrawObj;
42 class SwRect;
43 class SwDrawContact;
44 struct SwPosition;
45 class SwIndex;
46 class SdrTextObj;
48 /** The other way round: Search format for given object.
49 If object is a SwVirtFlyDrawObj the format will be obtained from it.
50 If not it is a simple DrawObject. It has a UserCall which
51 is client of the format we are looking for.
52 Implementation in dcontact.cxx. */
53 SW_DLLPUBLIC SwFrameFormat *FindFrameFormat( SdrObject *pObj );
54 inline const SwFrameFormat *FindFrameFormat( const SdrObject *pObj )
55 { return ::FindFrameFormat( const_cast<SdrObject*>(pObj) ); }
56 bool HasWrap( const SdrObject* pObj );
58 void setContextWritingMode( SdrObject* pObj, SwFrame* pAnchor );
60 /// @return BoundRect plus distance.
61 SwRect GetBoundRectOfAnchoredObj( const SdrObject* pObj );
63 /// @return UserCall of goup object (if applicable).
64 SwContact* GetUserCall( const SdrObject* );
66 /// @return TRUE if the SrdObject is a Marquee object.
67 bool IsMarqueeTextObj( const SdrObject& rObj );
69 /// Base class for the following contact objects (frame + draw objects).
70 class SW_DLLPUBLIC SwContact : public SdrObjUserCall, public SwClient
72 /** boolean, indicating destruction of contact object
73 important note: boolean has to be set at the beginning of each destructor
74 in the subclasses using method <SetInDTOR()>. */
75 bool mbInDTOR;
77 /** method to move object to visible/invisible layer
79 Implementation for the public method <MoveObjToVisibleLayer(..)>
80 and <MoveObjToInvisibleLayer(..)>
81 If object is in invisble respectively visible layer, its moved to
82 the corresponding visible respectively invisible layers.
83 For group object the members are individually moved to the corresponding
84 layer, because <SdrObjGroup::GetLayer()> does return 0, if members
85 aren't on the same layer as the group object, and
86 <SdrObjGroup::SetLayer(..)|NbcSetLayer(..)> sets also the layer of
87 the members.
89 @author OD
91 @param _bToVisible
92 input parameter - boolean indicating, if object has to be moved to
93 visible (== true) or invisible (== false) layer.
95 @param _pDrawObj
96 input parameter, which will be changed - drawing object, which will
97 change its layer.
99 void MoveObjToLayer( const bool _bToVisible,
100 SdrObject* _pDrawObj );
102 protected:
103 void SetInDTOR();
104 virtual void SwClientNotify(const SwModify&, const SfxHint& rHint) override;
106 public:
108 /// For reader. Only the connection is created.
109 SwContact( SwFrameFormat *pToRegisterIn );
110 virtual ~SwContact() override;
112 virtual const SwAnchoredObject* GetAnchoredObj( const SdrObject* _pSdrObj ) const = 0;
113 virtual SwAnchoredObject* GetAnchoredObj( SdrObject* _pSdrObj ) = 0;
115 virtual const SdrObject *GetMaster() const = 0;
116 virtual SdrObject *GetMaster() = 0;
118 SwFrameFormat *GetFormat() { return static_cast<SwFrameFormat*>(GetRegisteredIn()); }
119 const SwFrameFormat *GetFormat() const
120 { return static_cast<const SwFrameFormat*>(GetRegisteredIn()); }
122 bool IsInDTOR() const { return mbInDTOR;}
124 /** method to move drawing object to corresponding visible layer
126 uses method <MoveObjToLayer(..)>
128 @author OD
130 @param _pDrawObj
131 drawing object, which will be moved to the visible layer
133 virtual void MoveObjToVisibleLayer( SdrObject* _pDrawObj );
135 /** method to move drawing object to corresponding invisible layer
137 uses method <MoveObjToLayer(..)>
139 @author OD
141 @param _pDrawObj
142 drawing object, which will be moved to the visible layer
144 virtual void MoveObjToInvisibleLayer( SdrObject* _pDrawObj );
146 /** some virtual helper methods for information
147 about the object (Writer fly frame resp. drawing object) */
148 const SwFormatAnchor& GetAnchorFormat() const
150 assert( GetFormat() );
152 return GetFormat()->GetAnchor();
155 RndStdIds GetAnchorId() const { return GetAnchorFormat().GetAnchorId(); }
156 bool ObjAnchoredAtPage() const { return GetAnchorId() == RndStdIds::FLY_AT_PAGE; }
157 bool ObjAnchoredAtFly() const { return GetAnchorId() == RndStdIds::FLY_AT_FLY; }
158 bool ObjAnchoredAtPara() const { return GetAnchorId() == RndStdIds::FLY_AT_PARA; }
159 bool ObjAnchoredAtChar() const { return GetAnchorId() == RndStdIds::FLY_AT_CHAR; }
160 bool ObjAnchoredAsChar() const { return GetAnchorId() == RndStdIds::FLY_AS_CHAR; }
162 const SwPosition& GetContentAnchor() const
164 assert( GetAnchorFormat().GetContentAnchor() );
165 return *(GetAnchorFormat().GetContentAnchor());
168 const SwIndex& GetContentAnchorIndex() const;
170 /** get data collection of anchored objects, handled by with contact
173 virtual void GetAnchoredObjs( std::list<SwAnchoredObject*>& _roAnchoredObjs ) const = 0;
175 /** get minimum order number of anchored objects handled by with contact
178 sal_uInt32 GetMinOrdNum() const;
180 /** get maximum order number of anchored objects handled by with contact
183 sal_uInt32 GetMaxOrdNum() const;
186 /** ContactObject for connection between frames (or their formats respectively)
187 in SwClient and the drawobjects of Drawing (DsrObjUserCall). */
189 class SW_DLLPUBLIC SwFlyDrawContact final : public SwContact
191 private:
192 std::unique_ptr<SwFlyDrawObj> mpMasterObj;
193 void SwClientNotify(const SwModify&, const SfxHint& rHint) override;
194 sal_uInt32 GetOrdNumForNewRef(const SwFlyFrame* pFly);
196 public:
198 /// Creates DrawObject and registers it with the Model.
199 SwFlyDrawContact( SwFlyFrameFormat* pToRegisterIn );
200 static SwVirtFlyDrawObj* CreateNewRef(SwFlyFrame* pFly, SwFlyFrameFormat* pFormat);
201 virtual ~SwFlyDrawContact() override;
203 virtual const SwAnchoredObject* GetAnchoredObj( const SdrObject* _pSdrObj ) const override;
204 virtual SwAnchoredObject* GetAnchoredObj( SdrObject* _pSdrObj ) override;
206 virtual const SdrObject* GetMaster() const override
207 { return const_cast<SwFlyDrawContact*>(this)->GetMaster(); };
208 virtual SdrObject* GetMaster() override;
210 /** override methods to control Writer fly frames,
211 which are linked, and to assure that all objects anchored at/inside the
212 Writer fly frame are also made visible/invisible. */
213 virtual void MoveObjToVisibleLayer( SdrObject* _pDrawObj ) override;
214 virtual void MoveObjToInvisibleLayer( SdrObject* _pDrawObj ) override;
216 /** get data collection of anchored objects handled by with contact
218 virtual void GetAnchoredObjs( std::list<SwAnchoredObject*>& _roAnchoredObjs ) const override;
221 /** new class for re-direct methods calls at a 'virtual'
222 drawing object to its referenced object. */
223 class SwDrawVirtObj : public SdrVirtObj
225 private:
226 // data for connection to writer layout
227 /** anchored drawing object instance for the
228 'virtual' drawing object */
229 SwAnchoredDrawObject maAnchoredDrawObj;
231 /** writer-drawing contact object the 'virtual' drawing object is controlled by.
232 This object is also the <UserCall> of the drawing object, if it's
233 inserted into the drawing layer. */
234 SwDrawContact& mrDrawContact;
236 protected:
237 /** AW: Need own sdr::contact::ViewContact since AnchorPos from parent is
238 not used but something own (top left of new SnapRect minus top left
239 of original SnapRect) */
240 virtual sdr::contact::ViewContact* CreateObjectSpecificViewContact() override;
242 public:
244 SwDrawVirtObj( SdrObject& _rNewObj,
245 SwDrawContact& _rDrawContact );
246 virtual ~SwDrawVirtObj() override;
248 /// access to offset
249 virtual const Point GetOffset() const override;
251 virtual SwDrawVirtObj* Clone() const override;
252 SwDrawVirtObj& operator= (const SwDrawVirtObj& rObj);
254 /// connection to writer layout
255 const SwAnchoredObject& GetAnchoredObj() const { return maAnchoredDrawObj; }
256 SwAnchoredObject& AnchoredObj() { return maAnchoredDrawObj; }
257 const SwFrame* GetAnchorFrame() const;
258 SwFrame* AnchorFrame();
259 void RemoveFromWriterLayout();
261 /// connection to drawing layer
262 void AddToDrawingPage();
263 void RemoveFromDrawingPage();
265 /** is 'virtual' drawing object connected to writer layout and
266 / to drawing layer. */
267 bool IsConnected() const;
269 virtual void NbcSetAnchorPos(const Point& rPnt) override;
271 /// All overridden methods which need to use the offset
272 virtual void RecalcBoundRect() override;
273 virtual ::basegfx::B2DPolyPolygon TakeXorPoly() const override;
274 virtual ::basegfx::B2DPolyPolygon TakeContour() const override;
275 virtual SdrHdl* GetHdl(sal_uInt32 nHdlNum) const override;
276 virtual void NbcMove(const Size& rSiz) override;
277 virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact) override;
278 virtual void NbcRotate(const Point& rRef, long nAngle, double sn, double cs) override;
279 virtual void NbcMirror(const Point& rRef1, const Point& rRef2) override;
280 virtual void NbcShear(const Point& rRef, long nAngle, double tn, bool bVShear) override;
281 virtual void Move(const Size& rSiz) override;
282 virtual void Resize(const Point& rRef, const Fraction& xFact, const Fraction& yFact, bool bUnsetRelative = true) override;
283 virtual void Rotate(const Point& rRef, long nAngle, double sn, double cs) override;
284 virtual void Mirror(const Point& rRef1, const Point& rRef2) override;
285 virtual void Shear(const Point& rRef, long nAngle, double tn, bool bVShear) override;
286 virtual void RecalcSnapRect() override;
287 virtual const tools::Rectangle& GetSnapRect() const override;
288 virtual void SetSnapRect(const tools::Rectangle& rRect) override;
289 virtual void NbcSetSnapRect(const tools::Rectangle& rRect) override;
290 virtual const tools::Rectangle& GetLogicRect() const override;
291 virtual void SetLogicRect(const tools::Rectangle& rRect) override;
292 virtual void NbcSetLogicRect(const tools::Rectangle& rRect) override;
293 virtual Point GetSnapPoint(sal_uInt32 i) const override;
294 virtual Point GetPoint(sal_uInt32 i) const override;
295 virtual void NbcSetPoint(const Point& rPnt, sal_uInt32 i) override;
297 virtual bool HasTextEdit() const override;
299 virtual SdrLayerID GetLayer() const override;
300 virtual void NbcSetLayer(SdrLayerID nLayer) override;
301 virtual void SetLayer(SdrLayerID nLayer) override;
303 virtual void SetBoundRectDirty() override;
304 virtual const tools::Rectangle& GetCurrentBoundRect() const override;
305 virtual const tools::Rectangle& GetLastBoundRect() const override;
308 bool CheckControlLayer( const SdrObject *pObj );
310 /** ContactObject for connection of formats as representatives of draw objects
311 in SwClient and the objects themselves in Drawing (SDrObjUserCall). */
312 class NestedUserCallHdl;
314 class SwDrawContact final : public SwContact
316 private:
317 /** anchored drawing object instance for the
318 'master' drawing object */
319 SwAnchoredDrawObject maAnchoredDrawObj;
321 /** container for 'virtual' drawing object supporting drawing objects in headers/footers. */
322 std::vector<std::unique_ptr<SwDrawVirtObj>> maDrawVirtObjs;
324 /** boolean indicating set 'master' drawing
325 object has been cleared. */
326 bool mbMasterObjCleared : 1;
328 /** internal flag to indicate that disconnect
329 from layout is in progress */
330 bool mbDisconnectInProgress : 1;
332 /** Needed data for handling of nested <SdrObjUserCall> events in
333 method <Changed_(..)> */
334 bool mbUserCallActive : 1;
335 /** event type, which is handled for <mpSdrObjHandledByCurrentUserCall>.
336 Note: value only valid, if <mbUserCallActive> is true. */
337 SdrUserCallType meEventTypeOfCurrentUserCall;
339 friend class NestedUserCallHdl;
342 void RemoveAllVirtObjs();
344 void InvalidateObjs_( const bool _bUpdateSortedObjsList = false );
346 SwDrawContact( const SwDrawContact& ) = delete;
347 SwDrawContact& operator=( const SwDrawContact& ) = delete;
349 virtual void SwClientNotify(const SwModify&, const SfxHint& rHint) override;
351 public:
353 SwDrawContact( SwFrameFormat *pToRegisterIn, SdrObject *pObj );
354 virtual ~SwDrawContact() override;
356 virtual const SwAnchoredObject* GetAnchoredObj( const SdrObject* _pSdrObj ) const override;
357 virtual SwAnchoredObject* GetAnchoredObj( SdrObject* _pSdrObj ) override;
359 virtual const SdrObject* GetMaster() const override
360 { return const_cast<SwDrawContact*>(this)->GetMaster(); };
361 virtual SdrObject* GetMaster() override;
363 const SwFrame* GetAnchorFrame( const SdrObject* _pDrawObj = nullptr ) const;
364 SwFrame* GetAnchorFrame( SdrObject* _pDrawObj = nullptr );
366 const SwPageFrame* GetPageFrame() const
368 return maAnchoredDrawObj.GetPageFrame();
370 SwPageFrame* GetPageFrame()
372 return maAnchoredDrawObj.GetPageFrame();
374 void ChkPage();
375 SwPageFrame* FindPage( const SwRect &rRect );
377 /** Inserts SdrObject in the arrays of the layout ((SwPageFrame and SwFrame).
378 The anchor is determined according to the attribute SwFormatAnchor.
379 If required the object gets unregistered with the old anchor. */
380 void ConnectToLayout( const SwFormatAnchor *pAnch = nullptr );
381 /** method to insert 'master' drawing object
382 into drawing page */
383 void InsertMasterIntoDrawPage();
385 void DisconnectFromLayout( bool _bMoveMasterToInvisibleLayer = true );
386 /** disconnect for a dedicated drawing object -
387 could be 'master' or 'virtual'. */
388 void DisconnectObjFromLayout( SdrObject* _pDrawObj );
389 /** method to remove 'master' drawing object
390 from drawing page.
391 To be used by the undo for delete of object. Call it after method
392 <DisconnectFromLayout( bool = true )> is already performed.
393 Note: <DisconnectFromLayout( bool )> no longer removes the 'master'
394 drawing object from drawing page. */
395 void RemoveMasterFromDrawPage();
397 /** get drawing object ('master' or 'virtual')
398 by frame. */
399 SdrObject* GetDrawObjectByAnchorFrame( const SwFrame& _rAnchorFrame );
401 /// Virtual methods of SdrObjUserCall.
402 virtual void Changed(const SdrObject& rObj, SdrUserCallType eType, const tools::Rectangle& rOldBoundRect) override;
404 /** Used by Changed() and by UndoDraw.
405 Notifies paragraphs that have to get out of the way. */
406 void Changed_(const SdrObject& rObj, SdrUserCallType eType, const tools::Rectangle* pOldBoundRect);
408 /// Moves all SW-connections to new Master)
409 void ChangeMasterObject( SdrObject *pNewMaster );
411 SwDrawVirtObj* AddVirtObj();
413 void NotifyBackgrdOfAllVirtObjs( const tools::Rectangle* pOldBoundRect );
415 /** get data collection of anchored objects, handled by with contact
418 static void GetTextObjectsFromFormat( std::list<SdrTextObj*>&, SwDoc* );
419 virtual void GetAnchoredObjs( std::list<SwAnchoredObject*>& _roAnchoredObjs ) const override;
422 #endif
424 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */