xref: /trunk/main/svx/source/svdraw/svdhlpln.cxx (revision f6e50924)
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/svdhlpln.hxx>
28 #include <tools/color.hxx>
29 
30 #include <vcl/outdev.hxx>
31 #include <vcl/window.hxx>
32 #include <tools/poly.hxx>
33 #include <vcl/lineinfo.hxx>
34 
35 ////////////////////////////////////////////////////////////////////////////////////////////////////
36 
GetPointer() const37 Pointer SdrHelpLine::GetPointer() const
38 {
39 	switch (eKind) {
40 		case SDRHELPLINE_VERTICAL  : return Pointer(POINTER_ESIZE);
41 		case SDRHELPLINE_HORIZONTAL: return Pointer(POINTER_SSIZE);
42 		default                    : return Pointer(POINTER_MOVE);
43 	} // switch
44 }
45 
IsHit(const Point & rPnt,sal_uInt16 nTolLog,const OutputDevice & rOut) const46 FASTBOOL SdrHelpLine::IsHit(const Point& rPnt, sal_uInt16 nTolLog, const OutputDevice& rOut) const
47 {
48 	Size a1Pix(rOut.PixelToLogic(Size(1,1)));
49 	FASTBOOL bXHit=rPnt.X()>=aPos.X()-nTolLog && rPnt.X()<=aPos.X()+nTolLog+a1Pix.Width();
50 	FASTBOOL bYHit=rPnt.Y()>=aPos.Y()-nTolLog && rPnt.Y()<=aPos.Y()+nTolLog+a1Pix.Height();
51 	switch (eKind) {
52 		case SDRHELPLINE_VERTICAL  : return bXHit;
53 		case SDRHELPLINE_HORIZONTAL: return bYHit;
54 		case SDRHELPLINE_POINT: {
55 			if (bXHit || bYHit) {
56 				Size aRad(rOut.PixelToLogic(Size(SDRHELPLINE_POINT_PIXELSIZE,SDRHELPLINE_POINT_PIXELSIZE)));
57 				return rPnt.X()>=aPos.X()-aRad.Width() && rPnt.X()<=aPos.X()+aRad.Width()+a1Pix.Width() &&
58 					   rPnt.Y()>=aPos.Y()-aRad.Height() && rPnt.Y()<=aPos.Y()+aRad.Height()+a1Pix.Height();
59 			}
60 		} break;
61 	} // switch
62 	return sal_False;
63 }
64 
GetBoundRect(const OutputDevice & rOut) const65 Rectangle SdrHelpLine::GetBoundRect(const OutputDevice& rOut) const
66 {
67 	Rectangle aRet(aPos,aPos);
68 	Point aOfs(rOut.GetMapMode().GetOrigin());
69 	Size aSiz(rOut.GetOutputSize());
70 	switch (eKind) {
71 		case SDRHELPLINE_VERTICAL  : aRet.Top()=-aOfs.Y(); aRet.Bottom()=-aOfs.Y()+aSiz.Height(); break;
72 		case SDRHELPLINE_HORIZONTAL: aRet.Left()=-aOfs.X(); aRet.Right()=-aOfs.X()+aSiz.Width();  break;
73 		case SDRHELPLINE_POINT     : {
74 			Size aRad(rOut.PixelToLogic(Size(SDRHELPLINE_POINT_PIXELSIZE,SDRHELPLINE_POINT_PIXELSIZE)));
75 			aRet.Left()  -=aRad.Width();
76 			aRet.Right() +=aRad.Width();
77 			aRet.Top()   -=aRad.Height();
78 			aRet.Bottom()+=aRad.Height();
79 		} break;
80 	} // switch
81 	return aRet;
82 }
83 
IsVisibleEqual(const SdrHelpLine & rHelpLine,const OutputDevice & rOut) const84 bool SdrHelpLine::IsVisibleEqual( const SdrHelpLine& rHelpLine, const OutputDevice& rOut ) const
85 {
86 	if( eKind == rHelpLine.eKind)
87 	{
88 		Point aPt1(rOut.LogicToPixel(aPos)), aPt2(rOut.LogicToPixel(rHelpLine.aPos));
89 		switch( eKind )
90 		{
91 			case SDRHELPLINE_POINT:
92 				return aPt1 == aPt2;
93 			case SDRHELPLINE_VERTICAL:
94 				return aPt1.X() == aPt2.X();
95 			case SDRHELPLINE_HORIZONTAL:
96 				return aPt1.Y() == aPt2.Y();
97 		}
98 	}
99 	return false;
100 }
101 
Clear()102 void SdrHelpLineList::Clear()
103 {
104 	sal_uInt16 nAnz=GetCount();
105 	for (sal_uInt16 i=0; i<nAnz; i++) {
106 		delete GetObject(i);
107 	}
108 	aList.Clear();
109 }
110 
operator =(const SdrHelpLineList & rSrcList)111 void SdrHelpLineList::operator=(const SdrHelpLineList& rSrcList)
112 {
113 	Clear();
114 	sal_uInt16 nAnz=rSrcList.GetCount();
115 	for (sal_uInt16 i=0; i<nAnz; i++) {
116 		Insert(rSrcList[i]);
117 	}
118 }
119 
operator ==(const SdrHelpLineList & rSrcList) const120 bool SdrHelpLineList::operator==(const SdrHelpLineList& rSrcList) const
121 {
122 	FASTBOOL bEqual=sal_False;
123 	sal_uInt16 nAnz=GetCount();
124 	if (nAnz==rSrcList.GetCount()) {
125 		bEqual=sal_True;
126 		for (sal_uInt16 i=0; i<nAnz && bEqual; i++) {
127 			if (*GetObject(i)!=*rSrcList.GetObject(i)) {
128 				bEqual=sal_False;
129 			}
130 		}
131 	}
132 	return bEqual;
133 }
134 
HitTest(const Point & rPnt,sal_uInt16 nTolLog,const OutputDevice & rOut) const135 sal_uInt16 SdrHelpLineList::HitTest(const Point& rPnt, sal_uInt16 nTolLog, const OutputDevice& rOut) const
136 {
137 	sal_uInt16 nAnz=GetCount();
138 	for (sal_uInt16 i=nAnz; i>0;) {
139 		i--;
140 		if (GetObject(i)->IsHit(rPnt,nTolLog,rOut)) return i;
141 	}
142 	return SDRHELPLINE_NOTFOUND;
143 }
144 
145 // eof
146