bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / svdraw / svdovirt.cxx
blob2e80aa5264880fbecf3e9b7da04d3036971bfc24
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>
32 ////////////////////////////////////////////////////////////////////////////////////////////////////
34 sdr::properties::BaseProperties& SdrVirtObj::GetProperties() const
36 return rRefObj.GetProperties();
39 ////////////////////////////////////////////////////////////////////////////////////////////////////
40 // #i27224#
41 sdr::contact::ViewContact* SdrVirtObj::CreateObjectSpecificViewContact()
43 return new sdr::contact::ViewContactOfVirtObj(*this);
46 ////////////////////////////////////////////////////////////////////////////////////////////////////
48 TYPEINIT1(SdrVirtObj,SdrObject);
50 SdrVirtObj::SdrVirtObj(SdrObject& rNewObj):
51 rRefObj(rNewObj)
53 bVirtObj=sal_True; // this is only a virtual object
54 rRefObj.AddReference(*this);
55 bClosedObj=rRefObj.IsClosedObj();
58 SdrVirtObj::~SdrVirtObj()
60 rRefObj.DelReference(*this);
63 ////////////////////////////////////////////////////////////////////////////////////////////////////
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;
89 ////////////////////////////////////////////////////////////////////////////////////////////////////
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 ((SdrVirtObj*)this)->aOutRect=rRefObj.GetCurrentBoundRect(); // TODO: Optimize this.
120 ((SdrVirtObj*)this)->aOutRect+=aAnchor;
121 return aOutRect;
124 const Rectangle& SdrVirtObj::GetLastBoundRect() const
126 ((SdrVirtObj*)this)->aOutRect=rRefObj.GetLastBoundRect(); // TODO: Optimize this.
127 ((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 void SdrVirtObj::TakeObjNameSingul(XubString& rName) const
156 rRefObj.TakeObjNameSingul(rName);
157 rName.Insert(sal_Unicode('['), 0);
158 rName += sal_Unicode(']');
160 String aName( GetName() );
161 if(aName.Len())
163 rName += sal_Unicode(' ');
164 rName += sal_Unicode('\'');
165 rName += aName;
166 rName += sal_Unicode('\'');
170 void SdrVirtObj::TakeObjNamePlural(XubString& rName) const
172 rRefObj.TakeObjNamePlural(rName);
173 rName.Insert(sal_Unicode('['), 0);
174 rName += sal_Unicode(']');
177 void operator +=(PolyPolygon& rPoly, const Point& rOfs)
179 if (rOfs.X()!=0 || rOfs.Y()!=0) {
180 sal_uInt16 i,j;
181 for (j=0; j<rPoly.Count(); j++) {
182 Polygon aP1(rPoly.GetObject(j));
183 for (i=0; i<aP1.GetSize(); i++) {
184 aP1[i]+=rOfs;
186 rPoly.Replace(aP1,j);
191 basegfx::B2DPolyPolygon SdrVirtObj::TakeXorPoly() const
193 basegfx::B2DPolyPolygon aPolyPolygon(rRefObj.TakeXorPoly());
195 if(aAnchor.X() || aAnchor.Y())
197 aPolyPolygon.transform(basegfx::tools::createTranslateB2DHomMatrix(aAnchor.X(), aAnchor.Y()));
200 return aPolyPolygon;
203 ////////////////////////////////////////////////////////////////////////////////////////////////////
205 sal_uInt32 SdrVirtObj::GetHdlCount() const
207 return rRefObj.GetHdlCount();
210 SdrHdl* SdrVirtObj::GetHdl(sal_uInt32 nHdlNum) const
212 SdrHdl* pHdl=rRefObj.GetHdl(nHdlNum);
214 // #i73248#
215 // GetHdl() at SdrObject is not guaranteed to return an object
216 if(pHdl)
218 Point aP(pHdl->GetPos()+aAnchor);
219 pHdl->SetPos(aP);
222 return pHdl;
225 sal_uInt32 SdrVirtObj::GetPlusHdlCount(const SdrHdl& rHdl) const
227 return rRefObj.GetPlusHdlCount(rHdl);
230 SdrHdl* SdrVirtObj::GetPlusHdl(const SdrHdl& rHdl, sal_uInt32 nPlNum) const
232 SdrHdl* pHdl=rRefObj.GetPlusHdl(rHdl,nPlNum);
233 pHdl->SetPos(pHdl->GetPos() + aAnchor);
234 return pHdl;
237 void SdrVirtObj::AddToHdlList(SdrHdlList& rHdlList) const
239 // #i73248#
240 // SdrObject::AddToHdlList(rHdlList) is not a good thing to call
241 // since at SdrPathObj, only AddToHdlList may be used and the call
242 // will instead use the standard implementation which uses GetHdlCount()
243 // and GetHdl instead. This is not wrong, but may be much less effective
244 // and may not be prepared to GetHdl returning NULL
246 // get handles using AddToHdlList from ref object
247 SdrHdlList aLocalList(0);
248 rRefObj.AddToHdlList(aLocalList);
249 const sal_uInt32 nHdlCount(aLocalList.GetHdlCount());
251 if(nHdlCount)
253 // translate handles and add them to dest list. They are temporarily part of
254 // two lists then
255 const Point aOffset(GetOffset());
257 for(sal_uInt32 a(0L); a < nHdlCount; a++)
259 SdrHdl* pCandidate = aLocalList.GetHdl(a);
260 pCandidate->SetPos(pCandidate->GetPos() + aOffset);
261 rHdlList.AddHdl(pCandidate);
264 // remove them from source list, else they will be deleted when
265 // source list is deleted
266 while(aLocalList.GetHdlCount())
268 aLocalList.RemoveHdl(aLocalList.GetHdlCount() - 1L);
273 ////////////////////////////////////////////////////////////////////////////////////////////////////
275 bool SdrVirtObj::hasSpecialDrag() const
277 return rRefObj.hasSpecialDrag();
280 bool SdrVirtObj::supportsFullDrag() const
282 return false;
285 SdrObject* SdrVirtObj::getFullDragClone() const
287 static bool bSpecialHandling(false);
288 SdrObject* pRetval = 0;
290 if(bSpecialHandling)
292 // special handling for VirtObj. Do not create another
293 // reference to rRefObj, this would allow to change that
294 // one on drag. Instead, create a SdrGrafObj for drag containing
295 // the graphical representation
296 pRetval = new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), this), GetLogicRect());
298 else
300 SdrObject& rReferencedObject = ((SdrVirtObj*)this)->ReferencedObj();
301 pRetval = new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), &rReferencedObject), GetLogicRect());
304 return pRetval;
307 bool SdrVirtObj::beginSpecialDrag(SdrDragStat& rDrag) const
309 return rRefObj.beginSpecialDrag(rDrag);
312 bool SdrVirtObj::applySpecialDrag(SdrDragStat& rDrag)
314 return rRefObj.applySpecialDrag(rDrag);
317 basegfx::B2DPolyPolygon SdrVirtObj::getSpecialDragPoly(const SdrDragStat& rDrag) const
319 return rRefObj.getSpecialDragPoly(rDrag);
320 // TODO: we don't handle offsets yet!
323 String SdrVirtObj::getSpecialDragComment(const SdrDragStat& rDrag) const
325 return rRefObj.getSpecialDragComment(rDrag);
328 ////////////////////////////////////////////////////////////////////////////////////////////////////
330 bool SdrVirtObj::BegCreate(SdrDragStat& rStat)
332 return rRefObj.BegCreate(rStat);
335 bool SdrVirtObj::MovCreate(SdrDragStat& rStat)
337 return rRefObj.MovCreate(rStat);
340 bool SdrVirtObj::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
342 return rRefObj.EndCreate(rStat,eCmd);
345 bool SdrVirtObj::BckCreate(SdrDragStat& rStat)
347 return rRefObj.BckCreate(rStat);
350 void SdrVirtObj::BrkCreate(SdrDragStat& rStat)
352 rRefObj.BrkCreate(rStat);
355 basegfx::B2DPolyPolygon SdrVirtObj::TakeCreatePoly(const SdrDragStat& rDrag) const
357 return rRefObj.TakeCreatePoly(rDrag);
358 // TODO: we don't handle offsets yet!
361 ////////////////////////////////////////////////////////////////////////////////////////////////////
363 void SdrVirtObj::NbcMove(const Size& rSiz)
365 MovePoint(aAnchor,rSiz);
366 SetRectsDirty();
369 void SdrVirtObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
371 rRefObj.NbcResize(rRef-aAnchor,xFact,yFact);
372 SetRectsDirty();
375 void SdrVirtObj::NbcRotate(const Point& rRef, long nWink, double sn, double cs)
377 rRefObj.NbcRotate(rRef-aAnchor,nWink,sn,cs);
378 SetRectsDirty();
381 void SdrVirtObj::NbcMirror(const Point& rRef1, const Point& rRef2)
383 rRefObj.NbcMirror(rRef1-aAnchor,rRef2-aAnchor);
384 SetRectsDirty();
387 void SdrVirtObj::NbcShear(const Point& rRef, long nWink, double tn, bool bVShear)
389 rRefObj.NbcShear(rRef-aAnchor,nWink,tn,bVShear);
390 SetRectsDirty();
393 ////////////////////////////////////////////////////////////////////////////////////////////////////
395 void SdrVirtObj::Move(const Size& rSiz)
397 if (rSiz.Width()!=0 || rSiz.Height()!=0) {
398 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
399 NbcMove(rSiz);
400 SetChanged();
401 BroadcastObjectChange();
402 SendUserCall(SDRUSERCALL_MOVEONLY,aBoundRect0);
406 void SdrVirtObj::Resize(const Point& rRef, const Fraction& xFact, const Fraction& yFact, bool bUnsetRelative)
408 if (xFact.GetNumerator()!=xFact.GetDenominator() || yFact.GetNumerator()!=yFact.GetDenominator()) {
409 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
410 rRefObj.Resize(rRef-aAnchor,xFact,yFact, bUnsetRelative);
411 SetRectsDirty();
412 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
416 void SdrVirtObj::Rotate(const Point& rRef, long nWink, double sn, double cs)
418 if (nWink!=0) {
419 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
420 rRefObj.Rotate(rRef-aAnchor,nWink,sn,cs);
421 SetRectsDirty();
422 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
426 void SdrVirtObj::Mirror(const Point& rRef1, const Point& rRef2)
428 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
429 rRefObj.Mirror(rRef1-aAnchor,rRef2-aAnchor);
430 SetRectsDirty();
431 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
434 void SdrVirtObj::Shear(const Point& rRef, long nWink, double tn, bool bVShear)
436 if (nWink!=0) {
437 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
438 rRefObj.Shear(rRef-aAnchor,nWink,tn,bVShear);
439 SetRectsDirty();
440 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
444 ////////////////////////////////////////////////////////////////////////////////////////////////////
446 void SdrVirtObj::RecalcSnapRect()
448 aSnapRect=rRefObj.GetSnapRect();
449 aSnapRect+=aAnchor;
452 const Rectangle& SdrVirtObj::GetSnapRect() const
454 ((SdrVirtObj*)this)->aSnapRect=rRefObj.GetSnapRect();
455 ((SdrVirtObj*)this)->aSnapRect+=aAnchor;
456 return aSnapRect;
459 void SdrVirtObj::SetSnapRect(const Rectangle& rRect)
462 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
463 Rectangle aR(rRect);
464 aR-=aAnchor;
465 rRefObj.SetSnapRect(aR);
466 SetRectsDirty();
467 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
471 void SdrVirtObj::NbcSetSnapRect(const Rectangle& rRect)
473 Rectangle aR(rRect);
474 aR-=aAnchor;
475 SetRectsDirty();
476 rRefObj.NbcSetSnapRect(aR);
479 ////////////////////////////////////////////////////////////////////////////////////////////////////
481 const Rectangle& SdrVirtObj::GetLogicRect() const
483 ((SdrVirtObj*)this)->aSnapRect=rRefObj.GetLogicRect(); // An abuse of aSnapRect!
484 ((SdrVirtObj*)this)->aSnapRect+=aAnchor; // If there's trouble, we need another Rectangle Member (or a Heap).
485 return aSnapRect;
488 void SdrVirtObj::SetLogicRect(const Rectangle& rRect)
490 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
491 Rectangle aR(rRect);
492 aR-=aAnchor;
493 rRefObj.SetLogicRect(aR);
494 SetRectsDirty();
495 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
498 void SdrVirtObj::NbcSetLogicRect(const Rectangle& rRect)
500 Rectangle aR(rRect);
501 aR-=aAnchor;
502 SetRectsDirty();
503 rRefObj.NbcSetLogicRect(aR);
506 ////////////////////////////////////////////////////////////////////////////////////////////////////
508 long SdrVirtObj::GetRotateAngle() const
510 return rRefObj.GetRotateAngle();
513 long SdrVirtObj::GetShearAngle(bool bVertical) const
515 return rRefObj.GetShearAngle(bVertical);
518 ////////////////////////////////////////////////////////////////////////////////////////////////////
520 sal_uInt32 SdrVirtObj::GetSnapPointCount() const
522 return rRefObj.GetSnapPointCount();
525 Point SdrVirtObj::GetSnapPoint(sal_uInt32 i) const
527 Point aP(rRefObj.GetSnapPoint(i));
528 aP+=aAnchor;
529 return aP;
532 sal_Bool SdrVirtObj::IsPolyObj() const
534 return rRefObj.IsPolyObj();
537 sal_uInt32 SdrVirtObj::GetPointCount() const
539 return rRefObj.GetPointCount();
542 Point SdrVirtObj::GetPoint(sal_uInt32 i) const
544 return Point(rRefObj.GetPoint(i) + aAnchor);
547 void SdrVirtObj::NbcSetPoint(const Point& rPnt, sal_uInt32 i)
549 Point aP(rPnt);
550 aP-=aAnchor;
551 rRefObj.SetPoint(aP,i);
552 SetRectsDirty();
555 ////////////////////////////////////////////////////////////////////////////////////////////////////
557 SdrObjGeoData* SdrVirtObj::NewGeoData() const
559 return rRefObj.NewGeoData();
562 void SdrVirtObj::SaveGeoData(SdrObjGeoData& rGeo) const
564 rRefObj.SaveGeoData(rGeo);
567 void SdrVirtObj::RestGeoData(const SdrObjGeoData& rGeo)
569 rRefObj.RestGeoData(rGeo);
570 SetRectsDirty();
573 ////////////////////////////////////////////////////////////////////////////////////////////////////
575 SdrObjGeoData* SdrVirtObj::GetGeoData() const
577 return rRefObj.GetGeoData();
580 void SdrVirtObj::SetGeoData(const SdrObjGeoData& rGeo)
582 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
583 rRefObj.SetGeoData(rGeo);
584 SetRectsDirty();
585 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
588 ////////////////////////////////////////////////////////////////////////////////////////////////////
590 void SdrVirtObj::NbcReformatText()
592 rRefObj.NbcReformatText();
595 void SdrVirtObj::ReformatText()
597 rRefObj.ReformatText();
600 ////////////////////////////////////////////////////////////////////////////////////////////////////
602 bool SdrVirtObj::HasMacro() const
604 return rRefObj.HasMacro();
607 SdrObject* SdrVirtObj::CheckMacroHit(const SdrObjMacroHitRec& rRec) const
609 return rRefObj.CheckMacroHit(rRec); // TODO: positioning offset
612 Pointer SdrVirtObj::GetMacroPointer(const SdrObjMacroHitRec& rRec) const
614 return rRefObj.GetMacroPointer(rRec); // TODO: positioning offset
617 void SdrVirtObj::PaintMacro(OutputDevice& rOut, const Rectangle& rDirtyRect, const SdrObjMacroHitRec& rRec) const
619 rRefObj.PaintMacro(rOut,rDirtyRect,rRec); // TODO: positioning offset
622 bool SdrVirtObj::DoMacro(const SdrObjMacroHitRec& rRec)
624 return rRefObj.DoMacro(rRec); // TODO: positioning offset
627 OUString SdrVirtObj::GetMacroPopupComment(const SdrObjMacroHitRec& rRec) const
629 return rRefObj.GetMacroPopupComment(rRec); // TODO: positioning offset
632 const Point SdrVirtObj::GetOffset() const
634 // #i73248# default offset of SdrVirtObj is aAnchor
635 return aAnchor;
638 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */