IHistory.c
上传用户:duwei1288
上传日期:2009-12-27
资源大小:451k
文件大小:5k
源码类别:

BREW编程

开发平台:

Visual C++

  1. #include "IHistory.h"
  2. #include "AeeFile.h"
  3. #include "AEEAppGen.h"
  4. #include "WindowStack.h"
  5. #include "MenuList_res.h"
  6. /////////////////////////Static Function//////////////////////
  7. static boolean HISTORYWIN_HandleKeyEvent(IHistoryWin* pWin,uint16 wParam);
  8. #define WAP_HISTORY_FILENAME "MenuList/history.dat"
  9. //窗口的控件
  10. typedef enum
  11. {
  12.     INPUT_SOFTKEYCTL=0,
  13.     INPUT_MENUCTL
  14. }THistoryWinCtlType;
  15. //软键控件的ItemId定义
  16. typedef enum
  17. {
  18.   INPUT_SOFTKEY_ITEM = 1,
  19.   INPUT_SOFTKEY_ITEM_GOTO,
  20.   INPUT_SOFTKEY_ITEM_EDIT,
  21.   INPUT_SOFTKEY_ITEM_NEW,
  22.   INPUT_SOFTKEY_ITEM_DEL
  23. }THistoryWinItems;
  24. //按键事件的处理
  25. //static boolean IINPUTWINDOW_HandleKeyEvent(IInputWin* pWin,uint16 wParam);
  26. //软键菜单的处理
  27. //static boolean IINPUTWINDOW_HandleCommandEvent(IInputWin* pWin,uint16 wParam);
  28. //设置窗口中控件的激活状态
  29. //static boolean IINPUTWINDOW_SetActiveCtl(IInputWin* pWin,TInputCtlType nTextCtl);
  30. /////////////////////////Public Function//////////////////////
  31. boolean HistoryDlg()
  32. {
  33. AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
  34. AEERect MenuRect;
  35. AEERect SoftRect;
  36. IFile *pIFile;
  37. IFileMgr *pIFileMgr = NULL;
  38. IHistoryWin *ptHistoryWin = (IHistoryWin *)MALLOC(sizeof(IHistoryWin));
  39. //AEERect m_rc;
  40. if (NULL == ptHistoryWin)
  41. return FALSE;
  42. ISHELL_CreateInstance(pApp->m_pIShell, AEECLSID_MENUCTL, (void **)&(ptHistoryWin->m_pMenuCtl));
  43. if(SUCCESS!=ISHELL_CreateInstance(pApp->m_pIShell,AEECLSID_SOFTKEYCTL,(void **)&(ptHistoryWin->m_pSoftKeyCtl)))
  44. {
  45. HistoryWIN_Release(pApp->m_pIShell,&ptHistoryWin);
  46. return FALSE;
  47. }
  48. IMENUCTL_AddItem(ptHistoryWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_GOTO,INPUT_SOFTKEY_ITEM_GOTO, NULL, 0);
  49. IMENUCTL_AddItem(ptHistoryWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_DEL,INPUT_SOFTKEY_ITEM_DEL, NULL, 0);
  50. IMENUCTL_GetRect(ptHistoryWin->m_pMenuCtl, &MenuRect);
  51. IMENUCTL_GetRect(ptHistoryWin->m_pSoftKeyCtl, &SoftRect);
  52. MenuRect.dy = (int16)(SoftRect.y);
  53. IMENUCTL_SetRect(ptHistoryWin->m_pMenuCtl, &MenuRect);
  54. if(SUCCESS!=ISHELL_CreateInstance(pApp->m_pIShell,AEECLSID_FILEMGR,(void **)&pIFileMgr))
  55. {
  56. HistoryWIN_Release(pApp->m_pIShell,&ptHistoryWin);
  57. return FALSE;
  58. }
  59. if (IFILEMGR_Test(pIFileMgr, WAP_HISTORY_FILENAME) == EFAILED) {
  60. pIFile = IFILEMGR_OpenFile(pIFileMgr, WAP_HISTORY_FILENAME, _OFM_CREATE);
  61. }
  62. else {
  63. if ((pIFile = IFILEMGR_OpenFile(pIFileMgr, WAP_HISTORY_FILENAME, _OFM_READWRITE)) == NULL) {
  64. IFILEMGR_Release(pIFileMgr);
  65. // free menus here
  66. return FALSE;
  67. }
  68. //ReadBookmarks(pIFileMgr, pIFile, ptBookmarkWin);
  69. }
  70. //IMENUCTL_SetActive(ptHistoryWin->m_pMenuCtl,TRUE);
  71. IMENUCTL_SetActive(ptHistoryWin->m_pSoftKeyCtl,TRUE);
  72. return IWINSTACK_OpenWindow(WAPWINID_HISTORY, ptHistoryWin);
  73. }
  74. void*   HistoryWIN_Create(IShell* pShell,void* pParam)
  75. {
  76. pShell=pShell;
  77. return pParam;
  78. }
  79. boolean HistoryWIN_Release(IShell* pShell,void** pWin)
  80. {
  81. IHistoryWin* pHistoryWin=*pWin;
  82. if(pHistoryWin)
  83. {
  84. if(pHistoryWin->m_pSoftKeyCtl)
  85. IMENUCTL_Release(pHistoryWin->m_pSoftKeyCtl);
  86. if(pHistoryWin->m_pMenuCtl)
  87. IMENUCTL_Release(pHistoryWin->m_pMenuCtl);
  88. FREEIF(*pWin);
  89. }
  90. return TRUE;
  91. }
  92. boolean HistoryWIN_Redraw(IShell* pShell,void* pWin)
  93. {
  94. IHistoryWin* pHistoryWin=pWin;
  95. AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
  96. if(pHistoryWin&&pApp)
  97. {
  98. IDISPLAY_ClearScreen(pApp->m_pIDisplay);
  99. if(pHistoryWin->m_pMenuCtl)
  100. IMENUCTL_Redraw(pHistoryWin->m_pMenuCtl);
  101. if(pHistoryWin->m_pSoftKeyCtl)
  102. IMENUCTL_Redraw(pHistoryWin->m_pSoftKeyCtl);
  103. IDISPLAY_Update(pApp->m_pIDisplay);
  104. }
  105. return TRUE;
  106. }
  107. boolean HISTORYWIN_EventHandle(void* pWin,AEEEvent eCode, uint16 wParam, uint32 dwParam)
  108. {
  109. IHistoryWin* pHistoryWin=pWin;
  110. boolean bDispatched = FALSE;
  111. //CMenuList *pApp = (CMenuList *) pWin;
  112. if(NULL==pHistoryWin) return FALSE;
  113. switch(eCode)
  114. {
  115. case EVT_KEY:
  116. bDispatched=HISTORYWIN_HandleKeyEvent(pHistoryWin,wParam);
  117. break;
  118. //case EVT_COMMAND:
  119. // bDispatched=HandleSoftButtons(pHistoryWin,wParam);
  120. //break;
  121. }
  122. return bDispatched;
  123. }
  124. static boolean HISTORYWIN_HandleKeyEvent(IHistoryWin* pWin,uint16 wParam)
  125. {
  126. IHistoryWin* pHistoryWin=pWin;
  127. boolean bDispatched = FALSE;
  128. if(NULL==pHistoryWin) 
  129. return FALSE;
  130. switch(wParam) 
  131. {
  132. case AVK_UP:
  133. case AVK_DOWN:
  134. if(IMENUCTL_IsActive(pHistoryWin->m_pSoftKeyCtl))
  135. {
  136. IMENUCTL_SetActive(pHistoryWin->m_pMenuCtl, TRUE);
  137. IMENUCTL_SetActive(pHistoryWin->m_pSoftKeyCtl, FALSE);
  138.        IMENUCTL_SetSel(pHistoryWin->m_pMenuCtl, INPUT_MENUCTL);
  139. bDispatched = TRUE;//保证每个分支都有返回
  140. }
  141. else //若当前激活是菜单控件则交由下面自己处理
  142. bDispatched=IMENUCTL_HandleEvent(pHistoryWin->m_pMenuCtl,EVT_KEY,wParam,0);
  143. break;
  144. case AVK_CLR://关闭窗口
  145. IWINSTACK_CloseWindow(TRUE);
  146. bDispatched = TRUE;
  147. break;
  148. case AVK_SELECT:
  149. //当软键不在激活状态时按Select会将软键设为激活
  150. if(pHistoryWin->m_pMenuCtl&&IMENUCTL_IsActive(pHistoryWin->m_pMenuCtl))
  151. {
  152. IMENUCTL_SetActive(pHistoryWin->m_pMenuCtl, FALSE);
  153. IMENUCTL_SetActive(pHistoryWin->m_pSoftKeyCtl, TRUE);
  154. }
  155. else if(pHistoryWin->m_pSoftKeyCtl&&IMENUCTL_IsActive(pHistoryWin->m_pSoftKeyCtl))
  156. bDispatched=IMENUCTL_HandleEvent(pHistoryWin->m_pSoftKeyCtl,EVT_KEY,wParam,0);
  157. //bDispatched = TRUE;
  158. break;
  159. case AVK_RIGHT:
  160. case AVK_LEFT:
  161. bDispatched = IMENUCTL_HandleEvent(pHistoryWin->m_pSoftKeyCtl, EVT_KEY, wParam, 0);
  162. break;
  163. }
  164. return bDispatched;
  165. }