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

BREW编程

开发平台:

Visual C++

  1. #include "IBookMark.h"
  2. #include "IBookmarkFile.h"
  3. #include "MenuList_res.h"
  4. #include "Windowstack.h"
  5. ////////////////////////////////////////////////////////////////////////////////////////////
  6. ////////////////////////////////////////////////////////////////////////////////////////////
  7. typedef enum
  8. {
  9.   INPUT_SOFTKEY_ITEM = 1,
  10.   INPUT_SOFTKEY_ITEM_GOTO,
  11.   INPUT_SOFTKEY_ITEM_EDIT,
  12.   INPUT_SOFTKEY_ITEM_NEW,
  13.   INPUT_SOFTKEY_ITEM_DEL
  14. }TBMWinWinItems;
  15. ////////////////////////////////////////////////////////////////////////////////////////////
  16. ////////////////////////////////////////////////////////////////////////////////////////////
  17. static boolean IBOOKMARKWIN_HandleKeyEvent(IBookMarkWin* pWin,uint16 wParam);
  18. static boolean IBOOKMARKWIN_HandleSoftButtonsEvent(IBookMarkWin *pWin, uint16 wParam);
  19. ////////////////////////////////////////////////////////////////////////////////////////////
  20. ////////////////////////////////////////////////////////////////////////////////////////////
  21. void*   IBOOKMARKWIN_Create(IShell* pShell,void* pParam)
  22. {
  23. AEERect MenuRect;
  24. AEERect SoftRect;
  25. IBookMarkWin *ptBookmarkWin=NULL;
  26. if(!pShell) return NULL;
  27. ptBookmarkWin= MALLOCREC(IBookMarkWin);
  28. if (!ptBookmarkWin)
  29. return NULL;
  30. //创建菜单
  31. if(SUCCESS!=ISHELL_CreateInstance(pShell, AEECLSID_MENUCTL, (void **)&(ptBookmarkWin->m_pMenuCtl)))
  32. {
  33. IBOOKMARKWIN_Release(pShell,&ptBookmarkWin);
  34. return NULL;
  35. }
  36. //创建软键
  37. if(SUCCESS!=ISHELL_CreateInstance(pShell, AEECLSID_SOFTKEYCTL, (void **)&(ptBookmarkWin->m_pSoftKeyCtl)))
  38. {
  39. IBOOKMARKWIN_Release(pShell,&ptBookmarkWin);
  40. return NULL;
  41. }
  42. IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_GOTO,INPUT_SOFTKEY_ITEM_GOTO, NULL, 0);
  43. IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_EDIT,  INPUT_SOFTKEY_ITEM_EDIT,     NULL, 0);
  44. IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl,MENULIST_RES_FILE, IDS_NEW,  INPUT_SOFTKEY_ITEM_NEW,       NULL, 0);
  45. IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_DEL,INPUT_SOFTKEY_ITEM_DEL, NULL, 0);
  46. //设置显示区域
  47. IMENUCTL_GetRect(ptBookmarkWin->m_pMenuCtl, &MenuRect);
  48. IMENUCTL_GetRect(ptBookmarkWin->m_pSoftKeyCtl, &SoftRect);
  49. MenuRect.dy = (int16)(SoftRect.y);
  50. IMENUCTL_SetRect(ptBookmarkWin->m_pMenuCtl, &MenuRect);
  51. //打开书签文件
  52. IBOOKMARKFILE_CreateInstance();
  53. return ptBookmarkWin;
  54. }
  55. boolean IBOOKMARKWIN_Release(IShell* pShell,void** pWin)
  56. {
  57. IBookMarkWin *ptBookmarkWin=*pWin;
  58. if(ptBookmarkWin)
  59. {
  60. if(ptBookmarkWin->m_pMenuCtl)
  61. IMENUCTL_Release(ptBookmarkWin->m_pMenuCtl);
  62. if(ptBookmarkWin->m_pSoftKeyCtl)
  63. IMENUCTL_Release(ptBookmarkWin->m_pSoftKeyCtl);
  64. }
  65. FREEIF(*pWin);
  66. return IBOOKMARKFILE_Release();
  67. }
  68. boolean IBOOKMARKWIN_Redraw(IShell* pShell,void* pWin)
  69. {
  70. AECHAR* pName=NULL;
  71. uint32  ulID=0;
  72. uint16  usItemID=1;
  73. IBookMarkWin *ptBookmarkWin=(IBookMarkWin*)pWin;
  74. if(!ptBookmarkWin||!ptBookmarkWin->m_pMenuCtl||!ptBookmarkWin->m_pSoftKeyCtl)
  75. return FALSE;
  76. //初始化数据
  77. IBOOKMARKFILE_StartToSeek();
  78. IMENUCTL_DeleteAll(ptBookmarkWin->m_pMenuCtl);
  79. //将数据读入列表
  80. while(IBOOKMARKFILE_GetNext(&pName,&ulID))
  81. {
  82. if(pName)
  83. IMENUCTL_AddItem(ptBookmarkWin->m_pMenuCtl, MENULIST_RES_FILE, 0, usItemID++, pName, ulID);
  84. }
  85. //绘制控键
  86. IMENUCTL_SetActive(ptBookmarkWin->m_pMenuCtl,TRUE);
  87. IMENUCTL_SetActive(ptBookmarkWin->m_pSoftKeyCtl,FALSE);
  88. IMENUCTL_Redraw(ptBookmarkWin->m_pMenuCtl);
  89. IMENUCTL_Redraw(ptBookmarkWin->m_pSoftKeyCtl);
  90. return TRUE;
  91. }
  92. boolean IBOOKMARKWIN_EventHandle(void* pWin,AEEEvent eCode, uint16 wParam, uint32 dwParam)
  93. {
  94. IBookMarkWin* pInputWin=(IBookMarkWin*)pWin;
  95. switch(eCode)
  96. {
  97. case EVT_KEY:
  98. return IBOOKMARKWIN_HandleKeyEvent(pInputWin,wParam);
  99. case EVT_COMMAND:
  100. return IBOOKMARKWIN_HandleSoftButtonsEvent(pInputWin,wParam);
  101. default:
  102. return FALSE;
  103. }
  104. }
  105. ////////////////////////////////////////////////////////////////////////////////////////////
  106. ////////////////////////////////////////////////////////////////////////////////////////////
  107. static boolean IBOOKMARKWIN_HandleKeyEvent(IBookMarkWin* pWin,uint16 wParam)
  108. {
  109. boolean bDispatched = FALSE;
  110. if(!pWin||!pWin->m_pMenuCtl||!pWin->m_pSoftKeyCtl) return FALSE;
  111. switch(wParam) 
  112. {
  113. case AVK_UP:
  114. case AVK_DOWN:
  115. if(IMENUCTL_IsActive(pWin->m_pSoftKeyCtl))
  116. {
  117. IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, FALSE);
  118. bDispatched = TRUE;
  119. }
  120. else 
  121. bDispatched=IMENUCTL_HandleEvent(pWin->m_pMenuCtl,EVT_KEY,wParam,0);
  122. break;
  123. case AVK_CLR:
  124. IWINSTACK_CloseWindow(TRUE);
  125. bDispatched = TRUE;
  126. break;
  127. case AVK_SELECT:
  128. if(!IMENUCTL_IsActive(pWin->m_pSoftKeyCtl))
  129. {
  130. IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, TRUE);
  131. bDispatched = TRUE;
  132. }
  133. else
  134. bDispatched=IMENUCTL_HandleEvent(pWin->m_pSoftKeyCtl,EVT_KEY,wParam,0);
  135. break;
  136. case AVK_RIGHT:
  137. case AVK_LEFT:
  138. if(IMENUCTL_IsActive(pWin->m_pSoftKeyCtl))
  139. bDispatched = IMENUCTL_HandleEvent(pWin->m_pSoftKeyCtl, EVT_KEY, wParam, 0);
  140. break;
  141. }
  142. return bDispatched;
  143. }
  144. static boolean IBOOKMARKWIN_HandleSoftButtonsEvent(IBookMarkWin* pWin,uint16 wParam)
  145. {
  146. //CtlAddItem InfoStruct;
  147. /*
  148. InputTextInfo Info1;
  149. InputTextInfo Info2;
  150. boolean bDispatched = FALSE;
  151. //AECHAR DlgTitle[BOOKMARKLEN];
  152. AECHAR DlgTitle[BOOKMARKLEN];
  153. AECHAR DlgUrl[BOOKMARKLEN];
  154. AECHAR *AWideUrl=NULL;
  155. AECHAR BkMrkStr[] = { '' };
  156. AECHAR BktitleStr[] = { '' };
  157. AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
  158. IBookMarkWin *ptBookmarkWin =  NULL;
  159. CtlAddItem InfoStruct;
  160. ptBookmarkWin = pWin;
  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(ptBookmarkWin->m_pMenuCtl, FALSE);
  167. IMENUCTL_SetActive(ptBookmarkWin->m_pSoftKeyCtl, TRUE);
  168. Info1.m_inputType=IT_TEXT;
  169. Info1.m_pText=ISETTINGFILE_GetStr(WAP_BOOKMARKNAME);
  170. Info1.m_pTitle=DlgTitle;
  171. Info2.m_inputType=IT_TEXT;
  172. Info2.m_pText=ISETTINGFILE_GetStr(WAP_BOOKMARKURL);
  173. Info2.m_pTitle=DlgUrl;
  174. //bDispatched = TRUE;
  175. return NewTextInputDialog(&Info1,&Info2,WAPSetHdl_SetNewBookMarkDlgResponse);
  176. case INPUT_SOFTKEY_ITEM_EDIT:
  177. if (IMENUCTL_GetItemCount(ptBookmarkWin->m_pMenuCtl) == 0)
  178. return TRUE;
  179. ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_BOOKMARKTITLE, DlgTitle, sizeof(DlgTitle));
  180. ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_URL, DlgUrl, sizeof(DlgUrl));
  181. IMENUCTL_GetItem(ptBookmarkWin->m_pMenuCtl, IMENUCTL_GetSel(ptBookmarkWin->m_pMenuCtl), &InfoStruct);
  182. IMENUCTL_SetActive(ptBookmarkWin->m_pMenuCtl, FALSE);
  183. AWideUrl=WSTRDUP(InfoStruct.dwData);
  184. Info1.m_inputType=IT_TEXT;
  185. Info1.m_pText=InfoStruct.pText;
  186. Info1.m_pTitle=DlgTitle;
  187. Info2.m_inputType=IT_TEXT;
  188. Info2.m_pText=AWideUrl;
  189. Info2.m_pTitle=DlgUrl; 
  190. FREEIF(m_pBookmarkURL);
  191. FREEIF(m_pBookmarkName);
  192. return NewTextInputDialog(&Info1,&Info2,WAPSetHdl_SetEditBookMarkDlgResponse);
  193. case INPUT_SOFTKEY_ITEM_DEL:
  194. if (IMENUCTL_GetItemCount(ptBookmarkWin->m_pMenuCtl) == 0)
  195. return TRUE;
  196. IMENUCTL_GetItem(ptBookmarkWin->m_pMenuCtl, IMENUCTL_GetSel(ptBookmarkWin->m_pMenuCtl), &InfoStruct);
  197. FREEIF(InfoStruct.dwData);
  198. IMENUCTL_DeleteItem(ptBookmarkWin->m_pMenuCtl, IMENUCTL_GetSel(ptBookmarkWin->m_pMenuCtl));
  199. WriteBookmarks(ptBookmarkWin);
  200. IMENUCTL_Redraw(ptBookmarkWin->m_pMenuCtl);
  201. bDispatched = TRUE;
  202. break;
  203. }*/
  204. return TRUE;
  205. }
  206. #if 0
  207. /////////////////////////Static Function//////////////////////
  208. static boolean BOOKMARKWIN_HandleKeyEvent(IBookMarkWin* pWin,uint16 wParam);
  209. static boolean BOOKMARKWIN_HandleSoftButtonsEvent(IBookMarkWin *pWin, uint16 wParam);
  210. static void ReadBookmarks(IFileMgr *pIFileMgr, IFile *pIFile, IBookMarkWin *ptBookmarkWin);
  211. static boolean WAPSetHdl_SetNewBookMarkDlgResponse(void*Applet, void* pPtr, const AECHAR *response1, const AECHAR *response2, boolean bOK);
  212. static boolean WAPSetHdl_SetEditBookMarkDlgResponse(void*Applet, void* pPtr, const AECHAR *response1, const AECHAR *response2, boolean bOK);
  213. static boolean UpdateBookmark(IBookMarkWin *pWin);
  214. static void WriteBookmarks(IBookMarkWin*ptBookmarkWin);
  215. #define BOOKMARKLEN  160+2
  216. #define MENU_X 7 //3级菜单正文区起始横坐标
  217. #define MENU_Y (32) //3级菜单正文区起始纵坐标
  218. #define MENU_W (SCREEN_W-7-8) //161,3级菜单正文区宽度
  219. #define MENU_SK_2LINE_H (SCREEN_H-32-9-22-16) //123,3级菜单(有2行softkey)中MENU控件高度
  220. #define MENU_SK_1LINE_H (SCREEN_H-32-9-22)
  221. //#define INPUT_TEXT_X_START 2
  222. //#define INPUT_TEXT_Y_START 0
  223. //#define INPUT_TEXT_MAX_SIZE 150
  224. #define WAP_BOOKMARKS_FILENAME "MenuList/bookmarks.dat"
  225. //窗口的控件
  226. typedef enum
  227. {
  228.     INPUT_SOFTKEYCTL=0,
  229.     INPUT_MENUCTL
  230. }TBMWinCtlType;
  231. //软键控件的ItemId定义
  232. typedef enum
  233. {
  234.   INPUT_SOFTKEY_ITEM = 1,
  235.   INPUT_SOFTKEY_ITEM_GOTO,
  236.   INPUT_SOFTKEY_ITEM_EDIT,
  237.   INPUT_SOFTKEY_ITEM_NEW,
  238.   INPUT_SOFTKEY_ITEM_DEL
  239. }TBMWinWinItems;
  240. ///////////////////////////////////////////////////////////////////
  241. AECHAR*   m_pBookmarkURL=NULL;
  242. AECHAR*       m_pBookmarkName=NULL;
  243. //按键事件的处理
  244. //static boolean IINPUTWINDOW_HandleKeyEvent(IInputWin* pWin,uint16 wParam);
  245. //软键菜单的处理
  246. //static boolean IINPUTWINDOW_HandleCommandEvent(IInputWin* pWin,uint16 wParam);
  247. //设置窗口中控件的激活状态
  248. //static boolean IINPUTWINDOW_SetActiveCtl(IInputWin* pWin,TInputCtlType nTextCtl);
  249. /////////////////////////Public Function//////////////////////
  250. boolean BookmarksDlg()
  251. {
  252. AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
  253. AEERect MenuRect;
  254. AEERect SoftRect;
  255. IFile *pIFile;
  256. IFileMgr *pIFileMgr = NULL;
  257. IBookMarkWin *ptBookmarkWin = (IBookMarkWin *)MALLOC(sizeof(IBookMarkWin));
  258. //AEERect m_rc;
  259. if (NULL == ptBookmarkWin)
  260. return FALSE;
  261. ISHELL_CreateInstance(pApp->m_pIShell, AEECLSID_MENUCTL, (void **)&(ptBookmarkWin->m_pMenuCtl));
  262. if(SUCCESS!=ISHELL_CreateInstance(pApp->m_pIShell,AEECLSID_SOFTKEYCTL,(void **)&(ptBookmarkWin->m_pSoftKeyCtl)))
  263. {
  264. BOOKMARKWIN_Release(pApp->m_pIShell,&ptBookmarkWin);
  265. return FALSE;
  266. }
  267. IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_GOTO,INPUT_SOFTKEY_ITEM_GOTO, NULL, 0);
  268. IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_EDIT,  INPUT_SOFTKEY_ITEM_EDIT,     NULL, 0);
  269. IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl,MENULIST_RES_FILE, IDS_NEW,  INPUT_SOFTKEY_ITEM_NEW,       NULL, 0);
  270. IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_DEL,INPUT_SOFTKEY_ITEM_DEL, NULL, 0);
  271. if (ISHELL_CreateInstance(pApp->m_pIShell, AEECLSID_FILEMGR, (void **)&pIFileMgr) != SUCCESS) {
  272. BOOKMARKWIN_Release(pApp->m_pIShell, &ptBookmarkWin);
  273. return FALSE ;
  274. }
  275. if (IFILEMGR_Test(pIFileMgr, WAP_BOOKMARKS_FILENAME) == EFAILED) {
  276. pIFile = IFILEMGR_OpenFile(pIFileMgr, WAP_BOOKMARKS_FILENAME, _OFM_CREATE);
  277. }
  278. else {
  279. if ((pIFile = IFILEMGR_OpenFile(pIFileMgr, WAP_BOOKMARKS_FILENAME, _OFM_READWRITE)) == NULL) {
  280. IFILEMGR_Release(pIFileMgr);
  281. // free menus here
  282. return FALSE;
  283. }
  284. ReadBookmarks(pIFileMgr, pIFile, ptBookmarkWin);
  285. }
  286. IMENUCTL_Sort(ptBookmarkWin->m_pSoftKeyCtl, MCS_NAME_ASCENDING);
  287. IMENUCTL_GetRect(ptBookmarkWin->m_pMenuCtl, &MenuRect);
  288. IMENUCTL_GetRect(ptBookmarkWin->m_pSoftKeyCtl, &SoftRect);
  289. MenuRect.dy = (int16)(SoftRect.y);
  290. IMENUCTL_SetRect(ptBookmarkWin->m_pMenuCtl, &MenuRect);
  291. //IMENUCTL_SetActive(ptBookmarkWin->m_pSoftKeyCtl,TRUE);
  292. IMENUCTL_Redraw((IMenuCtl *) ptBookmarkWin->m_pMenuCtl);
  293. IMENUCTL_SetActive(ptBookmarkWin->m_pMenuCtl, TRUE);
  294. IMENUCTL_Redraw((IMenuCtl *) ptBookmarkWin->m_pSoftKeyCtl); //liting 20040605
  295. IFILE_Release(pIFile);
  296. IFILEMGR_Release(pIFileMgr);
  297. return IWINSTACK_OpenWindow(WAPWINID_BOOKMARK, ptBookmarkWin);
  298. }
  299. void*   BOOKMARKWIN_Create(IShell* pShell,void* pParam)
  300. {
  301. pShell=pShell;
  302. return pParam;
  303. }
  304.  boolean BOOKMARKWIN_Release(IShell* pShell,void** pWin)
  305. {
  306. IBookMarkWin* pInputWin=*pWin;
  307. AECHAR *url;
  308. FREEIF(m_pBookmarkURL);
  309. FREEIF(m_pBookmarkName);
  310. if(pInputWin)
  311. {
  312. if(pInputWin->m_pSoftKeyCtl)
  313. IMENUCTL_DeleteAll(pInputWin->m_pSoftKeyCtl);
  314. IMENUCTL_Release(pInputWin->m_pSoftKeyCtl);
  315. if(pInputWin->m_pMenuCtl)
  316. {
  317. while (IMENUCTL_GetItemCount(pInputWin->m_pMenuCtl)) 
  318. {
  319. uint16 itemid = IMENUCTL_GetItemID(pInputWin->m_pMenuCtl, 0);
  320. IMENUCTL_GetItemData(pInputWin->m_pMenuCtl, itemid, (uint32 *) &url);
  321. FREEIF(url);
  322. IMENUCTL_DeleteItem(pInputWin->m_pMenuCtl, itemid);
  323. }
  324. IMENUCTL_Release(pInputWin->m_pMenuCtl);
  325. }
  326. FREEIF(*pWin);
  327. }
  328. return TRUE;
  329. }
  330. boolean BOOKMARKWIN_Redraw(IShell* pShell,void* pWin)//读文件并显示出来
  331. {
  332. IFile *pIFile;
  333. IFileMgr *pIFileMgr = NULL;
  334. AEERect rect;
  335. AECHAR buf[30];
  336. uint16 MenuItemID;
  337. IBookMarkWin* pBookmarkWin=pWin;
  338. AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
  339. if(pBookmarkWin&&pApp)
  340. {
  341. if(m_pBookmarkURL)
  342. {
  343. UpdateBookmark(pBookmarkWin);
  344. FREEIF(m_pBookmarkURL);
  345. FREEIF(m_pBookmarkName);
  346. }
  347. if (ISHELL_CreateInstance(pApp->m_pIShell, AEECLSID_FILEMGR, (void **)&pIFileMgr) != SUCCESS) 
  348. {
  349. BOOKMARKWIN_Release(pApp->m_pIShell, &pBookmarkWin);
  350. return FALSE ;
  351. }
  352. pIFile = IFILEMGR_OpenFile(pIFileMgr, WAP_BOOKMARKS_FILENAME, _OFM_READWRITE);
  353. ReadBookmarks(pIFileMgr, pIFile, pBookmarkWin);//显示出来
  354. IFILEMGR_Release(pIFileMgr);
  355. IFILE_Release(pIFile);
  356. SETAEERECT(&rect, 20, 10, 150, 25);
  357.        ISHELL_LoadResString (pApp->m_pIShell,
  358.                                         MENULIST_RES_FILE,
  359.                                         IDS_BOOKMARK,
  360.                                         buf,
  361.                                         sizeof(buf));
  362.              //Display
  363.              (void) IDISPLAY_DrawText(pApp->m_pIDisplay,
  364.                                             AEE_FONT_NORMAL,
  365.                                             buf,
  366.                                             -1,
  367.                                             0,
  368.                                             0,
  369.                                             &rect,
  370.                                             IDF_ALIGN_RIGHT 
  371.                                             |IDF_ALIGN_MIDDLE 
  372.                                             |IDF_TEXT_TRANSPARENT);
  373.    
  374.         IDISPLAY_Update(pApp->m_pIDisplay);
  375.    IDISPLAY_SetColor(pApp->m_pIDisplay,CLR_USER_TEXT, MAKE_RGB(0,0,0));
  376. IMENUCTL_SetActive(pBookmarkWin->m_pMenuCtl, TRUE);
  377.         MenuItemID = IMENUCTL_GetItemID(pBookmarkWin->m_pMenuCtl, IMENUCTL_GetItemCount(pBookmarkWin->m_pMenuCtl) - 1);
  378. IMENUCTL_Sort(pBookmarkWin->m_pMenuCtl, MCS_NAME_ASCENDING);
  379. IMENUCTL_SetSel(pBookmarkWin->m_pMenuCtl, MenuItemID);
  380. IMENUCTL_Redraw(pBookmarkWin->m_pMenuCtl);
  381. IMENUCTL_SetSel(pBookmarkWin->m_pSoftKeyCtl, IDS_GOTO);
  382. IMENUCTL_Redraw(pBookmarkWin->m_pSoftKeyCtl);
  383. IDISPLAY_ClearScreen(pApp->m_pIDisplay);
  384. if(pBookmarkWin->m_pMenuCtl)
  385. IMENUCTL_Redraw(pBookmarkWin->m_pMenuCtl);
  386. if(pBookmarkWin->m_pSoftKeyCtl)
  387. IMENUCTL_Redraw(pBookmarkWin->m_pSoftKeyCtl);
  388. IDISPLAY_Update(pApp->m_pIDisplay);
  389. }
  390. return TRUE;
  391. }
  392. boolean BOOKMARKWIN_EventHandle(void* pWin,AEEEvent eCode, uint16 wParam, uint32 dwParam)
  393. {
  394. IBookMarkWin* pInputWin=pWin;
  395. boolean bDispatched = FALSE;
  396. //CMenuList *pApp = (CMenuList *) pWin;
  397. if(NULL==pInputWin) return FALSE;
  398. switch(eCode)
  399. {
  400. case EVT_KEY:
  401. bDispatched=BOOKMARKWIN_HandleKeyEvent(pInputWin,wParam);
  402. break;
  403. case EVT_COMMAND:
  404. bDispatched=BOOKMARKWIN_HandleSoftButtonsEvent(pInputWin,wParam);
  405. break;
  406. }
  407. return bDispatched;
  408. }
  409. ///////////////////////////////////////////////////////////////////////////////////
  410. ///////////////////////////////////////////////////////////////////////////////////
  411. static boolean BOOKMARKWIN_HandleKeyEvent(IBookMarkWin* pWin,uint16 wParam)
  412. {
  413. IBookMarkWin* pInputWin=pWin;
  414. boolean bDispatched = FALSE;
  415. if(NULL==pInputWin) return FALSE;
  416. switch(wParam) 
  417. {
  418. case AVK_UP:
  419. case AVK_DOWN:
  420. if(IMENUCTL_IsActive(pInputWin->m_pSoftKeyCtl))
  421. {
  422. IMENUCTL_SetActive(pInputWin->m_pMenuCtl, TRUE);
  423. IMENUCTL_SetActive(pInputWin->m_pSoftKeyCtl, FALSE);
  424.        IMENUCTL_SetSel(pInputWin->m_pMenuCtl, INPUT_MENUCTL);
  425. bDispatched = TRUE;//保证每个分支都有返回
  426. }
  427. else //若当前激活是菜单控件则交由下面自己处理
  428. bDispatched=IMENUCTL_HandleEvent(pInputWin->m_pMenuCtl,EVT_KEY,wParam,0);
  429. break;
  430. case AVK_CLR://关闭窗口
  431. IWINSTACK_CloseWindow(TRUE);
  432. bDispatched = TRUE;
  433. break;
  434. case AVK_SELECT:
  435. //当软键不在激活状态时按Select会将软键设为激活
  436. if(pInputWin->m_pMenuCtl&&IMENUCTL_IsActive(pInputWin->m_pMenuCtl))
  437. {
  438. IMENUCTL_SetActive(pInputWin->m_pMenuCtl, FALSE);
  439. IMENUCTL_SetActive(pInputWin->m_pSoftKeyCtl, TRUE);
  440. }
  441. else if(pInputWin->m_pSoftKeyCtl&&IMENUCTL_IsActive(pInputWin->m_pSoftKeyCtl))
  442. bDispatched=IMENUCTL_HandleEvent(pInputWin->m_pSoftKeyCtl,EVT_KEY,wParam,0);
  443. //bDispatched = TRUE;
  444. break;
  445. case AVK_RIGHT:
  446. case AVK_LEFT:
  447. bDispatched = IMENUCTL_HandleEvent(pInputWin->m_pSoftKeyCtl, EVT_KEY, wParam, 0);
  448. break;
  449. }
  450. return bDispatched;
  451. }
  452. static boolean BOOKMARKWIN_HandleSoftButtonsEvent(IBookMarkWin* pWin,uint16 wParam)
  453. {
  454. //CtlAddItem InfoStruct;
  455. InputTextInfo Info1;
  456. InputTextInfo Info2;
  457. boolean bDispatched = FALSE;
  458. //AECHAR DlgTitle[BOOKMARKLEN];
  459. AECHAR DlgTitle[BOOKMARKLEN];
  460. AECHAR DlgUrl[BOOKMARKLEN];
  461. AECHAR *AWideUrl=NULL;
  462. AECHAR BkMrkStr[] = { '' };
  463. AECHAR BktitleStr[] = { '' };
  464. AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
  465. IBookMarkWin *ptBookmarkWin =  NULL;
  466. CtlAddItem InfoStruct;
  467. ptBookmarkWin = pWin;
  468. switch (wParam) 
  469. {
  470. case INPUT_SOFTKEY_ITEM_NEW:
  471. ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_BOOKMARKTITLE, DlgTitle, sizeof(DlgTitle));
  472. ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_URL, DlgUrl, sizeof(DlgUrl));
  473. IMENUCTL_SetActive(ptBookmarkWin->m_pMenuCtl, FALSE);
  474. IMENUCTL_SetActive(ptBookmarkWin->m_pSoftKeyCtl, TRUE);
  475. Info1.m_inputType=IT_TEXT;
  476. Info1.m_pText=ISETTINGFILE_GetStr(WAP_BOOKMARKNAME);
  477. Info1.m_pTitle=DlgTitle;
  478. Info2.m_inputType=IT_TEXT;
  479. Info2.m_pText=ISETTINGFILE_GetStr(WAP_BOOKMARKURL);
  480. Info2.m_pTitle=DlgUrl;
  481. //bDispatched = TRUE;
  482. return NewTextInputDialog(&Info1,&Info2,WAPSetHdl_SetNewBookMarkDlgResponse);
  483. case INPUT_SOFTKEY_ITEM_EDIT:
  484. if (IMENUCTL_GetItemCount(ptBookmarkWin->m_pMenuCtl) == 0)
  485. return TRUE;
  486. ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_BOOKMARKTITLE, DlgTitle, sizeof(DlgTitle));
  487. ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_URL, DlgUrl, sizeof(DlgUrl));
  488. IMENUCTL_GetItem(ptBookmarkWin->m_pMenuCtl, IMENUCTL_GetSel(ptBookmarkWin->m_pMenuCtl), &InfoStruct);
  489. IMENUCTL_SetActive(ptBookmarkWin->m_pMenuCtl, FALSE);
  490. AWideUrl=WSTRDUP(InfoStruct.dwData);
  491. Info1.m_inputType=IT_TEXT;
  492. Info1.m_pText=InfoStruct.pText;
  493. Info1.m_pTitle=DlgTitle;
  494. Info2.m_inputType=IT_TEXT;
  495. Info2.m_pText=AWideUrl;
  496. Info2.m_pTitle=DlgUrl; 
  497. FREEIF(m_pBookmarkURL);
  498. FREEIF(m_pBookmarkName);
  499. return NewTextInputDialog(&Info1,&Info2,WAPSetHdl_SetEditBookMarkDlgResponse);
  500. case INPUT_SOFTKEY_ITEM_DEL:
  501. if (IMENUCTL_GetItemCount(ptBookmarkWin->m_pMenuCtl) == 0)
  502. return TRUE;
  503. IMENUCTL_GetItem(ptBookmarkWin->m_pMenuCtl, IMENUCTL_GetSel(ptBookmarkWin->m_pMenuCtl), &InfoStruct);
  504. FREEIF(InfoStruct.dwData);
  505. IMENUCTL_DeleteItem(ptBookmarkWin->m_pMenuCtl, IMENUCTL_GetSel(ptBookmarkWin->m_pMenuCtl));
  506. WriteBookmarks(ptBookmarkWin);
  507. IMENUCTL_Redraw(ptBookmarkWin->m_pMenuCtl);
  508. bDispatched = TRUE;
  509. break;
  510. }
  511. return TRUE;
  512. }
  513. static boolean WAPSetHdl_SetNewBookMarkDlgResponse(const AECHAR *response1, const AECHAR *response2, boolean bOK)
  514. {
  515. IFile *pIFile;
  516. IFileMgr *pIFileMgr = NULL;
  517. AEEApplet* pApp= (AEEApplet*)GETAPPINSTANCE();
  518. AECHAR  pBug[] = {'r','n',''};
  519. if (response2 != NULL && bOK == TRUE) 
  520. {
  521. if (ISHELL_CreateInstance(pApp->m_pIShell, AEECLSID_FILEMGR, (void **)&pIFileMgr) != SUCCESS)
  522. return FALSE;
  523. if ((pIFile = IFILEMGR_OpenFile(pIFileMgr, WAP_BOOKMARKS_FILENAME, _OFM_READWRITE)) == NULL) 
  524. {
  525. IFILEMGR_Release(pIFileMgr);
  526. return FALSE;
  527. }
  528. IFILE_Seek(pIFile, _SEEK_END, 0); // goto end of file...
  529. IFILE_Write(pIFile, response1, 2*WSTRLEN(response1));
  530. IFILE_Write(pIFile, pBug, sizeof(pBug));//以回车换行区别每条
  531. IFILE_Write(pIFile, response2, 2*WSTRLEN(response2));
  532. IFILE_Write(pIFile, pBug, sizeof(pBug));
  533. IFILE_Release(pIFile);
  534. IFILEMGR_Release(pIFileMgr);
  535. }
  536. return TRUE;
  537. }
  538. static boolean WAPSetHdl_SetEditBookMarkDlgResponse(const AECHAR *response1, const AECHAR *response2, boolean bOK)
  539. {
  540. AEEApplet *pApp = (AEEApplet*)GETAPPINSTANCE();
  541. if((response2 == NULL)||(bOK != TRUE)) 
  542. return FALSE;
  543. if(response2)
  544. m_pBookmarkURL=WSTRDUP(response2);
  545. if(response1)
  546. m_pBookmarkName=WSTRDUP(response1);
  547. return TRUE;
  548. }
  549. static void ReadBookmarks(IFileMgr *pIFileMgr, IFile *pIFile, IBookMarkWin *ptBookmarkWin)
  550. {
  551. FileInfo Info;
  552. AECHAR* AWideTitle=NULL;
  553. AECHAR *Inbuff = NULL;
  554. uint16 MenuID = 0;
  555. AECHAR *url;
  556. //int bmLen;
  557. AECHAR *lfpos;
  558. AECHAR *strpos;
  559. // delete all items, and corresponding data
  560. while (IMENUCTL_GetItemCount(ptBookmarkWin->m_pMenuCtl)) {
  561. uint16 itemid = IMENUCTL_GetItemID(ptBookmarkWin->m_pMenuCtl, 0);
  562. IMENUCTL_GetItemData(ptBookmarkWin->m_pMenuCtl, itemid, (uint32 *) &url);
  563. FREEIF(url);
  564. IMENUCTL_DeleteItem(ptBookmarkWin->m_pMenuCtl, itemid);
  565. }
  566. IFILEMGR_GetInfo(pIFileMgr, WAP_BOOKMARKS_FILENAME, &Info);
  567. if (Info.dwSize > 1) {
  568. Inbuff = MALLOC(Info.dwSize + 2);
  569. if (NULL == Inbuff)
  570. return ;
  571. IFILE_Read(pIFile, Inbuff, Info.dwSize);
  572. strpos = Inbuff;
  573. for (MenuID = 1; (uint32)(strpos - Inbuff) < Info.dwSize; MenuID++) {
  574. lfpos = WSTRCHR(strpos, 'r');
  575. if (!lfpos || !lfpos[0])
  576. break; //
  577. lfpos[0] = ''; // nullterminate the string
  578. //STRTOWSTR(strpos, AWideTitle, BOOKMARKLEN);
  579. AWideTitle=MALLOC(2*WSTRLEN(strpos));
  580. WSTRCPY(AWideTitle, strpos);
  581. strpos = lfpos + 3;
  582. lfpos = WSTRCHR(strpos, 'r');
  583. if (!lfpos || !lfpos[0])
  584. break; //
  585. lfpos[0] = ''; // 在找到的一条记录末尾添零表示这是一条字符串
  586. url = WSTRDUP(strpos);
  587. strpos = lfpos + 3;
  588. IMENUCTL_AddItem(ptBookmarkWin->m_pMenuCtl, MENULIST_RES_FILE, 0, MenuID, AWideTitle, (uint32)url);
  589. FREEIF(AWideTitle);
  590. }
  591. FREE(Inbuff);
  592. }
  593. }
  594. static void WriteBookmarks(IBookMarkWin*ptBookmarkWin)
  595. {
  596. IFile *pIFile;
  597. int Index;
  598. int NumBkmrks;
  599. CtlAddItem InfoStruct;
  600. AECHAR* ATitle;
  601. AEEApplet *pApp = (AEEApplet*)(GETAPPINSTANCE());
  602. IFileMgr *pIFileMgr = NULL;
  603. AECHAR  pBug[] = {'r','n',''};
  604. if (ISHELL_CreateInstance(pApp->m_pIShell, AEECLSID_FILEMGR, (void **)&pIFileMgr) != SUCCESS)
  605. return ;
  606. IFILEMGR_Remove(pIFileMgr, WAP_BOOKMARKS_FILENAME);
  607. if ((pIFile = IFILEMGR_OpenFile(pIFileMgr, WAP_BOOKMARKS_FILENAME, _OFM_CREATE)) == NULL) {
  608. IFILEMGR_Release(pIFileMgr);
  609. return ;
  610. }
  611. NumBkmrks = IMENUCTL_GetItemCount(ptBookmarkWin->m_pMenuCtl);
  612. for (Index = 0; Index < NumBkmrks; Index++) 
  613. {
  614. IMENUCTL_GetItem(ptBookmarkWin->m_pMenuCtl, IMENUCTL_GetItemID(ptBookmarkWin->m_pMenuCtl, Index), &InfoStruct);
  615. //WSTRTOUTF8(InfoStruct.pText, WSTRLEN(InfoStruct.pText)+1, (byte *) ATitle, BOOKMARKLEN);
  616. ATitle=WSTRDUP(InfoStruct.pText);
  617. if(!ATitle) continue;
  618. IFILE_Write(pIFile, ATitle, 2*WSTRLEN((const char *)ATitle));
  619. IFILE_Write(pIFile, pBug, sizeof(pBug));
  620. IFILE_Write(pIFile, (char *)InfoStruct.dwData, 2*WSTRLEN((const char *)InfoStruct.dwData));
  621. IFILE_Write(pIFile, pBug,sizeof(pBug));
  622. FREE(ATitle);
  623. }
  624. IFILEMGR_Release(pIFileMgr);
  625. IFILE_Release(pIFile);
  626. }
  627. /*static boolean IINPUTWINDOW_HandleCommandEvent(IInputWin* pWin,uint16 wParam)
  628. {
  629. IInputWin* pInputWin=pWin;
  630. boolean bDispatched = FALSE;
  631. if(NULL==pInputWin) return FALSE;
  632. //
  633. switch(wParam)
  634. {
  635. case INPUT_SOFTKEY_ITEM_INPUT_MODE:
  636. break;
  637. case INPUT_SOFTKEY_ITEM_DONE:
  638. if(pWin->tpResponseFunction)
  639. {
  640. AECHAR* pText1=NULL;
  641. AECHAR* pText2=NULL;
  642. pText1=ITEXTCTL_GetTextPtr(pWin->m_pText1);
  643. if(pWin->m_pText2)
  644. pText2=ITEXTCTL_GetTextPtr(pWin->m_pText2);
  645. pWin->tpResponseFunction(pText1,pText2);
  646. }
  647. IWINSTACK_CloseWindow(TRUE);
  648. break;
  649. default:
  650. IWINSTACK_CloseWindow(TRUE);
  651. }
  652. return TRUE;
  653. }
  654. static boolean IINPUTWINDOW_SetActiveCtl(IInputWin* pWin,TInputCtlType nTextCtl)
  655. {
  656. //当nTextCtl=INPUT_SOFTKEYCTL,不显示任何文本控件
  657. //当text2不存在时,无论nTextCtl的值为多少,都显示text1
  658. //当text2存在时,nTextCtl=INPUT_TEXT1CTL,显示text1,否则显示text2
  659. switch(nTextCtl)
  660. {
  661. case INPUT_SOFTKEYCTL:
  662. ITEXTCTL_SetActive(pWin->m_pText1, FALSE);
  663. if ((pWin->m_pText2) && (ITEXTCTL_IsActive(pWin->m_pText2)))
  664. ITEXTCTL_SetActive(pWin->m_pText2, FALSE);
  665. IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, TRUE);
  666. IMENUCTL_SetSel(pWin->m_pSoftKeyCtl, INPUT_SOFTKEY_ITEM_INPUT_MODE);
  667. break;
  668. case INPUT_TEXT2CTL:
  669. if(pWin->m_pText2)
  670. {
  671. ITEXTCTL_SetInputMode(pWin->m_pText2, pWin->m_wMode);
  672. IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, FALSE);
  673. ITEXTCTL_SetActive(pWin->m_pText1, FALSE);
  674. ITEXTCTL_SetCursorPos(pWin->m_pText2, TC_CURSOREND);
  675. ITEXTCTL_SetActive(pWin->m_pText2, TRUE);
  676. break;
  677. }
  678. default:
  679. ITEXTCTL_SetInputMode(pWin->m_pText1, pWin->m_wMode);
  680. IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, FALSE);
  681. if (pWin->m_pText2)
  682. ITEXTCTL_SetActive(pWin->m_pText2, FALSE);
  683. ITEXTCTL_SetCursorPos(pWin->m_pText1, TC_CURSOREND);
  684. ITEXTCTL_SetActive(pWin->m_pText1, TRUE);
  685. }
  686. return TRUE;
  687. }*/
  688. static boolean UpdateBookmark(IBookMarkWin *pWin)
  689. {
  690. char* url=NULL;
  691. AECHAR* pUrl=WSTRDUP(m_pBookmarkURL);
  692. IBookMarkWin *ptBookmarkWin = (IBookMarkWin*)pWin;
  693. uint16 MenuItemID = IMENUCTL_GetSel(ptBookmarkWin->m_pMenuCtl);
  694. IMENUCTL_GetItemData(ptBookmarkWin->m_pMenuCtl, MenuItemID, (uint32 *) &url);
  695. FREEIF(url);
  696. IMENUCTL_DeleteItem(ptBookmarkWin->m_pMenuCtl, MenuItemID);
  697. if (m_pBookmarkName)
  698. IMENUCTL_AddItem(ptBookmarkWin->m_pMenuCtl, WAP_BOOKMARKS_FILENAME, 0, MenuItemID, (AECHAR *)m_pBookmarkName, (uint32)pUrl);
  699. else
  700. IMENUCTL_AddItem(ptBookmarkWin->m_pMenuCtl, WAP_BOOKMARKS_FILENAME, 0, MenuItemID, (AECHAR *)pUrl, (uint32)pUrl);
  701. IMENUCTL_SetSel(ptBookmarkWin->m_pMenuCtl, MenuItemID);
  702. WriteBookmarks(ptBookmarkWin);
  703. return TRUE;
  704. }
  705. #endif