xref: /AOO41X/main/svx/source/svdraw/svdglue.cxx (revision 330b556ef3b61775790d8c8a17a4c7863e4a22ad)
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 
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 
51cdf0e10cSrcweir 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 
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 
128cdf0e10cSrcweir 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 
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 
157cdf0e10cSrcweir 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 
168cdf0e10cSrcweir 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 
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 
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 
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 
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 
250*330b556eSmseidel // Unused code?!
251cdf0e10cSrcweir void SdrGluePoint::Draw(OutputDevice& rOut, const SdrObject* pObj) const
252cdf0e10cSrcweir {
253cdf0e10cSrcweir 	Color aBackPenColor(COL_WHITE);
254cdf0e10cSrcweir 	Color aForePenColor(COL_LIGHTBLUE);
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 	bool bMapMerk=rOut.IsMapModeEnabled();
257cdf0e10cSrcweir 	Point aPt(pObj!=NULL ? GetAbsolutePos(*pObj) : GetPos());
258cdf0e10cSrcweir 	aPt=rOut.LogicToPixel(aPt);
259cdf0e10cSrcweir 	rOut.EnableMapMode(sal_False);
260cdf0e10cSrcweir 	long x=aPt.X(),y=aPt.Y(); // Groesse erstmal fest auf 7 Pixel
261cdf0e10cSrcweir 
262cdf0e10cSrcweir 	rOut.SetLineColor( aBackPenColor );
263cdf0e10cSrcweir 	rOut.DrawLine(Point(x-2,y-3),Point(x+3,y+2));
264cdf0e10cSrcweir 	rOut.DrawLine(Point(x-3,y-2),Point(x+2,y+3));
265cdf0e10cSrcweir 	rOut.DrawLine(Point(x-3,y+2),Point(x+2,y-3));
266cdf0e10cSrcweir 	rOut.DrawLine(Point(x-2,y+3),Point(x+3,y-2));
267cdf0e10cSrcweir 
268cdf0e10cSrcweir 	if (bNoPercent)
269cdf0e10cSrcweir 	{
270cdf0e10cSrcweir 		switch (GetHorzAlign())
271cdf0e10cSrcweir 		{
272cdf0e10cSrcweir 			case SDRHORZALIGN_LEFT  : rOut.DrawLine(Point(x-3,y-1),Point(x-3,y+1)); break;
273cdf0e10cSrcweir 			case SDRHORZALIGN_RIGHT : rOut.DrawLine(Point(x+3,y-1),Point(x+3,y+1)); break;
274cdf0e10cSrcweir 		}
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 		switch (GetVertAlign())
277cdf0e10cSrcweir 		{
278cdf0e10cSrcweir 			case SDRVERTALIGN_TOP   : rOut.DrawLine(Point(x-1,y-3),Point(x+1,y-3)); break;
279cdf0e10cSrcweir 			case SDRVERTALIGN_BOTTOM: rOut.DrawLine(Point(x-1,y+3),Point(x+1,y+3)); break;
280cdf0e10cSrcweir 		}
281cdf0e10cSrcweir 	}
282cdf0e10cSrcweir 
283cdf0e10cSrcweir 	rOut.SetLineColor( aForePenColor );
284cdf0e10cSrcweir 	rOut.DrawLine(Point(x-2,y-2),Point(x+2,y+2));
285cdf0e10cSrcweir 	rOut.DrawLine(Point(x-2,y+2),Point(x+2,y-2));
286cdf0e10cSrcweir 	rOut.EnableMapMode(bMapMerk);
287cdf0e10cSrcweir }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir void SdrGluePoint::Invalidate(Window& rWin, const SdrObject* pObj) const
290cdf0e10cSrcweir {
291cdf0e10cSrcweir 	bool bMapMerk=rWin.IsMapModeEnabled();
292cdf0e10cSrcweir 	Point aPt(pObj!=NULL ? GetAbsolutePos(*pObj) : GetPos());
293cdf0e10cSrcweir 	aPt=rWin.LogicToPixel(aPt);
294cdf0e10cSrcweir 	rWin.EnableMapMode(sal_False);
295*330b556eSmseidel 	long x=aPt.X(),y=aPt.Y(); // size 9x9 pixel
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 	// #111096#
298cdf0e10cSrcweir 	// do not erase background, that causes flicker (!)
299*330b556eSmseidel 	rWin.Invalidate(Rectangle(Point(x-4,y-4),Point(x+4,y+4)), INVALIDATE_NOERASE);
300cdf0e10cSrcweir 
301cdf0e10cSrcweir 	rWin.EnableMapMode(bMapMerk);
302cdf0e10cSrcweir }
303cdf0e10cSrcweir 
304cdf0e10cSrcweir FASTBOOL SdrGluePoint::IsHit(const Point& rPnt, const OutputDevice& rOut, const SdrObject* pObj) const
305cdf0e10cSrcweir {
306cdf0e10cSrcweir 	Point aPt(pObj!=NULL ? GetAbsolutePos(*pObj) : GetPos());
307*330b556eSmseidel 	Size aSiz=rOut.PixelToLogic(Size(4,4));
308cdf0e10cSrcweir 	Rectangle aRect(aPt.X()-aSiz.Width(),aPt.Y()-aSiz.Height(),aPt.X()+aSiz.Width(),aPt.Y()+aSiz.Height());
309cdf0e10cSrcweir 	return aRect.IsInside(rPnt);
310cdf0e10cSrcweir }
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 
313cdf0e10cSrcweir void SdrGluePointList::Clear()
314cdf0e10cSrcweir {
315cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
316cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<nAnz; i++) {
317cdf0e10cSrcweir 		delete GetObject(i);
318cdf0e10cSrcweir 	}
319cdf0e10cSrcweir 	aList.Clear();
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir void SdrGluePointList::operator=(const SdrGluePointList& rSrcList)
323cdf0e10cSrcweir {
324cdf0e10cSrcweir 	if (GetCount()!=0) Clear();
325cdf0e10cSrcweir 	sal_uInt16 nAnz=rSrcList.GetCount();
326cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<nAnz; i++) {
327cdf0e10cSrcweir 		Insert(rSrcList[i]);
328cdf0e10cSrcweir 	}
329cdf0e10cSrcweir }
330cdf0e10cSrcweir 
331cdf0e10cSrcweir // Die Id's der Klebepunkte in der Liste sind stets streng monoton steigend!
332cdf0e10cSrcweir // Ggf. wird dem neuen Klebepunkt eine neue Id zugewiesen (wenn diese bereits
333cdf0e10cSrcweir // vergeben ist). Die Id 0 ist reserviert.
334cdf0e10cSrcweir sal_uInt16 SdrGluePointList::Insert(const SdrGluePoint& rGP)
335cdf0e10cSrcweir {
336cdf0e10cSrcweir 	SdrGluePoint* pGP=new SdrGluePoint(rGP);
337cdf0e10cSrcweir 	sal_uInt16 nId=pGP->GetId();
338cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
339cdf0e10cSrcweir 	sal_uInt16 nInsPos=nAnz;
340cdf0e10cSrcweir 	sal_uInt16 nLastId=nAnz!=0 ? GetObject(nAnz-1)->GetId() : 0;
341cdf0e10cSrcweir 	DBG_ASSERT(nLastId>=nAnz,"SdrGluePointList::Insert(): nLastId<nAnz");
342cdf0e10cSrcweir 	FASTBOOL bHole=nLastId>nAnz;
343cdf0e10cSrcweir 	if (nId<=nLastId) {
344cdf0e10cSrcweir 		if (!bHole || nId==0) {
345cdf0e10cSrcweir 			nId=nLastId+1;
346cdf0e10cSrcweir 		} else {
347cdf0e10cSrcweir 			FASTBOOL bBrk=sal_False;
348cdf0e10cSrcweir 			for (sal_uInt16 nNum=0; nNum<nAnz && !bBrk; nNum++) {
349cdf0e10cSrcweir 				const SdrGluePoint* pGP2=GetObject(nNum);
350cdf0e10cSrcweir 				sal_uInt16 nTmpId=pGP2->GetId();
351cdf0e10cSrcweir 				if (nTmpId==nId) {
352cdf0e10cSrcweir 					nId=nLastId+1; // bereits vorhanden
353cdf0e10cSrcweir 					bBrk=sal_True;
354cdf0e10cSrcweir 				}
355cdf0e10cSrcweir 				if (nTmpId>nId) {
356cdf0e10cSrcweir 					nInsPos=nNum; // Hier einfuegen (einsortieren)
357cdf0e10cSrcweir 					bBrk=sal_True;
358cdf0e10cSrcweir 				}
359cdf0e10cSrcweir 			}
360cdf0e10cSrcweir 		}
361cdf0e10cSrcweir 		pGP->SetId(nId);
362cdf0e10cSrcweir 	}
363cdf0e10cSrcweir 	aList.Insert(pGP,nInsPos);
364cdf0e10cSrcweir 	return nInsPos;
365cdf0e10cSrcweir }
366cdf0e10cSrcweir 
367cdf0e10cSrcweir void SdrGluePointList::Invalidate(Window& rWin, const SdrObject* pObj) const
368cdf0e10cSrcweir {
369cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
370cdf0e10cSrcweir 	for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
371cdf0e10cSrcweir 		GetObject(nNum)->Invalidate(rWin,pObj);
372cdf0e10cSrcweir 	}
373cdf0e10cSrcweir }
374cdf0e10cSrcweir 
375cdf0e10cSrcweir sal_uInt16 SdrGluePointList::FindGluePoint(sal_uInt16 nId) const
376cdf0e10cSrcweir {
377*330b556eSmseidel 	// TODO: Hier noch einen optimaleren Suchalgorithmus implementieren.
378*330b556eSmseidel 	// Die Liste sollte stets sortiert sein!
379cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
380cdf0e10cSrcweir 	sal_uInt16 nRet=SDRGLUEPOINT_NOTFOUND;
381cdf0e10cSrcweir 	for (sal_uInt16 nNum=0; nNum<nAnz && nRet==SDRGLUEPOINT_NOTFOUND; nNum++) {
382cdf0e10cSrcweir 		const SdrGluePoint* pGP=GetObject(nNum);
383cdf0e10cSrcweir 		if (pGP->GetId()==nId) nRet=nNum;
384cdf0e10cSrcweir 	}
385cdf0e10cSrcweir 	return nRet;
386cdf0e10cSrcweir }
387cdf0e10cSrcweir 
388cdf0e10cSrcweir sal_uInt16 SdrGluePointList::HitTest(const Point& rPnt, const OutputDevice& rOut, const SdrObject* pObj, FASTBOOL bBack, FASTBOOL bNext, sal_uInt16 nId0) const
389cdf0e10cSrcweir {
390cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
391cdf0e10cSrcweir 	sal_uInt16 nRet=SDRGLUEPOINT_NOTFOUND;
392cdf0e10cSrcweir 	sal_uInt16 nNum=bBack ? 0 : nAnz;
393cdf0e10cSrcweir 	while ((bBack ? nNum<nAnz : nNum>0) && nRet==SDRGLUEPOINT_NOTFOUND) {
394cdf0e10cSrcweir 		if (!bBack) nNum--;
395cdf0e10cSrcweir 		const SdrGluePoint* pGP=GetObject(nNum);
396cdf0e10cSrcweir 		if (bNext) {
397cdf0e10cSrcweir 			if (pGP->GetId()==nId0) bNext=sal_False;
398cdf0e10cSrcweir 		} else {
399cdf0e10cSrcweir 			if (pGP->IsHit(rPnt,rOut,pObj)) nRet=nNum;
400cdf0e10cSrcweir 		}
401cdf0e10cSrcweir 		if (bBack) nNum++;
402cdf0e10cSrcweir 	}
403cdf0e10cSrcweir 	return nRet;
404cdf0e10cSrcweir }
405cdf0e10cSrcweir 
406cdf0e10cSrcweir void SdrGluePointList::SetReallyAbsolute(FASTBOOL bOn, const SdrObject& rObj)
407cdf0e10cSrcweir {
408cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
409cdf0e10cSrcweir 	for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
410cdf0e10cSrcweir 		GetObject(nNum)->SetReallyAbsolute(bOn,rObj);
411cdf0e10cSrcweir 	}
412cdf0e10cSrcweir }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir void SdrGluePointList::Rotate(const Point& rRef, long nWink, double sn, double cs, const SdrObject* pObj)
415cdf0e10cSrcweir {
416cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
417cdf0e10cSrcweir 	for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
418cdf0e10cSrcweir 		GetObject(nNum)->Rotate(rRef,nWink,sn,cs,pObj);
419cdf0e10cSrcweir 	}
420cdf0e10cSrcweir }
421cdf0e10cSrcweir 
422cdf0e10cSrcweir void SdrGluePointList::Mirror(const Point& rRef1, const Point& rRef2, const SdrObject* pObj)
423cdf0e10cSrcweir {
424cdf0e10cSrcweir 	Point aPt(rRef2); aPt-=rRef1;
425cdf0e10cSrcweir 	long nWink=GetAngle(aPt);
426cdf0e10cSrcweir 	Mirror(rRef1,rRef2,nWink,pObj);
427cdf0e10cSrcweir }
428cdf0e10cSrcweir 
429cdf0e10cSrcweir void SdrGluePointList::Mirror(const Point& rRef1, const Point& rRef2, long nWink, const SdrObject* pObj)
430cdf0e10cSrcweir {
431cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
432cdf0e10cSrcweir 	for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
433cdf0e10cSrcweir 		GetObject(nNum)->Mirror(rRef1,rRef2,nWink,pObj);
434cdf0e10cSrcweir 	}
435cdf0e10cSrcweir }
436cdf0e10cSrcweir 
437cdf0e10cSrcweir void SdrGluePointList::Shear(const Point& rRef, long nWink, double tn, FASTBOOL bVShear, const SdrObject* pObj)
438cdf0e10cSrcweir {
439cdf0e10cSrcweir 	sal_uInt16 nAnz=GetCount();
440cdf0e10cSrcweir 	for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
441cdf0e10cSrcweir 		GetObject(nNum)->Shear(rRef,nWink,tn,bVShear,pObj);
442cdf0e10cSrcweir 	}
443cdf0e10cSrcweir }
444cdf0e10cSrcweir 
445*330b556eSmseidel /* vim: set noet sw=4 ts=4: */
446