Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef INCLUDED_SW_INC_DCONTACT_HXX
20 : #define INCLUDED_SW_INC_DCONTACT_HXX
21 :
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 :
29 : #include "calbck.hxx"
30 : #include <anchoreddrawobject.hxx>
31 :
32 : class SfxPoolItem;
33 : class SwFrameFormat;
34 : class SwFlyFrameFormat;
35 : class SwFlyFrm;
36 : class SwFrm;
37 : class SwPageFrm;
38 : class SwVirtFlyDrawObj;
39 : class SwFormatAnchor;
40 : class SwFlyDrawObj;
41 : class SwRect;
42 : class SwDrawContact;
43 : struct SwPosition;
44 : class SwIndex;
45 : class SdrTextObj;
46 :
47 : /** The other way round: Search format for given object.
48 : If object is a SwVirtFlyDrawObj the format will be obtained from it.
49 : If not it is a simple DrawObject. It has a UserCall which
50 : is client of the format we are looking for.
51 : Implementation in dcontact.cxx. */
52 : SW_DLLPUBLIC SwFrameFormat *FindFrameFormat( SdrObject *pObj );
53 2318 : inline const SwFrameFormat *FindFrameFormat( const SdrObject *pObj )
54 2318 : { return ::FindFrameFormat( const_cast<SdrObject*>(pObj) ); }
55 : bool HasWrap( const SdrObject* pObj );
56 :
57 : void setContextWritingMode( SdrObject* pObj, SwFrm* pAnchor );
58 :
59 : /// @return BoundRect plus distance.
60 : SwRect GetBoundRectOfAnchoredObj( const SdrObject* pObj );
61 :
62 : /// @return UserCall of goup object (if applicable).
63 : SwContact* GetUserCall( const SdrObject* );
64 :
65 : /// @return TRUE if the SrdObject is a Marquee object.
66 : bool IsMarqueeTextObj( const SdrObject& rObj );
67 :
68 : /// Base class for the following contact objects (frame + draw objects).
69 : class SwContact : public SdrObjUserCall, public SwClient
70 : {
71 : /** boolean, indicating destruction of contact object
72 : important note: boolean has to be set at the beginning of each destructor
73 : in the subclasses using method <SetInDTOR()>. */
74 : bool mbInDTOR;
75 :
76 : /** method to move object to visible/invisible layer
77 :
78 : Implementation for the public method <MoveObjToVisibleLayer(..)>
79 : and <MoveObjToInvisibleLayer(..)>
80 : If object is in invisble respectively visible layer, its moved to
81 : the corresponding visible respectively invisible layers.
82 : For group object the members are individually moved to the corresponding
83 : layer, because <SdrObjGroup::GetLayer()> does return 0, if members
84 : aren't on the same layer as the group object, and
85 : <SdrObjGroup::SetLayer(..)|NbcSetLayer(..)> sets also the layer of
86 : the members.
87 :
88 : @author OD
89 :
90 : @param _bToVisible
91 : input parameter - boolean indicating, if object has to be moved to
92 : visible (== true) or invisible (== false) layer.
93 :
94 : @param _pDrawObj
95 : input parameter, which will be changed - drawing object, which will
96 : change its layer.
97 : */
98 : void _MoveObjToLayer( const bool _bToVisible,
99 : SdrObject* _pDrawObj );
100 :
101 : protected:
102 : void SetInDTOR();
103 :
104 : public:
105 : TYPEINFO_OVERRIDE();
106 :
107 : /// For reader. Only the connection is created.
108 : SwContact( SwFrameFormat *pToRegisterIn );
109 : virtual ~SwContact();
110 :
111 : virtual const SwAnchoredObject* GetAnchoredObj( const SdrObject* _pSdrObj ) const = 0;
112 : virtual SwAnchoredObject* GetAnchoredObj( SdrObject* _pSdrObj ) = 0;
113 :
114 : virtual const SdrObject *GetMaster() const = 0;
115 : virtual SdrObject *GetMaster() = 0;
116 : virtual void SetMaster( SdrObject* _pNewMaster ) = 0;
117 :
118 940022 : SwFrameFormat *GetFormat() { return static_cast<SwFrameFormat*>(GetRegisteredIn()); }
119 113897 : const SwFrameFormat *GetFormat() const
120 113897 : { return static_cast<const SwFrameFormat*>(GetRegisteredIn()); }
121 :
122 1 : bool IsInDTOR() const { return mbInDTOR;}
123 :
124 : /** method to move drawing object to corresponding visible layer
125 :
126 : uses method <_MoveObjToLayer(..)>
127 :
128 : @author OD
129 :
130 : @param _pDrawObj
131 : drawing object, which will be moved to the visible layer
132 : */
133 : virtual void MoveObjToVisibleLayer( SdrObject* _pDrawObj );
134 :
135 : /** method to move drawing object to corresponding invisible layer
136 :
137 : uses method <_MoveObjToLayer(..)>
138 :
139 : @author OD
140 :
141 : @param _pDrawObj
142 : drawing object, which will be moved to the visible layer
143 : */
144 : virtual void MoveObjToInvisibleLayer( SdrObject* _pDrawObj );
145 :
146 : /** some virtual helper methods for information
147 : about the object (Writer fly frame resp. drawing object) */
148 112094 : const SwFormatAnchor& GetAnchorFormat() const
149 : {
150 : assert( GetFormat() );
151 :
152 112094 : return GetFormat()->GetAnchor();
153 : }
154 :
155 108923 : RndStdIds GetAnchorId() const { return GetAnchorFormat().GetAnchorId(); }
156 585 : bool ObjAnchoredAtPage() const { return GetAnchorId() == FLY_AT_PAGE; }
157 3468 : bool ObjAnchoredAtFly() const { return GetAnchorId() == FLY_AT_FLY; }
158 2458 : bool ObjAnchoredAtPara() const { return GetAnchorId() == FLY_AT_PARA; }
159 617 : bool ObjAnchoredAtChar() const { return GetAnchorId() == FLY_AT_CHAR; }
160 40363 : bool ObjAnchoredAsChar() const { return GetAnchorId() == FLY_AS_CHAR; }
161 :
162 3171 : const SwPosition& GetContentAnchor() const
163 : {
164 : assert( GetAnchorFormat().GetContentAnchor() );
165 3171 : return *(GetAnchorFormat().GetContentAnchor());
166 : }
167 :
168 : const SwIndex& GetContentAnchorIndex() const;
169 :
170 : /** get data collection of anchored objects, handled by with contact
171 :
172 : */
173 : virtual void GetAnchoredObjs( std::list<SwAnchoredObject*>& _roAnchoredObjs ) const = 0;
174 :
175 : /** get minimum order number of anchored objects handled by with contact
176 :
177 : */
178 : sal_uInt32 GetMinOrdNum() const;
179 :
180 : /** get maximum order number of anchored objects handled by with contact
181 :
182 : */
183 : sal_uInt32 GetMaxOrdNum() const;
184 : };
185 :
186 : /** ContactObject for connection between frames (or their formats respectively)
187 : in SwClient and the drawobjects of Drawing (DsrObjUserCall). */
188 :
189 : class SW_DLLPUBLIC SwFlyDrawContact : public SwContact
190 : {
191 : private:
192 : SwFlyDrawObj* mpMasterObj;
193 :
194 : protected:
195 : virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) SAL_OVERRIDE;
196 :
197 : public:
198 : TYPEINFO_OVERRIDE();
199 :
200 : /// Creates DrawObject and registers it with the Model.
201 : SwFlyDrawContact( SwFlyFrameFormat* pToRegisterIn, SdrModel* pMod );
202 : virtual ~SwFlyDrawContact();
203 :
204 : virtual const SwAnchoredObject* GetAnchoredObj( const SdrObject* _pSdrObj ) const SAL_OVERRIDE;
205 : virtual SwAnchoredObject* GetAnchoredObj( SdrObject* _pSdrObj ) SAL_OVERRIDE;
206 :
207 : virtual const SdrObject* GetMaster() const SAL_OVERRIDE;
208 : virtual SdrObject* GetMaster() SAL_OVERRIDE;
209 : virtual void SetMaster( SdrObject* _pNewMaster ) SAL_OVERRIDE;
210 :
211 : /** override methods to control Writer fly frames,
212 : which are linked, and to assure that all objects anchored at/inside the
213 : Writer fly frame are also made visible/invisible. */
214 : virtual void MoveObjToVisibleLayer( SdrObject* _pDrawObj ) SAL_OVERRIDE;
215 : virtual void MoveObjToInvisibleLayer( SdrObject* _pDrawObj ) SAL_OVERRIDE;
216 :
217 : /** get data collection of anchored objects handled by with contact
218 : */
219 : virtual void GetAnchoredObjs( std::list<SwAnchoredObject*>& _roAnchoredObjs ) const SAL_OVERRIDE;
220 : };
221 :
222 : /** new class for re-direct methods calls at a 'virtual'
223 : drawing object to its referenced object. */
224 : class SwDrawVirtObj : public SdrVirtObj
225 : {
226 : private:
227 : // data for connection to writer layout
228 : /** anchored drawing object instance for the
229 : 'virtual' drawing object */
230 : SwAnchoredDrawObject maAnchoredDrawObj;
231 :
232 : /** writer-drawing contact object the 'virtual' drawing object is controlled by.
233 : This object is also the <UserCall> of the drawing object, if it's
234 : inserted into the drawing layer. */
235 : SwDrawContact& mrDrawContact;
236 :
237 : protected:
238 : /** AW: Need own sdr::contact::ViewContact since AnchorPos from parent is
239 : not used but something own (top left of new SnapRect minus top left
240 : of original SnapRect) */
241 : virtual sdr::contact::ViewContact* CreateObjectSpecificViewContact() SAL_OVERRIDE;
242 :
243 : public:
244 : TYPEINFO_OVERRIDE();
245 :
246 : SwDrawVirtObj( SdrObject& _rNewObj,
247 : SwDrawContact& _rDrawContact );
248 : virtual ~SwDrawVirtObj();
249 :
250 : /// access to offset
251 : virtual const Point GetOffset() const SAL_OVERRIDE;
252 :
253 : virtual SwDrawVirtObj* Clone() const SAL_OVERRIDE;
254 : SwDrawVirtObj& operator= (const SwDrawVirtObj& rObj);
255 :
256 : /// connection to writer layout
257 1794 : const SwAnchoredObject& GetAnchoredObj() const { return maAnchoredDrawObj; }
258 1235 : SwAnchoredObject& AnchoredObj() { return maAnchoredDrawObj; }
259 : const SwFrm* GetAnchorFrm() const;
260 : SwFrm* AnchorFrm();
261 : void RemoveFromWriterLayout();
262 :
263 : /// connection to drawing layer
264 : void AddToDrawingPage();
265 : void RemoveFromDrawingPage();
266 :
267 : /** is 'virtual' drawing object connected to writer layout and
268 : / to drawing layer. */
269 : bool IsConnected() const;
270 :
271 : virtual void NbcSetAnchorPos(const Point& rPnt) SAL_OVERRIDE;
272 :
273 : /// All overridden methods which need to use the offset
274 : virtual void RecalcBoundRect() SAL_OVERRIDE;
275 : virtual ::basegfx::B2DPolyPolygon TakeXorPoly() const SAL_OVERRIDE;
276 : virtual ::basegfx::B2DPolyPolygon TakeContour() const SAL_OVERRIDE;
277 : virtual SdrHdl* GetHdl(sal_uInt32 nHdlNum) const SAL_OVERRIDE;
278 : virtual void NbcMove(const Size& rSiz) SAL_OVERRIDE;
279 : virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact) SAL_OVERRIDE;
280 : virtual void NbcRotate(const Point& rRef, long nAngle, double sn, double cs) SAL_OVERRIDE;
281 : virtual void NbcMirror(const Point& rRef1, const Point& rRef2) SAL_OVERRIDE;
282 : virtual void NbcShear(const Point& rRef, long nAngle, double tn, bool bVShear) SAL_OVERRIDE;
283 : virtual void Move(const Size& rSiz) SAL_OVERRIDE;
284 : virtual void Resize(const Point& rRef, const Fraction& xFact, const Fraction& yFact, bool bUnsetRelative = true) SAL_OVERRIDE;
285 : virtual void Rotate(const Point& rRef, long nAngle, double sn, double cs) SAL_OVERRIDE;
286 : virtual void Mirror(const Point& rRef1, const Point& rRef2) SAL_OVERRIDE;
287 : virtual void Shear(const Point& rRef, long nAngle, double tn, bool bVShear) SAL_OVERRIDE;
288 : virtual void RecalcSnapRect() SAL_OVERRIDE;
289 : virtual const Rectangle& GetSnapRect() const SAL_OVERRIDE;
290 : virtual void SetSnapRect(const Rectangle& rRect) SAL_OVERRIDE;
291 : virtual void NbcSetSnapRect(const Rectangle& rRect) SAL_OVERRIDE;
292 : virtual const Rectangle& GetLogicRect() const SAL_OVERRIDE;
293 : virtual void SetLogicRect(const Rectangle& rRect) SAL_OVERRIDE;
294 : virtual void NbcSetLogicRect(const Rectangle& rRect) SAL_OVERRIDE;
295 : virtual Point GetSnapPoint(sal_uInt32 i) const SAL_OVERRIDE;
296 : virtual Point GetPoint(sal_uInt32 i) const SAL_OVERRIDE;
297 : virtual void NbcSetPoint(const Point& rPnt, sal_uInt32 i) SAL_OVERRIDE;
298 :
299 : virtual bool HasTextEdit() const SAL_OVERRIDE;
300 :
301 : virtual SdrLayerID GetLayer() const SAL_OVERRIDE;
302 : virtual void NbcSetLayer(SdrLayerID nLayer) SAL_OVERRIDE;
303 : virtual void SetLayer(SdrLayerID nLayer) SAL_OVERRIDE;
304 :
305 : /// FullDrag support
306 : virtual bool supportsFullDrag() const SAL_OVERRIDE;
307 : virtual SdrObject* getFullDragClone() const SAL_OVERRIDE;
308 :
309 : virtual void SetBoundRectDirty() SAL_OVERRIDE;
310 : virtual const Rectangle& GetCurrentBoundRect() const SAL_OVERRIDE;
311 : virtual const Rectangle& GetLastBoundRect() const SAL_OVERRIDE;
312 : };
313 :
314 : bool CheckControlLayer( const SdrObject *pObj );
315 :
316 : /** ContactObject for connection of formats as representatives of draw objects
317 : in SwClient and the objects themselves in Drawing (SDrObjUserCall). */
318 : class NestedUserCallHdl;
319 :
320 : class SwDrawContact : public SwContact
321 : {
322 : private:
323 : /** anchored drawing object instance for the
324 : 'master' drawing object */
325 : SwAnchoredDrawObject maAnchoredDrawObj;
326 :
327 : /** data structure for collecting 'virtual'
328 : drawing object supporting drawing objects in headers/footers. */
329 : std::list<SwDrawVirtObj*> maDrawVirtObjs;
330 :
331 : /** boolean indicating set 'master' drawing
332 : object has been cleared. */
333 : bool mbMasterObjCleared : 1;
334 :
335 : /** internal flag to indicate that disconnect
336 : from layout is in progress */
337 : bool mbDisconnectInProgress : 1;
338 :
339 : /** Needed data for handling of nested <SdrObjUserCall> events in
340 : method <_Changed(..)> */
341 : bool mbUserCallActive : 1;
342 : /** event type, which is handled for <mpSdrObjHandledByCurrentUserCall>.
343 : Note: value only valid, if <mbUserCallActive> is true. */
344 : SdrUserCallType meEventTypeOfCurrentUserCall;
345 :
346 : friend class NestedUserCallHdl;
347 :
348 : /** unary function used by <list> iterator to find a disconnected 'virtual'
349 : drawing object */
350 : struct UsedOrUnusedVirtObjPred
351 : {
352 : bool mbUsedPred;
353 2024 : UsedOrUnusedVirtObjPred( bool _bUsed ) : mbUsedPred( _bUsed ) {};
354 4834 : bool operator() ( const SwDrawVirtObj* _pDrawVirtObj )
355 : {
356 4834 : if ( mbUsedPred )
357 : {
358 1315 : return _pDrawVirtObj->IsConnected();
359 : }
360 : else
361 : {
362 3519 : return !_pDrawVirtObj->IsConnected();
363 : }
364 : }
365 : };
366 :
367 : /** unary function used by <list> iterator to find a 'virtual' drawing
368 : object anchored at a given frame */
369 : struct VirtObjAnchoredAtFrmPred
370 : {
371 : const SwFrm* mpAnchorFrm;
372 : VirtObjAnchoredAtFrmPred( const SwFrm& _rAnchorFrm );
373 : bool operator() ( const SwDrawVirtObj* _pDrawVirtObj );
374 : };
375 :
376 : /// method for adding/removing 'virtual' drawing object.
377 : SwDrawVirtObj* CreateVirtObj();
378 : static void DestroyVirtObj( SwDrawVirtObj* pVirtObj );
379 : void RemoveAllVirtObjs();
380 :
381 : void _InvalidateObjs( const bool _bUpdateSortedObjsList = false );
382 :
383 : SwDrawContact( const SwDrawContact& ) SAL_DELETED_FUNCTION;
384 : SwDrawContact& operator=( const SwDrawContact& ) SAL_DELETED_FUNCTION;
385 :
386 : protected:
387 : /// virtuelle Methoden von SwClient
388 : virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) SAL_OVERRIDE;
389 :
390 : public:
391 : TYPEINFO_OVERRIDE();
392 :
393 : SwDrawContact( SwFrameFormat *pToRegisterIn, SdrObject *pObj );
394 : virtual ~SwDrawContact();
395 :
396 : virtual const SwAnchoredObject* GetAnchoredObj( const SdrObject* _pSdrObj ) const SAL_OVERRIDE;
397 : virtual SwAnchoredObject* GetAnchoredObj( SdrObject* _pSdrObj ) SAL_OVERRIDE;
398 :
399 : virtual const SdrObject* GetMaster() const SAL_OVERRIDE;
400 : virtual SdrObject* GetMaster() SAL_OVERRIDE;
401 : virtual void SetMaster( SdrObject* _pNewMaster ) SAL_OVERRIDE;
402 :
403 : const SwFrm* GetAnchorFrm( const SdrObject* _pDrawObj = 0L ) const;
404 : SwFrm* GetAnchorFrm( SdrObject* _pDrawObj = 0L );
405 :
406 : inline const SwPageFrm* GetPageFrm() const
407 : {
408 : return maAnchoredDrawObj.GetPageFrm();
409 : }
410 2232 : inline SwPageFrm* GetPageFrm()
411 : {
412 2232 : return maAnchoredDrawObj.GetPageFrm();
413 : }
414 0 : void SetPageFrm( SwPageFrm* _pNewPageFrm )
415 : {
416 0 : return maAnchoredDrawObj.SetPageFrm( _pNewPageFrm );
417 : }
418 : void ChkPage();
419 : SwPageFrm* FindPage( const SwRect &rRect );
420 :
421 : /** Inserts SdrObject in the arrays of the layout ((SwPageFrm and SwFrm).
422 : The anchor is determined according to the attribute SwFormatAnchor.
423 : If required the object gets unregistered with the old anchor. */
424 : void ConnectToLayout( const SwFormatAnchor *pAnch = 0 );
425 : /** method to insert 'master' drawing object
426 : into drawing page */
427 : void InsertMasterIntoDrawPage();
428 :
429 : void DisconnectFromLayout( bool _bMoveMasterToInvisibleLayer = true );
430 : /** disconnect for a dedicated drawing object -
431 : could be 'master' or 'virtual'. */
432 : void DisconnectObjFromLayout( SdrObject* _pDrawObj );
433 : /** method to remove 'master' drawing object
434 : from drawing page.
435 : To be used by the undo for delete of object. Call it after method
436 : <DisconnectFromLayout( bool = true )> is already performed.
437 : Note: <DisconnectFromLayout( bool )> no longer removes the 'master'
438 : drawing object from drawing page. */
439 : void RemoveMasterFromDrawPage();
440 :
441 : /** get drawing object ('master' or 'virtual')
442 : by frame. */
443 : SdrObject* GetDrawObjectByAnchorFrm( const SwFrm& _rAnchorFrm );
444 :
445 : /// Virtual methods of SdrObjUserCall.
446 : virtual void Changed(const SdrObject& rObj, SdrUserCallType eType, const Rectangle& rOldBoundRect) SAL_OVERRIDE;
447 :
448 : /** Used by Changed() and by UndoDraw.
449 : Notifies paragraphs that have to get out of the way. */
450 : void _Changed(const SdrObject& rObj, SdrUserCallType eType, const Rectangle* pOldBoundRect);
451 :
452 : /// Moves all SW-connections to new Master)
453 : void ChangeMasterObject( SdrObject *pNewMaster );
454 :
455 : SwDrawVirtObj* AddVirtObj();
456 :
457 : void NotifyBackgrdOfAllVirtObjs( const Rectangle* pOldBoundRect );
458 :
459 : /** get data collection of anchored objects, handled by with contact
460 : */
461 :
462 : static void GetTextObjectsFromFormat( std::list<SdrTextObj*>&, SwDoc* );
463 : virtual void GetAnchoredObjs( std::list<SwAnchoredObject*>& _roAnchoredObjs ) const SAL_OVERRIDE;
464 : };
465 :
466 : #endif
467 :
468 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|