xref: /aoo42x/main/svx/source/svdraw/svdhlpln.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include <svx/svdhlpln.hxx>
32 #include <tools/color.hxx>
33 
34 #include <vcl/outdev.hxx>
35 #include <vcl/window.hxx>
36 #include <tools/poly.hxx>
37 #include <vcl/lineinfo.hxx>
38 
39 ////////////////////////////////////////////////////////////////////////////////////////////////////
40 
41 Pointer SdrHelpLine::GetPointer() const
42 {
43 	switch (eKind) {
44 		case SDRHELPLINE_VERTICAL  : return Pointer(POINTER_ESIZE);
45 		case SDRHELPLINE_HORIZONTAL: return Pointer(POINTER_SSIZE);
46 		default                    : return Pointer(POINTER_MOVE);
47 	} // switch
48 }
49 
50 FASTBOOL SdrHelpLine::IsHit(const Point& rPnt, sal_uInt16 nTolLog, const OutputDevice& rOut) const
51 {
52 	Size a1Pix(rOut.PixelToLogic(Size(1,1)));
53 	FASTBOOL bXHit=rPnt.X()>=aPos.X()-nTolLog && rPnt.X()<=aPos.X()+nTolLog+a1Pix.Width();
54 	FASTBOOL bYHit=rPnt.Y()>=aPos.Y()-nTolLog && rPnt.Y()<=aPos.Y()+nTolLog+a1Pix.Height();
55 	switch (eKind) {
56 		case SDRHELPLINE_VERTICAL  : return bXHit;
57 		case SDRHELPLINE_HORIZONTAL: return bYHit;
58 		case SDRHELPLINE_POINT: {
59 			if (bXHit || bYHit) {
60 				Size aRad(rOut.PixelToLogic(Size(SDRHELPLINE_POINT_PIXELSIZE,SDRHELPLINE_POINT_PIXELSIZE)));
61 				return rPnt.X()>=aPos.X()-aRad.Width() && rPnt.X()<=aPos.X()+aRad.Width()+a1Pix.Width() &&
62 					   rPnt.Y()>=aPos.Y()-aRad.Height() && rPnt.Y()<=aPos.Y()+aRad.Height()+a1Pix.Height();
63 			}
64 		} break;
65 	} // switch
66 	return sal_False;
67 }
68 
69 Rectangle SdrHelpLine::GetBoundRect(const OutputDevice& rOut) const
70 {
71 	Rectangle aRet(aPos,aPos);
72 	Point aOfs(rOut.GetMapMode().GetOrigin());
73 	Size aSiz(rOut.GetOutputSize());
74 	switch (eKind) {
75 		case SDRHELPLINE_VERTICAL  : aRet.Top()=-aOfs.Y(); aRet.Bottom()=-aOfs.Y()+aSiz.Height(); break;
76 		case SDRHELPLINE_HORIZONTAL: aRet.Left()=-aOfs.X(); aRet.Right()=-aOfs.X()+aSiz.Width();  break;
77 		case SDRHELPLINE_POINT     : {
78 			Size aRad(rOut.PixelToLogic(Size(SDRHELPLINE_POINT_PIXELSIZE,SDRHELPLINE_POINT_PIXELSIZE)));
79 			aRet.Left()  -=aRad.Width();
80 			aRet.Right() +=aRad.Width();
81 			aRet.Top()   -=aRad.Height();
82 			aRet.Bottom()+=aRad.Height();
83 		} break;
84 	} // switch
85 	return aRet;
86 }
87 
88 bool SdrHelpLine::IsVisibleEqual( const SdrHelpLine& rHelpLine, const OutputDevice& rOut ) const
89 {
90 	if( eKind == rHelpLine.eKind)
91 	{
92 		Point aPt1(rOut.LogicToPixel(aPos)), aPt2(rOut.LogicToPixel(rHelpLine.aPos));
93 		switch( eKind )
94 		{
95 			case SDRHELPLINE_POINT:
96 				return aPt1 == aPt2;
97 			case SDRHELPLINE_VERTICAL:
98 				return aPt1.X() == aPt2.X();
99 			case SDRHELPLINE_HORIZONTAL:
100 				return aPt1.Y() == aPt2.Y();
101 		}
102 	}
103 	return false;
104 }
105 
106 void SdrHelpLineList::Clear()
107 {
108 	sal_uInt16 nAnz=GetCount();
109 	for (sal_uInt16 i=0; i<nAnz; i++) {
110 		delete GetObject(i);
111 	}
112 	aList.Clear();
113 }
114 
115 void SdrHelpLineList::operator=(const SdrHelpLineList& rSrcList)
116 {
117 	Clear();
118 	sal_uInt16 nAnz=rSrcList.GetCount();
119 	for (sal_uInt16 i=0; i<nAnz; i++) {
120 		Insert(rSrcList[i]);
121 	}
122 }
123 
124 bool SdrHelpLineList::operator==(const SdrHelpLineList& rSrcList) const
125 {
126 	FASTBOOL bEqual=sal_False;
127 	sal_uInt16 nAnz=GetCount();
128 	if (nAnz==rSrcList.GetCount()) {
129 		bEqual=sal_True;
130 		for (sal_uInt16 i=0; i<nAnz && bEqual; i++) {
131 			if (*GetObject(i)!=*rSrcList.GetObject(i)) {
132 				bEqual=sal_False;
133 			}
134 		}
135 	}
136 	return bEqual;
137 }
138 
139 sal_uInt16 SdrHelpLineList::HitTest(const Point& rPnt, sal_uInt16 nTolLog, const OutputDevice& rOut) const
140 {
141 	sal_uInt16 nAnz=GetCount();
142 	for (sal_uInt16 i=nAnz; i>0;) {
143 		i--;
144 		if (GetObject(i)->IsHit(rPnt,nTolLog,rOut)) return i;
145 	}
146 	return SDRHELPLINE_NOTFOUND;
147 }
148 
149 // eof
150