|
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 <peninputsplititutnew.rsg> |
|
20 #include <peninputsplititutconfig_chinese.rsg> |
|
21 #include <peninputdropdownlist.h> |
|
22 #include <coemain.h> |
|
23 #include <AknFepGlobalEnums.h> |
|
24 #include <PtiEngine.h> |
|
25 |
|
26 #include "peninputsplititutchnuistatepredict.h" |
|
27 #include "peninputsplititutuimgrbase.h" |
|
28 #include "peninputsplititutdatamgr.h" |
|
29 #include "peninputsplititutlayoutcontext.h" |
|
30 #include "peninputsplititutconverter.h" |
|
31 |
|
32 const TInt KInvalidIndex = -1; |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS ============================= |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CChnSplitItutUiStatePredict::NewL |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 CChnSplitItutUiStatePredict* CChnSplitItutUiStatePredict::NewL(CSplitItutUiMgrBase* aOwner) |
|
41 { |
|
42 CChnSplitItutUiStatePredict* self = new (ELeave) CChnSplitItutUiStatePredict(aOwner); |
|
43 CleanupStack::PushL(self); |
|
44 self->ConstructL(); |
|
45 CleanupStack::Pop(self); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // CChnSplitItutUiStatePredict::~CChnSplitItutUiStatePredict |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 CChnSplitItutUiStatePredict::~CChnSplitItutUiStatePredict() |
|
54 { |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CChnSplitItutUiStatePredict::CChnSplitItutUiStatePredict |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CChnSplitItutUiStatePredict::CChnSplitItutUiStatePredict(CSplitItutUiMgrBase* aOwner) |
|
62 :CSplitItutUiStateBase(aOwner), |
|
63 iLastOverlapIdx(KInvalidIndex) |
|
64 { |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // CChnSplitItutUiStatePredict::OnEntryL |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 void CChnSplitItutUiStatePredict::OnEntryL() |
|
72 { |
|
73 /* |
|
74 HBufC* puncText = NULL; |
|
75 switch (iOwner->DataMgr()->InputMode()) |
|
76 { |
|
77 case EPinyin: |
|
78 { |
|
79 iOwner->DataMgr()->NotifyChangeControlLayout( |
|
80 MItutPropertySubscriber::EItutPropertyKeypadResourceId, |
|
81 R_FINGER_INPUT_KEYPAD_PINYIN_STANDBY_PREDICT); |
|
82 puncText = CCoeEnv::Static()->AllocReadResourceL(R_ITUT_PUNC_PINYIN_ZHUYIN); |
|
83 } |
|
84 break; |
|
85 case EStroke: |
|
86 { |
|
87 TInt resID; |
|
88 if (iOwner->DataMgr()->InputLanguage() == ELangPrcChinese) |
|
89 { |
|
90 resID = R_FINGER_INPUT_KEYPAD_STROKE_STANDBY_PREDICT_PRC; |
|
91 } |
|
92 else |
|
93 { |
|
94 resID = R_FINGER_INPUT_KEYPAD_STROKE_STANDBY_PREDICT_TRA; |
|
95 } |
|
96 iOwner->DataMgr()->NotifyChangeControlLayout( |
|
97 MItutPropertySubscriber::EItutPropertyKeypadResourceId, |
|
98 resID); |
|
99 puncText = CCoeEnv::Static()->AllocReadResourceL(R_ITUT_PUNC_STROKE); |
|
100 } |
|
101 break; |
|
102 case EZhuyin: |
|
103 { |
|
104 iOwner->DataMgr()->NotifyChangeControlLayout( |
|
105 MItutPropertySubscriber::EItutPropertyKeypadResourceId, |
|
106 R_FINGER_INPUT_KEYPAD_ZHUYIN_STANDBY_PREDICT); |
|
107 puncText = CCoeEnv::Static()->AllocReadResourceL(R_ITUT_PUNC_PINYIN_ZHUYIN); |
|
108 } |
|
109 break; |
|
110 default: |
|
111 { |
|
112 // wrong input mode |
|
113 return; |
|
114 } |
|
115 } |
|
116 |
|
117 // show punc drop list, and set candidates to it |
|
118 CFepCtrlDropdownList* punclist = |
|
119 static_cast<CFepCtrlDropdownList*>(iOwner->LayoutContext()->Control(ECtrlIdPuncCandsList)); |
|
120 punclist->Hide(EFalse); |
|
121 |
|
122 iOwner->DataMgr()->ClearChnCandidates(EItutPuncCandidates); |
|
123 RPointerArray<HBufC>& punccandslist = |
|
124 TItutDataConverter::AnyToRptrArray(iOwner->DataMgr()->RequestData(EChnPuncCandidates)); |
|
125 TItutDataConverter::ConvertNonPhraseCandidateL(*puncText, punccandslist); |
|
126 |
|
127 punclist->SetCandidatesL(punccandslist, CFepCtrlDropdownList::EListNoExpandableWithBubble); |
|
128 delete puncText; |
|
129 |
|
130 // show candidate drop list |
|
131 CFepCtrlDropdownList* candlist = |
|
132 static_cast<CFepCtrlDropdownList*>(iOwner->LayoutContext()->Control(ECtrlIdStdCandsList)); |
|
133 candlist->Hide(EFalse); |
|
134 |
|
135 // may need to change resource id of candidte list to predictive, change keypad resource id if need |
|
136 iOwner->DataMgr()->NotifyChangeControlLayout( |
|
137 MItutPropertySubscriber::EItutPropertyCandidateListResourceId, |
|
138 R_AKN_FEP_NORMAL_CAND_DROP_DOWN_LIST); |
|
139 |
|
140 |
|
141 //hide navi button |
|
142 iOwner->LayoutContext()->ShowArrowBtn(0); |
|
143 |
|
144 //hide indicator |
|
145 iOwner->LayoutContext()->Control(ECtrlIdIndicator)->Hide(ETrue); |
|
146 */ |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // CChnSplitItutUiStatePredict::OnEntryL |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 void CChnSplitItutUiStatePredict::OnExit() |
|
154 { |
|
155 /* |
|
156 // hide dropdownlist & reset its status |
|
157 CFepCtrlDropdownList* punclist = |
|
158 static_cast<CFepCtrlDropdownList*>(iOwner->LayoutContext()->Control(ECtrlIdPuncCandsList)); |
|
159 punclist->ResetAndClear(CFepCtrlDropdownList::EListNoExpandable); |
|
160 iOwner->DataMgr()->ClearChnCandidates(EItutPuncCandidates); |
|
161 punclist->Hide(ETrue); |
|
162 |
|
163 CFepCtrlDropdownList* candlist = |
|
164 static_cast<CFepCtrlDropdownList*>(iOwner->LayoutContext()->Control(ECtrlIdStdCandsList)); |
|
165 candlist->ResetAndClear(CFepCtrlDropdownList::EListExpandable); |
|
166 iOwner->DataMgr()->ClearChnCandidates(EItutCandidates); |
|
167 candlist->Hide(ETrue); |
|
168 |
|
169 //show navi button |
|
170 iOwner->LayoutContext()->ShowArrowBtn(EBtnArrowLeft | EBtnArrowRight |
|
171 | EBtnArrowUp| EBtnArrowDown); |
|
172 |
|
173 //show indicator |
|
174 iOwner->LayoutContext()->Control(ECtrlIdIndicator)->Hide(EFalse); |
|
175 */ |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // CChnSplitItutUiStatePredict::HandleKeyL |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 TBool CChnSplitItutUiStatePredict::HandleKeyL(TInt aCmd, TInt aKey) |
|
183 { |
|
184 TInt immode = iOwner->DataMgr()->InputMode(); |
|
185 |
|
186 if (IsKeyValid(aKey)) |
|
187 { |
|
188 iOwner->SetNumLongPressValid(ETrue); |
|
189 iOwner->SetCurrentStateL(CSplitItutUiMgrBase::EStateComposition); |
|
190 iOwner->CurrentState()->HandleKeyL(aCmd, aKey); |
|
191 return ETrue; |
|
192 } |
|
193 else if ( ( immode == EPinyin && |
|
194 ( aKey == EPtiKey0 || aKey == EPtiKey1 || aKey == EPtiKeyStar ) ) || |
|
195 ( immode == EStroke && |
|
196 ( aKey == EPtiKeyStar || aKey == EPtiKey0 || (aKey >= EPtiKey7 && aKey <= EPtiKey9 ))) || |
|
197 ( immode == EZhuyin && aKey == EPtiKeyStar) || |
|
198 ( aKey == EKeyBackspace)) |
|
199 { |
|
200 iOwner->SetCurrentStateL(CSplitItutUiMgrBase::EStateStandby); |
|
201 } |
|
202 |
|
203 return EFalse; |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // CChnSplitItutUiStatePredict::StateType |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 CSplitItutUiMgrBase::TUiState CChnSplitItutUiStatePredict::StateType() |
|
211 { |
|
212 return CSplitItutUiMgrBase::EStatePredict; |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // CChnSplitItutUiStatePredict::IsKeyValid |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 TBool CChnSplitItutUiStatePredict::IsKeyValid(TInt aKey) |
|
220 { |
|
221 TInt immode = iOwner->DataMgr()->InputMode(); |
|
222 |
|
223 return (immode == EPinyin && aKey >= EPtiKey2 && aKey <= EPtiKey9) || |
|
224 (immode == EStroke && aKey >= EPtiKey1 && aKey <= EPtiKey6) || |
|
225 (immode == EZhuyin && aKey >= EPtiKey0 && aKey <= EPtiKey9); |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // CChnSplitItutUiStatePredict::HandleCtrlEventL |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 TBool CChnSplitItutUiStatePredict::HandleCtrlEventL(TInt /*aEventType*/, |
|
233 CFepUiBaseCtrl* /*aCtrl*/, |
|
234 const TDesC& /*aEventData*/) |
|
235 { |
|
236 /* |
|
237 switch (aEventType) |
|
238 { |
|
239 case EItutCmdCandidateSelected: |
|
240 { |
|
241 TPtrC buf = aEventData.Left(aEventData.Length() - 1); |
|
242 |
|
243 if (aCtrl->ControlId() == ECtrlIdStdCandsList) |
|
244 { |
|
245 // if press cell on candidate list, set predictive candidates of it |
|
246 iOwner->DataMgr()->PtiEngine()->SetPredictiveChineseChar(buf); |
|
247 TPtrC cands = iOwner->DataMgr()->PtiEngine()->CandidatePage(); |
|
248 |
|
249 iOwner->DataMgr()->ClearChnCandidates(EItutCandidates); |
|
250 |
|
251 RPointerArray<HBufC>& candslist = TItutDataConverter::AnyToRptrArray( |
|
252 iOwner->DataMgr()->RequestData(EChnCandidates)); |
|
253 TItutDataConverter::ConvertChnPhraseCandidateL(cands, candslist); |
|
254 |
|
255 // remove duplicate punctuation from predict candidate |
|
256 RPointerArray<HBufC>& punccandslist = TItutDataConverter::AnyToRptrArray( |
|
257 iOwner->DataMgr()->RequestData(EChnPuncCandidates)); |
|
258 iLastOverlapIdx = RemoveDuplicateCand(punccandslist, |
|
259 candslist, |
|
260 0, |
|
261 0); |
|
262 |
|
263 CFepCtrlDropdownList* canddroplist = |
|
264 reinterpret_cast<CFepCtrlDropdownList*>(aCtrl); |
|
265 canddroplist->SetCandidatesL(candslist, CFepCtrlDropdownList::EListExpandableWithBubble); |
|
266 |
|
267 // input pressed candidate |
|
268 iOwner->LayoutContext()->SubmitText(buf); |
|
269 |
|
270 return ETrue; |
|
271 } |
|
272 else if (aCtrl->ControlId() == ECtrlIdPuncCandsList) |
|
273 { |
|
274 // if press cell on punc drop list, input it directly |
|
275 iOwner->LayoutContext()->SubmitText(buf); |
|
276 |
|
277 return ETrue; |
|
278 } |
|
279 } |
|
280 break; |
|
281 case EItutCmdGetNextCandidatePage: |
|
282 { |
|
283 if (aCtrl->ControlId() == ECtrlIdStdCandsList) |
|
284 { |
|
285 RPointerArray<HBufC>& candslist = TItutDataConverter::AnyToRptrArray( |
|
286 iOwner->DataMgr()->RequestData(EChnCandidates)); |
|
287 |
|
288 if (candslist.Count() >= KMaxPredictCandCnt) |
|
289 { |
|
290 return ETrue; |
|
291 } |
|
292 |
|
293 // original candidate count before fetch new candidate |
|
294 TInt candscnt = candslist.Count(); |
|
295 if (iOwner->DataMgr()->GetNextPageCandidateL(candslist) == KErrNone) |
|
296 { |
|
297 // remove duplicate punctuation from predict candidate |
|
298 RPointerArray<HBufC>& punccandslist = TItutDataConverter::AnyToRptrArray( |
|
299 iOwner->DataMgr()->RequestData(EChnPuncCandidates)); |
|
300 iLastOverlapIdx = RemoveDuplicateCand(punccandslist, |
|
301 candslist, |
|
302 iLastOverlapIdx + 1, |
|
303 candscnt); |
|
304 |
|
305 if (candslist.Count() >= KMaxPredictCandCnt) |
|
306 { |
|
307 candscnt = candslist.Count(); |
|
308 for (TInt i = KMaxPredictCandCnt; i < candscnt; i++) |
|
309 { |
|
310 delete candslist[KMaxPredictCandCnt]; |
|
311 candslist.Remove(KMaxPredictCandCnt); |
|
312 } |
|
313 } |
|
314 |
|
315 static_cast<CFepCtrlDropdownList*>(aCtrl)->AddCandidatesL(candslist); |
|
316 } |
|
317 |
|
318 return ETrue; |
|
319 } |
|
320 } |
|
321 break; |
|
322 case EItutCmdCandidateExisted: |
|
323 { |
|
324 if (aCtrl->ControlId() == ECtrlIdStdCandsList) |
|
325 { |
|
326 RPointerArray<HBufC>& candslist = TItutDataConverter::AnyToRptrArray( |
|
327 iOwner->DataMgr()->RequestData(EChnCandidates)); |
|
328 |
|
329 if (candslist.Count() >= KMaxPredictCandCnt) |
|
330 { |
|
331 static_cast<CFepCtrlDropdownList*>(aCtrl)->SetFlagCandidateExist(EFalse); |
|
332 } |
|
333 else |
|
334 { |
|
335 static_cast<CFepCtrlDropdownList*>(aCtrl)->SetFlagCandidateExist( |
|
336 iOwner->DataMgr()->NextPageCandidateExist()); |
|
337 } |
|
338 |
|
339 return ETrue; |
|
340 } |
|
341 } |
|
342 break; |
|
343 case EEventControlFocusGained: |
|
344 { |
|
345 if (aCtrl->ControlId() == ECtrlIdICF) |
|
346 { |
|
347 iOwner->SetCurrentStateL(CSplitItutUiMgrBase::EStateStandby); |
|
348 |
|
349 // ui layout may also need to handle this event |
|
350 return EFalse; |
|
351 } |
|
352 } |
|
353 break; |
|
354 case EEventIcfPointerUpEvent: |
|
355 { |
|
356 if (aCtrl->ControlId() == ECtrlIdICF) |
|
357 { |
|
358 iOwner->SetCurrentStateL(CSplitItutUiMgrBase::EStateStandby); |
|
359 |
|
360 // ui layout may also need to handle this event |
|
361 return ETrue; |
|
362 } |
|
363 } |
|
364 break; |
|
365 default: |
|
366 break; |
|
367 } |
|
368 */ |
|
369 return EFalse; |
|
370 } |
|
371 |
|
372 // --------------------------------------------------------------------------- |
|
373 // CChnSplitItutUiStatePredict::RemoveDuplicateCand |
|
374 // --------------------------------------------------------------------------- |
|
375 // |
|
376 TInt CChnSplitItutUiStatePredict::RemoveDuplicateCand(const RPointerArray<HBufC>& aSrc, |
|
377 RPointerArray<HBufC>& aTgt, |
|
378 TInt aSrcStartIdx, |
|
379 TInt aTgtStartIdx) |
|
380 { |
|
381 TInt lastOverlapIdx = KInvalidIndex; |
|
382 |
|
383 // on the assumption that if candidate overlap, |
|
384 // it is overlap only once |
|
385 TInt srccandcnt = aSrc.Count(); |
|
386 |
|
387 for (TInt i = aSrcStartIdx; i < srccandcnt; i++) |
|
388 { |
|
389 for (TInt j = aTgtStartIdx; j < aTgt.Count(); j++) |
|
390 { |
|
391 if (aTgt[j]->Compare(*(aSrc[i])) == 0) |
|
392 { |
|
393 lastOverlapIdx = i; |
|
394 delete aTgt[j]; |
|
395 aTgt.Remove(j); |
|
396 j--; |
|
397 break; |
|
398 } |
|
399 } |
|
400 } |
|
401 |
|
402 return lastOverlapIdx; |
|
403 } |
|
404 |
|
405 // End Of File |