phonebookui/Phonebook2/UIControls/src/CPbk2ContactEditorNumberField.cpp
changeset 0 e686773b3f54
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 number field.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CPbk2ContactEditorNumberField.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include "MPbk2ContactEditorUiBuilder.h"
       
    23 #include "MPbk2ContactEditorFieldVisitor.h"
       
    24 #include <MPbk2FieldProperty.h>
       
    25 #include <CPbk2PresentationContactField.h>
       
    26 
       
    27 // Virtual Phonebook
       
    28 #include <MVPbkContactFieldTextData.h>
       
    29 
       
    30 // System includes
       
    31 #include <eikcapc.h>
       
    32 #include <eikedwin.h>
       
    33 #include <AknUtils.h>
       
    34 
       
    35 // --------------------------------------------------------------------------
       
    36 // CPbk2ContactEditorNumberField::CPbk2ContactEditorNumberField
       
    37 // --------------------------------------------------------------------------
       
    38 //
       
    39 inline CPbk2ContactEditorNumberField::CPbk2ContactEditorNumberField
       
    40         ( CPbk2PresentationContactField& aContactField,
       
    41           MPbk2ContactEditorUiBuilder& aUiBuilder,
       
    42           CPbk2IconInfoContainer& aIconInfoContainer ) :
       
    43             CPbk2ContactEditorFieldBase( aContactField, aUiBuilder,
       
    44                 aIconInfoContainer )
       
    45     {
       
    46     }
       
    47 
       
    48 // --------------------------------------------------------------------------
       
    49 // CPbk2ContactEditorNumberField::~CPbk2ContactEditorNumberField
       
    50 // --------------------------------------------------------------------------
       
    51 //  
       
    52 CPbk2ContactEditorNumberField::~CPbk2ContactEditorNumberField()
       
    53     {    
       
    54     }
       
    55 
       
    56 // --------------------------------------------------------------------------
       
    57 // CPbk2ContactEditorNumberField::NewL
       
    58 // --------------------------------------------------------------------------
       
    59 //
       
    60 CPbk2ContactEditorNumberField* CPbk2ContactEditorNumberField::NewLC
       
    61         ( CPbk2PresentationContactField& aContactField,
       
    62           MPbk2ContactEditorUiBuilder& aUiBuilder,
       
    63           CPbk2IconInfoContainer& aIconInfoContainer )
       
    64     {
       
    65     CPbk2ContactEditorNumberField* self = 
       
    66         new ( ELeave ) CPbk2ContactEditorNumberField( aContactField,
       
    67             aUiBuilder, aIconInfoContainer );
       
    68     CleanupStack::PushL( self );
       
    69     self->ConstructL();
       
    70     return self;
       
    71     }
       
    72 
       
    73 // --------------------------------------------------------------------------
       
    74 // CPbk2ContactEditorNumberField::ConstructL
       
    75 // --------------------------------------------------------------------------
       
    76 //
       
    77 inline void CPbk2ContactEditorNumberField::ConstructL()
       
    78     {
       
    79     // Create and insert a line in the dialog
       
    80     iControl = static_cast<CEikEdwin*>(iUiBuilder.CreateLineL(
       
    81             FieldLabel(), ControlId(), EEikCtEdwin));
       
    82 
       
    83     // Control is now owned by the dialog
       
    84     TInt maxFieldLength = iContactField.MaxDataLength();
       
    85     AknEditUtils::ConstructEditingL(iControl, maxFieldLength,
       
    86         maxFieldLength, EAknEditorTextCase | EAknEditorCharactersUpperCase
       
    87         | EAknEditorCharactersLowerCase, EAknEditorAlignLeft,
       
    88         ETrue, ETrue, EFalse);
       
    89         
       
    90     // Get text
       
    91     TPtrC dataPtr(MVPbkContactFieldTextData::Cast(
       
    92         iContactField.FieldData()).Text());
       
    93     HBufC* textBuf = HBufC::NewLC(dataPtr.Length());
       
    94     TPtr text= textBuf->Des();
       
    95     text = dataPtr;
       
    96     
       
    97     if (iContactField.FieldProperty().EditMode() == 
       
    98         EPbk2FieldEditModeLatinOnly)
       
    99         {
       
   100         iControl->SetAknEditorFlags(EAknEditorFlagLatinInputModesOnly);
       
   101         }
       
   102     else
       
   103         {
       
   104         // If not in 'only latin mode', convert digits to
       
   105         // foreign characters if necessary
       
   106         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(text);
       
   107         }
       
   108         
       
   109     if (iContactField.FieldProperty().EditMode() == EPbk2FieldEditModeNumeric)
       
   110         {
       
   111         iControl->SetAknEditorNumericKeymap(EAknEditorPlainNumberModeKeymap);
       
   112         iControl->SetAknEditorInputMode(EAknEditorNumericInputMode);
       
   113         iControl->SetAknEditorAllowedInputModes(EAknEditorNumericInputMode);
       
   114         }
       
   115         
       
   116     // Set formatted text to editor control
       
   117    	iControl->SetTextL(&text);
       
   118     // SetTextL method above copied the text to the control,
       
   119     // so it is safe to destroy the buffer
       
   120     CleanupStack::PopAndDestroy(textBuf);
       
   121 
       
   122     iUiBuilder.LoadBitmapToFieldL
       
   123         ( iContactField.FieldProperty(), iIconInfoContainer, ControlId() );
       
   124 
       
   125 	// Place cursor to the end of the line
       
   126 	iControl->AddFlagToUserFlags(CEikEdwin::EJustAutoCurEnd);
       
   127 
       
   128     // CreateTextViewL() is flagged as deprecated but if it is not 
       
   129     // called here the ActivateL() below crashes sometimes.
       
   130     iControl->CreateTextViewL();
       
   131     iCaptionedCtrl = iUiBuilder.LineControl(ControlId());
       
   132     iCaptionedCtrl->SetTakesEnterKey(ETrue);
       
   133     }
       
   134 
       
   135 // --------------------------------------------------------------------------
       
   136 // CPbk2ContactEditorNumberField::Control
       
   137 // --------------------------------------------------------------------------
       
   138 //
       
   139 CEikEdwin* CPbk2ContactEditorNumberField::Control() const
       
   140     {
       
   141     return iControl;
       
   142     }
       
   143 
       
   144 // --------------------------------------------------------------------------
       
   145 // CPbk2ContactEditorNumberField::SaveFieldL
       
   146 // --------------------------------------------------------------------------
       
   147 //  
       
   148 void CPbk2ContactEditorNumberField::SaveFieldL()
       
   149     {
       
   150     iContactDataHasChanged = EFalse;
       
   151 
       
   152     MVPbkContactFieldTextData& data = 
       
   153         MVPbkContactFieldTextData::Cast(iContactField.FieldData());
       
   154     TPtrC curText(data.Text());
       
   155     
       
   156     HBufC* text = iControl->GetTextInHBufL();
       
   157     if (text)
       
   158         {
       
   159         if (curText.Compare(*text))
       
   160             {
       
   161             CleanupStack::PushL(text);
       
   162             data.SetTextL(*text);
       
   163             CleanupStack::PopAndDestroy(text);
       
   164             iContactDataHasChanged = ETrue;
       
   165             }
       
   166         else
       
   167             {
       
   168             delete text;
       
   169             }
       
   170         }
       
   171     else if (curText.Length() > 0)
       
   172         {
       
   173         data.SetTextL(KNullDesC);
       
   174         iContactDataHasChanged = ETrue;
       
   175         }
       
   176     }
       
   177 
       
   178 // --------------------------------------------------------------------------
       
   179 // CPbk2ContactEditorNumberField::ActivateL
       
   180 // --------------------------------------------------------------------------
       
   181 //
       
   182 void CPbk2ContactEditorNumberField::ActivateL()
       
   183     {
       
   184     iCaptionedCtrl->ActivateL();
       
   185     }
       
   186 
       
   187 // --------------------------------------------------------------------------
       
   188 // CPbk2ContactEditorNumberField::AcceptL
       
   189 // --------------------------------------------------------------------------
       
   190 //
       
   191 void CPbk2ContactEditorNumberField::AcceptL
       
   192         (MPbk2ContactEditorFieldVisitor& aVisitor)
       
   193     {
       
   194     aVisitor.VisitL(*this);
       
   195     }
       
   196 
       
   197 // End of File