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 SwFrmFmt;
34 : class SwFlyFrmFmt;
35 : class SwFlyFrm;
36 : class SwFrm;
37 : class SwPageFrm;
38 : class SwVirtFlyDrawObj;
39 : class SwFmtAnchor;
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 SwFrmFmt *FindFrmFmt( SdrObject *pObj );
53 4224 : inline const SwFrmFmt *FindFrmFmt( const SdrObject *pObj )
54 4224 : { return ::FindFrmFmt( (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( SwFrmFmt *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 1855576 : SwFrmFmt *GetFmt(){ return (SwFrmFmt*)GetRegisteredIn(); }
119 216363 : const SwFrmFmt *GetFmt() const
120 216363 : { return (const SwFrmFmt*)GetRegisteredIn(); }
121 :
122 8 : 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 212927 : const SwFmtAnchor& GetAnchorFmt() const
149 : {
150 : assert( GetFmt() );
151 :
152 212927 : return GetFmt()->GetAnchor();
153 : }
154 :
155 206943 : RndStdIds GetAnchorId() const { return GetAnchorFmt().GetAnchorId(); }
156 965 : bool ObjAnchoredAtPage() const { return GetAnchorId() == FLY_AT_PAGE; }
157 6091 : bool ObjAnchoredAtFly() const { return GetAnchorId() == FLY_AT_FLY; }
158 4374 : bool ObjAnchoredAtPara() const { return GetAnchorId() == FLY_AT_PARA; }
159 1122 : bool ObjAnchoredAtChar() const { return GetAnchorId() == FLY_AT_CHAR; }
160 73885 : bool ObjAnchoredAsChar() const { return GetAnchorId() == FLY_AS_CHAR; }
161 :
162 5984 : const SwPosition& GetCntntAnchor() const
163 : {
164 : assert( GetAnchorFmt().GetCntntAnchor() );
165 5984 : return *(GetAnchorFmt().GetCntntAnchor());
166 : }
167 :
168 : const SwIndex& GetCntntAnchorIndex() 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( SwFlyFrmFmt* 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 : using SdrVirtObj::GetPlusHdl;
238 :
239 : protected:
240 : /** AW: Need own sdr::contact::ViewContact since AnchorPos from parent is
241 : not used but something own (top left of new SnapRect minus top left
242 : of original SnapRect) */
243 : virtual sdr::contact::ViewContact* CreateObjectSpecificViewContact() SAL_OVERRIDE;
244 :
245 : public:
246 : TYPEINFO_OVERRIDE();
247 :
248 : SwDrawVirtObj( SdrObject& _rNewObj,
249 : SwDrawContact& _rDrawContact );
250 : virtual ~SwDrawVirtObj();
251 :
252 : /// access to offset
253 : virtual const Point GetOffset() const SAL_OVERRIDE;
254 :
255 : virtual SwDrawVirtObj* Clone() const SAL_OVERRIDE;
256 : SwDrawVirtObj& operator= (const SwDrawVirtObj& rObj);
257 :
258 : /// connection to writer layout
259 3472 : const SwAnchoredObject& GetAnchoredObj() const { return maAnchoredDrawObj; }
260 2290 : SwAnchoredObject& AnchoredObj() { return maAnchoredDrawObj; }
261 : const SwFrm* GetAnchorFrm() const;
262 : SwFrm* AnchorFrm();
263 : void RemoveFromWriterLayout();
264 :
265 : /// connection to drawing layer
266 : void AddToDrawingPage();
267 : void RemoveFromDrawingPage();
268 :
269 : /** is 'virtual' drawing object connected to writer layout and
270 : / to drawing layer. */
271 : bool IsConnected() const;
272 :
273 : virtual void NbcSetAnchorPos(const Point& rPnt) SAL_OVERRIDE;
274 :
275 : /// All overloaded methods which need to use the offset
276 : virtual void RecalcBoundRect() SAL_OVERRIDE;
277 : virtual ::basegfx::B2DPolyPolygon TakeXorPoly() const SAL_OVERRIDE;
278 : virtual ::basegfx::B2DPolyPolygon TakeContour() const SAL_OVERRIDE;
279 : virtual SdrHdl* GetHdl(sal_uInt32 nHdlNum) const SAL_OVERRIDE;
280 : virtual SdrHdl* GetPlusHdl(const SdrHdl& rHdl, sal_uInt16 nPlNum) const;
281 : virtual void NbcMove(const Size& rSiz) SAL_OVERRIDE;
282 : virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact) SAL_OVERRIDE;
283 : virtual void NbcRotate(const Point& rRef, long nWink, double sn, double cs) SAL_OVERRIDE;
284 : virtual void NbcMirror(const Point& rRef1, const Point& rRef2) SAL_OVERRIDE;
285 : virtual void NbcShear(const Point& rRef, long nWink, double tn, bool bVShear) SAL_OVERRIDE;
286 : virtual void Move(const Size& rSiz) SAL_OVERRIDE;
287 : virtual void Resize(const Point& rRef, const Fraction& xFact, const Fraction& yFact, bool bUnsetRelative = true) SAL_OVERRIDE;
288 : virtual void Rotate(const Point& rRef, long nWink, double sn, double cs) SAL_OVERRIDE;
289 : virtual void Mirror(const Point& rRef1, const Point& rRef2) SAL_OVERRIDE;
290 : virtual void Shear(const Point& rRef, long nWink, double tn, bool bVShear) SAL_OVERRIDE;
291 : virtual void RecalcSnapRect() SAL_OVERRIDE;
292 : virtual const Rectangle& GetSnapRect() const SAL_OVERRIDE;
293 : virtual void SetSnapRect(const Rectangle& rRect) SAL_OVERRIDE;
294 : virtual void NbcSetSnapRect(const Rectangle& rRect) SAL_OVERRIDE;
295 : virtual const Rectangle& GetLogicRect() const SAL_OVERRIDE;
296 : virtual void SetLogicRect(const Rectangle& rRect) SAL_OVERRIDE;
297 : virtual void NbcSetLogicRect(const Rectangle& rRect) SAL_OVERRIDE;
298 : virtual Point GetSnapPoint(sal_uInt32 i) const SAL_OVERRIDE;
299 : virtual Point GetPoint(sal_uInt32 i) const SAL_OVERRIDE;
300 : virtual void NbcSetPoint(const Point& rPnt, sal_uInt32 i) SAL_OVERRIDE;
301 :
302 : virtual bool HasTextEdit() const SAL_OVERRIDE;
303 :
304 : virtual SdrLayerID GetLayer() const SAL_OVERRIDE;
305 : virtual void NbcSetLayer(SdrLayerID nLayer) SAL_OVERRIDE;
306 : virtual void SetLayer(SdrLayerID nLayer) SAL_OVERRIDE;
307 :
308 : /// FullDrag support
309 : virtual bool supportsFullDrag() const SAL_OVERRIDE;
310 : virtual SdrObject* getFullDragClone() const SAL_OVERRIDE;
311 :
312 : virtual void SetBoundRectDirty() SAL_OVERRIDE;
313 : virtual const Rectangle& GetCurrentBoundRect() const SAL_OVERRIDE;
314 : virtual const Rectangle& GetLastBoundRect() const SAL_OVERRIDE;
315 : };
316 :
317 : bool CheckControlLayer( const SdrObject *pObj );
318 :
319 : /** ContactObject for connection of formats as representatives of draw objects
320 : in SwClient and the objects themselves in Drawing (SDrObjUserCall). */
321 : class NestedUserCallHdl;
322 :
323 : class SwDrawContact : public SwContact
324 : {
325 : private:
326 : /** anchored drawing object instance for the
327 : 'master' drawing object */
328 : SwAnchoredDrawObject maAnchoredDrawObj;
329 :
330 : /** data structure for collecting 'virtual'
331 : drawing object supporting drawing objects in headers/footers. */
332 : std::list<SwDrawVirtObj*> maDrawVirtObjs;
333 :
334 : /** boolean indicating set 'master' drawing
335 : object has been cleared. */
336 : bool mbMasterObjCleared : 1;
337 :
338 : /** internal flag to indicate that disconnect
339 : from layout is in progress */
340 : bool mbDisconnectInProgress : 1;
341 :
342 : /** Needed data for handling of nested <SdrObjUserCall> events in
343 : method <_Changed(..)> */
344 : bool mbUserCallActive : 1;
345 : /** event type, which is handled for <mpSdrObjHandledByCurrentUserCall>.
346 : Note: value only valid, if <mbUserCallActive> is sal_True. */
347 : SdrUserCallType meEventTypeOfCurrentUserCall;
348 :
349 : friend class NestedUserCallHdl;
350 :
351 : /** unary function used by <list> iterator to find a disconnected 'virtual'
352 : drawing object */
353 : struct UsedOrUnusedVirtObjPred
354 : {
355 : bool mbUsedPred;
356 3856 : UsedOrUnusedVirtObjPred( bool _bUsed ) : mbUsedPred( _bUsed ) {};
357 9554 : bool operator() ( const SwDrawVirtObj* _pDrawVirtObj )
358 : {
359 9554 : if ( mbUsedPred )
360 : {
361 2614 : return _pDrawVirtObj->IsConnected();
362 : }
363 : else
364 : {
365 6940 : return !_pDrawVirtObj->IsConnected();
366 : }
367 : }
368 : };
369 :
370 : /** unary function used by <list> iterator to find a 'virtual' drawing
371 : object anchored at a given frame */
372 : struct VirtObjAnchoredAtFrmPred
373 : {
374 : const SwFrm* mpAnchorFrm;
375 : VirtObjAnchoredAtFrmPred( const SwFrm& _rAnchorFrm );
376 : bool operator() ( const SwDrawVirtObj* _pDrawVirtObj );
377 : };
378 :
379 : /// method for adding/removing 'virtual' drawing object.
380 : SwDrawVirtObj* CreateVirtObj();
381 : void DestroyVirtObj( SwDrawVirtObj* pVirtObj );
382 : void RemoveAllVirtObjs();
383 :
384 : void _InvalidateObjs( const bool _bUpdateSortedObjsList = false );
385 :
386 : /// no copy-constructor and no assignment operator
387 : SwDrawContact( const SwDrawContact& );
388 : SwDrawContact& operator=( const SwDrawContact& );
389 :
390 : protected:
391 : /// virtuelle Methoden von SwClient
392 : virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) SAL_OVERRIDE;
393 :
394 : public:
395 : TYPEINFO_OVERRIDE();
396 :
397 : SwDrawContact( SwFrmFmt *pToRegisterIn, SdrObject *pObj );
398 : virtual ~SwDrawContact();
399 :
400 : virtual const SwAnchoredObject* GetAnchoredObj( const SdrObject* _pSdrObj ) const SAL_OVERRIDE;
401 : virtual SwAnchoredObject* GetAnchoredObj( SdrObject* _pSdrObj ) SAL_OVERRIDE;
402 :
403 : virtual const SdrObject* GetMaster() const SAL_OVERRIDE;
404 : virtual SdrObject* GetMaster() SAL_OVERRIDE;
405 : virtual void SetMaster( SdrObject* _pNewMaster ) SAL_OVERRIDE;
406 :
407 : const SwFrm* GetAnchorFrm( const SdrObject* _pDrawObj = 0L ) const;
408 : SwFrm* GetAnchorFrm( SdrObject* _pDrawObj = 0L );
409 :
410 : inline const SwPageFrm* GetPageFrm() const
411 : {
412 : return maAnchoredDrawObj.GetPageFrm();
413 : }
414 4272 : inline SwPageFrm* GetPageFrm()
415 : {
416 4272 : return maAnchoredDrawObj.GetPageFrm();
417 : }
418 0 : void SetPageFrm( SwPageFrm* _pNewPageFrm )
419 : {
420 0 : return maAnchoredDrawObj.SetPageFrm( _pNewPageFrm );
421 : }
422 : void ChkPage();
423 : SwPageFrm* FindPage( const SwRect &rRect );
424 :
425 : /** Inserts SdrObject in the arrays of the layout ((SwPageFrm and SwFrm).
426 : The anchor is determined according to the attribute SwFmtAnchor.
427 : If required the object gets unregistered with the old anchor. */
428 : void ConnectToLayout( const SwFmtAnchor *pAnch = 0 );
429 : /** method to insert 'master' drawing object
430 : into drawing page */
431 : void InsertMasterIntoDrawPage();
432 :
433 : void DisconnectFromLayout( bool _bMoveMasterToInvisibleLayer = true );
434 : /** disconnect for a dedicated drawing object -
435 : could be 'master' or 'virtual'. */
436 : void DisconnectObjFromLayout( SdrObject* _pDrawObj );
437 : /** method to remove 'master' drawing object
438 : from drawing page.
439 : To be used by the undo for delete of object. Call it after method
440 : <DisconnectFromLayout( bool = true )> is already performed.
441 : Note: <DisconnectFromLayout( bool )> no longer removes the 'master'
442 : drawing object from drawing page. */
443 : void RemoveMasterFromDrawPage();
444 :
445 : /** get drawing object ('master' or 'virtual')
446 : by frame. */
447 : SdrObject* GetDrawObjectByAnchorFrm( const SwFrm& _rAnchorFrm );
448 :
449 : /// Virtual methods of SdrObjUserCall.
450 : virtual void Changed(const SdrObject& rObj, SdrUserCallType eType, const Rectangle& rOldBoundRect) SAL_OVERRIDE;
451 :
452 : /** Used by Changed() and by UndoDraw.
453 : Notifies paragraphs that have to get out of the way. */
454 : void _Changed(const SdrObject& rObj, SdrUserCallType eType, const Rectangle* pOldBoundRect);
455 :
456 : /// Moves all SW-connections to new Master)
457 : void ChangeMasterObject( SdrObject *pNewMaster );
458 :
459 : SwDrawVirtObj* AddVirtObj();
460 :
461 : void NotifyBackgrdOfAllVirtObjs( const Rectangle* pOldBoundRect );
462 :
463 : /** get data collection of anchored objects, handled by with contact
464 : */
465 :
466 : static void GetTextObjectsFromFmt( std::list<SdrTextObj*>&, SwDoc* );
467 : virtual void GetAnchoredObjs( std::list<SwAnchoredObject*>& _roAnchoredObjs ) const SAL_OVERRIDE;
468 : };
469 :
470 : #endif
471 :
472 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|