|
1 /* |
|
2 * Copyright (c) 2008-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Gesture helper helper functions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "gestureobserver.h" |
|
20 |
|
21 // system includes |
|
22 #include <alf/alfcontrol.h> |
|
23 #include <alf/alflayout.h> |
|
24 |
|
25 using namespace GestureHelper; |
|
26 |
|
27 namespace |
|
28 { |
|
29 /** @return the leaf-most visual that is under aPos */ |
|
30 const CAlfVisual* VisualByCoordinates( const CAlfVisual& aRoot, const TPoint& aPos ) |
|
31 { |
|
32 // If it has children, chose any of them is hit first |
|
33 const CAlfLayout* layout = dynamic_cast< const CAlfLayout* >( &aRoot ); |
|
34 if ( layout) |
|
35 { |
|
36 TInt i = layout->Count(); |
|
37 while( --i >= 0 ) |
|
38 { |
|
39 if( VisualByCoordinates( layout->Visual( i ), aPos ) ) |
|
40 { |
|
41 return &layout->Visual( i ); |
|
42 } |
|
43 } |
|
44 } |
|
45 |
|
46 // children were not hit. is this visual hit? |
|
47 if( TRect( aRoot.DisplayRect() ).Contains( aPos ) ) |
|
48 { |
|
49 return &aRoot; |
|
50 } |
|
51 |
|
52 // visual was not found |
|
53 return NULL; |
|
54 } |
|
55 |
|
56 TBool IsRootVisual( const CAlfVisual& aVisual ) |
|
57 { |
|
58 return !aVisual.Layout(); |
|
59 } |
|
60 } // unnamed namespace |
|
61 |
|
62 // ---------------------------------------------------------------------------- |
|
63 // VisualByCoordinates |
|
64 // ---------------------------------------------------------------------------- |
|
65 // |
|
66 EXPORT_C CAlfVisual* HitTest::VisualByCoordinates( const CAlfControl& aControl, |
|
67 const TPoint& aPos ) |
|
68 { |
|
69 TInt i = aControl.VisualCount(); |
|
70 while( --i >= 0 ) |
|
71 { |
|
72 // Ask only root visuals, since all children are within the root visuals |
|
73 if ( IsRootVisual( aControl.Visual( i ) ) ) |
|
74 { |
|
75 const CAlfVisual* hitVisual = ::VisualByCoordinates( |
|
76 aControl.Visual( i ), aPos ); |
|
77 if ( hitVisual ) |
|
78 { |
|
79 return const_cast< CAlfVisual* >( hitVisual ); |
|
80 } |
|
81 } |
|
82 } |
|
83 return NULL; |
|
84 } |