44
|
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:
|
|
15 |
* Provides the aknfepinputstatecandidatepinyinphrasecreation definition.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
// System includes
|
|
31 |
#include <PtiEngine.h>
|
|
32 |
#include <avkon.rsg>
|
|
33 |
#include <aknfep.rsg>
|
|
34 |
//#include <aknquerydialog.h> //CAknQueryDialog
|
|
35 |
|
|
36 |
// User includes
|
|
37 |
#include "aknfepinputstatecandidatepinyinphrasecreation.h"
|
|
38 |
#include "AknFepUiCtrlContainerChinese.h"
|
|
39 |
#include "AknFepUICtrlCandidatePane.h"
|
|
40 |
#include "AknFepUICtrlPinyinPopup.h" //Pinyin phrase
|
|
41 |
#include "aknfepuictrleditpane.h" //pinyin phrase creation
|
|
42 |
#include "AknFepUIManagerStateInterface.h"
|
|
43 |
#include "AknFepManager.h"
|
|
44 |
|
|
45 |
// Constant definition
|
|
46 |
const TInt KMinCnadidateCount = 1;
|
|
47 |
const TInt KMaxSpellingLength = 10;
|
|
48 |
const TInt KMaxPhraseCreationCount = 7;
|
|
49 |
|
|
50 |
//add the max phrase is seven
|
|
51 |
_LIT( KMaxPhraseNote,"\x8BCD\x7EC4\x6700\x957F\x4E3A\x4E03\x5B57" );
|
|
52 |
|
|
53 |
|
|
54 |
// ---------------------------------------------------------------------------
|
|
55 |
// AknFepUiInputStateCandidatePinyinAndStrokePhrase::
|
|
56 |
// TAknFepUiInputStateCandidatePinyinAndStrokePhrase
|
|
57 |
// (other items were commented in a header).
|
|
58 |
// ---------------------------------------------------------------------------
|
|
59 |
//
|
|
60 |
TAknFepInputStateCandidatePinyinPhraseCreation::
|
|
61 |
TAknFepInputStateCandidatePinyinPhraseCreation(
|
|
62 |
MAknFepUIManagerStateInterface* aOwner,
|
|
63 |
MAknFepUICtrlContainerChinese* aUIContainer) :
|
|
64 |
TAknFepInputStatePinyinPhraseCreationBase( aOwner, aUIContainer)
|
|
65 |
{
|
|
66 |
iState = ECandidateSelection;
|
|
67 |
MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
|
|
68 |
|
|
69 |
TBool multiplePages = !(uiContainer->CandidatePane()->IsLastPage() &&
|
|
70 |
uiContainer->CandidatePane()->IsFirstPage());
|
|
71 |
TInt bufLength = iOwner->PtiEngine()->CandidatePage().Length();
|
|
72 |
TBool showHorizontalScrollArrows = multiplePages || bufLength > KMinCnadidateCount;
|
|
73 |
|
|
74 |
uiContainer->ShowHorizontalScrollArrows(showHorizontalScrollArrows);
|
|
75 |
uiContainer->ShowVerticalScrollArrows(ETrue);
|
|
76 |
uiContainer->FocusCandidatePane(ETrue);
|
|
77 |
uiContainer->CandidatePane()->ShowCandidateOrdinals(ETrue);
|
|
78 |
uiContainer->CandidatePane()->SelectFirstPhrase();
|
|
79 |
uiContainer->SetFepMan( iOwner->FepMan() );
|
|
80 |
|
|
81 |
UpdateIndicator();
|
|
82 |
ChangeCba();
|
|
83 |
}
|
|
84 |
|
|
85 |
// ---------------------------------------------------------------------------
|
|
86 |
// TAknFepInputStateCandidatePinyinPhraseCreation::HandleKeyL
|
|
87 |
// (other items were commented in a header).
|
|
88 |
// ---------------------------------------------------------------------------
|
|
89 |
//
|
|
90 |
TBool TAknFepInputStateCandidatePinyinPhraseCreation::HandleKeyL(TInt aKey,
|
|
91 |
TKeyPressLength aLength)
|
|
92 |
{
|
|
93 |
switch( aKey )
|
|
94 |
{
|
|
95 |
case EKeyBackspace:
|
|
96 |
KeyBackspace();
|
|
97 |
break;
|
|
98 |
case EKeyCBA2:
|
|
99 |
iOwner->FepMan()->TryCloseUiL();
|
|
100 |
break;
|
|
101 |
default:
|
|
102 |
HandleKeyUpDownLeftRightArrowOrKeyCBA1OKL( aKey, aLength );
|
|
103 |
break;
|
|
104 |
}
|
|
105 |
return ETrue;
|
|
106 |
}
|
|
107 |
|
|
108 |
// ---------------------------------------------------------
|
|
109 |
// Update indicator.
|
|
110 |
// ---------------------------------------------------------
|
|
111 |
//
|
|
112 |
void TAknFepInputStateCandidatePinyinPhraseCreation::UpdateIndicator()
|
|
113 |
{
|
|
114 |
MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
|
|
115 |
MAknFepUICtrlCandidatePane* candidatePane = uiContainer->CandidatePane();
|
|
116 |
|
|
117 |
if (candidatePane->IsFirstPage())
|
|
118 |
{
|
|
119 |
uiContainer->CandidatePane()->ShowUpScrollArrows(EFalse);
|
|
120 |
}
|
|
121 |
else
|
|
122 |
{
|
|
123 |
uiContainer->CandidatePane()->ShowUpScrollArrows(ETrue);
|
|
124 |
}
|
|
125 |
if ( candidatePane->IsLastPage() )
|
|
126 |
{
|
|
127 |
uiContainer->CandidatePane()->ShowDownScrollArrows(EFalse);
|
|
128 |
}
|
|
129 |
else
|
|
130 |
{
|
|
131 |
uiContainer->CandidatePane()->ShowDownScrollArrows(ETrue);
|
|
132 |
}
|
|
133 |
}
|
|
134 |
|
|
135 |
// ---------------------------------------------------------
|
|
136 |
// Handle horizontal navigation.
|
|
137 |
// ---------------------------------------------------------
|
|
138 |
//
|
|
139 |
TBool TAknFepInputStateCandidatePinyinPhraseCreation::HandleHorizontalNavigation(TInt aKey)
|
|
140 |
{
|
|
141 |
MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane();
|
|
142 |
TBool response = EFalse;
|
|
143 |
|
|
144 |
// Do navigation...
|
|
145 |
if (aKey == EKeyLeftArrow)
|
|
146 |
{
|
|
147 |
if( !candidatePane->SelectPrev() )
|
|
148 |
{
|
|
149 |
candidatePane->SetCandidateBuffer();
|
|
150 |
candidatePane->SelectLastPhrase();
|
|
151 |
}
|
|
152 |
response = ETrue;
|
|
153 |
}
|
|
154 |
else if (aKey == EKeyRightArrow)
|
|
155 |
{
|
|
156 |
if( !candidatePane->SelectNext() )
|
|
157 |
{
|
|
158 |
candidatePane->SetCandidateBuffer();
|
|
159 |
candidatePane->SelectFirstPhrase();
|
|
160 |
}
|
|
161 |
response = ETrue;
|
|
162 |
}
|
|
163 |
|
|
164 |
if (response)
|
|
165 |
{
|
|
166 |
UpdateIndicator();
|
|
167 |
}
|
|
168 |
|
|
169 |
return response;
|
|
170 |
}
|
|
171 |
|
|
172 |
// ---------------------------------------------------------
|
|
173 |
// Handle vertical navigation.
|
|
174 |
// ---------------------------------------------------------
|
|
175 |
//
|
|
176 |
TBool TAknFepInputStateCandidatePinyinPhraseCreation::HandleVerticalNavigation(TInt aKey)
|
|
177 |
{
|
|
178 |
MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane();
|
|
179 |
|
|
180 |
if (aKey == EKeyDownArrow)
|
|
181 |
{
|
|
182 |
if (candidatePane->IsLastPage())
|
|
183 |
{
|
|
184 |
return ETrue;
|
|
185 |
}
|
|
186 |
candidatePane->NextCandidatePage();
|
|
187 |
}
|
|
188 |
else if (aKey == EKeyUpArrow)
|
|
189 |
{
|
|
190 |
if (candidatePane->IsFirstPage() )
|
|
191 |
{
|
|
192 |
return ETrue;
|
|
193 |
}
|
|
194 |
candidatePane->PreviousCandidatePage();
|
|
195 |
}
|
|
196 |
else
|
|
197 |
{
|
|
198 |
return EFalse;
|
|
199 |
}
|
|
200 |
candidatePane->SetCandidateBuffer();
|
|
201 |
candidatePane->SelectFirstPhrase();
|
|
202 |
UpdateIndicator();
|
|
203 |
|
|
204 |
return ETrue;
|
|
205 |
}
|
|
206 |
|
|
207 |
// ---------------------------------------------------------
|
|
208 |
// Commit inline to the EEP ctrl.
|
|
209 |
// ---------------------------------------------------------
|
|
210 |
//
|
|
211 |
TBool TAknFepInputStateCandidatePinyinPhraseCreation::CommitInlineEEPL( const TDesC& aText )
|
|
212 |
{//select from phrase candidates
|
|
213 |
MAknFepUICtrlPinyinPopup* popup = UIContainer()->PinyinPopupWindow();
|
|
214 |
CDesCArrayFlat* keystrokeArray = popup->ShowKeystrokeArray();
|
|
215 |
CDesCArrayFlat* validKeystroke = popup->InEffectKeystrokeArray();
|
|
216 |
CDesCArrayFlat* chooseChineseCharacterArray =
|
|
217 |
popup->ChooseChineseCharacterArray();
|
|
218 |
CDesCArrayFlat* chooseChineseCharacterArrayKeystroke =
|
|
219 |
popup->ChooseChineseCharacterArrayKeystroke();
|
|
220 |
TInt keyCount = validKeystroke->Count();
|
|
221 |
|
|
222 |
TBuf<KMaxSpellingLength> keystroke;
|
|
223 |
|
|
224 |
popup->SetPhraseCreationState( ETrue );
|
|
225 |
|
|
226 |
//stroe spelling
|
|
227 |
CDesCArrayFlat* spellingArray = popup->PhoneticSpellingArray();//spelling array
|
|
228 |
TInt selection = popup->CurrentSelection();//selection index of spelling array
|
|
229 |
CDesCArrayFlat* chooseChineseCharacterArraySpelling = popup->ChooseChineseCharacterArraySpelling();//phrase spelling array
|
|
230 |
TInt delCount = chooseChineseCharacterArraySpelling->Count() - chooseChineseCharacterArray->Count();
|
|
231 |
if(delCount > 0)//we can sure delCount>=0,impossible <0
|
|
232 |
{//remove unwanted spelling
|
|
233 |
chooseChineseCharacterArraySpelling->Delete(chooseChineseCharacterArray->Count(),delCount);
|
|
234 |
}
|
|
235 |
chooseChineseCharacterArraySpelling->AppendL(spellingArray->MdcaPoint(selection));
|
|
236 |
|
|
237 |
for ( TInt i = 0; i < keyCount; i++ )
|
|
238 |
{
|
|
239 |
keystroke.Append( keystrokeArray->MdcaPoint( 0 ) );
|
|
240 |
keystrokeArray->Delete( 0 );
|
|
241 |
}
|
|
242 |
chooseChineseCharacterArray->AppendL( aText );
|
|
243 |
chooseChineseCharacterArrayKeystroke->AppendL( keystroke );
|
|
244 |
validKeystroke->Reset();
|
|
245 |
|
|
246 |
if ( chooseChineseCharacterArray->Count() >= KMaxPhraseCreationCount )
|
|
247 |
{
|
|
248 |
keystrokeArray->Reset();
|
|
249 |
CDesCArrayFlat* phraseCandidates =
|
|
250 |
UIContainer()->CandidatePane()->CandidateArray();
|
|
251 |
phraseCandidates->Reset();
|
|
252 |
phraseCandidates->AppendL( KMaxPhraseNote );
|
|
253 |
RefreshUI( 0 );
|
|
254 |
return EFalse;
|
|
255 |
}
|
|
256 |
return keystrokeArray->Count();
|
|
257 |
}
|
|
258 |
|
|
259 |
// ---------------------------------------------------------
|
|
260 |
// KeyBackspace.
|
|
261 |
// ---------------------------------------------------------
|
|
262 |
//
|
|
263 |
void TAknFepInputStateCandidatePinyinPhraseCreation::KeyBackspace()
|
|
264 |
{
|
|
265 |
MAknFepUICtrlPinyinPopup* popup = UIContainer()->PinyinPopupWindow();
|
|
266 |
// there is "ChangeCba()" before
|
|
267 |
popup->SetChangeState( ETrue );
|
|
268 |
iOwner->ChangeState(ESpellingSelection);
|
|
269 |
}
|
|
270 |
|
|
271 |
// ---------------------------------------------------------
|
|
272 |
// Key Up,Down,Left,RightArrow Or Key CBA1,OK.
|
|
273 |
// ---------------------------------------------------------
|
|
274 |
//
|
|
275 |
void TAknFepInputStateCandidatePinyinPhraseCreation::HandleKeyUpDownLeftRightArrowOrKeyCBA1OKL(
|
|
276 |
TInt aKey,
|
|
277 |
TKeyPressLength aLength )
|
|
278 |
{
|
|
279 |
MAknFepUICtrlPinyinPopup* popup = UIContainer()->PinyinPopupWindow();
|
|
280 |
MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane();
|
|
281 |
TInt index = MapKeyToIndex(aKey);
|
|
282 |
|
|
283 |
if ( aKey == EKeyUpArrow &&
|
|
284 |
iOwner->FepMan()->InputMode() == EPinyin &&
|
|
285 |
candidatePane->IsFirstPage())
|
|
286 |
{
|
|
287 |
popup->SetChangeState( ETrue );
|
|
288 |
iOwner->ChangeState(ESpellingSelection);
|
|
289 |
return;
|
|
290 |
}
|
|
291 |
TBool state = ETrue;
|
|
292 |
if ( popup->IsChangeStatet() && aLength == ELongKeyPress )
|
|
293 |
{
|
|
294 |
state = EFalse;
|
|
295 |
}
|
|
296 |
else
|
|
297 |
{
|
|
298 |
popup->SetChangeState( EFalse );
|
|
299 |
}
|
|
300 |
|
|
301 |
if ( state )
|
|
302 |
{
|
|
303 |
if ( !(HandleVerticalNavigation( aKey )
|
|
304 |
|| HandleHorizontalNavigation( aKey ) ) )
|
|
305 |
{
|
|
306 |
// it may be one of the 'valid' numbers..
|
|
307 |
if ( candidatePane->SelectIndex( index, EFalse ) || aKey == EKeyOK
|
|
308 |
|| aKey == EKeyCBA1 )
|
|
309 |
{
|
|
310 |
ChangeStateOrNotL();
|
|
311 |
}
|
|
312 |
ChangeCba();
|
|
313 |
}
|
|
314 |
}
|
|
315 |
}
|
|
316 |
|
|
317 |
// ---------------------------------------------------------
|
|
318 |
// change the state or not
|
|
319 |
// ---------------------------------------------------------
|
|
320 |
//
|
|
321 |
void TAknFepInputStateCandidatePinyinPhraseCreation::ChangeStateOrNotL()
|
|
322 |
{
|
|
323 |
MAknFepUICtrlPinyinPopup* popup = UIContainer()->PinyinPopupWindow();
|
|
324 |
MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane();
|
|
325 |
TPtrC text = candidatePane->CurrentPhraseCandidate();
|
|
326 |
if ( text.Length() )
|
|
327 |
{
|
|
328 |
CDesCArrayFlat* chooseChineseCharacterArray =
|
|
329 |
popup->ChooseChineseCharacterArray();
|
|
330 |
//here need Commit text to EEP and change
|
|
331 |
//state to EEP entry state if keystroke is empty
|
|
332 |
//else keep spelling state
|
|
333 |
if ( chooseChineseCharacterArray->Count() < KMaxPhraseCreationCount )
|
|
334 |
{
|
|
335 |
if ( !CommitInlineEEPL( text ) )
|
|
336 |
{
|
|
337 |
popup->SetChangeState( ETrue );
|
|
338 |
iOwner->ChangeState( EKeySequenceEdit );
|
|
339 |
TBool visible =
|
|
340 |
( chooseChineseCharacterArray->Count() == KMaxPhraseCreationCount );
|
|
341 |
UIContainer()->SetControlInVisible( visible );
|
|
342 |
}
|
|
343 |
else
|
|
344 |
{
|
|
345 |
if ( !popup->IsEnabled() )
|
|
346 |
{
|
|
347 |
popup->Enable( ETrue );
|
|
348 |
}
|
|
349 |
if ( !GetValidKeystroke() )
|
|
350 |
{
|
|
351 |
UIContainer()->SetControlInVisible( EFalse );
|
|
352 |
popup->SetChangeState( ETrue );
|
|
353 |
iOwner->ChangeState( EKeySequenceEdit );
|
|
354 |
}
|
|
355 |
else
|
|
356 |
{
|
|
357 |
popup->SetChangeState( ETrue );
|
|
358 |
iOwner->ChangeState( ESpellingSelection );
|
|
359 |
}
|
|
360 |
}
|
|
361 |
}
|
|
362 |
else
|
|
363 |
{
|
|
364 |
popup->SetChangeState( ETrue );
|
|
365 |
iOwner->ChangeState( EKeySequenceEdit );
|
|
366 |
}
|
|
367 |
}
|
|
368 |
else
|
|
369 |
{
|
|
370 |
// No candidates available. Back to Entry state.
|
|
371 |
popup->SetChangeState( ETrue );
|
|
372 |
iOwner->ChangeState( EKeySequenceEdit );
|
|
373 |
}
|
|
374 |
}
|
|
375 |
|
|
376 |
|
|
377 |
// End of file
|