|
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: drop-down list control |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <peninputdropdownlist.h> |
|
20 #include <PtiEngine.h> |
|
21 #include <peninputgeneralitutnew.rsg> |
|
22 #include <peninputitutconfig_chinese.rsg> |
|
23 |
|
24 #include "peninputitutchnuistatepinyincomposition.h" |
|
25 #include "peninputgenericitutuimgrbase.h" |
|
26 #include "peninputgenericitutdatamgr.h" |
|
27 #include "peninputgenericitutlayoutcontext.h" |
|
28 #include "peninputgenericitutconverter.h" |
|
29 #include "peninputgenericitutwindowmanager.h" |
|
30 |
|
31 CChnItutUiStatePinyinComposition* CChnItutUiStatePinyinComposition::NewL( |
|
32 CGenericItutUiMgrBase* aOwner) |
|
33 { |
|
34 CChnItutUiStatePinyinComposition* self = |
|
35 new (ELeave) CChnItutUiStatePinyinComposition(aOwner); |
|
36 CleanupStack::PushL(self); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop(self); |
|
39 return self; |
|
40 } |
|
41 |
|
42 CChnItutUiStatePinyinComposition::~CChnItutUiStatePinyinComposition() |
|
43 { |
|
44 iSpellCands.ResetAndDestroy(); |
|
45 iSpellCands.Close(); |
|
46 } |
|
47 |
|
48 CChnItutUiStatePinyinComposition::CChnItutUiStatePinyinComposition( |
|
49 CGenericItutUiMgrBase* aOwner):CGenericItutUiStateBase(aOwner) |
|
50 { |
|
51 } |
|
52 |
|
53 void CChnItutUiStatePinyinComposition::OnEntryL() |
|
54 { |
|
55 // update resource id of keypad, candidate drop list |
|
56 iOwner->DataMgr()->NotifyChangeControlLayout( |
|
57 MItutPropertySubscriber::EItutPropertyKeypadResourceId, |
|
58 R_FINGER_INPUT_KEYPAD_PINYIN_COMPOSITION); |
|
59 iOwner->DataMgr()->NotifyChangeControlLayout( |
|
60 MItutPropertySubscriber::EItutPropertyCandidateListResourceId, |
|
61 R_AKN_FEP_PINYIN_CAND_DROP_DOWN_LIST); |
|
62 |
|
63 // show spell drop list |
|
64 CFepCtrlDropdownList* spelllist = static_cast<CFepCtrlDropdownList*>( |
|
65 iOwner->LayoutContext()->Control(ECtrlIdSpellCandsList)); |
|
66 spelllist->Hide(EFalse); |
|
67 |
|
68 // show candidate drop list |
|
69 CFepCtrlDropdownList* candlist = static_cast<CFepCtrlDropdownList*>( |
|
70 iOwner->LayoutContext()->Control(ECtrlIdStdCandsList)); |
|
71 candlist->Hide(EFalse); |
|
72 |
|
73 //hide navi button |
|
74 iOwner->LayoutContext()->ShowArrowBtn(0); |
|
75 // Show ICF, Backspace after position changed to avoid flick |
|
76 iOwner->LayoutContext()->Control(ECtrlIdICF)->Hide( EFalse ); |
|
77 iOwner->LayoutContext()->Control(ECtrlIdBackspace)->Hide( EFalse ); |
|
78 |
|
79 //hide indicator |
|
80 iOwner->LayoutContext()->Control(ECtrlIdIndicator)->Hide(ETrue); |
|
81 } |
|
82 |
|
83 void CChnItutUiStatePinyinComposition::OnExit() |
|
84 { |
|
85 // hide dropdownlist & reset its status |
|
86 CFepCtrlDropdownList* spelllist = static_cast<CFepCtrlDropdownList*>( |
|
87 iOwner->LayoutContext()->Control(ECtrlIdSpellCandsList)); |
|
88 spelllist->Hide(ETrue); |
|
89 |
|
90 CFepCtrlDropdownList* candlist = static_cast<CFepCtrlDropdownList*>( |
|
91 iOwner->LayoutContext()->Control(ECtrlIdStdCandsList)); |
|
92 iOwner->DataMgr()->ClearChnCandidates(EItutCandidates); |
|
93 candlist->Hide(ETrue); |
|
94 |
|
95 iOwner->DataMgr()->PtiEngine()->ClearCurrentWord(); |
|
96 // Hide ICF, Backspace, Arrow contrls when exit to avoid flick |
|
97 |
|
98 //show indicator |
|
99 |
|
100 iOwner->DataMgr()->PtiEngine()->ClearCurrentWord(); |
|
101 |
|
102 } |
|
103 |
|
104 TBool CChnItutUiStatePinyinComposition::HandleKeyL(TInt /*aCmd*/, TInt aKey) |
|
105 { |
|
106 if (!(aKey == EKeyBackspace || |
|
107 (aKey >= EPtiKey0 && aKey <= EPtiKey9) || |
|
108 (aKey == EPtiKeyStar))) |
|
109 { |
|
110 return EFalse; |
|
111 } |
|
112 |
|
113 if (aKey >= EPtiKey0 && aKey <= EPtiKey9) |
|
114 { |
|
115 // append keypress |
|
116 iOwner->DataMgr()->PtiEngine()->AppendKeyPress(TPtiKey(aKey)); |
|
117 } |
|
118 else if (aKey == EKeyBackspace) |
|
119 { |
|
120 if (!iOwner->DataMgr()->PtiEngine()->DeleteKeyPress().Length()) |
|
121 { |
|
122 iOwner->SetCurrentStateL(CGenericItutUiMgrBase::EStateStandby); |
|
123 |
|
124 iOwner->SetClrConsume(ETrue); |
|
125 |
|
126 return ETrue; |
|
127 } |
|
128 } |
|
129 else{ |
|
130 // input tonemark |
|
131 if (!iOwner->DataMgr()->PtiEngine()->IncrementToneMark(ETrue)) |
|
132 { |
|
133 // tonemark did not set correctly, everything unchanged |
|
134 return ETrue; |
|
135 } |
|
136 } |
|
137 |
|
138 // get all spelling |
|
139 TInt spellcnt = iOwner->DataMgr()->PtiEngine()->PhoneticSpellingCount(); |
|
140 |
|
141 iSpellCands.ResetAndDestroy(); |
|
142 iSpellCands.Close(); |
|
143 |
|
144 // note: ptiengine's phonetic spelling start index is 1, not 0 |
|
145 for (TInt i = 1; i < (spellcnt + 1); i++) |
|
146 { |
|
147 HBufC* spellbuf = (iOwner->DataMgr()->PtiEngine()->GetPhoneticSpelling(i)).AllocL(); |
|
148 |
|
149 CleanupStack::PushL(spellbuf); |
|
150 iSpellCands.Append(spellbuf); |
|
151 CleanupStack::Pop(spellbuf); |
|
152 } |
|
153 |
|
154 TInt nearestIdx = 0; |
|
155 |
|
156 /* |
|
157 if (iLastSelSpell) |
|
158 { |
|
159 nearestIdx = GetNearestSpell(iLastSelSpell->Length()); |
|
160 |
|
161 delete iLastSelSpell; |
|
162 iLastSelSpell = NULL; |
|
163 } |
|
164 |
|
165 iLastSelSpell = (iOwner->DataMgr()->PtiEngine()->GetPhoneticSpelling(nearestIdx + 1)).AllocL(); |
|
166 */ |
|
167 |
|
168 // set spell, set highlight of spelling candidate list |
|
169 CFepCtrlDropdownList* spelldroplist = static_cast<CFepCtrlDropdownList*>( |
|
170 iOwner->LayoutContext()->Control(ECtrlIdSpellCandsList)); |
|
171 spelldroplist->SetCandidatesL(iSpellCands, CFepCtrlDropdownList::EListExpandableRollWithIconWithBubble); |
|
172 spelldroplist->SetHighlightCell(nearestIdx); |
|
173 |
|
174 // get candidates of nearest spell |
|
175 iOwner->DataMgr()->PtiEngine()->SelectPhoneticSpelling(nearestIdx + 1); |
|
176 TPtrC cands = iOwner->DataMgr()->PtiEngine()->CandidatePage(); |
|
177 |
|
178 iOwner->DataMgr()->ClearChnCandidates(EItutCandidates); |
|
179 RPointerArray<HBufC>& candslist = |
|
180 TItutDataConverter::AnyToRptrArray(iOwner->DataMgr()->RequestData(EChnCandidates)); |
|
181 TItutDataConverter::ConvertChnPhraseCandidateL(cands, candslist); |
|
182 |
|
183 // set candidate |
|
184 CFepCtrlDropdownList* canddroplist = |
|
185 static_cast<CFepCtrlDropdownList*>(iOwner->LayoutContext()->Control(ECtrlIdStdCandsList)); |
|
186 canddroplist->SetCandidatesL(candslist, CFepCtrlDropdownList::EListExpandableWithBubble); |
|
187 |
|
188 return ETrue; |
|
189 } |
|
190 |
|
191 /* |
|
192 TInt CChnItutUiStatePinyinComposition::GetNearestSpell(TInt aValidLastSpellLen) |
|
193 { |
|
194 if (aValidLastSpellLen <= 0) |
|
195 { |
|
196 return 0; |
|
197 } |
|
198 |
|
199 for (TInt i = 0; i < iSpellCands.Count(); i++) |
|
200 { |
|
201 if ((iSpellCands[i]->Left(aValidLastSpellLen)).Compare(iLastSelSpell->Left(aValidLastSpellLen)) == 0) |
|
202 { |
|
203 return i; |
|
204 } |
|
205 } |
|
206 |
|
207 return GetNearestSpell(aValidLastSpellLen-1); |
|
208 } |
|
209 */ |
|
210 |
|
211 TBool CChnItutUiStatePinyinComposition::HandleCtrlEventL( |
|
212 TInt aEventType, CFepUiBaseCtrl* aCtrl, const TDesC& aEventData) |
|
213 { |
|
214 switch (aEventType) |
|
215 { |
|
216 case EItutCmdCandidateSelected: |
|
217 { |
|
218 // press cell on spelling list |
|
219 if (aCtrl->ControlId() == ECtrlIdSpellCandsList && |
|
220 aEventData.Length() > 0) |
|
221 { |
|
222 TInt selCandIdx = aEventData[aEventData.Length() - 1]; |
|
223 |
|
224 // note for ptiengine, spelling index start from 1, not 0 |
|
225 iOwner->DataMgr()->PtiEngine()->SelectPhoneticSpelling(selCandIdx + 1); |
|
226 |
|
227 CFepCtrlDropdownList* spelldroplist = static_cast<CFepCtrlDropdownList*>(aCtrl); |
|
228 spelldroplist->SetHighlightCell(selCandIdx); |
|
229 |
|
230 /* |
|
231 delete iLastSelSpell; |
|
232 iLastSelSpell = NULL; |
|
233 iLastSelSpell = (iOwner->DataMgr()->PtiEngine()->GetPhoneticSpelling(selCandIdx + 1)).AllocL(); |
|
234 */ |
|
235 |
|
236 TPtrC cands = iOwner->DataMgr()->PtiEngine()->CandidatePage(); |
|
237 |
|
238 iOwner->DataMgr()->ClearChnCandidates(EItutCandidates); |
|
239 RPointerArray<HBufC>& candslist = TItutDataConverter::AnyToRptrArray( |
|
240 iOwner->DataMgr()->RequestData(EChnCandidates)); |
|
241 TItutDataConverter::ConvertChnPhraseCandidateL(cands, candslist); |
|
242 |
|
243 CFepCtrlDropdownList* canddroplist = static_cast<CFepCtrlDropdownList*>( |
|
244 iOwner->LayoutContext()->Control(ECtrlIdStdCandsList)); |
|
245 canddroplist->SetCandidatesL(candslist, CFepCtrlDropdownList::EListExpandableWithBubble); |
|
246 |
|
247 return ETrue; |
|
248 } |
|
249 else if (aCtrl->ControlId() == ECtrlIdStdCandsList) |
|
250 { |
|
251 iOwner->SetCurrentStateL(CGenericItutUiMgrBase::EStatePredict); |
|
252 return iOwner->CurrentState()->HandleCtrlEventL(aEventType, aCtrl, aEventData); |
|
253 } |
|
254 } |
|
255 break; |
|
256 case EItutCmdGetNextCandidatePage: |
|
257 { |
|
258 if (aCtrl->ControlId() == ECtrlIdStdCandsList) |
|
259 { |
|
260 RPointerArray<HBufC>& candslist = TItutDataConverter::AnyToRptrArray( |
|
261 iOwner->DataMgr()->RequestData(EChnCandidates)); |
|
262 |
|
263 // original candidate count before fetch new candidate |
|
264 TInt candscnt = candslist.Count(); |
|
265 if (iOwner->DataMgr()->GetNextPageCandidateL(candslist) == KErrNone) |
|
266 { |
|
267 static_cast<CFepCtrlDropdownList*>(aCtrl)->AddCandidatesL(candslist); |
|
268 } |
|
269 |
|
270 return ETrue; |
|
271 } |
|
272 } |
|
273 break; |
|
274 case EItutCmdCandidateExisted: |
|
275 { |
|
276 if (aCtrl->ControlId() == ECtrlIdStdCandsList) |
|
277 { |
|
278 static_cast<CFepCtrlDropdownList*>( |
|
279 aCtrl)->SetFlagCandidateExist(iOwner->DataMgr()->NextPageCandidateExist()); |
|
280 return ETrue; |
|
281 } |
|
282 } |
|
283 break; |
|
284 // consume star key at pinyin composition state |
|
285 case EEventRawKeyDownEvent: |
|
286 { |
|
287 if ( iOwner->UiManager()->IsAllowHandleRawKeyEvent()) |
|
288 { |
|
289 const TKeyEvent *key = reinterpret_cast<const TKeyEvent*>(aEventData.Ptr()); |
|
290 |
|
291 if (key->iScanCode == EStdKeyNkpAsterisk) |
|
292 { |
|
293 HandleKeyL(ECmdPenInputFingerKeyPress, EPtiKeyStar); |
|
294 return ETrue; |
|
295 } |
|
296 } |
|
297 } |
|
298 break; |
|
299 case EEventRawKeyUpEvent: |
|
300 { |
|
301 if ( iOwner->UiManager()->IsAllowHandleRawKeyEvent()) |
|
302 { |
|
303 const TKeyEvent *key = reinterpret_cast<const TKeyEvent*>(aEventData.Ptr()); |
|
304 |
|
305 if (key->iScanCode == EStdKeyNkpAsterisk) |
|
306 { |
|
307 return ETrue; |
|
308 } |
|
309 } |
|
310 } |
|
311 break; |
|
312 default: |
|
313 break; |
|
314 } |
|
315 |
|
316 return EFalse; |
|
317 } |
|
318 |
|
319 CGenericItutUiMgrBase::TUiState CChnItutUiStatePinyinComposition::StateType() |
|
320 { |
|
321 return CGenericItutUiMgrBase::EStateComposition; |
|
322 } |
|
323 |
|
324 // End Of File |