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