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

📄 category.cpp

📁 联通手机的宝典画面.用brew 平台编辑而成.
💻 CPP
字号:
// ContentList.cpp: implementation of the CContentList class.
//
//////////////////////////////////////////////////////////////////////

#include "Category.h"
#include "wk_BaseFunc.h"
#include "ContentList.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CCategory::CCategory()
{

}

CCategory::~CCategory()
{

}

void CCategory::Init(AECHAR * szName, long nID, XFRAMEINFO * pInfo)
{
	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_pList			= NULL;
	m_pCategory		= NULL;
    m_pIStatic		= NULL;

	m_nType	= TYPE_CATEGORY;
	m_nSelect		= 0;
	m_bRelease	= TRUE;
}

void CCategory::Release()
{
	ClearScreen();

    if (m_szName) FREEIF(m_szName);
    if (m_szReceiveData) FREEIF(m_szReceiveData);
    if (m_szPostData) FREEIF(m_szPostData);

	if (m_pObject)
	{
		m_pObject->Release();
		delete m_pObject;
		m_pObject = NULL;
	}

	if (m_pList)
	{
		ReleaseNode(m_pList);
		m_pList = NULL;
	}

	m_bRelease	= TRUE;
}

void CCategory::Suspend()
{
	if (m_pObject)
	{
		m_pObject->Suspend();
	}
	else
	{
		if(m_pIStatic)
			ISTATIC_SetActive(m_pIStatic,FALSE);
		else
			ClearScreen();
	}
}

void CCategory::Resume()
{
	if (m_pObject)
	{
		m_pObject->Resume();
	}
	else
	{
		if(m_pIStatic)
		{
			ISTATIC_SetActive(m_pIStatic,TRUE);
			ISTATIC_Redraw(m_pIStatic);
		}
		else
		{
			ClearScreen();
			Display();
		}
	
	}
}

void CCategory::Create()
{
	// 传送目录请求信息
	long	  nLength;
	long	  nIndex;
	long	  nValue;
	long	  nTotal, nChunk1, nChunk2;
    char	  szPrefix[] = {'W', 'X', 'F', 'Z', '\0'};

	m_bRelease	= FALSE;
	// 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;	// is first login
	nChunk1 = m_nBufferLength - nChunk1;

	m_nBufferLength += 4;	// REQUESTTYPE
	m_nBufferLength += 4;	// Size
	nChunk2 = m_nBufferLength;
	m_nBufferLength += 4;	// CategoryType
	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_CONTENT_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 = 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_CATEGORY;
	MEMCPY(m_szPostData + nIndex, &nValue, nLength);
	// Chunk size
	nIndex += nLength;
	nLength = 4;
	nValue = nChunk2;
	MEMCPY(m_szPostData + nIndex, &nValue, nLength);
	// REQUESTTYPE
	nIndex += nLength;
	nLength = 4;
	nValue = CATEGORY_ROOT;
	MEMCPY(m_szPostData + nIndex, &nValue, nLength);

	// 发送请求信息
	m_pNetWork->PostData(m_szPostData, m_nBufferLength, (CObject *)this);
	m_nBufferLength = 0;
}

boolean	CCategory::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;
	}

	switch(evt)
	{
		//Key handler
		case EVT_KEY:
		//case EVT_KEY_PRESS:	
			if (wParam == AVK_CLR)
			{
				if (m_pCategory)
				{// 回到上级目录菜单
					m_pCategory = m_pCategory->pParent;
					
					ClearScreen();
					Display();
				}
				else
				{// 回到根目录
					Release();
				}
				status = TRUE;
			}
			else if (m_pMenu)
			{
				if (IMENUCTL_HandleEvent(m_pMenu, evt, wParam, dwParam))
					status = TRUE;
			}
			break;
		case EVT_COMMAND:
			Browse(wParam);
			break;
	}

	return status;
}

