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