comparison src/ui/bmi/mmiCalculatorMain.c @ 92:c0052fe355d3

src/ui/bmi/*.[ch]: rm trailing white space
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 08 Nov 2020 06:39:16 +0000
parents 67bfe9f274f6
children f1f29e85f92b
comparison
equal deleted inserted replaced
91:c3d28a37caad 92:c0052fe355d3
1 /******************************************************************************* 1 /*******************************************************************************
2 2
3 CONDAT (UK) 3 CONDAT (UK)
4 4
5 ******************************************************************************** 5 ********************************************************************************
6 6
7 This software product is the property of Condat (UK) Ltd and may not be 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. 8 disclosed to any third party without the express permission of the owner.
9 9
10 ******************************************************************************** 10 ********************************************************************************
11 11
12 $Project name: Basic MMI 12 $Project name: Basic MMI
13 $Project code: BMI (6349) 13 $Project code: BMI (6349)
14 $Module: Calculator 14 $Module: Calculator
15 $File: MmiCalculatorMain.c 15 $File: MmiCalculatorMain.c
16 $Revision: 1.0 16 $Revision: 1.0
17 17
18 $Author: Condat(UK) 18 $Author: Condat(UK)
19 $Date: 25/10/00 19 $Date: 25/10/00
20 20
21 ******************************************************************************** 21 ********************************************************************************
22 22
23 Description 23 Description
24 24
25 This provides the main calculator functionality 25 This provides the main calculator functionality
26 26
27 27
28 ******************************************************************************** 28 ********************************************************************************
29 $History: MmiCalculatorMain.c 29 $History: MmiCalculatorMain.c
30 30
31 25/10/00 Original Condat(UK) BMI version. 31 25/10/00 Original Condat(UK) BMI version.
32 32
33 xrashmic 20 Oct, 2005 MMI-SPR-33845 33 xrashmic 20 Oct, 2005 MMI-SPR-33845
34 To display BACK softkey when no more character are left in the calulator editor 34 To display BACK softkey when no more character are left in the calulator editor
35 35
36 Oct 20, 2004 REF: CRR 25755 xnkulkar 36 Oct 20, 2004 REF: CRR 25755 xnkulkar
37 Description: calculator -divide by zero operation is allowed. 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 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. 39 division. Also, show the editor again so that user can enter a number other than 0.
40 40
41 $End 41 $End
42 42
43 *******************************************************************************/ 43 *******************************************************************************/
44 #define MAX_CALC_TOTAL 999999999 44 #define MAX_CALC_TOTAL 999999999
45 #define MIN_CALC_TOTAL -99999999 45 #define MIN_CALC_TOTAL -99999999
46 46
47 /****************************************************************************** 47 /******************************************************************************
48 48
49 Include Files 49 Include Files
50 50
51 *******************************************************************************/ 51 *******************************************************************************/
52 #define ENTITY_MFW 52 #define ENTITY_MFW
53 53
54 /* includes */ 54 /* includes */
55 #include <string.h> 55 #include <string.h>
129 129
130 #include "pcm.h" 130 #include "pcm.h"
131 131
132 132
133 /******************************************************************************* 133 /*******************************************************************************
134 134
135 Function Prototypes 135 Function Prototypes
136 136
137 *******************************************************************************/ 137 *******************************************************************************/
138 static T_MFW_HND calc_create(MfwHnd parent_window); 138 static T_MFW_HND calc_create(MfwHnd parent_window);
139 void calc_destroy(MfwHnd own_window); 139 void calc_destroy(MfwHnd own_window);
140 static void calcGetNumberCB( T_MFW_HND win, USHORT Identifier, SHORT reason ); 140 static void calcGetNumberCB( T_MFW_HND win, USHORT Identifier, SHORT reason );
141 static void calcGetOperandCB( T_MFW_HND win, USHORT Identifier, SHORT reason ); 141 static void calcGetOperandCB( T_MFW_HND win, USHORT Identifier, SHORT reason );
143 T_MFW_HND calc_start(T_MFW_HND parent_window); 143 T_MFW_HND calc_start(T_MFW_HND parent_window);
144 double calcGetRunningTotal(void); 144 double calcGetRunningTotal(void);
145 char operatorSymbol(UBYTE operator); 145 char operatorSymbol(UBYTE operator);
146 static void calc_menu_cb(T_MFW_HND parent_win, UBYTE identifier, UBYTE reason); 146 static void calc_menu_cb(T_MFW_HND parent_win, UBYTE identifier, UBYTE reason);
147 /******************************************************************************* 147 /*******************************************************************************
148 148
149 Static Global Variable(s) 149 Static Global Variable(s)
150 150
151 *******************************************************************************/ 151 *******************************************************************************/
152 152
153 static double running_total; 153 static double running_total;
154 154
155 static T_MFW_HND calculator_win = NULL; 155 static T_MFW_HND calculator_win = NULL;
156 156
157 157
158 // Oct 20, 2004 REF: CRR 25755 xnkulkar 158 // Oct 20, 2004 REF: CRR 25755 xnkulkar
159 // Added this flag to detect 'divide by zero' operation 159 // Added this flag to detect 'divide by zero' operation
160 BOOL divideByZero = FALSE; 160 BOOL divideByZero = FALSE;
161 161
162 /******************************************************************************* 162 /*******************************************************************************
163 163
164 Public Functions 164 Public Functions
165 165
166 *******************************************************************************/ 166 *******************************************************************************/
167 /******************************************************************************* 167 /*******************************************************************************
168 168
169 $Function: calculator 169 $Function: calculator
170 170
171 $Description: Starts the calculator function on user selection 171 $Description: Starts the calculator function on user selection
172 172
173 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise 173 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise
174 MFW_EVENT_PASSED 174 MFW_EVENT_PASSED
175 175
176 $Arguments: menu, menu item 176 $Arguments: menu, menu item
177 177
178 *******************************************************************************/ 178 *******************************************************************************/
179 int calculator(MfwMnu* m, MfwMnuItem* i) 179 int calculator(MfwMnu* m, MfwMnuItem* i)
180 { 180 {
181 T_MFW_HND parent = mfwParent( mfw_header()); 181 T_MFW_HND parent = mfwParent( mfw_header());
182 TRACE_FUNCTION("calculator()"); 182 TRACE_FUNCTION("calculator()");
187 /******************************************************************************* 187 /*******************************************************************************
188 188
189 $Function: calcPlus 189 $Function: calcPlus
190 190
191 $Description: Handles the selction of the "Plus" option in the calculator menu 191 $Description: Handles the selction of the "Plus" option in the calculator menu
192 192
193 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise 193 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise
194 MFW_EVENT_PASSED 194 MFW_EVENT_PASSED
195 195
196 $Arguments: menu, menu item 196 $Arguments: menu, menu item
197 197
198 *******************************************************************************/ 198 *******************************************************************************/
199 int calcPlus(MfwMnu* m, MfwMnuItem* i) 199 int calcPlus(MfwMnu* m, MfwMnuItem* i)
200 { 200 {
201 T_MFW_WIN* win_data; 201 T_MFW_WIN* win_data;
202 tCalcData* data; 202 tCalcData* data;
206 if (calculator_win NEQ NULL) 206 if (calculator_win NEQ NULL)
207 { win_data = ( (T_MFW_HDR *) calculator_win )->data; 207 { win_data = ( (T_MFW_HDR *) calculator_win )->data;
208 data = (tCalcData*)win_data->user; 208 data = (tCalcData*)win_data->user;
209 data->operation = PLUS;//set the arithmetic operation 209 data->operation = PLUS;//set the arithmetic operation
210 SEND_EVENT (calculator_win, CALC_ENTER_OPERAND, 0, 0); 210 SEND_EVENT (calculator_win, CALC_ENTER_OPERAND, 0, 0);
211 } 211 }
212 return MFW_EVENT_CONSUMED; 212 return MFW_EVENT_CONSUMED;
213 } 213 }
214 214
215 /******************************************************************************* 215 /*******************************************************************************
216 216
217 $Function: calcMinus 217 $Function: calcMinus
218 218
219 $Description: Handles the selection of the "Minus" option in the calculator menu 219 $Description: Handles the selection of the "Minus" option in the calculator menu
220 220
221 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise 221 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise
222 MFW_EVENT_PASSED 222 MFW_EVENT_PASSED
223 223
224 $Arguments: menu, menu item 224 $Arguments: menu, menu item
225 225
226 *******************************************************************************/ 226 *******************************************************************************/
227 int calcMinus(MfwMnu* m, MfwMnuItem* i) 227 int calcMinus(MfwMnu* m, MfwMnuItem* i)
228 { 228 {
229 T_MFW_WIN* win_data; 229 T_MFW_WIN* win_data;
230 tCalcData* data; 230 tCalcData* data;
234 if (calculator_win NEQ NULL) 234 if (calculator_win NEQ NULL)
235 { win_data = ( (T_MFW_HDR *) calculator_win )->data; 235 { win_data = ( (T_MFW_HDR *) calculator_win )->data;
236 data = (tCalcData*)win_data->user; 236 data = (tCalcData*)win_data->user;
237 data->operation = MINUS;//set the arithmetic operation 237 data->operation = MINUS;//set the arithmetic operation
238 SEND_EVENT (calculator_win, CALC_ENTER_OPERAND, 0, 0); 238 SEND_EVENT (calculator_win, CALC_ENTER_OPERAND, 0, 0);
239 } 239 }
240 return MFW_EVENT_CONSUMED; 240 return MFW_EVENT_CONSUMED;
241 } 241 }
242 242
243 /******************************************************************************* 243 /*******************************************************************************
244 244
245 $Function: calcDivide 245 $Function: calcDivide
246 246
247 $Description: Handles the selection of the "Divide" option in the calculator menu 247 $Description: Handles the selection of the "Divide" option in the calculator menu
248 248
249 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise 249 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise
250 MFW_EVENT_PASSED 250 MFW_EVENT_PASSED
251 251
252 $Arguments: menu, menu item 252 $Arguments: menu, menu item
253 253
254 *******************************************************************************/ 254 *******************************************************************************/
255 int calcDivide(MfwMnu* m, MfwMnuItem* i) 255 int calcDivide(MfwMnu* m, MfwMnuItem* i)
256 { 256 {
257 T_MFW_WIN* win_data; 257 T_MFW_WIN* win_data;
258 tCalcData* data; 258 tCalcData* data;
262 if (calculator_win NEQ NULL) 262 if (calculator_win NEQ NULL)
263 { win_data = ( (T_MFW_HDR *) calculator_win )->data; 263 { win_data = ( (T_MFW_HDR *) calculator_win )->data;
264 data = (tCalcData*)win_data->user; 264 data = (tCalcData*)win_data->user;
265 data->operation = DIVIDE;//set the arithmetic operation 265 data->operation = DIVIDE;//set the arithmetic operation
266 SEND_EVENT (calculator_win, CALC_ENTER_OPERAND, 0, 0); 266 SEND_EVENT (calculator_win, CALC_ENTER_OPERAND, 0, 0);
267 } 267 }
268 return MFW_EVENT_CONSUMED; 268 return MFW_EVENT_CONSUMED;
269 } 269 }
270 /******************************************************************************* 270 /*******************************************************************************
271 271
272 $Function: calcMultiply 272 $Function: calcMultiply
273 273
274 $Description: Handles the selection of the "Multiply" option in the calculator menu 274 $Description: Handles the selection of the "Multiply" option in the calculator menu
275 275
276 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise 276 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise
277 MFW_EVENT_PASSED 277 MFW_EVENT_PASSED
278 278
279 $Arguments: menu, menu item 279 $Arguments: menu, menu item
280 280
281 *******************************************************************************/ 281 *******************************************************************************/
282 int calcMultiply(MfwMnu* m, MfwMnuItem* i) 282 int calcMultiply(MfwMnu* m, MfwMnuItem* i)
283 { 283 {
284 T_MFW_WIN* win_data; 284 T_MFW_WIN* win_data;
285 tCalcData* data; 285 tCalcData* data;
289 if (calculator_win NEQ NULL) 289 if (calculator_win NEQ NULL)
290 { win_data = ( (T_MFW_HDR *) calculator_win )->data; 290 { win_data = ( (T_MFW_HDR *) calculator_win )->data;
291 data = (tCalcData*)win_data->user; 291 data = (tCalcData*)win_data->user;
292 data->operation = MULTIPLY;//set the arithmetic operation 292 data->operation = MULTIPLY;//set the arithmetic operation
293 SEND_EVENT (calculator_win, CALC_ENTER_OPERAND, 0, 0); 293 SEND_EVENT (calculator_win, CALC_ENTER_OPERAND, 0, 0);
294 } 294 }
295 return MFW_EVENT_CONSUMED; 295 return MFW_EVENT_CONSUMED;
296 } 296 }
297 297
298 // Oct 20, 2004 REF: CRR 25755 xnkulkar 298 // Oct 20, 2004 REF: CRR 25755 xnkulkar
299 /******************************************************************************* 299 /*******************************************************************************
300 300
301 $Function: info_screen_cb 301 $Function: info_screen_cb
302 302
303 $Description: Callback function for info screen 303 $Description: Callback function for info screen
304 304
305 $Returns: nothing 305 $Returns: nothing
306 306
307 $Arguments: Parent Window handle, identifier and reason 307 $Arguments: Parent Window handle, identifier and reason
308 308
309 *******************************************************************************/ 309 *******************************************************************************/
310 310
311 static void info_screen_cb(T_MFW_HND parent_win, UBYTE identifier, UBYTE reason) 311 static void info_screen_cb(T_MFW_HND parent_win, UBYTE identifier, UBYTE reason)
312 { 312 {
313 // Send CALC_ENTER_OPERAND event tp prompt the user to enter the operand again 313 // Send CALC_ENTER_OPERAND event tp prompt the user to enter the operand again
317 /******************************************************************************* 317 /*******************************************************************************
318 318
319 $Function: calcEquals 319 $Function: calcEquals
320 320
321 $Description: Handles the selection of the "Equals" option in the calculator menu 321 $Description: Handles the selection of the "Equals" option in the calculator menu
322 322
323 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise 323 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise
324 MFW_EVENT_PASSED 324 MFW_EVENT_PASSED
325 325
326 $Arguments: menu, menu item 326 $Arguments: menu, menu item
327 327
328 *******************************************************************************/ 328 *******************************************************************************/
329 int calcEquals(MfwMnu* m, MfwMnuItem* i) 329 int calcEquals(MfwMnu* m, MfwMnuItem* i)
330 { 330 {
331 TRACE_FUNCTION("calcEquals()"); 331 TRACE_FUNCTION("calcEquals()");
332 332
333 // Oct 20, 2004 REF: CRR 25755 xnkulkar 333 // Oct 20, 2004 REF: CRR 25755 xnkulkar
334 // if 'divide by zero' operation is attempted 334 // if 'divide by zero' operation is attempted
335 if(divideByZero == TRUE) 335 if(divideByZero == TRUE)
336 { 336 {
337 divideByZero = FALSE; // disable the flag 337 divideByZero = FALSE; // disable the flag
338 info_screen(0, TxtNotAllowed, TxtNull,(T_VOID_FUNC) info_screen_cb); // display "Not Allowed" message 338 info_screen(0, TxtNotAllowed, TxtNull,(T_VOID_FUNC) info_screen_cb); // display "Not Allowed" message
339 return MFW_EVENT_CONSUMED; // consume the event 339 return MFW_EVENT_CONSUMED; // consume the event
340 } 340 }
341 341
342 if (calculator_win NEQ NULL) 342 if (calculator_win NEQ NULL)
343 { 343 {
344 SEND_EVENT (calculator_win, CALC_DISPLAY_RESULT, 0, 0); 344 SEND_EVENT (calculator_win, CALC_DISPLAY_RESULT, 0, 0);
345 } 345 }
346 346
347 return MFW_EVENT_CONSUMED; 347 return MFW_EVENT_CONSUMED;
348 } 348 }
349 349
350 /******************************************************************************* 350 /*******************************************************************************
351 351
352 Private Functions 352 Private Functions
353 353
354 *******************************************************************************/ 354 *******************************************************************************/
355 /******************************************************************************* 355 /*******************************************************************************
356 356
357 $Function: calcGetRunningTotal 357 $Function: calcGetRunningTotal
358 358
359 $Description: If the calculator's running total value ever needs to be accessed by 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 360 code in another file, then this function ought to be made public to prevent
361 to allow safe access; 361 to allow safe access;
362 362
363 $Returns: Calculator's running total (double) 363 $Returns: Calculator's running total (double)
364 364
365 $Arguments: none 365 $Arguments: none
366 366
367 *******************************************************************************/ 367 *******************************************************************************/
368 double calcGetRunningTotal(void) 368 double calcGetRunningTotal(void)
369 { 369 {
370 TRACE_FUNCTION("calcGetRunningTotal()"); 370 TRACE_FUNCTION("calcGetRunningTotal()");
371 return running_total; 371 return running_total;
373 373
374 /******************************************************************************* 374 /*******************************************************************************
375 375
376 $Function: operatorSymbol 376 $Function: operatorSymbol
377 377
378 $Description: returns character corresponding to arithmetic operation 378 $Description: returns character corresponding to arithmetic operation
379 379
380 $Returns: Operator character 380 $Returns: Operator character
381 381
382 $Arguments: Operator enum 382 $Arguments: Operator enum
383 383
384 *******************************************************************************/ 384 *******************************************************************************/
385 char operatorSymbol(UBYTE operator) 385 char operatorSymbol(UBYTE operator)
386 { 386 {
387 TRACE_FUNCTION("operatorSymbol()"); 387 TRACE_FUNCTION("operatorSymbol()");
388 switch (operator) 388 switch (operator)
391 case (MINUS): return '-'; // break; // RAVI 391 case (MINUS): return '-'; // break; // RAVI
392 case (MULTIPLY): return '*'; // break; // RAVI 392 case (MULTIPLY): return '*'; // break; // RAVI
393 case (DIVIDE): return '/'; // break; // RAVI 393 case (DIVIDE): return '/'; // break; // RAVI
394 default: return '\0'; // break; // RAVI 394 default: return '\0'; // break; // RAVI
395 } 395 }
396 396
397 } 397 }
398 398
399 399
400 /******************************************************************************* 400 /*******************************************************************************
401 401
402 $Function: calc_start 402 $Function: calc_start
403 403
404 $Description: Creates the calculator window and calls for it to be initialised 404 $Description: Creates the calculator window and calls for it to be initialised
405 405
406 $Returns: Window 406 $Returns: Window
407 407
408 $Arguments: Parent Window 408 $Arguments: Parent Window
409 409
410 *******************************************************************************/ 410 *******************************************************************************/
411 411
412 T_MFW_HND calc_start(T_MFW_HND parent_window) 412 T_MFW_HND calc_start(T_MFW_HND parent_window)
413 { 413 {
414 T_MFW_HND win = calc_create(parent_window); 414 T_MFW_HND win = calc_create(parent_window);
415 TRACE_FUNCTION("calc_start()"); 415 TRACE_FUNCTION("calc_start()");
416 if (win NEQ NULL) 416 if (win NEQ NULL)
417 { 417 {
418 SEND_EVENT (win, CALC_INIT, 0, 0); 418 SEND_EVENT (win, CALC_INIT, 0, 0);
419 } 419 }
420 420
421 return win; 421 return win;
422 } 422 }
423 423
424 /******************************************************************************* 424 /*******************************************************************************
425 425
426 $Function: calc_create 426 $Function: calc_create
427 427
428 $Description: Creates the calculator window and connect the dialog data to it 428 $Description: Creates the calculator window and connect the dialog data to it
429 429
430 $Returns: Window 430 $Returns: Window
431 431
432 $Arguments: Parent Window 432 $Arguments: Parent Window
433 433
434 *******************************************************************************/ 434 *******************************************************************************/
435 static T_MFW_HND calc_create(MfwHnd parent_window) 435 static T_MFW_HND calc_create(MfwHnd parent_window)
436 { 436 {
437 tCalcData * data = (tCalcData *)ALLOC_MEMORY (sizeof (tCalcData )); 437 tCalcData * data = (tCalcData *)ALLOC_MEMORY (sizeof (tCalcData ));
438 T_MFW_WIN * win; 438 T_MFW_WIN * win;
439 439
445 445
446 // Create window handler 446 // Create window handler
447 data->win = win_create (parent_window, 0, E_WIN_VISIBLE, NULL); 447 data->win = win_create (parent_window, 0, E_WIN_VISIBLE, NULL);
448 if (data->win EQ NULL) 448 if (data->win EQ NULL)
449 { 449 {
450 450
451 return NULL; 451 return NULL;
452 } 452 }
453 // connect the dialog data to the MFW-window 453 // connect the dialog data to the MFW-window
454 data->mmi_control.dialog = (T_DIALOG_FUNC)calc_DialogCB; 454 data->mmi_control.dialog = (T_DIALOG_FUNC)calc_DialogCB;
455 data->mmi_control.data = data; 455 data->mmi_control.data = data;
463 /******************************************************************************* 463 /*******************************************************************************
464 464
465 $Function: calc_DialogCB 465 $Function: calc_DialogCB
466 466
467 $Description: Callback function for the calculator window 467 $Description: Callback function for the calculator window
468 468
469 $Returns: nothing 469 $Returns: nothing
470 470
471 $Arguments: Window, event, identifier (not used), parameter (not used) 471 $Arguments: Window, event, identifier (not used), parameter (not used)
472 472
473 *******************************************************************************/ 473 *******************************************************************************/
474 static void calc_DialogCB(T_MFW_HND win, USHORT e, SHORT identifier, void *parameter) 474 static void calc_DialogCB(T_MFW_HND win, USHORT e, SHORT identifier, void *parameter)
475 { 475 {
476 T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data; 476 T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data;
477 tCalcData* data = (tCalcData *) win_data->user; 477 tCalcData* data = (tCalcData *) win_data->user;
478 char display_buffer[28] = ""; 478 char display_buffer[28] = "";
479 #ifdef NEW_EDITOR 479 #ifdef NEW_EDITOR
480 // T_AUI_EDITOR_DATA editor_data; /* SPR#1428 - SH - New Editor data */ // RAVI 480 // T_AUI_EDITOR_DATA editor_data; /* SPR#1428 - SH - New Editor data */ // RAVI
481 #else 481 #else
482 // T_EDITOR_DATA editor_data; // RAVI 482 // T_EDITOR_DATA editor_data; // RAVI
483 #endif 483 #endif
484 char* running_total_out; 484 char* running_total_out;
485 // char debug_buffer[50]; // RAVI 485 // char debug_buffer[50]; // RAVI
486 TRACE_FUNCTION("calc_DialogCB()"); 486 TRACE_FUNCTION("calc_DialogCB()");
487 487
488 switch( e ) 488 switch( e )
489 { //when window first created 489 { //when window first created
505 #ifdef NEW_EDITOR 505 #ifdef NEW_EDITOR
506 AUI_edit_SetEvents(&data->editor_data, 0, TRUE, FOREVER, (T_AUI_EDIT_CB)calcGetNumberCB); 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); 507 data->editor_win = AUI_calc_Start(win, &data->editor_data);
508 #else /* NEW_EDITOR */ 508 #else /* NEW_EDITOR */
509 data->editor_data.Callback = (T_EDIT_CB)calcGetNumberCB; 509 data->editor_data.Callback = (T_EDIT_CB)calcGetNumberCB;
510 data->editor_win = editor_start(win, &(data->editor_data)); /* start the editor */ 510 data->editor_win = editor_start(win, &(data->editor_data)); /* start the editor */
511 #endif /* NEW_EDITOR */ 511 #endif /* NEW_EDITOR */
512 winShow(data->win); 512 winShow(data->win);
513 } 513 }
514 break; 514 break;
515 515
516 //when an arithmetic operator has been selected from the calc menu 516 //when an arithmetic operator has been selected from the calc menu
517 case CALC_ENTER_OPERAND: 517 case CALC_ENTER_OPERAND:
518 { 518 {
519 TRACE_EVENT("CALC_ENTER_OPERAND"); 519 TRACE_EVENT("CALC_ENTER_OPERAND");
520 /* This memory alloc seems to fix a problem where running_total_out 520 /* This memory alloc seems to fix a problem where running_total_out
521 * would become an empty string after sevaral running calculations */ 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 */ 522 running_total_out = (char*)ALLOC_MEMORY(22*sizeof(char)); /* SH - change malloc to ALLOC_MEMORY */
523 523
524 running_total_out[0] = '\0'; 524 running_total_out[0] = '\0';
525 525
526 /* Display the first operand and the operator symbol 526 /* Display the first operand and the operator symbol
527 * above the operand to be entered */ 527 * above the operand to be entered */
528 if ( (long)calcGetRunningTotal() == calcGetRunningTotal()) 528 if ( (long)calcGetRunningTotal() == calcGetRunningTotal())
529 sprintf((char*)running_total_out, "%d", (long)calcGetRunningTotal()); 529 sprintf((char*)running_total_out, "%d", (long)calcGetRunningTotal());
530 else 530 else
532 532
533 if (running_total_out[8] == '.') 533 if (running_total_out[8] == '.')
534 running_total_out[8] = '\0'; 534 running_total_out[8] = '\0';
535 else 535 else
536 running_total_out[9] = '\0'; 536 running_total_out[9] = '\0';
537 537
538 sprintf((char*)display_buffer,"%s %c", running_total_out, operatorSymbol(data->operation)); 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 */ 539 FREE_MEMORY((void*)running_total_out, 22*sizeof(char)); /* SH - change free to FREE_MEMORY */
540 540
541 /* SPR#1428 - SH - Calc now starts off with '0' */ 541 /* SPR#1428 - SH - Calc now starts off with '0' */
542 #ifdef NEW_EDITOR 542 #ifdef NEW_EDITOR
557 data->editor_data.TextString = display_buffer; 557 data->editor_data.TextString = display_buffer;
558 data->editor_data.editor_attr.win.px = 0; 558 data->editor_data.editor_attr.win.px = 0;
559 data->editor_data.editor_attr.win.py = Mmi_layout_line(3); //30 559 data->editor_data.editor_attr.win.py = Mmi_layout_line(3); //30
560 data->editor_data.editor_attr.win.sx = SCREEN_SIZE_X; 560 data->editor_data.editor_attr.win.sx = SCREEN_SIZE_X;
561 data->editor_data.editor_attr.win.sy = numberLineHeight()+2; 561 data->editor_data.editor_attr.win.sy = numberLineHeight()+2;
562 562
563 data->editor_data.Callback = (T_EDIT_CB)calcGetOperandCB; 563 data->editor_data.Callback = (T_EDIT_CB)calcGetOperandCB;
564 data->input_number_win = editor_start(win, &(data->editor_data)); /* start the editor */ 564 data->input_number_win = editor_start(win, &(data->editor_data)); /* start the editor */
565 #endif /* NEW_EDITOR */ 565 #endif /* NEW_EDITOR */
566 566
567 winShow(data->win); 567 winShow(data->win);
568 568
569 /* Marcus: Issue 1039: 05/09/2002: Start */ 569 /* Marcus: Issue 1039: 05/09/2002: Start */
571 { 571 {
572 bookMenuDestroy( data->menu_options_win ); 572 bookMenuDestroy( data->menu_options_win );
573 data->menu_options_win = NULL; 573 data->menu_options_win = NULL;
574 } 574 }
575 /* Marcus: Issue 1039: 05/09/2002: End */ 575 /* Marcus: Issue 1039: 05/09/2002: End */
576 } 576 }
577 break; 577 break;
578 578
579 //when "Equals" selected from calc menu 579 //when "Equals" selected from calc menu
580 case CALC_DISPLAY_RESULT: 580 case CALC_DISPLAY_RESULT:
581 { 581 {
582 //if running total out of display range, set it to 0 582 //if running total out of display range, set it to 0
583 if ((calcGetRunningTotal() > MAX_CALC_TOTAL) || (calcGetRunningTotal() < MIN_CALC_TOTAL)) 583 if ((calcGetRunningTotal() > MAX_CALC_TOTAL) || (calcGetRunningTotal() < MIN_CALC_TOTAL))
584 running_total =0; 584 running_total =0;
585 //Convert running total double to string 585 //Convert running total double to string
586 //if integer total, don't display any decimal places 586 //if integer total, don't display any decimal places
587 if ( (long)calcGetRunningTotal() == calcGetRunningTotal()) 587 if ( (long)calcGetRunningTotal() == calcGetRunningTotal())
588 sprintf(data->buffer, "%d", (long) calcGetRunningTotal()); 588 sprintf(data->buffer, "%d", (long) calcGetRunningTotal());
589 else //if a floating-point total, display as many decimal places as will fit 589 else //if a floating-point total, display as many decimal places as will fit
590 sprintf(data->buffer, "%f", (double) calcGetRunningTotal()); 590 sprintf(data->buffer, "%f", (double) calcGetRunningTotal());
591 //if last number in display is a decimal point 591 //if last number in display is a decimal point
592 if (data->buffer[8] == '.') 592 if (data->buffer[8] == '.')
593 data->buffer[8] = '\0';//remove it 593 data->buffer[8] = '\0';//remove it
594 data->buffer[9] = '\0'; //ensure string is properly terminated 594 data->buffer[9] = '\0'; //ensure string is properly terminated
595 //ensure string is no longer than 9 chars 595 //ensure string is no longer than 9 chars
596 596
597 calcSetEditor(win); 597 calcSetEditor(win);
598 598
599 /* SPR#1428 - SH - New Editor changes */ 599 /* SPR#1428 - SH - New Editor changes */
600 #ifdef NEW_EDITOR 600 #ifdef NEW_EDITOR
601 AUI_edit_SetEvents(&data->editor_data, 0, TRUE, FOREVER, (T_AUI_EDIT_CB)calcGetNumberCB); 601 AUI_edit_SetEvents(&data->editor_data, 0, TRUE, FOREVER, (T_AUI_EDIT_CB)calcGetNumberCB);
602 AUI_calc_Start(win, &data->editor_data); 602 AUI_calc_Start(win, &data->editor_data);
603 #else /* NEW_EDITOR */ 603 #else /* NEW_EDITOR */
604 data->editor_data.Callback = (T_EDIT_CB)calcGetNumberCB; 604 data->editor_data.Callback = (T_EDIT_CB)calcGetNumberCB;
605 editor_start(win, &(data->editor_data)); /* start the editor */ 605 editor_start(win, &(data->editor_data)); /* start the editor */
606 #endif /* NEW_EDITOR */ 606 #endif /* NEW_EDITOR */
607 607
608 /* Marcus: Issue 1039: 05/09/2002: Start */ 608 /* Marcus: Issue 1039: 05/09/2002: Start */
609 if (data->menu_options_win != NULL) 609 if (data->menu_options_win != NULL)
610 { 610 {
621 TRACE_EVENT("calc_DialogCB(): Unknown Event"); 621 TRACE_EVENT("calc_DialogCB(): Unknown Event");
622 } 622 }
623 break; 623 break;
624 624
625 } 625 }
626 626
627 627
628 } 628 }
629 629
630 /******************************************************************************* 630 /*******************************************************************************
631 631
632 $Function: calcGetNumberCB 632 $Function: calcGetNumberCB
633 633
634 $Description: Callback function for the editor window 634 $Description: Callback function for the editor window
635 635
636 $Returns: nothing 636 $Returns: nothing
637 637
638 $Arguments: Window, identifier (not used), reason (not used) 638 $Arguments: Window, identifier (not used), reason (not used)
639 639
640 *******************************************************************************/ 640 *******************************************************************************/
641 static void calcGetNumberCB( T_MFW_HND win, USHORT Identifier, SHORT reason) 641 static void calcGetNumberCB( T_MFW_HND win, USHORT Identifier, SHORT reason)
642 { 642 {
643 T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data; 643 T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data;
644 tCalcData *data = (tCalcData *) win_data->user; 644 tCalcData *data = (tCalcData *) win_data->user;
645 float after_decimal = 0; 645 float after_decimal = 0;
646 int digits_after_point = 0; 646 int digits_after_point = 0;
647 int i; 647 int i;
648 char* end; 648 char* end;
649 // char debug[40]; // RAVI 649 // char debug[40]; // RAVI
650 650
651 651
652 TRACE_FUNCTION("calcGetNumberCB()"); 652 TRACE_FUNCTION("calcGetNumberCB()");
653 653
654 switch (reason ) 654 switch (reason )
655 { 655 {
656 case INFO_KCD_LEFT: 656 case INFO_KCD_LEFT:
658 //get the number entered before the decimal point 658 //get the number entered before the decimal point
659 running_total = strtol(data->buffer, &end, 10); 659 running_total = strtol(data->buffer, &end, 10);
660 if (strlen(end) != 0) 660 if (strlen(end) != 0)
661 { //if decimal point entered 661 { //if decimal point entered
662 if ((end[0] == '.') && isdigit(end[1]))//get number after decimal point 662 if ((end[0] == '.') && isdigit(end[1]))//get number after decimal point
663 { 663 {
664 end++; 664 end++;
665 digits_after_point = strlen(end); 665 digits_after_point = strlen(end);
666 after_decimal = strtol(end, &end, 10); 666 after_decimal = strtol(end, &end, 10);
667 } 667 }
668 668
675 if (data->menu_options_win != NULL) 675 if (data->menu_options_win != NULL)
676 bookMenuDestroy( data->menu_options_win ); 676 bookMenuDestroy( data->menu_options_win );
677 //start the calculator option menu and kill this window 677 //start the calculator option menu and kill this window
678 data->menu_options_win = bookMenuStart( data->win, calcOptionMenuAttributes(),0); 678 data->menu_options_win = bookMenuStart( data->win, calcOptionMenuAttributes(),0);
679 SEND_EVENT(data->menu_options_win, ADD_CALLBACK, NULL, (void *)calc_menu_cb); 679 SEND_EVENT(data->menu_options_win, ADD_CALLBACK, NULL, (void *)calc_menu_cb);
680 680
681 } 681 }
682 break; 682 break;
683 683
684 case INFO_KCD_HUP: 684 case INFO_KCD_HUP:
685 case INFO_KCD_RIGHT: 685 case INFO_KCD_RIGHT:
686 { 686 {
687 TRACE_EVENT("Right button pressed in calculator"); 687 TRACE_EVENT("Right button pressed in calculator");
688 calc_destroy(win); 688 calc_destroy(win);
704 704
705 $Function: calcGetOperandCB 705 $Function: calcGetOperandCB
706 706
707 $Description: Callback function for the editor window, when second number in operation 707 $Description: Callback function for the editor window, when second number in operation
708 is entered. 708 is entered.
709 709
710 $Returns: nothing 710 $Returns: nothing
711 711
712 $Arguments: Window, identifier (not used), reason (not used) 712 $Arguments: Window, identifier (not used), reason (not used)
713 713
714 *******************************************************************************/ 714 *******************************************************************************/
715 715
716 static void calcGetOperandCB( T_MFW_HND win, USHORT Identifier, SHORT reason) 716 static void calcGetOperandCB( T_MFW_HND win, USHORT Identifier, SHORT reason)
717 { 717 {
718 T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data; 718 T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data;
722 float after_decimal = 0; 722 float after_decimal = 0;
723 int digits_after_point = 0; 723 int digits_after_point = 0;
724 int i; 724 int i;
725 char* end; 725 char* end;
726 char debug[40]; 726 char debug[40];
727 727
728 TRACE_FUNCTION("calcGetOperandCB()"); 728 TRACE_FUNCTION("calcGetOperandCB()");
729 TRACE_EVENT_P2("ID, reason: %d, %d", Identifier, reason); 729 TRACE_EVENT_P2("ID, reason: %d, %d", Identifier, reason);
730 730
731 switch (reason ) 731 switch (reason )
732 { 732 {
743 743
744 //if buffer not pointing at an empty string now 744 //if buffer not pointing at an empty string now
745 if (strlen(end) != 0) 745 if (strlen(end) != 0)
746 { //if decimal point entered 746 { //if decimal point entered
747 if ((end[0] == '.') && isdigit(end[1]))//get number after decimal point 747 if ((end[0] == '.') && isdigit(end[1]))//get number after decimal point
748 { 748 {
749 end++; 749 end++;
750 digits_after_point = strlen(end); 750 digits_after_point = strlen(end);
751 after_decimal = strtol(end, &end, 10); 751 after_decimal = strtol(end, &end, 10);
752 sprintf(debug,"Digits after decimal: %f.", after_decimal); 752 sprintf(debug,"Digits after decimal: %f.", after_decimal);
753 } 753 }
761 //perform the arithmetic function requested 761 //perform the arithmetic function requested
762 switch (data->operation) 762 switch (data->operation)
763 { 763 {
764 case PLUS: running_total = running_total + operand; break; 764 case PLUS: running_total = running_total + operand; break;
765 case MINUS: running_total = running_total - operand;break; 765 case MINUS: running_total = running_total - operand;break;
766 case MULTIPLY: running_total = running_total * operand;break; 766 case MULTIPLY: running_total = running_total * operand;break;
767 case DIVIDE: 767 case DIVIDE:
768 // Oct 20, 2004 REF: CRR 25755 xnkulkar 768 // Oct 20, 2004 REF: CRR 25755 xnkulkar
769 // if the attempted division is by zero 769 // if the attempted division is by zero
770 if(operand == 0) 770 if(operand == 0)
771 { 771 {
772 divideByZero = TRUE; // enable the flag 772 divideByZero = TRUE; // enable the flag
773 } 773 }
774 else // else perform the division operation 774 else // else perform the division operation
775 { 775 {
776 running_total = running_total / operand; 776 running_total = running_total / operand;
777 } 777 }
778 break; 778 break;
779 default: TRACE_EVENT("Unknown calc operation"); break; 779 default: TRACE_EVENT("Unknown calc operation"); break;
780 } 780 }
781 781
782 /* SPR#1428 - SH - New Editor: Can use '*' as 'equals', to show result */ 782 /* SPR#1428 - SH - New Editor: Can use '*' as 'equals', to show result */
783 #ifdef NEW_EDITOR 783 #ifdef NEW_EDITOR
784 #ifdef COLOURDISPLAY 784 #ifdef COLOURDISPLAY
785 if (reason==INFO_KCD_STAR || reason==INFO_KCD_SELECT) 785 if (reason==INFO_KCD_STAR || reason==INFO_KCD_SELECT)
786 #else /* COLOURDISPLAY */ 786 #else /* COLOURDISPLAY */
809 bookMenuDestroy( data->menu_options_win ); 809 bookMenuDestroy( data->menu_options_win );
810 data->menu_options_win = bookMenuStart( data->win, calcOptionMenuAttributes(),0); 810 data->menu_options_win = bookMenuStart( data->win, calcOptionMenuAttributes(),0);
811 } 811 }
812 } 812 }
813 break; 813 break;
814 814
815 case INFO_KCD_HUP: 815 case INFO_KCD_HUP:
816 case INFO_KCD_RIGHT: 816 case INFO_KCD_RIGHT:
817 { 817 {
818 TRACE_EVENT("Right button pressed in calculator"); 818 TRACE_EVENT("Right button pressed in calculator");
819 819
820 calc_destroy(win); 820 calc_destroy(win);
821 } 821 }
822 break; 822 break;
823 823
824 default: 824 default:
847 /******************************************************************************* 847 /*******************************************************************************
848 848
849 $Function: calcSetEditor 849 $Function: calcSetEditor
850 850
851 $Description: Sets the editor attributes to defaults for the calculator module 851 $Description: Sets the editor attributes to defaults for the calculator module
852 852
853 $Returns: nothing 853 $Returns: nothing
854 854
855 $Arguments: Window 855 $Arguments: Window
856 856
857 *******************************************************************************/ 857 *******************************************************************************/
858 void calcSetEditor(T_MFW_HND win) 858 void calcSetEditor(T_MFW_HND win)
859 { 859 {
860 T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data; 860 T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data;
861 tCalcData* data = (tCalcData *) win_data->user; 861 tCalcData* data = (tCalcData *) win_data->user;
862 862
863 TRACE_FUNCTION("calcSetEditor()"); 863 TRACE_FUNCTION("calcSetEditor()");
864 864
865 /* SPR#1428 - SH - New Editor changes */ 865 /* SPR#1428 - SH - New Editor changes */
866 #ifdef NEW_EDITOR 866 #ifdef NEW_EDITOR
867 { 867 {
868 AUI_edit_SetDefault(&data->editor_data); 868 AUI_edit_SetDefault(&data->editor_data);
869 AUI_edit_SetDisplay(&data->editor_data, ZONE_FULL_SK_TITLE, COLOUR_EDITOR, EDITOR_FONT); 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); 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); 871 AUI_edit_SetMode(&data->editor_data, 0, ED_CURSOR_NONE);
872 AUI_edit_SetEvents(&data->editor_data, 0, TRUE, FOREVER, NULL); 872 AUI_edit_SetEvents(&data->editor_data, 0, TRUE, FOREVER, NULL);
873 AUI_edit_SetTextStr(&data->editor_data, TxtSoftOptions, TxtDelete, TxtCalculator, NULL); 873 AUI_edit_SetTextStr(&data->editor_data, TxtSoftOptions, TxtDelete, TxtCalculator, NULL);
874 //xrashmic 20 Oct, 2005 MMI-SPR-33845 874 //xrashmic 20 Oct, 2005 MMI-SPR-33845
875 //Editor always starts with min one character "0" and 875 //Editor always starts with min one character "0" and
876 //alterRight softkey is set to "BACK" here. 876 //alterRight softkey is set to "BACK" here.
877 data->editor_data.min_enter=1; 877 data->editor_data.min_enter=1;
878 data->editor_data.AltRightSoftKey=TxtSoftBack ; 878 data->editor_data.AltRightSoftKey=TxtSoftBack ;
879 AUI_edit_SetFormatAttr(&data->editor_data, DS_ALIGN_RIGHT); 879 AUI_edit_SetFormatAttr(&data->editor_data, DS_ALIGN_RIGHT);
880 } 880 }
881 #else /* NEW_EDITOR */ 881 #else /* NEW_EDITOR */
882 editor_attr_init(&((data->editor_data).editor_attr), 0, edtCurBar1, 0, data->buffer, 10, COLOUR_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); 883 editor_data_init( &data->editor_data, NULL, TxtSoftOptions, TxtDelete, NULL, 1, CALC_MODE, FOREVER);
884 data->editor_data.hide = FALSE; 884 data->editor_data.hide = FALSE;
885 data->editor_data.Identifier = 0xFFFF ; 885 data->editor_data.Identifier = 0xFFFF ;
886 data->editor_data.destroyEditor = TRUE; 886 data->editor_data.destroyEditor = TRUE;
887 #endif /* NEW_EDITOR */ 887 #endif /* NEW_EDITOR */
888 888
889 return; 889 return;
890 } 890 }
892 /******************************************************************************* 892 /*******************************************************************************
893 893
894 $Function: calc_destroy 894 $Function: calc_destroy
895 895
896 $Description: Destroys the calculator editor window and frees up memory 896 $Description: Destroys the calculator editor window and frees up memory
897 897
898 $Returns: nothing 898 $Returns: nothing
899 899
900 $Arguments: Window 900 $Arguments: Window
901 901
902 *******************************************************************************/ 902 *******************************************************************************/
903 void calc_destroy(MfwHnd own_window) 903 void calc_destroy(MfwHnd own_window)
904 { 904 {
905 T_MFW_WIN * win_data; 905 T_MFW_WIN * win_data;
906 tCalcData * data = NULL; 906 tCalcData * data = NULL;
907 907
908 TRACE_EVENT ("calc_destroy()"); 908 TRACE_EVENT ("calc_destroy()");
909 if (own_window) 909 if (own_window)
910 { 910 {
911 911
912 win_data = ((T_MFW_HDR *)own_window)->data; 912 win_data = ((T_MFW_HDR *)own_window)->data;
913 if (win_data != NULL) //PATCH TB 913 if (win_data != NULL) //PATCH TB
914 data = (tCalcData *)win_data->user; 914 data = (tCalcData *)win_data->user;
915 915
916 if (data) 916 if (data)
917 { 917 {
918 918
919 win_delete (data->win); 919 win_delete (data->win);
920 /* Marcus: Issue 1039: 05/09/2002: Start */ 920 /* Marcus: Issue 1039: 05/09/2002: Start */
921 if (data->menu_options_win != NULL) 921 if (data->menu_options_win != NULL)
922 { 922 {
923 bookMenuDestroy( data->menu_options_win ); 923 bookMenuDestroy( data->menu_options_win );
924 data->menu_options_win = NULL; 924 data->menu_options_win = NULL;
925 } 925 }
926 /* Marcus: Issue 1039: 05/09/2002: End */ 926 /* Marcus: Issue 1039: 05/09/2002: End */
927 // Free Memory 927 // Free Memory
928 FREE_MEMORY ((void *)data, sizeof (tCalcData)); 928 FREE_MEMORY ((void *)data, sizeof (tCalcData));
929 929
930 } 930 }
931 else 931 else
932 { 932 {
933 TRACE_EVENT ("calc_destroy() called twice"); 933 TRACE_EVENT ("calc_destroy() called twice");
934 } 934 }