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