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