xref: /trunk/main/svx/source/svdraw/svdglue.cxx (revision f6e50924346d0b8c0b07c91832a97665dd718b0c)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew 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 
34cdf0e10cSrcweir void SdrGluePoint::SetReallyAbsolute(FASTBOOL bOn, const SdrObject& rObj)
35cdf0e10cSrcweir {
36cdf0e10cSrcweir     if ( bReallyAbsolute != bOn )
37cdf0e10cSrcweir     {
38cdf0e10cSrcweir        if ( bOn )
39cdf0e10cSrcweir        {
40cdf0e10cSrcweir            aPos=GetAbsolutePos(rObj);
41cdf0e10cSrcweir            bReallyAbsolute=bOn;
42cdf0e10cSrcweir        }
43cdf0e10cSrcweir        else
44cdf0e10cSrcweir        {
45cdf0e10cSrcweir            bReallyAbsolute=bOn;
46cdf0e10cSrcweir            Point aPt(aPos);
47cdf0e10cSrcweir            SetAbsolutePos(aPt,rObj);
48cdf0e10cSrcweir        }
49cdf0e10cSrcweir     }
50cdf0e10cSrcweir }
51cdf0e10cSrcweir 
52cdf0e10cSrcweir Point SdrGluePoint::GetAbsolutePos(const SdrObject& rObj) const
53cdf0e10cSrcweir {
54cdf0e10cSrcweir     if (bReallyAbsolute) return aPos;
55cdf0e10cSrcweir     Rectangle aSnap(rObj.GetSnapRect());
56cdf0e10cSrcweir     Rectangle aBound(rObj.GetSnapRect());
57cdf0e10cSrcweir     Point aPt(aPos);
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     Point aOfs(aSnap.Center());
60cdf0e10cSrcweir     switch (GetHorzAlign()) {
61cdf0e10cSrcweir         case SDRHORZALIGN_LEFT  : aOfs.X()=aSnap.Left(); break;
62cdf0e10cSrcweir         case SDRHORZALIGN_RIGHT : aOfs.X()=aSnap.Right(); break;
63cdf0e10cSrcweir     }
64cdf0e10cSrcweir     switch (GetVertAlign()) {
65cdf0e10cSrcweir         case SDRVERTALIGN_TOP   : aOfs.Y()=aSnap.Top(); break;
66cdf0e10cSrcweir         case SDRVERTALIGN_BOTTOM: aOfs.Y()=aSnap.Bottom(); break;
67cdf0e10cSrcweir     }
68cdf0e10cSrcweir     if (!bNoPercent) {
69cdf0e10cSrcweir         long nXMul=aSnap.Right()-aSnap.Left();
70cdf0e10cSrcweir         long nYMul=aSnap.Bottom()-aSnap.Top();
71cdf0e10cSrcweir         long nXDiv=10000;
72cdf0e10cSrcweir         long nYDiv=10000;
73cdf0e10cSrcweir         if (nXMul!=nXDiv) {
74cdf0e10cSrcweir             aPt.X()*=nXMul;
75cdf0e10cSrcweir             aPt.X()/=nXDiv;
76cdf0e10cSrcweir         }
77cdf0e10cSrcweir         if (nYMul!=nYDiv) {
78cdf0e10cSrcweir             aPt.Y()*=nYMul;
79cdf0e10cSrcweir             aPt.Y()/=nYDiv;
80cdf0e10cSrcweir         }
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir     aPt+=aOfs;
83cdf0e10cSrcweir     // Und nun auf's BoundRect des Objekts begrenzen
84cdf0e10cSrcweir     if (aPt.X()<aBound.Left  ()) aPt.X()=aBound.Left  ();
85cdf0e10cSrcweir     if (aPt.X()>aBound.Right ()) aPt.X()=aBound.Right ();
86cdf0e10cSrcweir     if (aPt.Y()<aBound.Top   ()) aPt.Y()=aBound.Top   ();
87cdf0e10cSrcweir     if (aPt.Y()>aBound.Bottom()) aPt.Y()=aBound.Bottom();
88cdf0e10cSrcweir     return aPt;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir void SdrGluePoint::SetAbsolutePos(const Point& rNewPos, const SdrObject& rObj)
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     if (bReallyAbsolute) {
94cdf0e10cSrcweir         aPos=rNewPos;
95cdf0e10cSrcweir         return;
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir     Rectangle aSnap(rObj.GetSnapRect());
98cdf0e10cSrcweir     Point aPt(rNewPos);
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     Point aOfs(aSnap.Center());
101cdf0e10cSrcweir     switch (GetHorzAlign()) {
102cdf0e10cSrcweir         case SDRHORZALIGN_LEFT  : aOfs.X()=aSnap.Left(); break;
103cdf0e10cSrcweir         case SDRHORZALIGN_RIGHT : aOfs.X()=aSnap.Right(); break;
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir     switch (GetVertAlign()) {
106cdf0e10cSrcweir         case SDRVERTALIGN_TOP   : aOfs.Y()=aSnap.Top(); break;
107cdf0e10cSrcweir         case SDRVERTALIGN_BOTTOM: aOfs.Y()=aSnap.Bottom(); break;
108cdf0e10cSrcweir     }
109cdf0e10cSrcweir     aPt-=aOfs;
110cdf0e10cSrcweir     if (!bNoPercent) {
111cdf0e10cSrcweir         long nXMul=aSnap.Right()-aSnap.Left();
112cdf0e10cSrcweir         long nYMul=aSnap.Bottom()-aSnap.Top();
113cdf0e10cSrcweir         if (nXMul==0) nXMul=1;
114cdf0e10cSrcweir         if (nYMul==0) nYMul=1;
115cdf0e10cSrcweir         long nXDiv=10000;
116cdf0e10cSrcweir         long nYDiv=10000;
117cdf0e10cSrcweir         if (nXMul!=nXDiv) {
118cdf0e10cSrcweir             aPt.X()*=nXDiv;
119cdf0e10cSrcweir             aPt.X()/=nXMul;
120cdf0e10cSrcweir         }
121cdf0e10cSrcweir         if (nYMul!=nYDiv) {
122cdf0e10cSrcweir             aPt.Y()*=nYDiv;
123cdf0e10cSrcweir             aPt.Y()/=nYMul;
124cdf0e10cSrcweir         }
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir     aPos=aPt;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir long SdrGluePoint::GetAlignAngle() const
130cdf0e10cSrcweir {
131cdf0e10cSrcweir     switch (nAlign) {
132cdf0e10cSrcweir         case SDRHORZALIGN_CENTER|SDRVERTALIGN_CENTER: return 0; // Invalid!
133cdf0e10cSrcweir         case SDRHORZALIGN_RIGHT |SDRVERTALIGN_CENTER: return 0;
134cdf0e10cSrcweir         case SDRHORZALIGN_RIGHT |SDRVERTALIGN_TOP   : return 4500;
135cdf0e10cSrcweir         case SDRHORZALIGN_CENTER|SDRVERTALIGN_TOP   : return 9000;
136cdf0e10cSrcweir         case SDRHORZALIGN_LEFT  |SDRVERTALIGN_TOP   : return 13500;
137cdf0e10cSrcweir         case SDRHORZALIGN_LEFT  |SDRVERTALIGN_CENTER: return 18000;
138cdf0e10cSrcweir         case SDRHORZALIGN_LEFT  |SDRVERTALIGN_BOTTOM: return 22500;
139cdf0e10cSrcweir         case SDRHORZALIGN_CENTER|SDRVERTALIGN_BOTTOM: return 27000;
140cdf0e10cSrcweir         case SDRHORZALIGN_RIGHT |SDRVERTALIGN_BOTTOM: return 31500;
141cdf0e10cSrcweir     } // switch
142cdf0e10cSrcweir     return 0;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir void SdrGluePoint::SetAlignAngle(long nWink)
146cdf0e10cSrcweir {
147cdf0e10cSrcweir     nWink=NormAngle360(nWink);
148cdf0e10cSrcweir     if (nWink>=33750 || nWink<2250) nAlign=SDRHORZALIGN_RIGHT |SDRVERTALIGN_CENTER;
149cdf0e10cSrcweir     else if (nWink< 6750) nAlign=SDRHORZALIGN_RIGHT |SDRVERTALIGN_TOP   ;
150cdf0e10cSrcweir     else if (nWink<11250) nAlign=SDRHORZALIGN_CENTER|SDRVERTALIGN_TOP   ;
151cdf0e10cSrcweir     else if (nWink<15750) nAlign=SDRHORZALIGN_LEFT  |SDRVERTALIGN_TOP   ;
152cdf0e10cSrcweir     else if (nWink<20250) nAlign=SDRHORZALIGN_LEFT  |SDRVERTALIGN_CENTER;
153cdf0e10cSrcweir     else if (nWink<24750) nAlign=SDRHORZALIGN_LEFT  |SDRVERTALIGN_BOTTOM;
154cdf0e10cSrcweir     else if (nWink<29250) nAlign=SDRHORZALIGN_CENTER|SDRVERTALIGN_BOTTOM;
155cdf0e10cSrcweir     else if (nWink<33750) nAlign=SDRHORZALIGN_RIGHT |SDRVERTALIGN_BOTTOM;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir long SdrGluePoint::EscDirToAngle(sal_uInt16 nEsc) const
159cdf0e10cSrcweir {
160cdf0e10cSrcweir     switch (nEsc) {
161cdf0e10cSrcweir         case SDRESC_RIGHT : return 0;
162cdf0e10cSrcweir         case SDRESC_TOP   : return 9000;
163cdf0e10cSrcweir         case SDRESC_LEFT  : return 18000;
164cdf0e10cSrcweir         case SDRESC_BOTTOM: return 27000;
165cdf0e10cSrcweir     } // switch
166cdf0e10cSrcweir     return 0;
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir sal_uInt16 SdrGluePoint::EscAngleToDir(long nWink) const
170cdf0e10cSrcweir {
171cdf0e10cSrcweir     nWink=NormAngle360(nWink);
172cdf0e10cSrcweir     if (nWink>=31500 || nWink<4500) return SDRESC_RIGHT;
173cdf0e10cSrcweir     if (nWink<13500) return SDRESC_TOP;
174cdf0e10cSrcweir     if (nWink<22500) return SDRESC_LEFT;
175cdf0e10cSrcweir     if (nWink<31500) return SDRESC_BOTTOM;
176cdf0e10cSrcweir     return 0;
177cdf0e10cSrcweir }
178cdf0e10cSrcweir 
179cdf0e10cSrcweir void SdrGluePoint::Rotate(const Point& rRef, long nWink, double sn, double cs, const SdrObject* pObj)
180cdf0e10cSrcweir {
181cdf0e10cSrcweir     Point aPt(pObj!=NULL ? GetAbsolutePos(*pObj) : GetPos());
182cdf0e10cSrcweir     RotatePoint(aPt,rRef,sn,cs);
183cdf0e10cSrcweir     // Bezugskante drehen
184cdf0e10cSrcweir     if(nAlign != (SDRHORZALIGN_CENTER|SDRVERTALIGN_CENTER))
185cdf0e10cSrcweir     {
186cdf0e10cSrcweir         SetAlignAngle(GetAlignAngle()+nWink);
187cdf0e10cSrcweir     }
188cdf0e10cSrcweir     // Austrittsrichtungen drehen
189cdf0e10cSrcweir     sal_uInt16 nEscDir0=nEscDir;
190cdf0e10cSrcweir     sal_uInt16 nEscDir1=0;
191cdf0e10cSrcweir     if ((nEscDir0&SDRESC_LEFT  )!=0) nEscDir1|=EscAngleToDir(EscDirToAngle(SDRESC_LEFT  )+nWink);
192cdf0e10cSrcweir     if ((nEscDir0&SDRESC_TOP   )!=0) nEscDir1|=EscAngleToDir(EscDirToAngle(SDRESC_TOP   )+nWink);
193cdf0e10cSrcweir     if ((nEscDir0&SDRESC_RIGHT )!=0) nEscDir1|=EscAngleToDir(EscDirToAngle(SDRESC_RIGHT )+nWink);
194cdf0e10cSrcweir     if ((nEscDir0&SDRESC_BOTTOM)!=0) nEscDir1|=EscAngleToDir(EscDirToAngle(SDRESC_BOTTOM)+nWink);
195cdf0e10cSrcweir     nEscDir=nEscDir1;
196cdf0e10cSrcweir     if (pObj!=NULL) SetAbsolutePos(aPt,*pObj); else SetPos(aPt);
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir void SdrGluePoint::Mirror(const Point& rRef1, const Point& rRef2, const SdrObject* pObj)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir     Point aPt(rRef2); aPt-=rRef1;
202cdf0e10cSrcweir     long nWink=GetAngle(aPt);
203cdf0e10cSrcweir     Mirror(rRef1,rRef2,nWink,pObj);
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir void SdrGluePoint::Mirror(const Point& rRef1, const Point& rRef2, long nWink, const SdrObject* pObj)
207cdf0e10cSrcweir {
208cdf0e10cSrcweir     Point aPt(pObj!=NULL ? GetAbsolutePos(*pObj) : GetPos());
209cdf0e10cSrcweir     MirrorPoint(aPt,rRef1,rRef2);
210cdf0e10cSrcweir     // Bezugskante spiegeln
211cdf0e10cSrcweir     if(nAlign != (SDRHORZALIGN_CENTER|SDRVERTALIGN_CENTER))
212cdf0e10cSrcweir     {
213cdf0e10cSrcweir         long nAW=GetAlignAngle();
214cdf0e10cSrcweir         nAW+=2*(nWink-nAW);
215cdf0e10cSrcweir         SetAlignAngle(nAW);
216cdf0e10cSrcweir     }
217cdf0e10cSrcweir     // Austrittsrichtungen spiegeln
218cdf0e10cSrcweir     sal_uInt16 nEscDir0=nEscDir;
219cdf0e10cSrcweir     sal_uInt16 nEscDir1=0;
220cdf0e10cSrcweir     if ((nEscDir0&SDRESC_LEFT)!=0) {
221cdf0e10cSrcweir         long nEW=EscDirToAngle(SDRESC_LEFT);
222cdf0e10cSrcweir         nEW+=2*(nWink-nEW);
223cdf0e10cSrcweir         nEscDir1|=EscAngleToDir(nEW);
224cdf0e10cSrcweir     }
225cdf0e10cSrcweir     if ((nEscDir0&SDRESC_TOP)!=0) {
226cdf0e10cSrcweir         long nEW=EscDirToAngle(SDRESC_TOP);
227cdf0e10cSrcweir         nEW+=2*(nWink-nEW);
228cdf0e10cSrcweir         nEscDir1|=EscAngleToDir(nEW);
229cdf0e10cSrcweir     }
230cdf0e10cSrcweir     if ((nEscDir0&SDRESC_RIGHT)!=0) {
231cdf0e10cSrcweir         long nEW=EscDirToAngle(SDRESC_RIGHT);
232cdf0e10cSrcweir         nEW+=2*(nWink-nEW);
233cdf0e10cSrcweir         nEscDir1|=EscAngleToDir(nEW);
234cdf0e10cSrcweir     }
235cdf0e10cSrcweir     if ((nEscDir0&SDRESC_BOTTOM)!=0) {
236cdf0e10cSrcweir         long nEW=EscDirToAngle(SDRESC_BOTTOM);
237cdf0e10cSrcweir         nEW+=2*(nWink-nEW);
238cdf0e10cSrcweir         nEscDir1|=EscAngleToDir(nEW);
239cdf0e10cSrcweir     }
240cdf0e10cSrcweir     nEscDir=nEscDir1;
241cdf0e10cSrcweir     if (pObj!=NULL) SetAbsolutePos(aPt,*pObj); else SetPos(aPt);
242cdf0e10cSrcweir }
243cdf0e10cSrcweir 
244cdf0e10cSrcweir void SdrGluePoint::Shear(const Point& rRef, long /*nWink*/, double tn, FASTBOOL bVShear, const SdrObject* pObj)
245cdf0e10cSrcweir {
246cdf0e10cSrcweir     Point aPt(pObj!=NULL ? GetAbsolutePos(*pObj) : GetPos());
247cdf0e10cSrcweir     ShearPoint(aPt,rRef,tn,bVShear);
248cdf0e10cSrcweir     if (pObj!=NULL) SetAbsolutePos(aPt,*pObj); else SetPos(aPt);
249cdf0e10cSrcweir }
250cdf0e10cSrcweir 
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);
295cdf0e10cSrcweir     long x=aPt.X(),y=aPt.Y(); // Groesse erstmal fest auf 7 Pixel
296cdf0e10cSrcweir 
297cdf0e10cSrcweir     // #111096#
298cdf0e10cSrcweir     // do not erase background, that causes flicker (!)
299cdf0e10cSrcweir     rWin.Invalidate(Rectangle(Point(x-3,y-3),Point(x+3,y+3)), 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());
307cdf0e10cSrcweir     Size aSiz=rOut.PixelToLogic(Size(3,3));
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 
314cdf0e10cSrcweir void SdrGluePointList::Clear()
315cdf0e10cSrcweir {
316cdf0e10cSrcweir     sal_uInt16 nAnz=GetCount();
317cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
318cdf0e10cSrcweir         delete GetObject(i);
319cdf0e10cSrcweir     }
320cdf0e10cSrcweir     aList.Clear();
321cdf0e10cSrcweir }
322cdf0e10cSrcweir 
323cdf0e10cSrcweir void SdrGluePointList::operator=(const SdrGluePointList& rSrcList)
324cdf0e10cSrcweir {
325cdf0e10cSrcweir     if (GetCount()!=0) Clear();
326cdf0e10cSrcweir     sal_uInt16 nAnz=rSrcList.GetCount();
327cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
328cdf0e10cSrcweir         Insert(rSrcList[i]);
329cdf0e10cSrcweir     }
330cdf0e10cSrcweir }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir // Die Id's der Klebepunkte in der Liste sind stets streng monoton steigend!
333cdf0e10cSrcweir // Ggf. wird dem neuen Klebepunkt eine neue Id zugewiesen (wenn diese bereits
334cdf0e10cSrcweir // vergeben ist). Die Id 0 ist reserviert.
335cdf0e10cSrcweir sal_uInt16 SdrGluePointList::Insert(const SdrGluePoint& rGP)
336cdf0e10cSrcweir {
337cdf0e10cSrcweir     SdrGluePoint* pGP=new SdrGluePoint(rGP);
338cdf0e10cSrcweir     sal_uInt16 nId=pGP->GetId();
339cdf0e10cSrcweir     sal_uInt16 nAnz=GetCount();
340cdf0e10cSrcweir     sal_uInt16 nInsPos=nAnz;
341cdf0e10cSrcweir     sal_uInt16 nLastId=nAnz!=0 ? GetObject(nAnz-1)->GetId() : 0;
342cdf0e10cSrcweir     DBG_ASSERT(nLastId>=nAnz,"SdrGluePointList::Insert(): nLastId<nAnz");
343cdf0e10cSrcweir     FASTBOOL bHole=nLastId>nAnz;
344cdf0e10cSrcweir     if (nId<=nLastId) {
345cdf0e10cSrcweir         if (!bHole || nId==0) {
346cdf0e10cSrcweir             nId=nLastId+1;
347cdf0e10cSrcweir         } else {
348cdf0e10cSrcweir             FASTBOOL bBrk=sal_False;
349cdf0e10cSrcweir             for (sal_uInt16 nNum=0; nNum<nAnz && !bBrk; nNum++) {
350cdf0e10cSrcweir                 const SdrGluePoint* pGP2=GetObject(nNum);
351cdf0e10cSrcweir                 sal_uInt16 nTmpId=pGP2->GetId();
352cdf0e10cSrcweir                 if (nTmpId==nId) {
353cdf0e10cSrcweir                     nId=nLastId+1; // bereits vorhanden
354cdf0e10cSrcweir                     bBrk=sal_True;
355cdf0e10cSrcweir                 }
356cdf0e10cSrcweir                 if (nTmpId>nId) {
357cdf0e10cSrcweir                     nInsPos=nNum; // Hier einfuegen (einsortieren)
358cdf0e10cSrcweir                     bBrk=sal_True;
359cdf0e10cSrcweir                 }
360cdf0e10cSrcweir             }
361cdf0e10cSrcweir         }
362cdf0e10cSrcweir         pGP->SetId(nId);
363cdf0e10cSrcweir     }
364cdf0e10cSrcweir     aList.Insert(pGP,nInsPos);
365cdf0e10cSrcweir     return nInsPos;
366cdf0e10cSrcweir }
367cdf0e10cSrcweir 
368cdf0e10cSrcweir void SdrGluePointList::Invalidate(Window& rWin, const SdrObject* pObj) const
369cdf0e10cSrcweir {
370cdf0e10cSrcweir     sal_uInt16 nAnz=GetCount();
371cdf0e10cSrcweir     for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
372cdf0e10cSrcweir         GetObject(nNum)->Invalidate(rWin,pObj);
373cdf0e10cSrcweir     }
374cdf0e10cSrcweir }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir sal_uInt16 SdrGluePointList::FindGluePoint(sal_uInt16 nId) const
377cdf0e10cSrcweir {
378cdf0e10cSrcweir     // Hier noch einen optimaleren Suchalgorithmus implementieren.
379cdf0e10cSrcweir     // Die Liste sollte stets sortiert sein!!!!
380cdf0e10cSrcweir     sal_uInt16 nAnz=GetCount();
381cdf0e10cSrcweir     sal_uInt16 nRet=SDRGLUEPOINT_NOTFOUND;
382cdf0e10cSrcweir     for (sal_uInt16 nNum=0; nNum<nAnz && nRet==SDRGLUEPOINT_NOTFOUND; nNum++) {
383cdf0e10cSrcweir         const SdrGluePoint* pGP=GetObject(nNum);
384cdf0e10cSrcweir         if (pGP->GetId()==nId) nRet=nNum;
385cdf0e10cSrcweir     }
386cdf0e10cSrcweir     return nRet;
387cdf0e10cSrcweir }
388cdf0e10cSrcweir 
389cdf0e10cSrcweir sal_uInt16 SdrGluePointList::HitTest(const Point& rPnt, const OutputDevice& rOut, const SdrObject* pObj, FASTBOOL bBack, FASTBOOL bNext, sal_uInt16 nId0) const
390cdf0e10cSrcweir {
391cdf0e10cSrcweir     sal_uInt16 nAnz=GetCount();
392cdf0e10cSrcweir     sal_uInt16 nRet=SDRGLUEPOINT_NOTFOUND;
393cdf0e10cSrcweir     sal_uInt16 nNum=bBack ? 0 : nAnz;
394cdf0e10cSrcweir     while ((bBack ? nNum<nAnz : nNum>0) && nRet==SDRGLUEPOINT_NOTFOUND) {
395cdf0e10cSrcweir         if (!bBack) nNum--;
396cdf0e10cSrcweir         const SdrGluePoint* pGP=GetObject(nNum);
397cdf0e10cSrcweir         if (bNext) {
398cdf0e10cSrcweir             if (pGP->GetId()==nId0) bNext=sal_False;
399cdf0e10cSrcweir         } else {
400cdf0e10cSrcweir             if (pGP->IsHit(rPnt,rOut,pObj)) nRet=nNum;
401cdf0e10cSrcweir         }
402cdf0e10cSrcweir         if (bBack) nNum++;
403cdf0e10cSrcweir     }
404cdf0e10cSrcweir     return nRet;
405cdf0e10cSrcweir }
406cdf0e10cSrcweir 
407cdf0e10cSrcweir void SdrGluePointList::SetReallyAbsolute(FASTBOOL bOn, const SdrObject& rObj)
408cdf0e10cSrcweir {
409cdf0e10cSrcweir     sal_uInt16 nAnz=GetCount();
410cdf0e10cSrcweir     for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
411cdf0e10cSrcweir         GetObject(nNum)->SetReallyAbsolute(bOn,rObj);
412cdf0e10cSrcweir     }
413cdf0e10cSrcweir }
414cdf0e10cSrcweir 
415cdf0e10cSrcweir void SdrGluePointList::Rotate(const Point& rRef, long nWink, double sn, double cs, const SdrObject* pObj)
416cdf0e10cSrcweir {
417cdf0e10cSrcweir     sal_uInt16 nAnz=GetCount();
418cdf0e10cSrcweir     for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
419cdf0e10cSrcweir         GetObject(nNum)->Rotate(rRef,nWink,sn,cs,pObj);
420cdf0e10cSrcweir     }
421cdf0e10cSrcweir }
422cdf0e10cSrcweir 
423cdf0e10cSrcweir void SdrGluePointList::Mirror(const Point& rRef1, const Point& rRef2, const SdrObject* pObj)
424cdf0e10cSrcweir {
425cdf0e10cSrcweir     Point aPt(rRef2); aPt-=rRef1;
426cdf0e10cSrcweir     long nWink=GetAngle(aPt);
427cdf0e10cSrcweir     Mirror(rRef1,rRef2,nWink,pObj);
428cdf0e10cSrcweir }
429cdf0e10cSrcweir 
430cdf0e10cSrcweir void SdrGluePointList::Mirror(const Point& rRef1, const Point& rRef2, long nWink, const SdrObject* pObj)
431cdf0e10cSrcweir {
432cdf0e10cSrcweir     sal_uInt16 nAnz=GetCount();
433cdf0e10cSrcweir     for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
434cdf0e10cSrcweir         GetObject(nNum)->Mirror(rRef1,rRef2,nWink,pObj);
435cdf0e10cSrcweir     }
436cdf0e10cSrcweir }
437cdf0e10cSrcweir 
438cdf0e10cSrcweir void SdrGluePointList::Shear(const Point& rRef, long nWink, double tn, FASTBOOL bVShear, const SdrObject* pObj)
439cdf0e10cSrcweir {
440cdf0e10cSrcweir     sal_uInt16 nAnz=GetCount();
441cdf0e10cSrcweir     for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
442cdf0e10cSrcweir         GetObject(nNum)->Shear(rRef,nWink,tn,bVShear,pObj);
443cdf0e10cSrcweir     }
444cdf0e10cSrcweir }
445cdf0e10cSrcweir 
446cdf0e10cSrcweir // eof
447