IHistory.c
资源名称:MenuList.rar [点击查看]
上传用户:duwei1288
上传日期:2009-12-27
资源大小:451k
文件大小:5k
源码类别:
BREW编程
开发平台:
Visual C++
- #include "IHistory.h"
- #include "AeeFile.h"
- #include "AEEAppGen.h"
- #include "WindowStack.h"
- #include "MenuList_res.h"
- /////////////////////////Static Function//////////////////////
- static boolean HISTORYWIN_HandleKeyEvent(IHistoryWin* pWin,uint16 wParam);
- #define WAP_HISTORY_FILENAME "MenuList/history.dat"
- //窗口的控件
- typedef enum
- {
- INPUT_SOFTKEYCTL=0,
- INPUT_MENUCTL
- }THistoryWinCtlType;
- //软键控件的ItemId定义
- typedef enum
- {
- INPUT_SOFTKEY_ITEM = 1,
- INPUT_SOFTKEY_ITEM_GOTO,
- INPUT_SOFTKEY_ITEM_EDIT,
- INPUT_SOFTKEY_ITEM_NEW,
- INPUT_SOFTKEY_ITEM_DEL
- }THistoryWinItems;
- //按键事件的处理
- //static boolean IINPUTWINDOW_HandleKeyEvent(IInputWin* pWin,uint16 wParam);
- //软键菜单的处理
- //static boolean IINPUTWINDOW_HandleCommandEvent(IInputWin* pWin,uint16 wParam);
- //设置窗口中控件的激活状态
- //static boolean IINPUTWINDOW_SetActiveCtl(IInputWin* pWin,TInputCtlType nTextCtl);
- /////////////////////////Public Function//////////////////////
- boolean HistoryDlg()
- {
- AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
- AEERect MenuRect;
- AEERect SoftRect;
- IFile *pIFile;
- IFileMgr *pIFileMgr = NULL;
- IHistoryWin *ptHistoryWin = (IHistoryWin *)MALLOC(sizeof(IHistoryWin));
- //AEERect m_rc;
- if (NULL == ptHistoryWin)
- return FALSE;
- ISHELL_CreateInstance(pApp->m_pIShell, AEECLSID_MENUCTL, (void **)&(ptHistoryWin->m_pMenuCtl));
- if(SUCCESS!=ISHELL_CreateInstance(pApp->m_pIShell,AEECLSID_SOFTKEYCTL,(void **)&(ptHistoryWin->m_pSoftKeyCtl)))
- {
- HistoryWIN_Release(pApp->m_pIShell,&ptHistoryWin);
- return FALSE;
- }
- IMENUCTL_AddItem(ptHistoryWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_GOTO,INPUT_SOFTKEY_ITEM_GOTO, NULL, 0);
- IMENUCTL_AddItem(ptHistoryWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_DEL,INPUT_SOFTKEY_ITEM_DEL, NULL, 0);
- IMENUCTL_GetRect(ptHistoryWin->m_pMenuCtl, &MenuRect);
- IMENUCTL_GetRect(ptHistoryWin->m_pSoftKeyCtl, &SoftRect);
- MenuRect.dy = (int16)(SoftRect.y);
- IMENUCTL_SetRect(ptHistoryWin->m_pMenuCtl, &MenuRect);
- if(SUCCESS!=ISHELL_CreateInstance(pApp->m_pIShell,AEECLSID_FILEMGR,(void **)&pIFileMgr))
- {
- HistoryWIN_Release(pApp->m_pIShell,&ptHistoryWin);
- return FALSE;
- }
- if (IFILEMGR_Test(pIFileMgr, WAP_HISTORY_FILENAME) == EFAILED) {
- pIFile = IFILEMGR_OpenFile(pIFileMgr, WAP_HISTORY_FILENAME, _OFM_CREATE);
- }
- else {
- if ((pIFile = IFILEMGR_OpenFile(pIFileMgr, WAP_HISTORY_FILENAME, _OFM_READWRITE)) == NULL) {
- IFILEMGR_Release(pIFileMgr);
- // free menus here
- return FALSE;
- }
- //ReadBookmarks(pIFileMgr, pIFile, ptBookmarkWin);
- }
- //IMENUCTL_SetActive(ptHistoryWin->m_pMenuCtl,TRUE);
- IMENUCTL_SetActive(ptHistoryWin->m_pSoftKeyCtl,TRUE);
- return IWINSTACK_OpenWindow(WAPWINID_HISTORY, ptHistoryWin);
- }
- void* HistoryWIN_Create(IShell* pShell,void* pParam)
- {
- pShell=pShell;
- return pParam;
- }
- boolean HistoryWIN_Release(IShell* pShell,void** pWin)
- {
- IHistoryWin* pHistoryWin=*pWin;
- if(pHistoryWin)
- {
- if(pHistoryWin->m_pSoftKeyCtl)
- IMENUCTL_Release(pHistoryWin->m_pSoftKeyCtl);
- if(pHistoryWin->m_pMenuCtl)
- IMENUCTL_Release(pHistoryWin->m_pMenuCtl);
- FREEIF(*pWin);
- }
- return TRUE;
- }
- boolean HistoryWIN_Redraw(IShell* pShell,void* pWin)
- {
- IHistoryWin* pHistoryWin=pWin;
- AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
- if(pHistoryWin&&pApp)
- {
- IDISPLAY_ClearScreen(pApp->m_pIDisplay);
- if(pHistoryWin->m_pMenuCtl)
- IMENUCTL_Redraw(pHistoryWin->m_pMenuCtl);
- if(pHistoryWin->m_pSoftKeyCtl)
- IMENUCTL_Redraw(pHistoryWin->m_pSoftKeyCtl);
- IDISPLAY_Update(pApp->m_pIDisplay);
- }
- return TRUE;
- }
- boolean HISTORYWIN_EventHandle(void* pWin,AEEEvent eCode, uint16 wParam, uint32 dwParam)
- {
- IHistoryWin* pHistoryWin=pWin;
- boolean bDispatched = FALSE;
- //CMenuList *pApp = (CMenuList *) pWin;
- if(NULL==pHistoryWin) return FALSE;
- switch(eCode)
- {
- case EVT_KEY:
- bDispatched=HISTORYWIN_HandleKeyEvent(pHistoryWin,wParam);
- break;
- //case EVT_COMMAND:
- // bDispatched=HandleSoftButtons(pHistoryWin,wParam);
- //break;
- }
- return bDispatched;
- }
- static boolean HISTORYWIN_HandleKeyEvent(IHistoryWin* pWin,uint16 wParam)
- {
- IHistoryWin* pHistoryWin=pWin;
- boolean bDispatched = FALSE;
- if(NULL==pHistoryWin)
- return FALSE;
- switch(wParam)
- {
- case AVK_UP:
- case AVK_DOWN:
- if(IMENUCTL_IsActive(pHistoryWin->m_pSoftKeyCtl))
- {
- IMENUCTL_SetActive(pHistoryWin->m_pMenuCtl, TRUE);
- IMENUCTL_SetActive(pHistoryWin->m_pSoftKeyCtl, FALSE);
- IMENUCTL_SetSel(pHistoryWin->m_pMenuCtl, INPUT_MENUCTL);
- bDispatched = TRUE;//保证每个分支都有返回
- }
- else //若当前激活是菜单控件则交由下面自己处理
- bDispatched=IMENUCTL_HandleEvent(pHistoryWin->m_pMenuCtl,EVT_KEY,wParam,0);
- break;
- case AVK_CLR://关闭窗口
- IWINSTACK_CloseWindow(TRUE);
- bDispatched = TRUE;
- break;
- case AVK_SELECT:
- //当软键不在激活状态时按Select会将软键设为激活
- if(pHistoryWin->m_pMenuCtl&&IMENUCTL_IsActive(pHistoryWin->m_pMenuCtl))
- {
- IMENUCTL_SetActive(pHistoryWin->m_pMenuCtl, FALSE);
- IMENUCTL_SetActive(pHistoryWin->m_pSoftKeyCtl, TRUE);
- }
- else if(pHistoryWin->m_pSoftKeyCtl&&IMENUCTL_IsActive(pHistoryWin->m_pSoftKeyCtl))
- bDispatched=IMENUCTL_HandleEvent(pHistoryWin->m_pSoftKeyCtl,EVT_KEY,wParam,0);
- //bDispatched = TRUE;
- break;
- case AVK_RIGHT:
- case AVK_LEFT:
- bDispatched = IMENUCTL_HandleEvent(pHistoryWin->m_pSoftKeyCtl, EVT_KEY, wParam, 0);
- break;
- }
- return bDispatched;
- }