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