25
|
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 |
static const TUint32 KNumKeyModifiers( EModifierLeftShift | EModifierRightShift | EModifierShift |
|
|
28 |
EModifierLeftFunc | EModifierRightFunc | EModifierFunc );
|
|
29 |
|
|
30 |
|
|
31 |
// FORWARD DECLARATIONS
|
|
32 |
|
|
33 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
34 |
|
|
35 |
// -----------------------------------------------------------------------------
|
|
36 |
// CPhoneQwertyHandler::CPhoneQwertyHandler
|
|
37 |
// C++ default constructor can NOT contain any code, that
|
|
38 |
// might leave.
|
|
39 |
// -----------------------------------------------------------------------------
|
|
40 |
//
|
|
41 |
CPhoneQwertyHandler::CPhoneQwertyHandler()
|
|
42 |
{
|
|
43 |
}
|
|
44 |
|
|
45 |
// -----------------------------------------------------------------------------
|
|
46 |
// CPhoneQwertyHandler::ConstructL
|
|
47 |
// Symbian 2nd phase constructor can leave.
|
|
48 |
// -----------------------------------------------------------------------------
|
|
49 |
//
|
|
50 |
void CPhoneQwertyHandler::ConstructL()
|
|
51 |
{
|
|
52 |
// Language setting monitor
|
|
53 |
iLangSettingMonitor = CPhoneLangSettingMonitor::NewL();
|
|
54 |
iLangSettingMonitor->AddObserverL( *this );
|
|
55 |
|
|
56 |
// Qwerty mode
|
|
57 |
iQwertyModeMonitor = CPhoneQwertyModeMonitor::NewL();
|
|
58 |
iQwertyModeMonitor->AddObserverL( *this );
|
|
59 |
|
|
60 |
// Read current values
|
|
61 |
iInputLanguageId = iLangSettingMonitor->InputLanguage();
|
|
62 |
iQwertyMode = iQwertyModeMonitor->QwertyMode();
|
|
63 |
|
|
64 |
if ( iQwertyMode )
|
|
65 |
{
|
|
66 |
LoadNumericKeyBindings( iInputLanguageId, iQwertyModeMonitor->Keyboard() );
|
|
67 |
}
|
|
68 |
}
|
|
69 |
|
|
70 |
// -----------------------------------------------------------------------------
|
|
71 |
// CPhoneQwertyHandler::NewL
|
|
72 |
// Two-phased constructor.
|
|
73 |
// -----------------------------------------------------------------------------
|
|
74 |
//
|
|
75 |
EXPORT_C CPhoneQwertyHandler* CPhoneQwertyHandler::NewL()
|
|
76 |
{
|
|
77 |
CPhoneQwertyHandler* self =
|
|
78 |
new (ELeave) CPhoneQwertyHandler();
|
|
79 |
|
|
80 |
CleanupStack::PushL( self );
|
|
81 |
self->ConstructL();
|
|
82 |
CleanupStack::Pop( self );
|
|
83 |
|
|
84 |
return self;
|
|
85 |
}
|
|
86 |
|
|
87 |
// Destructor
|
|
88 |
EXPORT_C CPhoneQwertyHandler::~CPhoneQwertyHandler()
|
|
89 |
{
|
|
90 |
iLangSettingMonitor->RemoveObserver( *this );
|
|
91 |
delete iLangSettingMonitor;
|
|
92 |
iLangSettingMonitor = NULL;
|
|
93 |
iQwertyModeMonitor->RemoveObserver( *this );
|
|
94 |
delete iQwertyModeMonitor;
|
|
95 |
iQwertyModeMonitor = NULL;
|
|
96 |
iNumericKeys.Close();
|
|
97 |
}
|
|
98 |
|
|
99 |
// -----------------------------------------------------------------------------
|
|
100 |
// CPhoneQwertyHandler::IsQwertyInput
|
|
101 |
// -----------------------------------------------------------------------------
|
|
102 |
//
|
|
103 |
EXPORT_C TBool CPhoneQwertyHandler::IsQwertyInput() const
|
|
104 |
{
|
|
105 |
return iQwertyMode > 0 ? ETrue : EFalse;
|
|
106 |
}
|
|
107 |
|
|
108 |
// -----------------------------------------------------------------------------
|
|
109 |
// CPhoneQwertyHandler::HandleLanguageSettingChange
|
|
110 |
// -----------------------------------------------------------------------------
|
|
111 |
//
|
|
112 |
void CPhoneQwertyHandler::HandleInputLanguageSettingChange( TInt aLanguage )
|
|
113 |
{
|
|
114 |
iInputLanguageId = aLanguage;
|
|
115 |
if ( iQwertyMode )
|
|
116 |
{
|
|
117 |
LoadNumericKeyBindings( iInputLanguageId, iQwertyModeMonitor->Keyboard() );
|
|
118 |
}
|
|
119 |
}
|
|
120 |
|
|
121 |
// -----------------------------------------------------------------------------
|
|
122 |
// CPhoneQwertyHandler::HandleQwertyModeChange
|
|
123 |
// Loads keybinding with keyboard EPtiKeyboardNone if no keyboeard has been
|
|
124 |
// defined
|
|
125 |
// -----------------------------------------------------------------------------
|
|
126 |
//
|
|
127 |
void CPhoneQwertyHandler::HandleQwertyModeChange( TInt aMode )
|
|
128 |
{
|
|
129 |
iQwertyMode = aMode;
|
|
130 |
#ifndef RD_INTELLIGENT_TEXT_INPUT
|
|
131 |
if ( iQwertyMode && !iNumericKeys.Count() )
|
|
132 |
{
|
|
133 |
LoadNumericKeyBindings( iInputLanguageId, iQwertyModeMonitor->Keyboard() );
|
|
134 |
}
|
|
135 |
#endif
|
|
136 |
}
|
|
137 |
|
|
138 |
// -----------------------------------------------------------------------------
|
|
139 |
// CPhoneQwertyHandler::HandleKeyboardLayoutChange
|
|
140 |
// This event comes after HandleQwertyModeChange
|
|
141 |
// -----------------------------------------------------------------------------
|
|
142 |
//
|
|
143 |
void CPhoneQwertyHandler::HandleKeyboardLayoutChange()
|
|
144 |
{
|
|
145 |
LoadNumericKeyBindings( iInputLanguageId, iQwertyModeMonitor->Keyboard() );
|
|
146 |
}
|
|
147 |
|
|
148 |
// -----------------------------------------------------------------------------
|
|
149 |
// CPhoneQwertyHandler::LoadNumericKeyBindings
|
|
150 |
// -----------------------------------------------------------------------------
|
|
151 |
//
|
|
152 |
void CPhoneQwertyHandler::LoadNumericKeyBindings( TInt aLanguage, TInt aKeyboard )
|
|
153 |
{
|
|
154 |
iNumericKeys.Reset();
|
|
155 |
|
|
156 |
#ifdef RD_INTELLIGENT_TEXT_INPUT
|
|
157 |
TPtiKeyboardType keyboard = static_cast<TPtiKeyboardType>( aKeyboard );
|
|
158 |
TRAPD( err,
|
|
159 |
{
|
|
160 |
CPtiEngine* ptiEngine = CPtiEngine::NewL();
|
|
161 |
CleanupStack::PushL( ptiEngine );
|
|
162 |
|
|
163 |
ptiEngine->GetNumericModeKeysForQwertyL( aLanguage,
|
|
164 |
iNumericKeys,
|
|
165 |
keyboard );
|
|
166 |
CleanupStack::PopAndDestroy( ptiEngine );
|
|
167 |
} ); // TRAP
|
|
168 |
#else
|
|
169 |
TRAPD( err,
|
|
170 |
{
|
|
171 |
CPtiEngine* ptiEngine = CPtiEngine::NewL();
|
|
172 |
CleanupStack::PushL( ptiEngine );
|
|
173 |
ptiEngine->GetNumericModeKeysForQwertyL( aLanguage,
|
|
174 |
iNumericKeys );
|
|
175 |
CleanupStack::PopAndDestroy( ptiEngine );
|
|
176 |
} ); // TRAP
|
|
177 |
#endif
|
|
178 |
|
|
179 |
if ( err )
|
|
180 |
{
|
|
181 |
iNumericKeys.Reset();
|
|
182 |
iQwertyMode = 0; // To default mode
|
|
183 |
}
|
|
184 |
else
|
|
185 |
{
|
|
186 |
// remove keys that are not remapped
|
|
187 |
TInt numericKeysCount = iNumericKeys.Count();
|
|
188 |
while ( numericKeysCount-- )
|
|
189 |
{
|
|
190 |
TPtiNumericKeyBinding numKeyBind = iNumericKeys[numericKeysCount];
|
|
191 |
|
|
192 |
// This is PTI bug? Should not be in numeric keys list.
|
|
193 |
if ( numKeyBind.iKey == EPtiKeyQwertySpace )
|
|
194 |
{
|
|
195 |
iNumericKeys.Remove( numericKeysCount );
|
|
196 |
}
|
|
197 |
}
|
|
198 |
}
|
|
199 |
}
|
|
200 |
|
|
201 |
// -----------------------------------------------------------------------------
|
|
202 |
// CPhoneQwertyHandler::NumericKeyCode
|
|
203 |
// -----------------------------------------------------------------------------
|
|
204 |
//
|
|
205 |
EXPORT_C TInt CPhoneQwertyHandler::NumericKeyCode( const TKeyEvent& aKeyEvent )
|
|
206 |
{
|
|
207 |
TInt keyCode( EKeyNull );
|
|
208 |
|
|
209 |
// It's possible that there are several numeric mode characters in same
|
|
210 |
// QWERTY key (for example, '2' and 'w' may be on same button) and there must
|
|
211 |
// be a way to enter each of these.
|
|
212 |
// Select numeric mode key code for the key event with the following logic:
|
|
213 |
// 1. If key contains exactly one numeric mode character, return that
|
|
214 |
// regardless of the current modifiers.
|
|
215 |
// 2a. If key has two numeric mode characters, then actual numbers are preferred.
|
|
216 |
// Pressing such key without modifiers will produce the number character.
|
|
217 |
// 2b. Pressing key with two numeric mode characters together with any modifier
|
|
218 |
// (Fn, Shift, Chr) will produce the secondary numeric mode character.
|
|
219 |
// 3. More than two numeric mode characters on one key are not supported.
|
|
220 |
// Such cases shouldn't ever occur, but if they will, then this algorithm
|
|
221 |
// must be changed.
|
|
222 |
|
|
223 |
// Check modifier state
|
|
224 |
TBool modifierActive = ( aKeyEvent.iModifiers & KNumKeyModifiers );
|
|
225 |
|
|
226 |
TInt numBindIdx = iNumericKeys.Count();
|
|
227 |
|
|
228 |
while ( numBindIdx-- )
|
|
229 |
{
|
|
230 |
const TPtiNumericKeyBinding& numKeyBind = iNumericKeys[numBindIdx];
|
|
231 |
|
|
232 |
if ( numKeyBind.iKey == aKeyEvent.iScanCode )
|
|
233 |
{
|
|
234 |
if ( !keyCode )
|
|
235 |
{
|
|
236 |
// first match for this key
|
|
237 |
keyCode = numKeyBind.iChar;
|
|
238 |
}
|
|
239 |
else
|
|
240 |
{
|
|
241 |
// Second numeric mode character for this key. Override
|
|
242 |
// previous code if it was the number character but some
|
|
243 |
// modifier is active or it was not number character and no
|
|
244 |
// modifiers are active.
|
|
245 |
if ( ( IsNumber(keyCode) && modifierActive ) ||
|
|
246 |
( !IsNumber(keyCode) && !modifierActive ) )
|
|
247 |
{
|
|
248 |
keyCode = numKeyBind.iChar;
|
|
249 |
}
|
|
250 |
}
|
|
251 |
}
|
|
252 |
}
|
|
253 |
|
|
254 |
return keyCode;
|
|
255 |
}
|
|
256 |
|
|
257 |
// -----------------------------------------------------------------------------
|
|
258 |
// CPhoneQwertyHandler::ConvertToNumeric
|
|
259 |
// -----------------------------------------------------------------------------
|
|
260 |
//
|
|
261 |
EXPORT_C TBool CPhoneQwertyHandler::ConvertToNumeric( TKeyEvent& aKeyEvent )
|
|
262 |
{
|
|
263 |
TBool ret( EFalse );
|
|
264 |
TInt numericCode = NumericKeyCode( aKeyEvent );
|
|
265 |
if ( numericCode )
|
|
266 |
{
|
|
267 |
aKeyEvent.iCode = numericCode;
|
|
268 |
aKeyEvent.iModifiers &= ~KNumKeyModifiers;
|
|
269 |
ret = ETrue;
|
|
270 |
}
|
|
271 |
return ret;
|
|
272 |
}
|
|
273 |
|
|
274 |
// -----------------------------------------------------------------------------
|
|
275 |
// CPhoneQwertyHandler::AddQwertyModeObserverL
|
|
276 |
// -----------------------------------------------------------------------------
|
|
277 |
//
|
|
278 |
EXPORT_C void CPhoneQwertyHandler::AddQwertyModeObserverL(
|
|
279 |
MPhoneQwertyModeObserver& aObserver )
|
|
280 |
{
|
|
281 |
iQwertyModeMonitor->AddObserverL( aObserver );
|
|
282 |
|
|
283 |
// Observer need to be notified with a current qwerty status so that
|
|
284 |
// status dependent objects would get correct initial value.
|
|
285 |
aObserver.HandleQwertyModeChange( iQwertyMode );
|
|
286 |
}
|
|
287 |
|
|
288 |
// -----------------------------------------------------------------------------
|
|
289 |
// CPhoneQwertyHandler::IsNumber
|
|
290 |
// -----------------------------------------------------------------------------
|
|
291 |
//
|
|
292 |
TBool CPhoneQwertyHandler::IsNumber( TText aChar ) const
|
|
293 |
{
|
|
294 |
return TChar( aChar ).IsDigit();
|
|
295 |
}
|
|
296 |
|
|
297 |
|
|
298 |
// End of File
|