|
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: Xuikon control adapter header file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __XNCONTROLADAPTERIMPL_H__ |
|
20 #define __XNCONTROLADAPTERIMPL_H__ |
|
21 |
|
22 // System includes |
|
23 #include <e32base.h> |
|
24 #include <coecntrl.h> |
|
25 #include <AknIconUtils.h> |
|
26 #include <AknsEffectAnim.h> |
|
27 #include <AknsItemID.h> |
|
28 #include <akntouchgesturefw.h> |
|
29 |
|
30 // Forward declarations |
|
31 class CXnNodePluginIf; |
|
32 class CXnComponent; |
|
33 class CWindowGc; |
|
34 class CXnControlAdapter; |
|
35 class CXnNode; |
|
36 class CXnProperty; |
|
37 class CGulIcon; |
|
38 class CXnUiEngine; |
|
39 class CAknPointerEventSuppressor; |
|
40 |
|
41 //Constants |
|
42 _LIT( KMif, "mif(" ); |
|
43 _LIT8( KMenuBarNode, "menubar" ); |
|
44 const TInt KSpaceChar = 32; |
|
45 const TInt KRightParenthesis = ')'; |
|
46 |
|
47 using namespace AknTouchGestureFw; |
|
48 // Class declaration |
|
49 |
|
50 /** |
|
51 * Control adapter class implementation. |
|
52 * |
|
53 * @ingroup group_xnlayoutengine |
|
54 * @lib xn3layoutengine.lib |
|
55 * @since Series 60 3.1 |
|
56 */ |
|
57 NONSHARABLE_CLASS( CXnControlAdapterImpl ) : public CBase, |
|
58 public MAknsEffectAnimObserver, |
|
59 public MAknTouchGestureFwObserver |
|
60 { |
|
61 public: |
|
62 |
|
63 /** |
|
64 * Response of property change handled/not handled |
|
65 */ |
|
66 enum TPropertyChangeResponse |
|
67 { |
|
68 /** The property change was not handled. */ |
|
69 EPropertyChangeNotConsumed, |
|
70 /** The property change was handled. */ |
|
71 EPropertyChangeConsumed |
|
72 }; |
|
73 |
|
74 public: |
|
75 |
|
76 /** |
|
77 * Icon provider used by AknIconUtils |
|
78 * |
|
79 * @since Series 60 3.1 |
|
80 */ |
|
81 class TIconProvider : public MAknIconFileProvider |
|
82 { |
|
83 public: |
|
84 /** |
|
85 * Constructor |
|
86 * |
|
87 * @param aFile File handle to use |
|
88 */ |
|
89 TIconProvider( RFile& aFile ); |
|
90 |
|
91 public: |
|
92 |
|
93 /** |
|
94 * Destructor. |
|
95 */ |
|
96 virtual ~TIconProvider(); |
|
97 |
|
98 // Functions from base classes |
|
99 /** |
|
100 * From MAknIconFileProvider Returns an open file handle to the icon |
|
101 * file. |
|
102 * This method should leave if an icon file with specified type does |
|
103 * not exist. That may be the case e.g. with MBM file, |
|
104 * if there are no bitmap icons. |
|
105 * |
|
106 * Note! RFs::ShareProtected must be called to the RFs instance used |
|
107 * for opening the file. |
|
108 * |
|
109 * @param aFile Icon file should be opened in this file handle, which |
|
110 * is an empty file handle, when the AknIcon framework calls this |
|
111 * method. The AknIcon framework takes care of closing the file handle |
|
112 * after having used it. |
|
113 * |
|
114 * @param aType Icon file type. |
|
115 */ |
|
116 virtual void RetrieveIconFileHandleL( RFile& aFile, |
|
117 const TIconFileType /*aType*/); |
|
118 |
|
119 /** |
|
120 * From MAknIconFileProvider With this method, AknIcon framework |
|
121 * informs that it does not use this MAknIconFileProvider instance |
|
122 * any more. After this call, |
|
123 * it is ok to delete the object. This can be implemented simply |
|
124 * e.g. by deleting self in this callback. |
|
125 * Normally, this callback is invoked when the icon in question |
|
126 * is deleted. |
|
127 * Note, however, that if the same MAknIconFileProvider instance is |
|
128 * supplied in multiple CreateIcon calls, then it must be accessible |
|
129 * by AknIcon framework until it has signalled a matching amount |
|
130 * of these callbacks. |
|
131 */ |
|
132 virtual void Finished(); |
|
133 |
|
134 private: |
|
135 |
|
136 // file to use |
|
137 RFile iFile; |
|
138 }; |
|
139 |
|
140 public: |
|
141 // Constructors and destructor |
|
142 |
|
143 /** |
|
144 * Two-phased constructor. |
|
145 * |
|
146 * @param aNode |
|
147 * @param aDadapter Control adapter |
|
148 * @param gc Window gc |
|
149 */ |
|
150 static CXnControlAdapterImpl* NewL( CXnNodePluginIf& aNode, |
|
151 CXnControlAdapter& aAdapter, CWindowGc& gc ); |
|
152 |
|
153 /** |
|
154 * Destructor. |
|
155 */ |
|
156 virtual ~CXnControlAdapterImpl(); |
|
157 |
|
158 public: |
|
159 // New functions |
|
160 |
|
161 /** |
|
162 * Sets component pointer. |
|
163 * |
|
164 * @since Series 60 3.1 |
|
165 * @param aComponent Component pointer. |
|
166 */ |
|
167 void SetComponent( CXnComponent* aComponent ); |
|
168 |
|
169 /** |
|
170 * Gets the component pointer. |
|
171 * |
|
172 * @since Series 60 3.1 |
|
173 * @return Component pointer. |
|
174 */ |
|
175 CXnComponent* Component(); |
|
176 |
|
177 /** |
|
178 * Const-version of getting the component pointer. |
|
179 * |
|
180 * @since Series 60 3.1 |
|
181 * @return Component pointer. |
|
182 */ |
|
183 CXnComponent* Component() const; |
|
184 |
|
185 /** |
|
186 * Add a child adapter |
|
187 * |
|
188 * @since Series 60 3.1 |
|
189 * @param aChild Child adapter |
|
190 */ |
|
191 void AppendChildL(CXnControlAdapter& aChild, CXnNode& aNode); |
|
192 |
|
193 /** |
|
194 * Checks if the control should be drawn, according to visibility and |
|
195 * display properties. |
|
196 * |
|
197 * @since Series 60 3.1 |
|
198 * @return ETrue if drawing is ok, EFalse otherwise |
|
199 */ |
|
200 TBool IsDrawingAllowed() const; |
|
201 |
|
202 /** |
|
203 * Gets content bitmaps. Ownership is not transferred. |
|
204 * |
|
205 * @since Series 60 3.1 |
|
206 * @param aBitmap Bitmap to draw |
|
207 * @param aMask Mask to use |
|
208 */ |
|
209 void ContentBitmaps( CFbsBitmap*& aBitmap, CFbsBitmap*& aMask ); |
|
210 |
|
211 /** |
|
212 * Sets content bitmaps. Ownership is transferred. |
|
213 * |
|
214 * @since Series 60 3.1 |
|
215 * @param aBitmap Bitmap to draw |
|
216 * @param aMask Mask to use |
|
217 */ |
|
218 void SetContentBitmaps( CFbsBitmap* aBitmap, CFbsBitmap* aMask ); |
|
219 |
|
220 /** |
|
221 * Sets content bitmaps. Ownership is transferred. |
|
222 * |
|
223 * @since Series 60 3.1 |
|
224 * @param aBitmapUrl Url of the bitmap to draw |
|
225 * @param aMaskUrl Url of the bitmap mask to use |
|
226 */ |
|
227 void SetContentBitmapsL( const TDesC& aBitmapUrl, const TDesC& aMaskUrl ); |
|
228 |
|
229 /** |
|
230 * Load a bitmap from the server. Ownership is transferred. |
|
231 * |
|
232 * @since Series 60 3.1 |
|
233 * @param aBitmapUrl Url of the bitmap to load |
|
234 * @return Bitmap |
|
235 */ |
|
236 CFbsBitmap* LoadBitmap( const TDesC& aBitmapUrl ); |
|
237 |
|
238 /** |
|
239 * Load a bitmap and mask from the server. Ownership is transferred. |
|
240 * |
|
241 * @since Series 60 3.1 |
|
242 * @param aBitmapUrl Url of the bitmap to load |
|
243 * @param aMaskUrl Url of the mask to load, if any |
|
244 * @param aBitmap Fetched bitmap |
|
245 * @param aMask Fetched mask |
|
246 * @return void |
|
247 */ |
|
248 void GetBitmapAndMask( const TDesC& aBitmapUrl, const TDesC& aMaskUrl, |
|
249 CFbsBitmap*& aBitmap, CFbsBitmap*& aMask ); |
|
250 |
|
251 /** |
|
252 * Handles pointer events |
|
253 * This method must always be called, even when it's overridden by derived |
|
254 * classes |
|
255 * |
|
256 * @param aPointerEvent pointer event |
|
257 */ |
|
258 TBool HandlePointerEventL( const TPointerEvent& aPointerEvent ); |
|
259 |
|
260 /** |
|
261 * Draws the control |
|
262 * This method must always be called, even when it's overridden by derived |
|
263 * classes |
|
264 * |
|
265 * @param aRect TRect to draw |
|
266 */ |
|
267 void Draw( const TRect& aRect ) const; |
|
268 |
|
269 /** |
|
270 * Draws the control using a client-specified gc. |
|
271 * |
|
272 * @param aRect TRect to draw |
|
273 * @param aGc Gc used for drawing |
|
274 */ |
|
275 void Draw( const TRect& aRect, CWindowGc& aGc ) const; |
|
276 |
|
277 /** |
|
278 * Return a child control by index |
|
279 * This method must not be overridden by derived classes |
|
280 * |
|
281 * @param aIndex Index of the child to return |
|
282 * @return Control at the given index |
|
283 */ |
|
284 CCoeControl* ComponentControl( TInt aIndex ) const; |
|
285 |
|
286 /** |
|
287 * From CCoeControl Return count of children |
|
288 * This method must not be overridden by derived classes |
|
289 * |
|
290 * @return Count of children |
|
291 */ |
|
292 TInt CountComponentControls() const; |
|
293 |
|
294 /** |
|
295 * Draws content image. |
|
296 * |
|
297 * @since Series 60 3.1 |
|
298 */ |
|
299 void DrawContentImage() const; |
|
300 |
|
301 /** |
|
302 * Draws content image. |
|
303 * |
|
304 * @param aGc Gc used for drawing |
|
305 * @since Series 60 3.1 |
|
306 */ |
|
307 void DrawContentImageL( CWindowGc& aGc ) const; |
|
308 |
|
309 /** |
|
310 * Size change notification |
|
311 */ |
|
312 void SizeChanged(); |
|
313 |
|
314 /** |
|
315 * Skin change notification |
|
316 */ |
|
317 void SkinChanged(); |
|
318 |
|
319 /** |
|
320 * Focus changed notification |
|
321 * |
|
322 * @since S60 5.0 |
|
323 * @param aFocused Control's current foucs state |
|
324 */ |
|
325 void FocusChangedL( TBool aFocused ); |
|
326 |
|
327 /** |
|
328 * Initialize or refresh background and border bitmaps |
|
329 * This is called when for example the skin or control size is changed |
|
330 */ |
|
331 void InitializeBackgroundAndBorderBitmapsL( TBool aForceRecreate = EFalse ); |
|
332 |
|
333 /** |
|
334 * This is called to measure adaptive content dimensions. |
|
335 * |
|
336 * @since 3.2 |
|
337 * @param aAvailableSize Not used |
|
338 * @return For now it returns default size - zero |
|
339 */ |
|
340 TSize MeasureAdaptiveContentL( const TSize& aAvailableSize ); |
|
341 |
|
342 /** |
|
343 * Sets the control blank |
|
344 * |
|
345 * @since S60 5.1 |
|
346 * @param aBlank, ETrue sets blank, EFalse resets blank |
|
347 */ |
|
348 void SetBlank( TBool aBlank ); |
|
349 |
|
350 /** |
|
351 * Creates trigger node for swipe event |
|
352 * |
|
353 * @since S60 5.1 |
|
354 * @param aUiEngine reference to uiengine |
|
355 * @param aDirection Direction of swipe |
|
356 * @return trigger node for swipe |
|
357 */ |
|
358 CXnNode* BuildSwipeTriggerNodeLC( CXnUiEngine& aUiEngine, |
|
359 const TDesC8& aDirection ); |
|
360 |
|
361 public: |
|
362 // Functions from base classes |
|
363 |
|
364 /** |
|
365 * From CCoeControl Handles key events. |
|
366 * |
|
367 * @since Series 60 3.1 |
|
368 * @param aKeyEvent Key event. |
|
369 * @param aType Event type. |
|
370 * @return Key response |
|
371 */ |
|
372 TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent, |
|
373 TEventCode aType ); |
|
374 |
|
375 /** |
|
376 * From MAknLongTapDetectorCallBack. Handles the long tap events. |
|
377 * |
|
378 * @since Series 60 3.1 |
|
379 * @param aPenEventLocation Long tap event location relative to parent |
|
380 * control. |
|
381 * @param aPenEventScreenLocation Long tap event location relative to |
|
382 * screen. |
|
383 */ |
|
384 void HandleLongTapEventL( const TPoint& aPenEventLocation, |
|
385 const TPoint& aPenEventScreenLocation ); |
|
386 |
|
387 /** |
|
388 * Creates highlight animation from a skin id when one is available. |
|
389 */ |
|
390 void CreateAnimationL(); |
|
391 |
|
392 /** |
|
393 * MAknsEffectAnimObserver callback. Draws the adapter again and renders |
|
394 * the animated area. |
|
395 * |
|
396 * @param aError Error - zero if error, nonzero otherwise |
|
397 */ |
|
398 virtual void AnimFrameReady( TInt aError, TInt ); |
|
399 |
|
400 /** |
|
401 * Starts highlight animation. |
|
402 * |
|
403 * @param aAnimRestart When true, the animation is stopped and then |
|
404 * started again. |
|
405 */ |
|
406 void StartHighlightAnimation( TBool aAnimRestart = EFalse ); |
|
407 |
|
408 /** |
|
409 * Stops highlight animation. |
|
410 */ |
|
411 void StopHighlightAnimation(); |
|
412 |
|
413 /** |
|
414 * Handles property change |
|
415 */ |
|
416 void DoHandlePropertyChangeL( CXnProperty* aProperty = NULL ); |
|
417 |
|
418 /** |
|
419 * Handles change of device screen |
|
420 */ |
|
421 void HandleScreenDeviceChangedL(); |
|
422 |
|
423 /** |
|
424 * Updates background image |
|
425 * |
|
426 * @param aProperty If it is background image, initializes background |
|
427 * bitmap |
|
428 * @return CXnControlAdapterImpl::TPropertyChangeResponse whether it was |
|
429 * consumed |
|
430 */ |
|
431 CXnControlAdapterImpl::TPropertyChangeResponse UpdateBackgroundImageL( |
|
432 CXnProperty* aProperty ); |
|
433 |
|
434 /** |
|
435 * Sets up gesture on buttondown event |
|
436 * |
|
437 * @param aPointerEvent Event to be forwarded |
|
438 */ |
|
439 void InitializeGestureL( |
|
440 const TPointerEvent& aPointerEvent ); |
|
441 |
|
442 /* |
|
443 * Resets child adapters |
|
444 */ |
|
445 void RemoveChildAdapters(); |
|
446 |
|
447 /* |
|
448 * Returns Child adapters |
|
449 * |
|
450 * @return Returns child adapters |
|
451 */ |
|
452 RPointerArray< CXnControlAdapter >& ChildAdapters(); |
|
453 |
|
454 private: // from MAknTouchGestureFwObserver |
|
455 /** |
|
456 * Implements gesture handling |
|
457 * |
|
458 * @see MAknTouchGestureFwObserver |
|
459 */ |
|
460 void HandleTouchGestureL( MAknTouchGestureFwEvent& aEvent ); |
|
461 |
|
462 protected: |
|
463 // New functions |
|
464 |
|
465 /** |
|
466 * C++ default constructor. |
|
467 */ |
|
468 CXnControlAdapterImpl( CXnNodePluginIf& aNode ); |
|
469 |
|
470 /** |
|
471 * Two-phased constructor. |
|
472 */ |
|
473 void ConstructL( CXnNodePluginIf& aNode, CXnControlAdapter& aAdapter, |
|
474 CWindowGc& gc ); |
|
475 |
|
476 private: |
|
477 void DoDrawL( const TRect& aRect, CWindowGc& aGc ) const; |
|
478 void DrawBackgroundDataL( const TRect& aRect, CXnNode& aNode, |
|
479 CWindowGc& aGc ); |
|
480 void DrawEditModeBgData( CXnNode& aNode, CWindowGc& aGc ); |
|
481 void DrawPlusSign( CXnNode& aNode, CWindowGc& aGc ); |
|
482 void DrawTransparentColorL( CXnNode& aNode, CWindowGc& aGc, |
|
483 CFbsBitmap* aMask ); |
|
484 void DrawBackgroundSkinL( CXnNode& aNode, CFbsBitmap* aMask, |
|
485 CWindowGc& aGc,CXnProperty* aBgColor, TRect aRect = TRect::EUninitialized ); |
|
486 void DrawBackgroundSkin(const TAknsItemID& aSkinId, CWindowGc& aGc, |
|
487 TRect aRect ); |
|
488 void DrawBackgroundImageL( const TRect& aRect, CXnNode& aNode, |
|
489 CWindowGc& aGc, CFbsBitmap* aBitmap, CFbsBitmap* aMask ); |
|
490 RFs& FsSession(); |
|
491 TBool IsDragThresholdExceeded( const TPoint& aPoint ); |
|
492 |
|
493 private: |
|
494 // Data |
|
495 |
|
496 /** Node */ |
|
497 CXnNodePluginIf& iNode; |
|
498 /** Pointer to component base object. */ |
|
499 CXnComponent* iComponent; |
|
500 /** child controls */ |
|
501 mutable RPointerArray< CXnControlAdapter > iChildren; |
|
502 /** content image */ |
|
503 mutable CFbsBitmap* iContentBitmap; |
|
504 /** content bitmap index */ |
|
505 mutable TInt iContentBitmapIndex; |
|
506 /** content mask */ |
|
507 mutable CFbsBitmap* iContentMask; |
|
508 /** content mask index */ |
|
509 mutable TInt iContentMaskIndex; |
|
510 /** background image */ |
|
511 mutable CFbsBitmap* iBackgroundBitmap; |
|
512 /** background mask */ |
|
513 mutable CFbsBitmap* iBackgroundMask; |
|
514 /** background image index */ |
|
515 mutable TInt iBackgroundBitmapIndex; |
|
516 /** border image */ |
|
517 mutable CFbsBitmap* iBorderBitmap; |
|
518 /** border image index */ |
|
519 mutable TInt iBorderBitmapIndex; |
|
520 /** border image split value for top border */ |
|
521 mutable TInt iBorderBitmapDividerTop; |
|
522 /** border image split value for right border */ |
|
523 mutable TInt iBorderBitmapDividerRight; |
|
524 /** border image split value for bottom border */ |
|
525 mutable TInt iBorderBitmapDividerBottom; |
|
526 /** border image split value for left border */ |
|
527 mutable TInt iBorderBitmapDividerLeft; |
|
528 /** graphics context */ |
|
529 mutable CWindowGc* iGc; |
|
530 /** control adapter */ |
|
531 mutable CXnControlAdapter* iAdapter; |
|
532 /** icon provider, for AknIconUtils */ |
|
533 mutable TIconProvider* iIconProvider; |
|
534 |
|
535 /** skin animation object for skin highlight animation */ |
|
536 CAknsEffectAnim* iAnimation; |
|
537 /** skin animation identifier */ |
|
538 TAknsItemID iAnimIID; |
|
539 /** flag: skin animation id is resolved from the CSS property */ |
|
540 TBool iAnimIDResolved; |
|
541 /** flag: for storing blank state */ |
|
542 TBool iBlank; |
|
543 /** flag: to detect whether longtap occured */ |
|
544 TBool iLongtap; |
|
545 /** Gesture framework, owned. */ |
|
546 CAknTouchGestureFw* iGestureFw; |
|
547 /** Gesture destination, Not owned. */ |
|
548 CXnNode* iGestureDestination; |
|
549 /** Starting point of button down event. */ |
|
550 TPoint iButtonDownStartPoint; |
|
551 /** Tells is background images are allready created*/ |
|
552 TBool iBackgrondInitialized; |
|
553 /** Tells is border images are allready created*/ |
|
554 TBool iBorderInitialized; |
|
555 /** Suppress drag events, owned */ |
|
556 CAknPointerEventSuppressor* iSuppressor; |
|
557 }; |
|
558 |
|
559 #endif //__XNCONTROLADAPTERIMPL_H__ |