meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrviewerstartdatefield.cpp
branchRCL_3
changeset 64 3533d4323edc
equal deleted inserted replaced
63:d189ee25cf9d 64:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 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:  Start date field for viewers
       
    15  *
       
    16 */
       
    17 
       
    18 #include "cesmrviewerstartdatefield.h"
       
    19 
       
    20 #include "cesmreditor.h"
       
    21 #include "mesmrlistobserver.h"
       
    22 #include "nmrlayoutmanager.h"
       
    23 #include "nmrbitmapmanager.h"
       
    24 #include "cmrlabel.h"
       
    25 #include "cmrimage.h"
       
    26 #include "emailtrace.h"
       
    27 #include "cesmrglobalnote.h"
       
    28 #include <esmrgui.rsg>
       
    29 
       
    30 #include <eiklabel.h>
       
    31 #include <caluser.h>
       
    32 #include <calalarm.h>
       
    33 #include <avkon.rsg>
       
    34 #include <calentry.h>
       
    35 #include <eikenv.h>
       
    36 #include <eikedwin.h>
       
    37 #include <StringLoader.h>
       
    38 #include <AknsConstants.h>
       
    39 #include <AknUtils.h>
       
    40 #include <AknLayout2ScalableDef.h>
       
    41 
       
    42 // ======== LOCAL FUNCTIONS ========
       
    43 namespace // codescanner::namespace
       
    44     {
       
    45     const TInt KComponentCount( 2 ); // icon and label
       
    46     const TInt KMaxTimeBuffer( 32 ); // buffer for date formatting
       
    47     } // unnamed namespace
       
    48 
       
    49 // ======== MEMBER FUNCTIONS ========
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CESMRViewerStartDateField::CESMRViewerStartDateField()
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CESMRViewerStartDateField::CESMRViewerStartDateField()
       
    56     {
       
    57     FUNC_LOG;
       
    58 
       
    59     SetFieldId ( EESMRFieldStartDate );
       
    60     SetFocusType( EESMRHighlightFocus );
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CESMRViewerStartDateField::~CESMRViewerStartDateField()
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CESMRViewerStartDateField::~CESMRViewerStartDateField()
       
    68     {
       
    69     FUNC_LOG;
       
    70 
       
    71     delete iIcon;
       
    72     delete iLockIcon;
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CESMRViewerStartDateField::NewL()
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 CESMRViewerStartDateField* CESMRViewerStartDateField::NewL()
       
    80     {
       
    81     FUNC_LOG;
       
    82 
       
    83     CESMRViewerStartDateField* self =
       
    84             new (ELeave) CESMRViewerStartDateField();
       
    85     CleanupStack::PushL( self );
       
    86     self->ConstructL();
       
    87     CleanupStack::Pop( self );
       
    88     return self;
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CESMRViewerStartDateField::ConstructL()
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CESMRViewerStartDateField::ConstructL()
       
    96     {
       
    97     FUNC_LOG;
       
    98 
       
    99     iLabel = CMRLabel::NewL( this );
       
   100     CESMRField::ConstructL( iLabel ); // ownership transfered
       
   101 
       
   102     iIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapDateStart, this );
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CESMRViewerStartDateField::InternalizeL()
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CESMRViewerStartDateField::InternalizeL( MESMRCalEntry& aEntry )
       
   110     {
       
   111     FUNC_LOG;
       
   112 
       
   113     CCalEntry& entry = aEntry.Entry();
       
   114     iStartTime = entry.StartTimeL().TimeLocalL();
       
   115 
       
   116     FormatDateStringL();
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CESMRViewerStartDateField::SizeChanged()
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CESMRViewerStartDateField::SizeChanged()
       
   124     {
       
   125     FUNC_LOG;
       
   126 
       
   127     TRect rect = Rect();
       
   128     TAknLayoutRect rowLayoutRect =
       
   129         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
       
   130     rect = rowLayoutRect.Rect();
       
   131 
       
   132     TAknWindowComponentLayout iconLayout =
       
   133         NMRLayoutManager::GetWindowComponentLayout(
       
   134                 NMRLayoutManager::EMRLayoutTextEditorIcon );
       
   135     AknLayoutUtils::LayoutImage( iIcon, rect, iconLayout );
       
   136 
       
   137     // Layouting lock icon
       
   138     if( iLockIcon )
       
   139     	{
       
   140     	TAknWindowComponentLayout iconLayout(
       
   141     			NMRLayoutManager::GetWindowComponentLayout(
       
   142     					NMRLayoutManager::EMRLayoutSingleRowDColumnGraphic ) );
       
   143     	AknLayoutUtils::LayoutImage( iLockIcon, rect, iconLayout );
       
   144     	}
       
   145 
       
   146     // Layouting label
       
   147     TAknTextComponentLayout viewerLayoutText;
       
   148     if( iLockIcon )
       
   149         {
       
   150         viewerLayoutText = NMRLayoutManager::GetTextComponentLayout(
       
   151                 NMRLayoutManager::EMRTextLayoutSingleRowEditorText );
       
   152         }
       
   153     else
       
   154         {
       
   155         viewerLayoutText = NMRLayoutManager::GetTextComponentLayout(
       
   156                 NMRLayoutManager::EMRTextLayoutTextEditor );
       
   157         }
       
   158 
       
   159     AknLayoutUtils::LayoutLabel( iLabel, rect, viewerLayoutText );
       
   160     TRect viewerRect( iLabel->Rect() );
       
   161 
       
   162     // Move focus rect so that it's relative to field's position.
       
   163     viewerRect.Move( -Position() );
       
   164     SetFocusRect( viewerRect );
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // CESMRViewerStartDateField::CountComponentControls()
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 TInt CESMRViewerStartDateField::CountComponentControls() const
       
   172     {
       
   173     FUNC_LOG;
       
   174 
       
   175     TInt count( KComponentCount );
       
   176     if( iLockIcon )
       
   177     	{
       
   178     	++count;
       
   179     	}
       
   180     return count;
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------------------------
       
   184 // CESMRViewerStartDateField::ComponentControl()
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 CCoeControl* CESMRViewerStartDateField::ComponentControl( TInt aIndex ) const
       
   188     {
       
   189     FUNC_LOG;
       
   190 
       
   191     switch ( aIndex )
       
   192         {
       
   193         case 0:
       
   194             return iIcon;
       
   195         case 1:
       
   196             return iLabel;
       
   197         case 2:
       
   198         	return iLockIcon;
       
   199         default:
       
   200             return NULL;
       
   201         }
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // CESMRViewerStartDateField::SetOutlineFocusL()
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 void CESMRViewerStartDateField::SetOutlineFocusL( TBool aFocus )
       
   209     {
       
   210     FUNC_LOG;
       
   211 
       
   212     CESMRField::SetOutlineFocusL ( aFocus );
       
   213     iLabel->SetFocus( aFocus );
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // CESMRViewerStartDateField::ExecuteGenericCommandL()
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 TBool CESMRViewerStartDateField::ExecuteGenericCommandL( TInt aCommand )
       
   221     {
       
   222     FUNC_LOG;
       
   223 
       
   224     TBool retValue( EFalse );
       
   225 
       
   226     if( (aCommand == EAknCmdOpen) && IsLocked()  )
       
   227     	{
       
   228 		HandleTactileFeedbackL();
       
   229 
       
   230     	CESMRGlobalNote::ExecuteL(
       
   231     			CESMRGlobalNote::EESMRUnableToEdit );
       
   232     	retValue = ETrue;
       
   233     	}
       
   234 
       
   235     if ( EMRCmdDoEnvironmentChange == aCommand )
       
   236         {
       
   237         FormatDateStringL();
       
   238         retValue = ETrue;
       
   239         }
       
   240 
       
   241     return retValue;
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // CESMRViewerStartDateField::LockL()
       
   246 // ---------------------------------------------------------------------------
       
   247 //
       
   248 void CESMRViewerStartDateField::LockL()
       
   249 	{
       
   250 	FUNC_LOG;
       
   251 	if( IsLocked() )
       
   252 		{
       
   253 		return;
       
   254 		}
       
   255 
       
   256 	CESMRField::LockL();
       
   257 
       
   258 	delete iLockIcon;
       
   259 	iLockIcon = NULL;
       
   260 	iLockIcon = CMRImage::NewL(
       
   261 	        NMRBitmapManager::EMRBitmapLockField,
       
   262 	        this,
       
   263 	        ETrue );
       
   264 	}
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // CESMRViewerStartDateField::FormatDateStringL()
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 void CESMRViewerStartDateField::FormatDateStringL()
       
   271     {
       
   272     FUNC_LOG;
       
   273 
       
   274     // Read format string from AVKON resource
       
   275     HBufC* dateFormatString =
       
   276             iEikonEnv->AllocReadResourceLC(
       
   277                     R_QTN_DATE_USUAL_WITH_ZERO);
       
   278 
       
   279     TBuf<KMaxTimeBuffer> buf;
       
   280     iStartTime.FormatL(buf, *dateFormatString);
       
   281 
       
   282     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( buf );
       
   283     iLabel->SetTextL( buf );
       
   284     CleanupStack::PopAndDestroy( dateFormatString );
       
   285     }
       
   286 
       
   287 // EOF