Leaked source code of windows server 2003
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.

247 lines
6.8 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. // Extract the Page Break ID. Since bPageBreak is true, the URL
  135. // is guaranteed to be prefixed with PAGEBREAK_URL
  136. USES_CONVERSION;
  137. LPCTSTR szPageBreakID = OLE2CT(URL) + _tcslen(PAGEBREAK_URL);
  138. int nPageBreakID = _tstoi(szPageBreakID);
  139. //PageBreakIDs start with 1; _tstoi returns 0 if it can't convert
  140. ASSERT(nPageBreakID != 0);
  141. m_pHistoryList->ScOnPageBreak(nPageBreakID);
  142. }
  143. }
  144. STDMETHODIMP_(void) CWebEventSink::NewWindow(BSTR URL, long Flags, BSTR TargetFrameName,
  145. VARIANT* PostData, BSTR Headers, BSTR Referrer)
  146. {
  147. }
  148. STDMETHODIMP_(void) CWebEventSink::Progress(long Progress, long ProgressMax)
  149. {
  150. Trace(tagWebEventSink, TEXT("Progress(Progress:%ld ProgressMax:%ld)\n"), Progress, ProgressMax);
  151. // display progress only if the web view is visible.
  152. if(m_pWebViewControl && m_pWebViewControl->IsWindowVisible())
  153. {
  154. m_pwndProgressCtrl->SetRange (0, ProgressMax);
  155. m_pwndProgressCtrl->SetPos (Progress);
  156. }
  157. // maintain "stop" button
  158. m_pHistoryList->UpdateWebBar (HB_STOP, ProgressMax != 0);
  159. }
  160. STDMETHODIMP_(void) CWebEventSink::PropertyChange(BSTR szProperty)
  161. {
  162. }
  163. STDMETHODIMP_(void) CWebEventSink::Quit(VARIANT_BOOL* pCancel)
  164. {
  165. Trace(tagWebEventSink, TEXT("Quit()"));
  166. }
  167. STDMETHODIMP_(void) CWebEventSink::StatusTextChange(BSTR bstrText)
  168. {
  169. // display progress only if the web view is visible.
  170. if(m_pWebViewControl && m_pWebViewControl->IsWindowVisible())
  171. {
  172. bool fThisTextIsEmpty = ((bstrText == NULL) || (bstrText[0] == 0));
  173. if (m_fLastTextWasEmpty && fThisTextIsEmpty)
  174. return;
  175. m_fLastTextWasEmpty = fThisTextIsEmpty;
  176. Trace(tagWebEventSink, TEXT("StatusTextChange(%s)"), bstrText);
  177. USES_CONVERSION;
  178. m_pStatusBar->ScSetStatusText(W2T( bstrText));
  179. }
  180. }
  181. STDMETHODIMP_(void) CWebEventSink::TitleChange(BSTR Text)
  182. {
  183. Trace(tagWebEventSink, TEXT("TitleChange(%s)"), Text);
  184. }
  185. STDMETHODIMP_(void) CWebEventSink::WindowActivate()
  186. {
  187. }
  188. STDMETHODIMP_(void) CWebEventSink::WindowMove()
  189. {
  190. }
  191. STDMETHODIMP_(void) CWebEventSink::WindowResize()
  192. {
  193. }