|
1 /* |
|
2 * Copyright (c) 2004 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: This is the implementation of application class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32svr.h> |
|
21 |
|
22 #include "finder.h" |
|
23 |
|
24 // ---------------------------------------------------------------------- |
|
25 |
|
26 #ifndef DBG |
|
27 #ifdef _DEBUG |
|
28 #define DBG(a) a |
|
29 #else |
|
30 #define DBG(a) |
|
31 #endif |
|
32 #endif |
|
33 |
|
34 // ---------------------------------------------------------------------- |
|
35 |
|
36 TKeyboardFinder::TKeyboardFinder() : |
|
37 iStandardKeys(0), iModifierKeys(0), iLeds(0), iAppCollection(0) |
|
38 { |
|
39 // Nothing else to do |
|
40 } |
|
41 |
|
42 // ---------------------------------------------------------------------- |
|
43 |
|
44 TBool TKeyboardFinder::BeginCollection(const CCollection* aCollection) |
|
45 { |
|
46 TBool examineCollection = ETrue; |
|
47 |
|
48 if ((aCollection->IsApplication()) && (iAppCollection == 0)) |
|
49 { |
|
50 // Top-level application collection. |
|
51 |
|
52 if ((aCollection->UsagePage() == EUsagePageGenericDesktop) |
|
53 && (aCollection->Usage() == EGenericDesktopUsageKeyboard)) |
|
54 { |
|
55 DBG(RDebug::Print(_L("[HID]\tTKeyboardFinder::BeginCollection: this is keyboard collection "))); |
|
56 // Collection is a keyboard device: |
|
57 iAppCollection = aCollection; |
|
58 iStandardKeys = iModifierKeys = iLeds = 0; |
|
59 } |
|
60 else |
|
61 { |
|
62 // (dont) Skip other types of top-level application collection: |
|
63 DBG(RDebug::Print(_L("[HID]\tTKeyboardFinder::BeginCollection: not keyboard collection "))); |
|
64 examineCollection = EFalse; |
|
65 } |
|
66 } |
|
67 |
|
68 return examineCollection; |
|
69 } |
|
70 |
|
71 TBool TKeyboardFinder::EndCollection(const CCollection* aCollection) |
|
72 { |
|
73 TBool continueSearch = ETrue; |
|
74 |
|
75 if (aCollection == iAppCollection) |
|
76 { |
|
77 // Top-level application(Generic Desktop:Keyboard) finished: |
|
78 // |
|
79 iAppCollection = 0; |
|
80 |
|
81 // Stop if we've found a keyboard we can use in this |
|
82 // application collection: |
|
83 // |
|
84 continueSearch = !Found(); |
|
85 } |
|
86 |
|
87 return continueSearch; |
|
88 } |
|
89 |
|
90 void TKeyboardFinder::Field(const CField* aField) |
|
91 { |
|
92 if (iAppCollection) |
|
93 { |
|
94 if (IsStandardKeys(aField)) |
|
95 { |
|
96 iStandardKeys = aField; |
|
97 } |
|
98 |
|
99 if (IsModifiers(aField)) |
|
100 { |
|
101 iModifierKeys = aField; |
|
102 } |
|
103 |
|
104 if (IsLeds(aField)) |
|
105 { |
|
106 iLeds = aField; |
|
107 } |
|
108 } |
|
109 } |
|
110 |
|
111 // ---------------------------------------------------------------------- |
|
112 |
|
113 TBool TKeyboardFinder::IsModifiers(const CField* aField) const |
|
114 { |
|
115 TBool found = EFalse; |
|
116 |
|
117 if (aField->IsInput() && aField->IsData() && (aField->UsagePage() |
|
118 == EUsagePageKeyboard)) |
|
119 { |
|
120 const TInt KKbdLeftControl = 224; |
|
121 const TInt KKbdRightGUI = 231; |
|
122 |
|
123 // Test for a field containing only modifier keys |
|
124 if ((aField->UsageMin() >= KKbdLeftControl) && (aField->UsageMax() |
|
125 <= KKbdRightGUI)) |
|
126 { |
|
127 DBG(RDebug::Print(_L("[HID]\t Modifier field found"))); |
|
128 found = ETrue; |
|
129 } |
|
130 } |
|
131 |
|
132 return found; |
|
133 } |
|
134 |
|
135 TBool TKeyboardFinder::IsStandardKeys(const CField* aField) const |
|
136 { |
|
137 TBool found = EFalse; |
|
138 |
|
139 if (aField->IsInput() && aField->IsData() && (aField->UsagePage() |
|
140 == EUsagePageKeyboard)) |
|
141 { |
|
142 const TInt KKeyboardRollOver = 0x01; |
|
143 const TInt KKeyboardUpArrow = 0x52; |
|
144 |
|
145 if ((aField->UsageMin() <= KKeyboardRollOver) && (aField->UsageMax() |
|
146 >= KKeyboardUpArrow)) |
|
147 { |
|
148 DBG(RDebug::Print(_L("[HID]\t Standard keys field found"))); |
|
149 found = ETrue; |
|
150 } |
|
151 } |
|
152 |
|
153 return found; |
|
154 } |
|
155 |
|
156 TBool TKeyboardFinder::IsLeds(const CField* aField) const |
|
157 { |
|
158 TBool found = EFalse; |
|
159 |
|
160 if (aField->IsOutput() && aField->IsData() && (aField->UsagePage() |
|
161 == EUsagePageLEDs)) |
|
162 { |
|
163 const TInt KNumLockLed = 1; |
|
164 const TInt KCapsLockLed = 2; |
|
165 |
|
166 // Test for a field containing at least num lock or caps lock |
|
167 if ((aField->UsageMin() <= KCapsLockLed) && (aField->UsageMax() |
|
168 >= KNumLockLed)) |
|
169 { |
|
170 DBG(RDebug::Print(_L("[HID]\t LED field found"))); |
|
171 found = ETrue; |
|
172 } |
|
173 } |
|
174 |
|
175 return found; |
|
176 } |
|
177 |
|
178 // ---------------------------------------------------------------------- |
|
179 |
|
180 TConsumerKeysFinder::TConsumerKeysFinder() : |
|
181 iField(0) |
|
182 { |
|
183 // Nothing else to do |
|
184 } |
|
185 |
|
186 void TConsumerKeysFinder::Field(const CField* aField) |
|
187 { |
|
188 if (!Found() && aField->IsInput() && aField->IsData() |
|
189 && (aField->UsagePage() == EUsagePageConsumer)) |
|
190 { |
|
191 DBG(RDebug::Print(_L("Consumer keys field found\r\n"))); |
|
192 iField = aField; |
|
193 } |
|
194 } |
|
195 |
|
196 TBool TConsumerKeysFinder::BeginCollection(const CCollection* aCollection) |
|
197 { |
|
198 const TInt KConsumerControl = 0x01; |
|
199 |
|
200 // Only look at top-level application (consumer devices: consumer |
|
201 // control) collections: |
|
202 // |
|
203 return aCollection->IsApplication() && (aCollection->UsagePage() |
|
204 == EUsagePageConsumer) && (aCollection->Usage() |
|
205 == KConsumerControl); |
|
206 } |
|
207 |
|
208 TBool TConsumerKeysFinder::EndCollection(const CCollection* /*aCollection*/) |
|
209 { |
|
210 return !Found(); |
|
211 } |
|
212 |
|
213 // ---------------------------------------------------------------------- |
|
214 |
|
215 TPowerKeysFinder::TPowerKeysFinder() : |
|
216 iField(0) |
|
217 { |
|
218 // Nothing else to do |
|
219 } |
|
220 |
|
221 void TPowerKeysFinder::Field(const CField* aField) |
|
222 { |
|
223 if (!Found() && aField->IsInput() && aField->IsData() |
|
224 && (aField->UsagePage() == EUsagePageGenericDesktop)) |
|
225 { |
|
226 // See if the range includes one or more of the power down, |
|
227 // sleep or wakeup controls: |
|
228 |
|
229 const TInt KPowerDown = 0x81; |
|
230 const TInt KWakeUp = 0x83; |
|
231 |
|
232 if ((aField->UsageMin() <= KWakeUp) && (aField->UsageMax() |
|
233 >= KPowerDown)) |
|
234 { |
|
235 DBG(RDebug::Print(_L("[HID]\t Power keys field found\r\n"))); |
|
236 iField = aField; |
|
237 } |
|
238 } |
|
239 } |
|
240 |
|
241 TBool TPowerKeysFinder::BeginCollection(const CCollection* aCollection) |
|
242 { |
|
243 const TInt KSystemControl = 0x80; |
|
244 |
|
245 // Only look at top-level application (generic desktop: system |
|
246 // control) collections: |
|
247 // |
|
248 return aCollection->IsApplication() && (aCollection->UsagePage() |
|
249 == EUsagePageGenericDesktop) && (aCollection->Usage() |
|
250 == KSystemControl); |
|
251 } |
|
252 |
|
253 TBool TPowerKeysFinder::EndCollection(const CCollection*) |
|
254 { |
|
255 return !Found(); |
|
256 } |
|
257 |
|
258 // ---------------------------------------------------------------------- |
|
259 TMouseFinder::TMouseFinder() : |
|
260 iXY(0), iButtons(0), iWheel(0), iAppCollection(0) |
|
261 { |
|
262 // Nothing else to do |
|
263 } |
|
264 |
|
265 // ---------------------------------------------------------------------- |
|
266 |
|
267 TBool TMouseFinder::BeginCollection(const CCollection *aCollection) |
|
268 { |
|
269 TBool examineCollection = ETrue; |
|
270 |
|
271 if ((aCollection->IsApplication()) && (iAppCollection == 0)) |
|
272 { |
|
273 // Top-level application collection. |
|
274 |
|
275 if ((aCollection->UsagePage() == EUsagePageGenericDesktop) |
|
276 && (aCollection->Usage() == EGenericDesktopUsageMouse)) |
|
277 { |
|
278 // Collection is a mouse device: |
|
279 iAppCollection = aCollection; |
|
280 iXY = iWheel = iButtons = 0; |
|
281 } |
|
282 else |
|
283 { |
|
284 // Skip other types of top-level application collection: |
|
285 examineCollection = EFalse; |
|
286 } |
|
287 } |
|
288 |
|
289 return examineCollection; |
|
290 } |
|
291 |
|
292 TBool TMouseFinder::EndCollection(const CCollection *aCollection) |
|
293 { |
|
294 TBool continueSearch = ETrue; |
|
295 |
|
296 DBG(RDebug::Print(_L("[HID]\tTHeadsetFinder::EndCollection"))); |
|
297 if (aCollection == iAppCollection) |
|
298 { |
|
299 // Top-level application(Generic Desktop:Mouse) finished: |
|
300 // |
|
301 iAppCollection = 0; |
|
302 |
|
303 // Stop if we've found a mouse we can use in this |
|
304 // application collection: |
|
305 // |
|
306 continueSearch = !Found(); |
|
307 } |
|
308 |
|
309 return continueSearch; |
|
310 } |
|
311 |
|
312 void TMouseFinder::Field(const CField* aField) |
|
313 { |
|
314 if (iAppCollection) |
|
315 { |
|
316 if (IsWheel(aField)) |
|
317 { |
|
318 iWheel = aField; |
|
319 } |
|
320 |
|
321 if (IsXY(aField)) |
|
322 { |
|
323 iXY = aField; |
|
324 } |
|
325 |
|
326 if (IsButtons(aField)) |
|
327 { |
|
328 iButtons = aField; |
|
329 } |
|
330 } |
|
331 } |
|
332 |
|
333 // ---------------------------------------------------------------------- |
|
334 |
|
335 |
|
336 TBool TMouseFinder::IsXY(const CField* aField) const |
|
337 { |
|
338 TBool found = EFalse; |
|
339 |
|
340 if (aField->IsInput() && aField->IsData() && (aField->UsagePage() |
|
341 == EUsagePageGenericDesktop)) |
|
342 { |
|
343 |
|
344 if (aField->HasUsage(EGenericDesktopUsageX) && aField->HasUsage( |
|
345 EGenericDesktopUsageY)) |
|
346 { |
|
347 DBG(RDebug::Print(_L("[HID]\tXY field found"))); |
|
348 found = ETrue; |
|
349 } |
|
350 } |
|
351 |
|
352 return found; |
|
353 } |
|
354 |
|
355 TBool TMouseFinder::IsButtons(const CField* aField) const |
|
356 { |
|
357 TBool found = EFalse; |
|
358 |
|
359 if (aField->IsInput() && aField->IsData() && (aField->UsagePage() |
|
360 == EUsagePageButton)) |
|
361 { |
|
362 const TInt KMinButtons = 1; |
|
363 const TInt KMaxButtons = 15; |
|
364 |
|
365 // Test for a field containing at least num lock or caps lock |
|
366 if ((aField->UsageMin() >= KMinButtons) && (aField->UsageMax() |
|
367 <= KMaxButtons)) |
|
368 { |
|
369 DBG(RDebug::Print(_L("[HID]\tButtons field found"))); |
|
370 found = ETrue; |
|
371 } |
|
372 } |
|
373 |
|
374 return found; |
|
375 } |
|
376 |
|
377 TBool TMouseFinder::IsWheel(const CField* aField) const |
|
378 { |
|
379 TBool found = EFalse; |
|
380 |
|
381 if (aField->IsInput() && aField->IsData() && (aField->UsagePage() |
|
382 == EUsagePageGenericDesktop)) |
|
383 { |
|
384 if (aField->HasUsage(EGenericDesktopUsageWheel)) |
|
385 { |
|
386 found = ETrue; |
|
387 } |
|
388 } |
|
389 |
|
390 return found; |
|
391 } |