1 /* |
|
2 * Copyright (c) 2006 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: Implementation of CPhoneQwertyHandler class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "cphoneqwertyhandler.h" |
|
21 #include "cphonelangsettingmonitor.h" |
|
22 #include "cphoneqwertymodemonitor.h" |
|
23 #include <PtiEngine.h> |
|
24 #include <w32std.h> |
|
25 |
|
26 // CONSTANTS |
|
27 |
|
28 // FORWARD DECLARATIONS |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CPhoneQwertyHandler::CPhoneQwertyHandler |
|
34 // C++ default constructor can NOT contain any code, that |
|
35 // might leave. |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CPhoneQwertyHandler::CPhoneQwertyHandler() |
|
39 { |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CPhoneQwertyHandler::ConstructL |
|
44 // Symbian 2nd phase constructor can leave. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 void CPhoneQwertyHandler::ConstructL() |
|
48 { |
|
49 // Language setting monitor |
|
50 iLangSettingMonitor = CPhoneLangSettingMonitor::NewL(); |
|
51 iLangSettingMonitor->AddObserverL( *this ); |
|
52 |
|
53 // Qwerty mode |
|
54 iQwertyModeMonitor = CPhoneQwertyModeMonitor::NewL(); |
|
55 iQwertyModeMonitor->AddObserverL( *this ); |
|
56 |
|
57 // Read current values |
|
58 iInputLanguageId = iLangSettingMonitor->InputLanguage(); |
|
59 iQwertyMode = iQwertyModeMonitor->QwertyMode(); |
|
60 |
|
61 if ( iQwertyMode ) |
|
62 { |
|
63 LoadNumericKeyBindings( iInputLanguageId, iQwertyModeMonitor->Keyboard() ); |
|
64 } |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CPhoneQwertyHandler::NewL |
|
69 // Two-phased constructor. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 EXPORT_C CPhoneQwertyHandler* CPhoneQwertyHandler::NewL() |
|
73 { |
|
74 CPhoneQwertyHandler* self = |
|
75 new (ELeave) CPhoneQwertyHandler(); |
|
76 |
|
77 CleanupStack::PushL( self ); |
|
78 self->ConstructL(); |
|
79 CleanupStack::Pop( self ); |
|
80 |
|
81 return self; |
|
82 } |
|
83 |
|
84 // Destructor |
|
85 EXPORT_C CPhoneQwertyHandler::~CPhoneQwertyHandler() |
|
86 { |
|
87 iLangSettingMonitor->RemoveObserver( *this ); |
|
88 delete iLangSettingMonitor; |
|
89 iLangSettingMonitor = NULL; |
|
90 iQwertyModeMonitor->RemoveObserver( *this ); |
|
91 delete iQwertyModeMonitor; |
|
92 iQwertyModeMonitor = NULL; |
|
93 iNumericKeys.Close(); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CPhoneQwertyHandler::IsQwertyInput |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 EXPORT_C TBool CPhoneQwertyHandler::IsQwertyInput() const |
|
101 { |
|
102 return iQwertyMode > 0 ? ETrue : EFalse; |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CPhoneQwertyHandler::HandleLanguageSettingChange |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 void CPhoneQwertyHandler::HandleInputLanguageSettingChange( TInt aLanguage ) |
|
110 { |
|
111 iInputLanguageId = aLanguage; |
|
112 if ( iQwertyMode ) |
|
113 { |
|
114 LoadNumericKeyBindings( iInputLanguageId, iQwertyModeMonitor->Keyboard() ); |
|
115 } |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CPhoneQwertyHandler::HandleQwertyModeChange |
|
120 // Loads keybinding with keyboard EPtiKeyboardNone if no keyboeard has been |
|
121 // defined |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 void CPhoneQwertyHandler::HandleQwertyModeChange( TInt aMode ) |
|
125 { |
|
126 iQwertyMode = aMode; |
|
127 #ifndef RD_INTELLIGENT_TEXT_INPUT |
|
128 if ( iQwertyMode && !iNumericKeys.Count() ) |
|
129 { |
|
130 LoadNumericKeyBindings( iInputLanguageId, iQwertyModeMonitor->Keyboard() ); |
|
131 } |
|
132 #endif |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CPhoneQwertyHandler::HandleKeyboardLayoutChange |
|
137 // This event comes after HandleQwertyModeChange |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 void CPhoneQwertyHandler::HandleKeyboardLayoutChange() |
|
141 { |
|
142 |
|
143 LoadNumericKeyBindings( iInputLanguageId, iQwertyModeMonitor->Keyboard() ); |
|
144 |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CPhoneQwertyHandler::LoadNumericKeyBindings |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void CPhoneQwertyHandler::LoadNumericKeyBindings( TInt aLanguage, TInt aKeyboard ) |
|
152 { |
|
153 iNumericKeys.Reset(); |
|
154 |
|
155 #ifdef RD_INTELLIGENT_TEXT_INPUT |
|
156 TPtiKeyboardType keyboard = static_cast<TPtiKeyboardType>( aKeyboard ); |
|
157 TRAPD( err, |
|
158 { |
|
159 CPtiEngine* ptiEngine = CPtiEngine::NewL(); |
|
160 CleanupStack::PushL( ptiEngine ); |
|
161 |
|
162 ptiEngine->GetNumericModeKeysForQwertyL( aLanguage, |
|
163 iNumericKeys, |
|
164 keyboard ); |
|
165 CleanupStack::PopAndDestroy( ptiEngine ); |
|
166 } ); // TRAP |
|
167 #else |
|
168 TRAPD( err, |
|
169 { |
|
170 CPtiEngine* ptiEngine = CPtiEngine::NewL(); |
|
171 CleanupStack::PushL( ptiEngine ); |
|
172 ptiEngine->GetNumericModeKeysForQwertyL( aLanguage, |
|
173 iNumericKeys ); |
|
174 CleanupStack::PopAndDestroy( ptiEngine ); |
|
175 } ); // TRAP |
|
176 #endif |
|
177 |
|
178 if ( err ) |
|
179 { |
|
180 iNumericKeys.Reset(); |
|
181 iQwertyMode = 0; // To default mode |
|
182 } |
|
183 else |
|
184 { |
|
185 // remove keys that are not remapped |
|
186 TInt numericKeysCount = iNumericKeys.Count(); |
|
187 while ( numericKeysCount-- ) |
|
188 { |
|
189 TPtiNumericKeyBinding numKeyBind = iNumericKeys[numericKeysCount]; |
|
190 |
|
191 // This is PTI bug? Should not be in numeric keys list. |
|
192 if ( numKeyBind.iKey == EPtiKeyQwertySpace ) |
|
193 { |
|
194 iNumericKeys.Remove( numericKeysCount ); |
|
195 } |
|
196 } |
|
197 } |
|
198 } |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CPhoneQwertyHandler::NumericKeyCode |
|
202 // ----------------------------------------------------------------------------- |
|
203 // |
|
204 EXPORT_C TInt CPhoneQwertyHandler::NumericKeyCode( const TKeyEvent& aKeyEvent ) |
|
205 { |
|
206 |
|
207 // Check shift state |
|
208 TBool shiftActive(EFalse); |
|
209 shiftActive = aKeyEvent.iModifiers & EModifierLeftShift || |
|
210 aKeyEvent.iModifiers & EModifierRightShift; //|| |
|
211 |
|
212 TInt numericKeysCount = iNumericKeys.Count(); |
|
213 |
|
214 while ( numericKeysCount-- ) |
|
215 { |
|
216 TPtiNumericKeyBinding numKeyBind = iNumericKeys[numericKeysCount]; |
|
217 |
|
218 TBool shiftRequired = ( numKeyBind.iCase ==EPtiCaseUpper ) || |
|
219 ( numKeyBind.iCase ==EPtiCaseChrUpper ); |
|
220 |
|
221 if ( numKeyBind.iKey == aKeyEvent.iScanCode && |
|
222 (shiftRequired == shiftActive ) ) |
|
223 { |
|
224 return numKeyBind.iChar; |
|
225 } |
|
226 } |
|
227 |
|
228 return EKeyNull; |
|
229 } |
|
230 |
|
231 // End of File |
|