void CCategory::Browse(uint16 nID)
{
	XFRAMEINFO	xFrame;
	CtlAddItem pMenu; 
	XNODE * pNode = NULL;

	if (m_pMenu == NULL) return;
	if (m_pList == NULL) return;

	if (!IMENUCTL_GetItem(m_pMenu, nID, &pMenu))
		return;

	// 查找节点
	if (m_pCategory)
		pNode = m_pCategory->pDown;
	else
		pNode = m_pList;
	while (pNode)
	{
		if (pNode->nID == nID)
			break;
		else
			pNode = pNode->pNext;
	}
	
	if (pNode->pDown)
	{// 浏览子目录
		m_pCategory = pNode;

		ClearScreen();
		Display();
	}
	else
	{// 浏览内容
		xFrame.pApplet		= m_pApplet;
		xFrame.pDevice		= m_pDevice;
		xFrame.pNetWork		= (void *)m_pNetWork;
		xFrame.szMobile		= m_szMobile;
		xFrame.szMobileType	= m_szMobileType;

		m_pObject = new CContentList;
		m_pObject->Init((AECHAR *)pMenu.pText, nID, &xFrame);
		m_pObject->Create();
			m_nSelect=nID;
		ClearScreen();
	}
}

void CCategory::Construct(char * szBuffer, long nBufferLength)
{
	long	nIndex;
	long	cstLong;
	long	nPostType, nValue;

    IDISPLAY_ClearScreen(m_pApplet->m_pIDisplay);

	if ((nBufferLength <= 0) || (szBuffer == NULL))
		return;


	// read head info
	nIndex	= 0;
	cstLong = 4;

	// prifix
	nIndex = 4;

	// total size
	MEMCPY(&nValue, szBuffer + nIndex, 4);
	nIndex += 4;

	// post type
	MEMCPY(&nPostType, szBuffer + nIndex, 4);
	nIndex += 4;

	// number of Chunks
	MEMCPY(&nValue, szBuffer + nIndex, 4);
	nIndex += 4;

	// chunkID
	MEMCPY(&nValue, szBuffer + nIndex, 4);
	nIndex += 4;

	// chunkSize
	MEMCPY(&nValue, szBuffer + nIndex, 4);
	nIndex += 4;

	// read text from buffer and add menu item
	if (nPostType == REQUEST_CATEGORY)
	{// 目录结构
		m_nBufferLength = nBufferLength - nIndex;		
		if (m_szReceiveData) FREEIF(m_szReceiveData);
		m_szReceiveData = (char *)MALLOC(m_nBufferLength);
		if (m_szReceiveData == NULL)
		{
			ClearScreen();
			ShowResString(m_pApplet->m_pIShell, &m_pIStatic, &m_rcScreen, m_szName, IDS_CONTENT_NONE);
			return;
		}

		MEMCPY(m_szReceiveData, szBuffer + nIndex, m_nBufferLength);

		ConstructList();
		Display();
	}

    return;
}

void CCategory::Display()
{
	XNODE * pNode = NULL;

//	if (m_pList == NULL) return;
	IDISPLAY_ClearScreen(m_pApplet->m_pIDisplay);
	
	ISHELL_CreateInstance(m_pApplet->m_pIShell, AEECLSID_MENUCTL, (void **) &m_pMenu);
	if (m_pMenu == NULL)
	{
		ShowResString(m_pApplet->m_pIShell, &m_pIStatic, &m_rcScreen, m_szName, IDS_ERR_MEM);
		return;
	}
	
	{
		// 设置菜单和图片位置
		AEERect	 rect;

		rect.x  = 0;
		rect.y	= LOGO_HEIGHT;
		rect.dx	= m_pDevice->cxScreen;
		rect.dy	= m_pDevice->cyScreen - LOGO_HEIGHT - BOTTOM_MARGIN;

		IMENUCTL_SetRect(m_pMenu,&rect);
	}

	// set menu title
	if (m_pCategory == NULL)
	{
		IMENUCTL_SetTitle(m_pMenu, RES_FILE, NULL, m_szName);
		pNode = m_pList;
	}
	else
	{
		IMENUCTL_SetTitle(m_pMenu, RES_FILE, NULL, m_pCategory->szName);
		pNode = m_pCategory->pDown;
	}

	while (pNode)
	{
		AddMenuItem(m_pMenu, 0, pNode->szName, BM_FOLDER_ICON, (uint16)pNode->nID, 0);

		pNode = pNode->pNext;
	}


	// implementation of lightening of main menu background color
	{
		AEEMenuColors colors;
		colors.wMask = MC_BACK | MC_SEL_BACK /*| MC_TITLE | MC_TITLE_TEXT*/;
		colors.cBack = MAKE_BACK_COLOR;	
		colors.cSelBack = MAKE_SEL_COLOR;
	//	colors.cTitle  = MAKE_RGB(0xff, 0x00, 0x00);	
	//	colors.cTitleText  = MAKE_RGB(0x00, 0xff, 0x00);
		IMENUCTL_SetColors(m_pMenu, &colors);
	}
	// end of lightening of main menu background color
	IMENUCTL_SetSel(m_pMenu,(uint16)m_nSelect);
	IMENUCTL_EnableCommand(m_pMenu, true);
	IMENUCTL_SetActive(m_pMenu, true); 
}

