phonebookui/Phonebook2/UIControls/src/CPbk2ContactEditorPostalCodeField.cpp
changeset 0 e686773b3f54
child 74 6b5524b4f673
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  Phonebook 2 contact editor postal code field.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CPbk2ContactEditorPostalCodeField.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include "MPbk2ContactEditorUiBuilder.h"
       
    23 #include "MPbk2ContactEditorFieldVisitor.h"
       
    24 #include <MPbk2FieldProperty.h>
       
    25 #include <CPbk2PresentationContactField.h>
       
    26 #include <Phonebook2PrivateCRKeys.h>
       
    27 
       
    28 // Virtual Phonebook
       
    29 #include <MVPbkContactFieldTextData.h>
       
    30 #include <VPbkVariant.hrh>
       
    31 
       
    32 // System includes
       
    33 #include <eikcapc.h>
       
    34 #include <eikedwin.h>
       
    35 #include <AknUtils.h>
       
    36 #include <centralrepository.h>
       
    37 
       
    38 // --------------------------------------------------------------------------
       
    39 // CPbk2ContactEditorPostalCodeField::CPbk2ContactEditorPostalCodeField
       
    40 // --------------------------------------------------------------------------
       
    41 //
       
    42 inline CPbk2ContactEditorPostalCodeField::CPbk2ContactEditorPostalCodeField
       
    43         ( CPbk2PresentationContactField& aContactField,
       
    44           MPbk2ContactEditorUiBuilder& aUiBuilder,
       
    45           CPbk2IconInfoContainer& aIconInfoContainer ) : 
       
    46             CPbk2ContactEditorFieldBase( aContactField, aUiBuilder,
       
    47                 aIconInfoContainer )
       
    48     {
       
    49     }
       
    50 
       
    51 // --------------------------------------------------------------------------
       
    52 // CPbk2ContactEditorPostalCodeField::~CPbk2ContactEditorPostalCodeField
       
    53 // --------------------------------------------------------------------------
       
    54 //
       
    55 CPbk2ContactEditorPostalCodeField::~CPbk2ContactEditorPostalCodeField()
       
    56     {    
       
    57     }
       
    58 
       
    59 // --------------------------------------------------------------------------
       
    60 // CPbk2ContactEditorPostalCodeField::NewLC
       
    61 // --------------------------------------------------------------------------
       
    62 //
       
    63 CPbk2ContactEditorPostalCodeField* CPbk2ContactEditorPostalCodeField::NewLC
       
    64         ( CPbk2PresentationContactField& aContactField,
       
    65           MPbk2ContactEditorUiBuilder& aUiBuilder,
       
    66           CPbk2IconInfoContainer& aIconInfoContainer )
       
    67     {
       
    68     CPbk2ContactEditorPostalCodeField* self = 
       
    69         new ( ELeave ) CPbk2ContactEditorPostalCodeField( aContactField, 
       
    70             aUiBuilder, aIconInfoContainer );
       
    71     CleanupStack::PushL( self );
       
    72     self->ConstructL();
       
    73     return self;
       
    74     }
       
    75 
       
    76 // --------------------------------------------------------------------------
       
    77 // CPbk2ContactEditorPostalCodeField::ConstructL
       
    78 // --------------------------------------------------------------------------
       
    79 //
       
    80 inline void CPbk2ContactEditorPostalCodeField::ConstructL()
       
    81     {
       
    82     // Create and insert a line in the dialog
       
    83     iControl = static_cast<CEikEdwin*>(iUiBuilder.CreateLineL(
       
    84             FieldLabel(), ControlId(), EEikCtEdwin));
       
    85 
       
    86     // Control is now owned by the dialog
       
    87     TInt maxFieldLength = iContactField.MaxDataLength();
       
    88     AknEditUtils::ConstructEditingL(iControl, maxFieldLength,
       
    89         maxFieldLength, EAknEditorTextCase | EAknEditorCharactersUpperCase
       
    90         | EAknEditorCharactersLowerCase, EAknEditorAlignLeft,
       
    91         ETrue, ETrue, EFalse);
       
    92 
       
    93     // Get text
       
    94     TPtrC dataPtr(MVPbkContactFieldTextData::Cast(
       
    95         iContactField.FieldData()).Text());
       
    96     HBufC* textBuf = HBufC::NewLC(dataPtr.Length());
       
    97     TPtr text= textBuf->Des();
       
    98     text = dataPtr;
       
    99     
       
   100     AknTextUtils::DisplayTextLanguageSpecificNumberConversion(text);
       
   101 
       
   102     // Set default editor mode (defaults to numeric unless variated)
       
   103     TInt lvFlags;
       
   104     CRepository* key = CRepository::NewLC(TUid::Uid(KCRUidPhonebook));
       
   105     TInt err = key->Get(KPhonebookLocalVariationFlags, lvFlags);
       
   106     CleanupStack::PopAndDestroy(key);
       
   107     if ((err == KErrNone) && (lvFlags & EVPbkLVPostalFieldAlphaDefault))
       
   108         {
       
   109         iControl->SetAknEditorInputMode(EAknEditorTextInputMode);
       
   110         }
       
   111     else
       
   112         {
       
   113         iControl->SetAknEditorInputMode(EAknEditorNumericInputMode);
       
   114         }
       
   115     // No japanese input modes tolerated, set the allowed ones manually
       
   116     iControl->SetAknEditorAllowedInputModes (EAknEditorTextInputMode |
       
   117         EAknEditorNumericInputMode);
       
   118     
       
   119     switch (iContactField.FieldProperty().DefaultCase())
       
   120         {
       
   121         case EPbk2FieldDefaultCaseLower:
       
   122             {
       
   123             iControl->SetAknEditorCase(EAknEditorLowerCase);
       
   124             break;
       
   125             }
       
   126         case EPbk2FieldDefaultCaseText:
       
   127             {
       
   128             iControl->SetAknEditorCase(EAknEditorTextCase);
       
   129             break;
       
   130             }
       
   131         default:
       
   132             {
       
   133             // Do nothing
       
   134             break;
       
   135             }
       
   136         }
       
   137 
       
   138     // Set formatted text to editor control
       
   139    	iControl->SetTextL(&text);
       
   140     // SetTextL method above copied the text to the control,
       
   141     // so it is safe to destroy the buffer
       
   142     CleanupStack::PopAndDestroy(textBuf);
       
   143 
       
   144     iUiBuilder.LoadBitmapToFieldL
       
   145         ( iContactField.FieldProperty(), iIconInfoContainer, ControlId() );
       
   146 
       
   147 	// Place cursor to the end of the line
       
   148 	iControl->AddFlagToUserFlags(CEikEdwin::EJustAutoCurEnd);
       
   149 
       
   150     // CreateTextViewL() is flagged as deprecated but if it is not 
       
   151     // called here the ActivateL() below crashes sometimes.
       
   152     iControl->CreateTextViewL();
       
   153     iCaptionedCtrl = iUiBuilder.LineControl(ControlId());
       
   154     iCaptionedCtrl->SetTakesEnterKey(ETrue);
       
   155     }
       
   156 
       
   157 // --------------------------------------------------------------------------
       
   158 // CPbk2ContactEditorPostalCodeField::Control
       
   159 // --------------------------------------------------------------------------
       
   160 //
       
   161 CEikEdwin* CPbk2ContactEditorPostalCodeField::Control() const
       
   162     {
       
   163     return iControl;
       
   164     }
       
   165 
       
   166 // --------------------------------------------------------------------------
       
   167 // CPbk2ContactEditorPostalCodeField::SaveFieldL
       
   168 // --------------------------------------------------------------------------
       
   169 //  
       
   170 void CPbk2ContactEditorPostalCodeField::SaveFieldL()
       
   171     {
       
   172     iContactDataHasChanged = EFalse;
       
   173 
       
   174     MVPbkContactFieldTextData& data = 
       
   175         MVPbkContactFieldTextData::Cast(iContactField.FieldData());
       
   176     TPtrC curText(data.Text());
       
   177     
       
   178     HBufC* text = iControl->GetTextInHBufL();
       
   179     if (text)
       
   180         {
       
   181         if (curText.Compare(*text))
       
   182             {
       
   183             CleanupStack::PushL(text);
       
   184             data.SetTextL(*text);
       
   185             CleanupStack::PopAndDestroy(text);
       
   186             iContactDataHasChanged = ETrue;
       
   187             }
       
   188         else
       
   189             {
       
   190             delete text;
       
   191             }
       
   192         }
       
   193     else if (curText.Length() > 0)
       
   194         {
       
   195         data.SetTextL(KNullDesC);
       
   196         iContactDataHasChanged = ETrue;
       
   197         }
       
   198     }
       
   199 
       
   200 // --------------------------------------------------------------------------
       
   201 // CPbk2ContactEditorPostalCodeField::ActivateL
       
   202 // --------------------------------------------------------------------------
       
   203 //
       
   204 void CPbk2ContactEditorPostalCodeField::ActivateL()
       
   205     {
       
   206     iCaptionedCtrl->ActivateL();
       
   207     }
       
   208 
       
   209 // --------------------------------------------------------------------------
       
   210 // CPbk2ContactEditorPostalCodeField::AcceptL
       
   211 // --------------------------------------------------------------------------
       
   212 //
       
   213 void CPbk2ContactEditorPostalCodeField::AcceptL
       
   214         (MPbk2ContactEditorFieldVisitor& aVisitor)
       
   215     {
       
   216     aVisitor.VisitL(*this);
       
   217     }
       
   218 
       
   219 // End of File