📄 downloadbmp.c
字号:
/*===========================================================================
FILE: downloadbmp.c
===========================================================================*/
/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEE.h" /* Standard AEE declarations */
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEEFile.h" // File interface definitions
#include "AEENet.h" // Socket interface definitions
#include "AEESound.h" // Sound Interface definitions
#include "AEEMenu.h"
#include "AEEHtmlViewer.h"
#include "AEEText.h" /* AEE Text control */
#include "AEEWeb.h"
#include "AEEStdLib.h"
#include "downloadbmp.bid"
#include "downloadbmp.h"
#include "downloadbmp_res.h"
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean downloadbmp_HandleEvent(CDBApp * pApp, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
static void DB_NotifyCB( void* pvUser, HViewNotify* pNotify );
static void DB_GoTo(CDBApp *pApp, const char *pszURL);
static void StrReplace(char **ppsz, const char *pszNew);
static void DB_DisplayMenu(CDBApp* pApp, const char *pszURL);
static boolean DB_InitAppData(CDBApp * pApp);
static boolean DB_CreateMainControls( CDBApp* pApp );
static void WebAction_Start(WebAction *pwa, char *pszUrl);
static void WebAction_GotResp(void *p);
static void WebAction_Header(void *p, const char *cpszName, GetLine *pglVal);
static void WebAction_Status(void *p, WebStatus ws, void *pVal);
static void WebAction_Stop(WebAction *pwa);
static void WebAction_ReadLines(void *p);
static void ReleaseObj(void ** ppObj);
static void ND_Print(CDBApp *pApp, char *pszFmt, ...);
static void ND_StartTest(CDBApp* pApp, const char* pszSubmit);
static DB_WriteFile(CDBApp * pApp,char *file,int32 p,int32 length);
static boolean DB_LoadBMPFromBMPFile(CDBApp*pApp);
static void StartProgressDisplay(CDBApp *pApp);
/*===============================================================================
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)
{
CDBApp*pApp = NULL;
if(ClsId == AEECLSID_DOWNLOADBMP){
if(AEEApplet_New(sizeof(CDBApp), ClsId, pIShell,po,(IApplet**)ppObj,
(AEEHANDLER)downloadbmp_HandleEvent,NULL)
== TRUE)
{
pApp=(CDBApp*)*ppObj;
if(!DB_InitAppData(pApp))
{
IAPPLET_Release((IApplet*)pApp);
*ppObj = NULL;
return EFAILED;
}
// Add your code here .....
return (AEE_SUCCESS);
}
}
return (EFAILED);
}
/*===========================================================================
FUNCTION downloadbmp_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 downloadbmp_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 downloadbmp_HandleEvent(CDBApp * pApp, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
if (pApp->m_pIStatic && ISTATIC_HandleEvent(pApp->m_pIStatic, eCode, wParam, dwParam))
return TRUE;
if (IHTMLVIEWER_HandleEvent(pApp->m_pHTMLViewer, eCode, wParam, dwParam))
return TRUE;
switch (eCode)
{
case EVT_APP_START:
DB_GoTo(pApp,JUMP_MAIN);
// Add your code here .....
return(TRUE);
case EVT_APP_STOP:
// Add your code here .....
return TRUE;
default:
break;
}
return FALSE;
}
//HTMLVIER 回调函数
static void DB_NotifyCB( void* pvUser, HViewNotify* pNotify )
{
CDBApp* pApp = (CDBApp*) pvUser;
switch( pNotify->code )
{
case HVN_REDRAW_SCREEN:
IDISPLAY_ClearScreen(pApp->a.m_pIDisplay);
IHTMLVIEWER_Redraw(pApp->m_pHTMLViewer);
break;
case HVN_JUMP:
//网页中确定、提交按牛被按下
case HVN_SUBMIT:
pApp->m_nTotleTimes=0;
ND_StartTest(pApp,pNotify->u.jump.pszURL);
break;
case HVN_DONE:
IHTMLVIEWER_SetRect(pApp->m_pHTMLViewer, &pApp->m_nScreenRect);
IHTMLVIEWER_Redraw( pApp->m_pHTMLViewer );
break;
}
}
//
static void DB_GoTo(CDBApp *pApp, const char *pszURL)
{
int pos = pApp->m_cntHistory; // pos = number of hist entries = next history entry
if (pszURL == NULL) {
// go back
if (pos < 2)
return;
--pos;
pszURL = pApp->m_ppszHistory[pos-1]; // use 'top' entry
} else {
// add new entry to history
if (pos >= MAX_HIST)
return;
++pos;
StrReplace(&pApp->m_ppszHistory[pos-1], pszURL);
}
// Cleanup previous state
if (pApp->m_pfnViewCleanup) {
pApp->m_pfnViewCleanup = NULL;
}
// Activate appropriate state
pApp->m_cntHistory = pos;
if (STRBEGINS("test:", pszURL)) {
// read form data and begin test
ND_StartTest(pApp, pszURL);
} else /*if (STRBEGINS("file:", pszURL))*/ {
// read and display file
DB_DisplayMenu(pApp, pszURL);
}
}
static void StrReplace(char **ppsz, const char *pszNew)
{
FREE(*ppsz); // FREE(NULL) is okay in BREW
*ppsz = (pszNew ? STRDUP(pszNew) : (char*)pszNew);
}
static void DB_DisplayMenu(CDBApp* pApp, const char *pszURL)
{
IFile *pf;
const char *pszFileName = pszURL;
if (STRBEGINS("file:", pszFileName))
pszFileName += STRLEN("file:");
if (STRBEGINS("///", pszFileName))
pszFileName += STRLEN("///");
pf = IFILEMGR_OpenFile(pApp->m_pFileMgr, pszFileName, _OFM_READ);
if (pf) {
// Set the file from which the viewer will get its text
IHTMLVIEWER_LoadStream( pApp->m_pHTMLViewer, (IAStream*)pf);
// Release our reference to the file. (The HTML viewer is responsible for
// its own reference count while it uses the stream.)
IFILE_Release(pf);
} else {
// Set the file from which the viewer will get its text
IHTMLVIEWER_SetData( pApp->m_pHTMLViewer, "<h1>Error</h1>File Not Found", -1);
}
}
static boolean DB_InitAppData(CDBApp * pApp)
{
AEEDeviceInfo *pDeviceinfo;//定义设备信息变量
AEEImageInfo *pImage;
if(!DB_CreateMainControls(pApp))
{
return EFAILED;
}
pDeviceinfo=MALLOC(sizeof(AEEDeviceInfo));
//加载标题图象
pApp->m_nTotleTimes=0;
/*if((pApp->m_pTitleBarImg = ISHELL_LoadResImage(pApp->a.m_pIShell, CMYCITY_RES_FILE, IDB_TITLEBAR)) == NULL)
return FALSE;
pImage=MALLOC(sizeof(AEEImageInfo));
IIMAGE_GetInfo(pApp->m_pTitleBarImg,pImage);*/
pApp->m_nFontHeight=IDISPLAY_GetFontMetrics( pApp->a.m_pIDisplay, AEE_FONT_NORMAL, NULL, NULL ) + 1;
pApp->m_pProgressImages[PROG_PHONE] = NULL;
pApp->m_pProgressImages[PROG_FILE] = NULL;
pApp->m_pProgressImages[PROG_ANIM] = NULL;
//初始化动画,装载图象
if ((pApp->m_pProgressImages[PROG_PHONE] = ISHELL_LoadResImage(pApp->a.m_pIShell, DOWNLOADBMP_RES_FILE, IDB_PHONE))==NULL ||
(pApp->m_pProgressImages[PROG_FILE] = ISHELL_LoadResImage(pApp->a.m_pIShell, DOWNLOADBMP_RES_FILE, IDB_FILE))==NULL ||
(pApp->m_pProgressImages[PROG_ANIM] = ISHELL_LoadResImage(pApp->a.m_pIShell, DOWNLOADBMP_RES_FILE, IDB_ANIM))==NULL)
{
return FALSE;
}
//设置动画显示的参数
IIMAGE_SetParm(pApp->m_pProgressImages[PROG_ANIM], IPARM_NFRAMES, 4, 0);
IIMAGE_SetParm(pApp->m_pProgressImages[PROG_ANIM], IPARM_CXFRAME, 15, 0);
IIMAGE_SetParm(pApp->m_pProgressImages[PROG_ANIM], IPARM_RATE, 300, 0);
ISHELL_GetDeviceInfo(pApp->a.m_pIShell,pDeviceinfo);
ISHELL_RegisterHandler(pApp->a.m_pIShell,HTYPE_VIEWER,NULL,NULL);
SETAEERECT( &pApp->m_nScreenRect, 0, 0/*pImage->cy*/, pDeviceinfo->cxScreen, pDeviceinfo->cyScreen/* - pImage->cy*/ );
// 初始化IWeb借口
{
int i = 0;
WebOpt awo[10];
// set the IWeb connect timeout to 10 seconds. this also sets the
// failover timeout, if unset, or set to 0, IWeb uses the system
// default (30 seconds unless an OEM changes it)
awo[i].nId = WEBOPT_CONNECTTIMEOUT;
awo[i].pVal = (void *)100000;
i++;
// test user-agent, uncomment this section to ship your own user-agent
// string. if unset, IWeb will send a default. If set to NULL, no
// user agent header will be sent */
// Set TEST_USER_AGENT in the NetDiagnostics project settings to all
// shipping of your own user agent.
#ifdef TEST_USER_AGENT
awo[i].nId = WEBOPT_USERAGENT;
awo[i].pVal = (void *)WEBBER_USERAGENT;
i++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -