meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrdatefield.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 0 8466d47a6819
child 16 b5fbb9b25d57
--- a/meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrdatefield.cpp	Mon Mar 15 12:39:10 2010 +0200
+++ b/meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrdatefield.cpp	Wed Mar 31 21:08:33 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -15,24 +15,25 @@
  *
 */
 
-#include "emailtrace.h"
 #include "cesmrdatefield.h"
-
-#include <eikmfne.h>
-#include <avkon.hrh>
-#include <AknsConstants.h>
-#include <AknUtils.h>
-#include <AknsDrawUtils.h>
-#include <AknsFrameBackgroundControlContext.h>
-//<cmail>
-#include "esmrdef.h"
-//</cmail>
-
 #include "cesmrmeetingtimevalidator.h"
 #include "cesmrglobalnote.h"
 #include "esmrfieldbuilderdef.h"
 #include "mesmrlistobserver.h"
 #include "cesmrgenericfieldevent.h"
+#include "cmrimage.h"
+#include "nmrlayoutmanager.h"
+#include "nmrcolormanager.h"
+#include "nmrbitmapmanager.h"
+
+#include <aknsbasicbackgroundcontrolcontext.h>
+
+#include <eikmfne.h>
+//<cmail>
+#include "esmrdef.h"
+//</cmail>
+
+#include "emailtrace.h"
 
 // ======== MEMBER FUNCTIONS ========
 
@@ -40,22 +41,24 @@
 // CESMRDateField::CESMRDateField
 // ---------------------------------------------------------------------------
 //
-CESMRDateField::CESMRDateField(
-        MESMRFieldValidator* aValidator ) :
-    iValidator(aValidator)
+CESMRDateField::CESMRDateField( MESMRFieldValidator* aValidator )
     {
     FUNC_LOG;
-    //do nothing
+    
+    iValidator = aValidator;
+        
+    SetFocusType( EESMRHighlightFocus );
     }
 
 // ---------------------------------------------------------------------------
 // CESMRDateField::~CESMRDateField
 // ---------------------------------------------------------------------------
 //
-CESMRDateField::~CESMRDateField( )
+CESMRDateField::~CESMRDateField()
     {
     FUNC_LOG;
-    delete iFrameBgContext;
+    delete iFieldIcon;
+    delete iBgCtrlContext;
     }
 
 // ---------------------------------------------------------------------------
