⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample.final

📁 brew 培训的sample source code
💻 FINAL
字号:
/*===========================================================================

FILE: sample.c
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h"          // Module interface definitions
#include "AEEAppGen.h"          // Applet interface definitions
#include "AEEShell.h"           // Shell interface definitions
#include "sample.bid"
#include "sample_res.h"
#include "AEE.h"
#include "AEEMenu.h"
#include "AEEStdLib.h"
//Lab 1
#include "AEEText.h"
// end of lab 1

//the defination for the menu items
#define ID_NAME  1
#define ID_ENTER 2
#define ID_HELP  3
#define ID_ABOUT 4

// defination for the different pages
#define STATUS_SPLASH    5
#define STATUS_MAINMENU  6
#define STATUS_ABOUT     7
#define STATUS_HELP      8
// lab 3
#define STATUS_GIVENAME  9
// end of lab 3

// lab 4
// defination for the softkey
#define ID_OK             11

// the length for the dog's name
#define NAME_LEN         12
// end of lab 4

typedef struct _SampleApp
{
	AEEApplet      a;
	AEEDeviceInfo  info;
	IMenuCtl       *pMenu;
	IStatic        *pAbout;
	IStatic        *pHelp;

	// Lab 2
	ITextCtl       *pDogName;
	IMenuCtl       *pSoftkey;
	AECHAR         *pText;
	// end of lab 2

	int            flag;
	int            TickTime;
	uint16         status;
}SampleApp;


/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean sample_HandleEvent(SampleApp * pi, AEEEvent eCode, 
                                      uint16 wParam, uint32 dwParam);

static boolean SampleApp_Init(SampleApp *pi);
static void SampleApp_Free(SampleApp *pi);
static void DisplaySplash(SampleApp *pi);
static void BuildMainMenu(SampleApp *pi);
static void DisplayAbout(SampleApp *pi);
static void DisplayHelp(SampleApp *pi);
static void SetDogName(SampleApp *pi);
/*===============================================================================
FUNCTION DEFINITIONS
=============================================================================== */

