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