@@ -67,8 +70,8 @@
         TESMREntryFieldId aId )
     {
     FUNC_LOG;
-    CESMRDateField* self = new (ELeave) CESMRDateField( aValidator );
-    CleanupStack::PushL ( self );
+    CESMRDateField* self = new(ELeave)CESMRDateField( aValidator );
+    CleanupStack::PushL( self );
     self->ConstructL( aId );
     CleanupStack::Pop( self );
     return self;
@@ -82,53 +85,40 @@
     {
     FUNC_LOG;
     SetFieldId ( aId );
-
+    SetComponentsToInheritVisibility( ETrue );
+    
     TTime startTime;
-    startTime.UniversalTime ( );
+    startTime.UniversalTime();
 
-    iDate = new (ELeave) CEikDateEditor;
-    iDate->ConstructL( TTIME_MINIMUMDATE, TTIME_MAXIMUMDATE, startTime, EFalse );
-    iDate->SetUpAndDownKeysConsumed ( EFalse );
+    iDate = new( ELeave )CEikDateEditor;
+    iDate->ConstructL( 
+            TTIME_MINIMUMDATE, TTIME_MAXIMUMDATE, startTime, EFalse );
+    iDate->SetUpAndDownKeysConsumed( EFalse );
+    
+    CESMRField::ConstructL( iDate ); //ownership transferred
     
-    TAknsItemID aIconID = (iFieldId == EESMRFieldStartDate) ? KAknsIIDQgnMeetReqIndiDateStart
-            : KAknsIIDQgnMeetReqIndiDateEnd;
+    NMRBitmapManager::TMRBitmapId iconId = 
+        ( iFieldId == EESMRFieldStartDate ) ? 
+            NMRBitmapManager::EMRBitmapDateStart : 
+            NMRBitmapManager::EMRBitmapDateEnd;
 
-    iBackground = AknsDrawUtils::ControlContext( this );
-    CESMRIconField::ConstructL( aIconID, iDate ); // ownership transferred
+    iFieldIcon = CMRImage::NewL( iconId );
+    iFieldIcon->SetParent( this );
 
     // Initialize validator
-    if ( iValidator )
-        {
-        switch ( iFieldId )
-            {
-            case EESMRFieldStartDate:
-                iValidator->SetStartDateFieldL( *iDate );
-                break;
-            case EESMRFieldStopDate:
-                iValidator->SetEndDateFieldL( *iDate );
-                break;
-            case EESMRFieldAlarmDate:
-                iValidator->SetAlarmDateFieldL( *iDate );
-                break;
-            default:
-                break;
-            }
-        }
-    }
+    InitializeValidatorL();
+    
+    // Setting background instead of theme skin 
+    TRect tempRect(0, 0, 0, 0);
+    NMRBitmapManager::TMRBitmapStruct bitmapStruct;
+    bitmapStruct = NMRBitmapManager::GetBitmapStruct( NMRBitmapManager::EMRBitmapInputCenter );
 
-// ---------------------------------------------------------------------------
-// CESMRDateField::InitializeL
-// ---------------------------------------------------------------------------
-//
-void CESMRDateField::InitializeL()
-    {
-    FUNC_LOG;
-    iDate->SetFont( iLayout->Font(iCoeEnv, iFieldId ) );
-    iDate->SetMfneAlignment( CESMRLayoutManager::IsMirrored()
-                             ? EAknEditorAlignRight : EAknEditorAlignLeft );
-
-    iDate->SetSkinTextColorL( iLayout->NormalTextColorID() );
-    iDate->SetBorder( TGulBorder::ENone );
+    iBgCtrlContext = CAknsBasicBackgroundControlContext::NewL( 
+                bitmapStruct.iItemId, 
+                tempRect, 
+                EFalse );
+        
+    iDate->SetSkinBackgroundControlContextL( iBgCtrlContext );    
     }
 
 // ---------------------------------------------------------------------------
@@ -152,55 +142,29 @@
     FUNC_LOG;
     TKeyResponse response( EKeyWasNotConsumed);
 
+    TInt fieldIndex( iDate->CurrentField() );
+
     if ( aType == EEventKey )
         {
-        TInt fieldIndex( iDate->CurrentField() );
 
         // flowthrough, these events shouldn't be consumed
         if ( aEvent.iScanCode != EStdKeyUpArrow &&
              aEvent.iScanCode != EStdKeyDownArrow )
             {
             response = iDate->OfferKeyEventL( aEvent, aType );
+            iDate->DrawDeferred();
             }
         }
-
-    return response;
-    }
-
-// ---------------------------------------------------------------------------
-// CESMRDateField::PositionChanged()
-// ---------------------------------------------------------------------------
-//
-void CESMRDateField::PositionChanged()
-    {
-    FUNC_LOG;
-    CCoeControl::PositionChanged();
-    if( iFrameBgContext )
-        {
-        iFrameBgContext->SetFrameRects( iDate->Rect(), iDate->Rect() );
-        }
-    }
+    
+    TInt endIndex( iDate->CurrentField());
 
-// ---------------------------------------------------------------------------
-// CESMRDateField::ActivateL
-// ---------------------------------------------------------------------------
-//
-void CESMRDateField::ActivateL()
-    {
-    FUNC_LOG;
-    CCoeControl::ActivateL();
-    TRect rect(TPoint(iDate->Position()), iDate->Size());
-    TRect inner(rect);
-    TRect outer(rect);
-
-    iDate->SetSize(iLayout->FieldSize( FieldId() ));
+    if ( ( response == EKeyWasConsumed ) &&
+    	 ( fieldIndex != endIndex) )
+    	{
+    	CheckIfValidatingNeededL ( fieldIndex );
+    	}
     
-    delete iFrameBgContext;
-    iFrameBgContext = NULL;
-    iFrameBgContext = CAknsFrameBackgroundControlContext::NewL(KAknsIIDQsnFrInput, outer, inner, EFalse ) ;
-
-    iFrameBgContext->SetParentContext( iBackground );
-    iDate->SetSkinBackgroundControlContextL(iFrameBgContext);
+    return response;
     }
 
 // ---------------------------------------------------------------------------
