|
1 /* |
|
2 * Copyright (c) 2007 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: Key capture utility |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "lockappkeycapturecontroller.h" |
|
21 #include <w32std.h> |
|
22 |
|
23 // ================= STATIC MEMBERS ========================= |
|
24 |
|
25 CLockAppKeyCaptureController* CLockAppKeyCaptureController::instance = NULL; |
|
26 |
|
27 |
|
28 // ================= STATIC FUNCTIONS ======================= |
|
29 |
|
30 // --------------------------------------------------------- |
|
31 // Initializes the key capture utility by creating an instance of it |
|
32 // --------------------------------------------------------- |
|
33 CLockAppKeyCaptureController* CLockAppKeyCaptureController::InitL( RWindowGroup& aWindowGroup ) |
|
34 { |
|
35 if ( !instance ) |
|
36 { |
|
37 instance = new ( ELeave ) CLockAppKeyCaptureController( aWindowGroup ); |
|
38 } |
|
39 return instance; |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------- |
|
43 // Destroys the key capture utility's instance |
|
44 // --------------------------------------------------------- |
|
45 void CLockAppKeyCaptureController::Destroy( ) |
|
46 { |
|
47 if ( instance ) |
|
48 { |
|
49 delete instance; |
|
50 instance = NULL; |
|
51 } |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------- |
|
55 // Capture a key |
|
56 // --------------------------------------------------------- |
|
57 void CLockAppKeyCaptureController::CaptureKey( TUint32 aKey, TUint32 aKeyCode, TPhoneKeyCaptureType aType ) |
|
58 { |
|
59 RDebug::Printf( "%s %s (%u) aKey=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aKey ); |
|
60 RDebug::Printf( "%s %s (%u) aKeyCode=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aKeyCode ); |
|
61 RDebug::Printf( "%s %s (%u) aType=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aType ); |
|
62 |
|
63 if ( instance ) |
|
64 { |
|
65 instance->StartCapturingKey( aKey, aKeyCode, aType ); |
|
66 } |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------- |
|
70 // Release a key (previously captured) |
|
71 // --------------------------------------------------------- |
|
72 void CLockAppKeyCaptureController::ReleaseKey( TUint32 aKey ) |
|
73 { |
|
74 RDebug::Printf( "%s %s (%u) aKey=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aKey ); |
|
75 |
|
76 if ( instance ) |
|
77 { |
|
78 instance->StopCapturingKey( aKey ); |
|
79 } |
|
80 } |
|
81 |
|
82 // ================= INSTANCE FUNCTIONS ============================ |
|
83 |
|
84 // --------------------------------------------------------- |
|
85 // Private default constructor |
|
86 // --------------------------------------------------------- |
|
87 CLockAppKeyCaptureController::CLockAppKeyCaptureController( RWindowGroup& aWindowGroup ) : |
|
88 iWindowGroup( aWindowGroup) |
|
89 { |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------- |
|
93 // Private destructor |
|
94 // --------------------------------------------------------- |
|
95 CLockAppKeyCaptureController::~CLockAppKeyCaptureController( ) |
|
96 { |
|
97 RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 ); |
|
98 |
|
99 // should we have any captured keys, stop capturing now |
|
100 TInt capturedKeyCount = iCapturedKeys.Count( ); |
|
101 for (TInt i = 0; i < capturedKeyCount; i++ ) |
|
102 { |
|
103 StopKeyCapture( iCapturedKeys[i] ); |
|
104 } |
|
105 iCapturedKeys.Close( ); |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------- |
|
109 // Starts capturing a key |
|
110 // --------------------------------------------------------- |
|
111 void CLockAppKeyCaptureController::StartCapturingKey( TUint32 aKey, TUint32 aKeyCode, TPhoneKeyCaptureType aType ) |
|
112 { |
|
113 TInt32 handle = KErrNotFound; |
|
114 RDebug::Printf( "%s %s (%u) aKey=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aKey ); |
|
115 RDebug::Printf( "%s %s (%u) aKeyCode=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aKeyCode ); |
|
116 RDebug::Printf( "%s %s (%u) aType=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aType ); |
|
117 |
|
118 if ( !IsKeyCaptured( aKey ) ) |
|
119 { |
|
120 TPhoneKeyCapture keyCapture; |
|
121 keyCapture.iKey = (TStdScanCode) aKey; |
|
122 keyCapture.iKeyCode = (TKeyCode) aKeyCode; |
|
123 keyCapture.iHandle = 0; // set as initial value |
|
124 keyCapture.iHandleForUpAndDown = 0; // set as initial value |
|
125 |
|
126 switch( aType ) |
|
127 { |
|
128 case EKeyCaptureEvent: |
|
129 keyCapture.iType = EKeyCaptureEvent; |
|
130 keyCapture.iHandle = iWindowGroup.CaptureKey( keyCapture.iKeyCode, 0, 0 ); |
|
131 handle = keyCapture.iHandle; |
|
132 break; |
|
133 case EKeyCaptureUpAndDownEvents: |
|
134 keyCapture.iType = EKeyCaptureUpAndDownEvents; |
|
135 keyCapture.iHandleForUpAndDown = iWindowGroup.CaptureKeyUpAndDowns( keyCapture.iKey, 0, 0 ); |
|
136 handle = keyCapture.iHandleForUpAndDown; |
|
137 break; |
|
138 default: // EKeyCaptureAllEvents |
|
139 { |
|
140 keyCapture.iType = EKeyCaptureAllEvents; |
|
141 keyCapture.iHandle = iWindowGroup.CaptureKey( keyCapture.iKeyCode, 0, 0 ); |
|
142 if ( keyCapture.iHandle >= 0 ) |
|
143 { |
|
144 keyCapture.iHandleForUpAndDown = iWindowGroup.CaptureKeyUpAndDowns( keyCapture.iKey, 0, 0 ); |
|
145 if ( keyCapture.iHandleForUpAndDown < 0 ) |
|
146 { |
|
147 iWindowGroup.CancelCaptureKey( keyCapture.iHandle ); |
|
148 } |
|
149 handle = keyCapture.iHandleForUpAndDown; |
|
150 } |
|
151 break; |
|
152 } |
|
153 } |
|
154 |
|
155 RDebug::Printf( "CLockAppKeyCaptureController::StartCapturingKey - handle: 0x%08x", handle ); |
|
156 |
|
157 if ( handle >= 0 ) |
|
158 { |
|
159 if ( iCapturedKeys.Append( keyCapture )!= KErrNone ) |
|
160 { |
|
161 StopKeyCapture( keyCapture ); |
|
162 } |
|
163 } |
|
164 } |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------- |
|
168 // Stops capturing a key |
|
169 // --------------------------------------------------------- |
|
170 void CLockAppKeyCaptureController::StopCapturingKey( TUint32 aKey ) |
|
171 { |
|
172 RDebug::Printf( "%s %s (%u) aKey=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aKey ); |
|
173 const TInt capturedKeyCount = iCapturedKeys.Count( ); |
|
174 TBool foundKey = EFalse; |
|
175 for (TInt i = 0; ( i < capturedKeyCount ) && !foundKey; i++ ) |
|
176 { |
|
177 if ( iCapturedKeys[i].iKey == aKey ) |
|
178 { |
|
179 foundKey = ETrue; |
|
180 StopKeyCapture( iCapturedKeys[i] ); |
|
181 iCapturedKeys.Remove( i ); |
|
182 } |
|
183 } |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------- |
|
187 // May be used to ask whether a key has been set to be captured |
|
188 // --------------------------------------------------------- |
|
189 TBool CLockAppKeyCaptureController::IsKeyCaptured( TUint32 aKey ) const |
|
190 { |
|
191 RDebug::Printf( "%s %s (%u) aKey=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aKey ); |
|
192 const TInt capturedKeyCount = iCapturedKeys.Count( ); |
|
193 TBool isCaptured = EFalse; |
|
194 for (TInt i = 0; ( i < capturedKeyCount ) && !isCaptured; i++ ) |
|
195 { |
|
196 isCaptured = iCapturedKeys[i].iKey == aKey; |
|
197 } |
|
198 return isCaptured; |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------- |
|
202 // Stops capturing a key |
|
203 // --------------------------------------------------------- |
|
204 void CLockAppKeyCaptureController::StopKeyCapture( TPhoneKeyCapture aKeyCapture ) |
|
205 { |
|
206 RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 ); |
|
207 switch ( aKeyCapture.iType ) |
|
208 { |
|
209 case EKeyCaptureEvent: |
|
210 iWindowGroup.CancelCaptureKey( aKeyCapture.iHandle ); |
|
211 break; |
|
212 case EKeyCaptureUpAndDownEvents: |
|
213 iWindowGroup.CancelCaptureKeyUpAndDowns( aKeyCapture.iHandleForUpAndDown ); |
|
214 break; |
|
215 default: // EPhoneKeyCaptureAllEvents |
|
216 { |
|
217 iWindowGroup.CancelCaptureKey( aKeyCapture.iHandle ); |
|
218 iWindowGroup.CancelCaptureKeyUpAndDowns( aKeyCapture.iHandleForUpAndDown ); |
|
219 break; |
|
220 } |
|
221 } |
|
222 } |
|
223 |
|
224 // end of file |