|
1 /* |
|
2 * Copyright (c) 2002-2004 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 * This class gives feature variant - independent access to Series 60 number grouping |
|
17 * and provides digit type conversion. |
|
18 * |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 #ifndef AKNPHONENUMBERGROUPING_H |
|
24 #define AKNPHONENUMBERGROUPING_H |
|
25 |
|
26 // INCLUDES |
|
27 |
|
28 #include <e32std.h> |
|
29 #include <gdi.h> |
|
30 |
|
31 // CONSTANTS |
|
32 |
|
33 |
|
34 // CLASS DECLARATION |
|
35 |
|
36 class CPNGNumberGrouping; |
|
37 |
|
38 |
|
39 /** |
|
40 * This class acts as a wrapper for the Number Grouping engine (NumberGrouping.dll). |
|
41 * It exposes non-static API to the engine so that it can be used without the client code dealing with the |
|
42 * issues of |
|
43 * - build switches for calling numbergrouping API |
|
44 * - build switches for linking to NumberGrouping.lib |
|
45 * - checks on Feature Manager. |
|
46 * |
|
47 * It deals with these internally. In the case of __SERIES60_PHONE_NUMBER_GROUPING being #undef-ed, this |
|
48 * object acts as if there is a "null" phone number grouping. |
|
49 * |
|
50 * Static methods are included for those who are doing a small number of individual groupings of phone numbers, |
|
51 * say, when a view or popup is constructed, or a title pane is refreshed. These construct the object |
|
52 * internally within the static call. |
|
53 * |
|
54 * The class also deals with the conversion of numbers to potentially locale or setting- |
|
55 * specific number symbols, using the Series 60 platform policy. |
|
56 * |
|
57 * For repeated, frequent operations, the non-static API is recommended. Only a limited number of methods |
|
58 * from NumberGrouping.h are exposed, but these suffice in the main use cases. |
|
59 * |
|
60 * @lib Avkon.dll |
|
61 * @since 2.6 |
|
62 */ |
|
63 NONSHARABLE_CLASS(CAknPhoneNumberGrouping) : public CBase |
|
64 { |
|
65 public: |
|
66 // 2 stage constructors |
|
67 IMPORT_C static CAknPhoneNumberGrouping* NewLC(TInt aUnformattedLength); |
|
68 IMPORT_C static CAknPhoneNumberGrouping* NewL(TInt aUnformattedLength); |
|
69 |
|
70 // Destructor |
|
71 ~CAknPhoneNumberGrouping(); |
|
72 |
|
73 public: // non-static methods for using phone number grouping engine in the simplest cases |
|
74 |
|
75 /** |
|
76 * Load an ungrouped number into the phone number grouping engine |
|
77 * This calls the CPNGNumberGrouping::Set within the engine |
|
78 * |
|
79 * @since 2.6 |
|
80 * @param aUngroupedNumber input ungrouped phone number |
|
81 * @return KErrNone if there was no error |
|
82 */ |
|
83 IMPORT_C TInt Set( const TDesC& aUngroupedNumber ); |
|
84 |
|
85 /** |
|
86 * Returns a reference to the formatted number stored within the number grouping engine |
|
87 * |
|
88 * NOTE: This api does not convert to current digit type. This requires a method that takes |
|
89 * a modifiable descriptor, so use CopyFormattedNumber( TDes& ) const |
|
90 * |
|
91 * This method is particularly useful for obtaining the size of the required buffer to copy |
|
92 * the grouped phone number to by calling FormattedNumber.Length() |
|
93 * |
|
94 * @since 2.6 |
|
95 * @return reference to internally held formatted (grouped) phone number |
|
96 */ |
|
97 IMPORT_C const TDesC& FormattedNumber() const; |
|
98 |
|
99 /** |
|
100 * Copies the grouped phone number stored in the object to the supplied output buffer, |
|
101 * performing any current digit type conversion required. |
|
102 * |
|
103 * The length required for the supplied output descriptor must be greater or equal to the text waiting |
|
104 * to be copied out of the instance. This can be determined before the call with no loss of |
|
105 * performance with FormattedNumber().Length(); |
|
106 * |
|
107 * The application will be Panicked (USER 11) if the output descriptor is too short. |
|
108 * |
|
109 * @since 2.6 |
|
110 * @param aGroupedNumber Output (grouped) descriptor to be written to. To avoid a panic, this |
|
111 * must be at least as big as the formatted number currently stored. |
|
112 */ |
|
113 IMPORT_C void CopyFormattedNumber( TDes& aGroupedNumber ) const; |
|
114 |
|
115 public: // Static utility methods for doing the one-off grouping of phone numbers |
|
116 |
|
117 /** |
|
118 * Static utility method for doing one-off grouping of a phone number according to the current |
|
119 * configuration. |
|
120 * |
|
121 * The method Leaves if the number grouping engine could not be allocated, or the output heap memory |
|
122 * could not be allocated. |
|
123 * |
|
124 * @since 2.6 |
|
125 * @param aUngroupedNumber Input descriptor to be grouped |
|
126 * @return Pointer to heap descriptor containing the grouped number |
|
127 * Ownership is transferred to the caller |
|
128 */ |
|
129 IMPORT_C static HBufC* CreateGroupedPhoneNumberL( const TDesC& aUngroupedNumber ); |
|
130 |
|
131 /** |
|
132 * Static utility method for doing one-off grouping of a phone number according to the current |
|
133 * configuration. |
|
134 * |
|
135 * The operations are internally trapped so as not to leave. The grouped number must fit into output |
|
136 * descriptor, or else no grouping will take place and the input will just be copied to the output. |
|
137 * A negative return value will indicate that the output did not fit, and by how much. |
|
138 * |
|
139 * The application will be Panicked (USER 11) if the output descriptor is too short even for an exact |
|
140 * copy of the input. |
|
141 * |
|
142 * @since 2.6 |
|
143 * @param aUngroupedNumber Input descriptor to be grouped |
|
144 * @param aGroupedNumber Output (grouped) descriptor to be written to |
|
145 * @return If the entire grouped number could be copied to the output, then the |
|
146 * returned number is zero or positive. This number represents the number |
|
147 * of further characters in the grouped number that could have been accomodated. |
|
148 * A negative return value indicates that the grouped number could not be |
|
149 * copied, and that the ungrouped number had to be copied. The magnitude |
|
150 * of the return value in this case is how many more characters would have |
|
151 * been needed. |
|
152 */ |
|
153 IMPORT_C static TInt GroupPhoneNumber( const TDesC& aUngroupedNumber, TDes& aGroupedNumber ); |
|
154 |
|
155 /** |
|
156 * Static utility method for doing one-off grouping of a phone number according to the current |
|
157 * configuration. |
|
158 * |
|
159 * The operations are internally trapped so as not to leave. The grouped number must fit into the one, |
|
160 * input/output descriptor, or else no grouping will take place. A negative return value indicates that the |
|
161 * grouped number did not fit. |
|
162 * |
|
163 * @since 2.6 |
|
164 * @param aUngroupedNumber Input descriptor to be grouped |
|
165 * @return If the entire grouped number could be copied to the output, then the |
|
166 * returned number is zero or positive. This number represents the number |
|
167 * of further characters in the grouped number that could have been accomodated. |
|
168 * A negative return value indicates that the grouped number could not be |
|
169 * copied, and that the ungrouped number had to be copied. The magnitude |
|
170 * of the return value in this case is how many more characters would have |
|
171 * been needed. |
|
172 */ |
|
173 IMPORT_C static TInt GroupPhoneNumber( TDes& aPhoneNumber ); |
|
174 |
|
175 private: |
|
176 /** |
|
177 * C++ constructor. |
|
178 */ |
|
179 CAknPhoneNumberGrouping(); |
|
180 |
|
181 /** |
|
182 * 2nd phase constructor is private. |
|
183 */ |
|
184 void ConstructL( TInt aUnformattedLength ); |
|
185 |
|
186 /** |
|
187 * Internal method for creating a phone number grouping engine and copying out the result to an |
|
188 * output buffer. |
|
189 * |
|
190 * The creation of the engine may leave, in which case nothing else happens. But if it does not |
|
191 * leave, an attempt will be made to copy the grouped phone number to aGroupedPhoneNumber. |
|
192 * If there is enough space, it is copied and the amount of space in characters left over in |
|
193 * the target buffer is returned. If it does not fit, then there is no copy made and the |
|
194 * aExtraSpace contains a negative value, the additional length required. |
|
195 * |
|
196 * @param aUngroupedNumber Input descriptor containing a phone number |
|
197 * @param aGroupedNumber Output descriptor for the grouped phone number |
|
198 * @param aExtraSpace How much extra space there was in the output descriptor |
|
199 * @return EFalse iff the grouped phone number was not copied. |
|
200 */ |
|
201 static TBool DoFormatPhoneNumberL( |
|
202 const TDesC& aUngroupedNumber, |
|
203 TDes& aGroupedNumber, |
|
204 TInt& aExtraSpace); |
|
205 |
|
206 private: |
|
207 // Owned number grouping engine |
|
208 CPNGNumberGrouping* iNumberGroupingEngine; |
|
209 }; |
|
210 |
|
211 #endif |
|
212 |
|
213 // End of File |