calendarui/editors/src/KoreanLunarDateEditor.cpp
branchRCL_3
changeset 31 97232defd20e
equal deleted inserted replaced
30:bd7edf625bdd 31:97232defd20e
       
     1 /*
       
     2 * Copyright (c) 2010 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <barsread.h>
       
    19 #include <aknextendedinputcapabilities.h>
       
    20 #include "KoreanLunarDateEditor.h"
       
    21 #include "KoreanLunarDateUtil.h"
       
    22 
       
    23 // debug
       
    24 #include "calendarui_debug.h"
       
    25 
       
    26 _LIT( KDelimiter, "/" );
       
    27 _LIT( KLunarIndicator, "\xC74C\xB825" );
       
    28 _LIT( KLeapIndicator, "\xC724\xB2EC" );
       
    29 
       
    30 const TInt KNumFields = 4; /* [Indicators][month]/[day] */
       
    31 const TInt KMinLeapMonth = 2;
       
    32 const TInt KMinMonth = 1;
       
    33 const TInt KMaxLeapMonth = 11;
       
    34 const TInt KMaxMonth = 12;
       
    35 const TInt KMinDay = 1;
       
    36 const TInt KMaxDay = 31;
       
    37 
       
    38 
       
    39 /**
       
    40  * Public method for constructing a CKoreanLunarDateEditor object.
       
    41  */
       
    42 CKoreanLunarDateEditor* CKoreanLunarDateEditor::NewL(MCalenServices* aServices)
       
    43     {
       
    44     TRACE_ENTRY_POINT;
       
    45     CKoreanLunarDateEditor* editor=new(ELeave)CKoreanLunarDateEditor(aServices);
       
    46     CleanupStack::PushL(editor);
       
    47     editor->ConstructL(0); // flags are not used
       
    48     CleanupStack::Pop(editor);
       
    49     
       
    50     TRACE_EXIT_POINT;
       
    51     return editor;
       
    52     }
       
    53 
       
    54 
       
    55 CKoreanLunarDateEditor::CKoreanLunarDateEditor(MCalenServices* aServices):iServices(aServices)
       
    56 	{
       
    57     TRACE_ENTRY_POINT;
       
    58     TRACE_EXIT_POINT;
       
    59 	}
       
    60 
       
    61 
       
    62 void CKoreanLunarDateEditor::ConstructL( const TInt /* aFlags */ )
       
    63 	{
       
    64     TRACE_ENTRY_POINT;
       
    65     HBufC* charField;
       
    66     iConverter = CKoreanCalConv::NewL();
       
    67     iDateUtil = CKoreanLunarDateUtil::NewL(iServices);
       
    68     iLeap = EFalse;
       
    69 // todo add editable field to first place to go around avkon crash if avkon can not be fixed
       
    70 	CreateFieldArrayL( KNumFields );
       
    71 
       
    72     iIndicatorField = HBufC::NewL(2);
       
    73     iIndicatorField->Des().Append( KLunarIndicator );
       
    74     AddField( CEikMfneSeparator::NewL( iIndicatorField ) );
       
    75 
       
    76 
       
    77     iMonthField = CEikMfneNumber::NewL( *Font(),
       
    78                                         KMinMonth,
       
    79                                         KMaxMonth,
       
    80                                         KMinMonth,
       
    81                                         (CEikMfneNumber::EFillWithLeadingZeros|CEikMfneNumber::EPreserveOldWidthBeforeEditing) );
       
    82     AddField( iMonthField );
       
    83     iMonthField->SetValue( KMinMonth, *Font() );
       
    84     charField = HBufC::NewLC(1);
       
    85     charField->Des().Append( KDelimiter );
       
    86     AddField( CEikMfneSeparator::NewL( charField ) );
       
    87     CleanupStack::Pop(); // charField
       
    88 
       
    89     iDayField = CEikMfneNumber::NewL( *Font(),
       
    90                                       KMinDay,
       
    91                                       KMaxDay,
       
    92                                       KMinDay,
       
    93                                       (CEikMfneNumber::EFillWithLeadingZeros|CEikMfneNumber::EPreserveOldWidthBeforeEditing) );
       
    94     AddField( iDayField );
       
    95     iDayField->SetValue( KMinDay, *Font() );
       
    96 	MObjectProvider* mop = InputCapabilities().ObjectProvider();
       
    97 	if( mop )
       
    98 	    {
       
    99 	    CAknExtendedInputCapabilities* extendedInputCapabilities = mop->MopGetObject( extendedInputCapabilities );
       
   100 	    if( extendedInputCapabilities ) 
       
   101 	        {
       
   102 	        extendedInputCapabilities->SetCapabilities( CAknExtendedInputCapabilities::ESupportsOnlyASCIIDigits );
       
   103 	        }
       
   104 	    }
       
   105 	TRACE_EXIT_POINT;
       
   106 	}
       
   107 
       
   108 /**
       
   109  * Method for Setting the date.
       
   110  * 
       
   111  */
       
   112 void CKoreanLunarDateEditor::SetDate( const TTime& aDate, TBool newEntry )
       
   113 	{
       
   114     TRACE_ENTRY_POINT;
       
   115     iDate = aDate.DateTime();
       
   116     TKoreanDate lunarDate;
       
   117     TInt err = KErrNone;
       
   118 
       
   119     if( !newEntry )
       
   120         {
       
   121         TRAP( err, iConverter->DateTimeToKoreanL( iDate, lunarDate ) );
       
   122         }
       
   123 
       
   124     if( newEntry || err != KErrNone )
       
   125         { /* Use always initial values in case of new entry or
       
   126              failed conversion */
       
   127         if( iLeap )
       
   128             {
       
   129             iMonthField->SetValue( KMinLeapMonth, *Font() );
       
   130             iDayField->SetValue( KMinDay, *Font() );
       
   131             }
       
   132         else
       
   133             {
       
   134             iMonthField->SetValue( KMinMonth, *Font() );
       
   135             iDayField->SetValue( KMinDay, *Font() );
       
   136             }
       
   137         }
       
   138     else
       
   139         {
       
   140         iMonthField->SetValue( lunarDate.iMonth, *Font() );
       
   141         iDayField->SetValue( lunarDate.iDay, *Font() );
       
   142         }
       
   143     //DrawNow();
       
   144     TBool error = EFalse;
       
   145     TBool dataAltered = ETrue;
       
   146     // needs to call this to make redraw work correctly
       
   147     HandleInteraction(EFalse, 2, 0, CEikMfneField::ECursor, dataAltered, error);
       
   148     TRACE_EXIT_POINT;
       
   149 	}
       
   150 
       
   151 /**
       
   152  * Method for reading the editor value.
       
   153  * 
       
   154  */
       
   155 TTime CKoreanLunarDateEditor::Date()
       
   156 	{
       
   157     TRACE_ENTRY_POINT;
       
   158     TRAP_IGNORE( iDate = iDateUtil->GetNearestGregorianDateL( iMonthField->Value(), iDayField->Value(), iLeap, iDate ) );
       
   159 	
       
   160     TRACE_EXIT_POINT;
       
   161     return TTime(iDate);
       
   162 	}
       
   163 
       
   164 /**
       
   165  * Method for setting the editor to leap mode.
       
   166  * Gets one parameter:
       
   167  * const TBool aLeap - ETrue if leap mode is to be enabled, EFalse if disabled.
       
   168  * 
       
   169  */
       
   170 void CKoreanLunarDateEditor::SetLeap( const TBool aLeap )
       
   171 	{
       
   172     TRACE_ENTRY_POINT;
       
   173     if( aLeap != iLeap )
       
   174         {
       
   175         iLeap = aLeap;
       
   176         if( iLeap )
       
   177             {
       
   178             iIndicatorField->Des().Replace( 0, 2, KLeapIndicator );
       
   179             iMonthField->SetValue( KMinLeapMonth, *Font() );
       
   180             iDayField->SetValue( KMinDay, *Font() );
       
   181             iMonthField->SetMinimumAndMaximum( KMinLeapMonth,
       
   182                                                KMaxLeapMonth,
       
   183                                                *Font() );
       
   184             }
       
   185         else
       
   186             {
       
   187             iIndicatorField->Des().Replace( 0, 2, KLunarIndicator );
       
   188             iMonthField->SetValue( KMinMonth, *Font() );
       
   189             iDayField->SetValue( KMinDay, *Font() );
       
   190             iMonthField->SetMinimumAndMaximum( KMinMonth,
       
   191                                                KMaxMonth,
       
   192                                                *Font() );
       
   193             }
       
   194         DrawNow();
       
   195         }
       
   196     TRACE_EXIT_POINT;
       
   197 	}
       
   198 
       
   199 /**
       
   200  * Method for reading the leap mode status.
       
   201  * 
       
   202  */
       
   203 TBool CKoreanLunarDateEditor::Leap() const
       
   204 	{
       
   205     TRACE_ENTRY_POINT;
       
   206     TRACE_EXIT_POINT;
       
   207     
       
   208     return iLeap;
       
   209     }
       
   210 
       
   211 /**
       
   212  * Method for constructing the control from resources.
       
   213  * Gets one parameter:
       
   214  * TResourceReader& aResourceReader - Reference to a resource reader associated to a
       
   215  * Korean lunar date editor control resource.
       
   216  * 
       
   217  */
       
   218 void CKoreanLunarDateEditor::ConstructFromResourceL(TResourceReader& aResourceReader)
       
   219 	{
       
   220     TRACE_ENTRY_POINT;
       
   221     TUint32 flags = aResourceReader.ReadUint8();
       
   222     ConstructL( flags );
       
   223     TRACE_EXIT_POINT;
       
   224 	}
       
   225 
       
   226 	
       
   227 void CKoreanLunarDateEditor::PrepareForFocusLossL()
       
   228 	{
       
   229     TRACE_ENTRY_POINT;
       
   230 	CEikMfne::PrepareForFocusLossL();
       
   231     CKoreanLunarDateUtil* dateUtil = CKoreanLunarDateUtil::NewLC(iServices);
       
   232     TTime nowTime;
       
   233     nowTime.HomeTime();
       
   234 
       
   235     TRAP_IGNORE( iDate = dateUtil->GetNearestGregorianDateL( iMonthField->Value(), iDayField->Value(), iLeap, nowTime.DateTime() ) );
       
   236     /* Pop and destroy dateUtil */
       
   237     CleanupStack::PopAndDestroy();
       
   238     TRACE_EXIT_POINT;
       
   239 	}
       
   240 
       
   241 void CKoreanLunarDateEditor::HandleControlStateChangeL( TInt aControlId )
       
   242 	{
       
   243     TRACE_ENTRY_POINT;
       
   244     TRACE_EXIT_POINT;
       
   245 	}
       
   246 
       
   247 void* CKoreanLunarDateEditor::ExtensionInterface( TUid /*aInterface*/ )
       
   248     {
       
   249     TRACE_ENTRY_POINT;
       
   250     TRACE_EXIT_POINT;
       
   251 
       
   252     return NULL;
       
   253     }
       
   254 
       
   255 void CKoreanLunarDateEditor::CEikMfne_Reserved()
       
   256 	{
       
   257     TRACE_ENTRY_POINT;
       
   258     TRACE_EXIT_POINT;
       
   259 	}
       
   260 	
       
   261 // End of file