|
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 number field. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbkContactEditorNumberField.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 CPbkContactEditorNumberField |
|
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, "CPbkContactEditorNumberField"); |
|
56 User::Panic(KPanicText, aReason); |
|
57 } |
|
58 #endif // _DEBUG |
|
59 |
|
60 } // namespace |
|
61 |
|
62 |
|
63 // ================= MEMBER FUNCTIONS ======================= |
|
64 |
|
65 CPbkContactEditorNumberField::CPbkContactEditorNumberField |
|
66 (TPbkContactItemField& aField, |
|
67 CPbkIconInfoContainer& aIconInfoContainer, |
|
68 MPbkContactEditorUiBuilder& aUiBuilder) : |
|
69 CPbkContactEditorFieldBase(aField, aIconInfoContainer, aUiBuilder) |
|
70 { |
|
71 } |
|
72 |
|
73 inline void CPbkContactEditorNumberField::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 if (ContactItemField().FieldInfo().EditMode() == EPbkFieldEditModeNumeric) |
|
108 { |
|
109 iControl->SetAknEditorNumericKeymap(EAknEditorPlainNumberModeKeymap); |
|
110 iControl->SetAknEditorInputMode(EAknEditorNumericInputMode); |
|
111 iControl->SetAknEditorAllowedInputModes(EAknEditorNumericInputMode); |
|
112 } |
|
113 |
|
114 switch (ContactItemField().FieldInfo().DefaultCase()) |
|
115 { |
|
116 case EPbkFieldDefaultCaseLower: |
|
117 { |
|
118 iControl->SetAknEditorCase(EAknEditorLowerCase); |
|
119 break; |
|
120 } |
|
121 case EPbkFieldDefaultCaseText: |
|
122 { |
|
123 iControl->SetAknEditorCase(EAknEditorTextCase); |
|
124 break; |
|
125 } |
|
126 default: |
|
127 { |
|
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 LoadBitmapToFieldL(iUiBuilder); |
|
139 |
|
140 // Place cursor to the end of the line |
|
141 iControl->AddFlagToUserFlags(CEikEdwin::EJustAutoCurEnd); |
|
142 |
|
143 // CreateTextViewL() is flagged as deprecated but if it is not |
|
144 // called here the ActivateL() below crashes sometimes. |
|
145 iControl->CreateTextViewL(); |
|
146 iCaptionedCtrl = iUiBuilder.LineControl(ControlId()); |
|
147 iCaptionedCtrl->SetTakesEnterKey(ETrue); |
|
148 } |
|
149 |
|
150 CPbkContactEditorNumberField* CPbkContactEditorNumberField::NewL |
|
151 (TPbkContactItemField& aField, |
|
152 MPbkContactEditorUiBuilder& aUiBuilder, |
|
153 CPbkIconInfoContainer& aIconInfoContainer) |
|
154 { |
|
155 CPbkContactEditorNumberField* self = |
|
156 new(ELeave) CPbkContactEditorNumberField(aField, |
|
157 aIconInfoContainer, aUiBuilder); |
|
158 CleanupStack::PushL(self); |
|
159 self->ConstructL(); |
|
160 CleanupStack::Pop(self); |
|
161 return self; |
|
162 } |
|
163 |
|
164 CPbkContactEditorNumberField::~CPbkContactEditorNumberField() |
|
165 { |
|
166 } |
|
167 |
|
168 void CPbkContactEditorNumberField::SaveFieldL() |
|
169 { |
|
170 __ASSERT_DEBUG(iControl && Field().StorageType() == KStorageTypeText, |
|
171 Panic(EPanicPreCond_SaveFieldL)); |
|
172 |
|
173 iContactDataHasChanged = EFalse; |
|
174 |
|
175 HBufC* text = iControl->GetTextInHBufL(); |
|
176 if (text) |
|
177 { |
|
178 if (Field().TextStorage()->Text() != *text) |
|
179 { |
|
180 // store the text in the contact item |
|
181 Field().TextStorage()->SetText(text); |
|
182 text = NULL; |
|
183 iContactDataHasChanged = ETrue; |
|
184 } |
|
185 delete text; |
|
186 } |
|
187 else |
|
188 { |
|
189 // Ensure field text is empty |
|
190 if (Field().TextStorage()->Text().Length() > 0) |
|
191 { |
|
192 Field().TextStorage()->SetTextL(KNullDesC); |
|
193 iContactDataHasChanged = ETrue; |
|
194 } |
|
195 } |
|
196 } |
|
197 |
|
198 void CPbkContactEditorNumberField::AddFieldL(CPbkContactItem& aContact) |
|
199 { |
|
200 HBufC* text = iControl->GetTextInHBufL(); |
|
201 if (text) |
|
202 { |
|
203 CleanupStack::PushL(text); |
|
204 TPbkContactItemField* field = aContact.AddOrReturnUnusedFieldL |
|
205 ( Field().FieldInfo() ); |
|
206 CleanupStack::Pop(text); |
|
207 if (field) |
|
208 { |
|
209 field->TextStorage()->SetText(text); |
|
210 } |
|
211 } |
|
212 } |
|
213 |
|
214 void CPbkContactEditorNumberField::SetControlTextL(const TDesC& aDes) |
|
215 { |
|
216 iControl->SetTextL(&aDes); |
|
217 } |
|
218 |
|
219 void CPbkContactEditorNumberField::ActivateL() |
|
220 { |
|
221 iCaptionedCtrl->ActivateL(); |
|
222 } |
|
223 |
|
224 void CPbkContactEditorNumberField::AcceptL(MPbkFieldEditorVisitor& aVisitor) |
|
225 { |
|
226 aVisitor.VisitL(*this); |
|
227 } |
|
228 |
|
229 // End of File |