MenuStack.c
资源名称:MenuList.rar [点击查看]
上传用户:duwei1288
上传日期:2009-12-27
资源大小:451k
文件大小:4k
源码类别:
BREW编程
开发平台:
Visual C++
- #include "MenuStack.h"
- #include "MenuList.brh"
- #include "AEEModGen.h"
- #include "AEEAppGen.h"
- /////////////////////////////////////////////////////////////
- static boolean IMENUSTACK_MoveIntoSubMenu(IMenuStack* pStack);
- /////////////////////////////////////////////////////////////
- IMenuStack* IMENUSTACK_CreateInstance(TMenuItem* pItem,PFNMENUREDRAWHDL *pRedrawCb,PFNGETSELITEM *pGetSelCb)
- {
- IMenuStack* pStack=NULL;
- AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
- if(!pApp)
- return NULL;
- pStack=MALLOCREC(IMenuStack);
- if(!pStack)
- return NULL;
- pStack->m_pStack=ISTACK_CreateInstance();
- if(!pStack->m_pStack)
- {
- IMENUSTACK_Release(&pStack);
- return NULL;
- }
- if(SUCCESS!=ISHELL_CreateInstance(pApp->m_pIShell,AEECLSID_MENUCTL,(void**)&pStack->m_pCtl))
- {
- IMENUSTACK_Release(&pStack);
- return NULL;
- }
- pStack->m_pGetSelCb=pGetSelCb;
- pStack->m_pRedrawCb=pRedrawCb;
- ISTACK_PushOnStack(pStack->m_pStack,(void*)pItem);
- return pStack;
- }
- void IMENUSTACK_Release(IMenuStack** pStack)
- {
- if(*pStack)
- {
- if((*pStack)->m_pCtl)
- IMENUCTL_Release((*pStack)->m_pCtl);
- ISTACK_Release(&(*pStack)->m_pStack);
- FREEIF(*pStack);
- }
- }
- boolean IMENUSTACK_Redraw(IMenuStack* pStack)
- {
- int nLoop=0;
- uint16 uiSel=0;
- CtlAddItem ai;
- TMenuItem* pMenu;
- if((!pStack)||(!pStack->m_pCtl))
- return FALSE;
- IMENUCTL_DeleteAll(pStack->m_pCtl);
- pMenu=(TMenuItem*)ISTACK_GetTopElement(pStack->m_pStack);
- if(!pMenu)
- return FALSE;
- ai.pImage = NULL;
- while(MENUITEM_NULL!=pMenu[nLoop].tItemId)
- {
- if(pStack->m_pRedrawCb)
- ai.pText = pStack->m_pRedrawCb(pMenu[nLoop].uiResourceId);
- else
- ai.pText = NULL;
- ai.wImage = pMenu[nLoop].tImageId;
- ai.wText = pMenu[nLoop].uiResourceId;
- ai.wItemID = pMenu[nLoop].tItemId;
- ai.wFont = AEE_FONT_NORMAL;
- if(ai.wImage)
- ai.pszResImage = MENULIST_RES_FILE;
- else
- ai.pszResImage = NULL;
- ai.pszResText = MENULIST_RES_FILE;
- IMENUCTL_AddItemEx(pStack->m_pCtl, &ai);
- FREEIF(ai.pText);
- nLoop++;
- }
- if(pStack->m_pGetSelCb)
- {
- uiSel=pStack->m_pGetSelCb(pMenu);
- if(uiSel>0)
- IMENUCTL_SetSel(pStack->m_pCtl,uiSel);
- }
- IMENUCTL_SetActive(pStack->m_pCtl,TRUE);
- IMENUCTL_Redraw(pStack->m_pCtl);
- return TRUE;
- }
- boolean IMENUSTACK_HandleEvent(IMenuStack* pStack,AEEEvent eCode,uint16 wParam,uint32 dwParam)
- {
- if(!pStack||!pStack->m_pCtl)
- return FALSE;
- switch(eCode)
- {
- case EVT_KEY:
- if(AVK_CLR==wParam)
- {
- ISTACK_PopFromStack(pStack->m_pStack);
- return IMENUSTACK_Redraw(pStack);
- }
- else
- return IMENUCTL_HandleEvent(pStack->m_pCtl,eCode,wParam,dwParam);
- case EVT_COMMAND:
- return IMENUSTACK_MoveIntoSubMenu(pStack);
- default:
- return FALSE;
- }
- }
- //////////////////////////////////////////////////////////////////////////////
- static boolean IMENUSTACK_MoveIntoSubMenu(IMenuStack* pStack)
- {
- TMenuItem* pList;
- TMenuItemId itemId;
- int SeekLoop=0;
- if(!pStack)
- return FALSE;
- itemId=IMENUCTL_GetSel(pStack->m_pCtl);
- pList=(TMenuItem*)ISTACK_GetTopElement(pStack->m_pStack);
- if(!pList)
- return FALSE;
- while((itemId!=pList[SeekLoop].tItemId)&&
- (MENUITEM_NULL!=pList[SeekLoop].tItemId))
- SeekLoop++;
- if(MENUITEM_NULL==pList[SeekLoop].tItemId)
- return FALSE;
- if(pList[SeekLoop].ChildFunc)
- if(FALSE==pList[SeekLoop].ChildFunc())
- return FALSE;
- if(!pList[SeekLoop].ptChildMenu)
- return FALSE;
- if(!ISTACK_PushOnStack(pStack->m_pStack,(void*)pList[SeekLoop].ptChildMenu))
- return FALSE;
- return IMENUSTACK_Redraw(pStack);
- }