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

BREW编程

开发平台:

Visual C++

  1. #include "IBookMark.h"
  2. #include "IBookmarkFile.h"
  3. #include "MenuList.brh"
  4. #include "Windowstack.h"
  5. #include "IInputwindow.h"
  6. ////////////////////////////////////////////////////////////////////////////////////////////
  7. ////////////////////////////////////////////////////////////////////////////////////////////
  8. #define BOOKMARKLEN  160+2
  9. typedef enum
  10. {
  11.   INPUT_SOFTKEY_ITEM = 1,
  12.   INPUT_SOFTKEY_ITEM_GOTO,
  13.   INPUT_SOFTKEY_ITEM_EDIT,
  14.   INPUT_SOFTKEY_ITEM_NEW,
  15.   INPUT_SOFTKEY_ITEM_DEL
  16. }TBMWinWinItems;
  17. ////////////////////////////////////////////////////////////////////////////////////////////
  18. ////////////////////////////////////////////////////////////////////////////////////////////
  19. static boolean IBOOKMARKWIN_HandleKeyEvent(IBookMarkWin* pWin,uint16 wParam);
  20. static boolean IBOOKMARKWIN_HandleSoftButtonsEvent(IBookMarkWin *pWin, uint16 wParam);
  21. static boolean SetNewBookMarkDlgRespons(const AECHAR *response1, const AECHAR *response2, boolean bOK);
  22. static boolean SetEditBookMarkDlgResponse(const AECHAR *response1, const AECHAR *response2, boolean bOK);
  23. ////////////////////////////////////////////////////////////////////////////////////////////
  24. ////////////////////////////////////////////////////////////////////////////////////////////
  25. void*   IBOOKMARKWIN_Create(IShell* pShell,void* pParam)
  26. {
  27. AEERect MenuRect;
  28. AEERect SoftRect;
  29. IBookMarkWin *ptBookmarkWin=NULL;
  30. if(!pShell) return NULL;
  31. ptBookmarkWin= MALLOCREC(IBookMarkWin);
  32. if (!ptBookmarkWin)
  33. return NULL;
  34. //创建菜单
  35. if(SUCCESS!=ISHELL_CreateInstance(pShell, AEECLSID_MENUCTL, (void **)&(ptBookmarkWin->m_pMenuCtl)))
  36. {
  37. IBOOKMARKWIN_Release(pShell,&ptBookmarkWin);
  38. return NULL;
  39. }
  40. //创建软键
  41. if(SUCCESS!=ISHELL_CreateInstance(pShell, AEECLSID_SOFTKEYCTL, (void **)&(ptBookmarkWin->m_pSoftKeyCtl)))
  42. {
  43. IBOOKMARKWIN_Release(pShell,&ptBookmarkWin);
  44. return NULL;
  45. }
  46. IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_GOTO,INPUT_SOFTKEY_ITEM_GOTO, NULL, 0);
  47. IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_EDIT,  INPUT_SOFTKEY_ITEM_EDIT,     NULL, 0);
  48. IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl,MENULIST_RES_FILE, IDS_NEW,  INPUT_SOFTKEY_ITEM_NEW,       NULL, 0);
  49. IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_DEL,INPUT_SOFTKEY_ITEM_DEL, NULL, 0);
  50. //设置显示区域
  51. IMENUCTL_GetRect(ptBookmarkWin->m_pMenuCtl, &MenuRect);
  52. IMENUCTL_GetRect(ptBookmarkWin->m_pSoftKeyCtl, &SoftRect);
  53. MenuRect.dy = (int16)(SoftRect.y);
  54. IMENUCTL_SetRect(ptBookmarkWin->m_pMenuCtl, &MenuRect);
  55. //打开书签文件
  56. IBOOKMARKFILE_CreateInstance();
  57. return ptBookmarkWin;
  58. }
  59. boolean IBOOKMARKWIN_Release(IShell* pShell,void** pWin)
  60. {
  61. IBookMarkWin *ptBookmarkWin=*pWin;
  62. if(ptBookmarkWin)
  63. {
  64. if(ptBookmarkWin->m_pMenuCtl)
  65. IMENUCTL_Release(ptBookmarkWin->m_pMenuCtl);
  66. if(ptBookmarkWin->m_pSoftKeyCtl)
  67. IMENUCTL_Release(ptBookmarkWin->m_pSoftKeyCtl);
  68. }
  69. FREEIF(*pWin);
  70. return IBOOKMARKFILE_Release();
  71. }
  72. boolean IBOOKMARKWIN_Redraw(IShell* pShell,void* pWin)
  73. {
  74. AECHAR* pName=NULL;
  75. uint32  ulID=0;
  76. boolean bActive;
  77. uint16  usItemID=1;
  78. IBookMarkWin *ptBookmarkWin=(IBookMarkWin*)pWin;
  79. if(!ptBookmarkWin||!ptBookmarkWin->m_pMenuCtl||!ptBookmarkWin->m_pSoftKeyCtl)
  80. return FALSE;
  81. //初始化数据
  82. bActive=IBOOKMARKFILE_StartToSeek();
  83. IMENUCTL_DeleteAll(ptBookmarkWin->m_pMenuCtl);
  84. //将数据读入列表
  85. while(IBOOKMARKFILE_GetNext(&pName,&ulID))
  86. {
  87. if(pName)
  88. IMENUCTL_AddItem(ptBookmarkWin->m_pMenuCtl, MENULIST_RES_FILE, 0, usItemID++, pName, ulID);
  89. }
  90. //绘制控件
  91. IMENUCTL_SetActive(ptBookmarkWin->m_pMenuCtl,bActive);
  92. bActive=!bActive;
  93. IMENUCTL_SetActive(ptBookmarkWin->m_pSoftKeyCtl,bActive);
  94. IMENUCTL_Redraw(ptBookmarkWin->m_pMenuCtl);
  95. IMENUCTL_Redraw(ptBookmarkWin->m_pSoftKeyCtl);
  96. return TRUE;
  97. }
  98. boolean IBOOKMARKWIN_EventHandle(void* pWin,AEEEvent eCode, uint16 wParam, uint32 dwParam)
  99. {
  100. IBookMarkWin* pInputWin=(IBookMarkWin*)pWin;
  101. switch(eCode)
  102. {
  103. case EVT_KEY:
  104. return IBOOKMARKWIN_HandleKeyEvent(pInputWin,wParam);
  105. case EVT_COMMAND:
  106. return IBOOKMARKWIN_HandleSoftButtonsEvent(pInputWin,wParam);
  107. default:
  108. return FALSE;
  109. }
  110. }
  111. ////////////////////////////////////////////////////////////////////////////////////////////
  112. ////////////////////////////////////////////////////////////////////////////////////////////
  113. static boolean IBOOKMARKWIN_HandleKeyEvent(IBookMarkWin* pWin,uint16 wParam)
  114. {
  115. boolean bDispatched = FALSE;
  116. if(!pWin||!pWin->m_pMenuCtl||!pWin->m_pSoftKeyCtl) return FALSE;
  117. switch(wParam) 
  118. {
  119. case AVK_UP:
  120. case AVK_DOWN:
  121. if(IMENUCTL_IsActive(pWin->m_pSoftKeyCtl))
  122. {
  123. IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, FALSE);
  124. bDispatched = TRUE;
  125. }
  126. else 
  127. bDispatched=IMENUCTL_HandleEvent(pWin->m_pMenuCtl,EVT_KEY,wParam,0);
  128. break;
  129. case AVK_CLR:
  130. IWINSTACK_CloseWindow(TRUE);
  131. bDispatched = TRUE;
  132. break;
  133. case AVK_SELECT:
  134. if(!IMENUCTL_IsActive(pWin->m_pSoftKeyCtl))
  135. {
  136. IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, TRUE);
  137. bDispatched = TRUE;
  138. }
  139. else
  140. bDispatched=IMENUCTL_HandleEvent(pWin->m_pSoftKeyCtl,EVT_KEY,wParam,0);
  141. break;
  142. case AVK_RIGHT:
  143. case AVK_LEFT:
  144. if(IMENUCTL_IsActive(pWin->m_pSoftKeyCtl))
  145. bDispatched = IMENUCTL_HandleEvent(pWin->m_pSoftKeyCtl, EVT_KEY, wParam, 0);
  146. break;
  147. }
  148. return bDispatched;
  149. }
  150. static boolean IBOOKMARKWIN_HandleSoftButtonsEvent(IBookMarkWin* pWin,uint16 wParam)
  151. {
  152. //CtlAddItem InfoStruct;
  153. InputTextInfo Info1;
  154. InputTextInfo Info2;
  155. boolean bDispatched = FALSE;
  156. uint32 uiID;
  157. AECHAR DlgTitle[BOOKMARKLEN];
  158. AECHAR DlgUrl[BOOKMARKLEN];
  159. AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
  160. CtlAddItem InfoStruct;
  161. switch (wParam) 
  162. {
  163. case INPUT_SOFTKEY_ITEM_NEW:
  164. ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_BOOKMARKTITLE, DlgTitle, sizeof(DlgTitle));
  165. ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_URL, DlgUrl, sizeof(DlgUrl));
  166. IMENUCTL_SetActive(pWin->m_pMenuCtl, FALSE);
  167. IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, FALSE);
  168. Info1.m_inputType=IT_TEXT;
  169. Info1.m_pText=NULL;
  170. Info1.m_pTitle=DlgTitle;
  171. Info2.m_inputType=IT_TEXT;
  172. Info2.m_pText=NULL;
  173. Info2.m_pTitle=DlgUrl;
  174. return NewTextInputDialog(&Info1,&Info2,SetNewBookMarkDlgRespons);
  175. case INPUT_SOFTKEY_ITEM_EDIT:
  176. if(IMENUCTL_GetItemCount(pWin->m_pMenuCtl) == 0)
  177. return TRUE;
  178. ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_BOOKMARKTITLE, DlgTitle, sizeof(DlgTitle));
  179. ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_URL, DlgUrl, sizeof(DlgUrl));
  180. IMENUCTL_GetItem(pWin->m_pMenuCtl, IMENUCTL_GetSel(pWin->m_pMenuCtl), &InfoStruct);
  181. IMENUCTL_SetActive(pWin->m_pMenuCtl, FALSE);
  182. IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, FALSE);
  183. Info1.m_inputType=IT_TEXT;
  184. Info1.m_pText=(AECHAR*)InfoStruct.pText;
  185. Info1.m_pTitle=DlgTitle;
  186. Info2.m_inputType=IT_TEXT;
  187. Info2.m_pText=IBOOKMARKFILE_GetUrl(InfoStruct.dwData);
  188. Info2.m_pTitle=DlgUrl; 
  189. IBOOKMARKFILE_EditStart(InfoStruct.dwData);
  190. return NewTextInputDialog(&Info1,&Info2,SetEditBookMarkDlgResponse);
  191. case INPUT_SOFTKEY_ITEM_DEL:
  192. if(0!=IMENUCTL_GetItemCount(pWin->m_pMenuCtl))
  193. {
  194. IMENUCTL_GetItemData(pWin->m_pMenuCtl, IMENUCTL_GetSel(pWin->m_pMenuCtl), &uiID);
  195. IBOOKMARKFILE_RemoveBookmark(uiID);
  196. IBOOKMARKWIN_Redraw(pApp->m_pIShell,pWin);
  197. }
  198. bDispatched = TRUE;
  199. break;
  200. }
  201. return TRUE;
  202. }
  203. static boolean SetNewBookMarkDlgRespons(const AECHAR *response1, const AECHAR *response2, boolean bOK)
  204. {
  205. if(!response2||!bOK)
  206. return FALSE;
  207. if(!response1)
  208. response1=response2;
  209. return IBOOKMARKFILE_InsertBookmark((AECHAR*)response1,(AECHAR*)response2);
  210. }
  211. static boolean SetEditBookMarkDlgResponse(const AECHAR *response1, const AECHAR *response2, boolean bOK)
  212. {
  213. if(!response2||!bOK)
  214. return FALSE;
  215. if(!response1)
  216. response1=response2;
  217. return IBOOKMARKFILE_EditFinish((AECHAR*)response1,(AECHAR*)response2);
  218. }