IBookMark.c
资源名称:MenuList.rar [点击查看]
上传用户:duwei1288
上传日期:2009-12-27
资源大小:451k
文件大小:26k
源码类别:
BREW编程
开发平台:
Visual C++
- #include "IBookMark.h"
- #include "IBookmarkFile.h"
- #include "MenuList_res.h"
- #include "Windowstack.h"
- ////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////
- typedef enum
- {
- INPUT_SOFTKEY_ITEM = 1,
- INPUT_SOFTKEY_ITEM_GOTO,
- INPUT_SOFTKEY_ITEM_EDIT,
- INPUT_SOFTKEY_ITEM_NEW,
- INPUT_SOFTKEY_ITEM_DEL
- }TBMWinWinItems;
- ////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////
- static boolean IBOOKMARKWIN_HandleKeyEvent(IBookMarkWin* pWin,uint16 wParam);
- static boolean IBOOKMARKWIN_HandleSoftButtonsEvent(IBookMarkWin *pWin, uint16 wParam);
- ////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////
- void* IBOOKMARKWIN_Create(IShell* pShell,void* pParam)
- {
- AEERect MenuRect;
- AEERect SoftRect;
- IBookMarkWin *ptBookmarkWin=NULL;
- if(!pShell) return NULL;
- ptBookmarkWin= MALLOCREC(IBookMarkWin);
- if (!ptBookmarkWin)
- return NULL;
- //创建菜单
- if(SUCCESS!=ISHELL_CreateInstance(pShell, AEECLSID_MENUCTL, (void **)&(ptBookmarkWin->m_pMenuCtl)))
- {
- IBOOKMARKWIN_Release(pShell,&ptBookmarkWin);
- return NULL;
- }
- //创建软键
- if(SUCCESS!=ISHELL_CreateInstance(pShell, AEECLSID_SOFTKEYCTL, (void **)&(ptBookmarkWin->m_pSoftKeyCtl)))
- {
- IBOOKMARKWIN_Release(pShell,&ptBookmarkWin);
- return NULL;
- }
- IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_GOTO,INPUT_SOFTKEY_ITEM_GOTO, NULL, 0);
- IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_EDIT, INPUT_SOFTKEY_ITEM_EDIT, NULL, 0);
- IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl,MENULIST_RES_FILE, IDS_NEW, INPUT_SOFTKEY_ITEM_NEW, NULL, 0);
- IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_DEL,INPUT_SOFTKEY_ITEM_DEL, NULL, 0);
- //设置显示区域
- IMENUCTL_GetRect(ptBookmarkWin->m_pMenuCtl, &MenuRect);
- IMENUCTL_GetRect(ptBookmarkWin->m_pSoftKeyCtl, &SoftRect);
- MenuRect.dy = (int16)(SoftRect.y);
- IMENUCTL_SetRect(ptBookmarkWin->m_pMenuCtl, &MenuRect);
- //打开书签文件
- IBOOKMARKFILE_CreateInstance();
- return ptBookmarkWin;
- }
- boolean IBOOKMARKWIN_Release(IShell* pShell,void** pWin)
- {
- IBookMarkWin *ptBookmarkWin=*pWin;
- if(ptBookmarkWin)
- {
- if(ptBookmarkWin->m_pMenuCtl)
- IMENUCTL_Release(ptBookmarkWin->m_pMenuCtl);
- if(ptBookmarkWin->m_pSoftKeyCtl)
- IMENUCTL_Release(ptBookmarkWin->m_pSoftKeyCtl);
- }
- FREEIF(*pWin);
- return IBOOKMARKFILE_Release();
- }
- boolean IBOOKMARKWIN_Redraw(IShell* pShell,void* pWin)
- {
- AECHAR* pName=NULL;
- uint32 ulID=0;
- uint16 usItemID=1;
- IBookMarkWin *ptBookmarkWin=(IBookMarkWin*)pWin;
- if(!ptBookmarkWin||!ptBookmarkWin->m_pMenuCtl||!ptBookmarkWin->m_pSoftKeyCtl)
- return FALSE;
- //初始化数据
- IBOOKMARKFILE_StartToSeek();
- IMENUCTL_DeleteAll(ptBookmarkWin->m_pMenuCtl);
- //将数据读入列表
- while(IBOOKMARKFILE_GetNext(&pName,&ulID))
- {
- if(pName)
- IMENUCTL_AddItem(ptBookmarkWin->m_pMenuCtl, MENULIST_RES_FILE, 0, usItemID++, pName, ulID);
- }
- //绘制控键
- IMENUCTL_SetActive(ptBookmarkWin->m_pMenuCtl,TRUE);
- IMENUCTL_SetActive(ptBookmarkWin->m_pSoftKeyCtl,FALSE);
- IMENUCTL_Redraw(ptBookmarkWin->m_pMenuCtl);
- IMENUCTL_Redraw(ptBookmarkWin->m_pSoftKeyCtl);
- return TRUE;
- }
- boolean IBOOKMARKWIN_EventHandle(void* pWin,AEEEvent eCode, uint16 wParam, uint32 dwParam)
- {
- IBookMarkWin* pInputWin=(IBookMarkWin*)pWin;
- switch(eCode)
- {
- case EVT_KEY:
- return IBOOKMARKWIN_HandleKeyEvent(pInputWin,wParam);
- case EVT_COMMAND:
- return IBOOKMARKWIN_HandleSoftButtonsEvent(pInputWin,wParam);
- default:
- return FALSE;
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////
- static boolean IBOOKMARKWIN_HandleKeyEvent(IBookMarkWin* pWin,uint16 wParam)
- {
- boolean bDispatched = FALSE;
- if(!pWin||!pWin->m_pMenuCtl||!pWin->m_pSoftKeyCtl) return FALSE;
- switch(wParam)
- {
- case AVK_UP:
- case AVK_DOWN:
- if(IMENUCTL_IsActive(pWin->m_pSoftKeyCtl))
- {
- IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, FALSE);
- bDispatched = TRUE;
- }
- else
- bDispatched=IMENUCTL_HandleEvent(pWin->m_pMenuCtl,EVT_KEY,wParam,0);
- break;
- case AVK_CLR:
- IWINSTACK_CloseWindow(TRUE);
- bDispatched = TRUE;
- break;
- case AVK_SELECT:
- if(!IMENUCTL_IsActive(pWin->m_pSoftKeyCtl))
- {
- IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, TRUE);
- bDispatched = TRUE;
- }
- else
- bDispatched=IMENUCTL_HandleEvent(pWin->m_pSoftKeyCtl,EVT_KEY,wParam,0);
- break;
- case AVK_RIGHT:
- case AVK_LEFT:
- if(IMENUCTL_IsActive(pWin->m_pSoftKeyCtl))
- bDispatched = IMENUCTL_HandleEvent(pWin->m_pSoftKeyCtl, EVT_KEY, wParam, 0);
- break;
- }
- return bDispatched;
- }
- static boolean IBOOKMARKWIN_HandleSoftButtonsEvent(IBookMarkWin* pWin,uint16 wParam)
- {
- //CtlAddItem InfoStruct;
- /*
- InputTextInfo Info1;
- InputTextInfo Info2;
- boolean bDispatched = FALSE;
- //AECHAR DlgTitle[BOOKMARKLEN];
- AECHAR DlgTitle[BOOKMARKLEN];
- AECHAR DlgUrl[BOOKMARKLEN];
- AECHAR *AWideUrl=NULL;
- AECHAR BkMrkStr[] = { ' ' };
- AECHAR BktitleStr[] = { ' ' };
- AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
- IBookMarkWin *ptBookmarkWin = NULL;
- CtlAddItem InfoStruct;
- ptBookmarkWin = pWin;
- switch (wParam)
- {
- case INPUT_SOFTKEY_ITEM_NEW:
- ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_BOOKMARKTITLE, DlgTitle, sizeof(DlgTitle));
- ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_URL, DlgUrl, sizeof(DlgUrl));
- IMENUCTL_SetActive(ptBookmarkWin->m_pMenuCtl, FALSE);
- IMENUCTL_SetActive(ptBookmarkWin->m_pSoftKeyCtl, TRUE);
- Info1.m_inputType=IT_TEXT;
- Info1.m_pText=ISETTINGFILE_GetStr(WAP_BOOKMARKNAME);
- Info1.m_pTitle=DlgTitle;
- Info2.m_inputType=IT_TEXT;
- Info2.m_pText=ISETTINGFILE_GetStr(WAP_BOOKMARKURL);
- Info2.m_pTitle=DlgUrl;
- //bDispatched = TRUE;
- return NewTextInputDialog(&Info1,&Info2,WAPSetHdl_SetNewBookMarkDlgResponse);
- case INPUT_SOFTKEY_ITEM_EDIT:
- if (IMENUCTL_GetItemCount(ptBookmarkWin->m_pMenuCtl) == 0)
- return TRUE;
- ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_BOOKMARKTITLE, DlgTitle, sizeof(DlgTitle));
- ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_URL, DlgUrl, sizeof(DlgUrl));
- IMENUCTL_GetItem(ptBookmarkWin->m_pMenuCtl, IMENUCTL_GetSel(ptBookmarkWin->m_pMenuCtl), &InfoStruct);
- IMENUCTL_SetActive(ptBookmarkWin->m_pMenuCtl, FALSE);
- AWideUrl=WSTRDUP(InfoStruct.dwData);
- Info1.m_inputType=IT_TEXT;
- Info1.m_pText=InfoStruct.pText;
- Info1.m_pTitle=DlgTitle;
- Info2.m_inputType=IT_TEXT;
- Info2.m_pText=AWideUrl;
- Info2.m_pTitle=DlgUrl;
- FREEIF(m_pBookmarkURL);
- FREEIF(m_pBookmarkName);
- return NewTextInputDialog(&Info1,&Info2,WAPSetHdl_SetEditBookMarkDlgResponse);
- case INPUT_SOFTKEY_ITEM_DEL:
- if (IMENUCTL_GetItemCount(ptBookmarkWin->m_pMenuCtl) == 0)
- return TRUE;
- IMENUCTL_GetItem(ptBookmarkWin->m_pMenuCtl, IMENUCTL_GetSel(ptBookmarkWin->m_pMenuCtl), &InfoStruct);
- FREEIF(InfoStruct.dwData);
- IMENUCTL_DeleteItem(ptBookmarkWin->m_pMenuCtl, IMENUCTL_GetSel(ptBookmarkWin->m_pMenuCtl));
- WriteBookmarks(ptBookmarkWin);
- IMENUCTL_Redraw(ptBookmarkWin->m_pMenuCtl);
- bDispatched = TRUE;
- break;
- }*/
- return TRUE;
- }
- #if 0
- /////////////////////////Static Function//////////////////////
- static boolean BOOKMARKWIN_HandleKeyEvent(IBookMarkWin* pWin,uint16 wParam);
- static boolean BOOKMARKWIN_HandleSoftButtonsEvent(IBookMarkWin *pWin, uint16 wParam);
- static void ReadBookmarks(IFileMgr *pIFileMgr, IFile *pIFile, IBookMarkWin *ptBookmarkWin);
- static boolean WAPSetHdl_SetNewBookMarkDlgResponse(void*Applet, void* pPtr, const AECHAR *response1, const AECHAR *response2, boolean bOK);
- static boolean WAPSetHdl_SetEditBookMarkDlgResponse(void*Applet, void* pPtr, const AECHAR *response1, const AECHAR *response2, boolean bOK);
- static boolean UpdateBookmark(IBookMarkWin *pWin);
- static void WriteBookmarks(IBookMarkWin*ptBookmarkWin);
- #define BOOKMARKLEN 160+2
- #define MENU_X 7 //3级菜单正文区起始横坐标
- #define MENU_Y (32) //3级菜单正文区起始纵坐标
- #define MENU_W (SCREEN_W-7-8) //161,3级菜单正文区宽度
- #define MENU_SK_2LINE_H (SCREEN_H-32-9-22-16) //123,3级菜单(有2行softkey)中MENU控件高度
- #define MENU_SK_1LINE_H (SCREEN_H-32-9-22)
- //#define INPUT_TEXT_X_START 2
- //#define INPUT_TEXT_Y_START 0
- //#define INPUT_TEXT_MAX_SIZE 150
- #define WAP_BOOKMARKS_FILENAME "MenuList/bookmarks.dat"
- //窗口的控件
- typedef enum
- {
- INPUT_SOFTKEYCTL=0,
- INPUT_MENUCTL
- }TBMWinCtlType;
- //软键控件的ItemId定义
- typedef enum
- {
- INPUT_SOFTKEY_ITEM = 1,
- INPUT_SOFTKEY_ITEM_GOTO,
- INPUT_SOFTKEY_ITEM_EDIT,
- INPUT_SOFTKEY_ITEM_NEW,
- INPUT_SOFTKEY_ITEM_DEL
- }TBMWinWinItems;
- ///////////////////////////////////////////////////////////////////
- AECHAR* m_pBookmarkURL=NULL;
- AECHAR* m_pBookmarkName=NULL;
- //按键事件的处理
- //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 BookmarksDlg()
- {
- AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
- AEERect MenuRect;
- AEERect SoftRect;
- IFile *pIFile;
- IFileMgr *pIFileMgr = NULL;
- IBookMarkWin *ptBookmarkWin = (IBookMarkWin *)MALLOC(sizeof(IBookMarkWin));
- //AEERect m_rc;
- if (NULL == ptBookmarkWin)
- return FALSE;
- ISHELL_CreateInstance(pApp->m_pIShell, AEECLSID_MENUCTL, (void **)&(ptBookmarkWin->m_pMenuCtl));
- if(SUCCESS!=ISHELL_CreateInstance(pApp->m_pIShell,AEECLSID_SOFTKEYCTL,(void **)&(ptBookmarkWin->m_pSoftKeyCtl)))
- {
- BOOKMARKWIN_Release(pApp->m_pIShell,&ptBookmarkWin);
- return FALSE;
- }
- IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_GOTO,INPUT_SOFTKEY_ITEM_GOTO, NULL, 0);
- IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_EDIT, INPUT_SOFTKEY_ITEM_EDIT, NULL, 0);
- IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl,MENULIST_RES_FILE, IDS_NEW, INPUT_SOFTKEY_ITEM_NEW, NULL, 0);
- IMENUCTL_AddItem(ptBookmarkWin->m_pSoftKeyCtl, MENULIST_RES_FILE, IDS_DEL,INPUT_SOFTKEY_ITEM_DEL, NULL, 0);
- if (ISHELL_CreateInstance(pApp->m_pIShell, AEECLSID_FILEMGR, (void **)&pIFileMgr) != SUCCESS) {
- BOOKMARKWIN_Release(pApp->m_pIShell, &ptBookmarkWin);
- return FALSE ;
- }
- if (IFILEMGR_Test(pIFileMgr, WAP_BOOKMARKS_FILENAME) == EFAILED) {
- pIFile = IFILEMGR_OpenFile(pIFileMgr, WAP_BOOKMARKS_FILENAME, _OFM_CREATE);
- }
- else {
- if ((pIFile = IFILEMGR_OpenFile(pIFileMgr, WAP_BOOKMARKS_FILENAME, _OFM_READWRITE)) == NULL) {
- IFILEMGR_Release(pIFileMgr);
- // free menus here
- return FALSE;
- }
- ReadBookmarks(pIFileMgr, pIFile, ptBookmarkWin);
- }
- IMENUCTL_Sort(ptBookmarkWin->m_pSoftKeyCtl, MCS_NAME_ASCENDING);
- IMENUCTL_GetRect(ptBookmarkWin->m_pMenuCtl, &MenuRect);
- IMENUCTL_GetRect(ptBookmarkWin->m_pSoftKeyCtl, &SoftRect);
- MenuRect.dy = (int16)(SoftRect.y);
- IMENUCTL_SetRect(ptBookmarkWin->m_pMenuCtl, &MenuRect);
- //IMENUCTL_SetActive(ptBookmarkWin->m_pSoftKeyCtl,TRUE);
- IMENUCTL_Redraw((IMenuCtl *) ptBookmarkWin->m_pMenuCtl);
- IMENUCTL_SetActive(ptBookmarkWin->m_pMenuCtl, TRUE);
- IMENUCTL_Redraw((IMenuCtl *) ptBookmarkWin->m_pSoftKeyCtl); //liting 20040605
- IFILE_Release(pIFile);
- IFILEMGR_Release(pIFileMgr);
- return IWINSTACK_OpenWindow(WAPWINID_BOOKMARK, ptBookmarkWin);
- }
- void* BOOKMARKWIN_Create(IShell* pShell,void* pParam)
- {
- pShell=pShell;
- return pParam;
- }
- boolean BOOKMARKWIN_Release(IShell* pShell,void** pWin)
- {
- IBookMarkWin* pInputWin=*pWin;
- AECHAR *url;
- FREEIF(m_pBookmarkURL);
- FREEIF(m_pBookmarkName);
- if(pInputWin)
- {
- if(pInputWin->m_pSoftKeyCtl)
- IMENUCTL_DeleteAll(pInputWin->m_pSoftKeyCtl);
- IMENUCTL_Release(pInputWin->m_pSoftKeyCtl);
- if(pInputWin->m_pMenuCtl)
- {
- while (IMENUCTL_GetItemCount(pInputWin->m_pMenuCtl))
- {
- uint16 itemid = IMENUCTL_GetItemID(pInputWin->m_pMenuCtl, 0);
- IMENUCTL_GetItemData(pInputWin->m_pMenuCtl, itemid, (uint32 *) &url);
- FREEIF(url);
- IMENUCTL_DeleteItem(pInputWin->m_pMenuCtl, itemid);
- }
- IMENUCTL_Release(pInputWin->m_pMenuCtl);
- }
- FREEIF(*pWin);
- }
- return TRUE;
- }
- boolean BOOKMARKWIN_Redraw(IShell* pShell,void* pWin)//读文件并显示出来
- {
- IFile *pIFile;
- IFileMgr *pIFileMgr = NULL;
- AEERect rect;
- AECHAR buf[30];
- uint16 MenuItemID;
- IBookMarkWin* pBookmarkWin=pWin;
- AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
- if(pBookmarkWin&&pApp)
- {
- if(m_pBookmarkURL)
- {
- UpdateBookmark(pBookmarkWin);
- FREEIF(m_pBookmarkURL);
- FREEIF(m_pBookmarkName);
- }
- if (ISHELL_CreateInstance(pApp->m_pIShell, AEECLSID_FILEMGR, (void **)&pIFileMgr) != SUCCESS)
- {
- BOOKMARKWIN_Release(pApp->m_pIShell, &pBookmarkWin);
- return FALSE ;
- }
- pIFile = IFILEMGR_OpenFile(pIFileMgr, WAP_BOOKMARKS_FILENAME, _OFM_READWRITE);
- ReadBookmarks(pIFileMgr, pIFile, pBookmarkWin);//显示出来
- IFILEMGR_Release(pIFileMgr);
- IFILE_Release(pIFile);
- SETAEERECT(&rect, 20, 10, 150, 25);
- ISHELL_LoadResString (pApp->m_pIShell,
- MENULIST_RES_FILE,
- IDS_BOOKMARK,
- buf,
- sizeof(buf));
- //Display
- (void) IDISPLAY_DrawText(pApp->m_pIDisplay,
- AEE_FONT_NORMAL,
- buf,
- -1,
- 0,
- 0,
- &rect,
- IDF_ALIGN_RIGHT
- |IDF_ALIGN_MIDDLE
- |IDF_TEXT_TRANSPARENT);
- IDISPLAY_Update(pApp->m_pIDisplay);
- IDISPLAY_SetColor(pApp->m_pIDisplay,CLR_USER_TEXT, MAKE_RGB(0,0,0));
- IMENUCTL_SetActive(pBookmarkWin->m_pMenuCtl, TRUE);
- MenuItemID = IMENUCTL_GetItemID(pBookmarkWin->m_pMenuCtl, IMENUCTL_GetItemCount(pBookmarkWin->m_pMenuCtl) - 1);
- IMENUCTL_Sort(pBookmarkWin->m_pMenuCtl, MCS_NAME_ASCENDING);
- IMENUCTL_SetSel(pBookmarkWin->m_pMenuCtl, MenuItemID);
- IMENUCTL_Redraw(pBookmarkWin->m_pMenuCtl);
- IMENUCTL_SetSel(pBookmarkWin->m_pSoftKeyCtl, IDS_GOTO);
- IMENUCTL_Redraw(pBookmarkWin->m_pSoftKeyCtl);
- IDISPLAY_ClearScreen(pApp->m_pIDisplay);
- if(pBookmarkWin->m_pMenuCtl)
- IMENUCTL_Redraw(pBookmarkWin->m_pMenuCtl);
- if(pBookmarkWin->m_pSoftKeyCtl)
- IMENUCTL_Redraw(pBookmarkWin->m_pSoftKeyCtl);
- IDISPLAY_Update(pApp->m_pIDisplay);
- }
- return TRUE;
- }
- boolean BOOKMARKWIN_EventHandle(void* pWin,AEEEvent eCode, uint16 wParam, uint32 dwParam)
- {
- IBookMarkWin* pInputWin=pWin;
- boolean bDispatched = FALSE;
- //CMenuList *pApp = (CMenuList *) pWin;
- if(NULL==pInputWin) return FALSE;
- switch(eCode)
- {
- case EVT_KEY:
- bDispatched=BOOKMARKWIN_HandleKeyEvent(pInputWin,wParam);
- break;
- case EVT_COMMAND:
- bDispatched=BOOKMARKWIN_HandleSoftButtonsEvent(pInputWin,wParam);
- break;
- }
- return bDispatched;
- }
- ///////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////////
- static boolean BOOKMARKWIN_HandleKeyEvent(IBookMarkWin* pWin,uint16 wParam)
- {
- IBookMarkWin* pInputWin=pWin;
- boolean bDispatched = FALSE;
- if(NULL==pInputWin) return FALSE;
- switch(wParam)
- {
- case AVK_UP:
- case AVK_DOWN:
- if(IMENUCTL_IsActive(pInputWin->m_pSoftKeyCtl))
- {
- IMENUCTL_SetActive(pInputWin->m_pMenuCtl, TRUE);
- IMENUCTL_SetActive(pInputWin->m_pSoftKeyCtl, FALSE);
- IMENUCTL_SetSel(pInputWin->m_pMenuCtl, INPUT_MENUCTL);
- bDispatched = TRUE;//保证每个分支都有返回
- }
- else //若当前激活是菜单控件则交由下面自己处理
- bDispatched=IMENUCTL_HandleEvent(pInputWin->m_pMenuCtl,EVT_KEY,wParam,0);
- break;
- case AVK_CLR://关闭窗口
- IWINSTACK_CloseWindow(TRUE);
- bDispatched = TRUE;
- break;
- case AVK_SELECT:
- //当软键不在激活状态时按Select会将软键设为激活
- if(pInputWin->m_pMenuCtl&&IMENUCTL_IsActive(pInputWin->m_pMenuCtl))
- {
- IMENUCTL_SetActive(pInputWin->m_pMenuCtl, FALSE);
- IMENUCTL_SetActive(pInputWin->m_pSoftKeyCtl, TRUE);
- }
- else if(pInputWin->m_pSoftKeyCtl&&IMENUCTL_IsActive(pInputWin->m_pSoftKeyCtl))
- bDispatched=IMENUCTL_HandleEvent(pInputWin->m_pSoftKeyCtl,EVT_KEY,wParam,0);
- //bDispatched = TRUE;
- break;
- case AVK_RIGHT:
- case AVK_LEFT:
- bDispatched = IMENUCTL_HandleEvent(pInputWin->m_pSoftKeyCtl, EVT_KEY, wParam, 0);
- break;
- }
- return bDispatched;
- }
- static boolean BOOKMARKWIN_HandleSoftButtonsEvent(IBookMarkWin* pWin,uint16 wParam)
- {
- //CtlAddItem InfoStruct;
- InputTextInfo Info1;
- InputTextInfo Info2;
- boolean bDispatched = FALSE;
- //AECHAR DlgTitle[BOOKMARKLEN];
- AECHAR DlgTitle[BOOKMARKLEN];
- AECHAR DlgUrl[BOOKMARKLEN];
- AECHAR *AWideUrl=NULL;
- AECHAR BkMrkStr[] = { ' ' };
- AECHAR BktitleStr[] = { ' ' };
- AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
- IBookMarkWin *ptBookmarkWin = NULL;
- CtlAddItem InfoStruct;
- ptBookmarkWin = pWin;
- switch (wParam)
- {
- case INPUT_SOFTKEY_ITEM_NEW:
- ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_BOOKMARKTITLE, DlgTitle, sizeof(DlgTitle));
- ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_URL, DlgUrl, sizeof(DlgUrl));
- IMENUCTL_SetActive(ptBookmarkWin->m_pMenuCtl, FALSE);
- IMENUCTL_SetActive(ptBookmarkWin->m_pSoftKeyCtl, TRUE);
- Info1.m_inputType=IT_TEXT;
- Info1.m_pText=ISETTINGFILE_GetStr(WAP_BOOKMARKNAME);
- Info1.m_pTitle=DlgTitle;
- Info2.m_inputType=IT_TEXT;
- Info2.m_pText=ISETTINGFILE_GetStr(WAP_BOOKMARKURL);
- Info2.m_pTitle=DlgUrl;
- //bDispatched = TRUE;
- return NewTextInputDialog(&Info1,&Info2,WAPSetHdl_SetNewBookMarkDlgResponse);
- case INPUT_SOFTKEY_ITEM_EDIT:
- if (IMENUCTL_GetItemCount(ptBookmarkWin->m_pMenuCtl) == 0)
- return TRUE;
- ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_BOOKMARKTITLE, DlgTitle, sizeof(DlgTitle));
- ISHELL_LoadResString(pApp->m_pIShell, MENULIST_RES_FILE, IDS_URL, DlgUrl, sizeof(DlgUrl));
- IMENUCTL_GetItem(ptBookmarkWin->m_pMenuCtl, IMENUCTL_GetSel(ptBookmarkWin->m_pMenuCtl), &InfoStruct);
- IMENUCTL_SetActive(ptBookmarkWin->m_pMenuCtl, FALSE);
- AWideUrl=WSTRDUP(InfoStruct.dwData);
- Info1.m_inputType=IT_TEXT;
- Info1.m_pText=InfoStruct.pText;
- Info1.m_pTitle=DlgTitle;
- Info2.m_inputType=IT_TEXT;
- Info2.m_pText=AWideUrl;
- Info2.m_pTitle=DlgUrl;
- FREEIF(m_pBookmarkURL);
- FREEIF(m_pBookmarkName);
- return NewTextInputDialog(&Info1,&Info2,WAPSetHdl_SetEditBookMarkDlgResponse);
- case INPUT_SOFTKEY_ITEM_DEL:
- if (IMENUCTL_GetItemCount(ptBookmarkWin->m_pMenuCtl) == 0)
- return TRUE;
- IMENUCTL_GetItem(ptBookmarkWin->m_pMenuCtl, IMENUCTL_GetSel(ptBookmarkWin->m_pMenuCtl), &InfoStruct);
- FREEIF(InfoStruct.dwData);
- IMENUCTL_DeleteItem(ptBookmarkWin->m_pMenuCtl, IMENUCTL_GetSel(ptBookmarkWin->m_pMenuCtl));
- WriteBookmarks(ptBookmarkWin);
- IMENUCTL_Redraw(ptBookmarkWin->m_pMenuCtl);
- bDispatched = TRUE;
- break;
- }
- return TRUE;
- }
- static boolean WAPSetHdl_SetNewBookMarkDlgResponse(const AECHAR *response1, const AECHAR *response2, boolean bOK)
- {
- IFile *pIFile;
- IFileMgr *pIFileMgr = NULL;
- AEEApplet* pApp= (AEEApplet*)GETAPPINSTANCE();
- AECHAR pBug[] = {'r','n',' '};
- if (response2 != NULL && bOK == TRUE)
- {
- if (ISHELL_CreateInstance(pApp->m_pIShell, AEECLSID_FILEMGR, (void **)&pIFileMgr) != SUCCESS)
- return FALSE;
- if ((pIFile = IFILEMGR_OpenFile(pIFileMgr, WAP_BOOKMARKS_FILENAME, _OFM_READWRITE)) == NULL)
- {
- IFILEMGR_Release(pIFileMgr);
- return FALSE;
- }
- IFILE_Seek(pIFile, _SEEK_END, 0); // goto end of file...
- IFILE_Write(pIFile, response1, 2*WSTRLEN(response1));
- IFILE_Write(pIFile, pBug, sizeof(pBug));//以回车换行区别每条
- IFILE_Write(pIFile, response2, 2*WSTRLEN(response2));
- IFILE_Write(pIFile, pBug, sizeof(pBug));
- IFILE_Release(pIFile);
- IFILEMGR_Release(pIFileMgr);
- }
- return TRUE;
- }
- static boolean WAPSetHdl_SetEditBookMarkDlgResponse(const AECHAR *response1, const AECHAR *response2, boolean bOK)
- {
- AEEApplet *pApp = (AEEApplet*)GETAPPINSTANCE();
- if((response2 == NULL)||(bOK != TRUE))
- return FALSE;
- if(response2)
- m_pBookmarkURL=WSTRDUP(response2);
- if(response1)
- m_pBookmarkName=WSTRDUP(response1);
- return TRUE;
- }
- static void ReadBookmarks(IFileMgr *pIFileMgr, IFile *pIFile, IBookMarkWin *ptBookmarkWin)
- {
- FileInfo Info;
- AECHAR* AWideTitle=NULL;
- AECHAR *Inbuff = NULL;
- uint16 MenuID = 0;
- AECHAR *url;
- //int bmLen;
- AECHAR *lfpos;
- AECHAR *strpos;
- // delete all items, and corresponding data
- while (IMENUCTL_GetItemCount(ptBookmarkWin->m_pMenuCtl)) {
- uint16 itemid = IMENUCTL_GetItemID(ptBookmarkWin->m_pMenuCtl, 0);
- IMENUCTL_GetItemData(ptBookmarkWin->m_pMenuCtl, itemid, (uint32 *) &url);
- FREEIF(url);
- IMENUCTL_DeleteItem(ptBookmarkWin->m_pMenuCtl, itemid);
- }
- IFILEMGR_GetInfo(pIFileMgr, WAP_BOOKMARKS_FILENAME, &Info);
- if (Info.dwSize > 1) {
- Inbuff = MALLOC(Info.dwSize + 2);
- if (NULL == Inbuff)
- return ;
- IFILE_Read(pIFile, Inbuff, Info.dwSize);
- strpos = Inbuff;
- for (MenuID = 1; (uint32)(strpos - Inbuff) < Info.dwSize; MenuID++) {
- lfpos = WSTRCHR(strpos, 'r');
- if (!lfpos || !lfpos[0])
- break; //
- lfpos[0] = ' '; // nullterminate the string
- //STRTOWSTR(strpos, AWideTitle, BOOKMARKLEN);
- AWideTitle=MALLOC(2*WSTRLEN(strpos));
- WSTRCPY(AWideTitle, strpos);
- strpos = lfpos + 3;
- lfpos = WSTRCHR(strpos, 'r');
- if (!lfpos || !lfpos[0])
- break; //
- lfpos[0] = ' '; // 在找到的一条记录末尾添零表示这是一条字符串
- url = WSTRDUP(strpos);
- strpos = lfpos + 3;
- IMENUCTL_AddItem(ptBookmarkWin->m_pMenuCtl, MENULIST_RES_FILE, 0, MenuID, AWideTitle, (uint32)url);
- FREEIF(AWideTitle);
- }
- FREE(Inbuff);
- }
- }
- static void WriteBookmarks(IBookMarkWin*ptBookmarkWin)
- {
- IFile *pIFile;
- int Index;
- int NumBkmrks;
- CtlAddItem InfoStruct;
- AECHAR* ATitle;
- AEEApplet *pApp = (AEEApplet*)(GETAPPINSTANCE());
- IFileMgr *pIFileMgr = NULL;
- AECHAR pBug[] = {'r','n',' '};
- if (ISHELL_CreateInstance(pApp->m_pIShell, AEECLSID_FILEMGR, (void **)&pIFileMgr) != SUCCESS)
- return ;
- IFILEMGR_Remove(pIFileMgr, WAP_BOOKMARKS_FILENAME);
- if ((pIFile = IFILEMGR_OpenFile(pIFileMgr, WAP_BOOKMARKS_FILENAME, _OFM_CREATE)) == NULL) {
- IFILEMGR_Release(pIFileMgr);
- return ;
- }
- NumBkmrks = IMENUCTL_GetItemCount(ptBookmarkWin->m_pMenuCtl);
- for (Index = 0; Index < NumBkmrks; Index++)
- {
- IMENUCTL_GetItem(ptBookmarkWin->m_pMenuCtl, IMENUCTL_GetItemID(ptBookmarkWin->m_pMenuCtl, Index), &InfoStruct);
- //WSTRTOUTF8(InfoStruct.pText, WSTRLEN(InfoStruct.pText)+1, (byte *) ATitle, BOOKMARKLEN);
- ATitle=WSTRDUP(InfoStruct.pText);
- if(!ATitle) continue;
- IFILE_Write(pIFile, ATitle, 2*WSTRLEN((const char *)ATitle));
- IFILE_Write(pIFile, pBug, sizeof(pBug));
- IFILE_Write(pIFile, (char *)InfoStruct.dwData, 2*WSTRLEN((const char *)InfoStruct.dwData));
- IFILE_Write(pIFile, pBug,sizeof(pBug));
- FREE(ATitle);
- }
- IFILEMGR_Release(pIFileMgr);
- IFILE_Release(pIFile);
- }
- /*static boolean IINPUTWINDOW_HandleCommandEvent(IInputWin* pWin,uint16 wParam)
- {
- IInputWin* pInputWin=pWin;
- boolean bDispatched = FALSE;
- if(NULL==pInputWin) return FALSE;
- //
- switch(wParam)
- {
- case INPUT_SOFTKEY_ITEM_INPUT_MODE:
- break;
- case INPUT_SOFTKEY_ITEM_DONE:
- if(pWin->tpResponseFunction)
- {
- AECHAR* pText1=NULL;
- AECHAR* pText2=NULL;
- pText1=ITEXTCTL_GetTextPtr(pWin->m_pText1);
- if(pWin->m_pText2)
- pText2=ITEXTCTL_GetTextPtr(pWin->m_pText2);
- pWin->tpResponseFunction(pText1,pText2);
- }
- IWINSTACK_CloseWindow(TRUE);
- break;
- default:
- IWINSTACK_CloseWindow(TRUE);
- }
- return TRUE;
- }
- static boolean IINPUTWINDOW_SetActiveCtl(IInputWin* pWin,TInputCtlType nTextCtl)
- {
- //当nTextCtl=INPUT_SOFTKEYCTL,不显示任何文本控件
- //当text2不存在时,无论nTextCtl的值为多少,都显示text1
- //当text2存在时,nTextCtl=INPUT_TEXT1CTL,显示text1,否则显示text2
- switch(nTextCtl)
- {
- case INPUT_SOFTKEYCTL:
- ITEXTCTL_SetActive(pWin->m_pText1, FALSE);
- if ((pWin->m_pText2) && (ITEXTCTL_IsActive(pWin->m_pText2)))
- ITEXTCTL_SetActive(pWin->m_pText2, FALSE);
- IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, TRUE);
- IMENUCTL_SetSel(pWin->m_pSoftKeyCtl, INPUT_SOFTKEY_ITEM_INPUT_MODE);
- break;
- case INPUT_TEXT2CTL:
- if(pWin->m_pText2)
- {
- ITEXTCTL_SetInputMode(pWin->m_pText2, pWin->m_wMode);
- IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, FALSE);
- ITEXTCTL_SetActive(pWin->m_pText1, FALSE);
- ITEXTCTL_SetCursorPos(pWin->m_pText2, TC_CURSOREND);
- ITEXTCTL_SetActive(pWin->m_pText2, TRUE);
- break;
- }
- default:
- ITEXTCTL_SetInputMode(pWin->m_pText1, pWin->m_wMode);
- IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, FALSE);
- if (pWin->m_pText2)
- ITEXTCTL_SetActive(pWin->m_pText2, FALSE);
- ITEXTCTL_SetCursorPos(pWin->m_pText1, TC_CURSOREND);
- ITEXTCTL_SetActive(pWin->m_pText1, TRUE);
- }
- return TRUE;
- }*/
- static boolean UpdateBookmark(IBookMarkWin *pWin)
- {
- char* url=NULL;
- AECHAR* pUrl=WSTRDUP(m_pBookmarkURL);
- IBookMarkWin *ptBookmarkWin = (IBookMarkWin*)pWin;
- uint16 MenuItemID = IMENUCTL_GetSel(ptBookmarkWin->m_pMenuCtl);
- IMENUCTL_GetItemData(ptBookmarkWin->m_pMenuCtl, MenuItemID, (uint32 *) &url);
- FREEIF(url);
- IMENUCTL_DeleteItem(ptBookmarkWin->m_pMenuCtl, MenuItemID);
- if (m_pBookmarkName)
- IMENUCTL_AddItem(ptBookmarkWin->m_pMenuCtl, WAP_BOOKMARKS_FILENAME, 0, MenuItemID, (AECHAR *)m_pBookmarkName, (uint32)pUrl);
- else
- IMENUCTL_AddItem(ptBookmarkWin->m_pMenuCtl, WAP_BOOKMARKS_FILENAME, 0, MenuItemID, (AECHAR *)pUrl, (uint32)pUrl);
- IMENUCTL_SetSel(ptBookmarkWin->m_pMenuCtl, MenuItemID);
- WriteBookmarks(ptBookmarkWin);
- return TRUE;
- }
- #endif