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