idlehomescreen/xmluirendering/uiengine/src/xnfocuscontrol.cpp
branchRCL_3
changeset 83 5456b4e8b3a8
child 88 3321d3e205b6
equal deleted inserted replaced
82:5f0182e07bfb 83:5456b4e8b3a8
       
     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:  Focus appearance drawer
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <AknsDrawUtils.h>
       
    20 #include <AknsUtils.h>
       
    21 #include <AknsItemID.h>
       
    22 
       
    23 // User includes
       
    24 #include "xncontroladapter.h"
       
    25 #include "xnproperty.h"
       
    26 #include "xnappuiadapter.h"
       
    27 #include "xnuiengine.h"
       
    28 #include "xneditmode.h"
       
    29 #include "xnnode.h"
       
    30 #include "xninactivitymonitor.h"
       
    31 
       
    32 #include "xnfocuscontrol.h"
       
    33 
       
    34 // Constants
       
    35 const TInt KSkinGfxInnerRectShrink( 5 );
       
    36 
       
    37 // ============================ LOCAL FUNCTIONS ================================
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 // -----------------------------------------------------------------------------
       
    41 // CXnFocusControl::NewL()
       
    42 // Two-phased constructor.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CXnFocusControl* CXnFocusControl::NewL( CXnAppUiAdapter& aAppUiAdapter )
       
    46     {
       
    47     CXnFocusControl* self = CXnFocusControl::NewLC( aAppUiAdapter );
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CXnFocusControl::NewLC()
       
    54 // Two-phased constructor.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CXnFocusControl* CXnFocusControl::NewLC( CXnAppUiAdapter& aAppUiAdapter )
       
    58     {
       
    59     CXnFocusControl* self = new ( ELeave ) CXnFocusControl( aAppUiAdapter );
       
    60     CleanupStack::PushL( self );
       
    61     self->ConstructL();
       
    62     return self;
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CXnFocusControl::~CXnFocusControl()
       
    67 // C++ default destructor.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CXnFocusControl::~CXnFocusControl()
       
    71     {
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CXnFocusControl::CXnFocusControl()
       
    76 // C++ default constructor.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 CXnFocusControl::CXnFocusControl( CXnAppUiAdapter& aAppUiAdapter )
       
    80     : iAppUiAdapter( aAppUiAdapter )
       
    81     {    
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CXnFocusControl::ConstructL()
       
    86 // 2nd phase constructor
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CXnFocusControl::ConstructL()
       
    90     {   
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CXnFocusControl::MakeVisible()
       
    95 // 
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CXnFocusControl::MakeVisible( TBool aVisible )
       
    99     {
       
   100     TRAP_IGNORE( DoMakeVisibleL( aVisible ) );
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CXnFocusControl::DoMakeVisibleL()
       
   105 // 
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 void CXnFocusControl::DoMakeVisibleL( TBool aVisible )
       
   109     {
       
   110     if ( aVisible != iVisible )
       
   111         {
       
   112         if ( !aVisible )
       
   113             {
       
   114             iVisible = aVisible;
       
   115             
       
   116             iRefused = EFalse;
       
   117             
       
   118             CXnNode* node( iAppUiAdapter.UiEngine().FocusedNode() ); 
       
   119                                    
       
   120             if ( node )
       
   121                 {
       
   122                 node->HideTooltipsL();
       
   123                                     
       
   124                 CXnControlAdapter* control( node->Control() );
       
   125                 
       
   126                 if  ( control && control->RefusesFocusLoss() )
       
   127                     {
       
   128                     // Need to keep drawing focus appearance
       
   129                     iRefused = ETrue;
       
   130                     
       
   131                     node->UnsetStateL( 
       
   132                         XnPropertyNames::style::common::KPressedDown );
       
   133                     }
       
   134                 else
       
   135                     {
       
   136                     node->UnsetStateL(  
       
   137                         XnPropertyNames::style::common::KFocus );                    
       
   138                     }
       
   139                                 
       
   140                 iAppUiAdapter.UiEngine().RenderUIL();                
       
   141                 }    
       
   142             }
       
   143         else
       
   144             {
       
   145             iRefused = EFalse;
       
   146             
       
   147             iVisible = aVisible;
       
   148             }              
       
   149         }        
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CXnFocusControl::IsVisible()
       
   154 // 
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 TBool CXnFocusControl::IsVisible() const
       
   158     {
       
   159     return iVisible;
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CXnFocusControl::Draw()
       
   164 // 
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 void CXnFocusControl::Draw( const TRect& aRect, CWindowGc& aGc ) const
       
   168     {
       
   169     TInt state( iAppUiAdapter.UiEngine().EditMode()->EditState() );
       
   170             
       
   171     // Don't draw focus appearance when shooting dragging widget in edit mode
       
   172     if ( state == CXnEditMode::EShootContent )
       
   173         {
       
   174         return;
       
   175         }
       
   176     
       
   177     if ( IsVisible() || iRefused ) 
       
   178         {                                       
       
   179         CXnNode* node( iAppUiAdapter.UiEngine().FocusedNode() );
       
   180         
       
   181         if ( node )
       
   182             {            
       
   183             CXnProperty* prop( NULL );
       
   184             
       
   185             TRAP_IGNORE( prop = node->GetPropertyL( 
       
   186                 XnPropertyNames::common::KFocusAppearance ) );
       
   187                                             
       
   188             if ( prop && prop->StringValue() == XnPropertyNames::KNone )
       
   189                 {
       
   190                 // Current element refuses to draw focus appearance
       
   191                 return;
       
   192                 }
       
   193             
       
   194             TRect innerRect( aRect );            
       
   195             
       
   196             innerRect.Shrink( 
       
   197                 KSkinGfxInnerRectShrink, KSkinGfxInnerRectShrink );
       
   198             
       
   199             MAknsSkinInstance* skin( AknsUtils::SkinInstance() );
       
   200                  
       
   201             if ( node->IsStateSet( XnPropertyNames::style::common::KPressedDown ) )
       
   202                 {
       
   203                 AknsDrawUtils::DrawFrame( skin, aGc, aRect, innerRect,
       
   204                     KAknsIIDQsnFrHomePressed, KAknsIIDDefault );                
       
   205                 }            
       
   206             
       
   207             if ( node->IsStateSet( XnPropertyNames::style::common::KFocus ) )
       
   208                 {
       
   209                 AknsDrawUtils::DrawFrame( skin, aGc, aRect, innerRect, 
       
   210                     KAknsIIDQsnFrHome, KAknsIIDDefault );                
       
   211                 }            
       
   212             }       
       
   213         }
       
   214     }
       
   215 
       
   216 // End of file
       
   217