|
1 /* |
|
2 * Copyright (c) 1999 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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <basched.h> |
|
21 #include <barsread.h> |
|
22 #include <eikenv.h> |
|
23 #include <eikmsg.h> |
|
24 #include <aknipfed.h> |
|
25 #include <in_sock.h> |
|
26 #include <gulfont.h> |
|
27 #include <avkon.hrh> |
|
28 #include <AknUtils.h> |
|
29 #include <aknextendedinputcapabilities.h> |
|
30 #include <AknTasHook.h> // for testability hooks |
|
31 |
|
32 |
|
33 // |
|
34 // CAknIpFieldEditor |
|
35 // |
|
36 |
|
37 |
|
38 const TInt KNumAddressFields=4; |
|
39 const TInt KNumDelimiterFields=3; |
|
40 const TInt KFieldA=0; |
|
41 const TInt KFieldB=2; |
|
42 const TInt KFieldC=4; |
|
43 const TInt KFieldD=6; |
|
44 // const TInt KTotalNumChars=15;// IPv4 is 4x3 numbers + 3x1 delimiter |
|
45 |
|
46 _LIT(KDelimiter, "."); // In IPv4 the delimiter is always a dot |
|
47 |
|
48 |
|
49 /** |
|
50 * Public method for constructing a CAknIpFieldEditor object. |
|
51 * Gets four parameters: |
|
52 * TInetAddr& aMinimumFieldValues - Reference to a TInetAddr struct. Defines lower limits for |
|
53 * IP editor fields. |
|
54 * TInetAddr& aMaximumFieldValues - Reference to a TInetAddr struct. Defines upper limits for |
|
55 * IP editor fields. |
|
56 * TInetAddr& aInitialAddress - Reference to a TInetAddr struct. Defines the initial address |
|
57 * the IP editor. |
|
58 * |
|
59 */ |
|
60 EXPORT_C CAknIpFieldEditor* CAknIpFieldEditor::NewL(TInetAddr& aMinimumFieldValues, |
|
61 TInetAddr& aMaximumFieldValues, |
|
62 TInetAddr& aInitialAddress) |
|
63 { |
|
64 CAknIpFieldEditor* editor=new(ELeave)CAknIpFieldEditor; |
|
65 CleanupStack::PushL(editor); |
|
66 editor->ConstructL(aMinimumFieldValues,aMaximumFieldValues,aInitialAddress); |
|
67 CleanupStack::Pop(); // editor |
|
68 AKNTASHOOK_ADDL( editor, "CAknIpFieldEditor" ); |
|
69 return editor; |
|
70 } |
|
71 |
|
72 /** |
|
73 * Public method for constructing a CAknIpFieldEditor object. Requires a call for |
|
74 * ConstructFromResourcesL method to finish construction. |
|
75 * |
|
76 */ |
|
77 EXPORT_C CAknIpFieldEditor* CAknIpFieldEditor::NewL() |
|
78 { |
|
79 CAknIpFieldEditor* editor=new(ELeave)CAknIpFieldEditor; |
|
80 AKNTASHOOK_ADDL( editor, "CAknIpFieldEditor" ); |
|
81 return editor; |
|
82 } |
|
83 |
|
84 EXPORT_C CAknIpFieldEditor::CAknIpFieldEditor() |
|
85 { |
|
86 } |
|
87 |
|
88 void CAknIpFieldEditor::ConstructL(TInetAddr& aMinimumFieldValues, |
|
89 TInetAddr& aMaximumFieldValues, |
|
90 TInetAddr& aInitialAddress, |
|
91 const TInt aFlags) |
|
92 { |
|
93 TInt numFields=KNumAddressFields+KNumDelimiterFields; |
|
94 CreateFieldArrayL(numFields); // MFNE with 7 fields |
|
95 |
|
96 TUint8 minValueFieldA=0; |
|
97 TUint8 minValueFieldB=0; |
|
98 TUint8 minValueFieldC=0; |
|
99 TUint8 minValueFieldD=0; |
|
100 |
|
101 TUint8 maxValueFieldA=0; |
|
102 TUint8 maxValueFieldB=0; |
|
103 TUint8 maxValueFieldC=0; |
|
104 TUint8 maxValueFieldD=0; |
|
105 |
|
106 TUint8 initialValueFieldA=0; |
|
107 TUint8 initialValueFieldB=0; |
|
108 TUint8 initialValueFieldC=0; |
|
109 TUint8 initialValueFieldD=0; |
|
110 |
|
111 SplitAddressIntoFields(aMinimumFieldValues, minValueFieldA, minValueFieldB, minValueFieldC, minValueFieldD); |
|
112 SplitAddressIntoFields(aMaximumFieldValues, maxValueFieldA, maxValueFieldB, maxValueFieldC, maxValueFieldD); |
|
113 SplitAddressIntoFields(aInitialAddress, initialValueFieldA, initialValueFieldB, initialValueFieldC, initialValueFieldD); |
|
114 |
|
115 // Set each number field to the correct minimum, maximum and initial values |
|
116 CEikMfneField* field; |
|
117 field=CEikMfneNumber::NewL(*Font(), |
|
118 minValueFieldA, |
|
119 maxValueFieldA, |
|
120 initialValueFieldA, |
|
121 aFlags); |
|
122 AddField(field); |
|
123 |
|
124 HBufC* delimiterText=HBufC::NewLC(3); |
|
125 delimiterText->Des().Append(KDelimiter); |
|
126 AddField(CEikMfneSeparator::NewL(delimiterText)); |
|
127 CleanupStack::Pop(); // delimiterText |
|
128 |
|
129 field=CEikMfneNumber::NewL(*Font(), |
|
130 minValueFieldB, |
|
131 maxValueFieldB, |
|
132 initialValueFieldB, |
|
133 aFlags); |
|
134 AddField(field); |
|
135 |
|
136 delimiterText=HBufC::NewLC(1); |
|
137 delimiterText->Des().Append(KDelimiter); |
|
138 AddField(CEikMfneSeparator::NewL(delimiterText)); |
|
139 CleanupStack::Pop(); // delimiterText |
|
140 |
|
141 field=CEikMfneNumber::NewL(*Font(), |
|
142 minValueFieldC, |
|
143 maxValueFieldC, |
|
144 initialValueFieldC, |
|
145 aFlags); |
|
146 AddField(field); |
|
147 |
|
148 delimiterText=HBufC::NewLC(1); |
|
149 delimiterText->Des().Append(KDelimiter); |
|
150 AddField(CEikMfneSeparator::NewL(delimiterText)); |
|
151 CleanupStack::Pop(); // delimiterText |
|
152 |
|
153 field=CEikMfneNumber::NewL(*Font(), |
|
154 minValueFieldD, |
|
155 maxValueFieldD, |
|
156 initialValueFieldD, |
|
157 aFlags); |
|
158 AddField(field); |
|
159 |
|
160 SetMinimumAndMaximum(aMinimumFieldValues, aMaximumFieldValues); |
|
161 |
|
162 MObjectProvider* mop = InputCapabilities().ObjectProvider(); |
|
163 |
|
164 if ( mop ) |
|
165 { |
|
166 CAknExtendedInputCapabilities* extendedInputCapabilities = |
|
167 mop->MopGetObject( extendedInputCapabilities ); |
|
168 |
|
169 if ( extendedInputCapabilities ) |
|
170 { |
|
171 extendedInputCapabilities->SetCapabilities( |
|
172 CAknExtendedInputCapabilities::ESupportsOnlyASCIIDigits ); |
|
173 } |
|
174 } |
|
175 } |
|
176 |
|
177 /** |
|
178 * Method for getting editor fields' minimum and maximum values. |
|
179 * Gets two parameters: |
|
180 * TInetAddr& aMinimumFieldValues - Reference to a TInetAddr struct in which the lower limits |
|
181 * are wanted to be returned. |
|
182 * IP editor fields. |
|
183 * TInetAddr& aMaximumFieldValues - Reference to a TInetAddr struct in which the upper limits |
|
184 * are wanted to be returned. |
|
185 * |
|
186 */ |
|
187 EXPORT_C void CAknIpFieldEditor::GetMinimumAndMaximum(TInetAddr& aMinimumFieldValues, |
|
188 TInetAddr& aMaximumFieldValues) const |
|
189 { |
|
190 TInt firstFieldMin; |
|
191 TInt firstFieldMax; |
|
192 (STATIC_CAST(CEikMfneNumber*,Field(KFieldA)))->GetMinimumAndMaximum(firstFieldMin,firstFieldMax); |
|
193 TInt secondFieldMin; |
|
194 TInt secondFieldMax; |
|
195 (STATIC_CAST(CEikMfneNumber*,Field(KFieldB)))->GetMinimumAndMaximum(secondFieldMin,secondFieldMax); |
|
196 TInt thirdFieldMin; |
|
197 TInt thirdFieldMax; |
|
198 (STATIC_CAST(CEikMfneNumber*,Field(KFieldC)))->GetMinimumAndMaximum(thirdFieldMin,thirdFieldMax); |
|
199 TInt fourthFieldMin; |
|
200 TInt fourthFieldMax; |
|
201 (STATIC_CAST(CEikMfneNumber*,Field(KFieldD)))->GetMinimumAndMaximum(fourthFieldMin,fourthFieldMax); |
|
202 |
|
203 aMinimumFieldValues=TInetAddr(INET_ADDR((TUint32)firstFieldMin, |
|
204 (TUint32)secondFieldMin, |
|
205 (TUint32)thirdFieldMin, |
|
206 (TUint32)fourthFieldMin), |
|
207 0); |
|
208 aMaximumFieldValues=TInetAddr(INET_ADDR((TUint32)firstFieldMax, |
|
209 (TUint32)secondFieldMax, |
|
210 (TUint32)thirdFieldMax, |
|
211 (TUint32)fourthFieldMax), |
|
212 0); |
|
213 } |
|
214 |
|
215 /** |
|
216 * Method for setting editor fields' minimum and maximum values. |
|
217 * Gets two parameters: |
|
218 * TInetAddr& aMinimumFieldValues - Reference to a TInetAddr struct defining the lower limits |
|
219 * of the editor fields. |
|
220 * IP editor fields. |
|
221 * TInetAddr& aMaximumFieldValues - Reference to a TInetAddr struct defining the upper limits |
|
222 * of the editor fields. |
|
223 * |
|
224 */ |
|
225 EXPORT_C void CAknIpFieldEditor::SetMinimumAndMaximum(const TInetAddr& aMinimumFieldValues, |
|
226 const TInetAddr& aMaximumFieldValues) |
|
227 { |
|
228 TUint8 minValueFieldA=0; |
|
229 TUint8 minValueFieldB=0; |
|
230 TUint8 minValueFieldC=0; |
|
231 TUint8 minValueFieldD=0; |
|
232 TUint8 maxValueFieldA=0; |
|
233 TUint8 maxValueFieldB=0; |
|
234 TUint8 maxValueFieldC=0; |
|
235 TUint8 maxValueFieldD=0; |
|
236 |
|
237 SplitAddressIntoFields(aMinimumFieldValues, minValueFieldA, minValueFieldB, minValueFieldC, minValueFieldD); |
|
238 SplitAddressIntoFields(aMaximumFieldValues, maxValueFieldA, maxValueFieldB, maxValueFieldC, maxValueFieldD); |
|
239 (STATIC_CAST(CEikMfneNumber*,Field(KFieldA)))->SetMinimumAndMaximum(minValueFieldA,maxValueFieldA,*Font()); |
|
240 (STATIC_CAST(CEikMfneNumber*,Field(KFieldB)))->SetMinimumAndMaximum(minValueFieldB,maxValueFieldB,*Font()); |
|
241 (STATIC_CAST(CEikMfneNumber*,Field(KFieldC)))->SetMinimumAndMaximum(minValueFieldC,maxValueFieldC,*Font()); |
|
242 (STATIC_CAST(CEikMfneNumber*,Field(KFieldD)))->SetMinimumAndMaximum(minValueFieldD,maxValueFieldD,*Font()); |
|
243 |
|
244 DrawNow(); |
|
245 } |
|
246 |
|
247 /** |
|
248 * Method takes a TInetAddr and returns 4 separate 8-bit unsigned fields |
|
249 * const TInetAddr& aAddress - Reference to a TInetAddr struct |
|
250 * |
|
251 */ |
|
252 void CAknIpFieldEditor::SplitAddressIntoFields( |
|
253 const TInetAddr& aAddress, |
|
254 TUint8 &aFieldA, |
|
255 TUint8 &aFieldB, |
|
256 TUint8 &aFieldC, |
|
257 TUint8 &aFieldD) const |
|
258 |
|
259 { |
|
260 TUint32 temp=0; |
|
261 |
|
262 temp=((aAddress.Address())&KInetAddrNetMaskA)>>KInetAddrShiftA; |
|
263 aFieldA=(TUint8)temp; |
|
264 |
|
265 |
|
266 temp=((aAddress.Address())&KInetAddrNetMaskB&~KInetAddrNetMaskA)>>KInetAddrShiftB; |
|
267 aFieldB=(TUint8)temp; |
|
268 |
|
269 |
|
270 temp=((aAddress.Address())&KInetAddrNetMaskC&~KInetAddrNetMaskB)>>KInetAddrShiftC; |
|
271 aFieldC=(TUint8)temp; |
|
272 |
|
273 |
|
274 temp=(aAddress.Address())&~KInetAddrNetMaskC; |
|
275 aFieldD=(TUint8)temp; |
|
276 } |
|
277 /** |
|
278 * Method for setting the editor fields dynamically. |
|
279 * Gets one parameter: |
|
280 * const TInetAddr& aAddress - Reference to a TInetAddr struct including the new address. |
|
281 * |
|
282 */ |
|
283 EXPORT_C void CAknIpFieldEditor::SetAddress(const TInetAddr& aAddress) |
|
284 { |
|
285 TUint8 fieldA=0; |
|
286 TUint8 fieldB=0; |
|
287 TUint8 fieldC=0; |
|
288 TUint8 fieldD=0; |
|
289 |
|
290 SplitAddressIntoFields(aAddress, fieldA, fieldB, fieldC, fieldD); |
|
291 |
|
292 (STATIC_CAST(CEikMfneNumber*,Field(KFieldA)))->SetValue(fieldA,*Font()); |
|
293 (STATIC_CAST(CEikMfneNumber*,Field(KFieldB)))->SetValue(fieldB,*Font()); |
|
294 (STATIC_CAST(CEikMfneNumber*,Field(KFieldC)))->SetValue(fieldC,*Font()); |
|
295 (STATIC_CAST(CEikMfneNumber*,Field(KFieldD)))->SetValue(fieldD,*Font()); |
|
296 DrawNow(); |
|
297 } |
|
298 |
|
299 /** |
|
300 * Method for reading the editor value. |
|
301 * |
|
302 */ |
|
303 EXPORT_C TInetAddr CAknIpFieldEditor::Address() const |
|
304 { |
|
305 // TE: The return value can not be a const reference because the |
|
306 // TInetAddress that is to be returned exists only withing this function. |
|
307 return TInetAddr(INET_ADDR((TUint8)(STATIC_CAST(CEikMfneNumber*,Field(KFieldA)))->Value(), |
|
308 (TUint8)(STATIC_CAST(CEikMfneNumber*,Field(KFieldB)))->Value(), |
|
309 (TUint8)(STATIC_CAST(CEikMfneNumber*,Field(KFieldC)))->Value(), |
|
310 (TUint8)(STATIC_CAST(CEikMfneNumber*,Field(KFieldD)))->Value()), |
|
311 0); |
|
312 } |
|
313 |
|
314 /** |
|
315 * Method for constructing the control from resources. |
|
316 * Gets one parameter: |
|
317 * TResourceReader& aResourceReader - Reference to a resource reader associated to a |
|
318 * IP Field Editor control resource. |
|
319 * |
|
320 */ |
|
321 EXPORT_C void CAknIpFieldEditor::ConstructFromResourceL(TResourceReader& aResourceReader) |
|
322 { |
|
323 TInetAddr minFieldValues=ReadIPAddress(aResourceReader); |
|
324 TInetAddr maxFieldValues=ReadIPAddress(aResourceReader); |
|
325 TUint32 flags=aResourceReader.ReadUint8(); |
|
326 ConstructL(minFieldValues, maxFieldValues, minFieldValues, flags); |
|
327 } |
|
328 |
|
329 /** |
|
330 * Method for reading an IP address from resources. |
|
331 * Gets one parameter: |
|
332 * TResourceReader& aResourceReader - Reference to a resource reader associated to the |
|
333 * IP address resource. |
|
334 * |
|
335 */ |
|
336 EXPORT_C TInetAddr CAknIpFieldEditor::ReadIPAddress(TResourceReader& aResourceReader) |
|
337 { |
|
338 TUint8 firstField=(TUint8)aResourceReader.ReadUint8(); |
|
339 TUint8 secondField=(TUint8)aResourceReader.ReadUint8(); |
|
340 TUint8 thirdField=(TUint8)aResourceReader.ReadUint8(); |
|
341 TUint8 fourthField=(TUint8)aResourceReader.ReadUint8(); |
|
342 return TInetAddr(INET_ADDR((TUint8)firstField, |
|
343 (TUint8)secondField, |
|
344 (TUint8)thirdField, |
|
345 (TUint8)fourthField), |
|
346 0); |
|
347 } |
|
348 |
|
349 /** |
|
350 * Method for handling key events. |
|
351 * |
|
352 */ |
|
353 EXPORT_C TKeyResponse CAknIpFieldEditor::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) |
|
354 { |
|
355 TKeyResponse response=EKeyWasNotConsumed; |
|
356 TKeyEvent event(aKeyEvent); |
|
357 |
|
358 if(aType==EEventKey && event.iCode=='.') // If delimiter key has been pressed. In IPv4 delimiter is always a dot. |
|
359 event.iCode=EKeyRightArrow; |
|
360 |
|
361 response=CEikMfne::OfferKeyEventL(event, aType); |
|
362 |
|
363 return response; |
|
364 } |
|
365 |
|
366 EXPORT_C void CAknIpFieldEditor::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
367 { |
|
368 CEikMfne::HandlePointerEventL(aPointerEvent); |
|
369 } |
|
370 |
|
371 EXPORT_C void* CAknIpFieldEditor::ExtensionInterface( TUid /*aInterface*/ ) |
|
372 { |
|
373 return NULL; |
|
374 } |
|
375 |
|
376 EXPORT_C void CAknIpFieldEditor::CEikMfne_Reserved() |
|
377 { |
|
378 } |
|
379 |