bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / svdraw / svdovirt.cxx
blob5cea7776090f9d900758022c2b5b00518e3df690
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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();
40 // #i27224#
41 sdr::contact::ViewContact* SdrVirtObj::CreateObjectSpecificViewContact()
43 return new sdr::contact::ViewContactOfVirtObj(*this);
48 TYPEINIT1(SdrVirtObj,SdrObject);
50 SdrVirtObj::SdrVirtObj(SdrObject& rNewObj):
51 rRefObj(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
67 return rRefObj;
70 SdrObject& SdrVirtObj::ReferencedObj()
72 return rRefObj;
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
81 ActionChanged();
84 void SdrVirtObj::NbcSetAnchorPos(const Point& rAnchorPos)
86 aAnchor=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;
121 return aOutRect;
124 const Rectangle& SdrVirtObj::GetLastBoundRect() const
126 const_cast<SdrVirtObj*>(this)->aOutRect=rRefObj.GetLastBoundRect(); // TODO: Optimize this.
127 const_cast<SdrVirtObj*>(this)->aOutRect+=aAnchor;
128 return aOutRect;
131 void SdrVirtObj::RecalcBoundRect()
133 aOutRect=rRefObj.GetCurrentBoundRect();
134 aOutRect+=aAnchor;
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;
151 return *this;
154 OUString SdrVirtObj::TakeObjNameSingul() const
156 OUStringBuffer sName(rRefObj.TakeObjNameSingul());
157 sName.insert(0, '[');
158 sName.append(']');
160 OUString aName(GetName());
161 if (!aName.isEmpty())
163 sName.append(' ');
164 sName.append('\'');
165 sName.append(aName);
166 sName.append('\'');
169 return sName.makeStringAndClear();
172 OUString SdrVirtObj::TakeObjNamePlural() const
174 OUStringBuffer sName(rRefObj.TakeObjNamePlural());
175 sName.insert(0, '[');
176 sName.append(']');
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()));
189 return aPolyPolygon;
194 sal_uInt32 SdrVirtObj::GetHdlCount() const
196 return rRefObj.GetHdlCount();
199 SdrHdl* SdrVirtObj::GetHdl(sal_uInt32 nHdlNum) const
201 SdrHdl* pHdl=rRefObj.GetHdl(nHdlNum);
203 // #i73248#
204 // GetHdl() at SdrObject is not guaranteed to return an object
205 if(pHdl)
207 Point aP(pHdl->GetPos()+aAnchor);
208 pHdl->SetPos(aP);
211 return pHdl;
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);
223 return pHdl;
226 void SdrVirtObj::AddToHdlList(SdrHdlList& rHdlList) const
228 // #i73248#
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());
240 if(nHdlCount)
242 // translate handles and add them to dest list. They are temporarily part of
243 // two lists then
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
271 return false;
274 SdrObject* SdrVirtObj::getFullDragClone() const
276 static bool bSpecialHandling(false);
277 SdrObject* pRetval = 0;
279 if(bSpecialHandling)
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());
287 else
289 SdrObject& rReferencedObject = const_cast<SdrVirtObj*>(this)->ReferencedObj();
290 pRetval = new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), &rReferencedObject), GetLogicRect());
293 return pRetval;
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);
355 SetRectsDirty();
358 void SdrVirtObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
360 rRefObj.NbcResize(rRef-aAnchor,xFact,yFact);
361 SetRectsDirty();
364 void SdrVirtObj::NbcRotate(const Point& rRef, long nAngle, double sn, double cs)
366 rRefObj.NbcRotate(rRef-aAnchor,nAngle,sn,cs);
367 SetRectsDirty();
370 void SdrVirtObj::NbcMirror(const Point& rRef1, const Point& rRef2)
372 rRefObj.NbcMirror(rRef1-aAnchor,rRef2-aAnchor);
373 SetRectsDirty();
376 void SdrVirtObj::NbcShear(const Point& rRef, long nAngle, double tn, bool bVShear)
378 rRefObj.NbcShear(rRef-aAnchor,nAngle,tn,bVShear);
379 SetRectsDirty();
384 void SdrVirtObj::Move(const Size& rSiz)
386 if (rSiz.Width()!=0 || rSiz.Height()!=0) {
387 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
388 NbcMove(rSiz);
389 SetChanged();
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);
400 SetRectsDirty();
401 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
405 void SdrVirtObj::Rotate(const Point& rRef, long nAngle, double sn, double cs)
407 if (nAngle!=0) {
408 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
409 rRefObj.Rotate(rRef-aAnchor,nAngle,sn,cs);
410 SetRectsDirty();
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);
419 SetRectsDirty();
420 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
423 void SdrVirtObj::Shear(const Point& rRef, long nAngle, double tn, bool bVShear)
425 if (nAngle!=0) {
426 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
427 rRefObj.Shear(rRef-aAnchor,nAngle,tn,bVShear);
428 SetRectsDirty();
429 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
435 void SdrVirtObj::RecalcSnapRect()
437 aSnapRect=rRefObj.GetSnapRect();
438 aSnapRect+=aAnchor;
441 const Rectangle& SdrVirtObj::GetSnapRect() const
443 const_cast<SdrVirtObj*>(this)->aSnapRect=rRefObj.GetSnapRect();
444 const_cast<SdrVirtObj*>(this)->aSnapRect+=aAnchor;
445 return aSnapRect;
448 void SdrVirtObj::SetSnapRect(const Rectangle& rRect)
451 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
452 Rectangle aR(rRect);
453 aR-=aAnchor;
454 rRefObj.SetSnapRect(aR);
455 SetRectsDirty();
456 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
460 void SdrVirtObj::NbcSetSnapRect(const Rectangle& rRect)
462 Rectangle aR(rRect);
463 aR-=aAnchor;
464 SetRectsDirty();
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).
474 return aSnapRect;
477 void SdrVirtObj::SetLogicRect(const Rectangle& rRect)
479 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
480 Rectangle aR(rRect);
481 aR-=aAnchor;
482 rRefObj.SetLogicRect(aR);
483 SetRectsDirty();
484 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
487 void SdrVirtObj::NbcSetLogicRect(const Rectangle& rRect)
489 Rectangle aR(rRect);
490 aR-=aAnchor;
491 SetRectsDirty();
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));
517 aP+=aAnchor;
518 return aP;
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)
538 Point aP(rPnt);
539 aP-=aAnchor;
540 rRefObj.SetPoint(aP,i);
541 SetRectsDirty();
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);
559 SetRectsDirty();
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);
573 SetRectsDirty();
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
624 return aAnchor;
627 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */