|
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 // T9 should be deactivated in all contact editors always |
|
100 DeactivateT9(iContactField.FieldProperty().EditMode()); |
|
101 |
|
102 if (iContactField.FieldProperty().EditMode() == |
|
103 EPbk2FieldEditModeLatinOnly) |
|
104 { |
|
105 iControl->SetAknEditorSpecialCharacterTable( |
|
106 R_AVKON_SPECIAL_CHARACTER_TABLE_DIALOG ); |
|
107 } |
|
108 else |
|
109 { |
|
110 // If not in 'only latin mode', convert digits to |
|
111 // foreign characters if necessary |
|
112 AknTextUtils::DisplayTextLanguageSpecificNumberConversion(text); |
|
113 } |
|
114 |
|
115 switch (iContactField.FieldProperty().DefaultCase()) |
|
116 { |
|
117 case EPbk2FieldDefaultCaseLower: |
|
118 { |
|
119 iControl->SetAknEditorCase(EAknEditorLowerCase); |
|
120 break; |
|
121 } |
|
122 case EPbk2FieldDefaultCaseText: |
|
123 { |
|
124 iControl->SetAknEditorCase(EAknEditorTextCase); |
|
125 break; |
|
126 } |
|
127 default: |
|
128 { |
|
129 // Do nothing |
|
130 break; |
|
131 } |
|
132 } |
|
133 |
|
134 // Set formatted text to editor control |
|
135 iControl->SetTextL(&text); |
|
136 // SetTextL method above copied the text to the control, |
|
137 // so it is safe to destroy the buffer |
|
138 CleanupStack::PopAndDestroy(textBuf); |
|
139 |
|
140 iUiBuilder.LoadBitmapToFieldL |
|
141 ( iContactField.FieldProperty(), iIconInfoContainer, ControlId() ); |
|
142 |
|
143 |
|
144 // Place cursor to the end of the line |
|
145 iControl->AddFlagToUserFlags(CEikEdwin::EJustAutoCurEnd); |
|
146 |
|
147 // CreateTextViewL() is flagged as deprecated but if it is not |
|
148 // called here the ActivateL() below crashes sometimes. |
|
149 iControl->CreateTextViewL(); |
|
150 iCaptionedCtrl = iUiBuilder.LineControl(ControlId()); |
|
151 iCaptionedCtrl->SetTakesEnterKey(EFalse); |
|
152 } |
|
153 |
|
154 // -------------------------------------------------------------------------- |
|
155 // CPbk2ContactEditorTextField::DeactivateT9 |
|
156 // -------------------------------------------------------------------------- |
|
157 // |
|
158 void CPbk2ContactEditorTextField::DeactivateT9(TInt8 aEditMode) |
|
159 { |
|
160 if (iControl) |
|
161 { |
|
162 if (aEditMode == EPbk2FieldEditModeLatinOnly) |
|
163 { |
|
164 iControl->SetAknEditorFlags( |
|
165 EAknEditorFlagLatinInputModesOnly | EAknEditorFlagNoT9); |
|
166 } |
|
167 else |
|
168 { |
|
169 iControl->SetAknEditorFlags(EAknEditorFlagNoT9); |
|
170 } |
|
171 } |
|
172 } |
|
173 |
|
174 // -------------------------------------------------------------------------- |
|
175 // CPbk2ContactEditorTextField::Control |
|
176 // -------------------------------------------------------------------------- |
|
177 // |
|
178 CEikEdwin* CPbk2ContactEditorTextField::Control() const |
|
179 { |
|
180 return iControl; |
|
181 } |
|
182 |
|
183 // -------------------------------------------------------------------------- |
|
184 // CPbk2ContactEditorTextField::SaveFieldL |
|
185 // -------------------------------------------------------------------------- |
|
186 // |
|
187 void CPbk2ContactEditorTextField::SaveFieldL() |
|
188 { |
|
189 iContactDataHasChanged = EFalse; |
|
190 |
|
191 MVPbkContactFieldTextData& data = |
|
192 MVPbkContactFieldTextData::Cast(iContactField.FieldData()); |
|
193 TPtrC curText(data.Text()); |
|
194 |
|
195 HBufC* text = iControl->GetTextInHBufL(); |
|
196 if (text) |
|
197 { |
|
198 //Trim spaces at the end of formatted name |
|
199 text->Des().TrimRight(); |
|
200 if (curText.Compare(*text)) |
|
201 { |
|
202 CleanupStack::PushL(text); |
|
203 data.SetTextL(*text); |
|
204 CleanupStack::PopAndDestroy(text); |
|
205 iContactDataHasChanged = ETrue; |
|
206 } |
|
207 else |
|
208 { |
|
209 delete text; |
|
210 } |
|
211 } |
|
212 else if (curText.Length() > 0) |
|
213 { |
|
214 data.SetTextL(KNullDesC); |
|
215 iContactDataHasChanged = ETrue; |
|
216 } |
|
217 } |
|
218 |
|
219 // -------------------------------------------------------------------------- |
|
220 // CPbk2ContactEditorTextField::ActivateL |
|
221 // -------------------------------------------------------------------------- |
|
222 // |
|
223 void CPbk2ContactEditorTextField::ActivateL() |
|
224 { |
|
225 iCaptionedCtrl->ActivateL(); |
|
226 } |
|
227 |
|
228 // -------------------------------------------------------------------------- |
|
229 // CPbk2ContactEditorTextField::AcceptL |
|
230 // -------------------------------------------------------------------------- |
|
231 // |
|
232 void CPbk2ContactEditorTextField::AcceptL |
|
233 ( MPbk2ContactEditorFieldVisitor& aVisitor ) |
|
234 { |
|
235 aVisitor.VisitL( *this ); |
|
236 } |
|
237 |
|
238 // End of File |