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