1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svdopath.cxx,v $
10 * $Revision: 1.51.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 <tools/bigint.hxx>
35 #include <svx/svdopath.hxx>
37 #include <svx/xpool.hxx>
38 #include <svx/xpoly.hxx>
39 #include <svx/svdattr.hxx>
40 #include <svx/svdtrans.hxx>
41 #include <svx/svdetc.hxx>
42 #include <svx/svddrag.hxx>
43 #include <svx/svdmodel.hxx>
44 #include <svx/svdpage.hxx>
45 #include <svx/svdhdl.hxx>
46 #include <svx/svdview.hxx> // fuer MovCreate bei Freihandlinien
47 #include "svdglob.hxx" // Stringcache
48 #include "svdstr.hrc" // Objektname
51 #pragma optimize ("",off)
52 #pragma warning(disable: 4748) // "... because optimizations are disabled ..."
55 #include <svx/xlnwtit.hxx>
56 #include <svx/xlnclit.hxx>
57 #include <svx/xflclit.hxx>
58 #include <svx/svdogrp.hxx>
60 #include <svx/polypolygoneditor.hxx>
61 #include <svx/xlntrit.hxx>
62 #include <vcl/salbtype.hxx> // FRound
63 #include "svdoimp.hxx"
64 #include <svx/sdr/contact/viewcontactofsdrpathobj.hxx>
65 #include <basegfx/matrix/b2dhommatrix.hxx>
67 // #104018# replace macros above with type-safe methods
68 inline sal_Int32
ImplTwipsToMM(sal_Int32 nVal
) { return ((nVal
* 127 + 36) / 72); }
69 inline sal_Int32
ImplMMToTwips(sal_Int32 nVal
) { return ((nVal
* 72 + 63) / 127); }
70 inline sal_Int64
ImplTwipsToMM(sal_Int64 nVal
) { return ((nVal
* 127 + 36) / 72); }
71 inline sal_Int64
ImplMMToTwips(sal_Int64 nVal
) { return ((nVal
* 72 + 63) / 127); }
72 inline double ImplTwipsToMM(double fVal
) { return (fVal
* (127.0 / 72.0)); }
73 inline double ImplMMToTwips(double fVal
) { return (fVal
* (72.0 / 127.0)); }
74 #include <basegfx/point/b2dpoint.hxx>
75 #include <basegfx/polygon/b2dpolypolygontools.hxx>
76 #include <basegfx/matrix/b2dhommatrix.hxx>
77 #include <basegfx/range/b2drange.hxx>
78 #include <basegfx/curve/b2dcubicbezier.hxx>
79 #include <basegfx/polygon/b2dpolygontools.hxx>
82 #include <svx/sdr/attribute/sdrtextattribute.hxx>
83 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
87 inline USHORT
GetPrevPnt(USHORT nPnt
, USHORT nPntMax
, FASTBOOL bClosed
)
98 inline USHORT
GetNextPnt(USHORT nPnt
, USHORT nPntMax
, FASTBOOL bClosed
)
101 if (nPnt
>nPntMax
|| (bClosed
&& nPnt
>=nPntMax
)) nPnt
=0;
105 struct ImpSdrPathDragData
: public SdrDragStatUserData
107 XPolygon aXP
; // Ausschnitt aud dem Originalpolygon
108 FASTBOOL bValid
; // FALSE = zu wenig Punkte
109 FASTBOOL bClosed
; // geschlossenes Objekt?
110 USHORT nPoly
; // Nummer des Polygons im PolyPolygon
111 USHORT nPnt
; // Punktnummer innerhalb des obigen Polygons
112 USHORT nPntAnz
; // Punktanzahl des Polygons
113 USHORT nPntMax
; // Maximaler Index
114 FASTBOOL bBegPnt
; // Gedraggter Punkt ist der Anfangspunkt einer Polyline
115 FASTBOOL bEndPnt
; // Gedraggter Punkt ist der Endpunkt einer Polyline
116 USHORT nPrevPnt
; // Index des vorherigen Punkts
117 USHORT nNextPnt
; // Index des naechsten Punkts
118 FASTBOOL bPrevIsBegPnt
; // Vorheriger Punkt ist Anfangspunkt einer Polyline
119 FASTBOOL bNextIsEndPnt
; // Folgepunkt ist Endpunkt einer Polyline
120 USHORT nPrevPrevPnt
; // Index des vorvorherigen Punkts
121 USHORT nNextNextPnt
; // Index des uebernaechsten Punkts
122 FASTBOOL bControl
; // Punkt ist ein Kontrollpunkt
123 FASTBOOL bIsPrevControl
; // Punkt ist Kontrollpunkt vor einem Stuetzpunkt
124 FASTBOOL bIsNextControl
; // Punkt ist Kontrollpunkt hinter einem Stuetzpunkt
125 FASTBOOL bPrevIsControl
; // Falls nPnt ein StPnt: Davor ist ein Kontrollpunkt
126 FASTBOOL bNextIsControl
; // Falls nPnt ein StPnt: Dahinter ist ein Kontrollpunkt
127 USHORT nPrevPrevPnt0
;
131 USHORT nNextNextPnt0
;
132 FASTBOOL bEliminate
; // Punkt loeschen? (wird von MovDrag gesetzt)
135 BOOL mbMultiPointDrag
;
136 const XPolyPolygon maOrig
;
141 ImpSdrPathDragData(const SdrPathObj
& rPO
, const SdrHdl
& rHdl
, BOOL bMuPoDr
, const SdrDragStat
& rDrag
);
142 void ResetPoly(const SdrPathObj
& rPO
);
143 BOOL
IsMultiPointDrag() const { return mbMultiPointDrag
; }
146 ImpSdrPathDragData::ImpSdrPathDragData(const SdrPathObj
& rPO
, const SdrHdl
& rHdl
, BOOL bMuPoDr
, const SdrDragStat
& rDrag
)
148 mbMultiPointDrag(bMuPoDr
),
149 maOrig(rPO
.GetPathPoly()),
154 const SdrMarkView
& rMarkView
= *rDrag
.GetView();
155 const SdrHdlList
& rHdlList
= rMarkView
.GetHdlList();
156 const sal_uInt32 nHdlCount
= rHdlList
.GetHdlCount();
157 const SdrObject
* pInteractionObject(nHdlCount
&& rHdlList
.GetHdl(0) ? rHdlList
.GetHdl(0)->GetObj() : 0);
159 for(sal_uInt32
a(0); a
< nHdlCount
; a
++)
161 SdrHdl
* pTestHdl
= rHdlList
.GetHdl(a
);
163 if(pTestHdl
&& pTestHdl
->IsSelected() && pTestHdl
->GetObj() == pInteractionObject
)
165 maHandles
.Insert(pTestHdl
, CONTAINER_APPEND
);
175 bClosed
=rPO
.IsClosed(); // geschlossenes Objekt?
176 nPoly
=(sal_uInt16
)rHdl
.GetPolyNum(); // Nummer des Polygons im PolyPolygon
177 nPnt
=(sal_uInt16
)rHdl
.GetPointNum(); // Punktnummer innerhalb des obigen Polygons
178 const XPolygon
aTmpXP(rPO
.GetPathPoly().getB2DPolygon(nPoly
));
179 nPntAnz
=aTmpXP
.GetPointCount(); // Punktanzahl des Polygons
180 if (nPntAnz
==0 || (bClosed
&& nPntAnz
==1)) return; // min. 1Pt bei Line, min. 2 bei Polygon
181 nPntMax
=nPntAnz
-1; // Maximaler Index
182 bBegPnt
=!bClosed
&& nPnt
==0; // Gedraggter Punkt ist der Anfangspunkt einer Polyline
183 bEndPnt
=!bClosed
&& nPnt
==nPntMax
; // Gedraggter Punkt ist der Endpunkt einer Polyline
184 if (bClosed
&& nPntAnz
<=3) { // Falls Polygon auch nur eine Linie ist
185 bBegPnt
=(nPntAnz
<3) || nPnt
==0;
186 bEndPnt
=(nPntAnz
<3) || nPnt
==nPntMax
-1;
188 nPrevPnt
=nPnt
; // Index des vorherigen Punkts
189 nNextPnt
=nPnt
; // Index des naechsten Punkts
190 if (!bBegPnt
) nPrevPnt
=GetPrevPnt(nPnt
,nPntMax
,bClosed
);
191 if (!bEndPnt
) nNextPnt
=GetNextPnt(nPnt
,nPntMax
,bClosed
);
192 bPrevIsBegPnt
=bBegPnt
|| (!bClosed
&& nPrevPnt
==0);
193 bNextIsEndPnt
=bEndPnt
|| (!bClosed
&& nNextPnt
==nPntMax
);
194 nPrevPrevPnt
=nPnt
; // Index des vorvorherigen Punkts
195 nNextNextPnt
=nPnt
; // Index des uebernaechsten Punkts
196 if (!bPrevIsBegPnt
) nPrevPrevPnt
=GetPrevPnt(nPrevPnt
,nPntMax
,bClosed
);
197 if (!bNextIsEndPnt
) nNextNextPnt
=GetNextPnt(nNextPnt
,nPntMax
,bClosed
);
198 bControl
=rHdl
.IsPlusHdl(); // Punkt ist ein Kontrollpunkt
199 bIsPrevControl
=FALSE
; // Punkt ist Kontrollpunkt vor einem Stuetzpunkt
200 bIsNextControl
=FALSE
; // Punkt ist Kontrollpunkt hinter einem Stuetzpunkt
201 bPrevIsControl
=FALSE
; // Falls nPnt ein StPnt: Davor ist ein Kontrollpunkt
202 bNextIsControl
=FALSE
; // Falls nPnt ein StPnt: Dahinter ist ein Kontrollpunkt
204 bIsPrevControl
=aTmpXP
.IsControl(nPrevPnt
);
205 bIsNextControl
=!bIsPrevControl
;
207 bPrevIsControl
=!bBegPnt
&& !bPrevIsBegPnt
&& aTmpXP
.GetFlags(nPrevPnt
)==XPOLY_CONTROL
;
208 bNextIsControl
=!bEndPnt
&& !bNextIsEndPnt
&& aTmpXP
.GetFlags(nNextPnt
)==XPOLY_CONTROL
;
210 nPrevPrevPnt0
=nPrevPrevPnt
;
214 nNextNextPnt0
=nNextNextPnt
;
226 void ImpSdrPathDragData::ResetPoly(const SdrPathObj
& rPO
)
228 const XPolygon
aTmpXP(rPO
.GetPathPoly().getB2DPolygon(nPoly
));
229 aXP
[0]=aTmpXP
[nPrevPrevPnt0
]; aXP
.SetFlags(0,aTmpXP
.GetFlags(nPrevPrevPnt0
));
230 aXP
[1]=aTmpXP
[nPrevPnt0
]; aXP
.SetFlags(1,aTmpXP
.GetFlags(nPrevPnt0
));
231 aXP
[2]=aTmpXP
[nPnt0
]; aXP
.SetFlags(2,aTmpXP
.GetFlags(nPnt0
));
232 aXP
[3]=aTmpXP
[nNextPnt0
]; aXP
.SetFlags(3,aTmpXP
.GetFlags(nNextPnt0
));
233 aXP
[4]=aTmpXP
[nNextNextPnt0
]; aXP
.SetFlags(4,aTmpXP
.GetFlags(nNextNextPnt0
));
236 /*************************************************************************/
238 struct ImpPathCreateUser
: public SdrDragStatUserData
257 FASTBOOL bBezHasCtrl0
;
264 FASTBOOL bMixedCreate
;
265 USHORT nBezierStartPoint
;
266 SdrObjKind eStartKind
;
270 ImpPathCreateUser(): nCircRadius(0),nCircStWink(0),nCircRelWink(0),
271 bBezier(FALSE
),bBezHasCtrl0(FALSE
),bCurve(FALSE
),bCircle(FALSE
),bAngleSnap(FALSE
),bLine(FALSE
),bLine90(FALSE
),bRect(FALSE
),
272 bMixedCreate(FALSE
),nBezierStartPoint(0),eStartKind(OBJ_NONE
),eAktKind(OBJ_NONE
) { }
274 void ResetFormFlags() { bBezier
=FALSE
; bCurve
=FALSE
; bCircle
=FALSE
; bLine
=FALSE
; bRect
=FALSE
; }
275 FASTBOOL
IsFormFlag() const { return bBezier
|| bCurve
|| bCircle
|| bLine
|| bRect
; }
276 XPolygon
GetFormPoly() const;
277 FASTBOOL
CalcBezier(const Point
& rP1
, const Point
& rP2
, const Point
& rDir
, FASTBOOL bMouseDown
);
278 XPolygon
GetBezierPoly() const;
279 //FASTBOOL CalcCurve(const Point& rP1, const Point& rP2, const Point& rDir, SdrView* pView) { return FALSE; }
280 XPolygon
GetCurvePoly() const { return XPolygon(); }
281 FASTBOOL
CalcCircle(const Point
& rP1
, const Point
& rP2
, const Point
& rDir
, SdrView
* pView
);
282 XPolygon
GetCirclePoly() const;
283 FASTBOOL
CalcLine(const Point
& rP1
, const Point
& rP2
, const Point
& rDir
, SdrView
* pView
);
284 Point
CalcLine(const Point
& rCsr
, long nDirX
, long nDirY
, SdrView
* pView
) const;
285 XPolygon
GetLinePoly() const;
286 FASTBOOL
CalcRect(const Point
& rP1
, const Point
& rP2
, const Point
& rDir
, SdrView
* pView
);
287 XPolygon
GetRectPoly() const;
290 XPolygon
ImpPathCreateUser::GetFormPoly() const
292 if (bBezier
) return GetBezierPoly();
293 if (bCurve
) return GetCurvePoly();
294 if (bCircle
) return GetCirclePoly();
295 if (bLine
) return GetLinePoly();
296 if (bRect
) return GetRectPoly();
300 FASTBOOL
ImpPathCreateUser::CalcBezier(const Point
& rP1
, const Point
& rP2
, const Point
& rDir
, FASTBOOL bMouseDown
)
308 // Also copy the end point when no end point is set yet
309 if (!bMouseDown
|| (0L == aBezEnd
.X() && 0L == aBezEnd
.Y())) aBezEnd
=rP2
;
315 XPolygon
ImpPathCreateUser::GetBezierPoly() const
318 aXP
[0]=aBezStart
; aXP
.SetFlags(0,XPOLY_SMOOTH
);
319 aXP
[1]=aBezCtrl1
; aXP
.SetFlags(1,XPOLY_CONTROL
);
320 aXP
[2]=aBezCtrl2
; aXP
.SetFlags(2,XPOLY_CONTROL
);
325 FASTBOOL
ImpPathCreateUser::CalcCircle(const Point
& rP1
, const Point
& rP2
, const Point
& rDir
, SdrView
* pView
)
327 long nTangAngle
=GetAngle(rDir
);
331 long dx
=rP2
.X()-rP1
.X();
332 long dy
=rP2
.Y()-rP1
.Y();
333 long dAngle
=GetAngle(Point(dx
,dy
))-nTangAngle
;
334 dAngle
=NormAngle360(dAngle
);
335 long nTmpAngle
=NormAngle360(9000-dAngle
);
336 FASTBOOL bRet
=nTmpAngle
!=9000 && nTmpAngle
!=27000;
339 double cs
=cos(nTmpAngle
*nPi180
);
340 double nR
=(double)GetLen(Point(dx
,dy
))/cs
/2;
344 nCircStWink
=NormAngle360(nTangAngle
-9000);
345 nCircRelWink
=NormAngle360(2*dAngle
);
346 aCircCenter
.X()+=Round(nRad
*cos((nTangAngle
+9000)*nPi180
));
347 aCircCenter
.Y()-=Round(nRad
*sin((nTangAngle
+9000)*nPi180
));
349 nCircStWink
=NormAngle360(nTangAngle
+9000);
350 nCircRelWink
=-NormAngle360(36000-2*dAngle
);
351 aCircCenter
.X()+=Round(nRad
*cos((nTangAngle
-9000)*nPi180
));
352 aCircCenter
.Y()-=Round(nRad
*sin((nTangAngle
-9000)*nPi180
));
354 bAngleSnap
=pView
!=NULL
&& pView
->IsAngleSnapEnabled();
356 long nSA
=pView
->GetSnapAngle();
357 if (nSA
!=0) { // Winkelfang
358 FASTBOOL bNeg
=nCircRelWink
<0;
359 if (bNeg
) nCircRelWink
=-nCircRelWink
;
363 nCircRelWink
=NormAngle360(nCircRelWink
);
364 if (bNeg
) nCircRelWink
=-nCircRelWink
;
368 if (nRad
==0 || Abs(nCircRelWink
)<5) bRet
=FALSE
;
373 XPolygon
ImpPathCreateUser::GetCirclePoly() const
375 if (nCircRelWink
>=0) {
376 XPolygon
aXP(aCircCenter
,nCircRadius
,nCircRadius
,
377 USHORT((nCircStWink
+5)/10),USHORT((nCircStWink
+nCircRelWink
+5)/10),FALSE
);
378 aXP
[0]=aCircStart
; aXP
.SetFlags(0,XPOLY_SMOOTH
);
379 if (!bAngleSnap
) aXP
[aXP
.GetPointCount()-1]=aCircEnd
;
382 XPolygon
aXP(aCircCenter
,nCircRadius
,nCircRadius
,
383 USHORT(NormAngle360(nCircStWink
+nCircRelWink
+5)/10),USHORT((nCircStWink
+5)/10),FALSE
);
384 USHORT nAnz
=aXP
.GetPointCount();
385 for (USHORT nNum
=nAnz
/2; nNum
>0;) {
386 nNum
--; // XPoly Punktreihenfolge umkehren
387 USHORT n2
=nAnz
-nNum
-1;
388 Point
aPt(aXP
[nNum
]);
392 aXP
[0]=aCircStart
; aXP
.SetFlags(0,XPOLY_SMOOTH
);
393 if (!bAngleSnap
) aXP
[aXP
.GetPointCount()-1]=aCircEnd
;
398 Point
ImpPathCreateUser::CalcLine(const Point
& aCsr
, long nDirX
, long nDirY
, SdrView
* pView
) const
400 long x
=aCsr
.X(),x1
=x
,x2
=x
;
401 long y
=aCsr
.Y(),y1
=y
,y2
=y
;
402 FASTBOOL bHLin
=nDirY
==0;
403 FASTBOOL bVLin
=nDirX
==0;
407 x1
=BigMulDiv(y
,nDirX
,nDirY
);
408 y2
=BigMulDiv(x
,nDirY
,nDirX
);
409 long l1
=Abs(x1
)+Abs(y1
);
410 long l2
=Abs(x2
)+Abs(y2
);
411 if (l1
<=l2
!=(pView
!=NULL
&& pView
->IsBigOrtho())) {
420 FASTBOOL
ImpPathCreateUser::CalcLine(const Point
& rP1
, const Point
& rP2
, const Point
& rDir
, SdrView
* pView
)
425 if (rP1
==rP2
|| (rDir
.X()==0 && rDir
.Y()==0)) { bLine
=FALSE
; return FALSE
; }
426 Point
aTmpPt(rP2
-rP1
);
429 Point
aP1(CalcLine(aTmpPt
, nDirX
, nDirY
,pView
)); aP1
-=aTmpPt
; long nQ1
=Abs(aP1
.X())+Abs(aP1
.Y());
430 Point
aP2(CalcLine(aTmpPt
, nDirY
,-nDirX
,pView
)); aP2
-=aTmpPt
; long nQ2
=Abs(aP2
.X())+Abs(aP2
.Y());
431 if (pView
!=NULL
&& pView
->IsOrtho()) nQ1
=0; // Ortho schaltet rechtwinklig aus
433 if (!bLine90
) { // glatter Uebergang
435 } else { // rechtwinkliger Uebergang
442 XPolygon
ImpPathCreateUser::GetLinePoly() const
445 aXP
[0]=aLineStart
; if (!bLine90
) aXP
.SetFlags(0,XPOLY_SMOOTH
);
450 FASTBOOL
ImpPathCreateUser::CalcRect(const Point
& rP1
, const Point
& rP2
, const Point
& rDir
, SdrView
* pView
)
455 if (rP1
==rP2
|| (rDir
.X()==0 && rDir
.Y()==0)) { bRect
=FALSE
; return FALSE
; }
456 Point
aTmpPt(rP2
-rP1
);
461 FASTBOOL bHLin
=nDirY
==0;
462 FASTBOOL bVLin
=nDirX
==0;
466 y
=BigMulDiv(x
,nDirY
,nDirX
);
467 long nHypLen
=aTmpPt
.Y()-y
;
468 long nTangAngle
=-GetAngle(rDir
);
470 double a
=nTangAngle
*nPi180
;
473 double nGKathLen
=nHypLen
*sn
;
474 y
+=Round(nGKathLen
*sn
);
475 x
+=Round(nGKathLen
*cs
);
479 if (pView
!=NULL
&& pView
->IsOrtho()) {
480 long dx1
=aRectP2
.X()-aRectP1
.X(); long dx1a
=Abs(dx1
);
481 long dy1
=aRectP2
.Y()-aRectP1
.Y(); long dy1a
=Abs(dy1
);
482 long dx2
=aRectP3
.X()-aRectP2
.X(); long dx2a
=Abs(dx2
);
483 long dy2
=aRectP3
.Y()-aRectP2
.Y(); long dy2a
=Abs(dy2
);
484 FASTBOOL b1MoreThan2
=dx1a
+dy1a
>dx2a
+dy2a
;
485 if (b1MoreThan2
!= pView
->IsBigOrtho()) {
486 long xtemp
=dy2a
-dx1a
; if (dx1
<0) xtemp
=-xtemp
;
487 long ytemp
=dx2a
-dy1a
; if (dy1
<0) ytemp
=-ytemp
;
493 long xtemp
=dy1a
-dx2a
; if (dx2
<0) xtemp
=-xtemp
;
494 long ytemp
=dx1a
-dy2a
; if (dy2
<0) ytemp
=-ytemp
;
503 XPolygon
ImpPathCreateUser::GetRectPoly() const
506 aXP
[0]=aRectP1
; aXP
.SetFlags(0,XPOLY_SMOOTH
);
508 if (aRectP3
!=aRectP2
) aXP
[2]=aRectP3
;
512 /*************************************************************************/
514 class ImpPathForDragAndCreate
516 SdrPathObj
& mrSdrPathObject
;
517 XPolyPolygon aPathPolygon
;
518 SdrObjKind meObjectKind
;
519 ImpSdrPathDragData
* mpSdrPathDragData
;
523 ImpPathForDragAndCreate(SdrPathObj
& rSdrPathObject
);
524 ~ImpPathForDragAndCreate();
527 bool beginPathDrag( SdrDragStat
& rDrag
) const;
528 bool movePathDrag( SdrDragStat
& rDrag
) const;
529 bool endPathDrag( SdrDragStat
& rDrag
);
530 //void cancelSpecialDrag( SdrDragStat& rDrag ) const;
531 String
getSpecialDragComment(const SdrDragStat
& rDrag
) const;
532 basegfx::B2DPolyPolygon
getSpecialDragPoly(const SdrDragStat
& rDrag
) const;
535 FASTBOOL
BegCreate(SdrDragStat
& rStat
);
536 FASTBOOL
MovCreate(SdrDragStat
& rStat
);
537 FASTBOOL
EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
);
538 FASTBOOL
BckCreate(SdrDragStat
& rStat
);
539 void BrkCreate(SdrDragStat
& rStat
);
540 Pointer
GetCreatePointer() const;
543 bool IsClosed(SdrObjKind eKind
) const { return eKind
==OBJ_POLY
|| eKind
==OBJ_PATHPOLY
|| eKind
==OBJ_PATHFILL
|| eKind
==OBJ_FREEFILL
|| eKind
==OBJ_SPLNFILL
; }
544 bool IsFreeHand(SdrObjKind eKind
) const { return eKind
==OBJ_FREELINE
|| eKind
==OBJ_FREEFILL
; }
545 bool IsBezier(SdrObjKind eKind
) const { return eKind
==OBJ_PATHLINE
|| eKind
==OBJ_PATHFILL
; }
546 bool IsCreating() const { return mbCreating
; }
549 basegfx::B2DPolyPolygon
TakeObjectPolyPolygon(const SdrDragStat
& rDrag
) const;
550 basegfx::B2DPolyPolygon
TakeDragPolyPolygon(const SdrDragStat
& rDrag
) const;
551 basegfx::B2DPolyPolygon
getModifiedPolyPolygon() const { return aPathPolygon
.getB2DPolyPolygon(); }
554 ImpPathForDragAndCreate::ImpPathForDragAndCreate(SdrPathObj
& rSdrPathObject
)
555 : mrSdrPathObject(rSdrPathObject
),
556 aPathPolygon(rSdrPathObject
.GetPathPoly()),
557 meObjectKind(mrSdrPathObject
.meKind
),
558 mpSdrPathDragData(0),
563 ImpPathForDragAndCreate::~ImpPathForDragAndCreate()
565 if(mpSdrPathDragData
)
567 delete mpSdrPathDragData
;
571 bool ImpPathForDragAndCreate::beginPathDrag( SdrDragStat
& rDrag
) const
573 const SdrHdl
* pHdl
=rDrag
.GetHdl();
577 BOOL
bMultiPointDrag(TRUE
);
579 if(aPathPolygon
[(sal_uInt16
)pHdl
->GetPolyNum()].IsControl((sal_uInt16
)pHdl
->GetPointNum()))
580 bMultiPointDrag
= FALSE
;
584 const SdrMarkView
& rMarkView
= *rDrag
.GetView();
585 const SdrHdlList
& rHdlList
= rMarkView
.GetHdlList();
586 const sal_uInt32 nHdlCount
= rHdlList
.GetHdlCount();
587 const SdrObject
* pInteractionObject(nHdlCount
&& rHdlList
.GetHdl(0) ? rHdlList
.GetHdl(0)->GetObj() : 0);
588 sal_uInt32
nSelectedPoints(0);
590 for(sal_uInt32
a(0); a
< nHdlCount
; a
++)
592 SdrHdl
* pTestHdl
= rHdlList
.GetHdl(a
);
594 if(pTestHdl
&& pTestHdl
->IsSelected() && pTestHdl
->GetObj() == pInteractionObject
)
600 if(nSelectedPoints
<= 1)
601 bMultiPointDrag
= FALSE
;
604 ((ImpPathForDragAndCreate
*)this)->mpSdrPathDragData
= new ImpSdrPathDragData(mrSdrPathObject
,*pHdl
,bMultiPointDrag
,rDrag
);
606 if(!mpSdrPathDragData
|| !mpSdrPathDragData
->bValid
)
608 DBG_ERROR("ImpPathForDragAndCreate::BegDrag(): ImpSdrPathDragData ist ungueltig");
609 delete mpSdrPathDragData
;
610 ((ImpPathForDragAndCreate
*)this)->mpSdrPathDragData
= 0;
617 bool ImpPathForDragAndCreate::movePathDrag( SdrDragStat
& rDrag
) const
619 if(!mpSdrPathDragData
|| !mpSdrPathDragData
->bValid
)
621 DBG_ERROR("ImpPathForDragAndCreate::MovDrag(): ImpSdrPathDragData ist ungueltig");
625 if(mpSdrPathDragData
->IsMultiPointDrag())
627 Point
aDelta(rDrag
.GetNow() - rDrag
.GetStart());
629 if(aDelta
.X() || aDelta
.Y())
631 for(sal_uInt32
a(0); a
< mpSdrPathDragData
->maHandles
.Count(); a
++)
633 SdrHdl
* pHandle
= (SdrHdl
*)mpSdrPathDragData
->maHandles
.GetObject(a
);
634 const sal_uInt16
nPolyIndex((sal_uInt16
)pHandle
->GetPolyNum());
635 const sal_uInt16
nPointIndex((sal_uInt16
)pHandle
->GetPointNum());
636 const XPolygon
& rOrig
= mpSdrPathDragData
->maOrig
[nPolyIndex
];
637 XPolygon
& rMove
= mpSdrPathDragData
->maMove
[nPolyIndex
];
638 const sal_uInt16
nPointCount(rOrig
.GetPointCount());
639 BOOL
bClosed(rOrig
[0] == rOrig
[nPointCount
-1]);
642 rMove
[nPointIndex
] = rOrig
[nPointIndex
] + aDelta
;
644 // when point is first and poly closed, move close point, too.
645 if(nPointCount
> 0 && !nPointIndex
&& bClosed
)
647 rMove
[nPointCount
- 1] = rOrig
[nPointCount
- 1] + aDelta
;
649 // when moving the last point it may be necessary to move the
650 // control point in front of this one, too.
651 if(nPointCount
> 1 && rOrig
.IsControl(nPointCount
- 2))
652 rMove
[nPointCount
- 2] = rOrig
[nPointCount
- 2] + aDelta
;
655 // is a control point before this?
656 if(nPointIndex
> 0 && rOrig
.IsControl(nPointIndex
- 1))
659 rMove
[nPointIndex
- 1] = rOrig
[nPointIndex
- 1] + aDelta
;
662 // is a control point after this?
663 if(nPointIndex
+ 1 < nPointCount
&& rOrig
.IsControl(nPointIndex
+ 1))
666 rMove
[nPointIndex
+ 1] = rOrig
[nPointIndex
+ 1] + aDelta
;
673 mpSdrPathDragData
->ResetPoly(mrSdrPathObject
);
675 // Div. Daten lokal Kopieren fuer weniger Code und schnelleren Zugriff
676 FASTBOOL bClosed
=mpSdrPathDragData
->bClosed
; // geschlossenes Objekt?
677 USHORT nPnt
=mpSdrPathDragData
->nPnt
; // Punktnummer innerhalb des obigen Polygons
678 FASTBOOL bBegPnt
=mpSdrPathDragData
->bBegPnt
; // Gedraggter Punkt ist der Anfangspunkt einer Polyline
679 FASTBOOL bEndPnt
=mpSdrPathDragData
->bEndPnt
; // Gedraggter Punkt ist der Endpunkt einer Polyline
680 USHORT nPrevPnt
=mpSdrPathDragData
->nPrevPnt
; // Index des vorherigen Punkts
681 USHORT nNextPnt
=mpSdrPathDragData
->nNextPnt
; // Index des naechsten Punkts
682 FASTBOOL bPrevIsBegPnt
=mpSdrPathDragData
->bPrevIsBegPnt
; // Vorheriger Punkt ist Anfangspunkt einer Polyline
683 FASTBOOL bNextIsEndPnt
=mpSdrPathDragData
->bNextIsEndPnt
; // Folgepunkt ist Endpunkt einer Polyline
684 USHORT nPrevPrevPnt
=mpSdrPathDragData
->nPrevPrevPnt
; // Index des vorvorherigen Punkts
685 USHORT nNextNextPnt
=mpSdrPathDragData
->nNextNextPnt
; // Index des uebernaechsten Punkts
686 FASTBOOL bControl
=mpSdrPathDragData
->bControl
; // Punkt ist ein Kontrollpunkt
687 //FASTBOOL bIsPrevControl=mpSdrPathDragData->bIsPrevControl; // Punkt ist Kontrollpunkt vor einem Stuetzpunkt
688 FASTBOOL bIsNextControl
=mpSdrPathDragData
->bIsNextControl
; // Punkt ist Kontrollpunkt hinter einem Stuetzpunkt
689 FASTBOOL bPrevIsControl
=mpSdrPathDragData
->bPrevIsControl
; // Falls nPnt ein StPnt: Davor ist ein Kontrollpunkt
690 FASTBOOL bNextIsControl
=mpSdrPathDragData
->bNextIsControl
; // Falls nPnt ein StPnt: Dahinter ist ein Kontrollpunkt
692 // Ortho bei Linien/Polygonen = Winkel beibehalten
693 if (!bControl
&& rDrag
.GetView()!=NULL
&& rDrag
.GetView()->IsOrtho()) {
694 FASTBOOL bBigOrtho
=rDrag
.GetView()->IsBigOrtho();
695 Point
aPos(rDrag
.GetNow()); // die aktuelle Position
696 Point
aPnt(mpSdrPathDragData
->aXP
[nPnt
]); // der gedraggte Punkt
697 USHORT nPnt1
=0xFFFF,nPnt2
=0xFFFF; // seine Nachbarpunkte
698 Point aNeuPos1
,aNeuPos2
; // die neuen Alternativen fuer aPos
699 FASTBOOL bPnt1
=FALSE
,bPnt2
=FALSE
; // die neuen Alternativen gueltig?
700 if (!bClosed
&& mpSdrPathDragData
->nPntAnz
>=2) { // Mind. 2 Pt bei Linien
701 if (!bBegPnt
) nPnt1
=nPrevPnt
;
702 if (!bEndPnt
) nPnt2
=nNextPnt
;
704 if (bClosed
&& mpSdrPathDragData
->nPntAnz
>=3) { // Mind. 3 Pt bei Polygon
708 if (nPnt1
!=0xFFFF && !bPrevIsControl
) {
709 Point aPnt1
=mpSdrPathDragData
->aXP
[nPnt1
];
710 long ndx0
=aPnt
.X()-aPnt1
.X();
711 long ndy0
=aPnt
.Y()-aPnt1
.Y();
712 FASTBOOL bHLin
=ndy0
==0;
713 FASTBOOL bVLin
=ndx0
==0;
714 if (!bHLin
|| !bVLin
) {
715 long ndx
=aPos
.X()-aPnt1
.X();
716 long ndy
=aPos
.Y()-aPnt1
.Y();
718 double nXFact
=0; if (!bVLin
) nXFact
=(double)ndx
/(double)ndx0
;
719 double nYFact
=0; if (!bHLin
) nYFact
=(double)ndy
/(double)ndy0
;
720 FASTBOOL bHor
=bHLin
|| (!bVLin
&& (nXFact
>nYFact
) ==bBigOrtho
);
721 FASTBOOL bVer
=bVLin
|| (!bHLin
&& (nXFact
<=nYFact
)==bBigOrtho
);
722 if (bHor
) ndy
=long(ndy0
*nXFact
);
723 if (bVer
) ndx
=long(ndx0
*nYFact
);
729 if (nPnt2
!=0xFFFF && !bNextIsControl
) {
730 Point aPnt2
=mpSdrPathDragData
->aXP
[nPnt2
];
731 long ndx0
=aPnt
.X()-aPnt2
.X();
732 long ndy0
=aPnt
.Y()-aPnt2
.Y();
733 FASTBOOL bHLin
=ndy0
==0;
734 FASTBOOL bVLin
=ndx0
==0;
735 if (!bHLin
|| !bVLin
) {
736 long ndx
=aPos
.X()-aPnt2
.X();
737 long ndy
=aPos
.Y()-aPnt2
.Y();
739 double nXFact
=0; if (!bVLin
) nXFact
=(double)ndx
/(double)ndx0
;
740 double nYFact
=0; if (!bHLin
) nYFact
=(double)ndy
/(double)ndy0
;
741 FASTBOOL bHor
=bHLin
|| (!bVLin
&& (nXFact
>nYFact
) ==bBigOrtho
);
742 FASTBOOL bVer
=bVLin
|| (!bHLin
&& (nXFact
<=nYFact
)==bBigOrtho
);
743 if (bHor
) ndy
=long(ndy0
*nXFact
);
744 if (bVer
) ndx
=long(ndx0
*nYFact
);
750 if (bPnt1
&& bPnt2
) { // beide Alternativen vorhanden (Konkurenz)
751 BigInt
nX1(aNeuPos1
.X()-aPos
.X()); nX1
*=nX1
;
752 BigInt
nY1(aNeuPos1
.Y()-aPos
.Y()); nY1
*=nY1
;
753 BigInt
nX2(aNeuPos2
.X()-aPos
.X()); nX2
*=nX2
;
754 BigInt
nY2(aNeuPos2
.Y()-aPos
.Y()); nY2
*=nY2
;
755 nX1
+=nY1
; // Korrekturabstand zum Quadrat
756 nX2
+=nY2
; // Korrekturabstand zum Quadrat
757 // Die Alternative mit dem geringeren Korrekturbedarf gewinnt
758 if (nX1
<nX2
) bPnt2
=FALSE
; else bPnt1
=FALSE
;
760 if (bPnt1
) rDrag
.Now()=aNeuPos1
;
761 if (bPnt2
) rDrag
.Now()=aNeuPos2
;
763 rDrag
.SetActionRect(Rectangle(rDrag
.GetNow(),rDrag
.GetNow()));
765 // IBM Special: Punkte eliminieren, wenn die beiden angrenzenden
766 // Linien eh' fast 180 deg sind.
767 if (!bControl
&& rDrag
.GetView()!=NULL
&& rDrag
.GetView()->IsEliminatePolyPoints() &&
768 !bBegPnt
&& !bEndPnt
&& !bPrevIsControl
&& !bNextIsControl
)
770 Point
aPt(mpSdrPathDragData
->aXP
[nNextPnt
]);
772 long nWink1
=GetAngle(aPt
);
774 aPt
-=mpSdrPathDragData
->aXP
[nPrevPnt
];
775 long nWink2
=GetAngle(aPt
);
776 long nDiff
=nWink1
-nWink2
;
778 mpSdrPathDragData
->bEliminate
=nDiff
<=rDrag
.GetView()->GetEliminatePolyPointLimitAngle();
779 if (mpSdrPathDragData
->bEliminate
) { // Position anpassen, damit Smooth an den Enden stimmt
780 aPt
=mpSdrPathDragData
->aXP
[nNextPnt
];
781 aPt
+=mpSdrPathDragData
->aXP
[nPrevPnt
];
787 // Um diese Entfernung wurde insgesamt gedraggd
788 Point
aDiff(rDrag
.GetNow()); aDiff
-=mpSdrPathDragData
->aXP
[nPnt
];
790 // Insgesamt sind 8 Faelle moeglich:
791 // X 1. Weder rechts noch links Ctrl.
792 // o--X--o 2. Rechts und links Ctrl, gedraggd wird St.
793 // o--X 3. Nur links Ctrl, gedraggd wird St.
794 // X--o 4. Nur rechts Ctrl, gedraggd wird St.
795 // x--O--o 5. Rechts und links Ctrl, gedraggd wird links.
796 // x--O 6. Nur links Ctrl, gedraggd wird links.
797 // o--O--x 7. Rechts und links Ctrl, gedraggd wird rechts.
798 // O--x 8. Nur rechts Ctrl, gedraggd wird rechts.
799 // Zusaetzlich ist zu beachten, dass das Veraendern einer Linie (keine Kurve)
800 // eine evtl. Kurve am anderen Ende der Linie bewirkt, falls dort Smooth
801 // gesetzt ist (Kontrollpunktausrichtung an Gerade).
803 mpSdrPathDragData
->aXP
[nPnt
]+=aDiff
;
805 // Nun symmetrische PlusHandles etc. checken
806 if (bControl
) { // Faelle 5,6,7,8
807 USHORT nSt
=nPnt
; // der zugehoerige Stuetzpunkt
808 USHORT nFix
=nPnt
; // der gegenueberliegende Kontrollpunkt
809 if (bIsNextControl
) { // Wenn der naechste ein Kontrollpunkt ist, muss der vorh. der Stuetzpunkt sein
816 if (mpSdrPathDragData
->aXP
.IsSmooth(nSt
)) {
817 mpSdrPathDragData
->aXP
.CalcSmoothJoin(nSt
,nPnt
,nFix
);
821 if (!bControl
) { // Faelle 1,2,3,4 wobei bei 1 nix passiert und bei 3+4 unten noch mehr folgt
822 // die beiden Kontrollpunkte mit verschieben
823 if (bPrevIsControl
) mpSdrPathDragData
->aXP
[nPrevPnt
]+=aDiff
;
824 if (bNextIsControl
) mpSdrPathDragData
->aXP
[nNextPnt
]+=aDiff
;
825 // Kontrollpunkt ggf. an Gerade ausrichten
826 if (mpSdrPathDragData
->aXP
.IsSmooth(nPnt
)) {
827 if (bPrevIsControl
&& !bNextIsControl
&& !bEndPnt
) { // Fall 3
828 mpSdrPathDragData
->aXP
.CalcSmoothJoin(nPnt
,nNextPnt
,nPrevPnt
);
830 if (bNextIsControl
&& !bPrevIsControl
&& !bBegPnt
) { // Fall 4
831 mpSdrPathDragData
->aXP
.CalcSmoothJoin(nPnt
,nPrevPnt
,nNextPnt
);
834 // Und nun noch die anderen Enden der Strecken ueberpruefen (nPnt+-1).
835 // Ist dort eine Kurve (IsControl(nPnt+-2)) mit SmoothJoin (nPnt+-1),
836 // so muss der entsprechende Kontrollpunkt (nPnt+-2) angepasst werden.
837 if (!bBegPnt
&& !bPrevIsControl
&& !bPrevIsBegPnt
&& mpSdrPathDragData
->aXP
.IsSmooth(nPrevPnt
)) {
838 if (mpSdrPathDragData
->aXP
.IsControl(nPrevPrevPnt
)) {
839 mpSdrPathDragData
->aXP
.CalcSmoothJoin(nPrevPnt
,nPnt
,nPrevPrevPnt
);
842 if (!bEndPnt
&& !bNextIsControl
&& !bNextIsEndPnt
&& mpSdrPathDragData
->aXP
.IsSmooth(nNextPnt
)) {
843 if (mpSdrPathDragData
->aXP
.IsControl(nNextNextPnt
)) {
844 mpSdrPathDragData
->aXP
.CalcSmoothJoin(nNextPnt
,nPnt
,nNextNextPnt
);
853 bool ImpPathForDragAndCreate::endPathDrag(SdrDragStat
& rDrag
)
857 bool bLineGlueMirror(OBJ_LINE
== meObjectKind
);
858 if (bLineGlueMirror
) { // #40549#
859 XPolygon
& rXP
=aPathPolygon
[0];
864 if(!mpSdrPathDragData
|| !mpSdrPathDragData
->bValid
)
866 DBG_ERROR("ImpPathForDragAndCreate::MovDrag(): ImpSdrPathDragData ist ungueltig");
870 if(mpSdrPathDragData
->IsMultiPointDrag())
872 aPathPolygon
= mpSdrPathDragData
->maMove
;
876 const SdrHdl
* pHdl
=rDrag
.GetHdl();
878 // Referenz auf das Polygon
879 XPolygon
& rXP
=aPathPolygon
[(sal_uInt16
)pHdl
->GetPolyNum()];
881 // Die 5 Punkte die sich evtl. geaendert haben
882 if (!mpSdrPathDragData
->bPrevIsBegPnt
) rXP
[mpSdrPathDragData
->nPrevPrevPnt0
]=mpSdrPathDragData
->aXP
[mpSdrPathDragData
->nPrevPrevPnt
];
883 if (!mpSdrPathDragData
->bNextIsEndPnt
) rXP
[mpSdrPathDragData
->nNextNextPnt0
]=mpSdrPathDragData
->aXP
[mpSdrPathDragData
->nNextNextPnt
];
884 if (!mpSdrPathDragData
->bBegPnt
) rXP
[mpSdrPathDragData
->nPrevPnt0
] =mpSdrPathDragData
->aXP
[mpSdrPathDragData
->nPrevPnt
];
885 if (!mpSdrPathDragData
->bEndPnt
) rXP
[mpSdrPathDragData
->nNextPnt0
] =mpSdrPathDragData
->aXP
[mpSdrPathDragData
->nNextPnt
];
886 rXP
[mpSdrPathDragData
->nPnt0
] =mpSdrPathDragData
->aXP
[mpSdrPathDragData
->nPnt
];
888 // Letzter Punkt muss beim Geschlossenen immer gleich dem Ersten sein
889 if (mpSdrPathDragData
->bClosed
) rXP
[rXP
.GetPointCount()-1]=rXP
[0];
891 if (mpSdrPathDragData
->bEliminate
)
893 basegfx::B2DPolyPolygon
aTempPolyPolygon(aPathPolygon
.getB2DPolyPolygon());
894 sal_uInt32 nPoly
,nPnt
;
896 if(PolyPolygonEditor::GetRelativePolyPoint(aTempPolyPolygon
, rDrag
.GetHdl()->GetSourceHdlNum(), nPoly
, nPnt
))
898 basegfx::B2DPolygon
aCandidate(aTempPolyPolygon
.getB2DPolygon(nPoly
));
899 aCandidate
.remove(nPnt
);
901 if((IsClosed(meObjectKind
) && aCandidate
.count() < 3L) || aCandidate
.count() < 2L)
903 aTempPolyPolygon
.remove(nPoly
);
907 aTempPolyPolygon
.setB2DPolygon(nPoly
, aCandidate
);
911 aPathPolygon
= XPolyPolygon(aTempPolyPolygon
);
914 // Winkel anpassen fuer Text an einfacher Linie
917 Point
aLinePt1_(aPathPolygon
[0][0]);
918 Point
aLinePt2_(aPathPolygon
[0][1]);
919 FASTBOOL bXMirr
=(aLinePt1_
.X()>aLinePt2_
.X())!=(aLinePt1
.X()>aLinePt2
.X());
920 FASTBOOL bYMirr
=(aLinePt1_
.Y()>aLinePt2_
.Y())!=(aLinePt1
.Y()>aLinePt2
.Y());
921 if (bXMirr
|| bYMirr
) {
922 Point
aRef1(mrSdrPathObject
.GetSnapRect().Center());
926 mrSdrPathObject
.NbcMirrorGluePoints(aRef1
,aRef2
);
931 mrSdrPathObject
.NbcMirrorGluePoints(aRef1
,aRef2
);
937 delete mpSdrPathDragData
;
938 mpSdrPathDragData
= 0;
943 /*void ImpPathForDragAndCreate::cancelSpecialDrag( SdrDragStat& rDrag ) const
945 ImpSdrPathDragData* pID=(ImpSdrPathDragData*)rDrag.GetUser();
952 String
ImpPathForDragAndCreate::getSpecialDragComment(const SdrDragStat
& rDrag
) const
954 ImpSdrPathDragData
* pDragData
= mpSdrPathDragData
;
958 // getSpecialDragComment is also used from create, so fallback to GetUser()
959 // when mpSdrPathDragData is not set
960 pDragData
= (ImpSdrPathDragData
*)rDrag
.GetUser();
965 DBG_ERROR("ImpPathForDragAndCreate::MovDrag(): ImpSdrPathDragData ist ungueltig");
969 // Hier auch mal pDragData verwenden !!!
972 const SdrHdl
* pHdl
= rDrag
.GetHdl();
974 if(!mrSdrPathObject
.GetModel() || !pHdl
)
976 mrSdrPathObject
.ImpTakeDescriptionStr(STR_DragPathObj
, aStr
);
980 if(!pDragData
->IsMultiPointDrag() && pDragData
->bEliminate
)
983 mrSdrPathObject
.ImpTakeDescriptionStr(STR_ViewMarkedPoint
, aStr
);
986 XubString
aStr2(ImpGetResStr(STR_EditDelete
));
988 // UNICODE: Punkt von ... loeschen
989 aStr2
.SearchAndReplaceAscii("%1", aStr
);
994 // dx=0.00 dy=0.00 // Beide Seiten Bezier
995 // dx=0.00 dy=0.00 l=0.00 0.00ø // Anfang oder Ende oder eine Seite Bezier bzw. Hebel
996 // dx=0.00 dy=0.00 l=0.00 0.00ø / l=0.00 0.00ø // Mittendrin
998 Point
aBeg(rDrag
.GetStart());
999 Point
aNow(rDrag
.GetNow());
1002 aStr
.AppendAscii("dx=");
1003 mrSdrPathObject
.GetModel()->TakeMetricStr(aNow
.X() - aBeg
.X(), aMetr
, TRUE
);
1006 aStr
.AppendAscii(" dy=");
1007 mrSdrPathObject
.GetModel()->TakeMetricStr(aNow
.Y() - aBeg
.Y(), aMetr
, TRUE
);
1010 if(!pDragData
->IsMultiPointDrag())
1012 UINT16
nPntNum((sal_uInt16
)pHdl
->GetPointNum());
1013 const XPolygon
& rXPoly
= aPathPolygon
[(sal_uInt16
)rDrag
.GetHdl()->GetPolyNum()];
1014 UINT16
nPntAnz((sal_uInt16
)rXPoly
.GetPointCount());
1015 BOOL
bClose(IsClosed(meObjectKind
));
1020 if(pHdl
->IsPlusHdl())
1023 UINT16
nRef(nPntNum
);
1025 if(rXPoly
.IsControl(nPntNum
+ 1))
1030 aNow
-= rXPoly
[nRef
];
1032 INT32
nLen(GetLen(aNow
));
1033 aStr
.AppendAscii(" l=");
1034 mrSdrPathObject
.GetModel()->TakeMetricStr(nLen
, aMetr
, TRUE
);
1037 INT32
nWink(GetAngle(aNow
));
1038 aStr
+= sal_Unicode(' ');
1039 mrSdrPathObject
.GetModel()->TakeWinkStr(nWink
, aMetr
);
1042 else if(nPntAnz
> 1)
1044 UINT16
nPntMax(nPntAnz
- 1);
1046 BOOL
bIsClosed(IsClosed(meObjectKind
));
1047 BOOL
bPt1(nPntNum
> 0);
1048 BOOL
bPt2(nPntNum
< nPntMax
);
1050 if(bIsClosed
&& nPntAnz
> 2)
1063 if(nPntNum
< nPntMax
)
1068 if(bPt1
&& rXPoly
.IsControl(nPt1
))
1069 bPt1
= FALSE
; // Keine Anzeige
1071 if(bPt2
&& rXPoly
.IsControl(nPt2
))
1072 bPt2
= FALSE
; // von Bezierdaten
1077 aPt
-= rXPoly
[nPt1
];
1079 INT32
nLen(GetLen(aPt
));
1080 aStr
.AppendAscii(" l=");
1081 mrSdrPathObject
.GetModel()->TakeMetricStr(nLen
, aMetr
, TRUE
);
1084 INT32
nWink(GetAngle(aPt
));
1085 aStr
+= sal_Unicode(' ');
1086 mrSdrPathObject
.GetModel()->TakeWinkStr(nWink
, aMetr
);
1093 aStr
.AppendAscii(" / ");
1095 aStr
.AppendAscii(" ");
1098 aPt
-= rXPoly
[nPt2
];
1100 INT32
nLen(GetLen(aPt
));
1101 aStr
.AppendAscii("l=");
1102 mrSdrPathObject
.GetModel()->TakeMetricStr(nLen
, aMetr
, TRUE
);
1105 INT32
nWink(GetAngle(aPt
));
1106 aStr
+= sal_Unicode(' ');
1107 mrSdrPathObject
.GetModel()->TakeWinkStr(nWink
, aMetr
);
1117 basegfx::B2DPolyPolygon
ImpPathForDragAndCreate::getSpecialDragPoly(const SdrDragStat
& rDrag
) const
1119 if(!mpSdrPathDragData
|| !mpSdrPathDragData
->bValid
)
1121 DBG_ERROR("ImpPathForDragAndCreate::MovDrag(): ImpSdrPathDragData ist ungueltig");
1122 return basegfx::B2DPolyPolygon();
1125 XPolyPolygon aRetval
;
1127 if(mpSdrPathDragData
->IsMultiPointDrag())
1129 aRetval
.Insert(mpSdrPathDragData
->maMove
);
1133 const XPolygon
& rXP
=aPathPolygon
[(sal_uInt16
)rDrag
.GetHdl()->GetPolyNum()];
1134 if (rXP
.GetPointCount()<=2) { //|| rXPoly.GetFlags(1)==XPOLY_CONTROL && rXPoly.GetPointCount()<=4
1135 XPolygon
aXPoly(rXP
);
1136 aXPoly
[(sal_uInt16
)rDrag
.GetHdl()->GetPointNum()]=rDrag
.GetNow();
1137 aRetval
.Insert(aXPoly
);
1138 return aRetval
.getB2DPolyPolygon();
1140 // Div. Daten lokal Kopieren fuer weniger Code und schnelleren Zugriff
1141 FASTBOOL bClosed
=mpSdrPathDragData
->bClosed
; // geschlossenes Objekt?
1142 USHORT nPntAnz
=mpSdrPathDragData
->nPntAnz
; // Punktanzahl
1143 USHORT nPnt
=mpSdrPathDragData
->nPnt
; // Punktnummer innerhalb des Polygons
1144 FASTBOOL bBegPnt
=mpSdrPathDragData
->bBegPnt
; // Gedraggter Punkt ist der Anfangspunkt einer Polyline
1145 FASTBOOL bEndPnt
=mpSdrPathDragData
->bEndPnt
; // Gedraggter Punkt ist der Endpunkt einer Polyline
1146 USHORT nPrevPnt
=mpSdrPathDragData
->nPrevPnt
; // Index des vorherigen Punkts
1147 USHORT nNextPnt
=mpSdrPathDragData
->nNextPnt
; // Index des naechsten Punkts
1148 FASTBOOL bPrevIsBegPnt
=mpSdrPathDragData
->bPrevIsBegPnt
; // Vorheriger Punkt ist Anfangspunkt einer Polyline
1149 FASTBOOL bNextIsEndPnt
=mpSdrPathDragData
->bNextIsEndPnt
; // Folgepunkt ist Endpunkt einer Polyline
1150 USHORT nPrevPrevPnt
=mpSdrPathDragData
->nPrevPrevPnt
; // Index des vorvorherigen Punkts
1151 USHORT nNextNextPnt
=mpSdrPathDragData
->nNextNextPnt
; // Index des uebernaechsten Punkts
1152 FASTBOOL bControl
=mpSdrPathDragData
->bControl
; // Punkt ist ein Kontrollpunkt
1153 //FASTBOOL bIsPrevControl=mpSdrPathDragData->bIsPrevControl; // Punkt ist Kontrollpunkt vor einem Stuetzpunkt
1154 FASTBOOL bIsNextControl
=mpSdrPathDragData
->bIsNextControl
; // Punkt ist Kontrollpunkt hinter einem Stuetzpunkt
1155 FASTBOOL bPrevIsControl
=mpSdrPathDragData
->bPrevIsControl
; // Falls nPnt ein StPnt: Davor ist ein Kontrollpunkt
1156 FASTBOOL bNextIsControl
=mpSdrPathDragData
->bNextIsControl
; // Falls nPnt ein StPnt: Dahinter ist ein Kontrollpunkt
1157 XPolygon
aXPoly(mpSdrPathDragData
->aXP
);
1163 aLine1
[1]=mpSdrPathDragData
->aXP
[nPnt
];
1164 if (bIsNextControl
) { // bin ich Kontrollpunkt hinter der Stuetzstelle?
1165 aLine1
[0]=mpSdrPathDragData
->aXP
[nPrevPnt
];
1166 aLine2
[0]=mpSdrPathDragData
->aXP
[nNextNextPnt
];
1167 aLine2
[1]=mpSdrPathDragData
->aXP
[nNextPnt
];
1168 if (mpSdrPathDragData
->aXP
.IsSmooth(nPrevPnt
) && !bPrevIsBegPnt
&& mpSdrPathDragData
->aXP
.IsControl(nPrevPrevPnt
)) {
1169 aXPoly
.Insert(0,rXP
[mpSdrPathDragData
->nPrevPrevPnt0
-1],XPOLY_CONTROL
);
1170 aXPoly
.Insert(0,rXP
[mpSdrPathDragData
->nPrevPrevPnt0
-2],XPOLY_NORMAL
);
1171 // Hebellienien fuer das gegenueberliegende Kurvensegment
1172 aLine3
[0]=mpSdrPathDragData
->aXP
[nPrevPnt
];
1173 aLine3
[1]=mpSdrPathDragData
->aXP
[nPrevPrevPnt
];
1174 aLine4
[0]=rXP
[mpSdrPathDragData
->nPrevPrevPnt0
-2];
1175 aLine4
[1]=rXP
[mpSdrPathDragData
->nPrevPrevPnt0
-1];
1179 } else { // ansonsten bin ich Kontrollpunkt vor der Stuetzstelle
1180 aLine1
[0]=mpSdrPathDragData
->aXP
[nNextPnt
];
1181 aLine2
[0]=mpSdrPathDragData
->aXP
[nPrevPrevPnt
];
1182 aLine2
[1]=mpSdrPathDragData
->aXP
[nPrevPnt
];
1183 if (mpSdrPathDragData
->aXP
.IsSmooth(nNextPnt
) && !bNextIsEndPnt
&& mpSdrPathDragData
->aXP
.IsControl(nNextNextPnt
)) {
1184 aXPoly
.Insert(XPOLY_APPEND
,rXP
[mpSdrPathDragData
->nNextNextPnt0
+1],XPOLY_CONTROL
);
1185 aXPoly
.Insert(XPOLY_APPEND
,rXP
[mpSdrPathDragData
->nNextNextPnt0
+2],XPOLY_NORMAL
);
1186 // Hebellinien fuer das gegenueberliegende Kurvensegment
1187 aLine3
[0]=mpSdrPathDragData
->aXP
[nNextPnt
];
1188 aLine3
[1]=mpSdrPathDragData
->aXP
[nNextNextPnt
];
1189 aLine4
[0]=rXP
[mpSdrPathDragData
->nNextNextPnt0
+2];
1190 aLine4
[1]=rXP
[mpSdrPathDragData
->nNextNextPnt0
+1];
1192 aXPoly
.Remove(aXPoly
.GetPointCount()-1,1);
1195 } else { // ansonsten kein Kontrollpunkt
1196 if (mpSdrPathDragData
->bEliminate
) {
1199 if (bPrevIsControl
) aXPoly
.Insert(0,rXP
[mpSdrPathDragData
->nPrevPrevPnt0
-1],XPOLY_NORMAL
);
1200 else if (!bBegPnt
&& !bPrevIsBegPnt
&& mpSdrPathDragData
->aXP
.IsControl(nPrevPrevPnt
)) {
1201 aXPoly
.Insert(0,rXP
[mpSdrPathDragData
->nPrevPrevPnt0
-1],XPOLY_CONTROL
);
1202 aXPoly
.Insert(0,rXP
[mpSdrPathDragData
->nPrevPrevPnt0
-2],XPOLY_NORMAL
);
1205 if (bBegPnt
) aXPoly
.Remove(0,1);
1207 if (bNextIsControl
) aXPoly
.Insert(XPOLY_APPEND
,rXP
[mpSdrPathDragData
->nNextNextPnt0
+1],XPOLY_NORMAL
);
1208 else if (!bEndPnt
&& !bNextIsEndPnt
&& mpSdrPathDragData
->aXP
.IsControl(nNextNextPnt
)) {
1209 aXPoly
.Insert(XPOLY_APPEND
,rXP
[mpSdrPathDragData
->nNextNextPnt0
+1],XPOLY_CONTROL
);
1210 aXPoly
.Insert(XPOLY_APPEND
,rXP
[mpSdrPathDragData
->nNextNextPnt0
+2],XPOLY_NORMAL
);
1212 aXPoly
.Remove(aXPoly
.GetPointCount()-1,1);
1213 if (bEndPnt
) aXPoly
.Remove(aXPoly
.GetPointCount()-1,1);
1215 if (bClosed
) { // "Birnenproblem": 2 Linien, 1 Kurve, alles Smooth, Punkt zw. beiden Linien wird gedraggt
1216 if (aXPoly
.GetPointCount()>nPntAnz
&& aXPoly
.IsControl(1)) {
1217 USHORT a
=aXPoly
.GetPointCount();
1218 aXPoly
[a
-2]=aXPoly
[2]; aXPoly
.SetFlags(a
-2,aXPoly
.GetFlags(2));
1219 aXPoly
[a
-1]=aXPoly
[3]; aXPoly
.SetFlags(a
-1,aXPoly
.GetFlags(3));
1224 aRetval
.Insert(aXPoly
);
1225 if (aLine1
.GetPointCount()>1) aRetval
.Insert(aLine1
);
1226 if (aLine2
.GetPointCount()>1) aRetval
.Insert(aLine2
);
1227 if (aLine3
.GetPointCount()>1) aRetval
.Insert(aLine3
);
1228 if (aLine4
.GetPointCount()>1) aRetval
.Insert(aLine4
);
1231 return aRetval
.getB2DPolyPolygon();
1234 FASTBOOL
ImpPathForDragAndCreate::BegCreate(SdrDragStat
& rStat
)
1236 bool bFreeHand(IsFreeHand(meObjectKind
));
1237 rStat
.SetNoSnap(bFreeHand
);
1238 rStat
.SetOrtho8Possible();
1239 aPathPolygon
.Clear();
1241 FASTBOOL bMakeStartPoint
=TRUE
;
1242 SdrView
* pView
=rStat
.GetView();
1243 if (pView
!=NULL
&& pView
->IsUseIncompatiblePathCreateInterface() &&
1244 (meObjectKind
==OBJ_POLY
|| meObjectKind
==OBJ_PLIN
|| meObjectKind
==OBJ_PATHLINE
|| meObjectKind
==OBJ_PATHFILL
)) {
1245 bMakeStartPoint
=FALSE
;
1247 aPathPolygon
.Insert(XPolygon());
1248 aPathPolygon
[0][0]=rStat
.GetStart();
1249 if (bMakeStartPoint
) {
1250 aPathPolygon
[0][1]=rStat
.GetNow();
1252 ImpPathCreateUser
* pU
=new ImpPathCreateUser
;
1253 pU
->eStartKind
=meObjectKind
;
1254 pU
->eAktKind
=meObjectKind
;
1259 FASTBOOL
ImpPathForDragAndCreate::MovCreate(SdrDragStat
& rStat
)
1261 ImpPathCreateUser
* pU
=(ImpPathCreateUser
*)rStat
.GetUser();
1262 SdrView
* pView
=rStat
.GetView();
1263 XPolygon
& rXPoly
=aPathPolygon
[aPathPolygon
.Count()-1];
1264 if (pView
!=NULL
&& pView
->IsCreateMode()) {
1265 // ggf. auf anderes CreateTool umschalten
1268 pView
->TakeCurrentObj(nIdent
,nInvent
);
1269 if (nInvent
==SdrInventor
&& pU
->eAktKind
!=(SdrObjKind
)nIdent
) {
1270 SdrObjKind eNewKind
=(SdrObjKind
)nIdent
;
1272 case OBJ_CARC
: case OBJ_CIRC
: case OBJ_CCUT
: case OBJ_SECT
: eNewKind
=OBJ_CARC
;
1274 case OBJ_LINE
: case OBJ_PLIN
: case OBJ_POLY
:
1275 case OBJ_PATHLINE
: case OBJ_PATHFILL
:
1276 case OBJ_FREELINE
: case OBJ_FREEFILL
:
1277 case OBJ_SPLNLINE
: case OBJ_SPLNFILL
: {
1278 pU
->eAktKind
=eNewKind
;
1279 pU
->bMixedCreate
=TRUE
;
1280 pU
->nBezierStartPoint
=rXPoly
.GetPointCount();
1281 if (pU
->nBezierStartPoint
>0) pU
->nBezierStartPoint
--;
1287 USHORT nActPoint
=rXPoly
.GetPointCount();
1288 if (aPathPolygon
.Count()>1 && rStat
.IsMouseDown() && nActPoint
<2) {
1289 rXPoly
[0]=rStat
.GetPos0();
1290 rXPoly
[1]=rStat
.GetNow();
1294 rXPoly
[0]=rStat
.GetPos0();
1296 FASTBOOL bFreeHand
=IsFreeHand(pU
->eAktKind
);
1297 rStat
.SetNoSnap(bFreeHand
/*|| (pU->bMixed && pU->eAktKind==OBJ_LINE)*/);
1298 rStat
.SetOrtho8Possible(pU
->eAktKind
!=OBJ_CARC
&& pU
->eAktKind
!=OBJ_RECT
&& (!pU
->bMixedCreate
|| pU
->eAktKind
!=OBJ_LINE
));
1299 Point
aActMerk(rXPoly
[nActPoint
]);
1300 rXPoly
[nActPoint
]=rStat
.Now();
1301 if (!pU
->bMixedCreate
&& pU
->eStartKind
==OBJ_LINE
&& rXPoly
.GetPointCount()>=1) {
1302 Point
aPt(rStat
.Start());
1303 if (pView
!=NULL
&& pView
->IsCreate1stPointAsCenter()) {
1309 OutputDevice
* pOut
=pView
==NULL
? NULL
: pView
->GetFirstOutputDevice(); // GetWin(0);
1311 if (pU
->nBezierStartPoint
>nActPoint
) pU
->nBezierStartPoint
=nActPoint
;
1312 if (rStat
.IsMouseDown() && nActPoint
>0) {
1313 // keine aufeinanderfolgenden Punkte an zu Nahe gelegenen Positionen zulassen
1315 if (pView
!=NULL
) nMinDist
=pView
->GetFreeHandMinDistPix();
1316 if (pOut
!=NULL
) nMinDist
=pOut
->PixelToLogic(Size(nMinDist
,0)).Width();
1317 if (nMinDist
<1) nMinDist
=1;
1319 Point
aPt0(rXPoly
[nActPoint
-1]);
1320 Point
aPt1(rStat
.Now());
1321 long dx
=aPt0
.X()-aPt1
.X(); if (dx
<0) dx
=-dx
;
1322 long dy
=aPt0
.Y()-aPt1
.Y(); if (dy
<0) dy
=-dy
;
1323 if (dx
<nMinDist
&& dy
<nMinDist
) return FALSE
;
1325 // folgendes ist aus EndCreate kopiert (nur kleine Modifikationen)
1326 // und sollte dann mal in eine Methode zusammengefasst werden:
1328 if (nActPoint
-pU
->nBezierStartPoint
>=3 && ((nActPoint
-pU
->nBezierStartPoint
)%3)==0) {
1329 rXPoly
.PointsToBezier(nActPoint
-3);
1330 rXPoly
.SetFlags(nActPoint
-1,XPOLY_CONTROL
);
1331 rXPoly
.SetFlags(nActPoint
-2,XPOLY_CONTROL
);
1333 if (nActPoint
>=6 && rXPoly
.IsControl(nActPoint
-4)) {
1334 rXPoly
.CalcTangent(nActPoint
-3,nActPoint
-4,nActPoint
-2);
1335 rXPoly
.SetFlags(nActPoint
-3,XPOLY_SMOOTH
);
1338 rXPoly
[nActPoint
+1]=rStat
.Now();
1341 pU
->nBezierStartPoint
=nActPoint
;
1345 pU
->ResetFormFlags();
1346 if (IsBezier(pU
->eAktKind
)) {
1348 pU
->CalcBezier(rXPoly
[nActPoint
-1],rXPoly
[nActPoint
],rXPoly
[nActPoint
-1]-rXPoly
[nActPoint
-2],rStat
.IsMouseDown());
1349 } else if (pU
->bBezHasCtrl0
) {
1350 pU
->CalcBezier(rXPoly
[nActPoint
-1],rXPoly
[nActPoint
],pU
->aBezControl0
-rXPoly
[nActPoint
-1],rStat
.IsMouseDown());
1353 if (pU
->eAktKind
==OBJ_CARC
&& nActPoint
>=2) {
1354 pU
->CalcCircle(rXPoly
[nActPoint
-1],rXPoly
[nActPoint
],rXPoly
[nActPoint
-1]-rXPoly
[nActPoint
-2],pView
);
1356 if (pU
->eAktKind
==OBJ_LINE
&& nActPoint
>=2) {
1357 pU
->CalcLine(rXPoly
[nActPoint
-1],rXPoly
[nActPoint
],rXPoly
[nActPoint
-1]-rXPoly
[nActPoint
-2],pView
);
1359 if (pU
->eAktKind
==OBJ_RECT
&& nActPoint
>=2) {
1360 pU
->CalcRect(rXPoly
[nActPoint
-1],rXPoly
[nActPoint
],rXPoly
[nActPoint
-1]-rXPoly
[nActPoint
-2],pView
);
1366 FASTBOOL
ImpPathForDragAndCreate::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
1368 ImpPathCreateUser
* pU
=(ImpPathCreateUser
*)rStat
.GetUser();
1369 FASTBOOL bRet
=FALSE
;
1370 SdrView
* pView
=rStat
.GetView();
1371 FASTBOOL bIncomp
=pView
!=NULL
&& pView
->IsUseIncompatiblePathCreateInterface();
1372 XPolygon
& rXPoly
=aPathPolygon
[aPathPolygon
.Count()-1];
1373 USHORT nActPoint
=rXPoly
.GetPointCount()-1;
1374 Point
aAktMerk(rXPoly
[nActPoint
]);
1375 rXPoly
[nActPoint
]=rStat
.Now();
1376 if (!pU
->bMixedCreate
&& pU
->eStartKind
==OBJ_LINE
) {
1377 if (rStat
.GetPointAnz()>=2) eCmd
=SDRCREATE_FORCEEND
;
1378 bRet
=eCmd
==SDRCREATE_FORCEEND
;
1382 rStat
.SetUser(NULL
);
1387 if (!pU
->bMixedCreate
&& IsFreeHand(pU
->eStartKind
)) {
1388 if (rStat
.GetPointAnz()>=2) eCmd
=SDRCREATE_FORCEEND
;
1389 bRet
=eCmd
==SDRCREATE_FORCEEND
;
1393 rStat
.SetUser(NULL
);
1397 if (eCmd
==SDRCREATE_NEXTPOINT
|| eCmd
==SDRCREATE_NEXTOBJECT
) {
1398 // keine aufeinanderfolgenden Punkte an identischer Position zulassen
1399 if (nActPoint
==0 || rStat
.Now()!=rXPoly
[nActPoint
-1]) {
1401 if (pU
->nBezierStartPoint
>nActPoint
) pU
->nBezierStartPoint
=nActPoint
;
1402 if (IsBezier(pU
->eAktKind
) && nActPoint
-pU
->nBezierStartPoint
>=3 && ((nActPoint
-pU
->nBezierStartPoint
)%3)==0) {
1403 rXPoly
.PointsToBezier(nActPoint
-3);
1404 rXPoly
.SetFlags(nActPoint
-1,XPOLY_CONTROL
);
1405 rXPoly
.SetFlags(nActPoint
-2,XPOLY_CONTROL
);
1407 if (nActPoint
>=6 && rXPoly
.IsControl(nActPoint
-4)) {
1408 rXPoly
.CalcTangent(nActPoint
-3,nActPoint
-4,nActPoint
-2);
1409 rXPoly
.SetFlags(nActPoint
-3,XPOLY_SMOOTH
);
1413 if (nActPoint
==1 && IsBezier(pU
->eAktKind
) && !pU
->bBezHasCtrl0
) {
1414 pU
->aBezControl0
=rStat
.GetNow();;
1415 pU
->bBezHasCtrl0
=TRUE
;
1418 if (pU
->IsFormFlag()) {
1419 USHORT nPtAnz0
=rXPoly
.GetPointCount();
1420 rXPoly
.Remove(nActPoint
-1,2); // die letzten beiden Punkte entfernen und durch die Form ersetzen
1421 rXPoly
.Insert(XPOLY_APPEND
,pU
->GetFormPoly());
1422 USHORT nPtAnz1
=rXPoly
.GetPointCount();
1423 for (USHORT i
=nPtAnz0
+1; i
<nPtAnz1
-1; i
++) { // Damit BckAction richtig funktioniert
1424 if (!rXPoly
.IsControl(i
)) rStat
.NextPoint();
1426 nActPoint
=rXPoly
.GetPointCount()-1;
1430 rXPoly
[nActPoint
]=rStat
.GetNow();
1432 if (eCmd
==SDRCREATE_NEXTOBJECT
) {
1433 if (rXPoly
.GetPointCount()>=2) {
1434 pU
->bBezHasCtrl0
=FALSE
;
1435 // nur einzelnes Polygon kann offen sein, deshalb schliessen
1436 rXPoly
[nActPoint
]=rXPoly
[0];
1438 aXP
[0]=rStat
.GetNow();
1439 aPathPolygon
.Insert(aXP
);
1444 USHORT nPolyAnz
=aPathPolygon
.Count();
1446 // den letzten Punkt ggf. wieder loeschen
1447 if (eCmd
==SDRCREATE_FORCEEND
) {
1448 XPolygon
& rXP
=aPathPolygon
[nPolyAnz
-1];
1449 USHORT nPtAnz
=rXP
.GetPointCount();
1451 if (!rXP
.IsControl(nPtAnz
-2)) {
1452 if (rXP
[nPtAnz
-1]==rXP
[nPtAnz
-2]) {
1453 rXP
.Remove(nPtAnz
-1,1);
1456 if (rXP
[nPtAnz
-3]==rXP
[nPtAnz
-2]) {
1457 rXP
.Remove(nPtAnz
-3,3);
1462 for (USHORT nPolyNum
=nPolyAnz
; nPolyNum
>0;) {
1464 XPolygon
& rXP
=aPathPolygon
[nPolyNum
];
1465 USHORT nPtAnz
=rXP
.GetPointCount();
1466 // Polygone mit zu wenig Punkten werden geloescht
1467 if (nPolyNum
<nPolyAnz
-1 || eCmd
==SDRCREATE_FORCEEND
) {
1468 if (nPtAnz
<2) aPathPolygon
.Remove(nPolyNum
);
1472 pU
->ResetFormFlags();
1473 bRet
=eCmd
==SDRCREATE_FORCEEND
;
1477 rStat
.SetUser(NULL
);
1482 FASTBOOL
ImpPathForDragAndCreate::BckCreate(SdrDragStat
& rStat
)
1484 ImpPathCreateUser
* pU
=(ImpPathCreateUser
*)rStat
.GetUser();
1485 if (aPathPolygon
.Count()>0) {
1486 XPolygon
& rXPoly
=aPathPolygon
[aPathPolygon
.Count()-1];
1487 USHORT nActPoint
=rXPoly
.GetPointCount();
1490 // Das letzte Stueck einer Bezierkurve wird erstmal zu 'ner Linie
1491 rXPoly
.Remove(nActPoint
,1);
1492 if (nActPoint
>=3 && rXPoly
.IsControl(nActPoint
-1)) {
1493 // Beziersegment am Ende sollte zwar nicht vorkommen, aber falls doch ...
1494 rXPoly
.Remove(nActPoint
-1,1);
1495 if (rXPoly
.IsControl(nActPoint
-2)) rXPoly
.Remove(nActPoint
-2,1);
1498 nActPoint
=rXPoly
.GetPointCount();
1499 if (nActPoint
>=4) { // Kein Beziersegment am Ende
1501 if (rXPoly
.IsControl(nActPoint
-1)) {
1502 rXPoly
.Remove(nActPoint
-1,1);
1503 if (rXPoly
.IsControl(nActPoint
-2)) rXPoly
.Remove(nActPoint
-2,1);
1506 if (rXPoly
.GetPointCount()<2) {
1507 aPathPolygon
.Remove(aPathPolygon
.Count()-1);
1509 if (aPathPolygon
.Count()>0) {
1510 XPolygon
& rLocalXPoly
=aPathPolygon
[aPathPolygon
.Count()-1];
1511 USHORT nLocalActPoint
=rLocalXPoly
.GetPointCount();
1512 if (nLocalActPoint
>0) {
1514 rLocalXPoly
[nLocalActPoint
]=rStat
.Now();
1518 pU
->ResetFormFlags();
1519 return aPathPolygon
.Count()!=0;
1522 void ImpPathForDragAndCreate::BrkCreate(SdrDragStat
& rStat
)
1524 ImpPathCreateUser
* pU
=(ImpPathCreateUser
*)rStat
.GetUser();
1525 aPathPolygon
.Clear();
1528 rStat
.SetUser(NULL
);
1531 basegfx::B2DPolyPolygon
ImpPathForDragAndCreate::TakeObjectPolyPolygon(const SdrDragStat
& rDrag
) const
1533 basegfx::B2DPolyPolygon
aRetval(aPathPolygon
.getB2DPolyPolygon());
1534 SdrView
* pView
= rDrag
.GetView();
1536 if(pView
&& pView
->IsUseIncompatiblePathCreateInterface())
1539 ImpPathCreateUser
* pU
= (ImpPathCreateUser
*)rDrag
.GetUser();
1540 basegfx::B2DPolygon
aNewPolygon(aRetval
.count() ? aRetval
.getB2DPolygon(aRetval
.count() - 1L) : basegfx::B2DPolygon());
1542 if(pU
->IsFormFlag() && aNewPolygon
.count() > 1L)
1544 // remove last segment and replace with current
1545 // do not forget to rescue the previous control point which will be lost when
1546 // the point it's associated with is removed
1547 const sal_uInt32
nChangeIndex(aNewPolygon
.count() - 2);
1548 const basegfx::B2DPoint
aSavedPrevCtrlPoint(aNewPolygon
.getPrevControlPoint(nChangeIndex
));
1550 aNewPolygon
.remove(nChangeIndex
, 2L);
1551 aNewPolygon
.append(pU
->GetFormPoly().getB2DPolygon());
1553 if(nChangeIndex
< aNewPolygon
.count())
1555 // if really something was added, set the saved prev control point at the
1556 // point where it belongs
1557 aNewPolygon
.setPrevControlPoint(nChangeIndex
, aSavedPrevCtrlPoint
);
1563 aRetval
.setB2DPolygon(aRetval
.count() - 1L, aNewPolygon
);
1567 aRetval
.append(aNewPolygon
);
1573 basegfx::B2DPolyPolygon
ImpPathForDragAndCreate::TakeDragPolyPolygon(const SdrDragStat
& rDrag
) const
1575 basegfx::B2DPolyPolygon aRetval
;
1576 SdrView
* pView
= rDrag
.GetView();
1578 if(pView
&& pView
->IsUseIncompatiblePathCreateInterface())
1581 ImpPathCreateUser
* pU
= (ImpPathCreateUser
*)rDrag
.GetUser();
1583 if(pU
&& pU
->bBezier
&& rDrag
.IsMouseDown())
1585 // no more XOR, no need for complicated helplines
1586 basegfx::B2DPolygon aHelpline
;
1587 aHelpline
.append(basegfx::B2DPoint(pU
->aBezCtrl2
.X(), pU
->aBezCtrl2
.Y()));
1588 aHelpline
.append(basegfx::B2DPoint(pU
->aBezEnd
.X(), pU
->aBezEnd
.Y()));
1589 aRetval
.append(aHelpline
);
1595 Pointer
ImpPathForDragAndCreate::GetCreatePointer() const
1597 switch (meObjectKind
) {
1598 case OBJ_LINE
: return Pointer(POINTER_DRAW_LINE
);
1599 case OBJ_POLY
: return Pointer(POINTER_DRAW_POLYGON
);
1600 case OBJ_PLIN
: return Pointer(POINTER_DRAW_POLYGON
);
1601 case OBJ_PATHLINE
: return Pointer(POINTER_DRAW_BEZIER
);
1602 case OBJ_PATHFILL
: return Pointer(POINTER_DRAW_BEZIER
);
1603 case OBJ_FREELINE
: return Pointer(POINTER_DRAW_FREEHAND
);
1604 case OBJ_FREEFILL
: return Pointer(POINTER_DRAW_FREEHAND
);
1605 case OBJ_SPLNLINE
: return Pointer(POINTER_DRAW_FREEHAND
);
1606 case OBJ_SPLNFILL
: return Pointer(POINTER_DRAW_FREEHAND
);
1607 case OBJ_PATHPOLY
: return Pointer(POINTER_DRAW_POLYGON
);
1608 case OBJ_PATHPLIN
: return Pointer(POINTER_DRAW_POLYGON
);
1611 return Pointer(POINTER_CROSS
);
1614 /*************************************************************************/
1616 SdrPathObjGeoData::SdrPathObjGeoData()
1620 SdrPathObjGeoData::~SdrPathObjGeoData()
1624 //////////////////////////////////////////////////////////////////////////////
1625 // DrawContact section
1627 sdr::contact::ViewContact
* SdrPathObj::CreateObjectSpecificViewContact()
1629 return new sdr::contact::ViewContactOfSdrPathObj(*this);
1632 /*************************************************************************/
1634 TYPEINIT1(SdrPathObj
,SdrTextObj
);
1636 SdrPathObj::SdrPathObj(SdrObjKind eNewKind
)
1640 bClosedObj
= IsClosed();
1643 SdrPathObj::SdrPathObj(SdrObjKind eNewKind
, const basegfx::B2DPolyPolygon
& rPathPoly
)
1644 : maPathPolygon(rPathPoly
),
1648 bClosedObj
= IsClosed();
1652 SdrPathObj::~SdrPathObj()
1657 sal_Bool
ImpIsLine(const basegfx::B2DPolyPolygon
& rPolyPolygon
)
1659 return (1L == rPolyPolygon
.count() && 2L == rPolyPolygon
.getB2DPolygon(0L).count());
1662 Rectangle
ImpGetBoundRect(const basegfx::B2DPolyPolygon
& rPolyPolygon
)
1664 basegfx::B2DRange
aRange(basegfx::tools::getRange(rPolyPolygon
));
1667 FRound(aRange
.getMinX()), FRound(aRange
.getMinY()),
1668 FRound(aRange
.getMaxX()), FRound(aRange
.getMaxY()));
1671 void SdrPathObj::ImpForceLineWink()
1673 if(OBJ_LINE
== meKind
&& ImpIsLine(GetPathPoly()))
1675 const basegfx::B2DPolygon
aPoly(GetPathPoly().getB2DPolygon(0L));
1676 const basegfx::B2DPoint
aB2DPoint0(aPoly
.getB2DPoint(0L));
1677 const basegfx::B2DPoint
aB2DPoint1(aPoly
.getB2DPoint(1L));
1678 const Point
aPoint0(FRound(aB2DPoint0
.getX()), FRound(aB2DPoint0
.getY()));
1679 const Point
aPoint1(FRound(aB2DPoint1
.getX()), FRound(aB2DPoint1
.getY()));
1680 const Point
aDelt(aPoint1
- aPoint0
);
1682 aGeo
.nDrehWink
=GetAngle(aDelt
);
1684 aGeo
.RecalcSinCos();
1687 // #101412# for SdrTextObj, keep aRect up to date
1688 aRect
= Rectangle(aPoint0
, aPoint1
);
1693 void SdrPathObj::ImpForceKind()
1695 if (meKind
==OBJ_PATHPLIN
) meKind
=OBJ_PLIN
;
1696 if (meKind
==OBJ_PATHPOLY
) meKind
=OBJ_POLY
;
1698 if(GetPathPoly().areControlPointsUsed())
1702 case OBJ_LINE
: meKind
=OBJ_PATHLINE
; break;
1703 case OBJ_PLIN
: meKind
=OBJ_PATHLINE
; break;
1704 case OBJ_POLY
: meKind
=OBJ_PATHFILL
; break;
1712 case OBJ_PATHLINE
: meKind
=OBJ_PLIN
; break;
1713 case OBJ_FREELINE
: meKind
=OBJ_PLIN
; break;
1714 case OBJ_PATHFILL
: meKind
=OBJ_POLY
; break;
1715 case OBJ_FREEFILL
: meKind
=OBJ_POLY
; break;
1720 if (meKind
==OBJ_LINE
&& !ImpIsLine(GetPathPoly())) meKind
=OBJ_PLIN
;
1721 if (meKind
==OBJ_PLIN
&& ImpIsLine(GetPathPoly())) meKind
=OBJ_LINE
;
1723 bClosedObj
=IsClosed();
1725 if (meKind
==OBJ_LINE
)
1731 // #i10659#, similar to #101412# but for polys with more than 2 points.
1733 // Here i again need to fix something, because when Path-Polys are Copy-Pasted
1734 // between Apps with different measurements (e.g. 100TH_MM and TWIPS) there is
1735 // a scaling loop started from SdrExchangeView::Paste. This is principally nothing
1736 // wrong, but aRect is wrong here and not even updated by RecalcSnapRect(). If
1737 // this is the case, some size needs to be set here in aRect to avoid that the cyclus
1738 // through Rect2Poly - Poly2Rect does something badly wrong since that cycle is
1739 // BASED on aRect. That cycle is triggered in SdrTextObj::NbcResize() which is called
1740 // from the local Resize() implementation.
1742 // Basic problem is that the member aRect in SdrTextObj basically is a unrotated
1743 // text rectangle for the text object itself and methods at SdrTextObj do handle it
1744 // in that way. Many draw objects derived from SdrTextObj 'abuse' aRect as SnapRect
1745 // which is basically wrong. To make the SdrText methods which deal with aRect directly
1746 // work it is necessary to always keep aRect updated. This e.g. not done after a Clone()
1747 // command for SdrPathObj. Since adding this update mechanism with #101412# to
1748 // ImpForceLineWink() for lines was very successful, i add it to where ImpForceLineWink()
1749 // was called, once here below and once on a 2nd place below.
1751 // #i10659# for SdrTextObj, keep aRect up to date
1752 if(GetPathPoly().count())
1754 aRect
= ImpGetBoundRect(GetPathPoly());
1758 // #i75974# adapt polygon state to object type. This may include a reinterpretation
1759 // of a closed geometry as open one, but with identical first and last point
1760 for(sal_uInt32
a(0); a
< maPathPolygon
.count(); a
++)
1762 basegfx::B2DPolygon
aCandidate(maPathPolygon
.getB2DPolygon(a
));
1764 if((bool)IsClosed() != aCandidate
.isClosed())
1766 // #i80213# really change polygon geometry; else e.g. the last point which
1767 // needs to be identical with the first one will be missing when opening
1768 // due to OBJ_PATH type
1769 if(aCandidate
.isClosed())
1771 basegfx::tools::openWithGeometryChange(aCandidate
);
1775 basegfx::tools::closeWithGeometryChange(aCandidate
);
1778 maPathPolygon
.setB2DPolygon(a
, aCandidate
);
1783 void SdrPathObj::ImpSetClosed(sal_Bool bClose
)
1789 case OBJ_LINE
: meKind
=OBJ_POLY
; break;
1790 case OBJ_PLIN
: meKind
=OBJ_POLY
; break;
1791 case OBJ_PATHLINE
: meKind
=OBJ_PATHFILL
; break;
1792 case OBJ_FREELINE
: meKind
=OBJ_FREEFILL
; break;
1793 case OBJ_SPLNLINE
: meKind
=OBJ_SPLNFILL
; break;
1803 case OBJ_POLY
: meKind
=OBJ_PLIN
; break;
1804 case OBJ_PATHFILL
: meKind
=OBJ_PATHLINE
; break;
1805 case OBJ_FREEFILL
: meKind
=OBJ_FREELINE
; break;
1806 case OBJ_SPLNFILL
: meKind
=OBJ_SPLNLINE
; break;
1816 void SdrPathObj::TakeObjInfo(SdrObjTransformInfoRec
& rInfo
) const
1818 rInfo
.bNoContortion
=FALSE
;
1820 FASTBOOL bCanConv
= !HasText() || ImpCanConvTextToCurve();
1821 FASTBOOL bIsPath
= IsBezier() || IsSpline();
1823 rInfo
.bEdgeRadiusAllowed
= FALSE
;
1824 rInfo
.bCanConvToPath
= bCanConv
&& !bIsPath
;
1825 rInfo
.bCanConvToPoly
= bCanConv
&& bIsPath
;
1826 rInfo
.bCanConvToContour
= !IsFontwork() && (rInfo
.bCanConvToPoly
|| LineGeometryUsageIsNecessary());
1829 UINT16
SdrPathObj::GetObjIdentifier() const
1831 return USHORT(meKind
);
1834 void SdrPathObj::operator=(const SdrObject
& rObj
)
1836 SdrTextObj::operator=(rObj
);
1837 SdrPathObj
& rPath
=(SdrPathObj
&)rObj
;
1838 maPathPolygon
=rPath
.GetPathPoly();
1841 void SdrPathObj::TakeObjNameSingul(XubString
& rName
) const
1843 if(OBJ_LINE
== meKind
)
1845 sal_uInt16
nId(STR_ObjNameSingulLINE
);
1847 if(ImpIsLine(GetPathPoly()))
1849 const basegfx::B2DPolygon
aPoly(GetPathPoly().getB2DPolygon(0L));
1850 const basegfx::B2DPoint
aB2DPoint0(aPoly
.getB2DPoint(0L));
1851 const basegfx::B2DPoint
aB2DPoint1(aPoly
.getB2DPoint(1L));
1852 const Point
aPoint0(FRound(aB2DPoint0
.getX()), FRound(aB2DPoint0
.getY()));
1853 const Point
aPoint1(FRound(aB2DPoint0
.getX()), FRound(aB2DPoint0
.getY()));
1855 if(aB2DPoint0
!= aB2DPoint1
)
1857 if(aB2DPoint0
.getY() == aB2DPoint1
.getY())
1859 nId
= STR_ObjNameSingulLINE_Hori
;
1861 else if(aB2DPoint0
.getX() == aB2DPoint1
.getX())
1863 nId
= STR_ObjNameSingulLINE_Vert
;
1867 const double fDx(fabs(aB2DPoint0
.getX() - aB2DPoint1
.getX()));
1868 const double fDy(fabs(aB2DPoint0
.getY() - aB2DPoint1
.getY()));
1872 nId
= STR_ObjNameSingulLINE_Diag
;
1878 rName
= ImpGetResStr(nId
);
1880 else if(OBJ_PLIN
== meKind
|| OBJ_POLY
== meKind
)
1882 const sal_Bool
bClosed(OBJ_POLY
== meKind
);
1885 if(mpDAC
&& mpDAC
->IsCreating())
1889 nId
= STR_ObjNameSingulPOLY
;
1893 nId
= STR_ObjNameSingulPLIN
;
1896 rName
= ImpGetResStr(nId
);
1901 sal_uInt32
nPointCount(0L);
1902 const sal_uInt32
nPolyCount(GetPathPoly().count());
1904 for(sal_uInt32
a(0L); a
< nPolyCount
; a
++)
1906 nPointCount
+= GetPathPoly().getB2DPolygon(a
).count();
1911 nId
= STR_ObjNameSingulPOLY_PntAnz
;
1915 nId
= STR_ObjNameSingulPLIN_PntAnz
;
1918 rName
= ImpGetResStr(nId
);
1919 sal_uInt16
nPos(rName
.SearchAscii("%2")); // #i96537#
1921 if(STRING_NOTFOUND
!= nPos
)
1923 rName
.Erase(nPos
, 2);
1924 rName
.Insert(UniString::CreateFromInt32(nPointCount
), nPos
);
1932 case OBJ_PATHLINE
: rName
=ImpGetResStr(STR_ObjNameSingulPATHLINE
); break;
1933 case OBJ_FREELINE
: rName
=ImpGetResStr(STR_ObjNameSingulFREELINE
); break;
1934 case OBJ_SPLNLINE
: rName
=ImpGetResStr(STR_ObjNameSingulNATSPLN
); break;
1935 case OBJ_PATHFILL
: rName
=ImpGetResStr(STR_ObjNameSingulPATHFILL
); break;
1936 case OBJ_FREEFILL
: rName
=ImpGetResStr(STR_ObjNameSingulFREEFILL
); break;
1937 case OBJ_SPLNFILL
: rName
=ImpGetResStr(STR_ObjNameSingulPERSPLN
); break;
1942 String
aName(GetName());
1945 rName
+= sal_Unicode(' ');
1946 rName
+= sal_Unicode('\'');
1948 rName
+= sal_Unicode('\'');
1952 void SdrPathObj::TakeObjNamePlural(XubString
& rName
) const
1956 case OBJ_LINE
: rName
=ImpGetResStr(STR_ObjNamePluralLINE
); break;
1957 case OBJ_PLIN
: rName
=ImpGetResStr(STR_ObjNamePluralPLIN
); break;
1958 case OBJ_POLY
: rName
=ImpGetResStr(STR_ObjNamePluralPOLY
); break;
1959 case OBJ_PATHLINE
: rName
=ImpGetResStr(STR_ObjNamePluralPATHLINE
); break;
1960 case OBJ_FREELINE
: rName
=ImpGetResStr(STR_ObjNamePluralFREELINE
); break;
1961 case OBJ_SPLNLINE
: rName
=ImpGetResStr(STR_ObjNamePluralNATSPLN
); break;
1962 case OBJ_PATHFILL
: rName
=ImpGetResStr(STR_ObjNamePluralPATHFILL
); break;
1963 case OBJ_FREEFILL
: rName
=ImpGetResStr(STR_ObjNamePluralFREEFILL
); break;
1964 case OBJ_SPLNFILL
: rName
=ImpGetResStr(STR_ObjNamePluralPERSPLN
); break;
1969 basegfx::B2DPolyPolygon
SdrPathObj::TakeXorPoly() const
1971 return GetPathPoly();
1974 sal_uInt32
SdrPathObj::GetHdlCount() const
1976 sal_uInt32
nRetval(0L);
1977 const sal_uInt32
nPolyCount(GetPathPoly().count());
1979 for(sal_uInt32
a(0L); a
< nPolyCount
; a
++)
1981 nRetval
+= GetPathPoly().getB2DPolygon(a
).count();
1987 SdrHdl
* SdrPathObj::GetHdl(sal_uInt32 nHdlNum
) const
1990 // Warn the user that this is ineffective and show alternatives. Should not be used at all.
1991 OSL_ENSURE(false, "SdrPathObj::GetHdl(): ineffective, use AddToHdlList instead (!)");
1993 // to have an alternative, get single handle using the ineffective way
1994 SdrHdl
* pRetval
= 0;
1995 SdrHdlList
aLocalList(0);
1996 AddToHdlList(aLocalList
);
1997 const sal_uInt32
nHdlCount(aLocalList
.GetHdlCount());
1999 if(nHdlCount
&& nHdlNum
< nHdlCount
)
2001 // remove and remember. The other created handles will be deleted again with the
2002 // destruction of the local list
2003 pRetval
= aLocalList
.RemoveHdl(nHdlNum
);
2009 void SdrPathObj::AddToHdlList(SdrHdlList
& rHdlList
) const
2011 // keep old stuff to be able to keep old SdrHdl stuff, too
2012 const XPolyPolygon
aOldPathPolygon(GetPathPoly());
2013 USHORT nPolyCnt
=aOldPathPolygon
.Count();
2014 FASTBOOL bClosed
=IsClosed();
2017 for (USHORT i
=0; i
<nPolyCnt
; i
++) {
2018 const XPolygon
& rXPoly
=aOldPathPolygon
.GetObject(i
);
2019 USHORT nPntCnt
=rXPoly
.GetPointCount();
2020 if (bClosed
&& nPntCnt
>1) nPntCnt
--;
2022 for (USHORT j
=0; j
<nPntCnt
; j
++) {
2023 if (rXPoly
.GetFlags(j
)!=XPOLY_CONTROL
) {
2024 const Point
& rPnt
=rXPoly
[j
];
2025 SdrHdl
* pHdl
=new SdrHdl(rPnt
,HDL_POLY
);
2026 pHdl
->SetPolyNum(i
);
2027 pHdl
->SetPointNum(j
);
2028 pHdl
->Set1PixMore(j
==0);
2029 pHdl
->SetSourceHdlNum(nIdx
);
2031 rHdlList
.AddHdl(pHdl
);
2037 sal_uInt32
SdrPathObj::GetPlusHdlCount(const SdrHdl
& rHdl
) const
2039 // keep old stuff to be able to keep old SdrHdl stuff, too
2040 const XPolyPolygon
aOldPathPolygon(GetPathPoly());
2041 sal_uInt16 nCnt
= 0;
2042 sal_uInt16 nPnt
= (sal_uInt16
)rHdl
.GetPointNum();
2043 sal_uInt16 nPolyNum
= (sal_uInt16
)rHdl
.GetPolyNum();
2045 if(nPolyNum
< aOldPathPolygon
.Count())
2047 const XPolygon
& rXPoly
= aOldPathPolygon
[nPolyNum
];
2048 sal_uInt16 nPntMax
= rXPoly
.GetPointCount();
2054 if (rXPoly
.GetFlags(nPnt
)!=XPOLY_CONTROL
)
2056 if (nPnt
==0 && IsClosed()) nPnt
=nPntMax
;
2057 if (nPnt
>0 && rXPoly
.GetFlags(nPnt
-1)==XPOLY_CONTROL
) nCnt
++;
2058 if (nPnt
==nPntMax
&& IsClosed()) nPnt
=0;
2059 if (nPnt
<nPntMax
&& rXPoly
.GetFlags(nPnt
+1)==XPOLY_CONTROL
) nCnt
++;
2068 SdrHdl
* SdrPathObj::GetPlusHdl(const SdrHdl
& rHdl
, sal_uInt32 nPlusNum
) const
2070 // keep old stuff to be able to keep old SdrHdl stuff, too
2071 const XPolyPolygon
aOldPathPolygon(GetPathPoly());
2073 sal_uInt16 nPnt
= (sal_uInt16
)rHdl
.GetPointNum();
2074 sal_uInt16 nPolyNum
= (sal_uInt16
)rHdl
.GetPolyNum();
2076 if (nPolyNum
<aOldPathPolygon
.Count())
2078 const XPolygon
& rXPoly
= aOldPathPolygon
[nPolyNum
];
2079 sal_uInt16 nPntMax
= rXPoly
.GetPointCount();
2086 pHdl
=new SdrHdlBezWgt(&rHdl
);
2087 pHdl
->SetPolyNum(rHdl
.GetPolyNum());
2089 if (nPnt
==0 && IsClosed()) nPnt
=nPntMax
;
2090 if (nPnt
>0 && rXPoly
.GetFlags(nPnt
-1)==XPOLY_CONTROL
&& nPlusNum
==0)
2092 pHdl
->SetPos(rXPoly
[nPnt
-1]);
2093 pHdl
->SetPointNum(nPnt
-1);
2097 if (nPnt
==nPntMax
&& IsClosed()) nPnt
=0;
2098 if (nPnt
<rXPoly
.GetPointCount()-1 && rXPoly
.GetFlags(nPnt
+1)==XPOLY_CONTROL
)
2100 pHdl
->SetPos(rXPoly
[nPnt
+1]);
2101 pHdl
->SetPointNum(nPnt
+1);
2105 pHdl
->SetSourceHdlNum(rHdl
.GetSourceHdlNum());
2106 pHdl
->SetPlusHdl(TRUE
);
2113 ////////////////////////////////////////////////////////////////////////////////////////////////////
2115 bool SdrPathObj::hasSpecialDrag() const
2120 bool SdrPathObj::beginSpecialDrag(SdrDragStat
& rDrag
) const
2122 ImpPathForDragAndCreate
aDragAndCreate(*((SdrPathObj
*)this));
2124 return aDragAndCreate
.beginPathDrag(rDrag
);
2127 bool SdrPathObj::applySpecialDrag(SdrDragStat
& rDrag
)
2129 ImpPathForDragAndCreate
aDragAndCreate(*this);
2130 bool bRetval(aDragAndCreate
.beginPathDrag(rDrag
));
2134 bRetval
= aDragAndCreate
.movePathDrag(rDrag
);
2139 bRetval
= aDragAndCreate
.endPathDrag(rDrag
);
2144 NbcSetPathPoly(aDragAndCreate
.getModifiedPolyPolygon());
2150 String
SdrPathObj::getSpecialDragComment(const SdrDragStat
& rDrag
) const
2153 ImpPathForDragAndCreate
aDragAndCreate(*((SdrPathObj
*)this));
2154 bool bDidWork(aDragAndCreate
.beginPathDrag((SdrDragStat
&)rDrag
));
2158 aRetval
= aDragAndCreate
.getSpecialDragComment(rDrag
);
2164 basegfx::B2DPolyPolygon
SdrPathObj::getSpecialDragPoly(const SdrDragStat
& rDrag
) const
2166 basegfx::B2DPolyPolygon aRetval
;
2167 ImpPathForDragAndCreate
aDragAndCreate(*((SdrPathObj
*)this));
2168 bool bDidWork(aDragAndCreate
.beginPathDrag((SdrDragStat
&)rDrag
));
2172 aRetval
= aDragAndCreate
.getSpecialDragPoly(rDrag
);
2178 ////////////////////////////////////////////////////////////////////////////////////////////////////
2180 FASTBOOL
SdrPathObj::BegCreate(SdrDragStat
& rStat
)
2183 return impGetDAC().BegCreate(rStat
);
2186 FASTBOOL
SdrPathObj::MovCreate(SdrDragStat
& rStat
)
2188 return impGetDAC().MovCreate(rStat
);
2191 FASTBOOL
SdrPathObj::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
2193 FASTBOOL
bRetval(impGetDAC().EndCreate(rStat
, eCmd
));
2195 if(bRetval
&& mpDAC
)
2197 SetPathPoly(mpDAC
->getModifiedPolyPolygon());
2199 // #i75974# Check for AutoClose feature. Moved here from ImpPathForDragAndCreate::EndCreate
2200 // to be able to use the type-changing ImpSetClosed method
2203 SdrView
* pView
= rStat
.GetView();
2205 if(pView
&& pView
->IsAutoClosePolys() && !pView
->IsUseIncompatiblePathCreateInterface())
2207 OutputDevice
* pOut
= pView
->GetFirstOutputDevice();
2211 if(GetPathPoly().count())
2213 const basegfx::B2DPolygon
aCandidate(GetPathPoly().getB2DPolygon(0));
2215 if(aCandidate
.count() > 2)
2217 // check distance of first and last point
2218 const sal_Int32
nCloseDist(pOut
->PixelToLogic(Size(pView
->GetAutoCloseDistPix(), 0)).Width());
2219 const basegfx::B2DVector
aDistVector(aCandidate
.getB2DPoint(aCandidate
.count() - 1) - aCandidate
.getB2DPoint(0));
2221 if(aDistVector
.getLength() <= (double)nCloseDist
)
2238 FASTBOOL
SdrPathObj::BckCreate(SdrDragStat
& rStat
)
2240 return impGetDAC().BckCreate(rStat
);
2243 void SdrPathObj::BrkCreate(SdrDragStat
& rStat
)
2245 impGetDAC().BrkCreate(rStat
);
2249 basegfx::B2DPolyPolygon
SdrPathObj::TakeCreatePoly(const SdrDragStat
& rDrag
) const
2251 basegfx::B2DPolyPolygon aRetval
;
2255 aRetval
= mpDAC
->TakeObjectPolyPolygon(rDrag
);
2256 aRetval
.append(mpDAC
->TakeDragPolyPolygon(rDrag
));
2262 // during drag or create, allow accessing the so-far created/modified polyPolygon
2263 basegfx::B2DPolyPolygon
SdrPathObj::getObjectPolyPolygon(const SdrDragStat
& rDrag
) const
2265 basegfx::B2DPolyPolygon aRetval
;
2269 aRetval
= mpDAC
->TakeObjectPolyPolygon(rDrag
);
2275 basegfx::B2DPolyPolygon
SdrPathObj::getDragPolyPolygon(const SdrDragStat
& rDrag
) const
2277 basegfx::B2DPolyPolygon aRetval
;
2281 aRetval
= mpDAC
->TakeDragPolyPolygon(rDrag
);
2287 Pointer
SdrPathObj::GetCreatePointer() const
2289 return impGetDAC().GetCreatePointer();
2292 void SdrPathObj::NbcMove(const Size
& rSiz
)
2294 basegfx::B2DHomMatrix aTrans
;
2295 aTrans
.translate(rSiz
.Width(), rSiz
.Height());
2296 maPathPolygon
.transform(aTrans
);
2298 // #i19871# first modify locally, then call parent (to get correct SnapRect with GluePoints)
2299 SdrTextObj::NbcMove(rSiz
);
2302 void SdrPathObj::NbcResize(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
)
2304 basegfx::B2DHomMatrix aTrans
;
2305 aTrans
.translate(-rRef
.X(), -rRef
.Y());
2306 aTrans
.scale(double(xFact
), double(yFact
));
2307 aTrans
.translate(rRef
.X(), rRef
.Y());
2308 maPathPolygon
.transform(aTrans
);
2310 // #i19871# first modify locally, then call parent (to get correct SnapRect with GluePoints)
2311 SdrTextObj::NbcResize(rRef
,xFact
,yFact
);
2314 void SdrPathObj::NbcRotate(const Point
& rRef
, long nWink
, double sn
, double cs
)
2316 basegfx::B2DHomMatrix aTrans
;
2317 aTrans
.translate(-rRef
.X(), -rRef
.Y());
2318 aTrans
.rotate(-nWink
* nPi180
); // Thank JOE, the angles are defined mirrored to the mathematical meanings
2319 aTrans
.translate(rRef
.X(), rRef
.Y());
2320 maPathPolygon
.transform(aTrans
);
2322 // #i19871# first modify locally, then call parent (to get correct SnapRect with GluePoints)
2323 SdrTextObj::NbcRotate(rRef
,nWink
,sn
,cs
);
2326 void SdrPathObj::NbcShear(const Point
& rRefPnt
, long nAngle
, double fTan
, FASTBOOL bVShear
)
2328 basegfx::B2DHomMatrix aTrans
;
2329 aTrans
.translate(-rRefPnt
.X(), -rRefPnt
.Y());
2333 // Thank JOE, the angles are defined mirrored to the mathematical meanings
2334 aTrans
.shearY(-fTan
);
2338 aTrans
.shearX(-fTan
);
2341 aTrans
.translate(rRefPnt
.X(), rRefPnt
.Y());
2342 maPathPolygon
.transform(aTrans
);
2344 // #i19871# first modify locally, then call parent (to get correct SnapRect with GluePoints)
2345 SdrTextObj::NbcShear(rRefPnt
,nAngle
,fTan
,bVShear
);
2348 void SdrPathObj::NbcMirror(const Point
& rRefPnt1
, const Point
& rRefPnt2
)
2350 basegfx::B2DHomMatrix aTrans
;
2351 const double fDiffX(rRefPnt2
.X() - rRefPnt1
.X());
2352 const double fDiffY(rRefPnt2
.Y() - rRefPnt1
.Y());
2353 const double fRot(atan2(fDiffY
, fDiffX
));
2354 aTrans
.translate(-rRefPnt1
.X(), -rRefPnt1
.Y());
2355 aTrans
.rotate(-fRot
);
2356 aTrans
.scale(1.0, -1.0);
2357 aTrans
.rotate(fRot
);
2358 aTrans
.translate(rRefPnt1
.X(), rRefPnt1
.Y());
2359 maPathPolygon
.transform(aTrans
);
2361 // #97538# Do Joe's special handling for lines when mirroring, too
2364 // #i19871# first modify locally, then call parent (to get correct SnapRect with GluePoints)
2365 SdrTextObj::NbcMirror(rRefPnt1
,rRefPnt2
);
2368 void SdrPathObj::TakeUnrotatedSnapRect(Rectangle
& rRect
) const
2372 rRect
= GetSnapRect();
2376 XPolyPolygon
aXPP(GetPathPoly());
2377 RotateXPoly(aXPP
,Point(),-aGeo
.nSin
,aGeo
.nCos
);
2378 rRect
=aXPP
.GetBoundRect();
2379 Point
aTmp(rRect
.TopLeft());
2380 RotatePoint(aTmp
,Point(),aGeo
.nSin
,aGeo
.nCos
);
2381 aTmp
-=rRect
.TopLeft();
2382 rRect
.Move(aTmp
.X(),aTmp
.Y());
2386 void SdrPathObj::RecalcSnapRect()
2388 if(GetPathPoly().count())
2390 maSnapRect
= ImpGetBoundRect(GetPathPoly());
2394 void SdrPathObj::NbcSetSnapRect(const Rectangle
& rRect
)
2396 Rectangle
aOld(GetSnapRect());
2398 // #95736# Take RECT_EMPTY into account when calculating scale factors
2399 long nMulX
= (RECT_EMPTY
== rRect
.Right()) ? 0 : rRect
.Right() - rRect
.Left();
2401 long nDivX
= aOld
.Right() - aOld
.Left();
2403 // #95736# Take RECT_EMPTY into account when calculating scale factors
2404 long nMulY
= (RECT_EMPTY
== rRect
.Bottom()) ? 0 : rRect
.Bottom() - rRect
.Top();
2406 long nDivY
= aOld
.Bottom() - aOld
.Top();
2407 if ( nDivX
== 0 ) { nMulX
= 1; nDivX
= 1; }
2408 if ( nDivY
== 0 ) { nMulY
= 1; nDivY
= 1; }
2409 Fraction
aX(nMulX
,nDivX
);
2410 Fraction
aY(nMulY
,nDivY
);
2411 NbcResize(aOld
.TopLeft(), aX
, aY
);
2412 NbcMove(Size(rRect
.Left() - aOld
.Left(), rRect
.Top() - aOld
.Top()));
2415 sal_uInt32
SdrPathObj::GetSnapPointCount() const
2417 return GetHdlCount();
2420 Point
SdrPathObj::GetSnapPoint(sal_uInt32 nSnapPnt
) const
2422 sal_uInt32 nPoly
,nPnt
;
2423 if(!PolyPolygonEditor::GetRelativePolyPoint(GetPathPoly(), nSnapPnt
, nPoly
, nPnt
))
2425 DBG_ASSERT(FALSE
,"SdrPathObj::GetSnapPoint: Punkt nSnapPnt nicht vorhanden!");
2428 const basegfx::B2DPoint
aB2DPoint(GetPathPoly().getB2DPolygon(nPoly
).getB2DPoint(nPnt
));
2429 return Point(FRound(aB2DPoint
.getX()), FRound(aB2DPoint
.getY()));
2432 sal_Bool
SdrPathObj::IsPolyObj() const
2437 sal_uInt32
SdrPathObj::GetPointCount() const
2439 const sal_uInt32
nPolyCount(GetPathPoly().count());
2440 sal_uInt32
nRetval(0L);
2442 for(sal_uInt32
a(0L); a
< nPolyCount
; a
++)
2444 nRetval
+= GetPathPoly().getB2DPolygon(a
).count();
2450 Point
SdrPathObj::GetPoint(sal_uInt32 nHdlNum
) const
2453 sal_uInt32 nPoly
,nPnt
;
2455 if(PolyPolygonEditor::GetRelativePolyPoint(GetPathPoly(), nHdlNum
, nPoly
, nPnt
))
2457 const basegfx::B2DPolygon
aPoly(GetPathPoly().getB2DPolygon(nPoly
));
2458 const basegfx::B2DPoint
aPoint(aPoly
.getB2DPoint(nPnt
));
2459 aRetval
= Point(FRound(aPoint
.getX()), FRound(aPoint
.getY()));
2465 void SdrPathObj::NbcSetPoint(const Point
& rPnt
, sal_uInt32 nHdlNum
)
2467 sal_uInt32 nPoly
,nPnt
;
2469 if(PolyPolygonEditor::GetRelativePolyPoint(GetPathPoly(), nHdlNum
, nPoly
, nPnt
))
2471 basegfx::B2DPolygon
aNewPolygon(GetPathPoly().getB2DPolygon(nPoly
));
2472 aNewPolygon
.setB2DPoint(nPnt
, basegfx::B2DPoint(rPnt
.X(), rPnt
.Y()));
2473 maPathPolygon
.setB2DPolygon(nPoly
, aNewPolygon
);
2475 if(meKind
==OBJ_LINE
)
2481 if(GetPathPoly().count())
2483 // #i10659# for SdrTextObj, keep aRect up to date
2484 aRect
= ImpGetBoundRect(GetPathPoly()); // fuer SdrTextObj#
2492 sal_uInt32
SdrPathObj::NbcInsPointOld(const Point
& rPos
, sal_Bool bNewObj
, sal_Bool bHideHim
)
2498 nNewHdl
= NbcInsPoint(0L, rPos
, sal_True
, bHideHim
);
2502 // look for smallest distance data
2503 const basegfx::B2DPoint
aTestPoint(rPos
.X(), rPos
.Y());
2504 sal_uInt32
nSmallestPolyIndex(0L);
2505 sal_uInt32
nSmallestEdgeIndex(0L);
2506 double fSmallestCut
;
2507 basegfx::tools::getSmallestDistancePointToPolyPolygon(GetPathPoly(), aTestPoint
, nSmallestPolyIndex
, nSmallestEdgeIndex
, fSmallestCut
);
2509 // create old polygon index from it
2510 sal_uInt32
nPolyIndex(nSmallestEdgeIndex
);
2512 for(sal_uInt32
a(0L); a
< nSmallestPolyIndex
; a
++)
2514 nPolyIndex
+= GetPathPoly().getB2DPolygon(a
).count();
2517 nNewHdl
= NbcInsPoint(nPolyIndex
, rPos
, sal_False
, bHideHim
);
2524 sal_uInt32
SdrPathObj::NbcInsPoint(sal_uInt32
/*nHdlNum*/, const Point
& rPos
, sal_Bool bNewObj
, sal_Bool
/*bHideHim*/)
2530 basegfx::B2DPolygon aNewPoly
;
2531 const basegfx::B2DPoint
aPoint(rPos
.X(), rPos
.Y());
2532 aNewPoly
.append(aPoint
);
2533 aNewPoly
.setClosed(IsClosed());
2534 maPathPolygon
.append(aNewPoly
);
2536 nNewHdl
= GetHdlCount();
2540 // look for smallest distance data
2541 const basegfx::B2DPoint
aTestPoint(rPos
.X(), rPos
.Y());
2542 sal_uInt32
nSmallestPolyIndex(0L);
2543 sal_uInt32
nSmallestEdgeIndex(0L);
2544 double fSmallestCut
;
2545 basegfx::tools::getSmallestDistancePointToPolyPolygon(GetPathPoly(), aTestPoint
, nSmallestPolyIndex
, nSmallestEdgeIndex
, fSmallestCut
);
2546 basegfx::B2DPolygon
aCandidate(GetPathPoly().getB2DPolygon(nSmallestPolyIndex
));
2547 const bool bBefore(!aCandidate
.isClosed() && 0L == nSmallestEdgeIndex
&& 0.0 == fSmallestCut
);
2548 const bool bAfter(!aCandidate
.isClosed() && aCandidate
.count() == nSmallestEdgeIndex
+ 2L && 1.0 == fSmallestCut
);
2552 // before first point
2553 aCandidate
.insert(0L, aTestPoint
);
2555 if(aCandidate
.areControlPointsUsed())
2557 if(aCandidate
.isNextControlPointUsed(1))
2559 aCandidate
.setNextControlPoint(0, interpolate(aTestPoint
, aCandidate
.getB2DPoint(1), (1.0 / 3.0)));
2560 aCandidate
.setPrevControlPoint(1, interpolate(aTestPoint
, aCandidate
.getB2DPoint(1), (2.0 / 3.0)));
2569 aCandidate
.append(aTestPoint
);
2571 if(aCandidate
.areControlPointsUsed())
2573 if(aCandidate
.isPrevControlPointUsed(aCandidate
.count() - 2))
2575 aCandidate
.setNextControlPoint(aCandidate
.count() - 2, interpolate(aCandidate
.getB2DPoint(aCandidate
.count() - 2), aTestPoint
, (1.0 / 3.0)));
2576 aCandidate
.setPrevControlPoint(aCandidate
.count() - 1, interpolate(aCandidate
.getB2DPoint(aCandidate
.count() - 2), aTestPoint
, (2.0 / 3.0)));
2580 nNewHdl
= aCandidate
.count() - 1L;
2585 bool bSegmentSplit(false);
2586 const sal_uInt32
nNextIndex((nSmallestEdgeIndex
+ 1) % aCandidate
.count());
2588 if(aCandidate
.areControlPointsUsed())
2590 if(aCandidate
.isNextControlPointUsed(nSmallestEdgeIndex
) || aCandidate
.isPrevControlPointUsed(nNextIndex
))
2592 bSegmentSplit
= true;
2598 // rebuild original segment to get the split data
2599 basegfx::B2DCubicBezier aBezierA
, aBezierB
;
2600 const basegfx::B2DCubicBezier
aBezier(
2601 aCandidate
.getB2DPoint(nSmallestEdgeIndex
),
2602 aCandidate
.getNextControlPoint(nSmallestEdgeIndex
),
2603 aCandidate
.getPrevControlPoint(nNextIndex
),
2604 aCandidate
.getB2DPoint(nNextIndex
));
2606 // split and insert hit point
2607 aBezier
.split(fSmallestCut
, &aBezierA
, &aBezierB
);
2608 aCandidate
.insert(nSmallestEdgeIndex
+ 1, aTestPoint
);
2610 // since we inserted hit point and not split point, we need to add an offset
2611 // to the control points to get the C1 continuity we want to achieve
2612 const basegfx::B2DVector
aOffset(aTestPoint
- aBezierA
.getEndPoint());
2613 aCandidate
.setNextControlPoint(nSmallestEdgeIndex
, aBezierA
.getControlPointA() + aOffset
);
2614 aCandidate
.setPrevControlPoint(nSmallestEdgeIndex
+ 1, aBezierA
.getControlPointB() + aOffset
);
2615 aCandidate
.setNextControlPoint(nSmallestEdgeIndex
+ 1, aBezierB
.getControlPointA() + aOffset
);
2616 aCandidate
.setPrevControlPoint((nSmallestEdgeIndex
+ 2) % aCandidate
.count(), aBezierB
.getControlPointB() + aOffset
);
2620 aCandidate
.insert(nSmallestEdgeIndex
+ 1L, aTestPoint
);
2623 nNewHdl
= nSmallestEdgeIndex
+ 1L;
2626 maPathPolygon
.setB2DPolygon(nSmallestPolyIndex
, aCandidate
);
2628 // create old polygon index from it
2629 for(sal_uInt32
a(0L); a
< nSmallestPolyIndex
; a
++)
2631 nNewHdl
+= GetPathPoly().getB2DPolygon(a
).count();
2639 SdrObject
* SdrPathObj::RipPoint(sal_uInt32 nHdlNum
, sal_uInt32
& rNewPt0Index
)
2641 SdrPathObj
* pNewObj
= 0L;
2642 const basegfx::B2DPolyPolygon
aLocalPolyPolygon(GetPathPoly());
2643 sal_uInt32 nPoly
, nPnt
;
2645 if(PolyPolygonEditor::GetRelativePolyPoint(aLocalPolyPolygon
, nHdlNum
, nPoly
, nPnt
))
2649 const basegfx::B2DPolygon
aCandidate(aLocalPolyPolygon
.getB2DPolygon(nPoly
));
2650 const sal_uInt32
nPointCount(aCandidate
.count());
2656 // when closed, RipPoint means to open the polygon at the selected point. To
2657 // be able to do that, it is necessary to make the selected point the first one
2658 basegfx::B2DPolygon
aNewPolygon(basegfx::tools::makeStartPoint(aCandidate
, nPnt
));
2659 SetPathPoly(basegfx::B2DPolyPolygon(aNewPolygon
));
2662 // give back new position of old start point (historical reasons)
2663 rNewPt0Index
= (nPointCount
- nPnt
) % nPointCount
;
2667 if(nPointCount
>= 3L && nPnt
!= 0L && nPnt
+ 1L < nPointCount
)
2669 // split in two objects at point nPnt
2670 basegfx::B2DPolygon
aSplitPolyA(aCandidate
, 0L, nPnt
+ 1L);
2671 SetPathPoly(basegfx::B2DPolyPolygon(aSplitPolyA
));
2673 pNewObj
= (SdrPathObj
*)Clone();
2674 basegfx::B2DPolygon
aSplitPolyB(aCandidate
, nPnt
, nPointCount
- nPnt
);
2675 pNewObj
->SetPathPoly(basegfx::B2DPolyPolygon(aSplitPolyB
));
2685 SdrObject
* SdrPathObj::DoConvertToPolyObj(BOOL bBezier
) const
2687 // #i89784# check for FontWork with activated HideContour
2688 bool bHideContour(false);
2691 drawinglayer::attribute::SdrTextAttribute
* pText
= drawinglayer::primitive2d::createNewSdrTextAttribute(GetObjectItemSet(), *getText(0));
2692 bHideContour
= pText
&& pText
->getSdrFormTextAttribute() && pText
->isHideContour();
2696 SdrObject
* pRet
= bHideContour
?
2698 ImpConvertMakeObj(GetPathPoly(), IsClosed(), bBezier
);
2700 SdrPathObj
* pPath
= PTR_CAST(SdrPathObj
, pRet
);
2704 if(pPath
->GetPathPoly().areControlPointsUsed())
2708 // reduce all bezier curves
2709 pPath
->SetPathPoly(basegfx::tools::adaptiveSubdivideByAngle(pPath
->GetPathPoly()));
2716 // create bezier curves
2717 pPath
->SetPathPoly(basegfx::tools::expandToCurve(pPath
->GetPathPoly()));
2722 pRet
= ImpConvertAddText(pRet
, bBezier
);
2727 SdrObjGeoData
* SdrPathObj::NewGeoData() const
2729 return new SdrPathObjGeoData
;
2732 void SdrPathObj::SaveGeoData(SdrObjGeoData
& rGeo
) const
2734 SdrTextObj::SaveGeoData(rGeo
);
2735 SdrPathObjGeoData
& rPGeo
= (SdrPathObjGeoData
&) rGeo
;
2736 rPGeo
.maPathPolygon
=GetPathPoly();
2737 rPGeo
.meKind
=meKind
;
2740 void SdrPathObj::RestGeoData(const SdrObjGeoData
& rGeo
)
2742 SdrTextObj::RestGeoData(rGeo
);
2743 SdrPathObjGeoData
& rPGeo
=(SdrPathObjGeoData
&)rGeo
;
2744 maPathPolygon
=rPGeo
.maPathPolygon
;
2745 meKind
=rPGeo
.meKind
;
2746 ImpForceKind(); // damit u.a. bClosed gesetzt wird
2749 void SdrPathObj::NbcSetPathPoly(const basegfx::B2DPolyPolygon
& rPathPoly
)
2751 if(GetPathPoly() != rPathPoly
)
2753 maPathPolygon
=rPathPoly
;
2759 void SdrPathObj::SetPathPoly(const basegfx::B2DPolyPolygon
& rPathPoly
)
2761 if(GetPathPoly() != rPathPoly
)
2763 Rectangle aBoundRect0
; if (pUserCall
!=NULL
) aBoundRect0
=GetLastBoundRect();
2764 NbcSetPathPoly(rPathPoly
);
2766 BroadcastObjectChange();
2767 SendUserCall(SDRUSERCALL_RESIZE
,aBoundRect0
);
2771 void SdrPathObj::ToggleClosed() // long nOpenDistance)
2773 Rectangle aBoundRect0
;
2774 if(pUserCall
!= NULL
)
2775 aBoundRect0
= GetLastBoundRect();
2776 ImpSetClosed(!IsClosed()); // neuen ObjKind setzen
2777 ImpForceKind(); // wg. Line->Poly->PolyLine statt Line->Poly->Line
2780 BroadcastObjectChange();
2781 SendUserCall(SDRUSERCALL_RESIZE
, aBoundRect0
);
2784 // fuer friend class SdrPolyEditView auf einigen Compilern:
2785 void SdrPathObj::SetRectsDirty(sal_Bool bNotMyself
)
2787 SdrTextObj::SetRectsDirty(bNotMyself
);
2790 ImpPathForDragAndCreate
& SdrPathObj::impGetDAC() const
2794 ((SdrPathObj
*)this)->mpDAC
= new ImpPathForDragAndCreate(*((SdrPathObj
*)this));
2800 void SdrPathObj::impDeleteDAC() const
2805 ((SdrPathObj
*)this)->mpDAC
= 0L;
2809 ////////////////////////////////////////////////////////////////////////////////////////////////////
2811 // transformation interface for StarOfficeAPI. This implements support for
2812 // homogen 3x3 matrices containing the transformation of the SdrObject. At the
2813 // moment it contains a shearX, rotation and translation, but for setting all linear
2814 // transforms like Scale, ShearX, ShearY, Rotate and Translate are supported.
2816 ////////////////////////////////////////////////////////////////////////////////////////////////////
2817 // gets base transformation and rectangle of object. If it's an SdrPathObj it fills the PolyPolygon
2818 // with the base geometry and returns TRUE. Otherwise it returns FALSE.
2819 sal_Bool
SdrPathObj::TRGetBaseGeometry(basegfx::B2DHomMatrix
& rMatrix
, basegfx::B2DPolyPolygon
& rPolyPolygon
) const
2821 double fRotate(0.0);
2822 double fShearX(0.0);
2823 basegfx::B2DTuple
aScale(1.0, 1.0);
2824 basegfx::B2DTuple
aTranslate(0.0, 0.0);
2826 if(GetPathPoly().count())
2829 basegfx::B2DHomMatrix aMoveToZeroMatrix
;
2830 rPolyPolygon
= GetPathPoly();
2832 if(OBJ_LINE
== meKind
)
2834 // ignore shear and rotate, just use scale and translate
2835 OSL_ENSURE(GetPathPoly().count() > 0L && GetPathPoly().getB2DPolygon(0L).count() > 1L, "OBJ_LINE with too less polygons (!)");
2836 // #i72287# use polygon without control points for range calculation. Do not change rPolyPolygon
2837 // itself, else this method will no longer return the full polygon information (curve will
2839 const basegfx::B2DRange
aPolyRangeNoCurve(basegfx::tools::getRange(rPolyPolygon
));
2840 aScale
= aPolyRangeNoCurve
.getRange();
2841 aTranslate
= aPolyRangeNoCurve
.getMinimum();
2843 // define matrix for move polygon to zero point
2844 aMoveToZeroMatrix
.translate(-aTranslate
.getX(), -aTranslate
.getY());
2848 if(aGeo
.nShearWink
|| aGeo
.nDrehWink
)
2850 // get rotate and shear in drawingLayer notation
2851 fRotate
= aGeo
.nDrehWink
* F_PI18000
;
2852 fShearX
= aGeo
.nShearWink
* F_PI18000
;
2854 // build mathematically correct (negative shear and rotate) object transform
2855 // containing shear and rotate to extract unsheared, unrotated polygon
2856 basegfx::B2DHomMatrix aObjectMatrix
;
2857 aObjectMatrix
.shearX(tan((36000 - aGeo
.nShearWink
) * F_PI18000
));
2858 aObjectMatrix
.rotate((36000 - aGeo
.nDrehWink
) * F_PI18000
);
2860 // create inverse from it and back-transform polygon
2861 basegfx::B2DHomMatrix
aInvObjectMatrix(aObjectMatrix
);
2862 aInvObjectMatrix
.invert();
2863 rPolyPolygon
.transform(aInvObjectMatrix
);
2865 // get range from unsheared, unrotated polygon and extract scale and translate.
2866 // transform topLeft from it back to transformed state to get original
2867 // topLeft (rotation center)
2868 // #i72287# use polygon without control points for range calculation. Do not change rPolyPolygon
2869 // itself, else this method will no longer return the full polygon information (curve will
2871 const basegfx::B2DRange
aCorrectedRangeNoCurve(basegfx::tools::getRange(rPolyPolygon
));
2872 aTranslate
= aObjectMatrix
* aCorrectedRangeNoCurve
.getMinimum();
2873 aScale
= aCorrectedRangeNoCurve
.getRange();
2875 // define matrix for move polygon to zero point
2876 aMoveToZeroMatrix
.translate(-aCorrectedRangeNoCurve
.getMinX(), aCorrectedRangeNoCurve
.getMinY());
2880 // get scale and translate from unsheared, unrotated polygon
2881 // #i72287# use polygon without control points for range calculation. Do not change rPolyPolygon
2882 // itself, else this method will no longer return the full polygon information (curve will
2884 const basegfx::B2DRange
aPolyRangeNoCurve(basegfx::tools::getRange(rPolyPolygon
));
2885 aScale
= aPolyRangeNoCurve
.getRange();
2886 aTranslate
= aPolyRangeNoCurve
.getMinimum();
2888 // define matrix for move polygon to zero point
2889 aMoveToZeroMatrix
.translate(-aTranslate
.getX(), -aTranslate
.getY());
2893 // move polygon to zero point with pre-defined matrix
2894 rPolyPolygon
.transform(aMoveToZeroMatrix
);
2897 // position maybe relative to anchorpos, convert
2898 if( pModel
&& pModel
->IsWriter() )
2900 if(GetAnchorPos().X() || GetAnchorPos().Y())
2902 aTranslate
-= basegfx::B2DTuple(GetAnchorPos().X(), GetAnchorPos().Y());
2906 // force MapUnit to 100th mm
2907 SfxMapUnit eMapUnit
= GetObjectItemSet().GetPool()->GetMetric(0);
2908 if(eMapUnit
!= SFX_MAPUNIT_100TH_MM
)
2912 case SFX_MAPUNIT_TWIP
:
2915 aTranslate
.setX(ImplTwipsToMM(aTranslate
.getX()));
2916 aTranslate
.setY(ImplTwipsToMM(aTranslate
.getY()));
2919 aScale
.setX(ImplTwipsToMM(aScale
.getX()));
2920 aScale
.setY(ImplTwipsToMM(aScale
.getY()));
2923 basegfx::B2DHomMatrix aTwipsToMM
;
2924 const double fFactorTwipsToMM(127.0 / 72.0);
2925 aTwipsToMM
.scale(fFactorTwipsToMM
, fFactorTwipsToMM
);
2926 rPolyPolygon
.transform(aTwipsToMM
);
2932 DBG_ERROR("TRGetBaseGeometry: Missing unit translation to 100th mm!");
2937 // build return value matrix
2940 if(!basegfx::fTools::equal(aScale
.getX(), 1.0) || !basegfx::fTools::equal(aScale
.getY(), 1.0))
2942 rMatrix
.scale(aScale
.getX(), aScale
.getY());
2945 if(!basegfx::fTools::equalZero(fShearX
))
2947 rMatrix
.shearX(tan(fShearX
));
2950 if(!basegfx::fTools::equalZero(fRotate
))
2953 // fRotate is from the old GeoStat and thus mathematically wrong orientated. For
2954 // the linear combination of matrices it needed to be fixed in the API, so it needs to
2956 rMatrix
.rotate(-fRotate
);
2959 if(!aTranslate
.equalZero())
2961 rMatrix
.translate(aTranslate
.getX(), aTranslate
.getY());
2967 // sets the base geometry of the object using infos contained in the homogen 3x3 matrix.
2968 // If it's an SdrPathObj it will use the provided geometry information. The Polygon has
2969 // to use (0,0) as upper left and will be scaled to the given size in the matrix.
2970 void SdrPathObj::TRSetBaseGeometry(const basegfx::B2DHomMatrix
& rMatrix
, const basegfx::B2DPolyPolygon
& rPolyPolygon
)
2973 basegfx::B2DTuple aScale
;
2974 basegfx::B2DTuple aTranslate
;
2975 double fRotate
, fShearX
;
2976 rMatrix
.decompose(aScale
, aTranslate
, fRotate
, fShearX
);
2978 // #i75086# Old DrawingLayer (GeoStat and geometry) does not support holding negative scalings
2979 // in X and Y which equal a 180 degree rotation. Recognize it and react accordingly
2980 if(basegfx::fTools::less(aScale
.getX(), 0.0) && basegfx::fTools::less(aScale
.getY(), 0.0))
2982 aScale
.setX(fabs(aScale
.getX()));
2983 aScale
.setY(fabs(aScale
.getY()));
2984 fRotate
= fmod(fRotate
+ F_PI
, F_2PI
);
2988 basegfx::B2DPolyPolygon
aNewPolyPolygon(rPolyPolygon
);
2990 // reset object shear and rotations
2992 aGeo
.RecalcSinCos();
2993 aGeo
.nShearWink
= 0;
2996 // force metric to pool metric
2997 SfxMapUnit eMapUnit
= GetObjectItemSet().GetPool()->GetMetric(0);
2998 if(eMapUnit
!= SFX_MAPUNIT_100TH_MM
)
3002 case SFX_MAPUNIT_TWIP
:
3005 aTranslate
.setX(ImplMMToTwips(aTranslate
.getX()));
3006 aTranslate
.setY(ImplMMToTwips(aTranslate
.getY()));
3009 aScale
.setX(ImplMMToTwips(aScale
.getX()));
3010 aScale
.setY(ImplMMToTwips(aScale
.getY()));
3013 basegfx::B2DHomMatrix aMMToTwips
;
3014 const double fFactorMMToTwips(72.0 / 127.0);
3015 aMMToTwips
.scale(fFactorMMToTwips
, fFactorMMToTwips
);
3016 aNewPolyPolygon
.transform(aMMToTwips
);
3022 DBG_ERROR("TRSetBaseGeometry: Missing unit translation to PoolMetric!");
3027 if( pModel
&& pModel
->IsWriter() )
3029 // if anchor is used, make position relative to it
3030 if(GetAnchorPos().X() || GetAnchorPos().Y())
3032 aTranslate
+= basegfx::B2DTuple(GetAnchorPos().X(), GetAnchorPos().Y());
3036 // create transformation for polygon, set values at aGeo direct
3037 basegfx::B2DHomMatrix aTransform
;
3040 // Given polygon is already scaled (for historical reasons), but not mirrored yet.
3041 // Thus, when scale is negative in X or Y, apply the needed mirroring accordingly.
3042 if(basegfx::fTools::less(aScale
.getX(), 0.0) || basegfx::fTools::less(aScale
.getY(), 0.0))
3045 basegfx::fTools::less(aScale
.getX(), 0.0) ? -1.0 : 1.0,
3046 basegfx::fTools::less(aScale
.getY(), 0.0) ? -1.0 : 1.0);
3049 if(!basegfx::fTools::equalZero(fShearX
))
3051 aTransform
.shearX(tan(-atan(fShearX
)));
3052 aGeo
.nShearWink
= FRound(atan(fShearX
) / F_PI18000
);
3056 if(!basegfx::fTools::equalZero(fRotate
))
3059 // fRotate is matematically correct for linear transformations, so it's
3060 // the one to use for the geometry change
3061 aTransform
.rotate(fRotate
);
3064 // fRotate is matematically correct, but aGeoStat.nDrehWink is
3065 // mirrored -> mirror value here
3066 aGeo
.nDrehWink
= NormAngle360(FRound(-fRotate
/ F_PI18000
));
3067 aGeo
.RecalcSinCos();
3070 if(!aTranslate
.equalZero())
3072 // #i39529# absolute positioning, so get current position (without control points (!))
3073 const basegfx::B2DRange
aCurrentRange(basegfx::tools::getRange(aNewPolyPolygon
));
3074 aTransform
.translate(aTranslate
.getX() - aCurrentRange
.getMinX(), aTranslate
.getY() - aCurrentRange
.getMinY());
3077 // transform polygon and trigger change
3078 aNewPolyPolygon
.transform(aTransform
);
3079 SetPathPoly(aNewPolyPolygon
);
3082 //////////////////////////////////////////////////////////////////////////////