ReactOS 0.4.17-dev-573-g8315b8c
CEnumIDListBase.cpp
Go to the documentation of this file.
1/*
2 * IEnumIDList
3 *
4 * Copyright 1998 Juergen Schmied <juergen.schmied@metronet.de>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include "precomp.h"
22
24
26 mpFirst(NULL),
27 mpLast(NULL),
28 mpCurrent(NULL)
29{
30}
31
33{
34 DeleteList();
35}
36
37/**************************************************************************
38 * AddToEnumList()
39 */
41{
42 ENUMLIST *pNew;
43
44 TRACE("(%p)->(pidl=%p)\n", this, pidl);
45
46 if (!pidl)
47 return FALSE;
48
49 pNew = static_cast<ENUMLIST *>(SHAlloc(sizeof(ENUMLIST)));
50 if (pNew)
51 {
52 /*set the next pointer */
53 pNew->pNext = NULL;
54 pNew->pidl = pidl;
55
56 /*is This the first item in the list? */
57 if (!mpFirst)
58 {
59 mpFirst = pNew;
60 mpCurrent = pNew;
61 }
62
63 if (mpLast)
64 {
65 /*add the new item to the end of the list */
66 mpLast->pNext = pNew;
67 }
68
69 /*update the last item pointer */
70 mpLast = pNew;
71 TRACE("-- (%p)->(first=%p, last=%p)\n", this, mpFirst, mpLast);
72 return TRUE;
73 }
74 return FALSE;
75}
76
77/**************************************************************************
78* DeleteList()
79*/
81{
82 ENUMLIST *pDelete;
83
84 TRACE("(%p)->()\n", this);
85
86 while (mpFirst)
87 {
88 pDelete = mpFirst;
89 mpFirst = pDelete->pNext;
90 SHFree(pDelete->pidl);
91 SHFree(pDelete);
92 }
93 mpFirst = NULL;
94 mpLast = NULL;
96 return TRUE;
97}
98
100{
101 LPITEMIDLIST pidl;
102 DWORD dwFetched;
103
104 if (!pEnum)
105 return E_INVALIDARG;
106
107 pEnum->Reset();
108
109 while((S_OK == pEnum->Next(1, &pidl, &dwFetched)) && dwFetched)
110 {
111 if (!AddToEnumList(pidl))
112 {
113 ILFree(pidl);
114 return E_OUTOFMEMORY;
115 }
116 }
117
118 return S_OK;
119}
120
121/**************************************************************************
122 * IEnumIDList_fnNext
123 */
124
126 ULONG celt,
127 LPITEMIDLIST * rgelt,
128 ULONG *pceltFetched)
129{
130 ULONG i;
131 HRESULT hr = S_OK;
133
134 TRACE("(%p)->(%d,%p, %p)\n", this, celt, rgelt, pceltFetched);
135
136/* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
137 * subsystems actually use it (and so may a third party browser)
138 */
139 if(pceltFetched)
140 *pceltFetched = 0;
141
142 *rgelt=0;
143
144 if(celt > 1 && !pceltFetched)
145 { return E_INVALIDARG;
146 }
147
148 if(celt > 0 && !mpCurrent)
149 { return S_FALSE;
150 }
151
152 for(i = 0; i < celt; i++)
153 { if(!mpCurrent)
154 { hr = S_FALSE;
155 break;
156 }
157
159 if (!temp)
160 { hr = i ? S_FALSE : E_OUTOFMEMORY;
161 break;
162 }
163 rgelt[i] = temp;
165 }
166 if(pceltFetched)
167 { *pceltFetched = i;
168 }
169
170 return hr;
171}
172
173/**************************************************************************
174* IEnumIDList_fnSkip
175*/
177 ULONG celt)
178{
179 DWORD dwIndex;
180 HRESULT hr = S_OK;
181
182 TRACE("(%p)->(%u)\n", this, celt);
183
184 for(dwIndex = 0; dwIndex < celt; dwIndex++)
185 { if(!mpCurrent)
186 { hr = S_FALSE;
187 break;
188 }
190 }
191 return hr;
192}
193
194/**************************************************************************
195* IEnumIDList_fnReset
196*/
198{
199 TRACE("(%p)\n", this);
201 return S_OK;
202}
203
204/**************************************************************************
205* IEnumIDList_fnClone
206*/
208{
209 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n", this, ppenum);
210 return E_NOTIMPL;
211}
212
213/**************************************************************************
214* CreateInstance
215*/
216HRESULT CEnumIDListBase::CreateInstance(IEnumIDList &Source, CREATEINSTANCEFILTERFUNC Filter, void *CallerCookie, IEnumIDList **ppEnum)
217{
218 *ppEnum = NULL;
220 HRESULT hr = ShellObjectCreator(pEnum);
221 if (FAILED(hr))
222 return hr;
223
224 for (;;)
225 {
227 hr = Source.Next(1, &pidl, NULL);
228 if (hr == S_OK)
229 {
230 if (Filter)
231 hr = Filter(CallerCookie, pidl);
232 if (FAILED(hr))
233 return hr;
234 if (hr != S_OK)
235 continue;
236 if (!pEnum->AddToEnumList(pidl))
237 return E_OUTOFMEMORY;
238 pidl.Detach(); // AddToEnumList took ownership
239 continue;
240 }
241 if (FAILED(hr))
242 return hr;
243 *ppEnum = pEnum.Detach();
244 return S_OK;
245 }
246}
247
248/**************************************************************************
249 * IEnumIDList_Folder_Constructor
250 *
251 */
253{
254 return ShellObjectCreator<CEnumIDListBase>(IID_PPV_ARG(IEnumIDList, enumerator));
255}
HRESULT IEnumIDList_Constructor(IEnumIDList **enumerator)
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
void shell(int argc, const char *argv[])
Definition: cmds.c:1231
T * Detach()
Definition: atlcomcli.h:186
static HRESULT CreateInstance(IEnumIDList &Source, CREATEINSTANCEFILTERFUNC Filter, void *CallerCookie, IEnumIDList **ppEnum)
STDMETHOD() Clone(IEnumIDList **ppenum) override
STDMETHOD() Skip(ULONG celt) override
ENUMLIST * mpLast
ENUMLIST * mpCurrent
ENUMLIST * mpFirst
BOOL AddToEnumList(LPITEMIDLIST pidl)
virtual ~CEnumIDListBase()
HRESULT AppendItemsFromEnumerator(IEnumIDList *pEnum)
STDMETHOD() Reset() override
STDMETHOD() Next(ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched) override
T * Detach()
Definition: atlalloc.h:168
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:370
LPVOID WINAPI SHAlloc(SIZE_T len)
Definition: shellole.c:348
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_opt_ PFLT_FILTER Filter
Definition: fltkernel.h:1801
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] PITEMID_CHILD *rgelt, [out] ULONG *pceltFetched)
HRESULT Reset()
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
LPITEMIDLIST WINAPI ILClone(LPCITEMIDLIST pidl)
Definition: pidl.c:238
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:1051
static calc_node_t temp
Definition: rpn_ieee.c:38
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define TRACE(s)
Definition: solgame.cpp:4
ENUMLIST * pNext
LPITEMIDLIST pidl
uint32_t ULONG
Definition: typedefs.h:59
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:3451
#define IID_PPV_ARG(Itype, ppType)