update dev300-m58
[ooovba.git] / svx / source / svdraw / sdrhittesthelper.cxx
blob008ae7734ed8663efbb9c4d7ce40921d6c284783
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: svdetc.cxx,v $
10 * $Revision: 1.35.18.2 $
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/sdrhittesthelper.hxx>
35 #include <svx/obj3d.hxx>
36 #include <svx/helperhittest3d.hxx>
37 #include <svx/sdrpagewindow.hxx>
38 #include <svx/sdr/contact/viewobjectcontact.hxx>
39 #include <svx/sdr/contact/displayinfo.hxx>
40 #include <svx/sdr/contact/objectcontact.hxx>
41 #include <drawinglayer/processor2d/hittestprocessor2d.hxx>
42 #include <svx/svdpagv.hxx>
43 #include <svx/sdr/contact/viewcontact.hxx>
45 ////////////////////////////////////////////////////////////////////////////////////////////////////
46 // #i101872# new Object HitTest as View-tooling
48 SdrObject* SdrObjectPrimitiveHit(
49 const SdrObject& rObject,
50 const Point& rPnt,
51 sal_uInt16 nTol,
52 const SdrPageView& rSdrPageView,
53 const SetOfByte* pVisiLayer,
54 bool bTextOnly)
56 SdrObject* pResult = 0;
58 if(rObject.GetSubList() && rObject.GetSubList()->GetObjCount())
60 // group or scene with content. Single 3D objects also have a
61 // true == rObject.GetSubList(), but no content
62 pResult = SdrObjListPrimitiveHit(*rObject.GetSubList(), rPnt, nTol, rSdrPageView, pVisiLayer, bTextOnly);
64 else
66 if(!pVisiLayer || pVisiLayer->IsSet(rObject.GetLayer()))
68 // single object, 3d object, empty scene or empty group. Check if
69 // it's a single 3D object
70 const E3dCompoundObject* pE3dCompoundObject = dynamic_cast< const E3dCompoundObject* >(&rObject);
72 if(pE3dCompoundObject)
74 const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y());
76 if(checkHitSingle3DObject(aHitPosition, *pE3dCompoundObject))
78 pResult = const_cast< E3dCompoundObject* >(pE3dCompoundObject);
81 else
83 // not a single 3D object; Check in first PageWindow using prmitives (only SC
84 // with split views uses multiple PageWindows nowadays)
85 if(rSdrPageView.PageWindowCount())
87 const double fLogicTolerance(nTol);
88 const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y());
89 const sdr::contact::ViewObjectContact& rVOC = rObject.GetViewContact().GetViewObjectContact(
90 rSdrPageView.GetPageWindow(0)->GetObjectContact());
92 if(ViewObjectContactPrimitiveHit(rVOC, aHitPosition, fLogicTolerance, bTextOnly))
94 pResult = const_cast< SdrObject* >(&rObject);
101 return pResult;
104 /////////////////////////////////////////////////////////////////////
106 SdrObject* SdrObjListPrimitiveHit(
107 const SdrObjList& rList,
108 const Point& rPnt,
109 sal_uInt16 nTol,
110 const SdrPageView& rSdrPageView,
111 const SetOfByte* pVisiLayer,
112 bool bTextOnly)
114 sal_uInt32 nObjNum(rList.GetObjCount());
115 SdrObject* pRetval = 0;
117 while(!pRetval && nObjNum > 0)
119 nObjNum--;
120 SdrObject* pObj = rList.GetObj(nObjNum);
122 pRetval = SdrObjectPrimitiveHit(*pObj, rPnt, nTol, rSdrPageView, pVisiLayer, bTextOnly);
125 return pRetval;
128 /////////////////////////////////////////////////////////////////////
130 bool ViewObjectContactPrimitiveHit(
131 const sdr::contact::ViewObjectContact& rVOC,
132 const basegfx::B2DPoint& rHitPosition,
133 double fLogicHitTolerance,
134 bool bTextOnly)
136 basegfx::B2DRange aObjectRange(rVOC.getObjectRange());
138 if(!aObjectRange.isEmpty())
140 // first do a rough B2DRange based HitTest; do not forget to
141 // include the HitTolerance if given
142 if(basegfx::fTools::more(fLogicHitTolerance, 0.0))
144 aObjectRange.grow(fLogicHitTolerance);
147 if(aObjectRange.isInside(rHitPosition))
149 // get primitive sequence
150 sdr::contact::DisplayInfo aDisplayInfo;
151 const drawinglayer::primitive2d::Primitive2DSequence& rSequence(rVOC.getPrimitive2DSequence(aDisplayInfo));
153 if(rSequence.hasElements())
155 // create a HitTest processor
156 const drawinglayer::geometry::ViewInformation2D& rViewInformation2D = rVOC.GetObjectContact().getViewInformation2D();
157 drawinglayer::processor2d::HitTestProcessor2D aHitTestProcessor2D(
158 rViewInformation2D,
159 rHitPosition,
160 fLogicHitTolerance,
161 bTextOnly);
163 // feed it with the primitives
164 aHitTestProcessor2D.process(rSequence);
166 // deliver result
167 return aHitTestProcessor2D.getHit();
172 return false;
175 ////////////////////////////////////////////////////////////////////////////////////////////////////
176 // eof