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 * An AVKON form class containing popup fields and floating point editors. |
|
16 * Implements the 'Main State' of the application. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 #ifndef __CCNVMAINFORM_H__ |
|
23 #define __CCNVMAINFORM_H__ |
|
24 |
|
25 // INCLUDES |
|
26 #include <AknForm.h> |
|
27 #include <TCnvCategory.h> |
|
28 |
|
29 //Select Edwin |
|
30 #include <eikedwob.h> |
|
31 |
|
32 |
|
33 // FORWARD DECLARATIONS |
|
34 class CCnvConverter; |
|
35 class CAknPopupField; |
|
36 class CErrorUI; |
|
37 |
|
38 // CLASS DEFINITION |
|
39 /** |
|
40 * An AVKON form class containing popup fields and floating point editors. |
|
41 * Implements the 'Main State' of the application. |
|
42 */ |
|
43 class CCnvMainForm : public CAknForm , public MEikEdwinObserver |
|
44 { |
|
45 |
|
46 public: // constructors and destructor |
|
47 |
|
48 /** |
|
49 * Default constructor. |
|
50 */ |
|
51 CCnvMainForm( TBool &aAlreadyDead ); |
|
52 |
|
53 /** |
|
54 * Destructor. |
|
55 */ |
|
56 ~CCnvMainForm(); |
|
57 |
|
58 /** |
|
59 * 2nd phase constructor. |
|
60 */ |
|
61 void ConstructL(); |
|
62 |
|
63 private: // constructors |
|
64 |
|
65 /** |
|
66 * Default constructor. Not implemented. |
|
67 */ |
|
68 CCnvMainForm(); |
|
69 |
|
70 public: // from CCoeControl |
|
71 |
|
72 /** |
|
73 * Specifies the help context for this form. |
|
74 * @param aContext the context IDs are placed here |
|
75 */ |
|
76 void GetHelpContext( TCoeHelpContext& aContext ) const; |
|
77 |
|
78 public: // from MEikCommandObserver |
|
79 |
|
80 /** |
|
81 * Handles menu commands. |
|
82 * @param aCommandId Command identifier. |
|
83 */ |
|
84 void ProcessCommandL( TInt aCommandId ); |
|
85 |
|
86 public: // from MEikDialogPageObserver |
|
87 |
|
88 /** |
|
89 * Takes any action required when the current line is |
|
90 * changed to aControlId. |
|
91 * @param aControlId Control identifier. |
|
92 */ |
|
93 void LineChangedL( TInt aControlId ); |
|
94 |
|
95 public: // from MEikMenuObserver |
|
96 |
|
97 /** |
|
98 * Dynamically initialises a menu pane. The Uikon framework calls this |
|
99 * function, immediately before the menu pane is activated. |
|
100 * @param aResourceId Resource ID identifying a menu pane to initialise |
|
101 * @param aMenuPane The in-memory representation of the menu pane. |
|
102 */ |
|
103 void DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane ); |
|
104 |
|
105 protected: // from MCoeControlObserver |
|
106 |
|
107 /** |
|
108 * Handles an event originating from one of the form's controls. |
|
109 * @param aControl The control that reported the event. |
|
110 * @param aEventType The type of the reported event. |
|
111 */ |
|
112 void HandleControlEventL( CCoeControl* aControl, |
|
113 TCoeEvent aEventType ); |
|
114 |
|
115 protected: // from CAknForm |
|
116 |
|
117 /** |
|
118 * Saves form popup field states to a file (not implemented, yet). |
|
119 * @return ETrue if the editable state can be left |
|
120 * (always in this case). |
|
121 */ |
|
122 TBool SaveFormData(); |
|
123 |
|
124 /** |
|
125 * Deal with that the field is empty,when move focus to other field. |
|
126 * The Uikon framework calls this function,immediately before focus move. |
|
127 */ |
|
128 void PrepareForFocusTransitionL(); |
|
129 protected: // from CEikDialog |
|
130 |
|
131 /** |
|
132 * Tests if it is OK to exit the dialog. |
|
133 * @param aButtonId The ID of the button that was activated. |
|
134 * @return ETrue to validate and exit the dialog, |
|
135 * EFalse to keep the dialog active. |
|
136 */ |
|
137 TBool OkToExitL( TInt aButtonId ); |
|
138 |
|
139 /** |
|
140 * Pre-layout dialog initialisation. |
|
141 */ |
|
142 void PreLayoutDynInitL(); |
|
143 |
|
144 private: // new methods |
|
145 /** |
|
146 * returns ETrue if the the character is an integer |
|
147 */ |
|
148 TBool IsDigit(TUint aChar); |
|
149 |
|
150 /** |
|
151 * Checks if a form control has REALLY changed (uses history knowledge) |
|
152 * Form controls report bogus state changed events, this is used to |
|
153 * filter them out. |
|
154 * @param controlId Form ID of the control to be checked |
|
155 * @return ETrue if the specified control's state has changed |
|
156 */ |
|
157 TBool HasReallyChanged( TInt controlId ); |
|
158 |
|
159 /** |
|
160 * Initialised change history (for HasReallyChanged) |
|
161 */ |
|
162 void InitialiseChangeHistory(); |
|
163 |
|
164 /** |
|
165 * Called when the user has changed |
|
166 * the unit type popup field selection. |
|
167 */ |
|
168 void HandleCategoryChangedL(); |
|
169 |
|
170 /** |
|
171 * Called when the user has changed |
|
172 * either of the unit popup field selections. |
|
173 */ |
|
174 void HandleUnitChangedL(); |
|
175 |
|
176 /** |
|
177 * Checks if the unit rates (factors) are defined in the model |
|
178 * for the currently selected unit type. |
|
179 * @param aShowNote If ETrue "rates missing note" is shown, if |
|
180 * rates are not valid. |
|
181 * @return ETrue if rates are valid, EFalse otherwise. |
|
182 */ |
|
183 TBool AreRatesValidL(TBool aShowNote); |
|
184 |
|
185 /** |
|
186 * Checks if a floating point editor's value is within allowable range. |
|
187 * @param aEditorId Resource ID of the editor control to be checked. |
|
188 * @return ETrue If value is in range, EFalse otherwise. |
|
189 */ |
|
190 TBool IsEditorValueValidL( TUint aEditorId ); |
|
191 |
|
192 /** |
|
193 * Checks if a floating point editor's value is such that no conversion |
|
194 * should be made and no "invalid value" error should be reported. |
|
195 * @param aEditorId Resource ID of the editor control to be checked. |
|
196 * @return ETrue Indicates that conversion should not proceed. |
|
197 */ |
|
198 TBool EditorValueCausesHold( TUint aEditorId ); |
|
199 |
|
200 /** |
|
201 * Handles the ECmdRates command. Launches the Rates Form. |
|
202 */ |
|
203 void CmdRatesL(); |
|
204 |
|
205 /** |
|
206 * Handles the ECmdSetType command. |
|
207 */ |
|
208 void CmdSetTypeL(); |
|
209 |
|
210 /** |
|
211 * Handles the ECmdSetUnit command. |
|
212 */ |
|
213 void CmdSetUnitL(); |
|
214 |
|
215 /** |
|
216 * Tells the model to load its state from a file. |
|
217 */ |
|
218 void LoadStateL(); |
|
219 |
|
220 /** |
|
221 * Tells the model to save its state to a file. |
|
222 * Displays an error note if there is not enough space in permanent |
|
223 * storage. |
|
224 */ |
|
225 void SaveState(); |
|
226 |
|
227 /** |
|
228 * Calculates and displays the unit conversion immediately. |
|
229 */ |
|
230 void SynchronousConversionL( TBool aShowRateInvalidNote = ETrue ); |
|
231 |
|
232 /** |
|
233 * Calculates and displays the unit conversion after 0.75 seconds. |
|
234 */ |
|
235 void AsynchronousConversion(); |
|
236 |
|
237 /** |
|
238 * Cancels a queued asynchronous conversion request, if any. |
|
239 */ |
|
240 void CancelConversion(); |
|
241 |
|
242 /** |
|
243 * Called by the conversion timer after the 0.75 second timeout |
|
244 * has exipred. Calls SynchronousConversion() to do |
|
245 * the actual conversion. |
|
246 * @param aMainForm Pointer to the CCnvMainForm instance. |
|
247 */ |
|
248 static TInt TimerCallback( TAny* aMainForm ); |
|
249 |
|
250 /** |
|
251 * Shows an error note for invalid value situation |
|
252 * @param aEditorId Id of the editor that holds the invalid value |
|
253 */ |
|
254 void ShowInvalidValueNoteL(TInt aEditorId); |
|
255 |
|
256 /** |
|
257 * From CCoeControl processing of a key event |
|
258 * @param aKeyEvent : Key event information |
|
259 * aType : EEventKeyDown | EEventKey | EEventKeyUp |
|
260 * @return : EKeyWasConsumed if keyevent is consumed. |
|
261 * EKeyWasNotConsumed if keyevent is not consumed. |
|
262 * Handling of the keys is taken care for the editor fields |
|
263 */ |
|
264 TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, |
|
265 TEventCode aType); |
|
266 |
|
267 /** |
|
268 *Checks if the number entered in the editor field is a valid number |
|
269 *@param aEditroId : Id of the editor that needs to be evaluated |
|
270 *@return : EFalse if the editor value is not a vaild number |
|
271 * : ETrue if the number is a valid number |
|
272 */ |
|
273 TBool IsVaildNumberEntered(TInt aEditorId); |
|
274 |
|
275 /** |
|
276 *From MEikEdwinObserver. handles the Navigation on the editor control. |
|
277 */ |
|
278 void HandleEdwinEventL(CEikEdwin* aEdwin,TEdwinEvent aEventType); |
|
279 |
|
280 /** |
|
281 *Do the calculation and change the value for the related edit field |
|
282 */ |
|
283 void ValueCalculationL( TUint aUnit1Popup, TUint aUnit2Popup, TReal aMount ); |
|
284 |
|
285 private: // data |
|
286 |
|
287 /** |
|
288 * Pointer to our model. Owned. |
|
289 */ |
|
290 CCnvConverter* iModel; |
|
291 |
|
292 /** |
|
293 * Model accessor for unit types. |
|
294 */ |
|
295 TCnvCategory iTypeCategory; |
|
296 |
|
297 /** |
|
298 * Model accessor for source units. |
|
299 */ |
|
300 TCnvCategory iUnit1Category; |
|
301 |
|
302 /** |
|
303 * Model accessor for destination units. |
|
304 */ |
|
305 TCnvCategory iUnit2Category; |
|
306 |
|
307 /** |
|
308 * Pointer to the Unit Type popup field. Not owned. |
|
309 */ |
|
310 CAknPopupField* iTypePopupCtrl; |
|
311 |
|
312 /** |
|
313 * Pointer to the source Unit popup field. Not owned. |
|
314 */ |
|
315 CAknPopupField* iUnit1PopupCtrl; |
|
316 |
|
317 /** |
|
318 * Pointer to the destination Unit popup field. Not owned. |
|
319 */ |
|
320 CAknPopupField* iUnit2PopupCtrl; |
|
321 |
|
322 /** |
|
323 * Id of the currency category in the model. |
|
324 */ |
|
325 TUint iCurrencyCategoryId; |
|
326 |
|
327 /** |
|
328 * ETrue if this instance is fully constructed, EFalse otherwise. |
|
329 */ |
|
330 TBool iIsFullyConstructed; |
|
331 |
|
332 /** |
|
333 * ETrue if the user has already been notified that the disk is full. |
|
334 */ |
|
335 TBool iHasNotifiedDiscFull; |
|
336 |
|
337 /** |
|
338 * ETrue if the iLastUsedEditorId has changed after the focus |
|
339 * has entered the editor. |
|
340 */ |
|
341 TBool iActiveEditorChanged; |
|
342 |
|
343 /** |
|
344 * Pointer to the timer used for asynchronous conversions |
|
345 * (which need a0.75 second delay..) |
|
346 */ |
|
347 CPeriodic* iConversionTimer; |
|
348 |
|
349 /** |
|
350 * The id of the unit amount field that the user has modified last. |
|
351 */ |
|
352 TInt iLastUsedEditorId; |
|
353 |
|
354 /** |
|
355 * The id of the line that was last active in the form. |
|
356 */ |
|
357 TInt iLastActiveEditorLine; |
|
358 |
|
359 /** |
|
360 * The previous type selection. |
|
361 */ |
|
362 TInt iHistoryTypeCategory; |
|
363 |
|
364 /** |
|
365 * The previous source unit selection. |
|
366 */ |
|
367 TInt iHistoryUnit1Category; |
|
368 |
|
369 /** |
|
370 * The previous destination unit selection. |
|
371 */ |
|
372 TInt iHistoryUnit2Category; |
|
373 |
|
374 /** |
|
375 * Pointer to the Error UI object. Owned |
|
376 * Used for displaying the Disk Full error message. |
|
377 */ |
|
378 CErrorUI* iErrorUI; |
|
379 |
|
380 /** |
|
381 * Reference to a flag in this form's owner. |
|
382 * Used to indicate that we have been deleted by someone |
|
383 * (could be the app framework.. <sigh>) |
|
384 */ |
|
385 TBool& iAlreadyDead; |
|
386 |
|
387 TKeyEvent iKeyEvent; |
|
388 |
|
389 TBool isEdwinNavigated; |
|
390 TBool isEdwinUpdateText; |
|
391 |
|
392 }; |
|
393 |
|
394 #endif // __CCNVMAINFORM_H__ |
|
395 |
|