meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrdatefield.cpp
changeset 0 8466d47a6819
child 12 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:  ESMR date field impl.
       
    15  *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include "cesmrdatefield.h"
       
    20 
       
    21 #include <eikmfne.h>
       
    22 #include <avkon.hrh>
       
    23 #include <AknsConstants.h>
       
    24 #include <AknUtils.h>
       
    25 #include <AknsDrawUtils.h>
       
    26 #include <AknsFrameBackgroundControlContext.h>
       
    27 //<cmail>
       
    28 #include "esmrdef.h"
       
    29 //</cmail>
       
    30 
       
    31 #include "cesmrmeetingtimevalidator.h"
       
    32 #include "cesmrglobalnote.h"
       
    33 #include "esmrfieldbuilderdef.h"
       
    34 #include "mesmrlistobserver.h"
       
    35 #include "cesmrgenericfieldevent.h"
       
    36 
       
    37 // ======== MEMBER FUNCTIONS ========
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CESMRDateField::CESMRDateField
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CESMRDateField::CESMRDateField(
       
    44         MESMRFieldValidator* aValidator ) :
       
    45     iValidator(aValidator)
       
    46     {
       
    47     FUNC_LOG;
       
    48     //do nothing
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CESMRDateField::~CESMRDateField
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CESMRDateField::~CESMRDateField( )
       
    56     {
       
    57     FUNC_LOG;
       
    58     delete iFrameBgContext;
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CESMRDateField::NewL
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CESMRDateField* CESMRDateField::NewL(
       
    66         MESMRFieldValidator* aValidator,
       
    67         TESMREntryFieldId aId )
       
    68     {
       
    69     FUNC_LOG;
       
    70     CESMRDateField* self = new (ELeave) CESMRDateField( aValidator );
       
    71     CleanupStack::PushL ( self );
       
    72     self->ConstructL( aId );
       
    73     CleanupStack::Pop( self );
       
    74     return self;
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // CESMRDateField::ConstructL
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 void CESMRDateField::ConstructL( TESMREntryFieldId aId )
       
    82     {
       
    83     FUNC_LOG;
       
    84     SetFieldId ( aId );
       
    85 
       
    86     TTime startTime;
       
    87     startTime.UniversalTime ( );
       
    88 
       
    89     iDate = new (ELeave) CEikDateEditor;
       
    90     iDate->ConstructL( TTIME_MINIMUMDATE, TTIME_MAXIMUMDATE, startTime, EFalse );
       
    91     iDate->SetUpAndDownKeysConsumed ( EFalse );
       
    92     
       
    93     TAknsItemID aIconID = (iFieldId == EESMRFieldStartDate) ? KAknsIIDQgnMeetReqIndiDateStart
       
    94             : KAknsIIDQgnMeetReqIndiDateEnd;
       
    95 
       
    96     iBackground = AknsDrawUtils::ControlContext( this );
       
    97     CESMRIconField::ConstructL( aIconID, iDate ); // ownership transferred
       
    98 
       
    99     // Initialize validator
       
   100     if ( iValidator )
       
   101         {
       
   102         switch ( iFieldId )
       
   103             {
       
   104             case EESMRFieldStartDate:
       
   105                 iValidator->SetStartDateFieldL( *iDate );
       
   106                 break;
       
   107             case EESMRFieldStopDate:
       
   108                 iValidator->SetEndDateFieldL( *iDate );
       
   109                 break;
       
   110             case EESMRFieldAlarmDate:
       
   111                 iValidator->SetAlarmDateFieldL( *iDate );
       
   112                 break;
       
   113             default:
       
   114                 break;
       
   115             }
       
   116         }
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CESMRDateField::InitializeL
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CESMRDateField::InitializeL()
       
   124     {
       
   125     FUNC_LOG;
       
   126     iDate->SetFont( iLayout->Font(iCoeEnv, iFieldId ) );
       
   127     iDate->SetMfneAlignment( CESMRLayoutManager::IsMirrored()
       
   128                              ? EAknEditorAlignRight : EAknEditorAlignLeft );
       
   129 
       
   130     iDate->SetSkinTextColorL( iLayout->NormalTextColorID() );
       
   131     iDate->SetBorder( TGulBorder::ENone );
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CESMRDateField::OkToLoseFocusL
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 TBool CESMRDateField::OkToLoseFocusL(
       
   139         TESMREntryFieldId /*aNextItem*/ )
       
   140     {
       
   141     FUNC_LOG;
       
   142     return TriggerValidatorL();
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // CESMRDateField::OfferKeyEventL
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 TKeyResponse CESMRDateField::OfferKeyEventL(const TKeyEvent& aEvent,
       
   150         TEventCode aType )
       
   151     {
       
   152     FUNC_LOG;
       
   153     TKeyResponse response( EKeyWasNotConsumed);
       
   154 
       
   155     if ( aType == EEventKey )
       
   156         {
       
   157         TInt fieldIndex( iDate->CurrentField() );
       
   158 
       
   159         // flowthrough, these events shouldn't be consumed
       
   160         if ( aEvent.iScanCode != EStdKeyUpArrow &&
       
   161              aEvent.iScanCode != EStdKeyDownArrow )
       
   162             {
       
   163             response = iDate->OfferKeyEventL( aEvent, aType );
       
   164             }
       
   165         }
       
   166 
       
   167     return response;
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // CESMRDateField::PositionChanged()
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 void CESMRDateField::PositionChanged()
       
   175     {
       
   176     FUNC_LOG;
       
   177     CCoeControl::PositionChanged();
       
   178     if( iFrameBgContext )
       
   179         {
       
   180         iFrameBgContext->SetFrameRects( iDate->Rect(), iDate->Rect() );
       
   181         }
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // CESMRDateField::ActivateL
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 void CESMRDateField::ActivateL()
       
   189     {
       
   190     FUNC_LOG;
       
   191     CCoeControl::ActivateL();
       
   192     TRect rect(TPoint(iDate->Position()), iDate->Size());
       
   193     TRect inner(rect);
       
   194     TRect outer(rect);
       
   195 
       
   196     iDate->SetSize(iLayout->FieldSize( FieldId() ));
       
   197     
       
   198     delete iFrameBgContext;
       
   199     iFrameBgContext = NULL;
       
   200     iFrameBgContext = CAknsFrameBackgroundControlContext::NewL(KAknsIIDQsnFrInput, outer, inner, EFalse ) ;
       
   201 
       
   202     iFrameBgContext->SetParentContext( iBackground );
       
   203     iDate->SetSkinBackgroundControlContextL(iFrameBgContext);
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // CESMRDateField::CheckIfValidatingNeededL
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 void CESMRDateField::CheckIfValidatingNeededL(
       
   211         TInt aStartFieldIndex )
       
   212     {
       
   213     FUNC_LOG;
       
   214     TInt fieldIndex( iDate->CurrentField() );
       
   215 
       
   216     if ( fieldIndex != aStartFieldIndex )
       
   217         {
       
   218         TriggerValidatorL();
       
   219         }
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CESMRDateField::TriggerValidatorL
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 TBool CESMRDateField::TriggerValidatorL()
       
   227     {
       
   228     FUNC_LOG;
       
   229     TInt err( KErrNone );
       
   230 
       
   231     if (iValidator )
       
   232         {
       
   233         switch ( iFieldId )
       
   234             {
       
   235             case EESMRFieldStartDate:
       
   236                 TRAP( err, iValidator->StartDateChandedL() );
       
   237                 break;
       
   238             case EESMRFieldStopDate:
       
   239                 TRAP(err, iValidator->EndDateChangedL() );
       
   240                 break;
       
   241             case EESMRFieldAlarmDate:
       
   242                 TRAP(err, iValidator->AlarmDateChangedL() );
       
   243                 break;
       
   244             default:
       
   245                 break;
       
   246             }
       
   247         }
       
   248 
       
   249 
       
   250     if ( KErrNone != err )
       
   251         {
       
   252         switch ( iFieldId )
       
   253             {
       
   254             case EESMRFieldStartDate:
       
   255                 {
       
   256                 CESMRGlobalNote::ExecuteL(
       
   257                         CESMRGlobalNote::EESMRRepeatReSchedule );                
       
   258                 }
       
   259                 break;                
       
   260             case EESMRFieldStopDate:
       
   261                 {
       
   262                 if ( err == KErrArgument )
       
   263                     {
       
   264                     CESMRGlobalNote::ExecuteL(
       
   265                             CESMRGlobalNote::EESMREndsBeforeStarts );
       
   266                     }
       
   267                 else if ( err == KErrOverflow )
       
   268                     {
       
   269                     CESMRGlobalNote::ExecuteL(
       
   270                             CESMRGlobalNote::EESMRRepeatReSchedule );                    
       
   271                     }
       
   272                 }
       
   273                 break;
       
   274 
       
   275             case EESMRFieldAlarmDate:
       
   276                 {
       
   277                 CESMRGlobalNote::ExecuteL(
       
   278                         CESMRGlobalNote::EESMRCalenLaterDate );
       
   279                 }
       
   280                 break;
       
   281             
       
   282             default:
       
   283                 break;
       
   284             }
       
   285         }
       
   286     
       
   287     return ( KErrNone == err );
       
   288     }
       
   289 
       
   290 // ---------------------------------------------------------------------------
       
   291 // CESMRDateField::SetOutlineFocusL
       
   292 // ---------------------------------------------------------------------------
       
   293 //
       
   294 void CESMRDateField::SetOutlineFocusL( TBool aFocus )
       
   295     {
       
   296     FUNC_LOG;
       
   297     CESMRField::SetOutlineFocusL ( aFocus );
       
   298     if ( aFocus )
       
   299         {
       
   300         ChangeMiddleSoftKeyL(EESMRCmdSaveMR,R_QTN_MSK_SAVE);
       
   301         }
       
   302     }
       
   303 
       
   304 // EOF