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/svdhdl.hxx>
23 #include <svx/sdr/contact/viewcontactofvirtobj.hxx>
24 #include <svx/svdograf.hxx>
25 #include <svx/svddrgv.hxx>
26 #include <basegfx/matrix/b2dhommatrixtools.hxx>
27 #include <rtl/ustrbuf.hxx>
29 sdr::properties::BaseProperties
& SdrVirtObj::GetProperties() const
31 return rRefObj
.GetProperties();
36 std::unique_ptr
<sdr::contact::ViewContact
> SdrVirtObj::CreateObjectSpecificViewContact()
38 return std::make_unique
<sdr::contact::ViewContactOfVirtObj
>(*this);
41 SdrVirtObj::SdrVirtObj(
44 : SdrObject(rSdrModel
),
47 bVirtObj
=true; // this is only a virtual object
48 rRefObj
.AddReference(*this);
49 bClosedObj
=rRefObj
.IsClosedObj();
52 SdrVirtObj::~SdrVirtObj()
54 rRefObj
.DelReference(*this);
57 const SdrObject
& SdrVirtObj::GetReferencedObj() const
62 SdrObject
& SdrVirtObj::ReferencedObj()
67 void SdrVirtObj::Notify(SfxBroadcaster
& /*rBC*/, const SfxHint
& /*rHint*/)
69 bClosedObj
=rRefObj
.IsClosedObj();
70 SetRectsDirty(); // TODO: Optimize this.
72 // Only a repaint here, rRefObj may have changed and broadcasts
76 void SdrVirtObj::NbcSetAnchorPos(const Point
& rAnchorPos
)
81 void SdrVirtObj::TakeObjInfo(SdrObjTransformInfoRec
& rInfo
) const
83 rRefObj
.TakeObjInfo(rInfo
);
86 SdrInventor
SdrVirtObj::GetObjInventor() const
88 return rRefObj
.GetObjInventor();
91 SdrObjKind
SdrVirtObj::GetObjIdentifier() const
93 return rRefObj
.GetObjIdentifier();
96 SdrObjList
* SdrVirtObj::GetSubList() const
98 return rRefObj
.GetSubList();
101 const tools::Rectangle
& SdrVirtObj::GetCurrentBoundRect() const
103 const_cast<SdrVirtObj
*>(this)->aOutRect
=rRefObj
.GetCurrentBoundRect(); // TODO: Optimize this.
104 const_cast<SdrVirtObj
*>(this)->aOutRect
+=aAnchor
;
108 const tools::Rectangle
& SdrVirtObj::GetLastBoundRect() const
110 const_cast<SdrVirtObj
*>(this)->aOutRect
=rRefObj
.GetLastBoundRect(); // TODO: Optimize this.
111 const_cast<SdrVirtObj
*>(this)->aOutRect
+=aAnchor
;
115 void SdrVirtObj::RecalcBoundRect()
117 aOutRect
=rRefObj
.GetCurrentBoundRect();
121 SdrVirtObj
* SdrVirtObj::CloneSdrObject(SdrModel
& rTargetModel
) const
123 return CloneHelper
< SdrVirtObj
>(rTargetModel
);
124 // TTTT not sure if the above works - how could SdrObjFactory::MakeNewObject
125 // create an object with correct rRefObj (?) OTOH VirtObj probably needs not
126 // to be cloned ever - only used in Writer for multiple instances e.g. Header/Footer
127 // return new SdrVirtObj(
128 // getSdrModelFromSdrObject(),
129 // rRefObj); // only a further reference
132 SdrVirtObj
& SdrVirtObj::operator=(const SdrVirtObj
& rObj
)
134 SdrObject::operator=(rObj
);
136 // reference different object?? TTTT -> yes!
137 rRefObj
.DelReference(*this);
138 rRefObj
= rObj
.rRefObj
;
139 rRefObj
.AddReference(*this);
141 aSnapRect
= rObj
.aSnapRect
;
142 aAnchor
= rObj
.aAnchor
;
147 OUString
SdrVirtObj::TakeObjNameSingul() const
149 OUStringBuffer
sName(rRefObj
.TakeObjNameSingul());
150 sName
.insert(0, '[');
153 OUString
aName(GetName());
154 if (!aName
.isEmpty())
162 return sName
.makeStringAndClear();
165 OUString
SdrVirtObj::TakeObjNamePlural() const
167 OUStringBuffer
sName(rRefObj
.TakeObjNamePlural());
168 sName
.insert(0, '[');
170 return sName
.makeStringAndClear();
173 bool SdrVirtObj::HasLimitedRotation() const
175 // RotGrfFlyFrame: If true, this SdrObject supports only limited rotation
176 return rRefObj
.HasLimitedRotation();
179 basegfx::B2DPolyPolygon
SdrVirtObj::TakeXorPoly() const
181 basegfx::B2DPolyPolygon
aPolyPolygon(rRefObj
.TakeXorPoly());
183 if(aAnchor
.X() || aAnchor
.Y())
185 aPolyPolygon
.transform(basegfx::utils::createTranslateB2DHomMatrix(aAnchor
.X(), aAnchor
.Y()));
192 sal_uInt32
SdrVirtObj::GetHdlCount() const
194 return rRefObj
.GetHdlCount();
197 void SdrVirtObj::AddToHdlList(SdrHdlList
& rHdlList
) const
199 SdrHdlList
tempList(nullptr);
200 rRefObj
.AddToHdlList(tempList
);
201 for (size_t i
=0; i
<tempList
.GetHdlCount(); ++i
)
203 SdrHdl
* pHdl
= tempList
.GetHdl(i
);
204 Point
aP(pHdl
->GetPos()+aAnchor
);
207 tempList
.MoveTo(rHdlList
);
210 void SdrVirtObj::AddToPlusHdlList(SdrHdlList
& rHdlList
, SdrHdl
& rHdl
) const
212 SdrHdlList
tempList(nullptr);
213 rRefObj
.AddToPlusHdlList(tempList
, rHdl
);
214 for (size_t i
=0; i
<tempList
.GetHdlCount(); ++i
)
216 SdrHdl
* pHdl
= tempList
.GetHdl(i
);
217 Point
aP(pHdl
->GetPos()+aAnchor
);
220 tempList
.MoveTo(rHdlList
);
223 bool SdrVirtObj::hasSpecialDrag() const
225 return rRefObj
.hasSpecialDrag();
228 bool SdrVirtObj::supportsFullDrag() const
233 SdrObjectUniquePtr
SdrVirtObj::getFullDragClone() const
235 SdrObject
& rReferencedObject
= const_cast<SdrVirtObj
*>(this)->ReferencedObj();
236 return SdrObjectUniquePtr(new SdrGrafObj(
237 getSdrModelFromSdrObject(),
238 SdrDragView::GetObjGraphic(rReferencedObject
),
242 bool SdrVirtObj::beginSpecialDrag(SdrDragStat
& rDrag
) const
244 return rRefObj
.beginSpecialDrag(rDrag
);
247 bool SdrVirtObj::applySpecialDrag(SdrDragStat
& rDrag
)
249 return rRefObj
.applySpecialDrag(rDrag
);
252 basegfx::B2DPolyPolygon
SdrVirtObj::getSpecialDragPoly(const SdrDragStat
& rDrag
) const
254 return rRefObj
.getSpecialDragPoly(rDrag
);
255 // TODO: we don't handle offsets yet!
258 OUString
SdrVirtObj::getSpecialDragComment(const SdrDragStat
& rDrag
) const
260 return rRefObj
.getSpecialDragComment(rDrag
);
264 bool SdrVirtObj::BegCreate(SdrDragStat
& rStat
)
266 return rRefObj
.BegCreate(rStat
);
269 bool SdrVirtObj::MovCreate(SdrDragStat
& rStat
)
271 return rRefObj
.MovCreate(rStat
);
274 bool SdrVirtObj::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
276 return rRefObj
.EndCreate(rStat
,eCmd
);
279 bool SdrVirtObj::BckCreate(SdrDragStat
& rStat
)
281 return rRefObj
.BckCreate(rStat
);
284 void SdrVirtObj::BrkCreate(SdrDragStat
& rStat
)
286 rRefObj
.BrkCreate(rStat
);
289 basegfx::B2DPolyPolygon
SdrVirtObj::TakeCreatePoly(const SdrDragStat
& rDrag
) const
291 return rRefObj
.TakeCreatePoly(rDrag
);
292 // TODO: we don't handle offsets yet!
296 void SdrVirtObj::NbcMove(const Size
& rSiz
)
302 void SdrVirtObj::NbcResize(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
)
304 rRefObj
.NbcResize(rRef
-aAnchor
,xFact
,yFact
);
308 void SdrVirtObj::NbcRotate(const Point
& rRef
, tools::Long nAngle
, double sn
, double cs
)
310 rRefObj
.NbcRotate(rRef
-aAnchor
,nAngle
,sn
,cs
);
314 void SdrVirtObj::NbcMirror(const Point
& rRef1
, const Point
& rRef2
)
316 rRefObj
.NbcMirror(rRef1
-aAnchor
,rRef2
-aAnchor
);
320 void SdrVirtObj::NbcShear(const Point
& rRef
, tools::Long nAngle
, double tn
, bool bVShear
)
322 rRefObj
.NbcShear(rRef
-aAnchor
,nAngle
,tn
,bVShear
);
327 void SdrVirtObj::Move(const Size
& rSiz
)
329 if (!rSiz
.IsEmpty()) {
330 tools::Rectangle aBoundRect0
; if (pUserCall
!=nullptr) aBoundRect0
=GetLastBoundRect();
333 BroadcastObjectChange();
334 SendUserCall(SdrUserCallType::MoveOnly
,aBoundRect0
);
338 void SdrVirtObj::Resize(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
, bool bUnsetRelative
)
340 if (xFact
.GetNumerator()!=xFact
.GetDenominator() || yFact
.GetNumerator()!=yFact
.GetDenominator()) {
341 tools::Rectangle aBoundRect0
; if (pUserCall
!=nullptr) aBoundRect0
=GetLastBoundRect();
342 rRefObj
.Resize(rRef
-aAnchor
,xFact
,yFact
, bUnsetRelative
);
344 SendUserCall(SdrUserCallType::Resize
,aBoundRect0
);
348 void SdrVirtObj::Rotate(const Point
& rRef
, tools::Long nAngle
, double sn
, double cs
)
351 tools::Rectangle aBoundRect0
; if (pUserCall
!=nullptr) aBoundRect0
=GetLastBoundRect();
352 rRefObj
.Rotate(rRef
-aAnchor
,nAngle
,sn
,cs
);
354 SendUserCall(SdrUserCallType::Resize
,aBoundRect0
);
358 void SdrVirtObj::Mirror(const Point
& rRef1
, const Point
& rRef2
)
360 tools::Rectangle aBoundRect0
; if (pUserCall
!=nullptr) aBoundRect0
=GetLastBoundRect();
361 rRefObj
.Mirror(rRef1
-aAnchor
,rRef2
-aAnchor
);
363 SendUserCall(SdrUserCallType::Resize
,aBoundRect0
);
366 void SdrVirtObj::Shear(const Point
& rRef
, tools::Long nAngle
, double tn
, bool bVShear
)
369 tools::Rectangle aBoundRect0
; if (pUserCall
!=nullptr) aBoundRect0
=GetLastBoundRect();
370 rRefObj
.Shear(rRef
-aAnchor
,nAngle
,tn
,bVShear
);
372 SendUserCall(SdrUserCallType::Resize
,aBoundRect0
);
377 void SdrVirtObj::RecalcSnapRect()
379 aSnapRect
=rRefObj
.GetSnapRect();
383 const tools::Rectangle
& SdrVirtObj::GetSnapRect() const
385 const_cast<SdrVirtObj
*>(this)->aSnapRect
=rRefObj
.GetSnapRect();
386 const_cast<SdrVirtObj
*>(this)->aSnapRect
+=aAnchor
;
390 void SdrVirtObj::SetSnapRect(const tools::Rectangle
& rRect
)
392 tools::Rectangle aBoundRect0
; if (pUserCall
!=nullptr) aBoundRect0
=GetLastBoundRect();
393 tools::Rectangle
aR(rRect
);
395 rRefObj
.SetSnapRect(aR
);
397 SendUserCall(SdrUserCallType::Resize
,aBoundRect0
);
400 void SdrVirtObj::NbcSetSnapRect(const tools::Rectangle
& rRect
)
402 tools::Rectangle
aR(rRect
);
405 rRefObj
.NbcSetSnapRect(aR
);
409 const tools::Rectangle
& SdrVirtObj::GetLogicRect() const
411 const_cast<SdrVirtObj
*>(this)->aSnapRect
=rRefObj
.GetLogicRect(); // An abuse of aSnapRect!
412 const_cast<SdrVirtObj
*>(this)->aSnapRect
+=aAnchor
; // If there's trouble, we need another Rectangle Member (or a Heap).
416 void SdrVirtObj::SetLogicRect(const tools::Rectangle
& rRect
)
418 tools::Rectangle aBoundRect0
; if (pUserCall
!=nullptr) aBoundRect0
=GetLastBoundRect();
419 tools::Rectangle
aR(rRect
);
421 rRefObj
.SetLogicRect(aR
);
423 SendUserCall(SdrUserCallType::Resize
,aBoundRect0
);
426 void SdrVirtObj::NbcSetLogicRect(const tools::Rectangle
& rRect
)
428 tools::Rectangle
aR(rRect
);
431 rRefObj
.NbcSetLogicRect(aR
);
435 tools::Long
SdrVirtObj::GetRotateAngle() const
437 return rRefObj
.GetRotateAngle();
440 tools::Long
SdrVirtObj::GetShearAngle(bool bVertical
) const
442 return rRefObj
.GetShearAngle(bVertical
);
446 sal_uInt32
SdrVirtObj::GetSnapPointCount() const
448 return rRefObj
.GetSnapPointCount();
451 Point
SdrVirtObj::GetSnapPoint(sal_uInt32 i
) const
453 Point
aP(rRefObj
.GetSnapPoint(i
));
458 bool SdrVirtObj::IsPolyObj() const
460 return rRefObj
.IsPolyObj();
463 sal_uInt32
SdrVirtObj::GetPointCount() const
465 return rRefObj
.GetPointCount();
468 Point
SdrVirtObj::GetPoint(sal_uInt32 i
) const
470 return rRefObj
.GetPoint(i
) + aAnchor
;
473 void SdrVirtObj::NbcSetPoint(const Point
& rPnt
, sal_uInt32 i
)
477 rRefObj
.SetPoint(aP
,i
);
482 SdrObjGeoData
* SdrVirtObj::NewGeoData() const
484 return rRefObj
.NewGeoData();
487 void SdrVirtObj::SaveGeoData(SdrObjGeoData
& rGeo
) const
489 rRefObj
.SaveGeoData(rGeo
);
492 void SdrVirtObj::RestGeoData(const SdrObjGeoData
& rGeo
)
494 rRefObj
.RestGeoData(rGeo
);
499 SdrObjGeoData
* SdrVirtObj::GetGeoData() const
501 return rRefObj
.GetGeoData();
504 void SdrVirtObj::SetGeoData(const SdrObjGeoData
& rGeo
)
506 tools::Rectangle aBoundRect0
; if (pUserCall
!=nullptr) aBoundRect0
=GetLastBoundRect();
507 rRefObj
.SetGeoData(rGeo
);
509 SendUserCall(SdrUserCallType::Resize
,aBoundRect0
);
513 void SdrVirtObj::NbcReformatText()
515 rRefObj
.NbcReformatText();
518 bool SdrVirtObj::HasMacro() const
520 return rRefObj
.HasMacro();
523 SdrObject
* SdrVirtObj::CheckMacroHit(const SdrObjMacroHitRec
& rRec
) const
525 return rRefObj
.CheckMacroHit(rRec
); // TODO: positioning offset
528 PointerStyle
SdrVirtObj::GetMacroPointer(const SdrObjMacroHitRec
& rRec
) const
530 return rRefObj
.GetMacroPointer(rRec
); // TODO: positioning offset
533 void SdrVirtObj::PaintMacro(OutputDevice
& rOut
, const tools::Rectangle
& rDirtyRect
, const SdrObjMacroHitRec
& rRec
) const
535 rRefObj
.PaintMacro(rOut
,rDirtyRect
,rRec
); // TODO: positioning offset
538 bool SdrVirtObj::DoMacro(const SdrObjMacroHitRec
& rRec
)
540 return rRefObj
.DoMacro(rRec
); // TODO: positioning offset
543 Point
SdrVirtObj::GetOffset() const
545 // #i73248# default offset of SdrVirtObj is aAnchor
549 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */