|
1 /* |
|
2 * Copyright (c) 2009 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: Taskswitcher Fast Swap area UI |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef TSFASTSWAPGRID_H_ |
|
20 #define TSFASTSWAPGRID_H_ |
|
21 |
|
22 #include <AknGrid.h> |
|
23 #include <aknconsts.h> |
|
24 #include "tsdevicestate.h" |
|
25 |
|
26 class CAknsFrameBackgroundControlContext; |
|
27 class CTsFastSwapTimer; |
|
28 |
|
29 /** |
|
30 * Observer for handling fast swap grid events |
|
31 */ |
|
32 class MTsFastSwapGridObserver |
|
33 { |
|
34 public: |
|
35 /** |
|
36 * Called when close icon is tapped on the grid item. |
|
37 * |
|
38 * @param aItemIdx index of the the item for which close icon |
|
39 * has been tapped |
|
40 */ |
|
41 virtual void HandleCloseEventL( TInt aItemIdx ) = 0; |
|
42 }; |
|
43 |
|
44 |
|
45 class MTsFastSwapTimerObserver |
|
46 { |
|
47 public: |
|
48 /** |
|
49 * Called when timer is completed |
|
50 */ |
|
51 virtual void TimerCompletedL( CTsFastSwapTimer* aSource ) = 0; |
|
52 }; |
|
53 |
|
54 |
|
55 /** |
|
56 * Avkon grid implementing custom item drawer |
|
57 */ |
|
58 class CTsFastSwapGrid: |
|
59 public CAknGrid, |
|
60 public MTsDeviceStateObserver, |
|
61 public MTsFastSwapTimerObserver |
|
62 { |
|
63 public: // enums |
|
64 enum TFastSwapGridBehaviour |
|
65 { |
|
66 // Highlight always visible |
|
67 EHybrid, |
|
68 |
|
69 // Touch only highlight handling |
|
70 ETouchOnly |
|
71 }; |
|
72 |
|
73 public: // Constructor and destructor |
|
74 CTsFastSwapGrid(); |
|
75 ~CTsFastSwapGrid(); |
|
76 void ConstructL( const CCoeControl* aParent ); |
|
77 |
|
78 public: // From CCoeControl |
|
79 void HandlePointerEventL( const TPointerEvent &aPointerEvent ); |
|
80 void HandleResourceChange( TInt aType ); |
|
81 void SizeChanged(); |
|
82 void Draw( const TRect& aRect ) const; |
|
83 |
|
84 public: //From MTsDeviceStateObserver |
|
85 /** |
|
86 * Called when a change, to which the observer is registered, |
|
87 * has happened. |
|
88 */ |
|
89 virtual void HandleDeviceStateChanged( TChangeType aChangeType ); |
|
90 |
|
91 public: // New functions |
|
92 |
|
93 /** |
|
94 * Sets fast swap grid observer |
|
95 */ |
|
96 void SetFastSwapGridObserver( MTsFastSwapGridObserver* aObserver ); |
|
97 |
|
98 /** |
|
99 * Set indexes of items which can be closed. |
|
100 * Copies item index array. |
|
101 */ |
|
102 void SetCloseItemsL( RArray<TInt>& aItemIndex ); |
|
103 |
|
104 /** |
|
105 * Checks if the item of given index is closable |
|
106 */ |
|
107 TBool CanCloseItem( TInt aItemIndex ); |
|
108 |
|
109 /** |
|
110 * Checks if the given item's close icon has been tapped. |
|
111 */ |
|
112 TBool IsItemCloseHit( TInt aItemIndex ); |
|
113 |
|
114 /** |
|
115 * Resets index of the item that has been close icon hit |
|
116 */ |
|
117 void ResetCloseHit(); |
|
118 |
|
119 /** |
|
120 * Sets color for the screenshot stroke. |
|
121 * |
|
122 * @param aColor color for the thumbnail |
|
123 * @param aHighlightedColor color for thumbnail when item is highlighted |
|
124 */ |
|
125 void SetStrokeColors( TRgb aColor, |
|
126 TRgb aHighlightedColor ); |
|
127 |
|
128 /** |
|
129 * Sets items for which stroke will be drawn |
|
130 * |
|
131 * @param aItemIndex array of item indexes for which stroke |
|
132 * is drawn |
|
133 */ |
|
134 void SetStrokeItemsL( RArray<TInt>& aItemIndex ); |
|
135 |
|
136 /** |
|
137 * Sets grid behaviour |
|
138 * |
|
139 * @param aBehaviour behaviour to be set |
|
140 */ |
|
141 void SetGridBehaviour( TFastSwapGridBehaviour aBehaviour ); |
|
142 |
|
143 /** |
|
144 * Getter for grid behaviour |
|
145 * |
|
146 * @return girds behaviour |
|
147 */ |
|
148 TFastSwapGridBehaviour GridBehaviour(); |
|
149 |
|
150 /** |
|
151 * Shows highlight. In touch only behaviour highlight |
|
152 * will be shown only for ammount of time. |
|
153 */ |
|
154 void ShowHighlight(); |
|
155 |
|
156 /** |
|
157 * Hides highlight. |
|
158 */ |
|
159 void HideHighlight(); |
|
160 |
|
161 /** |
|
162 * Checks if the highlight is currently visible. |
|
163 * |
|
164 * @return ETrue if highlight is visible |
|
165 * EFalse if highlight is not visible |
|
166 */ |
|
167 TBool IsHighlightVisible(); |
|
168 |
|
169 /** |
|
170 * Sets visible view, items outside of view will not be drawn |
|
171 */ |
|
172 void SetVisibleViewRect( const TRect aRect ); |
|
173 |
|
174 /** |
|
175 * Returns visible view. Items outside of visible rectangle are not drawn. |
|
176 */ |
|
177 TRect VisibleViewRect(); |
|
178 |
|
179 /** |
|
180 * Updates layout data for item drawer. Should be called when |
|
181 * layout maybe out of date |
|
182 */ |
|
183 void UpdateItemDrawerLayoutDataL(); |
|
184 |
|
185 /** |
|
186 * Enables/disables avkon event handling. |
|
187 * |
|
188 * @param aEnable if set to ETrue, pointer events will be forwarded |
|
189 * to CAknGrid base class if necessary. If set to EFalse, |
|
190 * no pointer events will be forwarded. |
|
191 */ |
|
192 void EnableAknEventHandling( TBool aEnable ); |
|
193 |
|
194 private: // From CAknGrid |
|
195 virtual void CreateItemDrawerL(); |
|
196 |
|
197 private: // From MTsFastSwapTimerObserver |
|
198 void TimerCompletedL( CTsFastSwapTimer* aSource ); |
|
199 |
|
200 private: // New functions |
|
201 |
|
202 /** |
|
203 * Loads close icon bitmap and mask |
|
204 */ |
|
205 void LoadCloseIconAndStrokeParams(); |
|
206 |
|
207 /** |
|
208 * Redraws grid and parent controls |
|
209 */ |
|
210 void Redraw(); |
|
211 |
|
212 private: // Data |
|
213 |
|
214 // Grid's parent |
|
215 const CCoeControl* iParent; |
|
216 |
|
217 // Close icon handling |
|
218 RArray<TInt> iCloseItems; |
|
219 TInt iCloseIconHitIdx; |
|
220 MTsFastSwapGridObserver* iFastSwapGridObserver; |
|
221 CTsFastSwapTimer* iCloseIconRedrawTimer; |
|
222 |
|
223 // Highlight handling |
|
224 TFastSwapGridBehaviour iBehaviour; |
|
225 TBool iHighlightVisible; |
|
226 |
|
227 // Visible view rectangle (horizontal scrolling support) |
|
228 TRect iVisibleViewRect; |
|
229 |
|
230 // Flag controlling input handling by grid |
|
231 TBool iAknEventHandlingEnabled; |
|
232 }; |
|
233 |
|
234 |
|
235 |
|
236 /** |
|
237 * Custom item drawer for drawing grid items |
|
238 */ |
|
239 class CTsGridItemDrawer: public CFormattedCellListBoxItemDrawer |
|
240 { |
|
241 |
|
242 public: // Constructor and destructor |
|
243 CTsGridItemDrawer( CTsFastSwapGrid* aGrid, |
|
244 CFormattedCellListBoxData* aData ); |
|
245 ~CTsGridItemDrawer(); |
|
246 |
|
247 public: // New functions |
|
248 |
|
249 /** |
|
250 * Sets close icon drawn for items that can be closed. |
|
251 * Ownership transferred. |
|
252 */ |
|
253 void SetCloseIcon( CFbsBitmap* aBmp, CFbsBitmap* aBmpMask, |
|
254 CFbsBitmap* aBmpPressed, CFbsBitmap* aBmpPressedMask ); |
|
255 |
|
256 /** |
|
257 * Initializes close icon rectangles. |
|
258 * |
|
259 * @param aButtonRect rectangle for the button, coordinates must be relative to the grid item |
|
260 * @param aIconRect rectangle for the icon, coordinates must be relative to the grid item |
|
261 */ |
|
262 void SetCloseIconRect( const TRect& aButtonRect, const TRect& aIconRect ); |
|
263 |
|
264 /** |
|
265 * Returns current close icon coordinates for the given item rectangle |
|
266 * |
|
267 * @param aItemRect rectangle of the item for which close button coordinates |
|
268 * are to be returned |
|
269 */ |
|
270 TRect GetCloseButtonRect( const TRect& aItemRect ) const; |
|
271 |
|
272 /** |
|
273 * Sets screen offset for the item drawer to not draw items on the |
|
274 * grid edges |
|
275 */ |
|
276 void SetEdgeOffset( TInt aLeftOffset, TInt aRightOffset ); |
|
277 |
|
278 /** |
|
279 * Enables/Disables item drawer background redrawing |
|
280 * |
|
281 * @param aEnable if set to ETrue, background will be redrawn by item drawer |
|
282 * if set to EFalse, background will not be redrawn |
|
283 */ |
|
284 void SetRedrawBackground( TBool aEnable ); |
|
285 |
|
286 /** |
|
287 * Sets color for the screenshot stroke. |
|
288 * |
|
289 * @param aColor color for the thumbnail |
|
290 * @param aHighlightedColor color for thumbnail when item is highlighted |
|
291 */ |
|
292 void SetStrokeColors( TRgb aNormalColor, |
|
293 TRgb aHighlightedColor ); |
|
294 |
|
295 /** |
|
296 * Sets items for which stroke will be drawn |
|
297 * |
|
298 * @param aItemIndex array of item indexes for which stroke |
|
299 * is drawn. |
|
300 */ |
|
301 void SetStrokeItemsL( RArray<TInt>& aItemIndex ); |
|
302 |
|
303 /** |
|
304 * Sets stroke offset and size: values must be relative |
|
305 * to item rectangle. |
|
306 * |
|
307 * @param aStrokeOffset offset of the stroke rectangle relative |
|
308 * to item rectangle |
|
309 * @param aStrokeSize size of the stroke rectangle |
|
310 */ |
|
311 void SetStrokeOffset( TPoint aStrokeOffset, TSize aStrokeSize ); |
|
312 |
|
313 /** |
|
314 * Set screen rectangle, used by the item drawer to determine |
|
315 * drawn area. |
|
316 * |
|
317 * @param aRect screen rectangle |
|
318 */ |
|
319 void SetScreenRect( TRect aRect ); |
|
320 |
|
321 private: // From CFormattedCellListBoxItemDrawer |
|
322 void DrawActualItem( TInt aItemIndex, const TRect& aActualItemRect, |
|
323 TBool aItemIsCurrent, TBool aViewIsEmphasized, |
|
324 TBool aViewIsDimmed, TBool aItemIsSelected ) const; |
|
325 private: // New functions |
|
326 /** |
|
327 * Checks if the item rectangle is visible in the view. |
|
328 * |
|
329 * @param aItemRect rectangle of the item to be checked |
|
330 * @return ETrue if rectangle is fully or partially visible |
|
331 * EFalse if rectangle is not visible |
|
332 */ |
|
333 TBool IsItemRectVisible( const TRect& aItemRect ) const; |
|
334 |
|
335 /** |
|
336 * Checks if the aRectContained rectancle is contained by aRectContainig |
|
337 * |
|
338 * @param aRectContained rectangle that is suppose to be contained |
|
339 * @param aRectContainig rectangle that is suppose to be containing |
|
340 * @return ETrue if rectangle is fully contained |
|
341 * EFalse if rectangle is not fully contained |
|
342 */ |
|
343 TBool IsRectContained(const TRect& aRectContained, |
|
344 const TRect& aRectContainig) const; |
|
345 |
|
346 /** |
|
347 * Calculates current inner button rectangle for close icon |
|
348 */ |
|
349 TRect CalculateInnerButtonRect( const TRect& aOuterRect ) const; |
|
350 |
|
351 private: // Data |
|
352 // Not owned |
|
353 CTsFastSwapGrid* iGrid; |
|
354 // Owned |
|
355 CFbsBitmap* iCloseIcon; |
|
356 CFbsBitmap* iCloseIconMask; |
|
357 CFbsBitmap* iCloseIconPressed; |
|
358 CFbsBitmap* iCloseIconPressedMask; |
|
359 |
|
360 TRect iScreenRect; |
|
361 TInt iLeftOffset; |
|
362 TInt iRightOffset; |
|
363 |
|
364 // Close button data |
|
365 TRect iCloseIconRect; |
|
366 TRect iCloseButtonRect; |
|
367 |
|
368 TBool iRedrawBackground; |
|
369 |
|
370 // Stroke data |
|
371 TRgb iStrokeColor; |
|
372 TRgb iHighlightStrokeColor; |
|
373 RArray<TInt> iStrokeItems; |
|
374 TRect iStrokeRect; |
|
375 }; |
|
376 |
|
377 |
|
378 |
|
379 /** |
|
380 * Timer class for handling highlight bevaiour |
|
381 */ |
|
382 class CTsFastSwapTimer : public CTimer |
|
383 { |
|
384 public: |
|
385 // Constructor |
|
386 CTsFastSwapTimer( MTsFastSwapTimerObserver& aObserver ); |
|
387 // Destructor |
|
388 ~CTsFastSwapTimer(); |
|
389 // 2nd phase constructor |
|
390 void ConstructL(); |
|
391 |
|
392 private: // From CTimer |
|
393 void RunL(); |
|
394 |
|
395 private: // Data |
|
396 MTsFastSwapTimerObserver* iObserver; // not own |
|
397 }; |
|
398 |
|
399 #endif /* TSFASTSWAPGRID_H_ */ |