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