1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
30 #include <svx/svdovirt.hxx>
31 #include <svx/xpool.hxx>
32 #include <svx/svdtrans.hxx>
33 #include <svx/svdetc.hxx>
34 #include <svx/svdhdl.hxx>
35 #include <svx/sdr/contact/viewcontactofvirtobj.hxx>
36 #include <basegfx/matrix/b2dhommatrix.hxx>
37 #include <svx/svdograf.hxx>
38 #include <svx/svddrgv.hxx>
39 #include <basegfx/matrix/b2dhommatrixtools.hxx>
41 ////////////////////////////////////////////////////////////////////////////////////////////////////
43 sdr::properties::BaseProperties
& SdrVirtObj::GetProperties() const
45 return rRefObj
.GetProperties();
48 ////////////////////////////////////////////////////////////////////////////////////////////////////
50 sdr::contact::ViewContact
* SdrVirtObj::CreateObjectSpecificViewContact()
52 return new sdr::contact::ViewContactOfVirtObj(*this);
55 ////////////////////////////////////////////////////////////////////////////////////////////////////
57 TYPEINIT1(SdrVirtObj
,SdrObject
);
59 SdrVirtObj::SdrVirtObj(SdrObject
& rNewObj
):
62 bVirtObj
=sal_True
; // this is only a virtual object
63 rRefObj
.AddReference(*this);
64 bClosedObj
=rRefObj
.IsClosedObj();
67 SdrVirtObj::~SdrVirtObj()
69 rRefObj
.DelReference(*this);
72 ////////////////////////////////////////////////////////////////////////////////////////////////////
74 const SdrObject
& SdrVirtObj::GetReferencedObj() const
79 SdrObject
& SdrVirtObj::ReferencedObj()
84 void SdrVirtObj::Notify(SfxBroadcaster
& /*rBC*/, const SfxHint
& /*rHint*/)
86 bClosedObj
=rRefObj
.IsClosedObj();
87 SetRectsDirty(); // TODO: Optimize this.
89 // Only a repaint here, rRefObj may have changed and broadcasts
93 void SdrVirtObj::NbcSetAnchorPos(const Point
& rAnchorPos
)
98 ////////////////////////////////////////////////////////////////////////////////////////////////////
100 void SdrVirtObj::SetModel(SdrModel
* pNewModel
)
102 SdrObject::SetModel(pNewModel
);
103 rRefObj
.SetModel(pNewModel
);
106 void SdrVirtObj::TakeObjInfo(SdrObjTransformInfoRec
& rInfo
) const
108 rRefObj
.TakeObjInfo(rInfo
);
111 sal_uInt32
SdrVirtObj::GetObjInventor() const
113 return rRefObj
.GetObjInventor();
116 sal_uInt16
SdrVirtObj::GetObjIdentifier() const
118 return rRefObj
.GetObjIdentifier();
121 SdrObjList
* SdrVirtObj::GetSubList() const
123 return rRefObj
.GetSubList();
126 const Rectangle
& SdrVirtObj::GetCurrentBoundRect() const
128 ((SdrVirtObj
*)this)->aOutRect
=rRefObj
.GetCurrentBoundRect(); // TODO: Optimize this.
129 ((SdrVirtObj
*)this)->aOutRect
+=aAnchor
;
133 const Rectangle
& SdrVirtObj::GetLastBoundRect() const
135 ((SdrVirtObj
*)this)->aOutRect
=rRefObj
.GetLastBoundRect(); // TODO: Optimize this.
136 ((SdrVirtObj
*)this)->aOutRect
+=aAnchor
;
140 void SdrVirtObj::RecalcBoundRect()
142 aOutRect
=rRefObj
.GetCurrentBoundRect();
146 void SdrVirtObj::SetChanged()
148 SdrObject::SetChanged();
151 SdrVirtObj
* SdrVirtObj::Clone() const
153 return new SdrVirtObj(this->rRefObj
); // only a further reference
156 SdrVirtObj
& SdrVirtObj::operator=(const SdrVirtObj
& rObj
)
157 { // reference different object??
158 SdrObject::operator=(rObj
);
159 aAnchor
=rObj
.aAnchor
;
163 void SdrVirtObj::TakeObjNameSingul(XubString
& rName
) const
165 rRefObj
.TakeObjNameSingul(rName
);
166 rName
.Insert(sal_Unicode('['), 0);
167 rName
+= sal_Unicode(']');
169 String
aName( GetName() );
172 rName
+= sal_Unicode(' ');
173 rName
+= sal_Unicode('\'');
175 rName
+= sal_Unicode('\'');
179 void SdrVirtObj::TakeObjNamePlural(XubString
& rName
) const
181 rRefObj
.TakeObjNamePlural(rName
);
182 rName
.Insert(sal_Unicode('['), 0);
183 rName
+= sal_Unicode(']');
186 void operator +=(PolyPolygon
& rPoly
, const Point
& rOfs
)
188 if (rOfs
.X()!=0 || rOfs
.Y()!=0) {
190 for (j
=0; j
<rPoly
.Count(); j
++) {
191 Polygon
aP1(rPoly
.GetObject(j
));
192 for (i
=0; i
<aP1
.GetSize(); i
++) {
195 rPoly
.Replace(aP1
,j
);
200 basegfx::B2DPolyPolygon
SdrVirtObj::TakeXorPoly() const
202 basegfx::B2DPolyPolygon
aPolyPolygon(rRefObj
.TakeXorPoly());
204 if(aAnchor
.X() || aAnchor
.Y())
206 aPolyPolygon
.transform(basegfx::tools::createTranslateB2DHomMatrix(aAnchor
.X(), aAnchor
.Y()));
212 ////////////////////////////////////////////////////////////////////////////////////////////////////
214 sal_uInt32
SdrVirtObj::GetHdlCount() const
216 return rRefObj
.GetHdlCount();
219 SdrHdl
* SdrVirtObj::GetHdl(sal_uInt32 nHdlNum
) const
221 SdrHdl
* pHdl
=rRefObj
.GetHdl(nHdlNum
);
224 // GetHdl() at SdrObject is not guaranteed to return an object
227 Point
aP(pHdl
->GetPos()+aAnchor
);
234 sal_uInt32
SdrVirtObj::GetPlusHdlCount(const SdrHdl
& rHdl
) const
236 return rRefObj
.GetPlusHdlCount(rHdl
);
239 SdrHdl
* SdrVirtObj::GetPlusHdl(const SdrHdl
& rHdl
, sal_uInt32 nPlNum
) const
241 SdrHdl
* pHdl
=rRefObj
.GetPlusHdl(rHdl
,nPlNum
);
242 pHdl
->SetPos(pHdl
->GetPos() + aAnchor
);
246 void SdrVirtObj::AddToHdlList(SdrHdlList
& rHdlList
) const
249 // SdrObject::AddToHdlList(rHdlList) is not a good thing to call
250 // since at SdrPathObj, only AddToHdlList may be used and the call
251 // will instead use the standard implementation which uses GetHdlCount()
252 // and GetHdl instead. This is not wrong, but may be much less effective
253 // and may not be prepared to GetHdl returning NULL
255 // get handles using AddToHdlList from ref object
256 SdrHdlList
aLocalList(0);
257 rRefObj
.AddToHdlList(aLocalList
);
258 const sal_uInt32
nHdlCount(aLocalList
.GetHdlCount());
262 // translate handles and add them to dest list. They are temporarily part of
264 const Point
aOffset(GetOffset());
266 for(sal_uInt32
a(0L); a
< nHdlCount
; a
++)
268 SdrHdl
* pCandidate
= aLocalList
.GetHdl(a
);
269 pCandidate
->SetPos(pCandidate
->GetPos() + aOffset
);
270 rHdlList
.AddHdl(pCandidate
);
273 // remove them from source list, else they will be deleted when
274 // source list is deleted
275 while(aLocalList
.GetHdlCount())
277 aLocalList
.RemoveHdl(aLocalList
.GetHdlCount() - 1L);
282 ////////////////////////////////////////////////////////////////////////////////////////////////////
284 bool SdrVirtObj::hasSpecialDrag() const
286 return rRefObj
.hasSpecialDrag();
289 bool SdrVirtObj::supportsFullDrag() const
294 SdrObject
* SdrVirtObj::getFullDragClone() const
296 static bool bSpecialHandling(false);
297 SdrObject
* pRetval
= 0;
301 // special handling for VirtObj. Do not create another
302 // reference to rRefObj, this would allow to change that
303 // one on drag. Instead, create a SdrGrafObj for drag containing
304 // the graphical representation
305 pRetval
= new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), this), GetLogicRect());
309 SdrObject
& rReferencedObject
= ((SdrVirtObj
*)this)->ReferencedObj();
310 pRetval
= new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), &rReferencedObject
), GetLogicRect());
316 bool SdrVirtObj::beginSpecialDrag(SdrDragStat
& rDrag
) const
318 return rRefObj
.beginSpecialDrag(rDrag
);
321 bool SdrVirtObj::applySpecialDrag(SdrDragStat
& rDrag
)
323 return rRefObj
.applySpecialDrag(rDrag
);
326 basegfx::B2DPolyPolygon
SdrVirtObj::getSpecialDragPoly(const SdrDragStat
& rDrag
) const
328 return rRefObj
.getSpecialDragPoly(rDrag
);
329 // TODO: we don't handle offsets yet!
332 String
SdrVirtObj::getSpecialDragComment(const SdrDragStat
& rDrag
) const
334 return rRefObj
.getSpecialDragComment(rDrag
);
337 ////////////////////////////////////////////////////////////////////////////////////////////////////
339 bool SdrVirtObj::BegCreate(SdrDragStat
& rStat
)
341 return rRefObj
.BegCreate(rStat
);
344 bool SdrVirtObj::MovCreate(SdrDragStat
& rStat
)
346 return rRefObj
.MovCreate(rStat
);
349 bool SdrVirtObj::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
351 return rRefObj
.EndCreate(rStat
,eCmd
);
354 bool SdrVirtObj::BckCreate(SdrDragStat
& rStat
)
356 return rRefObj
.BckCreate(rStat
);
359 void SdrVirtObj::BrkCreate(SdrDragStat
& rStat
)
361 rRefObj
.BrkCreate(rStat
);
364 basegfx::B2DPolyPolygon
SdrVirtObj::TakeCreatePoly(const SdrDragStat
& rDrag
) const
366 return rRefObj
.TakeCreatePoly(rDrag
);
367 // TODO: we don't handle offsets yet!
370 ////////////////////////////////////////////////////////////////////////////////////////////////////
372 void SdrVirtObj::NbcMove(const Size
& rSiz
)
374 MovePoint(aAnchor
,rSiz
);
378 void SdrVirtObj::NbcResize(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
)
380 rRefObj
.NbcResize(rRef
-aAnchor
,xFact
,yFact
);
384 void SdrVirtObj::NbcRotate(const Point
& rRef
, long nWink
, double sn
, double cs
)
386 rRefObj
.NbcRotate(rRef
-aAnchor
,nWink
,sn
,cs
);
390 void SdrVirtObj::NbcMirror(const Point
& rRef1
, const Point
& rRef2
)
392 rRefObj
.NbcMirror(rRef1
-aAnchor
,rRef2
-aAnchor
);
396 void SdrVirtObj::NbcShear(const Point
& rRef
, long nWink
, double tn
, bool bVShear
)
398 rRefObj
.NbcShear(rRef
-aAnchor
,nWink
,tn
,bVShear
);
402 ////////////////////////////////////////////////////////////////////////////////////////////////////
404 void SdrVirtObj::Move(const Size
& rSiz
)
406 if (rSiz
.Width()!=0 || rSiz
.Height()!=0) {
407 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
410 BroadcastObjectChange();
411 SendUserCall(SDRUSERCALL_MOVEONLY
,aBoundRect0
);
415 void SdrVirtObj::Resize(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
)
417 if (xFact
.GetNumerator()!=xFact
.GetDenominator() || yFact
.GetNumerator()!=yFact
.GetDenominator()) {
418 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
419 rRefObj
.Resize(rRef
-aAnchor
,xFact
,yFact
);
421 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
425 void SdrVirtObj::Rotate(const Point
& rRef
, long nWink
, double sn
, double cs
)
428 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
429 rRefObj
.Rotate(rRef
-aAnchor
,nWink
,sn
,cs
);
431 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
435 void SdrVirtObj::Mirror(const Point
& rRef1
, const Point
& rRef2
)
437 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
438 rRefObj
.Mirror(rRef1
-aAnchor
,rRef2
-aAnchor
);
440 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
443 void SdrVirtObj::Shear(const Point
& rRef
, long nWink
, double tn
, bool bVShear
)
446 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
447 rRefObj
.Shear(rRef
-aAnchor
,nWink
,tn
,bVShear
);
449 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
453 ////////////////////////////////////////////////////////////////////////////////////////////////////
455 void SdrVirtObj::RecalcSnapRect()
457 aSnapRect
=rRefObj
.GetSnapRect();
461 const Rectangle
& SdrVirtObj::GetSnapRect() const
463 ((SdrVirtObj
*)this)->aSnapRect
=rRefObj
.GetSnapRect();
464 ((SdrVirtObj
*)this)->aSnapRect
+=aAnchor
;
468 void SdrVirtObj::SetSnapRect(const Rectangle
& rRect
)
471 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
474 rRefObj
.SetSnapRect(aR
);
476 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
480 void SdrVirtObj::NbcSetSnapRect(const Rectangle
& rRect
)
485 rRefObj
.NbcSetSnapRect(aR
);
488 ////////////////////////////////////////////////////////////////////////////////////////////////////
490 const Rectangle
& SdrVirtObj::GetLogicRect() const
492 ((SdrVirtObj
*)this)->aSnapRect
=rRefObj
.GetLogicRect(); // An abuse of aSnapRect!
493 ((SdrVirtObj
*)this)->aSnapRect
+=aAnchor
; // If there's trouble, we need another Rectangle Member (or a Heap).
497 void SdrVirtObj::SetLogicRect(const Rectangle
& rRect
)
499 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
502 rRefObj
.SetLogicRect(aR
);
504 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
507 void SdrVirtObj::NbcSetLogicRect(const Rectangle
& rRect
)
512 rRefObj
.NbcSetLogicRect(aR
);
515 ////////////////////////////////////////////////////////////////////////////////////////////////////
517 long SdrVirtObj::GetRotateAngle() const
519 return rRefObj
.GetRotateAngle();
522 long SdrVirtObj::GetShearAngle(bool bVertical
) const
524 return rRefObj
.GetShearAngle(bVertical
);
527 ////////////////////////////////////////////////////////////////////////////////////////////////////
529 sal_uInt32
SdrVirtObj::GetSnapPointCount() const
531 return rRefObj
.GetSnapPointCount();
534 Point
SdrVirtObj::GetSnapPoint(sal_uInt32 i
) const
536 Point
aP(rRefObj
.GetSnapPoint(i
));
541 sal_Bool
SdrVirtObj::IsPolyObj() const
543 return rRefObj
.IsPolyObj();
546 sal_uInt32
SdrVirtObj::GetPointCount() const
548 return rRefObj
.GetPointCount();
551 Point
SdrVirtObj::GetPoint(sal_uInt32 i
) const
553 return Point(rRefObj
.GetPoint(i
) + aAnchor
);
556 void SdrVirtObj::NbcSetPoint(const Point
& rPnt
, sal_uInt32 i
)
560 rRefObj
.SetPoint(aP
,i
);
564 ////////////////////////////////////////////////////////////////////////////////////////////////////
566 SdrObjGeoData
* SdrVirtObj::NewGeoData() const
568 return rRefObj
.NewGeoData();
571 void SdrVirtObj::SaveGeoData(SdrObjGeoData
& rGeo
) const
573 rRefObj
.SaveGeoData(rGeo
);
576 void SdrVirtObj::RestGeoData(const SdrObjGeoData
& rGeo
)
578 rRefObj
.RestGeoData(rGeo
);
582 ////////////////////////////////////////////////////////////////////////////////////////////////////
584 SdrObjGeoData
* SdrVirtObj::GetGeoData() const
586 return rRefObj
.GetGeoData();
589 void SdrVirtObj::SetGeoData(const SdrObjGeoData
& rGeo
)
591 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
592 rRefObj
.SetGeoData(rGeo
);
594 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
597 ////////////////////////////////////////////////////////////////////////////////////////////////////
599 void SdrVirtObj::NbcReformatText()
601 rRefObj
.NbcReformatText();
604 void SdrVirtObj::ReformatText()
606 rRefObj
.ReformatText();
609 ////////////////////////////////////////////////////////////////////////////////////////////////////
611 bool SdrVirtObj::HasMacro() const
613 return rRefObj
.HasMacro();
616 SdrObject
* SdrVirtObj::CheckMacroHit(const SdrObjMacroHitRec
& rRec
) const
618 return rRefObj
.CheckMacroHit(rRec
); // TODO: positioning offset
621 Pointer
SdrVirtObj::GetMacroPointer(const SdrObjMacroHitRec
& rRec
) const
623 return rRefObj
.GetMacroPointer(rRec
); // TODO: positioning offset
626 void SdrVirtObj::PaintMacro(OutputDevice
& rOut
, const Rectangle
& rDirtyRect
, const SdrObjMacroHitRec
& rRec
) const
628 rRefObj
.PaintMacro(rOut
,rDirtyRect
,rRec
); // TODO: positioning offset
631 bool SdrVirtObj::DoMacro(const SdrObjMacroHitRec
& rRec
)
633 return rRefObj
.DoMacro(rRec
); // TODO: positioning offset
636 rtl::OUString
SdrVirtObj::GetMacroPopupComment(const SdrObjMacroHitRec
& rRec
) const
638 return rRefObj
.GetMacroPopupComment(rRec
); // TODO: positioning offset
641 const Point
SdrVirtObj::GetOffset() const
643 // #i73248# default offset of SdrVirtObj is aAnchor
649 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */