IBookMark.c
资源名称:MenuList.rar [点击查看]
上传用户:duwei1288
上传日期:2009-12-27
资源大小:451k
文件大小:8k
源码类别:
BREW编程
开发平台:
Visual C++
- #include "IBookMark.h"
- #include "IBookmarkFile.h"
- #include "MenuList.brh"
- #include "Windowstack.h"
- #include "IInputwindow.h"
- ////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////
- #define BOOKMARKLEN 160+2
- 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);
- static boolean SetNewBookMarkDlgRespons(const AECHAR *response1, const AECHAR *response2, boolean bOK);
- static boolean SetEditBookMarkDlgResponse(const AECHAR *response1, const AECHAR *response2, boolean bOK);
- ////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////
- 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;
- boolean bActive;
- uint16 usItemID=1;
- IBookMarkWin *ptBookmarkWin=(IBookMarkWin*)pWin;
- if(!ptBookmarkWin||!ptBookmarkWin->m_pMenuCtl||!ptBookmarkWin->m_pSoftKeyCtl)
- return FALSE;
- //初始化数据
- bActive=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,bActive);
- bActive=!bActive;
- IMENUCTL_SetActive(ptBookmarkWin->m_pSoftKeyCtl,bActive);
- 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;
- uint32 uiID;
- AECHAR DlgTitle[BOOKMARKLEN];
- AECHAR DlgUrl[BOOKMARKLEN];
- AEEApplet* pApp=(AEEApplet*)GETAPPINSTANCE();
- CtlAddItem InfoStruct;
- 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(pWin->m_pMenuCtl, FALSE);
- IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, FALSE);
- Info1.m_inputType=IT_TEXT;
- Info1.m_pText=NULL;
- Info1.m_pTitle=DlgTitle;
- Info2.m_inputType=IT_TEXT;
- Info2.m_pText=NULL;
- Info2.m_pTitle=DlgUrl;
- return NewTextInputDialog(&Info1,&Info2,SetNewBookMarkDlgRespons);
- case INPUT_SOFTKEY_ITEM_EDIT:
- if(IMENUCTL_GetItemCount(pWin->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(pWin->m_pMenuCtl, IMENUCTL_GetSel(pWin->m_pMenuCtl), &InfoStruct);
- IMENUCTL_SetActive(pWin->m_pMenuCtl, FALSE);
- IMENUCTL_SetActive(pWin->m_pSoftKeyCtl, FALSE);
- Info1.m_inputType=IT_TEXT;
- Info1.m_pText=(AECHAR*)InfoStruct.pText;
- Info1.m_pTitle=DlgTitle;
- Info2.m_inputType=IT_TEXT;
- Info2.m_pText=IBOOKMARKFILE_GetUrl(InfoStruct.dwData);
- Info2.m_pTitle=DlgUrl;
- IBOOKMARKFILE_EditStart(InfoStruct.dwData);
- return NewTextInputDialog(&Info1,&Info2,SetEditBookMarkDlgResponse);
- case INPUT_SOFTKEY_ITEM_DEL:
- if(0!=IMENUCTL_GetItemCount(pWin->m_pMenuCtl))
- {
- IMENUCTL_GetItemData(pWin->m_pMenuCtl, IMENUCTL_GetSel(pWin->m_pMenuCtl), &uiID);
- IBOOKMARKFILE_RemoveBookmark(uiID);
- IBOOKMARKWIN_Redraw(pApp->m_pIShell,pWin);
- }
- bDispatched = TRUE;
- break;
- }
- return TRUE;
- }
- static boolean SetNewBookMarkDlgRespons(const AECHAR *response1, const AECHAR *response2, boolean bOK)
- {
- if(!response2||!bOK)
- return FALSE;
- if(!response1)
- response1=response2;
- return IBOOKMARKFILE_InsertBookmark((AECHAR*)response1,(AECHAR*)response2);
- }
- static boolean SetEditBookMarkDlgResponse(const AECHAR *response1, const AECHAR *response2, boolean bOK)
- {
- if(!response2||!bOK)
- return FALSE;
- if(!response1)
- response1=response2;
- return IBOOKMARKFILE_EditFinish((AECHAR*)response1,(AECHAR*)response2);
- }