1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svdovirt.cxx,v $
10 * $Revision: 1.21.18.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <svx/svdovirt.hxx>
35 #include <svx/xpool.hxx>
36 #include <svx/svdtrans.hxx>
37 #include <svx/svdetc.hxx>
38 #include <svx/svdhdl.hxx>
39 #include <svx/sdr/contact/viewcontactofvirtobj.hxx>
40 #include <basegfx/matrix/b2dhommatrix.hxx>
41 #include <svx/svdograf.hxx>
42 #include <svx/svddrgv.hxx>
44 ////////////////////////////////////////////////////////////////////////////////////////////////////
46 sdr::properties::BaseProperties
& SdrVirtObj::GetProperties() const
48 return rRefObj
.GetProperties();
51 ////////////////////////////////////////////////////////////////////////////////////////////////////
52 // AW, OD 2004-05-03 #i27224#
53 sdr::contact::ViewContact
* SdrVirtObj::CreateObjectSpecificViewContact()
55 return new sdr::contact::ViewContactOfVirtObj(*this);
58 ////////////////////////////////////////////////////////////////////////////////////////////////////
60 TYPEINIT1(SdrVirtObj
,SdrObject
);
62 SdrVirtObj::SdrVirtObj(SdrObject
& rNewObj
):
65 bVirtObj
=TRUE
; // Ja, ich bin ein virtuelles Objekt
66 rRefObj
.AddReference(*this);
67 bClosedObj
=rRefObj
.IsClosedObj();
70 SdrVirtObj::SdrVirtObj(SdrObject
& rNewObj
, const Point
& rAnchorPos
):
74 bVirtObj
=TRUE
; // Ja, ich bin ein virtuelles Objekt
75 rRefObj
.AddReference(*this);
76 bClosedObj
=rRefObj
.IsClosedObj();
79 SdrVirtObj::~SdrVirtObj()
81 rRefObj
.DelReference(*this);
84 ////////////////////////////////////////////////////////////////////////////////////////////////////
86 const SdrObject
& SdrVirtObj::GetReferencedObj() const
91 SdrObject
& SdrVirtObj::ReferencedObj()
96 void __EXPORT
SdrVirtObj::Notify(SfxBroadcaster
& /*rBC*/, const SfxHint
& /*rHint*/)
98 bClosedObj
=rRefObj
.IsClosedObj();
99 SetRectsDirty(); // hier noch Optimieren.
101 // Only a repaint here, rRefObj may have changed and broadcasts
103 // BroadcastObjectChange();
106 void SdrVirtObj::NbcSetAnchorPos(const Point
& rAnchorPos
)
111 ////////////////////////////////////////////////////////////////////////////////////////////////////
113 void SdrVirtObj::SetModel(SdrModel
* pNewModel
)
115 SdrObject::SetModel(pNewModel
);
116 rRefObj
.SetModel(pNewModel
);
119 void SdrVirtObj::TakeObjInfo(SdrObjTransformInfoRec
& rInfo
) const
121 rRefObj
.TakeObjInfo(rInfo
);
124 UINT32
SdrVirtObj::GetObjInventor() const
126 return rRefObj
.GetObjInventor();
129 UINT16
SdrVirtObj::GetObjIdentifier() const
131 return rRefObj
.GetObjIdentifier();
134 SdrObjList
* SdrVirtObj::GetSubList() const
136 return rRefObj
.GetSubList();
139 const Rectangle
& SdrVirtObj::GetCurrentBoundRect() const
141 ((SdrVirtObj
*)this)->aOutRect
=rRefObj
.GetCurrentBoundRect(); // Hier noch optimieren
142 ((SdrVirtObj
*)this)->aOutRect
+=aAnchor
;
146 const Rectangle
& SdrVirtObj::GetLastBoundRect() const
148 ((SdrVirtObj
*)this)->aOutRect
=rRefObj
.GetLastBoundRect(); // Hier noch optimieren
149 ((SdrVirtObj
*)this)->aOutRect
+=aAnchor
;
153 void SdrVirtObj::RecalcBoundRect()
155 aOutRect
=rRefObj
.GetCurrentBoundRect();
159 void SdrVirtObj::SetChanged()
161 SdrObject::SetChanged();
164 SdrObject
* SdrVirtObj::Clone() const
166 SdrObject
* pObj
=new SdrVirtObj(((SdrVirtObj
*)this)->rRefObj
); // Nur eine weitere Referenz
170 void SdrVirtObj::operator=(const SdrObject
& rObj
)
171 { // ???anderes Objekt referenzieren???
172 SdrObject::operator=(rObj
);
173 aAnchor
=((SdrVirtObj
&)rObj
).aAnchor
;
176 void SdrVirtObj::TakeObjNameSingul(XubString
& rName
) const
178 rRefObj
.TakeObjNameSingul(rName
);
179 rName
.Insert(sal_Unicode('['), 0);
180 rName
+= sal_Unicode(']');
182 String
aName( GetName() );
185 rName
+= sal_Unicode(' ');
186 rName
+= sal_Unicode('\'');
188 rName
+= sal_Unicode('\'');
192 void SdrVirtObj::TakeObjNamePlural(XubString
& rName
) const
194 rRefObj
.TakeObjNamePlural(rName
);
195 rName
.Insert(sal_Unicode('['), 0);
196 rName
+= sal_Unicode(']');
199 void operator +=(PolyPolygon
& rPoly
, const Point
& rOfs
)
201 if (rOfs
.X()!=0 || rOfs
.Y()!=0) {
203 for (j
=0; j
<rPoly
.Count(); j
++) {
204 Polygon
aP1(rPoly
.GetObject(j
));
205 for (i
=0; i
<aP1
.GetSize(); i
++) {
208 rPoly
.Replace(aP1
,j
);
213 basegfx::B2DPolyPolygon
SdrVirtObj::TakeXorPoly() const
215 basegfx::B2DPolyPolygon
aPolyPolygon(rRefObj
.TakeXorPoly());
217 if(aAnchor
.X() || aAnchor
.Y())
219 basegfx::B2DHomMatrix aMatrix
;
220 aMatrix
.translate(aAnchor
.X(), aAnchor
.Y());
221 aPolyPolygon
.transform(aMatrix
);
227 ////////////////////////////////////////////////////////////////////////////////////////////////////
229 sal_uInt32
SdrVirtObj::GetHdlCount() const
231 return rRefObj
.GetHdlCount();
234 SdrHdl
* SdrVirtObj::GetHdl(sal_uInt32 nHdlNum
) const
236 SdrHdl
* pHdl
=rRefObj
.GetHdl(nHdlNum
);
239 // GetHdl() at SdrObject is not guaranteed to return an object
242 Point
aP(pHdl
->GetPos()+aAnchor
);
249 sal_uInt32
SdrVirtObj::GetPlusHdlCount(const SdrHdl
& rHdl
) const
251 return rRefObj
.GetPlusHdlCount(rHdl
);
254 SdrHdl
* SdrVirtObj::GetPlusHdl(const SdrHdl
& rHdl
, sal_uInt32 nPlNum
) const
256 SdrHdl
* pHdl
=rRefObj
.GetPlusHdl(rHdl
,nPlNum
);
257 pHdl
->SetPos(pHdl
->GetPos() + aAnchor
);
261 void SdrVirtObj::AddToHdlList(SdrHdlList
& rHdlList
) const
264 // SdrObject::AddToHdlList(rHdlList) is not a good thing to call
265 // since at SdrPathObj, only AddToHdlList may be used and the call
266 // will instead use the standard implementation which uses GetHdlCount()
267 // and GetHdl instead. This is not wrong, but may be much less effective
268 // and may not be prepared to GetHdl returning NULL
270 // get handles using AddToHdlList from ref object
271 SdrHdlList
aLocalList(0);
272 rRefObj
.AddToHdlList(aLocalList
);
273 const sal_uInt32
nHdlCount(aLocalList
.GetHdlCount());
277 // translate handles and add them to dest list. They are temporarily part of
279 const Point
aOffset(GetOffset());
281 for(sal_uInt32
a(0L); a
< nHdlCount
; a
++)
283 SdrHdl
* pCandidate
= aLocalList
.GetHdl(a
);
284 pCandidate
->SetPos(pCandidate
->GetPos() + aOffset
);
285 rHdlList
.AddHdl(pCandidate
);
288 // remove them from source list, else they will be deleted when
289 // source list is deleted
290 while(aLocalList
.GetHdlCount())
292 aLocalList
.RemoveHdl(aLocalList
.GetHdlCount() - 1L);
297 ////////////////////////////////////////////////////////////////////////////////////////////////////
299 bool SdrVirtObj::hasSpecialDrag() const
301 return rRefObj
.hasSpecialDrag();
304 bool SdrVirtObj::supportsFullDrag() const
309 SdrObject
* SdrVirtObj::getFullDragClone() const
311 static bool bSpecialHandling(false);
312 SdrObject
* pRetval
= 0;
316 // special handling for VirtObj. Do not create another
317 // reference to rRefObj, this would allow to change that
318 // one on drag. Instead, create a SdrGrafObj for drag containing
319 // the graphical representation
320 pRetval
= new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), this), GetLogicRect());
324 SdrObject
& rReferencedObject
= ((SdrVirtObj
*)this)->ReferencedObj();
325 pRetval
= new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), &rReferencedObject
), GetLogicRect());
331 bool SdrVirtObj::beginSpecialDrag(SdrDragStat
& rDrag
) const
333 return rRefObj
.beginSpecialDrag(rDrag
);
336 bool SdrVirtObj::applySpecialDrag(SdrDragStat
& rDrag
)
338 return rRefObj
.applySpecialDrag(rDrag
);
341 basegfx::B2DPolyPolygon
SdrVirtObj::getSpecialDragPoly(const SdrDragStat
& rDrag
) const
343 return rRefObj
.getSpecialDragPoly(rDrag
);
344 // Offset handlen !!!!!! fehlt noch !!!!!!!
347 String
SdrVirtObj::getSpecialDragComment(const SdrDragStat
& rDrag
) const
349 return rRefObj
.getSpecialDragComment(rDrag
);
352 ////////////////////////////////////////////////////////////////////////////////////////////////////
354 FASTBOOL
SdrVirtObj::BegCreate(SdrDragStat
& rStat
)
356 return rRefObj
.BegCreate(rStat
);
359 FASTBOOL
SdrVirtObj::MovCreate(SdrDragStat
& rStat
)
361 return rRefObj
.MovCreate(rStat
);
364 FASTBOOL
SdrVirtObj::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
366 return rRefObj
.EndCreate(rStat
,eCmd
);
369 FASTBOOL
SdrVirtObj::BckCreate(SdrDragStat
& rStat
)
371 return rRefObj
.BckCreate(rStat
);
374 void SdrVirtObj::BrkCreate(SdrDragStat
& rStat
)
376 rRefObj
.BrkCreate(rStat
);
379 basegfx::B2DPolyPolygon
SdrVirtObj::TakeCreatePoly(const SdrDragStat
& rDrag
) const
381 return rRefObj
.TakeCreatePoly(rDrag
);
382 // Offset handlen !!!!!! fehlt noch !!!!!!!
385 ////////////////////////////////////////////////////////////////////////////////////////////////////
387 void SdrVirtObj::NbcMove(const Size
& rSiz
)
389 MovePoint(aAnchor
,rSiz
);
393 void SdrVirtObj::NbcResize(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
)
395 rRefObj
.NbcResize(rRef
-aAnchor
,xFact
,yFact
);
399 void SdrVirtObj::NbcRotate(const Point
& rRef
, long nWink
, double sn
, double cs
)
401 rRefObj
.NbcRotate(rRef
-aAnchor
,nWink
,sn
,cs
);
405 void SdrVirtObj::NbcMirror(const Point
& rRef1
, const Point
& rRef2
)
407 rRefObj
.NbcMirror(rRef1
-aAnchor
,rRef2
-aAnchor
);
411 void SdrVirtObj::NbcShear(const Point
& rRef
, long nWink
, double tn
, FASTBOOL bVShear
)
413 rRefObj
.NbcShear(rRef
-aAnchor
,nWink
,tn
,bVShear
);
417 ////////////////////////////////////////////////////////////////////////////////////////////////////
419 void SdrVirtObj::Move(const Size
& rSiz
)
421 if (rSiz
.Width()!=0 || rSiz
.Height()!=0) {
422 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
423 // #110094#-14 SendRepaintBroadcast();
426 BroadcastObjectChange();
427 SendUserCall(SDRUSERCALL_MOVEONLY
,aBoundRect0
);
431 void SdrVirtObj::Resize(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
)
433 if (xFact
.GetNumerator()!=xFact
.GetDenominator() || yFact
.GetNumerator()!=yFact
.GetDenominator()) {
434 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
435 rRefObj
.Resize(rRef
-aAnchor
,xFact
,yFact
);
437 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
441 void SdrVirtObj::Rotate(const Point
& rRef
, long nWink
, double sn
, double cs
)
444 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
445 rRefObj
.Rotate(rRef
-aAnchor
,nWink
,sn
,cs
);
447 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
451 void SdrVirtObj::Mirror(const Point
& rRef1
, const Point
& rRef2
)
453 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
454 rRefObj
.Mirror(rRef1
-aAnchor
,rRef2
-aAnchor
);
456 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
459 void SdrVirtObj::Shear(const Point
& rRef
, long nWink
, double tn
, FASTBOOL bVShear
)
462 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
463 rRefObj
.Shear(rRef
-aAnchor
,nWink
,tn
,bVShear
);
465 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
469 ////////////////////////////////////////////////////////////////////////////////////////////////////
471 void SdrVirtObj::RecalcSnapRect()
473 aSnapRect
=rRefObj
.GetSnapRect();
477 const Rectangle
& SdrVirtObj::GetSnapRect() const
479 ((SdrVirtObj
*)this)->aSnapRect
=rRefObj
.GetSnapRect();
480 ((SdrVirtObj
*)this)->aSnapRect
+=aAnchor
;
484 void SdrVirtObj::SetSnapRect(const Rectangle
& rRect
)
487 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
490 rRefObj
.SetSnapRect(aR
);
492 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
496 void SdrVirtObj::NbcSetSnapRect(const Rectangle
& rRect
)
501 rRefObj
.NbcSetSnapRect(aR
);
504 ////////////////////////////////////////////////////////////////////////////////////////////////////
506 const Rectangle
& SdrVirtObj::GetLogicRect() const
508 ((SdrVirtObj
*)this)->aSnapRect
=rRefObj
.GetLogicRect(); // !!! Missbrauch von aSnapRect !!!
509 ((SdrVirtObj
*)this)->aSnapRect
+=aAnchor
; // Wenns mal Aerger gibt, muss ein weiteres Rectangle Member her (oder Heap)
513 void SdrVirtObj::SetLogicRect(const Rectangle
& rRect
)
515 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
518 rRefObj
.SetLogicRect(aR
);
520 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
523 void SdrVirtObj::NbcSetLogicRect(const Rectangle
& rRect
)
528 rRefObj
.NbcSetLogicRect(aR
);
531 ////////////////////////////////////////////////////////////////////////////////////////////////////
533 long SdrVirtObj::GetRotateAngle() const
535 return rRefObj
.GetRotateAngle();
538 long SdrVirtObj::GetShearAngle(FASTBOOL bVertical
) const
540 return rRefObj
.GetShearAngle(bVertical
);
543 ////////////////////////////////////////////////////////////////////////////////////////////////////
545 sal_uInt32
SdrVirtObj::GetSnapPointCount() const
547 return rRefObj
.GetSnapPointCount();
550 Point
SdrVirtObj::GetSnapPoint(sal_uInt32 i
) const
552 Point
aP(rRefObj
.GetSnapPoint(i
));
557 sal_Bool
SdrVirtObj::IsPolyObj() const
559 return rRefObj
.IsPolyObj();
562 sal_uInt32
SdrVirtObj::GetPointCount() const
564 return rRefObj
.GetPointCount();
567 Point
SdrVirtObj::GetPoint(sal_uInt32 i
) const
569 return Point(rRefObj
.GetPoint(i
) + aAnchor
);
572 void SdrVirtObj::NbcSetPoint(const Point
& rPnt
, sal_uInt32 i
)
576 rRefObj
.SetPoint(aP
,i
);
580 ////////////////////////////////////////////////////////////////////////////////////////////////////
582 SdrObjGeoData
* SdrVirtObj::NewGeoData() const
584 return rRefObj
.NewGeoData();
587 void SdrVirtObj::SaveGeoData(SdrObjGeoData
& rGeo
) const
589 rRefObj
.SaveGeoData(rGeo
);
592 void SdrVirtObj::RestGeoData(const SdrObjGeoData
& rGeo
)
594 rRefObj
.RestGeoData(rGeo
);
598 ////////////////////////////////////////////////////////////////////////////////////////////////////
600 SdrObjGeoData
* SdrVirtObj::GetGeoData() const
602 return rRefObj
.GetGeoData();
605 void SdrVirtObj::SetGeoData(const SdrObjGeoData
& rGeo
)
607 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
608 rRefObj
.SetGeoData(rGeo
);
610 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
613 ////////////////////////////////////////////////////////////////////////////////////////////////////
615 void SdrVirtObj::NbcReformatText()
617 rRefObj
.NbcReformatText();
620 void SdrVirtObj::ReformatText()
622 rRefObj
.ReformatText();
625 ////////////////////////////////////////////////////////////////////////////////////////////////////
627 FASTBOOL
SdrVirtObj::HasMacro() const
629 return rRefObj
.HasMacro();
632 SdrObject
* SdrVirtObj::CheckMacroHit(const SdrObjMacroHitRec
& rRec
) const
634 return rRefObj
.CheckMacroHit(rRec
); // Todo: Positionsversatz
637 Pointer
SdrVirtObj::GetMacroPointer(const SdrObjMacroHitRec
& rRec
) const
639 return rRefObj
.GetMacroPointer(rRec
); // Todo: Positionsversatz
642 void SdrVirtObj::PaintMacro(OutputDevice
& rOut
, const Rectangle
& rDirtyRect
, const SdrObjMacroHitRec
& rRec
) const
644 rRefObj
.PaintMacro(rOut
,rDirtyRect
,rRec
); // Todo: Positionsversatz
647 FASTBOOL
SdrVirtObj::DoMacro(const SdrObjMacroHitRec
& rRec
)
649 return rRefObj
.DoMacro(rRec
); // Todo: Positionsversatz
652 XubString
SdrVirtObj::GetMacroPopupComment(const SdrObjMacroHitRec
& rRec
) const
654 return rRefObj
.GetMacroPopupComment(rRec
); // Todo: Positionsversatz
657 const Point
SdrVirtObj::GetOffset() const
659 // #i73248# default offset of SdrVirtObj is aAnchor