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