WindowStack.c
资源名称:MenuList.rar [点击查看]
上传用户:duwei1288
上传日期:2009-12-27
资源大小:451k
文件大小:4k
源码类别:
BREW编程
开发平台:
Visual C++
- #include "WindowStack.h"
- #include "IBookMark.h"
- #include "Push.h"
- #include "IHistory.h"
- #include "IInputWindow.h"
- #include "IMenuWindow.h"
- ////////////////defination of static var///////////////////////
- //定义一个窗口时,定义其相关函数然后在下面的数组中增加一条纪录
- static IWinFunctionDef atWinDef[]=
- {
- {WAPWINID_MAINMENU,IMENUWINDOW_Create,IMENUWINDOW_Release,IMENUWINDOW_Redraw,IMENUWINDOW_EventHandle},
- {WAPWINID_INPUT,IINPUTWINDOW_Create,IINPUTWINDOW_Release,IINPUTWINDOW_Redraw,IINPUTWINDOW_EventHandle},
- {WAPWINID_BOOKMARK,IBOOKMARKWIN_Create,IBOOKMARKWIN_Release,IBOOKMARKWIN_Redraw,IBOOKMARKWIN_EventHandle},
- {WAPWINID_PUSH,PUSHWIN_Create,PUSHWIN_Release,PUSHWIN_Redraw,NULL},
- {WAPWINID_HISTORY,HistoryWIN_Create,HistoryWIN_Release,HistoryWIN_Redraw,HISTORYWIN_EventHandle},
- {WAPWINID_NULL,NULL,NULL,NULL,NULL}
- };
- static IWindowStack* pWinStack=NULL;
- ////////////////declaration of static function///////////////////
- //将栈顶窗口出栈
- static boolean IWINSTACK_DestroyTopWin();
- //绘制栈顶窗口
- static boolean IWINSTACK_DrawWindow();
- //根据窗口ID得到窗口处理函数
- static IWinFunctionDef* IWINSTACK_GetWindow(TWindowID nWinID);
- ////////////////defination of interface function/////////////////
- boolean IWINSTACK_CreateInstance()
- {
- AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
- if(!pApp) return FALSE;
- //为窗口分配空间
- if(NULL==pWinStack)
- pWinStack=MALLOCREC(IWindowStack);
- if(NULL==pWinStack)
- return FALSE;
- //为栈分配空间
- pWinStack->m_pStack=ISTACK_CreateInstance();
- if(NULL==pWinStack->m_pStack)
- {
- FREEIF(pWinStack);
- return FALSE;
- }
- pWinStack->m_pShell=pApp->m_pIShell;
- return TRUE;
- }
- boolean IWINSTACK_Release()
- {
- if(pWinStack)
- {
- //释放栈的空间
- while(TRUE==IWINSTACK_DestroyTopWin());
- ISTACK_Release(&pWinStack->m_pStack);
- //释放窗口的空间
- FREE(pWinStack);
- pWinStack=NULL;
- }
- return TRUE;
- }
- boolean IWINSTACK_HandleEvent(AEEEvent eCode, uint16 wParam, uint32 dwParam)
- {
- TWinElement* pWin;
- IWinFunctionDef* pFunc;
- if(!pWinStack||!pWinStack->m_pStack)
- return FALSE;
- //得到栈顶窗口ID
- pWin=ISTACK_GetTopElement(pWinStack->m_pStack);
- if(!pWin) return FALSE;
- //根据ID得到窗口处理函数
- pFunc=IWINSTACK_GetWindow(pWin->nWinID);
- //执行事件处理函数
- if(pFunc&&pFunc->pEventHdl)
- return pFunc->pEventHdl(pWin->m_pWin,eCode,wParam,dwParam);
- return FALSE;
- }
- boolean IWINSTACK_OpenWindow(TWindowID nWinID,void* pParam)
- {
- TWinElement* pWin;
- IWinFunctionDef* pFunc;
- if(!pWinStack)
- if(!IWINSTACK_CreateInstance())
- return FALSE;
- //查找与窗口相关的处理函数
- pFunc=IWINSTACK_GetWindow(nWinID);
- if(!pFunc||!pFunc->pCreate)
- return FALSE;
- //创建窗口资源并入栈
- pWin=MALLOCREC(TWinElement);
- if(!pWin) return FALSE;
- pWin->m_pWin=pFunc->pCreate(pWinStack->m_pShell,pParam);
- pWin->nWinID=nWinID;
- if(!pWin->m_pWin)
- {
- FREE(pWin);
- return FALSE;
- }
- if(!ISTACK_PushOnStack(pWinStack->m_pStack,pWin))
- {
- if(pFunc->pRelease)
- pFunc->pRelease(pWinStack->m_pShell,&pWin->m_pWin);
- FREE(pWin);
- return FALSE;
- }
- //绘制栈顶窗口
- return IWINSTACK_DrawWindow();
- }
- boolean IWINSTACK_CloseWindow(boolean bRedraw)
- {
- //栈顶窗口出栈
- IWINSTACK_DestroyTopWin();
- //绘制当前栈顶窗口
- if(bRedraw)
- IWINSTACK_DrawWindow();
- return TRUE;
- }
- ////////////////defination of static function/////////////////
- static boolean IWINSTACK_DestroyTopWin()
- {
- TWinElement* pWin;
- IWinFunctionDef* pFunc;
- if(NULL==pWinStack)
- return FALSE;
- //将栈顶指针出栈
- pWin=ISTACK_PopFromStack(pWinStack->m_pStack);
- if(NULL==pWin)
- return FALSE;
- //释放出栈的栈顶窗口的资源
- pFunc=IWINSTACK_GetWindow(pWin->nWinID);
- if(NULL==pFunc)
- return FALSE;
- if(pFunc->pRelease)
- pFunc->pRelease(pWinStack->m_pShell,&pWin->m_pWin);
- //释放栈顶窗口的空间
- FREEIF(pWin);
- return TRUE;
- }
- static IWinFunctionDef* IWINSTACK_GetWindow(TWindowID nWinID)
- {
- int nLoop=0;
- while(WAPWINID_NULL!=atWinDef[nLoop].nWinID)
- {
- if(nWinID==atWinDef[nLoop].nWinID)
- return atWinDef+nLoop;
- else
- nLoop++;
- }
- return NULL;
- }
- static boolean IWINSTACK_DrawWindow()
- {
- TWinElement* pWin;
- IWinFunctionDef* pFunc;
- if(NULL==pWinStack)
- return FALSE;
- //得到栈顶窗口
- pWin=ISTACK_GetTopElement(pWinStack->m_pStack);
- if(NULL==pWin)
- return FALSE;
- //得到栈顶窗口的处理函数
- pFunc=IWINSTACK_GetWindow(pWin->nWinID);
- if(NULL==pFunc)
- return FALSE;
- //绘制栈顶窗口
- if(pFunc->pRedraw)
- return pFunc->pRedraw(pWinStack->m_pShell,pWin->m_pWin);
- return FALSE;
- }