44
|
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 chinese phrase state
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
#include "AknFepUiInputStateCandidateChinesePhrase.h"
|
|
30 |
#include "AknFepUiCtrlContainerChinese.h"
|
|
31 |
#include "AknFepUIManagerStateInterface.h" //MAknFepUIManagerStateInterface
|
|
32 |
#include "AknFepUICtrlPinyinPopup.h" //Pinyin phrase
|
|
33 |
#include "aknfepuictrleditpane.h"
|
|
34 |
#include "AknFepUICtrlCandidatePane.h" //MAknFepUICtrlCandidatePane
|
|
35 |
#include <PtiEngine.h> //CPtiEngine
|
|
36 |
#include <aknnotewrappers.h>
|
|
37 |
#include "aknfepzhuyinconvertion.h"
|
|
38 |
#include "aknfepzhuyinkeyhandlerinterface.h"
|
|
39 |
#include <PtiUserDicEntry.h>
|
|
40 |
|
|
41 |
const TInt KMaxBufLen = 100;
|
|
42 |
const TInt KInputPhraseMaxLength = 7;
|
|
43 |
const TInt KMaxPinYinSpellLength = 7;//max pinyin length for one chinese Zi
|
|
44 |
|
|
45 |
_LIT( KMaxPhraseNote,"\x8BCD\x7EC4\x6700\x957F\x4E3A\x4E03\x5B57" );
|
|
46 |
///////////////////
|
|
47 |
// Candidate state
|
|
48 |
///////////////////
|
|
49 |
|
|
50 |
TAknFepInputStateCandidateChinesePhrase::TAknFepInputStateCandidateChinesePhrase(
|
|
51 |
MAknFepUIManagerStateInterface* aOwner,
|
|
52 |
MAknFepUICtrlContainerChinese* aUIContainer)
|
|
53 |
:TAknFepInputStateCandidateBaseChinesePhrase(aOwner, aUIContainer)
|
|
54 |
{
|
|
55 |
iState = ECandidate;
|
|
56 |
MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
|
|
57 |
|
|
58 |
uiContainer->CandidatePane()->SelectFirstPhrase();
|
|
59 |
|
|
60 |
TBool multiplePages = !(uiContainer->CandidatePane()->IsLastPage() &&
|
|
61 |
uiContainer->CandidatePane()->IsFirstPage());
|
|
62 |
TInt bufLength = iOwner->PtiEngine()->CandidatePage().Length();
|
|
63 |
TBool showHorizontalScrollArrows = multiplePages || bufLength>1;
|
|
64 |
|
|
65 |
uiContainer->ShowHorizontalScrollArrows(showHorizontalScrollArrows);
|
|
66 |
uiContainer->ShowVerticalScrollArrows(multiplePages);
|
|
67 |
uiContainer->FocusCandidatePane(ETrue);
|
|
68 |
uiContainer->CandidatePane()->ShowCandidateOrdinals(ETrue);
|
|
69 |
UpdateIndicator();
|
|
70 |
UIContainer()->EditPaneWindow()->DisableCursor();
|
|
71 |
}
|
|
72 |
|
|
73 |
TBool TAknFepInputStateCandidateChinesePhrase::HandleKeyL(TInt aKey, TKeyPressLength aLength)
|
|
74 |
{
|
|
75 |
MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
|
|
76 |
MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
|
|
77 |
MAknFepUICtrlCandidatePane* candidatePane = uiContainer->CandidatePane();
|
|
78 |
MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
|
|
79 |
MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
|
|
80 |
|
|
81 |
CDesCArrayFlat* zhuyinSymbols = uiContainer->PinyinPopupWindow()->ZhuyinSymbols();
|
|
82 |
CDesCArrayFlat* chineseDisped = uiContainer->PinyinPopupWindow()->ChineseCharsDisped();
|
|
83 |
CDesCArrayFlat* zhuyinSymbolsForChinese = uiContainer->PinyinPopupWindow()->ZhuyinSymbolsForChineseCharsDisped();
|
|
84 |
CDesCArrayFlat* candidateList = uiContainer->CandidatePane()->CandidateArray();
|
|
85 |
|
|
86 |
MZhuyinKeyHandler* zhuyinKeyHandler = iOwner->ZhuyinKeyHandler();
|
|
87 |
|
|
88 |
TInt index = MapKeyToIndex(aKey);
|
|
89 |
|
|
90 |
if(aKey == EKeyBackspace)
|
|
91 |
{
|
|
92 |
zhuyinKeyHandler->SetStatusChgFlag(MZhuyinKeyHandler::EFromCandidateToEntry);
|
|
93 |
iOwner->ChangeState(EEntry);
|
|
94 |
return ETrue;
|
|
95 |
}
|
|
96 |
|
|
97 |
// for fix bug when press left or right arrow play err-tone
|
|
98 |
if ( HandleVerticalNavigation( aKey ) || HandleHorizontalNavigation( aKey ) )
|
|
99 |
{
|
|
100 |
return ETrue;
|
|
101 |
}
|
|
102 |
|
|
103 |
if ( aLength == EShortKeyPress && ( candidatePane->SelectIndex(index,EFalse)
|
|
104 |
|| aKey == EKeyOK || aKey == EKeyCBA1 ))
|
|
105 |
{
|
|
106 |
TPtrC text = candidatePane->CurrentPhraseCandidate();//current selected in candidates
|
|
107 |
if ( text.Length() == 0 )
|
|
108 |
{
|
|
109 |
return ETrue;
|
|
110 |
}
|
|
111 |
TBuf<KMaxBufLen> pinyinshown = UIContainer()->PinyinPopupWindow()->GetEEPContent();//current selected spelling
|
|
112 |
TInt count = TZhuyinSymbolsMethods::GetChineseCount(pinyinshown);//zhuyin group num
|
|
113 |
if ( count > text.Length() )
|
|
114 |
{
|
|
115 |
fepMan->PhraseCreation(ETrue);
|
|
116 |
}
|
|
117 |
if ( fepMan->IsPhraseCreation( ) )
|
|
118 |
{
|
|
119 |
TBuf<KMaxBufLen> buf;
|
|
120 |
buf.Copy( text );
|
|
121 |
TBool commit = TZhuyinSymbolsMethods::AppendChineseChar( buf,
|
|
122 |
fepMan->ZhuyinAnalyser( ), zhuyinSymbols, chineseDisped,
|
|
123 |
zhuyinSymbolsForChinese );
|
|
124 |
TBool changeState = UpdateEEPContent();
|
|
125 |
if ( commit )
|
|
126 |
{
|
|
127 |
TBuf<KMaxBufLen> commitbuf;
|
|
128 |
TZhuyinSymbolsMethods::Convert2Des(chineseDisped, commitbuf);
|
|
129 |
fepMan->NewTextL(commitbuf);
|
|
130 |
fepMan->CommitInlineEditL();
|
|
131 |
|
|
132 |
//we pass zhuyin-spelling to db together with phrase.
|
|
133 |
//chineseDisped is created phrase
|
|
134 |
//zhuyinSymbolsForChinese is spelling
|
|
135 |
TBuf<(1+KMaxPinYinSpellLength)*KInputPhraseMaxLength> phraseCreatedWithZhuYin;//(Zi+zhuyin)* max_Zi
|
|
136 |
phraseCreatedWithZhuYin.FillZ();
|
|
137 |
for (TInt i = 0; i < chineseDisped->Count(); i++)
|
|
138 |
{
|
|
139 |
TPtrC ptrZi = chineseDisped->MdcaPoint(i);
|
|
140 |
phraseCreatedWithZhuYin.Append(ptrZi);
|
|
141 |
|
|
142 |
TPtrC ptrZhuYin = zhuyinSymbolsForChinese->MdcaPoint(i);
|
|
143 |
phraseCreatedWithZhuYin.Append(ptrZhuYin);
|
|
144 |
|
|
145 |
TInt zeroTail = (1+KMaxPinYinSpellLength)-(ptrZi.Length()+ptrZhuYin.Length());
|
|
146 |
phraseCreatedWithZhuYin.AppendFill(0,zeroTail);
|
|
147 |
|
|
148 |
}
|
|
149 |
|
|
150 |
AddPhraseToDB(phraseCreatedWithZhuYin);
|
|
151 |
if ( chineseDisped->Count() < KInputPhraseMaxLength ||
|
|
152 |
zhuyinSymbols->Count() == 0 )
|
|
153 |
{
|
|
154 |
iOwner->FepMan()->TryCloseUiL();
|
|
155 |
}
|
|
156 |
else
|
|
157 |
{
|
|
158 |
CAknWarningNote* errnote = new( ELeave ) CAknWarningNote();
|
|
159 |
errnote->SetTone( CAknNoteDialog::EWarningTone );
|
|
160 |
errnote->ExecuteLD( KMaxPhraseNote );
|
|
161 |
fepMan->TryCloseUiL();
|
|
162 |
}
|
|
163 |
popup->ResetStrokeArray();
|
|
164 |
}
|
|
165 |
else
|
|
166 |
{
|
|
167 |
editPane->SetCursorIndexOfKeystroke( 0 );
|
|
168 |
if ( changeState )
|
|
169 |
{
|
|
170 |
for ( TInt i = 0; i < candidateList->Count(); i++ )
|
|
171 |
{
|
|
172 |
if ( TZhuyinSymbolsMethods::IsZhuyinSymbol( //0x3105~0x3129 is zhuyin symbol,not include tone
|
|
173 |
candidateList->MdcaPoint( i ) ) )
|
|
174 |
{
|
|
175 |
candidateList->Delete( i, 1 );
|
|
176 |
break;
|
|
177 |
}
|
|
178 |
}
|
|
179 |
if ( candidateList->Count() > 0 )
|
|
180 |
{
|
|
181 |
popup->SetChangeState( ETrue );
|
|
182 |
iOwner->ChangeState( EEntry );
|
|
183 |
}
|
|
184 |
else
|
|
185 |
{
|
|
186 |
popup->SetChangeState( ETrue );
|
|
187 |
iOwner->ChangeState( EZhuyinSequenceEdit );
|
|
188 |
}
|
|
189 |
}
|
|
190 |
else
|
|
191 |
{
|
|
192 |
popup->SetChangeState( ETrue );
|
|
193 |
iOwner->ChangeState( EZhuyinSequenceEdit );
|
|
194 |
}
|
|
195 |
}
|
|
196 |
}
|
|
197 |
else
|
|
198 |
{
|
|
199 |
TBuf<KMaxBufLen> textbuf;
|
|
200 |
for ( TInt i = 0; i < chineseDisped->Count(); i++ )
|
|
201 |
{
|
|
202 |
textbuf.Append(chineseDisped->MdcaPoint(i));
|
|
203 |
}
|
|
204 |
textbuf.Append(text);
|
|
205 |
fepMan->NewTextL(textbuf);
|
|
206 |
fepMan->CommitInlineEditL();
|
|
207 |
AddPhraseToDB(textbuf);
|
|
208 |
popup->ResetStrokeArray();
|
|
209 |
if ( text.Length() <= KInputPhraseMaxLength && !fepMan->IsPhraseCreation() )
|
|
210 |
{
|
|
211 |
if (fepMan->IsFlagSet(CAknFepManager::EFlagEditorFull))
|
|
212 |
{
|
|
213 |
fepMan->ClearFlag(CAknFepManager::EFlagEditorFull);
|
|
214 |
iOwner->FepMan()->TryCloseUiL();
|
|
215 |
}
|
|
216 |
else
|
|
217 |
{
|
|
218 |
iOwner->ChangeState( EPredictiveCandidate );
|
|
219 |
}
|
|
220 |
}
|
|
221 |
else
|
|
222 |
{
|
|
223 |
fepMan->TryCloseUiL();
|
|
224 |
}
|
|
225 |
}
|
|
226 |
}
|
|
227 |
else if ( aKey == EPtiKeyStar )
|
|
228 |
{
|
|
229 |
return ETrue;
|
|
230 |
}
|
|
231 |
else if ( aKey == EKeyCBA2 )
|
|
232 |
{
|
|
233 |
popup->ResetStrokeArray();
|
|
234 |
iOwner->FepMan()->EntryPhrase( EFalse );
|
|
235 |
iOwner->FepMan()->TryCloseUiL();
|
|
236 |
}
|
|
237 |
else if ( !iOwner->IsValidChineseInputKey(aKey) )
|
|
238 |
{
|
|
239 |
iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
|
|
240 |
}
|
|
241 |
return ETrue;
|
|
242 |
}
|
|
243 |
|
|
244 |
TBool TAknFepInputStateCandidateChinesePhrase::UpdateEEPContent( )
|
|
245 |
{
|
|
246 |
CPtiEngine* ptiengine = iOwner->PtiEngine();
|
|
247 |
CDesCArrayFlat* zhuyinSymbols = UIContainer()->PinyinPopupWindow()->ZhuyinSymbols();
|
|
248 |
CDesCArrayFlat* chineseDisped = UIContainer()->PinyinPopupWindow()->ChineseCharsDisped();
|
|
249 |
CAknFepZhuyinAnalyser* analyser = iOwner->ZhuyinAnalyser();
|
|
250 |
CDesCArrayFlat* candidateList = UIContainer()->CandidatePane()->CandidateArray();
|
|
251 |
TBuf<KMaxBufLen> buf;
|
|
252 |
TBool isPhraseCreation = EFalse;
|
|
253 |
TBool valid = TZhuyinSymbolsMethods::UpdateEEPContent(
|
|
254 |
ptiengine,
|
|
255 |
analyser,
|
|
256 |
zhuyinSymbols,
|
|
257 |
chineseDisped,
|
|
258 |
candidateList,
|
|
259 |
buf,
|
|
260 |
isPhraseCreation
|
|
261 |
);
|
|
262 |
|
|
263 |
if ( chineseDisped->Count() != 0 || zhuyinSymbols->Count() > 1 )
|
|
264 |
{
|
|
265 |
for ( TInt i = 0; i < candidateList->Count(); ++i )
|
|
266 |
{
|
|
267 |
if ( TZhuyinSymbolsMethods::IsZhuyinSymbol( candidateList->MdcaPoint( i ) ) )
|
|
268 |
{
|
|
269 |
candidateList->Delete( i, 1 );
|
|
270 |
break;
|
|
271 |
}
|
|
272 |
}
|
|
273 |
}
|
|
274 |
iOwner->FepMan()->PhraseCreation(isPhraseCreation);
|
|
275 |
UIContainer()->PinyinPopupWindow()->SetEEPContent(buf);
|
|
276 |
UIContainer()->PinyinPopupWindow()->SetEEPContentValid(valid);
|
|
277 |
return valid;
|
|
278 |
}
|
|
279 |
void TAknFepInputStateCandidateChinesePhrase::AddPhraseToDB( TDes& aPhrase )
|
|
280 |
{
|
|
281 |
TPtiUserDictionaryEntry addUdbEntry( aPhrase );
|
|
282 |
//Add the phrase to the DB by PTI Engine
|
|
283 |
iOwner->PtiEngine()->AddUserDictionaryEntry( addUdbEntry );
|
|
284 |
}
|
|
285 |
|
|
286 |
// End of file
|