xref: /AOO41X/main/svx/source/svdraw/svdglue.cxx (revision 5876ddcaa727000da06189fba3a2f4ebb924ef74)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <tools/debug.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <svx/svdglue.hxx>
29cdf0e10cSrcweir #include <svx/svdobj.hxx>
30cdf0e10cSrcweir #include <svx/svdtrans.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
SetReallyAbsolute(FASTBOOL bOn,const SdrObject & rObj)33cdf0e10cSrcweir void SdrGluePoint::SetReallyAbsolute(FASTBOOL bOn, const SdrObject& rObj)
34cdf0e10cSrcweir {
35cdf0e10cSrcweir 	if ( bReallyAbsolute != bOn )
36cdf0e10cSrcweir 	{
37cdf0e10cSrcweir 		if ( bOn )
38cdf0e10cSrcweir 		{
39cdf0e10cSrcweir 			aPos=GetAbsolutePos(rObj);
40cdf0e10cSrcweir 			bReallyAbsolute=bOn;
41cdf0e10cSrcweir 		}
42cdf0e10cSrcweir 		else
43cdf0e10cSrcweir 		{
44cdf0e10cSrcweir 			bReallyAbsolute=bOn;
45cdf0e10cSrcweir 			Point aPt(aPos);
46cdf0e10cSrcweir 			SetAbsolutePos(aPt,rObj);
47cdf0e10cSrcweir 		}
48cdf0e10cSrcweir 	}
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
GetAbsolutePos(const SdrObject & rObj) const51cdf0e10cSrcweir Point SdrGluePoint::GetAbsolutePos(const SdrObject& rObj) const
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 	if (bReallyAbsolute) return aPos;
54cdf0e10cSrcweir 	Rectangle aSnap(rObj.GetSnapRect());
55cdf0e10cSrcweir 	Rectangle aBound(rObj.GetSnapRect());
56cdf0e10cSrcweir 	Point aPt(aPos);
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	Point aOfs(aSnap.Center());
59cdf0e10cSrcweir 	switch (GetHorzAlign()) {
60cdf0e10cSrcweir 		case SDRHORZALIGN_LEFT  : aOfs.X()=aSnap.Left(); break;
61cdf0e10cSrcweir 		case SDRHORZALIGN_RIGHT : aOfs.X()=aSnap.Right(); break;
62cdf0e10cSrcweir 	}
63cdf0e10cSrcweir 	switch (GetVertAlign()) {
64cdf0e10cSrcweir 		case SDRVERTALIGN_TOP   : aOfs.Y()=aSnap.Top(); break;
65cdf0e10cSrcweir 		case SDRVERTALIGN_BOTTOM: aOfs.Y()=aSnap.Bottom(); break;
66cdf0e10cSrcweir 	}
67cdf0e10cSrcweir 	if (!bNoPercent) {
68cdf0e10cSrcweir 		long nXMul=aSnap.Right()-aSnap.Left();
69cdf0e10cSrcweir 		long nYMul=aSnap.Bottom()-aSnap.Top();
70cdf0e10cSrcweir 		long nXDiv=10000;
71cdf0e10cSrcweir 		long nYDiv=10000;
72cdf0e10cSrcweir 		if (nXMul!=nXDiv) {
73cdf0e10cSrcweir 			aPt.X()*=nXMul;
74cdf0e10cSrcweir 			aPt.X()/=nXDiv;
75cdf0e10cSrcweir 		}
76cdf0e10cSrcweir 		if (nYMul!=nYDiv) {
77cdf0e10cSrcweir 			aPt.Y()*=nYMul;
78cdf0e10cSrcweir 			aPt.Y()/=nYDiv;
79cdf0e10cSrcweir 		}
80cdf0e10cSrcweir 	}
81cdf0e10cSrcweir 	aPt+=aOfs;
82cdf0e10cSrcweir 	// Und nun auf's BoundRect des Objekts begrenzen
83cdf0e10cSrcweir 	if (aPt.X()<aBound.Left  ()) aPt.X()=aBound.Left  ();
84cdf0e10cSrcweir 	if (aPt.X()>aBound.Right ()) aPt.X()=aBound.Right ();
85cdf0e10cSrcweir 	if (aPt.Y()<aBound.Top   ()) aPt.Y()=aBound.Top   ();
86cdf0e10cSrcweir 	if (aPt.Y()>aBound.Bottom()) aPt.Y()=aBound.Bottom();
87cdf0e10cSrcweir 	return aPt;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
SetAbsolutePos(const Point & rNewPos,const SdrObject & rObj)90cdf0e10cSrcweir void SdrGluePoint::SetAbsolutePos(const Point& rNewPos, const SdrObject& rObj)
91cdf0e10cSrcweir {
92cdf0e10cSrcweir 	if (bReallyAbsolute) {
93cdf0e10cSrcweir 		aPos=rNewPos;
94cdf0e10cSrcweir 		return;
95cdf0e10cSrcweir 	}
96cdf0e10cSrcweir 	Rectangle aSnap(rObj.GetSnapRect());
97cdf0e10cSrcweir 	Point aPt(rNewPos);
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	Point aOfs(aSnap.Center());
100cdf0e10cSrcweir 	switch (GetHorzAlign()) {
101cdf0e10cSrcweir 		case SDRHORZALIGN_LEFT  : aOfs.X()=aSnap.Left(); break;
102cdf0e10cSrcweir 		case SDRHORZALIGN_RIGHT : aOfs.X()=aSnap.Right(); break;
103cdf0e10cSrcweir 	}
104cdf0e10cSrcweir 	switch (GetVertAlign()) {
105cdf0e10cSrcweir 		case SDRVERTALIGN_TOP   : aOfs.Y()=aSnap.Top(); break;
106cdf0e10cSrcweir 		case SDRVERTALIGN_BOTTOM: aOfs.Y()=aSnap.Bottom(); break;
107cdf0e10cSrcweir 	}
108cdf0e10cSrcweir 	aPt-=aOfs;
109cdf0e10cSrcweir 	if (!bNoPercent) {
110cdf0e10cSrcweir 		long nXMul=aSnap.Right()-aSnap.Left();
111cdf0e10cSrcweir 		long nYMul=aSnap.Bottom()-aSnap.Top();
112cdf0e10cSrcweir 		if (nXMul==0) nXMul=1;
113cdf0e10cSrcweir 		if (nYMul==0) nYMul=1;
114cdf0e10cSrcweir 		long nXDiv=10000;
115cdf0e10cSrcweir 		long nYDiv=10000;
116cdf0e10cSrcweir 		if (nXMul!=nXDiv) {
117cdf0e10cSrcweir 			aPt.X()*=nXDiv;
118cdf0e10cSrcweir 			aPt.X()/=nXMul;
119cdf0e10cSrcweir 		}
120cdf0e10cSrcweir 		if (nYMul!=nYDiv) {
121cdf0e10cSrcweir 			aPt.Y()*=nYDiv;
122cdf0e10cSrcweir 			aPt.Y()/=nYMul;
123cdf0e10cSrcweir 		}
124cdf0e10cSrcweir 	}
125cdf0e10cSrcweir 	aPos=aPt;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
GetAlignAngle() const128cdf0e10cSrcweir long SdrGluePoint::GetAlignAngle() const
129cdf0e10cSrcweir {
130cdf0e10cSrcweir 	switch (nAlign) {
131cdf0e10cSrcweir 		case SDRHORZALIGN_CENTER|SDRVERTALIGN_CENTER: return 0; // Invalid!
132cdf0e10cSrcweir 		case SDRHORZALIGN_RIGHT |SDRVERTALIGN_CENTER: return 0;
133cdf0e10cSrcweir 		case SDRHORZALIGN_RIGHT |SDRVERTALIGN_TOP   : return 4500;
134cdf0e10cSrcweir 		case SDRHORZALIGN_CENTER|SDRVERTALIGN_TOP   : return 9000;
135cdf0e10cSrcweir 		case SDRHORZALIGN_LEFT  |SDRVERTALIGN_TOP   : return 13500;
136cdf0e10cSrcweir 		case SDRHORZALIGN_LEFT  |SDRVERTALIGN_CENTER: return 18000;
137cdf0e10cSrcweir 		case SDRHORZALIGN_LEFT  |SDRVERTALIGN_BOTTOM: return 22500;
138cdf0e10cSrcweir 		case SDRHORZALIGN_CENTER|SDRVERTALIGN_BOTTOM: return 27000;
139cdf0e10cSrcweir 		case SDRHORZALIGN_RIGHT |SDRVERTALIGN_BOTTOM: return 31500;
140cdf0e10cSrcweir 	} // switch
141cdf0e10cSrcweir 	return 0;
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
SetAlignAngle(long nWink)144cdf0e10cSrcweir void SdrGluePoint::SetAlignAngle(long nWink)
145cdf0e10cSrcweir {
146cdf0e10cSrcweir 	nWink=NormAngle360(nWink);
147cdf0e10cSrcweir 	if (nWink>=33750 || nWink<2250) nAlign=SDRHORZALIGN_RIGHT |SDRVERTALIGN_CENTER;
148cdf0e10cSrcweir 	else if (nWink< 6750) nAlign=SDRHORZALIGN_RIGHT |SDRVERTALIGN_TOP   ;
149cdf0e10cSrcweir 	else if (nWink<11250) nAlign=SDRHORZALIGN_CENTER|SDRVERTALIGN_TOP   ;
150cdf0e10cSrcweir 	else if (nWink<15750) nAlign=SDRHORZALIGN_LEFT  |SDRVERTALIGN_TOP   ;
151cdf0e10cSrcweir 	else if (nWink<20250) nAlign=SDRHORZALIGN_LEFT  |SDRVERTALIGN_CENTER;
152cdf0e10cSrcweir 	else if (nWink<24750) nAlign=SDRHORZALIGN_LEFT  |SDRVERTALIGN_BOTTOM;
153cdf0e10cSrcweir 	else if (nWink<29250) nAlign=SDRHORZALIGN_CENTER|SDRVERTALIGN_BOTTOM;
154cdf0e10cSrcweir 	else if (nWink<33750) nAlign=SDRHORZALIGN_RIGHT |SDRVERTALIGN_BOTTOM;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
EscDirToAngle(sal_uInt16 nEsc) const157cdf0e10cSrcweir long SdrGluePoint::EscDirToAngle(sal_uInt16 nEsc) const
158cdf0e10cSrcweir {
159cdf0e10cSrcweir 	switch (nEsc) {
160cdf0e10cSrcweir 		case SDRESC_RIGHT : return 0;
161cdf0e10cSrcweir 		case SDRESC_TOP   : return 9000;
162cdf0e10cSrcweir 		case SDRESC_LEFT  : return 18000;
163cdf0e10cSrcweir 		case SDRESC_BOTTOM: return 27000;
164cdf0e10cSrcweir 	} // switch
165cdf0e10cSrcweir 	return 0;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
EscAngleToDir(long nWink) const168cdf0e10cSrcweir sal_uInt16 SdrGluePoint::EscAngleToDir(long nWink) const
169cdf0e10cSrcweir {
170cdf0e10cSrcweir 	nWink=NormAngle360(nWink);
171cdf0e10cSrcweir 	if (nWink>=31500 || nWink<4500) return SDRESC_RIGHT;
172cdf0e10cSrcweir 	if (nWink<13500) return SDRESC_TOP;
173cdf0e10cSrcweir 	if (nWink<22500) return SDRESC_LEFT;
174cdf0e10cSrcweir 	if (nWink<31500) return SDRESC_BOTTOM;
175cdf0e10cSrcweir 	return 0;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
Rotate(const Point & rRef,long nWink,double sn,double cs,const SdrObject * pObj)178cdf0e10cSrcweir void SdrGluePoint::Rotate(const Point& rRef, long nWink, double sn, double cs, const SdrObject* pObj)
179cdf0e10cSrcweir {
180cdf0e10cSrcweir 	Point aPt(pObj!=NULL ? GetAbsolutePos(*pObj) : GetPos());
181cdf0e10cSrcweir 	RotatePoint(aPt,rRef,sn,cs);
182cdf0e10cSrcweir 	// Bezugskante drehen
183cdf0e10cSrcweir 	if(nAlign != (SDRHORZALIGN_CENTER|SDRVERTALIGN_CENTER))
184cdf0e10cSrcweir 	{
185cdf0e10cSrcweir 		SetAlignAngle(GetAlignAngle()+nWink);
186cdf0e10cSrcweir 	}
187*330b556eSmseidel 	// rotate escape directions
188cdf0e10cSrcweir 	sal_uInt16 nEscDir0=nEscDir;
189cdf0e10cSrcweir 	sal_uInt16 nEscDir1=0;
190cdf0e10cSrcweir 	if ((nEscDir0&SDRESC_LEFT  )!=0) nEscDir1|=EscAngleToDir(EscDirToAngle(SDRESC_LEFT  )+nWink);
191cdf0e10cSrcweir 	if ((nEscDir0&SDRESC_TOP   )!=0) nEscDir1|=EscAngleToDir(EscDirToAngle(SDRESC_TOP   )+nWink);
192cdf0e10cSrcweir 	if ((nEscDir0&SDRESC_RIGHT )!=0) nEscDir1|=EscAngleToDir(EscDirToAngle(SDRESC_RIGHT )+nWink);
193cdf0e10cSrcweir 	if ((nEscDir0&SDRESC_BOTTOM)!=0) nEscDir1|=EscAngleToDir(EscDirToAngle(SDRESC_BOTTOM)+nWink);
194cdf0e10cSrcweir 	nEscDir=nEscDir1;
195cdf0e10cSrcweir 	if (pObj!=NULL) SetAbsolutePos(aPt,*pObj); else SetPos(aPt);
196cdf0e10cSrcweir }
197cdf0e10cSrcweir 
Mirror(const Point & rRef1,const Point & rRef2,const SdrObject * pObj)198cdf0e10cSrcweir void SdrGluePoint::Mirror(const Point& rRef1, const Point& rRef2, const SdrObject* pObj)
199cdf0e10cSrcweir {
200cdf0e10cSrcweir 	Point aPt(rRef2); aPt-=rRef1;
201cdf0e10cSrcweir 	long nWink=GetAngle(aPt);
202cdf0e10cSrcweir 	Mirror(rRef1,rRef2,nWink,pObj);
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
Mirror(const Point & rRef1,const Point & rRef2,long nWink,const SdrObject * pObj)205cdf0e10cSrcweir void SdrGluePoint::Mirror(const Point& rRef1, const Point& rRef2, long nWink, const SdrObject* pObj)
206cdf0e10cSrcweir {
207cdf0e10cSrcweir 	Point aPt(pObj!=NULL ? GetAbsolutePos(*pObj) : GetPos());
208cdf0e10cSrcweir 	MirrorPoint(aPt,rRef1,rRef2);
209cdf0e10cSrcweir 	// Bezugskante spiegeln
210cdf0e10cSrcweir 	if(nAlign != (SDRHORZALIGN_CENTER|SDRVERTALIGN_CENTER))
211cdf0e10cSrcweir 	{
212cdf0e10cSrcweir 		long nAW=GetAlignAngle();
213cdf0e10cSrcweir 		nAW+=2*(nWink-nAW);
214cdf0e10cSrcweir 		SetAlignAngle(nAW);
215cdf0e10cSrcweir 	}
216*330b556eSmseidel 	// mirror escape directions
217cdf0e10cSrcweir 	sal_uInt16 nEscDir0=nEscDir;
218cdf0e10cSrcweir 	sal_uInt16 nEscDir1=0;
219cdf0e10cSrcweir 	if ((nEscDir0&SDRESC_LEFT)!=0) {
220cdf0e10cSrcweir 		long nEW=EscDirToAngle(SDRESC_LEFT);
221cdf0e10cSrcweir 		nEW+=2*(nWink-nEW);
222cdf0e10cSrcweir 		nEscDir1|=EscAngleToDir(nEW);
223cdf0e10cSrcweir 	}
224cdf0e10cSrcweir 	if ((nEscDir0&SDRESC_TOP)!=0) {
225cdf0e10cSrcweir 		long nEW=EscDirToAngle(SDRESC_TOP);
226cdf0e10cSrcweir 		nEW+=2*(nWink-nEW);
227cdf0e10cSrcweir 		nEscDir1|=EscAngleToDir(nEW);
228cdf0e10cSrcweir 	}
229cdf0e10cSrcweir 	if ((nEscDir0&SDRESC_RIGHT)!=0) {
230cdf0e10cSrcweir 		long nEW=EscDirToAngle(SDRESC_RIGHT);
231cdf0e10cSrcweir 		nEW+=2*(nWink-nEW);
232cdf0e10cSrcweir 		nEscDir1|=EscAngleToDir(nEW);
233cdf0e10cSrcweir 	}
234cdf0e10cSrcweir 	if ((nEscDir0&SDRESC_BOTTOM)!=0) {
235cdf0e10cSrcweir 		long nEW=EscDirToAngle(SDRESC_BOTTOM);
236cdf0e10cSrcweir 		nEW+=2*(nWink-nEW);
237cdf0e10cSrcweir 		nEscDir1|=EscAngleToDir(nEW);
238cdf0e10cSrcweir 	}
239cdf0e10cSrcweir 	nEscDir=nEscDir1;
240cdf0e10cSrcweir 	if (pObj!=NULL) SetAbsolutePos(aPt,*pObj); else SetPos(aPt);
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
Shear(const Point & rRef,long,double tn,FASTBOOL bVShear,const SdrObject * pObj)243cdf0e10cSrcweir void SdrGluePoint::Shear(const Point& rRef, long /*nWink*/, double tn, FASTBOOL bVShear, const SdrObject* pObj)
244cdf0e10cSrcweir {
245cdf0e10cSrcweir 	Point aPt(pObj!=NULL ? GetAbsolutePos(*pObj) : GetPos());
246cdf0e10cSrcweir 	ShearPoint(aPt,rRef,tn,bVShear);
247cdf0e10cSrcweir 	if (pObj!=NULL) SetAbsolutePos(aPt,*pObj); else SetPos(aPt);
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
Invalidate(Window & rWin,const SdrObject * pObj) const250cdf0e10cSrcweir void SdrGluePoint::Invalidate(Window& rWin, const SdrObject* pObj) const
251cdf0e10cSrcweir {
252cdf0e10cSrcweir 	bool bMapMerk=rWin.IsMapModeEnabled();
253cdf0e10cSrcweir 	Point aPt(pObj!=NULL ? GetAbsolutePos(*pObj) : GetPos());
254cdf0e10cSrcweir 	aPt=rWin.LogicToPixel(aPt);
255cdf0e10cSrcweir 	rWin.EnableMapMode(sal_False);
256*330b556eSmseidel 	long x=aPt.X(),y=aPt.Y(); // size 9x9 pixel
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 	// #111096#
259cdf0e10cSrcweir 	// do not erase background, that causes flicker (!)
260*330b556eSmseidel 	rWin.Invalidate(Rectangle(Point(x-4,y-4),Point(x+4,y+4)), INVALIDATE_NOERASE);
261cdf0e10cSrcweir 
262cdf0e10cSrcweir 	rWin.EnableMapMode(bMapMerk);
263cdf0e10cSrcweir }
264cdf0e10cSrcweir 
IsHit(const Point & rPnt,const OutputDevice & rOut,const SdrObject * pObj) const265cdf0e10cSrcweir FASTBOOL SdrGluePoint::IsHit(const Point& rPnt, const OutputDevice& rOut, const SdrObject* pObj) const
266cdf0e10cSrcweir {
267cdf0e10cSrcweir 	Point aPt(pObj!=NULL ? GetAbsolutePos(*pObj) : GetPos());
268*330b556eSmseidel 	Size aSiz=rOut.PixelToLogic(Size(4,4));
269cdf0e10cSrcweir 	Rectangle aRect(aPt.X()-aSiz.Width(),aPt.Y()-aSiz.Height(),aPt.X()+aSiz.Width(),aPt.Y()+aSiz.Height());
270cdf0e10cSrcweir 	return aRect.IsInside(rPnt);
271cdf0e10cSrcweir }
272cdf0e10cSrcweir 
273cdf0e10cSrcweir 
Clear()274cdf0e10cSrcweir void SdrGluePointList::Clear()
275cdf0e10cSrcweir {
276cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
277cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<nAnz; i++) {
278cdf0e10cSrcweir 		delete GetObject(i);
279cdf0e10cSrcweir 	}
280cdf0e10cSrcweir 	aList.Clear();
281cdf0e10cSrcweir }
282cdf0e10cSrcweir 
operator =(const SdrGluePointList & rSrcList)283cdf0e10cSrcweir void SdrGluePointList::operator=(const SdrGluePointList& rSrcList)
284cdf0e10cSrcweir {
285cdf0e10cSrcweir 	if (GetCount()!=0) Clear();
286cdf0e10cSrcweir 	sal_uInt16 nAnz=rSrcList.GetCount();
287cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<nAnz; i++) {
288cdf0e10cSrcweir 		Insert(rSrcList[i]);
289cdf0e10cSrcweir 	}
290cdf0e10cSrcweir }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir // Die Id's der Klebepunkte in der Liste sind stets streng monoton steigend!
293cdf0e10cSrcweir // Ggf. wird dem neuen Klebepunkt eine neue Id zugewiesen (wenn diese bereits
294cdf0e10cSrcweir // vergeben ist). Die Id 0 ist reserviert.
Insert(const SdrGluePoint & rGP)295cdf0e10cSrcweir sal_uInt16 SdrGluePointList::Insert(const SdrGluePoint& rGP)
296cdf0e10cSrcweir {
297cdf0e10cSrcweir 	SdrGluePoint* pGP=new SdrGluePoint(rGP);
298cdf0e10cSrcweir 	sal_uInt16 nId=pGP->GetId();
299cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
300cdf0e10cSrcweir 	sal_uInt16 nInsPos=nAnz;
301cdf0e10cSrcweir 	sal_uInt16 nLastId=nAnz!=0 ? GetObject(nAnz-1)->GetId() : 0;
302cdf0e10cSrcweir 	DBG_ASSERT(nLastId>=nAnz,"SdrGluePointList::Insert(): nLastId<nAnz");
303cdf0e10cSrcweir 	FASTBOOL bHole=nLastId>nAnz;
304cdf0e10cSrcweir 	if (nId<=nLastId) {
305cdf0e10cSrcweir 		if (!bHole || nId==0) {
306cdf0e10cSrcweir 			nId=nLastId+1;
307cdf0e10cSrcweir 		} else {
308cdf0e10cSrcweir 			FASTBOOL bBrk=sal_False;
309cdf0e10cSrcweir 			for (sal_uInt16 nNum=0; nNum<nAnz && !bBrk; nNum++) {
310cdf0e10cSrcweir 				const SdrGluePoint* pGP2=GetObject(nNum);
311cdf0e10cSrcweir 				sal_uInt16 nTmpId=pGP2->GetId();
312cdf0e10cSrcweir 				if (nTmpId==nId) {
313cdf0e10cSrcweir 					nId=nLastId+1; // bereits vorhanden
314cdf0e10cSrcweir 					bBrk=sal_True;
315cdf0e10cSrcweir 				}
316cdf0e10cSrcweir 				if (nTmpId>nId) {
317cdf0e10cSrcweir 					nInsPos=nNum; // Hier einfuegen (einsortieren)
318cdf0e10cSrcweir 					bBrk=sal_True;
319cdf0e10cSrcweir 				}
320cdf0e10cSrcweir 			}
321cdf0e10cSrcweir 		}
322cdf0e10cSrcweir 		pGP->SetId(nId);
323cdf0e10cSrcweir 	}
324cdf0e10cSrcweir 	aList.Insert(pGP,nInsPos);
325cdf0e10cSrcweir 	return nInsPos;
326cdf0e10cSrcweir }
327cdf0e10cSrcweir 
Invalidate(Window & rWin,const SdrObject * pObj) const328cdf0e10cSrcweir void SdrGluePointList::Invalidate(Window& rWin, const SdrObject* pObj) const
329cdf0e10cSrcweir {
330cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
331cdf0e10cSrcweir 	for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
332cdf0e10cSrcweir 		GetObject(nNum)->Invalidate(rWin,pObj);
333cdf0e10cSrcweir 	}
334cdf0e10cSrcweir }
335cdf0e10cSrcweir 
FindGluePoint(sal_uInt16 nId) const336cdf0e10cSrcweir sal_uInt16 SdrGluePointList::FindGluePoint(sal_uInt16 nId) const
337cdf0e10cSrcweir {
338*330b556eSmseidel 	// TODO: Hier noch einen optimaleren Suchalgorithmus implementieren.
339*330b556eSmseidel 	// Die Liste sollte stets sortiert sein!
340cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
341cdf0e10cSrcweir 	sal_uInt16 nRet=SDRGLUEPOINT_NOTFOUND;
342cdf0e10cSrcweir 	for (sal_uInt16 nNum=0; nNum<nAnz && nRet==SDRGLUEPOINT_NOTFOUND; nNum++) {
343cdf0e10cSrcweir 		const SdrGluePoint* pGP=GetObject(nNum);
344cdf0e10cSrcweir 		if (pGP->GetId()==nId) nRet=nNum;
345cdf0e10cSrcweir 	}
346cdf0e10cSrcweir 	return nRet;
347cdf0e10cSrcweir }
348cdf0e10cSrcweir 
HitTest(const Point & rPnt,const OutputDevice & rOut,const SdrObject * pObj,FASTBOOL bBack,FASTBOOL bNext,sal_uInt16 nId0) const349cdf0e10cSrcweir sal_uInt16 SdrGluePointList::HitTest(const Point& rPnt, const OutputDevice& rOut, const SdrObject* pObj, FASTBOOL bBack, FASTBOOL bNext, sal_uInt16 nId0) const
350cdf0e10cSrcweir {
351cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
352cdf0e10cSrcweir 	sal_uInt16 nRet=SDRGLUEPOINT_NOTFOUND;
353cdf0e10cSrcweir 	sal_uInt16 nNum=bBack ? 0 : nAnz;
354cdf0e10cSrcweir 	while ((bBack ? nNum<nAnz : nNum>0) && nRet==SDRGLUEPOINT_NOTFOUND) {
355cdf0e10cSrcweir 		if (!bBack) nNum--;
356cdf0e10cSrcweir 		const SdrGluePoint* pGP=GetObject(nNum);
357cdf0e10cSrcweir 		if (bNext) {
358cdf0e10cSrcweir 			if (pGP->GetId()==nId0) bNext=sal_False;
359cdf0e10cSrcweir 		} else {
360cdf0e10cSrcweir 			if (pGP->IsHit(rPnt,rOut,pObj)) nRet=nNum;
361cdf0e10cSrcweir 		}
362cdf0e10cSrcweir 		if (bBack) nNum++;
363cdf0e10cSrcweir 	}
364cdf0e10cSrcweir 	return nRet;
365cdf0e10cSrcweir }
366cdf0e10cSrcweir 
SetReallyAbsolute(FASTBOOL bOn,const SdrObject & rObj)367cdf0e10cSrcweir void SdrGluePointList::SetReallyAbsolute(FASTBOOL bOn, const SdrObject& rObj)
368cdf0e10cSrcweir {
369cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
370cdf0e10cSrcweir 	for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
371cdf0e10cSrcweir 		GetObject(nNum)->SetReallyAbsolute(bOn,rObj);
372cdf0e10cSrcweir 	}
373cdf0e10cSrcweir }
374cdf0e10cSrcweir 
Rotate(const Point & rRef,long nWink,double sn,double cs,const SdrObject * pObj)375cdf0e10cSrcweir void SdrGluePointList::Rotate(const Point& rRef, long nWink, double sn, double cs, const SdrObject* pObj)
376cdf0e10cSrcweir {
377cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
378cdf0e10cSrcweir 	for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
379cdf0e10cSrcweir 		GetObject(nNum)->Rotate(rRef,nWink,sn,cs,pObj);
380cdf0e10cSrcweir 	}
381cdf0e10cSrcweir }
382cdf0e10cSrcweir 
Mirror(const Point & rRef1,const Point & rRef2,const SdrObject * pObj)383cdf0e10cSrcweir void SdrGluePointList::Mirror(const Point& rRef1, const Point& rRef2, const SdrObject* pObj)
384cdf0e10cSrcweir {
385cdf0e10cSrcweir 	Point aPt(rRef2); aPt-=rRef1;
386cdf0e10cSrcweir 	long nWink=GetAngle(aPt);
387cdf0e10cSrcweir 	Mirror(rRef1,rRef2,nWink,pObj);
388cdf0e10cSrcweir }
389cdf0e10cSrcweir 
Mirror(const Point & rRef1,const Point & rRef2,long nWink,const SdrObject * pObj)390cdf0e10cSrcweir void SdrGluePointList::Mirror(const Point& rRef1, const Point& rRef2, long nWink, const SdrObject* pObj)
391cdf0e10cSrcweir {
392cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
393cdf0e10cSrcweir 	for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
394cdf0e10cSrcweir 		GetObject(nNum)->Mirror(rRef1,rRef2,nWink,pObj);
395cdf0e10cSrcweir 	}
396cdf0e10cSrcweir }
397cdf0e10cSrcweir 
Shear(const Point & rRef,long nWink,double tn,FASTBOOL bVShear,const SdrObject * pObj)398cdf0e10cSrcweir void SdrGluePointList::Shear(const Point& rRef, long nWink, double tn, FASTBOOL bVShear, const SdrObject* pObj)
399cdf0e10cSrcweir {
400cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
401cdf0e10cSrcweir 	for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
402cdf0e10cSrcweir 		GetObject(nNum)->Shear(rRef,nWink,tn,bVShear,pObj);
403cdf0e10cSrcweir 	}
404cdf0e10cSrcweir }
405cdf0e10cSrcweir 
406*330b556eSmseidel /* vim: set noet sw=4 ts=4: */
407