|
1 /* |
|
2 * Copyright (c) 2009 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: Predictive list |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <AknsDrawUtils.h> |
|
21 #include <aknconsts.h> // KStatusPaneBackgroundColor |
|
22 #include <aknlayoutscalable_avkon.cdl.h> // AknLayoutScalable_Avkon |
|
23 #include <peninputeventjp.h> // EPeninputLayoutEventSelectItem |
|
24 #include <peninputrepeatbutton.h> // CAknFepCtrlEventButton,CAknFepCtrlRepeatButton |
|
25 #include <peninputlayout.h> |
|
26 #include <AknsBasicBackgroundControlContext.h> |
|
27 |
|
28 #include "peninputeventjp.h" |
|
29 #include "peninputjapanesepredictivewnd.h" |
|
30 #include "peninputjapanesepredictivelistbox.h" |
|
31 #include "peninputjapanesepredictivecelllistboxdata.h" |
|
32 #include "peninputjapanesepredictiveListboxitemdrawer.h" |
|
33 #include "peninputlayoutwindowjp.h" |
|
34 |
|
35 // CONSTANTS |
|
36 const TInt KMaxListColumns = 24; // for vkb |
|
37 const TInt KSpaceCharCode = ' '; |
|
38 |
|
39 /** |
|
40 * CPeninputJapanesePredictiveWnd class. |
|
41 * |
|
42 */ |
|
43 |
|
44 // ============================ MEMBER FUNCTIONS =============================== |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CPeninputJapanesePredictiveWnd::NewL |
|
48 // Two-phased constructor. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 EXPORT_C CPeninputJapanesePredictiveWnd* CPeninputJapanesePredictiveWnd::NewL(CFepUiLayout* aUiLayout, |
|
52 TInt aControlId, const CCoeControl* aParent) |
|
53 { |
|
54 CPeninputJapanesePredictiveWnd* self = |
|
55 new(ELeave) CPeninputJapanesePredictiveWnd(aUiLayout, aControlId); |
|
56 CleanupStack::PushL(self); |
|
57 self->ConstructL(aParent); |
|
58 CleanupStack::Pop(self); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CPeninputJapanesePredictiveWnd::~CPeninputJapanesePredictiveWnd |
|
64 // Destructor |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 CPeninputJapanesePredictiveWnd::~CPeninputJapanesePredictiveWnd() |
|
68 { |
|
69 delete iListBox; |
|
70 if (iLineInfoArray) |
|
71 { |
|
72 iLineInfoArray->ResetAndDestroy(); |
|
73 } |
|
74 delete iLineInfoArray; |
|
75 delete iListTextArray; |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // CPeninputJapanesePredictiveWnd::SetRect |
|
80 // Set the prediction pane's rect |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 EXPORT_C void CPeninputJapanesePredictiveWnd::SetRect(const TRect& aRect) |
|
84 { |
|
85 if (!iUnitWidth) |
|
86 { |
|
87 return; // not ready |
|
88 } |
|
89 iRect = aRect; |
|
90 CFepUiBaseCtrl::UpdateValidRegion(this, ETrue); // for getting pointer event |
|
91 TRect rect(aRect); |
|
92 TAknWindowLineLayout textWindowLayout = |
|
93 AknLayoutScalable_Avkon::list_single_choice_list_pane(0).LayoutLine(); |
|
94 TInt topMargin = (iUnitHeight > textWindowLayout.iH)? (iUnitHeight - textWindowLayout.iH) : KPENINPUT_LAYOUT_VALUE_2; |
|
95 rect.Shrink(KPENINPUT_LAYOUT_VALUE_4, topMargin); |
|
96 |
|
97 rect.iBr.iX -=iUnitWidth; |
|
98 iListBox->SetRect(rect); // call iListBox->SizeChaged() |
|
99 if (iScrollUpBtn && iScrollDownBtn) |
|
100 { |
|
101 TRect upBtn(TPoint(iRect.iBr.iX -iUnitWidth , iRect.iTl.iY), TSize(iUnitWidth, iUnitHeight)); |
|
102 TRect downBtn(TPoint(iRect.iBr.iX - iUnitWidth, iRect.iTl.iY + iUnitHeight), TSize(iUnitWidth, iUnitHeight)); |
|
103 iScrollUpBtn->SetRect(upBtn); |
|
104 iScrollDownBtn->SetRect(downBtn); |
|
105 } |
|
106 |
|
107 // instead of MakeVisible(EFalse) |
|
108 if (iListBox->ScrollBarFrame()->GetScrollBarHandle(CEikScrollBar::EVertical)) |
|
109 { |
|
110 TRect sbRect(TPoint(rect.iBr.iX, Rect().iTl.iY) |
|
111 , TSize(iListBox->ScrollBarFrame()->GetScrollBarHandle(CEikScrollBar::EVertical)->Rect().Size().iHeight,0)); |
|
112 |
|
113 iListBox->ScrollBarFrame()->GetScrollBarHandle(CEikScrollBar::EVertical)->SetRect(sbRect); |
|
114 } |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CPeninputJapanesePredictiveWnd::Hide |
|
119 // (other items were commented in a header). |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 void CPeninputJapanesePredictiveWnd::Hide(TBool aFlag) |
|
123 { |
|
124 if (iScrollUpBtn && iScrollDownBtn) |
|
125 { |
|
126 CPeninputLayoutWindowJp* window = static_cast<CPeninputLayoutWindowJp*>(iScrollUpBtn->ParentCtrl()); |
|
127 if (window) |
|
128 { |
|
129 window->ICFDisableRegionUpdating(); // ICF::OnDeActivate() |
|
130 } |
|
131 if (aFlag || !iScrollUpBtn->IsDimmed()) |
|
132 { |
|
133 iScrollUpBtn->Hide(aFlag); |
|
134 iScrollDownBtn->Hide(aFlag); |
|
135 } |
|
136 else |
|
137 { |
|
138 iScrollUpBtn->Hide(ETrue); |
|
139 iScrollDownBtn->Hide(ETrue); |
|
140 } |
|
141 } |
|
142 CFepLayoutPopupWnd::Hide(aFlag); |
|
143 } |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CPeninputJapanesePredictiveWnd::SetButtons |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 void CPeninputJapanesePredictiveWnd::SetButtons(CAknFepCtrlEventButton* aScrollUpBtn |
|
149 , CAknFepCtrlEventButton* aScrollDownBtn) |
|
150 { |
|
151 if (aScrollUpBtn && aScrollDownBtn) |
|
152 { |
|
153 iScrollUpBtn = aScrollUpBtn; |
|
154 iScrollDownBtn = aScrollDownBtn; |
|
155 iScrollUpBtn->AddEventObserver(this); |
|
156 iScrollDownBtn->AddEventObserver(this); |
|
157 ActivateButtons(EFalse); |
|
158 } |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CPeninputJapanesePredictiveWnd::SetCurrentItemIndex |
|
163 // Specify the cursor position of a pop-up list. |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 void CPeninputJapanesePredictiveWnd::SetCurrentItemIndex(TInt aItemIndex) const |
|
167 { |
|
168 CPeninputJapanesePredictiveListBoxModel* model = |
|
169 static_cast<CPeninputJapanesePredictiveListBoxModel*>(iListBox->Model()); |
|
170 const TInt maximumItems = model->MaximumItems(); |
|
171 |
|
172 if (aItemIndex > maximumItems) |
|
173 { |
|
174 aItemIndex = maximumItems; |
|
175 } |
|
176 |
|
177 iListBox->SetCurrentCandidateNo(aItemIndex, EFalse); |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // CPeninputJapanesePredictiveWnd::HandleControlEvent |
|
182 // (other items were commented in a header). |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 void CPeninputJapanesePredictiveWnd::HandleControlEvent(TInt aEventType, |
|
186 CFepUiBaseCtrl* /*aCtrl*/, |
|
187 const TDesC& /*aEventData*/) |
|
188 { |
|
189 TPointerEvent pEvent; |
|
190 pEvent.iType = TPointerEvent::EButton1Down; |
|
191 pEvent.iModifiers = 0; |
|
192 pEvent.iParentPosition = TPoint(0,0); |
|
193 switch (aEventType) |
|
194 { |
|
195 case EPeninputLayoutEventScrollUp: |
|
196 if (iListBox->ScrollBarFrame()->GetScrollBarHandle(CEikScrollBar::EVertical)) |
|
197 { |
|
198 TRAP_IGNORE(iListBox->HandleScrollEventL(iListBox->ScrollBarFrame()->GetScrollBarHandle(CEikScrollBar::EVertical),EEikScrollUp)); |
|
199 ReDraw(); |
|
200 } |
|
201 break; |
|
202 case EPeninputLayoutEventScrollDown: |
|
203 if (iListBox->ScrollBarFrame()->GetScrollBarHandle(CEikScrollBar::EVertical)) |
|
204 { |
|
205 TRAP_IGNORE(iListBox->HandleScrollEventL(iListBox->ScrollBarFrame()->GetScrollBarHandle(CEikScrollBar::EVertical),EEikScrollDown)); |
|
206 ReDraw(); |
|
207 } |
|
208 break; |
|
209 default: |
|
210 break; |
|
211 } |
|
212 } |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // CPeninputJapanesePredictiveWnd::ShowPredictiveListL |
|
216 // popup is shown always.this method draws lists. |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 void CPeninputJapanesePredictiveWnd::ShowPopupL(const CDesCArrayFlat* aItems, TInt aIndex) |
|
220 { |
|
221 if(Hiden()) |
|
222 { |
|
223 return; |
|
224 } |
|
225 if(aItems->Count() <= 0) |
|
226 { |
|
227 HidePopup(); // clear lists |
|
228 return; |
|
229 } |
|
230 |
|
231 if (iLineInfoArray) |
|
232 { |
|
233 iLineInfoArray->ResetAndDestroy(); |
|
234 } |
|
235 else |
|
236 { |
|
237 iLineInfoArray = new(ELeave) CPredictivePopupLineInfoArray(1); |
|
238 } |
|
239 |
|
240 TAknTextLineLayout textLineLayout = |
|
241 AknLayoutScalable_Avkon::fep_vkb_top_text_pane_t1().LayoutLine(); |
|
242 |
|
243 TInt allowDrawWidth = Rect().Size().iWidth - iUnitWidth-KPENINPUT_LAYOUT_VALUE_16; |
|
244 |
|
245 // Setup iLineInfoArray |
|
246 CreatePredictivePopupLineInfoArrayL(aItems, allowDrawWidth, textLineLayout.iFont); |
|
247 |
|
248 // Create iListTextArray |
|
249 CreateListTextArrayL(*iLineInfoArray); |
|
250 |
|
251 // Set listitems. |
|
252 CPeninputJapanesePredictiveListBoxModel* model = |
|
253 static_cast<CPeninputJapanesePredictiveListBoxModel*>(iListBox->Model()); |
|
254 model->SetMaximumItems(aItems->Count()); |
|
255 model->SetLineInfoArray(iLineInfoArray); |
|
256 model->SetItemTextArray(iListTextArray); |
|
257 model->SetOwnershipType(ELbmDoesNotOwnItemArray); |
|
258 |
|
259 SetCurrentItemIndex(aIndex); |
|
260 SetRect(Rect()); |
|
261 iListBox->ActivateL(); |
|
262 TBool dimm = EFalse; |
|
263 if (iLineInfoArray->Count() <= iListBox->BottomItemIndex() + 1) |
|
264 { |
|
265 dimm = ETrue; |
|
266 } |
|
267 if (iListBox->ScrollBarFrame()->GetScrollBarHandle(CEikScrollBar::EVertical)) |
|
268 { |
|
269 iListBox->ScrollBarFrame()->GetScrollBarHandle(CEikScrollBar::EVertical)->SetDimmed(dimm); |
|
270 } |
|
271 ActivateButtons(!dimm); |
|
272 if (dimm) |
|
273 { |
|
274 ClearList(); |
|
275 } |
|
276 iListBox->Draw(); |
|
277 if (iScrollUpBtn && iScrollDownBtn && !iScrollUpBtn->IsDimmed()) |
|
278 { |
|
279 iScrollUpBtn->Draw(); |
|
280 iScrollDownBtn->Draw(); |
|
281 } |
|
282 UpdateArea(iRect, EFalse); |
|
283 } |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CPeninputJapanesePredictiveWnd::HideWindow |
|
287 // popup is shown always.this method clear lists. |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 void CPeninputJapanesePredictiveWnd::HidePopup() |
|
291 { |
|
292 if(!Hiden()) |
|
293 { |
|
294 // Reset listitems. |
|
295 if (iLineInfoArray) |
|
296 { |
|
297 iLineInfoArray->ResetAndDestroy(); |
|
298 } |
|
299 ActivateButtons(EFalse); |
|
300 ClearList(); |
|
301 } |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // CPeninputJapanesePredictiveWnd::CurrentItemIndexOfCandidate |
|
306 // Return a selected candidate item number currently |
|
307 // ----------------------------------------------------------------------------- |
|
308 // |
|
309 TInt CPeninputJapanesePredictiveWnd::CurrentItemIndexOfCandidate() const |
|
310 { |
|
311 if (iListBox->IsVisible()) |
|
312 { |
|
313 return iListBox->CurrentCandidateNo(); |
|
314 } |
|
315 return -1; // Disable window |
|
316 } |
|
317 |
|
318 // ----------------------------------------------------------------------------- |
|
319 // CPeninputJapanesePredictiveWnd::MoveTo |
|
320 // Move a current item in an appointed direction |
|
321 // ----------------------------------------------------------------------------- |
|
322 // |
|
323 void CPeninputJapanesePredictiveWnd::MoveTo(TPeninputUICtrlScroll aDirection) |
|
324 { |
|
325 if (iListBox->IsVisible()) |
|
326 { |
|
327 TBool action = ETrue; |
|
328 |
|
329 switch(aDirection) |
|
330 { |
|
331 case EScrollLeft: |
|
332 { |
|
333 iListBox->MovePreviousItem(); |
|
334 } |
|
335 break; |
|
336 |
|
337 case EScrollRight: |
|
338 { |
|
339 iListBox->MoveNextItem(); |
|
340 } |
|
341 break; |
|
342 case EScrollUp: |
|
343 { |
|
344 iListBox->MovePreviousLineItem(); |
|
345 } |
|
346 break; |
|
347 |
|
348 case EScrollDown: |
|
349 { |
|
350 iListBox->MoveNextLineItem(); |
|
351 } |
|
352 break; |
|
353 |
|
354 default: |
|
355 { |
|
356 action = EFalse; |
|
357 } |
|
358 break; |
|
359 } |
|
360 if (action) |
|
361 { |
|
362 if (!Hiden()) |
|
363 { |
|
364 ReDraw(); |
|
365 } |
|
366 } |
|
367 } |
|
368 } |
|
369 |
|
370 // --------------------------------------------------------------------------- |
|
371 // CPeninputJapanesePredictiveWnd::SizeChanged |
|
372 // called by CPeninputLayoutWindowJp::SetControlsFont() |
|
373 // (other items were commented in a header). |
|
374 // --------------------------------------------------------------------------- |
|
375 // |
|
376 void CPeninputJapanesePredictiveWnd::SizeChanged(TInt aWidth, TInt aUnitWidth, TInt aUnitHeight) |
|
377 { |
|
378 if (aWidth > iUnitWidth) |
|
379 { |
|
380 iUnitWidth = aUnitWidth; |
|
381 iUnitHeight = aUnitHeight; |
|
382 TRect newRect(Rect().iTl ,TSize(aWidth,iUnitHeight*KPENINPUT_LAYOUT_PREDICTIONPANE_ROW_COUNT)); |
|
383 SetRect(newRect); // call iListBox->SetRect(), call iListBox->SizeChanged() |
|
384 iScrollUpBtn->SizeChanged(iScrollUpBtn->Rect(), iScrollUpBtn->Rect(), ETrue); |
|
385 iScrollDownBtn->SizeChanged(iScrollDownBtn->Rect(), iScrollDownBtn->Rect(), ETrue); |
|
386 } |
|
387 } |
|
388 |
|
389 // --------------------------------------------------------------------------- |
|
390 // CPeninputJapanesePredictiveWnd::HitTest |
|
391 // Get item whose region contains the point. |
|
392 // (other items were commented in a header). |
|
393 // --------------------------------------------------------------------------- |
|
394 // |
|
395 TInt CPeninputJapanesePredictiveWnd::HitTest(const TPoint& aPoint) |
|
396 { |
|
397 if( !Rect().Contains(aPoint) ) |
|
398 { |
|
399 return -1; |
|
400 } |
|
401 TRect listRect = iListBox->Rect(); |
|
402 if (listRect.iBr.iX >= aPoint.iX) |
|
403 { |
|
404 return 1; // ListBox Side |
|
405 } |
|
406 return 0; // ScrollBar |
|
407 } |
|
408 |
|
409 // --------------------------------------------------------------------------- |
|
410 // CPeninputJapanesePredictiveWnd::HandlePointerDownEventL |
|
411 // Handle pointer down event. |
|
412 // (other items were commented in a header). |
|
413 // --------------------------------------------------------------------------- |
|
414 // |
|
415 CFepUiBaseCtrl* CPeninputJapanesePredictiveWnd::HandlePointerDownEventL(const TPoint& aPoint) |
|
416 { |
|
417 CFepLayoutPopupWnd::HandlePointerDownEventL(aPoint); // set pointer down |
|
418 if (iLineInfoArray && iLineInfoArray->Count() > 0) |
|
419 { |
|
420 TInt index = HitTest(aPoint); |
|
421 TPointerEvent pEvent; |
|
422 pEvent.iType = TPointerEvent::EButton1Down; |
|
423 pEvent.iPosition = aPoint; |
|
424 pEvent.iModifiers = 0; |
|
425 pEvent.iParentPosition = TPoint(0,0); |
|
426 if (1 == index) // on ListBox |
|
427 { |
|
428 TInt oldItem = iListBox->CurrentItemIndex(); |
|
429 iListBox->HandlePointerEventL(pEvent); |
|
430 TInt currentItem = iListBox->CurrentItemIndex(); |
|
431 if (0 <= currentItem) |
|
432 { |
|
433 iListBox->SetCurrentCandidateNo(currentItem, aPoint-iListBox->Rect().iTl, ETrue); |
|
434 if (oldItem != currentItem) |
|
435 { |
|
436 TInt topItem = iListBox->TopItemIndex(); |
|
437 if (topItem <= oldItem && topItem + KPENINPUT_LAYOUT_PREDICTIONPANE_ROW_COUNT> oldItem) |
|
438 { |
|
439 iListBox->SetCurrentItemIndexAndDraw(oldItem); |
|
440 iListBox->SetCurrentItemIndex(currentItem); |
|
441 } |
|
442 } |
|
443 ReDraw(); |
|
444 } |
|
445 } |
|
446 } |
|
447 return this; |
|
448 } |
|
449 |
|
450 // --------------------------------------------------------------------------- |
|
451 // CPeninputJapanesePredictiveWnd::HandlePointerMoveEventL |
|
452 // Handle pointer move event. |
|
453 // (other items were commented in a header). |
|
454 // --------------------------------------------------------------------------- |
|
455 // |
|
456 CFepUiBaseCtrl* CPeninputJapanesePredictiveWnd::HandlePointerMoveEventL(const TPoint& aPoint) |
|
457 { |
|
458 CFepLayoutPopupWnd::HandlePointerMoveEventL(aPoint); // nop |
|
459 if( PointerDown() && iLineInfoArray && iLineInfoArray->Count() > 0) |
|
460 { |
|
461 TInt index = HitTest(aPoint); |
|
462 TPointerEvent pEvent; |
|
463 pEvent.iType = TPointerEvent::EDrag; |
|
464 pEvent.iPosition = aPoint; |
|
465 pEvent.iModifiers = 0; |
|
466 pEvent.iParentPosition = TPoint(0,0); |
|
467 if (1 == index) |
|
468 { |
|
469 TInt oldItem = iListBox->CurrentItemIndex(); |
|
470 iListBox->HandlePointerEventL(pEvent); |
|
471 TInt currentItem = iListBox->CurrentItemIndex(); |
|
472 if (0 <= currentItem) |
|
473 { |
|
474 iListBox->SetCurrentCandidateNo(currentItem, aPoint-iListBox->Rect().iTl, ETrue); |
|
475 if (oldItem != currentItem) |
|
476 { |
|
477 iListBox->SetCurrentItemIndexAndDraw(oldItem); |
|
478 iListBox->SetCurrentItemIndex(currentItem); |
|
479 } |
|
480 ReDraw(); |
|
481 } |
|
482 } |
|
483 } |
|
484 return this; |
|
485 } |
|
486 |
|
487 // --------------------------------------------------------------------------- |
|
488 // CPeninputJapanesePredictiveWnd::HandlePointerUpEventL |
|
489 // Handle pointer up event. |
|
490 // (other items were commented in a header). |
|
491 // --------------------------------------------------------------------------- |
|
492 // |
|
493 CFepUiBaseCtrl* CPeninputJapanesePredictiveWnd::HandlePointerUpEventL(const TPoint& aPoint) |
|
494 { |
|
495 TBool down = PointerDown(); |
|
496 CFepLayoutPopupWnd::HandlePointerUpEventL(aPoint); // pointer down off |
|
497 TInt index = HitTest(aPoint); |
|
498 if (down && iLineInfoArray && iLineInfoArray->Count() > 0) |
|
499 { |
|
500 TPointerEvent pEvent; |
|
501 pEvent.iType = TPointerEvent::EButton1Up; |
|
502 pEvent.iPosition = aPoint; |
|
503 pEvent.iModifiers = 0; |
|
504 pEvent.iParentPosition = TPoint(0,0); |
|
505 if (1 == index) // onListBox |
|
506 { |
|
507 iListBox->HandlePointerEventL(pEvent); |
|
508 TInt currentItem = iListBox->CurrentItemIndex(); |
|
509 if (0 <= currentItem) |
|
510 { |
|
511 iListBox->SetCurrentCandidateNo(currentItem, aPoint-iListBox->Rect().iTl, ETrue); |
|
512 } |
|
513 ReportEvent(EPeninputLayoutEventSelectItem); |
|
514 } |
|
515 } |
|
516 return this; |
|
517 } |
|
518 |
|
519 // CallBack from ListBox |
|
520 // --------------------------------------------------------------------------- |
|
521 // CPeninputJapanesePredictiveWnd::HandleListBoxEventL |
|
522 // (other items were commented in a header). |
|
523 // --------------------------------------------------------------------------- |
|
524 // |
|
525 void CPeninputJapanesePredictiveWnd::HandleListBoxEventL( |
|
526 CEikListBox* /*aListBox*/, TListBoxEvent /*aEventType*/) |
|
527 { |
|
528 } |
|
529 |
|
530 // ----------------------------------------------------------------------------- |
|
531 // CPeninputJapanesePredictiveWnd::SetLineCount |
|
532 // (other items were commented in a header). |
|
533 // ----------------------------------------------------------------------------- |
|
534 // |
|
535 void CPeninputJapanesePredictiveWnd::SetLineCount(TInt aLineCount) |
|
536 { |
|
537 iListBox->SetLineCount(aLineCount); |
|
538 } |
|
539 |
|
540 // ----------------------------------------------------------------------------- |
|
541 // CPeninputJapanesePredictiveWnd::ReDraw |
|
542 // (other items were commented in a header). |
|
543 // --------------------------------------------------------------------------- |
|
544 void CPeninputJapanesePredictiveWnd::ReDraw() |
|
545 { |
|
546 if(Hiden() || !Ready()) |
|
547 { |
|
548 return; |
|
549 } |
|
550 UpdateArea(iRect, EFalse); |
|
551 } |
|
552 |
|
553 // --------------------------------------------------------- |
|
554 // Cancel repeat |
|
555 // --------------------------------------------------------- |
|
556 // |
|
557 void CPeninputJapanesePredictiveWnd::CancelRepeat() |
|
558 { |
|
559 if (iScrollUpBtn) |
|
560 { |
|
561 static_cast<CAknFepCtrlRepeatButton*>(iScrollUpBtn)->CancelRepeat(); |
|
562 } |
|
563 if (iScrollDownBtn) |
|
564 { |
|
565 static_cast<CAknFepCtrlRepeatButton*>(iScrollDownBtn)->CancelRepeat(); |
|
566 } |
|
567 } |
|
568 |
|
569 // ----------------------------------------------------------------------------- |
|
570 // CPeninputJapanesePredictiveWnd::ListBox() |
|
571 // (other items were commented in a header). |
|
572 // --------------------------------------------------------------------------- |
|
573 CPeninputJapanesePredictiveListBox* CPeninputJapanesePredictiveWnd::ListBox() const |
|
574 { |
|
575 return iListBox; |
|
576 } |
|
577 |
|
578 // --------------------------------------------------------------------------- |
|
579 // CPeninputJapanesePredictiveWnd::OnDeActivate |
|
580 // DeActivate popup window |
|
581 // --------------------------------------------------------------------------- |
|
582 // |
|
583 void CPeninputJapanesePredictiveWnd::OnDeActivate() |
|
584 { |
|
585 ;// Do not CloseWindow; |
|
586 } |
|
587 |
|
588 // ----------------------------------------------------------------------------- |
|
589 // Constructor |
|
590 // |
|
591 // (other items were commented in a header). |
|
592 // --------------------------------------------------------------------------- |
|
593 // |
|
594 CPeninputJapanesePredictiveWnd::CPeninputJapanesePredictiveWnd(CFepUiLayout* aUiLayout, |
|
595 TInt aControlId) |
|
596 :CFepLayoutPopupWnd(TSize(0,0), aUiLayout, aControlId) |
|
597 { |
|
598 SetControlType(ECtrlBackgroundCtrl|ControlType()); // should not be ActiveCtrl of ControlGroup |
|
599 } |
|
600 |
|
601 // ----------------------------------------------------------------------------- |
|
602 // CPeninputJapanesePredictiveWnd::ConstructL |
|
603 // Symbian 2nd phase constructor can leave. |
|
604 // ----------------------------------------------------------------------------- |
|
605 // |
|
606 void CPeninputJapanesePredictiveWnd::ConstructL(const CCoeControl* aParent) |
|
607 { |
|
608 CFepLayoutPopupWnd::ConstructL(); |
|
609 iListBox = new(ELeave) CPeninputJapanesePredictiveListBox; |
|
610 iListBox->SetBorder(TGulBorder::ENone); |
|
611 iListBox->ConstructL(aParent, CEikListBox::ELeftDownInViewRect); |
|
612 iListBox->CreateScrollBarFrameL(ETrue, EFalse, EFalse); |
|
613 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
614 CEikScrollBarFrame::EOff, |
|
615 CEikScrollBarFrame::EAuto); |
|
616 iListBox->ItemDrawer()->SetGc(static_cast<CWindowGc*>(BitGc())); |
|
617 iListBox->ItemDrawer()->FormattedCellData()->SetSkinEnabledL( ETrue ); |
|
618 static_cast<CPeninputJapanesePredictiveListBoxItemDrawer*>(iListBox->ItemDrawer())->SetBitmapDevice(BitmapDevice()); |
|
619 static_cast<CPeninputJapanesePredictiveCellListBoxData*>(iListBox->ItemDrawer()->FormattedCellData())->SetWnd(this); |
|
620 iLineInfoArray = NULL; |
|
621 iListTextArray = NULL; |
|
622 } |
|
623 |
|
624 // ----------------------------------------------------------------------------- |
|
625 // CPeninputJapanesePredictiveWnd::CreatePredictivePopupLineInfoArrayL |
|
626 // Create a array with line information in candidate list |
|
627 // ----------------------------------------------------------------------------- |
|
628 void CPeninputJapanesePredictiveWnd::CreatePredictivePopupLineInfoArrayL( |
|
629 const CDesCArrayFlat* aItems, |
|
630 const TInt aMaxDisplayWidthInPixel, |
|
631 const TInt aFontId) |
|
632 { |
|
633 |
|
634 // getting font object from font id |
|
635 const CFont* font = AknLayoutUtils::FontFromId(aFontId); |
|
636 |
|
637 TInt displayWidthInPixel = aMaxDisplayWidthInPixel; |
|
638 TInt elementStartXPos = 0; |
|
639 |
|
640 TBufC<KMaxListColumns*2> bufferOfLine; |
|
641 TPtr lineText(bufferOfLine.Des()); |
|
642 lineText.SetLength(0); |
|
643 |
|
644 CPredictivePopupElementArray* elementArray = NULL; |
|
645 |
|
646 const TInt widthOfSpaceInPixel = font->CharWidthInPixels(KSpaceCharCode); |
|
647 const TInt numberOfItem = aItems->Count(); |
|
648 TInt i; |
|
649 for (i = 0; i < numberOfItem; i++) |
|
650 { |
|
651 TPtrC itemText = aItems->MdcaPoint(i); |
|
652 TInt itemTextLength = itemText.Length(); |
|
653 |
|
654 // getting a number of characters within width |
|
655 TInt count = font->TextCount(itemText, displayWidthInPixel); |
|
656 |
|
657 // If a candidate cannot occupy a line, it is |
|
658 // continued in next line |
|
659 if (count < itemTextLength && elementArray) |
|
660 { |
|
661 PredictivePopupAppendLineL(lineText, elementArray); |
|
662 CleanupStack::Pop(elementArray); // elementArray |
|
663 elementArray = NULL; |
|
664 lineText.SetLength(0); |
|
665 |
|
666 displayWidthInPixel = aMaxDisplayWidthInPixel; |
|
667 elementStartXPos = 0; |
|
668 count = font->TextCount(itemText, displayWidthInPixel); |
|
669 } |
|
670 |
|
671 FOREVER |
|
672 { |
|
673 if (!elementArray) |
|
674 { |
|
675 elementArray = new(ELeave) CPredictivePopupElementArray(1); |
|
676 CleanupStack::PushL(elementArray); |
|
677 } |
|
678 |
|
679 TPtrC elementText = itemText.Left(count); |
|
680 TInt elementWidthInPixels = font->TextWidthInPixels(elementText); |
|
681 |
|
682 // setting a item string to line string |
|
683 lineText.Append(elementText); |
|
684 displayWidthInPixel -= elementWidthInPixels; |
|
685 |
|
686 TPredictivePopupElement& element = elementArray->ExtendL(); |
|
687 element.iStartXPos = elementStartXPos; |
|
688 elementStartXPos += elementWidthInPixels; |
|
689 element.iEndXPos = elementStartXPos; |
|
690 element.iCandidateNo = i; |
|
691 |
|
692 // creating a string which removes a item string |
|
693 itemTextLength -= count; |
|
694 if (itemTextLength > 0) |
|
695 { |
|
696 // If this line is full, add this line and create a new line. |
|
697 PredictivePopupAppendLineL(lineText, elementArray); |
|
698 CleanupStack::Pop(elementArray); // elementArray |
|
699 elementArray = NULL; |
|
700 lineText.SetLength(0); |
|
701 |
|
702 itemText.Set(itemText.Right(itemTextLength)); |
|
703 displayWidthInPixel = aMaxDisplayWidthInPixel; |
|
704 elementStartXPos = 0; |
|
705 |
|
706 // Calculating a number of characters which be able to shown in the width and |
|
707 // cutting the string |
|
708 count = font->TextCount(itemText, displayWidthInPixel); |
|
709 } |
|
710 else |
|
711 { |
|
712 break; |
|
713 } |
|
714 } |
|
715 |
|
716 if (displayWidthInPixel > widthOfSpaceInPixel) |
|
717 { |
|
718 // adding space if it is possible to add space |
|
719 lineText.Append(KSpaceCharCode); |
|
720 displayWidthInPixel -= widthOfSpaceInPixel; |
|
721 elementStartXPos += widthOfSpaceInPixel; |
|
722 } |
|
723 else |
|
724 { |
|
725 // adding a line information if it isn't possible to add space |
|
726 PredictivePopupAppendLineL(lineText, elementArray); |
|
727 CleanupStack::Pop(elementArray); // elementArray |
|
728 elementArray = NULL; |
|
729 lineText.SetLength(0); |
|
730 |
|
731 displayWidthInPixel = aMaxDisplayWidthInPixel - 1; |
|
732 elementStartXPos = 0; |
|
733 } |
|
734 } |
|
735 |
|
736 if (lineText.Length() > 0 && elementArray) |
|
737 { |
|
738 PredictivePopupAppendLineL(lineText, elementArray); |
|
739 CleanupStack::Pop(elementArray); // elementArray |
|
740 } |
|
741 |
|
742 } |
|
743 |
|
744 // ----------------------------------------------------------------------------- |
|
745 // CPeninputJapanesePredictiveWnd::PredictivePopupAppendLineL |
|
746 // Append to array with line information |
|
747 // ----------------------------------------------------------------------------- |
|
748 // |
|
749 void CPeninputJapanesePredictiveWnd::PredictivePopupAppendLineL( |
|
750 const TPtr& aLineText, |
|
751 CPredictivePopupElementArray* aElementArray) |
|
752 { |
|
753 HBufC* lineTextBuf = HBufC::NewL(aLineText.Length()); |
|
754 CleanupStack::PushL(lineTextBuf); |
|
755 TPtr lineTextBufPtr = lineTextBuf->Des(); |
|
756 lineTextBufPtr = aLineText; |
|
757 |
|
758 CPredictivePopupLineInfo* lineInfo = new(ELeave) CPredictivePopupLineInfo; |
|
759 CleanupStack::PushL(lineInfo); |
|
760 iLineInfoArray->AppendL(lineInfo); |
|
761 CleanupStack::Pop(lineInfo); |
|
762 lineInfo->iLineText = lineTextBuf; |
|
763 CleanupStack::Pop(lineTextBuf); |
|
764 lineInfo->iElementsOnLine = aElementArray; |
|
765 } |
|
766 |
|
767 // ----------------------------------------------------------------------------- |
|
768 // CPeninputJapanesePredictiveWnd::CreateListTextArrayL |
|
769 // Create arrary with string to show in a line |
|
770 // ----------------------------------------------------------------------------- |
|
771 // |
|
772 void CPeninputJapanesePredictiveWnd::CreateListTextArrayL(const CPredictivePopupLineInfoArray& aLineArray) |
|
773 { |
|
774 CDesCArrayFlat* textArray = new(ELeave) CDesCArrayFlat(1); |
|
775 CleanupStack::PushL(textArray); |
|
776 |
|
777 const TInt numberOfItem = aLineArray.Count(); |
|
778 TInt i; |
|
779 for (i = 0; i < numberOfItem; i++) |
|
780 { |
|
781 CPredictivePopupLineInfo* lineInfo = aLineArray.At(i); |
|
782 textArray->AppendL(*lineInfo->iLineText); |
|
783 } |
|
784 |
|
785 CleanupStack::Pop(textArray); |
|
786 delete iListTextArray; |
|
787 iListTextArray = NULL; |
|
788 iListTextArray = textArray; |
|
789 } |
|
790 |
|
791 // ----------------------------------------------------------------------------- |
|
792 // CPeninputJapanesePredictiveWnd::Draw |
|
793 // Called by the framework to draw the control |
|
794 // ----------------------------------------------------------------------------- |
|
795 // |
|
796 void CPeninputJapanesePredictiveWnd::Draw() |
|
797 { |
|
798 if(Hiden() || !Ready()) |
|
799 { |
|
800 return; |
|
801 } |
|
802 CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc()); |
|
803 ClearList(); |
|
804 if (iLineInfoArray && iLineInfoArray->Count() > 0) |
|
805 { |
|
806 iListBox->Draw(); |
|
807 if (iScrollUpBtn && iScrollDownBtn && !iScrollUpBtn->IsDimmed()) |
|
808 { |
|
809 iScrollUpBtn->Draw(); |
|
810 iScrollDownBtn->Draw(); |
|
811 } |
|
812 } |
|
813 } |
|
814 |
|
815 // ----------------------------------------------------------------------------- |
|
816 // CPeninputJapanesePredictiveWnd::Clear |
|
817 // (other items were commented in a header). |
|
818 // ----------------------------------------------------------------------------- |
|
819 // |
|
820 void CPeninputJapanesePredictiveWnd::ClearList() |
|
821 { |
|
822 if(Hiden() || !Ready()) |
|
823 { |
|
824 return; |
|
825 } |
|
826 CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc()); |
|
827 gc->Activate( MaskBitmapDevice() ); |
|
828 gc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
829 gc->SetBrushColor( MaskBkCol());//Non transparent at all |
|
830 gc->SetPenSize( PenSize()); |
|
831 gc->SetPenColor( MaskBkCol() ); |
|
832 gc->DrawRect(Rect()); |
|
833 gc->Activate( BitmapDevice() ); |
|
834 |
|
835 MAknsControlContext *cc = AknsDrawUtils::ControlContext( iListBox ); |
|
836 if (cc) |
|
837 { |
|
838 CAknsBasicBackgroundControlContext *bcc = |
|
839 (CAknsBasicBackgroundControlContext*)cc; |
|
840 bcc->SetBitmap(KAknsIIDQsnFrPopupCenter); |
|
841 bcc->SetRect(Rect()); |
|
842 } |
|
843 |
|
844 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
845 |
|
846 TBool skinnedDraw = AknsDrawUtils::DrawFrame( skin, *gc, Rect(), Rect(), |
|
847 KAknsIIDQsnFrPopupCenter,KAknsIIDQsnFrPopupCenter); |
|
848 |
|
849 if (!skinnedDraw) |
|
850 { |
|
851 gc->SetPenStyle(CGraphicsContext::ENullPen); |
|
852 gc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
853 gc->SetBrushColor(AKN_LAF_COLOR(KStatusPaneBackgroundColor)); |
|
854 gc->DrawRect(Rect()); |
|
855 } |
|
856 UpdateArea(iRect,EFalse); |
|
857 } |
|
858 |
|
859 // ----------------------------------------------------------------------------- |
|
860 // CPeninputJapanesePredictiveWnd::ActivateButtons |
|
861 // (other items were commented in a header). |
|
862 // ----------------------------------------------------------------------------- |
|
863 // |
|
864 void CPeninputJapanesePredictiveWnd::ActivateButtons(TBool aActive) const |
|
865 { |
|
866 if (iScrollUpBtn && iScrollDownBtn) |
|
867 { |
|
868 CPeninputLayoutWindowJp* window = static_cast<CPeninputLayoutWindowJp*>(iScrollUpBtn->ParentCtrl()); |
|
869 if (window) |
|
870 { |
|
871 window->ICFDisableRegionUpdating(); // ICF::OnDeActivate() |
|
872 } |
|
873 iScrollUpBtn->SetDimmed(!aActive); |
|
874 iScrollDownBtn->SetDimmed(!aActive); |
|
875 iScrollUpBtn->Hide(!aActive); |
|
876 iScrollDownBtn->Hide(!aActive); |
|
877 window->ICFEnableRegionUpdating(); // ICF::OnActivate() |
|
878 } |
|
879 } |
|
880 // End of File |