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