1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <svx/sdrhittesthelper.hxx>
22 #include <svx/obj3d.hxx>
23 #include <svx/helperhittest3d.hxx>
24 #include <svx/sdrpagewindow.hxx>
25 #include <svx/sdr/contact/viewobjectcontact.hxx>
26 #include <svx/sdr/contact/displayinfo.hxx>
27 #include <svx/sdr/contact/objectcontact.hxx>
28 #include <drawinglayer/processor2d/hittestprocessor2d.hxx>
29 #include <svx/svdpagv.hxx>
30 #include <svx/sdr/contact/viewcontact.hxx>
33 // #i101872# new Object HitTest as View-tooling
35 SdrObject
* SdrObjectPrimitiveHit(
36 const SdrObject
& rObject
,
39 const SdrPageView
& rSdrPageView
,
40 const SetOfByte
* pVisiLayer
,
43 SdrObject
* pResult
= 0;
45 if(rObject
.GetSubList() && rObject
.GetSubList()->GetObjCount())
47 // group or scene with content. Single 3D objects also have a
48 // true == rObject.GetSubList(), but no content
49 pResult
= SdrObjListPrimitiveHit(*rObject
.GetSubList(), rPnt
, nTol
, rSdrPageView
, pVisiLayer
, bTextOnly
);
53 if( rObject
.IsVisible() && (!pVisiLayer
|| pVisiLayer
->IsSet(rObject
.GetLayer())))
55 // single object, 3d object, empty scene or empty group. Check if
56 // it's a single 3D object
57 const E3dCompoundObject
* pE3dCompoundObject
= dynamic_cast< const E3dCompoundObject
* >(&rObject
);
59 if(pE3dCompoundObject
)
61 const basegfx::B2DPoint
aHitPosition(rPnt
.X(), rPnt
.Y());
63 if(checkHitSingle3DObject(aHitPosition
, *pE3dCompoundObject
))
65 pResult
= const_cast< E3dCompoundObject
* >(pE3dCompoundObject
);
70 // not a single 3D object; Check in first PageWindow using prmitives (only SC
71 // with split views uses multiple PageWindows nowadays)
72 if(rSdrPageView
.PageWindowCount())
74 const double fLogicTolerance(nTol
);
75 const basegfx::B2DPoint
aHitPosition(rPnt
.X(), rPnt
.Y());
76 const sdr::contact::ViewObjectContact
& rVOC
= rObject
.GetViewContact().GetViewObjectContact(
77 rSdrPageView
.GetPageWindow(0)->GetObjectContact());
79 if(ViewObjectContactPrimitiveHit(rVOC
, aHitPosition
, fLogicTolerance
, bTextOnly
))
81 pResult
= const_cast< SdrObject
* >(&rObject
);
93 SdrObject
* SdrObjListPrimitiveHit(
94 const SdrObjList
& rList
,
97 const SdrPageView
& rSdrPageView
,
98 const SetOfByte
* pVisiLayer
,
101 sal_uInt32
nObjNum(rList
.GetObjCount());
102 SdrObject
* pRetval
= 0;
104 while(!pRetval
&& nObjNum
> 0)
107 SdrObject
* pObj
= rList
.GetObj(nObjNum
);
109 pRetval
= SdrObjectPrimitiveHit(*pObj
, rPnt
, nTol
, rSdrPageView
, pVisiLayer
, bTextOnly
);
117 bool ViewObjectContactPrimitiveHit(
118 const sdr::contact::ViewObjectContact
& rVOC
,
119 const basegfx::B2DPoint
& rHitPosition
,
120 double fLogicHitTolerance
,
123 basegfx::B2DRange
aObjectRange(rVOC
.getObjectRange());
125 if(!aObjectRange
.isEmpty())
127 // first do a rough B2DRange based HitTest; do not forget to
128 // include the HitTolerance if given
129 if(basegfx::fTools::more(fLogicHitTolerance
, 0.0))
131 aObjectRange
.grow(fLogicHitTolerance
);
134 if(aObjectRange
.isInside(rHitPosition
))
136 // get primitive sequence
137 sdr::contact::DisplayInfo aDisplayInfo
;
138 const drawinglayer::primitive2d::Primitive2DSequence
& rSequence(rVOC
.getPrimitive2DSequence(aDisplayInfo
));
140 if(rSequence
.hasElements())
142 // create a HitTest processor
143 const drawinglayer::geometry::ViewInformation2D
& rViewInformation2D
= rVOC
.GetObjectContact().getViewInformation2D();
144 drawinglayer::processor2d::HitTestProcessor2D
aHitTestProcessor2D(
150 // feed it with the primitives
151 aHitTestProcessor2D
.process(rSequence
);
154 return aHitTestProcessor2D
.getHit();
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */