📄 searchcontent.cpp
字号:
// SearchContent.cpp: implementation of the CSearchContent class.
//
//////////////////////////////////////////////////////////////////////
#include "SearchContent.h"
#include "wk_BaseFunc.h"
#include "SmsText.h"
#include "media.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CSearchContent::CSearchContent()
{
}
CSearchContent::~CSearchContent()
{
}
void CSearchContent::Init(AECHAR * szName, long nID, XFRAMEINFO * pInfo)
{
m_nID = nID;
if (szName)
{
long nLen = sizeof(AECHAR) * (WSTRLEN(szName) + 1);
m_szName = (AECHAR *)MALLOC(nLen);
if (m_szName)
MEMCPY(m_szName, szName, nLen);
}
else
m_szName = NULL;
m_pApplet = pInfo->pApplet;
m_pDevice = pInfo->pDevice;
m_pNetWork = (CNetWork *)pInfo->pNetWork;
m_szMobile = pInfo->szMobile;
m_szMobileType = pInfo->szMobileType;
m_rcScreen.x = 0;
m_rcScreen.y = 0;
m_rcScreen.dx = m_pDevice->cxScreen;
m_rcScreen.dy = m_pDevice->cyScreen;
m_szReceiveData = NULL;
m_szPostData = NULL;
m_nBufferLength = 0;
m_pMenu = NULL;
m_pObject = NULL;
m_pIText = NULL;
m_pIStatic = NULL;
m_nPageIndex = 0;
m_nMenuCount = 0;
m_nState = STATE_INPUT_TEXT;
m_szSearchContent = NULL;
m_nType = TYPE_SEARCH;
m_bRelease = TRUE;
}
void CSearchContent::Release()
{
ClearScreen();
if (m_szName) FREEIF(m_szName);
if (m_szReceiveData) FREEIF(m_szReceiveData);
if (m_szPostData) FREEIF(m_szPostData);
if (m_szSearchContent) FREEIF(m_szSearchContent);
if (m_pObject)
{
m_pObject->Release();
delete m_pObject;
m_pObject = NULL;
}
m_bRelease = TRUE;
}
void CSearchContent::Suspend()
{
if (m_pObject)
{
m_pObject->Suspend();
}
else
{
if(m_pIStatic)
{
ISTATIC_SetActive(m_pIStatic,FALSE);
}
else
{
if (m_nState == STATE_INPUT_TEXT && m_pIText)
{// 备份文本
AECHAR buf[100];
int nTemp;
MEMSET(buf, 0, sizeof(buf));
ITEXTCTL_GetText(m_pIText, buf, sizeof(buf)) ;
if (m_szSearchContent) FREEIF(m_szSearchContent);
nTemp = (WSTRLEN(buf) + 1) * sizeof(AECHAR);
m_szSearchContent = (AECHAR *) MALLOC(nTemp);
if (m_szSearchContent == NULL)
{
ClearScreen();
// ShowResString(m_pApplet->m_pIShell, &m_pIStatic, &m_rcScreen, m_szName, IDS_ERR_SPACE);
return;
}
MEMCPY(m_szSearchContent, buf, nTemp);
}
ClearScreen();
}
}
}
void CSearchContent::Resume()
{
if (m_pObject)
{
m_pObject->Resume();
}
else
{
if(m_pIStatic)
{
ISTATIC_SetActive(m_pIStatic,TRUE);
ISTATIC_Redraw(m_pIStatic);
}
else
{
ClearScreen();
Display();
}
}
}
void CSearchContent::Create()
{
m_nState = STATE_INPUT_TEXT;
Display();
m_nType = TYPE_SEARCH;
}
void CSearchContent::PostRequest()
{
// 传送搜索请求信息
long nLength;
long nIndex;
long nValue;
long nTotal, nChunk1, nChunk2;
char szPrefix[] = {'W', 'X', 'F', 'Z', '\0'};
// APPID + VERSION + SZMOBILE + SZMOBILETYPE + REQUESTTYPE
// 计算发送请求的总长度
m_nBufferLength = 0;
nLength = STRLEN(szPrefix); // prifix
m_nBufferLength += sizeof(char) * (nLength);
m_nBufferLength += 4; // APPID
m_nBufferLength += 4; // VERSION
m_nBufferLength += 4; // TotalSize
m_nBufferLength += 4; // Number of Chunks
m_nBufferLength += 4; // REQUESTTYPE
m_nBufferLength += 4; // Size
nChunk1 = m_nBufferLength;
nLength = WSTRLEN(m_szMobile) + 1; // SZMOBILE
m_nBufferLength += sizeof(AECHAR) * (nLength);
nLength = WSTRLEN(m_szMobileType) + 1; // SZMOBILETYPE
m_nBufferLength += sizeof(AECHAR) * (nLength);
m_nBufferLength += 4;
nChunk1 = m_nBufferLength - nChunk1;
m_nBufferLength += 4; // REQUESTTYPE
m_nBufferLength += 4; // Size
nChunk2 = m_nBufferLength;
m_nBufferLength += 4; // CategoryID
nLength = WSTRLEN(m_szSearchContent) + 1; // keyword
m_nBufferLength += sizeof(AECHAR) * (nLength);
nChunk2 = m_nBufferLength - nChunk2;
nTotal = m_nBufferLength;
if (m_szPostData)
FREEIF(m_szPostData);
m_szPostData = (char *) MALLOC(m_nBufferLength);
if (m_szPostData == NULL)
{
ClearScreen();
// ShowResString(m_pApplet->m_pIShell, &m_pIStatic, &m_rcScreen, m_szName, IDS_SEARCH_NONE);
return;
}
nIndex = 0;
// Prefix
nLength = sizeof(char) * (STRLEN(szPrefix));
MEMCPY(m_szPostData + nIndex, szPrefix, nLength);
// APPID
nIndex += nLength;
nLength = 4;
nValue = APPID;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// VERSION
nIndex += nLength;
nLength = 4;
nValue = VERSION;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// Total size
nIndex += nLength;
nLength = sizeof(long);
nLength = 4;
nValue = nTotal;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// number of chunks
nIndex += nLength;
nLength = 4;
nValue = 2;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// Chunk type
nIndex += nLength;
nLength = 4;
nValue = REQUEST_ACCOUNT;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// Chunk size
nIndex += nLength;
nLength = 4;
nValue = nChunk1;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// MOBILE
nIndex += nLength;
nLength = sizeof(AECHAR) * (WSTRLEN(m_szMobile) + 1);
MEMCPY(m_szPostData + nIndex, m_szMobile, nLength);
// MOBILETYPE
nIndex += nLength;
nLength = sizeof(AECHAR) * (WSTRLEN(m_szMobileType) + 1);
MEMCPY(m_szPostData + nIndex, m_szMobileType, nLength);
//login
nIndex += nLength;
nLength = 4;
if(m_pNetWork->m_bFirst)
nValue=1;
else
nValue=0;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// Chunk type
nIndex += nLength;
nLength = 4;
nValue = REQUEST_SEARCH;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// Chunk size
nIndex += nLength;
nLength = 4;
nValue = nChunk2;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// categoryID
nIndex += nLength;
nLength = 4;
nValue = m_nID;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
//keyword
nIndex += nLength;
nLength = sizeof(AECHAR) * (WSTRLEN(m_szSearchContent) + 1);
MEMCPY(m_szPostData + nIndex, m_szSearchContent, nLength);
// 发送请求信息
m_pNetWork->PostData(m_szPostData, m_nBufferLength, (CObject *)this);
}
boolean CSearchContent::KeyHandle(AEEEvent evt, uint16 wParam, uint32 dwParam)
{
boolean status = FALSE;
if (m_pObject)
{
status = m_pObject->KeyHandle(evt, wParam, dwParam);
if (m_pObject->m_bRelease)
{
delete m_pObject;
m_pObject = NULL;
Display();
}
return status;
}
// 把文本输入的方法单独提出来处理
if(TEXT_INPUT_PRESS)
{
if (m_nState == STATE_INPUT_TEXT)
{
if (m_pIText && ITEXTCTL_IsActive(m_pIText))
{
if ((evt == EVT_KEY) && (wParam == AVK_SELECT))
{
if(ITEXTCTL_HandleEvent(m_pIText, evt, wParam, dwParam))
status= TRUE;
else if(m_pISoftKey)
IMENUCTL_SetActive(m_pISoftKey,true);
}
else
{
ITEXTCTL_HandleEvent(m_pIText, evt, wParam, dwParam);
}
return TRUE;
}
}
}
switch(evt)
{
//Key handler
case EVT_KEY:
//case EVT_KEY_PRESS:
if (m_nState == STATE_INPUT_TEXT)
{
if (wParam == AVK_CLR)
{
AECHAR buf[100];
MEMSET(buf, 0, sizeof(buf));
if (m_pIText != NULL)
ITEXTCTL_GetText(m_pIText, buf, sizeof(buf)) ;
if(WSTRLEN(buf) > 0)
{
ITEXTCTL_SetActive(m_pIText,true);
if(m_pISoftKey != NULL)
IMENUCTL_SetActive(m_pISoftKey,false);
ITEXTCTL_HandleEvent(m_pIText, evt, wParam, dwParam);
}
else
Release();
status = TRUE;
}
else if (m_pIText)
{
if (wParam == AVK_SELECT)
{
if (ITEXTCTL_IsActive(m_pIText))
{
if(ITEXTCTL_HandleEvent(m_pIText, evt, wParam, dwParam))
status= TRUE;
else if(m_pISoftKey)
IMENUCTL_SetActive(m_pISoftKey,true);
}
else if(m_pISoftKey != NULL &&IMENUCTL_IsActive(m_pISoftKey))
{
IMENUCTL_HandleEvent(m_pISoftKey, EVT_KEY, wParam, dwParam);
{
//由菜单控件处理的事件
status = TRUE;
}
}
else
{
ITEXTCTL_SetActive(m_pIText,true);
ITEXTCTL_HandleEvent(m_pIText, evt, wParam, dwParam);
status = TRUE;
}
}
else if(wParam==AVK_LEFT||wParam==AVK_RIGHT)
{
if(ITEXTCTL_IsActive(m_pIText))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -