xref: /AOO42X/main/svx/source/svdraw/svdhlpln.cxx (revision b1c5455db1639c48e26c568e4fa7ee78ca5d60ee)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <svx/svdhlpln.hxx>
28cdf0e10cSrcweir #include <tools/color.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <vcl/outdev.hxx>
31cdf0e10cSrcweir #include <vcl/window.hxx>
32cdf0e10cSrcweir #include <tools/poly.hxx>
33cdf0e10cSrcweir #include <vcl/lineinfo.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
36cdf0e10cSrcweir 
GetPointer() const37cdf0e10cSrcweir Pointer SdrHelpLine::GetPointer() const
38cdf0e10cSrcweir {
39cdf0e10cSrcweir     switch (eKind) {
40cdf0e10cSrcweir         case SDRHELPLINE_VERTICAL  : return Pointer(POINTER_ESIZE);
41cdf0e10cSrcweir         case SDRHELPLINE_HORIZONTAL: return Pointer(POINTER_SSIZE);
42cdf0e10cSrcweir         default                    : return Pointer(POINTER_MOVE);
43cdf0e10cSrcweir     } // switch
44cdf0e10cSrcweir }
45cdf0e10cSrcweir 
IsHit(const Point & rPnt,sal_uInt16 nTolLog,const OutputDevice & rOut) const46cdf0e10cSrcweir FASTBOOL SdrHelpLine::IsHit(const Point& rPnt, sal_uInt16 nTolLog, const OutputDevice& rOut) const
47cdf0e10cSrcweir {
48cdf0e10cSrcweir     Size a1Pix(rOut.PixelToLogic(Size(1,1)));
49cdf0e10cSrcweir     FASTBOOL bXHit=rPnt.X()>=aPos.X()-nTolLog && rPnt.X()<=aPos.X()+nTolLog+a1Pix.Width();
50cdf0e10cSrcweir     FASTBOOL bYHit=rPnt.Y()>=aPos.Y()-nTolLog && rPnt.Y()<=aPos.Y()+nTolLog+a1Pix.Height();
51cdf0e10cSrcweir     switch (eKind) {
52cdf0e10cSrcweir         case SDRHELPLINE_VERTICAL  : return bXHit;
53cdf0e10cSrcweir         case SDRHELPLINE_HORIZONTAL: return bYHit;
54cdf0e10cSrcweir         case SDRHELPLINE_POINT: {
55cdf0e10cSrcweir             if (bXHit || bYHit) {
56cdf0e10cSrcweir                 Size aRad(rOut.PixelToLogic(Size(SDRHELPLINE_POINT_PIXELSIZE,SDRHELPLINE_POINT_PIXELSIZE)));
57cdf0e10cSrcweir                 return rPnt.X()>=aPos.X()-aRad.Width() && rPnt.X()<=aPos.X()+aRad.Width()+a1Pix.Width() &&
58cdf0e10cSrcweir                        rPnt.Y()>=aPos.Y()-aRad.Height() && rPnt.Y()<=aPos.Y()+aRad.Height()+a1Pix.Height();
59cdf0e10cSrcweir             }
60cdf0e10cSrcweir         } break;
61cdf0e10cSrcweir     } // switch
62cdf0e10cSrcweir     return sal_False;
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
GetBoundRect(const OutputDevice & rOut) const65cdf0e10cSrcweir Rectangle SdrHelpLine::GetBoundRect(const OutputDevice& rOut) const
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     Rectangle aRet(aPos,aPos);
68cdf0e10cSrcweir     Point aOfs(rOut.GetMapMode().GetOrigin());
69cdf0e10cSrcweir     Size aSiz(rOut.GetOutputSize());
70cdf0e10cSrcweir     switch (eKind) {
71cdf0e10cSrcweir         case SDRHELPLINE_VERTICAL  : aRet.Top()=-aOfs.Y(); aRet.Bottom()=-aOfs.Y()+aSiz.Height(); break;
72cdf0e10cSrcweir         case SDRHELPLINE_HORIZONTAL: aRet.Left()=-aOfs.X(); aRet.Right()=-aOfs.X()+aSiz.Width();  break;
73cdf0e10cSrcweir         case SDRHELPLINE_POINT     : {
74cdf0e10cSrcweir             Size aRad(rOut.PixelToLogic(Size(SDRHELPLINE_POINT_PIXELSIZE,SDRHELPLINE_POINT_PIXELSIZE)));
75cdf0e10cSrcweir             aRet.Left()  -=aRad.Width();
76cdf0e10cSrcweir             aRet.Right() +=aRad.Width();
77cdf0e10cSrcweir             aRet.Top()   -=aRad.Height();
78cdf0e10cSrcweir             aRet.Bottom()+=aRad.Height();
79cdf0e10cSrcweir         } break;
80cdf0e10cSrcweir     } // switch
81cdf0e10cSrcweir     return aRet;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
IsVisibleEqual(const SdrHelpLine & rHelpLine,const OutputDevice & rOut) const84cdf0e10cSrcweir bool SdrHelpLine::IsVisibleEqual( const SdrHelpLine& rHelpLine, const OutputDevice& rOut ) const
85cdf0e10cSrcweir {
86cdf0e10cSrcweir     if( eKind == rHelpLine.eKind)
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir         Point aPt1(rOut.LogicToPixel(aPos)), aPt2(rOut.LogicToPixel(rHelpLine.aPos));
89cdf0e10cSrcweir         switch( eKind )
90cdf0e10cSrcweir         {
91cdf0e10cSrcweir             case SDRHELPLINE_POINT:
92cdf0e10cSrcweir                 return aPt1 == aPt2;
93cdf0e10cSrcweir             case SDRHELPLINE_VERTICAL:
94cdf0e10cSrcweir                 return aPt1.X() == aPt2.X();
95cdf0e10cSrcweir             case SDRHELPLINE_HORIZONTAL:
96cdf0e10cSrcweir                 return aPt1.Y() == aPt2.Y();
97cdf0e10cSrcweir         }
98cdf0e10cSrcweir     }
99cdf0e10cSrcweir     return false;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
Clear()102cdf0e10cSrcweir void SdrHelpLineList::Clear()
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     sal_uInt16 nAnz=GetCount();
105cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
106cdf0e10cSrcweir         delete GetObject(i);
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir     aList.Clear();
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
operator =(const SdrHelpLineList & rSrcList)111cdf0e10cSrcweir void SdrHelpLineList::operator=(const SdrHelpLineList& rSrcList)
112cdf0e10cSrcweir {
113cdf0e10cSrcweir     Clear();
114cdf0e10cSrcweir     sal_uInt16 nAnz=rSrcList.GetCount();
115cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
116cdf0e10cSrcweir         Insert(rSrcList[i]);
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
operator ==(const SdrHelpLineList & rSrcList) const120cdf0e10cSrcweir bool SdrHelpLineList::operator==(const SdrHelpLineList& rSrcList) const
121cdf0e10cSrcweir {
122cdf0e10cSrcweir     FASTBOOL bEqual=sal_False;
123cdf0e10cSrcweir     sal_uInt16 nAnz=GetCount();
124cdf0e10cSrcweir     if (nAnz==rSrcList.GetCount()) {
125cdf0e10cSrcweir         bEqual=sal_True;
126cdf0e10cSrcweir         for (sal_uInt16 i=0; i<nAnz && bEqual; i++) {
127cdf0e10cSrcweir             if (*GetObject(i)!=*rSrcList.GetObject(i)) {
128cdf0e10cSrcweir                 bEqual=sal_False;
129cdf0e10cSrcweir             }
130cdf0e10cSrcweir         }
131cdf0e10cSrcweir     }
132cdf0e10cSrcweir     return bEqual;
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
HitTest(const Point & rPnt,sal_uInt16 nTolLog,const OutputDevice & rOut) const135cdf0e10cSrcweir sal_uInt16 SdrHelpLineList::HitTest(const Point& rPnt, sal_uInt16 nTolLog, const OutputDevice& rOut) const
136cdf0e10cSrcweir {
137cdf0e10cSrcweir     sal_uInt16 nAnz=GetCount();
138cdf0e10cSrcweir     for (sal_uInt16 i=nAnz; i>0;) {
139cdf0e10cSrcweir         i--;
140cdf0e10cSrcweir         if (GetObject(i)->IsHit(rPnt,nTolLog,rOut)) return i;
141cdf0e10cSrcweir     }
142cdf0e10cSrcweir     return SDRHELPLINE_NOTFOUND;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir // eof
146