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.

166 lines
4.8 KiB

  1. #include "priv.h"
  2. #include "wvcoord.h"
  3. /////////////////////////////////////////////////////////////////////////////
  4. // CThumbNailWrapper
  5. /////////////////////////////////////////////////////////////////////////////
  6. CThumbNailWrapper::CThumbNailWrapper()
  7. {
  8. // Do nothing for now
  9. }
  10. CThumbNailWrapper::~CThumbNailWrapper()
  11. {
  12. m_spThumbNailCtl = NULL;
  13. m_spThumbNailStyle = NULL;
  14. m_spThumbnailLabel = NULL;
  15. }
  16. HRESULT CThumbNailWrapper::Init(CComPtr<IThumbCtl> spThumbNailCtl,
  17. CComPtr<IHTMLElement> spThumbnailLabel)
  18. {
  19. m_spThumbNailCtl = spThumbNailCtl;
  20. m_spThumbnailLabel = spThumbnailLabel;
  21. HRESULT hr = FindObjectStyle((IThumbCtl *)spThumbNailCtl, m_spThumbNailStyle);
  22. if (SUCCEEDED(hr))
  23. {
  24. m_spThumbNailStyle->put_display(OLESTR("none")); // Hide the thumbctl initially when nothing is displayed.
  25. }
  26. return hr;
  27. }
  28. STDMETHODIMP CThumbNailWrapper::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
  29. WORD wFlags, DISPPARAMS *pDispParams,
  30. VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
  31. UINT *puArgErr)
  32. {
  33. HRESULT hr;
  34. if (riid != IID_NULL) {
  35. return DISP_E_UNKNOWNINTERFACE;
  36. }
  37. hr = S_OK;
  38. if (dispIdMember == DISPID_ONTHUMBNAILREADY) {
  39. hr = OnThumbNailReady();
  40. }
  41. return hr;
  42. }
  43. HRESULT CThumbNailWrapper::OnThumbNailReady(VOID)
  44. {
  45. HRESULT hr = S_OK;
  46. if (m_spThumbNailCtl)
  47. {
  48. VARIANT_BOOL bHaveThumbnail;
  49. if (SUCCEEDED(m_spThumbNailCtl->haveThumbnail(&bHaveThumbnail)) && bHaveThumbnail)
  50. {
  51. hr = m_spThumbNailStyle->put_display(OLESTR(""));
  52. }
  53. else
  54. {
  55. ClearThumbNail();
  56. }
  57. }
  58. return hr;
  59. }
  60. HRESULT CThumbNailWrapper::FreeSpace(CComBSTR &bstrFree)
  61. {
  62. return m_spThumbNailCtl->get_freeSpace(&bstrFree);
  63. }
  64. HRESULT CThumbNailWrapper::TotalSpace(CComBSTR &bstrTotal)
  65. {
  66. return m_spThumbNailCtl->get_totalSpace(&bstrTotal);
  67. }
  68. HRESULT CThumbNailWrapper::UsedSpace(CComBSTR &bstrUsed)
  69. {
  70. return m_spThumbNailCtl->get_usedSpace(&bstrUsed);
  71. }
  72. HRESULT CThumbNailWrapper::SetDisplay(CComBSTR &bstrDisplay)
  73. {
  74. return m_spThumbNailStyle->put_display(bstrDisplay);
  75. }
  76. HRESULT CThumbNailWrapper::SetHeight(int iHeight)
  77. {
  78. return m_spThumbNailStyle->put_height(CComVariant(iHeight));
  79. }
  80. HRESULT CThumbNailWrapper::_SetThumbnailLabel(CComBSTR& bstrLabel)
  81. {
  82. if (m_spThumbnailLabel)
  83. {
  84. m_spThumbnailLabel->put_innerText(bstrLabel);
  85. }
  86. return S_OK;
  87. }
  88. BOOL CThumbNailWrapper::UpdateThumbNail(CComPtr<FolderItem> spFolderItem)
  89. {
  90. BOOL bRet = FALSE;
  91. VARIANT_BOOL bDisplayed;
  92. CComBSTR bstrPath;
  93. ClearThumbNail();
  94. if (SUCCEEDED(spFolderItem->get_Path(&bstrPath)) && (bstrPath.Length() > 0)
  95. && SUCCEEDED(m_spThumbNailCtl->displayFile(bstrPath, &bDisplayed)) && bDisplayed)
  96. {
  97. CComBSTR bstrLabel, bstrFolderItemName;
  98. WCHAR wszTemp[MAX_PATH];
  99. if (PathIsRootW(bstrPath))
  100. {
  101. CComBSTR bstrSpace;
  102. if (SUCCEEDED(UsedSpace(bstrSpace)))
  103. {
  104. LoadStringW(_Module.GetResourceInstance(), IDS_USEDSPACE, wszTemp, ARRAYSIZE(wszTemp));
  105. bstrLabel = wszTemp;
  106. bstrLabel += bstrSpace;
  107. }
  108. if (SUCCEEDED(FreeSpace(bstrSpace)))
  109. {
  110. if (bstrLabel.Length() > 0)
  111. {
  112. LoadStringW(_Module.GetResourceInstance(), IDS_PHRASESEPERATOR, wszTemp, ARRAYSIZE(wszTemp));
  113. bstrLabel += wszTemp;
  114. }
  115. LoadStringW(_Module.GetResourceInstance(), IDS_FREESPACE, wszTemp, ARRAYSIZE(wszTemp));
  116. bstrLabel += wszTemp;
  117. bstrLabel += bstrSpace;
  118. }
  119. }
  120. else if (SUCCEEDED(spFolderItem->get_Name(&bstrFolderItemName)))
  121. {
  122. WCHAR wszName[MAX_PATH];
  123. StrCpyNW(wszName, bstrFolderItemName, ARRAYSIZE(wszName));
  124. WCHAR wszTemp2[MAX_PATH * 2];
  125. LoadStringW(_Module.GetResourceInstance(), IDS_THUMBNAIL_LABEL, wszTemp, ARRAYSIZE(wszTemp));
  126. wnsprintfW(wszTemp2, ARRAYSIZE(wszTemp2), wszTemp, wszName);
  127. bstrLabel = wszTemp2;
  128. }
  129. _SetThumbnailLabel(bstrLabel);
  130. bRet = TRUE;
  131. }
  132. return bRet;
  133. }
  134. HRESULT CThumbNailWrapper::ClearThumbNail()
  135. {
  136. CComBSTR bstrLabel;
  137. // Optimization to prevent loading mshtmled.dll - we only need to clear the label if text is currently there.
  138. if (m_spThumbnailLabel && SUCCEEDED(m_spThumbnailLabel->get_innerText(&bstrLabel)) && bstrLabel)
  139. _SetThumbnailLabel(CComBSTR(""));
  140. return m_spThumbNailStyle->put_display(OLESTR("none"));
  141. }