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: LandmarksUi Content File - |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 // INCLUDE FILES |
|
26 #include <LmkUi.rsg> |
|
27 #include <e32math.h> |
|
28 #include <eikmfne.h> |
|
29 #include <AknUtils.h> |
|
30 #include <AknEditStateIndicator.h> |
|
31 #include <eikenv.h> |
|
32 #include <stringloader.h> |
|
33 |
|
34 #include "landmarks.hrh" |
|
35 #include "LmkConsts.h" |
|
36 |
|
37 #include "CLmkMfneFloat.h" |
|
38 #include "CLmkFloatEditor.h" |
|
39 |
|
40 // CONSTANTS |
|
41 /// Unnamed namespace for local definitions |
|
42 namespace { |
|
43 |
|
44 #if defined(_DEBUG) |
|
45 void Panic(TInt aReason) |
|
46 { |
|
47 _LIT(KPanicCategory, "CLmkFloatEditor"); |
|
48 User::Panic(KPanicCategory, aReason); |
|
49 } |
|
50 #endif |
|
51 |
|
52 } // namespace |
|
53 |
|
54 // ============================ MEMBER FUNCTIONS ============================== |
|
55 |
|
56 // ---------------------------------------------------------------------------- |
|
57 // CLmkFloatEditor::CLmkFloatEditor |
|
58 // C++ default constructor can NOT contain any code, that |
|
59 // might leave. |
|
60 // ---------------------------------------------------------------------------- |
|
61 // |
|
62 CLmkFloatEditor::CLmkFloatEditor() |
|
63 { |
|
64 iIsMirroredLayout = AknLayoutUtils::LayoutMirrored(); |
|
65 } |
|
66 |
|
67 // ---------------------------------------------------- |
|
68 // CLmkFloatEditor::BaseConstructL |
|
69 // ---------------------------------------------------- |
|
70 // |
|
71 void CLmkFloatEditor::BaseConstructL(TInt aMaxNumFields) |
|
72 { |
|
73 __ASSERT_DEBUG(aMaxNumFields > 0, Panic(KErrArgument)); |
|
74 CreateFieldArrayL(aMaxNumFields); |
|
75 } |
|
76 |
|
77 // ---------------------------------------------------- |
|
78 // CLmkFloatEditor::ConstructValueFieldL |
|
79 // ---------------------------------------------------- |
|
80 // |
|
81 void CLmkFloatEditor::ConstructValueFieldL( |
|
82 TInt aMaxNumSignificantDigits, |
|
83 TInt aMaxDecimals) |
|
84 { |
|
85 __ASSERT_DEBUG(iValueField == NULL, Panic(KErrGeneral)); |
|
86 |
|
87 iValueField = |
|
88 CLmkMfneFloat::NewL( |
|
89 aMaxNumSignificantDigits, |
|
90 aMaxDecimals); |
|
91 |
|
92 AddField(iValueField); |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // CLmkFloatEditor::~CLmkFloatEditor |
|
97 // ---------------------------------------------------------------------------- |
|
98 // |
|
99 CLmkFloatEditor::~CLmkFloatEditor() |
|
100 { |
|
101 } |
|
102 |
|
103 // ---------------------------------------------------- |
|
104 // CLmkDistanceEditor::SetNumberL |
|
105 // ---------------------------------------------------- |
|
106 // |
|
107 void CLmkFloatEditor::SetNumber(TReal aNumber) |
|
108 { |
|
109 __ASSERT_DEBUG(iValueField, Panic(KErrGeneral)); |
|
110 iValueField->SetValue(aNumber); |
|
111 HandleValueChanged(); |
|
112 } |
|
113 |
|
114 // ---------------------------------------------------- |
|
115 // CLmkFloatEditor::Number |
|
116 // ---------------------------------------------------- |
|
117 // |
|
118 TReal CLmkFloatEditor::Number() const |
|
119 { |
|
120 __ASSERT_DEBUG(iValueField, Panic(KErrGeneral)); |
|
121 return iValueField->Value(); |
|
122 } |
|
123 |
|
124 // ---------------------------------------------------- |
|
125 // CLmkFloatEditor::IsModified |
|
126 // ---------------------------------------------------- |
|
127 // |
|
128 TBool CLmkFloatEditor::IsModified() |
|
129 { |
|
130 return iIsModified; |
|
131 } |
|
132 |
|
133 // ---------------------------------------------------- |
|
134 // CLmkFloatEditor::IsNan |
|
135 // ---------------------------------------------------- |
|
136 // |
|
137 TBool CLmkFloatEditor::IsNan() |
|
138 { |
|
139 __ASSERT_DEBUG(iValueField, Panic(KErrGeneral)); |
|
140 return Math::IsNaN(iValueField->Value()); |
|
141 } |
|
142 |
|
143 // ---------------------------------------------------- |
|
144 // CLmkFloatEditor::SetLimits |
|
145 // ---------------------------------------------------- |
|
146 // |
|
147 TBool CLmkFloatEditor::SetLimits(TReal aMinimumValue, TReal aMaximumValue) |
|
148 { |
|
149 __ASSERT_DEBUG(iValueField, Panic(KErrGeneral)); |
|
150 if (iValueField->SetLimits(aMinimumValue, aMaximumValue)) |
|
151 { |
|
152 HandleValueChanged(); |
|
153 return ETrue; |
|
154 } |
|
155 else |
|
156 { |
|
157 return EFalse; |
|
158 } |
|
159 } |
|
160 |
|
161 // ---------------------------------------------------- |
|
162 // CLmkFloatEditor::GetLimits |
|
163 // ---------------------------------------------------- |
|
164 // |
|
165 void CLmkFloatEditor::GetLimits(TReal& aMinimum, TReal& aMaximum) |
|
166 { |
|
167 __ASSERT_DEBUG(iValueField, Panic(KErrGeneral)); |
|
168 iValueField->GetLimits(aMinimum, aMaximum); |
|
169 } |
|
170 |
|
171 // ---------------------------------------------------- |
|
172 // CLmkFloatEditor::HandleValueChanged |
|
173 // ---------------------------------------------------- |
|
174 // |
|
175 void CLmkFloatEditor::HandleValueChanged() |
|
176 { |
|
177 if (IsNan()) |
|
178 { |
|
179 // switch to iValueField, |
|
180 // otherwise it won't be possible to enter value anymore |
|
181 if (Field(CurrentField()) != iValueField) |
|
182 { |
|
183 HighlightField(FindValueField()); |
|
184 } |
|
185 } |
|
186 DrawDeferred(); |
|
187 } |
|
188 |
|
189 // ---------------------------------------------------- |
|
190 // CLmkFloatEditor::HandleCustomFieldChanged |
|
191 // ---------------------------------------------------- |
|
192 // |
|
193 void CLmkFloatEditor::HandleCustomFieldChanged(TInt /*aCustomFieldIndex*/) |
|
194 { |
|
195 DrawDeferred(); |
|
196 } |
|
197 |
|
198 void CLmkFloatEditor::HandleEnter() |
|
199 { |
|
200 DrawDeferred(); |
|
201 } |
|
202 |
|
203 void CLmkFloatEditor::HandleExit() |
|
204 { |
|
205 DrawDeferred(); |
|
206 } |
|
207 |
|
208 // ---------------------------------------------------- |
|
209 // CLmkFloatEditor::FindValueField |
|
210 // ---------------------------------------------------- |
|
211 // |
|
212 TInt CLmkFloatEditor::FindValueField() |
|
213 { |
|
214 for (TInt i = 0; i < NumFields(); i++) |
|
215 { |
|
216 if (Field(i) == iValueField) |
|
217 { |
|
218 return i; |
|
219 } |
|
220 } |
|
221 return KErrNotFound; |
|
222 } |
|
223 |
|
224 // ---------------------------------------------------- |
|
225 // CLmkFloatEditor::HighlightField |
|
226 // ---------------------------------------------------- |
|
227 // |
|
228 void CLmkFloatEditor::HighlightField(TInt aFieldPosition) |
|
229 { |
|
230 if (CurrentField() != aFieldPosition) |
|
231 { |
|
232 TBool dataAltered = EFalse; |
|
233 TBool error = EFalse; |
|
234 const CFont& font=*Font(); |
|
235 |
|
236 CEikMfne::HandleInteraction( |
|
237 ETrue, |
|
238 aFieldPosition, |
|
239 Field(CurrentField())->MaximumWidthInPixels(font, EFalse), |
|
240 Field(CurrentField())->HighlightType(), |
|
241 dataAltered, |
|
242 error); |
|
243 } |
|
244 } |
|
245 |
|
246 // ---------------------------------------------------- |
|
247 // CLmkFloatEditor::FocusChanged |
|
248 // ---------------------------------------------------- |
|
249 // |
|
250 void CLmkFloatEditor::FocusChanged(TDrawNow aDrawNow) |
|
251 { |
|
252 if (!IsReadyToDraw()) |
|
253 { |
|
254 // this is workaround for MFNE's bug. |
|
255 // otherwise it will panic hiding cursor |
|
256 return; |
|
257 } |
|
258 |
|
259 if (IsFocused()) |
|
260 { |
|
261 HandleEnter(); |
|
262 |
|
263 // need to inform CLmkMfneFloat that it is highlighted |
|
264 // because CEikMfne does not do it |
|
265 if (iValueField && |
|
266 iValueField == Field(CurrentField())) |
|
267 { |
|
268 iValueField->HandleHighlight(); |
|
269 } |
|
270 } |
|
271 else |
|
272 { |
|
273 HandleExit(); |
|
274 } |
|
275 |
|
276 CEikMfne::FocusChanged(aDrawNow); |
|
277 } |
|
278 |
|
279 // ---------------------------------------------------- |
|
280 // CLmkFloatEditor::OfferKeyEventL |
|
281 // ---------------------------------------------------- |
|
282 // |
|
283 TKeyResponse CLmkFloatEditor::OfferKeyEventL( |
|
284 const TKeyEvent& aKeyEvent, |
|
285 TEventCode aType) |
|
286 { |
|
287 |
|
288 // disallow switch to other fields if value is nan, |
|
289 // because it's hard to inform CLmkMfneFloat |
|
290 // that focus has changed to it from other field. |
|
291 // If it is not done, then CEikMfne will panic when |
|
292 // hiding cursor |
|
293 if (IsNan() && |
|
294 (aKeyEvent.iCode == EKeyLeftArrow || |
|
295 aKeyEvent.iCode == EKeyRightArrow)) |
|
296 { |
|
297 return EKeyWasConsumed; |
|
298 } |
|
299 |
|
300 TInt oldField = CurrentField(); |
|
301 TKeyResponse response = CEikMfne::OfferKeyEventL(aKeyEvent, aType); |
|
302 |
|
303 if (response == EKeyWasConsumed) |
|
304 { |
|
305 // update focus state in CLmkMfneFloat |
|
306 if (oldField != CurrentField() && |
|
307 Field(CurrentField()) == iValueField) |
|
308 { |
|
309 iValueField->HandleHighlight(); |
|
310 } |
|
311 |
|
312 // inform about changes |
|
313 if (aKeyEvent.iCode != EKeyLeftArrow && |
|
314 aKeyEvent.iCode != EKeyRightArrow) |
|
315 { |
|
316 iIsModified = ETrue; |
|
317 if (Field(oldField) == iValueField) |
|
318 { |
|
319 HandleValueChanged(); |
|
320 } |
|
321 else |
|
322 { |
|
323 HandleCustomFieldChanged(oldField); |
|
324 } |
|
325 } |
|
326 } |
|
327 |
|
328 DrawNow(); |
|
329 return response; |
|
330 } |
|
331 |
|
332 // End of File |
|