xref: /trunk/main/svx/source/svdraw/svdorect.cxx (revision e9eb28911c9f73955f54794d304724ab1a9a37e1)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_svx.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <svx/svdorect.hxx>
26cdf0e10cSrcweir #include <math.h>
27cdf0e10cSrcweir #include <stdlib.h>
28cdf0e10cSrcweir #include <svx/xpool.hxx>
29cdf0e10cSrcweir #include <svx/xpoly.hxx>
30cdf0e10cSrcweir #include <svx/svdattr.hxx>
31cdf0e10cSrcweir #include <svx/svdpool.hxx>
32cdf0e10cSrcweir #include <svx/svdtrans.hxx>
33cdf0e10cSrcweir #include <svx/svdetc.hxx>
34cdf0e10cSrcweir #include <svx/svddrag.hxx>
35cdf0e10cSrcweir #include <svx/svdmodel.hxx>
36cdf0e10cSrcweir #include <svx/svdpage.hxx>
377a060572Smseidel #include <svx/svdocapt.hxx> // für Import von SdrFileVersion 2
387a060572Smseidel #include <svx/svdpagv.hxx> // für
39cdf0e10cSrcweir #include <svx/svdview.hxx> // das
40cdf0e10cSrcweir #include <svx/svdundo.hxx> // Macro-Beispiel
41cdf0e10cSrcweir #include <svx/svdopath.hxx>
42cdf0e10cSrcweir #include "svx/svdglob.hxx" // Stringcache
43cdf0e10cSrcweir #include "svx/svdstr.hrc" // Objektname
44cdf0e10cSrcweir #include <svx/xflclit.hxx>
45cdf0e10cSrcweir #include <svx/xlnclit.hxx>
46cdf0e10cSrcweir #include <svx/xlnwtit.hxx>
47cdf0e10cSrcweir #include "svdoimp.hxx"
48cdf0e10cSrcweir #include <svx/sdr/properties/rectangleproperties.hxx>
49cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofsdrrectobj.hxx>
50cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
51cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
52cdf0e10cSrcweir 
53cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
54cdf0e10cSrcweir // BaseProperties section
55cdf0e10cSrcweir 
CreateObjectSpecificProperties()56cdf0e10cSrcweir sdr::properties::BaseProperties* SdrRectObj::CreateObjectSpecificProperties()
57cdf0e10cSrcweir {
58cdf0e10cSrcweir     return new sdr::properties::RectangleProperties(*this);
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
62cdf0e10cSrcweir // DrawContact section
63cdf0e10cSrcweir 
CreateObjectSpecificViewContact()64cdf0e10cSrcweir sdr::contact::ViewContact* SdrRectObj::CreateObjectSpecificViewContact()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     return new sdr::contact::ViewContactOfSdrRectObj(*this);
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
70cdf0e10cSrcweir 
71cdf0e10cSrcweir TYPEINIT1(SdrRectObj,SdrTextObj);
72cdf0e10cSrcweir 
SdrRectObj()73cdf0e10cSrcweir SdrRectObj::SdrRectObj()
74cdf0e10cSrcweir :   mpXPoly(0L)
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     bClosedObj=sal_True;
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
SdrRectObj(const Rectangle & rRect)79cdf0e10cSrcweir SdrRectObj::SdrRectObj(const Rectangle& rRect)
80cdf0e10cSrcweir :   SdrTextObj(rRect),
81cdf0e10cSrcweir     mpXPoly(NULL)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir     bClosedObj=sal_True;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
SdrRectObj(SdrObjKind eNewTextKind)86cdf0e10cSrcweir SdrRectObj::SdrRectObj(SdrObjKind eNewTextKind)
87cdf0e10cSrcweir :   SdrTextObj(eNewTextKind),
88cdf0e10cSrcweir     mpXPoly(NULL)
89cdf0e10cSrcweir {
90cdf0e10cSrcweir     DBG_ASSERT(eTextKind==OBJ_TEXT || eTextKind==OBJ_TEXTEXT ||
91cdf0e10cSrcweir                eTextKind==OBJ_OUTLINETEXT || eTextKind==OBJ_TITLETEXT,
927a060572Smseidel                "SdrRectObj::SdrRectObj(SdrObjKind) ist nur für Textrahmen gedacht");
93cdf0e10cSrcweir     bClosedObj=sal_True;
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
SdrRectObj(SdrObjKind eNewTextKind,const Rectangle & rRect)96cdf0e10cSrcweir SdrRectObj::SdrRectObj(SdrObjKind eNewTextKind, const Rectangle& rRect)
97cdf0e10cSrcweir :   SdrTextObj(eNewTextKind,rRect),
98cdf0e10cSrcweir     mpXPoly(NULL)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir     DBG_ASSERT(eTextKind==OBJ_TEXT || eTextKind==OBJ_TEXTEXT ||
101cdf0e10cSrcweir                eTextKind==OBJ_OUTLINETEXT || eTextKind==OBJ_TITLETEXT,
1027a060572Smseidel                "SdrRectObj::SdrRectObj(SdrObjKind,...) ist nur für Textrahmen gedacht");
103cdf0e10cSrcweir     bClosedObj=sal_True;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
SdrRectObj(SdrObjKind eNewTextKind,const Rectangle & rNewRect,SvStream & rInput,const String & rBaseURL,sal_uInt16 eFormat)106cdf0e10cSrcweir SdrRectObj::SdrRectObj(SdrObjKind eNewTextKind, const Rectangle& rNewRect, SvStream& rInput, const String& rBaseURL, sal_uInt16 eFormat)
107cdf0e10cSrcweir :   SdrTextObj(eNewTextKind,rNewRect,rInput,rBaseURL,eFormat),
108cdf0e10cSrcweir     mpXPoly(NULL)
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     DBG_ASSERT(eTextKind==OBJ_TEXT || eTextKind==OBJ_TEXTEXT ||
111cdf0e10cSrcweir                eTextKind==OBJ_OUTLINETEXT || eTextKind==OBJ_TITLETEXT,
1127a060572Smseidel                "SdrRectObj::SdrRectObj(SdrObjKind,...) ist nur für Textrahmen gedacht");
113cdf0e10cSrcweir     bClosedObj=sal_True;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
~SdrRectObj()116cdf0e10cSrcweir SdrRectObj::~SdrRectObj()
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     if(mpXPoly)
119cdf0e10cSrcweir     {
120cdf0e10cSrcweir         delete mpXPoly;
121cdf0e10cSrcweir     }
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
SetXPolyDirty()124cdf0e10cSrcweir void SdrRectObj::SetXPolyDirty()
125cdf0e10cSrcweir {
126cdf0e10cSrcweir     if(mpXPoly)
127cdf0e10cSrcweir     {
128cdf0e10cSrcweir         delete mpXPoly;
129cdf0e10cSrcweir         mpXPoly = 0L;
130cdf0e10cSrcweir     }
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
PaintNeedsXPoly(long nEckRad) const133cdf0e10cSrcweir FASTBOOL SdrRectObj::PaintNeedsXPoly(long nEckRad) const
134cdf0e10cSrcweir {
135cdf0e10cSrcweir     FASTBOOL bNeed=aGeo.nDrehWink!=0 || aGeo.nShearWink!=0 || nEckRad!=0;
136cdf0e10cSrcweir     return bNeed;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
ImpCalcXPoly(const Rectangle & rRect1,long nRad1) const139cdf0e10cSrcweir XPolygon SdrRectObj::ImpCalcXPoly(const Rectangle& rRect1, long nRad1) const
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     XPolygon aXPoly(rRect1,nRad1,nRad1);
1427a060572Smseidel     const sal_uInt16 nPointCount(aXPoly.GetPointCount());
143*e9eb2891Smseidel     XPolygon aNewPoly(nPointCount+1);
1447a060572Smseidel     sal_uInt16 nShift=nPointCount-2;
1457a060572Smseidel     if (nRad1!=0) nShift=nPointCount-5;
146cdf0e10cSrcweir     sal_uInt16 j=nShift;
1477a060572Smseidel     for (sal_uInt16 i=1; i<nPointCount; i++) {
148*e9eb2891Smseidel         aNewPoly[i]=aXPoly[j];
149*e9eb2891Smseidel         aNewPoly.SetFlags(i,aXPoly.GetFlags(j));
150cdf0e10cSrcweir         j++;
1517a060572Smseidel         if (j>=nPointCount) j=1;
152cdf0e10cSrcweir     }
153*e9eb2891Smseidel     aNewPoly[0]=rRect1.BottomCenter();
154*e9eb2891Smseidel     aNewPoly[nPointCount]=aNewPoly[0];
155*e9eb2891Smseidel     aXPoly=aNewPoly;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     // Die Winkelangaben beziehen sich immer auf die linke obere Ecke von !aRect!
158cdf0e10cSrcweir     if (aGeo.nShearWink!=0) ShearXPoly(aXPoly,aRect.TopLeft(),aGeo.nTan);
159cdf0e10cSrcweir     if (aGeo.nDrehWink!=0) RotateXPoly(aXPoly,aRect.TopLeft(),aGeo.nSin,aGeo.nCos);
160cdf0e10cSrcweir     return aXPoly;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
RecalcXPoly()163cdf0e10cSrcweir void SdrRectObj::RecalcXPoly()
164cdf0e10cSrcweir {
165cdf0e10cSrcweir     mpXPoly = new XPolygon(ImpCalcXPoly(aRect,GetEckenradius()));
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
GetXPoly() const168cdf0e10cSrcweir const XPolygon& SdrRectObj::GetXPoly() const
169cdf0e10cSrcweir {
170cdf0e10cSrcweir     if(!mpXPoly)
171cdf0e10cSrcweir     {
172cdf0e10cSrcweir         ((SdrRectObj*)this)->RecalcXPoly();
173cdf0e10cSrcweir     }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     return *mpXPoly;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
TakeObjInfo(SdrObjTransformInfoRec & rInfo) const178cdf0e10cSrcweir void SdrRectObj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
179cdf0e10cSrcweir {
180cdf0e10cSrcweir     FASTBOOL bNoTextFrame=!IsTextFrame();
181cdf0e10cSrcweir     rInfo.bResizeFreeAllowed=bNoTextFrame || aGeo.nDrehWink%9000==0;
182cdf0e10cSrcweir     rInfo.bResizePropAllowed=sal_True;
183cdf0e10cSrcweir     rInfo.bRotateFreeAllowed=sal_True;
184cdf0e10cSrcweir     rInfo.bRotate90Allowed =sal_True;
185cdf0e10cSrcweir     rInfo.bMirrorFreeAllowed=bNoTextFrame;
186cdf0e10cSrcweir     rInfo.bMirror45Allowed =bNoTextFrame;
187cdf0e10cSrcweir     rInfo.bMirror90Allowed =bNoTextFrame;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     // allow transparence
190cdf0e10cSrcweir     rInfo.bTransparenceAllowed = sal_True;
191cdf0e10cSrcweir 
192cdf0e10cSrcweir     // gradient depends on fillstyle
193cdf0e10cSrcweir     XFillStyle eFillStyle = ((XFillStyleItem&)(GetObjectItem(XATTR_FILLSTYLE))).GetValue();
194cdf0e10cSrcweir     rInfo.bGradientAllowed = (eFillStyle == XFILL_GRADIENT);
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     rInfo.bShearAllowed =bNoTextFrame;
197cdf0e10cSrcweir     rInfo.bEdgeRadiusAllowed=sal_True;
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     FASTBOOL bCanConv=!HasText() || ImpCanConvTextToCurve();
200cdf0e10cSrcweir     if (bCanConv && !bNoTextFrame && !HasText()) {
201cdf0e10cSrcweir         bCanConv=HasFill() || HasLine();
202cdf0e10cSrcweir     }
203cdf0e10cSrcweir     rInfo.bCanConvToPath =bCanConv;
204cdf0e10cSrcweir     rInfo.bCanConvToPoly =bCanConv;
205cdf0e10cSrcweir     rInfo.bCanConvToContour = (rInfo.bCanConvToPoly || LineGeometryUsageIsNecessary());
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
GetObjIdentifier() const208cdf0e10cSrcweir sal_uInt16 SdrRectObj::GetObjIdentifier() const
209cdf0e10cSrcweir {
210cdf0e10cSrcweir     if (IsTextFrame()) return sal_uInt16(eTextKind);
211cdf0e10cSrcweir     else return sal_uInt16(OBJ_RECT);
212cdf0e10cSrcweir }
213cdf0e10cSrcweir 
TakeUnrotatedSnapRect(Rectangle & rRect) const214cdf0e10cSrcweir void SdrRectObj::TakeUnrotatedSnapRect(Rectangle& rRect) const
215cdf0e10cSrcweir {
216cdf0e10cSrcweir     rRect=aRect;
217cdf0e10cSrcweir     if (aGeo.nShearWink!=0) {
218cdf0e10cSrcweir         long nDst=Round((aRect.Bottom()-aRect.Top())*aGeo.nTan);
219cdf0e10cSrcweir         if (aGeo.nShearWink>0) {
220cdf0e10cSrcweir             Point aRef(rRect.TopLeft());
221cdf0e10cSrcweir             rRect.Left()-=nDst;
222cdf0e10cSrcweir             Point aTmpPt(rRect.TopLeft());
223cdf0e10cSrcweir             RotatePoint(aTmpPt,aRef,aGeo.nSin,aGeo.nCos);
224cdf0e10cSrcweir             aTmpPt-=rRect.TopLeft();
225cdf0e10cSrcweir             rRect.Move(aTmpPt.X(),aTmpPt.Y());
226cdf0e10cSrcweir         } else {
227cdf0e10cSrcweir             rRect.Right()-=nDst;
228cdf0e10cSrcweir         }
229cdf0e10cSrcweir     }
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
TakeObjNameSingul(XubString & rName) const232cdf0e10cSrcweir void SdrRectObj::TakeObjNameSingul(XubString& rName) const
233cdf0e10cSrcweir {
234cdf0e10cSrcweir     if (IsTextFrame())
235cdf0e10cSrcweir     {
236cdf0e10cSrcweir         SdrTextObj::TakeObjNameSingul(rName);
237cdf0e10cSrcweir     }
238cdf0e10cSrcweir     else
239cdf0e10cSrcweir     {
240cdf0e10cSrcweir         sal_uInt16 nResId=STR_ObjNameSingulRECT;
241cdf0e10cSrcweir         if (aGeo.nShearWink!=0) {
242cdf0e10cSrcweir             nResId+=4; // Parallelogramm oder Raute
2437a060572Smseidel             // Raute ist nicht, weil Shear die vertikalen Kanten verlängert!
244cdf0e10cSrcweir             // Wenn Zeit ist, werde ich das mal berechnen.
245cdf0e10cSrcweir         } else {
246cdf0e10cSrcweir             if (aRect.GetWidth()==aRect.GetHeight()) nResId+=2; // Quadrat
247cdf0e10cSrcweir         }
248cdf0e10cSrcweir         if (GetEckenradius()!=0) nResId+=8; // abgerundet
249cdf0e10cSrcweir         rName=ImpGetResStr(nResId);
250cdf0e10cSrcweir 
251cdf0e10cSrcweir         String aName( GetName() );
252cdf0e10cSrcweir         if(aName.Len())
253cdf0e10cSrcweir         {
254cdf0e10cSrcweir             rName += sal_Unicode(' ');
255cdf0e10cSrcweir             rName += sal_Unicode('\'');
256cdf0e10cSrcweir             rName += aName;
257cdf0e10cSrcweir             rName += sal_Unicode('\'');
258cdf0e10cSrcweir         }
259cdf0e10cSrcweir     }
260cdf0e10cSrcweir }
261cdf0e10cSrcweir 
TakeObjNamePlural(XubString & rName) const262cdf0e10cSrcweir void SdrRectObj::TakeObjNamePlural(XubString& rName) const
263cdf0e10cSrcweir {
264cdf0e10cSrcweir     if (IsTextFrame()) SdrTextObj::TakeObjNamePlural(rName);
265cdf0e10cSrcweir     else {
266cdf0e10cSrcweir         sal_uInt16 nResId=STR_ObjNamePluralRECT;
267cdf0e10cSrcweir         if (aGeo.nShearWink!=0) {
268cdf0e10cSrcweir             nResId+=4; // Parallelogramm oder Raute
269cdf0e10cSrcweir         } else {
270cdf0e10cSrcweir             if (aRect.GetWidth()==aRect.GetHeight()) nResId+=2; // Quadrat
271cdf0e10cSrcweir         }
272cdf0e10cSrcweir         if (GetEckenradius()!=0) nResId+=8; // abgerundet
273cdf0e10cSrcweir         rName=ImpGetResStr(nResId);
274cdf0e10cSrcweir     }
275cdf0e10cSrcweir }
276cdf0e10cSrcweir 
operator =(const SdrObject & rObj)277cdf0e10cSrcweir void SdrRectObj::operator=(const SdrObject& rObj)
278cdf0e10cSrcweir {
279cdf0e10cSrcweir     SdrTextObj::operator=(rObj);
280cdf0e10cSrcweir }
281cdf0e10cSrcweir 
TakeXorPoly() const282cdf0e10cSrcweir basegfx::B2DPolyPolygon SdrRectObj::TakeXorPoly() const
283cdf0e10cSrcweir {
284cdf0e10cSrcweir     XPolyPolygon aXPP;
285cdf0e10cSrcweir     aXPP.Insert(ImpCalcXPoly(aRect,GetEckenradius()));
286cdf0e10cSrcweir     return aXPP.getB2DPolyPolygon();
287cdf0e10cSrcweir }
288cdf0e10cSrcweir 
RecalcSnapRect()289cdf0e10cSrcweir void SdrRectObj::RecalcSnapRect()
290cdf0e10cSrcweir {
291cdf0e10cSrcweir     long nEckRad=GetEckenradius();
292cdf0e10cSrcweir     if ((aGeo.nDrehWink!=0 || aGeo.nShearWink!=0) && nEckRad!=0) {
293cdf0e10cSrcweir         maSnapRect=GetXPoly().GetBoundRect();
294cdf0e10cSrcweir     } else {
295cdf0e10cSrcweir         SdrTextObj::RecalcSnapRect();
296cdf0e10cSrcweir     }
297cdf0e10cSrcweir }
298cdf0e10cSrcweir 
NbcSetSnapRect(const Rectangle & rRect)299cdf0e10cSrcweir void SdrRectObj::NbcSetSnapRect(const Rectangle& rRect)
300cdf0e10cSrcweir {
301cdf0e10cSrcweir     SdrTextObj::NbcSetSnapRect(rRect);
302cdf0e10cSrcweir     SetXPolyDirty();
303cdf0e10cSrcweir }
304cdf0e10cSrcweir 
NbcSetLogicRect(const Rectangle & rRect)305cdf0e10cSrcweir void SdrRectObj::NbcSetLogicRect(const Rectangle& rRect)
306cdf0e10cSrcweir {
307cdf0e10cSrcweir     SdrTextObj::NbcSetLogicRect(rRect);
308cdf0e10cSrcweir     SetXPolyDirty();
309cdf0e10cSrcweir }
310cdf0e10cSrcweir 
GetHdlCount() const311cdf0e10cSrcweir sal_uInt32 SdrRectObj::GetHdlCount() const
312cdf0e10cSrcweir {
313cdf0e10cSrcweir     return IsTextFrame() ? 10 : 9;
314cdf0e10cSrcweir }
315cdf0e10cSrcweir 
GetHdl(sal_uInt32 nHdlNum) const316cdf0e10cSrcweir SdrHdl* SdrRectObj::GetHdl(sal_uInt32 nHdlNum) const
317cdf0e10cSrcweir {
318cdf0e10cSrcweir     SdrHdl* pH = NULL;
319cdf0e10cSrcweir     Point aPnt;
320cdf0e10cSrcweir     SdrHdlKind eKind = HDL_MOVE;
321cdf0e10cSrcweir 
322cdf0e10cSrcweir     if(!IsTextFrame())
323cdf0e10cSrcweir     {
324cdf0e10cSrcweir         nHdlNum++;
325cdf0e10cSrcweir     }
326cdf0e10cSrcweir 
327cdf0e10cSrcweir     switch(nHdlNum)
328cdf0e10cSrcweir     {
329cdf0e10cSrcweir         case 0:
330cdf0e10cSrcweir         {
331d8a41635SArmin Le Grand             OSL_ENSURE(!IsTextEditActive(), "Do not use a ImpTextframeHdl for hilighting text in active text edit, this will collide with EditEngine paints (!)");
332cdf0e10cSrcweir             pH = new ImpTextframeHdl(aRect);
333cdf0e10cSrcweir             pH->SetObj((SdrObject*)this);
334cdf0e10cSrcweir             pH->SetDrehWink(aGeo.nDrehWink);
335cdf0e10cSrcweir             break;
336cdf0e10cSrcweir         }
337cdf0e10cSrcweir         case 1:
338cdf0e10cSrcweir         {
339cdf0e10cSrcweir             long a = GetEckenradius();
340cdf0e10cSrcweir             long b = Max(aRect.GetWidth(),aRect.GetHeight())/2; // Wird aufgerundet, da GetWidth() eins draufaddiert
341cdf0e10cSrcweir             if (a>b) a=b;
342cdf0e10cSrcweir             if (a<0) a=0;
343cdf0e10cSrcweir             aPnt=aRect.TopLeft();
344cdf0e10cSrcweir             aPnt.X()+=a;
345cdf0e10cSrcweir             eKind = HDL_CIRC;
346cdf0e10cSrcweir             break;
347cdf0e10cSrcweir         }
348cdf0e10cSrcweir         case 2: aPnt=aRect.TopLeft();      eKind = HDL_UPLFT; break; // Oben links
349cdf0e10cSrcweir         case 3: aPnt=aRect.TopCenter();    eKind = HDL_UPPER; break; // Oben
350cdf0e10cSrcweir         case 4: aPnt=aRect.TopRight();     eKind = HDL_UPRGT; break; // Oben rechts
3517a060572Smseidel         case 5: aPnt=aRect.LeftCenter();   eKind = HDL_LEFT ; break; // Left
3527a060572Smseidel         case 6: aPnt=aRect.RightCenter();  eKind = HDL_RIGHT; break; // Right
353cdf0e10cSrcweir         case 7: aPnt=aRect.BottomLeft();   eKind = HDL_LWLFT; break; // Unten links
354cdf0e10cSrcweir         case 8: aPnt=aRect.BottomCenter(); eKind = HDL_LOWER; break; // Unten
355cdf0e10cSrcweir         case 9: aPnt=aRect.BottomRight();  eKind = HDL_LWRGT; break; // Unten rechts
356cdf0e10cSrcweir     }
357cdf0e10cSrcweir 
358cdf0e10cSrcweir     if(!pH)
359cdf0e10cSrcweir     {
360cdf0e10cSrcweir         if(aGeo.nShearWink)
361cdf0e10cSrcweir         {
362cdf0e10cSrcweir             ShearPoint(aPnt,aRect.TopLeft(),aGeo.nTan);
363cdf0e10cSrcweir         }
364cdf0e10cSrcweir 
365cdf0e10cSrcweir         if(aGeo.nDrehWink)
366cdf0e10cSrcweir         {
367cdf0e10cSrcweir             RotatePoint(aPnt,aRect.TopLeft(),aGeo.nSin,aGeo.nCos);
368cdf0e10cSrcweir         }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir         pH = new SdrHdl(aPnt,eKind);
371cdf0e10cSrcweir         pH->SetObj((SdrObject*)this);
372cdf0e10cSrcweir         pH->SetDrehWink(aGeo.nDrehWink);
373cdf0e10cSrcweir     }
374cdf0e10cSrcweir 
375cdf0e10cSrcweir     return pH;
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
379cdf0e10cSrcweir 
hasSpecialDrag() const380cdf0e10cSrcweir bool SdrRectObj::hasSpecialDrag() const
381cdf0e10cSrcweir {
382cdf0e10cSrcweir     return true;
383cdf0e10cSrcweir }
384cdf0e10cSrcweir 
beginSpecialDrag(SdrDragStat & rDrag) const385cdf0e10cSrcweir bool SdrRectObj::beginSpecialDrag(SdrDragStat& rDrag) const
386cdf0e10cSrcweir {
387cdf0e10cSrcweir     const bool bRad(rDrag.GetHdl() && HDL_CIRC == rDrag.GetHdl()->GetKind());
388cdf0e10cSrcweir 
389cdf0e10cSrcweir     if(bRad)
390cdf0e10cSrcweir     {
391cdf0e10cSrcweir         rDrag.SetEndDragChangesAttributes(true);
392cdf0e10cSrcweir 
393cdf0e10cSrcweir         return true;
394cdf0e10cSrcweir     }
395cdf0e10cSrcweir 
396cdf0e10cSrcweir     return SdrTextObj::beginSpecialDrag(rDrag);
397cdf0e10cSrcweir }
398cdf0e10cSrcweir 
applySpecialDrag(SdrDragStat & rDrag)399cdf0e10cSrcweir bool SdrRectObj::applySpecialDrag(SdrDragStat& rDrag)
400cdf0e10cSrcweir {
401cdf0e10cSrcweir     const bool bRad(rDrag.GetHdl() && HDL_CIRC == rDrag.GetHdl()->GetKind());
402cdf0e10cSrcweir 
403cdf0e10cSrcweir     if (bRad)
404cdf0e10cSrcweir     {
405cdf0e10cSrcweir         Rectangle aBoundRect0;
406cdf0e10cSrcweir         Point aPt(rDrag.GetNow());
407cdf0e10cSrcweir 
408cdf0e10cSrcweir         if(aGeo.nDrehWink)
409cdf0e10cSrcweir             RotatePoint(aPt,aRect.TopLeft(),-aGeo.nSin,aGeo.nCos);
410cdf0e10cSrcweir 
411cdf0e10cSrcweir         sal_Int32 nRad(aPt.X() - aRect.Left());
412cdf0e10cSrcweir 
413cdf0e10cSrcweir         if (nRad < 0)
414cdf0e10cSrcweir             nRad = 0;
415cdf0e10cSrcweir 
416cdf0e10cSrcweir         if(nRad != GetEckenradius())
417cdf0e10cSrcweir         {
418cdf0e10cSrcweir             NbcSetEckenradius(nRad);
419cdf0e10cSrcweir         }
420cdf0e10cSrcweir 
421cdf0e10cSrcweir         return true;
422cdf0e10cSrcweir     }
423cdf0e10cSrcweir     else
424cdf0e10cSrcweir     {
425cdf0e10cSrcweir         return SdrTextObj::applySpecialDrag(rDrag);
426cdf0e10cSrcweir     }
427cdf0e10cSrcweir }
428cdf0e10cSrcweir 
getSpecialDragComment(const SdrDragStat & rDrag) const429cdf0e10cSrcweir String SdrRectObj::getSpecialDragComment(const SdrDragStat& rDrag) const
430cdf0e10cSrcweir {
431cdf0e10cSrcweir     const bool bCreateComment(rDrag.GetView() && this == rDrag.GetView()->GetCreateObj());
432cdf0e10cSrcweir 
433cdf0e10cSrcweir     if(bCreateComment)
434cdf0e10cSrcweir     {
435cdf0e10cSrcweir         return String();
436cdf0e10cSrcweir     }
437cdf0e10cSrcweir     else
438cdf0e10cSrcweir     {
439cdf0e10cSrcweir         const bool bRad(rDrag.GetHdl() && HDL_CIRC == rDrag.GetHdl()->GetKind());
440cdf0e10cSrcweir 
441cdf0e10cSrcweir         if(bRad)
442cdf0e10cSrcweir         {
443cdf0e10cSrcweir             Point aPt(rDrag.GetNow());
444cdf0e10cSrcweir 
4457a060572Smseidel             // -sin für Umkehrung
446cdf0e10cSrcweir             if(aGeo.nDrehWink)
447cdf0e10cSrcweir                 RotatePoint(aPt, aRect.TopLeft(), -aGeo.nSin, aGeo.nCos);
448cdf0e10cSrcweir 
449cdf0e10cSrcweir             sal_Int32 nRad(aPt.X() - aRect.Left());
450cdf0e10cSrcweir 
451cdf0e10cSrcweir             if(nRad < 0)
452cdf0e10cSrcweir                 nRad = 0;
453cdf0e10cSrcweir 
454cdf0e10cSrcweir             XubString aStr;
455cdf0e10cSrcweir 
456cdf0e10cSrcweir             ImpTakeDescriptionStr(STR_DragRectEckRad, aStr);
457cdf0e10cSrcweir             aStr.AppendAscii(" (");
458cdf0e10cSrcweir             aStr += GetMetrStr(nRad);
459cdf0e10cSrcweir             aStr += sal_Unicode(')');
460cdf0e10cSrcweir 
461cdf0e10cSrcweir             return aStr;
462cdf0e10cSrcweir         }
463cdf0e10cSrcweir         else
464cdf0e10cSrcweir         {
465cdf0e10cSrcweir             return SdrTextObj::getSpecialDragComment(rDrag);
466cdf0e10cSrcweir         }
467cdf0e10cSrcweir     }
468cdf0e10cSrcweir }
469cdf0e10cSrcweir 
470cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
471cdf0e10cSrcweir 
TakeCreatePoly(const SdrDragStat & rDrag) const472cdf0e10cSrcweir basegfx::B2DPolyPolygon SdrRectObj::TakeCreatePoly(const SdrDragStat& rDrag) const
473cdf0e10cSrcweir {
474cdf0e10cSrcweir     Rectangle aRect1;
475cdf0e10cSrcweir     rDrag.TakeCreateRect(aRect1);
476cdf0e10cSrcweir     aRect1.Justify();
477cdf0e10cSrcweir 
478cdf0e10cSrcweir     basegfx::B2DPolyPolygon aRetval;
479cdf0e10cSrcweir     aRetval.append(ImpCalcXPoly(aRect1,GetEckenradius()).getB2DPolygon());
480cdf0e10cSrcweir     return aRetval;
481cdf0e10cSrcweir }
482cdf0e10cSrcweir 
GetCreatePointer() const483cdf0e10cSrcweir Pointer SdrRectObj::GetCreatePointer() const
484cdf0e10cSrcweir {
485cdf0e10cSrcweir     if (IsTextFrame()) return Pointer(POINTER_DRAW_TEXT);
486cdf0e10cSrcweir     return Pointer(POINTER_DRAW_RECT);
487cdf0e10cSrcweir }
488cdf0e10cSrcweir 
NbcMove(const Size & rSiz)489cdf0e10cSrcweir void SdrRectObj::NbcMove(const Size& rSiz)
490cdf0e10cSrcweir {
491cdf0e10cSrcweir     SdrTextObj::NbcMove(rSiz);
492cdf0e10cSrcweir     SetXPolyDirty();
493cdf0e10cSrcweir }
494cdf0e10cSrcweir 
NbcResize(const Point & rRef,const Fraction & xFact,const Fraction & yFact)495cdf0e10cSrcweir void SdrRectObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
496cdf0e10cSrcweir {
497cdf0e10cSrcweir     SdrTextObj::NbcResize(rRef,xFact,yFact);
498cdf0e10cSrcweir     SetXPolyDirty();
499cdf0e10cSrcweir }
500cdf0e10cSrcweir 
NbcRotate(const Point & rRef,long nWink,double sn,double cs)501cdf0e10cSrcweir void SdrRectObj::NbcRotate(const Point& rRef, long nWink, double sn, double cs)
502cdf0e10cSrcweir {
503cdf0e10cSrcweir     SdrTextObj::NbcRotate(rRef,nWink,sn,cs);
504cdf0e10cSrcweir     SetXPolyDirty();
505cdf0e10cSrcweir }
506cdf0e10cSrcweir 
NbcShear(const Point & rRef,long nWink,double tn,FASTBOOL bVShear)507cdf0e10cSrcweir void SdrRectObj::NbcShear(const Point& rRef, long nWink, double tn, FASTBOOL bVShear)
508cdf0e10cSrcweir {
509cdf0e10cSrcweir     SdrTextObj::NbcShear(rRef,nWink,tn,bVShear);
510cdf0e10cSrcweir     SetXPolyDirty();
511cdf0e10cSrcweir }
512cdf0e10cSrcweir 
NbcMirror(const Point & rRef1,const Point & rRef2)513cdf0e10cSrcweir void SdrRectObj::NbcMirror(const Point& rRef1, const Point& rRef2)
514cdf0e10cSrcweir {
515cdf0e10cSrcweir     SdrTextObj::NbcMirror(rRef1,rRef2);
516cdf0e10cSrcweir     SetXPolyDirty();
517cdf0e10cSrcweir }
518cdf0e10cSrcweir 
DoMacro(const SdrObjMacroHitRec & rRec)519cdf0e10cSrcweir FASTBOOL SdrRectObj::DoMacro(const SdrObjMacroHitRec& rRec)
520cdf0e10cSrcweir {
521cdf0e10cSrcweir     return SdrTextObj::DoMacro(rRec);
522cdf0e10cSrcweir }
523cdf0e10cSrcweir 
GetMacroPopupComment(const SdrObjMacroHitRec & rRec) const524cdf0e10cSrcweir XubString SdrRectObj::GetMacroPopupComment(const SdrObjMacroHitRec& rRec) const
525cdf0e10cSrcweir {
526cdf0e10cSrcweir     return SdrTextObj::GetMacroPopupComment(rRec);
527cdf0e10cSrcweir }
528cdf0e10cSrcweir 
GetVertexGluePoint(sal_uInt16 nPosNum) const529cdf0e10cSrcweir SdrGluePoint SdrRectObj::GetVertexGluePoint(sal_uInt16 nPosNum) const
530cdf0e10cSrcweir {
531cdf0e10cSrcweir     sal_Int32 nWdt = ImpGetLineWdt(); // #i25616# ((XLineWidthItem&)(GetObjectItem(XATTR_LINEWIDTH))).GetValue();
532cdf0e10cSrcweir 
533cdf0e10cSrcweir     // #i25616#
534cdf0e10cSrcweir     if(!LineIsOutsideGeometry())
535cdf0e10cSrcweir     {
536cdf0e10cSrcweir         nWdt++;
537cdf0e10cSrcweir         nWdt /= 2;
538cdf0e10cSrcweir     }
539cdf0e10cSrcweir 
540cdf0e10cSrcweir     Point aPt;
541cdf0e10cSrcweir     switch (nPosNum) {
542cdf0e10cSrcweir         case 0: aPt=aRect.TopCenter();    aPt.Y()-=nWdt; break;
543cdf0e10cSrcweir         case 1: aPt=aRect.RightCenter();  aPt.X()+=nWdt; break;
544cdf0e10cSrcweir         case 2: aPt=aRect.BottomCenter(); aPt.Y()+=nWdt; break;
545cdf0e10cSrcweir         case 3: aPt=aRect.LeftCenter();   aPt.X()-=nWdt; break;
546cdf0e10cSrcweir     }
547cdf0e10cSrcweir     if (aGeo.nShearWink!=0) ShearPoint(aPt,aRect.TopLeft(),aGeo.nTan);
548cdf0e10cSrcweir     if (aGeo.nDrehWink!=0) RotatePoint(aPt,aRect.TopLeft(),aGeo.nSin,aGeo.nCos);
549cdf0e10cSrcweir     aPt-=GetSnapRect().Center();
550cdf0e10cSrcweir     SdrGluePoint aGP(aPt);
551cdf0e10cSrcweir     aGP.SetPercent(sal_False);
552cdf0e10cSrcweir     return aGP;
553cdf0e10cSrcweir }
554cdf0e10cSrcweir 
GetCornerGluePoint(sal_uInt16 nPosNum) const555cdf0e10cSrcweir SdrGluePoint SdrRectObj::GetCornerGluePoint(sal_uInt16 nPosNum) const
556cdf0e10cSrcweir {
557cdf0e10cSrcweir     sal_Int32 nWdt = ImpGetLineWdt(); // #i25616# ((XLineWidthItem&)(GetObjectItem(XATTR_LINEWIDTH))).GetValue();
558cdf0e10cSrcweir 
559cdf0e10cSrcweir     // #i25616#
560cdf0e10cSrcweir     if(!LineIsOutsideGeometry())
561cdf0e10cSrcweir     {
562cdf0e10cSrcweir         nWdt++;
563cdf0e10cSrcweir         nWdt /= 2;
564cdf0e10cSrcweir     }
565cdf0e10cSrcweir 
566cdf0e10cSrcweir     Point aPt;
567cdf0e10cSrcweir     switch (nPosNum) {
568cdf0e10cSrcweir         case 0: aPt=aRect.TopLeft();     aPt.X()-=nWdt; aPt.Y()-=nWdt; break;
569cdf0e10cSrcweir         case 1: aPt=aRect.TopRight();    aPt.X()+=nWdt; aPt.Y()-=nWdt; break;
570cdf0e10cSrcweir         case 2: aPt=aRect.BottomRight(); aPt.X()+=nWdt; aPt.Y()+=nWdt; break;
571cdf0e10cSrcweir         case 3: aPt=aRect.BottomLeft();  aPt.X()-=nWdt; aPt.Y()+=nWdt; break;
572cdf0e10cSrcweir     }
573cdf0e10cSrcweir     if (aGeo.nShearWink!=0) ShearPoint(aPt,aRect.TopLeft(),aGeo.nTan);
574cdf0e10cSrcweir     if (aGeo.nDrehWink!=0) RotatePoint(aPt,aRect.TopLeft(),aGeo.nSin,aGeo.nCos);
575cdf0e10cSrcweir     aPt-=GetSnapRect().Center();
576cdf0e10cSrcweir     SdrGluePoint aGP(aPt);
577cdf0e10cSrcweir     aGP.SetPercent(sal_False);
578cdf0e10cSrcweir     return aGP;
579cdf0e10cSrcweir }
580cdf0e10cSrcweir 
DoConvertToPolyObj(sal_Bool bBezier,bool bAddText) const581a5258243SPedro Giffuni SdrObject* SdrRectObj::DoConvertToPolyObj(sal_Bool bBezier, bool bAddText) const
582cdf0e10cSrcweir {
583cdf0e10cSrcweir     XPolygon aXP(ImpCalcXPoly(aRect,GetEckenradius()));
5847a060572Smseidel     { // #40608# Nur übergangsweise bis zum neuen TakeContour()
585cdf0e10cSrcweir         aXP.Remove(0,1);
586cdf0e10cSrcweir         aXP[aXP.GetPointCount()-1]=aXP[0];
587cdf0e10cSrcweir     }
588cdf0e10cSrcweir 
589cdf0e10cSrcweir     basegfx::B2DPolyPolygon aPolyPolygon(aXP.getB2DPolygon());
590cdf0e10cSrcweir     aPolyPolygon.removeDoublePoints();
591cdf0e10cSrcweir     SdrObject* pRet = 0L;
592cdf0e10cSrcweir 
593ddde725dSArmin Le Grand     // small correction: Do not create something when no fill and no line. To
594ddde725dSArmin Le Grand     // be sure to not damage something with non-text frames, do this only
595ddde725dSArmin Le Grand     // when used with bAddText==false from other converters
596ddde725dSArmin Le Grand     if((bAddText && !IsTextFrame()) || HasFill() || HasLine())
597cdf0e10cSrcweir     {
598cdf0e10cSrcweir         pRet = ImpConvertMakeObj(aPolyPolygon, sal_True, bBezier);
599cdf0e10cSrcweir     }
600cdf0e10cSrcweir 
601a5258243SPedro Giffuni     if(bAddText)
602a5258243SPedro Giffuni     {
603cdf0e10cSrcweir     pRet = ImpConvertAddText(pRet, bBezier);
604a5258243SPedro Giffuni     }
605cdf0e10cSrcweir 
606cdf0e10cSrcweir     return pRet;
607cdf0e10cSrcweir }
608cdf0e10cSrcweir 
Notify(SfxBroadcaster & rBC,const SfxHint & rHint)609cdf0e10cSrcweir void SdrRectObj::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
610cdf0e10cSrcweir {
611cdf0e10cSrcweir     SdrTextObj::Notify(rBC,rHint);
612cdf0e10cSrcweir     SetXPolyDirty(); // wg. Eckenradius
613cdf0e10cSrcweir }
614cdf0e10cSrcweir 
RestGeoData(const SdrObjGeoData & rGeo)615cdf0e10cSrcweir void SdrRectObj::RestGeoData(const SdrObjGeoData& rGeo)
616cdf0e10cSrcweir {
617cdf0e10cSrcweir     SdrTextObj::RestGeoData(rGeo);
618cdf0e10cSrcweir     SetXPolyDirty();
619cdf0e10cSrcweir }
620cdf0e10cSrcweir 
6217a060572Smseidel /* vim: set noet sw=4 ts=4: */
622