|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbCore module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include "hbinputkeymap.h" |
|
27 |
|
28 #include <QChar> |
|
29 #include <QString> |
|
30 #include <QStringList> |
|
31 |
|
32 const int DeadKeyTable[14] = {0x060, 0x0B4, 0x05E, 0x0A8, 0x022, 0x2C7, 0x2D8, 0x0B0, 0x2DB, 0x2DD, 0x07E, 0x0B8, 0x201A, 0x0B7}; |
|
33 |
|
34 const int DeadKeyCombineTable[59][3] = { |
|
35 {0x060, 0x061, 0x0e0}, |
|
36 {0x060, 0x065, 0x0e8}, |
|
37 {0x060, 0x069, 0x0ec}, |
|
38 {0x060, 0x06F, 0x0f2}, |
|
39 {0x060, 0x075, 0x0f9}, |
|
40 |
|
41 {0x0b4, 0x061, 0x0e1}, |
|
42 {0x0b4, 0x065, 0x0e9}, |
|
43 {0x0b4, 0x069, 0x0ed}, |
|
44 {0x0b4, 0x06F, 0x0f3}, |
|
45 {0x0b4, 0x075, 0x0fa}, |
|
46 {0x0b4, 0x079, 0x0fd}, |
|
47 {0x0b4, 0x063, 0x107}, |
|
48 {0x0b4, 0x06c, 0x13A}, |
|
49 {0x0b4, 0x06e, 0x144}, |
|
50 {0x0b4, 0x072, 0x155}, |
|
51 {0x0b4, 0x053, 0x15b}, |
|
52 {0x0b4, 0x074, 0x163}, |
|
53 {0x0b4, 0x07A, 0x17A}, |
|
54 |
|
55 {0x05e, 0x061, 0x0e2}, |
|
56 {0x05e, 0x065, 0x0ea}, |
|
57 {0x05e, 0x069, 0x0ee}, |
|
58 {0x05e, 0x06F, 0x0f4}, |
|
59 {0x05e, 0x075, 0x0fb}, |
|
60 |
|
61 {0x0a8, 0x061, 0x0e4}, |
|
62 {0x0a8, 0x065, 0x0eb}, |
|
63 {0x0a8, 0x069, 0x0ef}, |
|
64 {0x0a8, 0x06F, 0x0f6}, |
|
65 {0x0a8, 0x075, 0x0fc}, |
|
66 {0x0a8, 0x079, 0x0ff}, |
|
67 |
|
68 {0x022, 0x061, 0x0e4}, |
|
69 {0x022, 0x065, 0x0eb}, |
|
70 {0x022, 0x069, 0x0ef}, |
|
71 {0x022, 0x06F, 0x0f6}, |
|
72 {0x022, 0x075, 0x0fc}, |
|
73 {0x022, 0x079, 0x0ff}, |
|
74 |
|
75 {0x2c7, 0x065, 0x11b}, |
|
76 {0x2c7, 0x063, 0x10d}, |
|
77 {0x2c7, 0x064, 0x10f}, |
|
78 {0x2c7, 0x06C, 0x13e}, |
|
79 {0x2c7, 0x06E, 0x148}, |
|
80 {0x2c7, 0x072, 0x159}, |
|
81 {0x2c7, 0x053, 0x161}, |
|
82 {0x2c7, 0x074, 0x165}, |
|
83 {0x2c7, 0x07A, 0x17E}, |
|
84 |
|
85 {0x2d8, 0x061, 0x103}, |
|
86 |
|
87 {0x0b0, 0x061, 0x0c5}, |
|
88 {0x0b0, 0x075, 0x16f}, |
|
89 |
|
90 {0x2db, 0x061, 0x105}, |
|
91 {0x2db, 0x065, 0x119}, |
|
92 |
|
93 {0x2dd, 0x06F, 0x151}, |
|
94 {0x2dd, 0x075, 0x171}, |
|
95 |
|
96 {0x07e, 0x061, 0x0e3}, |
|
97 {0x07e, 0x06F, 0x0f5}, |
|
98 {0x07e, 0x06E, 0x0f1}, |
|
99 |
|
100 {0x0b8, 0x063, 0x0e7}, |
|
101 {0x0b8, 0x072, 0x15f}, |
|
102 |
|
103 {0x201a, 0x063, 0x0e7}, |
|
104 {0x201a, 0x072, 0x15f}, |
|
105 |
|
106 {0x0b7, 0x07A, 0x17c}}; |
|
107 |
|
108 class HbKeymapPrivate |
|
109 { |
|
110 |
|
111 public: |
|
112 HbKeymapPrivate(HbInputLanguage language); |
|
113 ~HbKeymapPrivate(); |
|
114 |
|
115 public: |
|
116 QMap<HbKeyboardType, HbKeyboardMap*> mKeyboards; |
|
117 HbInputLanguage mLanguage; |
|
118 }; |
|
119 |
|
120 |
|
121 HbKeymapPrivate::HbKeymapPrivate(HbInputLanguage language) |
|
122 : mLanguage(language) |
|
123 { |
|
124 } |
|
125 |
|
126 HbKeymapPrivate::~HbKeymapPrivate() |
|
127 { |
|
128 foreach (HbKeyboardMap* keymap, mKeyboards) { |
|
129 foreach (HbMappedKey* key, keymap->keys) { |
|
130 delete key; |
|
131 } |
|
132 delete keymap; |
|
133 } |
|
134 mKeyboards.clear(); |
|
135 } |
|
136 |
|
137 /// @endcond |
|
138 |
|
139 /*! |
|
140 @alpha |
|
141 @hbcore |
|
142 \class HbMappedKey |
|
143 |
|
144 \brief Contains definition for characters associated with one keyboard key. |
|
145 |
|
146 */ |
|
147 |
|
148 /*! |
|
149 Constructs the object. |
|
150 */ |
|
151 HbMappedKey::HbMappedKey() |
|
152 { |
|
153 |
|
154 } |
|
155 |
|
156 /*! |
|
157 Destructs the object. |
|
158 */ |
|
159 HbMappedKey::~HbMappedKey() |
|
160 { |
|
161 } |
|
162 |
|
163 /*! |
|
164 Returns QString of characters associated with the given modifiers in this key if defined, |
|
165 otherwise returns an empty QString. |
|
166 */ |
|
167 const QString HbMappedKey::characters(const HbModifiers modifiers) const |
|
168 { |
|
169 switch (modifiers) { |
|
170 case HbModifierNone: |
|
171 if (chars.count() >= 1) { |
|
172 return chars.at(0); |
|
173 } else { |
|
174 return QString(); |
|
175 } |
|
176 case HbModifierShiftPressed: |
|
177 if (chars.count() >= 2) { |
|
178 return chars.at(1); |
|
179 } else { |
|
180 return QString(); |
|
181 } |
|
182 case HbModifierFnPressed: |
|
183 if (chars.count() >= 3) { |
|
184 return chars.at(2); |
|
185 } else { |
|
186 return QString(); |
|
187 } |
|
188 case HbModifierShiftPressed | HbModifierFnPressed: |
|
189 if (chars.count() >= 4) { |
|
190 return chars.at(3); |
|
191 } else { |
|
192 return QString(); |
|
193 } |
|
194 default: |
|
195 return QString(); |
|
196 } |
|
197 } |
|
198 /*! |
|
199 @alpha |
|
200 @hbcore |
|
201 \class HbKeymap |
|
202 \brief Contains information on characters mapped to keyboard keys. |
|
203 |
|
204 HbKeymaps contain keymap data for different keyboards and a single language. |
|
205 Usually a HbKeymap is created by HbKeymapFactory and already contains the data |
|
206 for all keyboards defined in the system. |
|
207 |
|
208 The keyboards can be accessed using the keyboard() function, which returns a HbKeyboardMap struct, containing |
|
209 a list of HbMappedKeys. HbMappedKeys each contain keycode and strings for characters available using different modifiers. |
|
210 Any of the character strings except noModifier may be null if they are not defined. |
|
211 |
|
212 Also helper methods are provided for finding keys containing certain keycodes or mapped characters. |
|
213 |
|
214 \sa HbKeymapFactory |
|
215 \sa HbInputLanguage |
|
216 */ |
|
217 |
|
218 /*! |
|
219 Constructs the object. |
|
220 */ |
|
221 HbKeymap::HbKeymap(HbInputLanguage language) |
|
222 { |
|
223 mPrivate = new HbKeymapPrivate(language); |
|
224 } |
|
225 |
|
226 /*! |
|
227 Destructs the object. |
|
228 */ |
|
229 HbKeymap::~HbKeymap() |
|
230 { |
|
231 delete mPrivate; |
|
232 } |
|
233 |
|
234 /*! |
|
235 Adds a keyboard definition to the keymap. Usually needed only by the HbKeymapFactory. |
|
236 |
|
237 \param keyboard Keyboard to be added in the internal structure. |
|
238 */ |
|
239 void HbKeymap::addKeyboard(HbKeyboardMap *keyboard) |
|
240 { |
|
241 if (keyboard) { |
|
242 mPrivate->mKeyboards.insert(keyboard->type, keyboard); |
|
243 } |
|
244 } |
|
245 |
|
246 /*! |
|
247 Returns a keyboard of the type \a keyboard or 0 if not found. |
|
248 |
|
249 \param keyboard The type of the keyboard. |
|
250 */ |
|
251 const HbKeyboardMap *HbKeymap::keyboard(HbKeyboardType keyboard) const |
|
252 { |
|
253 HbKeyboardMap* keyboardMap = 0; |
|
254 if (mPrivate->mKeyboards.contains(keyboard)) { |
|
255 keyboardMap = mPrivate->mKeyboards.value(keyboard); |
|
256 } |
|
257 return keyboardMap; |
|
258 } |
|
259 |
|
260 /*! |
|
261 Returns the language of this keymap. |
|
262 |
|
263 \sa HbInputLanguage |
|
264 */ |
|
265 HbInputLanguage HbKeymap::language() const |
|
266 { |
|
267 return mPrivate->mLanguage; |
|
268 } |
|
269 |
|
270 /*! |
|
271 Returns the key in the keyboard of type \a keyboard, on the position \a keyIndex or 0 if not found. |
|
272 |
|
273 \param keyboard The type of the keyboard. |
|
274 \param keyIndex Index of the key, first key at index 0. |
|
275 */ |
|
276 const HbMappedKey *HbKeymap::keyForIndex(HbKeyboardType keyboard, int keyIndex) const |
|
277 { |
|
278 HbMappedKey* key = 0; |
|
279 if (mPrivate->mKeyboards.contains(keyboard)) { |
|
280 HbKeyboardMap* keymap = mPrivate->mKeyboards.value(keyboard); |
|
281 if (keymap->keys.count() > keyIndex && keyIndex >= 0) { |
|
282 key = keymap->keys.at(keyIndex); |
|
283 } |
|
284 } |
|
285 |
|
286 return key; |
|
287 } |
|
288 |
|
289 /*! |
|
290 Returns the key on the keyboard \a keyboard with specified \a keycode or 0 if not found. |
|
291 |
|
292 \param keyboard The type of the keyboard. |
|
293 \param keycode Keycode to look for. |
|
294 */ |
|
295 const HbMappedKey *HbKeymap::keyForKeycode(HbKeyboardType keyboard, QChar keycode) const |
|
296 { |
|
297 HbMappedKey* key = 0; |
|
298 if (mPrivate->mKeyboards.contains(keyboard)) { |
|
299 HbKeyboardMap* keymap = mPrivate->mKeyboards.value(keyboard); |
|
300 foreach (HbMappedKey* mappedKey, keymap->keys) { |
|
301 if (mappedKey->keycode == keycode) { |
|
302 key = mappedKey; |
|
303 break; |
|
304 } |
|
305 } |
|
306 } |
|
307 |
|
308 return key; |
|
309 } |
|
310 |
|
311 /*! |
|
312 Returns the key on the keyboard \a keyboard containing a mapping to character \a character or 0 |
|
313 if not found. |
|
314 |
|
315 \param keyboard The type of the keyboard. |
|
316 \param character Character to look for. |
|
317 */ |
|
318 const HbMappedKey *HbKeymap::keyForCharacter(HbKeyboardType keyboard, QChar character) const |
|
319 { |
|
320 HbMappedKey* key = 0; |
|
321 if (mPrivate->mKeyboards.contains(keyboard)) { |
|
322 HbKeyboardMap* keymap = mPrivate->mKeyboards.value(keyboard); |
|
323 foreach (HbMappedKey* mappedKey, keymap->keys) { |
|
324 foreach (QString charstring, mappedKey->chars) { |
|
325 if (charstring.contains(character)) { |
|
326 key = mappedKey; |
|
327 break; |
|
328 } |
|
329 } |
|
330 if (key) { |
|
331 break; |
|
332 } |
|
333 } |
|
334 } |
|
335 |
|
336 return key; |
|
337 } |
|
338 |
|
339 /*! |
|
340 Returns true if key is a dead key |
|
341 |
|
342 \param key Key to check. |
|
343 */ |
|
344 |
|
345 bool HbKeymap::isDeadKey(int key) |
|
346 { |
|
347 int size = sizeof(DeadKeyTable) / sizeof(DeadKeyTable[0]); |
|
348 for (int i=0; i<size; i++){ |
|
349 if (key == DeadKeyTable[i]){ |
|
350 return true; |
|
351 } |
|
352 } |
|
353 return false; |
|
354 } |
|
355 |
|
356 /*! |
|
357 Returns key combination for dead key + another key |
|
358 |
|
359 \param deadKey Dead key |
|
360 \param key Key after dead key. |
|
361 \param firstKey possible first combination result key |
|
362 \param secondKey possible second combination result key |
|
363 */ |
|
364 void HbKeymap::combineCharacter(QChar deadKey, QChar key, QChar &firstKey, QChar &secondKey) |
|
365 { |
|
366 QChar lowerKey = key.toLower(); |
|
367 if (key == Qt::Key_Space) { |
|
368 // deadkey + space = deadkey |
|
369 firstKey = deadKey; |
|
370 secondKey = 0; |
|
371 } else if (key == Qt::Key_Backspace) { |
|
372 // deadkey + backspace = nothing |
|
373 firstKey = 0; |
|
374 secondKey = 0; |
|
375 } else { |
|
376 firstKey = deadKey; |
|
377 secondKey = key; |
|
378 int size = sizeof(DeadKeyCombineTable) / sizeof(DeadKeyCombineTable[0][0])/3; |
|
379 for (int i=0; i<size; i++){ |
|
380 if (deadKey == DeadKeyCombineTable[i][0] && lowerKey == DeadKeyCombineTable[i][1]){ |
|
381 if (key.isUpper()) { |
|
382 firstKey = ((QChar)DeadKeyCombineTable[i][2]).toUpper(); |
|
383 } else { |
|
384 firstKey = DeadKeyCombineTable[i][2]; |
|
385 } |
|
386 secondKey = 0; |
|
387 break; |
|
388 } |
|
389 } |
|
390 } |
|
391 return; |
|
392 } |
|
393 |
|
394 // End of file |