meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrviewerstopdatefield.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:  End date field for viewers
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cesmrviewerstopdatefield.h"
       
    19 #include "cesmreditor.h"
       
    20 #include "mesmrlistobserver.h"
       
    21 #include "emailtrace.h"
       
    22 #include "nmrlayoutmanager.h"
       
    23 #include "cmrlabel.h"
       
    24 #include "cmrimage.h"
       
    25 #include "nmrbitmapmanager.h"
       
    26 
       
    27 #include <esmrgui.rsg>
       
    28 #include <AknUtils.h>
       
    29 #include <eiklabel.h>
       
    30 #include <caluser.h>
       
    31 #include <calalarm.h>
       
    32 #include <avkon.rsg>
       
    33 #include <calentry.h>
       
    34 #include <eikenv.h>
       
    35 #include <eikedwin.h>
       
    36 #include <StringLoader.h>
       
    37 #include <AknsConstants.h>
       
    38 #include "esmrfieldbuilderdef.h"
       
    39 
       
    40 // ======== LOCAL FUNCTIONS ========
       
    41 namespace // codescanner::namespace
       
    42     {
       
    43     const TInt KComponentCount( 2 ); // icon and label
       
    44     } // unnamed namespace
       
    45 
       
    46 // ======== MEMBER FUNCTIONS ========
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // CESMRViewerStopDateField::CESMRViewerStopDateField
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CESMRViewerStopDateField::CESMRViewerStopDateField()
       
    53     {
       
    54     FUNC_LOG;
       
    55     SetFieldId ( EESMRFieldStopDate );
       
    56     SetFocusType( EESMRHighlightFocus );     
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CESMRViewerStopDateField::~CESMRViewerStopDateField
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CESMRViewerStopDateField::~CESMRViewerStopDateField()
       
    64     {
       
    65     FUNC_LOG;
       
    66     delete iLabel;
       
    67     delete iIcon;
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CESMRViewerStopDateField::NewL
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 CESMRViewerStopDateField* CESMRViewerStopDateField::NewL()
       
    75     {
       
    76     FUNC_LOG;
       
    77     CESMRViewerStopDateField* self =
       
    78     new (ELeave) CESMRViewerStopDateField();
       
    79     CleanupStack::PushL( self );
       
    80     self->ConstructL();
       
    81     CleanupStack::Pop( self );
       
    82     return self;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CESMRViewerStopDateField::ConstructL()
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CESMRViewerStopDateField::ConstructL()
       
    90     {
       
    91     iLabel = CMRLabel::NewL();
       
    92     iLabel->SetParent( this );
       
    93     iIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapDateEnd );
       
    94     iIcon->SetParent( this );    
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // CESMRViewerStartDateField::InitializeL()
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 void CESMRViewerStopDateField::InitializeL()
       
   102     {
       
   103     TAknLayoutText text = NMRLayoutManager::GetLayoutText( 
       
   104             Rect(), 
       
   105             NMRLayoutManager::EMRTextLayoutTextEditor );
       
   106     
       
   107     iLabel->SetFont( text.Font() );
       
   108     // This is called so that theme changes will apply when changing theme "on the fly"
       
   109     if ( IsFocused() )
       
   110         {
       
   111         iLabel->FocusChanged( EDrawNow );
       
   112         }
       
   113 
       
   114     AknLayoutUtils::OverrideControlColorL ( *iLabel, EColorLabelText,
       
   115                                              KRgbBlack );
       
   116 }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CESMRViewerStopDateField::InternalizeL
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CESMRViewerStopDateField::InternalizeL(
       
   123         MESMRCalEntry& aEntry )
       
   124     {
       
   125     FUNC_LOG;
       
   126     CCalEntry& entry = aEntry.Entry();
       
   127     TTime endTime = entry.EndTimeL().TimeLocalL();
       
   128     TTime startTime = entry.StartTimeL().TimeLocalL();
       
   129     TDateTime startDate = startTime.DateTime();
       
   130     TDateTime endDate = endTime.DateTime();
       
   131 
       
   132     if ( aEntry.IsAllDayEventL() )
       
   133         {
       
   134         // if the event is allday event, previous day for end date will be
       
   135         // shown in UI. See Outlook for reference...
       
   136         endTime -= TTimeIntervalDays( KAllDayEventDurationInDays );
       
   137         endDate = endTime.DateTime();
       
   138         }
       
   139 
       
   140     // If the entry start and end date for the event are the same, hide end time.
       
   141     // Hide only if the entry is meeting, meeting request or memo
       
   142     if( ( (aEntry.Entry().EntryTypeL() == CCalEntry::EAppt ) ||
       
   143     	  (aEntry.Entry().EntryTypeL() == CCalEntry::EEvent ) )&&
       
   144         ( startDate.Year() == endDate.Year() ) &&
       
   145         ( startDate.Month() == endDate.Month() ) &&
       
   146         ( startDate.Day() == endDate.Day() ) )
       
   147         {
       
   148         iObserver->RemoveControl( FieldId() );
       
   149         }
       
   150     else // else set the text for end time label
       
   151         {
       
   152         // Read format string from AVKON resource
       
   153         HBufC* dateFormatString =
       
   154             iEikonEnv->AllocReadResourceLC( R_QTN_DATE_USUAL_WITH_ZERO );
       
   155         HBufC* buf = HBufC::NewLC( KBufferLength );
       
   156         TPtr ptr( buf->Des() );
       
   157 
       
   158         endTime.FormatL( ptr, *dateFormatString );
       
   159         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr );
       
   160         iLabel->SetTextL( ptr );
       
   161         CleanupStack::PopAndDestroy( 2, dateFormatString );
       
   162         }
       
   163     }
       
   164 // ---------------------------------------------------------------------------
       
   165 // CESMRViewerStopDateField::SizeChanged()
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 void CESMRViewerStopDateField::SizeChanged()
       
   169     {
       
   170     TRect rect = Rect();
       
   171     TAknLayoutRect rowLayoutRect =
       
   172         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
       
   173     rect = rowLayoutRect.Rect();
       
   174     
       
   175     TAknWindowComponentLayout iconLayout =
       
   176         NMRLayoutManager::GetWindowComponentLayout( 
       
   177                 NMRLayoutManager::EMRLayoutTextEditorIcon );
       
   178     AknLayoutUtils::LayoutImage( iIcon, rect, iconLayout );
       
   179     
       
   180     TAknLayoutRect bgLayoutRect = NMRLayoutManager::GetLayoutRect( rect, NMRLayoutManager::EMRLayoutTextEditorBg );
       
   181     TRect bgRect( bgLayoutRect.Rect() );
       
   182     // Move focus rect so that it's relative to field's position.
       
   183     bgRect.Move( -Position() );
       
   184     SetFocusRect( bgRect );
       
   185        
       
   186     TAknLayoutText labelLayout = 
       
   187         NMRLayoutManager::GetLayoutText( 
       
   188                 rect, NMRLayoutManager::EMRTextLayoutTextEditor );
       
   189     iLabel->SetRect( labelLayout.TextRect() );
       
   190     }
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // CESMRViewerStopDateField::CountComponentControls()
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 TInt CESMRViewerStopDateField::CountComponentControls() const
       
   197     {
       
   198     TInt count( KComponentCount );
       
   199     return count;
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // CESMRViewerStopDateField::ComponentControl()
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 CCoeControl* CESMRViewerStopDateField::ComponentControl( TInt aIndex ) const
       
   207     {
       
   208     switch ( aIndex )
       
   209         {
       
   210         case 0:
       
   211             return iIcon;
       
   212         case 1:
       
   213             return iLabel;
       
   214         default:
       
   215             return NULL;
       
   216         }
       
   217     }
       
   218 
       
   219 // ---------------------------------------------------------------------------
       
   220 // CESMRViewerStopDateField::SetOutlineFocusL()
       
   221 // ---------------------------------------------------------------------------
       
   222 //
       
   223 void CESMRViewerStopDateField::SetOutlineFocusL( TBool aFocus )
       
   224     {
       
   225     CESMRField::SetOutlineFocusL ( aFocus );
       
   226     
       
   227     iLabel->SetFocus( aFocus );    
       
   228 
       
   229     if ( !aFocus )
       
   230         {
       
   231         AknLayoutUtils::OverrideControlColorL ( *iLabel, EColorLabelText,
       
   232                                                  KRgbBlack );
       
   233         }
       
   234     }
       
   235 // EOF
       
   236