mmicalculatormain.c

来自「是一个手机功能的模拟程序」· C语言 代码 · 共 788 行 · 第 1/2 页

C
788
字号
/*******************************************************************************

					CONDAT (UK)

********************************************************************************                                                                              

 This software product is the property of Condat (UK) Ltd and may not be
 disclosed to any third party without the express permission of the owner.                                 
                                                                              
********************************************************************************

 $Project name:	Basic MMI                                                      
 $Project code:	BMI (6349)                                                           
 $Module:		Calculator
 $File:		    MmiCalculatorMain.c
 $Revision:		1.0                                                       
                                                                              
 $Author:		Condat(UK)                                                         
 $Date:		    25/10/00                                                      
                                                                               
********************************************************************************
                                                                              
 Description

    This provides the main calculator functionality

  
********************************************************************************
 $History: MmiCalculatorMain.c

	25/10/00			Original Condat(UK) BMI version.	
	   
 $End

*******************************************************************************/
#define MAX_CALC_TOTAL 999999999
#define MIN_CALC_TOTAL -99999999

/******************************************************************************
                                                                              
                                Include Files
                                                                              
*******************************************************************************/
#define ENTITY_MFW

/* includes */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#if defined (NEW_FRAME)

#include "typedefs.h"
#include "vsi.h"
#include "pei.h"
#include "custom.h"
#include "gsm.h"

#else

#include "stddefs.h"
#include "custom.h"
#include "gsm.h"
#include "vsi.h"

#endif
#include "MmiCalculatorMain.h"
#include "MmiEditor.h"
#include "Mfw_edt.h"
#include "MmiDialogs.h"

#include "p_sim.h"

#include "mfw_mfw.h"
#include "mfw_win.h"
#include "mfw_edt.h"
#include "mfw_tim.h"
#include "mfw_phb.h"
#include "ksd.h"
#include "psa.h"
#include "mfw_icn.h"
#include "mfw_mnu.h"
#include "mfw_lng.h"
#include "mfw_sat.h"
#include "mfw_kbd.h"
#include "mfw_nm.h"
#include "mfw_sms.h"

#include "dspl.h"

#include "MmiMmi.h"
#include "MmiDummy.h"
#include "MmiDialogs.h"
#include "MmiLists.h"
#include "MmiIdle.h"
#include "MmiSoftkeys.h"
#include "MmiIcons.h"
#include "MmiMenu.h"
#include "MmiMain.h"
#include "MmiStart.h"
#include "MmiPins.h"
#include "MmiSettings.h"

#include "MmiEditor.h"
#include "MmiBookShared.h"
#include "MmiSmsMenu.h"
#include "MmiCalculatorMain.h"



#include "cus_aci.h"
#include "p_sim.h"
#include "pcm.h"


/*******************************************************************************
                                                                              
                                Function Prototypes
                                                                              
*******************************************************************************/
T_MFW_HND calc_create(MfwHnd parent_window);
void calc_destroy(MfwHnd own_window);
static void calcGetNumberCB( T_MFW_HND win, USHORT Identifier,UBYTE reason );
static void calcGetOperandCB( T_MFW_HND win, USHORT Identifier,UBYTE reason );
static void calc_DialogCB( T_MFW_HND win, USHORT event, SHORT identifier, void *parameter);
T_MFW_HND calc_start(T_MFW_HND parent_window);
double calcGetRunningTotal();
char operatorSymbol(UBYTE operator);
static void calc_menu_cb(T_MFW_HND parent_win, UBYTE identifier, UBYTE reason);
/*******************************************************************************
                                                                              
                                Static Global Variable(s) 
                                                                              
*******************************************************************************/	

static double running_total;

static T_MFW_HND calculator_win = NULL;

/*******************************************************************************
                                                                              
                                Public Functions
                                                                              
*******************************************************************************/
/*******************************************************************************

 $Function:    	calculator

 $Description:	Starts the calculator function on user selection
 
 $Returns:		MFW_EVENT_CONSUMED if event handled, otherwise
				MFW_EVENT_PASSED

 $Arguments:	menu, menu item
 
*******************************************************************************/
int calculator(MfwMnu* m, MfwMnuItem* i)
{
    T_MFW_HND	    	parent       = mfwParent( mfw_header());
    calc_start(parent);
    return MFW_EVENT_CONSUMED;
}

/*******************************************************************************

 $Function:    	calcPlus

 $Description:	Handles the selction of the "Plus" option in the calculator menu
 
 $Returns:		MFW_EVENT_CONSUMED if event handled, otherwise
				MFW_EVENT_PASSED

 $Arguments:	menu, menu item
 
*******************************************************************************/
int calcPlus(MfwMnu* m, MfwMnuItem* i)
{
    //T_MFW_HND	    	parent_window       = mfwParent( mfw_header()); 
    T_MFW_WIN*			win_data;
	//T_MFW_HND       	win           = calc_create(parent_window);
	tCalcData*			data;

	//if new window successfully created
    if (calculator_win NEQ NULL)
        {	win_data   = ( (T_MFW_HDR *) calculator_win )->data;
        	data = (tCalcData*)win_data->user;
        	data->operation = PLUS;//set the arithmetic operation
           	SEND_EVENT (calculator_win, CALC_ENTER_OPERAND, 0, 0);
        } 
    return MFW_EVENT_CONSUMED;
}

/*******************************************************************************

 $Function:    	calcMinus

 $Description:	Handles the selection of the "Minus" option in the calculator menu
 
 $Returns:		MFW_EVENT_CONSUMED if event handled, otherwise
				MFW_EVENT_PASSED

 $Arguments:	menu, menu item
 
*******************************************************************************/
int calcMinus(MfwMnu* m, MfwMnuItem* i)
{
     //T_MFW_HND	    	parent_window       = mfwParent( mfw_header()); 
    T_MFW_WIN*			win_data;
	//T_MFW_HND       	win           = calc_create(parent_window);
	tCalcData*			data;

	//if new window successfully created
    if (calculator_win NEQ NULL)
        {	win_data   = ( (T_MFW_HDR *) calculator_win )->data;
        	data = (tCalcData*)win_data->user;
        	data->operation = MINUS;//set the arithmetic operation
           	SEND_EVENT (calculator_win, CALC_ENTER_OPERAND, 0, 0);
        } 
    return MFW_EVENT_CONSUMED;
}

/*******************************************************************************

 $Function:    	calcDivide

 $Description:	Handles the selection of the "Divide" option in the calculator menu
 
 $Returns:		MFW_EVENT_CONSUMED if event handled, otherwise
				MFW_EVENT_PASSED

 $Arguments:	menu, menu item
 
*******************************************************************************/
int calcDivide(MfwMnu* m, MfwMnuItem* i)
{
    //T_MFW_HND	    	parent_window       = mfwParent( mfw_header()); 
    T_MFW_WIN*			win_data;
	//T_MFW_HND       	win           = calc_create(parent_window);
	tCalcData*			data;

	//if new window successfully created
    if (calculator_win NEQ NULL)
        {	win_data   = ( (T_MFW_HDR *) calculator_win )->data;
        	data = (tCalcData*)win_data->user;
        	data->operation = DIVIDE;//set the arithmetic operation
           	SEND_EVENT (calculator_win, CALC_ENTER_OPERAND, 0, 0);
        } 
    return MFW_EVENT_CONSUMED;
}
/*******************************************************************************

 $Function:    	calcMultiply

 $Description:	Handles the selection of the "Multiply" option in the calculator menu
 
 $Returns:		MFW_EVENT_CONSUMED if event handled, otherwise
				MFW_EVENT_PASSED

 $Arguments:	menu, menu item
 
*******************************************************************************/
int calcMultiply(MfwMnu* m, MfwMnuItem* i)
{
    //T_MFW_HND	    	parent_window       = mfwParent( mfw_header()); 
    T_MFW_WIN*			win_data;
	//T_MFW_HND       	win           = calc_create(parent_window);
	tCalcData*			data;

	//if new window successfully created
    if (calculator_win NEQ NULL)
        {	win_data   = ( (T_MFW_HDR *) calculator_win )->data;
        	data = (tCalcData*)win_data->user;
        	data->operation = MULTIPLY;//set the arithmetic operation
           	SEND_EVENT (calculator_win, CALC_ENTER_OPERAND, 0, 0);
        } 
    return MFW_EVENT_CONSUMED;
}

/*******************************************************************************

 $Function:    	calcEquals

 $Description:	Handles the selection of the "Equals" option in the calculator menu
 
 $Returns:		MFW_EVENT_CONSUMED if event handled, otherwise
				MFW_EVENT_PASSED

 $Arguments:	menu, menu item
 
*******************************************************************************/
int calcEquals(MfwMnu* m, MfwMnuItem* i)
{

    if (calculator_win NEQ NULL)
        {	
           	SEND_EVENT (calculator_win, CALC_DISPLAY_RESULT, 0, 0);
        } 

    return MFW_EVENT_CONSUMED;
}

/*******************************************************************************
                                                                              
                                Private Functions
                                                                              
*******************************************************************************/	
/*******************************************************************************

 $Function:    	calcGetRunningTotal

 $Description:	If the calculator's running total value ever needs to be accessed by 
 				code in another file, then this function ought to be made public to prevent 
 				to allow safe access;
 
 $Returns:		Calculator's running total (double)

 $Arguments:	none
 
*******************************************************************************/
double calcGetRunningTotal()
{
	return running_total;
}

/*******************************************************************************

 $Function:    	operatorSymbol

 $Description:	returns character corresponding to arithmetic operation 
 
 $Returns:		Operator character

 $Arguments:	Operator enum
 
*******************************************************************************/
char operatorSymbol(UBYTE operator)
{
	switch (operator)
	{
		case (PLUS): 	return '+'; break;
		case (MINUS):	return '-'; break;
		case (MULTIPLY): return '*'; break;
		case (DIVIDE):	return '/'; break;
		default: 		return '\0'; break;
	}
		
}


/*******************************************************************************

 $Function:    	calc_start

 $Description:	Creates the calculator window and calls for it to be initialised 
 
 $Returns:		Window

 $Arguments:	Parent Window
 
*******************************************************************************/

T_MFW_HND calc_start(T_MFW_HND parent_window)
{
  	T_MFW_HND       	win           = calc_create(parent_window);
	TRACE_FUNCTION("calc_start()");
    if (win NEQ NULL)
        {
           	SEND_EVENT (win, CALC_INIT, 0, 0);
        } 

   return win;
}

/*******************************************************************************

 $Function:    	calc_create

 $Description:	Creates the calculator window and connect the dialog data to it
 
 $Returns:		Window

 $Arguments:	Parent Window
 
*******************************************************************************/	
static T_MFW_HND calc_create(MfwHnd parent_window)
{
	tCalcData     * data = (tCalcData *)ALLOC_MEMORY (sizeof (tCalcData ));
	T_MFW_WIN  * win;

	if (data EQ NULL)
	{
		return NULL;
	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?