williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@2
|
3 |
* All rights reserved.
|
williamr@2
|
4 |
* This component and the accompanying materials are made available
|
williamr@4
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
williamr@2
|
6 |
* which accompanies this distribution, and is available
|
williamr@4
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
williamr@2
|
8 |
*
|
williamr@2
|
9 |
* Initial Contributors:
|
williamr@2
|
10 |
* Nokia Corporation - initial contribution.
|
williamr@2
|
11 |
*
|
williamr@2
|
12 |
* Contributors:
|
williamr@2
|
13 |
*
|
williamr@2
|
14 |
* Description: Unit multi-field numeric editor
|
williamr@2
|
15 |
*
|
williamr@2
|
16 |
*/
|
williamr@2
|
17 |
|
williamr@2
|
18 |
|
williamr@2
|
19 |
#ifndef CAKNUNITEDITOR_H
|
williamr@2
|
20 |
#define CAKNUNITEDITOR_H
|
williamr@2
|
21 |
|
williamr@2
|
22 |
#include <eikmfne.h>
|
williamr@2
|
23 |
|
williamr@2
|
24 |
class CAknMfneFloat;
|
williamr@2
|
25 |
class CAknMfneSeparator;
|
williamr@2
|
26 |
|
williamr@2
|
27 |
/**
|
williamr@2
|
28 |
* A multi-field numeric editor for displaying and editing a floating value
|
williamr@2
|
29 |
* and an associated label.
|
williamr@2
|
30 |
*
|
williamr@2
|
31 |
* CAknUnitEditor is a multi-field numeric editor (MFNE), which is used for
|
williamr@2
|
32 |
* displaying and editing floating point numeric data with a textual
|
williamr@2
|
33 |
* label. Unit in the class name refers to a unit of measurement, for
|
williamr@2
|
34 |
* example distance or speed, hence a typical use case might be an editor
|
williamr@2
|
35 |
* which is used to edit an altitude value for a position in a GPS
|
williamr@2
|
36 |
* application.
|
williamr@2
|
37 |
*
|
williamr@2
|
38 |
* Creating the editor is carried out by using either NewL() or
|
williamr@2
|
39 |
* NewLC() function followed by a call to either ConstructL()
|
williamr@2
|
40 |
* or ConstructFromResourceL() function. Note that if the editor is
|
williamr@2
|
41 |
* not constructed fully, most functions will panic with KERN-EXEC 3.
|
williamr@2
|
42 |
*
|
williamr@2
|
43 |
* The value to be shown by the editor must be set at construction, and
|
williamr@2
|
44 |
* can be later set using SetValue(). The current value of the editor
|
williamr@2
|
45 |
* can be retrieved using Value().
|
williamr@2
|
46 |
*
|
williamr@2
|
47 |
* Minimum and maximum limits can be set using the function
|
williamr@2
|
48 |
* SetMinimumAndMaximum(). NaN values for this function are
|
williamr@2
|
49 |
* not supported, and will cause undefined behaviour.
|
williamr@2
|
50 |
*
|
williamr@2
|
51 |
* The editor supports a label shown next to the value. This label can be
|
williamr@2
|
52 |
* set to a custom value (referred to as custom unit), or a set of
|
williamr@2
|
53 |
* predefined and localized units can be used. See TAknUnitEditorUnits in
|
williamr@2
|
54 |
* eikon.hrh and the two overloads of SetUnitL(). Note that the editor
|
williamr@2
|
55 |
* discards the custom unit when a localized unit is set, so setting
|
williamr@2
|
56 |
* the localized unit back to EAknUnitEditorCustomUnit clears
|
williamr@2
|
57 |
* the unit.
|
williamr@2
|
58 |
*
|
williamr@2
|
59 |
* The editor supports variable number of fractional digits. A value
|
williamr@2
|
60 |
* with no fractional part at all can also be displayed and edited. This
|
williamr@2
|
61 |
* feature can be used with the function SetMaxFractionalDigits(), and
|
williamr@2
|
62 |
* the corresponding getter MaxFractionalDigits(). Values set using
|
williamr@2
|
63 |
* construction functions or SetValue() are rounded to correspond
|
williamr@2
|
64 |
* with the number of fractional digits, so data loss may occur in such
|
williamr@2
|
65 |
* case.
|
williamr@2
|
66 |
*
|
williamr@2
|
67 |
* The editor also supports an uninitialized state, which in practice means
|
williamr@2
|
68 |
* that it can have nothing to display and in such case contains a
|
williamr@2
|
69 |
* 'not a number' (NaN) value. This state can be allowed by the using the flag
|
williamr@2
|
70 |
* EAknUnitEditorAllowUninitialized, found in TAknUnitEditorFlags in
|
williamr@2
|
71 |
* eikon.hrh. For more information about NaN, see Math::IsNaN() and
|
williamr@2
|
72 |
* TRealX::SetNaN().
|
williamr@2
|
73 |
*
|
williamr@2
|
74 |
* @lib eikctl.lib
|
williamr@2
|
75 |
* @since S60 v3.2
|
williamr@2
|
76 |
*/
|
williamr@2
|
77 |
NONSHARABLE_CLASS( CAknUnitEditor ) : public CEikMfne
|
williamr@2
|
78 |
{
|
williamr@2
|
79 |
public:
|
williamr@2
|
80 |
/**
|
williamr@2
|
81 |
* Creates a new CAknUnitEditor object. The client must call ConstructL()
|
williamr@2
|
82 |
* or ConstructFromResourceL() after calling this function.
|
williamr@2
|
83 |
*
|
williamr@2
|
84 |
* @return The created CAknUnitEditor.
|
williamr@2
|
85 |
*/
|
williamr@2
|
86 |
IMPORT_C static CAknUnitEditor* NewL();
|
williamr@2
|
87 |
|
williamr@2
|
88 |
/**
|
williamr@2
|
89 |
* Creates a new CAknUnitEditor object, leaving it in the cleanup stack.
|
williamr@2
|
90 |
* The client must call ConstructL() or ConstructFromResourceL()
|
williamr@2
|
91 |
* after calling this function.
|
williamr@2
|
92 |
*
|
williamr@2
|
93 |
* @return The created CAknUnitEditor.
|
williamr@2
|
94 |
*/
|
williamr@2
|
95 |
IMPORT_C static CAknUnitEditor* NewLC();
|
williamr@2
|
96 |
|
williamr@2
|
97 |
/**
|
williamr@2
|
98 |
* C++ destructor. Deletes all owned member data.
|
williamr@2
|
99 |
*/
|
williamr@2
|
100 |
virtual ~CAknUnitEditor();
|
williamr@2
|
101 |
|
williamr@2
|
102 |
/**
|
williamr@2
|
103 |
* Second-phase constructor. This should be called after creating a
|
williamr@2
|
104 |
* new editor object with NewL() or NewLC(), if the
|
williamr@2
|
105 |
* editor is not constructed from a resource.
|
williamr@2
|
106 |
*
|
williamr@2
|
107 |
* @param aMinimumValue The minimum allowable value.
|
williamr@2
|
108 |
* @param aMaximumValue The maximum allowable value.
|
williamr@2
|
109 |
* @param aInitialValue The initial value, can be NaN if the editor
|
williamr@2
|
110 |
* is set to support it by using the
|
williamr@2
|
111 |
* EAknUnitEditorAllowedUninitialized flag.
|
williamr@2
|
112 |
* @param aMaxFractionalDigits The maximum number of fractional digits.
|
williamr@2
|
113 |
* @param aUnit The unit type, see TAknUnitEditorUnits
|
williamr@2
|
114 |
* in eikon.hrh. Can be set to EAknUnitEditorCustomUnit
|
williamr@2
|
115 |
* or zero if you plan on using a custom unit.
|
williamr@2
|
116 |
* @param aFlags The editor flags, see TAknUnitEditorFlags
|
williamr@2
|
117 |
* in eikon.hrh. This can be set to zero if no flags
|
williamr@2
|
118 |
* are desired. This is also the default parameter.
|
williamr@2
|
119 |
* @leave KErrNotSupported If the given predefined unit type, aUnit,
|
williamr@2
|
120 |
* is not found.
|
williamr@2
|
121 |
* @see TAknUnitEditorUnits
|
williamr@2
|
122 |
* @see TAknUnitEditorFlags
|
williamr@2
|
123 |
*/
|
williamr@2
|
124 |
IMPORT_C void ConstructL(
|
williamr@2
|
125 |
TReal aMinimumValue, TReal aMaximumValue,
|
williamr@2
|
126 |
TReal aInitialValue,
|
williamr@2
|
127 |
TInt aMaxFractionalDigits, TInt aUnit, TUint aFlags = 0 );
|
williamr@2
|
128 |
|
williamr@2
|
129 |
/**
|
williamr@2
|
130 |
* Second-phase constructor. This should be called after creating a
|
williamr@2
|
131 |
* new editor object with NewL() or NewLC(), if the
|
williamr@2
|
132 |
* editor is constructed from a resource. The resource structure
|
williamr@2
|
133 |
* used in creating the editor is AVKON_UNIT_EDITOR.
|
williamr@2
|
134 |
*
|
williamr@2
|
135 |
* @param aResourceReader A resource file reader.
|
williamr@2
|
136 |
* @leave KErrNotSupported If the predefined unit type in the resource
|
williamr@2
|
137 |
* is not found.
|
williamr@2
|
138 |
* @see AVKON_UNIT_EDITOR
|
williamr@2
|
139 |
*/
|
williamr@2
|
140 |
IMPORT_C void ConstructFromResourceL( TResourceReader& aResourceReader );
|
williamr@2
|
141 |
|
williamr@2
|
142 |
/**
|
williamr@2
|
143 |
* Sets a value to the editor. If the value is too large or small it is
|
williamr@2
|
144 |
* set to maximum or minimum value, respectively. In case of an
|
williamr@2
|
145 |
* unallowed NaN the value is set to be the maximum value.
|
williamr@2
|
146 |
*
|
williamr@2
|
147 |
* @param aValue The value to be set.
|
williamr@2
|
148 |
* @return ETrue, if the value was valid and not changed. The value is
|
williamr@2
|
149 |
* also considered to be valid in case it is rounded to the
|
williamr@2
|
150 |
* limits of the editor's maximum fractional digits.
|
williamr@2
|
151 |
*/
|
williamr@2
|
152 |
IMPORT_C TBool SetValue( TReal aValue );
|
williamr@2
|
153 |
|
williamr@2
|
154 |
/**
|
williamr@2
|
155 |
* Gets the value from the editor.
|
williamr@2
|
156 |
*
|
williamr@2
|
157 |
* @return The value from the editor.
|
williamr@2
|
158 |
*/
|
williamr@2
|
159 |
IMPORT_C TReal Value() const;
|
williamr@2
|
160 |
|
williamr@2
|
161 |
/**
|
williamr@2
|
162 |
* Tests if particular predefined unit type is supported.
|
williamr@2
|
163 |
*
|
williamr@2
|
164 |
* @param aUnit The predefined unit type, from the enum
|
williamr@2
|
165 |
* TAknUnitEditorUnits.
|
williamr@2
|
166 |
* @return ETrue, if the given predefined unit type is supported.
|
williamr@2
|
167 |
* @see TAknUnitEditorUnits
|
williamr@2
|
168 |
*/
|
williamr@2
|
169 |
IMPORT_C TBool SupportsUnit( TInt aUnit ) const;
|
williamr@2
|
170 |
|
williamr@2
|
171 |
/**
|
williamr@2
|
172 |
* Sets the custom unit type. There's no actual limit for the length of
|
williamr@2
|
173 |
* the text, but if the unit text overflows, it will not be wrapped.
|
williamr@2
|
174 |
*
|
williamr@2
|
175 |
* @param aUnit The unit type to be set.
|
williamr@2
|
176 |
*/
|
williamr@2
|
177 |
IMPORT_C void SetUnitL( const TDesC& aUnit );
|
williamr@2
|
178 |
|
williamr@2
|
179 |
/**
|
williamr@2
|
180 |
* Sets the predefined and localized unit type. If the given unit type
|
williamr@2
|
181 |
* is EAknUnitEditorCustomUnit, the unit field is emptied and a
|
williamr@2
|
182 |
* subsequent call to SetUnitL( const TDesC& aUnit ) is needed.
|
williamr@2
|
183 |
*
|
williamr@2
|
184 |
* @param aUnit The predefined unit type, from the enum
|
williamr@2
|
185 |
* TAknUnitEditorUnits.
|
williamr@2
|
186 |
* @leave KErrNotSupported If the given predefined unit type is not found.
|
williamr@2
|
187 |
* @see TAknUnitEditorUnits
|
williamr@2
|
188 |
*/
|
williamr@2
|
189 |
IMPORT_C void SetUnitL( TInt aUnit );
|
williamr@2
|
190 |
|
williamr@2
|
191 |
/**
|
williamr@2
|
192 |
* Gets the current unit type as a descriptor. This returns the textual
|
williamr@2
|
193 |
* representation of the unit field, regardless of the way it was set.
|
williamr@2
|
194 |
*
|
williamr@2
|
195 |
* @param aDes On return, contains the editor's unit type if it fits in
|
williamr@2
|
196 |
* the given descriptor.
|
williamr@2
|
197 |
* @return Zero, if the function executed successfully. Otherwise the
|
williamr@2
|
198 |
* minimum length needed for the editor's content.
|
williamr@2
|
199 |
*/
|
williamr@2
|
200 |
IMPORT_C TInt GetUnit( TDes& aDes ) const;
|
williamr@2
|
201 |
|
williamr@2
|
202 |
/**
|
williamr@2
|
203 |
* Gets the current unit type as an predefined unit type id,
|
williamr@2
|
204 |
* from the enum TAknUnitEditorUnits. Returns EAknUnitEditorCustomUnit
|
williamr@2
|
205 |
* if the last unit set was a custom unit.
|
williamr@2
|
206 |
*
|
williamr@2
|
207 |
* @return The current unit type identifier. EAknUnitEditorCustomUnit
|
williamr@2
|
208 |
* if custom unit was set.
|
williamr@2
|
209 |
* @see TAknUnitEditorUnits
|
williamr@2
|
210 |
*/
|
williamr@2
|
211 |
IMPORT_C TInt Unit() const;
|
williamr@2
|
212 |
|
williamr@2
|
213 |
/**
|
williamr@2
|
214 |
* Sets the maximum number of digits to show in the fractional part of
|
williamr@2
|
215 |
* the value. The maximum number of fractional digits is limited
|
williamr@2
|
216 |
* to eight. Setting a value outside of valid range (0 to 8) has
|
williamr@2
|
217 |
* no effect in release builds, and panics in debug builds.
|
williamr@2
|
218 |
*
|
williamr@2
|
219 |
* @param aFractionalDigits The maximum number of digits in the
|
williamr@2
|
220 |
* fractional part. Can be zero to eight.
|
williamr@2
|
221 |
* @panic 1 In debug builds only, if aMaxFractionalDigits is out of
|
williamr@2
|
222 |
* range.
|
williamr@2
|
223 |
*/
|
williamr@2
|
224 |
IMPORT_C void SetMaxFractionalDigits( TInt aMaxFractionalDigits );
|
williamr@2
|
225 |
|
williamr@2
|
226 |
/**
|
williamr@2
|
227 |
* Gets the maximum number of digits in the fractional part of the
|
williamr@2
|
228 |
* value.
|
williamr@2
|
229 |
*
|
williamr@2
|
230 |
* @return The maximum number of digits in the fractional part
|
williamr@2
|
231 |
*/
|
williamr@2
|
232 |
IMPORT_C TInt MaxFractionalDigits() const;
|
williamr@2
|
233 |
|
williamr@2
|
234 |
/**
|
williamr@2
|
235 |
* Sets the minimum and maximum editor values. NaN values are not
|
williamr@2
|
236 |
* supported, and will cause undefined behaviour.
|
williamr@2
|
237 |
*
|
williamr@2
|
238 |
* @param aMinimumValue The minimum allowable value
|
williamr@2
|
239 |
* @param aMaximumValue The maximum allowable value
|
williamr@2
|
240 |
*/
|
williamr@2
|
241 |
IMPORT_C void SetMinimumAndMaximum(
|
williamr@2
|
242 |
TReal aMinimumValue, TReal aMaximumValue );
|
williamr@2
|
243 |
|
williamr@2
|
244 |
/**
|
williamr@2
|
245 |
* Gets the minimum and maximum editor values.
|
williamr@2
|
246 |
*
|
williamr@2
|
247 |
* @param aMinimumValue On return, contains the editor's minimum value
|
williamr@2
|
248 |
* @param aMaximumValue On return, contains the editor's maximum value
|
williamr@2
|
249 |
*/
|
williamr@2
|
250 |
IMPORT_C void GetMinimumAndMaximum(
|
williamr@2
|
251 |
TReal& aMinimumValue, TReal& aMaximumValue ) const;
|
williamr@2
|
252 |
|
williamr@2
|
253 |
/**
|
williamr@2
|
254 |
* Sets the editor flags, see TAknUnitEditorFlags in eikon.hrh.
|
williamr@2
|
255 |
*
|
williamr@2
|
256 |
* @param aFlags The editor flags. Note that this overrides all
|
williamr@2
|
257 |
* the flags. Use zero if no flags are desired.
|
williamr@2
|
258 |
* @see TAknUnitEditorFlags
|
williamr@2
|
259 |
*/
|
williamr@2
|
260 |
IMPORT_C void SetFlags( TUint aFlags );
|
williamr@2
|
261 |
|
williamr@2
|
262 |
/**
|
williamr@2
|
263 |
* Gets the editor flags, see TAknUnitEditorFlags in eikon.hrh.
|
williamr@2
|
264 |
*
|
williamr@2
|
265 |
* @return The editor flags.
|
williamr@2
|
266 |
* @see TAknUnitEditorFlags
|
williamr@2
|
267 |
*/
|
williamr@2
|
268 |
IMPORT_C TUint Flags() const;
|
williamr@2
|
269 |
|
williamr@2
|
270 |
// from base class CEikMfne
|
williamr@2
|
271 |
|
williamr@2
|
272 |
/**
|
williamr@2
|
273 |
* From CEikMfne.
|
williamr@2
|
274 |
* Validates the values in the editor. This function should be called
|
williamr@2
|
275 |
* before removing focus from the editor.
|
williamr@2
|
276 |
*
|
williamr@2
|
277 |
* @leave KLeaveWithoutAlert If the value in the field had an error
|
williamr@2
|
278 |
* in it.
|
williamr@2
|
279 |
*/
|
williamr@2
|
280 |
IMPORT_C void PrepareForFocusLossL();
|
williamr@2
|
281 |
|
williamr@2
|
282 |
protected:
|
williamr@2
|
283 |
|
williamr@2
|
284 |
/**
|
williamr@2
|
285 |
* From CEikMfne.
|
williamr@2
|
286 |
* Deals with focus changes.
|
williamr@2
|
287 |
*
|
williamr@2
|
288 |
* @param aDrawNow Whether to draw the control immediately.
|
williamr@2
|
289 |
*/
|
williamr@2
|
290 |
void FocusChanged( TDrawNow aDrawNow );
|
williamr@2
|
291 |
|
williamr@2
|
292 |
private:
|
williamr@2
|
293 |
|
williamr@2
|
294 |
/**
|
williamr@2
|
295 |
* C++ constructor.
|
williamr@2
|
296 |
*/
|
williamr@2
|
297 |
CAknUnitEditor();
|
williamr@2
|
298 |
|
williamr@2
|
299 |
/**
|
williamr@2
|
300 |
* Checks if the unit field label should be visible.
|
williamr@2
|
301 |
*
|
williamr@2
|
302 |
* @return ETrue, if the unit field should be visible.
|
williamr@2
|
303 |
*/
|
williamr@2
|
304 |
TBool UnitFieldVisibility() const;
|
williamr@2
|
305 |
|
williamr@2
|
306 |
private: // data
|
williamr@2
|
307 |
|
williamr@2
|
308 |
/**
|
williamr@2
|
309 |
* Bit flags
|
williamr@2
|
310 |
*/
|
williamr@2
|
311 |
TUint iFlags;
|
williamr@2
|
312 |
|
williamr@2
|
313 |
/**
|
williamr@2
|
314 |
* The limit for predefined unit indices
|
williamr@2
|
315 |
*/
|
williamr@2
|
316 |
const TInt iUnitLimit;
|
williamr@2
|
317 |
|
williamr@2
|
318 |
/**
|
williamr@2
|
319 |
* Value of the current unit type, as in enum
|
williamr@2
|
320 |
* TAknUnitEditorUnits.
|
williamr@2
|
321 |
*/
|
williamr@2
|
322 |
TInt iUnitType;
|
williamr@2
|
323 |
|
williamr@2
|
324 |
/**
|
williamr@2
|
325 |
* Helper pointer to float value field
|
williamr@2
|
326 |
* Not own.
|
williamr@2
|
327 |
*/
|
williamr@2
|
328 |
CAknMfneFloat* iFloatField;
|
williamr@2
|
329 |
|
williamr@2
|
330 |
/**
|
williamr@2
|
331 |
* Helper pointer to separator field
|
williamr@2
|
332 |
* Not own.
|
williamr@2
|
333 |
*/
|
williamr@2
|
334 |
CAknMfneSeparator* iSeparatorField;
|
williamr@2
|
335 |
|
williamr@2
|
336 |
/**
|
williamr@2
|
337 |
* Helper pointer to unit field
|
williamr@2
|
338 |
* Not own.
|
williamr@2
|
339 |
*/
|
williamr@2
|
340 |
CAknMfneSeparator* iUnitField;
|
williamr@2
|
341 |
|
williamr@2
|
342 |
};
|
williamr@2
|
343 |
|
williamr@2
|
344 |
#endif // CAKNUNITEDITOR_H
|