|
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 SWTLISTVIEW_H |
|
14 #define SWTLISTVIEW_H |
|
15 |
|
16 |
|
17 #include <eiklbo.h> |
|
18 #include "eswtmobileextensions.h" |
|
19 #include "swtscrollablebase.h" |
|
20 #include "swtscrollbar.h" |
|
21 |
|
22 |
|
23 class CAknIconArray; |
|
24 class CSelectionIndexArray; |
|
25 class CSwtGrid; |
|
26 class CAknGridM; |
|
27 class CAknGridView; |
|
28 class CSwtControlMenu; |
|
29 class CSwtMenu; |
|
30 class CSwtMenuItem; |
|
31 |
|
32 |
|
33 /** |
|
34 * CSwtListView |
|
35 * This class implements the eSWT ListView on S60 platform |
|
36 * @lib eswt |
|
37 */ |
|
38 NONSHARABLE_CLASS(CSwtListView) |
|
39 : public CAknControl |
|
40 , public ASwtScrollableBase |
|
41 , public MSwtListView |
|
42 , public MEikCommandObserver |
|
43 , public MEikListBoxObserver |
|
44 { |
|
45 public: |
|
46 static CSwtListView* NewL(MSwtDisplay& aDisplay, TSwtPeer aPeer, |
|
47 MSwtComposite& aParent, TInt aStyle); |
|
48 static CSwtListView* NewLC(MSwtDisplay& aDisplay, TSwtPeer aPeer, |
|
49 MSwtComposite& aParent, TInt aStyle); |
|
50 virtual ~CSwtListView(); |
|
51 void ScrollViewToShowAsManyItemsAsPossibleL(); |
|
52 TInt ScrollBarBreadth(const CEikScrollBar* aBar); |
|
53 |
|
54 // From CCoeControl |
|
55 CCoeControl* ComponentControl(TInt aIndex) const; |
|
56 TInt CountComponentControls() const; |
|
57 void SizeChanged(); |
|
58 void PositionChanged(); |
|
59 void HandleResourceChange(TInt aType); |
|
60 void FocusChanged(TDrawNow aDrawNow); |
|
61 TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType); |
|
62 void MakeVisible(TBool aVisible); |
|
63 void SetDimmed(TBool aDimmed); |
|
64 TTypeUid::Ptr MopSupplyObject(TTypeUid aId); |
|
65 |
|
66 private: |
|
67 void Draw(const TRect& aRect) const; |
|
68 |
|
69 // From MSwtListView |
|
70 public: |
|
71 MSwtScrollable* Scrollable(); |
|
72 void AppendL(const TDesC& aPtr, const MSwtImage* aImage); |
|
73 void InsertL(TInt aPos, const TDesC& aPtr, const MSwtImage* aImage); |
|
74 void DeselectItem(TInt aIndex); |
|
75 void DeselectRange(TInt aStart, TInt aEnd); |
|
76 void DeselectItems(const TInt* aIndices, TInt aCount); |
|
77 void DeselectAll(); |
|
78 TInt GetFocusIndex() const; |
|
79 void GetItemL(TInt aItemIndex, TPtrC& aString) const; |
|
80 TPoint GetIconSize(TInt aStyle) const; |
|
81 TInt GetItemCount() const; |
|
82 CPtrCArray* GetItemsL() const; |
|
83 CPtrCArray* GetSelectionL() const; |
|
84 TInt GetSelectionCount() const; |
|
85 const CArrayFix<TInt>* GetSelectionIndices() const; |
|
86 TInt GetTopIndex() const; |
|
87 TInt IndexOf(const TDesC& aString, TInt& aStart) const; |
|
88 TBool IsSelected(TInt aIndex) const; |
|
89 void RemoveItemL(TInt aIndex); |
|
90 void RemoveRangeL(TInt aStart, TInt aEnd); |
|
91 void RemoveItemsL(const TInt* aIndices, TInt aCount); |
|
92 void RemoveAllL(); |
|
93 void SelectItemL(TInt aIndex, TBool aScroll); |
|
94 void SelectRangeL(TInt aStart, TInt aEnd); |
|
95 void SelectAllL(); |
|
96 void SetItemsL(MDesCArray* aStringArray, RPointerArray<MSwtImage>& aImagesArray); |
|
97 void SetLayoutL(TInt aLayout); |
|
98 void SetLayoutDensityL(TInt aDensity); |
|
99 void ShowSelection(); |
|
100 void SetFocusIndex(TInt aIndex); |
|
101 |
|
102 // From ASwtScrollableBase |
|
103 CEikScrollBarFrame* SbFrame() const; |
|
104 void SetVisibleScrollBar(TInt aStyle, TBool aVisible); |
|
105 void ScrollBarDestroyed(const MSwtScrollBar* aScrollBar); |
|
106 #if defined( RD_SCALABLE_UI_V2) |
|
107 void HandleScrollEventL(CEikScrollBar* aScrollBar, |
|
108 TEikScrollEvent aEventType); |
|
109 #endif |
|
110 |
|
111 // From MSwtControl |
|
112 CCoeControl& CoeControl(); |
|
113 const CCoeControl& CoeControl() const; |
|
114 void ProcessKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType); |
|
115 TRgb GetBackground() const; |
|
116 TRgb GetForeground() const; |
|
117 void SetBackgroundL(const MSwtColor* aColor); |
|
118 void SetForegroundL(const MSwtColor* aColor); |
|
119 TSize ComputeSizeL(TInt aWHint, TInt aHHint); |
|
120 TBool IsKeyUsed(TUint aKeyCode) const; |
|
121 TBool MSKSelCmdEnabled() const; |
|
122 const MSwtMenu* GetControlMenu() const; |
|
123 void UpdateDoNotDrawFlag(); |
|
124 HBufC* MSKLabelL() const; |
|
125 #if defined( RD_SCALABLE_UI_V2) |
|
126 void HandlePointerEventL(const TPointerEvent& aPointerEvent); |
|
127 const MSwtMenu* GetStylusPopupControlMenu() const; |
|
128 #endif |
|
129 #ifdef RD_JAVA_S60_RELEASE_9_2 |
|
130 void EnableFocusHighlight(TBool aEnable); |
|
131 #endif //RD_JAVA_S60_RELEASE_9_2 |
|
132 TInt FocusBackgroundPolicy() const; |
|
133 void PrepareForTraverse(); |
|
134 |
|
135 // From MEikCommandObserver |
|
136 public: |
|
137 void ProcessCommandL(TInt aCmdId); |
|
138 |
|
139 // From MEikListBoxObserver |
|
140 public: |
|
141 void HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType); |
|
142 |
|
143 // Own methods |
|
144 private: |
|
145 CSwtListView(MSwtDisplay& aDisplay, TSwtPeer aPeer, MSwtComposite& aParent, TInt aStyle); |
|
146 void ConstructL(); |
|
147 |
|
148 enum TSwtListViewDensity |
|
149 { |
|
150 ELowListViewDensity = 1, |
|
151 EMediumListViewDensity = 2, |
|
152 EHighListViewDensity = 3 |
|
153 }; |
|
154 |
|
155 void ApplyGridCellLayoutL(); |
|
156 CDesCArray* GetTextArray() const; |
|
157 CAknIconArray* GetIconArray() const; |
|
158 CAknGridM* GetGridModel() const; |
|
159 CAknGridView* GetGridView() const; |
|
160 CGulIcon* CreateIconL(const MSwtImage* aIcon) const; |
|
161 void DoGridCellLayoutL(const TSwtListViewDensity& aDensity); |
|
162 void LoadLayouts(const TSwtListViewDensity& aDensity, TSize& aCellSize, |
|
163 TRect& aIconRect, TRect& aSelRect, TRect& aTextRect, |
|
164 TInt& aTextCellFontId); |
|
165 void CalcRowsColumns(const TSize& aCellSize, TInt& aXCells, TInt& aYCells) const; |
|
166 void AddTextL(const TDesC& aPtr, const TInt& aPos); |
|
167 void AddIconL(const MSwtImage* aImage, const TInt& aPos); |
|
168 void AddItemL(const TDesC& aPtr, const MSwtImage* aImage, const TInt& aPos); |
|
169 void UpdateIconIndexL(const TInt& arrayIndex); |
|
170 void UpdateSelectionIndexesL(TInt aStart, TInt aEnd, TBool aItemsAdded); |
|
171 void UntabifyL(RBuf& aAll); |
|
172 TInt GetCaption(const TInt& aIndex, TPtrC& aTxt) const; |
|
173 void SingleSelectL(const TInt& aIndex, TBool aScroll); |
|
174 void SingleOrMultiSelectL(const TInt& aIndex, TBool aScroll); |
|
175 void UpdateTextColorL(); |
|
176 CGulIcon* GetMarkedItemIconL(); |
|
177 void HandleResourceChangeL(TInt aType); |
|
178 void SizeChangedL(); |
|
179 TInt ItemIconIndex(const TInt& aItemPos); |
|
180 void UpdateControlMenu(); |
|
181 TInt GetBorderSize(const TInt& aAlignment) const; |
|
182 TSize GetCellSize() const; |
|
183 TUint ISqrt(TUint x); |
|
184 TInt GetRowColumnCount(const TInt& aItemCount, const TInt& aRowColumnCount) const; |
|
185 void UpdateMSKLabelL(); |
|
186 void LayoutCell(const TRect& aCellRect, TRect& aTextRect, TRect& aIconRect, TRect& aSelRect); |
|
187 void UpdateSetItemCount(const TInt& textChange, const TInt& iconChange); |
|
188 void DoGridCellLayoutIfNeededL(); |
|
189 void UpdateRemovedItemCountersL(const TInt& aIndex); |
|
190 void GetSelection(CArrayFix<TInt>* aSelectionArray) const; |
|
191 TInt GetSelectionL(const TInt aIndex) const; |
|
192 void SetSelectionL(const CArrayFix<TInt>* aSelectionArray) const; |
|
193 void UpdateImageSizes(const TSize& aNewMaxSize); |
|
194 void RemoveImageRef(const TInt& aIndex); |
|
195 void GetCellVariants(const TSwtListViewDensity& aDensity, |
|
196 TInt& aCellVariant, TInt& aSubcellVariantG1, |
|
197 TInt& aSubcellVariantG2, TInt& aSubcellVariantT) const; |
|
198 void UpdateIconSizes(const TSwtListViewDensity& aDensity, |
|
199 const TRect& aCellRect); |
|
200 void GetLafFacadeRectIds( |
|
201 const TSwtListViewDensity& aDensity, |
|
202 CSwtLafFacade::TSwtLafFacadeRectId& aRectIdPane, |
|
203 CSwtLafFacade::TSwtLafFacadeRectId& aRectIdPaneG1, |
|
204 CSwtLafFacade::TSwtLafFacadeRectId& aRectIdPaneG2, |
|
205 CSwtLafFacade::TSwtLafFacadeTextId& aRectIdPaneT1, |
|
206 CSwtLafFacade::TSwtLafFacadeFontId& aRectIdPaneT1Font |
|
207 ) const; |
|
208 void CoerceCellRect(const TSwtListViewDensity& aDensity, |
|
209 TRect& aCellRect) const; |
|
210 void UpdateFlickScrollingState(TListBoxEvent aEventType); |
|
211 |
|
212 #ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
213 public: |
|
214 void DoControlSpecificFeedback( |
|
215 const TBool& aFirstTap, |
|
216 const TBool& aTappedToChildRect, |
|
217 const TPointerEvent& aPointerEvent) const; |
|
218 #endif //RD_JAVA_ADVANCED_TACTILE_FEEDBACK |
|
219 |
|
220 private: // data |
|
221 |
|
222 /** |
|
223 * Cell layout params for the grid. |
|
224 */ |
|
225 TBool iVerticalOrientation; |
|
226 TBool iLeftToRight; |
|
227 TBool iTopToBottom; |
|
228 TInt iNumOfRows; |
|
229 TInt iNumOfColumns; |
|
230 TInt iWidthOfSpaceBetweenItems; |
|
231 TInt iHeightOfSpaceBetweenItems; |
|
232 |
|
233 /** |
|
234 * The current density. |
|
235 */ |
|
236 TSwtListViewDensity iDensity; |
|
237 |
|
238 /** |
|
239 * Icon sizes for getIconSize |
|
240 */ |
|
241 TPoint iIconSizeInLowDensity; |
|
242 TPoint iIconSizeInMediumDensity; |
|
243 TPoint iIconSizeInHighDensity; |
|
244 |
|
245 /** |
|
246 * Number of non-NULL icons and texts |
|
247 */ |
|
248 TInt iNumberOfTexts; |
|
249 TInt iNumberOfIcons; |
|
250 |
|
251 /** |
|
252 * The control menu. |
|
253 * Owned. |
|
254 */ |
|
255 CSwtControlMenu* iMenu; |
|
256 |
|
257 /** |
|
258 * The control menu submenu. |
|
259 * Owned. |
|
260 */ |
|
261 CSwtControlMenu* iSubMenu; |
|
262 |
|
263 /** |
|
264 * The control menu items. |
|
265 * Owned. |
|
266 */ |
|
267 CSwtMenuItem* iMenuItemEditList; |
|
268 CSwtMenuItem* iMenuItemMarkUnmark; |
|
269 CSwtMenuItem* iMenuItemMarkAll; |
|
270 CSwtMenuItem* iMenuItemUnmarkAll; |
|
271 |
|
272 /** |
|
273 * The strings for mark/unmark command and its state. |
|
274 */ |
|
275 TBool iIsMarkDisplayed; |
|
276 HBufC* iMarkString; |
|
277 HBufC* iUnmarkString; |
|
278 |
|
279 /** |
|
280 * The Selection array before a key event, for multiselection only. |
|
281 * Own. |
|
282 */ |
|
283 CArrayFix<TInt>* iOldSelectionArray; |
|
284 |
|
285 /** |
|
286 * The Selection array for handling selection indexes with mirrored layout. |
|
287 * Own. |
|
288 */ |
|
289 CArrayFix<TInt>* iSelectionArray; |
|
290 |
|
291 /** |
|
292 * The colors used to draw text and background. |
|
293 * Not own. |
|
294 */ |
|
295 const MSwtColor* iTextColor; |
|
296 const MSwtColor* iBgColor; |
|
297 |
|
298 /** |
|
299 * Referenced images as the ListView does not copy the bitmaps it uses. |
|
300 */ |
|
301 RPointerArray<const MSwtImage> iRefImages; |
|
302 |
|
303 /** |
|
304 * Maximum image size for the current layout. |
|
305 */ |
|
306 TSize iMaxImageSize; |
|
307 |
|
308 /** |
|
309 * The grid control. |
|
310 * Own. |
|
311 */ |
|
312 CSwtGrid* iGrid; |
|
313 |
|
314 /** |
|
315 * Deliver all pointer event to the scrollbar when this on. |
|
316 */ |
|
317 TBool iVScrollBarGrabsPointerEvents; |
|
318 |
|
319 #ifdef RD_SCALABLE_UI_V2 |
|
320 /** |
|
321 * The control menu for stylus popup. |
|
322 * Owned. |
|
323 */ |
|
324 CSwtControlMenu* iStylusPopupMenu; |
|
325 |
|
326 /** |
|
327 * The control menu items fro stylus popup. |
|
328 * Owned. |
|
329 */ |
|
330 CSwtMenuItem* iStylusPopupMarkAll; |
|
331 CSwtMenuItem* iStylusPopupUnmarkAll; |
|
332 #endif //RD_SCALABLE_UI_V2 |
|
333 |
|
334 /** |
|
335 * Stores last known focus index. Use only during paint and key handlers. |
|
336 */ |
|
337 TInt iPrevFocusIndex; |
|
338 |
|
339 /** |
|
340 * Stores grid cell layout update status |
|
341 */ |
|
342 TBool iIsGridCellLayoutNeeded; |
|
343 |
|
344 /** |
|
345 * View visible rect at last draw |
|
346 */ |
|
347 mutable TRect iLastViewVisibleRect; |
|
348 |
|
349 /** |
|
350 * True when list is flick scrolling |
|
351 */ |
|
352 TBool iFlickScrollingOngoing; |
|
353 |
|
354 /** |
|
355 * True when pointer events on scrollbar should be delivered to listbox |
|
356 */ |
|
357 TBool iScrollbarPointerEventToListbox; |
|
358 }; |
|
359 |
|
360 |
|
361 #endif // SWTLISTVIEW_H |