Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
6.3 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: evtsink.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "winnls.h"
  12. #include "AMC.h"
  13. #include "AMCDoc.h"
  14. #include "AMCView.h"
  15. #include "histlist.h"
  16. #include "exdisp.h" // for the IE dispatch interfaces.
  17. #include "websnk.h"
  18. #include "evtsink.h"
  19. #include "WebCtrl.h"
  20. #include "cstr.h"
  21. #include "constatbar.h"
  22. #ifdef DBG
  23. CTraceTag tagWebEventSink(TEXT("Web View"), TEXT("Web Event Sink"));
  24. #endif // DBG
  25. CWebEventSink::CWebEventSink()
  26. : m_bBrowserBackEnabled(false), m_bBrowserForwardEnabled(false),
  27. m_pWebViewControl(NULL), m_pStatusBar(NULL), m_pwndProgressCtrl(NULL),
  28. m_pHistoryList(NULL)
  29. {
  30. }
  31. SC
  32. CWebEventSink::ScInitialize(CAMCWebViewCtrl *pWebViewControl)
  33. {
  34. DECLARE_SC(sc, TEXT("CWebEventSink::ScInitialize"));
  35. sc = ScCheckPointers(pWebViewControl);
  36. if(sc)
  37. return sc;
  38. m_pWebViewControl = pWebViewControl;
  39. CAMCView* pAMCView = dynamic_cast<CAMCView*>(pWebViewControl->GetParent());
  40. CFrameWnd* pwndParentFrame = pWebViewControl->GetParentFrame();
  41. sc = ScCheckPointers(pAMCView, pwndParentFrame);
  42. if(sc)
  43. return sc;
  44. m_pHistoryList = pAMCView->GetHistoryList();
  45. sc = ScCheckPointers(m_pHistoryList);
  46. if(sc)
  47. return sc;
  48. // Create the status bar for this instance of the web control
  49. m_pStatusBar = dynamic_cast<CConsoleStatusBar*>(pwndParentFrame);
  50. sc = ScCheckPointers(m_pStatusBar, E_UNEXPECTED);
  51. if(sc)
  52. return sc;
  53. // find the progress control on the status bar for the parent frame
  54. CAMCStatusBar* pwndStatusBar =
  55. reinterpret_cast<CAMCStatusBar*>(pwndParentFrame->GetMessageBar());
  56. sc = ScCheckPointers(pwndStatusBar);
  57. if(sc)
  58. return sc;
  59. ASSERT_KINDOF (CAMCStatusBar, pwndStatusBar);
  60. m_pwndProgressCtrl = pwndStatusBar->GetStatusProgressCtrlHwnd();
  61. m_fLastTextWasEmpty = false;
  62. return sc;
  63. }
  64. CWebEventSink::~CWebEventSink()
  65. {
  66. /*
  67. * clear the status bar text
  68. */
  69. if (m_pStatusBar != NULL)
  70. m_pStatusBar->ScSetStatusText(NULL);
  71. }
  72. void CWebEventSink::SetActiveTo(BOOL /*bState*/)
  73. {
  74. }
  75. STDMETHODIMP_(void) CWebEventSink::BeforeNavigate(BSTR URL, long Flags, BSTR TargetFrameName, VARIANT* PostData,
  76. BSTR Headers, VARIANT_BOOL* Cancel)
  77. {
  78. Trace(tagWebEventSink, TEXT("BeginNavigate(URL:%s, flags:%0X, targetfrm:%s, headers:%s)\n"), URL, Flags, TargetFrameName, Headers);
  79. bool bPageBreak = IsPageBreak(URL);
  80. m_pHistoryList->OnPageBreakStateChange(bPageBreak);
  81. m_pHistoryList->UpdateWebBar (HB_STOP, TRUE); // turn on "stop" button
  82. }
  83. STDMETHODIMP_(void) CWebEventSink::CommandStateChange(int Command, VARIANT_BOOL Enable)
  84. {
  85. if(Command == CSC_NAVIGATEFORWARD)
  86. {
  87. m_bBrowserForwardEnabled = Enable;
  88. }
  89. else if(Command == CSC_NAVIGATEBACK)
  90. {
  91. m_bBrowserBackEnabled = Enable;
  92. }
  93. }
  94. STDMETHODIMP_(void) CWebEventSink::DownloadBegin()
  95. {
  96. Trace(tagWebEventSink, TEXT("DownloadBegin()"));
  97. }
  98. STDMETHODIMP_(void) CWebEventSink::DownloadComplete()
  99. {
  100. Trace(tagWebEventSink, TEXT("DownloadComplete()"));
  101. }
  102. STDMETHODIMP_(void) CWebEventSink::FrameBeforeNavigate(BSTR URL, long Flags, BSTR TargetFrameName, VARIANT* PostData,
  103. BSTR Headers, VARIANT_BOOL* Cancel)
  104. {
  105. m_pHistoryList->UpdateWebBar (HB_STOP, TRUE); // turn on "stop" button
  106. }
  107. STDMETHODIMP_(void) CWebEventSink::FrameNavigateComplete(BSTR URL)
  108. {
  109. }
  110. STDMETHODIMP_(void) CWebEventSink::FrameNewWindow(BSTR URL, long Flags, BSTR TargetFrameName, VARIANT* PostData,
  111. BSTR Headers, VARIANT_BOOL* Processed)
  112. {
  113. }
  114. bool CWebEventSink::IsPageBreak(BSTR URL)
  115. {
  116. USES_CONVERSION;
  117. CStr strURL = OLE2T(URL);
  118. strURL.MakeLower();
  119. bool bPageBreak = (_tcsstr(strURL, PAGEBREAK_URL) != NULL);
  120. return bPageBreak;
  121. }
  122. STDMETHODIMP_(void) CWebEventSink::NavigateComplete(BSTR URL)
  123. {
  124. Trace(tagWebEventSink, TEXT("NavigateComplete()\n"));
  125. // Set progress bar position to 0
  126. m_pwndProgressCtrl->SetPos (0);
  127. bool bPageBreak = IsPageBreak(URL);
  128. m_pHistoryList->OnPageBreakStateChange(bPageBreak);
  129. // send the browser state across AFTER sending the OnPageBreakStateChange and BEFORE
  130. // the OnPageBreak.
  131. m_pHistoryList->OnBrowserStateChange(m_bBrowserForwardEnabled, m_bBrowserBackEnabled);
  132. if(bPageBreak)
  133. {
  134. m_pHistoryList->ScOnPageBreak();
  135. }
  136. // special handling: selecting "Stop" causes this
  137. if (!wcscmp ((LPOLESTR)URL, L"about:NavigationCanceled"))
  138. return;
  139. }
  140. STDMETHODIMP_(void) CWebEventSink::NewWindow(BSTR URL, long Flags, BSTR TargetFrameName,
  141. VARIANT* PostData, BSTR Headers, BSTR Referrer)
  142. {
  143. }
  144. STDMETHODIMP_(void) CWebEventSink::Progress(long Progress, long ProgressMax)
  145. {
  146. Trace(tagWebEventSink, TEXT("Progress(Progress:%ld ProgressMax:%ld)\n"), Progress, ProgressMax);
  147. // display progress only if the web view is visible.
  148. if(m_pWebViewControl && m_pWebViewControl->IsWindowVisible())
  149. {
  150. m_pwndProgressCtrl->SetRange (0, ProgressMax);
  151. m_pwndProgressCtrl->SetPos (Progress);
  152. }
  153. // maintain "stop" button
  154. m_pHistoryList->UpdateWebBar (HB_STOP, ProgressMax != 0);
  155. }
  156. STDMETHODIMP_(void) CWebEventSink::PropertyChange(BSTR szProperty)
  157. {
  158. }
  159. STDMETHODIMP_(void) CWebEventSink::Quit(VARIANT_BOOL* pCancel)
  160. {
  161. Trace(tagWebEventSink, TEXT("Quit()"));
  162. }
  163. STDMETHODIMP_(void) CWebEventSink::StatusTextChange(BSTR bstrText)
  164. {
  165. // display progress only if the web view is visible.
  166. if(m_pWebViewControl && m_pWebViewControl->IsWindowVisible())
  167. {
  168. bool fThisTextIsEmpty = ((bstrText == NULL) || (bstrText[0] == 0));
  169. if (m_fLastTextWasEmpty && fThisTextIsEmpty)
  170. return;
  171. m_fLastTextWasEmpty = fThisTextIsEmpty;
  172. Trace(tagWebEventSink, TEXT("StatusTextChange(%s)"), bstrText);
  173. USES_CONVERSION;
  174. m_pStatusBar->ScSetStatusText(W2T( bstrText));
  175. }
  176. }
  177. STDMETHODIMP_(void) CWebEventSink::TitleChange(BSTR Text)
  178. {
  179. Trace(tagWebEventSink, TEXT("TitleChange(%s)"), Text);
  180. }
  181. STDMETHODIMP_(void) CWebEventSink::WindowActivate()
  182. {
  183. }
  184. STDMETHODIMP_(void) CWebEventSink::WindowMove()
  185. {
  186. }
  187. STDMETHODIMP_(void) CWebEventSink::WindowResize()
  188. {
  189. }