merge the formfield patch from ooo-build
[ooovba.git] / svx / source / svdraw / svdhlpln.cxx
blob731285801b714a8c6f5d6dcbb822660c19c5ebd5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svdhlpln.cxx,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <svx/svdhlpln.hxx>
35 #include <tools/color.hxx>
37 #include <vcl/outdev.hxx>
38 #include <vcl/window.hxx>
39 #include <tools/poly.hxx>
40 #include <vcl/lineinfo.hxx>
42 ////////////////////////////////////////////////////////////////////////////////////////////////////
44 Pointer SdrHelpLine::GetPointer() const
46 switch (eKind) {
47 case SDRHELPLINE_VERTICAL : return Pointer(POINTER_ESIZE);
48 case SDRHELPLINE_HORIZONTAL: return Pointer(POINTER_SSIZE);
49 default : return Pointer(POINTER_MOVE);
50 } // switch
53 FASTBOOL SdrHelpLine::IsHit(const Point& rPnt, USHORT nTolLog, const OutputDevice& rOut) const
55 Size a1Pix(rOut.PixelToLogic(Size(1,1)));
56 FASTBOOL bXHit=rPnt.X()>=aPos.X()-nTolLog && rPnt.X()<=aPos.X()+nTolLog+a1Pix.Width();
57 FASTBOOL bYHit=rPnt.Y()>=aPos.Y()-nTolLog && rPnt.Y()<=aPos.Y()+nTolLog+a1Pix.Height();
58 switch (eKind) {
59 case SDRHELPLINE_VERTICAL : return bXHit;
60 case SDRHELPLINE_HORIZONTAL: return bYHit;
61 case SDRHELPLINE_POINT: {
62 if (bXHit || bYHit) {
63 Size aRad(rOut.PixelToLogic(Size(SDRHELPLINE_POINT_PIXELSIZE,SDRHELPLINE_POINT_PIXELSIZE)));
64 return rPnt.X()>=aPos.X()-aRad.Width() && rPnt.X()<=aPos.X()+aRad.Width()+a1Pix.Width() &&
65 rPnt.Y()>=aPos.Y()-aRad.Height() && rPnt.Y()<=aPos.Y()+aRad.Height()+a1Pix.Height();
67 } break;
68 } // switch
69 return FALSE;
72 Rectangle SdrHelpLine::GetBoundRect(const OutputDevice& rOut) const
74 Rectangle aRet(aPos,aPos);
75 Point aOfs(rOut.GetMapMode().GetOrigin());
76 Size aSiz(rOut.GetOutputSize());
77 switch (eKind) {
78 case SDRHELPLINE_VERTICAL : aRet.Top()=-aOfs.Y(); aRet.Bottom()=-aOfs.Y()+aSiz.Height(); break;
79 case SDRHELPLINE_HORIZONTAL: aRet.Left()=-aOfs.X(); aRet.Right()=-aOfs.X()+aSiz.Width(); break;
80 case SDRHELPLINE_POINT : {
81 Size aRad(rOut.PixelToLogic(Size(SDRHELPLINE_POINT_PIXELSIZE,SDRHELPLINE_POINT_PIXELSIZE)));
82 aRet.Left() -=aRad.Width();
83 aRet.Right() +=aRad.Width();
84 aRet.Top() -=aRad.Height();
85 aRet.Bottom()+=aRad.Height();
86 } break;
87 } // switch
88 return aRet;
91 bool SdrHelpLine::IsVisibleEqual( const SdrHelpLine& rHelpLine, const OutputDevice& rOut ) const
93 if( eKind == rHelpLine.eKind)
95 Point aPt1(rOut.LogicToPixel(aPos)), aPt2(rOut.LogicToPixel(rHelpLine.aPos));
96 switch( eKind )
98 case SDRHELPLINE_POINT:
99 return aPt1 == aPt2;
100 case SDRHELPLINE_VERTICAL:
101 return aPt1.X() == aPt2.X();
102 case SDRHELPLINE_HORIZONTAL:
103 return aPt1.Y() == aPt2.Y();
106 return false;
109 void SdrHelpLineList::Clear()
111 USHORT nAnz=GetCount();
112 for (USHORT i=0; i<nAnz; i++) {
113 delete GetObject(i);
115 aList.Clear();
118 void SdrHelpLineList::operator=(const SdrHelpLineList& rSrcList)
120 Clear();
121 USHORT nAnz=rSrcList.GetCount();
122 for (USHORT i=0; i<nAnz; i++) {
123 Insert(rSrcList[i]);
127 bool SdrHelpLineList::operator==(const SdrHelpLineList& rSrcList) const
129 FASTBOOL bEqual=FALSE;
130 USHORT nAnz=GetCount();
131 if (nAnz==rSrcList.GetCount()) {
132 bEqual=TRUE;
133 for (USHORT i=0; i<nAnz && bEqual; i++) {
134 if (*GetObject(i)!=*rSrcList.GetObject(i)) {
135 bEqual=FALSE;
139 return bEqual;
142 USHORT SdrHelpLineList::HitTest(const Point& rPnt, USHORT nTolLog, const OutputDevice& rOut) const
144 USHORT nAnz=GetCount();
145 for (USHORT i=nAnz; i>0;) {
146 i--;
147 if (GetObject(i)->IsHit(rPnt,nTolLog,rOut)) return i;
149 return SDRHELPLINE_NOTFOUND;
152 // eof