StylerView.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:22k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // StylerView.cpp : implementation of the CStylerView class
  2. //
  3. #include "stdafx.h"
  4. #include "Styler.h"
  5. #include "StylerDoc.h"
  6. #include "StylerView.h"
  7. #include "MainFrm.h"
  8. #include "PopupFilter.h"
  9. #include "ComboBoxSearch.h"
  10. #include "MouseManager.h"
  11. #include "FilterDialog.h"
  12. #include "ChildFrm.h"
  13. #include <Mshtml.h>
  14. #include "LinkProperties.h"
  15. #include <intshcut.h>
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #endif
  19. BOOL CStylerView::m_bShowImages = TRUE;
  20. long CStylerView::m_nFontSize = 2;
  21. BOOL CStylerView::m_bFilterAll = FALSE;
  22. BOOL CStylerView::m_bFilterList = TRUE;
  23. //CImageList CStylerView::m_lstTabImages;
  24. HICON CStylerView::m_arrIcons[5];
  25. IMPLEMENT_DYNCREATE(CStylerView, CHtmlView)
  26. BEGIN_MESSAGE_MAP(CStylerView, CHtmlView)
  27. //{{AFX_MSG_MAP(CChildFrame)
  28. ON_WM_SIZE()
  29. ON_WM_PARENTNOTIFY()
  30. ON_COMMAND(ID_ADD_TO_FAV, OnAddToFavorites)
  31. ON_COMMAND(ID_FILE_PROPERTIES, OnFileProperties)
  32. ON_COMMAND(ID_FILE_PRINT, CHtmlView::OnFilePrint)
  33. ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
  34. ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
  35. ON_COMMAND(ID_EDIT_FIND, OnEditFind)
  36. ON_COMMAND(ID_EDIT_SELECTALL, OnEditSelectall)
  37. ON_COMMAND(ID_GOTO_BACK, CHtmlView::GoBack)
  38. ON_COMMAND(ID_GOTO_FORWARD, CHtmlView::GoForward)
  39. ON_COMMAND(ID_GOTO_HOME, CHtmlView::GoHome)
  40. ON_COMMAND(ID_VIEW_REFRESH, CHtmlView::Refresh)
  41. ON_COMMAND(ID_VIEW_STOP, CHtmlView::Stop)
  42. ON_COMMAND(ID_VIEW_SOURCE, OnViewSource)
  43. ON_COMMAND(ID_TOOLS_OPTIONS, OnToolsOptions)
  44. ON_COMMAND(ID_SHOWIMAGES, OnShowImages)
  45. ON_UPDATE_COMMAND_UI(ID_SHOWIMAGES, OnUpdateShowImages)
  46. ON_UPDATE_COMMAND_UI(ID_GOTO_BACK, OnUpdateGotoBack)
  47. ON_UPDATE_COMMAND_UI(ID_GOTO_FORWARD, OnUpdateGotoForward)
  48. ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
  49. ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
  50. ON_COMMAND(ID_EDIT_CUT, OnEditCut)
  51. ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
  52. ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
  53. ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
  54. ON_COMMAND(ID_TEXTSIZE, OnTextSize)
  55. ON_COMMAND_RANGE(ID_TEXTSIZE_LARGEST, ID_TEXTSIZE_SMALLEST, OnTextSizeRange)
  56. ON_UPDATE_COMMAND_UI_RANGE(ID_TEXTSIZE_LARGEST, ID_TEXTSIZE_SMALLEST, OnUpdateTextSizeRange)
  57. ON_COMMAND_RANGE(ID_VIEW_ENCODING_FIRST, ID_VIEW_ENCODING_LAST, OnViewEncodingRange)
  58. ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_ENCODING_FIRST, ID_VIEW_ENCODING_LAST, OnUpdateViewEncodingRange)
  59. ON_MESSAGE(WM_XTP_GETTABICON, OnGetTabIcon)
  60. ON_COMMAND(ID_VIEW_LOCK, OnViewLock)
  61. ON_UPDATE_COMMAND_UI(ID_VIEW_LOCK, OnUpdateViewLock)
  62. ON_UPDATE_COMMAND_UI(ID_INDICATOR, OnUpdateIndicator)
  63. ON_NOTIFY(ID_LINK_STARTDRAG, ID_GOTO_URL, OnLinkStartDrag)
  64. //}}AFX_MSG_MAP
  65. ON_XTP_EXECUTE(ID_ADDPAGEHERE, OnAddPageHere)
  66. ON_UPDATE_COMMAND_UI(ID_ADDPAGEHERE, OnUpdateAddPageHere)
  67. END_MESSAGE_MAP()
  68. CStylerView::CStylerView()
  69. {
  70. EnableAutomation();
  71. /*if (!m_lstTabImages.GetSafeHandle())
  72. {
  73. m_lstTabImages.Create(16, 16, ILC_COLORDDB | ILC_MASK, 5, 1);
  74. CBitmap bmp;
  75. bmp.LoadBitmap(IDB_BITMAP_TABS);
  76. m_lstTabImages.Add(&bmp, RGB(255,0,255));
  77. }*/
  78. if (m_arrIcons[0] == 0)
  79. {
  80. CImageList il;
  81. il.Create(16, 16, ILC_COLORDDB | ILC_MASK, 5, 1);
  82. CBitmap bmp;
  83. bmp.LoadBitmap(IDB_BITMAP_TABS);
  84. il.Add(&bmp, RGB(255,0,255));
  85. for (int i = 0; i < 5; i++)
  86. m_arrIcons[i] = il.ExtractIcon(i);
  87. }
  88. m_nLoadingState = -1;
  89. m_nProgress = 0;
  90. m_bPopup = FALSE;
  91. m_bLock = FALSE;
  92. m_lpDisp = NULL;
  93. m_bActive = FALSE;
  94. m_infMouse.Clear();
  95. }
  96. CStylerView::~CStylerView()
  97. {
  98. }
  99. // CStylerView diagnostics
  100. #ifdef _DEBUG
  101. void CStylerView::AssertValid() const
  102. {
  103. CHtmlView::AssertValid();
  104. }
  105. void CStylerView::Dump(CDumpContext& dc) const
  106. {
  107. CHtmlView::Dump(dc);
  108. }
  109. CStylerDoc* CStylerView::GetDocument() const // non-debug version is inline
  110. {
  111. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CStylerDoc)));
  112. return (CStylerDoc*)m_pDocument;
  113. }
  114. #endif //_DEBUG
  115. // CStylerView Commons
  116. void CStylerView::Load()
  117. {
  118. m_nFontSize = AfxGetApp()->GetProfileInt(_T("StylerView"), _T("FontSize"), 2);
  119. m_bShowImages = AfxGetApp()->GetProfileInt(_T("StylerView"), _T("ShowImages"), 1);
  120. m_bFilterAll = AfxGetApp()->GetProfileInt(_T("StylerView"), _T("FilterAll"), 0);
  121. m_bFilterList = AfxGetApp()->GetProfileInt(_T("StylerView"), _T("FilterList"), 1);
  122. }
  123. void CStylerView::Save()
  124. {
  125. AfxGetApp()->WriteProfileInt(_T("StylerView"), _T("FontSize"), m_nFontSize);
  126. AfxGetApp()->WriteProfileInt(_T("StylerView"), _T("ShowImages"), m_bShowImages);
  127. AfxGetApp()->WriteProfileInt(_T("StylerView"), _T("FilterAll"), m_bFilterAll);
  128. AfxGetApp()->WriteProfileInt(_T("StylerView"), _T("FilterList"), m_bFilterList);
  129. }
  130. CComPtr<IHTMLDocument2> CStylerView::GetHtmlDocument2()
  131. {
  132. LPDISPATCH lpDisp = GetHtmlDocument();
  133. CComQIPtr<IHTMLDocument2> spDoc = lpDisp;
  134. if (lpDisp) lpDisp->Release();
  135. return spDoc;
  136. }
  137. void CStylerView::SetAddress()
  138. {
  139. if (m_nLoadingState == -1)
  140. return;
  141. try
  142. {
  143. CString strUrl = GetLocationURL();
  144. if (GetDocument() &&  !strUrl.IsEmpty() && strUrl != GetDocument()->GetCurrentUrl())
  145. {
  146. GetDocument()->SetUrl(strUrl);
  147. if (m_bActive)
  148. {
  149. GetMainFrame()->SetAddress(strUrl);
  150. }
  151. }
  152. }
  153. catch (...)
  154. {
  155. }
  156. }
  157. void CStylerView::RefreshExplorer()
  158. {
  159. CSourceCtrl* pBar = GetMainFrame()->GetSourceCtrl();
  160. if (pBar && pBar->m_hWnd && pBar->IsWindowVisible())
  161. {
  162. pBar->Refresh(this, FALSE);
  163. }
  164. }
  165. EXTERN_C const GUID CGID_MSHTML;
  166. #define CMDSETID_Forms3 CGID_MSHTML
  167. void CStylerView::ExecFormsCommand(DWORD dwCommandID)
  168. {
  169. CComQIPtr<IOleCommandTarget> spCmdTarget(m_pBrowserApp);
  170. if (spCmdTarget)
  171. {
  172. spCmdTarget->Exec(&CMDSETID_Forms3, dwCommandID, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0);
  173. }
  174. }
  175. BOOL CStylerView::QueryFormsCommand(DWORD dwCommandID)
  176. {
  177. try
  178. {
  179. CComQIPtr<IOleCommandTarget> spCmdTarget(m_pBrowserApp);
  180. if (spCmdTarget)
  181. {
  182. OLECMD cmdInfo = {dwCommandID, 0};
  183. if (SUCCEEDED(spCmdTarget->QueryStatus(&CMDSETID_Forms3, 1, &cmdInfo, NULL)))
  184. return cmdInfo.cmdf & OLECMDF_ENABLED;
  185. }
  186. }
  187. catch(...)
  188. {
  189. }
  190. return FALSE;
  191. }
  192. void CStylerView::SetLoading(BOOL bLoading)
  193. {
  194. int nState = bLoading ? -1 : 3;
  195. if (m_nLoadingState != nState)
  196. {
  197. m_nLoadingState = nState;
  198. GetMainFrame()->m_MTIClientWnd.Invalidate(FALSE);
  199. }
  200. }
  201. BOOL CStylerView::PopupFilter(CString str)
  202. {
  203. for (int i = 0; i < CPopupFilter::m_lstFilter.GetSize(); i++)
  204. {
  205. if (str.Find(CPopupFilter::m_lstFilter[i]) != -1)
  206. {
  207. return TRUE;
  208. }
  209. }
  210. return FALSE;
  211. }
  212. // CStylerView virtuals
  213. BOOL CStylerView::Create(LPCTSTR /*lpszClassName*/, LPCTSTR lpszWindowName,
  214. DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
  215. UINT nID, CCreateContext* pContext)
  216. {
  217. static CString strClassName;
  218. if (strClassName.IsEmpty())
  219. {
  220. strClassName = AfxRegisterWndClass(
  221. CS_DBLCLKS,                       // if you need double-clicks
  222. NULL,                             // no cursor (use default)
  223. NULL,                             // no background brush
  224. AfxGetApp()->LoadIcon(IDR_MAINFRAME)); // app icon
  225. ASSERT(strClassName);
  226. }
  227.  
  228.     
  229. // create the view window itself
  230. m_pCreateContext = pContext;
  231. if (!CView::Create(strClassName, lpszWindowName,
  232. dwStyle, rect, pParentWnd,  nID, pContext))
  233. {
  234. return FALSE;
  235. }
  236. AfxEnableControlContainer();
  237. RECT rectClient;
  238. GetClientRect(&rectClient);
  239. // create the control window
  240. // AFX_IDW_PANE_FIRST is a safe but arbitrary ID
  241. if (!m_wndBrowser.CreateControl(CLSID_WebBrowser, lpszWindowName,
  242. WS_VISIBLE | WS_CHILD, rectClient, this, AFX_IDW_PANE_FIRST))
  243. {
  244. DestroyWindow();
  245. return FALSE;
  246. }
  247. LPUNKNOWN lpUnk = m_wndBrowser.GetControlUnknown();
  248. HRESULT hr = lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp);
  249. if (!SUCCEEDED(hr))
  250. {
  251. m_pBrowserApp = NULL;
  252. m_wndBrowser.DestroyWindow();
  253. DestroyWindow();
  254. return FALSE;
  255. }
  256. if (m_pBrowserApp)
  257. {
  258. CComPtr<IOleObject> spOleObj;
  259. m_pBrowserApp->QueryInterface(IID_IOleObject, (void**)&spOleObj);
  260. if (spOleObj)
  261. spOleObj->SetClientSite((IOleClientSite*)GetInterface(&IID_IOleClientSite));
  262. }
  263. return TRUE;
  264. }
  265. BOOL CStylerView::PreTranslateMessage(MSG* pMsg)
  266. {
  267. if(pMsg == NULL || m_hWnd == NULL)
  268. return TRUE;
  269. if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
  270. {
  271. m_infMouse.nLClick = GetTickCount();
  272. m_infMouse.nRClick = 0;
  273. }
  274. if (pMsg->message == WM_LBUTTONDOWN ||
  275. pMsg->message == WM_RBUTTONDOWN ||
  276. pMsg->message == WM_MBUTTONDOWN ||
  277. pMsg->message == WM_LBUTTONDBLCLK ||
  278. pMsg->message == WM_RBUTTONDBLCLK)
  279. {
  280. int nCommand = CMouseManager::FindMouseCommand(MOUSE_AREA_BROWSER, pMsg->message);
  281. if (nCommand != -1)
  282. {
  283. AfxGetMainWnd()->PostMessage(WM_COMMAND, nCommand);
  284. return TRUE;
  285. }
  286. }
  287. if (CView::PreTranslateMessage(pMsg))
  288. return TRUE;
  289. // don't translate dialog messages when in Shift+F1 help mode
  290. CFrameWnd* pFrameWnd = GetTopLevelFrame();
  291. if (pFrameWnd != NULL && pFrameWnd->m_bHelpMode)
  292. return FALSE;
  293. if (pFrameWnd->PreTranslateMessage(pMsg))
  294. return TRUE;
  295. if (pMsg->message == WM_KEYDOWN && m_pBrowserApp)
  296. {
  297. CComQIPtr<IOleInPlaceActiveObject> spActiveObj(m_pBrowserApp);
  298. if (spActiveObj && spActiveObj->TranslateAccelerator(pMsg) == S_OK)
  299. return TRUE;
  300. }
  301. return FALSE;
  302. }
  303. BOOL CStylerView::PreCreateWindow(CREATESTRUCT& cs)
  304. {
  305. cs.style &= ~WS_BORDER;
  306. return CHtmlView::PreCreateWindow(cs);
  307. }
  308. void CStylerView::OnInitialUpdate()
  309. {
  310. CHtmlView::OnInitialUpdate();
  311. COleVariant vaZoomFactor(m_nFontSize);
  312. ExecWB(OLECMDID_ZOOM , OLECMDEXECOPT_DONTPROMPTUSER,  &vaZoomFactor, NULL);
  313. if (GetDocument()->GetCurrentUrl().IsEmpty())
  314. {
  315. if (CMainFrame::m_nStartup == STARTUP_HOME) GoHome(); else
  316. if (CMainFrame::m_nStartup == STARTUP_BLANK) Navigate(ABOUTBLANK);
  317. }
  318. }
  319. void CStylerView::PostNcDestroy() 
  320. {
  321. CHtmlView::PostNcDestroy();
  322. }
  323. void CStylerView::OnActivateView( BOOL bActivate, CView* pActivateView, 
  324. CView* pDeactiveView )
  325. {
  326. if (bActivate && !m_bActive)
  327. {
  328. GetMainFrame()->SetAddress(GetDocument()->GetCurrentUrl());
  329. RefreshExplorer();
  330. }
  331. m_bActive = bActivate;
  332. CHtmlView:: OnActivateView(bActivate, pActivateView, pDeactiveView);
  333. }
  334. void CStylerView::OnNewWindow2(LPDISPATCH* ppDisp, BOOL* Cancel)
  335. {
  336. if(ppDisp == NULL || Cancel == NULL)
  337. return;
  338. if(m_bFilterAll)
  339. {
  340. double secs = (double)(GetTickCount() - m_infMouse.nLClick)/(double)1000;
  341. double Rsecs = (double)(GetTickCount() - m_infMouse.nRClick)/(double)1000;
  342. BSTR bstrTag = NULL;
  343. if((secs > 0.7 && secs < 4.0) && !IsLoading())
  344. {
  345. //get click point
  346. IHTMLElement* pElem = NULL;
  347. try
  348. {
  349. CComPtr<IHTMLDocument2> spDoc = GetHtmlDocument2();
  350. if(spDoc)
  351. {
  352. if(SUCCEEDED(spDoc->elementFromPoint(m_infMouse.ptClick.x, m_infMouse.ptClick.y, &pElem)))
  353. {
  354. if(pElem)
  355. {
  356. pElem->get_tagName(&bstrTag);
  357. pElem->Release();
  358. }
  359. }
  360. }
  361. }catch(...)
  362. {
  363. }
  364. }
  365. if( !(m_infMouse.nLClick && ((secs >= 0 && secs <= 0.7) || (bstrTag && wcscmp(bstrTag, L"A") == 0) /*|| !IsLoading()*/)) 
  366. && !((Rsecs >= 0 && Rsecs <= 10 && m_infMouse.nRClick) /*|| !IsLoading()*/))
  367. {
  368. *ppDisp = NULL;
  369. *Cancel = TRUE;
  370. TRACE(_T("Filter Popupn"));
  371. m_infMouse.Clear();
  372. if(bstrTag) SysFreeString(bstrTag);
  373. return;
  374. }
  375. if(bstrTag) SysFreeString(bstrTag);
  376. }
  377. CWinApp* pApp = AfxGetApp();
  378. // Get the correct document template.
  379. POSITION pos = pApp->GetFirstDocTemplatePosition();
  380. CDocTemplate* pDocTemplate = pApp->GetNextDocTemplate( pos );
  381. CStylerDoc* pDoc = (CStylerDoc*)pDocTemplate->CreateNewDocument();
  382. pDoc->SetUrl(GetDocument()->GetCurrentUrl());
  383. // Create a new frame.
  384. CFrameWnd* pFrame = pDocTemplate->CreateNewFrame(pDoc, (CFrameWnd*)AfxGetMainWnd() );
  385. // Activate the frame.
  386. if (m_bLock) ((CChildFrame*)pFrame)->m_bActivate = FALSE;
  387. pDocTemplate->InitialUpdateFrame( pFrame, NULL );
  388. CStylerView* pView = (CStylerView*)pFrame->GetActiveView();
  389. // Pass pointer of WebBrowser object.
  390. pView->SetRegisterAsBrowser( TRUE );   
  391. *ppDisp = pView->GetApplication();   
  392. pView->m_bPopup = TRUE;
  393. }
  394. void CStylerView::OnTitleChange(LPCTSTR lpszText)
  395. {
  396. if (m_pDocument != NULL)
  397. m_pDocument->SetTitle(lpszText);
  398. SetAddress();
  399. }
  400. void CStylerView::NavigateComplete2(LPDISPATCH pDisp, VARIANT* /*URL*/)
  401. {
  402. if (!m_lpDisp) m_lpDisp = pDisp;
  403. }
  404. void CStylerView::DocumentComplete(LPDISPATCH /*pDisp*/, VARIANT* /*URL*/)
  405. {
  406. if (m_lpDisp && m_lpDisp == m_lpDisp)
  407. {
  408. m_lpDisp = NULL;
  409. TRACE(_T("Document is done downloadingn"));
  410. try
  411. {
  412. SetLoading(FALSE);
  413. RefreshExplorer();
  414. CComPtr<IHTMLDocument2> spDoc = GetHtmlDocument2();
  415. SetAddress();
  416. if( spDoc )
  417. {
  418. BSTR bstr = NULL;
  419. spDoc->get_charset( &bstr );
  420. CString strCharset(bstr);
  421. SysFreeString(bstr);
  422. for (int i = 0; i < CMainFrame::m_arrEncodingPage.GetSize(); i++)
  423. {
  424. if (CMainFrame::m_arrEncodingPage[i] == strCharset)
  425. {
  426. m_nEncoding = i + ID_VIEW_ENCODING_FIRST;
  427. break;
  428. }
  429. }
  430. }
  431. m_bPopup = FALSE;
  432. }
  433. catch(...)
  434. {
  435. }
  436. m_infMouse.Clear();
  437. }
  438. }
  439. void CStylerView::OnProgressChange(long nProgress, long nProgressMax)
  440. {
  441. if (nProgressMax && nProgress >= 0)
  442. {
  443. long nIndex = nProgress * 4 / nProgressMax;
  444. if (nIndex > 3) nIndex = 3;
  445. m_nProgress = nProgress * 100 / nProgressMax;
  446. if (m_nLoadingState != nIndex)
  447. {
  448. m_nLoadingState = nIndex;
  449. GetMainFrame()->m_MTIClientWnd.Invalidate(FALSE);
  450. }
  451. } else m_nProgress = 0;
  452. }
  453. void CStylerView::OnBeforeNavigate2(LPCTSTR lpszURL, DWORD /*nFlags*/,
  454. LPCTSTR /*lpszTargetFrameName*/, CByteArray& baPostedData,
  455. LPCTSTR /*lpszHeaders*/, BOOL* pbCancel)
  456. {
  457. if (m_bFilterList && m_bPopup && PopupFilter(lpszURL))
  458. {
  459. if (pbCancel) *pbCancel = TRUE;
  460. GetParentFrame()->PostMessage(WM_CLOSE);
  461. return;
  462. }
  463. if (m_bLock && !baPostedData.GetSize() && GetTickCount() - m_infMouse.nLClick < 600)
  464. {
  465. if(_tcsstr(lpszURL, _T("mailto:")) == NULL && _tcsstr(lpszURL, _T("javascript:")) == NULL)
  466. {
  467. if (pbCancel)
  468. {
  469. OpenWindow(lpszURL, FALSE);
  470.  *pbCancel = TRUE;
  471. }
  472. }
  473. }
  474. }
  475. void CStylerView::OnCommandStateChange(long nCommand, BOOL bEnable)
  476. {
  477. if (nCommand == CSC_NAVIGATEFORWARD) m_bForward = bEnable;
  478. if (nCommand == CSC_NAVIGATEBACK) m_bBack = bEnable;
  479. }
  480. // CStylerView message handlers
  481. void CStylerView::OnSize(UINT nType, int cx, int cy)
  482. {
  483. CFormView::OnSize(nType, cx, cy);
  484. if (::IsWindow(m_wndBrowser.m_hWnd))
  485. {
  486. HDWP wp = BeginDeferWindowPos(1);
  487. wp = DeferWindowPos(wp, m_wndBrowser.m_hWnd, 0, 0, 0, cx, cy, 
  488. SWP_NOZORDER | SWP_NOREPOSITION);
  489. EndDeferWindowPos(wp);
  490. //m_wndBrowser.MoveWindow(0, 0, cx, cy);
  491. }
  492. }
  493. void CStylerView::OnParentNotify(UINT message, LPARAM lParam) 
  494. {
  495. if(message == WM_LBUTTONDOWN )
  496. {
  497. m_infMouse.nLClick = GetTickCount();
  498. m_infMouse.nRClick = 0;
  499. m_infMouse.ptClick = CPoint(LOWORD((DWORD)lParam), HIWORD((DWORD)lParam));
  500. }
  501. else if(message == WM_RBUTTONDOWN ) 
  502. {
  503. m_infMouse.nRClick = GetTickCount();
  504. m_infMouse.nLClick = 0;
  505. } else if(message == WM_DESTROY)
  506. {
  507. GetParentFrame()->PostMessage(WM_CLOSE);
  508. }
  509. CHtmlView::OnParentNotify(message, lParam);
  510. }
  511. LRESULT CStylerView::OnGetTabIcon(WPARAM /*lParam*/, LPARAM /*wParam*/)
  512. {
  513. int nIndex = m_bLock ? 4 : m_nLoadingState < 0 ? 3 : m_nLoadingState;
  514. if (nIndex < 5)
  515. return (LRESULT)m_arrIcons[nIndex];
  516. return 0;
  517. }
  518. void CStylerView::OnUpdateGotoBack(CCmdUI *pCmdUI)
  519. {
  520. pCmdUI->Enable(m_bBack);
  521. }
  522. void CStylerView::OnUpdateGotoForward(CCmdUI *pCmdUI)
  523. {
  524. pCmdUI->Enable(m_bForward);
  525. }
  526. void CStylerView::OnFileProperties()
  527. {
  528. ExecWB(OLECMDID_PROPERTIES, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
  529. }
  530. void CStylerView::OnEditSelectall()
  531. {
  532. ExecWB(OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
  533. }
  534. void CStylerView::OnFilePrintPreview()
  535. {
  536. ExecWB(OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
  537. }
  538. void CStylerView::OnFileSaveAs()
  539. {
  540. ExecWB(OLECMDID_SAVEAS, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
  541. }
  542. void CStylerView::OnEditFind()
  543. {
  544. CComQIPtr<IOleCommandTarget> spCmdTarget = m_pBrowserApp;
  545. spCmdTarget->Exec(&CGID_IWebBrowser, HTMLID_FIND, 0, NULL, NULL);
  546.  }
  547. void CStylerView::OnViewSource()
  548. {
  549. CComQIPtr<IOleCommandTarget> spCmdTarget = m_pBrowserApp;
  550. spCmdTarget->Exec(&CGID_IWebBrowser, HTMLID_VIEWSOURCE, 0, NULL, NULL);
  551. }
  552. void CStylerView::OnToolsOptions()
  553. {
  554. CComQIPtr<IOleCommandTarget> spCmdTarget = m_pBrowserApp;
  555. spCmdTarget->Exec(&CGID_IWebBrowser, HTMLID_OPTIONS, 0, NULL, NULL);
  556. }
  557. void CStylerView::OnAddToFavorites()
  558. {
  559. IShellUIHelper* pShell = NULL;
  560. HRESULT hr = CoCreateInstance(CLSID_ShellUIHelper, NULL, CLSCTX_SERVER,
  561. IID_IShellUIHelper, (void**)&pShell);
  562. if (hr == S_OK)
  563. {
  564. COleVariant vtTitle(GetDocument()->GetTitle());
  565. BSTR bstrUrl = GetDocument()->GetCurrentUrl().AllocSysString();
  566. pShell->AddFavorite(bstrUrl, &vtTitle);
  567. SysFreeString(bstrUrl);
  568. pShell->Release();
  569. }
  570. }
  571. void CStylerView::OnShowImages()
  572. {
  573. m_bShowImages = !m_bShowImages;
  574. IOleControl* pControl;
  575. m_pBrowserApp->QueryInterface( IID_IOleControl, (void**)&pControl );
  576. if( pControl != NULL )
  577. {
  578. pControl->OnAmbientPropertyChange( DISPID_AMBIENT_DLCONTROL );
  579. pControl->Release();
  580. }
  581. Navigate2(GetDocument()->GetCurrentUrl());
  582. }
  583. void CStylerView::OnUpdateShowImages(CCmdUI *pCmdUI)
  584. {
  585. pCmdUI->SetCheck(!m_bShowImages);
  586. }
  587. void CStylerView::OnEditCopy() 
  588. {
  589. ExecFormsCommand(IDM_COPY);
  590. }
  591. void CStylerView::OnUpdateEditCopy(CCmdUI* pCmdUI) 
  592. {
  593. pCmdUI->Enable(QueryFormsCommand(IDM_COPY));
  594. }
  595. void CStylerView::OnEditCut() 
  596. {
  597. ExecFormsCommand(IDM_CUT);
  598. }
  599. void CStylerView::OnUpdateEditCut(CCmdUI* pCmdUI) 
  600. {
  601. pCmdUI->Enable(QueryFormsCommand(IDM_CUT));
  602. }
  603. void CStylerView::OnEditPaste() 
  604. {
  605. ExecFormsCommand(IDM_PASTE);
  606. }
  607. void CStylerView::OnUpdateEditPaste(CCmdUI* pCmdUI) 
  608. {
  609. pCmdUI->Enable(QueryFormsCommand(IDM_PASTE));
  610. }
  611.   
  612. void CStylerView::OnTextSize()
  613. {
  614. m_nFontSize = (m_nFontSize + 1) % 5;
  615. ASSERT(m_nFontSize >=0 && m_nFontSize < 5);
  616. if (m_pBrowserApp)
  617. {
  618. COleVariant vaZoomFactor(m_nFontSize);
  619. ExecWB(OLECMDID_ZOOM , OLECMDEXECOPT_DONTPROMPTUSER,  &vaZoomFactor, NULL);
  620. }
  621. }
  622. void CStylerView::OnTextSizeRange(UINT nID)
  623. {
  624. m_nFontSize = ID_TEXTSIZE_SMALLEST - nID;
  625. ASSERT(m_nFontSize >=0 && m_nFontSize < 5);
  626. if (m_pBrowserApp)
  627. {
  628. COleVariant vaZoomFactor(m_nFontSize);
  629. ExecWB(OLECMDID_ZOOM , OLECMDEXECOPT_DONTPROMPTUSER,  &vaZoomFactor, NULL);
  630. }
  631. }
  632. void CStylerView::OnUpdateTextSizeRange(CCmdUI* pCmdUI) 
  633. {
  634. pCmdUI->SetCheck(long(ID_TEXTSIZE_SMALLEST - pCmdUI->m_nID) == m_nFontSize);
  635. }
  636. void CStylerView::OnUpdateViewEncodingRange(CCmdUI *pCmdUI)
  637. {
  638. pCmdUI->SetCheck(m_nEncoding == pCmdUI->m_nID);
  639. }
  640. void CStylerView::OnViewEncodingRange(UINT nID)
  641. {
  642. CComPtr<IHTMLDocument2> spDoc = GetHtmlDocument2();
  643. if( spDoc )
  644. {
  645. int nIndex = nID - ID_VIEW_ENCODING_FIRST;
  646. ASSERT(nIndex < CMainFrame::m_arrEncodingPage.GetSize());
  647. BSTR bstr;
  648. bstr = CMainFrame::m_arrEncodingPage[nIndex].AllocSysString();
  649. spDoc->put_charset( bstr );
  650. SysFreeString(bstr);
  651. Refresh2(1);
  652. m_nEncoding = nID;
  653. }
  654. }
  655. void CStylerView::OnLinkStartDrag(NMHDR* /*pNMHDR*/, LRESULT* /*pRes*/)
  656. {
  657. USES_CONVERSION;
  658. CString strTitle = GetDocument()->GetTitle();
  659. CString strAddress = GetDocument()->GetCurrentUrl();
  660. strTitle.Replace(_T('\'), _T('-'));
  661. strTitle.Replace(_T('/'), _T('-'));
  662. strTitle.Replace(_T(':'), _T(' '));
  663. strTitle.Replace(_T('|'), _T(' '));
  664. CString strDirectory;
  665. GetTempPath (MAX_PATH, strDirectory.GetBuffer(MAX_PATH));
  666. strDirectory.ReleaseBuffer();
  667. CString strPath = strDirectory + strTitle + _T(".url");
  668. WritePrivateProfileString(_T("InternetShortcut"), _T("URL"), strAddress,  strPath);
  669. TCHAR chFilePath[_MAX_PATH];
  670. ZeroMemory(chFilePath, sizeof(chFilePath));
  671. STRCPY_S(chFilePath, _MAX_PATH, (LPCTSTR)strPath);
  672. COleDataSource ds;
  673. CSharedFile sharedFile;
  674. CArchive ar (&sharedFile, CArchive::store);
  675. DROPFILES df;
  676. df.pFiles = sizeof(DROPFILES);
  677. df.pt = CPoint(0, 0);
  678. df.fNC = 0;
  679. #ifdef _UNICODE
  680. df.fWide = TRUE;
  681. #else
  682. df.fWide = FALSE;
  683. #endif
  684. ar.Write(&df, sizeof(DROPFILES));
  685. ar.Write(chFilePath, (strPath.GetLength() + 2) * sizeof(TCHAR));
  686. ar.Close();
  687. HGLOBAL hGlobal = sharedFile.Detach();
  688. ds.CacheGlobalData(CF_HDROP, hGlobal);
  689. ds.DoDragDrop(DROPEFFECT_COPY|DROPEFFECT_LINK);
  690. return;
  691. }
  692. void CStylerView::OnViewLock()
  693. {
  694. m_bLock = !m_bLock;
  695. GetMainFrame()->m_MTIClientWnd.Invalidate(FALSE);
  696. }
  697. void CStylerView::OnUpdateViewLock(CCmdUI *pCmdUI)
  698. {
  699. pCmdUI->SetCheck(m_bLock);
  700. }
  701. void CStylerView::OnUpdateAddPageHere(CCmdUI *pCmdUI)
  702. {
  703. pCmdUI->Enable(TRUE);
  704. }
  705. void CStylerView::OnAddPageHere(NMHDR* pNMHDR, LRESULT* /*pResult*/)
  706. {
  707. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  708. CString strDirectory = tagNMCONTROL->pControl->GetParameter();
  709. CString strParent = strDirectory.Left(strDirectory.GetLength() - 1);
  710. if (strParent.Find('\') != -1)
  711. {
  712. strParent.Delete(0, strParent.ReverseFind('\') + 1);
  713. }
  714. CLinkProperties lp;
  715. lp.m_strTitle = GetDocument()->GetTitle();
  716. lp.m_strAddress = GetDocument()->GetCurrentUrl();
  717. lp.m_strParent = strParent;
  718. lp.m_strTitle.Replace('\', '-');
  719. lp.m_strTitle.Replace('/', '-');
  720. lp.m_strTitle.Replace(':', ' ');
  721. lp.m_strTitle.Replace('|', ' ');
  722. if (lp.DoModal() == IDOK)
  723. {
  724. WritePrivateProfileString(_T("InternetShortcut"), _T("URL"), lp.m_strAddress, 
  725. strDirectory + lp.m_strTitle + _T(".url"));
  726. }
  727. }
  728. void CStylerView::OnUpdateIndicator(CCmdUI *pCmdUI)
  729. {
  730. ASSERT_KINDOF(CXTPStatusBar, pCmdUI->m_pOther);
  731. CIndicatorStatusBar* bar =(CIndicatorStatusBar*) pCmdUI->m_pOther;
  732. int nProgress = (m_nLoadingState != -1 && m_nLoadingState != 3) ? m_nProgress : 0;
  733. bar->SetProgress(nProgress);
  734. }