meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrsingletimefield.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:  ESMR single time field implementation
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <eikmfne.h>
       
    21 #include <eiklabel.h>
       
    22 #include <AknsConstants.h>
       
    23 #include <avkon.hrh>
       
    24 #include <AknsDrawUtils.h>
       
    25 #include <AknsFrameBackgroundControlContext.h>
       
    26 
       
    27 #include "cesmrsingletimefield.h"
       
    28 #include "mesmrfieldvalidator.h"
       
    29 #include "cesmrglobalnote.h"
       
    30 #include "esmrfieldbuilderdef.h"
       
    31 #include <AknUtils.h>
       
    32 
       
    33 namespace{  // codescanner::namespace
       
    34 #define KMinimumTime (TTime(0)) // codescanner::baddefines
       
    35 
       
    36 // 24 hours in microseconds
       
    37 const TInt64 KDayInMicroSeconds = 86400000000;
       
    38 #define KMaximumTime (TTime(KDayInMicroSeconds)) // codescanner::baddefines 
       
    39 }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CESMRSingleTimeField::CESMRSingleTimeField
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CESMRSingleTimeField::CESMRSingleTimeField(
       
    46         MESMRFieldValidator* aValidator ) :
       
    47     iValidator( aValidator )
       
    48     {
       
    49     FUNC_LOG;
       
    50     //do nothing
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CESMRSingleTimeField::~CESMRSingleTimeField
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CESMRSingleTimeField::~CESMRSingleTimeField( )
       
    58     {
       
    59     FUNC_LOG;
       
    60     delete iFrameBgContext;
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CESMRSingleTimeField::NewL
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CESMRSingleTimeField* CESMRSingleTimeField::NewL(
       
    68         MESMRFieldValidator* aValidator )
       
    69     {
       
    70     FUNC_LOG;
       
    71     CESMRSingleTimeField* self =
       
    72             new (ELeave) CESMRSingleTimeField( aValidator );
       
    73     CleanupStack::PushL ( self );
       
    74     self->ConstructL ( );
       
    75     CleanupStack::Pop ( self );
       
    76     return self;
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CESMRSingleTimeField::ConstructL
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 void CESMRSingleTimeField::ConstructL( )
       
    84     {
       
    85     FUNC_LOG;
       
    86     SetFieldId ( EESMRFieldAlarmTime );
       
    87 
       
    88     TTime startTime;
       
    89     startTime.HomeTime();
       
    90 
       
    91     iTime = new (ELeave) CEikTimeEditor();
       
    92     iTime->ConstructL(
       
    93             KMinimumTime,
       
    94             KMaximumTime,
       
    95             startTime,
       
    96             EEikTimeWithoutSecondsField );
       
    97     iTime->SetUpAndDownKeysConsumed( EFalse );
       
    98 
       
    99     iBackground = AknsDrawUtils::ControlContext( this );
       
   100 
       
   101     CESMRIconField::ConstructL(
       
   102             KAknsIIDQgnFscalIndiAlarmTime,
       
   103             iTime );
       
   104 
       
   105     if ( iValidator )
       
   106         {
       
   107         iValidator->SetAlarmTimeFieldL( *iTime );
       
   108         }
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CESMRSingleTimeField::InitializeL
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CESMRSingleTimeField::InitializeL()
       
   116     {
       
   117     FUNC_LOG;
       
   118     iTime->SetFont ( iLayout->Font (iCoeEnv, iFieldId ) );
       
   119     iTime->SetMfneAlignment ( CESMRLayoutManager::IsMirrored ( ) ? EAknEditorAlignRight
       
   120             : EAknEditorAlignLeft );
       
   121 
       
   122     iTime->SetBorder( TGulBorder::ENone );
       
   123     iTime->SetSkinTextColorL( iLayout->NormalTextColorID ( ) );
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CESMRSingleTimeField::OkToLoseFocusL
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 TBool CESMRSingleTimeField::OkToLoseFocusL(
       
   131         TESMREntryFieldId /*aNextItem*/ )
       
   132     {
       
   133     FUNC_LOG;
       
   134     TInt err(KErrNone );
       
   135     if ( iValidator )
       
   136         {
       
   137         TRAP( err, iValidator->AlarmTimeChangedL() );
       
   138         }
       
   139     if ( err != KErrNone )
       
   140         {
       
   141         CESMRGlobalNote::ExecuteL (
       
   142                 CESMRGlobalNote::EESMRCalenLaterDate );
       
   143         return EFalse;
       
   144         }
       
   145     return ETrue;
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // CESMRSingleTimeField::OfferKeyEventL
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 TKeyResponse CESMRSingleTimeField::OfferKeyEventL(const TKeyEvent& aEvent,
       
   153         TEventCode aType )
       
   154     {
       
   155     FUNC_LOG;
       
   156     TKeyResponse response( EKeyWasNotConsumed);
       
   157     if ( aType == EEventKey )
       
   158         {
       
   159         TInt fieldIndex( iTime->CurrentField() );
       
   160 
       
   161         switch ( aEvent.iScanCode )
       
   162             {
       
   163             // make sure these events are NOT consumed
       
   164             case EStdKeyUpArrow:
       
   165             case EStdKeyDownArrow:
       
   166                 break;
       
   167 
       
   168             default:
       
   169                 response = iTime->OfferKeyEventL ( aEvent, aType );
       
   170                 break;
       
   171             }
       
   172 
       
   173         CheckIfValidatingNeededL( fieldIndex );
       
   174         }
       
   175     return response;
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CESMRSingleTimeField::ActivateL
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void CESMRSingleTimeField::ActivateL()
       
   183     {
       
   184     FUNC_LOG;
       
   185     CCoeControl::ActivateL();
       
   186     TRect rect(TPoint(iTime->Position()), iTime->Size());
       
   187     TRect inner(rect);
       
   188     TRect outer(rect);
       
   189 
       
   190     iTime->SetSize(iLayout->FieldSize( FieldId() ));
       
   191     
       
   192     delete iFrameBgContext;
       
   193     iFrameBgContext = NULL;
       
   194     iFrameBgContext = CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrInput, outer, inner, EFalse ) ;
       
   195 
       
   196     iFrameBgContext->SetParentContext( iBackground );
       
   197     iTime->SetSkinBackgroundControlContextL(iFrameBgContext);
       
   198     }
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // CESMRSingleTimeField::PositionChanged
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 void CESMRSingleTimeField::PositionChanged()
       
   205     {
       
   206     FUNC_LOG;
       
   207     CCoeControl::PositionChanged();
       
   208     if( iFrameBgContext )
       
   209         {
       
   210         iFrameBgContext->SetFrameRects( iTime->Rect(), iTime->Rect() );
       
   211         }
       
   212     }
       
   213 
       
   214 // ---------------------------------------------------------------------------
       
   215 // CESMRSingleTimeField::CheckIfValidatingNeededL
       
   216 // ---------------------------------------------------------------------------
       
   217 //
       
   218 void CESMRSingleTimeField::CheckIfValidatingNeededL(
       
   219         TInt aStartFieldIndex )
       
   220     {
       
   221     FUNC_LOG;
       
   222     TInt err( KErrNone );
       
   223     TInt fieldIndex( iTime->CurrentField() );
       
   224 
       
   225     if ( fieldIndex != aStartFieldIndex )
       
   226         {
       
   227         TRAP( err, iValidator->AlarmTimeChangedL() );
       
   228         }
       
   229 
       
   230     if ( err != KErrNone )
       
   231         {
       
   232         CESMRGlobalNote::ExecuteL (
       
   233                 CESMRGlobalNote::EESMRCalenLaterDate );
       
   234         }
       
   235     }
       
   236 // ---------------------------------------------------------------------------
       
   237 // CESMRSingleTimeField::SetOutlineFocusL
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 void CESMRSingleTimeField::SetOutlineFocusL( TBool aFocus )
       
   241     {
       
   242     FUNC_LOG;
       
   243     CESMRField::SetOutlineFocusL ( aFocus );
       
   244     if ( aFocus )
       
   245         {
       
   246         ChangeMiddleSoftKeyL(EESMRCmdSaveMR,R_QTN_MSK_SAVE);
       
   247         }
       
   248     }
       
   249 
       
   250 // EOF
       
   251