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 * This class is a data container of unit conversion parameters |
|
16 * for a single unit category. It creates and owns the units in this |
|
17 * category. It is able to construct itself from a resource file. |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 |
|
23 #ifndef __CCNVCATEGORY_H__ |
|
24 #define __CCNVCATEGORY_H__ |
|
25 |
|
26 // INCLUDES |
|
27 #include <e32base.h> |
|
28 #include <bamdesca.h> |
|
29 #include "TCnvUnit.h" |
|
30 |
|
31 // FORWARD DECLARATIONS |
|
32 class TResourceReader; |
|
33 class RWriteStream; |
|
34 |
|
35 // CONSTANTS |
|
36 const TInt KMaxNameLength = 32; |
|
37 |
|
38 // CLASS DEFINITION |
|
39 /** |
|
40 * This class is a data container of unit conversion parameters |
|
41 * for a single unit category. It creates and owns the units in this category. |
|
42 * It is able to construct itself from a resource file. |
|
43 */ |
|
44 class CCnvCategory : public CBase, public MDesCArray |
|
45 { |
|
46 public: // Constructors and destructor |
|
47 |
|
48 /** |
|
49 * Destructor. |
|
50 */ |
|
51 ~CCnvCategory(); |
|
52 |
|
53 /** |
|
54 * Two-phased constructor |
|
55 * @param aReader A resource reader object initialised to a resource. |
|
56 */ |
|
57 static CCnvCategory* NewLC( TResourceReader& aReader, TBool aIsCurrencyCategory = EFalse ); |
|
58 |
|
59 private: // Constructors |
|
60 |
|
61 /** |
|
62 * Default constructor. Inlined to save a few bytes |
|
63 * 2 = array granularity ( balanced between memory usage and speed ) |
|
64 */ |
|
65 inline CCnvCategory() : iUnitArray( 2 ) , iTempUintForRestoreArray( 2 ) {}; |
|
66 |
|
67 /** |
|
68 * Constructs this category from a CNV_CATEGORY resource. |
|
69 * @param aReader A resource reader object initialised to a resource. |
|
70 */ |
|
71 void ConstructFromResourceL( TResourceReader& aReader , TBool aIsCurrencyCategory = EFalse); |
|
72 |
|
73 public: // from MDesCArray |
|
74 |
|
75 /** |
|
76 * Returns the number of items (units) in this category. |
|
77 * @return number of items. |
|
78 */ |
|
79 TInt MdcaCount() const; |
|
80 |
|
81 /** |
|
82 * Returns a pointer to a unit name specified by aIndex. |
|
83 * @param aIndex Defines the point in the array that is |
|
84 * queried for the name. |
|
85 * @return Pointer to unit name. |
|
86 */ |
|
87 TPtrC MdcaPoint( TInt aIndex ) const; |
|
88 |
|
89 public: // new methods |
|
90 |
|
91 /** |
|
92 * Calculates the conversion from source unit to destination unit. |
|
93 * @param aSourceUnit Index of the source unit. |
|
94 * @param aDestinationUnit Index of the destination unit. |
|
95 * @param aAmount Convert this many source units. |
|
96 * @return Result of conversion, rounded to aDecimals decimal places. |
|
97 */ |
|
98 TReal Convert( TUint aSourceUnit, TUint aDestinationUnit, |
|
99 const TReal& aAmount, TUint aDecimals ) const; |
|
100 |
|
101 /** |
|
102 * Returns the default unit indices. |
|
103 * @param aSourceUnit Index placeholder of the source unit. |
|
104 * @param aDestinationUnit Index placeholder of the destination unit. |
|
105 */ |
|
106 void GetDefaultUnits( TUint& aSourceUnit, |
|
107 TUint& aDestinationUnit ) const; |
|
108 |
|
109 /** |
|
110 * Sets the default unit indices. |
|
111 * @param aSourceUnit Index of the new source unit. |
|
112 * @param aDestinationUnit Index of the new destination unit. |
|
113 */ |
|
114 void SetDefaultUnits( TUint aSourceUnit, TUint aDestinationUnit ); |
|
115 |
|
116 /** |
|
117 * Returns the index of the base unit. |
|
118 * @return base unit index. |
|
119 */ |
|
120 TUint BaseUnit() const; |
|
121 |
|
122 /** |
|
123 * Changes the index of the base unit. |
|
124 * @param aIndex new base unit index. |
|
125 */ |
|
126 void SetBaseUnit( const TUint& aIndex ); |
|
127 |
|
128 /** |
|
129 * Returns a pointer to this category's name. |
|
130 * @return the category name. |
|
131 */ |
|
132 const TDes& Name() const; |
|
133 |
|
134 /** |
|
135 * Returns a reference to the Unit object identified by aIndex. |
|
136 * @return the requested Unit object. |
|
137 */ |
|
138 TCnvUnit& Unit( TUint aIndex ); |
|
139 |
|
140 /** |
|
141 * Stores the unit array to the given stream. |
|
142 * @param aStream Stream for writing. |
|
143 */ |
|
144 void ExternalizeL( RWriteStream& aStream ) const; |
|
145 |
|
146 /** |
|
147 * Loads the unit array from the given stream. |
|
148 * @param aStream Stream for reading. |
|
149 */ |
|
150 void InternalizeL( RReadStream& aStream , TBool aIsCurrencyCategory = EFalse); |
|
151 |
|
152 /** |
|
153 * create a unit array copy |
|
154 * |
|
155 */ |
|
156 void CreateTempUnitArrayForRestore(); |
|
157 |
|
158 /** |
|
159 * restore the unit array |
|
160 * |
|
161 */ |
|
162 void RestoreUnitArray(); |
|
163 |
|
164 private: // data |
|
165 |
|
166 /** |
|
167 * Index of the default source unit (in the unit array). |
|
168 */ |
|
169 TUint iSourceUnitIndex; |
|
170 |
|
171 /** |
|
172 * Index of the default destination unit (in the unit array). |
|
173 */ |
|
174 TUint iDestinationUnitIndex; |
|
175 |
|
176 /** |
|
177 * Index of the base unit (in the unit array). |
|
178 */ |
|
179 TUint iBaseUnitIndex; |
|
180 |
|
181 /** |
|
182 * Name of this category. |
|
183 */ |
|
184 TBuf< KMaxNameLength > iName; |
|
185 |
|
186 /** |
|
187 * The array for units in this category. Owned. |
|
188 */ |
|
189 CArrayFixSeg< TCnvUnit > iUnitArray; |
|
190 |
|
191 // Save unit for restore |
|
192 CArrayFixSeg< TCnvUnit > iTempUintForRestoreArray; |
|
193 |
|
194 public: |
|
195 /** |
|
196 *Deletes a particular currency from the list. |
|
197 *@param aControlId indicates which currency has to be deleted. |
|
198 */ |
|
199 void DeleteCurrency(TInt aCurrencyId); |
|
200 |
|
201 /** |
|
202 *Adds a new field at a given position(focus) |
|
203 *@param aControlId indicates the currenct focus and the new currency |
|
204 * should be added accordingly |
|
205 *@param aNewName indicates the name of the currecy being added |
|
206 *@param aNewFactor indicates the factor of the currency that will be added |
|
207 */ |
|
208 void AddNewCurrencyL( TInt aCurrencyId, TDesC& aNewName, TReal& aNewFactor , TCurrencyType aType); |
|
209 |
|
210 }; |
|
211 |
|
212 #endif // __CCNVCATEGORY_H__ |
|