meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrvieweralarmtimefield.cpp
changeset 0 8466d47a6819
child 16 4ce476e64c59
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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:  ESMR UI Container class
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cesmrvieweralarmtimefield.h"
       
    19 #include "cesmreditor.h"
       
    20 #include "mesmrlistobserver.h"
       
    21 #include "nmrbitmapmanager.h"
       
    22 #include "nmrlayoutmanager.h"
       
    23 #include "cmrlabel.h"
       
    24 #include "cmrimage.h"
       
    25 
       
    26 #include <eiklabel.h>
       
    27 #include <caluser.h>
       
    28 #include <calalarm.h>
       
    29 #include <avkon.rsg>
       
    30 #include <calentry.h>
       
    31 #include <eikenv.h>
       
    32 #include <eikedwin.h>
       
    33 #include <StringLoader.h>
       
    34 #include <AknsConstants.h>
       
    35 #include <AknUtils.h>
       
    36 #include <AknLayout2ScalableDef.h>
       
    37 
       
    38 #include <esmrgui.rsg>
       
    39 
       
    40 //unnamed namespace for local constants functions
       
    41 namespace{ // codescanner::namespace
       
    42 
       
    43 const TInt KComponentCount( 2 ); // icon and label
       
    44 const TInt KMaxTimeBuffer( 50 ); // buffer for time formatting
       
    45 
       
    46 }//namespace
       
    47 
       
    48 // ======== MEMBER FUNCTIONS ========
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // CESMRViewerAlarmTimeField::CESMRViewerAlarmTimeField()
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CESMRViewerAlarmTimeField* CESMRViewerAlarmTimeField::NewL()
       
    55     {
       
    56     CESMRViewerAlarmTimeField* self = new (ELeave) CESMRViewerAlarmTimeField();
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL();
       
    59     CleanupStack::Pop( self );
       
    60     return self;
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CESMRViewerAlarmTimeField::~CESMRViewerAlarmTimeField()
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CESMRViewerAlarmTimeField::~CESMRViewerAlarmTimeField()
       
    68     {
       
    69     delete iIcon;
       
    70     delete iLabel;
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CESMRViewerAlarmTimeField::CESMRViewerAlarmTimeField()
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CESMRViewerAlarmTimeField::CESMRViewerAlarmTimeField()
       
    78     {
       
    79     SetFieldId ( EESMRFieldAlarmTime );
       
    80     SetFocusType( EESMRHighlightFocus );
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CESMRViewerAlarmTimeField::ConstructL()
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 void CESMRViewerAlarmTimeField::ConstructL()
       
    88     {
       
    89     iLabel = CMRLabel::NewL();
       
    90     iLabel->SetParent( this );
       
    91     iIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapAlarmTime );
       
    92     iIcon->SetParent( this );
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CESMRViewerAlarmTimeField::InitializeL()
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CESMRViewerAlarmTimeField::InitializeL()
       
   100     {
       
   101     TAknLayoutText text = NMRLayoutManager::GetLayoutText( 
       
   102             Rect(), 
       
   103             NMRLayoutManager::EMRTextLayoutTextEditor );
       
   104     
       
   105     iLabel->SetFont( text.Font() );
       
   106     // This is called so that theme changes will apply when changing theme "on the fly"
       
   107     if ( IsFocused() )
       
   108         {
       
   109         iLabel->FocusChanged( EDrawNow );
       
   110         }
       
   111 
       
   112     AknLayoutUtils::OverrideControlColorL ( *iLabel, EColorLabelText,
       
   113                                              KRgbBlack );
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // CESMRViewerAlarmTimeField::InternalizeL()
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 void CESMRViewerAlarmTimeField::InternalizeL( MESMRCalEntry& aEntry )
       
   121     {
       
   122     MESMRCalEntry::TESMRAlarmType alarmType;
       
   123     TTime alarmTime;
       
   124 
       
   125     aEntry.GetAlarmL( alarmType, alarmTime );
       
   126 
       
   127     if( alarmType == MESMRCalEntry::EESMRAlarmAbsolute )
       
   128         {
       
   129         // Read format string from AVKON resource
       
   130         HBufC* dateFormatString =
       
   131             iEikonEnv->AllocReadResourceLC( R_QTN_TIME_USUAL_WITH_ZERO );
       
   132         TBuf<KMaxTimeBuffer> buf;
       
   133             
       
   134         alarmTime.FormatL( buf, *dateFormatString );
       
   135         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( buf );
       
   136         iLabel->SetTextL( buf );
       
   137         CleanupStack::PopAndDestroy( dateFormatString );
       
   138         }
       
   139     else // Remove the alarm fields
       
   140         {
       
   141         CCoeControl::MakeVisible( EFalse );
       
   142         iObserver->RemoveControl( EESMRFieldAlarmTime );
       
   143         }
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CESMRViewerAlarmTimeField::SizeChanged()
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void CESMRViewerAlarmTimeField::SizeChanged()
       
   151     {
       
   152     TRect rect = Rect();
       
   153     TAknLayoutRect rowLayoutRect =
       
   154         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
       
   155     rect = rowLayoutRect.Rect();
       
   156     
       
   157     TAknWindowComponentLayout iconLayout =
       
   158         NMRLayoutManager::GetWindowComponentLayout( 
       
   159                 NMRLayoutManager::EMRLayoutTextEditorIcon );
       
   160     AknLayoutUtils::LayoutImage( iIcon, rect, iconLayout );
       
   161     
       
   162     TAknLayoutRect bgLayoutRect =
       
   163         NMRLayoutManager::GetLayoutRect( 
       
   164                 rect, NMRLayoutManager::EMRLayoutTextEditorBg );
       
   165     TRect bgRect( bgLayoutRect.Rect() );
       
   166     // Move focus rect so that it's relative to field's position.
       
   167     bgRect.Move( -Position() );
       
   168     SetFocusRect( bgRect );
       
   169     
       
   170     TAknLayoutText labelLayout = 
       
   171         NMRLayoutManager::GetLayoutText( 
       
   172                 rect, NMRLayoutManager::EMRTextLayoutTextEditor );
       
   173     iLabel->SetRect( labelLayout.TextRect() );
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // CESMRViewerAlarmTimeField::CountComponentControls()
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 TInt CESMRViewerAlarmTimeField::CountComponentControls() const
       
   181     {
       
   182     TInt count( KComponentCount );
       
   183     return count;
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // CESMRViewerAlarmTimeField::ComponentControl()
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 CCoeControl* CESMRViewerAlarmTimeField::ComponentControl( TInt aIndex ) const
       
   191     {
       
   192     switch ( aIndex )
       
   193         {
       
   194         case 0:
       
   195             return iIcon;
       
   196         case 1:
       
   197             return iLabel;
       
   198         default:
       
   199             return NULL;
       
   200         }
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CESMRViewerAlarmTimeField::SetOutlineFocusL()
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 void CESMRViewerAlarmTimeField::SetOutlineFocusL( TBool aFocus )
       
   208     {
       
   209     CESMRField::SetOutlineFocusL ( aFocus );
       
   210     iLabel->SetFocus( aFocus );    
       
   211 
       
   212     if ( !aFocus )
       
   213         {
       
   214         AknLayoutUtils::OverrideControlColorL ( *iLabel, EColorLabelText,
       
   215                                                  KRgbBlack );
       
   216         }
       
   217     }
       
   218 // EOF
       
   219