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