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