emailuis/emailui/src/ncscontrol.cpp
branchRCL_3
changeset 25 3533d4323edc
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Implementation of the CNcsEngine
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <AknsConstants.h>
       
    21 #include <AknsUtils.h>
       
    22 #include <AknsSkinInstance.h>
       
    23 #include <gulcolor.h>
       
    24 #include <eikdef.h>
       
    25 #include <AknUtils.h>
       
    26 
       
    27 #include "ncscontrol.h"
       
    28 #include "FreestyleEmailUiLayoutData.h"
       
    29 #include "ncsutility.h"
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // MNcsControl::MNcsControl
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 MNcsControl::MNcsControl( MNcsFieldSizeObserver* aObserver ) :
       
    36     iSizeObserver( aObserver )
       
    37     {
       
    38     FUNC_LOG;
       
    39     }
       
    40 
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // CNcsLabel::CNcsLabel
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 CNcsLabel::CNcsLabel( 
       
    47         const CCoeControl& aParent, 
       
    48         MNcsFieldSizeObserver* aSizeObserver ) :
       
    49     MNcsControl( aSizeObserver ), iParent( aParent )
       
    50     {
       
    51     FUNC_LOG;
       
    52     UpdateTextColor();
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CNcsLabel::Reposition
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 void CNcsLabel::Reposition( TPoint& aPt, TInt /*aWidth*/ )
       
    60     {
       
    61     FUNC_LOG;
       
    62     SetPosition( aPt );
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CNcsLabel::FocusChanged
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 void CNcsLabel::FocusChanged( TDrawNow aDrawNow )
       
    70     {
       
    71     FUNC_LOG;
       
    72     if( IsFocused() )
       
    73         {
       
    74         //Check if we need to reposition
       
    75         if (Rect().iTl.iY < 0) 
       
    76             {
       
    77             TPoint pt = TPoint(0,0);
       
    78             Reposition(pt,Rect().Width());
       
    79             if ( iSizeObserver )
       
    80                 {
       
    81                 iSizeObserver->UpdateFieldPosition(this);
       
    82                 }
       
    83             }
       
    84         }
       
    85     
       
    86     if( aDrawNow ) 
       
    87         {
       
    88         DrawNow();
       
    89         }
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CNcsLabel::HandleResourceChange
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 void CNcsLabel::HandleResourceChange( TInt aType )
       
    97     {
       
    98     FUNC_LOG;
       
    99     CEikLabel::HandleResourceChange( aType );
       
   100     if ( aType == KAknsMessageSkinChange ||
       
   101          aType == KEikMessageColorSchemeChange )
       
   102         {
       
   103         UpdateTextColor();
       
   104         }
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CNcsLabel::UpdateTextColor
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 void CNcsLabel::UpdateTextColor()
       
   112     {
       
   113     FUNC_LOG;
       
   114     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   115     TRgb newColor;
       
   116     
       
   117     TInt err = AknsUtils::GetCachedColor(
       
   118         skin,
       
   119         newColor,
       
   120         KAknsIIDFsTextColors,
       
   121         EAknsCIFsTextColorsCG8 );
       
   122     
       
   123     if ( err == KErrNone )
       
   124         {
       
   125         TRAP_IGNORE( OverrideColorL( EColorLabelText, newColor ) );
       
   126         }
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // CNcsLabel::LayoutLineCount
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 TInt CNcsLabel::LayoutLineCount() const
       
   134     {
       
   135     FUNC_LOG;
       
   136     return IsVisible() ? 1 : 0;
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // CNcsLabel::TextHitAreaRect
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 TRect CNcsLabel::TextHitAreaRect()
       
   144     {
       
   145     FUNC_LOG;
       
   146     TRect rect;
       
   147     if ( Font() && Text() )
       
   148         {
       
   149         rect = Rect();
       
   150         rect.SetWidth( Font()->TextWidthInPixels( *Text() ) );
       
   151         if( AknLayoutUtils::LayoutMirrored() )
       
   152             {
       
   153             rect.Move( Rect().Size().iWidth - 
       
   154                        rect.Size().iWidth - 
       
   155                        rect.iTl.iX - 2, 0 );
       
   156             }
       
   157         }
       
   158     return rect;
       
   159     }