xref: /trunk/main/svx/source/svdraw/svdoedge.cxx (revision d3069caad29ae0df2efcdd74497d40d1ed39231c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <svx/svdoedge.hxx>
28 #include <svx/xpool.hxx>
29 #include <svx/xpoly.hxx>
30 #include <svx/svdattrx.hxx>
31 #include <svx/svdpool.hxx>
32 #include <svx/svdmodel.hxx>
33 #include <svx/svdpage.hxx>
34 #include <svx/svdpagv.hxx>
35 #include <svx/svdview.hxx>
36 #include <svx/svddrag.hxx>
37 #include <svx/svddrgv.hxx>
38 #include "svddrgm1.hxx"
39 #include <svx/svdhdl.hxx>
40 #include <svx/svdtrans.hxx>
41 #include <svx/svdetc.hxx>
42 #include "svx/svdglob.hxx"   // StringCache
43 #include "svx/svdstr.hrc"    // Objektname
44 #include <svl/style.hxx>
45 #include <svl/smplhint.hxx>
46 #include <editeng/eeitem.hxx>
47 #include "svdoimp.hxx"
48 #include <svx/sdr/properties/connectorproperties.hxx>
49 #include <svx/sdr/contact/viewcontactofsdredgeobj.hxx>
50 #include <basegfx/polygon/b2dpolygon.hxx>
51 #include <basegfx/polygon/b2dpolygontools.hxx>
52 #include <basegfx/matrix/b2dhommatrix.hxx>
53 #include <svx/sdrhittesthelper.hxx>
54 
55 ////////////////////////////////////////////////////////////////////////////////////////////////////
56 
57 SdrObjConnection::~SdrObjConnection()
58 {
59 }
60 
61 void SdrObjConnection::ResetVars()
62 {
63     pObj=NULL;
64     nConId=0;
65     nXDist=0;
66     nYDist=0;
67     bBestConn=sal_True;
68     bBestVertex=sal_True;
69     bXDistOvr=sal_False;
70     bYDistOvr=sal_False;
71     bAutoVertex=sal_False;
72     bAutoCorner=sal_False;
73 }
74 
75 FASTBOOL SdrObjConnection::TakeGluePoint(SdrGluePoint& rGP, FASTBOOL bSetAbsPos) const
76 {
77     FASTBOOL bRet=sal_False;
78     if (pObj!=NULL) { // Ein Obj muss schon angedockt sein!
79         if (bAutoVertex) {
80             rGP=pObj->GetVertexGluePoint(nConId);
81             bRet=sal_True;
82         } else if (bAutoCorner) {
83             rGP=pObj->GetCornerGluePoint(nConId);
84             bRet=sal_True;
85         } else {
86             const SdrGluePointList* pGPL=pObj->GetGluePointList();
87             if (pGPL!=NULL) {
88                 sal_uInt16 nNum=pGPL->FindGluePoint(nConId);
89                 if (nNum!=SDRGLUEPOINT_NOTFOUND) {
90                     rGP=(*pGPL)[nNum];
91                     bRet=sal_True;
92                 }
93             }
94         }
95     }
96     if (bRet && bSetAbsPos) {
97         Point aPt(rGP.GetAbsolutePos(*pObj));
98         aPt+=aObjOfs;
99         rGP.SetPos(aPt);
100     }
101     return bRet;
102 }
103 
104 Point& SdrEdgeInfoRec::ImpGetLineVersatzPoint(SdrEdgeLineCode eLineCode)
105 {
106     switch (eLineCode) {
107         case OBJ1LINE2 : return aObj1Line2;
108         case OBJ1LINE3 : return aObj1Line3;
109         case OBJ2LINE2 : return aObj2Line2;
110         case OBJ2LINE3 : return aObj2Line3;
111         case MIDDLELINE: return aMiddleLine;
112     } // switch
113     return aMiddleLine;
114 }
115 
116 sal_uInt16 SdrEdgeInfoRec::ImpGetPolyIdx(SdrEdgeLineCode eLineCode, const XPolygon& rXP) const
117 {
118     switch (eLineCode) {
119         case OBJ1LINE2 : return 1;
120         case OBJ1LINE3 : return 2;
121         case OBJ2LINE2 : return rXP.GetPointCount()-3;
122         case OBJ2LINE3 : return rXP.GetPointCount()-4;
123         case MIDDLELINE: return nMiddleLine;
124     } // switch
125     return 0;
126 }
127 
128 FASTBOOL SdrEdgeInfoRec::ImpIsHorzLine(SdrEdgeLineCode eLineCode, const XPolygon& rXP) const
129 {
130     sal_uInt16 nIdx=ImpGetPolyIdx(eLineCode,rXP);
131     FASTBOOL bHorz=nAngle1==0 || nAngle1==18000;
132     if (eLineCode==OBJ2LINE2 || eLineCode==OBJ2LINE3) {
133         nIdx=rXP.GetPointCount()-nIdx; // #36314#
134         bHorz=nAngle2==0 || nAngle2==18000; // #52000#
135     }
136     if ((nIdx & 1)==1) bHorz=!bHorz;
137     return bHorz;
138 }
139 
140 void SdrEdgeInfoRec::ImpSetLineVersatz(SdrEdgeLineCode eLineCode, const XPolygon& rXP, long nVal)
141 {
142     Point& rPt=ImpGetLineVersatzPoint(eLineCode);
143     if (ImpIsHorzLine(eLineCode,rXP)) rPt.Y()=nVal;
144     else rPt.X()=nVal;
145 }
146 
147 long SdrEdgeInfoRec::ImpGetLineVersatz(SdrEdgeLineCode eLineCode, const XPolygon& rXP) const
148 {
149     const Point& rPt=ImpGetLineVersatzPoint(eLineCode);
150     if (ImpIsHorzLine(eLineCode,rXP)) return rPt.Y();
151     else return rPt.X();
152 }
153 
154 //////////////////////////////////////////////////////////////////////////////
155 // BaseProperties section
156 
157 sdr::properties::BaseProperties* SdrEdgeObj::CreateObjectSpecificProperties()
158 {
159     return new sdr::properties::ConnectorProperties(*this);
160 }
161 
162 //////////////////////////////////////////////////////////////////////////////
163 // DrawContact section
164 
165 sdr::contact::ViewContact* SdrEdgeObj::CreateObjectSpecificViewContact()
166 {
167     return new sdr::contact::ViewContactOfSdrEdgeObj(*this);
168 }
169 
170 //////////////////////////////////////////////////////////////////////////////
171 
172 TYPEINIT1(SdrEdgeObj,SdrTextObj);
173 
174 SdrEdgeObj::SdrEdgeObj()
175 :   SdrTextObj(),
176     nNotifyingCount(0),
177     bEdgeTrackDirty(sal_False),
178     bEdgeTrackUserDefined(sal_False),
179     // #109007# Default is to allow default connects
180     mbSuppressDefaultConnect(sal_False),
181     // #110649#
182     mbBoundRectCalculationRunning(sal_False)
183 {
184     bClosedObj=sal_False;
185     bIsEdge=sal_True;
186     pEdgeTrack=new XPolygon;
187 
188 }
189 
190 SdrEdgeObj::~SdrEdgeObj()
191 {
192     DisconnectFromNode(sal_True);
193     DisconnectFromNode(sal_False);
194     delete pEdgeTrack;
195 }
196 
197 void SdrEdgeObj::ImpSetAttrToEdgeInfo()
198 {
199     const SfxItemSet& rSet = GetObjectItemSet();
200     SdrEdgeKind eKind = ((SdrEdgeKindItem&)(rSet.Get(SDRATTR_EDGEKIND))).GetValue();
201     sal_Int32 nVal1 = ((SdrEdgeLine1DeltaItem&)rSet.Get(SDRATTR_EDGELINE1DELTA)).GetValue();
202     sal_Int32 nVal2 = ((SdrEdgeLine2DeltaItem&)rSet.Get(SDRATTR_EDGELINE2DELTA)).GetValue();
203     sal_Int32 nVal3 = ((SdrEdgeLine3DeltaItem&)rSet.Get(SDRATTR_EDGELINE3DELTA)).GetValue();
204 
205     if(eKind == SDREDGE_ORTHOLINES || eKind == SDREDGE_BEZIER)
206     {
207         sal_Int32 nVals[3] = { nVal1, nVal2, nVal3 };
208         sal_uInt16 n = 0;
209 
210         if(aEdgeInfo.nObj1Lines >= 2 && n < 3)
211         {
212             aEdgeInfo.ImpSetLineVersatz(OBJ1LINE2, *pEdgeTrack, nVals[n]);
213             n++;
214         }
215 
216         if(aEdgeInfo.nObj1Lines >= 3 && n < 3)
217         {
218             aEdgeInfo.ImpSetLineVersatz(OBJ1LINE3, *pEdgeTrack, nVals[n]);
219             n++;
220         }
221 
222         if(aEdgeInfo.nMiddleLine != 0xFFFF && n < 3)
223         {
224             aEdgeInfo.ImpSetLineVersatz(MIDDLELINE, *pEdgeTrack, nVals[n]);
225             n++;
226         }
227 
228         if(aEdgeInfo.nObj2Lines >= 3 && n < 3)
229         {
230             aEdgeInfo.ImpSetLineVersatz(OBJ2LINE3, *pEdgeTrack, nVals[n]);
231             n++;
232         }
233 
234         if(aEdgeInfo.nObj2Lines >= 2 && n < 3)
235         {
236             aEdgeInfo.ImpSetLineVersatz(OBJ2LINE2, *pEdgeTrack, nVals[n]);
237             n++;
238         }
239     }
240     else if(eKind == SDREDGE_THREELINES)
241     {
242         sal_Bool bHor1 = aEdgeInfo.nAngle1 == 0 || aEdgeInfo.nAngle1 == 18000;
243         sal_Bool bHor2 = aEdgeInfo.nAngle2 == 0 || aEdgeInfo.nAngle2 == 18000;
244 
245         if(bHor1)
246         {
247             aEdgeInfo.aObj1Line2.X() = nVal1;
248         }
249         else
250         {
251             aEdgeInfo.aObj1Line2.Y() = nVal1;
252         }
253 
254         if(bHor2)
255         {
256             aEdgeInfo.aObj2Line2.X() = nVal2;
257         }
258         else
259         {
260             aEdgeInfo.aObj2Line2.Y() = nVal2;
261         }
262     }
263 
264     // #84649#
265     ImpDirtyEdgeTrack();
266 }
267 
268 void SdrEdgeObj::ImpSetEdgeInfoToAttr()
269 {
270     const SfxItemSet& rSet = GetObjectItemSet();
271     SdrEdgeKind eKind = ((SdrEdgeKindItem&)(rSet.Get(SDRATTR_EDGEKIND))).GetValue();
272     sal_Int32 nValAnz = ((SdrEdgeLineDeltaAnzItem&)rSet.Get(SDRATTR_EDGELINEDELTAANZ)).GetValue();
273     sal_Int32 nVal1 = ((SdrEdgeLine1DeltaItem&)rSet.Get(SDRATTR_EDGELINE1DELTA)).GetValue();
274     sal_Int32 nVal2 = ((SdrEdgeLine2DeltaItem&)rSet.Get(SDRATTR_EDGELINE2DELTA)).GetValue();
275     sal_Int32 nVal3 = ((SdrEdgeLine3DeltaItem&)rSet.Get(SDRATTR_EDGELINE3DELTA)).GetValue();
276     sal_Int32 nVals[3] = { nVal1, nVal2, nVal3 };
277     sal_uInt16 n = 0;
278 
279     if(eKind == SDREDGE_ORTHOLINES || eKind == SDREDGE_BEZIER)
280     {
281         if(aEdgeInfo.nObj1Lines >= 2 && n < 3)
282         {
283             nVals[n] = aEdgeInfo.ImpGetLineVersatz(OBJ1LINE2, *pEdgeTrack);
284             n++;
285         }
286 
287         if(aEdgeInfo.nObj1Lines >= 3 && n < 3)
288         {
289             nVals[n] = aEdgeInfo.ImpGetLineVersatz(OBJ1LINE3, *pEdgeTrack);
290             n++;
291         }
292 
293         if(aEdgeInfo.nMiddleLine != 0xFFFF && n < 3)
294         {
295             nVals[n] = aEdgeInfo.ImpGetLineVersatz(MIDDLELINE, *pEdgeTrack);
296             n++;
297         }
298 
299         if(aEdgeInfo.nObj2Lines >= 3 && n < 3)
300         {
301             nVals[n] = aEdgeInfo.ImpGetLineVersatz(OBJ2LINE3, *pEdgeTrack);
302             n++;
303         }
304 
305         if(aEdgeInfo.nObj2Lines >= 2 && n < 3)
306         {
307             nVals[n] = aEdgeInfo.ImpGetLineVersatz(OBJ2LINE2, *pEdgeTrack);
308             n++;
309         }
310     }
311     else if(eKind == SDREDGE_THREELINES)
312     {
313         sal_Bool bHor1 = aEdgeInfo.nAngle1 == 0 || aEdgeInfo.nAngle1 == 18000;
314         sal_Bool bHor2 = aEdgeInfo.nAngle2 == 0 || aEdgeInfo.nAngle2 == 18000;
315 
316         n = 2;
317         nVals[0] = bHor1 ? aEdgeInfo.aObj1Line2.X() : aEdgeInfo.aObj1Line2.Y();
318         nVals[1] = bHor2 ? aEdgeInfo.aObj2Line2.X() : aEdgeInfo.aObj2Line2.Y();
319     }
320 
321     if(n != nValAnz || nVals[0] != nVal1 || nVals[1] != nVal2 || nVals[2] != nVal3)
322     {
323         // #75371# Here no more notifying is necessary, just local changes are OK.
324         if(n != nValAnz)
325         {
326             GetProperties().SetObjectItemDirect(SdrEdgeLineDeltaAnzItem(n));
327         }
328 
329         if(nVals[0] != nVal1)
330         {
331             GetProperties().SetObjectItemDirect(SdrEdgeLine1DeltaItem(nVals[0]));
332         }
333 
334         if(nVals[1] != nVal2)
335         {
336             GetProperties().SetObjectItemDirect(SdrEdgeLine2DeltaItem(nVals[1]));
337         }
338 
339         if(nVals[2] != nVal3)
340         {
341             GetProperties().SetObjectItemDirect(SdrEdgeLine3DeltaItem(nVals[2]));
342         }
343 
344         if(n < 3)
345         {
346             GetProperties().ClearObjectItemDirect(SDRATTR_EDGELINE3DELTA);
347         }
348 
349         if(n < 2)
350         {
351             GetProperties().ClearObjectItemDirect(SDRATTR_EDGELINE2DELTA);
352         }
353 
354         if(n < 1)
355         {
356             GetProperties().ClearObjectItemDirect(SDRATTR_EDGELINE1DELTA);
357         }
358     }
359 }
360 
361 void SdrEdgeObj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
362 {
363     // #54102# allow rotation, mirror and shear
364     rInfo.bRotateFreeAllowed = true;
365     rInfo.bRotate90Allowed = true;
366     rInfo.bMirrorFreeAllowed = true;
367     rInfo.bMirror45Allowed = true;
368     rInfo.bMirror90Allowed = true;
369     rInfo.bTransparenceAllowed = sal_False;
370     rInfo.bGradientAllowed = sal_False;
371     rInfo.bShearAllowed = true;
372     rInfo.bEdgeRadiusAllowed = sal_False;
373     FASTBOOL bCanConv=!HasText() || ImpCanConvTextToCurve();
374     rInfo.bCanConvToPath=bCanConv;
375     rInfo.bCanConvToPoly=bCanConv;
376     rInfo.bCanConvToContour = (rInfo.bCanConvToPoly || LineGeometryUsageIsNecessary());
377 }
378 
379 sal_uInt16 SdrEdgeObj::GetObjIdentifier() const
380 {
381     return sal_uInt16(OBJ_EDGE);
382 }
383 
384 const Rectangle& SdrEdgeObj::GetCurrentBoundRect() const
385 {
386     if(bEdgeTrackDirty)
387     {
388         ((SdrEdgeObj*)this)->ImpRecalcEdgeTrack();
389     }
390 
391     return SdrTextObj::GetCurrentBoundRect();
392 }
393 
394 const Rectangle& SdrEdgeObj::GetSnapRect() const
395 {
396     if(bEdgeTrackDirty)
397     {
398         ((SdrEdgeObj*)this)->ImpRecalcEdgeTrack();
399     }
400 
401     return SdrTextObj::GetSnapRect();
402 }
403 
404 void SdrEdgeObj::RecalcSnapRect()
405 {
406     maSnapRect=pEdgeTrack->GetBoundRect();
407 }
408 
409 void SdrEdgeObj::TakeUnrotatedSnapRect(Rectangle& rRect) const
410 {
411     rRect=GetSnapRect();
412 }
413 
414 FASTBOOL SdrEdgeObj::IsNode() const
415 {
416     return sal_True;
417 }
418 
419 SdrGluePoint SdrEdgeObj::GetVertexGluePoint(sal_uInt16 nNum) const
420 {
421     Point aPt;
422     sal_uInt16 nPntAnz=pEdgeTrack->GetPointCount();
423     if (nPntAnz>0)
424     {
425         Point aOfs = GetSnapRect().Center();
426         if (nNum==2 && GetConnectedNode(sal_True)==NULL) aPt=(*pEdgeTrack)[0];
427         else if (nNum==3 && GetConnectedNode(sal_False)==NULL) aPt=(*pEdgeTrack)[nPntAnz-1];
428         else {
429             if ((nPntAnz & 1) ==1) {
430                 aPt=(*pEdgeTrack)[nPntAnz/2];
431             } else {
432                 Point aPt1((*pEdgeTrack)[nPntAnz/2-1]);
433                 Point aPt2((*pEdgeTrack)[nPntAnz/2]);
434                 aPt1+=aPt2;
435                 aPt1.X()/=2;
436                 aPt1.Y()/=2;
437                 aPt=aPt1;
438             }
439         }
440         aPt-=aOfs;
441     }
442     SdrGluePoint aGP(aPt);
443     aGP.SetPercent(sal_False);
444     return aGP;
445 }
446 
447 SdrGluePoint SdrEdgeObj::GetCornerGluePoint(sal_uInt16 nNum) const
448 {
449     return GetVertexGluePoint(nNum);
450 }
451 
452 const SdrGluePointList* SdrEdgeObj::GetGluePointList() const
453 {
454     return NULL; // Keine benutzerdefinierten Klebepunkte fuer Verbinder #31671#
455 }
456 
457 SdrGluePointList* SdrEdgeObj::ForceGluePointList()
458 {
459     return NULL; // Keine benutzerdefinierten Klebepunkte fuer Verbinder #31671#
460 }
461 
462 FASTBOOL SdrEdgeObj::IsEdge() const
463 {
464     return sal_True;
465 }
466 
467 void SdrEdgeObj::ConnectToNode(FASTBOOL bTail1, SdrObject* pObj)
468 {
469     SdrObjConnection& rCon=GetConnection(bTail1);
470     DisconnectFromNode(bTail1);
471     if (pObj!=NULL) {
472         pObj->AddListener(*this);
473         rCon.pObj=pObj;
474         ImpDirtyEdgeTrack();
475     }
476 }
477 
478 void SdrEdgeObj::DisconnectFromNode(FASTBOOL bTail1)
479 {
480     SdrObjConnection& rCon=GetConnection(bTail1);
481     if (rCon.pObj!=NULL) {
482         rCon.pObj->RemoveListener(*this);
483         rCon.pObj=NULL;
484     }
485 }
486 
487 SdrObject* SdrEdgeObj::GetConnectedNode(FASTBOOL bTail1) const
488 {
489     SdrObject* pObj=GetConnection(bTail1).pObj;
490     if (pObj!=NULL && (pObj->GetPage()!=pPage || !pObj->IsInserted())) pObj=NULL;
491     return pObj;
492 }
493 
494 FASTBOOL SdrEdgeObj::CheckNodeConnection(FASTBOOL bTail1) const
495 {
496     FASTBOOL bRet=sal_False;
497     const SdrObjConnection& rCon=GetConnection(bTail1);
498     sal_uInt16 nPtAnz=pEdgeTrack->GetPointCount();
499     if (rCon.pObj!=NULL && rCon.pObj->GetPage()==pPage && nPtAnz!=0) {
500         const SdrGluePointList* pGPL=rCon.pObj->GetGluePointList();
501         sal_uInt16 nConAnz=pGPL==NULL ? 0 : pGPL->GetCount();
502         sal_uInt16 nGesAnz=nConAnz+8;
503         Point aTail(bTail1 ? (*pEdgeTrack)[0] : (*pEdgeTrack)[sal_uInt16(nPtAnz-1)]);
504         for (sal_uInt16 i=0; i<nGesAnz && !bRet; i++) {
505             if (i<nConAnz) { // UserDefined
506                 bRet=aTail==(*pGPL)[i].GetAbsolutePos(*rCon.pObj);
507             } else if (i<nConAnz+4) { // Vertex
508                 SdrGluePoint aPt(rCon.pObj->GetVertexGluePoint(i-nConAnz));
509                 bRet=aTail==aPt.GetAbsolutePos(*rCon.pObj);
510             } else {                  // Corner
511                 SdrGluePoint aPt(rCon.pObj->GetCornerGluePoint(i-nConAnz-4));
512                 bRet=aTail==aPt.GetAbsolutePos(*rCon.pObj);
513             }
514         }
515     }
516     return bRet;
517 }
518 
519 void SdrEdgeObj::ImpSetTailPoint(FASTBOOL bTail1, const Point& rPt)
520 {
521     sal_uInt16 nPtAnz=pEdgeTrack->GetPointCount();
522     if (nPtAnz==0) {
523         (*pEdgeTrack)[0]=rPt;
524         (*pEdgeTrack)[1]=rPt;
525     } else if (nPtAnz==1) {
526         if (!bTail1) (*pEdgeTrack)[1]=rPt;
527         else { (*pEdgeTrack)[1]=(*pEdgeTrack)[0]; (*pEdgeTrack)[0]=rPt; }
528     } else {
529         if (!bTail1) (*pEdgeTrack)[sal_uInt16(nPtAnz-1)]=rPt;
530         else (*pEdgeTrack)[0]=rPt;
531     }
532     ImpRecalcEdgeTrack();
533     SetRectsDirty();
534 }
535 
536 void SdrEdgeObj::ImpDirtyEdgeTrack()
537 {
538     if ( !bEdgeTrackUserDefined || !(GetModel() && GetModel()->isLocked()) )
539         bEdgeTrackDirty = sal_True;
540 }
541 
542 void SdrEdgeObj::ImpUndirtyEdgeTrack()
543 {
544     if (bEdgeTrackDirty && (GetModel() && GetModel()->isLocked()) ) {
545         ImpRecalcEdgeTrack();
546     }
547 }
548 
549 void SdrEdgeObj::ImpRecalcEdgeTrack()
550 {
551     if ( bEdgeTrackUserDefined && (GetModel() && GetModel()->isLocked()) )
552         return;
553 
554     // #110649#
555     if(IsBoundRectCalculationRunning())
556     {
557         // this object is involved into another ImpRecalcEdgeTrack() call
558         // from another SdrEdgeObj. Do not calculate again to avoid loop.
559         // Also, do not change bEdgeTrackDirty so that it gets recalculated
560         // later at the first non-looping call.
561     }
562     // #i43068#
563     else if(GetModel() && GetModel()->isLocked())
564     {
565         // avoid re-layout during imports/API call sequences
566         // #i45294# but calc EdgeTrack and secure properties there
567         ((SdrEdgeObj*)this)->mbBoundRectCalculationRunning = sal_True;
568         *pEdgeTrack=ImpCalcEdgeTrack(*pEdgeTrack,aCon1,aCon2,&aEdgeInfo);
569         ImpSetAttrToEdgeInfo();
570         bEdgeTrackDirty=sal_False;
571         ((SdrEdgeObj*)this)->mbBoundRectCalculationRunning = sal_False;
572     }
573     else
574     {
575         // To not run in a depth loop, use a coloring algorythm on
576         // SdrEdgeObj BoundRect calculations
577         ((SdrEdgeObj*)this)->mbBoundRectCalculationRunning = sal_True;
578 
579         Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetCurrentBoundRect();
580         SetRectsDirty();
581         // #110094#-14 if (!bEdgeTrackDirty) SendRepaintBroadcast();
582         *pEdgeTrack=ImpCalcEdgeTrack(*pEdgeTrack,aCon1,aCon2,&aEdgeInfo);
583         ImpSetEdgeInfoToAttr(); // Die Werte aus aEdgeInfo in den Pool kopieren
584         bEdgeTrackDirty=sal_False;
585 
586         // Only redraw here, no object change
587         ActionChanged();
588         // BroadcastObjectChange();
589 
590         SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
591 
592         // #110649#
593         ((SdrEdgeObj*)this)->mbBoundRectCalculationRunning = sal_False;
594     }
595 }
596 
597 sal_uInt16 SdrEdgeObj::ImpCalcEscAngle(SdrObject* pObj, const Point& rPt) const
598 {
599     if (pObj==NULL) return SDRESC_ALL;
600     Rectangle aR(pObj->GetSnapRect());
601     long dxl=rPt.X()-aR.Left();
602     long dyo=rPt.Y()-aR.Top();
603     long dxr=aR.Right()-rPt.X();
604     long dyu=aR.Bottom()-rPt.Y();
605     FASTBOOL bxMitt=Abs(dxl-dxr)<2;
606     FASTBOOL byMitt=Abs(dyo-dyu)<2;
607     long dx=Min(dxl,dxr);
608     long dy=Min(dyo,dyu);
609     FASTBOOL bDiag=Abs(dx-dy)<2;
610     if (bxMitt && byMitt) return SDRESC_ALL; // In der Mitte
611     if (bDiag) {  // diagonal
612         sal_uInt16 nRet=0;
613         if (byMitt) nRet|=SDRESC_VERT;
614         if (bxMitt) nRet|=SDRESC_HORZ;
615         if (dxl<dxr) { // Links
616             if (dyo<dyu) nRet|=SDRESC_LEFT | SDRESC_TOP;
617             else nRet|=SDRESC_LEFT | SDRESC_BOTTOM;
618         } else {       // Rechts
619             if (dyo<dyu) nRet|=SDRESC_RIGHT | SDRESC_TOP;
620             else nRet|=SDRESC_RIGHT | SDRESC_BOTTOM;
621         }
622         return nRet;
623     }
624     if (dx<dy) { // waagerecht
625         if (bxMitt) return SDRESC_HORZ;
626         if (dxl<dxr) return SDRESC_LEFT;
627         else return SDRESC_RIGHT;
628     } else {     // senkrecht
629         if (byMitt) return SDRESC_VERT;
630         if (dyo<dyu) return SDRESC_TOP;
631         else return SDRESC_BOTTOM;
632     }
633 }
634 
635 FASTBOOL SdrEdgeObj::ImpStripPolyPoints(XPolygon& /*rXP*/) const
636 {
637     // fehlende Implementation !!!
638     return sal_False;
639 }
640 
641 XPolygon SdrEdgeObj::ImpCalcObjToCenter(const Point& rStPt, long nEscAngle, const Rectangle& rRect, const Point& rMeeting) const
642 {
643     XPolygon aXP;
644     aXP.Insert(XPOLY_APPEND,rStPt,XPOLY_NORMAL);
645     FASTBOOL bRts=nEscAngle==0;
646     FASTBOOL bObn=nEscAngle==9000;
647     FASTBOOL bLks=nEscAngle==18000;
648     FASTBOOL bUnt=nEscAngle==27000;
649 
650     Point aP1(rStPt); // erstmal den Pflichtabstand
651     if (bLks) aP1.X()=rRect.Left();
652     if (bRts) aP1.X()=rRect.Right();
653     if (bObn) aP1.Y()=rRect.Top();
654     if (bUnt) aP1.Y()=rRect.Bottom();
655 
656     FASTBOOL bFinish=sal_False;
657     if (!bFinish) {
658         Point aP2(aP1); // Und nun den Pflichtabstand ggf. bis auf Meetinghoehe erweitern
659         if (bLks && rMeeting.X()<=aP2.X()) aP2.X()=rMeeting.X();
660         if (bRts && rMeeting.X()>=aP2.X()) aP2.X()=rMeeting.X();
661         if (bObn && rMeeting.Y()<=aP2.Y()) aP2.Y()=rMeeting.Y();
662         if (bUnt && rMeeting.Y()>=aP2.Y()) aP2.Y()=rMeeting.Y();
663         aXP.Insert(XPOLY_APPEND,aP2,XPOLY_NORMAL);
664 
665         Point aP3(aP2);
666         if ((bLks && rMeeting.X()>aP2.X()) || (bRts && rMeeting.X()<aP2.X())) { // Aussenrum
667             if (rMeeting.Y()<aP2.Y()) {
668                 aP3.Y()=rRect.Top();
669                 if (rMeeting.Y()<aP3.Y()) aP3.Y()=rMeeting.Y();
670             } else {
671                 aP3.Y()=rRect.Bottom();
672                 if (rMeeting.Y()>aP3.Y()) aP3.Y()=rMeeting.Y();
673             }
674             aXP.Insert(XPOLY_APPEND,aP3,XPOLY_NORMAL);
675             if (aP3.Y()!=rMeeting.Y()) {
676                 aP3.X()=rMeeting.X();
677                 aXP.Insert(XPOLY_APPEND,aP3,XPOLY_NORMAL);
678             }
679         }
680         if ((bObn && rMeeting.Y()>aP2.Y()) || (bUnt && rMeeting.Y()<aP2.Y())) { // Aussenrum
681             if (rMeeting.X()<aP2.X()) {
682                 aP3.X()=rRect.Left();
683                 if (rMeeting.X()<aP3.X()) aP3.X()=rMeeting.X();
684             } else {
685                 aP3.X()=rRect.Right();
686                 if (rMeeting.X()>aP3.X()) aP3.X()=rMeeting.X();
687             }
688             aXP.Insert(XPOLY_APPEND,aP3,XPOLY_NORMAL);
689             if (aP3.X()!=rMeeting.X()) {
690                 aP3.Y()=rMeeting.Y();
691                 aXP.Insert(XPOLY_APPEND,aP3,XPOLY_NORMAL);
692             }
693         }
694     }
695 #ifdef DBG_UTIL
696     if (aXP.GetPointCount()>4) {
697         DBG_ERROR("SdrEdgeObj::ImpCalcObjToCenter(): Polygon hat mehr als 4 Punkte!");
698     }
699 #endif
700     return aXP;
701 }
702 
703 XPolygon SdrEdgeObj::ImpCalcEdgeTrack(const XPolygon& rTrack0, SdrObjConnection& rCon1, SdrObjConnection& rCon2, SdrEdgeInfoRec* pInfo) const
704 {
705     Point aPt1,aPt2;
706     SdrGluePoint aGP1,aGP2;
707     sal_uInt16 nEsc1=SDRESC_ALL,nEsc2=SDRESC_ALL;
708     Rectangle aBoundRect1;
709     Rectangle aBoundRect2;
710     Rectangle aBewareRect1;
711     Rectangle aBewareRect2;
712     // Erstmal die alten Endpunkte wiederholen
713     if (rTrack0.GetPointCount()!=0) {
714         aPt1=rTrack0[0];
715         sal_uInt16 nSiz=rTrack0.GetPointCount();
716         nSiz--;
717         aPt2=rTrack0[nSiz];
718     } else {
719         if (!aOutRect.IsEmpty()) {
720             aPt1=aOutRect.TopLeft();
721             aPt2=aOutRect.BottomRight();
722         }
723     }
724 
725     // #54102# To allow interactive preview, do also if not inserted
726     FASTBOOL bCon1=rCon1.pObj!=NULL && rCon1.pObj->GetPage()==pPage; // && rCon1.pObj->IsInserted();
727     FASTBOOL bCon2=rCon2.pObj!=NULL && rCon2.pObj->GetPage()==pPage; // && rCon2.pObj->IsInserted();
728     const SfxItemSet& rSet = GetObjectItemSet();
729 
730     if (bCon1) {
731         if (rCon1.pObj==(SdrObject*)this)
732         {
733             // sicherheitshalber Abfragen #44515#
734             aBoundRect1=aOutRect;
735         }
736         else
737         {
738             aBoundRect1 = rCon1.pObj->GetCurrentBoundRect();
739         }
740         aBoundRect1.Move(rCon1.aObjOfs.X(),rCon1.aObjOfs.Y());
741         aBewareRect1=aBoundRect1;
742 
743         sal_Int32 nH = ((SdrEdgeNode1HorzDistItem&)rSet.Get(SDRATTR_EDGENODE1HORZDIST)).GetValue();
744         sal_Int32 nV = ((SdrEdgeNode1VertDistItem&)rSet.Get(SDRATTR_EDGENODE1VERTDIST)).GetValue();
745 
746         aBewareRect1.Left()-=nH;
747         aBewareRect1.Right()+=nH;
748         aBewareRect1.Top()-=nV;
749         aBewareRect1.Bottom()+=nV;
750     } else {
751         aBoundRect1=Rectangle(aPt1,aPt1);
752         aBoundRect1.Move(rCon1.aObjOfs.X(),rCon1.aObjOfs.Y());
753         aBewareRect1=aBoundRect1;
754     }
755     if (bCon2) {
756         if (rCon2.pObj==(SdrObject*)this) { // sicherheitshalber Abfragen #44515#
757             aBoundRect2=aOutRect;
758         }
759         else
760         {
761             aBoundRect2 = rCon2.pObj->GetCurrentBoundRect();
762         }
763         aBoundRect2.Move(rCon2.aObjOfs.X(),rCon2.aObjOfs.Y());
764         aBewareRect2=aBoundRect2;
765 
766         sal_Int32 nH = ((SdrEdgeNode2HorzDistItem&)rSet.Get(SDRATTR_EDGENODE2HORZDIST)).GetValue();
767         sal_Int32 nV = ((SdrEdgeNode2VertDistItem&)rSet.Get(SDRATTR_EDGENODE2VERTDIST)).GetValue();
768 
769         aBewareRect2.Left()-=nH;
770         aBewareRect2.Right()+=nH;
771         aBewareRect2.Top()-=nV;
772         aBewareRect2.Bottom()+=nV;
773     } else {
774         aBoundRect2=Rectangle(aPt2,aPt2);
775         aBoundRect2.Move(rCon2.aObjOfs.X(),rCon2.aObjOfs.Y());
776         aBewareRect2=aBoundRect2;
777     }
778     XPolygon aBestXP;
779     sal_uIntPtr nBestQual=0xFFFFFFFF;
780     SdrEdgeInfoRec aBestInfo;
781     FASTBOOL bAuto1=bCon1 && rCon1.bBestVertex;
782     FASTBOOL bAuto2=bCon2 && rCon2.bBestVertex;
783     if (bAuto1) rCon1.bAutoVertex=sal_True;
784     if (bAuto2) rCon2.bAutoVertex=sal_True;
785     sal_uInt16 nBestAuto1=0;
786     sal_uInt16 nBestAuto2=0;
787     sal_uInt16 nAnz1=bAuto1 ? 4 : 1;
788     sal_uInt16 nAnz2=bAuto2 ? 4 : 1;
789     for (sal_uInt16 nNum1=0; nNum1<nAnz1; nNum1++) {
790         if (bAuto1) rCon1.nConId=nNum1;
791         if (bCon1 && rCon1.TakeGluePoint(aGP1,sal_True)) {
792             aPt1=aGP1.GetPos();
793             nEsc1=aGP1.GetEscDir();
794             if (nEsc1==SDRESC_SMART) nEsc1=ImpCalcEscAngle(rCon1.pObj,aPt1-rCon1.aObjOfs);
795         }
796         for (sal_uInt16 nNum2=0; nNum2<nAnz2; nNum2++) {
797             if (bAuto2) rCon2.nConId=nNum2;
798             if (bCon2 && rCon2.TakeGluePoint(aGP2,sal_True)) {
799                 aPt2=aGP2.GetPos();
800                 nEsc2=aGP2.GetEscDir();
801                 if (nEsc2==SDRESC_SMART) nEsc2=ImpCalcEscAngle(rCon2.pObj,aPt2-rCon2.aObjOfs);
802             }
803             for (long nA1=0; nA1<36000; nA1+=9000) {
804                 sal_uInt16 nE1=nA1==0 ? SDRESC_RIGHT : nA1==9000 ? SDRESC_TOP : nA1==18000 ? SDRESC_LEFT : nA1==27000 ? SDRESC_BOTTOM : 0;
805                 for (long nA2=0; nA2<36000; nA2+=9000) {
806                     sal_uInt16 nE2=nA2==0 ? SDRESC_RIGHT : nA2==9000 ? SDRESC_TOP : nA2==18000 ? SDRESC_LEFT : nA2==27000 ? SDRESC_BOTTOM : 0;
807                     if ((nEsc1&nE1)!=0 && (nEsc2&nE2)!=0) {
808                         sal_uIntPtr nQual=0;
809                         SdrEdgeInfoRec aInfo;
810                         if (pInfo!=NULL) aInfo=*pInfo;
811                         XPolygon aXP(ImpCalcEdgeTrack(aPt1,nA1,aBoundRect1,aBewareRect1,aPt2,nA2,aBoundRect2,aBewareRect2,&nQual,&aInfo));
812                         if (nQual<nBestQual) {
813                             aBestXP=aXP;
814                             nBestQual=nQual;
815                             aBestInfo=aInfo;
816                             nBestAuto1=nNum1;
817                             nBestAuto2=nNum2;
818                         }
819                     }
820                 }
821             }
822         }
823     }
824     if (bAuto1) rCon1.nConId=nBestAuto1;
825     if (bAuto2) rCon2.nConId=nBestAuto2;
826     if (pInfo!=NULL) *pInfo=aBestInfo;
827     return aBestXP;
828 }
829 
830 XPolygon SdrEdgeObj::ImpCalcEdgeTrack(const Point& rPt1, long nAngle1, const Rectangle& rBoundRect1, const Rectangle& rBewareRect1,
831     const Point& rPt2, long nAngle2, const Rectangle& rBoundRect2, const Rectangle& rBewareRect2,
832     sal_uIntPtr* pnQuality, SdrEdgeInfoRec* pInfo) const
833 {
834     SdrEdgeKind eKind=((SdrEdgeKindItem&)(GetObjectItem(SDRATTR_EDGEKIND))).GetValue();
835     FASTBOOL bRts1=nAngle1==0;
836     FASTBOOL bObn1=nAngle1==9000;
837     FASTBOOL bLks1=nAngle1==18000;
838     FASTBOOL bUnt1=nAngle1==27000;
839     FASTBOOL bHor1=bLks1 || bRts1;
840     FASTBOOL bVer1=bObn1 || bUnt1;
841     FASTBOOL bRts2=nAngle2==0;
842     FASTBOOL bObn2=nAngle2==9000;
843     FASTBOOL bLks2=nAngle2==18000;
844     FASTBOOL bUnt2=nAngle2==27000;
845     FASTBOOL bHor2=bLks2 || bRts2;
846     FASTBOOL bVer2=bObn2 || bUnt2;
847     FASTBOOL bInfo=pInfo!=NULL;
848     if (bInfo) {
849         pInfo->cOrthoForm=0;
850         pInfo->nAngle1=nAngle1;
851         pInfo->nAngle2=nAngle2;
852         pInfo->nObj1Lines=1;
853         pInfo->nObj2Lines=1;
854         pInfo->nMiddleLine=0xFFFF;
855     }
856     Point aPt1(rPt1);
857     Point aPt2(rPt2);
858     Rectangle aBoundRect1 (rBoundRect1 );
859     Rectangle aBoundRect2 (rBoundRect2 );
860     Rectangle aBewareRect1(rBewareRect1);
861     Rectangle aBewareRect2(rBewareRect2);
862     Point aMeeting((aPt1.X()+aPt2.X()+1)/2,(aPt1.Y()+aPt2.Y()+1)/2);
863     FASTBOOL bMeetingXMid=sal_True;
864     FASTBOOL bMeetingYMid=sal_True;
865     if (eKind==SDREDGE_ONELINE) {
866         XPolygon aXP(2);
867         aXP[0]=rPt1;
868         aXP[1]=rPt2;
869         if (pnQuality!=NULL) {
870             *pnQuality=Abs(rPt1.X()-rPt2.X())+Abs(rPt1.Y()-rPt2.Y());
871         }
872         return aXP;
873     } else if (eKind==SDREDGE_THREELINES) {
874         XPolygon aXP(4);
875         aXP[0]=rPt1;
876         aXP[1]=rPt1;
877         aXP[2]=rPt2;
878         aXP[3]=rPt2;
879         if (bRts1) aXP[1].X()=aBewareRect1.Right();  //+=500;
880         if (bObn1) aXP[1].Y()=aBewareRect1.Top();    //-=500;
881         if (bLks1) aXP[1].X()=aBewareRect1.Left();   //-=500;
882         if (bUnt1) aXP[1].Y()=aBewareRect1.Bottom(); //+=500;
883         if (bRts2) aXP[2].X()=aBewareRect2.Right();  //+=500;
884         if (bObn2) aXP[2].Y()=aBewareRect2.Top();    //-=500;
885         if (bLks2) aXP[2].X()=aBewareRect2.Left();   //-=500;
886         if (bUnt2) aXP[2].Y()=aBewareRect2.Bottom(); //+=500;
887         if (pnQuality!=NULL) {
888             long nQ=Abs(aXP[1].X()-aXP[0].X())+Abs(aXP[1].Y()-aXP[0].Y());
889                 nQ+=Abs(aXP[2].X()-aXP[1].X())+Abs(aXP[2].Y()-aXP[1].Y());
890                 nQ+=Abs(aXP[3].X()-aXP[2].X())+Abs(aXP[3].Y()-aXP[2].Y());
891             *pnQuality=nQ;
892         }
893         if (bInfo) {
894             pInfo->nObj1Lines=2;
895             pInfo->nObj2Lines=2;
896             if (bHor1) {
897                 aXP[1].X()+=pInfo->aObj1Line2.X();
898             } else {
899                 aXP[1].Y()+=pInfo->aObj1Line2.Y();
900             }
901             if (bHor2) {
902                 aXP[2].X()+=pInfo->aObj2Line2.X();
903             } else {
904                 aXP[2].Y()+=pInfo->aObj2Line2.Y();
905             }
906         }
907         return aXP;
908     }
909     sal_uInt16 nIntersections=0;
910     FASTBOOL bForceMeeting=sal_False; // Muss die Linie durch den MeetingPoint laufen?
911     {
912         Point aC1(aBewareRect1.Center());
913         Point aC2(aBewareRect2.Center());
914         if (aBewareRect1.Left()<=aBewareRect2.Right() && aBewareRect1.Right()>=aBewareRect2.Left()) {
915             // Ueberschneidung auf der X-Achse
916             long n1=Max(aBewareRect1.Left(),aBewareRect2.Left());
917             long n2=Min(aBewareRect1.Right(),aBewareRect2.Right());
918             aMeeting.X()=(n1+n2+1)/2;
919         } else {
920             // Ansonsten den Mittelpunkt des Freiraums
921             if (aC1.X()<aC2.X()) {
922                 aMeeting.X()=(aBewareRect1.Right()+aBewareRect2.Left()+1)/2;
923             } else {
924                 aMeeting.X()=(aBewareRect1.Left()+aBewareRect2.Right()+1)/2;
925             }
926         }
927         if (aBewareRect1.Top()<=aBewareRect2.Bottom() && aBewareRect1.Bottom()>=aBewareRect2.Top()) {
928             // Ueberschneidung auf der Y-Achse
929             long n1=Max(aBewareRect1.Top(),aBewareRect2.Top());
930             long n2=Min(aBewareRect1.Bottom(),aBewareRect2.Bottom());
931             aMeeting.Y()=(n1+n2+1)/2;
932         } else {
933             // Ansonsten den Mittelpunkt des Freiraums
934             if (aC1.Y()<aC2.Y()) {
935                 aMeeting.Y()=(aBewareRect1.Bottom()+aBewareRect2.Top()+1)/2;
936             } else {
937                 aMeeting.Y()=(aBewareRect1.Top()+aBewareRect2.Bottom()+1)/2;
938             }
939         }
940         // Im Prinzip gibt es 3 zu unterscheidene Faelle:
941         //   1. Beide in die selbe Richtung
942         //   2. Beide in genau entgegengesetzte Richtungen
943         //   3. Einer waagerecht und der andere senkrecht
944         long nXMin=Min(aBewareRect1.Left(),aBewareRect2.Left());
945         long nXMax=Max(aBewareRect1.Right(),aBewareRect2.Right());
946         long nYMin=Min(aBewareRect1.Top(),aBewareRect2.Top());
947         long nYMax=Max(aBewareRect1.Bottom(),aBewareRect2.Bottom());
948         //int bBoundOverlap=aBoundRect1.Right()>aBoundRect2.Left() && aBoundRect1.Left()<aBoundRect2.Right() &&
949                                aBoundRect1.Bottom()>aBoundRect2.Top() && aBoundRect1.Top()<aBoundRect2.Bottom();
950         FASTBOOL bBewareOverlap=aBewareRect1.Right()>aBewareRect2.Left() && aBewareRect1.Left()<aBewareRect2.Right() &&
951                                 aBewareRect1.Bottom()>aBewareRect2.Top() && aBewareRect1.Top()<aBewareRect2.Bottom();
952         unsigned nMainCase=3;
953         if (nAngle1==nAngle2) nMainCase=1;
954         else if ((bHor1 && bHor2) || (bVer1 && bVer2)) nMainCase=2;
955         if (nMainCase==1) { // Fall 1: Beide in eine Richtung moeglich.
956             if (bVer1) aMeeting.X()=(aPt1.X()+aPt2.X()+1)/2; // ist hier besser, als der
957             if (bHor1) aMeeting.Y()=(aPt1.Y()+aPt2.Y()+1)/2; // Mittelpunkt des Freiraums
958             // bX1Ok bedeutet, dass die Vertikale, die aus Obj1 austritt, keinen Konflikt mit Obj2 bildet, ...
959             FASTBOOL bX1Ok=aPt1.X()<=aBewareRect2.Left() || aPt1.X()>=aBewareRect2.Right();
960             FASTBOOL bX2Ok=aPt2.X()<=aBewareRect1.Left() || aPt2.X()>=aBewareRect1.Right();
961             FASTBOOL bY1Ok=aPt1.Y()<=aBewareRect2.Top() || aPt1.Y()>=aBewareRect2.Bottom();
962             FASTBOOL bY2Ok=aPt2.Y()<=aBewareRect1.Top() || aPt2.Y()>=aBewareRect1.Bottom();
963             if (bLks1 && (bY1Ok || aBewareRect1.Left()<aBewareRect2.Right()) && (bY2Ok || aBewareRect2.Left()<aBewareRect1.Right())) {
964                 aMeeting.X()=nXMin;
965                 bMeetingXMid=sal_False;
966             }
967             if (bRts1 && (bY1Ok || aBewareRect1.Right()>aBewareRect2.Left()) && (bY2Ok || aBewareRect2.Right()>aBewareRect1.Left())) {
968                 aMeeting.X()=nXMax;
969                 bMeetingXMid=sal_False;
970             }
971             if (bObn1 && (bX1Ok || aBewareRect1.Top()<aBewareRect2.Bottom()) && (bX2Ok || aBewareRect2.Top()<aBewareRect1.Bottom())) {
972                 aMeeting.Y()=nYMin;
973                 bMeetingYMid=sal_False;
974             }
975             if (bUnt1 && (bX1Ok || aBewareRect1.Bottom()>aBewareRect2.Top()) && (bX2Ok || aBewareRect2.Bottom()>aBewareRect1.Top())) {
976                 aMeeting.Y()=nYMax;
977                 bMeetingYMid=sal_False;
978             }
979         } else if (nMainCase==2) {
980             // Fall 2:
981             bForceMeeting=sal_True;
982             if (bHor1) { // beide waagerecht
983                 /* 9 Moeglichkeiten:                   � � �                    */
984                 /*   2.1 Gegenueber, Ueberschneidung   � � �                    */
985                 /*       nur auf der Y-Achse           � � �                    */
986                 /*   2.2, 2.3 Gegenueber, vertikal versetzt. � � �   � � �      */
987                 /*            Ueberschneidung weder auf der  � � �   � � �      */
988                 /*            X- noch auf der Y-Achse        � � �   � � �      */
989                 /*   2.4, 2.5 Untereinander,   � � �   � � �                    */
990                 /*            Ueberschneidung  � � �   � � �                    */
991                 /*            nur auf X-Achse  � � �   � � �                    */
992                 /*   2.6, 2.7 Gegeneinander, vertikal versetzt. � � �   � � �   */
993                 /*            Ueberschneidung weder auf der     � � �   � � �   */
994                 /*            X- noch auf der Y-Achse.          � � �   � � �   */
995                 /*   2.8 Gegeneinander.       � � �                             */
996                 /*       Ueberschneidung nur  � � �                             */
997                 /*       auf der Y-Achse.     � � �                             */
998                 /*   2.9 Die BewareRects der Objekte ueberschneiden             */
999                 /*       sich auf X- und Y-Achse.                               */
1000                 /* Die Faelle gelten entsprechend umgesetzt auch fuer           */
1001                 /* senkrechte Linienaustritte.                                  */
1002                 /* Die Faelle 2.1-2.7 werden mit dem Default-Meeting ausreichend*/
1003                 /* gut behandelt. Spezielle MeetingPoints werden hier also nur  */
1004                 /* fuer 2.8 und 2.9 bestimmt.                                   */
1005 
1006                 // Normalisierung. aR1 soll der nach rechts und
1007                 // aR2 der nach links austretende sein.
1008                 Rectangle aBewR1(bRts1 ? aBewareRect1 : aBewareRect2);
1009                 Rectangle aBewR2(bRts1 ? aBewareRect2 : aBewareRect1);
1010                 Rectangle aBndR1(bRts1 ? aBoundRect1 : aBoundRect2);
1011                 Rectangle aBndR2(bRts1 ? aBoundRect2 : aBoundRect1);
1012                 if (aBewR1.Bottom()>aBewR2.Top() && aBewR1.Top()<aBewR2.Bottom()) {
1013                     // Ueberschneidung auf der Y-Achse. Faelle 2.1, 2.8, 2.9
1014                     if (aBewR1.Right()>aBewR2.Left()) {
1015                         // Faelle 2.8, 2.9
1016                         // Fall 2.8 ist immer Aussenrumlauf (bDirect=sal_False).
1017                         // Fall 2.9 kann auch Direktverbindung sein (bei geringer
1018                         // Ueberschneidung der BewareRects ohne Ueberschneidung der
1019                         // Boundrects wenn die Linienaustritte sonst das BewareRect
1020                         // des jeweils anderen Objekts verletzen wuerden.
1021                         FASTBOOL bCase29Direct=sal_False;
1022                         FASTBOOL bCase29=aBewR1.Right()>aBewR2.Left();
1023                         if (aBndR1.Right()<=aBndR2.Left()) { // Fall 2.9 und keine Boundrectueberschneidung
1024                             if ((aPt1.Y()>aBewareRect2.Top() && aPt1.Y()<aBewareRect2.Bottom()) ||
1025                                 (aPt2.Y()>aBewareRect1.Top() && aPt2.Y()<aBewareRect1.Bottom())) {
1026                                bCase29Direct=sal_True;
1027                             }
1028                         }
1029                         if (!bCase29Direct) {
1030                             FASTBOOL bObenLang=Abs(nYMin-aMeeting.Y())<=Abs(nYMax-aMeeting.Y());
1031                             if (bObenLang) {
1032                                 aMeeting.Y()=nYMin;
1033                             } else {
1034                                 aMeeting.Y()=nYMax;
1035                             }
1036                             bMeetingYMid=sal_False;
1037                             if (bCase29) {
1038                                 // und nun noch dafuer sorgen, dass das
1039                                 // umzingelte Obj nicht durchquert wird
1040                                 if ((aBewR1.Center().Y()<aBewR2.Center().Y()) != bObenLang) {
1041                                     aMeeting.X()=aBewR2.Right();
1042                                 } else {
1043                                     aMeeting.X()=aBewR1.Left();
1044                                 }
1045                                 bMeetingXMid=sal_False;
1046                             }
1047                         } else {
1048                             // Direkte Verbindung (3-Linien Z-Verbindung), da
1049                             // Verletzung der BewareRects unvermeidlich ist.
1050                             // Via Dreisatz werden die BewareRects nun verkleinert.
1051                             long nWant1=aBewR1.Right()-aBndR1.Right(); // Abstand bei Obj1
1052                             long nWant2=aBndR2.Left()-aBewR2.Left();   // Abstand bei Obj2
1053                             long nSpace=aBndR2.Left()-aBndR1.Right(); // verfuegbarer Platz
1054                             long nGet1=BigMulDiv(nWant1,nSpace,nWant1+nWant2);
1055                             long nGet2=nSpace-nGet1;
1056                             if (bRts1) { // Normalisierung zurueckwandeln
1057                                 aBewareRect1.Right()+=nGet1-nWant1;
1058                                 aBewareRect2.Left()-=nGet2-nWant2;
1059                             } else {
1060                                 aBewareRect2.Right()+=nGet1-nWant1;
1061                                 aBewareRect1.Left()-=nGet2-nWant2;
1062                             }
1063                             nIntersections++; // Qualitaet herabsetzen
1064                         }
1065                     }
1066                 }
1067             } else if (bVer1) { // beide senkrecht
1068                 Rectangle aBewR1(bUnt1 ? aBewareRect1 : aBewareRect2);
1069                 Rectangle aBewR2(bUnt1 ? aBewareRect2 : aBewareRect1);
1070                 Rectangle aBndR1(bUnt1 ? aBoundRect1 : aBoundRect2);
1071                 Rectangle aBndR2(bUnt1 ? aBoundRect2 : aBoundRect1);
1072                 if (aBewR1.Right()>aBewR2.Left() && aBewR1.Left()<aBewR2.Right()) {
1073                     // Ueberschneidung auf der Y-Achse. Faelle 2.1, 2.8, 2.9
1074                     if (aBewR1.Bottom()>aBewR2.Top()) {
1075                         // Faelle 2.8, 2.9
1076                         // Fall 2.8 ist immer Aussenrumlauf (bDirect=sal_False).
1077                         // Fall 2.9 kann auch Direktverbindung sein (bei geringer
1078                         // Ueberschneidung der BewareRects ohne Ueberschneidung der
1079                         // Boundrects wenn die Linienaustritte sonst das BewareRect
1080                         // des jeweils anderen Objekts verletzen wuerden.
1081                         FASTBOOL bCase29Direct=sal_False;
1082                         FASTBOOL bCase29=aBewR1.Bottom()>aBewR2.Top();
1083                         if (aBndR1.Bottom()<=aBndR2.Top()) { // Fall 2.9 und keine Boundrectueberschneidung
1084                             if ((aPt1.X()>aBewareRect2.Left() && aPt1.X()<aBewareRect2.Right()) ||
1085                                 (aPt2.X()>aBewareRect1.Left() && aPt2.X()<aBewareRect1.Right())) {
1086                                bCase29Direct=sal_True;
1087                             }
1088                         }
1089                         if (!bCase29Direct) {
1090                             FASTBOOL bLinksLang=Abs(nXMin-aMeeting.X())<=Abs(nXMax-aMeeting.X());
1091                             if (bLinksLang) {
1092                                 aMeeting.X()=nXMin;
1093                             } else {
1094                                 aMeeting.X()=nXMax;
1095                             }
1096                             bMeetingXMid=sal_False;
1097                             if (bCase29) {
1098                                 // und nun noch dafuer sorgen, dass das
1099                                 // umzingelte Obj nicht durchquert wird
1100                                 if ((aBewR1.Center().X()<aBewR2.Center().X()) != bLinksLang) {
1101                                     aMeeting.Y()=aBewR2.Bottom();
1102                                 } else {
1103                                     aMeeting.Y()=aBewR1.Top();
1104                                 }
1105                                 bMeetingYMid=sal_False;
1106                             }
1107                         } else {
1108                             // Direkte Verbindung (3-Linien Z-Verbindung), da
1109                             // Verletzung der BewareRects unvermeidlich ist.
1110                             // Via Dreisatz werden die BewareRects nun verkleinert.
1111                             long nWant1=aBewR1.Bottom()-aBndR1.Bottom(); // Abstand bei Obj1
1112                             long nWant2=aBndR2.Top()-aBewR2.Top();   // Abstand bei Obj2
1113                             long nSpace=aBndR2.Top()-aBndR1.Bottom(); // verfuegbarer Platz
1114                             long nGet1=BigMulDiv(nWant1,nSpace,nWant1+nWant2);
1115                             long nGet2=nSpace-nGet1;
1116                             if (bUnt1) { // Normalisierung zurueckwandeln
1117                                 aBewareRect1.Bottom()+=nGet1-nWant1;
1118                                 aBewareRect2.Top()-=nGet2-nWant2;
1119                             } else {
1120                                 aBewareRect2.Bottom()+=nGet1-nWant1;
1121                                 aBewareRect1.Top()-=nGet2-nWant2;
1122                             }
1123                             nIntersections++; // Qualitaet herabsetzen
1124                         }
1125                     }
1126                 }
1127             }
1128         } else if (nMainCase==3) { // Fall 3: Einer waagerecht und der andere senkrecht. Sehr viele Fallunterscheidungen
1129             /* Kleine Legende: � � � � � -> Ohne Ueberschneidung, maximal Beruehrung.                   */
1130             /*                 � � � � � -> Ueberschneidung                                             */
1131             /*                 � � � � � -> Selbe Hoehe                                                 */
1132             /*                 � � � � � -> Ueberschneidung                                             */
1133             /*                 � � � � � -> Ohne Ueberschneidung, maximal Beruehrung.                   */
1134             /* Linienaustritte links �, rechts �, oben � und unten �.                                   */
1135             /* Insgesamt sind 96 Konstellationen moeglich, wobei einige nicht einmal                    */
1136             /* eindeutig einem Fall und damit einer Behandlungsmethode zugeordnet werden                */
1137             /* koennen.                                                                                 */
1138             /* 3.1: Hierzu moegen alle Konstellationen zaehlen, die durch den                           */
1139             /*      Default-MeetingPoint zufriedenstellend abgedeckt sind (20+12).                      */
1140             /*   � � � � �    � � � � �   Diese 12  � � � � �    � � � � �    � � � � �    � � � � �    */
1141             /*   � � � � �    � � � � �   Konstel.  � � � � �    � � � � �    � � � � �    � � � � �    */
1142             /*   � � � � �    � � � � �   jedoch    � � � � �    � � � � �    � � � � �    � � � � �    */
1143             /*   � � � � �    � � � � �   nur zum   � � � � �    � � � � �    � � � � �    � � � � �    */
1144             /*   � � � � �    � � � � �   Teil:     � � � � �    � � � � �    � � � � �    � � � � �    */
1145             /*   Letztere 16 Faelle scheiden aus, sobald sich die Objekte offen                         */
1146             /*   gegenueberstehen (siehe Fall 3.2).                                                     */
1147             /* 3.2: Die Objekte stehen sich offen gegenueber und somit ist eine                         */
1148             /*      Verbindung mit lediglich 2 Linien moeglich (4+20).                                  */
1149             /*      Dieser Fall hat 1. Prioritaet.                                                      */
1150             /*   � � � � �   � � � � �   Diese 20  � � � � �   � � � � �   � � � � �   � � � � �        */
1151             /*   � � � � �   � � � � �   Konstel.  � � � � �   � � � � �   � � � � �   � � � � �        */
1152             /*   � � � � �   � � � � �   jedoch    � � � � �   � � � � �   � � � � �   � � � � �        */
1153             /*   � � � � �   � � � � �   nur zum   � � � � �   � � � � �   � � � � �   � � � � �        */
1154             /*   � � � � �   � � � � �   Teil:     � � � � �   � � � � �   � � � � �   � � � � �        */
1155             /* 3.3: Die Linienaustritte zeigen vom anderen Objekt weg bzw. hinter                       */
1156             /*      dessen Ruecken vorbei (52+4).                                                       */
1157             /*   � � � � �   � � � � �   � � � � �   � � � � �   Diese 4   � � � � �   � � � � �        */
1158             /*   � � � � �   � � � � �   � � � � �   � � � � �   Konstel.  � � � � �   � � � � �        */
1159             /*   � � � � �   � � � � �   � � � � �   � � � � �   jedoch    � � � � �   � � � � �        */
1160             /*   � � � � �   � � � � �   � � � � �   � � � � �   nur zum   � � � � �   � � � � �        */
1161             /*   � � � � �   � � � � �   � � � � �   � � � � �   Teil:     � � � � �   � � � � �        */
1162 
1163             // Fall 3.2
1164             Rectangle aTmpR1(aBewareRect1);
1165             Rectangle aTmpR2(aBewareRect2);
1166             if (bBewareOverlap) {
1167                 // Ueberschneidung der BewareRects: BoundRects fuer Check auf Fall 3.2 verwenden.
1168                 aTmpR1=aBoundRect1;
1169                 aTmpR2=aBoundRect2;
1170             }
1171             if ((((bRts1 && aTmpR1.Right ()<=aPt2.X()) || (bLks1 && aTmpR1.Left()>=aPt2.X())) &&
1172                  ((bUnt2 && aTmpR2.Bottom()<=aPt1.Y()) || (bObn2 && aTmpR2.Top ()>=aPt1.Y()))) ||
1173                 (((bRts2 && aTmpR2.Right ()<=aPt1.X()) || (bLks2 && aTmpR2.Left()>=aPt1.X())) &&
1174                  ((bUnt1 && aTmpR1.Bottom()<=aPt2.Y()) || (bObn1 && aTmpR1.Top ()>=aPt2.Y())))) {
1175                 // Fall 3.2 trifft zu: Verbindung mit lediglich 2 Linien
1176                 bForceMeeting=sal_True;
1177                 bMeetingXMid=sal_False;
1178                 bMeetingYMid=sal_False;
1179                 if (bHor1) {
1180                     aMeeting.X()=aPt2.X();
1181                     aMeeting.Y()=aPt1.Y();
1182                 } else {
1183                     aMeeting.X()=aPt1.X();
1184                     aMeeting.Y()=aPt2.Y();
1185                 }
1186                 // Falls Ueberschneidung der BewareRects:
1187                 aBewareRect1=aTmpR1;
1188                 aBewareRect2=aTmpR2;
1189             } else if ((((bRts1 && aBewareRect1.Right ()>aBewareRect2.Left  ()) ||
1190                          (bLks1 && aBewareRect1.Left  ()<aBewareRect2.Right ())) &&
1191                         ((bUnt2 && aBewareRect2.Bottom()>aBewareRect1.Top   ()) ||
1192                          (bObn2 && aBewareRect2.Top   ()<aBewareRect1.Bottom()))) ||
1193                        (((bRts2 && aBewareRect2.Right ()>aBewareRect1.Left  ()) ||
1194                          (bLks2 && aBewareRect2.Left  ()<aBewareRect1.Right ())) &&
1195                         ((bUnt1 && aBewareRect1.Bottom()>aBewareRect2.Top   ()) ||
1196                          (bObn1 && aBewareRect1.Top   ()<aBewareRect2.Bottom())))) {
1197                 // Fall 3.3
1198                 bForceMeeting=sal_True;
1199                 if (bRts1 || bRts2) { aMeeting.X()=nXMax; bMeetingXMid=sal_False; }
1200                 if (bLks1 || bLks2) { aMeeting.X()=nXMin; bMeetingXMid=sal_False; }
1201                 if (bUnt1 || bUnt2) { aMeeting.Y()=nYMax; bMeetingYMid=sal_False; }
1202                 if (bObn1 || bObn2) { aMeeting.Y()=nYMin; bMeetingYMid=sal_False; }
1203             }
1204         }
1205     }
1206 
1207     XPolygon aXP1(ImpCalcObjToCenter(aPt1,nAngle1,aBewareRect1,aMeeting));
1208     XPolygon aXP2(ImpCalcObjToCenter(aPt2,nAngle2,aBewareRect2,aMeeting));
1209     sal_uInt16 nXP1Anz=aXP1.GetPointCount();
1210     sal_uInt16 nXP2Anz=aXP2.GetPointCount();
1211     if (bInfo) {
1212         pInfo->nObj1Lines=nXP1Anz; if (nXP1Anz>1) pInfo->nObj1Lines--;
1213         pInfo->nObj2Lines=nXP2Anz; if (nXP2Anz>1) pInfo->nObj2Lines--;
1214     }
1215     Point aEP1(aXP1[nXP1Anz-1]);
1216     Point aEP2(aXP2[nXP2Anz-1]);
1217     FASTBOOL bInsMeetingPoint=aEP1.X()!=aEP2.X() && aEP1.Y()!=aEP2.Y();
1218     FASTBOOL bHorzE1=aEP1.Y()==aXP1[nXP1Anz-2].Y(); // letzte Linie von XP1 horizontal?
1219     FASTBOOL bHorzE2=aEP2.Y()==aXP2[nXP2Anz-2].Y(); // letzte Linie von XP2 horizontal?
1220     if (aEP1==aEP2 && (bHorzE1 && bHorzE2 && aEP1.Y()==aEP2.Y()) || (!bHorzE1 && !bHorzE2 && aEP1.X()==aEP2.X())) {
1221         // Sonderbehandlung fuer 'I'-Verbinder
1222         nXP1Anz--; aXP1.Remove(nXP1Anz,1);
1223         nXP2Anz--; aXP2.Remove(nXP2Anz,1);
1224         bMeetingXMid=sal_False;
1225         bMeetingYMid=sal_False;
1226     }
1227     if (bInsMeetingPoint) {
1228         aXP1.Insert(XPOLY_APPEND,aMeeting,XPOLY_NORMAL);
1229         if (bInfo) {
1230             // Durch einfuegen des MeetingPoints kommen 2 weitere Linie hinzu.
1231             // Evtl. wird eine von diesen die Mittellinie.
1232             if (pInfo->nObj1Lines==pInfo->nObj2Lines) {
1233                 pInfo->nObj1Lines++;
1234                 pInfo->nObj2Lines++;
1235             } else {
1236                 if (pInfo->nObj1Lines>pInfo->nObj2Lines) {
1237                     pInfo->nObj2Lines++;
1238                     pInfo->nMiddleLine=nXP1Anz-1;
1239                 } else {
1240                     pInfo->nObj1Lines++;
1241                     pInfo->nMiddleLine=nXP1Anz;
1242                 }
1243             }
1244         }
1245     } else if (bInfo && aEP1!=aEP2 && nXP1Anz+nXP2Anz>=4) {
1246         // Durch Verbinden der beiden Enden kommt eine weitere Linie hinzu.
1247         // Dies wird die Mittellinie.
1248         pInfo->nMiddleLine=nXP1Anz-1;
1249     }
1250     sal_uInt16 nNum=aXP2.GetPointCount();
1251     if (aXP1[nXP1Anz-1]==aXP2[nXP2Anz-1] && nXP1Anz>1 && nXP2Anz>1) nNum--;
1252     while (nNum>0) {
1253         nNum--;
1254         aXP1.Insert(XPOLY_APPEND,aXP2[nNum],XPOLY_NORMAL);
1255     }
1256     sal_uInt16 nPntAnz=aXP1.GetPointCount();
1257     char cForm=0;
1258     if (bInfo || pnQuality!=NULL) {
1259         cForm='?';
1260         if (nPntAnz==2) cForm='I';
1261         else if (nPntAnz==3) cForm='L';
1262         else if (nPntAnz==4) { // Z oder U
1263             if (nAngle1==nAngle2) cForm='U';
1264             else cForm='Z';
1265         } else if (nPntAnz==4) { /* �-�  �-�  */
1266             /* ...                 -�     -�  */
1267         } else if (nPntAnz==6) { // S oder C oder ...
1268             if (nAngle1!=nAngle2) {
1269                 // Fuer Typ S hat Linie2 dieselbe Richtung wie Linie4.
1270                 // Bei Typ C sind die beiden genau entgegengesetzt.
1271                 Point aP1(aXP1[1]);
1272                 Point aP2(aXP1[2]);
1273                 Point aP3(aXP1[3]);
1274                 Point aP4(aXP1[4]);
1275                 if (aP1.Y()==aP2.Y()) { // beide Linien Horz
1276                     if ((aP1.X()<aP2.X())==(aP3.X()<aP4.X())) cForm='S';
1277                     else cForm='C';
1278                 } else { // sonst beide Linien Vert
1279                     if ((aP1.Y()<aP2.Y())==(aP3.Y()<aP4.Y())) cForm='S';
1280                     else cForm='C';
1281                 }
1282             } else cForm='4'; // sonst der 3. Fall mit 5 Linien
1283         } else cForm='?';  //
1284         // Weitere Formen:
1285         if (bInfo) {
1286             pInfo->cOrthoForm=cForm;
1287             if (cForm=='I' || cForm=='L' || cForm=='Z' || cForm=='U') {
1288                 pInfo->nObj1Lines=1;
1289                 pInfo->nObj2Lines=1;
1290                 if (cForm=='Z' || cForm=='U') {
1291                     pInfo->nMiddleLine=1;
1292                 } else {
1293                     pInfo->nMiddleLine=0xFFFF;
1294                 }
1295             } else if (cForm=='S' || cForm=='C') {
1296                 pInfo->nObj1Lines=2;
1297                 pInfo->nObj2Lines=2;
1298                 pInfo->nMiddleLine=2;
1299             }
1300         }
1301     }
1302     if (pnQuality!=NULL) {
1303         sal_uIntPtr nQual=0;
1304         sal_uIntPtr nQual0=nQual; // Ueberlaeufe vorbeugen
1305         FASTBOOL bOverflow=sal_False;
1306         Point aPt0(aXP1[0]);
1307         for (sal_uInt16 nPntNum=1; nPntNum<nPntAnz; nPntNum++) {
1308             Point aPt1b(aXP1[nPntNum]);
1309             nQual+=Abs(aPt1b.X()-aPt0.X())+Abs(aPt1b.Y()-aPt0.Y());
1310             if (nQual<nQual0) bOverflow=sal_True;
1311             nQual0=nQual;
1312             aPt0=aPt1b;
1313         }
1314 
1315         sal_uInt16 nTmp=nPntAnz;
1316         if (cForm=='Z') {
1317             nTmp=2; // Z-Form hat gute Qualitaet (nTmp=2 statt 4)
1318             sal_uIntPtr n1=Abs(aXP1[1].X()-aXP1[0].X())+Abs(aXP1[1].Y()-aXP1[0].Y());
1319             sal_uIntPtr n2=Abs(aXP1[2].X()-aXP1[1].X())+Abs(aXP1[2].Y()-aXP1[1].Y());
1320             sal_uIntPtr n3=Abs(aXP1[3].X()-aXP1[2].X())+Abs(aXP1[3].Y()-aXP1[2].Y());
1321             // fuer moeglichst gleichlange Linien sorgen
1322             sal_uIntPtr nBesser=0;
1323             n1+=n3;
1324             n3=n2/4;
1325             if (n1>=n2) nBesser=6;
1326             else if (n1>=3*n3) nBesser=4;
1327             else if (n1>=2*n3) nBesser=2;
1328             if (aXP1[0].Y()!=aXP1[1].Y()) nBesser++; // Senkrechte Startlinie kriegt auch noch einen Pluspunkt (fuer H/V-Prio)
1329             if (nQual>nBesser) nQual-=nBesser; else nQual=0;
1330         }
1331         if (nTmp>=3) {
1332             nQual0=nQual;
1333             nQual+=(sal_uIntPtr)nTmp*0x01000000;
1334             if (nQual<nQual0 || nTmp>15) bOverflow=sal_True;
1335         }
1336         if (nPntAnz>=2) { // Austrittswinkel nochmal pruefen
1337             Point aP1(aXP1[1]); aP1-=aXP1[0];
1338             Point aP2(aXP1[nPntAnz-2]); aP2-=aXP1[nPntAnz-1];
1339             long nAng1=0; if (aP1.X()<0) nAng1=18000; if (aP1.Y()>0) nAng1=27000;
1340             if (aP1.Y()<0) nAng1=9000; if (aP1.X()!=0 && aP1.Y()!=0) nAng1=1; // Schraeg!?!
1341             long nAng2=0; if (aP2.X()<0) nAng2=18000; if (aP2.Y()>0) nAng2=27000;
1342             if (aP2.Y()<0) nAng2=9000; if (aP2.X()!=0 && aP2.Y()!=0) nAng2=1; // Schraeg!?!
1343             if (nAng1!=nAngle1) nIntersections++;
1344             if (nAng2!=nAngle2) nIntersections++;
1345         }
1346 
1347         // Fuer den Qualitaetscheck wieder die Original-Rects verwenden und
1348         // gleichzeitig checken, ob eins fuer die Edge-Berechnung verkleinert
1349         // wurde (z.B. Fall 2.9)
1350         aBewareRect1=rBewareRect1;
1351         aBewareRect2=rBewareRect2;
1352 
1353         for (sal_uInt16 i=0; i<nPntAnz; i++) {
1354             Point aPt1b(aXP1[i]);
1355             FASTBOOL b1=aPt1b.X()>aBewareRect1.Left() && aPt1b.X()<aBewareRect1.Right() &&
1356                         aPt1b.Y()>aBewareRect1.Top() && aPt1b.Y()<aBewareRect1.Bottom();
1357             FASTBOOL b2=aPt1b.X()>aBewareRect2.Left() && aPt1b.X()<aBewareRect2.Right() &&
1358                         aPt1b.Y()>aBewareRect2.Top() && aPt1b.Y()<aBewareRect2.Bottom();
1359             sal_uInt16 nInt0=nIntersections;
1360             if (i==0 || i==nPntAnz-1) {
1361                 if (b1 && b2) nIntersections++;
1362             } else {
1363                 if (b1) nIntersections++;
1364                 if (b2) nIntersections++;
1365             }
1366             // und nun noch auf Ueberschneidungen checken
1367             if (i>0 && nInt0==nIntersections) {
1368                 if (aPt0.Y()==aPt1b.Y()) { // Horizontale Linie
1369                     if (aPt0.Y()>aBewareRect1.Top() && aPt0.Y()<aBewareRect1.Bottom() &&
1370                         ((aPt0.X()<=aBewareRect1.Left() && aPt1b.X()>=aBewareRect1.Right()) ||
1371                          (aPt1b.X()<=aBewareRect1.Left() && aPt0.X()>=aBewareRect1.Right()))) nIntersections++;
1372                     if (aPt0.Y()>aBewareRect2.Top() && aPt0.Y()<aBewareRect2.Bottom() &&
1373                         ((aPt0.X()<=aBewareRect2.Left() && aPt1b.X()>=aBewareRect2.Right()) ||
1374                          (aPt1b.X()<=aBewareRect2.Left() && aPt0.X()>=aBewareRect2.Right()))) nIntersections++;
1375                 } else { // Vertikale Linie
1376                     if (aPt0.X()>aBewareRect1.Left() && aPt0.X()<aBewareRect1.Right() &&
1377                         ((aPt0.Y()<=aBewareRect1.Top() && aPt1b.Y()>=aBewareRect1.Bottom()) ||
1378                          (aPt1b.Y()<=aBewareRect1.Top() && aPt0.Y()>=aBewareRect1.Bottom()))) nIntersections++;
1379                     if (aPt0.X()>aBewareRect2.Left() && aPt0.X()<aBewareRect2.Right() &&
1380                         ((aPt0.Y()<=aBewareRect2.Top() && aPt1b.Y()>=aBewareRect2.Bottom()) ||
1381                          (aPt1b.Y()<=aBewareRect2.Top() && aPt0.Y()>=aBewareRect2.Bottom()))) nIntersections++;
1382                 }
1383             }
1384             aPt0=aPt1b;
1385         }
1386         if (nPntAnz<=1) nIntersections++;
1387         nQual0=nQual;
1388         nQual+=(sal_uIntPtr)nIntersections*0x10000000;
1389         if (nQual<nQual0 || nIntersections>15) bOverflow=sal_True;
1390 
1391         if (bOverflow || nQual==0xFFFFFFFF) nQual=0xFFFFFFFE;
1392         *pnQuality=nQual;
1393     }
1394     if (bInfo) { // nun die Linienversaetze auf aXP1 anwenden
1395         if (pInfo->nMiddleLine!=0xFFFF) {
1396             sal_uInt16 nIdx=pInfo->ImpGetPolyIdx(MIDDLELINE,aXP1);
1397             if (pInfo->ImpIsHorzLine(MIDDLELINE,aXP1)) {
1398                 aXP1[nIdx].Y()+=pInfo->aMiddleLine.Y();
1399                 aXP1[nIdx+1].Y()+=pInfo->aMiddleLine.Y();
1400             } else {
1401                 aXP1[nIdx].X()+=pInfo->aMiddleLine.X();
1402                 aXP1[nIdx+1].X()+=pInfo->aMiddleLine.X();
1403             }
1404         }
1405         if (pInfo->nObj1Lines>=2) {
1406             sal_uInt16 nIdx=pInfo->ImpGetPolyIdx(OBJ1LINE2,aXP1);
1407             if (pInfo->ImpIsHorzLine(OBJ1LINE2,aXP1)) {
1408                 aXP1[nIdx].Y()+=pInfo->aObj1Line2.Y();
1409                 aXP1[nIdx+1].Y()+=pInfo->aObj1Line2.Y();
1410             } else {
1411                 aXP1[nIdx].X()+=pInfo->aObj1Line2.X();
1412                 aXP1[nIdx+1].X()+=pInfo->aObj1Line2.X();
1413             }
1414         }
1415         if (pInfo->nObj1Lines>=3) {
1416             sal_uInt16 nIdx=pInfo->ImpGetPolyIdx(OBJ1LINE3,aXP1);
1417             if (pInfo->ImpIsHorzLine(OBJ1LINE3,aXP1)) {
1418                 aXP1[nIdx].Y()+=pInfo->aObj1Line3.Y();
1419                 aXP1[nIdx+1].Y()+=pInfo->aObj1Line3.Y();
1420             } else {
1421                 aXP1[nIdx].X()+=pInfo->aObj1Line3.X();
1422                 aXP1[nIdx+1].X()+=pInfo->aObj1Line3.X();
1423             }
1424         }
1425         if (pInfo->nObj2Lines>=2) {
1426             sal_uInt16 nIdx=pInfo->ImpGetPolyIdx(OBJ2LINE2,aXP1);
1427             if (pInfo->ImpIsHorzLine(OBJ2LINE2,aXP1)) {
1428                 aXP1[nIdx].Y()+=pInfo->aObj2Line2.Y();
1429                 aXP1[nIdx+1].Y()+=pInfo->aObj2Line2.Y();
1430             } else {
1431                 aXP1[nIdx].X()+=pInfo->aObj2Line2.X();
1432                 aXP1[nIdx+1].X()+=pInfo->aObj2Line2.X();
1433             }
1434         }
1435         if (pInfo->nObj2Lines>=3) {
1436             sal_uInt16 nIdx=pInfo->ImpGetPolyIdx(OBJ2LINE3,aXP1);
1437             if (pInfo->ImpIsHorzLine(OBJ2LINE3,aXP1)) {
1438                 aXP1[nIdx].Y()+=pInfo->aObj2Line3.Y();
1439                 aXP1[nIdx+1].Y()+=pInfo->aObj2Line3.Y();
1440             } else {
1441                 aXP1[nIdx].X()+=pInfo->aObj2Line3.X();
1442                 aXP1[nIdx+1].X()+=pInfo->aObj2Line3.X();
1443             }
1444         }
1445     }
1446     // Nun mache ich ggf. aus dem Verbinder eine Bezierkurve
1447     if (eKind==SDREDGE_BEZIER && nPntAnz>2) {
1448         Point* pPt1=&aXP1[0];
1449         Point* pPt2=&aXP1[1];
1450         Point* pPt3=&aXP1[nPntAnz-2];
1451         Point* pPt4=&aXP1[nPntAnz-1];
1452         long dx1=pPt2->X()-pPt1->X();
1453         long dy1=pPt2->Y()-pPt1->Y();
1454         long dx2=pPt3->X()-pPt4->X();
1455         long dy2=pPt3->Y()-pPt4->Y();
1456         if (cForm=='L') { // nPntAnz==3
1457             aXP1.SetFlags(1,XPOLY_CONTROL);
1458             Point aPt3(*pPt2);
1459             aXP1.Insert(2,aPt3,XPOLY_CONTROL);
1460             nPntAnz=aXP1.GetPointCount();
1461             pPt1=&aXP1[0];
1462             pPt2=&aXP1[1];
1463             pPt3=&aXP1[nPntAnz-2];
1464             pPt4=&aXP1[nPntAnz-1];
1465             pPt2->X()-=dx1/3;
1466             pPt2->Y()-=dy1/3;
1467             pPt3->X()-=dx2/3;
1468             pPt3->Y()-=dy2/3;
1469         } else if (nPntAnz>=4 && nPntAnz<=6) { // Z oder U oder ...
1470             // fuer Alle Anderen werden die Endpunkte der Ausgangslinien
1471             // erstmal zu Kontrollpunkten. Bei nPntAnz>4 ist also noch
1472             // Nacharbeit erforderlich!
1473             aXP1.SetFlags(1,XPOLY_CONTROL);
1474             aXP1.SetFlags(nPntAnz-2,XPOLY_CONTROL);
1475             // Distanz x1.5
1476             pPt2->X()+=dx1/2;
1477             pPt2->Y()+=dy1/2;
1478             pPt3->X()+=dx2/2;
1479             pPt3->Y()+=dy2/2;
1480             if (nPntAnz==5) {
1481                 // Vor und hinter dem Mittelpunkt jeweils
1482                 // noch einen Kontrollpunkt einfuegen
1483                 Point aCenter(aXP1[2]);
1484                 long dx1b=aCenter.X()-aXP1[1].X();
1485                 long dy1b=aCenter.Y()-aXP1[1].Y();
1486                 long dx2b=aCenter.X()-aXP1[3].X();
1487                 long dy2b=aCenter.Y()-aXP1[3].Y();
1488                 aXP1.Insert(2,aCenter,XPOLY_CONTROL);
1489                 aXP1.SetFlags(3,XPOLY_SYMMTR);
1490                 aXP1.Insert(4,aCenter,XPOLY_CONTROL);
1491                 aXP1[2].X()-=dx1b/2;
1492                 aXP1[2].Y()-=dy1b/2;
1493                 aXP1[3].X()-=(dx1b+dx2b)/4;
1494                 aXP1[3].Y()-=(dy1b+dy2b)/4;
1495                 aXP1[4].X()-=dx2b/2;
1496                 aXP1[4].Y()-=dy2b/2;
1497             }
1498             if (nPntAnz==6) {
1499                 Point aPt1b(aXP1[2]);
1500                 Point aPt2b(aXP1[3]);
1501                 aXP1.Insert(2,aPt1b,XPOLY_CONTROL);
1502                 aXP1.Insert(5,aPt2b,XPOLY_CONTROL);
1503                 long dx=aPt1b.X()-aPt2b.X();
1504                 long dy=aPt1b.Y()-aPt2b.Y();
1505                 aXP1[3].X()-=dx/2;
1506                 aXP1[3].Y()-=dy/2;
1507                 aXP1.SetFlags(3,XPOLY_SYMMTR);
1508                 //aXP1[4].X()+=dx/2;
1509                 //aXP1[4].Y()+=dy/2;
1510                 aXP1.Remove(4,1); // weil identisch mit aXP1[3]
1511             }
1512         }
1513     }
1514     return aXP1;
1515 }
1516 
1517 /*
1518 Nach einer einfachen Rechnung koennte es max. 64 unterschiedliche Verlaeufe mit
1519 5 Linien, 32 mit 4 Linien, 16 mit 3, 8 mit 2 Linien und 4 mit 1 Linie geben=124.
1520 Normalisiert auf 1. Austrittswinkel nach rechts bleiben dann noch 31.
1521 Dann noch eine vertikale Spiegelung wegnormalisiert bleiben noch 16
1522 characteristische Verlaufszuege mit 1-5 Linien:
1523 Mit 1 Linie (Typ 'I'):  --
1524 Mit 2 Linien (Typ 'L'): -�
1525 Mit 3 Linien (Typ 'U'):  -�  (Typ 'Z'):  �-
1526                          -�             -�
1527 Mit 4 Linien: 1 ist nicht plausibel, 3 ist=2 (90deg Drehung). Verbleibt 2,4
1528      �-�  ڿ  ��  ڿ                               ڿ  �-�
1529     -�   -�   -�  -�                              -�    -�
1530 Mit 5 Linien: nicht plausibel sind 1,2,4,5. 7 ist identisch mit 3 (Richtungsumkehr)
1531               Bleibt also 3,6 und 8.              '4'  'S'  'C'
1532        �    �             -�   �-  �-�                  �-
1533      �-�  �-�  �-�   �-�   ��  �� -� � �-�         �-�  ��  �-�
1534     -�   -�   -� �  -� �-  -�  -�  --� � �        -� �  -�  � �
1535 Insgesamt sind also 9 Grundtypen zu unterscheiden die den 400 Konstellationen
1536 aus Objektposition und Austrittswinkeln zuzuordnen sind.
1537 4 der 9 Grundtypen haben eine 'Mittellinie'. Die Anzahl der zu Objektabstaende
1538 je Objekt variiert von 0-3:
1539      Mi   O1   O2   Anmerkung
1540 'I':  n   0    0
1541 'L':  n   0    0
1542 'U':  n  0-1  0-1
1543 'Z':  j   0    0
1544 4.1:  j   0    1    = U+1 bzw. 1+U
1545 4.2:  n  0-2  0-2   = Z+1
1546 '4':  j   0    2    = Z+2
1547 'S':  j   1    1    = 1+Z+1
1548 'C':  n  0-3  0-3   = 1+U+1
1549 */
1550 
1551 void __EXPORT SdrEdgeObj::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
1552 {
1553     SfxSimpleHint* pSimple=PTR_CAST(SfxSimpleHint,&rHint);
1554     sal_uIntPtr nId=pSimple==0 ? 0 : pSimple->GetId();
1555     FASTBOOL bDataChg=nId==SFX_HINT_DATACHANGED;
1556     FASTBOOL bDying=nId==SFX_HINT_DYING;
1557     FASTBOOL bObj1=aCon1.pObj!=NULL && aCon1.pObj->GetBroadcaster()==&rBC;
1558     FASTBOOL bObj2=aCon2.pObj!=NULL && aCon2.pObj->GetBroadcaster()==&rBC;
1559     if (bDying && (bObj1 || bObj2)) {
1560         // #35605# Dying vorher abfangen, damit AttrObj nicht
1561         // wg. vermeintlicher Vorlagenaenderung rumbroadcastet
1562         if (bObj1) aCon1.pObj=NULL;
1563         if (bObj2) aCon2.pObj=NULL;
1564         return; // Und mehr braucht hier nicht getan werden.
1565     }
1566     if ( bObj1 || bObj2 )
1567     {
1568         bEdgeTrackUserDefined = sal_False;
1569     }
1570     SdrTextObj::Notify(rBC,rHint);
1571     if (nNotifyingCount==0) { // Hier nun auch ein VerriegelungsFlag
1572         ((SdrEdgeObj*)this)->nNotifyingCount++;
1573         SdrHint* pSdrHint=PTR_CAST(SdrHint,&rHint);
1574         if (bDataChg) { // StyleSheet geaendert
1575             ImpSetAttrToEdgeInfo(); // Werte bei Vorlagenaenderung vom Pool nach aEdgeInfo kopieren
1576         }
1577         if (bDataChg                                ||
1578             (bObj1 && aCon1.pObj->GetPage()==pPage) ||
1579             (bObj2 && aCon2.pObj->GetPage()==pPage) ||
1580             (pSdrHint && pSdrHint->GetKind()==HINT_OBJREMOVED))
1581         {
1582             // Broadcasting nur, wenn auf der selben Page
1583             Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetCurrentBoundRect();
1584             // #110094#-14 if (!bEdgeTrackDirty) SendRepaintBroadcast();
1585             ImpDirtyEdgeTrack();
1586 
1587             // only redraw here, no objectchange
1588             ActionChanged();
1589             // BroadcastObjectChange();
1590 
1591             SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
1592         }
1593         ((SdrEdgeObj*)this)->nNotifyingCount--;
1594     }
1595 }
1596 
1597 /** updates edges that are connected to the edges of this object
1598     as if the connected objects send a repaint broadcast
1599     #103122#
1600 */
1601 void SdrEdgeObj::Reformat()
1602 {
1603     if( NULL != aCon1.pObj )
1604     {
1605         SfxSimpleHint aHint( SFX_HINT_DATACHANGED );
1606         Notify( *const_cast<SfxBroadcaster*>(aCon1.pObj->GetBroadcaster()), aHint );
1607     }
1608 
1609     if( NULL != aCon2.pObj )
1610     {
1611         SfxSimpleHint aHint( SFX_HINT_DATACHANGED );
1612         Notify( *const_cast<SfxBroadcaster*>(aCon2.pObj->GetBroadcaster()), aHint );
1613     }
1614 }
1615 
1616 void SdrEdgeObj::operator=(const SdrObject& rObj)
1617 {
1618     SdrTextObj::operator=(rObj);
1619     *pEdgeTrack    =*((SdrEdgeObj&)rObj).pEdgeTrack;
1620     bEdgeTrackDirty=((SdrEdgeObj&)rObj).bEdgeTrackDirty;
1621     aCon1          =((SdrEdgeObj&)rObj).aCon1;
1622     aCon2          =((SdrEdgeObj&)rObj).aCon2;
1623     aCon1.pObj=NULL;
1624     aCon2.pObj=NULL;
1625     aEdgeInfo=((SdrEdgeObj&)rObj).aEdgeInfo;
1626 }
1627 
1628 void SdrEdgeObj::TakeObjNameSingul(XubString& rName) const
1629 {
1630     rName=ImpGetResStr(STR_ObjNameSingulEDGE);
1631 
1632     String aName( GetName() );
1633     if(aName.Len())
1634     {
1635         rName += sal_Unicode(' ');
1636         rName += sal_Unicode('\'');
1637         rName += aName;
1638         rName += sal_Unicode('\'');
1639     }
1640 }
1641 
1642 void SdrEdgeObj::TakeObjNamePlural(XubString& rName) const
1643 {
1644     rName=ImpGetResStr(STR_ObjNamePluralEDGE);
1645 }
1646 
1647 basegfx::B2DPolyPolygon SdrEdgeObj::TakeXorPoly() const
1648 {
1649     basegfx::B2DPolyPolygon aPolyPolygon;
1650 
1651     if (bEdgeTrackDirty)
1652     {
1653         ((SdrEdgeObj*)this)->ImpRecalcEdgeTrack();
1654     }
1655 
1656     if(pEdgeTrack)
1657     {
1658         aPolyPolygon.append(pEdgeTrack->getB2DPolygon());
1659     }
1660 
1661     return aPolyPolygon;
1662 }
1663 
1664 void SdrEdgeObj::SetEdgeTrackPath( const basegfx::B2DPolyPolygon& rPoly )
1665 {
1666     if ( !rPoly.count() )
1667     {
1668         bEdgeTrackDirty = sal_True;
1669         bEdgeTrackUserDefined = sal_False;
1670     }
1671     else
1672     {
1673         *pEdgeTrack = XPolygon( rPoly.getB2DPolygon( 0 ) );
1674         bEdgeTrackDirty = sal_False;
1675         bEdgeTrackUserDefined = sal_True;
1676 
1677         // #i110629# also set aRect and maSnapeRect dependent from pEdgeTrack
1678         const Rectangle aPolygonBounds(pEdgeTrack->GetBoundRect());
1679         aRect = aPolygonBounds;
1680         maSnapRect = aPolygonBounds;
1681     }
1682 }
1683 
1684 basegfx::B2DPolyPolygon SdrEdgeObj::GetEdgeTrackPath() const
1685 {
1686     basegfx::B2DPolyPolygon aPolyPolygon;
1687 
1688     if (bEdgeTrackDirty)
1689         ((SdrEdgeObj*)this)->ImpRecalcEdgeTrack();
1690 
1691     aPolyPolygon.append( pEdgeTrack->getB2DPolygon() );
1692 
1693     return aPolyPolygon;
1694 }
1695 
1696 sal_uInt32 SdrEdgeObj::GetHdlCount() const
1697 {
1698     SdrEdgeKind eKind=((SdrEdgeKindItem&)(GetObjectItem(SDRATTR_EDGEKIND))).GetValue();
1699     sal_uInt32 nHdlAnz(0L);
1700     sal_uInt32 nPntAnz(pEdgeTrack->GetPointCount());
1701 
1702     if(nPntAnz)
1703     {
1704         nHdlAnz = 2L;
1705 
1706         if ((eKind==SDREDGE_ORTHOLINES || eKind==SDREDGE_BEZIER) && nPntAnz >= 4L)
1707         {
1708             sal_uInt32 nO1(aEdgeInfo.nObj1Lines > 0L ? aEdgeInfo.nObj1Lines - 1L : 0L);
1709             sal_uInt32 nO2(aEdgeInfo.nObj2Lines > 0L ? aEdgeInfo.nObj2Lines - 1L : 0L);
1710             sal_uInt32 nM(aEdgeInfo.nMiddleLine != 0xFFFF ? 1L : 0L);
1711             nHdlAnz += nO1 + nO2 + nM;
1712         }
1713         else if (eKind==SDREDGE_THREELINES && nPntAnz == 4L)
1714         {
1715             if(GetConnectedNode(sal_True))
1716                 nHdlAnz++;
1717 
1718             if(GetConnectedNode(sal_False))
1719                 nHdlAnz++;
1720         }
1721     }
1722 
1723     return nHdlAnz;
1724 }
1725 
1726 SdrHdl* SdrEdgeObj::GetHdl(sal_uInt32 nHdlNum) const
1727 {
1728     SdrHdl* pHdl=NULL;
1729     sal_uInt32 nPntAnz(pEdgeTrack->GetPointCount());
1730     if (nPntAnz!=0) {
1731         if (nHdlNum==0) {
1732             pHdl=new ImpEdgeHdl((*pEdgeTrack)[0],HDL_POLY);
1733             if (aCon1.pObj!=NULL && aCon1.bBestVertex) pHdl->Set1PixMore(sal_True);
1734         } else if (nHdlNum==1) {
1735             pHdl=new ImpEdgeHdl((*pEdgeTrack)[sal_uInt16(nPntAnz-1)],HDL_POLY);
1736             if (aCon2.pObj!=NULL && aCon2.bBestVertex) pHdl->Set1PixMore(sal_True);
1737         } else {
1738             SdrEdgeKind eKind=((SdrEdgeKindItem&)(GetObjectItem(SDRATTR_EDGEKIND))).GetValue();
1739             if (eKind==SDREDGE_ORTHOLINES || eKind==SDREDGE_BEZIER) {
1740                 sal_uInt32 nO1(aEdgeInfo.nObj1Lines > 0L ? aEdgeInfo.nObj1Lines - 1L : 0L);
1741                 sal_uInt32 nO2(aEdgeInfo.nObj2Lines > 0L ? aEdgeInfo.nObj2Lines - 1L : 0L);
1742                 sal_uInt32 nM(aEdgeInfo.nMiddleLine != 0xFFFF ? 1L : 0L);
1743                 sal_uInt32 nNum(nHdlNum - 2L);
1744                 sal_Int32 nPt(0L);
1745                 pHdl=new ImpEdgeHdl(Point(),HDL_POLY);
1746                 if (nNum<nO1) {
1747                     nPt=nNum+1L;
1748                     if (nNum==0) ((ImpEdgeHdl*)pHdl)->SetLineCode(OBJ1LINE2);
1749                     if (nNum==1) ((ImpEdgeHdl*)pHdl)->SetLineCode(OBJ1LINE3);
1750                 } else {
1751                     nNum=nNum-nO1;
1752                     if (nNum<nO2) {
1753                         nPt=nPntAnz-3-nNum;
1754                         if (nNum==0) ((ImpEdgeHdl*)pHdl)->SetLineCode(OBJ2LINE2);
1755                         if (nNum==1) ((ImpEdgeHdl*)pHdl)->SetLineCode(OBJ2LINE3);
1756                     } else {
1757                         nNum=nNum-nO2;
1758                         if (nNum<nM) {
1759                             nPt=aEdgeInfo.nMiddleLine;
1760                             ((ImpEdgeHdl*)pHdl)->SetLineCode(MIDDLELINE);
1761                         }
1762                     }
1763                 }
1764                 if (nPt>0) {
1765                     Point aPos((*pEdgeTrack)[(sal_uInt16)nPt]);
1766                     aPos+=(*pEdgeTrack)[(sal_uInt16)nPt+1];
1767                     aPos.X()/=2;
1768                     aPos.Y()/=2;
1769                     pHdl->SetPos(aPos);
1770                 } else {
1771                     delete pHdl;
1772                     pHdl=NULL;
1773                 }
1774             } else if (eKind==SDREDGE_THREELINES) {
1775                 sal_uInt32 nNum(nHdlNum);
1776                 if (GetConnectedNode(sal_True)==NULL) nNum++;
1777                 Point aPos((*pEdgeTrack)[(sal_uInt16)nNum-1]);
1778                 pHdl=new ImpEdgeHdl(aPos,HDL_POLY);
1779                 if (nNum==2) ((ImpEdgeHdl*)pHdl)->SetLineCode(OBJ1LINE2);
1780                 if (nNum==3) ((ImpEdgeHdl*)pHdl)->SetLineCode(OBJ2LINE2);
1781             }
1782         }
1783         if (pHdl!=NULL) {
1784             pHdl->SetPointNum(nHdlNum);
1785         }
1786     }
1787     return pHdl;
1788 }
1789 
1790 ////////////////////////////////////////////////////////////////////////////////////////////////////
1791 
1792 bool SdrEdgeObj::hasSpecialDrag() const
1793 {
1794     return true;
1795 }
1796 
1797 SdrObject* SdrEdgeObj::getFullDragClone() const
1798 {
1799     // use Clone operator
1800     SdrEdgeObj* pRetval = (SdrEdgeObj*)Clone();
1801 
1802     // copy connections for clone, SdrEdgeObj::operator= does not do this
1803     pRetval->ConnectToNode(true, GetConnectedNode(true));
1804     pRetval->ConnectToNode(false, GetConnectedNode(false));
1805 
1806     return pRetval;
1807 }
1808 
1809 bool SdrEdgeObj::beginSpecialDrag(SdrDragStat& rDrag) const
1810 {
1811     if(!rDrag.GetHdl())
1812         return false;
1813 
1814     rDrag.SetEndDragChangesAttributes(true);
1815 
1816     if(rDrag.GetHdl()->GetPointNum() < 2)
1817     {
1818         rDrag.SetNoSnap(true);
1819     }
1820 
1821     return true;
1822 }
1823 
1824 bool SdrEdgeObj::applySpecialDrag(SdrDragStat& rDragStat)
1825 {
1826     SdrEdgeObj* pOriginalEdge = dynamic_cast< SdrEdgeObj* >(rDragStat.GetHdl()->GetObj());
1827     const bool bOriginalEdgeModified(pOriginalEdge == this);
1828 
1829     if(!bOriginalEdgeModified && pOriginalEdge)
1830     {
1831         // copy connections when clone is modified. This is needed because
1832         // as preparation to this modification the data from the original object
1833         // was copied to the clone using the operator=. As can be seen there,
1834         // that operator does not copy the connections (for good reason)
1835         ConnectToNode(true, pOriginalEdge->GetConnection(true).GetObject());
1836         ConnectToNode(false, pOriginalEdge->GetConnection(false).GetObject());
1837     }
1838 
1839     if(rDragStat.GetHdl()->GetPointNum() < 2)
1840     {
1841         // start or end point connector drag
1842         const bool bDragA(0 == rDragStat.GetHdl()->GetPointNum());
1843         const Point aPointNow(rDragStat.GetNow());
1844 
1845         if(rDragStat.GetPageView())
1846         {
1847             SdrObjConnection* pDraggedOne(bDragA ? &aCon1 : &aCon2);
1848 
1849             // clear connection
1850             DisconnectFromNode(bDragA);
1851 
1852             // look for new connection
1853             ImpFindConnector(aPointNow, *rDragStat.GetPageView(), *pDraggedOne, pOriginalEdge);
1854 
1855             if(pDraggedOne->pObj)
1856             {
1857                 // if found, officially connect to it; ImpFindConnector only
1858                 // sets pObj hard
1859                 SdrObject* pNewConnection = pDraggedOne->pObj;
1860                 pDraggedOne->pObj = 0;
1861                 ConnectToNode(bDragA, pNewConnection);
1862             }
1863 
1864             if(rDragStat.GetView() && !bOriginalEdgeModified)
1865             {
1866                 // show IA helper, but only do this during IA, so not when the original
1867                 // Edge gets modified in the last call
1868                 rDragStat.GetView()->SetConnectMarker(*pDraggedOne, *rDragStat.GetPageView());
1869             }
1870         }
1871 
1872         if(pEdgeTrack)
1873         {
1874             // change pEdgeTrack to modified position
1875             if(bDragA)
1876             {
1877                 (*pEdgeTrack)[0] = aPointNow;
1878             }
1879             else
1880             {
1881                 (*pEdgeTrack)[sal_uInt16(pEdgeTrack->GetPointCount()-1)] = aPointNow;
1882             }
1883         }
1884 
1885         // reset edge info's offsets, this is a end point drag
1886         aEdgeInfo.aObj1Line2 = Point();
1887         aEdgeInfo.aObj1Line3 = Point();
1888         aEdgeInfo.aObj2Line2 = Point();
1889         aEdgeInfo.aObj2Line3 = Point();
1890         aEdgeInfo.aMiddleLine = Point();
1891     }
1892     else
1893     {
1894         // control point connector drag
1895         const ImpEdgeHdl* pEdgeHdl = (ImpEdgeHdl*)rDragStat.GetHdl();
1896         const SdrEdgeLineCode eLineCode = pEdgeHdl->GetLineCode();
1897         const Point aDist(rDragStat.GetNow() - rDragStat.GetStart());
1898         sal_Int32 nDist(pEdgeHdl->IsHorzDrag() ? aDist.X() : aDist.Y());
1899 
1900         nDist += aEdgeInfo.ImpGetLineVersatz(eLineCode, *pEdgeTrack);
1901         aEdgeInfo.ImpSetLineVersatz(eLineCode, *pEdgeTrack, nDist);
1902     }
1903 
1904     // force recalc EdgeTrack
1905     *pEdgeTrack = ImpCalcEdgeTrack(*pEdgeTrack, aCon1, aCon2, &aEdgeInfo);
1906     bEdgeTrackDirty=sal_False;
1907 
1908     // save EdgeInfos and mark object as user modified
1909     ImpSetEdgeInfoToAttr();
1910     bEdgeTrackUserDefined = false;
1911     //SetRectsDirty();
1912     //SetChanged();
1913 
1914     if(bOriginalEdgeModified && rDragStat.GetView())
1915     {
1916         // hide connect marker helper again when original gets changed.
1917         // This happens at the end of the interaction
1918         rDragStat.GetView()->HideConnectMarker();
1919     }
1920 
1921     return true;
1922 }
1923 
1924 String SdrEdgeObj::getSpecialDragComment(const SdrDragStat& rDrag) const
1925 {
1926     const bool bCreateComment(rDrag.GetView() && this == rDrag.GetView()->GetCreateObj());
1927 
1928     if(bCreateComment)
1929     {
1930         return String();
1931     }
1932     else
1933     {
1934         XubString aStr;
1935         ImpTakeDescriptionStr(STR_DragEdgeTail, aStr);
1936 
1937         return aStr;
1938     }
1939 }
1940 
1941 ////////////////////////////////////////////////////////////////////////////////////////////////////
1942 
1943 basegfx::B2DPolygon SdrEdgeObj::ImplAddConnectorOverlay(SdrDragMethod& rDragMethod, bool bTail1, bool bTail2, bool bDetail) const
1944 {
1945     basegfx::B2DPolygon aResult;
1946 
1947     if(bDetail)
1948     {
1949         SdrObjConnection aMyCon1(aCon1);
1950         SdrObjConnection aMyCon2(aCon2);
1951 
1952         if (bTail1)
1953         {
1954             const basegfx::B2DPoint aTemp(rDragMethod.getCurrentTransformation() * basegfx::B2DPoint(aMyCon1.aObjOfs.X(), aMyCon1.aObjOfs.Y()));
1955             aMyCon1.aObjOfs.X() = basegfx::fround(aTemp.getX());
1956             aMyCon1.aObjOfs.Y() = basegfx::fround(aTemp.getY());
1957         }
1958 
1959         if (bTail2)
1960         {
1961             const basegfx::B2DPoint aTemp(rDragMethod.getCurrentTransformation() * basegfx::B2DPoint(aMyCon2.aObjOfs.X(), aMyCon2.aObjOfs.Y()));
1962             aMyCon2.aObjOfs.X() = basegfx::fround(aTemp.getX());
1963             aMyCon2.aObjOfs.Y() = basegfx::fround(aTemp.getY());
1964         }
1965 
1966         SdrEdgeInfoRec aInfo(aEdgeInfo);
1967         XPolygon aXP(ImpCalcEdgeTrack(*pEdgeTrack, aMyCon1, aMyCon2, &aInfo));
1968 
1969         if(aXP.GetPointCount())
1970         {
1971             aResult = aXP.getB2DPolygon();
1972         }
1973     }
1974     else
1975     {
1976         Point aPt1((*pEdgeTrack)[0]);
1977         Point aPt2((*pEdgeTrack)[sal_uInt16(pEdgeTrack->GetPointCount() - 1)]);
1978 
1979         if (aCon1.pObj && (aCon1.bBestConn || aCon1.bBestVertex))
1980             aPt1 = aCon1.pObj->GetSnapRect().Center();
1981 
1982         if (aCon2.pObj && (aCon2.bBestConn || aCon2.bBestVertex))
1983             aPt2 = aCon2.pObj->GetSnapRect().Center();
1984 
1985         if (bTail1)
1986         {
1987             const basegfx::B2DPoint aTemp(rDragMethod.getCurrentTransformation() * basegfx::B2DPoint(aPt1.X(), aPt1.Y()));
1988             aPt1.X() = basegfx::fround(aTemp.getX());
1989             aPt1.Y() = basegfx::fround(aTemp.getY());
1990         }
1991 
1992         if (bTail2)
1993         {
1994             const basegfx::B2DPoint aTemp(rDragMethod.getCurrentTransformation() * basegfx::B2DPoint(aPt2.X(), aPt2.Y()));
1995             aPt2.X() = basegfx::fround(aTemp.getX());
1996             aPt2.Y() = basegfx::fround(aTemp.getY());
1997         }
1998 
1999         aResult.append(basegfx::B2DPoint(aPt1.X(), aPt1.Y()));
2000         aResult.append(basegfx::B2DPoint(aPt2.X(), aPt2.Y()));
2001     }
2002 
2003     return aResult;
2004 }
2005 
2006 FASTBOOL SdrEdgeObj::BegCreate(SdrDragStat& rDragStat)
2007 {
2008     rDragStat.SetNoSnap(sal_True);
2009     pEdgeTrack->SetPointCount(2);
2010     (*pEdgeTrack)[0]=rDragStat.GetStart();
2011     (*pEdgeTrack)[1]=rDragStat.GetNow();
2012     if (rDragStat.GetPageView()!=NULL) {
2013         ImpFindConnector(rDragStat.GetStart(),*rDragStat.GetPageView(),aCon1,this);
2014         ConnectToNode(sal_True,aCon1.pObj);
2015     }
2016     *pEdgeTrack=ImpCalcEdgeTrack(*pEdgeTrack,aCon1,aCon2,&aEdgeInfo);
2017     return sal_True;
2018 }
2019 
2020 FASTBOOL SdrEdgeObj::MovCreate(SdrDragStat& rDragStat)
2021 {
2022     sal_uInt16 nMax=pEdgeTrack->GetPointCount();
2023     (*pEdgeTrack)[nMax-1]=rDragStat.GetNow();
2024     if (rDragStat.GetPageView()!=NULL) {
2025         ImpFindConnector(rDragStat.GetNow(),*rDragStat.GetPageView(),aCon2,this);
2026         rDragStat.GetView()->SetConnectMarker(aCon2,*rDragStat.GetPageView());
2027     }
2028     SetBoundRectDirty();
2029     bSnapRectDirty=sal_True;
2030     ConnectToNode(sal_False,aCon2.pObj);
2031     *pEdgeTrack=ImpCalcEdgeTrack(*pEdgeTrack,aCon1,aCon2,&aEdgeInfo);
2032     bEdgeTrackDirty=sal_False;
2033     return sal_True;
2034 }
2035 
2036 FASTBOOL SdrEdgeObj::EndCreate(SdrDragStat& rDragStat, SdrCreateCmd eCmd)
2037 {
2038     FASTBOOL bOk=(eCmd==SDRCREATE_FORCEEND || rDragStat.GetPointAnz()>=2);
2039     if (bOk) {
2040         ConnectToNode(sal_True,aCon1.pObj);
2041         ConnectToNode(sal_False,aCon2.pObj);
2042         if (rDragStat.GetView()!=NULL) {
2043             rDragStat.GetView()->HideConnectMarker();
2044         }
2045         ImpSetEdgeInfoToAttr(); // Die Werte aus aEdgeInfo in den Pool kopieren
2046     }
2047     SetRectsDirty();
2048     return bOk;
2049 }
2050 
2051 FASTBOOL SdrEdgeObj::BckCreate(SdrDragStat& rDragStat)
2052 {
2053     if (rDragStat.GetView()!=NULL) {
2054         rDragStat.GetView()->HideConnectMarker();
2055     }
2056     return sal_False;
2057 }
2058 
2059 void SdrEdgeObj::BrkCreate(SdrDragStat& rDragStat)
2060 {
2061     if (rDragStat.GetView()!=NULL) {
2062         rDragStat.GetView()->HideConnectMarker();
2063     }
2064 }
2065 
2066 basegfx::B2DPolyPolygon SdrEdgeObj::TakeCreatePoly(const SdrDragStat& /*rStatDrag*/) const
2067 {
2068     basegfx::B2DPolyPolygon aRetval;
2069     aRetval.append(pEdgeTrack->getB2DPolygon());
2070     return aRetval;
2071 }
2072 
2073 Pointer SdrEdgeObj::GetCreatePointer() const
2074 {
2075     return Pointer(POINTER_DRAW_CONNECT);
2076 }
2077 
2078 FASTBOOL SdrEdgeObj::ImpFindConnector(const Point& rPt, const SdrPageView& rPV, SdrObjConnection& rCon, const SdrEdgeObj* pThis, OutputDevice* pOut)
2079 {
2080     rCon.ResetVars();
2081     if (pOut==NULL) pOut=rPV.GetView().GetFirstOutputDevice(); // GetWin(0);
2082     if (pOut==NULL) return sal_False;
2083     SdrObjList* pOL=rPV.GetObjList();
2084     const SetOfByte& rVisLayer=rPV.GetVisibleLayers();
2085     // Sensitiver Bereich der Konnektoren ist doppelt so gross wie die Handles:
2086     sal_uInt16 nMarkHdSiz=rPV.GetView().GetMarkHdlSizePixel();
2087     Size aHalfConSiz(nMarkHdSiz,nMarkHdSiz);
2088     aHalfConSiz=pOut->PixelToLogic(aHalfConSiz);
2089     Size aHalfCenterSiz(2*aHalfConSiz.Width(),2*aHalfConSiz.Height());
2090     Rectangle aMouseRect(rPt,rPt);
2091     aMouseRect.Left()  -=aHalfConSiz.Width();
2092     aMouseRect.Top()   -=aHalfConSiz.Height();
2093     aMouseRect.Right() +=aHalfConSiz.Width();
2094     aMouseRect.Bottom()+=aHalfConSiz.Height();
2095     sal_uInt16 nBoundHitTol=(sal_uInt16)aHalfConSiz.Width()/2; if (nBoundHitTol==0) nBoundHitTol=1;
2096     sal_uIntPtr no=pOL->GetObjCount();
2097     FASTBOOL bFnd=sal_False;
2098     SdrObjConnection aTestCon;
2099     SdrObjConnection aBestCon;
2100     FASTBOOL bTestBoundHit=sal_False;
2101     //int bBestBoundHit=sal_False;
2102 
2103     while (no>0 && !bFnd) {
2104         // Problem: Gruppenobjekt mit verschiedenen Layern liefert LayerID 0 !!!!
2105         no--;
2106         SdrObject* pObj=pOL->GetObj(no);
2107         if (rVisLayer.IsSet(pObj->GetLayer()) && pObj->IsVisible() &&      // only visible objects
2108             (pThis==NULL || pObj!=(SdrObject*)pThis) && // nicht an mich selbst connecten
2109             pObj->IsNode())
2110         {
2111             Rectangle aObjBound(pObj->GetCurrentBoundRect());
2112             if (aObjBound.IsOver(aMouseRect)) {
2113                 aTestCon.ResetVars();
2114                 bTestBoundHit=sal_False;
2115                 FASTBOOL bEdge=HAS_BASE(SdrEdgeObj,pObj); // kein BestCon fuer Edge
2116                 // Die Userdefined Konnektoren haben absolute Prioritaet.
2117                 // Danach kommt Vertex, Corner und Mitte(Best) gleich priorisiert.
2118                 // Zum Schluss kommt noch ein HitTest aufs Obj.
2119                 const SdrGluePointList* pGPL=pObj->GetGluePointList();
2120                 sal_uInt16 nConAnz=pGPL==NULL ? 0 : pGPL->GetCount();
2121                 sal_uInt16 nGesAnz=nConAnz+9;
2122                 FASTBOOL bUserFnd=sal_False;
2123                 sal_uIntPtr nBestDist=0xFFFFFFFF;
2124                 for (sal_uInt16 i=0; i<nGesAnz; i++)
2125                 {
2126                     FASTBOOL bUser=i<nConAnz;
2127                     FASTBOOL bVertex=i>=nConAnz+0 && i<nConAnz+4;
2128                     FASTBOOL bCorner=i>=nConAnz+4 && i<nConAnz+8;
2129                     FASTBOOL bCenter=i==nConAnz+8;
2130                     FASTBOOL bOk=sal_False;
2131                     Point aConPos;
2132                     sal_uInt16 nConNum=i;
2133                     if (bUser) {
2134                         const SdrGluePoint& rGP=(*pGPL)[nConNum];
2135                         aConPos=rGP.GetAbsolutePos(*pObj);
2136                         nConNum=rGP.GetId();
2137                         bOk=sal_True;
2138                     } else if (bVertex && !bUserFnd) {
2139                         nConNum=nConNum-nConAnz;
2140                         if (rPV.GetView().IsAutoVertexConnectors()) {
2141                             SdrGluePoint aPt(pObj->GetVertexGluePoint(nConNum));
2142                             aConPos=aPt.GetAbsolutePos(*pObj);
2143                             bOk=sal_True;
2144                         } else i+=3;
2145                     } else if (bCorner && !bUserFnd) {
2146                         nConNum-=nConAnz+4;
2147                         if (rPV.GetView().IsAutoCornerConnectors()) {
2148                             SdrGluePoint aPt(pObj->GetCornerGluePoint(nConNum));
2149                             aConPos=aPt.GetAbsolutePos(*pObj);
2150                             bOk=sal_True;
2151                         } else i+=3;
2152                     }
2153                     else if (bCenter && !bUserFnd && !bEdge)
2154                     {
2155                         // #109007#
2156                         // Suppress default connect at object center
2157                         if(!pThis || !pThis->GetSuppressDefaultConnect())
2158                         {
2159                             // Edges nicht!
2160                             nConNum=0;
2161                             aConPos=aObjBound.Center();
2162                             bOk=sal_True;
2163                         }
2164                     }
2165                     if (bOk && aMouseRect.IsInside(aConPos)) {
2166                         if (bUser) bUserFnd=sal_True;
2167                         bFnd=sal_True;
2168                         sal_uIntPtr nDist=(sal_uIntPtr)Abs(aConPos.X()-rPt.X())+(sal_uIntPtr)Abs(aConPos.Y()-rPt.Y());
2169                         if (nDist<nBestDist) {
2170                             nBestDist=nDist;
2171                             aTestCon.pObj=pObj;
2172                             aTestCon.nConId=nConNum;
2173                             aTestCon.bAutoCorner=bCorner;
2174                             aTestCon.bAutoVertex=bVertex;
2175                             aTestCon.bBestConn=sal_False; // bCenter;
2176                             aTestCon.bBestVertex=bCenter;
2177                         }
2178                     }
2179                 }
2180                 // Falls kein Konnektor getroffen wird nochmal
2181                 // HitTest versucht fuer BestConnector (=bCenter)
2182                 if(!bFnd &&
2183                     !bEdge &&
2184                     SdrObjectPrimitiveHit(*pObj, rPt, nBoundHitTol, rPV, &rVisLayer, false))
2185                 {
2186                     // #109007#
2187                     // Suppress default connect at object inside bound
2188                     if(!pThis || !pThis->GetSuppressDefaultConnect())
2189                     {
2190                         bFnd=sal_True;
2191                         aTestCon.pObj=pObj;
2192                         aTestCon.bBestConn=sal_True;
2193                     }
2194                 }
2195                 if (bFnd) {
2196                     Rectangle aMouseRect2(rPt,rPt);
2197                     aMouseRect.Left()  -=nBoundHitTol;
2198                     aMouseRect.Top()   -=nBoundHitTol;
2199                     aMouseRect.Right() +=nBoundHitTol;
2200                     aMouseRect.Bottom()+=nBoundHitTol;
2201                     bTestBoundHit=aObjBound.IsOver(aMouseRect2);
2202                 }
2203 
2204             }
2205         }
2206     }
2207     rCon=aTestCon;
2208     return bFnd;
2209 }
2210 
2211 void SdrEdgeObj::NbcSetSnapRect(const Rectangle& rRect)
2212 {
2213     const Rectangle aOld(GetSnapRect());
2214 
2215     if(aOld != rRect)
2216     {
2217         if(aRect.IsEmpty() && 0 == pEdgeTrack->GetPointCount())
2218         {
2219             // #i110629# When initializing, do not scale on empty Rectangle; this
2220             // will mirror the underlying text object (!)
2221             aRect = rRect;
2222             maSnapRect = rRect;
2223         }
2224         else
2225         {
2226             long nMulX = rRect.Right()  - rRect.Left();
2227             long nDivX = aOld.Right()   - aOld.Left();
2228             long nMulY = rRect.Bottom() - rRect.Top();
2229             long nDivY = aOld.Bottom()  - aOld.Top();
2230             if ( nDivX == 0 ) { nMulX = 1; nDivX = 1; }
2231             if ( nDivY == 0 ) { nMulY = 1; nDivY = 1; }
2232             Fraction aX(nMulX, nDivX);
2233             Fraction aY(nMulY, nDivY);
2234             NbcResize(aOld.TopLeft(), aX, aY);
2235             NbcMove(Size(rRect.Left() - aOld.Left(), rRect.Top() - aOld.Top()));
2236         }
2237     }
2238 }
2239 
2240 void SdrEdgeObj::NbcMove(const Size& rSiz)
2241 {
2242     SdrTextObj::NbcMove(rSiz);
2243     MoveXPoly(*pEdgeTrack,rSiz);
2244 }
2245 
2246 void SdrEdgeObj::NbcResize(const Point& rRefPnt, const Fraction& aXFact, const Fraction& aYFact)
2247 {
2248     SdrTextObj::NbcResize(rRefPnt,aXFact,aXFact);
2249     ResizeXPoly(*pEdgeTrack,rRefPnt,aXFact,aYFact);
2250 
2251     // #75371# if resize is not from paste, forget user distances
2252     if(!GetModel()->IsPasteResize())
2253     {
2254         // #75735#
2255         aEdgeInfo.aObj1Line2 = Point();
2256         aEdgeInfo.aObj1Line3 = Point();
2257         aEdgeInfo.aObj2Line2 = Point();
2258         aEdgeInfo.aObj2Line3 = Point();
2259         aEdgeInfo.aMiddleLine = Point();
2260     }
2261 }
2262 
2263 // #54102# added rotation support
2264 void SdrEdgeObj::NbcRotate(const Point& rRef, long /* nWink */, double sn, double cs)
2265 {
2266     // handle start and end point if not connected
2267     FASTBOOL bCon1=aCon1.pObj!=NULL && aCon1.pObj->GetPage()==pPage;
2268     FASTBOOL bCon2=aCon2.pObj!=NULL && aCon2.pObj->GetPage()==pPage;
2269 
2270     if(!bCon1 && pEdgeTrack)
2271     {
2272         RotatePoint((*pEdgeTrack)[0],rRef,sn,cs);
2273         ImpDirtyEdgeTrack();
2274     }
2275 
2276     if(!bCon2 && pEdgeTrack)
2277     {
2278         sal_uInt16 nPntAnz = pEdgeTrack->GetPointCount();
2279         RotatePoint((*pEdgeTrack)[sal_uInt16(nPntAnz-1)],rRef,sn,cs);
2280         ImpDirtyEdgeTrack();
2281     }
2282 }
2283 
2284 // #54102# added mirror support
2285 void SdrEdgeObj::NbcMirror(const Point& rRef1, const Point& rRef2)
2286 {
2287     // handle start and end point if not connected
2288     FASTBOOL bCon1=aCon1.pObj!=NULL && aCon1.pObj->GetPage()==pPage;
2289     FASTBOOL bCon2=aCon2.pObj!=NULL && aCon2.pObj->GetPage()==pPage;
2290 
2291     if(!bCon1 && pEdgeTrack)
2292     {
2293         MirrorPoint((*pEdgeTrack)[0],rRef1,rRef2);
2294         ImpDirtyEdgeTrack();
2295     }
2296 
2297     if(!bCon2 && pEdgeTrack)
2298     {
2299         sal_uInt16 nPntAnz = pEdgeTrack->GetPointCount();
2300         MirrorPoint((*pEdgeTrack)[sal_uInt16(nPntAnz-1)],rRef1,rRef2);
2301         ImpDirtyEdgeTrack();
2302     }
2303 }
2304 
2305 // #54102# added shear support
2306 void SdrEdgeObj::NbcShear(const Point& rRef, long /* nWink */, double tn, FASTBOOL bVShear)
2307 {
2308     // handle start and end point if not connected
2309     FASTBOOL bCon1=aCon1.pObj!=NULL && aCon1.pObj->GetPage()==pPage;
2310     FASTBOOL bCon2=aCon2.pObj!=NULL && aCon2.pObj->GetPage()==pPage;
2311 
2312     if(!bCon1 && pEdgeTrack)
2313     {
2314         ShearPoint((*pEdgeTrack)[0],rRef,tn,bVShear);
2315         ImpDirtyEdgeTrack();
2316     }
2317 
2318     if(!bCon2 && pEdgeTrack)
2319     {
2320         sal_uInt16 nPntAnz = pEdgeTrack->GetPointCount();
2321         ShearPoint((*pEdgeTrack)[sal_uInt16(nPntAnz-1)],rRef,tn,bVShear);
2322         ImpDirtyEdgeTrack();
2323     }
2324 }
2325 
2326 SdrObject* SdrEdgeObj::DoConvertToPolyObj(sal_Bool bBezier, bool bAddText) const
2327 {
2328     basegfx::B2DPolyPolygon aPolyPolygon;
2329     aPolyPolygon.append(pEdgeTrack->getB2DPolygon());
2330     SdrObject* pRet = ImpConvertMakeObj(aPolyPolygon, sal_False, bBezier);
2331 
2332     if(bAddText)
2333     {
2334         pRet = ImpConvertAddText(pRet, bBezier);
2335     }
2336 
2337     return pRet;
2338 }
2339 
2340 sal_uInt32 SdrEdgeObj::GetSnapPointCount() const
2341 {
2342     return 2L;
2343 }
2344 
2345 Point SdrEdgeObj::GetSnapPoint(sal_uInt32 i) const
2346 {
2347     ((SdrEdgeObj*)this)->ImpUndirtyEdgeTrack();
2348     sal_uInt16 nAnz=pEdgeTrack->GetPointCount();
2349     if (i==0) return (*pEdgeTrack)[0];
2350     else return (*pEdgeTrack)[nAnz-1];
2351 }
2352 
2353 sal_Bool SdrEdgeObj::IsPolyObj() const
2354 {
2355     return sal_False;
2356 }
2357 
2358 sal_uInt32 SdrEdgeObj::GetPointCount() const
2359 {
2360     return 0L;
2361 }
2362 
2363 Point SdrEdgeObj::GetPoint(sal_uInt32 i) const
2364 {
2365     ((SdrEdgeObj*)this)->ImpUndirtyEdgeTrack();
2366     sal_uInt16 nAnz=pEdgeTrack->GetPointCount();
2367     if (0L == i)
2368         return (*pEdgeTrack)[0];
2369     else
2370         return (*pEdgeTrack)[nAnz-1];
2371 }
2372 
2373 void SdrEdgeObj::NbcSetPoint(const Point& rPnt, sal_uInt32 i)
2374 {
2375     // ToDo: Umconnekten fehlt noch
2376     ImpUndirtyEdgeTrack();
2377     sal_uInt16 nAnz=pEdgeTrack->GetPointCount();
2378     if (0L == i)
2379         (*pEdgeTrack)[0]=rPnt;
2380     if (1L == i)
2381         (*pEdgeTrack)[nAnz-1]=rPnt;
2382     SetEdgeTrackDirty();
2383     SetRectsDirty();
2384 }
2385 
2386 SdrEdgeObjGeoData::SdrEdgeObjGeoData()
2387 {
2388     pEdgeTrack=new XPolygon;
2389 }
2390 
2391 SdrEdgeObjGeoData::~SdrEdgeObjGeoData()
2392 {
2393     delete pEdgeTrack;
2394 }
2395 
2396 SdrObjGeoData* SdrEdgeObj::NewGeoData() const
2397 {
2398     return new SdrEdgeObjGeoData;
2399 }
2400 
2401 void SdrEdgeObj::SaveGeoData(SdrObjGeoData& rGeo) const
2402 {
2403     SdrTextObj::SaveGeoData(rGeo);
2404     SdrEdgeObjGeoData& rEGeo=(SdrEdgeObjGeoData&)rGeo;
2405     rEGeo.aCon1          =aCon1;
2406     rEGeo.aCon2          =aCon2;
2407     *rEGeo.pEdgeTrack    =*pEdgeTrack;
2408     rEGeo.bEdgeTrackDirty=bEdgeTrackDirty;
2409     rEGeo.bEdgeTrackUserDefined=bEdgeTrackUserDefined;
2410     rEGeo.aEdgeInfo      =aEdgeInfo;
2411 }
2412 
2413 void SdrEdgeObj::RestGeoData(const SdrObjGeoData& rGeo)
2414 {
2415     SdrTextObj::RestGeoData(rGeo);
2416     SdrEdgeObjGeoData& rEGeo=(SdrEdgeObjGeoData&)rGeo;
2417     if (aCon1.pObj!=rEGeo.aCon1.pObj) {
2418         if (aCon1.pObj!=NULL) aCon1.pObj->RemoveListener(*this);
2419         aCon1=rEGeo.aCon1;
2420         if (aCon1.pObj!=NULL) aCon1.pObj->AddListener(*this);
2421     }
2422     if (aCon2.pObj!=rEGeo.aCon2.pObj) {
2423         if (aCon2.pObj!=NULL) aCon2.pObj->RemoveListener(*this);
2424         aCon2=rEGeo.aCon2;
2425         if (aCon2.pObj!=NULL) aCon2.pObj->AddListener(*this);
2426     }
2427     *pEdgeTrack    =*rEGeo.pEdgeTrack;
2428     bEdgeTrackDirty=rEGeo.bEdgeTrackDirty;
2429     bEdgeTrackUserDefined=rEGeo.bEdgeTrackUserDefined;
2430     aEdgeInfo      =rEGeo.aEdgeInfo;
2431 }
2432 
2433 Point SdrEdgeObj::GetTailPoint( sal_Bool bTail ) const
2434 {
2435     if( pEdgeTrack && pEdgeTrack->GetPointCount()!=0)
2436     {
2437         const XPolygon& rTrack0 = *pEdgeTrack;
2438         if(bTail)
2439         {
2440             return rTrack0[0];
2441         }
2442         else
2443         {
2444             const sal_uInt16 nSiz = rTrack0.GetPointCount() - 1;
2445             return rTrack0[nSiz];
2446         }
2447     }
2448     else
2449     {
2450         if(bTail)
2451             return aOutRect.TopLeft();
2452         else
2453             return aOutRect.BottomRight();
2454     }
2455 
2456 }
2457 
2458 void SdrEdgeObj::SetTailPoint( sal_Bool bTail, const Point& rPt )
2459 {
2460     ImpSetTailPoint( bTail, rPt );
2461     SetChanged();
2462 }
2463 
2464 /** this method is used by the api to set a glue point for a connection
2465     nId == -1 :     The best default point is automaticly choosen
2466     0 <= nId <= 3 : One of the default points is choosen
2467     nId >= 4 :      A user defined glue point is choosen
2468 */
2469 void SdrEdgeObj::setGluePointIndex( sal_Bool bTail, sal_Int32 nIndex /* = -1 */ )
2470 {
2471     Rectangle aBoundRect0; if (pUserCall!=NULL) aBoundRect0=GetCurrentBoundRect();
2472     // #110094#-14 BroadcastObjectChange();
2473 
2474     SdrObjConnection& rConn1 = GetConnection( bTail );
2475 
2476     rConn1.SetAutoVertex( nIndex >= 0 && nIndex <= 3 );
2477     rConn1.SetBestConnection( nIndex < 0 );
2478     rConn1.SetBestVertex( nIndex < 0 );
2479 
2480     if( nIndex > 3 )
2481     {
2482 //      nIndex -= 4;
2483         nIndex -= 3;        // SJ: the start api index is 0, whereas the implementation in svx starts from 1
2484 
2485         // for user defined glue points we have
2486         // to get the id for this index first
2487         const SdrGluePointList* pList = rConn1.GetObject() ? rConn1.GetObject()->GetGluePointList() : NULL;
2488         if( pList == NULL || SDRGLUEPOINT_NOTFOUND == pList->FindGluePoint((sal_uInt16)nIndex) )
2489             return;
2490     }
2491     else if( nIndex < 0 )
2492     {
2493         nIndex = 0;
2494     }
2495 
2496     rConn1.SetConnectorId( (sal_uInt16)nIndex );
2497 
2498     SetChanged();
2499     SetRectsDirty();
2500     ImpRecalcEdgeTrack();
2501     // bEdgeTrackDirty=sal_True;
2502 }
2503 
2504 /** this method is used by the api to return a glue point id for a connection.
2505     See setGluePointId for possible return values */
2506 sal_Int32 SdrEdgeObj::getGluePointIndex( sal_Bool bTail )
2507 {
2508     SdrObjConnection& rConn1 = GetConnection( bTail );
2509     sal_Int32 nId = -1;
2510     if( !rConn1.IsBestConnection() )
2511     {
2512         nId = rConn1.GetConnectorId();
2513         if( !rConn1.IsAutoVertex() )
2514 //          nId += 4;
2515             nId += 3;       // SJ: the start api index is 0, whereas the implementation in svx starts from 1
2516     }
2517     return nId;
2518 }
2519 
2520 // #102344# Implementation was missing; edge track needs to be invalidated additionally.
2521 void SdrEdgeObj::NbcSetAnchorPos(const Point& rPnt)
2522 {
2523     // call parent functionality
2524     SdrTextObj::NbcSetAnchorPos(rPnt);
2525 
2526     // Additionally, invalidate edge track
2527     ImpDirtyEdgeTrack();
2528 }
2529 
2530 sal_Bool SdrEdgeObj::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B2DPolyPolygon& rPolyPolygon) const
2531 {
2532     // use base method from SdrObject, it's not rotatable and
2533     // a call to GetSnapRect() is used. That's what we need for Connector.
2534     return SdrObject::TRGetBaseGeometry(rMatrix, rPolyPolygon);
2535 }
2536 
2537 void SdrEdgeObj::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, const basegfx::B2DPolyPolygon& rPolyPolygon)
2538 {
2539     // evtl. take care for existing connections. For now, just use the
2540     // implementation from SdrObject.
2541     SdrObject::TRSetBaseGeometry(rMatrix, rPolyPolygon);
2542 }
2543 
2544 // for geometry access
2545 ::basegfx::B2DPolygon SdrEdgeObj::getEdgeTrack() const
2546 {
2547     if(bEdgeTrackDirty)
2548     {
2549         const_cast< SdrEdgeObj* >(this)->ImpRecalcEdgeTrack();
2550     }
2551 
2552     if(pEdgeTrack)
2553     {
2554         return pEdgeTrack->getB2DPolygon();
2555     }
2556     else
2557     {
2558         return ::basegfx::B2DPolygon();
2559     }
2560 }
2561 
2562 //////////////////////////////////////////////////////////////////////////////
2563 // eof
2564