|
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 Candidate list view |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "peninputjapanesepredictivelistboxmodel.h" |
|
21 #include "peninputjapanesepredictiveListboxitemdrawer.h" |
|
22 #include "peninputjapanesepredictivelistboxview.h" |
|
23 |
|
24 // ============================ MEMBER FUNCTIONS =============================== |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // CPeninputJapanesePredictiveListBoxView::CurrentCandidateNo |
|
28 // Return the selected candidate number currently |
|
29 // ----------------------------------------------------------------------------- |
|
30 TInt CPeninputJapanesePredictiveListBoxView::CurrentCandidateNo() const |
|
31 { |
|
32 return iCurrentCandidateNo; |
|
33 } |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CPeninputJapanesePredictiveListBoxView::SetCurrentCandidateNo |
|
37 // Set current candidate number |
|
38 // ----------------------------------------------------------------------------- |
|
39 TInt CPeninputJapanesePredictiveListBoxView::SetCurrentCandidateNo( |
|
40 TInt aCandidateNo) |
|
41 { |
|
42 iOldCandidateNo = iCurrentCandidateNo; |
|
43 iCurrentCandidateNo = aCandidateNo; |
|
44 |
|
45 CPeninputJapanesePredictiveListBoxModel* model = |
|
46 static_cast<CPeninputJapanesePredictiveListBoxModel*>(iModel); |
|
47 |
|
48 const TInt itemIndex = model->SearchItemIndexFromCandidateNo(aCandidateNo); |
|
49 |
|
50 return itemIndex; |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CPeninputJapanesePredictiveListBoxView::SetCurrentCandidateNo |
|
55 // Set current candidate number |
|
56 // ----------------------------------------------------------------------------- |
|
57 TInt CPeninputJapanesePredictiveListBoxView::SetCurrentCandidateNo( |
|
58 TInt aLineNo, const TPoint& aPoint) |
|
59 { |
|
60 CPeninputJapanesePredictiveListBoxModel* model = |
|
61 static_cast<CPeninputJapanesePredictiveListBoxModel*>(iModel); |
|
62 |
|
63 iCurrentCandidateNo = model->SearchCandidateNoFromPosition(aLineNo, aPoint); |
|
64 if (iCurrentCandidateNo < 0) // no data |
|
65 { |
|
66 iCurrentCandidateNo = 0; |
|
67 } |
|
68 |
|
69 return aLineNo; |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CPeninputJapanesePredictiveListBoxView::PreviousItem |
|
74 // Return previous candidate number |
|
75 // ----------------------------------------------------------------------------- |
|
76 TInt CPeninputJapanesePredictiveListBoxView::PreviousItem() |
|
77 { |
|
78 CPeninputJapanesePredictiveListBoxModel* model = |
|
79 static_cast<CPeninputJapanesePredictiveListBoxModel*>(iModel); |
|
80 const TInt maximumItems = model->MaximumItems(); |
|
81 |
|
82 TInt itemindex = iCurrentCandidateNo - 1; |
|
83 if (itemindex < 0) |
|
84 { |
|
85 itemindex = maximumItems - 1; |
|
86 } |
|
87 |
|
88 return itemindex; |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CPeninputJapanesePredictiveListBoxView::NextItem |
|
93 // Return next candidate number |
|
94 // ----------------------------------------------------------------------------- |
|
95 TInt CPeninputJapanesePredictiveListBoxView::NextItem() |
|
96 { |
|
97 CPeninputJapanesePredictiveListBoxModel* model = |
|
98 static_cast<CPeninputJapanesePredictiveListBoxModel*>(iModel); |
|
99 const TInt maximumItems = model->MaximumItems(); |
|
100 |
|
101 TInt itemindex = iCurrentCandidateNo +1; |
|
102 if (itemindex >= maximumItems) |
|
103 { |
|
104 itemindex = 0; |
|
105 } |
|
106 |
|
107 return itemindex; |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CPeninputJapanesePredictiveListBoxView::PreviousLineItem |
|
112 // Return candidate number of previous line |
|
113 // ----------------------------------------------------------------------------- |
|
114 TInt CPeninputJapanesePredictiveListBoxView::PreviousLineItem() |
|
115 { |
|
116 TInt currentItemIndex = CurrentItemIndex(); |
|
117 TPredictivePopupElement currentElement; |
|
118 |
|
119 CPeninputJapanesePredictiveListBoxModel* model = |
|
120 static_cast<CPeninputJapanesePredictiveListBoxModel*>(iModel); |
|
121 CPredictivePopupLineInfoArray* lineInfoArray = model->LineInfoArray(); |
|
122 TInt previousCandidateNo = -1; |
|
123 if (lineInfoArray) |
|
124 { |
|
125 const TInt lineInfoArrayCount = lineInfoArray->Count(); |
|
126 |
|
127 TInt previousItemIndex = currentItemIndex; |
|
128 |
|
129 if (model->SearchElement( |
|
130 currentItemIndex, iCurrentCandidateNo, currentElement)) |
|
131 { |
|
132 do |
|
133 { |
|
134 previousItemIndex--; |
|
135 if (previousItemIndex < 0) |
|
136 { |
|
137 previousItemIndex = lineInfoArrayCount - 1; |
|
138 } |
|
139 |
|
140 if (previousItemIndex == currentItemIndex) |
|
141 { |
|
142 break; // in case one loop |
|
143 } |
|
144 |
|
145 CPredictivePopupLineInfo* lineInfo = |
|
146 lineInfoArray->At(previousItemIndex); |
|
147 |
|
148 CPredictivePopupElementArray* elementArray = |
|
149 lineInfo->iElementsOnLine; |
|
150 |
|
151 const TInt numberOfElement = elementArray->Count(); |
|
152 TInt lastCandidateNo = -1; |
|
153 TInt i; |
|
154 for (i = 0; i < numberOfElement; i++) |
|
155 { |
|
156 TPredictivePopupElement element = elementArray->At(i); |
|
157 if (currentElement.iStartXPos >= element.iStartXPos |
|
158 && currentElement.iStartXPos < element.iEndXPos) |
|
159 { |
|
160 previousCandidateNo = element.iCandidateNo; |
|
161 break; |
|
162 } |
|
163 else if (currentElement.iStartXPos < element.iStartXPos) |
|
164 { |
|
165 previousCandidateNo = element.iCandidateNo; |
|
166 break; |
|
167 } |
|
168 |
|
169 lastCandidateNo = element.iCandidateNo; |
|
170 } |
|
171 |
|
172 if (previousCandidateNo == -1) |
|
173 { |
|
174 previousCandidateNo = lastCandidateNo; |
|
175 } |
|
176 } |
|
177 while (previousCandidateNo == iCurrentCandidateNo); |
|
178 } |
|
179 } |
|
180 |
|
181 if (previousCandidateNo == -1) |
|
182 { |
|
183 previousCandidateNo = iCurrentCandidateNo; |
|
184 } |
|
185 |
|
186 return previousCandidateNo; |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CPeninputJapanesePredictiveListBoxView::NextLineItem |
|
191 // Return candidate number of next line |
|
192 // ----------------------------------------------------------------------------- |
|
193 TInt CPeninputJapanesePredictiveListBoxView::NextLineItem() |
|
194 { |
|
195 TInt currentItemIndex = CurrentItemIndex(); |
|
196 TPredictivePopupElement currentElement; |
|
197 |
|
198 CPeninputJapanesePredictiveListBoxModel* model = |
|
199 static_cast<CPeninputJapanesePredictiveListBoxModel*>(iModel); |
|
200 |
|
201 CPredictivePopupLineInfoArray* lineInfoArray = model->LineInfoArray(); |
|
202 TInt nextCandidateNo = -1; |
|
203 |
|
204 if (lineInfoArray) |
|
205 { |
|
206 const TInt lineInfoArrayCount = lineInfoArray->Count(); |
|
207 |
|
208 TInt nextItemIndex = currentItemIndex; |
|
209 |
|
210 if (model->SearchElement( |
|
211 currentItemIndex, iCurrentCandidateNo, currentElement)) |
|
212 { |
|
213 do |
|
214 { |
|
215 nextItemIndex++; |
|
216 if (nextItemIndex >= lineInfoArrayCount) |
|
217 { |
|
218 nextItemIndex = 0; |
|
219 } |
|
220 |
|
221 if (nextItemIndex == currentItemIndex) |
|
222 { |
|
223 break; // in case one loop |
|
224 } |
|
225 |
|
226 CPredictivePopupLineInfo* lineInfo = |
|
227 lineInfoArray->At(nextItemIndex); |
|
228 |
|
229 CPredictivePopupElementArray* elementArray = |
|
230 lineInfo->iElementsOnLine; |
|
231 |
|
232 const TInt numberOfElement = elementArray->Count(); |
|
233 TInt lastCandidateNo = -1; |
|
234 TInt i; |
|
235 for (i = 0; i < numberOfElement; i++) |
|
236 { |
|
237 TPredictivePopupElement element = elementArray->At(i); |
|
238 if (currentElement.iStartXPos >= element.iStartXPos |
|
239 && currentElement.iStartXPos < element.iEndXPos) |
|
240 { |
|
241 nextCandidateNo = element.iCandidateNo; |
|
242 break; |
|
243 } |
|
244 else if (currentElement.iStartXPos < element.iStartXPos) |
|
245 { |
|
246 nextCandidateNo = element.iCandidateNo; |
|
247 break; |
|
248 } |
|
249 |
|
250 lastCandidateNo = element.iCandidateNo; |
|
251 } |
|
252 |
|
253 if (nextCandidateNo == -1) |
|
254 { |
|
255 nextCandidateNo = lastCandidateNo; |
|
256 } |
|
257 } |
|
258 while (nextCandidateNo == iCurrentCandidateNo); |
|
259 } |
|
260 } |
|
261 if (nextCandidateNo == -1) |
|
262 { |
|
263 nextCandidateNo = iCurrentCandidateNo; |
|
264 } |
|
265 return nextCandidateNo; |
|
266 } |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // CPeninputJapanesePredictiveListBoxView::OldCandidateNo |
|
270 // Return the selected candidate number previously |
|
271 // ----------------------------------------------------------------------------- |
|
272 TInt CPeninputJapanesePredictiveListBoxView::OldCandidateNo() const |
|
273 { |
|
274 return iOldCandidateNo; |
|
275 } |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CPeninputJapanesePredictiveListBoxView::DrawItem |
|
279 // Drawing item |
|
280 // ----------------------------------------------------------------------------- |
|
281 void CPeninputJapanesePredictiveListBoxView::DrawItem(TInt aItemIndex) const |
|
282 { |
|
283 if (RedrawDisabled() || !IsVisible()) |
|
284 return; |
|
285 |
|
286 CPeninputJapanesePredictiveListBoxModel* model = |
|
287 static_cast<CPeninputJapanesePredictiveListBoxModel*>(iModel); |
|
288 |
|
289 if (model->LineInfoArray()) |
|
290 { |
|
291 if (((aItemIndex > -1) && (aItemIndex < model->LineInfoArray()->Count())) |
|
292 && ItemIsVisible(aItemIndex)) |
|
293 { |
|
294 TInt highlightStartXPos = 0; |
|
295 TInt highlightEndXPos = 0; |
|
296 |
|
297 TPredictivePopupElement currentElement; |
|
298 |
|
299 if (model->SearchElement(aItemIndex, |
|
300 iCurrentCandidateNo, currentElement)) |
|
301 { |
|
302 highlightStartXPos = currentElement.iStartXPos; |
|
303 highlightEndXPos = currentElement.iEndXPos; |
|
304 } |
|
305 |
|
306 CPeninputJapanesePredictiveListBoxItemDrawer* itemDrawer = |
|
307 static_cast<CPeninputJapanesePredictiveListBoxItemDrawer*>(iItemDrawer); |
|
308 |
|
309 itemDrawer->DrawItem( |
|
310 aItemIndex, |
|
311 ItemPos(aItemIndex), |
|
312 ItemIsSelected(aItemIndex), |
|
313 (aItemIndex == iCurrentItemIndex), |
|
314 (iFlags & EEmphasized) > 0, (iFlags & EDimmed) > 0, |
|
315 highlightStartXPos, highlightEndXPos); |
|
316 } |
|
317 } |
|
318 } |
|
319 |
|
320 // End of File |