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.

351 lines
9.5 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1999 **
  4. //*********************************************************************
  5. //
  6. // STATUSPN.CPP - Implementation of CIFrmStatusPane
  7. //
  8. // HISTORY:
  9. //
  10. // 9/11/99 vyung Created.
  11. //
  12. // Class which will handle the creation of an Iframe which is hosted in the mainpane.
  13. //
  14. #include <assert.h>
  15. #include "STATUSPN.h"
  16. #include "appdefs.h"
  17. #include "dispids.h"
  18. #include <shlwapi.h>
  19. #define IMG_ITEM L"imgStatus%s"
  20. #define IMG_ACTIVE L"active.gif"
  21. #define IMG_INACTIVE L"inactive.gif"
  22. #define IMG_ACTIVE_TOP L"act_top.gif"
  23. #define IMG_INACTIVE_TOP L"inact_top.gif"
  24. //Statuspane script functions
  25. #define SCRIPTFN_ADDSTATUSITEM L"AddStatusItem(\"%s\", %i)"
  26. #define SCRIPTFN_REDRAWFORNEWCURITEM L"RedrawForNewCurrentItem(%i)"
  27. ///////////////////////////////////////////////////////////
  28. //
  29. // Creation function used by CIFrmStatusPane.
  30. //
  31. CIFrmStatusPane::CIFrmStatusPane()
  32. : m_hStatusWnd (NULL),
  33. m_pObWebBrowser (NULL),
  34. m_pDispEvent (NULL)
  35. {
  36. m_iCurrentSelection = 0;
  37. m_iTotalItems = 0;
  38. }
  39. ///////////////////////////////////////////////////////////
  40. // ~CIFrmStatusPane
  41. //
  42. CIFrmStatusPane::~CIFrmStatusPane()
  43. {
  44. }
  45. ///////////////////////////////////////////////////////////
  46. // InitStatusPane
  47. //
  48. HRESULT CIFrmStatusPane::InitStatusPane(IObWebBrowser* pObWebBrowser)
  49. {
  50. HRESULT hr = E_FAIL;
  51. if (pObWebBrowser)
  52. {
  53. m_pObWebBrowser = pObWebBrowser;
  54. }
  55. return S_OK;
  56. }
  57. ///////////////////////////////////////////////////////////
  58. // GetFrame
  59. //
  60. HRESULT CIFrmStatusPane::GetFrame(IHTMLWindow2** pFrWin)
  61. {
  62. HRESULT hr = E_FAIL;
  63. IDispatch* pDisp = NULL;
  64. IHTMLDocument2* pDoc = NULL;
  65. IHTMLDocument2* pParentDoc = NULL;
  66. IHTMLFramesCollection2* pFrColl = NULL;
  67. IHTMLWindow2* pParentWin = NULL;
  68. if (m_pObWebBrowser)
  69. {
  70. if(SUCCEEDED(m_pObWebBrowser->get_WebBrowserDoc(&pDisp)) && pDisp)
  71. {
  72. if(SUCCEEDED(pDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc)) && pDoc)
  73. {
  74. if(SUCCEEDED(pDoc->get_parentWindow(&pParentWin)) && pParentWin)
  75. {
  76. if(SUCCEEDED(pParentWin->get_document(&pParentDoc))&& pParentDoc)
  77. {
  78. if(SUCCEEDED(pParentDoc->get_frames(&pFrColl)) && pFrColl)
  79. {
  80. VARIANT varRet;
  81. VARIANTARG varg;
  82. VariantInit(&varg);
  83. V_VT(&varg) = VT_BSTR;
  84. varg.bstrVal= SysAllocString(IFRMSTATUSPANE);
  85. if(SUCCEEDED(pFrColl->item(&varg, &varRet)) && varRet.pdispVal)
  86. {
  87. if(SUCCEEDED(varRet.pdispVal->QueryInterface(IID_IHTMLWindow2, (void**)pFrWin)) && *pFrWin)
  88. {
  89. VARIANT varExec;
  90. VariantInit(&varExec);
  91. hr = S_OK;
  92. }
  93. varRet.pdispVal->Release();
  94. varRet.pdispVal = NULL;
  95. }
  96. pFrColl->Release();
  97. pFrColl = NULL;
  98. }
  99. pParentDoc->Release();
  100. pParentDoc = NULL;
  101. }
  102. pParentWin->Release();
  103. pParentWin = NULL;
  104. }
  105. pDoc->Release();
  106. pDoc = NULL;
  107. }
  108. pDisp->Release();
  109. pDisp = NULL;
  110. }
  111. }
  112. return hr;
  113. }
  114. ///////////////////////////////////////////////////////////
  115. // GetElement
  116. //
  117. HRESULT CIFrmStatusPane::GetElement(WCHAR* szHTMLId, IHTMLElement** lpElem)
  118. {
  119. IHTMLWindow2* pFrWin = NULL;
  120. IHTMLDocument2* pFrDoc = NULL;
  121. IHTMLElementCollection* pColl = NULL;
  122. HRESULT hr = E_FAIL;
  123. if(SUCCEEDED(GetFrame(&pFrWin)) && pFrWin)
  124. {
  125. VARIANT varExec;
  126. VariantInit(&varExec);
  127. if(SUCCEEDED(pFrWin->get_document(&pFrDoc)) && pFrDoc)
  128. {
  129. if(SUCCEEDED(pFrDoc->get_all(&pColl)) && pColl)
  130. {
  131. if (SUCCEEDED(GetElementFromCollection(pColl, szHTMLId, lpElem)) && *lpElem)
  132. {
  133. hr = S_OK;
  134. }
  135. pColl->Release();
  136. pColl = NULL;
  137. }
  138. pFrDoc->Release();
  139. pFrDoc = NULL;
  140. }
  141. pFrWin->Release();
  142. pFrWin = NULL;
  143. }
  144. return hr;
  145. }
  146. ///////////////////////////////////////////////////////////
  147. // SetImageSrc
  148. //
  149. HRESULT CIFrmStatusPane::SetImageSrc(WCHAR* szID, BSTR bstrPath)
  150. {
  151. IHTMLElement* pElement = NULL;
  152. IHTMLImgElement* pImage = NULL;
  153. if(SUCCEEDED(GetElement(szID, &pElement)) && pElement)
  154. {
  155. if(SUCCEEDED(pElement->QueryInterface(IID_IHTMLImgElement, (void**)&pImage)) && pImage)
  156. {
  157. pImage->put_src(bstrPath);
  158. pImage->Release();
  159. pImage = NULL;
  160. }
  161. pElement->Release();
  162. pElement = NULL;
  163. }
  164. return S_OK;
  165. }
  166. ///////////////////////////////////////////////////////////
  167. // GetElementFromCollection
  168. //
  169. HRESULT CIFrmStatusPane::GetElementFromCollection(IHTMLElementCollection* pColl, WCHAR* szHTMLId, IHTMLElement** lpElem)
  170. {
  171. VARIANT varName;
  172. VARIANT varIdx;
  173. IDispatch* pDisp = NULL;
  174. HRESULT hr = E_FAIL;
  175. VariantInit(&varName);
  176. V_VT(&varName) = VT_BSTR;
  177. varIdx.vt = VT_UINT;
  178. varIdx.lVal = 0;
  179. varName.bstrVal = SysAllocString(szHTMLId);
  180. if (SUCCEEDED(pColl->item(varName, varIdx, &pDisp)) && pDisp)
  181. {
  182. if(SUCCEEDED(pDisp->QueryInterface(IID_IHTMLElement, (void**)lpElem)) && *lpElem)
  183. {
  184. hr = S_OK;
  185. }
  186. pDisp->Release();
  187. }
  188. return hr;
  189. }
  190. ///////////////////////////////////////////////////////////
  191. // SetSelectionAttributes
  192. //
  193. HRESULT CIFrmStatusPane::SetSelectionAttributes(int iIndex, BOOL bActive)
  194. {
  195. WCHAR szimgStatus [20] = L"\0";
  196. WCHAR szIndex [3] = L"\0";
  197. _itow(iIndex, szIndex, 10);
  198. wsprintf(szimgStatus, IMG_ITEM, szIndex);
  199. if (1 == iIndex)
  200. {
  201. if (bActive)
  202. {
  203. SetImageSrc(szimgStatus, IMG_ACTIVE_TOP);
  204. }
  205. else
  206. {
  207. SetImageSrc(szimgStatus, IMG_INACTIVE_TOP);
  208. }
  209. }
  210. else
  211. {
  212. if (bActive)
  213. {
  214. SetImageSrc(szimgStatus, IMG_ACTIVE);
  215. }
  216. else
  217. {
  218. SetImageSrc(szimgStatus, IMG_INACTIVE);
  219. }
  220. }
  221. return S_OK;
  222. }
  223. ///////////////////////////////////////////////////////////
  224. // SelectItem
  225. //
  226. HRESULT CIFrmStatusPane::SelectItem(int iIndex)
  227. {
  228. if ((iIndex <= m_iTotalItems) && (iIndex >= OBSHEL_STATUSPANE_MINITEM))
  229. {
  230. if (iIndex > m_iCurrentSelection)
  231. {
  232. for (int i = m_iCurrentSelection + 1; i <= iIndex; i++)
  233. {
  234. // To make the status go from Bottom to top use:
  235. // SetSelectionAttributes(m_iTotalItems - i + 1, 1);
  236. // Status goes from Top to Bottom:
  237. SetSelectionAttributes(i, 1);
  238. }
  239. }
  240. else if(iIndex < m_iCurrentSelection)
  241. {
  242. for (int i = m_iCurrentSelection; i > iIndex; i--)
  243. {
  244. // To make the status go from Bottom to top use:
  245. // SetSelectionAttributes(m_iTotalItems - i + 1, 0);
  246. // Status goes from Top to Bottom:
  247. SetSelectionAttributes(i, 0);
  248. }
  249. }
  250. // reset text colors, current item marker ptr. easier to do this in script.
  251. VARIANT varRet;
  252. WCHAR szScriptFn [MAX_PATH] = L"\0";
  253. wsprintf(szScriptFn, SCRIPTFN_REDRAWFORNEWCURITEM, iIndex);
  254. BSTR bstrScriptFn = SysAllocString(szScriptFn);
  255. if (NULL == bstrScriptFn)
  256. {
  257. return E_OUTOFMEMORY;
  258. }
  259. ExecScriptFn(bstrScriptFn, &varRet);
  260. m_iCurrentSelection = iIndex;
  261. }
  262. return S_OK;
  263. }
  264. ///////////////////////////////////////////////////////////
  265. // AddItem
  266. //
  267. HRESULT CIFrmStatusPane::AddItem(BSTR bstrText, int iIndex)
  268. {
  269. m_iTotalItems++;
  270. VARIANT varRet;
  271. WCHAR szScriptFn [MAX_PATH] = L"\0";
  272. wsprintf(szScriptFn, SCRIPTFN_ADDSTATUSITEM, bstrText, iIndex);
  273. BSTR bstrScriptFn = SysAllocString(szScriptFn);
  274. if (NULL == bstrScriptFn)
  275. {
  276. return E_OUTOFMEMORY;
  277. }
  278. ExecScriptFn(bstrScriptFn, &varRet);
  279. SysFreeString(bstrScriptFn);
  280. return S_OK;
  281. }
  282. ///////////////////////////////////////////////////////////
  283. // ExecScriptFn
  284. //
  285. HRESULT CIFrmStatusPane::ExecScriptFn(BSTR bstrScriptFn, VARIANT* pvarRet)
  286. {
  287. IHTMLWindow2* pFrWin = NULL;
  288. HRESULT hr = E_FAIL;
  289. if(SUCCEEDED(GetFrame(&pFrWin)) && pFrWin)
  290. {
  291. VariantInit(pvarRet);
  292. hr = pFrWin->execScript(bstrScriptFn, NULL, pvarRet);
  293. pFrWin->Release();
  294. pFrWin = NULL;
  295. }
  296. return hr;
  297. }