merge the formfield patch from ooo-build
[ooovba.git] / svx / source / svdraw / svdovirt.cxx
blob63ff2ef6692f4d8c26b5e24c8f3d8b1df19bab68
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svdovirt.cxx,v $
10 * $Revision: 1.21.18.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <svx/svdovirt.hxx>
35 #include <svx/xpool.hxx>
36 #include <svx/svdtrans.hxx>
37 #include <svx/svdetc.hxx>
38 #include <svx/svdhdl.hxx>
39 #include <svx/sdr/contact/viewcontactofvirtobj.hxx>
40 #include <basegfx/matrix/b2dhommatrix.hxx>
41 #include <svx/svdograf.hxx>
42 #include <svx/svddrgv.hxx>
44 ////////////////////////////////////////////////////////////////////////////////////////////////////
46 sdr::properties::BaseProperties& SdrVirtObj::GetProperties() const
48 return rRefObj.GetProperties();
51 ////////////////////////////////////////////////////////////////////////////////////////////////////
52 // AW, OD 2004-05-03 #i27224#
53 sdr::contact::ViewContact* SdrVirtObj::CreateObjectSpecificViewContact()
55 return new sdr::contact::ViewContactOfVirtObj(*this);
58 ////////////////////////////////////////////////////////////////////////////////////////////////////
60 TYPEINIT1(SdrVirtObj,SdrObject);
62 SdrVirtObj::SdrVirtObj(SdrObject& rNewObj):
63 rRefObj(rNewObj)
65 bVirtObj=TRUE; // Ja, ich bin ein virtuelles Objekt
66 rRefObj.AddReference(*this);
67 bClosedObj=rRefObj.IsClosedObj();
70 SdrVirtObj::SdrVirtObj(SdrObject& rNewObj, const Point& rAnchorPos):
71 rRefObj(rNewObj)
73 aAnchor=rAnchorPos;
74 bVirtObj=TRUE; // Ja, ich bin ein virtuelles Objekt
75 rRefObj.AddReference(*this);
76 bClosedObj=rRefObj.IsClosedObj();
79 SdrVirtObj::~SdrVirtObj()
81 rRefObj.DelReference(*this);
84 ////////////////////////////////////////////////////////////////////////////////////////////////////
86 const SdrObject& SdrVirtObj::GetReferencedObj() const
88 return rRefObj;
91 SdrObject& SdrVirtObj::ReferencedObj()
93 return rRefObj;
96 void __EXPORT SdrVirtObj::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& /*rHint*/)
98 bClosedObj=rRefObj.IsClosedObj();
99 SetRectsDirty(); // hier noch Optimieren.
101 // Only a repaint here, rRefObj may have changed and broadcasts
102 ActionChanged();
103 // BroadcastObjectChange();
106 void SdrVirtObj::NbcSetAnchorPos(const Point& rAnchorPos)
108 aAnchor=rAnchorPos;
111 ////////////////////////////////////////////////////////////////////////////////////////////////////
113 void SdrVirtObj::SetModel(SdrModel* pNewModel)
115 SdrObject::SetModel(pNewModel);
116 rRefObj.SetModel(pNewModel);
119 void SdrVirtObj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
121 rRefObj.TakeObjInfo(rInfo);
124 UINT32 SdrVirtObj::GetObjInventor() const
126 return rRefObj.GetObjInventor();
129 UINT16 SdrVirtObj::GetObjIdentifier() const
131 return rRefObj.GetObjIdentifier();
134 SdrObjList* SdrVirtObj::GetSubList() const
136 return rRefObj.GetSubList();
139 const Rectangle& SdrVirtObj::GetCurrentBoundRect() const
141 ((SdrVirtObj*)this)->aOutRect=rRefObj.GetCurrentBoundRect(); // Hier noch optimieren
142 ((SdrVirtObj*)this)->aOutRect+=aAnchor;
143 return aOutRect;
146 const Rectangle& SdrVirtObj::GetLastBoundRect() const
148 ((SdrVirtObj*)this)->aOutRect=rRefObj.GetLastBoundRect(); // Hier noch optimieren
149 ((SdrVirtObj*)this)->aOutRect+=aAnchor;
150 return aOutRect;
153 void SdrVirtObj::RecalcBoundRect()
155 aOutRect=rRefObj.GetCurrentBoundRect();
156 aOutRect+=aAnchor;
159 void SdrVirtObj::SetChanged()
161 SdrObject::SetChanged();
164 SdrObject* SdrVirtObj::Clone() const
166 SdrObject* pObj=new SdrVirtObj(((SdrVirtObj*)this)->rRefObj); // Nur eine weitere Referenz
167 return pObj;
170 void SdrVirtObj::operator=(const SdrObject& rObj)
171 { // ???anderes Objekt referenzieren???
172 SdrObject::operator=(rObj);
173 aAnchor=((SdrVirtObj&)rObj).aAnchor;
176 void SdrVirtObj::TakeObjNameSingul(XubString& rName) const
178 rRefObj.TakeObjNameSingul(rName);
179 rName.Insert(sal_Unicode('['), 0);
180 rName += sal_Unicode(']');
182 String aName( GetName() );
183 if(aName.Len())
185 rName += sal_Unicode(' ');
186 rName += sal_Unicode('\'');
187 rName += aName;
188 rName += sal_Unicode('\'');
192 void SdrVirtObj::TakeObjNamePlural(XubString& rName) const
194 rRefObj.TakeObjNamePlural(rName);
195 rName.Insert(sal_Unicode('['), 0);
196 rName += sal_Unicode(']');
199 void operator +=(PolyPolygon& rPoly, const Point& rOfs)
201 if (rOfs.X()!=0 || rOfs.Y()!=0) {
202 USHORT i,j;
203 for (j=0; j<rPoly.Count(); j++) {
204 Polygon aP1(rPoly.GetObject(j));
205 for (i=0; i<aP1.GetSize(); i++) {
206 aP1[i]+=rOfs;
208 rPoly.Replace(aP1,j);
213 basegfx::B2DPolyPolygon SdrVirtObj::TakeXorPoly() const
215 basegfx::B2DPolyPolygon aPolyPolygon(rRefObj.TakeXorPoly());
217 if(aAnchor.X() || aAnchor.Y())
219 basegfx::B2DHomMatrix aMatrix;
220 aMatrix.translate(aAnchor.X(), aAnchor.Y());
221 aPolyPolygon.transform(aMatrix);
224 return aPolyPolygon;
227 ////////////////////////////////////////////////////////////////////////////////////////////////////
229 sal_uInt32 SdrVirtObj::GetHdlCount() const
231 return rRefObj.GetHdlCount();
234 SdrHdl* SdrVirtObj::GetHdl(sal_uInt32 nHdlNum) const
236 SdrHdl* pHdl=rRefObj.GetHdl(nHdlNum);
238 // #i73248#
239 // GetHdl() at SdrObject is not guaranteed to return an object
240 if(pHdl)
242 Point aP(pHdl->GetPos()+aAnchor);
243 pHdl->SetPos(aP);
246 return pHdl;
249 sal_uInt32 SdrVirtObj::GetPlusHdlCount(const SdrHdl& rHdl) const
251 return rRefObj.GetPlusHdlCount(rHdl);
254 SdrHdl* SdrVirtObj::GetPlusHdl(const SdrHdl& rHdl, sal_uInt32 nPlNum) const
256 SdrHdl* pHdl=rRefObj.GetPlusHdl(rHdl,nPlNum);
257 pHdl->SetPos(pHdl->GetPos() + aAnchor);
258 return pHdl;
261 void SdrVirtObj::AddToHdlList(SdrHdlList& rHdlList) const
263 // #i73248#
264 // SdrObject::AddToHdlList(rHdlList) is not a good thing to call
265 // since at SdrPathObj, only AddToHdlList may be used and the call
266 // will instead use the standard implementation which uses GetHdlCount()
267 // and GetHdl instead. This is not wrong, but may be much less effective
268 // and may not be prepared to GetHdl returning NULL
270 // get handles using AddToHdlList from ref object
271 SdrHdlList aLocalList(0);
272 rRefObj.AddToHdlList(aLocalList);
273 const sal_uInt32 nHdlCount(aLocalList.GetHdlCount());
275 if(nHdlCount)
277 // translate handles and add them to dest list. They are temporarily part of
278 // two lists then
279 const Point aOffset(GetOffset());
281 for(sal_uInt32 a(0L); a < nHdlCount; a++)
283 SdrHdl* pCandidate = aLocalList.GetHdl(a);
284 pCandidate->SetPos(pCandidate->GetPos() + aOffset);
285 rHdlList.AddHdl(pCandidate);
288 // remove them from source list, else they will be deleted when
289 // source list is deleted
290 while(aLocalList.GetHdlCount())
292 aLocalList.RemoveHdl(aLocalList.GetHdlCount() - 1L);
297 ////////////////////////////////////////////////////////////////////////////////////////////////////
299 bool SdrVirtObj::hasSpecialDrag() const
301 return rRefObj.hasSpecialDrag();
304 bool SdrVirtObj::supportsFullDrag() const
306 return false;
309 SdrObject* SdrVirtObj::getFullDragClone() const
311 static bool bSpecialHandling(false);
312 SdrObject* pRetval = 0;
314 if(bSpecialHandling)
316 // special handling for VirtObj. Do not create another
317 // reference to rRefObj, this would allow to change that
318 // one on drag. Instead, create a SdrGrafObj for drag containing
319 // the graphical representation
320 pRetval = new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), this), GetLogicRect());
322 else
324 SdrObject& rReferencedObject = ((SdrVirtObj*)this)->ReferencedObj();
325 pRetval = new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), &rReferencedObject), GetLogicRect());
328 return pRetval;
331 bool SdrVirtObj::beginSpecialDrag(SdrDragStat& rDrag) const
333 return rRefObj.beginSpecialDrag(rDrag);
336 bool SdrVirtObj::applySpecialDrag(SdrDragStat& rDrag)
338 return rRefObj.applySpecialDrag(rDrag);
341 basegfx::B2DPolyPolygon SdrVirtObj::getSpecialDragPoly(const SdrDragStat& rDrag) const
343 return rRefObj.getSpecialDragPoly(rDrag);
344 // Offset handlen !!!!!! fehlt noch !!!!!!!
347 String SdrVirtObj::getSpecialDragComment(const SdrDragStat& rDrag) const
349 return rRefObj.getSpecialDragComment(rDrag);
352 ////////////////////////////////////////////////////////////////////////////////////////////////////
354 FASTBOOL SdrVirtObj::BegCreate(SdrDragStat& rStat)
356 return rRefObj.BegCreate(rStat);
359 FASTBOOL SdrVirtObj::MovCreate(SdrDragStat& rStat)
361 return rRefObj.MovCreate(rStat);
364 FASTBOOL SdrVirtObj::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
366 return rRefObj.EndCreate(rStat,eCmd);
369 FASTBOOL SdrVirtObj::BckCreate(SdrDragStat& rStat)
371 return rRefObj.BckCreate(rStat);
374 void SdrVirtObj::BrkCreate(SdrDragStat& rStat)
376 rRefObj.BrkCreate(rStat);
379 basegfx::B2DPolyPolygon SdrVirtObj::TakeCreatePoly(const SdrDragStat& rDrag) const
381 return rRefObj.TakeCreatePoly(rDrag);
382 // Offset handlen !!!!!! fehlt noch !!!!!!!
385 ////////////////////////////////////////////////////////////////////////////////////////////////////
387 void SdrVirtObj::NbcMove(const Size& rSiz)
389 MovePoint(aAnchor,rSiz);
390 SetRectsDirty();
393 void SdrVirtObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
395 rRefObj.NbcResize(rRef-aAnchor,xFact,yFact);
396 SetRectsDirty();
399 void SdrVirtObj::NbcRotate(const Point& rRef, long nWink, double sn, double cs)
401 rRefObj.NbcRotate(rRef-aAnchor,nWink,sn,cs);
402 SetRectsDirty();
405 void SdrVirtObj::NbcMirror(const Point& rRef1, const Point& rRef2)
407 rRefObj.NbcMirror(rRef1-aAnchor,rRef2-aAnchor);
408 SetRectsDirty();
411 void SdrVirtObj::NbcShear(const Point& rRef, long nWink, double tn, FASTBOOL bVShear)
413 rRefObj.NbcShear(rRef-aAnchor,nWink,tn,bVShear);
414 SetRectsDirty();
417 ////////////////////////////////////////////////////////////////////////////////////////////////////
419 void SdrVirtObj::Move(const Size& rSiz)
421 if (rSiz.Width()!=0 || rSiz.Height()!=0) {
422 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
423 // #110094#-14 SendRepaintBroadcast();
424 NbcMove(rSiz);
425 SetChanged();
426 BroadcastObjectChange();
427 SendUserCall(SDRUSERCALL_MOVEONLY,aBoundRect0);
431 void SdrVirtObj::Resize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
433 if (xFact.GetNumerator()!=xFact.GetDenominator() || yFact.GetNumerator()!=yFact.GetDenominator()) {
434 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
435 rRefObj.Resize(rRef-aAnchor,xFact,yFact);
436 SetRectsDirty();
437 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
441 void SdrVirtObj::Rotate(const Point& rRef, long nWink, double sn, double cs)
443 if (nWink!=0) {
444 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
445 rRefObj.Rotate(rRef-aAnchor,nWink,sn,cs);
446 SetRectsDirty();
447 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
451 void SdrVirtObj::Mirror(const Point& rRef1, const Point& rRef2)
453 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
454 rRefObj.Mirror(rRef1-aAnchor,rRef2-aAnchor);
455 SetRectsDirty();
456 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
459 void SdrVirtObj::Shear(const Point& rRef, long nWink, double tn, FASTBOOL bVShear)
461 if (nWink!=0) {
462 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
463 rRefObj.Shear(rRef-aAnchor,nWink,tn,bVShear);
464 SetRectsDirty();
465 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
469 ////////////////////////////////////////////////////////////////////////////////////////////////////
471 void SdrVirtObj::RecalcSnapRect()
473 aSnapRect=rRefObj.GetSnapRect();
474 aSnapRect+=aAnchor;
477 const Rectangle& SdrVirtObj::GetSnapRect() const
479 ((SdrVirtObj*)this)->aSnapRect=rRefObj.GetSnapRect();
480 ((SdrVirtObj*)this)->aSnapRect+=aAnchor;
481 return aSnapRect;
484 void SdrVirtObj::SetSnapRect(const Rectangle& rRect)
487 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
488 Rectangle aR(rRect);
489 aR-=aAnchor;
490 rRefObj.SetSnapRect(aR);
491 SetRectsDirty();
492 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
496 void SdrVirtObj::NbcSetSnapRect(const Rectangle& rRect)
498 Rectangle aR(rRect);
499 aR-=aAnchor;
500 SetRectsDirty();
501 rRefObj.NbcSetSnapRect(aR);
504 ////////////////////////////////////////////////////////////////////////////////////////////////////
506 const Rectangle& SdrVirtObj::GetLogicRect() const
508 ((SdrVirtObj*)this)->aSnapRect=rRefObj.GetLogicRect(); // !!! Missbrauch von aSnapRect !!!
509 ((SdrVirtObj*)this)->aSnapRect+=aAnchor; // Wenns mal Aerger gibt, muss ein weiteres Rectangle Member her (oder Heap)
510 return aSnapRect;
513 void SdrVirtObj::SetLogicRect(const Rectangle& rRect)
515 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
516 Rectangle aR(rRect);
517 aR-=aAnchor;
518 rRefObj.SetLogicRect(aR);
519 SetRectsDirty();
520 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
523 void SdrVirtObj::NbcSetLogicRect(const Rectangle& rRect)
525 Rectangle aR(rRect);
526 aR-=aAnchor;
527 SetRectsDirty();
528 rRefObj.NbcSetLogicRect(aR);
531 ////////////////////////////////////////////////////////////////////////////////////////////////////
533 long SdrVirtObj::GetRotateAngle() const
535 return rRefObj.GetRotateAngle();
538 long SdrVirtObj::GetShearAngle(FASTBOOL bVertical) const
540 return rRefObj.GetShearAngle(bVertical);
543 ////////////////////////////////////////////////////////////////////////////////////////////////////
545 sal_uInt32 SdrVirtObj::GetSnapPointCount() const
547 return rRefObj.GetSnapPointCount();
550 Point SdrVirtObj::GetSnapPoint(sal_uInt32 i) const
552 Point aP(rRefObj.GetSnapPoint(i));
553 aP+=aAnchor;
554 return aP;
557 sal_Bool SdrVirtObj::IsPolyObj() const
559 return rRefObj.IsPolyObj();
562 sal_uInt32 SdrVirtObj::GetPointCount() const
564 return rRefObj.GetPointCount();
567 Point SdrVirtObj::GetPoint(sal_uInt32 i) const
569 return Point(rRefObj.GetPoint(i) + aAnchor);
572 void SdrVirtObj::NbcSetPoint(const Point& rPnt, sal_uInt32 i)
574 Point aP(rPnt);
575 aP-=aAnchor;
576 rRefObj.SetPoint(aP,i);
577 SetRectsDirty();
580 ////////////////////////////////////////////////////////////////////////////////////////////////////
582 SdrObjGeoData* SdrVirtObj::NewGeoData() const
584 return rRefObj.NewGeoData();
587 void SdrVirtObj::SaveGeoData(SdrObjGeoData& rGeo) const
589 rRefObj.SaveGeoData(rGeo);
592 void SdrVirtObj::RestGeoData(const SdrObjGeoData& rGeo)
594 rRefObj.RestGeoData(rGeo);
595 SetRectsDirty();
598 ////////////////////////////////////////////////////////////////////////////////////////////////////
600 SdrObjGeoData* SdrVirtObj::GetGeoData() const
602 return rRefObj.GetGeoData();
605 void SdrVirtObj::SetGeoData(const SdrObjGeoData& rGeo)
607 Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetLastBoundRect();
608 rRefObj.SetGeoData(rGeo);
609 SetRectsDirty();
610 SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
613 ////////////////////////////////////////////////////////////////////////////////////////////////////
615 void SdrVirtObj::NbcReformatText()
617 rRefObj.NbcReformatText();
620 void SdrVirtObj::ReformatText()
622 rRefObj.ReformatText();
625 ////////////////////////////////////////////////////////////////////////////////////////////////////
627 FASTBOOL SdrVirtObj::HasMacro() const
629 return rRefObj.HasMacro();
632 SdrObject* SdrVirtObj::CheckMacroHit(const SdrObjMacroHitRec& rRec) const
634 return rRefObj.CheckMacroHit(rRec); // Todo: Positionsversatz
637 Pointer SdrVirtObj::GetMacroPointer(const SdrObjMacroHitRec& rRec) const
639 return rRefObj.GetMacroPointer(rRec); // Todo: Positionsversatz
642 void SdrVirtObj::PaintMacro(OutputDevice& rOut, const Rectangle& rDirtyRect, const SdrObjMacroHitRec& rRec) const
644 rRefObj.PaintMacro(rOut,rDirtyRect,rRec); // Todo: Positionsversatz
647 FASTBOOL SdrVirtObj::DoMacro(const SdrObjMacroHitRec& rRec)
649 return rRefObj.DoMacro(rRec); // Todo: Positionsversatz
652 XubString SdrVirtObj::GetMacroPopupComment(const SdrObjMacroHitRec& rRec) const
654 return rRefObj.GetMacroPopupComment(rRec); // Todo: Positionsversatz
657 const Point SdrVirtObj::GetOffset() const
659 // #i73248# default offset of SdrVirtObj is aAnchor
660 return aAnchor;
663 // eof