1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <svx/svdovirt.hxx>
22 #include <svx/xpool.hxx>
23 #include <svx/svdtrans.hxx>
24 #include <svx/svdetc.hxx>
25 #include <svx/svdhdl.hxx>
26 #include <svx/sdr/contact/viewcontactofvirtobj.hxx>
27 #include <basegfx/matrix/b2dhommatrix.hxx>
28 #include <svx/svdograf.hxx>
29 #include <svx/svddrgv.hxx>
30 #include <basegfx/matrix/b2dhommatrixtools.hxx>
34 sdr::properties::BaseProperties
& SdrVirtObj::GetProperties() const
36 return rRefObj
.GetProperties();
41 sdr::contact::ViewContact
* SdrVirtObj::CreateObjectSpecificViewContact()
43 return new sdr::contact::ViewContactOfVirtObj(*this);
48 TYPEINIT1(SdrVirtObj
,SdrObject
);
50 SdrVirtObj::SdrVirtObj(SdrObject
& rNewObj
):
53 bVirtObj
=true; // this is only a virtual object
54 rRefObj
.AddReference(*this);
55 bClosedObj
=rRefObj
.IsClosedObj();
58 SdrVirtObj::~SdrVirtObj()
60 rRefObj
.DelReference(*this);
65 const SdrObject
& SdrVirtObj::GetReferencedObj() const
70 SdrObject
& SdrVirtObj::ReferencedObj()
75 void SdrVirtObj::Notify(SfxBroadcaster
& /*rBC*/, const SfxHint
& /*rHint*/)
77 bClosedObj
=rRefObj
.IsClosedObj();
78 SetRectsDirty(); // TODO: Optimize this.
80 // Only a repaint here, rRefObj may have changed and broadcasts
84 void SdrVirtObj::NbcSetAnchorPos(const Point
& rAnchorPos
)
91 void SdrVirtObj::SetModel(SdrModel
* pNewModel
)
93 SdrObject::SetModel(pNewModel
);
94 rRefObj
.SetModel(pNewModel
);
97 void SdrVirtObj::TakeObjInfo(SdrObjTransformInfoRec
& rInfo
) const
99 rRefObj
.TakeObjInfo(rInfo
);
102 sal_uInt32
SdrVirtObj::GetObjInventor() const
104 return rRefObj
.GetObjInventor();
107 sal_uInt16
SdrVirtObj::GetObjIdentifier() const
109 return rRefObj
.GetObjIdentifier();
112 SdrObjList
* SdrVirtObj::GetSubList() const
114 return rRefObj
.GetSubList();
117 const Rectangle
& SdrVirtObj::GetCurrentBoundRect() const
119 const_cast<SdrVirtObj
*>(this)->aOutRect
=rRefObj
.GetCurrentBoundRect(); // TODO: Optimize this.
120 const_cast<SdrVirtObj
*>(this)->aOutRect
+=aAnchor
;
124 const Rectangle
& SdrVirtObj::GetLastBoundRect() const
126 const_cast<SdrVirtObj
*>(this)->aOutRect
=rRefObj
.GetLastBoundRect(); // TODO: Optimize this.
127 const_cast<SdrVirtObj
*>(this)->aOutRect
+=aAnchor
;
131 void SdrVirtObj::RecalcBoundRect()
133 aOutRect
=rRefObj
.GetCurrentBoundRect();
137 void SdrVirtObj::SetChanged()
139 SdrObject::SetChanged();
142 SdrVirtObj
* SdrVirtObj::Clone() const
144 return new SdrVirtObj(this->rRefObj
); // only a further reference
147 SdrVirtObj
& SdrVirtObj::operator=(const SdrVirtObj
& rObj
)
148 { // reference different object??
149 SdrObject::operator=(rObj
);
150 aAnchor
=rObj
.aAnchor
;
154 OUString
SdrVirtObj::TakeObjNameSingul() const
156 OUStringBuffer
sName(rRefObj
.TakeObjNameSingul());
157 sName
.insert(0, '[');
160 OUString
aName(GetName());
161 if (!aName
.isEmpty())
169 return sName
.makeStringAndClear();
172 OUString
SdrVirtObj::TakeObjNamePlural() const
174 OUStringBuffer
sName(rRefObj
.TakeObjNamePlural());
175 sName
.insert(0, '[');
177 return sName
.makeStringAndClear();
180 basegfx::B2DPolyPolygon
SdrVirtObj::TakeXorPoly() const
182 basegfx::B2DPolyPolygon
aPolyPolygon(rRefObj
.TakeXorPoly());
184 if(aAnchor
.X() || aAnchor
.Y())
186 aPolyPolygon
.transform(basegfx::tools::createTranslateB2DHomMatrix(aAnchor
.X(), aAnchor
.Y()));
194 sal_uInt32
SdrVirtObj::GetHdlCount() const
196 return rRefObj
.GetHdlCount();
199 SdrHdl
* SdrVirtObj::GetHdl(sal_uInt32 nHdlNum
) const
201 SdrHdl
* pHdl
=rRefObj
.GetHdl(nHdlNum
);
204 // GetHdl() at SdrObject is not guaranteed to return an object
207 Point
aP(pHdl
->GetPos()+aAnchor
);
214 sal_uInt32
SdrVirtObj::GetPlusHdlCount(const SdrHdl
& rHdl
) const
216 return rRefObj
.GetPlusHdlCount(rHdl
);
219 SdrHdl
* SdrVirtObj::GetPlusHdl(const SdrHdl
& rHdl
, sal_uInt32 nPlNum
) const
221 SdrHdl
* pHdl
=rRefObj
.GetPlusHdl(rHdl
,nPlNum
);
222 pHdl
->SetPos(pHdl
->GetPos() + aAnchor
);
226 void SdrVirtObj::AddToHdlList(SdrHdlList
& rHdlList
) const
229 // SdrObject::AddToHdlList(rHdlList) is not a good thing to call
230 // since at SdrPathObj, only AddToHdlList may be used and the call
231 // will instead use the standard implementation which uses GetHdlCount()
232 // and GetHdl instead. This is not wrong, but may be much less effective
233 // and may not be prepared to GetHdl returning NULL
235 // get handles using AddToHdlList from ref object
236 SdrHdlList
aLocalList(0);
237 rRefObj
.AddToHdlList(aLocalList
);
238 const size_t nHdlCount(aLocalList
.GetHdlCount());
242 // translate handles and add them to dest list. They are temporarily part of
244 const Point
aOffset(GetOffset());
246 for(size_t a
= 0; a
< nHdlCount
; ++a
)
248 SdrHdl
* pCandidate
= aLocalList
.GetHdl(a
);
249 pCandidate
->SetPos(pCandidate
->GetPos() + aOffset
);
250 rHdlList
.AddHdl(pCandidate
);
253 // remove them from source list, else they will be deleted when
254 // source list is deleted
255 while(aLocalList
.GetHdlCount())
257 aLocalList
.RemoveHdl(aLocalList
.GetHdlCount() - 1);
264 bool SdrVirtObj::hasSpecialDrag() const
266 return rRefObj
.hasSpecialDrag();
269 bool SdrVirtObj::supportsFullDrag() const
274 SdrObject
* SdrVirtObj::getFullDragClone() const
276 static bool bSpecialHandling(false);
277 SdrObject
* pRetval
= 0;
281 // special handling for VirtObj. Do not create another
282 // reference to rRefObj, this would allow to change that
283 // one on drag. Instead, create a SdrGrafObj for drag containing
284 // the graphical representation
285 pRetval
= new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), this), GetLogicRect());
289 SdrObject
& rReferencedObject
= const_cast<SdrVirtObj
*>(this)->ReferencedObj();
290 pRetval
= new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), &rReferencedObject
), GetLogicRect());
296 bool SdrVirtObj::beginSpecialDrag(SdrDragStat
& rDrag
) const
298 return rRefObj
.beginSpecialDrag(rDrag
);
301 bool SdrVirtObj::applySpecialDrag(SdrDragStat
& rDrag
)
303 return rRefObj
.applySpecialDrag(rDrag
);
306 basegfx::B2DPolyPolygon
SdrVirtObj::getSpecialDragPoly(const SdrDragStat
& rDrag
) const
308 return rRefObj
.getSpecialDragPoly(rDrag
);
309 // TODO: we don't handle offsets yet!
312 OUString
SdrVirtObj::getSpecialDragComment(const SdrDragStat
& rDrag
) const
314 return rRefObj
.getSpecialDragComment(rDrag
);
319 bool SdrVirtObj::BegCreate(SdrDragStat
& rStat
)
321 return rRefObj
.BegCreate(rStat
);
324 bool SdrVirtObj::MovCreate(SdrDragStat
& rStat
)
326 return rRefObj
.MovCreate(rStat
);
329 bool SdrVirtObj::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
331 return rRefObj
.EndCreate(rStat
,eCmd
);
334 bool SdrVirtObj::BckCreate(SdrDragStat
& rStat
)
336 return rRefObj
.BckCreate(rStat
);
339 void SdrVirtObj::BrkCreate(SdrDragStat
& rStat
)
341 rRefObj
.BrkCreate(rStat
);
344 basegfx::B2DPolyPolygon
SdrVirtObj::TakeCreatePoly(const SdrDragStat
& rDrag
) const
346 return rRefObj
.TakeCreatePoly(rDrag
);
347 // TODO: we don't handle offsets yet!
352 void SdrVirtObj::NbcMove(const Size
& rSiz
)
354 MovePoint(aAnchor
,rSiz
);
358 void SdrVirtObj::NbcResize(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
)
360 rRefObj
.NbcResize(rRef
-aAnchor
,xFact
,yFact
);
364 void SdrVirtObj::NbcRotate(const Point
& rRef
, long nAngle
, double sn
, double cs
)
366 rRefObj
.NbcRotate(rRef
-aAnchor
,nAngle
,sn
,cs
);
370 void SdrVirtObj::NbcMirror(const Point
& rRef1
, const Point
& rRef2
)
372 rRefObj
.NbcMirror(rRef1
-aAnchor
,rRef2
-aAnchor
);
376 void SdrVirtObj::NbcShear(const Point
& rRef
, long nAngle
, double tn
, bool bVShear
)
378 rRefObj
.NbcShear(rRef
-aAnchor
,nAngle
,tn
,bVShear
);
384 void SdrVirtObj::Move(const Size
& rSiz
)
386 if (rSiz
.Width()!=0 || rSiz
.Height()!=0) {
387 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
390 BroadcastObjectChange();
391 SendUserCall(SDRUSERCALL_MOVEONLY
,aBoundRect0
);
395 void SdrVirtObj::Resize(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
, bool bUnsetRelative
)
397 if (xFact
.GetNumerator()!=xFact
.GetDenominator() || yFact
.GetNumerator()!=yFact
.GetDenominator()) {
398 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
399 rRefObj
.Resize(rRef
-aAnchor
,xFact
,yFact
, bUnsetRelative
);
401 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
405 void SdrVirtObj::Rotate(const Point
& rRef
, long nAngle
, double sn
, double cs
)
408 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
409 rRefObj
.Rotate(rRef
-aAnchor
,nAngle
,sn
,cs
);
411 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
415 void SdrVirtObj::Mirror(const Point
& rRef1
, const Point
& rRef2
)
417 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
418 rRefObj
.Mirror(rRef1
-aAnchor
,rRef2
-aAnchor
);
420 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
423 void SdrVirtObj::Shear(const Point
& rRef
, long nAngle
, double tn
, bool bVShear
)
426 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
427 rRefObj
.Shear(rRef
-aAnchor
,nAngle
,tn
,bVShear
);
429 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
435 void SdrVirtObj::RecalcSnapRect()
437 aSnapRect
=rRefObj
.GetSnapRect();
441 const Rectangle
& SdrVirtObj::GetSnapRect() const
443 const_cast<SdrVirtObj
*>(this)->aSnapRect
=rRefObj
.GetSnapRect();
444 const_cast<SdrVirtObj
*>(this)->aSnapRect
+=aAnchor
;
448 void SdrVirtObj::SetSnapRect(const Rectangle
& rRect
)
451 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
454 rRefObj
.SetSnapRect(aR
);
456 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
460 void SdrVirtObj::NbcSetSnapRect(const Rectangle
& rRect
)
465 rRefObj
.NbcSetSnapRect(aR
);
470 const Rectangle
& SdrVirtObj::GetLogicRect() const
472 const_cast<SdrVirtObj
*>(this)->aSnapRect
=rRefObj
.GetLogicRect(); // An abuse of aSnapRect!
473 const_cast<SdrVirtObj
*>(this)->aSnapRect
+=aAnchor
; // If there's trouble, we need another Rectangle Member (or a Heap).
477 void SdrVirtObj::SetLogicRect(const Rectangle
& rRect
)
479 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
482 rRefObj
.SetLogicRect(aR
);
484 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
487 void SdrVirtObj::NbcSetLogicRect(const Rectangle
& rRect
)
492 rRefObj
.NbcSetLogicRect(aR
);
497 long SdrVirtObj::GetRotateAngle() const
499 return rRefObj
.GetRotateAngle();
502 long SdrVirtObj::GetShearAngle(bool bVertical
) const
504 return rRefObj
.GetShearAngle(bVertical
);
509 sal_uInt32
SdrVirtObj::GetSnapPointCount() const
511 return rRefObj
.GetSnapPointCount();
514 Point
SdrVirtObj::GetSnapPoint(sal_uInt32 i
) const
516 Point
aP(rRefObj
.GetSnapPoint(i
));
521 bool SdrVirtObj::IsPolyObj() const
523 return rRefObj
.IsPolyObj();
526 sal_uInt32
SdrVirtObj::GetPointCount() const
528 return rRefObj
.GetPointCount();
531 Point
SdrVirtObj::GetPoint(sal_uInt32 i
) const
533 return Point(rRefObj
.GetPoint(i
) + aAnchor
);
536 void SdrVirtObj::NbcSetPoint(const Point
& rPnt
, sal_uInt32 i
)
540 rRefObj
.SetPoint(aP
,i
);
546 SdrObjGeoData
* SdrVirtObj::NewGeoData() const
548 return rRefObj
.NewGeoData();
551 void SdrVirtObj::SaveGeoData(SdrObjGeoData
& rGeo
) const
553 rRefObj
.SaveGeoData(rGeo
);
556 void SdrVirtObj::RestGeoData(const SdrObjGeoData
& rGeo
)
558 rRefObj
.RestGeoData(rGeo
);
564 SdrObjGeoData
* SdrVirtObj::GetGeoData() const
566 return rRefObj
.GetGeoData();
569 void SdrVirtObj::SetGeoData(const SdrObjGeoData
& rGeo
)
571 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
572 rRefObj
.SetGeoData(rGeo
);
574 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
579 void SdrVirtObj::NbcReformatText()
581 rRefObj
.NbcReformatText();
584 void SdrVirtObj::ReformatText()
586 rRefObj
.ReformatText();
591 bool SdrVirtObj::HasMacro() const
593 return rRefObj
.HasMacro();
596 SdrObject
* SdrVirtObj::CheckMacroHit(const SdrObjMacroHitRec
& rRec
) const
598 return rRefObj
.CheckMacroHit(rRec
); // TODO: positioning offset
601 Pointer
SdrVirtObj::GetMacroPointer(const SdrObjMacroHitRec
& rRec
) const
603 return rRefObj
.GetMacroPointer(rRec
); // TODO: positioning offset
606 void SdrVirtObj::PaintMacro(OutputDevice
& rOut
, const Rectangle
& rDirtyRect
, const SdrObjMacroHitRec
& rRec
) const
608 rRefObj
.PaintMacro(rOut
,rDirtyRect
,rRec
); // TODO: positioning offset
611 bool SdrVirtObj::DoMacro(const SdrObjMacroHitRec
& rRec
)
613 return rRefObj
.DoMacro(rRec
); // TODO: positioning offset
616 OUString
SdrVirtObj::GetMacroPopupComment(const SdrObjMacroHitRec
& rRec
) const
618 return rRefObj
.GetMacroPopupComment(rRec
); // TODO: positioning offset
621 const Point
SdrVirtObj::GetOffset() const
623 // #i73248# default offset of SdrVirtObj is aAnchor
627 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */