[SHELL32]
[reactos.git] / dll / win32 / shell32 / wine / pidl.c
1 /*
2 * pidl Handling
3 *
4 * Copyright 1998 Juergen Schmied
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 * NOTES
21 * a pidl == NULL means desktop and is legal
22 *
23 */
24
25 #include <wine/config.h>
26
27 #define WIN32_NO_STATUS
28 #define _INC_WINDOWS
29 #define COBJMACROS
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
32
33 #include <windef.h>
34 #include <winbase.h>
35 #include <shlobj.h>
36 #include <undocshell.h>
37 #include <shlwapi.h>
38 #include <shlguid_undoc.h>
39 #include <wine/debug.h>
40 #include <wine/unicode.h>
41
42 #include "pidl.h"
43 #include "shell32_main.h"
44 #include "shresdef.h"
45
46 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
47 WINE_DECLARE_DEBUG_CHANNEL(shell);
48
49 /* from comctl32.dll */
50 extern LPVOID WINAPI Alloc(INT);
51 extern BOOL WINAPI Free(LPVOID);
52
53 static LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl);
54 static LPWSTR _ILGetTextPointerW(LPCITEMIDLIST pidl);
55
56 /*************************************************************************
57 * ILGetDisplayNameExA
58 *
59 * Retrieves the display name of an ItemIDList
60 *
61 * PARAMS
62 * psf [I] Shell Folder to start with, if NULL the desktop is used
63 * pidl [I] ItemIDList relative to the psf to get the display name for
64 * path [O] Filled in with the display name, assumed to be at least MAX_PATH long
65 * type [I] Type of display name to retrieve
66 * 0 = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR uses always the desktop as root
67 * 1 = SHGDN_NORMAL relative to the root folder
68 * 2 = SHGDN_INFOLDER relative to the root folder, only the last name
69 *
70 * RETURNS
71 * True if the display name could be retrieved successfully, False otherwise
72 */
73 static BOOL ILGetDisplayNameExA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPSTR path, DWORD type)
74 {
75 BOOL ret = FALSE;
76 WCHAR wPath[MAX_PATH];
77
78 TRACE("%p %p %p %d\n", psf, pidl, path, type);
79
80 if (!pidl || !path)
81 return FALSE;
82
83 ret = ILGetDisplayNameExW(psf, pidl, wPath, type);
84 WideCharToMultiByte(CP_ACP, 0, wPath, -1, path, MAX_PATH, NULL, NULL);
85 TRACE("%p %p %s\n", psf, pidl, debugstr_a(path));
86
87 return ret;
88 }
89
90 BOOL ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
91 {
92 LPSHELLFOLDER psfParent, lsf = psf;
93 HRESULT ret = NO_ERROR;
94 LPCITEMIDLIST pidllast;
95 STRRET strret;
96 DWORD flag;
97
98 TRACE("%p %p %p %x\n", psf, pidl, path, type);
99
100 if (!pidl || !path)
101 return FALSE;
102
103 if (!lsf)
104 {
105 ret = SHGetDesktopFolder(&lsf);
106 if (FAILED(ret))
107 return FALSE;
108 }
109
110 switch (type)
111 {
112 case ILGDN_FORPARSING:
113 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
114 break;
115 case ILGDN_NORMAL:
116 flag = SHGDN_NORMAL;
117 break;
118 case ILGDN_INFOLDER:
119 flag = SHGDN_INFOLDER;
120 break;
121 default:
122 FIXME("Unknown type parameter = %x\n", type);
123 flag = SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
124 break;
125 }
126
127 if (!*(const WORD*)pidl || type == ILGDN_FORPARSING)
128 {
129 ret = IShellFolder_GetDisplayNameOf(lsf, pidl, flag, &strret);
130 if (SUCCEEDED(ret))
131 {
132 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidl))
133 ret = E_FAIL;
134 }
135 }
136 else
137 {
138 ret = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidllast);
139 if (SUCCEEDED(ret))
140 {
141 ret = IShellFolder_GetDisplayNameOf(psfParent, pidllast, flag, &strret);
142 if (SUCCEEDED(ret))
143 {
144 if(!StrRetToStrNW(path, MAX_PATH, &strret, pidllast))
145 ret = E_FAIL;
146 }
147 IShellFolder_Release(psfParent);
148 }
149 }
150
151 TRACE("%p %p %s\n", psf, pidl, debugstr_w(path));
152
153 if (!psf)
154 IShellFolder_Release(lsf);
155 return SUCCEEDED(ret);
156 }
157
158 /*************************************************************************
159 * ILGetDisplayNameEx [SHELL32.186]
160 */
161 BOOL WINAPI ILGetDisplayNameEx(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPVOID path, DWORD type)
162 {
163 TRACE_(shell)("%p %p %p %d\n", psf, pidl, path, type);
164
165 if (SHELL_OsIsUnicode())
166 return ILGetDisplayNameExW(psf, pidl, path, type);
167 return ILGetDisplayNameExA(psf, pidl, path, type);
168 }
169
170 /*************************************************************************
171 * ILGetDisplayName [SHELL32.15]
172 */
173 BOOL WINAPI ILGetDisplayName(LPCITEMIDLIST pidl, LPVOID path)
174 {
175 TRACE_(shell)("%p %p\n", pidl, path);
176
177 if (SHELL_OsIsUnicode())
178 return ILGetDisplayNameExW(NULL, pidl, path, ILGDN_FORPARSING);
179 return ILGetDisplayNameExA(NULL, pidl, path, ILGDN_FORPARSING);
180 }
181
182 /*************************************************************************
183 * ILFindLastID [SHELL32.16]
184 *
185 * NOTES
186 * observed: pidl=Desktop return=pidl
187 */
188 LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
189 {
190 LPCITEMIDLIST pidlLast = pidl;
191
192 TRACE("(pidl=%p)\n",pidl);
193
194 if (!pidl)
195 return NULL;
196
197 while (pidl->mkid.cb)
198 {
199 pidlLast = pidl;
200 pidl = ILGetNext(pidl);
201 }
202 return (LPITEMIDLIST)pidlLast;
203 }
204
205 /*************************************************************************
206 * ILRemoveLastID [SHELL32.17]
207 *
208 * NOTES
209 * when pidl=Desktop return=FALSE
210 */
211 BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
212 {
213 TRACE_(shell)("pidl=%p\n",pidl);
214
215 if (_ILIsEmpty(pidl))
216 return FALSE;
217 ILFindLastID(pidl)->mkid.cb = 0;
218 return TRUE;
219 }
220
221 /*************************************************************************
222 * ILClone [SHELL32.18]
223 *
224 * NOTES
225 * duplicate an idlist
226 */
227 LPITEMIDLIST WINAPI ILClone (LPCITEMIDLIST pidl)
228 {
229 DWORD len;
230 LPITEMIDLIST newpidl;
231
232 if (!pidl)
233 return NULL;
234
235 len = ILGetSize(pidl);
236 newpidl = SHAlloc(len);
237 if (newpidl)
238 memcpy(newpidl,pidl,len);
239
240 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
241 pdump(pidl);
242
243 return newpidl;
244 }
245
246 /*************************************************************************
247 * ILCloneFirst [SHELL32.19]
248 *
249 * NOTES
250 * duplicates the first idlist of a complex pidl
251 */
252 LPITEMIDLIST WINAPI ILCloneFirst(LPCITEMIDLIST pidl)
253 {
254 DWORD len;
255 LPITEMIDLIST pidlNew = NULL;
256
257 TRACE("pidl=%p\n", pidl);
258 pdump(pidl);
259
260 if (pidl)
261 {
262 len = pidl->mkid.cb;
263 pidlNew = SHAlloc(len+2);
264 if (pidlNew)
265 {
266 memcpy(pidlNew,pidl,len+2); /* 2 -> mind a desktop pidl */
267
268 if (len)
269 ILGetNext(pidlNew)->mkid.cb = 0x00;
270 }
271 }
272 TRACE("-- newpidl=%p\n",pidlNew);
273
274 return pidlNew;
275 }
276
277 /*************************************************************************
278 * ILLoadFromStream (SHELL32.26)
279 *
280 * NOTES
281 * the first two bytes are the len, the pidl is following then
282 */
283 HRESULT WINAPI ILLoadFromStream (IStream * pStream, LPITEMIDLIST * ppPidl)
284 {
285 WORD wLen = 0;
286 DWORD dwBytesRead;
287 HRESULT ret = E_FAIL;
288
289
290 TRACE_(shell)("%p %p\n", pStream , ppPidl);
291
292 SHFree(*ppPidl);
293 *ppPidl = NULL;
294
295 IStream_AddRef (pStream);
296
297 if (SUCCEEDED(IStream_Read(pStream, &wLen, 2, &dwBytesRead)))
298 {
299 TRACE("PIDL length is %d\n", wLen);
300 if (wLen != 0)
301 {
302 *ppPidl = SHAlloc (wLen);
303 if (SUCCEEDED(IStream_Read(pStream, *ppPidl , wLen, &dwBytesRead)))
304 {
305 TRACE("Stream read OK\n");
306 ret = S_OK;
307 }
308 else
309 {
310 WARN("reading pidl failed\n");
311 SHFree(*ppPidl);
312 *ppPidl = NULL;
313 }
314 }
315 else
316 {
317 *ppPidl = NULL;
318 ret = S_OK;
319 }
320 }
321
322 /* we are not yet fully compatible */
323 if (*ppPidl && !pcheck(*ppPidl))
324 {
325 WARN("Check failed\n");
326 SHFree(*ppPidl);
327 *ppPidl = NULL;
328 }
329
330 IStream_Release (pStream);
331 TRACE("done\n");
332 return ret;
333 }
334
335 /*************************************************************************
336 * ILSaveToStream (SHELL32.27)
337 *
338 * NOTES
339 * the first two bytes are the len, the pidl is following then
340 */
341 HRESULT WINAPI ILSaveToStream (IStream * pStream, LPCITEMIDLIST pPidl)
342 {
343 WORD wLen = 0;
344 HRESULT ret = E_FAIL;
345
346 TRACE_(shell)("%p %p\n", pStream, pPidl);
347
348 IStream_AddRef (pStream);
349
350 wLen = ILGetSize(pPidl);
351
352 if (SUCCEEDED(IStream_Write(pStream, &wLen, 2, NULL)))
353 {
354 if (SUCCEEDED(IStream_Write(pStream, pPidl, wLen, NULL)))
355 ret = S_OK;
356 }
357 IStream_Release (pStream);
358
359 return ret;
360 }
361
362 /*************************************************************************
363 * SHILCreateFromPath [SHELL32.28]
364 *
365 * Create an ItemIDList from a path
366 *
367 * PARAMS
368 * path [I]
369 * ppidl [O]
370 * attributes [I/O] requested attributes on call and actual attributes when
371 * the function returns
372 *
373 * RETURNS
374 * NO_ERROR if successful, or an OLE errer code otherwise
375 *
376 * NOTES
377 * Wrapper for IShellFolder_ParseDisplayName().
378 */
379 HRESULT WINAPI SHILCreateFromPathA(LPCSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
380 {
381 WCHAR lpszDisplayName[MAX_PATH];
382
383 TRACE_(shell)("%s %p 0x%08x\n", path, ppidl, attributes ? *attributes : 0);
384
385 if (!MultiByteToWideChar(CP_ACP, 0, path, -1, lpszDisplayName, MAX_PATH))
386 lpszDisplayName[MAX_PATH-1] = 0;
387
388 return SHILCreateFromPathW(lpszDisplayName, ppidl, attributes);
389 }
390
391 HRESULT WINAPI SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST * ppidl, DWORD * attributes)
392 {
393 LPSHELLFOLDER sf;
394 DWORD pchEaten;
395 HRESULT ret = E_FAIL;
396
397 TRACE_(shell)("%s %p 0x%08x\n", debugstr_w(path), ppidl, attributes ? *attributes : 0);
398
399 if (SUCCEEDED (SHGetDesktopFolder(&sf)))
400 {
401 ret = IShellFolder_ParseDisplayName(sf, 0, NULL, (LPWSTR)path, &pchEaten, ppidl, attributes);
402 IShellFolder_Release(sf);
403 }
404 return ret;
405 }
406
407 HRESULT WINAPI SHILCreateFromPathAW (LPCVOID path, LPITEMIDLIST * ppidl, DWORD * attributes)
408 {
409 if ( SHELL_OsIsUnicode())
410 return SHILCreateFromPathW (path, ppidl, attributes);
411 return SHILCreateFromPathA (path, ppidl, attributes);
412 }
413
414 /*************************************************************************
415 * SHCloneSpecialIDList [SHELL32.89]
416 *
417 * Create an ItemIDList to one of the special folders.
418
419 * PARAMS
420 * hwndOwner [in]
421 * nFolder [in] CSIDL_xxxxx
422 * fCreate [in] Create folder if it does not exist
423 *
424 * RETURNS
425 * Success: The newly created pidl
426 * Failure: NULL, if inputs are invalid.
427 *
428 * NOTES
429 * exported by ordinal.
430 * Caller is responsible for deallocating the returned ItemIDList with the
431 * shells IMalloc interface, aka ILFree.
432 */
433 LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner, int nFolder, BOOL fCreate)
434 {
435 LPITEMIDLIST ppidl;
436 TRACE_(shell)("(hwnd=%p,csidl=0x%x,%s).\n", hwndOwner, nFolder, fCreate ? "T" : "F");
437
438 if (fCreate)
439 nFolder |= CSIDL_FLAG_CREATE;
440
441 SHGetSpecialFolderLocation(hwndOwner, nFolder, &ppidl);
442 return ppidl;
443 }
444
445 /*************************************************************************
446 * ILGlobalClone [SHELL32.20]
447 *
448 * Clones an ItemIDList using Alloc.
449 *
450 * PARAMS
451 * pidl [I] ItemIDList to clone
452 *
453 * RETURNS
454 * Newly allocated ItemIDList.
455 *
456 * NOTES
457 * exported by ordinal.
458 */
459 LPITEMIDLIST WINAPI ILGlobalClone(LPCITEMIDLIST pidl)
460 {
461 DWORD len;
462 LPITEMIDLIST newpidl;
463
464 if (!pidl)
465 return NULL;
466
467 len = ILGetSize(pidl);
468 newpidl = Alloc(len);
469 if (newpidl)
470 memcpy(newpidl,pidl,len);
471
472 TRACE("pidl=%p newpidl=%p\n",pidl, newpidl);
473 pdump(pidl);
474
475 return newpidl;
476 }
477
478 /*************************************************************************
479 * ILIsEqual [SHELL32.21]
480 *
481 */
482 BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
483 {
484 char szData1[MAX_PATH];
485 char szData2[MAX_PATH];
486
487 LPCITEMIDLIST pidltemp1 = pidl1;
488 LPCITEMIDLIST pidltemp2 = pidl2;
489
490 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
491
492 /*
493 * Explorer reads from registry directly (StreamMRU),
494 * so we can only check here
495 */
496 if (!pcheck(pidl1) || !pcheck (pidl2))
497 return FALSE;
498
499 pdump (pidl1);
500 pdump (pidl2);
501
502 if (!pidl1 || !pidl2)
503 return FALSE;
504
505 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
506 {
507 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
508 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
509
510 if (strcasecmp( szData1, szData2 ))
511 return FALSE;
512
513 pidltemp1 = ILGetNext(pidltemp1);
514 pidltemp2 = ILGetNext(pidltemp2);
515 }
516
517 if (!pidltemp1->mkid.cb && !pidltemp2->mkid.cb)
518 return TRUE;
519
520 return FALSE;
521 }
522
523 /*************************************************************************
524 * ILIsParent [SHELL32.23]
525 *
526 * Verifies that pidlParent is indeed the (immediate) parent of pidlChild.
527 *
528 * PARAMS
529 * pidlParent [I]
530 * pidlChild [I]
531 * bImmediate [I] only return true if the parent is the direct parent
532 * of the child
533 *
534 * RETURNS
535 * True if the parent ItemIDlist is a complete part of the child ItemIdList,
536 * False otherwise.
537 *
538 * NOTES
539 * parent = a/b, child = a/b/c -> true, c is in folder a/b
540 * child = a/b/c/d -> false if bImmediate is true, d is not in folder a/b
541 * child = a/b/c/d -> true if bImmediate is false, d is in a subfolder of a/b
542 * child = a/b -> false if bImmediate is true
543 * child = a/b -> true if bImmediate is false
544 */
545 BOOL WINAPI ILIsParent(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
546 {
547 char szData1[MAX_PATH];
548 char szData2[MAX_PATH];
549 LPCITEMIDLIST pParent = pidlParent;
550 LPCITEMIDLIST pChild = pidlChild;
551
552 TRACE("%p %p %x\n", pidlParent, pidlChild, bImmediate);
553
554 if (!pParent || !pChild)
555 return FALSE;
556
557 while (pParent->mkid.cb && pChild->mkid.cb)
558 {
559 _ILSimpleGetText(pParent, szData1, MAX_PATH);
560 _ILSimpleGetText(pChild, szData2, MAX_PATH);
561
562 if (strcasecmp( szData1, szData2 ))
563 return FALSE;
564
565 pParent = ILGetNext(pParent);
566 pChild = ILGetNext(pChild);
567 }
568
569 /* child has shorter name than parent */
570 if (pParent->mkid.cb)
571 return FALSE;
572
573 /* not immediate descent */
574 if ((!pChild->mkid.cb || ILGetNext(pChild)->mkid.cb) && bImmediate)
575 return FALSE;
576
577 return TRUE;
578 }
579
580 /*************************************************************************
581 * ILFindChild [SHELL32.24]
582 *
583 * Compares elements from pidl1 and pidl2.
584 *
585 * PARAMS
586 * pidl1 [I]
587 * pidl2 [I]
588 *
589 * RETURNS
590 * pidl1 is desktop pidl2
591 * pidl1 shorter pidl2 pointer to first different element of pidl2
592 * if there was at least one equal element
593 * pidl2 shorter pidl1 0
594 * pidl2 equal pidl1 pointer to last 0x00-element of pidl2
595 *
596 * NOTES
597 * exported by ordinal.
598 */
599 LPITEMIDLIST WINAPI ILFindChild(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
600 {
601 char szData1[MAX_PATH];
602 char szData2[MAX_PATH];
603
604 LPCITEMIDLIST pidltemp1 = pidl1;
605 LPCITEMIDLIST pidltemp2 = pidl2;
606 LPCITEMIDLIST ret=NULL;
607
608 TRACE("pidl1=%p pidl2=%p\n",pidl1, pidl2);
609
610 /* explorer reads from registry directly (StreamMRU),
611 so we can only check here */
612 if ((!pcheck (pidl1)) || (!pcheck (pidl2)))
613 return FALSE;
614
615 pdump (pidl1);
616 pdump (pidl2);
617
618 if (_ILIsDesktop(pidl1))
619 {
620 ret = pidl2;
621 }
622 else
623 {
624 while (pidltemp1->mkid.cb && pidltemp2->mkid.cb)
625 {
626 _ILSimpleGetText(pidltemp1, szData1, MAX_PATH);
627 _ILSimpleGetText(pidltemp2, szData2, MAX_PATH);
628
629 if (strcasecmp(szData1,szData2))
630 break;
631
632 pidltemp1 = ILGetNext(pidltemp1);
633 pidltemp2 = ILGetNext(pidltemp2);
634 ret = pidltemp2;
635 }
636
637 if (pidltemp1->mkid.cb)
638 ret = NULL; /* elements of pidl1 left*/
639 }
640 TRACE_(shell)("--- %p\n", ret);
641 return (LPITEMIDLIST)ret; /* pidl 1 is shorter */
642 }
643
644 /*************************************************************************
645 * ILCombine [SHELL32.25]
646 *
647 * Concatenates two complex ItemIDLists.
648 *
649 * PARAMS
650 * pidl1 [I] first complex ItemIDLists
651 * pidl2 [I] complex ItemIDLists to append
652 *
653 * RETURNS
654 * if both pidl's == NULL NULL
655 * if pidl1 == NULL cloned pidl2
656 * if pidl2 == NULL cloned pidl1
657 * otherwise new pidl with pidl2 appended to pidl1
658 *
659 * NOTES
660 * exported by ordinal.
661 * Does not destroy the passed in ItemIDLists!
662 */
663 LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
664 {
665 DWORD len1,len2;
666 LPITEMIDLIST pidlNew;
667
668 TRACE("pidl=%p pidl=%p\n",pidl1,pidl2);
669
670 if (!pidl1 && !pidl2) return NULL;
671
672 pdump (pidl1);
673 pdump (pidl2);
674
675 if (!pidl1)
676 {
677 pidlNew = ILClone(pidl2);
678 return pidlNew;
679 }
680
681 if (!pidl2)
682 {
683 pidlNew = ILClone(pidl1);
684 return pidlNew;
685 }
686
687 len1 = ILGetSize(pidl1)-2;
688 len2 = ILGetSize(pidl2);
689 pidlNew = SHAlloc(len1+len2);
690
691 if (pidlNew)
692 {
693 memcpy(pidlNew,pidl1,len1);
694 memcpy(((BYTE *)pidlNew)+len1,pidl2,len2);
695 }
696
697 /* TRACE(pidl,"--new pidl=%p\n",pidlNew);*/
698 return pidlNew;
699 }
700
701 /*************************************************************************
702 * SHGetRealIDL [SHELL32.98]
703 *
704 * NOTES
705 */
706 HRESULT WINAPI SHGetRealIDL(LPSHELLFOLDER lpsf, LPCITEMIDLIST pidlSimple, LPITEMIDLIST *pidlReal)
707 {
708 IDataObject* pDataObj;
709 HRESULT hr;
710
711 hr = IShellFolder_GetUIObjectOf(lpsf, 0, 1, &pidlSimple,
712 &IID_IDataObject, 0, (LPVOID*)&pDataObj);
713 if (SUCCEEDED(hr))
714 {
715 STGMEDIUM medium;
716 FORMATETC fmt;
717
718 fmt.cfFormat = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
719 fmt.ptd = NULL;
720 fmt.dwAspect = DVASPECT_CONTENT;
721 fmt.lindex = -1;
722 fmt.tymed = TYMED_HGLOBAL;
723
724 hr = IDataObject_GetData(pDataObj, &fmt, &medium);
725
726 IDataObject_Release(pDataObj);
727
728 if (SUCCEEDED(hr))
729 {
730 /*assert(pida->cidl==1);*/
731 LPIDA pida = GlobalLock(medium.u.hGlobal);
732
733 LPCITEMIDLIST pidl_folder = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
734 LPCITEMIDLIST pidl_child = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[1]);
735
736 *pidlReal = ILCombine(pidl_folder, pidl_child);
737
738 if (!*pidlReal)
739 hr = E_OUTOFMEMORY;
740
741 GlobalUnlock(medium.u.hGlobal);
742 GlobalFree(medium.u.hGlobal);
743 }
744 }
745
746 return hr;
747 }
748
749 /*************************************************************************
750 * SHLogILFromFSIL [SHELL32.95]
751 *
752 * NOTES
753 * pild = CSIDL_DESKTOP ret = 0
754 * pild = CSIDL_DRIVES ret = 0
755 */
756 LPITEMIDLIST WINAPI SHLogILFromFSIL(LPITEMIDLIST pidl)
757 {
758 FIXME("(pidl=%p)\n",pidl);
759
760 pdump(pidl);
761
762 return 0;
763 }
764
765 /*************************************************************************
766 * ILGetSize [SHELL32.152]
767 *
768 * Gets the byte size of an ItemIDList including zero terminator
769 *
770 * PARAMS
771 * pidl [I] ItemIDList
772 *
773 * RETURNS
774 * size of pidl in bytes
775 *
776 * NOTES
777 * exported by ordinal
778 */
779 UINT WINAPI ILGetSize(LPCITEMIDLIST pidl)
780 {
781 LPCSHITEMID si;
782 UINT len=0;
783
784 if (pidl)
785 {
786 si = &(pidl->mkid);
787
788 while (si->cb)
789 {
790 len += si->cb;
791 si = (LPCSHITEMID)(((const BYTE*)si)+si->cb);
792 }
793 len += 2;
794 }
795 TRACE("pidl=%p size=%u\n",pidl, len);
796 return len;
797 }
798
799 /*************************************************************************
800 * ILGetNext [SHELL32.153]
801 *
802 * Gets the next ItemID of an ItemIDList
803 *
804 * PARAMS
805 * pidl [I] ItemIDList
806 *
807 * RETURNS
808 * null -> null
809 * desktop -> null
810 * simple pidl -> pointer to 0x0000 element
811 *
812 * NOTES
813 * exported by ordinal.
814 */
815 LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
816 {
817 WORD len;
818
819 TRACE("%p\n", pidl);
820
821 if (pidl)
822 {
823 len = pidl->mkid.cb;
824 if (len)
825 {
826 pidl = (LPCITEMIDLIST) (((const BYTE*)pidl)+len);
827 TRACE("-- %p\n", pidl);
828 return (LPITEMIDLIST)pidl;
829 }
830 }
831 return NULL;
832 }
833
834 /*************************************************************************
835 * ILAppendID [SHELL32.154]
836 *
837 * Adds the single ItemID item to the ItemIDList indicated by pidl.
838 * If bEnd is FALSE, inserts the item in the front of the list,
839 * otherwise it adds the item to the end. (???)
840 *
841 * PARAMS
842 * pidl [I] ItemIDList to extend
843 * item [I] ItemID to prepend/append
844 * bEnd [I] Indicates if the item should be appended
845 *
846 * NOTES
847 * Destroys the passed in idlist! (???)
848 */
849 LPITEMIDLIST WINAPI ILAppendID(LPITEMIDLIST pidl, LPCSHITEMID item, BOOL bEnd)
850 {
851 LPITEMIDLIST idlRet;
852 LPCITEMIDLIST itemid = (LPCITEMIDLIST)item;
853
854 WARN("(pidl=%p,pidl=%p,%08u)semi-stub\n",pidl,item,bEnd);
855
856 pdump (pidl);
857 pdump (itemid);
858
859 if (_ILIsDesktop(pidl))
860 {
861 idlRet = ILClone(itemid);
862 SHFree (pidl);
863 return idlRet;
864 }
865
866 if (bEnd)
867 idlRet = ILCombine(pidl, itemid);
868 else
869 idlRet = ILCombine(itemid, pidl);
870
871 SHFree(pidl);
872 return idlRet;
873 }
874
875 /*************************************************************************
876 * ILFree [SHELL32.155]
877 *
878 * Frees memory (if not NULL) allocated by SHMalloc allocator
879 *
880 * PARAMS
881 * pidl [I]
882 *
883 * RETURNS
884 * Nothing
885 *
886 * NOTES
887 * exported by ordinal
888 */
889 void WINAPI ILFree(LPITEMIDLIST pidl)
890 {
891 TRACE("(pidl=%p)\n",pidl);
892 SHFree(pidl);
893 }
894
895 /*************************************************************************
896 * ILGlobalFree [SHELL32.156]
897 *
898 * Frees memory (if not NULL) allocated by Alloc allocator
899 *
900 * PARAMS
901 * pidl [I]
902 *
903 * RETURNS
904 * Nothing
905 *
906 * NOTES
907 * exported by ordinal.
908 */
909 void WINAPI ILGlobalFree( LPITEMIDLIST pidl)
910 {
911 TRACE("%p\n", pidl);
912
913 Free(pidl);
914 }
915
916 /*************************************************************************
917 * ILCreateFromPathA [SHELL32.189]
918 *
919 * Creates a complex ItemIDList from a path and returns it.
920 *
921 * PARAMS
922 * path [I]
923 *
924 * RETURNS
925 * the newly created complex ItemIDList or NULL if failed
926 *
927 * NOTES
928 * exported by ordinal.
929 */
930 LPITEMIDLIST WINAPI ILCreateFromPathA (LPCSTR path)
931 {
932 LPITEMIDLIST pidlnew = NULL;
933
934 TRACE_(shell)("%s\n", debugstr_a(path));
935
936 if (SUCCEEDED(SHILCreateFromPathA(path, &pidlnew, NULL)))
937 return pidlnew;
938 return NULL;
939 }
940
941 /*************************************************************************
942 * ILCreateFromPathW [SHELL32.190]
943 *
944 * See ILCreateFromPathA.
945 */
946 LPITEMIDLIST WINAPI ILCreateFromPathW (LPCWSTR path)
947 {
948 LPITEMIDLIST pidlnew = NULL;
949
950 TRACE_(shell)("%s\n", debugstr_w(path));
951
952 if (SUCCEEDED(SHILCreateFromPathW(path, &pidlnew, NULL)))
953 return pidlnew;
954 return NULL;
955 }
956
957 /*************************************************************************
958 * ILCreateFromPath [SHELL32.157]
959 */
960 LPITEMIDLIST WINAPI ILCreateFromPathAW (LPCVOID path)
961 {
962 if ( SHELL_OsIsUnicode())
963 return ILCreateFromPathW (path);
964 return ILCreateFromPathA (path);
965 }
966
967 /*************************************************************************
968 * _ILParsePathW [internal]
969 *
970 * Creates an ItemIDList from a path and returns it.
971 *
972 * PARAMS
973 * path [I] path to parse and convert into an ItemIDList
974 * lpFindFile [I] pointer to buffer to initialize the FileSystem
975 * Bind Data object with
976 * bBindCtx [I] indicates to create a BindContext and assign a
977 * FileSystem Bind Data object
978 * ppidl [O] the newly create ItemIDList
979 * prgfInOut [I/O] requested attributes on input and actual
980 * attributes on return
981 *
982 * RETURNS
983 * NO_ERROR on success or an OLE error code
984 *
985 * NOTES
986 * If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
987 * creates a BindContext object and assigns a FileSystem Bind Data object
988 * to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
989 * IShellFolder uses that FileSystem Bind Data object of the BindContext
990 * to pass data about the current path element to the next object. This
991 * is used to avoid having to verify the current path element on disk, so
992 * that creating an ItemIDList from a nonexistent path still can work.
993 */
994 static HRESULT _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
995 BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
996 {
997 LPSHELLFOLDER pSF = NULL;
998 LPBC pBC = NULL;
999 HRESULT ret;
1000
1001 TRACE("%s %p %d (%p)->%p (%p)->0x%x\n", debugstr_w(path), lpFindFile, bBindCtx,
1002 ppidl, ppidl ? *ppidl : NULL,
1003 prgfInOut, prgfInOut ? *prgfInOut : 0);
1004
1005 ret = SHGetDesktopFolder(&pSF);
1006 if (FAILED(ret))
1007 return ret;
1008
1009 if (lpFindFile || bBindCtx)
1010 ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
1011
1012 if (SUCCEEDED(ret))
1013 {
1014 ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
1015 }
1016
1017 if (pBC)
1018 {
1019 IBindCtx_Release(pBC);
1020 pBC = NULL;
1021 }
1022
1023 IShellFolder_Release(pSF);
1024
1025 if (FAILED(ret) && ppidl)
1026 *ppidl = NULL;
1027
1028 TRACE("%s %p 0x%x\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
1029
1030 return ret;
1031 }
1032
1033 /*************************************************************************
1034 * SHSimpleIDListFromPath [SHELL32.162]
1035 *
1036 * Creates a simple ItemIDList from a path and returns it. This function
1037 * does not fail on nonexistent paths.
1038 *
1039 * PARAMS
1040 * path [I] path to parse and convert into an ItemIDList
1041 *
1042 * RETURNS
1043 * the newly created simple ItemIDList
1044 *
1045 * NOTES
1046 * Simple in the name does not mean a relative ItemIDList but rather a
1047 * fully qualified list, where only the file name is filled in and the
1048 * directory flag for those ItemID elements this is known about, eg.
1049 * it is not the last element in the ItemIDList or the actual directory
1050 * exists on disk.
1051 * exported by ordinal.
1052 */
1053 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA(LPCSTR lpszPath)
1054 {
1055 LPITEMIDLIST pidl = NULL;
1056 LPWSTR wPath = NULL;
1057 int len;
1058
1059 TRACE("%s\n", debugstr_a(lpszPath));
1060
1061 if (lpszPath)
1062 {
1063 len = MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, NULL, 0);
1064 wPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1065 MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, wPath, len);
1066 }
1067
1068 _ILParsePathW(wPath, NULL, TRUE, &pidl, NULL);
1069
1070 HeapFree(GetProcessHeap(), 0, wPath);
1071 TRACE("%s %p\n", debugstr_a(lpszPath), pidl);
1072 return pidl;
1073 }
1074
1075 LPITEMIDLIST WINAPI SHSimpleIDListFromPathW(LPCWSTR lpszPath)
1076 {
1077 LPITEMIDLIST pidl = NULL;
1078
1079 TRACE("%s\n", debugstr_w(lpszPath));
1080
1081 _ILParsePathW(lpszPath, NULL, TRUE, &pidl, NULL);
1082 TRACE("%s %p\n", debugstr_w(lpszPath), pidl);
1083 return pidl;
1084 }
1085
1086 LPITEMIDLIST WINAPI SHSimpleIDListFromPathAW(LPCVOID lpszPath)
1087 {
1088 if ( SHELL_OsIsUnicode())
1089 return SHSimpleIDListFromPathW (lpszPath);
1090 return SHSimpleIDListFromPathA (lpszPath);
1091 }
1092
1093 /*************************************************************************
1094 * SHGetDataFromIDListA [SHELL32.247]
1095 *
1096 * NOTES
1097 * the pidl can be a simple one. since we can't get the path out of the pidl
1098 * we have to take all data from the pidl
1099 */
1100 HRESULT WINAPI SHGetDataFromIDListA(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1101 int nFormat, LPVOID dest, int len)
1102 {
1103 LPSTR filename, shortname;
1104 WIN32_FIND_DATAA * pfd;
1105
1106 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1107
1108 pdump(pidl);
1109 if (!psf || !dest)
1110 return E_INVALIDARG;
1111
1112 switch (nFormat)
1113 {
1114 case SHGDFIL_FINDDATA:
1115 pfd = dest;
1116
1117 if (_ILIsDrive(pidl) || _ILIsSpecialFolder(pidl))
1118 return E_INVALIDARG;
1119
1120 if (len < sizeof(WIN32_FIND_DATAA))
1121 return E_INVALIDARG;
1122
1123 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAA));
1124 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1125 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1126 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1127
1128 filename = _ILGetTextPointer(pidl);
1129 shortname = _ILGetSTextPointer(pidl);
1130
1131 if (filename)
1132 lstrcpynA(pfd->cFileName, filename, sizeof(pfd->cFileName));
1133 else
1134 pfd->cFileName[0] = '\0';
1135
1136 if (shortname)
1137 lstrcpynA(pfd->cAlternateFileName, shortname, sizeof(pfd->cAlternateFileName));
1138 else
1139 pfd->cAlternateFileName[0] = '\0';
1140 return S_OK;
1141
1142 case SHGDFIL_NETRESOURCE:
1143 case SHGDFIL_DESCRIPTIONID:
1144 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1145 break;
1146
1147 default:
1148 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1149 }
1150
1151 return E_INVALIDARG;
1152 }
1153
1154 /*************************************************************************
1155 * SHGetDataFromIDListW [SHELL32.248]
1156 *
1157 */
1158 HRESULT WINAPI SHGetDataFromIDListW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl,
1159 int nFormat, LPVOID dest, int len)
1160 {
1161 LPSTR filename, shortname;
1162 WIN32_FIND_DATAW * pfd = dest;
1163
1164 TRACE_(shell)("sf=%p pidl=%p 0x%04x %p 0x%04x stub\n",psf,pidl,nFormat,dest,len);
1165
1166 pdump(pidl);
1167
1168 if (!psf || !dest)
1169 return E_INVALIDARG;
1170
1171 switch (nFormat)
1172 {
1173 case SHGDFIL_FINDDATA:
1174 pfd = dest;
1175
1176 if (_ILIsDrive(pidl))
1177 return E_INVALIDARG;
1178
1179 if (len < sizeof(WIN32_FIND_DATAW))
1180 return E_INVALIDARG;
1181
1182 ZeroMemory(pfd, sizeof (WIN32_FIND_DATAW));
1183 _ILGetFileDateTime( pidl, &(pfd->ftLastWriteTime));
1184 pfd->dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
1185 pfd->nFileSizeLow = _ILGetFileSize ( pidl, NULL, 0);
1186
1187 filename = _ILGetTextPointer(pidl);
1188 shortname = _ILGetSTextPointer(pidl);
1189
1190 if (!filename)
1191 pfd->cFileName[0] = '\0';
1192 else if (!MultiByteToWideChar(CP_ACP, 0, filename, -1, pfd->cFileName, MAX_PATH))
1193 pfd->cFileName[MAX_PATH-1] = 0;
1194
1195 if (!shortname)
1196 pfd->cAlternateFileName[0] = '\0';
1197 else if (!MultiByteToWideChar(CP_ACP, 0, shortname, -1, pfd->cAlternateFileName, 14))
1198 pfd->cAlternateFileName[13] = 0;
1199 return S_OK;
1200
1201 case SHGDFIL_NETRESOURCE:
1202 case SHGDFIL_DESCRIPTIONID:
1203 FIXME_(shell)("SHGDFIL %i stub\n", nFormat);
1204 break;
1205
1206 default:
1207 ERR_(shell)("Unknown SHGDFIL %i, please report\n", nFormat);
1208 }
1209
1210 return E_INVALIDARG;
1211 }
1212
1213 /*************************************************************************
1214 * SHGetPathFromIDListA [SHELL32.@][NT 4.0: SHELL32.220]
1215 *
1216 * PARAMETERS
1217 * pidl, [IN] pidl
1218 * pszPath [OUT] path
1219 *
1220 * RETURNS
1221 * path from a passed PIDL.
1222 *
1223 * NOTES
1224 * NULL returns FALSE
1225 * desktop pidl gives path to desktop directory back
1226 * special pidls returning FALSE
1227 */
1228 BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
1229 {
1230 WCHAR wszPath[MAX_PATH];
1231 BOOL bSuccess;
1232
1233 bSuccess = SHGetPathFromIDListW(pidl, wszPath);
1234 WideCharToMultiByte(CP_ACP, 0, wszPath, -1, pszPath, MAX_PATH, NULL, NULL);
1235
1236 return bSuccess;
1237 }
1238
1239 /*************************************************************************
1240 * SHGetPathFromIDListW [SHELL32.@]
1241 *
1242 * See SHGetPathFromIDListA.
1243 */
1244 BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
1245 {
1246 HRESULT hr;
1247 LPCITEMIDLIST pidlLast;
1248 LPSHELLFOLDER psfFolder;
1249 DWORD dwAttributes;
1250 STRRET strret;
1251
1252 TRACE_(shell)("(pidl=%p,%p)\n", pidl, pszPath);
1253 pdump(pidl);
1254
1255 *pszPath = '\0';
1256 if (!pidl)
1257 return FALSE;
1258
1259 hr = SHBindToParent(pidl, &IID_IShellFolder, (VOID**)&psfFolder, &pidlLast);
1260 if (FAILED(hr))
1261 {
1262 ERR("SHBindToParent failed: %x\n", hr);
1263 return FALSE;
1264 }
1265
1266 dwAttributes = SFGAO_FILESYSTEM;
1267 hr = IShellFolder_GetAttributesOf(psfFolder, 1, &pidlLast, &dwAttributes);
1268 if (FAILED(hr) || !(dwAttributes & SFGAO_FILESYSTEM)) {
1269 WARN("Wrong dwAttributes or GetAttributesOf failed: %x\n", hr);
1270 IShellFolder_Release(psfFolder);
1271 return FALSE;
1272 }
1273
1274 hr = IShellFolder_GetDisplayNameOf(psfFolder, pidlLast, SHGDN_FORPARSING, &strret);
1275 IShellFolder_Release(psfFolder);
1276 if (FAILED(hr)) return FALSE;
1277
1278 hr = StrRetToBufW(&strret, pidlLast, pszPath, MAX_PATH);
1279
1280 TRACE_(shell)("-- %s, 0x%08x\n",debugstr_w(pszPath), hr);
1281 return SUCCEEDED(hr);
1282 }
1283
1284 /*************************************************************************
1285 * SHBindToParent [shell version 5.0]
1286 */
1287 HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
1288 {
1289 IShellFolder * psfDesktop;
1290 HRESULT hr=E_FAIL;
1291
1292 TRACE_(shell)("pidl=%p\n", pidl);
1293 pdump(pidl);
1294
1295 if (!pidl || !ppv)
1296 return E_INVALIDARG;
1297
1298 *ppv = NULL;
1299 if (ppidlLast)
1300 *ppidlLast = NULL;
1301
1302 hr = SHGetDesktopFolder(&psfDesktop);
1303 if (FAILED(hr))
1304 return hr;
1305
1306 if (_ILIsPidlSimple(pidl))
1307 {
1308 /* we are on desktop level */
1309 hr = IShellFolder_QueryInterface(psfDesktop, riid, ppv);
1310 }
1311 else
1312 {
1313 LPITEMIDLIST pidlParent = ILClone(pidl);
1314 ILRemoveLastID(pidlParent);
1315 hr = IShellFolder_BindToObject(psfDesktop, pidlParent, NULL, riid, ppv);
1316 SHFree (pidlParent);
1317 }
1318
1319 IShellFolder_Release(psfDesktop);
1320
1321 if (SUCCEEDED(hr) && ppidlLast)
1322 *ppidlLast = ILFindLastID(pidl);
1323
1324 TRACE_(shell)("-- psf=%p pidl=%p ret=0x%08x\n", *ppv, (ppidlLast)?*ppidlLast:NULL, hr);
1325 return hr;
1326 }
1327
1328 /*************************************************************************
1329 * SHParseDisplayName [shell version 6.0]
1330 */
1331 HRESULT WINAPI SHParseDisplayName(LPCWSTR pszName, IBindCtx *pbc,
1332 LPITEMIDLIST *ppidl, SFGAOF sfgaoIn, SFGAOF *psfgaoOut)
1333 {
1334 IShellFolder *psfDesktop;
1335 HRESULT hr=E_FAIL;
1336 ULONG dwAttr=sfgaoIn;
1337
1338 if(!ppidl)
1339 return E_INVALIDARG;
1340
1341 if (!pszName || !psfgaoOut)
1342 {
1343 *ppidl = NULL;
1344 return E_INVALIDARG;
1345 }
1346
1347 hr = SHGetDesktopFolder(&psfDesktop);
1348 if (FAILED(hr))
1349 {
1350 *ppidl = NULL;
1351 return hr;
1352 }
1353
1354 hr = IShellFolder_ParseDisplayName(psfDesktop, (HWND)NULL, pbc, (LPOLESTR)pszName, (ULONG *)NULL, ppidl, &dwAttr);
1355
1356 IShellFolder_Release(psfDesktop);
1357
1358 if (SUCCEEDED(hr))
1359 *psfgaoOut = dwAttr;
1360 else
1361 *ppidl = NULL;
1362
1363 return hr;
1364 }
1365
1366 #ifndef __REACTOS__
1367
1368 /*************************************************************************
1369 * SHGetNameFromIDList [SHELL32.@]
1370 */
1371 HRESULT WINAPI SHGetNameFromIDList(PCIDLIST_ABSOLUTE pidl, SIGDN sigdnName, PWSTR *ppszName)
1372 {
1373 IShellFolder *psfparent;
1374 LPCITEMIDLIST child_pidl;
1375 STRRET disp_name;
1376 HRESULT ret;
1377
1378 TRACE("%p 0x%08x %p\n", pidl, sigdnName, ppszName);
1379
1380 *ppszName = NULL;
1381 ret = SHBindToParent(pidl, &IID_IShellFolder, (void**)&psfparent, &child_pidl);
1382 if(SUCCEEDED(ret))
1383 {
1384 switch(sigdnName)
1385 {
1386 /* sigdnName & 0xffff */
1387 case SIGDN_NORMALDISPLAY: /* SHGDN_NORMAL */
1388 case SIGDN_PARENTRELATIVEPARSING: /* SHGDN_INFOLDER | SHGDN_FORPARSING */
1389 case SIGDN_PARENTRELATIVEEDITING: /* SHGDN_INFOLDER | SHGDN_FOREDITING */
1390 case SIGDN_DESKTOPABSOLUTEPARSING: /* SHGDN_FORPARSING */
1391 case SIGDN_DESKTOPABSOLUTEEDITING: /* SHGDN_FOREDITING | SHGDN_FORADDRESSBAR*/
1392 case SIGDN_PARENTRELATIVEFORADDRESSBAR: /* SIGDN_INFOLDER | SHGDN_FORADDRESSBAR */
1393 case SIGDN_PARENTRELATIVE: /* SIGDN_INFOLDER */
1394
1395 disp_name.uType = STRRET_WSTR;
1396 ret = IShellFolder_GetDisplayNameOf(psfparent, child_pidl,
1397 sigdnName & 0xffff,
1398 &disp_name);
1399 if(SUCCEEDED(ret))
1400 ret = StrRetToStrW(&disp_name, pidl, ppszName);
1401
1402 break;
1403
1404 case SIGDN_FILESYSPATH:
1405 *ppszName = CoTaskMemAlloc(sizeof(WCHAR)*MAX_PATH);
1406 if(SHGetPathFromIDListW(pidl, *ppszName))
1407 {
1408 TRACE("Got string %s\n", debugstr_w(*ppszName));
1409 ret = S_OK;
1410 }
1411 else
1412 {
1413 CoTaskMemFree(*ppszName);
1414 ret = E_INVALIDARG;
1415 }
1416 break;
1417
1418 case SIGDN_URL:
1419 default:
1420 FIXME("Unsupported SIGDN %x\n", sigdnName);
1421 ret = E_FAIL;
1422 }
1423
1424 IShellFolder_Release(psfparent);
1425 }
1426 return ret;
1427 }
1428
1429 /*************************************************************************
1430 * SHGetIDListFromObject [SHELL32.@]
1431 */
1432 HRESULT WINAPI SHGetIDListFromObject(IUnknown *punk, PIDLIST_ABSOLUTE *ppidl)
1433 {
1434 IPersistIDList *ppersidl;
1435 IPersistFolder2 *ppf2;
1436 IDataObject *pdo;
1437 IFolderView *pfv;
1438 HRESULT ret;
1439
1440 if(!punk)
1441 return E_NOINTERFACE;
1442
1443 *ppidl = NULL;
1444
1445 /* Try IPersistIDList */
1446 ret = IUnknown_QueryInterface(punk, &IID_IPersistIDList, (void**)&ppersidl);
1447 if(SUCCEEDED(ret))
1448 {
1449 TRACE("IPersistIDList (%p)\n", ppersidl);
1450 ret = IPersistIDList_GetIDList(ppersidl, ppidl);
1451 IPersistIDList_Release(ppersidl);
1452 if(SUCCEEDED(ret))
1453 return ret;
1454 }
1455
1456 /* Try IPersistFolder2 */
1457 ret = IUnknown_QueryInterface(punk, &IID_IPersistFolder2, (void**)&ppf2);
1458 if(SUCCEEDED(ret))
1459 {
1460 TRACE("IPersistFolder2 (%p)\n", ppf2);
1461 ret = IPersistFolder2_GetCurFolder(ppf2, ppidl);
1462 IPersistFolder2_Release(ppf2);
1463 if(SUCCEEDED(ret))
1464 return ret;
1465 }
1466
1467 /* Try IDataObject */
1468 ret = IUnknown_QueryInterface(punk, &IID_IDataObject, (void**)&pdo);
1469 if(SUCCEEDED(ret))
1470 {
1471 IShellItem *psi;
1472 TRACE("IDataObject (%p)\n", pdo);
1473 ret = SHGetItemFromDataObject(pdo, DOGIF_ONLY_IF_ONE,
1474 &IID_IShellItem, (void**)&psi);
1475 if(SUCCEEDED(ret))
1476 {
1477 ret = SHGetIDListFromObject((IUnknown*)psi, ppidl);
1478 IShellItem_Release(psi);
1479 }
1480 IDataObject_Release(pdo);
1481
1482 if(SUCCEEDED(ret))
1483 return ret;
1484 }
1485
1486 /* Try IFolderView */
1487 ret = IUnknown_QueryInterface(punk, &IID_IFolderView, (void**)&pfv);
1488 if(SUCCEEDED(ret))
1489 {
1490 IShellFolder *psf;
1491 TRACE("IFolderView (%p)\n", pfv);
1492 ret = IFolderView_GetFolder(pfv, &IID_IShellFolder, (void**)&psf);
1493 if(SUCCEEDED(ret))
1494 {
1495 /* We might be able to get IPersistFolder2 from a shellfolder. */
1496 ret = SHGetIDListFromObject((IUnknown*)psf, ppidl);
1497 }
1498 IFolderView_Release(pfv);
1499 return ret;
1500 }
1501
1502 return ret;
1503 }
1504
1505 #endif /* !__REACTOS__ */
1506
1507 /**************************************************************************
1508 *
1509 * internal functions
1510 *
1511 * ### 1. section creating pidls ###
1512 *
1513 *************************************************************************
1514 */
1515
1516 /* Basic PIDL constructor. Allocates size + 5 bytes, where:
1517 * - two bytes are SHITEMID.cb
1518 * - one byte is PIDLDATA.type
1519 * - two bytes are the NULL PIDL terminator
1520 * Sets type of the returned PIDL to type.
1521 */
1522 static LPITEMIDLIST _ILAlloc(PIDLTYPE type, unsigned int size)
1523 {
1524 LPITEMIDLIST pidlOut = NULL;
1525
1526 pidlOut = SHAlloc(size + 5);
1527 if(pidlOut)
1528 {
1529 LPPIDLDATA pData;
1530 LPITEMIDLIST pidlNext;
1531
1532 ZeroMemory(pidlOut, size + 5);
1533 pidlOut->mkid.cb = size + 3;
1534
1535 pData = _ILGetDataPointer(pidlOut);
1536 if (pData)
1537 pData->type = type;
1538
1539 pidlNext = ILGetNext(pidlOut);
1540 if (pidlNext)
1541 pidlNext->mkid.cb = 0x00;
1542 TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
1543 }
1544
1545 return pidlOut;
1546 }
1547
1548 LPITEMIDLIST _ILCreateDesktop(void)
1549 {
1550 LPITEMIDLIST ret;
1551
1552 TRACE("()\n");
1553 ret = SHAlloc(2);
1554 if (ret)
1555 ret->mkid.cb = 0;
1556 return ret;
1557 }
1558
1559 LPITEMIDLIST _ILCreateMyComputer(void)
1560 {
1561 TRACE("()\n");
1562 return _ILCreateGuid(PT_GUID, &CLSID_MyComputer);
1563 }
1564
1565 LPITEMIDLIST _ILCreateMyDocuments(void)
1566 {
1567 TRACE("()\n");
1568 return _ILCreateGuid(PT_GUID, &CLSID_MyDocuments);
1569 }
1570
1571 LPITEMIDLIST _ILCreateIExplore(void)
1572 {
1573 TRACE("()\n");
1574 return _ILCreateGuid(PT_GUID, &CLSID_Internet);
1575 }
1576
1577 LPITEMIDLIST _ILCreateControlPanel(void)
1578 {
1579 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1580
1581 TRACE("()\n");
1582 if (parent)
1583 {
1584 LPITEMIDLIST cpl = _ILCreateGuid(PT_SHELLEXT, &CLSID_ControlPanel);
1585
1586 if (cpl)
1587 {
1588 ret = ILCombine(parent, cpl);
1589 SHFree(cpl);
1590 }
1591 SHFree(parent);
1592 }
1593 return ret;
1594 }
1595
1596 LPITEMIDLIST _ILCreatePrinters(void)
1597 {
1598 LPITEMIDLIST parent = _ILCreateGuid(PT_GUID, &CLSID_MyComputer), ret = NULL;
1599
1600 TRACE("()\n");
1601 if (parent)
1602 {
1603 LPITEMIDLIST printers = _ILCreateGuid(PT_YAGUID, &CLSID_Printers);
1604
1605 if (printers)
1606 {
1607 ret = ILCombine(parent, printers);
1608 SHFree(printers);
1609 }
1610 SHFree(parent);
1611 }
1612 return ret;
1613 }
1614
1615 LPITEMIDLIST _ILCreateNetwork(void)
1616 {
1617 TRACE("()\n");
1618 return _ILCreateGuid(PT_GUID, &CLSID_NetworkPlaces);
1619 }
1620
1621 LPITEMIDLIST _ILCreateBitBucket(void)
1622 {
1623 TRACE("()\n");
1624 return _ILCreateGuid(PT_GUID, &CLSID_RecycleBin);
1625 }
1626
1627 LPITEMIDLIST _ILCreateAdminTools(void)
1628 {
1629 TRACE("()\n");
1630 return _ILCreateGuid(PT_GUID, &CLSID_AdminFolderShortcut); //FIXME
1631 }
1632
1633 LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, REFIID guid)
1634 {
1635 LPITEMIDLIST pidlOut;
1636
1637 if (type == PT_SHELLEXT || type == PT_GUID || type == PT_YAGUID)
1638 {
1639 pidlOut = _ILAlloc(type, sizeof(GUIDStruct));
1640 if (pidlOut)
1641 {
1642 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1643
1644 pData->u.guid.guid = *guid;
1645 TRACE("-- create GUID-pidl %s\n",
1646 debugstr_guid(&(pData->u.guid.guid)));
1647 }
1648 }
1649 else
1650 {
1651 WARN("%d: invalid type for GUID\n", type);
1652 pidlOut = NULL;
1653 }
1654 return pidlOut;
1655 }
1656
1657 LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID)
1658 {
1659 IID iid;
1660
1661 if (FAILED(SHCLSIDFromStringA(szGUID, &iid)))
1662 {
1663 ERR("%s is not a GUID\n", szGUID);
1664 return NULL;
1665 }
1666 return _ILCreateGuid(PT_GUID, &iid);
1667 }
1668
1669 LPITEMIDLIST _ILCreateGuidFromStrW(LPCWSTR szGUID)
1670 {
1671 IID iid;
1672
1673 if (FAILED(SHCLSIDFromStringW(szGUID, &iid)))
1674 {
1675 ERR("%s is not a GUID\n", debugstr_w(szGUID));
1676 return NULL;
1677 }
1678 return _ILCreateGuid(PT_GUID, &iid);
1679 }
1680
1681 LPITEMIDLIST _ILCreateFromFindDataW( const WIN32_FIND_DATAW *wfd )
1682 {
1683 char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
1684 DWORD len, len1, wlen, alen;
1685 LPITEMIDLIST pidl;
1686 PIDLTYPE type;
1687
1688 if (!wfd)
1689 return NULL;
1690
1691 TRACE("(%s, %s)\n",debugstr_w(wfd->cAlternateFileName), debugstr_w(wfd->cFileName));
1692
1693 /* prepare buffer with both names */
1694 len = WideCharToMultiByte(CP_ACP,0,wfd->cFileName,-1,buff,MAX_PATH,NULL,NULL);
1695 len1 = WideCharToMultiByte(CP_ACP,0,wfd->cAlternateFileName,-1, buff+len, sizeof(buff)-len, NULL, NULL);
1696 alen = len + len1;
1697
1698 type = (wfd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER : PT_VALUE;
1699
1700 wlen = lstrlenW(wfd->cFileName) + 1;
1701 pidl = _ILAlloc(type, FIELD_OFFSET(FileStruct, szNames[alen + (alen & 1)]) +
1702 FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD));
1703 if (pidl)
1704 {
1705 LPPIDLDATA pData = _ILGetDataPointer(pidl);
1706 FileStruct *fs = &pData->u.file;
1707 FileStructW *fsw;
1708 WORD *pOffsetW;
1709
1710 FileTimeToDosDateTime( &wfd->ftLastWriteTime, &fs->uFileDate, &fs->uFileTime);
1711 fs->dwFileSize = wfd->nFileSizeLow;
1712 fs->uFileAttribs = wfd->dwFileAttributes;
1713 memcpy(fs->szNames, buff, alen);
1714
1715 fsw = (FileStructW*)(pData->u.file.szNames + alen + (alen & 0x1));
1716 fsw->cbLen = FIELD_OFFSET(FileStructW, wszName[wlen]) + sizeof(WORD);
1717 FileTimeToDosDateTime( &wfd->ftCreationTime, &fsw->uCreationDate, &fsw->uCreationTime);
1718 FileTimeToDosDateTime( &wfd->ftLastAccessTime, &fsw->uLastAccessDate, &fsw->uLastAccessTime);
1719 memcpy(fsw->wszName, wfd->cFileName, wlen * sizeof(WCHAR));
1720
1721 pOffsetW = (WORD*)((LPBYTE)pidl + pidl->mkid.cb - sizeof(WORD));
1722 *pOffsetW = (LPBYTE)fsw - (LPBYTE)pidl;
1723 TRACE("-- Set Value: %s\n",debugstr_w(fsw->wszName));
1724 }
1725 return pidl;
1726
1727 }
1728
1729 HRESULT _ILCreateFromPathW(LPCWSTR szPath, LPITEMIDLIST* ppidl)
1730 {
1731 HANDLE hFile;
1732 WIN32_FIND_DATAW stffile;
1733
1734 if (!ppidl)
1735 return E_INVALIDARG;
1736
1737 hFile = FindFirstFileW(szPath, &stffile);
1738 if (hFile == INVALID_HANDLE_VALUE)
1739 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
1740
1741 FindClose(hFile);
1742
1743 *ppidl = _ILCreateFromFindDataW(&stffile);
1744
1745 return *ppidl ? S_OK : E_OUTOFMEMORY;
1746 }
1747
1748 LPITEMIDLIST _ILCreateDrive(LPCWSTR lpszNew)
1749 {
1750 LPITEMIDLIST pidlOut;
1751
1752 TRACE("(%s)\n",debugstr_w(lpszNew));
1753
1754 pidlOut = _ILAlloc(PT_DRIVE, sizeof(DriveStruct));
1755 if (pidlOut)
1756 {
1757 LPSTR pszDest;
1758
1759 pszDest = _ILGetTextPointer(pidlOut);
1760 if (pszDest)
1761 {
1762 strcpy(pszDest, "x:\\");
1763 pszDest[0]=toupperW(lpszNew[0]);
1764 TRACE("-- create Drive: %s\n", debugstr_a(pszDest));
1765 }
1766 }
1767 return pidlOut;
1768 }
1769
1770 LPITEMIDLIST _ILCreateEntireNetwork(void)
1771 {
1772 LPITEMIDLIST pidlOut;
1773
1774 TRACE("\n");
1775
1776 pidlOut = _ILAlloc(PT_NETWORK, FIELD_OFFSET(PIDLDATA, u.network.szNames[sizeof("Entire Network")]));
1777 if (pidlOut)
1778 {
1779 LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
1780
1781 pData->u.network.dummy = 0;
1782 strcpy(pData->u.network.szNames, "Entire Network");
1783 }
1784 return pidlOut;
1785 }
1786
1787 /**************************************************************************
1788 * _ILGetDrive()
1789 *
1790 * Gets the text for the drive eg. 'c:\'
1791 *
1792 * RETURNS
1793 * strlen (lpszText)
1794 */
1795 DWORD _ILGetDrive(LPCITEMIDLIST pidl,LPSTR pOut, UINT uSize)
1796 {
1797 TRACE("(%p,%p,%u)\n",pidl,pOut,uSize);
1798
1799 if(_ILIsMyComputer(pidl))
1800 pidl = ILGetNext(pidl);
1801
1802 if (pidl && _ILIsDrive(pidl))
1803 return _ILSimpleGetText(pidl, pOut, uSize);
1804
1805 return 0;
1806 }
1807
1808 /**************************************************************************
1809 *
1810 * ### 2. section testing pidls ###
1811 *
1812 **************************************************************************
1813 * _ILIsUnicode()
1814 * _ILIsDesktop()
1815 * _ILIsMyComputer()
1816 * _ILIsSpecialFolder()
1817 * _ILIsDrive()
1818 * _ILIsFolder()
1819 * _ILIsValue()
1820 * _ILIsPidlSimple()
1821 */
1822 BOOL _ILIsUnicode(LPCITEMIDLIST pidl)
1823 {
1824 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1825
1826 TRACE("(%p)\n",pidl);
1827
1828 return (pidl && lpPData && PT_VALUEW == lpPData->type);
1829 }
1830
1831 BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
1832 {
1833 TRACE("(%p)\n",pidl);
1834
1835 return !pidl || !pidl->mkid.cb;
1836 }
1837
1838 BOOL _ILIsMyDocuments(LPCITEMIDLIST pidl)
1839 {
1840 IID *iid = _ILGetGUIDPointer(pidl);
1841
1842 TRACE("(%p)\n", pidl);
1843
1844 if (iid)
1845 return IsEqualIID(iid, &CLSID_MyDocuments);
1846 return FALSE;
1847 }
1848
1849 BOOL _ILIsNetHood(LPCITEMIDLIST pidl)
1850 {
1851 IID *iid = _ILGetGUIDPointer(pidl);
1852
1853 TRACE("(%p)\n", pidl);
1854
1855 if (iid)
1856 return IsEqualIID(iid, &CLSID_NetworkPlaces);
1857 return FALSE;
1858 }
1859
1860 BOOL _ILIsMyComputer(LPCITEMIDLIST pidl)
1861 {
1862 REFIID iid = _ILGetGUIDPointer(pidl);
1863
1864 TRACE("(%p)\n",pidl);
1865
1866 if (iid)
1867 return IsEqualIID(iid, &CLSID_MyComputer);
1868 return FALSE;
1869 }
1870
1871 BOOL _ILIsBitBucket(LPCITEMIDLIST pidl)
1872 {
1873 IID *iid = _ILGetGUIDPointer(pidl);
1874
1875 TRACE("(%p)\n", pidl);
1876
1877 if (iid)
1878 return IsEqualIID(iid, &CLSID_RecycleBin);
1879 return FALSE;
1880 }
1881
1882 BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
1883 {
1884 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1885
1886 TRACE("(%p)\n",pidl);
1887
1888 return (pidl && ( (lpPData && (PT_GUID== lpPData->type || PT_SHELLEXT== lpPData->type || PT_YAGUID == lpPData->type)) ||
1889 (pidl && pidl->mkid.cb == 0x00)
1890 ));
1891 }
1892
1893 BOOL _ILIsDrive(LPCITEMIDLIST pidl)
1894 {
1895 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1896
1897 TRACE("(%p)\n",pidl);
1898
1899 return (pidl && lpPData && (PT_DRIVE == lpPData->type ||
1900 PT_DRIVE1 == lpPData->type ||
1901 PT_DRIVE2 == lpPData->type ||
1902 PT_DRIVE3 == lpPData->type));
1903 }
1904
1905 BOOL _ILIsFolder(LPCITEMIDLIST pidl)
1906 {
1907 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1908
1909 TRACE("(%p)\n",pidl);
1910
1911 return (pidl && lpPData && (PT_FOLDER == lpPData->type || PT_FOLDER1 == lpPData->type));
1912 }
1913
1914 BOOL _ILIsValue(LPCITEMIDLIST pidl)
1915 {
1916 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1917
1918 TRACE("(%p)\n",pidl);
1919
1920 return (pidl && lpPData && PT_VALUE == lpPData->type);
1921 }
1922
1923 BOOL _ILIsCPanelStruct(LPCITEMIDLIST pidl)
1924 {
1925 LPPIDLDATA lpPData = _ILGetDataPointer(pidl);
1926
1927 TRACE("(%p)\n",pidl);
1928
1929 return (pidl && lpPData && (lpPData->type == 0));
1930 }
1931
1932 /**************************************************************************
1933 * _ILIsPidlSimple
1934 */
1935 BOOL _ILIsPidlSimple(LPCITEMIDLIST pidl)
1936 {
1937 BOOL ret = TRUE;
1938
1939 if(! _ILIsDesktop(pidl)) /* pidl=NULL or mkid.cb=0 */
1940 {
1941 WORD len = pidl->mkid.cb;
1942 LPCITEMIDLIST pidlnext = (LPCITEMIDLIST) (((const BYTE*)pidl) + len );
1943
1944 if (pidlnext->mkid.cb)
1945 ret = FALSE;
1946 }
1947
1948 TRACE("%s\n", ret ? "Yes" : "No");
1949 return ret;
1950 }
1951
1952 /**************************************************************************
1953 *
1954 * ### 3. section getting values from pidls ###
1955 */
1956
1957 /**************************************************************************
1958 * _ILSimpleGetText
1959 *
1960 * gets the text for the first item in the pidl (eg. simple pidl)
1961 *
1962 * returns the length of the string
1963 */
1964 DWORD _ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
1965 {
1966 DWORD dwReturn=0;
1967 LPSTR szSrc;
1968 LPWSTR szSrcW;
1969 GUID const * riid;
1970 char szTemp[MAX_PATH];
1971
1972 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
1973
1974 if (!pidl)
1975 return 0;
1976
1977 if (szOut)
1978 *szOut = 0;
1979
1980 if (_ILIsDesktop(pidl))
1981 {
1982 /* desktop */
1983 if (HCR_GetClassNameA(&CLSID_ShellDesktop, szTemp, MAX_PATH))
1984 {
1985 if (szOut)
1986 lstrcpynA(szOut, szTemp, uOutSize);
1987
1988 dwReturn = strlen (szTemp);
1989 }
1990 }
1991 else if (( szSrc = _ILGetTextPointer(pidl) ))
1992 {
1993 /* filesystem */
1994 if (szOut)
1995 lstrcpynA(szOut, szSrc, uOutSize);
1996
1997 dwReturn = strlen(szSrc);
1998 }
1999 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
2000 {
2001 /* unicode filesystem */
2002 WideCharToMultiByte(CP_ACP,0,szSrcW, -1, szTemp, MAX_PATH, NULL, NULL);
2003
2004 if (szOut)
2005 lstrcpynA(szOut, szTemp, uOutSize);
2006
2007 dwReturn = strlen (szTemp);
2008 }
2009 else if (( riid = _ILGetGUIDPointer(pidl) ))
2010 {
2011 /* special folder */
2012 if ( HCR_GetClassNameA(riid, szTemp, MAX_PATH) )
2013 {
2014 if (szOut)
2015 lstrcpynA(szOut, szTemp, uOutSize);
2016
2017 dwReturn = strlen (szTemp);
2018 }
2019 }
2020 else
2021 {
2022 ERR("-- no text\n");
2023 }
2024
2025 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_a(szOut),dwReturn);
2026 return dwReturn;
2027 }
2028
2029 /**************************************************************************
2030 * _ILSimpleGetTextW
2031 *
2032 * gets the text for the first item in the pidl (eg. simple pidl)
2033 *
2034 * returns the length of the string
2035 */
2036 DWORD _ILSimpleGetTextW (LPCITEMIDLIST pidl, LPWSTR szOut, UINT uOutSize)
2037 {
2038 DWORD dwReturn;
2039 FileStructW *pFileStructW = _ILGetFileStructW(pidl);
2040
2041 TRACE("(%p %p %x)\n",pidl,szOut,uOutSize);
2042
2043 if (pFileStructW) {
2044 lstrcpynW(szOut, pFileStructW->wszName, uOutSize);
2045 dwReturn = lstrlenW(pFileStructW->wszName);
2046 } else {
2047 GUID const * riid;
2048 WCHAR szTemp[MAX_PATH];
2049 LPSTR szSrc;
2050 LPWSTR szSrcW;
2051 dwReturn=0;
2052
2053 if (!pidl)
2054 return 0;
2055
2056 if (szOut)
2057 *szOut = 0;
2058
2059 if (_ILIsDesktop(pidl))
2060 {
2061 /* desktop */
2062 if (HCR_GetClassNameW(&CLSID_ShellDesktop, szTemp, MAX_PATH))
2063 {
2064 if (szOut)
2065 lstrcpynW(szOut, szTemp, uOutSize);
2066
2067 dwReturn = lstrlenW (szTemp);
2068 }
2069 }
2070 else if (( szSrcW = _ILGetTextPointerW(pidl) ))
2071 {
2072 /* unicode filesystem */
2073 if (szOut)
2074 lstrcpynW(szOut, szSrcW, uOutSize);
2075
2076 dwReturn = lstrlenW(szSrcW);
2077 }
2078 else if (( szSrc = _ILGetTextPointer(pidl) ))
2079 {
2080 /* filesystem */
2081 MultiByteToWideChar(CP_ACP, 0, szSrc, -1, szTemp, MAX_PATH);
2082
2083 if (szOut)
2084 lstrcpynW(szOut, szTemp, uOutSize);
2085
2086 dwReturn = lstrlenW (szTemp);
2087 }
2088 else if (( riid = _ILGetGUIDPointer(pidl) ))
2089 {
2090 /* special folder */
2091 if ( HCR_GetClassNameW(riid, szTemp, MAX_PATH) )
2092 {
2093 if (szOut)
2094 lstrcpynW(szOut, szTemp, uOutSize);
2095
2096 dwReturn = lstrlenW (szTemp);
2097 }
2098 }
2099 else
2100 {
2101 ERR("-- no text\n");
2102 }
2103 }
2104
2105 TRACE("-- (%p=%s 0x%08x)\n",szOut,debugstr_w(szOut),dwReturn);
2106 return dwReturn;
2107 }
2108
2109 /**************************************************************************
2110 *
2111 * ### 4. getting pointers to parts of pidls ###
2112 *
2113 **************************************************************************
2114 * _ILGetDataPointer()
2115 */
2116 LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
2117 {
2118 if(!_ILIsEmpty(pidl))
2119 return (LPPIDLDATA)pidl->mkid.abID;
2120 return NULL;
2121 }
2122
2123 /**************************************************************************
2124 * _ILGetTextPointerW()
2125 * gets a pointer to the unicode long filename string stored in the pidl
2126 */
2127 static LPWSTR _ILGetTextPointerW(LPCITEMIDLIST pidl)
2128 {
2129 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
2130
2131 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2132
2133 if (!pdata)
2134 return NULL;
2135
2136 switch (pdata->type)
2137 {
2138 case PT_GUID:
2139 case PT_SHELLEXT:
2140 case PT_YAGUID:
2141 return NULL;
2142
2143 case PT_DRIVE:
2144 case PT_DRIVE1:
2145 case PT_DRIVE2:
2146 case PT_DRIVE3:
2147 /*return (LPSTR)&(pdata->u.drive.szDriveName);*/
2148 return NULL;
2149
2150 case PT_FOLDER:
2151 case PT_FOLDER1:
2152 case PT_VALUE:
2153 case PT_IESPECIAL1:
2154 case PT_IESPECIAL2:
2155 /*return (LPSTR)&(pdata->u.file.szNames);*/
2156 return NULL;
2157
2158 case PT_WORKGRP:
2159 case PT_COMP:
2160 case PT_NETWORK:
2161 case PT_NETPROVIDER:
2162 case PT_SHARE:
2163 /*return (LPSTR)&(pdata->u.network.szNames);*/
2164 return NULL;
2165
2166 case PT_VALUEW:
2167 return (LPWSTR)pdata->u.file.szNames;
2168 }
2169 return NULL;
2170 }
2171
2172
2173 /**************************************************************************
2174 * _ILGetTextPointer()
2175 * gets a pointer to the long filename string stored in the pidl
2176 */
2177 LPSTR _ILGetTextPointer(LPCITEMIDLIST pidl)
2178 {
2179 /* TRACE(pidl,"(pidl%p)\n", pidl);*/
2180
2181 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2182
2183 if (!pdata)
2184 return NULL;
2185
2186 switch (pdata->type)
2187 {
2188 case PT_GUID:
2189 case PT_SHELLEXT:
2190 case PT_YAGUID:
2191 return NULL;
2192
2193 case PT_DRIVE:
2194 case PT_DRIVE1:
2195 case PT_DRIVE2:
2196 case PT_DRIVE3:
2197 return pdata->u.drive.szDriveName;
2198
2199 case PT_FOLDER:
2200 case PT_FOLDER1:
2201 case PT_VALUE:
2202 case PT_IESPECIAL1:
2203 case PT_IESPECIAL2:
2204 return pdata->u.file.szNames;
2205
2206 case PT_WORKGRP:
2207 case PT_COMP:
2208 case PT_NETWORK:
2209 case PT_NETPROVIDER:
2210 case PT_SHARE:
2211 return pdata->u.network.szNames;
2212
2213 #ifdef __REACTOS__ /* r54423 */
2214 case PT_CPLAPPLET:
2215 return pdata->u.cpanel.szName;
2216 #endif
2217 }
2218 return NULL;
2219 }
2220
2221 /**************************************************************************
2222 * _ILGetSTextPointer()
2223 * gets a pointer to the short filename string stored in the pidl
2224 */
2225 static LPSTR _ILGetSTextPointer(LPCITEMIDLIST pidl)
2226 {
2227 /* TRACE(pidl,"(pidl%p)\n", pidl); */
2228
2229 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2230
2231 if (!pdata)
2232 return NULL;
2233
2234 switch (pdata->type)
2235 {
2236 case PT_FOLDER:
2237 case PT_VALUE:
2238 case PT_IESPECIAL1:
2239 case PT_IESPECIAL2:
2240 return pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1;
2241
2242 case PT_WORKGRP:
2243 return pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1;
2244 }
2245 return NULL;
2246 }
2247
2248 /**************************************************************************
2249 * _ILGetGUIDPointer()
2250 *
2251 * returns reference to guid stored in some pidls
2252 */
2253 IID* _ILGetGUIDPointer(LPCITEMIDLIST pidl)
2254 {
2255 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
2256
2257 TRACE("%p\n", pidl);
2258
2259 if (!pdata)
2260 return NULL;
2261
2262 TRACE("pdata->type 0x%04x\n", pdata->type);
2263 switch (pdata->type)
2264 {
2265 case PT_SHELLEXT:
2266 case PT_GUID:
2267 case PT_YAGUID:
2268 return &(pdata->u.guid.guid);
2269
2270 default:
2271 TRACE("Unknown pidl type 0x%04x\n", pdata->type);
2272 break;
2273 }
2274 return NULL;
2275 }
2276
2277 /******************************************************************************
2278 * _ILGetFileStructW [Internal]
2279 *
2280 * Get pointer the a SHITEMID's FileStructW field if present
2281 *
2282 * PARAMS
2283 * pidl [I] The SHITEMID
2284 *
2285 * RETURNS
2286 * Success: Pointer to pidl's FileStructW field.
2287 * Failure: NULL
2288 */
2289 FileStructW* _ILGetFileStructW(LPCITEMIDLIST pidl) {
2290 FileStructW *pFileStructW;
2291 WORD cbOffset;
2292
2293 if (!(_ILIsValue(pidl) || _ILIsFolder(pidl)))
2294 return NULL;
2295
2296 cbOffset = *(const WORD *)((const BYTE *)pidl + pidl->mkid.cb - sizeof(WORD));
2297 pFileStructW = (FileStructW*)((LPBYTE)pidl + cbOffset);
2298
2299 /* Currently I don't see a fool prove way to figure out if a pidl is for sure of WinXP
2300 * style with a FileStructW member. If we switch all our shellfolder-implementations to
2301 * the new format, this won't be a problem. For now, we do as many sanity checks as possible. */
2302 if ((cbOffset & 0x1) || /* FileStructW member is word aligned in the pidl */
2303 /* FileStructW is positioned after FileStruct */
2304 cbOffset < sizeof(pidl->mkid.cb) + sizeof(PIDLTYPE) + sizeof(FileStruct) ||
2305 /* There has to be enough space at cbOffset in the pidl to hold FileStructW and cbOffset */
2306 cbOffset > pidl->mkid.cb - sizeof(cbOffset) - sizeof(FileStructW) ||
2307 pidl->mkid.cb != cbOffset + pFileStructW->cbLen)
2308 {
2309 WARN("Invalid pidl format (cbOffset = %d)!\n", cbOffset);
2310 return NULL;
2311 }
2312
2313 return pFileStructW;
2314 }
2315
2316 /*************************************************************************
2317 * _ILGetFileDateTime
2318 *
2319 * Given the ItemIdList, get the FileTime
2320 *
2321 * PARAMS
2322 * pidl [I] The ItemIDList
2323 * pFt [I] the resulted FILETIME of the file
2324 *
2325 * RETURNS
2326 * True if Successful
2327 *
2328 * NOTES
2329 *
2330 */
2331 BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
2332 {
2333 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2334
2335 if (!pdata)
2336 return FALSE;
2337
2338 switch (pdata->type)
2339 {
2340 case PT_FOLDER:
2341 case PT_VALUE:
2342 DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
2343 break;
2344 default:
2345 return FALSE;
2346 }
2347 return TRUE;
2348 }
2349
2350 BOOL _ILGetFileDate (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2351 {
2352 FILETIME ft,lft;
2353 SYSTEMTIME time;
2354 BOOL ret;
2355
2356 if (_ILGetFileDateTime( pidl, &ft ))
2357 {
2358 FileTimeToLocalFileTime(&ft, &lft);
2359 FileTimeToSystemTime (&lft, &time);
2360
2361 ret = GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&time, NULL, pOut, uOutSize);
2362 if (ret)
2363 {
2364 /* Append space + time without seconds */
2365 pOut[ret-1] = ' ';
2366 GetTimeFormatA(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &time, NULL, &pOut[ret], uOutSize - ret);
2367 }
2368 }
2369 else
2370 {
2371 pOut[0] = '\0';
2372 ret = FALSE;
2373 }
2374 return ret;
2375 }
2376
2377 /*************************************************************************
2378 * _ILGetFileSize
2379 *
2380 * Given the ItemIdList, get the FileSize
2381 *
2382 * PARAMS
2383 * pidl [I] The ItemIDList
2384 * pOut [I] The buffer to save the result
2385 * uOutsize [I] The size of the buffer
2386 *
2387 * RETURNS
2388 * The FileSize
2389 *
2390 * NOTES
2391 * pOut can be null when no string is needed
2392 *
2393 */
2394 DWORD _ILGetFileSize (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2395 {
2396 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
2397 DWORD dwSize;
2398
2399 if (!pdata)
2400 return 0;
2401
2402 switch (pdata->type)
2403 {
2404 case PT_VALUE:
2405 dwSize = pdata->u.file.dwFileSize;
2406 if (pOut)
2407 StrFormatKBSizeA(dwSize, pOut, uOutSize);
2408 return dwSize;
2409 }
2410 if (pOut)
2411 *pOut = 0x00;
2412 return 0;
2413 }
2414
2415 BOOL _ILGetExtension (LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2416 {
2417 char szTemp[MAX_PATH];
2418 const char * pPoint;
2419 LPCITEMIDLIST pidlTemp=pidl;
2420
2421 TRACE("pidl=%p\n",pidl);
2422
2423 if (!pidl)
2424 return FALSE;
2425
2426 pidlTemp = ILFindLastID(pidl);
2427
2428 if (!_ILIsValue(pidlTemp))
2429 return FALSE;
2430 if (!_ILSimpleGetText(pidlTemp, szTemp, MAX_PATH))
2431 return FALSE;
2432
2433 pPoint = PathFindExtensionA(szTemp);
2434
2435 if (!*pPoint)
2436 return FALSE;
2437
2438 pPoint++;
2439 lstrcpynA(pOut, pPoint, uOutSize);
2440 TRACE("%s\n",pOut);
2441
2442 return TRUE;
2443 }
2444
2445 /*************************************************************************
2446 * _ILGetFileType
2447 *
2448 * Given the ItemIdList, get the file type description
2449 *
2450 * PARAMS
2451 * pidl [I] The ItemIDList (simple)
2452 * pOut [I] The buffer to save the result
2453 * uOutsize [I] The size of the buffer
2454 *
2455 * RETURNS
2456 * nothing
2457 *
2458 * NOTES
2459 * This function copies as much as possible into the buffer.
2460 */
2461 void _ILGetFileType(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2462 {
2463 #ifdef __REACTOS__ /* r32966 */
2464 char sType[64];
2465 #endif
2466
2467 if(_ILIsValue(pidl))
2468 {
2469 char sTemp[64];
2470
2471 if(uOutSize > 0)
2472 pOut[0] = 0;
2473 #ifdef __REACTOS__ /* r32966 */
2474 if (_ILGetExtension (pidl, sType, 64))
2475 {
2476 if (HCR_MapTypeToValueA(sType, sTemp, 64, TRUE))
2477 {
2478 /* retrieve description */
2479 if(HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE ))
2480 return;
2481 }
2482 /* display Ext-file as description */
2483 strcpy(pOut, sType);
2484 _strupr(pOut);
2485 /* load localized file string */
2486 sTemp[0] = '\0';
2487 if(LoadStringA(shell32_hInstance, IDS_SHV_COLUMN1, sTemp, 64))
2488 {
2489 sTemp[63] = '\0';
2490 strcat(pOut, "-");
2491 strcat(pOut, sTemp);
2492 }
2493 }
2494 #else
2495 if (_ILGetExtension (pidl, sTemp, 64))
2496 {
2497 if (!( HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE)
2498 && HCR_MapTypeToValueA(sTemp, pOut, uOutSize, FALSE )))
2499 {
2500 lstrcpynA (pOut, sTemp, uOutSize - 6);
2501 strcat (pOut, "-file");
2502 }
2503 }
2504 #endif
2505 }
2506 else
2507 #ifdef __REACTOS__ /* r32966 */
2508 {
2509 pOut[0] = '\0';
2510 LoadStringA(shell32_hInstance, IDS_DIRECTORY, pOut, uOutSize);
2511 /* make sure its null terminated */
2512 pOut[uOutSize-1] = '\0';
2513 }
2514 #else
2515 lstrcpynA(pOut, "Folder", uOutSize);
2516 #endif
2517 }
2518
2519 /*************************************************************************
2520 * _ILGetFileAttributes
2521 *
2522 * Given the ItemIdList, get the Attrib string format
2523 *
2524 * PARAMS
2525 * pidl [I] The ItemIDList
2526 * pOut [I] The buffer to save the result
2527 * uOutsize [I] The size of the Buffer
2528 *
2529 * RETURNS
2530 * Attributes
2531 *
2532 * FIXME
2533 * return value 0 in case of error is a valid return value
2534 *
2535 */
2536 DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
2537 {
2538 LPPIDLDATA pData = _ILGetDataPointer(pidl);
2539 WORD wAttrib = 0;
2540 int i;
2541
2542 if (!pData)
2543 return 0;
2544
2545 switch(pData->type)
2546 {
2547 case PT_FOLDER:
2548 case PT_VALUE:
2549 wAttrib = pData->u.file.uFileAttribs;
2550 break;
2551 }
2552
2553 if(uOutSize >= 6)
2554 {
2555 i=0;
2556 if(wAttrib & FILE_ATTRIBUTE_READONLY)
2557 pOut[i++] = 'R';
2558 if(wAttrib & FILE_ATTRIBUTE_HIDDEN)
2559 pOut[i++] = 'H';
2560 if(wAttrib & FILE_ATTRIBUTE_SYSTEM)
2561 pOut[i++] = 'S';
2562 if(wAttrib & FILE_ATTRIBUTE_ARCHIVE)
2563 pOut[i++] = 'A';
2564 if(wAttrib & FILE_ATTRIBUTE_COMPRESSED)
2565 pOut[i++] = 'C';
2566 pOut[i] = 0x00;
2567 }
2568 return wAttrib;
2569 }
2570
2571 /*************************************************************************
2572 * ILFreeaPidl
2573 *
2574 * frees an aPidl struct
2575 */
2576 void _ILFreeaPidl(LPITEMIDLIST * apidl, UINT cidl)
2577 {
2578 UINT i;
2579
2580 if (apidl)
2581 {
2582 for (i = 0; i < cidl; i++)
2583 SHFree(apidl[i]);
2584 SHFree(apidl);
2585 }
2586 }
2587
2588 /*************************************************************************
2589 * ILCopyaPidl
2590 *
2591 * copies an aPidl struct
2592 */
2593 LPITEMIDLIST* _ILCopyaPidl(const LPCITEMIDLIST * apidlsrc, UINT cidl)
2594 {
2595 UINT i;
2596 LPITEMIDLIST *apidldest;
2597
2598 if (!apidlsrc)
2599 return NULL;
2600
2601 apidldest = SHAlloc(cidl * sizeof(LPITEMIDLIST));
2602
2603 for (i = 0; i < cidl; i++)
2604 apidldest[i] = ILClone(apidlsrc[i]);
2605
2606 return apidldest;
2607 }
2608
2609 /*************************************************************************
2610 * _ILCopyCidaToaPidl
2611 *
2612 * creates aPidl from CIDA
2613 */
2614 LPITEMIDLIST* _ILCopyCidaToaPidl(LPITEMIDLIST* pidl, const CIDA * cida)
2615 {
2616 UINT i;
2617 LPITEMIDLIST *dst;
2618
2619 dst = SHAlloc(cida->cidl * sizeof(LPITEMIDLIST));
2620 if (!dst)
2621 return NULL;
2622
2623 if (pidl)
2624 *pidl = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[0]]));
2625
2626 for (i = 0; i < cida->cidl; i++)
2627 dst[i] = ILClone((LPCITEMIDLIST)(&((const BYTE*)cida)[cida->aoffset[i + 1]]));
2628
2629 return dst;
2630 }