Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / svx / source / svdraw / svdhlpln.cxx
blobcd0a835d01a39c71406a51b973354df6e420e642
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <svx/svdhlpln.hxx>
32 #include <vcl/outdev.hxx>
33 #include <vcl/window.hxx>
34 #include <tools/poly.hxx>
35 #include <vcl/lineinfo.hxx>
37 ////////////////////////////////////////////////////////////////////////////////////////////////////
39 Pointer SdrHelpLine::GetPointer() const
41 switch (eKind) {
42 case SDRHELPLINE_VERTICAL : return Pointer(POINTER_ESIZE);
43 case SDRHELPLINE_HORIZONTAL: return Pointer(POINTER_SSIZE);
44 default : return Pointer(POINTER_MOVE);
45 } // switch
48 bool SdrHelpLine::IsHit(const Point& rPnt, sal_uInt16 nTolLog, const OutputDevice& rOut) const
50 Size a1Pix(rOut.PixelToLogic(Size(1,1)));
51 bool bXHit=rPnt.X()>=aPos.X()-nTolLog && rPnt.X()<=aPos.X()+nTolLog+a1Pix.Width();
52 bool bYHit=rPnt.Y()>=aPos.Y()-nTolLog && rPnt.Y()<=aPos.Y()+nTolLog+a1Pix.Height();
53 switch (eKind) {
54 case SDRHELPLINE_VERTICAL : return bXHit;
55 case SDRHELPLINE_HORIZONTAL: return bYHit;
56 case SDRHELPLINE_POINT: {
57 if (bXHit || bYHit) {
58 Size aRad(rOut.PixelToLogic(Size(SDRHELPLINE_POINT_PIXELSIZE,SDRHELPLINE_POINT_PIXELSIZE)));
59 return rPnt.X()>=aPos.X()-aRad.Width() && rPnt.X()<=aPos.X()+aRad.Width()+a1Pix.Width() &&
60 rPnt.Y()>=aPos.Y()-aRad.Height() && rPnt.Y()<=aPos.Y()+aRad.Height()+a1Pix.Height();
62 } break;
63 } // switch
64 return sal_False;
67 Rectangle SdrHelpLine::GetBoundRect(const OutputDevice& rOut) const
69 Rectangle aRet(aPos,aPos);
70 Point aOfs(rOut.GetMapMode().GetOrigin());
71 Size aSiz(rOut.GetOutputSize());
72 switch (eKind) {
73 case SDRHELPLINE_VERTICAL : aRet.Top()=-aOfs.Y(); aRet.Bottom()=-aOfs.Y()+aSiz.Height(); break;
74 case SDRHELPLINE_HORIZONTAL: aRet.Left()=-aOfs.X(); aRet.Right()=-aOfs.X()+aSiz.Width(); break;
75 case SDRHELPLINE_POINT : {
76 Size aRad(rOut.PixelToLogic(Size(SDRHELPLINE_POINT_PIXELSIZE,SDRHELPLINE_POINT_PIXELSIZE)));
77 aRet.Left() -=aRad.Width();
78 aRet.Right() +=aRad.Width();
79 aRet.Top() -=aRad.Height();
80 aRet.Bottom()+=aRad.Height();
81 } break;
82 } // switch
83 return aRet;
86 void SdrHelpLineList::Clear()
88 sal_uInt16 nAnz=GetCount();
89 for (sal_uInt16 i=0; i<nAnz; i++) {
90 delete GetObject(i);
92 aList.Clear();
95 void SdrHelpLineList::operator=(const SdrHelpLineList& rSrcList)
97 Clear();
98 sal_uInt16 nAnz=rSrcList.GetCount();
99 for (sal_uInt16 i=0; i<nAnz; i++) {
100 Insert(rSrcList[i]);
104 bool SdrHelpLineList::operator==(const SdrHelpLineList& rSrcList) const
106 bool bEqual = false;
107 sal_uInt16 nAnz=GetCount();
108 if (nAnz==rSrcList.GetCount()) {
109 bEqual = true;
110 for (sal_uInt16 i=0; i<nAnz && bEqual; i++) {
111 if (*GetObject(i)!=*rSrcList.GetObject(i)) {
112 bEqual = false;
116 return bEqual;
119 sal_uInt16 SdrHelpLineList::HitTest(const Point& rPnt, sal_uInt16 nTolLog, const OutputDevice& rOut) const
121 sal_uInt16 nAnz=GetCount();
122 for (sal_uInt16 i=nAnz; i>0;) {
123 i--;
124 if (GetObject(i)->IsHit(rPnt,nTolLog,rOut)) return i;
126 return SDRHELPLINE_NOTFOUND;
129 // eof
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */