phonebookui/Phonebook/View/src/CPbkContactEditorTextField.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 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 *           Methods for phonebook Contact editor text field.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbkContactEditorTextField.h"
       
    22 #include "MPbkContactEditorUiBuilder.h"
       
    23 #include "MPbkFieldEditorVisitor.h"
       
    24 
       
    25 #include <eikdialg.h>
       
    26 #include <eikedwin.h>
       
    27 #include <AknUtils.h>
       
    28 #include <eikcapc.h>
       
    29 
       
    30 #include <TPbkContactItemField.h>
       
    31 #include <CPbkContactItem.h>
       
    32 #include <CPbkFieldInfo.h>
       
    33 #include <CPbkConstants.h>
       
    34 
       
    35 
       
    36 /// Unnamed namespace for local definitons
       
    37 namespace {
       
    38 
       
    39 // LOCAL CONSTANTS AND MACROS
       
    40 
       
    41 #ifdef _DEBUG
       
    42 /// Panic codes for CPbkContactEditorTextField
       
    43 enum TPanicCode
       
    44     {
       
    45     EPanicPreCond_ConstructL,
       
    46 	EPanicPreCond_SaveFieldL
       
    47     };
       
    48 #endif  // _DEBUG
       
    49 
       
    50 // ==================== LOCAL FUNCTIONS ====================
       
    51 
       
    52 #ifdef _DEBUG
       
    53 void Panic(TPanicCode aReason)
       
    54     {
       
    55     _LIT(KPanicText, "CPbkContactEditorTextField");
       
    56     User::Panic(KPanicText, aReason);
       
    57     }
       
    58 #endif  // _DEBUG
       
    59 
       
    60 }  // namespace
       
    61 
       
    62 
       
    63 // ================= MEMBER FUNCTIONS =======================
       
    64 
       
    65 CPbkContactEditorTextField::CPbkContactEditorTextField
       
    66         (TPbkContactItemField& aField,
       
    67 		CPbkIconInfoContainer& aIconInfoContainer,
       
    68 		MPbkContactEditorUiBuilder& aUiBuilder) :
       
    69     CPbkContactEditorFieldBase(aField, aIconInfoContainer, aUiBuilder)
       
    70     {
       
    71     }
       
    72 
       
    73 inline void CPbkContactEditorTextField::ConstructL()
       
    74     {
       
    75     __ASSERT_DEBUG(ContactItemField().StorageType() == KStorageTypeText, 
       
    76         Panic(EPanicPreCond_ConstructL));
       
    77 
       
    78     // Create and insert a line in the dialog
       
    79     iControl = static_cast<CEikEdwin*>(iUiBuilder.CreateLineL(
       
    80             FieldLabel(), ControlId(), EEikCtEdwin));
       
    81 
       
    82     // ctrl is now owned by the dialog
       
    83     AknEditUtils::ConstructEditingL(iControl, ContactItemField().
       
    84         FieldInfo().MaxLength(), 
       
    85             CPbkConstants::FieldEditorLength(), 
       
    86             EAknEditorTextCase | EAknEditorCharactersUpperCase
       
    87             | EAknEditorCharactersLowerCase, EAknEditorAlignLeft,
       
    88             ETrue, ETrue, EFalse);
       
    89 
       
    90     // Get text
       
    91     HBufC* textBuf = HBufC::NewLC(ContactItemField().Text().Length());
       
    92     TPtr text= textBuf->Des();
       
    93     text = ContactItemField().Text();
       
    94     
       
    95     if (ContactItemField().FieldInfo().EditMode()
       
    96             == EPbkFieldEditModeLatinOnly)
       
    97         {
       
    98         iControl->SetAknEditorFlags(EAknEditorFlagLatinInputModesOnly);
       
    99         }
       
   100     else
       
   101         {
       
   102         // If not in 'only latin mode', convert digits to
       
   103         // foreign characters if necessary
       
   104         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(text);
       
   105         }
       
   106 
       
   107     switch (ContactItemField().FieldInfo().DefaultCase())
       
   108         {
       
   109         case EPbkFieldDefaultCaseLower:
       
   110             {
       
   111             iControl->SetAknEditorCase(EAknEditorLowerCase);
       
   112             break;
       
   113             }
       
   114         case EPbkFieldDefaultCaseText:
       
   115             {
       
   116             iControl->SetAknEditorCase(EAknEditorTextCase);
       
   117             break;
       
   118             }
       
   119         default:
       
   120             {
       
   121             break;
       
   122             }
       
   123         }
       
   124 
       
   125     // Set formatted text to editor control
       
   126    	iControl->SetTextL(&text);
       
   127     // SetTextL method above copied the text to the control,
       
   128     // so it is safe to destroy the buffer
       
   129     CleanupStack::PopAndDestroy(textBuf);
       
   130 
       
   131     LoadBitmapToFieldL(iUiBuilder);
       
   132 
       
   133 	// Place cursor to the end of the line
       
   134 	iControl->AddFlagToUserFlags(CEikEdwin::EJustAutoCurEnd);
       
   135 
       
   136     // CreateTextViewL() is flagged as deprecated but if it is not 
       
   137     // called here the ActivateL() below crashes sometimes.
       
   138     iControl->CreateTextViewL();
       
   139     iCaptionedCtrl = iUiBuilder.LineControl(ControlId());
       
   140     iCaptionedCtrl->SetTakesEnterKey(ETrue);
       
   141     }
       
   142 
       
   143 CPbkContactEditorTextField* CPbkContactEditorTextField::NewL
       
   144         (TPbkContactItemField& aField,
       
   145         MPbkContactEditorUiBuilder& aUiBuilder,
       
   146 		CPbkIconInfoContainer& aIconInfoContainer)
       
   147     {
       
   148     CPbkContactEditorTextField* self =
       
   149         new(ELeave) CPbkContactEditorTextField(aField,
       
   150         aIconInfoContainer, aUiBuilder);
       
   151     CleanupStack::PushL(self);
       
   152     self->ConstructL();
       
   153     CleanupStack::Pop(self);
       
   154     return self;
       
   155     }
       
   156 
       
   157 CPbkContactEditorTextField::~CPbkContactEditorTextField()
       
   158     {
       
   159     }
       
   160 
       
   161 void CPbkContactEditorTextField::SaveFieldL()
       
   162     {
       
   163     __ASSERT_DEBUG(iControl && Field().StorageType() == KStorageTypeText, 
       
   164             Panic(EPanicPreCond_SaveFieldL));
       
   165     
       
   166     iContactDataHasChanged = EFalse;
       
   167 
       
   168     HBufC* text = iControl->GetTextInHBufL();
       
   169     if (text)
       
   170         {
       
   171         if (Field().TextStorage()->Text() != *text)
       
   172             {
       
   173             // store the text in the contact item
       
   174             Field().TextStorage()->SetText(text);
       
   175             text = NULL;
       
   176             iContactDataHasChanged = ETrue;
       
   177             }
       
   178         delete text;
       
   179         }
       
   180     else
       
   181         {
       
   182         // Ensure field text is empty
       
   183         if (Field().TextStorage()->Text().Length() > 0)
       
   184             {
       
   185             Field().TextStorage()->SetTextL(KNullDesC);
       
   186             iContactDataHasChanged = ETrue;
       
   187             }
       
   188         }
       
   189     }
       
   190 
       
   191 void CPbkContactEditorTextField::AddFieldL(CPbkContactItem& aContact)
       
   192     {
       
   193     HBufC* text = iControl->GetTextInHBufL();    
       
   194     if (text)
       
   195         {
       
   196         CleanupStack::PushL(text);
       
   197         TPbkContactItemField* field = aContact.AddOrReturnUnusedFieldL
       
   198             (Field().FieldInfo());
       
   199         CleanupStack::Pop(text);
       
   200         if (field)
       
   201             {
       
   202             field->TextStorage()->SetText(text);
       
   203             }
       
   204         }
       
   205     }
       
   206 
       
   207 void CPbkContactEditorTextField::SetControlTextL(const TDesC& aDes)
       
   208     {
       
   209     iControl->SetTextL(&aDes);
       
   210     }
       
   211 
       
   212 void CPbkContactEditorTextField::ActivateL()
       
   213     {
       
   214     iCaptionedCtrl->ActivateL();
       
   215     }
       
   216 
       
   217 
       
   218 CEikEdwin* CPbkContactEditorTextField::Control()
       
   219     {
       
   220     return iControl;
       
   221     }
       
   222 
       
   223 TPbkFieldId CPbkContactEditorTextField::FieldId()
       
   224     {
       
   225     return ContactItemField().FieldInfo().FieldId();
       
   226     }
       
   227 
       
   228 void CPbkContactEditorTextField::AcceptL
       
   229         (MPbkFieldEditorVisitor& aVisitor)
       
   230     {
       
   231     aVisitor.VisitL(*this);
       
   232     }
       
   233 
       
   234 // End of File
       
   235