|
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 "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 "hidlayoutids.h" |
|
23 #include "mapping.h" |
|
24 #include "layout.h" |
|
25 #include "debug.h" |
|
26 |
|
27 // ---------------------------------------------------------------------- |
|
28 |
|
29 const TInt TFindLayoutId::KDefaultLayoutId = EUnitedKingdom; |
|
30 |
|
31 // ---------------------------------------------------------------------- |
|
32 // Map a HID country ID to a keyboard layout ID: |
|
33 // |
|
34 const TFindLayoutId::TCountryMapEntry TFindLayoutId::KMapCountryToLayout[] = |
|
35 { |
|
36 // HID ID -> Standard layout ID |
|
37 // |
|
38 { 2, EBelgian }, // Belgian |
|
39 { 6, EDanish }, // Danish |
|
40 { 7, EFinnishSwedish }, // Finnish |
|
41 { 8, EFrench }, // French |
|
42 { 9, EGerman }, // German |
|
43 { 14, EItalian }, // Italian |
|
44 { 18, EDutch }, // Netherlands/Dutch |
|
45 { 19, ENorwegian }, // Norwegian |
|
46 { 22, EPortuguese }, // Portuguese |
|
47 { 25, ESpanish }, // Spanish |
|
48 { 26, EFinnishSwedish }, // Swedish |
|
49 { 32, EUnitedKingdom }, // UK |
|
50 { 33, EUnitedStates }, // US |
|
51 // |
|
52 // Not in requirements, but layouts do exist. (Note that it |
|
53 // doesn't matter if a layout is listed here but isn't installed, |
|
54 // as the default layout will be used instead.) |
|
55 // |
|
56 { 4, ECanadianFrench }, // Canadian-French |
|
57 { 3, ECanadianMultilingual }, // Canadian-Bilingual |
|
58 { 13, EUSInternational }, // International (ISO) |
|
59 { 17, ELatinAmerican }, // Latin American |
|
60 { 27, ESwissFrench }, // Swiss/French |
|
61 { 28, ESwissGerman }, // Swiss/German |
|
62 }; |
|
63 |
|
64 const TInt TFindLayoutId::KCountryMapSize = |
|
65 (sizeof (KMapCountryToLayout)) / (sizeof (TCountryMapEntry)); |
|
66 |
|
67 // ---------------------------------------------------------------------- |
|
68 // Map a HID country ID (Nokia SU-8) to a keyboard layout ID: |
|
69 // |
|
70 const TFindLayoutId::TCountryMapEntry TFindLayoutId::KMapSu8CountryToLayout[] = |
|
71 { |
|
72 // HID ID -> Nokia SU-8 layout ID |
|
73 // |
|
74 // We don't know what language code the SU-8 keyboards will return, |
|
75 // so we'll include them all for now: |
|
76 // |
|
77 { 33, ESu8USEnglish }, // US |
|
78 { 7, ESu8FinnishSwedish }, // Finnish |
|
79 { 26, ESu8FinnishSwedish }, // Swedish |
|
80 { 6, ESu8DanishNorwegian }, // Danish |
|
81 { 19, ESu8DanishNorwegian }, // Norwegian |
|
82 { 9, ESu8German } // German |
|
83 }; |
|
84 |
|
85 const TInt TFindLayoutId::KSu8CountryMapSize = |
|
86 (sizeof (KMapSu8CountryToLayout)) / (sizeof (TCountryMapEntry)); |
|
87 |
|
88 // ---------------------------------------------------------------------- |
|
89 // Map a TLanguage enum, as returned by User::Language(), to a |
|
90 // keyboard layout ID: |
|
91 // |
|
92 const TFindLayoutId::TLanguageMapEntry TFindLayoutId::KMapLanguageToLayout[] = |
|
93 { |
|
94 // TLanguage ID -> Standard layout ID, Nokia SU-8 layout ID |
|
95 // |
|
96 { ELangEnglish, EUnitedKingdom, ESu8USEnglish }, |
|
97 { ELangFrench, EFrench, 0 }, |
|
98 { ELangGerman, EGerman, ESu8German }, |
|
99 { ELangSpanish, ESpanish, 0 }, |
|
100 { ELangItalian, EItalian, 0 }, |
|
101 { ELangSwedish, EFinnishSwedish, ESu8FinnishSwedish }, |
|
102 { ELangDanish, EDanish, ESu8DanishNorwegian }, |
|
103 { ELangNorwegian, ENorwegian, ESu8DanishNorwegian }, |
|
104 { ELangFinnish, EFinnishSwedish, ESu8FinnishSwedish }, |
|
105 { ELangAmerican, EUnitedStates, ESu8USEnglish }, |
|
106 { ELangSwissFrench, ESwissFrench, 0 }, |
|
107 { ELangSwissGerman, ESwissGerman, 0 }, |
|
108 { ELangPortuguese, EPortuguese, 0 }, |
|
109 { ELangIcelandic, EIcelandic, 0 }, |
|
110 { ELangDutch, EDutch, 0 }, |
|
111 { ELangBelgianFlemish, EBelgian, 0 }, |
|
112 { ELangBelgianFrench, EBelgian, 0 }, |
|
113 { ELangInternationalEnglish, EUSInternational, ESu8USEnglish }, |
|
114 { ELangCanadianFrench, ECanadianFrench, 0 }, |
|
115 { ELangLatinAmericanSpanish, ELatinAmerican, 0 }, |
|
116 { ELangFinlandSwedish, EFinnishSwedish, ESu8FinnishSwedish }, |
|
117 { ELangRussian, ERussian, ESu8Russian } |
|
118 |
|
119 // } |
|
120 }; |
|
121 |
|
122 const TInt TFindLayoutId::KLanguageMapSize = |
|
123 (sizeof (KMapLanguageToLayout)) / (sizeof (TLanguageMapEntry)); |
|
124 |
|
125 // ---------------------------------------------------------------------- |
|
126 |
|
127 TFindLayoutId::TFindLayoutId(TInt aHidCountryId, |
|
128 TInt aVendorId, TInt aProductCode) |
|
129 { |
|
130 TRACE_INFO( (_L("TFindLayoutId(Country %d, Vendor %d, Product %d)"), |
|
131 aHidCountryId, aVendorId, aProductCode)); |
|
132 |
|
133 const TInt KNokiaVendorId = 0x5555; |
|
134 const TInt KSu8ProductCode = 0x00dd; |
|
135 |
|
136 iIsNokiaSu8 = (aVendorId == KNokiaVendorId) |
|
137 && (aProductCode == KSu8ProductCode); |
|
138 |
|
139 //Used to identify the NOKIA SU8 PROTOTYPE |
|
140 if ((aVendorId == 0x5555) && (aProductCode == 0x5555)) |
|
141 { |
|
142 iIsNokiaSu8 = ETrue; |
|
143 } |
|
144 |
|
145 iLayout = 0; // 0 = invalid layout ID = "unknown" |
|
146 |
|
147 iFoundLayout = EFalse; |
|
148 |
|
149 if (aHidCountryId != 0) |
|
150 { |
|
151 // Use the look-up table to find the most appropriate keyboard |
|
152 // layout for this country code: |
|
153 // |
|
154 TRACE_INFO( (_L("TFindLayoutId(): country %d"), |
|
155 aHidCountryId)); |
|
156 iLayout = CountryToLayout(aHidCountryId, iIsNokiaSu8); |
|
157 |
|
158 if (iLayout != 0) |
|
159 { |
|
160 iFoundLayout = ETrue; |
|
161 } |
|
162 } |
|
163 |
|
164 if (iLayout == 0) |
|
165 { |
|
166 // Either no country code was specified, or we couldn't find |
|
167 // an appropriate layout listed in the look-up table. |
|
168 // Instead, attempt to infer the layout using the current |
|
169 // phone language setting: |
|
170 // |
|
171 TRACE_INFO( (_L("TFindLayoutId(): language %d"), |
|
172 User::Language())); |
|
173 iLayout = LanguageToLayout(User::Language(), iIsNokiaSu8); |
|
174 } |
|
175 |
|
176 if (iLayout == 0) |
|
177 { |
|
178 iLayout = KDefaultLayoutId; |
|
179 TRACE_INFO( (_L("TFindLayoutId(): default layout"))); |
|
180 } |
|
181 |
|
182 TRACE_INFO( (_L("TFindLayoutId(): layout is %d"), iLayout)); |
|
183 } |
|
184 |
|
185 // ---------------------------------------------------------------------- |
|
186 |
|
187 TInt TFindLayoutId::CountryToLayout(TInt aHidCountryId, TBool aIsNokiaSu8) |
|
188 { |
|
189 const TCountryMapEntry* table = |
|
190 aIsNokiaSu8 ? KMapSu8CountryToLayout : KMapCountryToLayout; |
|
191 const TInt size = |
|
192 aIsNokiaSu8 ? KSu8CountryMapSize : KCountryMapSize; |
|
193 |
|
194 TInt layout = 0; |
|
195 |
|
196 for (TInt i=0; (i<size) && (layout == 0); ++i) |
|
197 { |
|
198 const TCountryMapEntry& entry = table[i]; |
|
199 |
|
200 if (entry.iHidCountryId == aHidCountryId) |
|
201 { |
|
202 layout = entry.iLayoutId; |
|
203 } |
|
204 } |
|
205 |
|
206 return layout; |
|
207 } |
|
208 |
|
209 TInt TFindLayoutId::LanguageToLayout(TLanguage aLanguage, TBool aIsNokiaSu8) |
|
210 { |
|
211 TInt layout = 0; |
|
212 |
|
213 for (TInt i=0; (i<KLanguageMapSize) && (layout == 0); ++i) |
|
214 { |
|
215 const TLanguageMapEntry& entry = KMapLanguageToLayout[i]; |
|
216 |
|
217 if (entry.iLanguage == aLanguage) |
|
218 { |
|
219 layout = aIsNokiaSu8 ? entry.iSu8LayoutId : entry.iLayoutId; |
|
220 } |
|
221 } |
|
222 |
|
223 return layout; |
|
224 } |
|
225 |
|
226 // ---------------------------------------------------------------------- |