void CCategory::ClearScreen()
{
	if(m_pIStatic)
		ReleaseObj((void * *)&m_pIStatic);
	m_pIStatic=NULL;

    if (m_pMenu)
    {
        IMENUCTL_SetActive(m_pMenu, false);
        IMENUCTL_Release(m_pMenu);
    }
    m_pMenu = NULL;
}

void CCategory::ConstructList()
{
	long nIndex = 0, nFirstCategory, cstLong = 4;
	XNODE * pBrother = NULL;

	if ((m_szReceiveData == NULL) || m_nBufferLength == 0) return;

	// 先清除以前的目录
	if (m_pList)
	{
		ReleaseNode(m_pList);
		m_pList = NULL;
	}

	// 构造目录
	// read number of first category
	MEMCPY(&nFirstCategory, m_szReceiveData + nIndex, cstLong);
	nIndex += cstLong;

	while (nIndex < m_nBufferLength)
	{
		XNODE * pNode = ConstructNode(nIndex);
		if (pNode)
		{
			if(m_pList == NULL)
				m_pList = pNode;
			else
				pBrother->pNext = pNode;

			pBrother = pNode;
		}
	}

	// 清除变量
	FREEIF(m_szReceiveData);
	m_szReceiveData = NULL;
	m_nBufferLength = 0;
	m_pCategory		= NULL;
}

XNODE* CCategory::ConstructNode(long &nIndex)
{
	long cstLong = 4;
	XNODE * pNode = NULL;

	// 构造目录
	if (nIndex < m_nBufferLength)
	{
		long nType, nNumber, nLen;
		AECHAR * szMenu = NULL;
		XNODE * pNext = NULL;

		// read Name
		szMenu = (AECHAR * )(m_szReceiveData + nIndex);
		nLen = sizeof(AECHAR) * (WSTRLEN(szMenu) + 1);
		nIndex += nLen;
		if (nIndex > m_nBufferLength) return NULL;

		// read ID
		MEMCPY(&nType, m_szReceiveData + nIndex, cstLong);
		nIndex += cstLong;
		if (nIndex > m_nBufferLength) return NULL;

		// read Number
		MEMCPY(&nNumber, m_szReceiveData + nIndex, cstLong);
		nIndex += cstLong;
		if (nIndex > m_nBufferLength) return NULL;

		// 创建节点
		pNode = new XNODE;
		if (pNode == NULL) return NULL;

		pNode->szName = (AECHAR *)MALLOC(nLen);
		if (pNode->szName == NULL)
		{
			delete pNode;
			return NULL;
		}
		MEMCPY(pNode->szName, szMenu, nLen);
		pNode->nID = nType;
		pNode->pNext = NULL;
		pNode->pParent= NULL;
		pNode->pDown = NULL;

		// 创建子节点
		while (nNumber > 0)
		{
			XNODE * pChild = ConstructNode(nIndex);

			if (pChild)
			{
				pChild->pParent = pNode;
				if (pNode->pDown == NULL)
					pNode->pDown = pChild;

				if (pNext)
					pNext->pNext = pChild;

				pNext = pChild;
			}
			nNumber--;
		}
	}

	return pNode;
}

void CCategory::ReleaseNode(XNODE* pNode)
{
	if (pNode)
	{
		XNODE * pNext = pNode->pNext;
		XNODE * pDown = pNode->pDown;

		if (pNode->szName) FREEIF(pNode->szName);
		delete pNode;

		ReleaseNode(pNext);
		ReleaseNode(pDown);
	}
}

⌨️ 快捷键说明

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