meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrdatefield.cpp
branchRCL_3
changeset 25 3533d4323edc
equal deleted inserted replaced
24:d189ee25cf9d 25: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:  ESMR date field impl.
       
    15  *
       
    16 */
       
    17 
       
    18 #include "cesmrdatefield.h"
       
    19 #include "cesmrmeetingtimevalidator.h"
       
    20 #include "cesmrglobalnote.h"
       
    21 #include "esmrfieldbuilderdef.h"
       
    22 #include "mesmrlistobserver.h"
       
    23 #include "cesmrgenericfieldevent.h"
       
    24 #include "cmrimage.h"
       
    25 #include "nmrlayoutmanager.h"
       
    26 #include "nmrcolormanager.h"
       
    27 #include "nmrbitmapmanager.h"
       
    28 
       
    29 #include <AknsBasicBackgroundControlContext.h>
       
    30 
       
    31 #include <eikmfne.h>
       
    32 //<cmail>
       
    33 #include "esmrdef.h"
       
    34 //</cmail>
       
    35 
       
    36 #include "emailtrace.h"
       
    37 
       
    38 // ======== MEMBER FUNCTIONS ========
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // CESMRDateField::CESMRDateField
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CESMRDateField::CESMRDateField( MESMRFieldValidator* aValidator )
       
    45     {
       
    46     FUNC_LOG;
       
    47     
       
    48     iValidator = aValidator;
       
    49         
       
    50     SetFocusType( EESMRHighlightFocus );
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CESMRDateField::~CESMRDateField
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CESMRDateField::~CESMRDateField()
       
    58     {
       
    59     FUNC_LOG;
       
    60     delete iFieldIcon;
       
    61     delete iBgCtrlContext;
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CESMRDateField::NewL
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CESMRDateField* CESMRDateField::NewL(
       
    69         MESMRFieldValidator* aValidator,
       
    70         TESMREntryFieldId aId )
       
    71     {
       
    72     FUNC_LOG;
       
    73     CESMRDateField* self = new(ELeave)CESMRDateField( aValidator );
       
    74     CleanupStack::PushL( self );
       
    75     self->ConstructL( aId );
       
    76     CleanupStack::Pop( self );
       
    77     return self;
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CESMRDateField::ConstructL
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void CESMRDateField::ConstructL( TESMREntryFieldId aId )
       
    85     {
       
    86     FUNC_LOG;
       
    87     SetFieldId ( aId );
       
    88     SetComponentsToInheritVisibility( ETrue );
       
    89     
       
    90     TTime startTime;
       
    91     startTime.UniversalTime();
       
    92 
       
    93     iDate = new( ELeave )CEikDateEditor;
       
    94     iDate->ConstructL( 
       
    95             TTIME_MINIMUMDATE, TTIME_MAXIMUMDATE, startTime, EFalse );
       
    96     iDate->SetUpAndDownKeysConsumed( EFalse );
       
    97     
       
    98     CESMRField::ConstructL( iDate ); //ownership transferred
       
    99     
       
   100     NMRBitmapManager::TMRBitmapId iconId = 
       
   101         ( iFieldId == EESMRFieldStartDate ) ? 
       
   102             NMRBitmapManager::EMRBitmapDateStart : 
       
   103             NMRBitmapManager::EMRBitmapDateEnd;
       
   104 
       
   105     iFieldIcon = CMRImage::NewL( iconId );
       
   106     iFieldIcon->SetParent( this );
       
   107 
       
   108     // Initialize validator
       
   109     InitializeValidatorL();
       
   110     
       
   111     // Setting background instead of theme skin 
       
   112     TRect tempRect(0, 0, 0, 0);
       
   113     NMRBitmapManager::TMRBitmapStruct bitmapStruct;
       
   114     bitmapStruct = NMRBitmapManager::GetBitmapStruct( NMRBitmapManager::EMRBitmapInputCenter );
       
   115 
       
   116     iBgCtrlContext = CAknsBasicBackgroundControlContext::NewL( 
       
   117                 bitmapStruct.iItemId, 
       
   118                 tempRect, 
       
   119                 EFalse );
       
   120         
       
   121     iDate->SetSkinBackgroundControlContextL( iBgCtrlContext );    
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // CESMRDateField::OkToLoseFocusL
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 TBool CESMRDateField::OkToLoseFocusL(
       
   129         TESMREntryFieldId /*aNextItem*/ )
       
   130     {
       
   131     FUNC_LOG;
       
   132     return TriggerValidatorL();
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // CESMRDateField::OfferKeyEventL
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 TKeyResponse CESMRDateField::OfferKeyEventL(const TKeyEvent& aEvent,
       
   140         TEventCode aType )
       
   141     {
       
   142     FUNC_LOG;
       
   143     TKeyResponse response( EKeyWasNotConsumed);
       
   144 
       
   145     TInt fieldIndex( iDate->CurrentField() );
       
   146 
       
   147     if ( aType == EEventKey )
       
   148         {
       
   149 
       
   150         // flowthrough, these events shouldn't be consumed
       
   151         if ( aEvent.iScanCode != EStdKeyUpArrow &&
       
   152              aEvent.iScanCode != EStdKeyDownArrow )
       
   153             {
       
   154             response = iDate->OfferKeyEventL( aEvent, aType );
       
   155             iDate->DrawDeferred();
       
   156             }
       
   157         }
       
   158     
       
   159     TInt endIndex( iDate->CurrentField());
       
   160 
       
   161     if ( ( response == EKeyWasConsumed ) &&
       
   162     	 ( fieldIndex != endIndex) )
       
   163     	{
       
   164     	CheckIfValidatingNeededL ( fieldIndex );
       
   165     	}
       
   166     
       
   167     return response;
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // CESMRDateField::CheckIfValidatingNeededL
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 void CESMRDateField::CheckIfValidatingNeededL(
       
   175         TInt aStartFieldIndex )
       
   176     {
       
   177     FUNC_LOG;
       
   178     TInt fieldIndex( iDate->CurrentField() );
       
   179 
       
   180     if ( fieldIndex != aStartFieldIndex )
       
   181         {
       
   182         TriggerValidatorL();
       
   183         }
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // CESMRDateField::TriggerValidatorL
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 TBool CESMRDateField::TriggerValidatorL()
       
   191     {
       
   192     FUNC_LOG;
       
   193     TInt err( KErrNone );
       
   194 
       
   195     if ( iValidator )
       
   196         {
       
   197         switch ( iFieldId )
       
   198             {
       
   199             case EESMRFieldStartDate:
       
   200                 TRAP( err, iValidator->StartDateChandedL() );
       
   201                 break;
       
   202             case EESMRFieldStopDate:
       
   203                 TRAP(err, iValidator->EndDateChangedL() );
       
   204                 break;
       
   205             case EESMRFieldAlarmDate:
       
   206                 TRAP(err, iValidator->AlarmDateChangedL() );
       
   207                 break;
       
   208             default:
       
   209                 break;
       
   210             }
       
   211         }
       
   212 
       
   213     if ( KErrNone != err )
       
   214         {
       
   215         switch ( iFieldId )
       
   216             {
       
   217             case EESMRFieldStartDate:
       
   218                 {
       
   219                 if ( err == KErrOverflow )
       
   220                     {
       
   221                     CESMRGlobalNote::ExecuteL(
       
   222                             CESMRGlobalNote::EESMRRepeatReSchedule );
       
   223                     }
       
   224                 else if ( err == KErrUnderflow )
       
   225                     {
       
   226                     CESMRGlobalNote::ExecuteL(
       
   227                             CESMRGlobalNote::EESMRRepeatInstanceTooEarly );                    
       
   228                     }
       
   229                 }
       
   230                 break;                
       
   231             case EESMRFieldStopDate:
       
   232                 {
       
   233                 if ( err == KErrArgument )
       
   234                     {
       
   235                     CESMRGlobalNote::ExecuteL(
       
   236                             CESMRGlobalNote::EESMREndsBeforeStarts );
       
   237                     }
       
   238                 else if ( err == KErrOverflow )
       
   239                     {
       
   240                     CESMRGlobalNote::ExecuteL(
       
   241                             CESMRGlobalNote::EESMRRepeatReSchedule );                    
       
   242                     }
       
   243                 else if ( err == KErrUnderflow )
       
   244                     {
       
   245                     CESMRGlobalNote::ExecuteL(
       
   246                             CESMRGlobalNote::EESMRRepeatInstanceTooEarly );                    
       
   247                     }
       
   248                 }
       
   249                 break;
       
   250 
       
   251             case EESMRFieldAlarmDate:
       
   252                 {
       
   253                 CESMRGlobalNote::ExecuteL(
       
   254                         CESMRGlobalNote::EESMRCalenLaterDate );
       
   255                 }
       
   256                 break;
       
   257             
       
   258             default:
       
   259                 break;
       
   260             }
       
   261         }
       
   262     
       
   263     return ( KErrNone == err );
       
   264     }
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // CESMRDateField::SetOutlineFocusL
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 void CESMRDateField::SetOutlineFocusL( TBool aFocus )
       
   271     {
       
   272     FUNC_LOG;
       
   273     CESMRField::SetOutlineFocusL ( aFocus );
       
   274     if ( aFocus )
       
   275         {
       
   276         ChangeMiddleSoftKeyL( EESMRCmdSaveMR,R_QTN_MSK_SAVE );
       
   277         }
       
   278     }
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 // CESMRDateField::SetValidatorL
       
   282 // ---------------------------------------------------------------------------
       
   283 //
       
   284 void CESMRDateField::SetValidatorL( MESMRFieldValidator* aValidator )
       
   285     {
       
   286     CESMRField::SetValidatorL( aValidator );
       
   287     InitializeValidatorL();
       
   288     }
       
   289 
       
   290 // ---------------------------------------------------------------------------
       
   291 // CESMRDateField::SizeChanged()
       
   292 // ---------------------------------------------------------------------------
       
   293 //
       
   294 TBool CESMRDateField::ExecuteGenericCommandL( TInt aCommand )
       
   295     {
       
   296     FUNC_LOG;
       
   297     
       
   298     TBool retValue( EFalse );
       
   299     
       
   300     if ( EMRCmdDoEnvironmentChange == aCommand )
       
   301         {
       
   302         DoEnvChangeL();
       
   303         retValue = ETrue;
       
   304         }
       
   305     
       
   306     return retValue;
       
   307     }
       
   308 
       
   309 
       
   310 // ---------------------------------------------------------------------------
       
   311 // CESMRDateField::CountComponentControls
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 TInt CESMRDateField::CountComponentControls( ) const
       
   315     {
       
   316     FUNC_LOG;
       
   317     TInt count( 0 );
       
   318     if( iFieldIcon )
       
   319         {
       
   320         ++count;
       
   321         }
       
   322     if( iDate )
       
   323         {
       
   324         ++count;
       
   325         }
       
   326         
       
   327     return count;
       
   328     }
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // CESMRDateField::ComponentControl
       
   332 // ---------------------------------------------------------------------------
       
   333 //
       
   334 CCoeControl* CESMRDateField::ComponentControl( TInt aInd ) const
       
   335     {
       
   336     FUNC_LOG;
       
   337     
       
   338     switch ( aInd )
       
   339         {
       
   340         case 0:
       
   341             return iFieldIcon;
       
   342         case 1:
       
   343             return iDate;
       
   344         default:
       
   345             return NULL;
       
   346         }
       
   347     }
       
   348 
       
   349 // ---------------------------------------------------------------------------
       
   350 // CESMRDateField::SizeChanged
       
   351 // ---------------------------------------------------------------------------
       
   352 //
       
   353 void CESMRDateField::SizeChanged()
       
   354     {
       
   355     FUNC_LOG;
       
   356     TRect rect( Rect() );
       
   357 
       
   358     // Layouting field icon
       
   359     if( iFieldIcon )
       
   360         {
       
   361         TAknWindowComponentLayout iconLayout = 
       
   362             NMRLayoutManager::GetWindowComponentLayout( 
       
   363                     NMRLayoutManager::EMRLayoutDateEditorIcon );
       
   364         AknLayoutUtils::LayoutImage( iFieldIcon, rect, iconLayout );
       
   365         }
       
   366     
       
   367     // Layouting date editor
       
   368     if( iDate )
       
   369         {
       
   370         TAknLayoutRect bgLayoutRect = 
       
   371             NMRLayoutManager::GetLayoutRect( 
       
   372                     rect, NMRLayoutManager::EMRLayoutTextEditorBg );
       
   373         TRect bgRect( bgLayoutRect.Rect() );
       
   374         // Move focus rect so that it's relative to field's position.
       
   375         bgRect.Move( -Position() );
       
   376         SetFocusRect( bgRect );
       
   377         
       
   378         TAknTextComponentLayout editorLayout =
       
   379             NMRLayoutManager::GetTextComponentLayout( 
       
   380                     NMRLayoutManager::EMRTextLayoutDateEditor );
       
   381         AknLayoutUtils::LayoutMfne( iDate, rect, editorLayout );
       
   382 
       
   383         NMRColorManager::SetColor( *iDate, 
       
   384                                    NMRColorManager::EMRMainAreaTextColor );
       
   385         }
       
   386     }
       
   387 
       
   388 // ---------------------------------------------------------------------------
       
   389 // CESMRDateField::SetContainerWindowL
       
   390 // ---------------------------------------------------------------------------
       
   391 //
       
   392 void CESMRDateField::SetContainerWindowL( 
       
   393         const CCoeControl& aContainer )
       
   394     {    
       
   395     iContainerWindow = &aContainer;
       
   396     
       
   397     CCoeControl::SetContainerWindowL( *iContainerWindow );
       
   398     iDate->SetContainerWindowL( *iContainerWindow );
       
   399     iFieldIcon->SetContainerWindowL( *iContainerWindow );
       
   400     
       
   401     iDate->SetParent( this );
       
   402     iFieldIcon->SetParent( this );
       
   403     }
       
   404 
       
   405 // ---------------------------------------------------------------------------
       
   406 // CESMRDateField::InitializeValidatorL
       
   407 // ---------------------------------------------------------------------------
       
   408 //
       
   409 void CESMRDateField::InitializeValidatorL()
       
   410     {
       
   411     FUNC_LOG;
       
   412     
       
   413     // Initialize validator
       
   414     if ( iValidator )
       
   415         {
       
   416         switch ( iFieldId )
       
   417             {
       
   418             case EESMRFieldStartDate:
       
   419                 iValidator->SetStartDateFieldL( *iDate );
       
   420                 break;
       
   421             case EESMRFieldStopDate:
       
   422                 iValidator->SetEndDateFieldL( *iDate );
       
   423                 break;
       
   424             case EESMRFieldAlarmDate:
       
   425                 iValidator->SetAlarmDateFieldL( *iDate );
       
   426                 break;
       
   427             default:
       
   428                 break;
       
   429             }
       
   430         }    
       
   431     }
       
   432 
       
   433 // ---------------------------------------------------------------------------
       
   434 // CESMRDateField::DoEnvChangeL
       
   435 // ---------------------------------------------------------------------------
       
   436 //
       
   437 void CESMRDateField::DoEnvChangeL()
       
   438     {
       
   439     FUNC_LOG;
       
   440     
       
   441     CEikDateEditor* date = new( ELeave )CEikDateEditor;
       
   442     CleanupStack::PushL( date );
       
   443     
       
   444     TTime startTime;
       
   445     startTime.UniversalTime();
       
   446     
       
   447     date->ConstructL( 
       
   448             TTIME_MINIMUMDATE, 
       
   449             TTIME_MAXIMUMDATE, 
       
   450             startTime, 
       
   451             EFalse );
       
   452     
       
   453     date->SetUpAndDownKeysConsumed( EFalse );        
       
   454     
       
   455     UpdateExtControlL( date );
       
   456     
       
   457     CleanupStack::Pop( date );
       
   458     iDate = date;
       
   459     InitializeValidatorL();
       
   460     
       
   461     iDate->SetSkinBackgroundControlContextL( iBgCtrlContext );        
       
   462     SetContainerWindowL( *iContainerWindow );
       
   463     
       
   464     iDate->ActivateL();        
       
   465     SizeChanged();
       
   466     DrawDeferred();    
       
   467     }
       
   468 
       
   469 // EOF