1 /* |
|
2 * Copyright (c) 2007 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: CMmListBox |
|
15 * Version : %version: MM_22.1.16 % << Don't touch! Updated by Synergy at check-out. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef C_MMLISTBOX_H |
|
21 #define C_MMLISTBOX_H |
|
22 |
|
23 #include <e32std.h> |
|
24 #include <e32base.h> |
|
25 #include <aknlists.h> |
|
26 #include <e32cmn.h> |
|
27 |
|
28 class CMmListBoxModel; |
|
29 class CMmListBoxItemDrawer; |
|
30 class CMmMarqueeAdapter; |
|
31 class CMmWidgetContainer; |
|
32 class CMmTemplateLibrary; |
|
33 |
|
34 /** |
|
35 * CMmListBox |
|
36 * |
|
37 * @code |
|
38 * @endcode |
|
39 * @lib mmwidgets |
|
40 * @since S60 v3.0 |
|
41 * @ingroup group_mmwidgets |
|
42 */ |
|
43 NONSHARABLE_CLASS( CMmListBox ) : public CEikFormattedCellListBoxTypedef |
|
44 { |
|
45 public: |
|
46 /** |
|
47 * Two-phased constructor. |
|
48 * |
|
49 * @since S60 v3.0 |
|
50 * @param aParent Parent control. |
|
51 * @param aFlags Flags. |
|
52 * @param aTemplateLibrary Template library for drawer. |
|
53 * @return List box. |
|
54 */ |
|
55 static CMmListBox* NewL( const CCoeControl* aParent, TInt aFlags, |
|
56 CMmTemplateLibrary* aTemplateLibrary ); |
|
57 |
|
58 /** |
|
59 * Two-phased constructor. |
|
60 * |
|
61 * @since S60 v3.0 |
|
62 * @param aParent Parent control. |
|
63 * @param aFlags Flags. |
|
64 * @param aTemplateLibrary Template library for drawer. |
|
65 * @return List box. |
|
66 */ |
|
67 static CMmListBox* NewLC( const CCoeControl* aParent, TInt aFlags, |
|
68 CMmTemplateLibrary* aTemplateLibrary ); |
|
69 |
|
70 /** |
|
71 * Destructor. |
|
72 * |
|
73 * @since S60 v3.0 |
|
74 */ |
|
75 virtual ~CMmListBox(); |
|
76 |
|
77 /** |
|
78 * Gets the listbox model. |
|
79 * |
|
80 * @since S60 v3.0 |
|
81 * @return Listbox model. |
|
82 */ |
|
83 CMmListBoxModel * MmModel(); |
|
84 |
|
85 /** |
|
86 * Sets the listbox model. |
|
87 * |
|
88 * @since S60 v3.0 |
|
89 * @param aMmModel The model to be set. |
|
90 */ |
|
91 void SetMmModel( CMmListBoxModel* aMmModel ); |
|
92 |
|
93 /** |
|
94 * Creates the view class instance. |
|
95 * |
|
96 * @since S60 v3.0 |
|
97 * @return Listbox view. |
|
98 */ |
|
99 CListBoxView* MakeViewClassInstanceL(); |
|
100 |
|
101 /** |
|
102 * Creates the item drawer for listbox. |
|
103 * |
|
104 * @param aTemplateLibrary Template library for drawer. |
|
105 * @since S60 v3.0 |
|
106 */ |
|
107 void CreateItemDrawerL( CMmTemplateLibrary* aTemplateLibrary ); |
|
108 |
|
109 /** |
|
110 * Sets the flag. |
|
111 * |
|
112 * @since S60 v3.0 |
|
113 * @param aFlag Avkon list flag |
|
114 */ |
|
115 void SetListFlag( TInt aFlag ); |
|
116 |
|
117 /** |
|
118 * Clears the flag. |
|
119 * |
|
120 * @since S60 v3.0 |
|
121 * @param aFlag Avkon list flag |
|
122 */ |
|
123 void ClearListFlag( TInt aFlag ); |
|
124 |
|
125 |
|
126 public: // from base class CCoeControl. |
|
127 |
|
128 /** |
|
129 * From CCoeControl. |
|
130 * Handles pointer events. |
|
131 * |
|
132 * @since S60 v3.0 |
|
133 * @param aPointerEvent Pointer event. |
|
134 */ |
|
135 void HandlePointerEventL( const TPointerEvent& aPointerEvent ); |
|
136 |
|
137 /** |
|
138 * From base class. |
|
139 * |
|
140 * @since S60 v3.0 |
|
141 * @param aKeyEvent Key event. |
|
142 * @param aType Event code. |
|
143 */ |
|
144 TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent, |
|
145 TEventCode aType ); |
|
146 |
|
147 /** |
|
148 * Adjusts the given rectangle. |
|
149 * |
|
150 * @since S60 v3.0 |
|
151 * @param aRect Rectangle to be adjusted. |
|
152 * @return Error code. |
|
153 */ |
|
154 TInt AdjustRectHeightToWholeNumberOfItems( TRect& aRect ) const; |
|
155 |
|
156 /** |
|
157 * Sets item drawer and view background context. |
|
158 * |
|
159 * @since S60 v3.0 |
|
160 * @param aBgContext Background context. |
|
161 */ |
|
162 void SetItemDrawerAndViewBgContext( |
|
163 CAknsBasicBackgroundControlContext * aBgContext ); |
|
164 |
|
165 /** |
|
166 * Updates scrollbar. |
|
167 * |
|
168 * @since S60 v3.0 |
|
169 */ |
|
170 void UpdateScrollBarsL(); |
|
171 |
|
172 /** |
|
173 * Special version of Update scrollbar that never calls DrawNow() |
|
174 */ |
|
175 void UpdateScrollBarsNoRedrawL(); |
|
176 |
|
177 /** |
|
178 * Checks if all items fit in view rectangle. |
|
179 * |
|
180 * @since S60 v3.0 |
|
181 * @return Do all items fit in view rectangle. |
|
182 */ |
|
183 TBool AllItemsFitInViewRect(); |
|
184 |
|
185 /** |
|
186 * Handles scrollbar visibility change. |
|
187 * |
|
188 * @since S60 v3.0 |
|
189 * @return Is redraw needed. |
|
190 */ |
|
191 TBool HandleScrollbarVisibilityChangeL(); |
|
192 |
|
193 /** |
|
194 * Sets marquee adapter. |
|
195 * |
|
196 * @since S60 v3.0 |
|
197 * @param aAdapter Marquee adapter. |
|
198 */ |
|
199 void SetMarqueeAdapter( CMmMarqueeAdapter* aAdapter ); |
|
200 |
|
201 /** |
|
202 * Notifies that marquee is being drawn. |
|
203 * |
|
204 * @since S60 v3.0 |
|
205 * @param aIsMarqueeBeingDrawn Is marquee being drawn. |
|
206 */ |
|
207 void SetMarqueeDrawing( TBool aIsMarqueeBeingDrawn ); |
|
208 |
|
209 /** |
|
210 * Handles item removal. redraws view, updates scrollbar. |
|
211 * |
|
212 * @since S60 v3.0 |
|
213 */ |
|
214 void HandleItemRemovalL(); |
|
215 |
|
216 /** |
|
217 * Redraws items in view if it is necessary. |
|
218 * |
|
219 * @since S60 v3.0 |
|
220 * @param aPreviousCurrent Previously current item index. |
|
221 * @param aCurrent Current item index. |
|
222 * |
|
223 * @return true if anything was drawn. |
|
224 */ |
|
225 TBool RedrawIfNecessary( TInt aPreviousCurrent, TInt aCurrent ); |
|
226 |
|
227 /** |
|
228 * Overridden from base class to allow for drawing scrollbar |
|
229 * background in mirrored layout. |
|
230 * |
|
231 * @param aRect clipping rect |
|
232 */ |
|
233 void Draw(const TRect& aRect) const; |
|
234 |
|
235 /** |
|
236 * Draws the listbox view. |
|
237 * |
|
238 * @since S60 v5.0 |
|
239 */ |
|
240 void DrawView(); |
|
241 |
|
242 /** |
|
243 * Set the vertical item offset; |
|
244 * @param aOffset The offset to set to the widget. |
|
245 * |
|
246 * @since S60 v5.0 |
|
247 */ |
|
248 void SetVerticalItemOffset( TInt aOffset ); |
|
249 |
|
250 /** |
|
251 * Gets the current widget vertical item offset. |
|
252 * |
|
253 * @since S60 v5.0 |
|
254 * @return The current widget vertical item offset. |
|
255 */ |
|
256 TInt VerticalItemOffset() const; |
|
257 |
|
258 /** |
|
259 * Simply sets the item height members in widget and view. |
|
260 */ |
|
261 void SetItemHeight( TInt aItemHeight ); |
|
262 |
|
263 /** |
|
264 * Updates scrollbar thumbs. |
|
265 */ |
|
266 void UpdateScrollBarThumbs(); |
|
267 |
|
268 /** |
|
269 * Counts the number of component controls which this component owns. |
|
270 */ |
|
271 TInt CountComponentControls() const; |
|
272 |
|
273 /** |
|
274 * Disables/enables child component (scrollbar) drawing. |
|
275 */ |
|
276 void SetDisableChildComponentDrawing( TBool aDisable ); |
|
277 |
|
278 /** |
|
279 * Handles scrolling event. |
|
280 * |
|
281 * @since S60 v3.0 |
|
282 * @param aScrollBar Scrollbar being scrolled. |
|
283 * @param aEventType Type of scrollbar event. |
|
284 */ |
|
285 void HandleScrollEventL( CEikScrollBar* aScrollBar, |
|
286 TEikScrollEvent aEventType ); |
|
287 |
|
288 private: |
|
289 /** |
|
290 * Default constructor. |
|
291 * |
|
292 * @since S60 v3.0 |
|
293 */ |
|
294 CMmListBox(); |
|
295 |
|
296 /** |
|
297 * 2nd phase constructor. |
|
298 * |
|
299 * @since S60 v3.0 |
|
300 * @param aParent Parent control. |
|
301 * @param aFlags Flags. |
|
302 * @param aTemplateLibrary Template library for drawer. |
|
303 */ |
|
304 void ConstructL( const CCoeControl* aParent, TInt aFlags, |
|
305 CMmTemplateLibrary* aTemplateLibrary ); |
|
306 |
|
307 /** |
|
308 * Handles pointer events when edit mode is enabled. |
|
309 * |
|
310 * This method is only called during edit mode. It selectively passes |
|
311 * only some of the pointer events to CAknGrid::HandlePointerEventL |
|
312 * in order to disable flicking and panning. |
|
313 * |
|
314 * @param aPointerEvent pointer event |
|
315 */ |
|
316 void HandlePointerEventInEditModeL( const TPointerEvent& aPointerEvent ); |
|
317 |
|
318 /** |
|
319 * Scrolls the view if pointer is close to the top/bottom edge. |
|
320 * |
|
321 * This method is used only when edit mode is active. In a way it |
|
322 * brings back the focus based scrolling behavior that was present |
|
323 * in CAknGrid before ODE scrolling was introduced. |
|
324 */ |
|
325 void HandleScrollingInEditMode( const TPointerEvent& aPointerEvent ); |
|
326 |
|
327 /** |
|
328 * Checks if pointer position is within the scroll-triggering area. |
|
329 * |
|
330 * @param aPointerEvent pointer event |
|
331 * @return true if pointer above the top scrolling threshold. |
|
332 */ |
|
333 TBool IsPointerInTopScrollingThreshold( |
|
334 const TPointerEvent& aPointerEvent ) const; |
|
335 |
|
336 /** |
|
337 * Checks if pointer position is within the scroll-triggering area. |
|
338 * |
|
339 * @param aPointerEvent pointer event |
|
340 * @return true if pointer below the bottom scrolling threshold. |
|
341 */ |
|
342 TBool IsPointerInBottomScrollingThreshold( |
|
343 const TPointerEvent& aPointerEvent ) const; |
|
344 |
|
345 /** |
|
346 * Scrolls the view if the pointer is near top/bottom edge of the screen. |
|
347 * |
|
348 * Assumes that current item index is the index of the item under the |
|
349 * pointer. The time value returned is based on the distance of the pointer |
|
350 * from the top/bottom edge of the grid view (this makes the scrolling speed |
|
351 * dependent of how close the pointer is to the edge). |
|
352 * If there is no need to continue scrolling because the beginning/end of |
|
353 * the list has already been reached, 0 is returned. |
|
354 * |
|
355 * @param aPointerEvent pointer event |
|
356 * @return time to wait before calling this method again (in microseconds) |
|
357 * or 0 if already at the beginning/end of the list |
|
358 */ |
|
359 TInt ScrollIfNeeded( const TPointerEvent& aPointerEvent ); |
|
360 |
|
361 /** |
|
362 * Ensures that elements are drawn correctly when mirrored layout is |
|
363 * used and scrollbar is visible by shifting ViewRect to the right. |
|
364 */ |
|
365 void FixViewForMirroredLayout(); |
|
366 |
|
367 /** |
|
368 * Redraws the background under the vertical scrollbar in mirrored layout. |
|
369 * |
|
370 * The reason such method is needed is that view rectangle is shifted |
|
371 * to the right in mirrored layout and does not cover the scrollbar |
|
372 * area. In normal (non-mirrored) mode this method does nothing. |
|
373 */ |
|
374 void RedrawScrollbarBackground() const; |
|
375 |
|
376 /** |
|
377 * Does actual handling of scroll events. |
|
378 * |
|
379 * @param aScrollBar Scrollbar being scrolled. |
|
380 * @param aEventType Type of scrollbar event. |
|
381 */ |
|
382 void ProcessScrollEventL( CEikScrollBar* aScrollBar, |
|
383 TEikScrollEvent aEventType ); |
|
384 |
|
385 /** |
|
386 * Handles periodic events from @c iRedrawTimer. |
|
387 * Such events are generated at equal time intervals while |
|
388 * the view is being scrolled using the scrollbar. |
|
389 * This function typically calls @c ProcessScrollEventL, |
|
390 * which actually scrolls the view and causes a redraw. |
|
391 */ |
|
392 void HandleRedrawTimerEvent(); |
|
393 |
|
394 private: |
|
395 /** |
|
396 * Callback function for @c iRedrawTimer. |
|
397 * It simply calls @c HandleRedrawTimerEvent and returns 0. |
|
398 * |
|
399 * @param aPtr A pointer to CMmListBox object. |
|
400 * @return 0 (always). |
|
401 */ |
|
402 static TInt RedrawTimerCallback( TAny* aPtr ); |
|
403 |
|
404 private: // Data |
|
405 /** |
|
406 * Item drawer. |
|
407 */ |
|
408 CMmListBoxItemDrawer* iMmDrawer; |
|
409 |
|
410 /** |
|
411 * Multimedia Menu model. |
|
412 */ |
|
413 CMmListBoxModel* iMmModel; |
|
414 |
|
415 /** |
|
416 * marquee adapter. |
|
417 */ |
|
418 CMmMarqueeAdapter* iMarqueeAdapter; |
|
419 |
|
420 /** |
|
421 * Blocks scrollbar drawing. When this flag is set scrollbars components |
|
422 * are blocked in the CountComponentControls() method; |
|
423 */ |
|
424 TBool iDisableChildComponentDrawing; |
|
425 |
|
426 /** |
|
427 * This member is only used in edit mode to store the position of the pointer |
|
428 * during EButton1Down event. |
|
429 */ |
|
430 TPoint iButton1DownPos; |
|
431 |
|
432 /** |
|
433 * ETrue if the view is being scrolled with the scrollbar. |
|
434 */ |
|
435 TBool iScrollbarThumbIsBeingDragged; |
|
436 |
|
437 /** |
|
438 * Stores the number of scrollbar events that were ignored. |
|
439 * It is only used while scrolling the view using scrollbar, |
|
440 * in such situation the scroll events that this object receives |
|
441 * are ignored, and actual scrolling is done only when |
|
442 * iRedrawTimer completes. |
|
443 */ |
|
444 TInt iSkippedScrollbarEventsCount; |
|
445 |
|
446 /** |
|
447 * A timer that initiates redraws at certain time intervals. |
|
448 * It is used to refresh the view while scrolling with |
|
449 * the scrollbar. |
|
450 */ |
|
451 CPeriodic* iRedrawTimer; |
|
452 }; |
|
453 |
|
454 #endif // MMLISTBOX_H |
|