/*===========================================================================

FUNCTION: AEEClsCreateInstance

DESCRIPTION
	This function is invoked while the app is being loaded. All Modules must provide this 
	function. Ensure to retain the same name and parameters for this function.
	In here, the module must verify the ClassID and then invoke the AEEApplet_New() function
	that has been provided in AEEAppGen.c. 

   After invoking AEEApplet_New(), this function can do app specific initialization. In this
   example, a generic structure is provided so that app developers need not change app specific
   initialization section every time except for a call to IDisplay_InitAppData(). 
   This is done as follows: InitAppData() is called to initialize AppletData 
   instance. It is app developers responsibility to fill-in app data initialization 
   code of InitAppData(). App developer is also responsible to release memory 
   allocated for data contained in AppletData -- this can be done in 
   IDisplay_FreeAppData().

PROTOTYPE:
   int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)

PARAMETERS:
	clsID: [in]: Specifies the ClassID of the applet which is being loaded

	pIShell: [in]: Contains pointer to the IShell object. 

	pIModule: pin]: Contains pointer to the IModule object to the current module to which
	this app belongs

	ppObj: [out]: On return, *ppObj must point to a valid IApplet structure. Allocation
	of memory for this structure and initializing the base data members is done by AEEApplet_New().

DEPENDENCIES
  none

RETURN VALUE
  AEE_SUCCESS: If the app needs to be loaded and if AEEApplet_New() invocation was
     successful
  EFAILED: If the app does not need to be loaded or if errors occurred in 
     AEEApplet_New(). If this function returns FALSE, the app will not be loaded.

SIDE EFFECTS
  none
===========================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
{
   *ppObj = NULL;
		
   if(ClsId == AEECLSID_SAMPLE){
      if(AEEApplet_New(sizeof(SampleApp), ClsId, pIShell,po,(IApplet**)ppObj,
         (AEEHANDLER)sample_HandleEvent,(PFNFREEAPPDATA)SampleApp_Free)
         == TRUE)
      {
		 // Add your code here .....
		  if(!SampleApp_Init((SampleApp*)*ppObj))
		  {
			  IAPPLET_Release(*ppObj);
			  return EFAILED;
		  }

         return (AEE_SUCCESS);
      }
   }
	return (EFAILED);
}

/*===========================================================================

FUNCTION sample_HandleEvent

DESCRIPTION
	This is the EventHandler for this app. All events to this app are handled in this
	function. All APPs must supply an Event Handler.

PROTOTYPE:
	boolean sample_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)

PARAMETERS:
	pi: Pointer to the AEEApplet structure. This structure contains information specific
	to this applet. It was initialized during the AEEClsCreateInstance() function.

	ecode: Specifies the Event sent to this applet

   wParam, dwParam: Event specific data.

DEPENDENCIES
  none

RETURN VALUE
  TRUE: If the app has processed the event
  FALSE: If the app did not process the event

SIDE EFFECTS
  none
===========================================================================*/
static boolean sample_HandleEvent(SampleApp * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{  
	uint16        item;

	  if(pi->pMenu && IMENUCTL_HandleEvent(pi->pMenu,eCode,wParam,dwParam) )
		  return TRUE;

	  // lab 8
	  if(pi->pDogName && ITEXTCTL_HandleEvent(pi->pDogName,eCode,wParam,dwParam) )
			return TRUE;

	  if(pi->pSoftkey && IMENUCTL_HandleEvent(pi->pSoftkey,eCode,wParam,dwParam))
		  return TRUE;
	  // end of lab 8

	switch (eCode) 
	{
      case EVT_APP_START:                        
		    
		    // Add your code here .....

		  DisplaySplash(pi);
		  ISHELL_SetTimer(pi->a.m_pIShell,1000,(PFNNOTIFY)BuildMainMenu,pi);
      		return(TRUE);
	  case EVT_KEY:
		  //When the user press clear key and the current page is not the main pMenu, it should be returned to the main menu.
		  if((wParam == AVK_CLR) && (pi->status != STATUS_MAINMENU)) 
		  {
			  // lab 10
			  if(pi->pDogName)
			  {
				  ITEXTCTL_SetActive(pi->pDogName,FALSE);
				  ITEXTCTL_Release(pi->pDogName);
				  IMENUCTL_Release(pi->pSoftkey);
				  pi->pDogName = NULL;
				  pi->pSoftkey = NULL;
			  }
			  // end of lab 10
			  if(pi->pAbout)
			  {
				  ISTATIC_Release(pi->pAbout);
				  pi->pAbout = NULL;
			  }
			  if(pi->pHelp)
			  {
				  ISTATIC_Release(pi->pHelp);
				  pi->pHelp = NULL;
			  }
			  IMENUCTL_Redraw(pi->pMenu);
			  IMENUCTL_SetActive(pi->pMenu,TRUE);
			  pi->status = STATUS_MAINMENU;
			  return TRUE;
		  }
		  else //When the user press clear key and the current page is main menu, the application should exit.
			  return FALSE;
	  case EVT_COMMAND:
		  if(IMENUCTL_IsActive(pi->pMenu))
		  {
			  item = IMENUCTL_GetSel (pi->pMenu);
			  switch(item)
			  {
			  case ID_NAME:  // Set the name for the dog
				  // lab 7
				  SetDogName(pi);
				  // end of lab 7
				  break;
			  case ID_ENTER:  // Display the running dog on the screen with the music
				  break;
			  case ID_HELP:
				  break;
			  case ID_ABOUT:  // Display the information about this application
				  DisplayAbout(pi);
				  break;
			  default:
				  break;
			  }
			  return TRUE;
		  }
		  // lab 9
		  else if(IMENUCTL_IsActive(pi->pSoftkey))  
		  {
			  item = IMENUCTL_GetSel(pi->pSoftkey);
			  if(item == ID_OK)  // Get the name from the ITEXTCTL
			  {
				  if(!pi->pText)
					 pi->pText = (AECHAR*)MALLOC(NAME_LEN);
				  if(!pi->pText)
					  return FALSE;
				  ITEXTCTL_GetText(pi->pDogName,pi->pText,NAME_LEN/2);
				  ITEXTCTL_Release(pi->pDogName);
				  IMENUCTL_Release(pi->pSoftkey);
				  pi->pDogName = NULL;
				  pi->pSoftkey = NULL;
				  IMENUCTL_SetActive(pi->pMenu,TRUE);
			 	  return TRUE;
			  }
			  // end of lab 9
		  }
      case EVT_APP_STOP:

		    // Add your code here .....

         return TRUE;
	  case EVT_APP_SUSPEND:
		  switch(pi->status)
		  {
		  case STATUS_MAINMENU:
		      IMENUCTL_Release(pi->pMenu);
			  pi->pMenu = NULL;
			  break;
		  case STATUS_ABOUT:
			  ISTATIC_Release(pi->pAbout);
			  pi->pAbout = NULL;
			  break;
		  case STATUS_HELP:
			  ISTATIC_Release(pi->pHelp);
			  pi->pHelp = NULL;
			  break;
		  // lab 11
		  case STATUS_GIVENAME:
			  if(!pi->pText)
				 pi->pText = (AECHAR*)MALLOC(NAME_LEN);
			  if(!pi->pText)
				  return FALSE;
			  ITEXTCTL_GetText(pi->pDogName,pi->pText,NAME_LEN/2);
			  ITEXTCTL_SetActive(pi->pDogName,FALSE);
			  ITEXTCTL_Release(pi->pDogName);
			  IMENUCTL_Release(pi->pSoftkey);
			  pi->pDogName = NULL;
			  pi->pSoftkey = NULL;
			  break;
		  // end of lab 11
		  }
		  return TRUE;
	  case EVT_APP_RESUME:
		  switch(pi->status)
		  {
		  case STATUS_MAINMENU:
			  BuildMainMenu(pi);
			  break;
		  case STATUS_ABOUT:
			  DisplayAbout(pi);
			  break;
		  case STATUS_HELP:
			  DisplayHelp(pi);
			  break;
		  // lab 12
		  case STATUS_GIVENAME:
			  SetDogName(pi);
			  break;
		 // end of lab 12
		  }
		  return TRUE;
      default:
         break;
   }
   return FALSE;
}

static boolean SampleApp_Init(SampleApp *pi)
{
	ISHELL_GetDeviceInfo(pi->a.m_pIShell,&pi->info);

	pi->status = 0;
	pi->pMenu = NULL;
	// lab 5
	pi->pDogName = NULL;
	pi->pSoftkey = NULL;
    pi->pText = NULL;
	// enf of lab 5
	pi->pAbout = NULL;

	return TRUE;
}

static void SampleApp_Free(SampleApp *pi)
{
	if(pi->pMenu)
		IMENUCTL_Release(pi->pMenu);
	// lab 6
	if(pi->pDogName)
		ITEXTCTL_Release(pi->pDogName);
	if(pi->pSoftkey)
		IMENUCTL_Release(pi->pSoftkey);
	if(pi->pText)
		FREE(pi->pText);
	// end of lab 6
	if(pi->pAbout)
		ISTATIC_Release(pi->pAbout);
}

static void DisplaySplash(SampleApp *pi)
{
    AECHAR        szText[12];

    ISHELL_LoadResString(pi->a.m_pIShell,SAMPLE_RES_FILE,IDS_SAMPLE,szText,sizeof(szText));
    IDISPLAY_DrawText(pi->a.m_pIDisplay,    // Display instance
                     AEE_FONT_BOLD,       // Use BOLD font
                     szText,              // Text - Normally comes from resource
                     -1,                  // -1 = Use full string length
                     0,                   // Ignored - IDF_ALIGN_CENTER
                     0,                   // Ignored - IDF_ALIGN_MIDDLE
                     NULL,                // No clipping
                     IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
    IDISPLAY_Update (pi->a.m_pIDisplay);
}

static void BuildMainMenu(SampleApp *pi)
{
	if(ISHELL_CreateInstance(pi->a.m_pIShell,AEECLSID_MENUCTL,(void**)&pi->pMenu) != SUCCESS)
		return ;

	IMENUCTL_SetTitle(pi->pMenu,SAMPLE_RES_FILE,IDS_TITLE,NULL);

	IMENUCTL_AddItem(pi->pMenu,SAMPLE_RES_FILE,IDS_NAME,ID_NAME,NULL,0);
	IMENUCTL_AddItem(pi->pMenu,SAMPLE_RES_FILE,IDS_ENTER,ID_ENTER,NULL,0);
	IMENUCTL_AddItem(pi->pMenu,SAMPLE_RES_FILE,IDS_HELP,ID_HELP,NULL,0);
	IMENUCTL_AddItem(pi->pMenu,SAMPLE_RES_FILE,IDS_ABOUT,ID_ABOUT,NULL,0);

	IMENUCTL_SetActive(pi->pMenu,TRUE);
	pi->status = STATUS_MAINMENU;
}


static void DisplayAbout(SampleApp *pi)
{
	AEERect       rect;
    AECHAR        title[12];
	AECHAR        data[80];

	pi->status = STATUS_ABOUT;
	IMENUCTL_SetActive(pi->pMenu,FALSE);
	IDISPLAY_ClearScreen(pi->a.m_pIDisplay );
	if(!pi->pAbout)
	{
		if(ISHELL_CreateInstance(pi->a.m_pIShell,AEECLSID_STATIC,(void**)&pi->pAbout) != SUCCESS)
			return ;
	}
	SETAEERECT(&rect,0,0,pi->info.cxScreen,pi->info.cyScreen);
    ISTATIC_SetRect(pi->pAbout,&rect);

	ISHELL_LoadResString(pi->a.m_pIShell,SAMPLE_RES_FILE,IDS_ABOUT,title,sizeof(title));
	ISHELL_LoadResString(pi->a.m_pIShell,SAMPLE_RES_FILE,IDS_ABOUT_DATA,data,sizeof(data));
	ISTATIC_SetText(pi->pAbout,title,data,AEE_FONT_BOLD,AEE_FONT_NORMAL);
	ISTATIC_SetActive(pi->pAbout,TRUE);
	ISTATIC_Redraw(pi->pAbout);
}

static void DisplayHelp(SampleApp *pi)
{
	AEERect       rect;
	AECHAR        title[24];
	IImage        *pImage;

	IMENUCTL_SetActive(pi->pMenu,FALSE);
	IDISPLAY_ClearScreen(pi->a.m_pIDisplay );
	if(!pi->pHelp)
	{
		if(ISHELL_CreateInstance(pi->a.m_pIShell,AEECLSID_STATIC,(void**)&pi->pHelp) != SUCCESS)
			return ;
	}
	ISTATIC_SetProperties(pi->pHelp,ST_ICONTEXT);
	SETAEERECT(&rect,0,0,pi->info.cxScreen,pi->info.cyScreen);
    ISTATIC_SetRect(pi->pHelp,&rect);

	ISHELL_LoadResString(pi->a.m_pIShell,SAMPLE_RES_FILE,IDS_HELP,title,sizeof(title));
	pImage = ISHELL_LoadResImage(pi->a.m_pIShell,SAMPLE_RES_FILE,IDB_HELP);
	ISTATIC_SetText(pi->pHelp,title,(AECHAR*)pImage,AEE_FONT_NORMAL,AEE_FONT_NORMAL);
	ISTATIC_Redraw(pi->pHelp);
	IIMAGE_Release(pImage);
	pi->status = STATUS_HELP;
}

// lab 7
static void SetDogName(SampleApp *pi)
{
	AEERect       rect;

	pi->status = STATUS_GIVENAME;

	if(!pi->pDogName)
	{
		if(ISHELL_CreateInstance(pi->a.m_pIShell,AEECLSID_TEXTCTL,(void**)&pi->pDogName) != SUCCESS)
			return;
		if(ISHELL_CreateInstance(pi->a.m_pIShell,AEECLSID_SOFTKEYCTL,(void**)&pi->pSoftkey) != SUCCESS)
		{
			pi->pDogName = NULL;
			return ;
		}
	}

	IMENUCTL_SetActive(pi->pMenu,FALSE);
	IDISPLAY_ClearScreen(pi->a.m_pIDisplay);

	ITEXTCTL_SetTitle(pi->pDogName,SAMPLE_RES_FILE,IDS_DOG_NAME,NULL);
	ITEXTCTL_SetProperties(pi->pDogName,TP_FRAME);
	ITEXTCTL_SetMaxSize(pi->pDogName,5);
	SETAEERECT(&rect,0,20,pi->info.cxScreen,pi->info.cyScreen/2);
	ITEXTCTL_SetRect(pi->pDogName,&rect);
	if(pi->pText)
		ITEXTCTL_SetText(pi->pDogName,pi->pText,-1);
	ITEXTCTL_SetCursorPos(pi->pDogName,TC_CURSOREND);

	ITEXTCTL_SetSoftKeyMenu(pi->pDogName,pi->pSoftkey);
	ITEXTCTL_SetInputMode(pi->pDogName,AEE_TM_FIRST_OEM+1);
	IMENUCTL_AddItem(pi->pSoftkey,SAMPLE_RES_FILE,IDS_OK,ID_OK,NULL,0);

	ITEXTCTL_SetActive(pi->pDogName,TRUE);
}
// end of lab 7

⌨️ 快捷键说明

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