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