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.

191 lines
4.4 KiB

  1. #include "shellprv.h"
  2. #pragma hdrstop
  3. #include "dataprv.h"
  4. // TODO: use IShellDetails instead
  5. const LPCWSTR c_awszColumns[] =
  6. {
  7. L"Title",
  8. L"URL",
  9. };
  10. CSimpleData::~CSimpleData()
  11. {
  12. ATOMICRELEASE(_psf);
  13. DPA_FreeIDArray(_hdpa); // accepts NULL
  14. }
  15. STDMETHODIMP CSimpleData::getRowCount(DBROWCOUNT *pcRows)
  16. {
  17. *pcRows = 0;
  18. HRESULT hr = _DoEnum();
  19. if (SUCCEEDED(hr))
  20. *pcRows = DPA_GetPtrCount(_hdpa);
  21. return S_OK;
  22. }
  23. STDMETHODIMP CSimpleData::getColumnCount(DB_LORDINAL *pcColumns)
  24. {
  25. *pcColumns = ARRAYSIZE(c_awszColumns);
  26. return S_OK;
  27. }
  28. STDMETHODIMP CSimpleData::getRWStatus(DBROWCOUNT iRow, DB_LORDINAL iColumn, OSPRW *prwStatus)
  29. {
  30. *prwStatus = OSPRW_READONLY;
  31. return S_OK;
  32. }
  33. STDMETHODIMP CSimpleData::getVariant(DBROWCOUNT iRow, DB_LORDINAL iColumn, OSPFORMAT format, VARIANT *pVar)
  34. {
  35. VariantInit(pVar);
  36. HRESULT hr = _DoEnum();
  37. if (FAILED(hr))
  38. return hr;
  39. hr = E_FAIL;
  40. if (iColumn > 0 && iColumn <= ARRAYSIZE(c_awszColumns))
  41. {
  42. if (iRow == 0)
  43. {
  44. pVar->bstrVal = SysAllocString(c_awszColumns[iColumn - 1]);
  45. pVar->vt = VT_BSTR;
  46. hr = S_OK;
  47. }
  48. else if (iRow > 0)
  49. {
  50. if (_psf && _hdpa && ((iRow-1) < DPA_GetPtrCount(_hdpa)))
  51. {
  52. LPCITEMIDLIST pidl = (LPCITEMIDLIST)DPA_GetPtr(_hdpa, iRow - 1);
  53. WCHAR szValue[MAX_PATH];
  54. switch (iColumn)
  55. {
  56. case 1:
  57. hr = DisplayNameOf(_psf, pidl, SHGDN_INFOLDER, szValue, ARRAYSIZE(szValue));
  58. break;
  59. case 2:
  60. hr = DisplayNameOf(_psf, pidl, SHGDN_FORPARSING, szValue, ARRAYSIZE(szValue));
  61. break;
  62. default:
  63. ASSERT(FAILED(hr));
  64. break;
  65. }
  66. if (SUCCEEDED(hr))
  67. {
  68. pVar->vt = VT_BSTR;
  69. pVar->bstrVal = SysAllocString(szValue);
  70. }
  71. }
  72. }
  73. }
  74. return hr;
  75. }
  76. STDMETHODIMP CSimpleData::setVariant(DBROWCOUNT iRow, DB_LORDINAL iColumn, OSPFORMAT format, VARIANT Var)
  77. {
  78. return E_NOTIMPL;
  79. }
  80. STDMETHODIMP CSimpleData::getLocale(BSTR *pbstrLocale)
  81. {
  82. return E_NOTIMPL;
  83. }
  84. STDMETHODIMP CSimpleData::deleteRows(DBROWCOUNT iRow, DBROWCOUNT cRows, DBROWCOUNT *pcRowsDeleted)
  85. {
  86. return E_NOTIMPL;
  87. }
  88. STDMETHODIMP CSimpleData::insertRows(DBROWCOUNT iRow, DBROWCOUNT cRows, DBROWCOUNT *pcRowsInserted)
  89. {
  90. return E_NOTIMPL;
  91. }
  92. STDMETHODIMP CSimpleData::find(DBROWCOUNT iRowStart, DB_LORDINAL iColumn, VARIANT val,
  93. OSPFIND findFlags, OSPCOMP compType, DBROWCOUNT *piRowFound)
  94. {
  95. return E_NOTIMPL;
  96. }
  97. STDMETHODIMP CSimpleData::addOLEDBSimpleProviderListener(OLEDBSimpleProviderListener *pospIListener)
  98. {
  99. IUnknown_Set((IUnknown **)_ppListener, pospIListener);
  100. return S_OK;
  101. }
  102. STDMETHODIMP CSimpleData::removeOLEDBSimpleProviderListener(OLEDBSimpleProviderListener *pospIListener)
  103. {
  104. IUnknown_Set((IUnknown **)_ppListener, NULL);
  105. return S_OK;
  106. }
  107. STDMETHODIMP CSimpleData::getEstimatedRows(DBROWCOUNT *pcRows)
  108. {
  109. *pcRows = -1;
  110. return S_OK;
  111. }
  112. STDMETHODIMP CSimpleData::isAsync(BOOL *pbAsync)
  113. {
  114. *pbAsync = TRUE;
  115. return S_OK;
  116. }
  117. STDMETHODIMP CSimpleData::stopTransfer()
  118. {
  119. return E_NOTIMPL;
  120. }
  121. HRESULT CSimpleData::_DoEnum(void)
  122. {
  123. HRESULT hr = S_OK;
  124. if (_hdpa)
  125. {
  126. DPA_FreeIDArray(_hdpa);
  127. _hdpa = NULL;
  128. }
  129. if (_psf)
  130. {
  131. _hdpa = DPA_Create(4);
  132. if (_hdpa)
  133. {
  134. IEnumIDList* penum;
  135. hr = _psf->EnumObjects(NULL, SHCONTF_NONFOLDERS | SHCONTF_FOLDERS, &penum);
  136. if (S_OK == hr)
  137. {
  138. LPITEMIDLIST pidl;
  139. while (S_OK == penum->Next(1, &pidl, NULL))
  140. {
  141. DPA_AppendPtr(_hdpa, pidl);
  142. }
  143. penum->Release();
  144. }
  145. }
  146. else
  147. {
  148. hr = E_OUTOFMEMORY;
  149. }
  150. }
  151. else
  152. {
  153. hr = E_UNEXPECTED;
  154. }
  155. return hr;
  156. }
  157. HRESULT CSimpleData::SetShellFolder(IShellFolder *psf)
  158. {
  159. IUnknown_Set((IUnknown **)&_psf, psf);
  160. return S_OK;
  161. }