|
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 SWTLISTBASE_H |
|
14 #define SWTLISTBASE_H |
|
15 |
|
16 |
|
17 #include <eiklbo.h> |
|
18 #include "swtscrollablebase.h" |
|
19 #include "swtlistboxlists.h" |
|
20 #include "eswtwidgetscore.h" |
|
21 |
|
22 |
|
23 const TUint KCheckboxColumnIndex = 0; |
|
24 const TUint KTextColumnIndex = 1; |
|
25 |
|
26 |
|
27 /** |
|
28 * CSwtListBase |
|
29 * @lib eswt |
|
30 */ |
|
31 NONSHARABLE_CLASS(CSwtListBase) |
|
32 : public CAknControl |
|
33 , public ASwtScrollableBase |
|
34 , public MSwtListObserver |
|
35 , public MEikListBoxObserver |
|
36 { |
|
37 // Own methods |
|
38 public: |
|
39 /** |
|
40 * Create a list box. |
|
41 * @param aStyle control style. |
|
42 */ |
|
43 virtual CEikTextListBox* CreateListBoxL(TInt aStyle); |
|
44 |
|
45 /** |
|
46 * Create a list box model. |
|
47 */ |
|
48 virtual void CreateListBoxModelL(); |
|
49 |
|
50 /** |
|
51 * Create the list scrollbars. |
|
52 * @param aLb the list having the scrollbars. |
|
53 */ |
|
54 virtual void CreateScrollBarsL(CEikTextListBox* aLb); |
|
55 |
|
56 /** |
|
57 * Create the icon array containing the icons for the multi selection. |
|
58 * @param aLb the list having the icons. |
|
59 */ |
|
60 virtual void CreateIconArrayL(CEikTextListBox* aLb); |
|
61 |
|
62 /** |
|
63 * Create an item text according with its selection state. |
|
64 * @param aPtr the item text. |
|
65 * @param aSelected the item selection state. |
|
66 * @return the buffer containing the item text. |
|
67 */ |
|
68 virtual HBufC* CreateItemTextLC(const TDesC& aPtr, TBool aSelected = EFalse); |
|
69 |
|
70 /** |
|
71 * Update control size. |
|
72 */ |
|
73 virtual void UpdateSize(); |
|
74 |
|
75 /** |
|
76 * Update the list box font. |
|
77 */ |
|
78 void UpdateListBoxFontL(); |
|
79 |
|
80 /** |
|
81 * Update the list box text color. |
|
82 */ |
|
83 void UpdateListBoxTextColorL(); |
|
84 |
|
85 /** |
|
86 * Returns MSwtScrollable reference. |
|
87 * @return MSwtScrollable reference. |
|
88 */ |
|
89 MSwtScrollable* Scrollable(); |
|
90 |
|
91 /** |
|
92 * Deselect items. |
|
93 * @param aIndices the indices of items to deselect. |
|
94 * @param aCount the number of items to deselect. |
|
95 */ |
|
96 void DeselectItems(const TInt* aIndices, TInt aCount); |
|
97 |
|
98 /** |
|
99 * Deselect an item. |
|
100 * @param aIndex the index of the item to deselect. |
|
101 */ |
|
102 void DeselectItem(TInt aIndex); |
|
103 |
|
104 /** |
|
105 * Deselect a range of items. |
|
106 * @param aStart the start index of the item range. |
|
107 * @param aEnd the end index of the item range. |
|
108 */ |
|
109 void DeselectRange(TInt aStart, TInt aEnd); |
|
110 |
|
111 /** |
|
112 * Deselect all items. |
|
113 */ |
|
114 void DeselectAll(); |
|
115 |
|
116 /** |
|
117 * Get focus index. |
|
118 * @return the index of the focused item. |
|
119 */ |
|
120 TInt GetFocusIndex() const; |
|
121 |
|
122 /** |
|
123 * Get the number of selected items. |
|
124 * @return the number of selected items. |
|
125 */ |
|
126 TInt GetSelectionCount() const; |
|
127 |
|
128 /** |
|
129 * Get the indices of selected items. |
|
130 * @return the index array of selected items. |
|
131 */ |
|
132 const CArrayFix<TInt>* GetSelectionIndices() const; |
|
133 |
|
134 /** |
|
135 * Select an item. |
|
136 * @param aIndex the index of the item to select. |
|
137 * @param aScroll If ETrue the list is scrolled to make visible the selected item. |
|
138 */ |
|
139 void SelectItemL(TInt aIndex, TBool aScroll); |
|
140 |
|
141 /** |
|
142 * Select a range of items. |
|
143 * @param aStart the start index of the item range. |
|
144 * @param aEnd the end index of the item range. |
|
145 */ |
|
146 void SelectRangeL(TInt aStart, TInt aEnd); |
|
147 |
|
148 /** |
|
149 * Select all items. |
|
150 */ |
|
151 void SelectAllL(); |
|
152 |
|
153 /** |
|
154 * Show the selected item. |
|
155 */ |
|
156 void ShowSelection() const; |
|
157 |
|
158 /** |
|
159 * Post a selection event. |
|
160 */ |
|
161 void PostSelectionEvent() const; |
|
162 |
|
163 /** |
|
164 * Calculate the focus index and the top item index after an item removal. |
|
165 * @param aNewFocusIndex the new focusindex. |
|
166 * @param aRemovedItemIndices the removed item indices. |
|
167 * @param aOldFocusIndex the old focus index. |
|
168 */ |
|
169 void CalcFocusIndexAfterItemRemoval(TInt& aNewFocusIndex, |
|
170 const RArray<TInt>& aRemovedItemIndices, TInt aOldFocusIndex) const; |
|
171 |
|
172 /** |
|
173 * Get the minimum width of a list item. |
|
174 * @return the minimum width of a list item. |
|
175 */ |
|
176 TInt MinimumListItemWidth() const; |
|
177 |
|
178 /** |
|
179 * Get the preferred width. |
|
180 * @return preferred width. |
|
181 */ |
|
182 TInt PreferredWidth() const; |
|
183 |
|
184 /** |
|
185 * Get the preferred height. |
|
186 * @return preferred height. |
|
187 */ |
|
188 TInt PreferredHeight() const; |
|
189 |
|
190 /** |
|
191 * Compute the maximum width of item text. |
|
192 * @return the the maximum width of item text. |
|
193 */ |
|
194 TInt ComputeTextMaxWidth() const; |
|
195 |
|
196 /** |
|
197 * Compute the maximum width of item text. |
|
198 * @return the the maximum width of item text. |
|
199 */ |
|
200 void SetTextMaxWidth(TInt aMaxTxtWidth); |
|
201 |
|
202 /** |
|
203 * Update MSK. |
|
204 */ |
|
205 void UpdateListMskL(); |
|
206 |
|
207 protected: |
|
208 /** |
|
209 * First phase constructor |
|
210 * @param aDisplay parent display |
|
211 * @param aPeer java peer of this class |
|
212 * @param aParent composite parent |
|
213 * @param aStyle control style |
|
214 */ |
|
215 CSwtListBase(MSwtDisplay& aDisplay, TSwtPeer aPeer, MSwtComposite& aParent, TInt aStyle); |
|
216 |
|
217 /** |
|
218 * Destructor |
|
219 */ |
|
220 ~CSwtListBase(); |
|
221 |
|
222 /** |
|
223 * Second phase constructor |
|
224 */ |
|
225 void ConstructL(); |
|
226 |
|
227 private: |
|
228 /** |
|
229 * Update the default font. |
|
230 */ |
|
231 void UpdateDefaultFontL(); |
|
232 |
|
233 /** |
|
234 * Handling of resource change events. |
|
235 * @param aType event type. |
|
236 */ |
|
237 void HandleResourceChangeL(TInt aType); |
|
238 |
|
239 /** |
|
240 * Get current state of list selection. |
|
241 * @param aCurrSelItems resulting array of selected items. |
|
242 */ |
|
243 void GetUserSelectionL(CArrayFix<TInt>* aCurrSelItems); |
|
244 |
|
245 /** |
|
246 * Updates flick scrolling status. |
|
247 * @param aEventType CEikListbox event type. |
|
248 */ |
|
249 void UpdateFlickScrollingState(TListBoxEvent aEventType); |
|
250 |
|
251 // From CCoeControl |
|
252 public: |
|
253 TInt CountComponentControls() const; |
|
254 CCoeControl* ComponentControl(TInt aIndex) const; |
|
255 void MakeVisible(TBool aVisible); |
|
256 void SetDimmed(TBool aDimmed); |
|
257 TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType); |
|
258 void HandleResourceChange(TInt aType); |
|
259 |
|
260 protected: |
|
261 void SizeChanged(); |
|
262 void PositionChanged(); |
|
263 void FocusChanged(TDrawNow aDrawNow); |
|
264 TTypeUid::Ptr MopSupplyObject(TTypeUid aId); |
|
265 |
|
266 private: |
|
267 void Draw(const TRect& aRect) const; |
|
268 |
|
269 // From ASwtControlbase |
|
270 public: |
|
271 void SetFontL(const MSwtFont* aFont); |
|
272 HBufC* MSKLabelL() const; |
|
273 TBool MSKSelCmdEnabled() const; |
|
274 |
|
275 protected: |
|
276 const MSwtFont& DefaultFont() const; |
|
277 |
|
278 // From MSwtControl |
|
279 public: |
|
280 CCoeControl& CoeControl(); |
|
281 const CCoeControl& CoeControl() const; |
|
282 void ProcessKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType); |
|
283 void HandlePointerEventL(const TPointerEvent& aPointerEvent); |
|
284 TBool IsKeyUsed(TUint aKeyCode) const; |
|
285 TRgb GetForeground() const; |
|
286 void SetForegroundL(const MSwtColor* aColor); |
|
287 void SetBackgroundL(const MSwtColor* aColor); |
|
288 TBool IsLongTapAnimationCandidate(const TPointerEvent& aPointerEvent) const; |
|
289 #ifdef RD_JAVA_S60_RELEASE_9_2 |
|
290 void EnableFocusHighlight(TBool aEnable); |
|
291 #endif //RD_JAVA_S60_RELEASE_9_2 |
|
292 TInt FocusBackgroundPolicy() const; |
|
293 void PrepareForTraverse(); |
|
294 |
|
295 // From ASwtScrollableBase |
|
296 protected: |
|
297 CEikScrollBarFrame* SbFrame() const; |
|
298 |
|
299 // From MSwtListObserver |
|
300 public: |
|
301 void HandleSizeChangedL(); |
|
302 MSwtUiUtils& Utils() const; |
|
303 |
|
304 // From MEikScrollBarObserver |
|
305 public: |
|
306 void HandleScrollEventL(CEikScrollBar* aScrollBar, TEikScrollEvent aEventType); |
|
307 |
|
308 // From MEikListBoxObserver |
|
309 public: |
|
310 void HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType); |
|
311 |
|
312 // Data |
|
313 protected: |
|
314 /** |
|
315 * Previously selected items (temporary) |
|
316 * Own |
|
317 */ |
|
318 CArrayFix<TInt>* iPrevSelItems; |
|
319 |
|
320 /** |
|
321 * Pointer to the contained ListBox. |
|
322 * Own |
|
323 */ |
|
324 CEikTextListBox* iList; |
|
325 |
|
326 /** |
|
327 * Array of text items. |
|
328 * Own |
|
329 */ |
|
330 CDesCArray* iTextItems; |
|
331 |
|
332 /** |
|
333 * The default font. |
|
334 * Own |
|
335 */ |
|
336 MSwtFont* iDefaultFont; |
|
337 |
|
338 /** |
|
339 * The current used LAF font. |
|
340 */ |
|
341 const CFont* iCurrentLafFont; |
|
342 |
|
343 /** |
|
344 * The default item height (when default font is set). |
|
345 */ |
|
346 TInt iDefaultItemHeight; |
|
347 |
|
348 /** |
|
349 * Pointer to the text color. |
|
350 */ |
|
351 const MSwtColor* iTextColor; |
|
352 |
|
353 /** |
|
354 * Removed item indices. |
|
355 */ |
|
356 RArray<TInt> iRemovedItemIndices; |
|
357 |
|
358 /** |
|
359 * The maximum width of item text. |
|
360 */ |
|
361 TInt iTxtMaxWidth; |
|
362 |
|
363 /** |
|
364 * Deliver all pointer event to the scrollbar when this on. |
|
365 */ |
|
366 TBool iVScrollBarGrabsPointerEvents; |
|
367 |
|
368 /** |
|
369 * Stores last known focus index. Use only during paint and key handlers. |
|
370 */ |
|
371 TInt iPrevFocusIndex; |
|
372 |
|
373 /** |
|
374 * Type of the list |
|
375 */ |
|
376 TInt iListType; |
|
377 |
|
378 /** |
|
379 * View visible rect at last draw |
|
380 */ |
|
381 mutable TRect iLastViewVisibleRect; |
|
382 |
|
383 /** |
|
384 * True when list is flick scrolling |
|
385 */ |
|
386 TBool iFlickScrollingOngoing; |
|
387 |
|
388 /** |
|
389 * True when pointer events on scrollbar should be delivered to listbox |
|
390 */ |
|
391 TBool iScrollbarPointerEventToListbox; |
|
392 }; |
|
393 |
|
394 |
|
395 #endif // SWTLISTBASE_H |