meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrsingletimefield.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 0 8466d47a6819
child 16 b5fbb9b25d57
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
     1 /*
     1 /*
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    13 *
    13 *
    14 * Description:  ESMR single time field implementation
    14 * Description:  ESMR single time field implementation
    15  *
    15  *
    16 */
    16 */
    17 
    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"
    18 #include "cesmrsingletimefield.h"
    28 #include "mesmrfieldvalidator.h"
    19 #include "mesmrfieldvalidator.h"
    29 #include "cesmrglobalnote.h"
    20 #include "cesmrglobalnote.h"
    30 #include "esmrfieldbuilderdef.h"
    21 #include "esmrfieldbuilderdef.h"
    31 #include <AknUtils.h>
    22 #include "cmrimage.h"
       
    23 #include "nmrlayoutmanager.h"
       
    24 #include "nmrcolormanager.h"
       
    25 #include "nmrbitmapmanager.h"
       
    26 
       
    27 #include <aknsbasicbackgroundcontrolcontext.h>
       
    28 #include <eikmfne.h>
       
    29 
       
    30 #include "emailtrace.h"
    32 
    31 
    33 namespace{  // codescanner::namespace
    32 namespace{  // codescanner::namespace
    34 #define KMinimumTime (TTime(0)) // codescanner::baddefines
    33 #define KMinimumTime (TTime(0)) // codescanner::baddefines
    35 
    34 
    36 // 24 hours in microseconds
    35 // 24 hours in microseconds
    37 const TInt64 KDayInMicroSeconds = 86400000000;
    36 const TInt64 KDayInMicroSeconds = 86400000000;
    38 #define KMaximumTime (TTime(KDayInMicroSeconds)) // codescanner::baddefines 
    37 #define KMaximumTime (TTime(KDayInMicroSeconds)) // codescanner::baddefines 
    39 }
    38 }
    40 
    39 
       
    40 // ======== MEMBER FUNCTIONS ========
       
    41 
    41 // ---------------------------------------------------------------------------
    42 // ---------------------------------------------------------------------------
    42 // CESMRSingleTimeField::CESMRSingleTimeField
    43 // CESMRSingleTimeField::CESMRSingleTimeField
    43 // ---------------------------------------------------------------------------
    44 // ---------------------------------------------------------------------------
    44 //
    45 //
    45 CESMRSingleTimeField::CESMRSingleTimeField(
    46 CESMRSingleTimeField::CESMRSingleTimeField( MESMRFieldValidator* aValidator ) 
    46         MESMRFieldValidator* aValidator ) :
    47     {
    47     iValidator( aValidator )
    48     FUNC_LOG;
    48     {
    49     
    49     FUNC_LOG;
    50     iValidator = aValidator;
    50     //do nothing
    51     SetFieldId ( EESMRFieldAlarmTime );
       
    52     SetFocusType( EESMRHighlightFocus );
    51     }
    53     }
    52 
    54 
    53 // ---------------------------------------------------------------------------
    55 // ---------------------------------------------------------------------------
    54 // CESMRSingleTimeField::~CESMRSingleTimeField
    56 // CESMRSingleTimeField::~CESMRSingleTimeField
    55 // ---------------------------------------------------------------------------
    57 // ---------------------------------------------------------------------------
    56 //
    58 //
    57 CESMRSingleTimeField::~CESMRSingleTimeField( )
    59 CESMRSingleTimeField::~CESMRSingleTimeField()
    58     {
    60     {
    59     FUNC_LOG;
    61     FUNC_LOG;
    60     delete iFrameBgContext;
    62     delete iFieldIcon;
       
    63     delete iBgCtrlContext;
    61     }
    64     }
    62 
    65 
    63 // ---------------------------------------------------------------------------
    66 // ---------------------------------------------------------------------------
    64 // CESMRSingleTimeField::NewL
    67 // CESMRSingleTimeField::NewL
    65 // ---------------------------------------------------------------------------
    68 // ---------------------------------------------------------------------------
    66 //
    69 //
    67 CESMRSingleTimeField* CESMRSingleTimeField::NewL(
    70 CESMRSingleTimeField* CESMRSingleTimeField::NewL( 
    68         MESMRFieldValidator* aValidator )
    71         MESMRFieldValidator* aValidator )
    69     {
    72     {
    70     FUNC_LOG;
    73     FUNC_LOG;
    71     CESMRSingleTimeField* self =
    74     CESMRSingleTimeField* self =
    72             new (ELeave) CESMRSingleTimeField( aValidator );
    75             new( ELeave )CESMRSingleTimeField( aValidator );
    73     CleanupStack::PushL ( self );
    76     CleanupStack::PushL( self );
    74     self->ConstructL ( );
    77     self->ConstructL();
    75     CleanupStack::Pop ( self );
    78     CleanupStack::Pop( self );
    76     return self;
    79     return self;
    77     }
    80     }
    78 
    81 
    79 // ---------------------------------------------------------------------------
    82 // ---------------------------------------------------------------------------
    80 // CESMRSingleTimeField::ConstructL
    83 // CESMRSingleTimeField::ConstructL
    81 // ---------------------------------------------------------------------------
    84 // ---------------------------------------------------------------------------
    82 //
    85 //
    83 void CESMRSingleTimeField::ConstructL( )
    86 void CESMRSingleTimeField::ConstructL( )
    84     {
    87     {
    85     FUNC_LOG;
    88     FUNC_LOG;
    86     SetFieldId ( EESMRFieldAlarmTime );
    89     
    87 
    90     SetComponentsToInheritVisibility( ETrue );
       
    91     
    88     TTime startTime;
    92     TTime startTime;
    89     startTime.HomeTime();
    93     startTime.HomeTime();
    90 
    94 
    91     iTime = new (ELeave) CEikTimeEditor();
    95     iTime = new( ELeave )CEikTimeEditor();
       
    96     
       
    97     CESMRField::ConstructL( iTime ); //ownership transferred
       
    98     
    92     iTime->ConstructL(
    99     iTime->ConstructL(
    93             KMinimumTime,
   100             KMinimumTime,
    94             KMaximumTime,
   101             KMaximumTime,
    95             startTime,
   102             startTime,
    96             EEikTimeWithoutSecondsField );
   103             EEikTimeWithoutSecondsField );
    97     iTime->SetUpAndDownKeysConsumed( EFalse );
   104     iTime->SetUpAndDownKeysConsumed( EFalse );
    98 
   105   
    99     iBackground = AknsDrawUtils::ControlContext( this );
   106     iFieldIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapAlarmClock );
   100 
   107     iFieldIcon->SetParent( this );
   101     CESMRIconField::ConstructL(
   108     
   102             KAknsIIDQgnFscalIndiAlarmTime,
   109     if( iValidator )
   103             iTime );
       
   104 
       
   105     if ( iValidator )
       
   106         {
   110         {
   107         iValidator->SetAlarmTimeFieldL( *iTime );
   111         iValidator->SetAlarmTimeFieldL( *iTime );
   108         }
   112         }
   109     }
   113     
   110 
   114     TRect tempRect( 0, 0, 0, 0 );
   111 // ---------------------------------------------------------------------------
   115     
   112 // CESMRSingleTimeField::InitializeL
   116     // Setting background instead of theme skin  
   113 // ---------------------------------------------------------------------------
   117     NMRBitmapManager::TMRBitmapStruct bitmapStruct;
   114 //
   118     bitmapStruct = NMRBitmapManager::GetBitmapStruct( NMRBitmapManager::EMRBitmapInputCenter );
   115 void CESMRSingleTimeField::InitializeL()
   119 
   116     {
   120     iBgCtrlContext = CAknsBasicBackgroundControlContext::NewL( 
   117     FUNC_LOG;
   121                 bitmapStruct.iItemId, 
   118     iTime->SetFont ( iLayout->Font (iCoeEnv, iFieldId ) );
   122                 tempRect, 
   119     iTime->SetMfneAlignment ( CESMRLayoutManager::IsMirrored ( ) ? EAknEditorAlignRight
   123                 EFalse );
   120             : EAknEditorAlignLeft );
   124         
   121 
   125     iTime->SetSkinBackgroundControlContextL( iBgCtrlContext );
   122     iTime->SetBorder( TGulBorder::ENone );
       
   123     iTime->SetSkinTextColorL( iLayout->NormalTextColorID ( ) );
       
   124     }
   126     }
   125 
   127 
   126 // ---------------------------------------------------------------------------
   128 // ---------------------------------------------------------------------------
   127 // CESMRSingleTimeField::OkToLoseFocusL
   129 // CESMRSingleTimeField::OkToLoseFocusL
   128 // ---------------------------------------------------------------------------
   130 // ---------------------------------------------------------------------------
   129 //
   131 //
   130 TBool CESMRSingleTimeField::OkToLoseFocusL(
   132 TBool CESMRSingleTimeField::OkToLoseFocusL(
   131         TESMREntryFieldId /*aNextItem*/ )
   133         TESMREntryFieldId /*aNextItem*/ )
   132     {
   134     {
   133     FUNC_LOG;
   135     FUNC_LOG;
   134     TInt err(KErrNone );
   136     TInt err( KErrNone );
   135     if ( iValidator )
   137     if( iValidator )
   136         {
   138         {
   137         TRAP( err, iValidator->AlarmTimeChangedL() );
   139         TRAP( err, iValidator->AlarmTimeChangedL() );
   138         }
   140         }
   139     if ( err != KErrNone )
   141     if( err != KErrNone )
   140         {
   142         {
   141         CESMRGlobalNote::ExecuteL (
   143         CESMRGlobalNote::ExecuteL(
   142                 CESMRGlobalNote::EESMRCalenLaterDate );
   144                 CESMRGlobalNote::EESMRCalenLaterDate );
   143         return EFalse;
   145         return EFalse;
   144         }
   146         }
   145     return ETrue;
   147     return ETrue;
   146     }
   148     }
   147 
   149 
   148 // ---------------------------------------------------------------------------
   150 // ---------------------------------------------------------------------------
   149 // CESMRSingleTimeField::OfferKeyEventL
   151 // CESMRSingleTimeField::OfferKeyEventL
   150 // ---------------------------------------------------------------------------
   152 // ---------------------------------------------------------------------------
   151 //
   153 //
   152 TKeyResponse CESMRSingleTimeField::OfferKeyEventL(const TKeyEvent& aEvent,
   154 TKeyResponse CESMRSingleTimeField::OfferKeyEventL( const TKeyEvent& aEvent,
   153         TEventCode aType )
   155         TEventCode aType )
   154     {
   156     {
   155     FUNC_LOG;
   157     FUNC_LOG;
   156     TKeyResponse response( EKeyWasNotConsumed);
   158     TKeyResponse response( EKeyWasNotConsumed );
   157     if ( aType == EEventKey )
   159     if ( aType == EEventKey )
   158         {
   160         {
   159         TInt fieldIndex( iTime->CurrentField() );
   161         TInt fieldIndex( iTime->CurrentField() );
   160 
   162 
   161         switch ( aEvent.iScanCode )
   163         switch( aEvent.iScanCode )
   162             {
   164             {
   163             // make sure these events are NOT consumed
   165             // make sure these events are NOT consumed
   164             case EStdKeyUpArrow:
   166             case EStdKeyUpArrow:
   165             case EStdKeyDownArrow:
   167             case EStdKeyDownArrow:
   166                 break;
   168                 break;
   167 
   169 
   168             default:
   170             default:
   169                 response = iTime->OfferKeyEventL ( aEvent, aType );
   171                 response = iTime->OfferKeyEventL ( aEvent, aType );
       
   172                 iTime->DrawDeferred();
   170                 break;
   173                 break;
   171             }
   174             }
   172 
   175 
   173         CheckIfValidatingNeededL( fieldIndex );
   176         CheckIfValidatingNeededL( fieldIndex );
   174         }
   177         }
   175     return response;
   178     return response;
   176     }
   179     }
   177 
   180 
   178 // ---------------------------------------------------------------------------
   181 // ---------------------------------------------------------------------------
   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
   182 // CESMRSingleTimeField::CheckIfValidatingNeededL
   216 // ---------------------------------------------------------------------------
   183 // ---------------------------------------------------------------------------
   217 //
   184 //
   218 void CESMRSingleTimeField::CheckIfValidatingNeededL(
   185 void CESMRSingleTimeField::CheckIfValidatingNeededL(
   219         TInt aStartFieldIndex )
   186         TInt aStartFieldIndex )
   220     {
   187     {
   221     FUNC_LOG;
   188     FUNC_LOG;
   222     TInt err( KErrNone );
   189     TInt err( KErrNone );
   223     TInt fieldIndex( iTime->CurrentField() );
   190     TInt fieldIndex( iTime->CurrentField() );
   224 
   191 
   225     if ( fieldIndex != aStartFieldIndex )
   192     if( fieldIndex != aStartFieldIndex )
   226         {
   193         {
   227         TRAP( err, iValidator->AlarmTimeChangedL() );
   194         TRAP( err, iValidator->AlarmTimeChangedL() );
   228         }
   195         }
   229 
   196 
   230     if ( err != KErrNone )
   197     if( err != KErrNone )
   231         {
   198         {
   232         CESMRGlobalNote::ExecuteL (
   199         CESMRGlobalNote::ExecuteL (
   233                 CESMRGlobalNote::EESMRCalenLaterDate );
   200                 CESMRGlobalNote::EESMRCalenLaterDate );
   234         }
   201         }
   235     }
   202     }
   238 // ---------------------------------------------------------------------------
   205 // ---------------------------------------------------------------------------
   239 //
   206 //
   240 void CESMRSingleTimeField::SetOutlineFocusL( TBool aFocus )
   207 void CESMRSingleTimeField::SetOutlineFocusL( TBool aFocus )
   241     {
   208     {
   242     FUNC_LOG;
   209     FUNC_LOG;
   243     CESMRField::SetOutlineFocusL ( aFocus );
   210     CESMRField::SetOutlineFocusL( aFocus );
   244     if ( aFocus )
   211     
   245         {
   212     if( aFocus )
   246         ChangeMiddleSoftKeyL(EESMRCmdSaveMR,R_QTN_MSK_SAVE);
   213         {
   247         }
   214         ChangeMiddleSoftKeyL( EESMRCmdSaveMR, R_QTN_MSK_SAVE );
       
   215         }
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // CESMRSingleTimeField::SetValidatorL
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 void CESMRSingleTimeField::SetValidatorL( MESMRFieldValidator* aValidator )
       
   223     {
       
   224     FUNC_LOG;
       
   225     
       
   226     CESMRField::SetValidatorL( aValidator );
       
   227     
       
   228     if ( iValidator )
       
   229         {
       
   230         iValidator->SetAlarmTimeFieldL( *iTime );
       
   231         }
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // CESMRSingleTimeField::SizeChanged()
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 TBool CESMRSingleTimeField::ExecuteGenericCommandL( TInt aCommand )
       
   239     {
       
   240     FUNC_LOG;
       
   241     
       
   242     TBool retValue( EFalse );
       
   243     
       
   244     if ( EMRCmdDoEnvironmentChange == aCommand )
       
   245         {
       
   246         // Locale has been changed       
       
   247         DoEnvChangeL();
       
   248         retValue = ETrue;
       
   249         }
       
   250     
       
   251     return retValue;
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // CESMRSingleTimeField::SizeChanged()
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 void CESMRSingleTimeField::SizeChanged()
       
   259     {
       
   260      TRect rect( Rect() );
       
   261 
       
   262     // Layouting field icon
       
   263     if( iFieldIcon )
       
   264         {
       
   265         TAknWindowComponentLayout iconLayout = 
       
   266             NMRLayoutManager::GetWindowComponentLayout( 
       
   267                     NMRLayoutManager::EMRLayoutDateEditorIcon );
       
   268         AknLayoutUtils::LayoutImage( iFieldIcon, rect, iconLayout );
       
   269         }
       
   270         
       
   271     // Layouting time editor
       
   272     if( iTime )
       
   273         {
       
   274         TAknLayoutRect bgLayoutRect = 
       
   275             NMRLayoutManager::GetLayoutRect( 
       
   276                     rect, NMRLayoutManager::EMRLayoutTextEditorBg );
       
   277         TRect bgRect( bgLayoutRect.Rect() );
       
   278         // Move focus rect so that it's relative to field's position.
       
   279         bgRect.Move( -Position() );
       
   280         SetFocusRect( bgRect );
       
   281         
       
   282         TAknTextComponentLayout editorLayout =
       
   283             NMRLayoutManager::GetTextComponentLayout( 
       
   284                     NMRLayoutManager::EMRTextLayoutDateEditor );
       
   285         AknLayoutUtils::LayoutMfne( iTime, rect, editorLayout );
       
   286         
       
   287         NMRColorManager::SetColor( *iTime, 
       
   288                                    NMRColorManager::EMRMainAreaTextColor );
       
   289 
       
   290         }
       
   291     }
       
   292 
       
   293 // ---------------------------------------------------------------------------
       
   294 // CESMRSingleTimeField::CountComponentControls()
       
   295 // ---------------------------------------------------------------------------
       
   296 //
       
   297 TInt CESMRSingleTimeField::CountComponentControls() const
       
   298     {
       
   299     TInt count( 0 );
       
   300     if( iFieldIcon )
       
   301         {
       
   302         ++count;
       
   303         }
       
   304 
       
   305     if( iTime )
       
   306         {
       
   307         ++count;
       
   308         }
       
   309     return count;
       
   310     }
       
   311 
       
   312 // ---------------------------------------------------------------------------
       
   313 // CESMRSingleTimeField::ComponentControl()
       
   314 // ---------------------------------------------------------------------------
       
   315 //
       
   316 CCoeControl* CESMRSingleTimeField::ComponentControl( TInt aIndex ) const
       
   317     {
       
   318     switch( aIndex )
       
   319         {
       
   320         case 0:
       
   321             return iFieldIcon;
       
   322         case 1:
       
   323             return iTime;
       
   324         default:
       
   325             return NULL;
       
   326         }
       
   327     }
       
   328 
       
   329 // ---------------------------------------------------------------------------
       
   330 // CESMRSingleTimeField::SetContainerWindowL
       
   331 // ---------------------------------------------------------------------------
       
   332 //
       
   333 void CESMRSingleTimeField::SetContainerWindowL( 
       
   334         const CCoeControl& aContainer )
       
   335     {
       
   336     iContainerWindow = &aContainer;
       
   337     
       
   338     CCoeControl::SetContainerWindowL( *iContainerWindow );
       
   339     
       
   340     iFieldIcon->SetContainerWindowL( *iContainerWindow );
       
   341     iTime->SetContainerWindowL( *iContainerWindow );
       
   342     
       
   343     iFieldIcon->SetParent( this );
       
   344     iTime->SetParent( this );
       
   345     }
       
   346 
       
   347 // ---------------------------------------------------------------------------
       
   348 // CESMRSingleTimeField::DoEnvChangeL
       
   349 // ---------------------------------------------------------------------------
       
   350 //
       
   351 void CESMRSingleTimeField::DoEnvChangeL()
       
   352     {
       
   353     FUNC_LOG;
       
   354     
       
   355     CEikTimeEditor* time = new( ELeave )CEikTimeEditor;
       
   356     CleanupStack::PushL( time );
       
   357     
       
   358     TTime startTime;
       
   359     startTime.HomeTime();    
       
   360     
       
   361     time->ConstructL(
       
   362             KMinimumTime,
       
   363             KMaximumTime,
       
   364             startTime,
       
   365             EEikTimeWithoutSecondsField );
       
   366     
       
   367     time->SetUpAndDownKeysConsumed( EFalse );       
       
   368     
       
   369     UpdateExtControlL( time );
       
   370     
       
   371     CleanupStack::Pop( time );
       
   372     iTime = time;
       
   373 
       
   374     iTime->SetSkinBackgroundControlContextL( iBgCtrlContext );        
       
   375     SetContainerWindowL( *iContainerWindow );    
       
   376     
       
   377     if ( iValidator )
       
   378         {
       
   379         iValidator->SetAlarmTimeFieldL( *iTime );
       
   380         }
       
   381     
       
   382     iTime->ActivateL();
       
   383     
       
   384     SizeChanged();
       
   385     DrawDeferred();    
   248     }
   386     }
   249 
   387 
   250 // EOF
   388 // EOF
   251 
   389