@@ -228,7 +192,7 @@
     FUNC_LOG;
     TInt err( KErrNone );
 
-    if (iValidator )
+    if ( iValidator )
         {
         switch ( iFieldId )
             {
@@ -246,15 +210,22 @@
             }
         }
 
-
     if ( KErrNone != err )
         {
         switch ( iFieldId )
             {
             case EESMRFieldStartDate:
                 {
-                CESMRGlobalNote::ExecuteL(
-                        CESMRGlobalNote::EESMRRepeatReSchedule );                
+                if ( err == KErrOverflow )
+                    {
+                    CESMRGlobalNote::ExecuteL(
+                            CESMRGlobalNote::EESMRRepeatReSchedule );
+                    }
+                else if ( err == KErrUnderflow )
+                    {
+                    CESMRGlobalNote::ExecuteL(
+                            CESMRGlobalNote::EESMRRepeatInstanceTooEarly );                    
+                    }
                 }
                 break;                
             case EESMRFieldStopDate:
@@ -269,6 +240,11 @@
                     CESMRGlobalNote::ExecuteL(
                             CESMRGlobalNote::EESMRRepeatReSchedule );                    
                     }
+                else if ( err == KErrUnderflow )
+                    {
+                    CESMRGlobalNote::ExecuteL(
+                            CESMRGlobalNote::EESMRRepeatInstanceTooEarly );                    
+                    }
                 }
                 break;
 
@@ -297,8 +273,197 @@
     CESMRField::SetOutlineFocusL ( aFocus );
     if ( aFocus )
         {
-        ChangeMiddleSoftKeyL(EESMRCmdSaveMR,R_QTN_MSK_SAVE);
+        ChangeMiddleSoftKeyL( EESMRCmdSaveMR,R_QTN_MSK_SAVE );
+        }
+    }
+
+// ---------------------------------------------------------------------------
+// CESMRDateField::SetValidatorL
+// ---------------------------------------------------------------------------
+//
+void CESMRDateField::SetValidatorL( MESMRFieldValidator* aValidator )
+    {
+    CESMRField::SetValidatorL( aValidator );
+    InitializeValidatorL();
+    }
+
+// ---------------------------------------------------------------------------
+// CESMRDateField::SizeChanged()
+// ---------------------------------------------------------------------------
+//
+TBool CESMRDateField::ExecuteGenericCommandL( TInt aCommand )
+    {
+    FUNC_LOG;
+    
+    TBool retValue( EFalse );
+    
+    if ( EMRCmdDoEnvironmentChange == aCommand )
+        {
+        DoEnvChangeL();
+        retValue = ETrue;
+        }
+    
+    return retValue;
+    }
+
+
+// ---------------------------------------------------------------------------
+// CESMRDateField::CountComponentControls
+// ---------------------------------------------------------------------------
+//
+TInt CESMRDateField::CountComponentControls( ) const
+    {
+    FUNC_LOG;
+    TInt count( 0 );
+    if( iFieldIcon )
+        {
+        ++count;
+        }
+    if( iDate )
+        {
+        ++count;
+        }
+        
+    return count;
+    }
+
+// ---------------------------------------------------------------------------
+// CESMRDateField::ComponentControl
+// ---------------------------------------------------------------------------
+//
+CCoeControl* CESMRDateField::ComponentControl( TInt aInd ) const
+    {
+    FUNC_LOG;
+    
+    switch ( aInd )
+        {
+        case 0:
+            return iFieldIcon;
+        case 1:
+            return iDate;
+        default:
+            return NULL;
         }
     }
 
