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