|
1 /******************************************************************************* |
|
2 * Copyright (c) 2005, 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. This program and the accompanying materials |
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
|
5 * which accompanies this distribution, and is available at |
|
6 * http://www.eclipse.org/legal/epl-v10.html |
|
7 * |
|
8 * Contributors: |
|
9 * Nokia Corporation - S60 implementation |
|
10 *******************************************************************************/ |
|
11 |
|
12 |
|
13 #ifndef SWTLISTBOX_H |
|
14 #define SWTLISTBOX_H |
|
15 |
|
16 |
|
17 #include <eiklbo.h> |
|
18 #include "eswtmobileextensions.h" |
|
19 #include "swtscrollablebase.h" |
|
20 #include "swtlistboxlists.h" |
|
21 |
|
22 |
|
23 /** |
|
24 * CSwtLbItem |
|
25 * @lib eswt |
|
26 */ |
|
27 NONSHARABLE_CLASS(CSwtLbItem) |
|
28 : public CSwtListBoxItem |
|
29 { |
|
30 // Own methods |
|
31 public: |
|
32 /** |
|
33 * Constructor |
|
34 */ |
|
35 CSwtLbItem(); |
|
36 |
|
37 /** |
|
38 * Constructor |
|
39 */ |
|
40 CSwtLbItem( |
|
41 HBufC* aDtxt, |
|
42 const MSwtImage* aDimg, |
|
43 HBufC* aHtxt, |
|
44 const MSwtImage* aHimg); |
|
45 |
|
46 /** |
|
47 * Constructor |
|
48 */ |
|
49 CSwtLbItem( |
|
50 HBufC* aDtxt, |
|
51 const MSwtImage* aDimg, |
|
52 const TSize& aDimgSize, |
|
53 HBufC* aHtxt, |
|
54 const MSwtImage* aHimg, |
|
55 const TSize& aHimgSize); |
|
56 |
|
57 /** |
|
58 * Destructor |
|
59 */ |
|
60 virtual ~CSwtLbItem(); |
|
61 |
|
62 // Data |
|
63 public: |
|
64 /** |
|
65 * Heading image index |
|
66 */ |
|
67 TInt iHimgIdx; |
|
68 |
|
69 /** |
|
70 * Detail image index |
|
71 */ |
|
72 TInt iDimgIdx; |
|
73 |
|
74 /** |
|
75 * Item index |
|
76 */ |
|
77 TInt iIdx; |
|
78 }; |
|
79 |
|
80 |
|
81 /** Array of List Box Items */ |
|
82 typedef RPointerArray<CSwtLbItem> RSwtLbItems; |
|
83 |
|
84 |
|
85 /** |
|
86 * CSwtListBox |
|
87 * @lib eswt |
|
88 */ |
|
89 NONSHARABLE_CLASS(CSwtListBox) |
|
90 : public CAknControl |
|
91 , public ASwtScrollableBase |
|
92 , public MSwtListBox |
|
93 , public MSwtListObserver |
|
94 , public MEikListBoxObserver |
|
95 { |
|
96 // Types |
|
97 private: |
|
98 /** List box properties */ |
|
99 struct TSwtLbProp |
|
100 { |
|
101 TInt iListType; |
|
102 TInt iSelectionType; |
|
103 TInt iDiconVisible; |
|
104 }; |
|
105 |
|
106 // Own methods |
|
107 public: |
|
108 /** |
|
109 * Two phase constructor |
|
110 * @param aDisplay parent display |
|
111 * @param aPeer java peer of this class |
|
112 * @param aParent composite parent |
|
113 * @param aStyle control style |
|
114 * @return pointer to an object of this class |
|
115 */ |
|
116 static CSwtListBox* NewL(MSwtDisplay& aDisplay, TSwtPeer aPeer, |
|
117 MSwtComposite& aParent, TInt aStyle); |
|
118 |
|
119 protected: |
|
120 /** |
|
121 * First phase constructor. |
|
122 * @param aDisplay parent display |
|
123 * @param aPeer java peer of this class |
|
124 * @param aParent composite parent |
|
125 * @param aStyle control style |
|
126 */ |
|
127 CSwtListBox(MSwtDisplay& aDisplay, TSwtPeer aPeer, |
|
128 MSwtComposite& aParent, TInt aStyle); |
|
129 |
|
130 /** |
|
131 * Destructor |
|
132 */ |
|
133 virtual ~CSwtListBox(); |
|
134 |
|
135 /** |
|
136 * Second phase constructor |
|
137 */ |
|
138 void ConstructL(); |
|
139 |
|
140 // From CCoeControl |
|
141 public: |
|
142 TInt CountComponentControls() const; |
|
143 CCoeControl* ComponentControl(TInt aIdx) const; |
|
144 void MakeVisible(TBool aVisible); |
|
145 void SetDimmed(TBool aDimmed); |
|
146 TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType); |
|
147 void HandleResourceChange(TInt aType); |
|
148 |
|
149 protected: |
|
150 void SizeChanged(); |
|
151 void PositionChanged(); |
|
152 void FocusChanged(TDrawNow aDrawNow); |
|
153 TTypeUid::Ptr MopSupplyObject(TTypeUid aId); |
|
154 |
|
155 private: |
|
156 void Draw(const TRect& aRect) const; |
|
157 |
|
158 // From ASwtControlBase |
|
159 protected: |
|
160 HBufC* MSKLabelL() const; |
|
161 |
|
162 // From ASwtScrollableBase |
|
163 protected: |
|
164 CEikScrollBarFrame* SbFrame() const; |
|
165 |
|
166 // From MSwtControl |
|
167 public: |
|
168 CCoeControl& CoeControl(); |
|
169 const CCoeControl& CoeControl() const; |
|
170 TSize ComputeSizeL(TInt aWhint, TInt aHhint); |
|
171 void ProcessKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType); |
|
172 void HandlePointerEventL(const TPointerEvent& aPointerEvent); |
|
173 TBool IsKeyUsed(TUint aKeyCode) const; |
|
174 TBool MSKSelCmdEnabled() const; |
|
175 TRgb GetForeground() const; |
|
176 void SetForegroundL(const MSwtColor* aColor); |
|
177 void SetBackgroundL(const MSwtColor* aColor); |
|
178 TBool IsLongTapAnimationCandidate(const TPointerEvent& aPointerEvent) const; |
|
179 |
|
180 // From MSwtListBox |
|
181 public: |
|
182 MSwtScrollable* Scrollable(); |
|
183 void SetLayoutStyleL(TInt aLayoutStyle); |
|
184 void DeselectItemsL(const TInt* aIndices, TInt aCount); |
|
185 void DeselectItemL(TInt aIdx); |
|
186 void DeselectRangeL(TInt aStart, TInt aEnd); |
|
187 void DeselectAllL(); |
|
188 TInt GetFocusIndex() const; |
|
189 TInt GetSelectionCount() const; |
|
190 const CArrayFix<TInt>* GetSelectionIndices() const; |
|
191 void RefreshItemL(TInt aIdx, const CSwtListBoxItem* aItem); |
|
192 void RefreshListL(const RSwtListBoxItemsArray& aItemsArray); |
|
193 void SelectItemL(TInt aIdx, TBool aScroll); |
|
194 void SelectRangeL(TInt aStart, TInt aEnd); |
|
195 void SelectAllL(); |
|
196 void SetDataModelL(const RSwtListBoxItemsArray& aItemsArray); |
|
197 void SetHeadingFontL(const MSwtFont* aFont); |
|
198 void ShowSelection(); |
|
199 void SetFocusIndex(TInt aIndex); |
|
200 |
|
201 // From MSwtListObserver |
|
202 public: |
|
203 void HandleSizeChangedL(); |
|
204 MSwtUiUtils& Utils() const; |
|
205 |
|
206 // From MEikScrollBarObserver |
|
207 public: |
|
208 void HandleScrollEventL(CEikScrollBar* aScrollBar, TEikScrollEvent aEventType); |
|
209 |
|
210 // From MEikListBoxObserver |
|
211 public: |
|
212 void HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType); |
|
213 |
|
214 // New methods |
|
215 private: |
|
216 /** |
|
217 * Calculate the listbox properties. |
|
218 * @param aLayoutStyle listbox layout style |
|
219 * @param aStyle control style |
|
220 * @return properties structure |
|
221 */ |
|
222 TSwtLbProp ListProperties(TInt aLayoutStyle, TInt aStyle) const; |
|
223 |
|
224 /** |
|
225 * Create a certain type of list box |
|
226 * @param aListType one of the listbox types defined in SwtListBoxLists.h |
|
227 * @return pointer to the created listbox |
|
228 */ |
|
229 CEikTextListBox* CreateListL(TInt aListType); |
|
230 |
|
231 /** |
|
232 * Create the scrollbars for a listbox. |
|
233 * @param aList listbox pointer |
|
234 */ |
|
235 void CreateScrollBarsL(CEikTextListBox* aList) const; |
|
236 |
|
237 /** |
|
238 * Create a listbox image array. |
|
239 * @param aMultiSelImgs if ETrue adds checkbox icons to the image array. |
|
240 * @return image array |
|
241 */ |
|
242 CArrayPtr<CGulIcon>* CreateListImgArrL(TBool aMultiSelImgs) const; |
|
243 |
|
244 /** |
|
245 * Create a list selection image. |
|
246 * @param aSelected state of the selection image (on/off). |
|
247 * @return pointer to created image. |
|
248 */ |
|
249 CGulIcon* CreateListSelImgL(TBool aSelected) const; |
|
250 |
|
251 /** |
|
252 * Create or update the selection images in the list image array. |
|
253 * @param aImgArr the list image array. |
|
254 */ |
|
255 void CreateListSelImgsL(CArrayPtr<CGulIcon>* aImgArr) const; |
|
256 |
|
257 /** |
|
258 * Insert item into list. |
|
259 * @param aItem item data. |
|
260 */ |
|
261 void InsertListItemL(CSwtLbItem* aItem); |
|
262 |
|
263 /** |
|
264 * Create an image ready to be set to the list's image array. |
|
265 * @param aSwtImg swt image pointer. |
|
266 * @param aDetailIcon are we creating a detail icon or heading icon |
|
267 * @param aBitmapResSize size of the created bitmap is stored here |
|
268 * @return list image pointer. |
|
269 */ |
|
270 CGulIcon* CreateListImgL(const MSwtImage* aSwtImg, const TBool aDetailIcon, |
|
271 TSize& aBitmapResSize) const; |
|
272 |
|
273 /** |
|
274 * Insert a list image into the list (list image array) |
|
275 * @param aImg the image to be inserted. |
|
276 * @return position where the image was inserted. |
|
277 */ |
|
278 TInt InsertListImgL(CGulIcon* aImg); |
|
279 |
|
280 /** |
|
281 * Create a formatted string ready to be set to the list's string array |
|
282 * based on the image indexes and strings of an item. |
|
283 * @param aItem item data. |
|
284 * @return formatted string. |
|
285 */ |
|
286 HBufC* CreateListTxtL(const CSwtLbItem* aItem) const; |
|
287 |
|
288 /** |
|
289 * Insert a formatted item string into the list (list strings array) |
|
290 * @param aTxt the string to be inserted. |
|
291 * @param aIdx position where the string should be inserted. |
|
292 */ |
|
293 void InsertListTxtL(const TDesC& aTxt, TInt aIdx); |
|
294 |
|
295 /** |
|
296 * Remove list item. |
|
297 * @param aIdx index of the item in the item array. |
|
298 */ |
|
299 void DeleteListItem(TInt aIdx); |
|
300 |
|
301 /** |
|
302 * Remove all list items. |
|
303 */ |
|
304 void DeleteAllListItems(); |
|
305 |
|
306 /** |
|
307 * Remove list image. |
|
308 * @param aIdx index of the image in the image array. |
|
309 */ |
|
310 void DeleteListImg(TInt aIdx); |
|
311 |
|
312 /** |
|
313 * Remove list item string. |
|
314 * @param aIdx index of the string in the string array. |
|
315 */ |
|
316 void DeleteListTxt(TInt aIdx); |
|
317 |
|
318 /** |
|
319 * Select one item. |
|
320 * @param aIdx position of the item in the item array |
|
321 * @param aSelected new state of selection |
|
322 */ |
|
323 void SelectListItemL(TInt aIdx, TBool aSelected, TBool aScroll); |
|
324 |
|
325 /** |
|
326 * Select a range of items. |
|
327 * @param aStart first item in range. |
|
328 * @param aEnd last item in range. |
|
329 * @param aSelected new state of selection |
|
330 */ |
|
331 void SelectListItemsL(TInt aStart, TInt aEnd, TBool aSelected); |
|
332 |
|
333 /** |
|
334 * Select all items. |
|
335 * @param aSelected new state of selection |
|
336 */ |
|
337 void SelectListItemsL(TBool aSelected); |
|
338 |
|
339 /** |
|
340 * Get current state of list selection. |
|
341 * @param aCurrSelItems resulting array of selected items. |
|
342 */ |
|
343 void GetUserSelectionL(CArrayFix<TInt>* aCurrSelItems); |
|
344 |
|
345 /** |
|
346 * Set custom foreground color to the list. If the color is invalid, |
|
347 * the default color is set instead. |
|
348 */ |
|
349 void UpdateListColor(); |
|
350 |
|
351 /** |
|
352 * Update MSK. To be called after selection changed. |
|
353 */ |
|
354 void UpdateListMskL(); |
|
355 |
|
356 /** |
|
357 * Minimum width for which an item can display entirely its contents. |
|
358 * Very expensive to call. Goes trough all items and counts the maximum |
|
359 * string lengths. Asumes that the Avkon lists will always use the same |
|
360 * layouts and calculates the width based on these layouts. |
|
361 * @return minimum with for items |
|
362 */ |
|
363 TInt MinimumListItemWidth() const; |
|
364 |
|
365 /** |
|
366 * Removes the tabs in a string and replaces them with spaces. |
|
367 * @param aString string to be processed |
|
368 */ |
|
369 void TabsToSpaces(HBufC* aString) const; |
|
370 |
|
371 /* |
|
372 * Sets maximum icon sizes according to LAF. |
|
373 */ |
|
374 void SetMaximumIconSizes(); |
|
375 |
|
376 /* |
|
377 * Scales list images so that their size does not exceed the maximum |
|
378 * icon size from LAF. |
|
379 * @param aNewMaxDetailSize New maximum detail icon size. |
|
380 * @param aNewMaxHeadingSize New maximum heading icon size. |
|
381 */ |
|
382 void UpdateImageSizes(const TSize& aNewMaxDetailSize, |
|
383 const TSize& aNewMaxHeadingSize); |
|
384 |
|
385 /* |
|
386 * Scale an image so that it's size does not exceed maximum size |
|
387 * @param aImage Source image. |
|
388 * @param aIcon Update scaled image to aIcon. |
|
389 * @param aOldMaxSize Previous maximum size for images. |
|
390 * @param aNewMaxSize New maximum size for images. |
|
391 * @return Scaled size. |
|
392 */ |
|
393 TSize ScaleImage(const MSwtImage* aImage, CGulIcon* aIcon, |
|
394 const TSize& aOldMaxSize, const TSize& aNewMaxSize); |
|
395 |
|
396 /* |
|
397 * Remove sub-references from all images in all items. |
|
398 */ |
|
399 void RemoveSubRefs(); |
|
400 |
|
401 #ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
402 public: |
|
403 void DoControlSpecificFeedback( |
|
404 const TBool& aFirstTap, |
|
405 const TBool& aTappedToChildRect, |
|
406 const TPointerEvent& aPointerEvent) const; |
|
407 #endif //RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
408 |
|
409 // Data |
|
410 private: |
|
411 /** |
|
412 * Contained listbox. |
|
413 * Own |
|
414 */ |
|
415 CEikTextListBox* iList; |
|
416 |
|
417 /** |
|
418 * Cell array of the current list box |
|
419 */ |
|
420 RArray<TInt> iCells; |
|
421 |
|
422 /** |
|
423 * Items array. |
|
424 * Own |
|
425 */ |
|
426 RSwtLbItems iItems; |
|
427 |
|
428 /** |
|
429 * Listbox image array. |
|
430 * Own. |
|
431 */ |
|
432 CArrayPtr<CGulIcon>* iImgs; |
|
433 |
|
434 /** |
|
435 * Listbox string array. |
|
436 * Own. |
|
437 */ |
|
438 CDesCArray* iTxts; |
|
439 |
|
440 /** |
|
441 * Listbox properties. |
|
442 * Own. |
|
443 */ |
|
444 TSwtLbProp iProps; |
|
445 |
|
446 /** |
|
447 * Previously selected items (temporary) |
|
448 * Own |
|
449 */ |
|
450 CArrayFix<TInt>* iPrevSelItems; |
|
451 |
|
452 /** |
|
453 * Foreground color. |
|
454 * Own |
|
455 */ |
|
456 const MSwtColor* iColor; |
|
457 |
|
458 /** |
|
459 * Default foreground color. |
|
460 */ |
|
461 TRgb iDefColor; |
|
462 |
|
463 /** |
|
464 * Used to hide initial flickering. |
|
465 */ |
|
466 TBool iRestoreRedraw; |
|
467 |
|
468 /** |
|
469 * Maximum icon sizes for the current layout. |
|
470 */ |
|
471 TSize iMaxDetailIconSize; |
|
472 TSize iMaxHeadingIconSize; |
|
473 |
|
474 /** |
|
475 * Deliver all pointer event to the scrollbar when this on. |
|
476 */ |
|
477 TBool iVScrollBarGrabsPointerEvents; |
|
478 |
|
479 /** |
|
480 * Stores last known focus index. Use only during paint and key handlers. |
|
481 */ |
|
482 TInt iPrevFocusIndex; |
|
483 |
|
484 /** |
|
485 * View visible rect at last draw |
|
486 */ |
|
487 mutable TRect iLastViewVisibleRect; |
|
488 }; |
|
489 |
|
490 #endif // SWTLISTBOX_H |