+// ---------------------------------------------------------------------------
+// CESMRDateField::SizeChanged
+// ---------------------------------------------------------------------------
+//
+void CESMRDateField::SizeChanged()
+    {
+    FUNC_LOG;
+    TRect rect( Rect() );
+
+    // Layouting field icon
+    if( iFieldIcon )
+        {
+        TAknWindowComponentLayout iconLayout = 
+            NMRLayoutManager::GetWindowComponentLayout( 
+                    NMRLayoutManager::EMRLayoutDateEditorIcon );
+        AknLayoutUtils::LayoutImage( iFieldIcon, rect, iconLayout );
+        }
+    
+    // Layouting date editor
+    if( iDate )
+        {
+        TAknLayoutRect bgLayoutRect = 
+            NMRLayoutManager::GetLayoutRect( 
+                    rect, NMRLayoutManager::EMRLayoutTextEditorBg );
+        TRect bgRect( bgLayoutRect.Rect() );
+        // Move focus rect so that it's relative to field's position.
+        bgRect.Move( -Position() );
+        SetFocusRect( bgRect );
+        
+        TAknTextComponentLayout editorLayout =
+            NMRLayoutManager::GetTextComponentLayout( 
+                    NMRLayoutManager::EMRTextLayoutDateEditor );
+        AknLayoutUtils::LayoutMfne( iDate, rect, editorLayout );
+
+        NMRColorManager::SetColor( *iDate, 
+                                   NMRColorManager::EMRMainAreaTextColor );
+        }
+    }
+
+// ---------------------------------------------------------------------------
+// CESMRDateField::SetContainerWindowL
+// ---------------------------------------------------------------------------
+//
+void CESMRDateField::SetContainerWindowL( 
+        const CCoeControl& aContainer )
+    {    
+    iContainerWindow = &aContainer;
+    
+    CCoeControl::SetContainerWindowL( *iContainerWindow );
+    iDate->SetContainerWindowL( *iContainerWindow );
+    iFieldIcon->SetContainerWindowL( *iContainerWindow );
+    
+    iDate->SetParent( this );
+    iFieldIcon->SetParent( this );
+    }
+
+// ---------------------------------------------------------------------------
+// CESMRDateField::InitializeValidatorL
+// ---------------------------------------------------------------------------
+//
+void CESMRDateField::InitializeValidatorL()
+    {
+    FUNC_LOG;
+    
+    // Initialize validator
+    if ( iValidator )
+        {
+        switch ( iFieldId )
+            {
+            case EESMRFieldStartDate:
+                iValidator->SetStartDateFieldL( *iDate );
+                break;
+            case EESMRFieldStopDate:
+                iValidator->SetEndDateFieldL( *iDate );
+                break;
+            case EESMRFieldAlarmDate:
+                iValidator->SetAlarmDateFieldL( *iDate );
+                break;
+            default:
+                break;
+            }
+        }    
+    }
+
+// ---------------------------------------------------------------------------
+// CESMRDateField::DoEnvChangeL
+// ---------------------------------------------------------------------------
+//
+void CESMRDateField::DoEnvChangeL()
+    {
+    FUNC_LOG;
+    
+    CEikDateEditor* date = new( ELeave )CEikDateEditor;
+    CleanupStack::PushL( date );
+    
+    TTime startTime;
+    startTime.UniversalTime();
+    
+    date->ConstructL( 
+            TTIME_MINIMUMDATE, 
+            TTIME_MAXIMUMDATE, 
+            startTime, 
+            EFalse );
+    
+    date->SetUpAndDownKeysConsumed( EFalse );        
+    
+    UpdateExtControlL( date );
+    
+    CleanupStack::Pop( date );
+    iDate = date;
+    InitializeValidatorL();
+    
+    iDate->SetSkinBackgroundControlContextL( iBgCtrlContext );        
+    SetContainerWindowL( *iContainerWindow );
+    
+    iDate->ActivateL();        
+    SizeChanged();
+    DrawDeferred();    
+    }
+
 // EOF