1 /* |
|
2 * Copyright (c) 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 the License "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: Alf control group and control for capturing pointer events |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "pointercapturer.h" |
|
20 |
|
21 #include <alf/alfcontrol.h> |
|
22 #include <alf/alfcontrolgroup.h> |
|
23 #include <alf/alfdisplay.h> |
|
24 #include <alf/alfenv.h> |
|
25 #include <alf/alfevent.h> |
|
26 #include <alf/alfroster.h> |
|
27 |
|
28 #include "gesturehelperimpl.h" |
|
29 |
|
30 namespace RT_GestureHelper |
|
31 { |
|
32 |
|
33 /** |
|
34 * CPointerCaptureControl |
|
35 * Gesture control own a gesture helper, and captures any pointer events that |
|
36 * no other control captures. After it captures pointer down event, it will |
|
37 * capture all pointer events until pointer up. It does this by bringing its |
|
38 * control group to the top upon pointer down, and lowering the control group |
|
39 * to the botton upon pointer up. |
|
40 */ |
|
41 NONSHARABLE_CLASS( CPointerCaptureControl ) : public CAlfControl |
|
42 { |
|
43 public: |
|
44 /** Two-phased constructor */ |
|
45 static CPointerCaptureControl* NewLC( CGestureHelperImpl& aHelper, |
|
46 CAlfEnv& aEnv, CAlfDisplay& aDisplay ) |
|
47 { |
|
48 CPointerCaptureControl* self = new ( ELeave ) CPointerCaptureControl( aHelper ); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL( aEnv ); // construct base class |
|
51 self->BindDisplay( aDisplay ); |
|
52 self->AppendVisualL( EAlfVisualTypeVisual ); |
|
53 return self; |
|
54 } |
|
55 |
|
56 void StartCaptureL() |
|
57 { |
|
58 User::LeaveIfError( Display()->Roster().SetPointerEventObservers( |
|
59 EAlfPointerEventReportDrag | EAlfPointerEventReportUnhandled, |
|
60 *this ) ); |
|
61 Display()->Roster().ShowL( *ControlGroup(), KAlfRosterShowAtTop ); |
|
62 } |
|
63 |
|
64 void StopCapture() |
|
65 { |
|
66 ( void ) Display()->Roster().SetPointerEventObservers( 0, *this ); |
|
67 TRAP_IGNORE( Display()->Roster().ShowL( *ControlGroup(), KAlfRosterShowAtBottom ) ); |
|
68 } |
|
69 |
|
70 private: |
|
71 /** Constructor */ |
|
72 CPointerCaptureControl( CGestureHelperImpl& aHelper ) |
|
73 : iHelper( aHelper ) |
|
74 { |
|
75 } |
|
76 |
|
77 // From CAlfControl |
|
78 TBool OfferEventL( const TAlfEvent& aEvent ) |
|
79 { |
|
80 TBool consumed = EFalse; |
|
81 if ( aEvent.IsPointerEvent() ) |
|
82 { |
|
83 // pointer down should never come here if everything is working properly. |
|
84 // if pointer event comes here, stop capturing and allow the event to |
|
85 // fall to the controls below |
|
86 if ( aEvent.PointerDown() ) |
|
87 { |
|
88 StopCapture(); |
|
89 } |
|
90 else |
|
91 { |
|
92 consumed = iHelper.HandlePointerEventL( aEvent.PointerEvent() ); |
|
93 } |
|
94 } |
|
95 return consumed; |
|
96 } |
|
97 |
|
98 private: |
|
99 /// gesture helper that analyses pointer sequences. own. |
|
100 CGestureHelperImpl& iHelper; |
|
101 }; |
|
102 |
|
103 } // namespace RT_GestureHelper |
|
104 |
|
105 using namespace RT_GestureHelper; |
|
106 |
|
107 // ---------------------------------------------------------------------------- |
|
108 // Two phase constructor |
|
109 // ---------------------------------------------------------------------------- |
|
110 // |
|
111 CPointerCapturer* CPointerCapturer::NewL() |
|
112 { |
|
113 return new ( ELeave ) CPointerCapturer(); |
|
114 } |
|
115 |
|
116 // ---------------------------------------------------------------------------- |
|
117 // Two phase constructor |
|
118 // ---------------------------------------------------------------------------- |
|
119 // |
|
120 CPointerCapturer::~CPointerCapturer() |
|
121 { |
|
122 if ( iCaptureControl ) |
|
123 { |
|
124 // deleting the control group will also delete the control |
|
125 iCaptureControl->Env().DeleteControlGroup( iControlGroupId ); |
|
126 } |
|
127 } |
|
128 |
|
129 // ---------------------------------------------------------------------------- |
|
130 // InitForAlfredL |
|
131 // ---------------------------------------------------------------------------- |
|
132 // |
|
133 void CPointerCapturer::InitForAlfredL( CGestureHelperImpl& aHelper, |
|
134 CAlfEnv& aEnv, CAlfDisplay& aDisplay, TInt aControlGroupId ) |
|
135 { |
|
136 CAlfControlGroup& group = aEnv.NewControlGroupL( aControlGroupId ); |
|
137 CPointerCaptureControl* control = CPointerCaptureControl::NewLC( aHelper, |
|
138 aEnv, aDisplay ); |
|
139 group.AppendL( control ); |
|
140 CleanupStack::Pop( control ); |
|
141 |
|
142 // store control only after it has been successfully added to group |
|
143 iCaptureControl = control; |
|
144 iControlGroupId = aControlGroupId; |
|
145 } |
|
146 |
|
147 // ---------------------------------------------------------------------------- |
|
148 // StartCaptureL |
|
149 // ---------------------------------------------------------------------------- |
|
150 // |
|
151 void CPointerCapturer::StartL() |
|
152 { |
|
153 if ( iCaptureControl ) |
|
154 { |
|
155 iCaptureControl->StartCaptureL(); |
|
156 } |
|
157 } |
|
158 |
|
159 // ---------------------------------------------------------------------------- |
|
160 // StopCapture |
|
161 // ---------------------------------------------------------------------------- |
|
162 // |
|
163 void CPointerCapturer::Stop() |
|
164 { |
|
165 if ( iCaptureControl ) |
|
166 { |
|
167 iCaptureControl->StopCapture(); |
|
168 } |
|
169 } |
|