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.

188 lines
4.1 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); // accpets 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. }
  63. if (SUCCEEDED(hr))
  64. {
  65. pVar->vt = VT_BSTR;
  66. pVar->bstrVal = SysAllocString(szValue);
  67. }
  68. }
  69. }
  70. }
  71. return hr;
  72. }
  73. STDMETHODIMP CSimpleData::setVariant(DBROWCOUNT iRow, DB_LORDINAL iColumn, OSPFORMAT format, VARIANT Var)
  74. {
  75. return E_NOTIMPL;
  76. }
  77. STDMETHODIMP CSimpleData::getLocale(BSTR *pbstrLocale)
  78. {
  79. return E_NOTIMPL;
  80. }
  81. STDMETHODIMP CSimpleData::deleteRows(DBROWCOUNT iRow, DBROWCOUNT cRows, DBROWCOUNT *pcRowsDeleted)
  82. {
  83. return E_NOTIMPL;
  84. }
  85. STDMETHODIMP CSimpleData::insertRows(DBROWCOUNT iRow, DBROWCOUNT cRows, DBROWCOUNT *pcRowsInserted)
  86. {
  87. return E_NOTIMPL;
  88. }
  89. STDMETHODIMP CSimpleData::find(DBROWCOUNT iRowStart, DB_LORDINAL iColumn, VARIANT val,
  90. OSPFIND findFlags, OSPCOMP compType, DBROWCOUNT *piRowFound)
  91. {
  92. return E_NOTIMPL;
  93. }
  94. STDMETHODIMP CSimpleData::addOLEDBSimpleProviderListener(OLEDBSimpleProviderListener *pospIListener)
  95. {
  96. IUnknown_Set((IUnknown **)_ppListener, pospIListener);
  97. return S_OK;
  98. }
  99. STDMETHODIMP CSimpleData::removeOLEDBSimpleProviderListener(OLEDBSimpleProviderListener *pospIListener)
  100. {
  101. IUnknown_Set((IUnknown **)_ppListener, NULL);
  102. return S_OK;
  103. }
  104. STDMETHODIMP CSimpleData::getEstimatedRows(DBROWCOUNT *pcRows)
  105. {
  106. *pcRows = -1;
  107. return S_OK;
  108. }
  109. STDMETHODIMP CSimpleData::isAsync(BOOL *pbAsync)
  110. {
  111. *pbAsync = TRUE;
  112. return S_OK;
  113. }
  114. STDMETHODIMP CSimpleData::stopTransfer()
  115. {
  116. return E_NOTIMPL;
  117. }
  118. HRESULT CSimpleData::_DoEnum(void)
  119. {
  120. HRESULT hr = S_OK;
  121. if (_hdpa)
  122. {
  123. DPA_FreeIDArray(_hdpa);
  124. _hdpa = NULL;
  125. }
  126. if (_psf)
  127. {
  128. _hdpa = DPA_Create(4);
  129. if (_hdpa)
  130. {
  131. IEnumIDList* penum;
  132. hr = _psf->EnumObjects(NULL, SHCONTF_NONFOLDERS | SHCONTF_FOLDERS, &penum);
  133. if (S_OK == hr)
  134. {
  135. LPITEMIDLIST pidl;
  136. while (S_OK == penum->Next(1, &pidl, NULL))
  137. {
  138. DPA_AppendPtr(_hdpa, pidl);
  139. }
  140. penum->Release();
  141. }
  142. }
  143. else
  144. {
  145. hr = E_OUTOFMEMORY;
  146. }
  147. }
  148. else
  149. {
  150. hr = E_UNEXPECTED;
  151. }
  152. return hr;
  153. }
  154. HRESULT CSimpleData::SetShellFolder(IShellFolder *psf)
  155. {
  156. IUnknown_Set((IUnknown **)&_psf, psf);
  157. return S_OK;
  158. }