msvcrt: Implement _wfindnext64.
[wine] / dlls / shell32 / shfldr_printers.c
1 /*
2  *    Virtual Printers folder
3  *
4  *    Copyright 2010 Nikolay Sivov for CodeWeavers
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 <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
27
28 #include "winerror.h"
29 #include "windef.h"
30 #include "winbase.h"
31
32 #include "shell32_main.h"
33 #include "wine/debug.h"
34 #include "debughlp.h"
35
36 #include "shresdef.h"
37 #include "shfldr.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL (shell);
40
41 typedef struct {
42     const IShellFolder2Vtbl   *lpVtbl;
43     const IPersistFolder2Vtbl *lpvtblPersistFolder2;
44     LONG ref;
45
46     LPITEMIDLIST pidl;
47 } IPrintersFolderImpl;
48
49 static inline IPrintersFolderImpl *impl_from_IPersistFolder2(IPersistFolder2 *iface)
50 {
51     return (IPrintersFolderImpl *)((char*)iface - FIELD_OFFSET(IPrintersFolderImpl, lpvtblPersistFolder2));
52 }
53
54 static const shvheader printers_header[] = {
55     { IDS_SHV_COLUMN8,      SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 20 },
56     { IDS_SHV_COL_DOCS,     SHCOLSTATE_TYPE_INT | SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 12 },
57     { IDS_SHV_COL_STATUS,   SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 12 },
58     { IDS_SHV_COLUMN9,      SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 30 },
59     { IDS_SHV_COL_LOCATION, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 20 },
60     { IDS_SHV_COL_MODEL,    SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 20 }
61 };
62
63 #define PRINTERS_FOLDER_COL_NUM sizeof(printers_header)/sizeof(shvheader)
64
65 static HRESULT WINAPI IShellFolder_Printers_fnQueryInterface(IShellFolder2 *iface,
66                REFIID riid, LPVOID *ppvObj)
67 {
68     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
69
70     TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
71
72     *ppvObj = NULL;
73
74     if (IsEqualIID (riid, &IID_IUnknown) ||
75         IsEqualIID (riid, &IID_IShellFolder) ||
76         IsEqualIID (riid, &IID_IShellFolder2))
77     {
78         *ppvObj = This;
79     }
80     else if (IsEqualIID (riid, &IID_IPersist) ||
81              IsEqualIID (riid, &IID_IPersistFolder) ||
82              IsEqualIID (riid, &IID_IPersistFolder2))
83     {
84         *ppvObj = &This->lpvtblPersistFolder2;
85     }
86
87     if (*ppvObj)
88     {
89         IUnknown_AddRef ((IUnknown *) (*ppvObj));
90         TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
91         return S_OK;
92     }
93
94     ERR ("-- interface %s not supported\n", shdebugstr_guid (riid));
95     return E_NOINTERFACE;
96 }
97
98 static ULONG WINAPI IShellFolder_Printers_fnAddRef (IShellFolder2 * iface)
99 {
100     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
101     ULONG refCount = InterlockedIncrement(&This->ref);
102     TRACE ("(%p)->(count=%u)\n", This, refCount - 1);
103     return refCount;
104 }
105
106 static ULONG WINAPI IShellFolder_Printers_fnRelease (IShellFolder2 * iface)
107 {
108     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
109     ULONG refCount = InterlockedDecrement(&This->ref);
110
111     TRACE ("(%p)->(count=%u)\n", This, refCount + 1);
112
113     if (!refCount)
114     {
115         TRACE ("-- destroying IShellFolder(%p)\n", This);
116         SHFree(This->pidl);
117         LocalFree (This);
118     }
119     return refCount;
120 }
121
122 static HRESULT WINAPI IShellFolder_Printers_fnParseDisplayName (IShellFolder2 *iface,
123                HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
124                DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
125 {
126     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
127
128     FIXME("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p) stub\n", This,
129           hwndOwner, pbc, lpszDisplayName, debugstr_w (lpszDisplayName),
130           pchEaten, ppidl, pdwAttributes);
131
132     return E_NOTIMPL;
133 }
134
135 static HRESULT WINAPI IShellFolder_Printers_fnEnumObjects (IShellFolder2 *iface,
136                HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
137 {
138     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
139     FIXME("(%p)->(HWND=%p flags=0x%08x pplist=%p) stub\n", This,
140           hwndOwner, dwFlags, ppEnumIDList);
141     return E_NOTIMPL;
142 }
143
144 static HRESULT WINAPI IShellFolder_Printers_fnBindToObject (IShellFolder2 *iface,
145                LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
146 {
147     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
148     FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", This,
149           pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
150     return E_NOTIMPL;
151 }
152
153 static HRESULT WINAPI IShellFolder_Printers_fnBindToStorage (IShellFolder2 * iface,
154                LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
155 {
156     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
157
158     FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", This,
159           pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
160
161     *ppvOut = NULL;
162     return E_NOTIMPL;
163 }
164
165 static HRESULT WINAPI IShellFolder_Printers_fnCompareIDs(IShellFolder2 *iface,
166                LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
167 {
168     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
169     FIXME("(%p)->(0x%08lx,pidl1=%p,pidl2=%p) stub\n", This, lParam, pidl1, pidl2);
170     return E_NOTIMPL;
171 }
172
173 static HRESULT WINAPI IShellFolder_Printers_fnCreateViewObject(IShellFolder2 *iface,
174                HWND hwndOwner, REFIID riid, LPVOID *ppvOut)
175 {
176     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
177     HRESULT hr = E_NOTIMPL;
178
179     TRACE("(%p)->(hwnd=%p,%s,%p)\n", This,
180           hwndOwner, shdebugstr_guid (riid), ppvOut);
181
182     if (!ppvOut)
183         return E_INVALIDARG;
184
185     *ppvOut = NULL;
186
187     if (IsEqualIID (riid, &IID_IShellView))
188     {
189         IShellView *pShellView = IShellView_Constructor ((IShellFolder *) iface);
190         if (pShellView)
191         {
192             hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
193             IShellView_Release (pShellView);
194         }
195     }
196     else
197         WARN("unsupported interface %s\n", shdebugstr_guid (riid));
198
199     return hr;
200 }
201
202 static HRESULT WINAPI IShellFolder_Printers_fnGetAttributesOf (IShellFolder2 * iface,
203                 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
204 {
205     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
206     FIXME("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x)) stub\n",
207            This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
208     return E_NOTIMPL;
209 }
210
211 static HRESULT WINAPI IShellFolder_Printers_fnGetUIObjectOf (IShellFolder2 * iface,
212                 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl, REFIID riid,
213                 UINT * prgfInOut, LPVOID * ppvOut)
214 {
215     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
216
217     FIXME("(%p)->(%p,%u,apidl=%p,%s,%p,%p) stub\n", This,
218           hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
219
220     if (!ppvOut)
221         return E_INVALIDARG;
222
223     *ppvOut = NULL;
224
225     return E_NOTIMPL;
226 }
227
228 static HRESULT WINAPI IShellFolder_Printers_fnGetDisplayNameOf (IShellFolder2 *iface,
229                LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
230 {
231     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
232
233     FIXME("(%p)->(pidl=%p,0x%08x,%p) stub\n", This, pidl, dwFlags, strRet);
234
235     if (!strRet)
236         return E_INVALIDARG;
237
238     return E_NOTIMPL;
239 }
240
241 static HRESULT WINAPI IShellFolder_Printers_fnSetNameOf (
242                IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl,
243                LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
244 {
245     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
246     FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p) stub\n", This,
247            hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut);
248     return E_FAIL;
249 }
250
251 static HRESULT WINAPI IShellFolder_Printers_fnGetDefaultSearchGUID (
252                IShellFolder2 * iface, GUID * pguid)
253 {
254     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
255     FIXME ("(%p) stub\n", This);
256     return E_NOTIMPL;
257 }
258
259 static HRESULT WINAPI IShellFolder_Printers_fnEnumSearches (
260                IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
261 {
262     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
263     FIXME ("(%p) stub\n", This);
264     return E_NOTIMPL;
265 }
266
267 static HRESULT WINAPI IShellFolder_Printers_fnGetDefaultColumn (
268                IShellFolder2 *iface, DWORD dwRes, ULONG *pSort, ULONG *pDisplay)
269 {
270     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
271     FIXME("(%p) stub\n", This);
272     return E_NOTIMPL;
273 }
274
275 static HRESULT WINAPI IShellFolder_Printers_fnGetDefaultColumnState (
276                IShellFolder2 *iface, UINT iColumn, DWORD *pcsFlags)
277 {
278     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
279
280     TRACE("(%p)->(%d %p)\n", This, iColumn, pcsFlags);
281
282     if (iColumn >= PRINTERS_FOLDER_COL_NUM)
283         return E_INVALIDARG;
284
285     *pcsFlags = printers_header[iColumn].pcsFlags;
286
287     return S_OK;
288 }
289
290 static HRESULT WINAPI IShellFolder_Printers_fnGetDetailsEx (IShellFolder2 * iface,
291                LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
292 {
293     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
294     FIXME ("(%p) stub\n", This);
295     return E_NOTIMPL;
296 }
297
298 static HRESULT WINAPI IShellFolder_Printers_fnGetDetailsOf (IShellFolder2 *iface,
299                LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd)
300 {
301     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
302
303     TRACE("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
304
305     if (iColumn >= PRINTERS_FOLDER_COL_NUM)
306         return E_NOTIMPL;
307
308     if (!pidl)
309         return SHELL32_GetColumnDetails(printers_header, iColumn, psd);
310
311     FIXME("unimplemented for supplied pidl\n");
312
313     return E_NOTIMPL;
314 }
315
316 static HRESULT WINAPI IShellFolder_Printers_fnMapColumnToSCID (
317                IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
318 {
319     IPrintersFolderImpl *This = (IPrintersFolderImpl *)iface;
320     FIXME ("(%p)->(%u %p) stub\n", This, column, pscid);
321     return E_NOTIMPL;
322 }
323
324 static const IShellFolder2Vtbl vtbl_ShellFolder2 =
325 {
326     /* IUnknown */
327     IShellFolder_Printers_fnQueryInterface,
328     IShellFolder_Printers_fnAddRef,
329     IShellFolder_Printers_fnRelease,
330     /* IShellFolder */
331     IShellFolder_Printers_fnParseDisplayName,
332     IShellFolder_Printers_fnEnumObjects,
333     IShellFolder_Printers_fnBindToObject,
334     IShellFolder_Printers_fnBindToStorage,
335     IShellFolder_Printers_fnCompareIDs,
336     IShellFolder_Printers_fnCreateViewObject,
337     IShellFolder_Printers_fnGetAttributesOf,
338     IShellFolder_Printers_fnGetUIObjectOf,
339     IShellFolder_Printers_fnGetDisplayNameOf,
340     IShellFolder_Printers_fnSetNameOf,
341     /* IShellFolder2 */
342     IShellFolder_Printers_fnGetDefaultSearchGUID,
343     IShellFolder_Printers_fnEnumSearches,
344     IShellFolder_Printers_fnGetDefaultColumn,
345     IShellFolder_Printers_fnGetDefaultColumnState,
346     IShellFolder_Printers_fnGetDetailsEx,
347     IShellFolder_Printers_fnGetDetailsOf,
348     IShellFolder_Printers_fnMapColumnToSCID
349 };
350
351 /*** IPersistFolder2 ***/
352 static HRESULT WINAPI IPersistFolder2_Printers_fnQueryInterface(IPersistFolder2 * iface,
353                REFIID iid, LPVOID * ppvObj)
354 {
355     IPrintersFolderImpl *This = impl_from_IPersistFolder2(iface);
356     return IUnknown_QueryInterface( (IUnknown*) This, iid, ppvObj);
357 }
358
359 static ULONG WINAPI IPersistFolder2_Printers_fnAddRef(IPersistFolder2 *iface)
360 {
361     IPrintersFolderImpl *This = impl_from_IPersistFolder2(iface);
362     return IUnknown_AddRef( (IUnknown*) This);
363 }
364
365 static ULONG WINAPI IPersistFolder2_Printers_fnRelease(IPersistFolder2 *iface)
366 {
367     IPrintersFolderImpl *This = impl_from_IPersistFolder2(iface);
368     return IUnknown_Release( (IUnknown*) This);
369 }
370
371 static HRESULT WINAPI IPersistFolder2_Printers_fnGetClassID(IPersistFolder2 *iface, CLSID *classId)
372 {
373     IPrintersFolderImpl *This = impl_from_IPersistFolder2(iface);
374
375     FIXME("(%p) stub\n", This);
376
377     if (!classId)
378         return E_POINTER;
379
380     return E_NOTIMPL;
381 }
382
383 static HRESULT WINAPI IPersistFolder2_Printers_fnInitialize(IPersistFolder2 *iface, LPCITEMIDLIST pidl)
384 {
385     IPrintersFolderImpl *This = impl_from_IPersistFolder2(iface);
386
387     TRACE("(%p)->(%p)\n", This, pidl);
388
389     SHFree(This->pidl);
390     This->pidl = ILClone(pidl);
391
392     return S_OK;
393 }
394
395 static HRESULT WINAPI IPersistFolder2_Printers_fnGetCurFolder(IPersistFolder2 *iface, LPITEMIDLIST *pidl)
396 {
397     IPrintersFolderImpl *This = impl_from_IPersistFolder2(iface);
398
399     TRACE("(%p)->(%p)\n", This, pidl);
400
401     *pidl = ILClone(This->pidl);
402
403     return *pidl ? S_OK : S_FALSE;
404 }
405
406 static const IPersistFolder2Vtbl vtbl_PersistFolder2 =
407 {
408     IPersistFolder2_Printers_fnQueryInterface,
409     IPersistFolder2_Printers_fnAddRef,
410     IPersistFolder2_Printers_fnRelease,
411     IPersistFolder2_Printers_fnGetClassID,
412     IPersistFolder2_Printers_fnInitialize,
413     IPersistFolder2_Printers_fnGetCurFolder
414 };
415
416 HRESULT WINAPI Printers_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
417 {
418     IPrintersFolderImpl *sf;
419
420     TRACE("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
421
422     if (!ppv)
423         return E_POINTER;
424     if (pUnkOuter)
425         return CLASS_E_NOAGGREGATION;
426
427     sf = LocalAlloc(LMEM_FIXED, sizeof(IPrintersFolderImpl));
428     if (!sf)
429         return E_OUTOFMEMORY;
430
431     sf->ref = 0;
432     sf->pidl = NULL;
433     sf->lpVtbl = &vtbl_ShellFolder2;
434     sf->lpvtblPersistFolder2 = &vtbl_PersistFolder2;
435
436     if (IUnknown_QueryInterface((IShellFolder2 *)sf, riid, ppv) != S_OK)
437     {
438         IUnknown_Release((IShellFolder2 *) sf);
439         return E_NOINTERFACE;
440     }
441
442     TRACE("--(%p)\n", sf);
443     return S_OK;
444 }