FreeCalypso > hg > tcs211-l1-reconst
comparison g23m/condat/ms/src/bmi/MmiCalculatorMain.c @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 /******************************************************************************* | |
2 | |
3 CONDAT (UK) | |
4 | |
5 ******************************************************************************** | |
6 | |
7 This software product is the property of Condat (UK) Ltd and may not be | |
8 disclosed to any third party without the express permission of the owner. | |
9 | |
10 ******************************************************************************** | |
11 | |
12 $Project name: Basic MMI | |
13 $Project code: BMI (6349) | |
14 $Module: Calculator | |
15 $File: MmiCalculatorMain.c | |
16 $Revision: 1.0 | |
17 | |
18 $Author: Condat(UK) | |
19 $Date: 25/10/00 | |
20 | |
21 ******************************************************************************** | |
22 | |
23 Description | |
24 | |
25 This provides the main calculator functionality | |
26 | |
27 | |
28 ******************************************************************************** | |
29 $History: MmiCalculatorMain.c | |
30 | |
31 25/10/00 Original Condat(UK) BMI version. | |
32 | |
33 xrashmic 20 Oct, 2005 MMI-SPR-33845 | |
34 To display BACK softkey when no more character are left in the calulator editor | |
35 | |
36 Oct 20, 2004 REF: CRR 25755 xnkulkar | |
37 Description: calculator -divide by zero operation is allowed. | |
38 Fix: Display "Not Allowed" message when user tries to divide a number by 0 and do not perform the | |
39 division. Also, show the editor again so that user can enter a number other than 0. | |
40 | |
41 $End | |
42 | |
43 *******************************************************************************/ | |
44 #define MAX_CALC_TOTAL 999999999 | |
45 #define MIN_CALC_TOTAL -99999999 | |
46 | |
47 /****************************************************************************** | |
48 | |
49 Include Files | |
50 | |
51 *******************************************************************************/ | |
52 #define ENTITY_MFW | |
53 | |
54 /* includes */ | |
55 #include <string.h> | |
56 #include <stdio.h> | |
57 #include <stdlib.h> | |
58 | |
59 #if defined (NEW_FRAME) | |
60 | |
61 #include "typedefs.h" | |
62 #include "vsi.h" | |
63 #include "pei.h" | |
64 #include "custom.h" | |
65 #include "gsm.h" | |
66 | |
67 #else | |
68 | |
69 #include "STDDEFS.H" | |
70 #include "custom.h" | |
71 #include "gsm.h" | |
72 #include "vsi.h" | |
73 | |
74 #endif | |
75 #include "message.h" | |
76 #include "prim.h" | |
77 #include "aci_cmh.h" | |
78 | |
79 | |
80 #include "mfw_mfw.h" | |
81 #include "mfw_win.h" | |
82 /* SPR#1428 - SH - New Editor changes */ | |
83 #ifndef NEW_EDITOR | |
84 #include "mfw_edt.h" | |
85 #endif | |
86 #include "mfw_tim.h" | |
87 #include "mfw_phb.h" | |
88 #include "ksd.h" | |
89 #include "psa.h" | |
90 #include "mfw_icn.h" | |
91 #include "mfw_mnu.h" | |
92 #include "mfw_lng.h" | |
93 #include "mfw_sat.h" | |
94 #include "mfw_kbd.h" | |
95 #include "mfw_nm.h" | |
96 #include "mfw_sms.h" | |
97 | |
98 #include "dspl.h" | |
99 | |
100 #include "MmiMmi.h" | |
101 #include "MmiDummy.h" | |
102 #include "MmiDialogs.h" | |
103 #include "MmiLists.h" | |
104 #include "MmiIdle.h" | |
105 #include "MmiSoftKeys.h" | |
106 #include "Mmiicons.h" | |
107 #include "MmiMenu.h" | |
108 #include "MmiMain.h" | |
109 #include "MmiStart.h" | |
110 #include "MmiPins.h" | |
111 #include "MmiSettings.h" | |
112 | |
113 /* SPR#1428 - SH - New Editor changes */ | |
114 #ifdef NEW_EDITOR | |
115 #include "ATBCommon.h" | |
116 #include "ATBDisplay.h" | |
117 #include "ATBEditor.h" | |
118 #include "AUIEditor.h" | |
119 #include "AUICalcEditor.h" | |
120 #else | |
121 #include "MmiEditor.h" | |
122 #endif | |
123 #include "MmiBookShared.h" | |
124 #include "mmiSmsMenu.h" | |
125 #include "MmiCalculatorMain.h" | |
126 #include "mmiColours.h" | |
127 | |
128 #include "cus_aci.h" | |
129 | |
130 #include "pcm.h" | |
131 | |
132 | |
133 /******************************************************************************* | |
134 | |
135 Function Prototypes | |
136 | |
137 *******************************************************************************/ | |
138 static T_MFW_HND calc_create(MfwHnd parent_window); | |
139 void calc_destroy(MfwHnd own_window); | |
140 static void calcGetNumberCB( T_MFW_HND win, USHORT Identifier, SHORT reason ); | |
141 static void calcGetOperandCB( T_MFW_HND win, USHORT Identifier, SHORT reason ); | |
142 static void calc_DialogCB( T_MFW_HND win, USHORT event, SHORT identifier, void *parameter); | |
143 T_MFW_HND calc_start(T_MFW_HND parent_window); | |
144 double calcGetRunningTotal(void); | |
145 char operatorSymbol(UBYTE operator); | |
146 static void calc_menu_cb(T_MFW_HND parent_win, UBYTE identifier, UBYTE reason); | |
147 /******************************************************************************* | |
148 | |
149 Static Global Variable(s) | |
150 | |
151 *******************************************************************************/ | |
152 | |
153 static double running_total; | |
154 | |
155 static T_MFW_HND calculator_win = NULL; | |
156 | |
157 | |
158 // Oct 20, 2004 REF: CRR 25755 xnkulkar | |
159 // Added this flag to detect 'divide by zero' operation | |
160 BOOL divideByZero = FALSE; | |
161 | |
162 /******************************************************************************* | |
163 | |
164 Public Functions | |
165 | |
166 *******************************************************************************/ | |
167 /******************************************************************************* | |
168 | |
169 $Function: calculator | |
170 | |
171 $Description: Starts the calculator function on user selection | |
172 | |
173 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise | |
174 MFW_EVENT_PASSED | |
175 | |
176 $Arguments: menu, menu item | |
177 | |
178 *******************************************************************************/ | |
179 int calculator(MfwMnu* m, MfwMnuItem* i) | |
180 { | |
181 T_MFW_HND parent = mfwParent( mfw_header()); | |
182 TRACE_FUNCTION("calculator()"); | |
183 calc_start(parent); | |
184 return MFW_EVENT_CONSUMED; | |
185 } | |
186 | |
187 /******************************************************************************* | |
188 | |
189 $Function: calcPlus | |
190 | |
191 $Description: Handles the selction of the "Plus" option in the calculator menu | |
192 | |
193 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise | |
194 MFW_EVENT_PASSED | |
195 | |
196 $Arguments: menu, menu item | |
197 | |
198 *******************************************************************************/ | |
199 int calcPlus(MfwMnu* m, MfwMnuItem* i) | |
200 { | |
201 T_MFW_WIN* win_data; | |
202 tCalcData* data; | |
203 | |
204 TRACE_FUNCTION("calcPlus()"); | |
205 //if new window successfully created | |
206 if (calculator_win NEQ NULL) | |
207 { win_data = ( (T_MFW_HDR *) calculator_win )->data; | |
208 data = (tCalcData*)win_data->user; | |
209 data->operation = PLUS;//set the arithmetic operation | |
210 SEND_EVENT (calculator_win, CALC_ENTER_OPERAND, 0, 0); | |
211 } | |
212 return MFW_EVENT_CONSUMED; | |
213 } | |
214 | |
215 /******************************************************************************* | |
216 | |
217 $Function: calcMinus | |
218 | |
219 $Description: Handles the selection of the "Minus" option in the calculator menu | |
220 | |
221 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise | |
222 MFW_EVENT_PASSED | |
223 | |
224 $Arguments: menu, menu item | |
225 | |
226 *******************************************************************************/ | |
227 int calcMinus(MfwMnu* m, MfwMnuItem* i) | |
228 { | |
229 T_MFW_WIN* win_data; | |
230 tCalcData* data; | |
231 | |
232 //if new window successfully created | |
233 TRACE_FUNCTION("calcMinus()"); | |
234 if (calculator_win NEQ NULL) | |
235 { win_data = ( (T_MFW_HDR *) calculator_win )->data; | |
236 data = (tCalcData*)win_data->user; | |
237 data->operation = MINUS;//set the arithmetic operation | |
238 SEND_EVENT (calculator_win, CALC_ENTER_OPERAND, 0, 0); | |
239 } | |
240 return MFW_EVENT_CONSUMED; | |
241 } | |
242 | |
243 /******************************************************************************* | |
244 | |
245 $Function: calcDivide | |
246 | |
247 $Description: Handles the selection of the "Divide" option in the calculator menu | |
248 | |
249 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise | |
250 MFW_EVENT_PASSED | |
251 | |
252 $Arguments: menu, menu item | |
253 | |
254 *******************************************************************************/ | |
255 int calcDivide(MfwMnu* m, MfwMnuItem* i) | |
256 { | |
257 T_MFW_WIN* win_data; | |
258 tCalcData* data; | |
259 | |
260 TRACE_FUNCTION("calcDivide()"); | |
261 //if new window successfully created | |
262 if (calculator_win NEQ NULL) | |
263 { win_data = ( (T_MFW_HDR *) calculator_win )->data; | |
264 data = (tCalcData*)win_data->user; | |
265 data->operation = DIVIDE;//set the arithmetic operation | |
266 SEND_EVENT (calculator_win, CALC_ENTER_OPERAND, 0, 0); | |
267 } | |
268 return MFW_EVENT_CONSUMED; | |
269 } | |
270 /******************************************************************************* | |
271 | |
272 $Function: calcMultiply | |
273 | |
274 $Description: Handles the selection of the "Multiply" option in the calculator menu | |
275 | |
276 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise | |
277 MFW_EVENT_PASSED | |
278 | |
279 $Arguments: menu, menu item | |
280 | |
281 *******************************************************************************/ | |
282 int calcMultiply(MfwMnu* m, MfwMnuItem* i) | |
283 { | |
284 T_MFW_WIN* win_data; | |
285 tCalcData* data; | |
286 | |
287 TRACE_FUNCTION("calcMultiply()"); | |
288 //if new window successfully created | |
289 if (calculator_win NEQ NULL) | |
290 { win_data = ( (T_MFW_HDR *) calculator_win )->data; | |
291 data = (tCalcData*)win_data->user; | |
292 data->operation = MULTIPLY;//set the arithmetic operation | |
293 SEND_EVENT (calculator_win, CALC_ENTER_OPERAND, 0, 0); | |
294 } | |
295 return MFW_EVENT_CONSUMED; | |
296 } | |
297 | |
298 // Oct 20, 2004 REF: CRR 25755 xnkulkar | |
299 /******************************************************************************* | |
300 | |
301 $Function: info_screen_cb | |
302 | |
303 $Description: Callback function for info screen | |
304 | |
305 $Returns: nothing | |
306 | |
307 $Arguments: Parent Window handle, identifier and reason | |
308 | |
309 *******************************************************************************/ | |
310 | |
311 static void info_screen_cb(T_MFW_HND parent_win, UBYTE identifier, UBYTE reason) | |
312 { | |
313 // Send CALC_ENTER_OPERAND event tp prompt the user to enter the operand again | |
314 SEND_EVENT (calculator_win, CALC_ENTER_OPERAND, 0, 0); | |
315 } | |
316 | |
317 /******************************************************************************* | |
318 | |
319 $Function: calcEquals | |
320 | |
321 $Description: Handles the selection of the "Equals" option in the calculator menu | |
322 | |
323 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise | |
324 MFW_EVENT_PASSED | |
325 | |
326 $Arguments: menu, menu item | |
327 | |
328 *******************************************************************************/ | |
329 int calcEquals(MfwMnu* m, MfwMnuItem* i) | |
330 { | |
331 TRACE_FUNCTION("calcEquals()"); | |
332 | |
333 // Oct 20, 2004 REF: CRR 25755 xnkulkar | |
334 // if 'divide by zero' operation is attempted | |
335 if(divideByZero == TRUE) | |
336 { | |
337 divideByZero = FALSE; // disable the flag | |
338 info_screen(0, TxtNotAllowed, TxtNull, info_screen_cb); // display "Not Allowed" message | |
339 return MFW_EVENT_CONSUMED; // consume the event | |
340 } | |
341 | |
342 if (calculator_win NEQ NULL) | |
343 { | |
344 SEND_EVENT (calculator_win, CALC_DISPLAY_RESULT, 0, 0); | |
345 } | |
346 | |
347 return MFW_EVENT_CONSUMED; | |
348 } | |
349 | |
350 /******************************************************************************* | |
351 | |
352 Private Functions | |
353 | |
354 *******************************************************************************/ | |
355 /******************************************************************************* | |
356 | |
357 $Function: calcGetRunningTotal | |
358 | |
359 $Description: If the calculator's running total value ever needs to be accessed by | |
360 code in another file, then this function ought to be made public to prevent | |
361 to allow safe access; | |
362 | |
363 $Returns: Calculator's running total (double) | |
364 | |
365 $Arguments: none | |
366 | |
367 *******************************************************************************/ | |
368 double calcGetRunningTotal(void) | |
369 { | |
370 TRACE_FUNCTION("calcGetRunningTotal()"); | |
371 return running_total; | |
372 } | |
373 | |
374 /******************************************************************************* | |
375 | |
376 $Function: operatorSymbol | |
377 | |
378 $Description: returns character corresponding to arithmetic operation | |
379 | |
380 $Returns: Operator character | |
381 | |
382 $Arguments: Operator enum | |
383 | |
384 *******************************************************************************/ | |
385 char operatorSymbol(UBYTE operator) | |
386 { | |
387 TRACE_FUNCTION("operatorSymbol()"); | |
388 switch (operator) | |
389 { | |
390 case (PLUS): return '+'; // break; // RAVI | |
391 case (MINUS): return '-'; // break; // RAVI | |
392 case (MULTIPLY): return '*'; // break; // RAVI | |
393 case (DIVIDE): return '/'; // break; // RAVI | |
394 default: return '\0'; // break; // RAVI | |
395 } | |
396 | |
397 } | |
398 | |
399 | |
400 /******************************************************************************* | |
401 | |
402 $Function: calc_start | |
403 | |
404 $Description: Creates the calculator window and calls for it to be initialised | |
405 | |
406 $Returns: Window | |
407 | |
408 $Arguments: Parent Window | |
409 | |
410 *******************************************************************************/ | |
411 | |
412 T_MFW_HND calc_start(T_MFW_HND parent_window) | |
413 { | |
414 T_MFW_HND win = calc_create(parent_window); | |
415 TRACE_FUNCTION("calc_start()"); | |
416 if (win NEQ NULL) | |
417 { | |
418 SEND_EVENT (win, CALC_INIT, 0, 0); | |
419 } | |
420 | |
421 return win; | |
422 } | |
423 | |
424 /******************************************************************************* | |
425 | |
426 $Function: calc_create | |
427 | |
428 $Description: Creates the calculator window and connect the dialog data to it | |
429 | |
430 $Returns: Window | |
431 | |
432 $Arguments: Parent Window | |
433 | |
434 *******************************************************************************/ | |
435 static T_MFW_HND calc_create(MfwHnd parent_window) | |
436 { | |
437 tCalcData * data = (tCalcData *)ALLOC_MEMORY (sizeof (tCalcData )); | |
438 T_MFW_WIN * win; | |
439 | |
440 TRACE_FUNCTION("calc_create()"); | |
441 if (data EQ NULL) | |
442 { | |
443 return NULL; | |
444 } | |
445 | |
446 // Create window handler | |
447 data->win = win_create (parent_window, 0, E_WIN_VISIBLE, NULL); | |
448 if (data->win EQ NULL) | |
449 { | |
450 | |
451 return NULL; | |
452 } | |
453 // connect the dialog data to the MFW-window | |
454 data->mmi_control.dialog = (T_DIALOG_FUNC)calc_DialogCB; | |
455 data->mmi_control.data = data; | |
456 win = ((T_MFW_HDR *)data->win)->data; | |
457 win->user = (void *)data; | |
458 data->parent_win = parent_window; | |
459 calculator_win = data->win; | |
460 return data->win; | |
461 } | |
462 | |
463 /******************************************************************************* | |
464 | |
465 $Function: calc_DialogCB | |
466 | |
467 $Description: Callback function for the calculator window | |
468 | |
469 $Returns: nothing | |
470 | |
471 $Arguments: Window, event, identifier (not used), parameter (not used) | |
472 | |
473 *******************************************************************************/ | |
474 static void calc_DialogCB(T_MFW_HND win, USHORT e, SHORT identifier, void *parameter) | |
475 { | |
476 T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data; | |
477 tCalcData* data = (tCalcData *) win_data->user; | |
478 char display_buffer[28] = ""; | |
479 #ifdef NEW_EDITOR | |
480 // T_AUI_EDITOR_DATA editor_data; /* SPR#1428 - SH - New Editor data */ // RAVI | |
481 #else | |
482 // T_EDITOR_DATA editor_data; // RAVI | |
483 #endif | |
484 char* running_total_out; | |
485 // char debug_buffer[50]; // RAVI | |
486 TRACE_FUNCTION("calc_DialogCB()"); | |
487 | |
488 switch( e ) | |
489 { //when window first created | |
490 case CALC_INIT: | |
491 { //set running total to 0 and display in editor | |
492 TRACE_EVENT("CALC-INIT-JGG"); | |
493 running_total = 0; | |
494 data->menu_options_win = NULL; | |
495 | |
496 /* SPR#1428 - SH - New editor: calc starts with 0 */ | |
497 #ifdef NEW_EDITOR | |
498 sprintf(data->buffer, "%s", "0"); /* SH - calc starts off with '0'*/ | |
499 #else | |
500 sprintf(data->buffer, "%s", ""); /* SH - calc starts off with nothing*/ | |
501 #endif | |
502 | |
503 calcSetEditor(win);//set editor with default attribute values | |
504 /* SPR#1428 - SH - New Editor changes: use calc editor */ | |
505 #ifdef NEW_EDITOR | |
506 AUI_edit_SetEvents(&data->editor_data, 0, TRUE, FOREVER, (T_AUI_EDIT_CB)calcGetNumberCB); | |
507 data->editor_win = AUI_calc_Start(win, &data->editor_data); | |
508 #else /* NEW_EDITOR */ | |
509 data->editor_data.Callback = (T_EDIT_CB)calcGetNumberCB; | |
510 data->editor_win = editor_start(win, &(data->editor_data)); /* start the editor */ | |
511 #endif /* NEW_EDITOR */ | |
512 winShow(data->win); | |
513 } | |
514 break; | |
515 | |
516 //when an arithmetic operator has been selected from the calc menu | |
517 case CALC_ENTER_OPERAND: | |
518 { | |
519 TRACE_EVENT("CALC_ENTER_OPERAND"); | |
520 /* This memory alloc seems to fix a problem where running_total_out | |
521 * would become an empty string after sevaral running calculations */ | |
522 running_total_out = (char*)ALLOC_MEMORY(22*sizeof(char)); /* SH - change malloc to ALLOC_MEMORY */ | |
523 | |
524 running_total_out[0] = '\0'; | |
525 | |
526 /* Display the first operand and the operator symbol | |
527 * above the operand to be entered */ | |
528 if ( (long)calcGetRunningTotal() == calcGetRunningTotal()) | |
529 sprintf((char*)running_total_out, "%d", (long)calcGetRunningTotal()); | |
530 else | |
531 sprintf((char*)running_total_out, "%f", calcGetRunningTotal()); | |
532 | |
533 if (running_total_out[8] == '.') | |
534 running_total_out[8] = '\0'; | |
535 else | |
536 running_total_out[9] = '\0'; | |
537 | |
538 sprintf((char*)display_buffer,"%s %c", running_total_out, operatorSymbol(data->operation)); | |
539 FREE_MEMORY((void*)running_total_out, 22*sizeof(char)); /* SH - change free to FREE_MEMORY */ | |
540 | |
541 /* SPR#1428 - SH - Calc now starts off with '0' */ | |
542 #ifdef NEW_EDITOR | |
543 sprintf(data->buffer, "%s", "0"); /* SH - calc starts off with '0'*/ | |
544 #else | |
545 sprintf(data->buffer, "%s", ""); /* SH - calc starts off with nothing*/ | |
546 #endif | |
547 | |
548 calcSetEditor(win); | |
549 | |
550 /* SPR#1428 - SH - New Editor changes */ | |
551 #ifdef NEW_EDITOR | |
552 AUI_edit_SetEvents(&data->editor_data, 0, TRUE, FOREVER, (T_AUI_EDIT_CB)calcGetOperandCB); | |
553 AUI_edit_SetTextStr(&data->editor_data, TxtSoftOptions, TxtDelete, TxtCalculator, (UBYTE *)display_buffer); | |
554 AUI_edit_SetAltTextStr(&data->editor_data, 1, TxtSoftOptions, TRUE, TxtSoftBack);//x0035544 17-11-2005 | |
555 data->input_number_win = AUI_calc_Start(win, &data->editor_data); | |
556 #else /* NEW_EDITOR */ | |
557 data->editor_data.TextString = display_buffer; | |
558 data->editor_data.editor_attr.win.px = 0; | |
559 data->editor_data.editor_attr.win.py = Mmi_layout_line(3); //30 | |
560 data->editor_data.editor_attr.win.sx = SCREEN_SIZE_X; | |
561 data->editor_data.editor_attr.win.sy = numberLineHeight()+2; | |
562 | |
563 data->editor_data.Callback = (T_EDIT_CB)calcGetOperandCB; | |
564 data->input_number_win = editor_start(win, &(data->editor_data)); /* start the editor */ | |
565 #endif /* NEW_EDITOR */ | |
566 | |
567 winShow(data->win); | |
568 | |
569 /* Marcus: Issue 1039: 05/09/2002: Start */ | |
570 if (data->menu_options_win != NULL) | |
571 { | |
572 bookMenuDestroy( data->menu_options_win ); | |
573 data->menu_options_win = NULL; | |
574 } | |
575 /* Marcus: Issue 1039: 05/09/2002: End */ | |
576 } | |
577 break; | |
578 | |
579 //when "Equals" selected from calc menu | |
580 case CALC_DISPLAY_RESULT: | |
581 { | |
582 //if running total out of display range, set it to 0 | |
583 if ((calcGetRunningTotal() > MAX_CALC_TOTAL) || (calcGetRunningTotal() < MIN_CALC_TOTAL)) | |
584 running_total =0; | |
585 //Convert running total double to string | |
586 //if integer total, don't display any decimal places | |
587 if ( (long)calcGetRunningTotal() == calcGetRunningTotal()) | |
588 sprintf(data->buffer, "%d", (long) calcGetRunningTotal()); | |
589 else //if a floating-point total, display as many decimal places as will fit | |
590 sprintf(data->buffer, "%f", (double) calcGetRunningTotal()); | |
591 //if last number in display is a decimal point | |
592 if (data->buffer[8] == '.') | |
593 data->buffer[8] = '\0';//remove it | |
594 data->buffer[9] = '\0'; //ensure string is properly terminated | |
595 //ensure string is no longer than 9 chars | |
596 | |
597 calcSetEditor(win); | |
598 | |
599 /* SPR#1428 - SH - New Editor changes */ | |
600 #ifdef NEW_EDITOR | |
601 AUI_edit_SetEvents(&data->editor_data, 0, TRUE, FOREVER, (T_AUI_EDIT_CB)calcGetNumberCB); | |
602 AUI_calc_Start(win, &data->editor_data); | |
603 #else /* NEW_EDITOR */ | |
604 data->editor_data.Callback = (T_EDIT_CB)calcGetNumberCB; | |
605 editor_start(win, &(data->editor_data)); /* start the editor */ | |
606 #endif /* NEW_EDITOR */ | |
607 | |
608 /* Marcus: Issue 1039: 05/09/2002: Start */ | |
609 if (data->menu_options_win != NULL) | |
610 { | |
611 bookMenuDestroy( data->menu_options_win ); | |
612 data->menu_options_win = NULL; | |
613 } | |
614 /* Marcus: Issue 1039: 05/09/2002: End */ | |
615 | |
616 winShow(data->win); | |
617 } | |
618 break; | |
619 default: | |
620 { | |
621 TRACE_EVENT("calc_DialogCB(): Unknown Event"); | |
622 } | |
623 break; | |
624 | |
625 } | |
626 | |
627 | |
628 } | |
629 | |
630 /******************************************************************************* | |
631 | |
632 $Function: calcGetNumberCB | |
633 | |
634 $Description: Callback function for the editor window | |
635 | |
636 $Returns: nothing | |
637 | |
638 $Arguments: Window, identifier (not used), reason (not used) | |
639 | |
640 *******************************************************************************/ | |
641 static void calcGetNumberCB( T_MFW_HND win, USHORT Identifier, SHORT reason) | |
642 { | |
643 T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data; | |
644 tCalcData *data = (tCalcData *) win_data->user; | |
645 float after_decimal = 0; | |
646 int digits_after_point = 0; | |
647 int i; | |
648 char* end; | |
649 // char debug[40]; // RAVI | |
650 | |
651 | |
652 TRACE_FUNCTION("calcGetNumberCB()"); | |
653 | |
654 switch (reason ) | |
655 { | |
656 case INFO_KCD_LEFT: | |
657 { TRACE_EVENT("Left button pressed in calculator"); | |
658 //get the number entered before the decimal point | |
659 running_total = strtol(data->buffer, &end, 10); | |
660 if (strlen(end) != 0) | |
661 { //if decimal point entered | |
662 if ((end[0] == '.') && isdigit(end[1]))//get number after decimal point | |
663 { | |
664 end++; | |
665 digits_after_point = strlen(end); | |
666 after_decimal = strtol(end, &end, 10); | |
667 } | |
668 | |
669 //convert number after decimal point to it's actual fractional value | |
670 for (i=0; i < digits_after_point; i++) | |
671 after_decimal = after_decimal/10; | |
672 //add whole number and fraction together | |
673 running_total = running_total + after_decimal; | |
674 } | |
675 if (data->menu_options_win != NULL) | |
676 bookMenuDestroy( data->menu_options_win ); | |
677 //start the calculator option menu and kill this window | |
678 data->menu_options_win = bookMenuStart( data->win, calcOptionMenuAttributes(),0); | |
679 SEND_EVENT(data->menu_options_win, ADD_CALLBACK, NULL, (void *)calc_menu_cb); | |
680 | |
681 } | |
682 break; | |
683 | |
684 case INFO_KCD_HUP: | |
685 case INFO_KCD_RIGHT: | |
686 { | |
687 TRACE_EVENT("Right button pressed in calculator"); | |
688 calc_destroy(win); | |
689 } | |
690 break; | |
691 | |
692 default: | |
693 { | |
694 /* otherwise no action to be performed | |
695 */ | |
696 /*calc_destroy(win); */ /*SH - do not destroy calc for other key */ | |
697 break; | |
698 } | |
699 } | |
700 } | |
701 | |
702 | |
703 /******************************************************************************* | |
704 | |
705 $Function: calcGetOperandCB | |
706 | |
707 $Description: Callback function for the editor window, when second number in operation | |
708 is entered. | |
709 | |
710 $Returns: nothing | |
711 | |
712 $Arguments: Window, identifier (not used), reason (not used) | |
713 | |
714 *******************************************************************************/ | |
715 | |
716 static void calcGetOperandCB( T_MFW_HND win, USHORT Identifier, SHORT reason) | |
717 { | |
718 T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data; | |
719 tCalcData *data = (tCalcData *) win_data->user; | |
720 // char* buffer; // RAVI | |
721 float operand = 0; | |
722 float after_decimal = 0; | |
723 int digits_after_point = 0; | |
724 int i; | |
725 char* end; | |
726 char debug[40]; | |
727 | |
728 TRACE_FUNCTION("calcGetOperandCB()"); | |
729 TRACE_EVENT_P2("ID, reason: %d, %d", Identifier, reason); | |
730 | |
731 switch (reason ) | |
732 { | |
733 case INFO_KCD_LEFT: | |
734 /* SPR#1428 - SH - New Editor: Can use '*' or centre button as 'equals', to show result */ | |
735 #ifdef NEW_EDITOR | |
736 #ifdef COLOURDISPLAY | |
737 case INFO_KCD_SELECT: | |
738 #endif /* COLOURDISPLAY */ | |
739 case INFO_KCD_STAR: | |
740 #endif /* NEW_EDITOR */ | |
741 { //Get whole number before decimal point | |
742 operand = strtol(data->buffer, &end, 10); | |
743 | |
744 //if buffer not pointing at an empty string now | |
745 if (strlen(end) != 0) | |
746 { //if decimal point entered | |
747 if ((end[0] == '.') && isdigit(end[1]))//get number after decimal point | |
748 { | |
749 end++; | |
750 digits_after_point = strlen(end); | |
751 after_decimal = strtol(end, &end, 10); | |
752 sprintf(debug,"Digits after decimal: %f.", after_decimal); | |
753 } | |
754 //convert number after decimal point to an appropriate fraction | |
755 for (i=0; i < digits_after_point; i++) | |
756 after_decimal = after_decimal/10; | |
757 //add whole and fraction together | |
758 operand = operand + after_decimal; | |
759 } | |
760 | |
761 //perform the arithmetic function requested | |
762 switch (data->operation) | |
763 { | |
764 case PLUS: running_total = running_total + operand; break; | |
765 case MINUS: running_total = running_total - operand;break; | |
766 case MULTIPLY: running_total = running_total * operand;break; | |
767 case DIVIDE: | |
768 // Oct 20, 2004 REF: CRR 25755 xnkulkar | |
769 // if the attempted division is by zero | |
770 if(operand == 0) | |
771 { | |
772 divideByZero = TRUE; // enable the flag | |
773 } | |
774 else // else perform the division operation | |
775 { | |
776 running_total = running_total / operand; | |
777 } | |
778 break; | |
779 default: TRACE_EVENT("Unknown calc operation"); break; | |
780 } | |
781 | |
782 /* SPR#1428 - SH - New Editor: Can use '*' as 'equals', to show result */ | |
783 #ifdef NEW_EDITOR | |
784 #ifdef COLOURDISPLAY | |
785 if (reason==INFO_KCD_STAR || reason==INFO_KCD_SELECT) | |
786 #else /* COLOURDISPLAY */ | |
787 if (reason==INFO_KCD_STAR) | |
788 #endif /* COLOURDISPLAY */ | |
789 { | |
790 TRACE_EVENT("Star key - show result"); | |
791 /* Star didn't destroy window automatically, do it here */ | |
792 if (data->menu_options_win != NULL) | |
793 { | |
794 bookMenuDestroy( data->menu_options_win ); | |
795 data->menu_options_win = NULL; | |
796 } | |
797 if (data->input_number_win) | |
798 { | |
799 AUI_calc_Destroy(data->input_number_win); | |
800 data->input_number_win = NULL; | |
801 } | |
802 SEND_EVENT(data->win, CALC_DISPLAY_RESULT, 0, 0); | |
803 } | |
804 else | |
805 #endif /* NEW_EDITOR */ | |
806 { | |
807 //Show option menu | |
808 if (data->menu_options_win != NULL) | |
809 bookMenuDestroy( data->menu_options_win ); | |
810 data->menu_options_win = bookMenuStart( data->win, calcOptionMenuAttributes(),0); | |
811 } | |
812 } | |
813 break; | |
814 | |
815 case INFO_KCD_HUP: | |
816 case INFO_KCD_RIGHT: | |
817 { | |
818 TRACE_EVENT("Right button pressed in calculator"); | |
819 | |
820 calc_destroy(win); | |
821 } | |
822 break; | |
823 | |
824 default: | |
825 { | |
826 /* otherwise no action to be performed | |
827 */ | |
828 break; | |
829 } | |
830 } | |
831 } | |
832 | |
833 | |
834 static void calc_menu_cb(T_MFW_HND parent_win, UBYTE identifier, UBYTE reason) | |
835 { | |
836 T_MFW_WIN *win_data = ( (T_MFW_HDR *) parent_win )->data; | |
837 tCalcData* data = (tCalcData *) win_data->user; | |
838 | |
839 TRACE_FUNCTION("calc_menu_cb()"); | |
840 //set menu window to NULL to prevent any dealloc problems | |
841 data->menu_options_win = NULL; | |
842 calc_destroy(parent_win); | |
843 | |
844 | |
845 } | |
846 | |
847 /******************************************************************************* | |
848 | |
849 $Function: calcSetEditor | |
850 | |
851 $Description: Sets the editor attributes to defaults for the calculator module | |
852 | |
853 $Returns: nothing | |
854 | |
855 $Arguments: Window | |
856 | |
857 *******************************************************************************/ | |
858 void calcSetEditor(T_MFW_HND win) | |
859 { | |
860 T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data; | |
861 tCalcData* data = (tCalcData *) win_data->user; | |
862 | |
863 TRACE_FUNCTION("calcSetEditor()"); | |
864 | |
865 /* SPR#1428 - SH - New Editor changes */ | |
866 #ifdef NEW_EDITOR | |
867 { | |
868 AUI_edit_SetDefault(&data->editor_data); | |
869 AUI_edit_SetDisplay(&data->editor_data, ZONE_FULL_SK_TITLE, COLOUR_EDITOR, EDITOR_FONT); | |
870 AUI_edit_SetBuffer(&data->editor_data, ATB_DCS_ASCII, (UBYTE *)data->buffer, 10); | |
871 AUI_edit_SetMode(&data->editor_data, 0, ED_CURSOR_NONE); | |
872 AUI_edit_SetEvents(&data->editor_data, 0, TRUE, FOREVER, NULL); | |
873 AUI_edit_SetTextStr(&data->editor_data, TxtSoftOptions, TxtDelete, TxtCalculator, NULL); | |
874 //xrashmic 20 Oct, 2005 MMI-SPR-33845 | |
875 //Editor always starts with min one character "0" and | |
876 //alterRight softkey is set to "BACK" here. | |
877 data->editor_data.min_enter=1; | |
878 data->editor_data.AltRightSoftKey=TxtSoftBack ; | |
879 AUI_edit_SetFormatAttr(&data->editor_data, DS_ALIGN_RIGHT); | |
880 } | |
881 #else /* NEW_EDITOR */ | |
882 editor_attr_init(&((data->editor_data).editor_attr), 0, edtCurBar1, 0, data->buffer, 10, COLOUR_EDITOR); | |
883 editor_data_init( &data->editor_data, NULL, TxtSoftOptions, TxtDelete, NULL, 1, CALC_MODE, FOREVER); | |
884 data->editor_data.hide = FALSE; | |
885 data->editor_data.Identifier = 0xFFFF ; | |
886 data->editor_data.destroyEditor = TRUE; | |
887 #endif /* NEW_EDITOR */ | |
888 | |
889 return; | |
890 } | |
891 | |
892 /******************************************************************************* | |
893 | |
894 $Function: calc_destroy | |
895 | |
896 $Description: Destroys the calculator editor window and frees up memory | |
897 | |
898 $Returns: nothing | |
899 | |
900 $Arguments: Window | |
901 | |
902 *******************************************************************************/ | |
903 void calc_destroy(MfwHnd own_window) | |
904 { | |
905 T_MFW_WIN * win_data; | |
906 tCalcData * data = NULL; | |
907 | |
908 TRACE_EVENT ("calc_destroy()"); | |
909 if (own_window) | |
910 { | |
911 | |
912 win_data = ((T_MFW_HDR *)own_window)->data; | |
913 if (win_data != NULL) //PATCH TB | |
914 data = (tCalcData *)win_data->user; | |
915 | |
916 if (data) | |
917 { | |
918 | |
919 win_delete (data->win); | |
920 /* Marcus: Issue 1039: 05/09/2002: Start */ | |
921 if (data->menu_options_win != NULL) | |
922 { | |
923 bookMenuDestroy( data->menu_options_win ); | |
924 data->menu_options_win = NULL; | |
925 } | |
926 /* Marcus: Issue 1039: 05/09/2002: End */ | |
927 // Free Memory | |
928 FREE_MEMORY ((void *)data, sizeof (tCalcData)); | |
929 | |
930 } | |
931 else | |
932 { | |
933 TRACE_EVENT ("calc_destroy() called twice"); | |
934 } | |
935 } | |
936 } | |
937 | |
938 | |
939 | |
940 |