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