Author: mjansen
Date: Sun Aug 21 19:58:32 2016
New Revision: 72416
URL:
http://svn.reactos.org/svn/reactos?rev=72416&view=rev
Log:
[SHELL32] Partially implement CFolderItems. Thanks to Giannis for the advice :)
Modified:
trunk/reactos/dll/win32/shell32/CFolder.cpp
trunk/reactos/dll/win32/shell32/CFolderItems.cpp
trunk/reactos/dll/win32/shell32/CFolderItems.h
Modified: trunk/reactos/dll/win32/shell32/CFolder.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/CFolder.…
==============================================================================
--- trunk/reactos/dll/win32/shell32/CFolder.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/CFolder.cpp [iso-8859-1] Sun Aug 21 19:58:32 2016
@@ -82,9 +82,17 @@
HRESULT STDMETHODCALLTYPE CFolder::Items(FolderItems **ppid)
{
- CFolderItems* item = new CComObject<CFolderItems>();
- item->AddRef();
- *ppid = item;
+ CFolderItems* items = new CComObject<CFolderItems>();
+ items->AddRef();
+
+ HRESULT hr = items->Init(ILClone(m_idlist));
+ if (FAILED_UNEXPECTEDLY(hr))
+ {
+ items->Release();
+ return hr;
+ }
+
+ *ppid = items;
return S_OK;
}
Modified: trunk/reactos/dll/win32/shell32/CFolderItems.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/CFolderI…
==============================================================================
--- trunk/reactos/dll/win32/shell32/CFolderItems.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/CFolderItems.cpp [iso-8859-1] Sun Aug 21 19:58:32
2016
@@ -1,7 +1,7 @@
/*
* FolderItem(s) implementation
*
- * Copyright 2015 Mark Jansen
+ * Copyright 2015,2016 Mark Jansen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -162,18 +162,65 @@
CFolderItems::CFolderItems()
+ :m_Count(-1)
{
}
CFolderItems::~CFolderItems()
{
+}
+
+HRESULT CFolderItems::Init(LPITEMIDLIST idlist)
+{
+ CComPtr<IShellFolder> psfDesktop, psfTarget;
+
+ m_idlist.Attach(idlist);
+
+ HRESULT hr = SHGetDesktopFolder(&psfDesktop);
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
+
+ hr = psfDesktop->BindToObject(m_idlist, NULL, IID_PPV_ARG(IShellFolder,
&psfTarget));
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
+
+ hr = psfTarget->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS,
&m_EnumIDList);
+
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
+
+ return S_OK;
}
// *** FolderItems methods ***
HRESULT STDMETHODCALLTYPE CFolderItems::get_Count(long *plCount)
{
- TRACE("(%p, %p)\n", this, plCount);
- return E_NOTIMPL;
+ if (!m_EnumIDList)
+ return E_FAIL;
+
+ if (!plCount)
+ return E_POINTER;
+
+ if (m_Count == -1)
+ {
+ long count = 0;
+
+ HRESULT hr = m_EnumIDList->Reset();
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
+
+ CComHeapPtr<ITEMIDLIST> Pidl;
+ hr = m_EnumIDList->Next(1, &Pidl, 0);
+ while (hr != S_FALSE)
+ {
+ count++;
+ Pidl.Free();
+ }
+ m_Count = count;
+ }
+ *plCount = m_Count;
+
+ return S_OK;
}
HRESULT STDMETHODCALLTYPE CFolderItems::get_Application(IDispatch **ppid)
@@ -190,13 +237,43 @@
HRESULT STDMETHODCALLTYPE CFolderItems::Item(VARIANT index, FolderItem **ppid)
{
- TRACE("(%p, %s, %p)\n", this, wine_dbgstr_variant(&index), ppid);
- return E_NOTIMPL;
+ if (!m_EnumIDList)
+ return E_FAIL;
+
+ if (V_VT(&index) != VT_I4 && V_VT(&index) != VT_UI4)
+ return E_INVALIDARG;
+
+ ULONG count = V_UI4(&index);
+
+ HRESULT hr = m_EnumIDList->Reset();
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
+
+ hr = m_EnumIDList->Skip(count);
+
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
+
+ CComHeapPtr<ITEMIDLIST> spPidl;
+ hr = m_EnumIDList->Next(1, &spPidl, 0);
+ if (hr == S_OK)
+ {
+ CFolderItem* item = new CComObject<CFolderItem>();
+ item->AddRef();
+ item->Init(spPidl.Detach());
+ *ppid = item;
+ return S_OK;
+ }
+
+ return hr;
}
HRESULT STDMETHODCALLTYPE CFolderItems::_NewEnum(IUnknown **ppunk)
{
- TRACE("(%p, %p)\n", this, ppunk);
- return E_NOTIMPL;
-}
-
+ CFolderItems* items = new CComObject<CFolderItems>();
+ items->AddRef();
+ items->Init(ILClone(m_idlist));
+ *ppunk = items;
+ return S_OK;
+}
+
Modified: trunk/reactos/dll/win32/shell32/CFolderItems.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/CFolderI…
==============================================================================
--- trunk/reactos/dll/win32/shell32/CFolderItems.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/CFolderItems.h [iso-8859-1] Sun Aug 21 19:58:32 2016
@@ -34,6 +34,7 @@
CFolderItem();
~CFolderItem();
+ // Please note: CFolderItem takes ownership of idlist.
void Init(LPITEMIDLIST idlist);
@@ -72,10 +73,16 @@
public IDispatchImpl<FolderItems, &IID_FolderItems>
{
private:
+ CComHeapPtr<ITEMIDLIST> m_idlist;
+ CComPtr<IEnumIDList> m_EnumIDList;
+ long m_Count;
public:
CFolderItems();
~CFolderItems();
+
+ // Please note: CFolderItems takes ownership of idlist.
+ HRESULT Init(LPITEMIDLIST idlist);
// *** FolderItems methods ***
virtual HRESULT STDMETHODCALLTYPE get_Count(long *plCount);