|
1 /* |
|
2 * Copyright (c) 2008 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 #ifndef TSFASTSWAPAREA_H |
|
19 #define TSFASTSWAPAREA_H |
|
20 |
|
21 #include <e32base.h> |
|
22 #include <eikmobs.h> |
|
23 #include "tsdevicestate.h" |
|
24 #include "tsfswclientobserver.h" |
|
25 #include "tsfastswapgrid.h" |
|
26 #include "tseventcontrolerobserver.h" |
|
27 |
|
28 |
|
29 // FORWARD DECLARATIONS |
|
30 class CTsFswClient; |
|
31 class CTsFswEntry; |
|
32 class CAknStylusPopUpMenu; |
|
33 class CAknQueryDialog; |
|
34 class CTsEventControler; |
|
35 class MTsDataChangeObserver; |
|
36 class CAknLongTapAnimation; |
|
37 |
|
38 /** |
|
39 * Taskswitcher Fast Swap area UI. |
|
40 */ |
|
41 class CTsFastSwapArea: public CCoeControl, |
|
42 public MEikMenuObserver, |
|
43 public MTsFswObserver, |
|
44 public MEikListBoxObserver, |
|
45 public MTsFastSwapGridObserver, |
|
46 private MTsEventControlerObserver, |
|
47 public MTsDeviceStateObserver, |
|
48 public MTsFastSwapTimerObserver |
|
49 { |
|
50 public: |
|
51 /** |
|
52 * Two-phase constructor. |
|
53 * |
|
54 * @param aRect Area where fast swap info & list should draw itself. |
|
55 * @param aParent Parent CoeControl. |
|
56 */ |
|
57 static CTsFastSwapArea* NewL( const TRect& aRect, |
|
58 CCoeControl& aParent, CTsDeviceState& aDeviceState, |
|
59 CTsEventControler& aEventHandler); |
|
60 |
|
61 /** |
|
62 * @copydoc NewL |
|
63 */ |
|
64 static CTsFastSwapArea* NewLC( const TRect& aRect, |
|
65 CCoeControl& aParent, CTsDeviceState& aDeviceState, |
|
66 CTsEventControler& aEventHandler); |
|
67 |
|
68 /** |
|
69 * Destructor. |
|
70 */ |
|
71 ~CTsFastSwapArea(); |
|
72 |
|
73 /** |
|
74 * Called from appview when coming to foreground. |
|
75 */ |
|
76 void HandleSwitchToForegroundEvent(); |
|
77 |
|
78 /** |
|
79 * Called from appview when going to background. |
|
80 */ |
|
81 void HandleSwitchToBackgroundEvent(); |
|
82 |
|
83 /** |
|
84 * Called after construction to set up additional properties, |
|
85 * like the control observer. |
|
86 */ |
|
87 void Setup( MCoeControlObserver& aControlObserver ); |
|
88 |
|
89 /** |
|
90 * Saves the index of the currently selected (highlighted) item. |
|
91 */ |
|
92 void SaveSelectedIndex(); |
|
93 |
|
94 /** |
|
95 * Restores the selection (highlight) position. |
|
96 */ |
|
97 void RestoreSelectedIndex(); |
|
98 |
|
99 // Functions to perform activate, close, close others operations. |
|
100 // They are public so same functionality can be implemented in the |
|
101 // Options menu (appui) for example. |
|
102 |
|
103 /** |
|
104 * Index of highlighted item or KErrNotFound. |
|
105 */ |
|
106 TInt SelectedIndex() const; |
|
107 |
|
108 /** |
|
109 * Brings the app corresponding to the item at given index into foreground. |
|
110 */ |
|
111 void SwitchToApp( TInt aIndex ); |
|
112 |
|
113 /** |
|
114 * Brings the app with the give Uid into foreground |
|
115 */ |
|
116 void SwitchToApp( const TUid& aUid ); |
|
117 |
|
118 /** |
|
119 * Sends close msg to given app. |
|
120 * @param aIndex index |
|
121 * @param aSuppressRendering content is not refreshed if ETrue |
|
122 */ |
|
123 void TryCloseAppL( TInt aIndex, TBool aSuppressRendering = EFalse ); |
|
124 |
|
125 /** |
|
126 * Tries to Close all applications that cn be closed |
|
127 */ |
|
128 void TryCloseAllL(); |
|
129 |
|
130 /** |
|
131 * True if it is allowed to ask the given app to close. |
|
132 * @param aIndex index |
|
133 */ |
|
134 TBool CanClose( TInt aIndex ) const; |
|
135 |
|
136 /** |
|
137 * @param aSelectedItem item for which pop up is shown |
|
138 * |
|
139 * @return ETrue, when number of closable apps is >= 2 or there is at least |
|
140 * one closable item and non closable item is selected. |
|
141 * @return EFalse, when number of closable apps is < 2. |
|
142 */ |
|
143 TBool CanCloseAll( TInt aSelectedItem ) const; |
|
144 |
|
145 /** |
|
146 * Returns the number of items in the list. |
|
147 */ |
|
148 TInt Count() const; |
|
149 |
|
150 /** |
|
151 * Returns the underlying Ganes control pointer. |
|
152 */ |
|
153 CCoeControl* GetChildControl() { return iGrid; } |
|
154 |
|
155 /** |
|
156 * Sets the data-changed observer. |
|
157 */ |
|
158 void SetDataChangeObserver( MTsDataChangeObserver* aDcObserver ); |
|
159 |
|
160 /* |
|
161 * Handling short/long app key. |
|
162 */ |
|
163 void HandleAppKey(TInt aType); |
|
164 |
|
165 private: |
|
166 |
|
167 /** |
|
168 * @copydoc NewL |
|
169 */ |
|
170 void ConstructL( const TRect& aRect ); |
|
171 |
|
172 /** |
|
173 * C++ constructor. |
|
174 */ |
|
175 CTsFastSwapArea(CCoeControl& aParent, |
|
176 CTsDeviceState& aDeviceState, |
|
177 CTsEventControler& aEventHandler); |
|
178 |
|
179 // From MEikListBoxObserver |
|
180 void HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType); |
|
181 |
|
182 public: |
|
183 /** |
|
184 * Implements drag gesture handling |
|
185 * @see MTsEventControlerObserver |
|
186 */ |
|
187 void MoveOffset(const TPoint&, TBool); |
|
188 |
|
189 /** |
|
190 * Implements tap gesture handling |
|
191 * @see MTsEventControlerObserver |
|
192 */ |
|
193 void TapL(const TPoint&); |
|
194 |
|
195 /** |
|
196 * Implements long tap gesture handling |
|
197 * @see MTsEventControlerObserver |
|
198 */ |
|
199 void LongTapL(const TPoint&); |
|
200 |
|
201 /** |
|
202 * Implements drag gesture handling |
|
203 * @see MTsEventControlerObserver |
|
204 */ |
|
205 void DragL(const AknTouchGestureFw::MAknTouchGestureFwDragEvent& aEvent); |
|
206 |
|
207 /** |
|
208 * Implements animation stop handling |
|
209 * @see MTsEventControlerObserver |
|
210 */ |
|
211 void Stop(); |
|
212 |
|
213 /** |
|
214 * Implements view position getter. Returns point in the middle of the |
|
215 * grid view window. |
|
216 * |
|
217 * @see MTsEventControlerObserver |
|
218 */ |
|
219 TPoint ViewPos()const; |
|
220 |
|
221 /** |
|
222 * Checks if the app with the given window group id is closing |
|
223 */ |
|
224 TBool IsAppClosing( TInt aWgId ); |
|
225 |
|
226 /** |
|
227 * Checks if app with the given window group id is present on taskswitcher |
|
228 * list. |
|
229 */ |
|
230 TBool WgOnTaskList( TInt aWgId ); |
|
231 |
|
232 public: |
|
233 // from CCoeControl |
|
234 TInt CountComponentControls() const; |
|
235 CCoeControl* ComponentControl(TInt aIndex) const; |
|
236 void FocusChanged( TDrawNow aDrawNow ); |
|
237 void SizeChanged(); |
|
238 void Draw( const TRect& aRect ) const; |
|
239 TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ); |
|
240 void HandlePointerEventL( const TPointerEvent& aPointerEvent ); |
|
241 |
|
242 private: |
|
243 // From MTsFswObserver |
|
244 void HandleFswContentChanged(); |
|
245 |
|
246 // From MEikMenuObserver |
|
247 void ProcessCommandL( TInt aCommandId ); |
|
248 void SetEmphasis( CCoeControl*, TBool ) { } |
|
249 |
|
250 // From MTsFastSwapGridObserver |
|
251 void HandleCloseEventL(TInt aItemIdx); |
|
252 |
|
253 // From MTsDeviceStateObserver |
|
254 void HandleDeviceStateChanged( TChangeType aChangeType ); |
|
255 |
|
256 // From MTsFastSwapTimerObserver |
|
257 void TimerCompletedL( CTsFastSwapTimer* aSource ); |
|
258 |
|
259 // new functions |
|
260 |
|
261 /** |
|
262 * Switches to another application. |
|
263 */ |
|
264 void SwitchToApp( TInt aWgId, const TUid& aUid ); |
|
265 |
|
266 /** |
|
267 * Makes a copy of the given bitmap. |
|
268 * Also scaled to the given size, but maintains aspect ratio, |
|
269 * so the size of the returned bitmap may be less then aSize. |
|
270 */ |
|
271 CFbsBitmap* CopyBitmapL( TInt aFbsHandle, TSize aSize ); |
|
272 |
|
273 /** |
|
274 * Called from HandleFswContentChanged. |
|
275 */ |
|
276 void HandleFswContentChangedL(); |
|
277 |
|
278 /** |
|
279 * Shows the content from iArray on the screen. |
|
280 */ |
|
281 void RenderContentL( TBool aSuppressAnimation = EFalse ); |
|
282 |
|
283 /** |
|
284 * Creates the ganes grid control. |
|
285 */ |
|
286 void ReCreateGridL(); |
|
287 |
|
288 /** |
|
289 * Setup grid layout |
|
290 */ |
|
291 void LayoutGridL(); |
|
292 |
|
293 /** |
|
294 * Setup grid layout for view |
|
295 * |
|
296 * @param aItemCount number of items in grid |
|
297 */ |
|
298 void LayoutGridViewL( TInt aItemCount ); |
|
299 |
|
300 /** |
|
301 * Returns rectangles for fast swap area controls |
|
302 */ |
|
303 void GetFastSwapAreaRects( RArray<TAknLayoutRect>& aRects ); |
|
304 |
|
305 /** |
|
306 * Creates a stylus popup instance (iPopup) if not yet done. |
|
307 */ |
|
308 void PreCreatePopupL(); |
|
309 |
|
310 /** |
|
311 * Shows the stylus popup menu if not yet visible. |
|
312 * @param aIndex index of item in the grid |
|
313 * @param aPoint position for the popup |
|
314 */ |
|
315 TBool ShowPopupL( TInt aIndex, const TPoint& aPoint ); |
|
316 |
|
317 /** |
|
318 * Sends the data-changed notification. |
|
319 */ |
|
320 void NotifyChange(); |
|
321 |
|
322 /** |
|
323 * Retrieves and returns size for image graphics. |
|
324 */ |
|
325 TSize PreferredImageSize(); |
|
326 |
|
327 /** |
|
328 * Retrieves number of items in grid |
|
329 */ |
|
330 TInt GridItemCount(); |
|
331 |
|
332 /** |
|
333 * Calculates the correct size if aspect ratio needs to be preserved. |
|
334 */ |
|
335 TSize CalculateSizePreserveRatio(const TSize& aTargetAreaSize, |
|
336 const TSize& aSourceSize); |
|
337 |
|
338 /** |
|
339 * Selects next item in grid |
|
340 */ |
|
341 void SelectNextItem(); |
|
342 |
|
343 /** |
|
344 * Centralise most centered item so it was most exposed on the view. |
|
345 * Centered element is being selected by grid. |
|
346 * Animation to the centered element is made after aRedrawDelay time. |
|
347 * |
|
348 * @param aRedrawDelay - animation delay. |
|
349 */ |
|
350 void CenterItem( TInt aRedrawDelay); |
|
351 |
|
352 /** |
|
353 * Returns full grid view size. |
|
354 */ |
|
355 TSize GridWorldSize(); |
|
356 |
|
357 /** |
|
358 * Updates grid, called for manual grid scroll update |
|
359 * |
|
360 * @param aForceRedraw if set to ETrue - redraw will be forced |
|
361 * @param aAnimate set to ETrue to enable animation |
|
362 */ |
|
363 void UpdateGrid( TBool aForceRedraw = EFalse, |
|
364 TBool aAnimate = ETrue ); |
|
365 |
|
366 /** |
|
367 * Returns grid view size |
|
368 */ |
|
369 TSize ViewSize(); |
|
370 |
|
371 /** |
|
372 * Returns the position of the given item inside grid world rect. |
|
373 * Returns point in the middle of the view rectangle. |
|
374 * |
|
375 * @param aItemIdx index of the item for which calculation will be done |
|
376 */ |
|
377 TPoint ItemViewPosition( TInt aItemIdx ); |
|
378 |
|
379 /** |
|
380 * Returns index of the shown item, based on the logical |
|
381 * position of the grids view. Item that is closest to the |
|
382 * middle of screen is returned. |
|
383 * |
|
384 * @param aViewPos grids view position. This must be point in |
|
385 * the middle of the view rectangle |
|
386 * @return index of the item |
|
387 */ |
|
388 TInt ViewToVisibleItem( const TPoint aViewPos ); |
|
389 |
|
390 /** |
|
391 * Launches increasing pop-up feedback. |
|
392 */ |
|
393 void LaunchPopupFeedback(); |
|
394 |
|
395 /** |
|
396 * Show highlight when disabled and |
|
397 * consume EEventKeyUp that follows after event that swiched on the highlight. |
|
398 */ |
|
399 TKeyResponse ShowHighlightOnKeyEvent(const TKeyEvent& aKeyEvent, TEventCode aType); |
|
400 |
|
401 /** |
|
402 * Returns current screen orientation: |
|
403 * |
|
404 * @return 1 if landscape, 0 if portait |
|
405 */ |
|
406 TInt GetCurrentScreenOrientation(); |
|
407 |
|
408 /** |
|
409 * Retrieves variety value, based on current screen resolution. |
|
410 * |
|
411 * @param aVariety result of the function, 0 value means portrait |
|
412 * value of 1 indicates landscape |
|
413 * @return ETrue if screen resolution differs from vale returned by |
|
414 * layout meta data functions. |
|
415 */ |
|
416 TBool GetVariety( TInt& aVariety ); |
|
417 |
|
418 /** |
|
419 * Cancels long tap animation. |
|
420 */ |
|
421 void CancelLongTapAnimation( TBool aDisablePopup = ETrue ); |
|
422 |
|
423 /** |
|
424 * Checks if long tap animation should be shown in |
|
425 * a given point. |
|
426 * |
|
427 * @param aHitPoint point where tapped event is registered |
|
428 * @return ETrue if long animation is allowed for that position |
|
429 */ |
|
430 TBool LongTapAnimForPos( const TPoint& aHitPoint ); |
|
431 |
|
432 private: // Data |
|
433 |
|
434 // parent control |
|
435 CCoeControl& iParent; |
|
436 |
|
437 // device state |
|
438 // not own |
|
439 CTsDeviceState& iDeviceState; |
|
440 |
|
441 // grid, own |
|
442 CTsFastSwapGrid* iGrid; |
|
443 |
|
444 // fsw client, own |
|
445 CTsFswClient* iFSClient; |
|
446 // fsw content, ptrs owned |
|
447 RPointerArray<CTsFswEntry> iArray; |
|
448 |
|
449 // index of selected (highlighted) item in the grid |
|
450 // when the fsw was last focused |
|
451 TInt iSavedSelectedIndex; |
|
452 |
|
453 // fsw popup (activate, close, etc.), own |
|
454 CAknStylusPopUpMenu* iPopup; |
|
455 // the aIndex argument of ShowPopupL is stored here |
|
456 TInt iAppIndexForPopup; |
|
457 |
|
458 // Observer ptr, may be NULL, not owned |
|
459 MTsDataChangeObserver* iDcObserver; |
|
460 |
|
461 //Input events handler |
|
462 CTsEventControler& iEvtHandler; |
|
463 |
|
464 TInt iMaxItemsOnScreen; |
|
465 |
|
466 // Tap event |
|
467 TPointerEvent iTapEvent; |
|
468 CTsFastSwapTimer* iHighlightTimer; |
|
469 TPoint iActivateOnPointerRelease; |
|
470 TBool iHandlePointerCandidate; |
|
471 |
|
472 // View offset position, used by animation physics |
|
473 TInt iLogicalViewPosOffset; |
|
474 |
|
475 // Grid scrolling |
|
476 TInt iGridItemWidth; |
|
477 TInt iGridItemGap; |
|
478 |
|
479 CTsFastSwapTimer* iRedrawTimer; // owned |
|
480 CTsFastSwapTimer* iUpdateGridTimer;//owned |
|
481 CTsFastSwapTimer* iOrientationSignalTimer; // owned |
|
482 TInt iPrevScreenOrientation; |
|
483 TBool iIgnoreLayoutSwitch; |
|
484 |
|
485 // Key event handling |
|
486 TBool iConsumeEvent; |
|
487 TBool iKeyEvent; |
|
488 |
|
489 // App closing handling |
|
490 RArray<TInt> iIsClosing; |
|
491 TInt iWidgetClosingCount; |
|
492 TInt iPrevAppCount; |
|
493 |
|
494 // Long tap animation |
|
495 CAknLongTapAnimation* iLongTapAnimation; |
|
496 CTsFastSwapTimer* iLongTapAnimationTimer; |
|
497 TBool iLongTapAnimationRunning; |
|
498 }; |
|
499 |
|
500 #endif // TSFASTSWAPAREA_H |