From f112c043e35e8cdbc126fcaf99a1ae138b8a4e1b Mon Sep 17 00:00:00 2001 From: blueantst Date: Sun, 5 Apr 2015 01:56:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8F=E8=A7=88=E5=99=A8demo=E6=94=AF?= =?UTF-8?q?=E6=8C=81IE=E5=92=8Cwke=E5=8F=8C=E5=86=85=E6=A0=B8=EF=BC=8C?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E9=80=9A=E8=BF=87=E8=AE=BE=E7=BD=AE=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E5=86=85=E6=A0=B8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DuiVisionExplorer/DuiHandlerMain.cpp | 238 +++++++++++++++--- .../DuiVisionExplorer/DuiHandlerMain.h | 16 +- DuiVisionExplorer/DuiVisionExplorer/stdafx.h | 1 + .../bin/xml/duiexplorer/dlg_option.xml | 31 +++ .../bin/xml/duiexplorer/tab_wkeview.xml | 12 + .../bin/xml/duivision/dlg_about.xml | 6 +- .../bin/xml/duivision/dlg_main.xml | 2 +- .../bin/xml/duivision/menu_main.xml | 2 +- DuiVisionExplorer/bin/xml/resource.xml | 16 +- 9 files changed, 271 insertions(+), 53 deletions(-) create mode 100644 DuiVisionExplorer/bin/xml/duiexplorer/dlg_option.xml create mode 100644 DuiVisionExplorer/bin/xml/duiexplorer/tab_wkeview.xml diff --git a/DuiVisionExplorer/DuiVisionExplorer/DuiHandlerMain.cpp b/DuiVisionExplorer/DuiVisionExplorer/DuiHandlerMain.cpp index d28818e8..250b70bd 100644 --- a/DuiVisionExplorer/DuiVisionExplorer/DuiHandlerMain.cpp +++ b/DuiVisionExplorer/DuiVisionExplorer/DuiHandlerMain.cpp @@ -126,8 +126,8 @@ LRESULT CDuiHandlerMain::OnDuiMsgInterprocess(UINT uID, CString strName, UINT Ms return TRUE; } -// 获取Tab页中的浏览器控件 -CDuiWebBrowserCtrl* CDuiHandlerMain::GetTabWebControl(CControlBase* pTabCtrl) +// 获取Tab页中的IE浏览器控件 +CDuiWebBrowserCtrl* CDuiHandlerMain::GetTabWebIEControl(CControlBase* pTabCtrl) { if(pTabCtrl == NULL) { @@ -150,6 +150,30 @@ CDuiWebBrowserCtrl* CDuiHandlerMain::GetTabWebControl(CControlBase* pTabCtrl) return NULL; } +// 获取Tab页中的wke浏览器控件 +CDuiWkeView* CDuiHandlerMain::GetTabWebWkeControl(CControlBase* pTabCtrl) +{ + if(pTabCtrl == NULL) + { + return NULL; + } + + vector* paControls = pTabCtrl->GetControls(); + if(paControls) + { + for (size_t i = 0; i < paControls->size(); i++) + { + CControlBase* pControl = paControls->at(i); + if(pControl && pControl->IsClass(CDuiWkeView::GetClassName())) + { + return (CDuiWkeView*)pControl; + } + } + } + + return NULL; +} + // 获取Tab页中某个控件ID对应的Tab页信息 TabItemInfo* CDuiHandlerMain::GetTabInfoByWebCtrlId(UINT uID) { @@ -162,10 +186,17 @@ TabItemInfo* CDuiHandlerMain::GetTabInfoByWebCtrlId(UINT uID) TabItemInfo* pTabInfo = pTabCtrl->GetItemInfo(i); if(pTabInfo && pTabInfo->pControl) { - CDuiWebBrowserCtrl* pWebControl = (CDuiWebBrowserCtrl*)GetTabWebControl(pTabInfo->pControl); + CDuiWebBrowserCtrl* pWebControl = (CDuiWebBrowserCtrl*)GetTabWebIEControl(pTabInfo->pControl); if(pWebControl && (pWebControl->GetID() == uID)) { return pTabInfo; + }else + { + CDuiWkeView* pWebControl = (CDuiWkeView*)GetTabWebWkeControl(pTabInfo->pControl); + if(pWebControl && (pWebControl->GetID() == uID)) + { + return pTabInfo; + } } } } @@ -174,8 +205,8 @@ TabItemInfo* CDuiHandlerMain::GetTabInfoByWebCtrlId(UINT uID) return NULL; } -// 获取当前页面的浏览器控件 -CDuiWebBrowserCtrl* CDuiHandlerMain::GetCurTabWebControl() +// 获取当前页面的IE浏览器控件 +CDuiWebBrowserCtrl* CDuiHandlerMain::GetCurTabWebIEControl() { CDuiTabCtrl* pTabCtrl = (CDuiTabCtrl*)GetControl(_T("tabctrl.main")); if(pTabCtrl) @@ -184,8 +215,25 @@ CDuiWebBrowserCtrl* CDuiHandlerMain::GetCurTabWebControl() TabItemInfo* pTabInfo = pTabCtrl->GetItemInfo(nItem); if(pTabInfo && pTabInfo->pControl) { - //CDuiWebBrowserCtrl* pWebControl = (CDuiWebBrowserCtrl*)(pTabInfo->pControl->GetControl(L"webbrowser")); - CDuiWebBrowserCtrl* pWebControl = (CDuiWebBrowserCtrl*)GetTabWebControl(pTabInfo->pControl); + CDuiWebBrowserCtrl* pWebControl = (CDuiWebBrowserCtrl*)GetTabWebIEControl(pTabInfo->pControl); + return pWebControl; + } + } + + return NULL; +} + +// 获取当前页面的wke浏览器控件 +CDuiWkeView* CDuiHandlerMain::GetCurTabWebWkeControl() +{ + CDuiTabCtrl* pTabCtrl = (CDuiTabCtrl*)GetControl(_T("tabctrl.main")); + if(pTabCtrl) + { + int nItem = pTabCtrl->GetSelectItem(); + TabItemInfo* pTabInfo = pTabCtrl->GetItemInfo(nItem); + if(pTabInfo && pTabInfo->pControl) + { + CDuiWkeView* pWebControl = (CDuiWkeView*)GetTabWebWkeControl(pTabInfo->pControl); return pWebControl; } } @@ -199,19 +247,42 @@ void CDuiHandlerMain::InsertExplorerTab(int nIndex, CString strTitle, CString st CDuiTabCtrl* pTabCtrl = (CDuiTabCtrl*)GetControl(_T("tabctrl.main")); if(pTabCtrl) { - pTabCtrl->LoadTabXml(L"tab_webbrowser"); - int nCount = pTabCtrl->GetItemCount(); - pTabCtrl->SetSelectItem(nCount-1); - TabItemInfo* pTabInfo = pTabCtrl->GetItemInfo(nCount - 1); - if(pTabInfo && pTabInfo->pControl) + // 浏览器类型 + CRegistryUtil reg(HKEY_CURRENT_USER); + CString strWebType = reg.GetStringValue(NULL, REG_EXPLORER_SUBKEY, REG_EXPLORER_WEBTYPE); + BOOL bWebTypeIE = (strWebType != L"wke"); + + if(bWebTypeIE) { - pTabInfo->strText = strTitle; - pTabInfo->nImageIndex = 0; - //CDuiWebBrowserCtrl* pWebControl = (CDuiWebBrowserCtrl*)(pTabInfo->pControl->GetControl(L"webbrowser")); - CDuiWebBrowserCtrl* pWebControl = (CDuiWebBrowserCtrl*)GetTabWebControl(pTabInfo->pControl); - if(pWebControl) + pTabCtrl->LoadTabXml(L"tab_webie"); + int nCount = pTabCtrl->GetItemCount(); + pTabCtrl->SetSelectItem(nCount-1); + TabItemInfo* pTabInfo = pTabCtrl->GetItemInfo(nCount - 1); + if(pTabInfo && pTabInfo->pControl) + { + pTabInfo->strText = strTitle; + pTabInfo->nImageIndex = 0; + CDuiWebBrowserCtrl* pWebControl = (CDuiWebBrowserCtrl*)GetTabWebIEControl(pTabInfo->pControl); + if(pWebControl) + { + pWebControl->Navigate(strUrl); + } + } + }else + { + pTabCtrl->LoadTabXml(L"tab_webwke"); + int nCount = pTabCtrl->GetItemCount(); + pTabCtrl->SetSelectItem(nCount-1); + TabItemInfo* pTabInfo = pTabCtrl->GetItemInfo(nCount - 1); + if(pTabInfo && pTabInfo->pControl) { - pWebControl->Navigate(strUrl); + pTabInfo->strText = strTitle; + pTabInfo->nImageIndex = 0; + CDuiWkeView* pWebControl = (CDuiWkeView*)GetTabWebWkeControl(pTabInfo->pControl); + if(pWebControl) + { + pWebControl->Navigate(strUrl); + } } } } @@ -242,13 +313,58 @@ void CDuiHandlerMain::InsertExplorerTab(int nIndex, CString strTitle, CString st */ } +// 显示系统设置对话框菜单消息处理 +LRESULT CDuiHandlerMain::OnDuiMsgMenuOption(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam) +{ + CDlgBase* pDlg = DuiSystem::CreateDuiDialog(_T("dlg_option"), m_pDlg, _T(""), TRUE, 0, TRUE); + if(pDlg == NULL) + { + return FALSE; + } + + // 浏览器类型 + CRegistryUtil reg(HKEY_CURRENT_USER); + CString strWebType = reg.GetStringValue(NULL, REG_EXPLORER_SUBKEY, REG_EXPLORER_WEBTYPE); + BOOL bWebTypeIE = (strWebType != L"wke"); + pDlg->SetControlValue(L"option.webtype.ie", L"check", bWebTypeIE ? L"true" : L"false"); + pDlg->SetControlValue(L"option.webtype.wke", L"check", !bWebTypeIE ? L"true" : L"false"); + + int nResponse = pDlg->DoModal(); + DuiSystem::Instance()->RemoveDuiDialog(pDlg); + return TRUE; +} + +// 系统设置对话框的确认按钮消息处理 +LRESULT CDuiHandlerMain::OnDuiMsgOptionDlgOK(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam) +{ + CDlgBase* pDlg = GetControlDialog(uID); + if(pDlg == NULL) + { + return FALSE; + } + + // 浏览器类型 + CDuiRadioButton* pControlWebTypeIE = static_cast(pDlg->GetControl(L"option.webtype.ie")); + CString strWebType = pControlWebTypeIE->GetGroupValue(); + CRegistryUtil reg(HKEY_CURRENT_USER); + reg.SetStringValue(HKEY_CURRENT_USER, REG_EXPLORER_SUBKEY, REG_EXPLORER_WEBTYPE, strWebType); + + pDlg->DoOK(); + return TRUE; +} + // 导航到上一页 LRESULT CDuiHandlerMain::OnDuiMsgButtonGoBack(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam) { - CDuiWebBrowserCtrl* pWebControl = GetCurTabWebControl(); - if(pWebControl) + CDuiWebBrowserCtrl* pWebControlIE = GetCurTabWebIEControl(); + CDuiWkeView* pWebControlWke = GetCurTabWebWkeControl(); + if(pWebControlIE) { - pWebControl->GoBack(); + pWebControlIE->GoBack(); + }else + if(pWebControlWke) + { + pWebControlWke->goBack(); } return TRUE; @@ -257,10 +373,15 @@ LRESULT CDuiHandlerMain::OnDuiMsgButtonGoBack(UINT uID, CString strName, UINT Ms // 导航到下一页 LRESULT CDuiHandlerMain::OnDuiMsgButtonGoForward(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam) { - CDuiWebBrowserCtrl* pWebControl = GetCurTabWebControl(); - if(pWebControl) + CDuiWebBrowserCtrl* pWebControlIE = GetCurTabWebIEControl(); + CDuiWkeView* pWebControlWke = GetCurTabWebWkeControl(); + if(pWebControlIE) + { + pWebControlIE->GoForward(); + }else + if(pWebControlWke) { - pWebControl->GoForward(); + pWebControlWke->goForward(); } return TRUE; @@ -269,10 +390,15 @@ LRESULT CDuiHandlerMain::OnDuiMsgButtonGoForward(UINT uID, CString strName, UINT // 刷新web页面 LRESULT CDuiHandlerMain::OnDuiMsgButtonRefresh(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam) { - CDuiWebBrowserCtrl* pWebControl = GetCurTabWebControl(); - if(pWebControl) + CDuiWebBrowserCtrl* pWebControlIE = GetCurTabWebIEControl(); + CDuiWkeView* pWebControlWke = GetCurTabWebWkeControl(); + if(pWebControlIE) + { + pWebControlIE->Refresh(); + }else + if(pWebControlWke) { - pWebControl->Refresh(); + //pWebControlWke->(); } return TRUE; @@ -281,10 +407,15 @@ LRESULT CDuiHandlerMain::OnDuiMsgButtonRefresh(UINT uID, CString strName, UINT M // 导航到首页 LRESULT CDuiHandlerMain::OnDuiMsgButtonHome(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam) { - CDuiWebBrowserCtrl* pWebControl = GetCurTabWebControl(); - if(pWebControl) + CDuiWebBrowserCtrl* pWebControlIE = GetCurTabWebIEControl(); + CDuiWkeView* pWebControlWke = GetCurTabWebWkeControl(); + if(pWebControlIE) { - pWebControl->Navigate(L"http://www.blueantstudio.net"); + pWebControlIE->Navigate(L"http://www.blueantstudio.net"); + }else + if(pWebControlWke) + { + pWebControlWke->Navigate(L"http://www.blueantstudio.net"); } return TRUE; @@ -305,10 +436,15 @@ LRESULT CDuiHandlerMain::OnDuiMsgComboUrlKeyDown(UINT uID, CString strName, UINT strUrl = pUrlCtrl->GetEditText(); } - CDuiWebBrowserCtrl* pWebControl = GetCurTabWebControl(); - if(pWebControl) + CDuiWebBrowserCtrl* pWebControlIE = GetCurTabWebIEControl(); + CDuiWkeView* pWebControlWke = GetCurTabWebWkeControl(); + if(pWebControlIE) + { + pWebControlIE->Navigate(strUrl); + }else + if(pWebControlWke) { - pWebControl->Navigate(strUrl); + pWebControlWke->Navigate(strUrl); } return TRUE; @@ -329,10 +465,15 @@ LRESULT CDuiHandlerMain::OnDuiMsgComboUrl(UINT uID, CString strName, UINT Msg, W strUrl = pUrlCtrl->GetEditText(); } - CDuiWebBrowserCtrl* pWebControl = GetCurTabWebControl(); - if(pWebControl) + CDuiWebBrowserCtrl* pWebControlIE = GetCurTabWebIEControl(); + CDuiWkeView* pWebControlWke = GetCurTabWebWkeControl(); + if(pWebControlIE) + { + pWebControlIE->Navigate(strUrl); + }else + if(pWebControlWke) { - pWebControl->Navigate(strUrl); + pWebControlWke->Navigate(strUrl); } return TRUE; @@ -361,8 +502,8 @@ LRESULT CDuiHandlerMain::OnDuiMsgButtonCloseTab(UINT uID, CString strName, UINT } #define MAX_URL 256 -// 浏览器页面的标题变更事件 -LRESULT CDuiHandlerMain::OnDuiMsgWebTitleChange(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam) +// IE浏览器页面的标题变更事件 +LRESULT CDuiHandlerMain::OnDuiMsgWebIETitleChange(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam) { // 获取页面标题 CString strTitle = L""; @@ -390,3 +531,24 @@ LRESULT CDuiHandlerMain::OnDuiMsgWebTitleChange(UINT uID, CString strName, UINT return TRUE; } + +// wke浏览器事件 +LRESULT CDuiHandlerMain::OnDuiMsgWebWkeEvent(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam) +{ + if(wParam == WKE_EVENT_TITLECHANGED) // 页面标题变更 + { + // 获取页面标题 + CString strTitle = (LPCTSTR)lParam; + + // 找对对应的浏览器控件,并设置对应的tab页签文字 + CDuiTabCtrl* pTabCtrl = (CDuiTabCtrl*)GetControl(_T("tabctrl.main")); + TabItemInfo* pTabInfo = GetTabInfoByWebCtrlId(uID); + if(pTabInfo && pTabCtrl) + { + pTabInfo->strText = strTitle; + pTabCtrl->RefreshItems(); + } + } + + return TRUE; +} diff --git a/DuiVisionExplorer/DuiVisionExplorer/DuiHandlerMain.h b/DuiVisionExplorer/DuiVisionExplorer/DuiHandlerMain.h index aa4fba6a..727a204e 100644 --- a/DuiVisionExplorer/DuiVisionExplorer/DuiHandlerMain.h +++ b/DuiVisionExplorer/DuiVisionExplorer/DuiHandlerMain.h @@ -22,6 +22,8 @@ class CDuiHandlerMain : public CDuiHandler //virtual LRESULT OnDuiMessage(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam); virtual void OnTimer(UINT uTimerID, CString strTimerName); + LRESULT OnDuiMsgMenuOption(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam); + LRESULT OnDuiMsgOptionDlgOK(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam); LRESULT OnDuiMsgButtonGoBack(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam); LRESULT OnDuiMsgButtonGoForward(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam); LRESULT OnDuiMsgButtonRefresh(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam); @@ -30,11 +32,14 @@ class CDuiHandlerMain : public CDuiHandler LRESULT OnDuiMsgComboUrl(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam); LRESULT OnDuiMsgButtonNewTab(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam); LRESULT OnDuiMsgButtonCloseTab(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam); - LRESULT OnDuiMsgWebTitleChange(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam); + LRESULT OnDuiMsgWebIETitleChange(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam); + LRESULT OnDuiMsgWebWkeEvent(UINT uID, CString strName, UINT Msg, WPARAM wParam, LPARAM lParam); - CDuiWebBrowserCtrl* GetTabWebControl(CControlBase* pTabCtrl); + CDuiWebBrowserCtrl* GetTabWebIEControl(CControlBase* pTabCtrl); + CDuiWkeView* GetTabWebWkeControl(CControlBase* pTabCtrl); TabItemInfo* GetTabInfoByWebCtrlId(UINT uID); - CDuiWebBrowserCtrl* GetCurTabWebControl(); + CDuiWebBrowserCtrl* GetCurTabWebIEControl(); + CDuiWkeView* GetCurTabWebWkeControl(); void InsertExplorerTab(int nIndex, CString strTitle, CString strUrl); CDlgBase* m_pDlg; @@ -46,6 +51,8 @@ class CDuiHandlerMain : public CDuiHandler DUI_DECLARE_MESSAGE_BEGIN(CDuiHandlerMain) DUI_CONTROL_ID_MESSAGE(APP_IPC, OnDuiMsgInterprocess) DUI_CONTROL_NAME_MESSAGE(NAME_SKIN_WND, OnDuiMsgSkin) + DUI_CONTROL_NAMEMSG_MESSAGE(L"item_setup", MSG_BUTTON_UP, OnDuiMsgMenuOption) + DUI_CONTROL_NAMEMSG_MESSAGE(L"config.button.ok", MSG_BUTTON_UP, OnDuiMsgOptionDlgOK) DUI_CONTROL_NAMEMSG_MESSAGE(L"button.goback", MSG_BUTTON_UP, OnDuiMsgButtonGoBack) DUI_CONTROL_NAMEMSG_MESSAGE(L"button.goforward", MSG_BUTTON_UP, OnDuiMsgButtonGoForward) DUI_CONTROL_NAMEMSG_MESSAGE(L"button.reflush", MSG_BUTTON_UP, OnDuiMsgButtonRefresh) @@ -54,6 +61,7 @@ class CDuiHandlerMain : public CDuiHandler DUI_CONTROL_NAME_MESSAGE(L"combo.url", OnDuiMsgComboUrl) DUI_CONTROL_NAMEMSG_MESSAGE(L"button.new", MSG_BUTTON_UP, OnDuiMsgButtonNewTab) DUI_CONTROL_NAMEMSG_MESSAGE(L"tabctrl.main", MSG_CONTROL_BUTTON, OnDuiMsgButtonCloseTab) - DUI_CONTROL_MSG_MESSAGE(DISPID_TITLECHANGE, OnDuiMsgWebTitleChange) + DUI_CONTROL_MSG_MESSAGE(DISPID_TITLECHANGE, OnDuiMsgWebIETitleChange) + DUI_CONTROL_MSG_MESSAGE(MSG_CONTROL_EVENT, OnDuiMsgWebWkeEvent) DUI_DECLARE_MESSAGE_END() }; diff --git a/DuiVisionExplorer/DuiVisionExplorer/stdafx.h b/DuiVisionExplorer/DuiVisionExplorer/stdafx.h index c06c96f1..425e5b49 100644 --- a/DuiVisionExplorer/DuiVisionExplorer/stdafx.h +++ b/DuiVisionExplorer/DuiVisionExplorer/stdafx.h @@ -47,3 +47,4 @@ #define REG_CONFIG_BKCOLOR _T("BkColor") // 背景颜色 #define REG_EXPLORER_SUBKEY _T("Software\\DuiVisionExplorer\\Expiorer") +#define REG_EXPLORER_WEBTYPE _T("WebType") // 浏览器内核类型(ie|wke) diff --git a/DuiVisionExplorer/bin/xml/duiexplorer/dlg_option.xml b/DuiVisionExplorer/bin/xml/duiexplorer/dlg_option.xml new file mode 100644 index 00000000..9b8fc60a --- /dev/null +++ b/DuiVisionExplorer/bin/xml/duiexplorer/dlg_option.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + +