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