Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
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>
31 : :
32 : : ////////////////////////////////////////////////////////////////////////////////////////////////////
33 : : // #i101872# new Object HitTest as View-tooling
34 : :
35 : 2 : SdrObject* SdrObjectPrimitiveHit(
36 : : const SdrObject& rObject,
37 : : const Point& rPnt,
38 : : sal_uInt16 nTol,
39 : : const SdrPageView& rSdrPageView,
40 : : const SetOfByte* pVisiLayer,
41 : : bool bTextOnly)
42 : : {
43 : 2 : SdrObject* pResult = 0;
44 : :
45 [ - + ][ # # ]: 2 : if(rObject.GetSubList() && rObject.GetSubList()->GetObjCount())
[ - + ]
46 : : {
47 : : // group or scene with content. Single 3D objects also have a
48 : : // true == rObject.GetSubList(), but no content
49 : 0 : pResult = SdrObjListPrimitiveHit(*rObject.GetSubList(), rPnt, nTol, rSdrPageView, pVisiLayer, bTextOnly);
50 : : }
51 : : else
52 : : {
53 [ + - ][ + - ]: 2 : if( rObject.IsVisible() && (!pVisiLayer || pVisiLayer->IsSet(rObject.GetLayer())))
[ + - ][ + - ]
54 : : {
55 : : // single object, 3d object, empty scene or empty group. Check if
56 : : // it's a single 3D object
57 [ - + ]: 2 : const E3dCompoundObject* pE3dCompoundObject = dynamic_cast< const E3dCompoundObject* >(&rObject);
58 : :
59 [ - + ]: 2 : if(pE3dCompoundObject)
60 : : {
61 : 0 : const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y());
62 : :
63 [ # # ][ # # ]: 0 : if(checkHitSingle3DObject(aHitPosition, *pE3dCompoundObject))
64 : : {
65 : 0 : pResult = const_cast< E3dCompoundObject* >(pE3dCompoundObject);
66 : 0 : }
67 : : }
68 : : else
69 : : {
70 : : // not a single 3D object; Check in first PageWindow using prmitives (only SC
71 : : // with split views uses multiple PageWindows nowadays)
72 [ + - ]: 2 : if(rSdrPageView.PageWindowCount())
73 : : {
74 : 2 : const double fLogicTolerance(nTol);
75 : 2 : const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y());
76 [ + - ]: 2 : const sdr::contact::ViewObjectContact& rVOC = rObject.GetViewContact().GetViewObjectContact(
77 [ + - ][ + - ]: 4 : rSdrPageView.GetPageWindow(0)->GetObjectContact());
[ + - ]
78 : :
79 [ + - ][ + - ]: 2 : if(ViewObjectContactPrimitiveHit(rVOC, aHitPosition, fLogicTolerance, bTextOnly))
80 : : {
81 : 2 : pResult = const_cast< SdrObject* >(&rObject);
82 : 2 : }
83 : : }
84 : : }
85 : : }
86 : : }
87 : :
88 : 2 : return pResult;
89 : : }
90 : :
91 : : /////////////////////////////////////////////////////////////////////
92 : :
93 : 0 : SdrObject* SdrObjListPrimitiveHit(
94 : : const SdrObjList& rList,
95 : : const Point& rPnt,
96 : : sal_uInt16 nTol,
97 : : const SdrPageView& rSdrPageView,
98 : : const SetOfByte* pVisiLayer,
99 : : bool bTextOnly)
100 : : {
101 : 0 : sal_uInt32 nObjNum(rList.GetObjCount());
102 : 0 : SdrObject* pRetval = 0;
103 : :
104 [ # # ][ # # ]: 0 : while(!pRetval && nObjNum > 0)
[ # # ]
105 : : {
106 : 0 : nObjNum--;
107 : 0 : SdrObject* pObj = rList.GetObj(nObjNum);
108 : :
109 : 0 : pRetval = SdrObjectPrimitiveHit(*pObj, rPnt, nTol, rSdrPageView, pVisiLayer, bTextOnly);
110 : : }
111 : :
112 : 0 : return pRetval;
113 : : }
114 : :
115 : : /////////////////////////////////////////////////////////////////////
116 : :
117 : 2 : bool ViewObjectContactPrimitiveHit(
118 : : const sdr::contact::ViewObjectContact& rVOC,
119 : : const basegfx::B2DPoint& rHitPosition,
120 : : double fLogicHitTolerance,
121 : : bool bTextOnly)
122 : : {
123 [ + - ]: 2 : basegfx::B2DRange aObjectRange(rVOC.getObjectRange());
124 : :
125 [ + - ][ + - ]: 2 : if(!aObjectRange.isEmpty())
126 : : {
127 : : // first do a rough B2DRange based HitTest; do not forget to
128 : : // include the HitTolerance if given
129 [ + - ]: 2 : if(basegfx::fTools::more(fLogicHitTolerance, 0.0))
130 : : {
131 [ + - ]: 2 : aObjectRange.grow(fLogicHitTolerance);
132 : : }
133 : :
134 [ + - ][ + - ]: 2 : if(aObjectRange.isInside(rHitPosition))
135 : : {
136 : : // get primitive sequence
137 [ + - ]: 2 : sdr::contact::DisplayInfo aDisplayInfo;
138 [ + - ]: 2 : const drawinglayer::primitive2d::Primitive2DSequence& rSequence(rVOC.getPrimitive2DSequence(aDisplayInfo));
139 : :
140 [ + - ]: 2 : if(rSequence.hasElements())
141 : : {
142 : : // create a HitTest processor
143 : 2 : const drawinglayer::geometry::ViewInformation2D& rViewInformation2D = rVOC.GetObjectContact().getViewInformation2D();
144 : : drawinglayer::processor2d::HitTestProcessor2D aHitTestProcessor2D(
145 : : rViewInformation2D,
146 : : rHitPosition,
147 : : fLogicHitTolerance,
148 [ + - ]: 2 : bTextOnly);
149 : :
150 : : // feed it with the primitives
151 [ + - ]: 2 : aHitTestProcessor2D.process(rSequence);
152 : :
153 : : // deliver result
154 [ + - ]: 2 : return aHitTestProcessor2D.getHit();
155 [ + - ][ + - ]: 2 : }
[ + - ][ - + ]
156 : : }
157 : : }
158 : :
159 : 2 : return false;
160 : : }
161 : :
162 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|