|
1 /* |
|
2 * Copyright (c) 2002-2007 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 candidate list |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <aknlayoutscalable_avkon.cdl.h> |
|
21 |
|
22 #include "peninputeventjp.h" |
|
23 #include "peninputjapanesepredictivelistboxview.h" |
|
24 #include "peninputjapanesepredictiveListboxitemdrawer.h" |
|
25 #include "peninputjapanesepredictivecelllistboxdata.h" |
|
26 #include "peninputjapanesepredictivelistboxmodel.h" |
|
27 #include "peninputjapanesepredictivelistbox.h" |
|
28 #include "peninputjapanesepredictivewnd.h" |
|
29 |
|
30 // CONSTANTS |
|
31 const TInt KScrollRightMarge = 5; |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CPeninputJapanesePredictiveListBox::ConstructL |
|
37 // Symbian 2nd phase constructor can leave. |
|
38 // ----------------------------------------------------------------------------- |
|
39 void CPeninputJapanesePredictiveListBox::ConstructL( |
|
40 const CCoeControl* aParent, |
|
41 TInt aFlags) |
|
42 { |
|
43 CAknFilteredTextListBoxModel* model = |
|
44 new(ELeave) CPeninputJapanesePredictiveListBoxModel; |
|
45 iModel=model; |
|
46 model->ConstructL(); |
|
47 CreateItemDrawerL(); |
|
48 |
|
49 EnableExtendedDrawingL(); |
|
50 |
|
51 iItemDrawer->SetDrawMark(EFalse); |
|
52 CEikListBox::ConstructL(aParent,aFlags); |
|
53 iLineCount = KPENINPUT_LAYOUT_PREDICTIONPANE_ROW_COUNT; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CPeninputJapanesePredictiveListBox::SetCurrentCandidateNo |
|
58 // Selecting a candidate number appointed with an argument |
|
59 // ----------------------------------------------------------------------------- |
|
60 void CPeninputJapanesePredictiveListBox::SetCurrentCandidateNo( |
|
61 TInt aCandidateNo, TBool aDraw) const |
|
62 { |
|
63 CPeninputJapanesePredictiveListBoxView* view = |
|
64 static_cast<CPeninputJapanesePredictiveListBoxView*>(View()); |
|
65 TInt itemIndex = view->SetCurrentCandidateNo(aCandidateNo); |
|
66 if (itemIndex >= 0) |
|
67 { |
|
68 if (aDraw) |
|
69 { |
|
70 SetCurrentItemIndexAndDraw(itemIndex); |
|
71 } |
|
72 else |
|
73 { |
|
74 SetCurrentItemIndex(itemIndex); |
|
75 } |
|
76 } |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CPeninputJapanesePredictiveListBox::SetCurrentCandidateNo |
|
81 // Selecting a candidate number appointed with an argument |
|
82 // ----------------------------------------------------------------------------- |
|
83 void CPeninputJapanesePredictiveListBox::SetCurrentCandidateNo( |
|
84 TInt aLineNo, const TPoint& aPoint, TBool aDraw) const |
|
85 { |
|
86 CPeninputJapanesePredictiveListBoxView* view = |
|
87 static_cast<CPeninputJapanesePredictiveListBoxView*>(View()); |
|
88 TInt itemIndex = view->SetCurrentCandidateNo(aLineNo, aPoint); |
|
89 |
|
90 if (aDraw) |
|
91 { |
|
92 SetCurrentItemIndexAndDraw(itemIndex); |
|
93 } |
|
94 else |
|
95 { |
|
96 SetCurrentItemIndex(itemIndex); |
|
97 } |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CPeninputJapanesePredictiveListBox::CurrentCandidateNo |
|
102 // Returning a selected number |
|
103 // ----------------------------------------------------------------------------- |
|
104 TInt CPeninputJapanesePredictiveListBox::CurrentCandidateNo() const |
|
105 { |
|
106 CPeninputJapanesePredictiveListBoxView* view = |
|
107 static_cast<CPeninputJapanesePredictiveListBoxView*>(View()); |
|
108 return view->CurrentCandidateNo(); |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CPeninputJapanesePredictiveListBox::MovePreviousItem |
|
113 // selecting a previous candidate |
|
114 // ----------------------------------------------------------------------------- |
|
115 TInt CPeninputJapanesePredictiveListBox::MovePreviousItem() const |
|
116 { |
|
117 CPeninputJapanesePredictiveListBoxView* view = |
|
118 static_cast<CPeninputJapanesePredictiveListBoxView*>(View()); |
|
119 |
|
120 TInt candidateNo = view->PreviousItem(); |
|
121 SetCurrentCandidateNo(candidateNo, ETrue); |
|
122 |
|
123 return candidateNo; |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CPeninputJapanesePredictiveListBox::MoveNextItem |
|
128 // selecting a next candidate |
|
129 // ----------------------------------------------------------------------------- |
|
130 TInt CPeninputJapanesePredictiveListBox::MoveNextItem() const |
|
131 { |
|
132 CPeninputJapanesePredictiveListBoxView* view = |
|
133 static_cast<CPeninputJapanesePredictiveListBoxView*>(View()); |
|
134 |
|
135 TInt candidateNo = view->NextItem(); |
|
136 SetCurrentCandidateNo(candidateNo, ETrue); |
|
137 |
|
138 return candidateNo; |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CPeninputJapanesePredictiveListBox::MovePreviousLineItem |
|
143 // selecting a previous line candidate |
|
144 // ----------------------------------------------------------------------------- |
|
145 TInt CPeninputJapanesePredictiveListBox::MovePreviousLineItem() const |
|
146 { |
|
147 CPeninputJapanesePredictiveListBoxView* view = |
|
148 static_cast<CPeninputJapanesePredictiveListBoxView*>(View()); |
|
149 TInt candidateNo = view->PreviousLineItem(); |
|
150 SetCurrentCandidateNo(candidateNo, ETrue); |
|
151 |
|
152 return candidateNo; |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CPeninputJapanesePredictiveListBox::MoveNextLineItem |
|
157 // selecting a next line candidate |
|
158 // ----------------------------------------------------------------------------- |
|
159 TInt CPeninputJapanesePredictiveListBox::MoveNextLineItem() const |
|
160 { |
|
161 CPeninputJapanesePredictiveListBoxView* view = |
|
162 static_cast<CPeninputJapanesePredictiveListBoxView*>(View()); |
|
163 TInt candidateNo = view->NextLineItem(); |
|
164 SetCurrentCandidateNo(candidateNo, ETrue); |
|
165 |
|
166 return candidateNo; |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CPeninputJapanesePredictiveListBox::HandlePointerEventL |
|
171 // (other items were commented in a header). |
|
172 // ----------------------------------------------------------------------------- |
|
173 void CPeninputJapanesePredictiveListBox::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
174 { |
|
175 CAknSinglePopupMenuStyleListBox::HandlePointerEventL(aPointerEvent); |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CPeninputJapanesePredictiveListBox::Draw |
|
180 // (other items were commented in a header). |
|
181 // ----------------------------------------------------------------------------- |
|
182 void CPeninputJapanesePredictiveListBox::Draw() const |
|
183 { |
|
184 CWindowGc* gcSave = CCoeEnv::Static()->SwapSystemGc(ItemDrawer()->Gc()); |
|
185 DrawNow(); |
|
186 CCoeEnv::Static()->SwapSystemGc(gcSave); |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CPeninputJapanesePredictiveListBox::SetLineCount |
|
191 // (other items were commented in a header). |
|
192 // ----------------------------------------------------------------------------- |
|
193 void CPeninputJapanesePredictiveListBox::SetLineCount(TInt aLineCount) |
|
194 { |
|
195 iLineCount = aLineCount; |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CPeninputJapanesePredictiveListBox::SizeChanged |
|
200 // This function is called in case changing size |
|
201 // ----------------------------------------------------------------------------- |
|
202 void CPeninputJapanesePredictiveListBox::SizeChanged() |
|
203 { |
|
204 CEikFormattedCellListBox& listBox = *this; |
|
205 CFormattedCellListBoxItemDrawer* itemDrawer = listBox.ItemDrawer(); |
|
206 |
|
207 TAknWindowLineLayout textWindowLayout = |
|
208 AknLayoutScalable_Avkon::list_single_choice_list_pane(0).LayoutLine(); |
|
209 |
|
210 TAknTextLineLayout textLineLayout = |
|
211 AknLayoutScalable_Avkon::fep_vkb_top_text_pane_t1().LayoutLine(); |
|
212 const CFont* font = AknLayoutUtils::FontFromId(textLineLayout.iFont, NULL); |
|
213 textWindowLayout.iH = Rect().Size().iHeight/2; // control itemheight |
|
214 |
|
215 AknListBoxLayouts::SetupStandardListBox(listBox); // SetBorder(TGulBorder::ENone) |
|
216 AknListBoxLayouts::SetupStandardFormListbox(itemDrawer); // Set Standard Colors |
|
217 AknListBoxLayouts::SetupListboxPos(listBox, textWindowLayout); // ItemDrawer()->SetItemCellSize() |
|
218 { |
|
219 TRgb color( KRgbBlack ); |
|
220 // this does not modify color unless it gets a correct one |
|
221 // no real need to check errors |
|
222 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), |
|
223 color, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG10 ); |
|
224 itemDrawer->SetHighlightedTextColor( color ); |
|
225 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), |
|
226 color, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG7 ); |
|
227 iItemDrawer->SetTextColor( color ); |
|
228 } |
|
229 |
|
230 TSize itemSize = View()->ItemSize(); |
|
231 |
|
232 // setting textbox size in listbox |
|
233 TInt baseline = itemSize.iHeight/2 + font->AscentInPixels() / 2; |
|
234 textLineLayout.iB = ELayoutP - baseline; // control itemheight |
|
235 |
|
236 AknListBoxLayouts::SetupFormAntiFlickerTextCell(listBox, itemDrawer, 0, |
|
237 textLineLayout, |
|
238 TPoint(0, 0), |
|
239 TPoint(itemSize.iWidth, itemSize.iHeight)); |
|
240 |
|
241 CEikFormattedCellListBox::SizeChanged(); |
|
242 |
|
243 // Scroll bar |
|
244 TAknWindowLineLayout scrollLineLayout = AknLayoutScalable_Avkon::scroll_pane_cp30().LayoutLine(); |
|
245 scrollLineLayout.il = ELayoutEmpty; |
|
246 scrollLineLayout.ir = KScrollRightMarge; |
|
247 scrollLineLayout.it = 0; |
|
248 scrollLineLayout.ib = 0; |
|
249 TRect scrollBarParent = TRect(TPoint(listBox.Rect().iTl), |
|
250 TSize(listBox.Rect().Width() + scrollLineLayout.iW + scrollLineLayout.ir, |
|
251 listBox.Rect().Height())); |
|
252 AknLayoutUtils::LayoutVerticalScrollBar(iSBFrame, scrollBarParent, scrollLineLayout); |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CPeninputJapanesePredictiveListBox::MakeViewClassInstanceL |
|
257 // Creating a view |
|
258 // ----------------------------------------------------------------------------- |
|
259 CListBoxView* CPeninputJapanesePredictiveListBox::MakeViewClassInstanceL() |
|
260 { |
|
261 return new(ELeave) CPeninputJapanesePredictiveListBoxView; |
|
262 } |
|
263 |
|
264 void CPeninputJapanesePredictiveListBox::HandleScrollEventL(CEikScrollBar* aScrollBar,TEikScrollEvent aEventType) |
|
265 { |
|
266 TInt oldThumbPos = (aEventType & KEikScrollEventBarMask) ? iView->HScrollOffset() : iView->TopItemIndex(); |
|
267 TInt newThumbPos = oldThumbPos; |
|
268 TInt maxThumbPos = static_cast<CTextListBoxModel*>(Model())->NumberOfItems() - iLineCount; |
|
269 |
|
270 switch (aEventType & KEikScrollEventBarMask) |
|
271 { |
|
272 case KEikScrollEventFromVBar: |
|
273 switch (aEventType) |
|
274 { |
|
275 case EEikScrollUp: |
|
276 if (newThumbPos > 0) |
|
277 { |
|
278 -- newThumbPos; |
|
279 } |
|
280 if ( oldThumbPos == 0 && (iListBoxFlags & ELoopScrolling)) |
|
281 { |
|
282 newThumbPos = maxThumbPos; |
|
283 } |
|
284 break; |
|
285 case EEikScrollDown: |
|
286 if (newThumbPos < maxThumbPos) |
|
287 { |
|
288 ++ newThumbPos; |
|
289 } |
|
290 if ( oldThumbPos == maxThumbPos && (iListBoxFlags & ELoopScrolling) ) |
|
291 { |
|
292 newThumbPos = 0; |
|
293 } |
|
294 break; |
|
295 |
|
296 default: |
|
297 break; |
|
298 } |
|
299 |
|
300 if ( newThumbPos != oldThumbPos ) |
|
301 { |
|
302 iView->VScrollTo(newThumbPos); |
|
303 aScrollBar->SetModelThumbPosition(iView->TopItemIndex()); |
|
304 UpdateScrollBarThumbs(); |
|
305 } |
|
306 break; |
|
307 default: |
|
308 break; |
|
309 } |
|
310 } |
|
311 |
|
312 // ----------------------------------------------------------------------------- |
|
313 // CPeninputJapanesePredictiveListBox::CreateItemDrawerL |
|
314 // Creating a ItemDrawer |
|
315 // ----------------------------------------------------------------------------- |
|
316 void CPeninputJapanesePredictiveListBox::CreateItemDrawerL() |
|
317 { |
|
318 CPeninputJapanesePredictiveCellListBoxData* |
|
319 cellData = CPeninputJapanesePredictiveCellListBoxData::NewL(); |
|
320 CleanupStack::PushL(cellData); |
|
321 |
|
322 iItemDrawer = |
|
323 new(ELeave) CPeninputJapanesePredictiveListBoxItemDrawer( |
|
324 Model(), NULL, cellData); |
|
325 |
|
326 CleanupStack::Pop(cellData); // cellData |
|
327 } |
|
328 |
|
329 // ----------------------------------------------------------------------------- |
|
330 // CPeninputJapanesePredictiveListBox::UpdateCurrentItem |
|
331 // Update the current index |
|
332 // Notes: The argument of aItemIndex means the current line. (not current candidate index) |
|
333 // ----------------------------------------------------------------------------- |
|
334 void CPeninputJapanesePredictiveListBox::UpdateCurrentItem(TInt aItemIndex) const |
|
335 { |
|
336 CPeninputJapanesePredictiveListBoxModel* model = |
|
337 static_cast<CPeninputJapanesePredictiveListBoxModel*>(Model()); |
|
338 CPeninputJapanesePredictiveListBoxView* view = |
|
339 static_cast<CPeninputJapanesePredictiveListBoxView*>(View()); |
|
340 |
|
341 if (!model->LineInfoArray()) |
|
342 { |
|
343 return; |
|
344 } |
|
345 TPredictivePopupElement element; |
|
346 TInt curCandi = view->CurrentCandidateNo(); |
|
347 TInt oldCandi = view->OldCandidateNo(); |
|
348 TInt maxLine = model->LineInfoArray()->Count(); |
|
349 |
|
350 TInt oldCurrentItemIndex = view->CurrentItemIndex(); |
|
351 if (oldCurrentItemIndex != aItemIndex) |
|
352 { |
|
353 // Set the current line |
|
354 view->SetCurrentItemIndex(aItemIndex); |
|
355 |
|
356 if ( IsReadyToDraw() ) |
|
357 { |
|
358 // Draw the old line |
|
359 view->DrawItem(oldCurrentItemIndex); |
|
360 } |
|
361 |
|
362 if (oldCurrentItemIndex+1 < maxLine |
|
363 && oldCurrentItemIndex+1 != aItemIndex) |
|
364 { |
|
365 if (model->SearchElement(oldCurrentItemIndex+1, |
|
366 oldCandi, element)) |
|
367 { |
|
368 view->DrawItem(oldCurrentItemIndex+1); |
|
369 } |
|
370 } |
|
371 // Set the top position |
|
372 if (!(view->ItemIsVisible(aItemIndex))) |
|
373 { |
|
374 SetTopItemIndex(view->CalcNewTopItemIndexSoItemIsVisible(aItemIndex)); |
|
375 DrawNow(); |
|
376 } |
|
377 } |
|
378 // Draw the current line |
|
379 DrawItem(aItemIndex); |
|
380 // Check next line including the same candidate |
|
381 TInt nextLine = aItemIndex+1; |
|
382 if (nextLine < maxLine |
|
383 && model->SearchElement(nextLine, curCandi, element)) |
|
384 { |
|
385 if (!(view->ItemIsVisible(nextLine))) |
|
386 { |
|
387 SetTopItemIndex(view->CalcNewTopItemIndexSoItemIsVisible(nextLine)); |
|
388 DrawNow(); |
|
389 } |
|
390 DrawItem(nextLine); |
|
391 } |
|
392 UpdateScrollBarThumbs(); |
|
393 } |
|
394 |
|
395 // End of File |