|
1 /* |
|
2 * Copyright (c) 2002-2005 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 candidate qwerty base chinese phrase state |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 #include "AknFepUiInputStateCandidateQwertyBaseChinesePhrase.h" |
|
30 #include "AknFepUiCtrlContainerChinese.h" |
|
31 #include "AknFepUICtrlCandidatePane.h" |
|
32 #include "AknFepUIManagerStateInterface.h" //MAknFepUIManagerStateInterface |
|
33 #include "AknFepManagerUIInterface.h" |
|
34 #include "AknFepManager.h" //FepMan flag |
|
35 #include "AknFepUICtrlPinyinPopup.h" |
|
36 |
|
37 #include <PtiEngine.h> //CPtiEngine |
|
38 |
|
39 const TUint16 KSegment = 0x0020; |
|
40 |
|
41 TAknFepInputStateCandidateQwertyBaseChinesePhrase:: |
|
42 TAknFepInputStateCandidateQwertyBaseChinesePhrase( |
|
43 MAknFepUIManagerStateInterface* aOwner, |
|
44 MAknFepUICtrlContainerChinese* aUIContainer) |
|
45 :TAknFepInputStateChineseBase(aOwner, aUIContainer) |
|
46 { |
|
47 } |
|
48 |
|
49 TBool TAknFepInputStateCandidateQwertyBaseChinesePhrase::HandleKeyL(TInt aKey, TKeyPressLength /*aLength*/) |
|
50 { |
|
51 if(aKey == EStdKeyDevice1) |
|
52 { |
|
53 iOwner->FepMan()->TryCloseUiL(); |
|
54 } |
|
55 |
|
56 else if(!( HandleVerticalNavigation(aKey) || HandleHorizontalNavigation(aKey) )) |
|
57 { |
|
58 TInt index = 0; |
|
59 #ifdef RD_INTELLIGENT_TEXT_INPUT |
|
60 // it may be one of the 'valid' numbers.. |
|
61 TPtiKeyboardType keyboardtype = iOwner->FepMan()->KeyboardLayout(); |
|
62 if ( EPtiKeyboardQwerty4x10 == keyboardtype || |
|
63 EPtiKeyboardQwerty3x11 == keyboardtype || |
|
64 EPtiKeyboardHalfQwerty == keyboardtype || |
|
65 EPtiKeyboardCustomQwerty == keyboardtype) |
|
66 { |
|
67 MPtiLanguage *lang = NULL; |
|
68 RArray < TPtiNumericKeyBinding > keybinding; |
|
69 TBool validnumkey = EFalse; |
|
70 CPtiEngine* ptiengine = iOwner->PtiEngine(); |
|
71 lang = ptiengine->CurrentLanguage(); |
|
72 if( ptiengine && lang ) |
|
73 { |
|
74 TRAP_IGNORE(ptiengine->GetNumericModeKeysForQwertyL(lang->LanguageCode(), |
|
75 keybinding, keyboardtype)); |
|
76 TInt numericKeysCount = keybinding.Count(); |
|
77 TInt candidateCount = UIContainer()->CandidatePane()->VisibleCandidateCount(); |
|
78 while ( numericKeysCount-- ) |
|
79 { |
|
80 TPtiNumericKeyBinding numKeyBind = keybinding[numericKeysCount]; |
|
81 if ( (numKeyBind.iChar >= 0x31 && numKeyBind.iChar <= ( 0x31 + candidateCount - 1 )) |
|
82 |
|
83 &&(aKey == numKeyBind.iKey)) |
|
84 { |
|
85 index = numKeyBind.iChar - EPtiKey0 -1; |
|
86 validnumkey = ETrue; |
|
87 break; |
|
88 } |
|
89 } |
|
90 } |
|
91 keybinding.Reset(); |
|
92 |
|
93 if (!validnumkey) |
|
94 { |
|
95 iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone); |
|
96 return ETrue; |
|
97 } |
|
98 |
|
99 } |
|
100 else |
|
101 { |
|
102 #endif |
|
103 index = MapKeyToIndex(aKey); |
|
104 #ifdef RD_INTELLIGENT_TEXT_INPUT |
|
105 } |
|
106 #endif |
|
107 MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane(); |
|
108 |
|
109 if(candidatePane->SelectIndex(index) || aKey == EStdKeyDevice3 || aKey == EStdKeyEnter) |
|
110 { |
|
111 TPtrC text = candidatePane->CurrentPhraseCandidate(); |
|
112 if(text.Length()) |
|
113 { |
|
114 MAknFepManagerUIInterface* fepMan = iOwner->FepMan(); |
|
115 fepMan->NewTextL(text); |
|
116 fepMan->CommitInlineEditL(); |
|
117 iOwner->PtiEngine()->SetPredictiveChineseChar(text); |
|
118 if (fepMan->IsFlagSet(CAknFepManager::EFlagEditorFull)) |
|
119 { |
|
120 fepMan->ClearFlag(CAknFepManager::EFlagEditorFull); |
|
121 iOwner->FepMan()->TryCloseUiL(); |
|
122 } |
|
123 else |
|
124 { |
|
125 #ifdef RD_INTELLIGENT_TEXT_INPUT |
|
126 if ( EPtiKeyboardQwerty4x10 == iOwner->FepMan()->KeyboardLayout() || |
|
127 EPtiKeyboardHalfQwerty == iOwner->FepMan()->KeyboardLayout() || |
|
128 EPtiKeyboardQwerty3x11 == iOwner->FepMan()->KeyboardLayout() ) |
|
129 { |
|
130 UIContainer()->PinyinPopupWindow()->SetChangeState( ETrue ); |
|
131 iOwner->ChangeState(EPredictiveCandidate); |
|
132 } |
|
133 #endif |
|
134 } |
|
135 } |
|
136 else |
|
137 { |
|
138 // No candidates available. Back to Entry state. |
|
139 iOwner->ChangeState(EEntry); |
|
140 } |
|
141 } |
|
142 } |
|
143 return ETrue; |
|
144 } |
|
145 |
|
146 TBool TAknFepInputStateCandidateQwertyBaseChinesePhrase::HandleHorizontalNavigation(TInt aKey) |
|
147 { |
|
148 MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane(); |
|
149 TBool response = EFalse; |
|
150 |
|
151 // Do navigation... |
|
152 if (aKey == EStdKeyLeftArrow) |
|
153 { |
|
154 if (candidatePane->SelectedIndex() == 0 && |
|
155 candidatePane->IsFirstPage() ) |
|
156 { |
|
157 return ETrue; |
|
158 } |
|
159 |
|
160 if(!candidatePane->SelectPrev()) |
|
161 { |
|
162 candidatePane->PreviousCandidatePage(); |
|
163 candidatePane->SetCandidateBuffer(); |
|
164 candidatePane->SelectLastPhrase(); |
|
165 } |
|
166 response = ETrue; |
|
167 } |
|
168 else if (aKey == EStdKeyRightArrow) |
|
169 { |
|
170 if ( candidatePane->IsLastPage() && |
|
171 (candidatePane->SelectedIndex() == candidatePane->VisibleCandidateCount() - 1)) |
|
172 { |
|
173 return ETrue; |
|
174 } |
|
175 |
|
176 if(!candidatePane->SelectNext()) |
|
177 { |
|
178 candidatePane->NextCandidatePage(); |
|
179 candidatePane->SetCandidateBuffer(); |
|
180 candidatePane->SelectFirstPhrase(); |
|
181 } |
|
182 response = ETrue; |
|
183 } |
|
184 if (response) |
|
185 { |
|
186 UpdateIndicator(); |
|
187 } |
|
188 return response; |
|
189 } |
|
190 |
|
191 TBool TAknFepInputStateCandidateQwertyBaseChinesePhrase::HandleVerticalNavigation(TInt aKey) |
|
192 { |
|
193 MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane(); |
|
194 |
|
195 if (aKey == EStdKeyDownArrow || aKey == EStdKeySpace) |
|
196 { |
|
197 if (candidatePane->IsLastPage()) |
|
198 { |
|
199 return ETrue; |
|
200 } |
|
201 if ( iState != EPredictiveCandidate && |
|
202 iState != EPredictiveInput ) |
|
203 { |
|
204 if ( candidatePane->NeedGetNewCandidatePage() ) |
|
205 { |
|
206 if ( !iOwner->PtiEngine()->NextCandidatePage( ) ) |
|
207 { |
|
208 if ( candidatePane->IsLastPage() ) |
|
209 { |
|
210 iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone ); |
|
211 return ETrue; |
|
212 } |
|
213 } |
|
214 else |
|
215 { |
|
216 CDesCArrayFlat* phraseCandidates = candidatePane->CandidateArray(); |
|
217 RPointerArray<HBufC> list; |
|
218 TRAP_IGNORE( |
|
219 GetNewCandidatesL( iOwner->PtiEngine()->CandidatePage( ), list ); |
|
220 for (TInt i = 0; i < list.Count( ); ++i ) |
|
221 { |
|
222 phraseCandidates->AppendL( *(list[i]) ); |
|
223 } |
|
224 list.ResetAndDestroy();) |
|
225 } |
|
226 } |
|
227 } |
|
228 candidatePane->NextCandidatePage(); |
|
229 } |
|
230 else if (aKey == EStdKeyUpArrow) |
|
231 { |
|
232 if (candidatePane->IsFirstPage()) |
|
233 { |
|
234 return ETrue; |
|
235 } |
|
236 candidatePane->PreviousCandidatePage(); |
|
237 } |
|
238 else |
|
239 { |
|
240 return EFalse; |
|
241 } |
|
242 candidatePane->SetCandidateBuffer(); |
|
243 candidatePane->SelectFirstPhrase(); |
|
244 UpdateIndicator(); |
|
245 return ETrue; |
|
246 } |
|
247 |
|
248 void TAknFepInputStateCandidateQwertyBaseChinesePhrase::UpdateIndicator() |
|
249 { |
|
250 CPtiEngine* ptiengine = iOwner->PtiEngine(); |
|
251 MAknFepUICtrlContainerChinese* uiContainer = UIContainer(); |
|
252 MAknFepUICtrlCandidatePane* candidatePane = uiContainer->CandidatePane(); |
|
253 |
|
254 if (candidatePane->IsFirstPage()) |
|
255 { |
|
256 uiContainer->CandidatePane()->ShowUpScrollArrows(EFalse); |
|
257 } |
|
258 else |
|
259 { |
|
260 uiContainer->CandidatePane()->ShowUpScrollArrows(ETrue); |
|
261 } |
|
262 |
|
263 if (candidatePane->IsLastPage()) |
|
264 { |
|
265 uiContainer->CandidatePane()->ShowDownScrollArrows(EFalse); |
|
266 } |
|
267 else |
|
268 { |
|
269 uiContainer->CandidatePane()->ShowDownScrollArrows(ETrue); |
|
270 } |
|
271 #ifdef RD_INTELLIGENT_TEXT_INPUT |
|
272 if(iOwner->FepMan()->KeyboardLayout() == EPtiKeyboardQwerty4x10) |
|
273 { |
|
274 if(candidatePane->VisibleCandidateCount()==1) |
|
275 { |
|
276 uiContainer->CandidatePane()->ShowLeftScrollArrows(EFalse); |
|
277 uiContainer->CandidatePane()->ShowRightScrollArrows(EFalse); |
|
278 } |
|
279 else |
|
280 { |
|
281 uiContainer->CandidatePane()->ShowLeftScrollArrows(ETrue); |
|
282 uiContainer->CandidatePane()->ShowRightScrollArrows(ETrue); |
|
283 } |
|
284 } |
|
285 else |
|
286 { |
|
287 #endif |
|
288 if (candidatePane->SelectedIndex() == 0 && |
|
289 candidatePane->IsFirstPage() ) |
|
290 { |
|
291 uiContainer->CandidatePane()->ShowLeftScrollArrows(EFalse); |
|
292 } |
|
293 else |
|
294 { |
|
295 uiContainer->CandidatePane()->ShowLeftScrollArrows(ETrue); |
|
296 } |
|
297 |
|
298 if (candidatePane->IsLastPage() && |
|
299 (candidatePane->SelectedIndex() == candidatePane->VisibleCandidateCount() - 1)) |
|
300 { |
|
301 uiContainer->CandidatePane()->ShowRightScrollArrows(EFalse); |
|
302 } |
|
303 else |
|
304 { |
|
305 uiContainer->CandidatePane()->ShowRightScrollArrows(ETrue); |
|
306 } |
|
307 } |
|
308 #ifdef RD_INTELLIGENT_TEXT_INPUT |
|
309 } |
|
310 #endif |
|
311 |
|
312 // --------------------------------------------------------------------------- |
|
313 // TAknFepInputStateCandidateQwertyBaseChinesePhrase::MapKeyToIndexSelectCandidate |
|
314 // Check the select candidate numeric key is valid or not |
|
315 // --------------------------------------------------------------------------- |
|
316 // |
|
317 #ifdef RD_INTELLIGENT_TEXT_INPUT |
|
318 TBool TAknFepInputStateCandidateQwertyBaseChinesePhrase::MapKeyToIndexSelectCandidate( |
|
319 TInt aKey,TInt& aIndex ) |
|
320 { |
|
321 TBool validnumkey = EFalse; |
|
322 MPtiLanguage *lang= NULL; |
|
323 CPtiEngine* ptiengine = iOwner->PtiEngine(); |
|
324 TPtiKeyboardType keyboardtype = iOwner->FepMan()->KeyboardLayout(); |
|
325 if (EPtiKeyboardQwerty4x10 == keyboardtype || EPtiKeyboardQwerty3x11 |
|
326 == keyboardtype || EPtiKeyboardHalfQwerty == keyboardtype |
|
327 || EPtiKeyboardCustomQwerty == keyboardtype) |
|
328 { |
|
329 RArray <TPtiNumericKeyBinding> keybinding; |
|
330 lang = ptiengine->CurrentLanguage(); |
|
331 if ( ptiengine && lang ) |
|
332 { |
|
333 TRAP_IGNORE(ptiengine->GetNumericModeKeysForQwertyL(lang->LanguageCode(), keybinding, keyboardtype)); |
|
334 TInt numericKeysCount = keybinding.Count(); |
|
335 while ( numericKeysCount-- ) |
|
336 { |
|
337 TPtiNumericKeyBinding numKeyBind = |
|
338 keybinding[numericKeysCount]; |
|
339 if ( (numKeyBind.iChar >= 0x31 && numKeyBind.iChar <= 0x36) |
|
340 &&(aKey == numKeyBind.iKey)) |
|
341 { |
|
342 aIndex = numKeyBind.iChar - EPtiKey0 - 1; |
|
343 validnumkey = ETrue; |
|
344 break; |
|
345 } |
|
346 } |
|
347 } |
|
348 keybinding.Reset(); |
|
349 if ( !validnumkey ) |
|
350 { |
|
351 iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone); |
|
352 } |
|
353 } |
|
354 else |
|
355 { |
|
356 aIndex = MapKeyToIndex(aKey); |
|
357 } |
|
358 return validnumkey ; |
|
359 } |
|
360 #endif |
|
361 // --------------------------------------------------------------------------- |
|
362 // TAknFepInputStateCandidateQwertyBaseChinesePhrase::HandleCommandL |
|
363 // Handling Command |
|
364 // --------------------------------------------------------------------------- |
|
365 // |
|
366 void TAknFepInputStateCandidateQwertyBaseChinesePhrase::HandleCommandL( |
|
367 TInt aCommandId ) |
|
368 { |
|
369 TAknFepInputStateChineseBase::HandleCommandL( aCommandId ); |
|
370 } |
|
371 |
|
372 void TAknFepInputStateCandidateQwertyBaseChinesePhrase::GetNewCandidatesL(const TDesC& aSource, |
|
373 RPointerArray<HBufC>& aList) |
|
374 { |
|
375 TInt start = 0; |
|
376 TInt length = 0; |
|
377 |
|
378 for (TInt ii = 0; ii < aSource.Length(); ii++) |
|
379 { |
|
380 if (aSource[ii] == KSegment) |
|
381 { |
|
382 TPtrC segment(aSource.Ptr() + start, length); |
|
383 aList.AppendL(segment.AllocL()); |
|
384 start += (length + 1); |
|
385 length = 0; |
|
386 } |
|
387 else |
|
388 { |
|
389 length++; |
|
390 } |
|
391 } |
|
392 |
|
393 if (length) |
|
394 { |
|
395 TPtrC segm(aSource.Ptr() + start, length); |
|
396 aList.AppendL(segm.AllocL()); |
|
397 } |
|
398 } |
|
399 |
|
400 // End of file |