meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrviewertimefield.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:  Time field for viewers
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cesmrviewertimefield.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 #include <esmrgui.rsg>
       
    38 // DEBUG
       
    39 #include "emailtrace.h"
       
    40 
       
    41 //unnamed namespace for local constants functions
       
    42 namespace{ // codescanner::namespace
       
    43 
       
    44 const TInt KTimeBufferSize( 50 );
       
    45 const TInt KTempBufferSize( 20 );
       
    46 
       
    47 }//namespace
       
    48 
       
    49 // ======== MEMBER FUNCTIONS ========
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CESMRViewerTimeField::NewL()
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CESMRViewerTimeField* CESMRViewerTimeField::NewL()
       
    56     {
       
    57     FUNC_LOG;
       
    58     CESMRViewerTimeField* self = new (ELeave) CESMRViewerTimeField();
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL();
       
    61     CleanupStack::Pop( self );
       
    62     return self;
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CESMRViewerTimeField::~CESMRViewerTimeField()
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CESMRViewerTimeField::~CESMRViewerTimeField()
       
    70     {
       
    71     FUNC_LOG;
       
    72     delete iIcon;
       
    73     delete iLabel;
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CESMRViewerTimeField::InternalizeL()
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 void CESMRViewerTimeField::InternalizeL( MESMRCalEntry& aEntry )
       
    81     {
       
    82     FUNC_LOG;
       
    83     if ( aEntry.IsAllDayEventL() )
       
    84         {
       
    85         // set the field as hidden:
       
    86         iObserver->RemoveControl( FieldId() );
       
    87         }
       
    88     else
       
    89         {
       
    90         _LIT(KTimeSeparator," - ");
       
    91         CCalEntry& entry = aEntry.Entry();
       
    92         
       
    93         TTime startTime = entry.StartTimeL().TimeLocalL();
       
    94         TTime endTime = entry.EndTimeL().TimeLocalL();
       
    95 
       
    96         HBufC* timeFormatString =
       
    97             iEikonEnv->AllocReadResourceLC( R_QTN_TIME_USUAL_WITH_ZERO );
       
    98         HBufC* finalBuf = HBufC::NewLC( KTimeBufferSize );
       
    99         HBufC* startBuf = HBufC::NewLC( KTempBufferSize );
       
   100         HBufC* endBuf = HBufC::NewLC( KTempBufferSize );
       
   101         const TInt KNumBuffers( 4 );
       
   102         
       
   103         TPtr startPtr( startBuf->Des() );
       
   104         startTime.FormatL( startPtr, *timeFormatString );
       
   105         TPtr endPtr( endBuf->Des() );
       
   106         endTime.FormatL( endPtr, *timeFormatString );
       
   107         TPtr finalPtr( finalBuf->Des() );
       
   108         finalPtr.Append( startPtr );
       
   109         finalPtr.Append( KTimeSeparator );
       
   110         finalPtr.Append( endPtr );
       
   111         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( finalPtr );
       
   112         iLabel->SetTextL( finalPtr );
       
   113         CleanupStack::PopAndDestroy( KNumBuffers, timeFormatString );
       
   114         }
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // CESMRViewerTimeField::InitializeL()
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 void CESMRViewerTimeField::InitializeL()
       
   122     {
       
   123     TAknLayoutText text = NMRLayoutManager::GetLayoutText( 
       
   124             Rect(), 
       
   125             NMRLayoutManager::EMRTextLayoutTextEditor );
       
   126     
       
   127     iLabel->SetFont( text.Font() );
       
   128     // This is called so that theme changes will apply when changing theme "on the fly"
       
   129     if ( IsFocused() )
       
   130         {
       
   131         iLabel->FocusChanged( EDrawNow );
       
   132         }
       
   133 
       
   134     AknLayoutUtils::OverrideControlColorL ( *iLabel, EColorLabelText,
       
   135                                              KRgbBlack );
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CESMRViewerTimeField::SizeChanged()
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 void CESMRViewerTimeField::SizeChanged()
       
   143     {
       
   144     TRect rect = Rect();
       
   145     TAknLayoutRect rowLayoutRect =
       
   146         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
       
   147     rect = rowLayoutRect.Rect();
       
   148     
       
   149     TAknWindowComponentLayout iconLayout =
       
   150         NMRLayoutManager::GetWindowComponentLayout( 
       
   151                 NMRLayoutManager::EMRLayoutTextEditorIcon );
       
   152     AknLayoutUtils::LayoutImage( iIcon, rect, iconLayout );
       
   153     
       
   154     TAknLayoutRect bgLayoutRect =
       
   155         NMRLayoutManager::GetLayoutRect( 
       
   156                 rect, NMRLayoutManager::EMRLayoutTextEditorBg );
       
   157     TRect bgRect( bgLayoutRect.Rect() );
       
   158     // Move focus rect so that it's relative to field's position.
       
   159     bgRect.Move( -Position() );
       
   160     SetFocusRect( bgRect );
       
   161     
       
   162     TAknLayoutText labelLayout = 
       
   163         NMRLayoutManager::GetLayoutText( 
       
   164                 rect, NMRLayoutManager::EMRTextLayoutTextEditor );
       
   165     iLabel->SetRect( labelLayout.TextRect() );
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // CESMRViewerTimeField::CountComponentControls()
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 TInt CESMRViewerTimeField::CountComponentControls() const
       
   173     {
       
   174     TInt count( 2 );
       
   175     return count;
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CESMRViewerTimeField::ComponentControl()
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 CCoeControl* CESMRViewerTimeField::ComponentControl( TInt aIndex ) const
       
   183     {
       
   184     switch ( aIndex )
       
   185         {
       
   186         case 0:
       
   187             return iIcon;
       
   188         case 1:
       
   189             return iLabel;
       
   190         default:
       
   191             return NULL;
       
   192         }
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // CESMRViewerTimeField::CESMRViewerTimeField()
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 CESMRViewerTimeField::CESMRViewerTimeField()
       
   200     {
       
   201     SetFieldId( EESMRFieldMeetingTime );
       
   202     SetFocusType( EESMRHighlightFocus );
       
   203     }
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 // CESMRViewerTimeField::ConstructL()
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 void CESMRViewerTimeField::ConstructL()
       
   210     {
       
   211     iLabel = CMRLabel::NewL();
       
   212     iLabel->SetParent( this );
       
   213     iIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapClock );
       
   214     iIcon->SetParent( this );
       
   215     }
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 // CESMRViewerTimeField::SetOutlineFocusL()
       
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 void CESMRViewerTimeField::SetOutlineFocusL( TBool aFocus )
       
   222     {
       
   223     CESMRField::SetOutlineFocusL ( aFocus );
       
   224     
       
   225     iLabel->SetFocus( aFocus );
       
   226 
       
   227     if ( !aFocus )
       
   228         {
       
   229         AknLayoutUtils::OverrideControlColorL ( *iLabel, EColorLabelText,
       
   230                                                  KRgbBlack );
       
   231         }
       
   232     }
       
   233 
       
   234 // EOF