xref: /aoo42x/main/sw/inc/dcontact.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _DCONTACT_HXX
28 #define	_DCONTACT_HXX
29 
30 #include <svx/svdobj.hxx>
31 #include <svx/svdovirt.hxx>
32 #include <swtypes.hxx>
33 #include <fmtanchr.hxx>
34 #include <frmfmt.hxx>
35 #include <list>
36 
37 #include "calbck.hxx"
38 #include <anchoreddrawobject.hxx>
39 
40 class SfxPoolItem;
41 class SwFrmFmt;
42 class SwFlyFrmFmt;
43 class SwFlyFrm;
44 class SwFrm;
45 class SwPageFrm;
46 class SwVirtFlyDrawObj;
47 class SwFmtAnchor;
48 class SwFlyDrawObj;
49 class SwRect;
50 class SwDrawContact;
51 struct SwPosition;
52 class SwIndex;
53 class SdrTextObj;
54 
55 //Der Umgekehrte Weg: Sucht das Format zum angegebenen Objekt.
56 //Wenn das Object ein SwVirtFlyDrawObj ist so wird das Format von
57 //selbigem besorgt.
58 //Anderfalls ist es eben ein einfaches Zeichenobjekt. Diese hat einen
59 //UserCall und der ist Client vom gesuchten Format.
60 //Implementierung in dcontact.cxx
61 SW_DLLPUBLIC SwFrmFmt *FindFrmFmt( SdrObject *pObj );
62 inline const SwFrmFmt *FindFrmFmt( const SdrObject *pObj )
63 {	return ::FindFrmFmt( (SdrObject*)pObj ); }
64 sal_Bool HasWrap( const SdrObject* pObj );
65 
66 void setContextWritingMode( SdrObject* pObj, SwFrm* pAnchor );
67 
68 //Bei Aenderungen das Objekt aus dem ContourCache entfernen.
69 //Implementierung in TxtFly.Cxx
70 void ClrContourCache( const SdrObject *pObj );
71 
72 // liefert BoundRect inklusive Abstand
73 // --> OD 2006-08-15 #i68520# - change naming
74 SwRect GetBoundRectOfAnchoredObj( const SdrObject* pObj );
75 // <--
76 
77 //Liefert den UserCall ggf. vom Gruppenobjekt
78 // OD 2004-03-31 #i26791# - change return type
79 SwContact* GetUserCall( const SdrObject* );
80 
81 // liefert sal_True falls das SrdObject ein Marquee-Object (Lauftext) ist
82 sal_Bool IsMarqueeTextObj( const SdrObject& rObj );
83 
84 //Basisklasse fuer die folgenden KontaktObjekte (Rahmen+Zeichenobjekte)
85 class SwContact : public SdrObjUserCall, public SwClient
86 {
87     // OD 05.09.2003 #112039# - boolean, indicating destruction of contact object
88     // important note: boolean has to be set at the beginning of each destructor
89     //                 in the subclasses using method <SetInDTOR()>.
90     bool mbInDTOR;
91 
92     /** method to move object to visible/invisible layer
93 
94         OD 21.08.2003 #i18447#
95         Implementation for the public method <MoveObjToVisibleLayer(..)>
96         and <MoveObjToInvisibleLayer(..)>
97         If object is in invisble respectively visible layer, its moved to
98         the corresponding visible respectively invisible layers.
99         For group object the members are individually moved to the corresponding
100         layer, because <SdrObjGroup::GetLayer()> does return 0, if members
101         aren't on the same layer as the group object, and
102         <SdrObjGroup::SetLayer(..)|NbcSetLayer(..)> sets also the layer of
103         the members.
104         OD 2004-01-15 #110582# - moved from subclass <SwDrawContact>
105 
106         @author OD
107 
108         @param _bToVisible
109         input parameter - boolean indicating, if object has to be moved to
110         visible (== true) or invisible (== false) layer.
111 
112         @param _pDrawObj
113         input parameter, which will be changed - drawing object, which will
114         change its layer.
115     */
116     void _MoveObjToLayer( const bool _bToVisible,
117                           SdrObject* _pDrawObj );
118 
119 protected:
120     // OD 05.09.2003 #112039# - accessor to set member <mbInDTOR>
121     void SetInDTOR();
122 
123 public:
124 	TYPEINFO();
125 
126 	//Fuer den Reader, es wir nur die Verbindung hergestellt.
127     SwContact( SwFrmFmt *pToRegisterIn );
128     virtual ~SwContact();
129 
130     // OD 2004-03-29 #i26791#
131     virtual const SwAnchoredObject* GetAnchoredObj( const SdrObject* _pSdrObj ) const = 0;
132     virtual SwAnchoredObject* GetAnchoredObj( SdrObject* _pSdrObj ) = 0;
133 
134     // OD 13.05.2003 #108784# - made methods virtual and not inline
135     // OD 2004-04-01 #i26791# - made methods pure virtual
136     virtual const SdrObject *GetMaster() const = 0;
137     virtual SdrObject *GetMaster() = 0;
138     virtual void SetMaster( SdrObject* _pNewMaster ) = 0;
139 
140 		  SwFrmFmt	*GetFmt(){ return (SwFrmFmt*)GetRegisteredIn(); }
141 	const SwFrmFmt	*GetFmt() const
142 		{ return (const SwFrmFmt*)GetRegisteredIn(); }
143 
144     // OD 05.09.2003 #112039# - accessor for member <mbInDTOR>
145     bool IsInDTOR() const;
146 
147     /** method to move drawing object to corresponding visible layer
148 
149         OD 21.08.2003 #i18447#
150         uses method <_MoveObjToLayer(..)>
151         OD 2004-01-15 #110582# - moved from subclass <SwDrawContact> and made virtual
152 
153         @author OD
154 
155         @param _pDrawObj
156         drawing object, which will be moved to the visible layer
157     */
158     virtual void MoveObjToVisibleLayer( SdrObject* _pDrawObj );
159 
160     /** method to move drawing object to corresponding invisible layer
161 
162         OD 21.08.2003 #i18447#
163         uses method <_MoveObjToLayer(..)>
164         OD 2004-01-15 #110582# - moved from subclass <SwDrawContact> and made virtual.
165 
166         @author OD
167 
168         @param _pDrawObj
169         drawing object, which will be moved to the visible layer
170     */
171     virtual void MoveObjToInvisibleLayer( SdrObject* _pDrawObj );
172 
173     // -------------------------------------------------------------------------
174     // OD 2004-01-16 #110582# - some virtual helper methods for information
175     // about the object (Writer fly frame resp. drawing object)
176     const SwFmtAnchor& GetAnchorFmt() const
177     {
178         ASSERT( GetFmt(),
179                 "<SwContact::GetAnchorFmt()> - no frame format -> crash" );
180 
181         return GetFmt()->GetAnchor();
182     }
183 
184     RndStdIds GetAnchorId() const { return GetAnchorFmt().GetAnchorId(); }
185     bool      ObjAnchoredAtPage() const { return GetAnchorId() == FLY_AT_PAGE; }
186     bool      ObjAnchoredAtFly()  const { return GetAnchorId() == FLY_AT_FLY; }
187     bool      ObjAnchoredAtPara() const { return GetAnchorId() == FLY_AT_PARA; }
188     bool      ObjAnchoredAtChar() const { return GetAnchorId() == FLY_AT_CHAR; }
189     bool      ObjAnchoredAsChar() const { return GetAnchorId() == FLY_AS_CHAR; }
190 
191     const SwPosition&  GetCntntAnchor() const
192     {
193         ASSERT( GetAnchorFmt().GetCntntAnchor(),
194                 "<SwContact::GetCntntAnchor()> - no content anchor -> crash" );
195 
196         return *(GetAnchorFmt().GetCntntAnchor());
197     }
198 
199     const SwIndex&     GetCntntAnchorIndex() const;
200 
201     // -------------------------------------------------------------------------
202 
203     /** get data collection of anchored objects, handled by with contact
204 
205         OD 2004-08-23 #110810#
206 
207         @author
208     */
209     virtual void GetAnchoredObjs( std::list<SwAnchoredObject*>& _roAnchoredObjs ) const = 0;
210 
211     /** get minimum order number of anchored objects handled by with contact
212 
213         OD 2004-08-24 #110810#
214 
215         @author
216     */
217     sal_uInt32 GetMinOrdNum() const;
218 
219     /** get maximum order number of anchored objects handled by with contact
220 
221         OD 2004-08-24 #110810#
222 
223         @author
224     */
225     sal_uInt32 GetMaxOrdNum() const;
226 };
227 
228 //KontactObjekt fuer die Verbindung zwischen Rahmen bzw. deren Formaten
229 //im StarWriter (SwClient) und den Zeichenobjekten des Drawing (SdrObjUserCall)
230 
231 class SW_DLLPUBLIC SwFlyDrawContact : public SwContact
232 {
233 private:
234     // OD 2004-04-01 #i26791#
235     SwFlyDrawObj* mpMasterObj;
236 
237 protected:
238 	 // virtuelle Methoden von SwClient
239     virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew );
240 
241 public:
242 	TYPEINFO();
243 
244 	//Legt das DrawObjekt an und meldet es beim Model an.
245     SwFlyDrawContact( SwFlyFrmFmt* pToRegisterIn, SdrModel* pMod );
246     virtual ~SwFlyDrawContact();
247 
248     // OD 2004-03-29 #i26791#
249     virtual const SwAnchoredObject* GetAnchoredObj( const SdrObject* _pSdrObj ) const;
250     virtual SwAnchoredObject* GetAnchoredObj( SdrObject* _pSdrObj );
251 
252     // OD 2004-04-01 #i26791#
253     virtual const SdrObject* GetMaster() const;
254     virtual SdrObject* GetMaster();
255     virtual void SetMaster( SdrObject* _pNewMaster );
256 
257     // OD 2004-01-16 #110582# - override methods to control Writer fly frames,
258     // which are linked, and to assure that all objects anchored at/inside the
259     // Writer fly frame are also made visible/invisible.
260     virtual void MoveObjToVisibleLayer( SdrObject* _pDrawObj );
261     virtual void MoveObjToInvisibleLayer( SdrObject* _pDrawObj );
262 
263     /** get data collection of anchored objects handled by with contact
264 
265         OD 2004-08-23 #110810#
266 
267         @author
268     */
269     virtual void GetAnchoredObjs( std::list<SwAnchoredObject*>& _roAnchoredObjs ) const;
270 };
271 
272 // OD 16.05.2003 #108784# - new class for re-direct methods calls at a 'virtual'
273 //      drawing object to its referenced object.
274 class SwDrawVirtObj : public SdrVirtObj
275 {
276     private:
277         // data for connection to writer layout
278         // OD 2004-03-25 #i26791# - anchored drawing object instance for the
279         // 'virtual' drawing object
280         SwAnchoredDrawObject maAnchoredDrawObj;
281 
282         // writer-drawing contact object the 'virtual' drawing object is controlled by.
283         // This object is also the <UserCall> of the drawing object, if it's
284         // inserted into the drawing layer.
285         SwDrawContact&  mrDrawContact;
286 
287         using SdrVirtObj::GetPlusHdl;
288 
289    protected:
290         // AW: Need own sdr::contact::ViewContact since AnchorPos from parent is
291         // not used but something own (top left of new SnapRect minus top left
292         // of original SnapRect)
293         virtual sdr::contact::ViewContact* CreateObjectSpecificViewContact();
294 
295    public:
296         TYPEINFO();
297 
298         SwDrawVirtObj( SdrObject&       _rNewObj,
299                        SwDrawContact&   _rDrawContact );
300         virtual ~SwDrawVirtObj();
301 
302 		// access to offset
303         // OD 30.06.2003 #108784# - virtual!!!
304         virtual const Point GetOffset() const;
305 
306         virtual SdrObject* Clone() const;
307         virtual void operator=( const SdrObject& rObj );
308 
309         // connection to writer layout
310         // OD 2004-03-29 #i26791#
311         const SwAnchoredObject* GetAnchoredObj() const;
312         SwAnchoredObject* AnchoredObj();
313         const SwFrm* GetAnchorFrm() const;
314         SwFrm* AnchorFrm();
315         void RemoveFromWriterLayout();
316 
317         // connection to drawing layer
318         void AddToDrawingPage();
319         void RemoveFromDrawingPage();
320 
321         // is 'virtual' drawing object connected to writer layout and
322         // to drawing layer.
323         bool IsConnected() const;
324 
325         virtual void NbcSetAnchorPos(const Point& rPnt);
326 
327         // #108784#
328 		// All overloaded methods which need to use the offset
329 		virtual void RecalcBoundRect();
330 		virtual ::basegfx::B2DPolyPolygon TakeXorPoly() const;
331         virtual ::basegfx::B2DPolyPolygon TakeContour() const;
332 		virtual SdrHdl* GetHdl(sal_uInt32 nHdlNum) const;
333 		virtual SdrHdl* GetPlusHdl(const SdrHdl& rHdl, sal_uInt16 nPlNum) const;
334         virtual void NbcMove(const Size& rSiz);
335 		virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact);
336 		virtual void NbcRotate(const Point& rRef, long nWink, double sn, double cs);
337 		virtual void NbcMirror(const Point& rRef1, const Point& rRef2);
338 		virtual void NbcShear(const Point& rRef, long nWink, double tn, FASTBOOL bVShear);
339         virtual void Move(const Size& rSiz);
340         virtual void Resize(const Point& rRef, const Fraction& xFact, const Fraction& yFact);
341 		virtual void Rotate(const Point& rRef, long nWink, double sn, double cs);
342 		virtual void Mirror(const Point& rRef1, const Point& rRef2);
343 		virtual void Shear(const Point& rRef, long nWink, double tn, FASTBOOL bVShear);
344 		virtual void RecalcSnapRect();
345 		virtual const Rectangle& GetSnapRect() const;
346 		virtual void SetSnapRect(const Rectangle& rRect);
347         virtual void NbcSetSnapRect(const Rectangle& rRect);
348 		virtual const Rectangle& GetLogicRect() const;
349 		virtual void SetLogicRect(const Rectangle& rRect);
350         virtual void NbcSetLogicRect(const Rectangle& rRect);
351 		virtual Point GetSnapPoint(sal_uInt32 i) const;
352 		virtual Point GetPoint(sal_uInt32 i) const;
353         virtual void NbcSetPoint(const Point& rPnt, sal_uInt32 i);
354 
355 		// #108784#
356 		virtual FASTBOOL HasTextEdit() const;
357 
358         // OD 17.06.2003 #108784# - overload 'layer' methods
359         virtual SdrLayerID GetLayer() const;
360         virtual void NbcSetLayer(SdrLayerID nLayer);
361         virtual void SetLayer(SdrLayerID nLayer);
362 
363         // FullDrag support
364 	    virtual bool supportsFullDrag() const;
365 	    virtual SdrObject* getFullDragClone() const;
366 
367         // #i97197#
368 	    virtual void SetBoundRectDirty();
369     	virtual const Rectangle& GetCurrentBoundRect() const;
370     	virtual const Rectangle& GetLastBoundRect() const;
371 };
372 
373 // OD 26.06.2003 #108784#
374 bool CheckControlLayer( const SdrObject *pObj );
375 
376 //KontactObjekt fuer die Verbindung von Formaten als Repraesentanten der
377 //Zeichenobjekte im StarWriter (SwClient) und den Objekten selbst im Drawing
378 //(SdrObjUserCall).
379 
380 // --> OD 2006-01-18 #129959#
381 class NestedUserCallHdl;
382 // <--
383 
384 class SwDrawContact : public SwContact
385 {
386     private:
387         // OD 2004-03-25 #i26791# - anchored drawing object instance for the
388         // 'master' drawing object
389         SwAnchoredDrawObject maAnchoredDrawObj;
390 
391         // OD 16.05.2003 #108784# - data structure for collecting 'virtual'
392         // drawing object supporting drawing objects in headers/footers.
393         std::list<SwDrawVirtObj*> maDrawVirtObjs;
394 
395         // OD 2004-04-01 #i26791# - boolean indicating set 'master' drawing
396         // object has been cleared.
397         bool mbMasterObjCleared : 1;
398 
399         // OD 10.10.2003 #112299# - internal flag to indicate that disconnect
400         // from layout is in progress
401         bool mbDisconnectInProgress : 1;
402 
403         // --> OD 2006-01-18 #129959#
404         // Needed data for handling of nested <SdrObjUserCall> events in
405         // method <_Changed(..)>
406         bool mbUserCallActive : 1;
407         // event type, which is handled for <mpSdrObjHandledByCurrentUserCall>.
408         // Note: value only valid, if <mbUserCallActive> is sal_True.
409         SdrUserCallType meEventTypeOfCurrentUserCall;
410 
411         friend class NestedUserCallHdl;
412         // <--
413 
414         // unary function used by <list> iterator to find a disconnected 'virtual'
415         // drawing object
416         struct UsedOrUnusedVirtObjPred
417         {
418             bool mbUsedPred;
419             UsedOrUnusedVirtObjPred( bool _bUsed ) : mbUsedPred( _bUsed ) {};
420             bool operator() ( const SwDrawVirtObj* _pDrawVirtObj )
421             {
422                 if ( mbUsedPred )
423                 {
424                     return _pDrawVirtObj->IsConnected();
425                 }
426                 else
427                 {
428                     return !_pDrawVirtObj->IsConnected();
429                 }
430             }
431         };
432 
433         // unary function used by <list> iterator to find a 'virtual' drawing
434         // object anchored at a given frame
435         struct VirtObjAnchoredAtFrmPred
436         {
437             const SwFrm* mpAnchorFrm;
438             VirtObjAnchoredAtFrmPred( const SwFrm& _rAnchorFrm );
439             bool operator() ( const SwDrawVirtObj* _pDrawVirtObj );
440         };
441 
442         // OD 16.05.2003 #108784# - method for adding/removing 'virtual' drawing object.
443         SwDrawVirtObj* CreateVirtObj();
444         void DestroyVirtObj( SwDrawVirtObj* pVirtObj );
445         void RemoveAllVirtObjs();
446 
447         // OD 2004-03-31 #i26791#
448         void _InvalidateObjs( const bool _bUpdateSortedObjsList = false );
449 
450         // --> OD 2006-01-23 #124157#
451         // no copy-constructor and no assignment operator
452         SwDrawContact( const SwDrawContact& );
453         SwDrawContact& operator=( const SwDrawContact& );
454         // <--
455 
456     protected:
457         // virtuelle Methoden von SwClient
458         virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew );
459 
460     public:
461         TYPEINFO();
462 
463         SwDrawContact( SwFrmFmt *pToRegisterIn, SdrObject *pObj );
464         virtual ~SwDrawContact();
465 
466         // OD 2004-03-29 #i26791#
467         // --> OD 2005-01-06 #i30669# - no default value for parameter <_pSdrObj>
468         virtual const SwAnchoredObject* GetAnchoredObj( const SdrObject* _pSdrObj ) const;
469         virtual SwAnchoredObject* GetAnchoredObj( SdrObject* _pSdrObj );
470         // <--
471 
472         // OD 2004-04-01 #i26791#
473         virtual const SdrObject* GetMaster() const;
474         virtual SdrObject* GetMaster();
475         virtual void SetMaster( SdrObject* _pNewMaster );
476 
477         // OD 2004-03-29 #i26791#
478         const SwFrm* GetAnchorFrm( const SdrObject* _pDrawObj = 0L ) const;
479         SwFrm* GetAnchorFrm( SdrObject* _pDrawObj = 0L );
480 
481         // --> OD 2004-06-30 #i28701# - page frame is now stored at member <maAnchoredDrawObj>
482         inline const SwPageFrm* GetPageFrm() const
483         {
484             return maAnchoredDrawObj.GetPageFrm();
485         }
486         inline SwPageFrm* GetPageFrm()
487         {
488             return maAnchoredDrawObj.GetPageFrm();
489         }
490         void SetPageFrm( SwPageFrm* _pNewPageFrm )
491         {
492             return maAnchoredDrawObj.SetPageFrm( _pNewPageFrm );
493         }
494         // <--
495         void ChkPage();
496         SwPageFrm* FindPage( const SwRect &rRect );
497 
498         //Fuegt das SdrObject in die Arrays (SwPageFrm und SwFrm) des Layouts ein.
499         //Der Anker wird Anhand des Attributes SwFmtAnchor bestimmt.
500         //Das Objekt wird ggf. beim alten Anker abgemeldet.
501         void ConnectToLayout( const SwFmtAnchor *pAnch = 0 );
502         // OD 27.06.2003 #108784# - method to insert 'master' drawing object
503         // into drawing page
504         void InsertMasterIntoDrawPage();
505 
506         void DisconnectFromLayout( bool _bMoveMasterToInvisibleLayer = true );
507         // OD 19.06.2003 #108784# - disconnect for a dedicated drawing object -
508         // could be 'master' or 'virtual'.
509         void DisconnectObjFromLayout( SdrObject* _pDrawObj );
510         // OD 26.06.2003 #108784# - method to remove 'master' drawing object
511         // from drawing page.
512         // To be used by the undo for delete of object. Call it after method
513         // <DisconnectFromLayout( bool = true )> is already performed.
514         // Note: <DisconnectFromLayout( bool )> no longer removes the 'master'
515         // drawing object from drawing page.
516         void RemoveMasterFromDrawPage();
517 
518         // OD 19.06.2003 #108784# - get drawing object ('master' or 'virtual')
519         // by frame.
520         SdrObject* GetDrawObjectByAnchorFrm( const SwFrm& _rAnchorFrm );
521 
522         // virtuelle Methoden von SdrObjUserCall
523         virtual void Changed(const SdrObject& rObj, SdrUserCallType eType, const Rectangle& rOldBoundRect);
524 
525         // wird von Changed() und auch vom UndoDraw benutzt, uebernimmt
526         // das Notifien von Absaetzen, die ausweichen muessen
527         void _Changed(const SdrObject& rObj, SdrUserCallType eType, const Rectangle* pOldBoundRect);
528 
529         //Moved alle SW-Verbindungen zu dem neuen Master.
530         void ChangeMasterObject( SdrObject *pNewMaster );
531 
532         // OD 19.06.2003 #108784#
533         SwDrawVirtObj* AddVirtObj();
534 
535         // OD 20.06.2003 #108784#
536         void NotifyBackgrdOfAllVirtObjs( const Rectangle* pOldBoundRect );
537 
538         /** get data collection of anchored objects, handled by with contact
539 
540             OD 2004-08-23 #110810#
541 
542             @author
543         */
544 
545         static void GetTextObjectsFromFmt( std::list<SdrTextObj*>&, SwDoc* );
546         virtual void GetAnchoredObjs( std::list<SwAnchoredObject*>& _roAnchoredObjs ) const;
547 };
548 
549 #endif
550