|
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 custom field. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPbk2ContactEditorReadonlyField.h" |
|
21 #include <AknUtils.h> |
|
22 #include <AknDef.h> |
|
23 #include <CPbk2AppUiBase.h> |
|
24 #include <Pbk2UIControls.hrh> |
|
25 #include <Pbk2Commands.hrh> |
|
26 #include <MPbk2ContactEditorField2.h> |
|
27 #include <MPbk2ContactEditorUIField.h> |
|
28 |
|
29 /// Unnamed namespace for local definitions |
|
30 namespace |
|
31 { |
|
32 |
|
33 enum TContactEditorPanicCodes |
|
34 { |
|
35 EEditorTouchFeedbackMissing |
|
36 }; |
|
37 |
|
38 void Panic(TContactEditorPanicCodes aReason) |
|
39 { |
|
40 _LIT( KPanicText, "CPbk2_editor_ReadonlyField" ); |
|
41 User::Panic(KPanicText, aReason); |
|
42 } |
|
43 } /// namespace |
|
44 |
|
45 |
|
46 // ============================ MEMBER FUNCTIONS =============================== |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // CCPbk2ContactEditorReadonlyField::CCPbk2ContactEditorReadonlyField() |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 CPbk2ContactEditorReadonlyField::CPbk2ContactEditorReadonlyField() |
|
53 { |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CPbk2ContactEditorReadonlyField::~CPbk2ContactEditorReadonlyField() |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CPbk2ContactEditorReadonlyField::~CPbk2ContactEditorReadonlyField() |
|
61 { |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CPbk2ContactEditorReadonlyField::InitializeL |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 EXPORT_C void CPbk2ContactEditorReadonlyField::InitializeL( |
|
69 MPbk2ContactEditorUIField* aPbk2ContactEditorField) |
|
70 { |
|
71 ActivateL(); |
|
72 iPbk2ContactEditorUIField = aPbk2ContactEditorField; |
|
73 iTouchFeedbackRef = MTouchFeedback::Instance(); |
|
74 __ASSERT_ALWAYS( iTouchFeedbackRef, Panic( EEditorTouchFeedbackMissing )); |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CPbk2ContactEditorReadonlyField::InitializeL |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 void CPbk2ContactEditorReadonlyField::InitializeL( |
|
82 MPbk2ContactEditorField* aPbk2ContactEditorField) |
|
83 { |
|
84 ActivateL(); |
|
85 iPbk2ContactEditorField = aPbk2ContactEditorField; |
|
86 iTouchFeedbackRef = MTouchFeedback::Instance(); |
|
87 __ASSERT_ALWAYS( iTouchFeedbackRef, Panic( EEditorTouchFeedbackMissing )); |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CPbk2ContactEditorReadonlyField::OfferKeyEventL() |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 TKeyResponse CPbk2ContactEditorReadonlyField::OfferKeyEventL( |
|
95 const TKeyEvent& aKeyEvent, TEventCode aType) |
|
96 { |
|
97 TKeyResponse exitCode = EKeyWasNotConsumed; |
|
98 if (aType == EEventKey) |
|
99 { |
|
100 switch (aKeyEvent.iCode) |
|
101 { |
|
102 case EKeyOK: |
|
103 //no op |
|
104 break; |
|
105 case EKeyEnter: |
|
106 { |
|
107 exitCode = EKeyWasConsumed; |
|
108 if (iPbk2ContactEditorField) |
|
109 { |
|
110 MPbk2ContactEditorField2 * tempContactEditorField = |
|
111 reinterpret_cast<MPbk2ContactEditorField2*> ( |
|
112 iPbk2ContactEditorField->ContactEditorFieldExtension( |
|
113 KMPbk2ContactEditorFieldExtension2Uid)); |
|
114 |
|
115 tempContactEditorField->HandleCustomFieldCommandL( |
|
116 EPbk2CmdEditorHandleCustomSelect); |
|
117 } |
|
118 else if (iPbk2ContactEditorUIField) |
|
119 { |
|
120 iPbk2ContactEditorUIField->HandleCustomFieldCommandL( |
|
121 EPbk2CmdEditorHandleCustomSelect); |
|
122 } |
|
123 |
|
124 } |
|
125 break; |
|
126 |
|
127 case EKeyDelete: |
|
128 case EKeyBackspace: |
|
129 { |
|
130 if (iPbk2ContactEditorField) |
|
131 { |
|
132 MPbk2ContactEditorField2* tempContactEditorField = |
|
133 reinterpret_cast<MPbk2ContactEditorField2*> (iPbk2ContactEditorField->ContactEditorFieldExtension( |
|
134 KMPbk2ContactEditorFieldExtension2Uid)); |
|
135 tempContactEditorField-> HandleCustomFieldCommandL( |
|
136 EPbk2CmdEditorHandleCustomRemove); |
|
137 exitCode = EKeyWasConsumed; |
|
138 } |
|
139 |
|
140 } |
|
141 break; |
|
142 |
|
143 default: |
|
144 break; |
|
145 } |
|
146 } |
|
147 else if (aType == EEventKeyDown) |
|
148 { |
|
149 } |
|
150 |
|
151 if (exitCode != EKeyWasConsumed) |
|
152 { |
|
153 exitCode = CEikEdwin::OfferKeyEventL(aKeyEvent, aType); |
|
154 } |
|
155 |
|
156 return exitCode; |
|
157 } |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // CPbk2ContactEditorReadonlyField::SetTextL() |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 EXPORT_C void CPbk2ContactEditorReadonlyField::SetTextL(const TDesC* aData) |
|
164 { |
|
165 // Shorten data and take max length of head of text, |
|
166 // otherwise edwin takes tail of text. |
|
167 CTextLayout* layout = const_cast<CTextLayout *> (iTextView->Layout()); |
|
168 |
|
169 if (!layout->Truncating()) |
|
170 { |
|
171 layout->SetTruncating(TRUE); |
|
172 } |
|
173 |
|
174 TInt maxLen = iTextLimit; |
|
175 HBufC* stripBuf = HBufC::NewLC(maxLen); |
|
176 TPtr stripPtr = stripBuf->Des(); |
|
177 stripPtr.Append(aData->Left(maxLen)); |
|
178 // Replace some common unicode control characters with spaces |
|
179 // as Edwin can't show them correctly. |
|
180 // - normal ASCII line break (\n) |
|
181 // - normal ASCII tab (\t) |
|
182 // - paragraph separator (0x2029) |
|
183 // - line break (0x2028) |
|
184 _LIT(KParagraphCharacter, "\n\t\x2029\x2028"); |
|
185 TChar space(' '); |
|
186 AknTextUtils::ReplaceCharacters(stripPtr, KParagraphCharacter, space); |
|
187 CEikEdwin::SetTextL(stripBuf); |
|
188 CleanupStack::PopAndDestroy(stripBuf); |
|
189 } |
|
190 |
|
191 // -------------------------------------------------------------------------- |
|
192 // CPbk2ContactEditorReadonlyField::HandlePointerEventL |
|
193 // -------------------------------------------------------------------------- |
|
194 // |
|
195 void CPbk2ContactEditorReadonlyField::HandlePointerEventL( |
|
196 const TPointerEvent& aPointerEvent) |
|
197 { |
|
198 //If overriding HandlePointerEventL(), the implementation must include a |
|
199 //base call to CCoeControl's HandlePointerEventL(). |
|
200 CCoeControl::HandlePointerEventL(aPointerEvent); |
|
201 |
|
202 if (AknLayoutUtils::PenEnabled()) |
|
203 { |
|
204 switch (aPointerEvent.iType) |
|
205 { |
|
206 //When stylus dragged two EButton1Up events received per one EButton1Up |
|
207 //event. Prevent EButton1Up processing if stylus dragged out of this |
|
208 //control's rect. |
|
209 case TPointerEvent::EButton1Down: |
|
210 { |
|
211 iTouchFeedbackRef->InstantFeedback(ETouchFeedbackBasic); |
|
212 iButton1UpReceived = EFalse; |
|
213 break; |
|
214 } |
|
215 case TPointerEvent::EButton1Up: |
|
216 { |
|
217 TInt y = aPointerEvent.iPosition.iY; |
|
218 if (Rect().iTl.iY <= y && y <= Rect().iBr.iY |
|
219 && !iButton1UpReceived) |
|
220 { |
|
221 iTouchFeedbackRef->InstantFeedback( |
|
222 this, |
|
223 ETouchFeedbackBasic, |
|
224 ETouchFeedbackVibra, |
|
225 aPointerEvent); |
|
226 |
|
227 if (iPbk2ContactEditorField) |
|
228 { |
|
229 MPbk2ContactEditorField2* tempContactEditorField = |
|
230 reinterpret_cast<MPbk2ContactEditorField2*> (iPbk2ContactEditorField->ContactEditorFieldExtension( |
|
231 KMPbk2ContactEditorFieldExtension2Uid)); |
|
232 |
|
233 tempContactEditorField-> HandleCustomFieldCommandL( |
|
234 EPbk2CmdEditorHandleCustomSelect); |
|
235 } |
|
236 else if (iPbk2ContactEditorUIField) |
|
237 { |
|
238 iPbk2ContactEditorUIField-> HandleCustomFieldCommandL( |
|
239 EPbk2CmdEditorHandleCustomSelect); |
|
240 } |
|
241 } |
|
242 iButton1UpReceived = ETrue; |
|
243 break; |
|
244 } |
|
245 default:; |
|
246 } |
|
247 } |
|
248 } |
|
249 |
|
250 // End of File |