Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / svx / source / svdraw / svdovirt.cxx
blob8bb8190bdd70be0e52e4fe7226c52d4993f9193c
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 ////////////////////////////////////////////////////////////////////////////////////////////////////
49 // #i27224#
50 sdr::contact::ViewContact* SdrVirtObj::CreateObjectSpecificViewContact()
52 return new sdr::contact::ViewContactOfVirtObj(*this);
55 ////////////////////////////////////////////////////////////////////////////////////////////////////
57 TYPEINIT1(SdrVirtObj,SdrObject);
59 SdrVirtObj::SdrVirtObj(SdrObject& rNewObj):
60 rRefObj(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
76 return rRefObj;
79 SdrObject& SdrVirtObj::ReferencedObj()
81 return rRefObj;
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
90 ActionChanged();
93 void SdrVirtObj::NbcSetAnchorPos(const Point& rAnchorPos)
95 aAnchor=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;
130 return aOutRect;
133 const Rectangle& SdrVirtObj::GetLastBoundRect() const
135 ((SdrVirtObj*)this)->aOutRect=rRefObj.GetLastBoundRect(); // TODO: Optimize this.
136 ((SdrVirtObj*)this)->aOutRect+=aAnchor;
137 return aOutRect;
140 void SdrVirtObj::RecalcBoundRect()
142 aOutRect=rRefObj.GetCurrentBoundRect();
143 aOutRect+=aAnchor;
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;
160 return *this;
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() );
170 if(aName.Len())
172 rName += sal_Unicode(' ');
173 rName += sal_Unicode('\'');
174 rName += aName;
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) {
189 sal_uInt16 i,j;
190 for (j=0; j<rPoly.Count(); j++) {
191 Polygon aP1(rPoly.GetObject(j));
192 for (i=0; i<aP1.GetSize(); i++) {
193 aP1[i]+=rOfs;
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()));
209 return aPolyPolygon;
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);
223 // #i73248#
224 // GetHdl() at SdrObject is not guaranteed to return an object
225 if(pHdl)
227 Point aP(pHdl->GetPos()+aAnchor);
228 pHdl->SetPos(aP);
231 return pHdl;
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);
243 return pHdl;
246 void SdrVirtObj::AddToHdlList(SdrHdlList& rHdlList) const
248 // #i73248#
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());
260 if(nHdlCount)
262 // translate handles and add them to dest list. They are temporarily part of
263 // two lists then
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
291 return false;
294 SdrObject* SdrVirtObj::getFullDragClone() const
296 static bool bSpecialHandling(false);
297 SdrObject* pRetval = 0;
299 if(bSpecialHandling)
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());
307 else
309 SdrObject& rReferencedObject = ((SdrVirtObj*)this)->ReferencedObj();
310 pRetval = new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), &rReferencedObject), GetLogicRect());
313 return pRetval;
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);
375 SetRectsDirty();
378 void SdrVirtObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
380 rRefObj.NbcResize(rRef-aAnchor,xFact,yFact);
381 SetRectsDirty();
384 void SdrVirtObj::NbcRotate(const Point& rRef, long nWink, double sn, double cs)
386 rRefObj.NbcRotate(rRef-aAnchor,nWink,sn,cs);
387 SetRectsDirty();
390 void SdrVirtObj::NbcMirror(const Point& rRef1, const Point& rRef2)
392 rRefObj.NbcMirror(rRef1-aAnchor,rRef2-aAnchor);
393 SetRectsDirty();
396 void SdrVirtObj::NbcShear(const Point& rRef, long nWink, double tn, bool bVShear)
398 rRefObj.NbcShear(rRef-aAnchor,nWink,tn,bVShear);
399 SetRectsDirty();
402 ////////////////////////////////////////////////////////////////////////////////////////////////////
404 void SdrVirtObj::Move(const Size& rSiz)
406 if (rSiz.Width()!=0 || rSiz.Height()!=0) {
407 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
408 NbcMove(rSiz);
409 SetChanged();
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);
420 SetRectsDirty();
421 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
425 void SdrVirtObj::Rotate(const Point& rRef, long nWink, double sn, double cs)
427 if (nWink!=0) {
428 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
429 rRefObj.Rotate(rRef-aAnchor,nWink,sn,cs);
430 SetRectsDirty();
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);
439 SetRectsDirty();
440 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
443 void SdrVirtObj::Shear(const Point& rRef, long nWink, double tn, bool bVShear)
445 if (nWink!=0) {
446 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
447 rRefObj.Shear(rRef-aAnchor,nWink,tn,bVShear);
448 SetRectsDirty();
449 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
453 ////////////////////////////////////////////////////////////////////////////////////////////////////
455 void SdrVirtObj::RecalcSnapRect()
457 aSnapRect=rRefObj.GetSnapRect();
458 aSnapRect+=aAnchor;
461 const Rectangle& SdrVirtObj::GetSnapRect() const
463 ((SdrVirtObj*)this)->aSnapRect=rRefObj.GetSnapRect();
464 ((SdrVirtObj*)this)->aSnapRect+=aAnchor;
465 return aSnapRect;
468 void SdrVirtObj::SetSnapRect(const Rectangle& rRect)
471 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
472 Rectangle aR(rRect);
473 aR-=aAnchor;
474 rRefObj.SetSnapRect(aR);
475 SetRectsDirty();
476 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
480 void SdrVirtObj::NbcSetSnapRect(const Rectangle& rRect)
482 Rectangle aR(rRect);
483 aR-=aAnchor;
484 SetRectsDirty();
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).
494 return aSnapRect;
497 void SdrVirtObj::SetLogicRect(const Rectangle& rRect)
499 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
500 Rectangle aR(rRect);
501 aR-=aAnchor;
502 rRefObj.SetLogicRect(aR);
503 SetRectsDirty();
504 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
507 void SdrVirtObj::NbcSetLogicRect(const Rectangle& rRect)
509 Rectangle aR(rRect);
510 aR-=aAnchor;
511 SetRectsDirty();
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));
537 aP+=aAnchor;
538 return aP;
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)
558 Point aP(rPnt);
559 aP-=aAnchor;
560 rRefObj.SetPoint(aP,i);
561 SetRectsDirty();
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);
579 SetRectsDirty();
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);
593 SetRectsDirty();
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
644 return aAnchor;
647 // eof
649 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */