66
|
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 |
#ifdef RD_JAVA_S60_RELEASE_9_2
|
|
180 |
void EnableFocusHighlight(TBool aEnable);
|
|
181 |
#endif //RD_JAVA_S60_RELEASE_9_2
|
|
182 |
TInt FocusBackgroundPolicy() const;
|
|
183 |
|
|
184 |
// From MSwtListBox
|
|
185 |
public:
|
|
186 |
MSwtScrollable* Scrollable();
|
|
187 |
void SetLayoutStyleL(TInt aLayoutStyle);
|
|
188 |
void DeselectItemsL(const TInt* aIndices, TInt aCount);
|
|
189 |
void DeselectItemL(TInt aIdx);
|
|
190 |
void DeselectRangeL(TInt aStart, TInt aEnd);
|
|
191 |
void DeselectAllL();
|
|
192 |
TInt GetFocusIndex() const;
|
|
193 |
TInt GetSelectionCount() const;
|
|
194 |
const CArrayFix<TInt>* GetSelectionIndices() const;
|
|
195 |
void RefreshItemL(TInt aIdx, const CSwtListBoxItem* aItem);
|
|
196 |
void RefreshListL(const RSwtListBoxItemsArray& aItemsArray);
|
|
197 |
void SelectItemL(TInt aIdx, TBool aScroll);
|
|
198 |
void SelectRangeL(TInt aStart, TInt aEnd);
|
|
199 |
void SelectAllL();
|
|
200 |
void SetDataModelL(const RSwtListBoxItemsArray& aItemsArray);
|
|
201 |
void SetHeadingFontL(const MSwtFont* aFont);
|
|
202 |
void ShowSelection();
|
|
203 |
void SetFocusIndex(TInt aIndex);
|
|
204 |
|
|
205 |
// From MSwtListObserver
|
|
206 |
public:
|
|
207 |
void HandleSizeChangedL();
|
|
208 |
MSwtUiUtils& Utils() const;
|
|
209 |
|
|
210 |
// From MEikScrollBarObserver
|
|
211 |
public:
|
|
212 |
void HandleScrollEventL(CEikScrollBar* aScrollBar, TEikScrollEvent aEventType);
|
|
213 |
|
|
214 |
// From MEikListBoxObserver
|
|
215 |
public:
|
|
216 |
void HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType);
|
|
217 |
|
|
218 |
// New methods
|
|
219 |
private:
|
|
220 |
/**
|
|
221 |
* Calculate the listbox properties.
|
|
222 |
* @param aLayoutStyle listbox layout style
|
|
223 |
* @param aStyle control style
|
|
224 |
* @return properties structure
|
|
225 |
*/
|
|
226 |
TSwtLbProp ListProperties(TInt aLayoutStyle, TInt aStyle) const;
|
|
227 |
|
|
228 |
/**
|
|
229 |
* Create a certain type of list box
|
|
230 |
* @param aListType one of the listbox types defined in SwtListBoxLists.h
|
|
231 |
* @return pointer to the created listbox
|
|
232 |
*/
|
|
233 |
CEikTextListBox* CreateListL(TInt aListType);
|
|
234 |
|
|
235 |
/**
|
|
236 |
* Create the scrollbars for a listbox.
|
|
237 |
* @param aList listbox pointer
|
|
238 |
*/
|
|
239 |
void CreateScrollBarsL(CEikTextListBox* aList) const;
|
|
240 |
|
|
241 |
/**
|
|
242 |
* Create a listbox image array.
|
|
243 |
* @param aMultiSelImgs if ETrue adds checkbox icons to the image array.
|
|
244 |
* @return image array
|
|
245 |
*/
|
|
246 |
CArrayPtr<CGulIcon>* CreateListImgArrL(TBool aMultiSelImgs) const;
|
|
247 |
|
|
248 |
/**
|
|
249 |
* Create a list selection image.
|
|
250 |
* @param aSelected state of the selection image (on/off).
|
|
251 |
* @return pointer to created image.
|
|
252 |
*/
|
|
253 |
CGulIcon* CreateListSelImgL(TBool aSelected) const;
|
|
254 |
|
|
255 |
/**
|
|
256 |
* Create or update the selection images in the list image array.
|
|
257 |
* @param aImgArr the list image array.
|
|
258 |
*/
|
|
259 |
void CreateListSelImgsL(CArrayPtr<CGulIcon>* aImgArr) const;
|
|
260 |
|
|
261 |
/**
|
|
262 |
* Insert item into list.
|
|
263 |
* @param aItem item data.
|
|
264 |
*/
|
|
265 |
void InsertListItemL(CSwtLbItem* aItem);
|
|
266 |
|
|
267 |
/**
|
|
268 |
* Create an image ready to be set to the list's image array.
|
|
269 |
* @param aSwtImg swt image pointer.
|
|
270 |
* @param aDetailIcon are we creating a detail icon or heading icon
|
|
271 |
* @param aBitmapResSize size of the created bitmap is stored here
|
|
272 |
* @return list image pointer.
|
|
273 |
*/
|
|
274 |
CGulIcon* CreateListImgL(const MSwtImage* aSwtImg, const TBool aDetailIcon,
|
|
275 |
TSize& aBitmapResSize) const;
|
|
276 |
|
|
277 |
/**
|
|
278 |
* Insert a list image into the list (list image array)
|
|
279 |
* @param aImg the image to be inserted.
|
|
280 |
* @return position where the image was inserted.
|
|
281 |
*/
|
|
282 |
TInt InsertListImgL(CGulIcon* aImg);
|
|
283 |
|
|
284 |
/**
|
|
285 |
* Create a formatted string ready to be set to the list's string array
|
|
286 |
* based on the image indexes and strings of an item.
|
|
287 |
* @param aItem item data.
|
|
288 |
* @return formatted string.
|
|
289 |
*/
|
|
290 |
HBufC* CreateListTxtL(const CSwtLbItem* aItem) const;
|
|
291 |
|
|
292 |
/**
|
|
293 |
* Insert a formatted item string into the list (list strings array)
|
|
294 |
* @param aTxt the string to be inserted.
|
|
295 |
* @param aIdx position where the string should be inserted.
|
|
296 |
*/
|
|
297 |
void InsertListTxtL(const TDesC& aTxt, TInt aIdx);
|
|
298 |
|
|
299 |
/**
|
|
300 |
* Remove list item.
|
|
301 |
* @param aIdx index of the item in the item array.
|
|
302 |
*/
|
|
303 |
void DeleteListItem(TInt aIdx);
|
|
304 |
|
|
305 |
/**
|
|
306 |
* Remove all list items.
|
|
307 |
*/
|
|
308 |
void DeleteAllListItems();
|
|
309 |
|
|
310 |
/**
|
|
311 |
* Remove list image.
|
|
312 |
* @param aIdx index of the image in the image array.
|
|
313 |
*/
|
|
314 |
void DeleteListImg(TInt aIdx);
|
|
315 |
|
|
316 |
/**
|
|
317 |
* Remove list item string.
|
|
318 |
* @param aIdx index of the string in the string array.
|
|
319 |
*/
|
|
320 |
void DeleteListTxt(TInt aIdx);
|
|
321 |
|
|
322 |
/**
|
|
323 |
* Select one item.
|
|
324 |
* @param aIdx position of the item in the item array
|
|
325 |
* @param aSelected new state of selection
|
|
326 |
*/
|
|
327 |
void SelectListItemL(TInt aIdx, TBool aSelected, TBool aScroll);
|
|
328 |
|
|
329 |
/**
|
|
330 |
* Select a range of items.
|
|
331 |
* @param aStart first item in range.
|
|
332 |
* @param aEnd last item in range.
|
|
333 |
* @param aSelected new state of selection
|
|
334 |
*/
|
|
335 |
void SelectListItemsL(TInt aStart, TInt aEnd, TBool aSelected);
|
|
336 |
|
|
337 |
/**
|
|
338 |
* Select all items.
|
|
339 |
* @param aSelected new state of selection
|
|
340 |
*/
|
|
341 |
void SelectListItemsL(TBool aSelected);
|
|
342 |
|
|
343 |
/**
|
|
344 |
* Get current state of list selection.
|
|
345 |
* @param aCurrSelItems resulting array of selected items.
|
|
346 |
*/
|
|
347 |
void GetUserSelectionL(CArrayFix<TInt>* aCurrSelItems);
|
|
348 |
|
|
349 |
/**
|
|
350 |
* Set custom foreground color to the list. If the color is invalid,
|
|
351 |
* the default color is set instead.
|
|
352 |
*/
|
|
353 |
void UpdateListColor();
|
|
354 |
|
|
355 |
/**
|
|
356 |
* Update MSK. To be called after selection changed.
|
|
357 |
*/
|
|
358 |
void UpdateListMskL();
|
|
359 |
|
|
360 |
/**
|
|
361 |
* Minimum width for which an item can display entirely its contents.
|
|
362 |
* Very expensive to call. Goes trough all items and counts the maximum
|
|
363 |
* string lengths. Asumes that the Avkon lists will always use the same
|
|
364 |
* layouts and calculates the width based on these layouts.
|
|
365 |
* @return minimum with for items
|
|
366 |
*/
|
|
367 |
TInt MinimumListItemWidth() const;
|
|
368 |
|
|
369 |
/**
|
|
370 |
* Removes the tabs in a string and replaces them with spaces.
|
|
371 |
* @param aString string to be processed
|
|
372 |
*/
|
|
373 |
void TabsToSpaces(HBufC* aString) const;
|
|
374 |
|
|
375 |
/*
|
|
376 |
* Sets maximum icon sizes according to LAF.
|
|
377 |
*/
|
|
378 |
void SetMaximumIconSizes();
|
|
379 |
|
|
380 |
/*
|
|
381 |
* Scales list images so that their size does not exceed the maximum
|
|
382 |
* icon size from LAF.
|
|
383 |
* @param aNewMaxDetailSize New maximum detail icon size.
|
|
384 |
* @param aNewMaxHeadingSize New maximum heading icon size.
|
|
385 |
*/
|
|
386 |
void UpdateImageSizes(const TSize& aNewMaxDetailSize,
|
|
387 |
const TSize& aNewMaxHeadingSize);
|
|
388 |
|
|
389 |
/*
|
|
390 |
* Scale an image so that it's size does not exceed maximum size
|
|
391 |
* @param aImage Source image.
|
|
392 |
* @param aIcon Update scaled image to aIcon.
|
|
393 |
* @param aOldMaxSize Previous maximum size for images.
|
|
394 |
* @param aNewMaxSize New maximum size for images.
|
|
395 |
* @return Scaled size.
|
|
396 |
*/
|
|
397 |
TSize ScaleImage(const MSwtImage* aImage, CGulIcon* aIcon,
|
|
398 |
const TSize& aOldMaxSize, const TSize& aNewMaxSize);
|
|
399 |
|
|
400 |
/*
|
|
401 |
* Remove sub-references from all images in all items.
|
|
402 |
*/
|
|
403 |
void RemoveSubRefs();
|
|
404 |
|
|
405 |
/**
|
|
406 |
* Updates flick scrolling status.
|
|
407 |
* @param aEventType CEikListbox event type.
|
|
408 |
*/
|
|
409 |
void UpdateFlickScrollingState(TListBoxEvent aEventType);
|
|
410 |
|
|
411 |
#ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK
|
|
412 |
public:
|
|
413 |
void DoControlSpecificFeedback(
|
|
414 |
const TBool& aFirstTap,
|
|
415 |
const TBool& aTappedToChildRect,
|
|
416 |
const TPointerEvent& aPointerEvent) const;
|
|
417 |
#endif //RD_JAVA_ADVANCED_TACTILE_FEEDBACK
|
|
418 |
|
|
419 |
// Data
|
|
420 |
private:
|
|
421 |
/**
|
|
422 |
* Contained listbox.
|
|
423 |
* Own
|
|
424 |
*/
|
|
425 |
CEikTextListBox* iList;
|
|
426 |
|
|
427 |
/**
|
|
428 |
* Cell array of the current list box
|
|
429 |
*/
|
|
430 |
RArray<TInt> iCells;
|
|
431 |
|
|
432 |
/**
|
|
433 |
* Items array.
|
|
434 |
* Own
|
|
435 |
*/
|
|
436 |
RSwtLbItems iItems;
|
|
437 |
|
|
438 |
/**
|
|
439 |
* Listbox image array.
|
|
440 |
* Own.
|
|
441 |
*/
|
|
442 |
CArrayPtr<CGulIcon>* iImgs;
|
|
443 |
|
|
444 |
/**
|
|
445 |
* Listbox string array.
|
|
446 |
* Own.
|
|
447 |
*/
|
|
448 |
CDesCArray* iTxts;
|
|
449 |
|
|
450 |
/**
|
|
451 |
* Listbox properties.
|
|
452 |
* Own.
|
|
453 |
*/
|
|
454 |
TSwtLbProp iProps;
|
|
455 |
|
|
456 |
/**
|
|
457 |
* Previously selected items (temporary)
|
|
458 |
* Own
|
|
459 |
*/
|
|
460 |
CArrayFix<TInt>* iPrevSelItems;
|
|
461 |
|
|
462 |
/**
|
|
463 |
* Foreground color.
|
|
464 |
* Own
|
|
465 |
*/
|
|
466 |
const MSwtColor* iColor;
|
|
467 |
|
|
468 |
/**
|
|
469 |
* Default foreground color.
|
|
470 |
*/
|
|
471 |
TRgb iDefColor;
|
|
472 |
|
|
473 |
/**
|
|
474 |
* Maximum icon sizes for the current layout.
|
|
475 |
*/
|
|
476 |
TSize iMaxDetailIconSize;
|
|
477 |
TSize iMaxHeadingIconSize;
|
|
478 |
|
|
479 |
/**
|
|
480 |
* Deliver all pointer event to the scrollbar when this on.
|
|
481 |
*/
|
|
482 |
TBool iVScrollBarGrabsPointerEvents;
|
|
483 |
|
|
484 |
/**
|
|
485 |
* Stores last known focus index. Use only during paint and key handlers.
|
|
486 |
*/
|
|
487 |
TInt iPrevFocusIndex;
|
|
488 |
|
|
489 |
/**
|
|
490 |
* View visible rect at last draw
|
|
491 |
*/
|
|
492 |
mutable TRect iLastViewVisibleRect;
|
|
493 |
|
|
494 |
/**
|
|
495 |
* True when list is flick scrolling
|
|
496 |
*/
|
|
497 |
TBool iFlickScrollingOngoing;
|
|
498 |
|
|
499 |
/**
|
|
500 |
* True when pointer events on scrollbar should be delivered to listbox
|
|
501 |
*/
|
|
502 |
TBool iScrollbarPointerEventToListbox;
|
|
503 |
};
|
|
504 |
|
|
505 |
#endif // SWTLISTBOX_H
|