shlfolder.c 20.2 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1
/*
2
 *	Shell Folder stuff
Alexandre Julliard's avatar
Alexandre Julliard committed
3
 *
4 5
 *	Copyright 1997			Marcus Meissner
 *	Copyright 1998, 1999, 2002	Juergen Schmied
6
 *
7
 *	IShellFolder2 and related interfaces
Alexandre Julliard's avatar
Alexandre Julliard committed
8
 *
9 10 11 12 13 14 15 16 17 18 19 20
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Alexandre Julliard's avatar
Alexandre Julliard committed
22 23
 */

24 25 26
#include "config.h"
#include "wine/port.h"

Alexandre Julliard's avatar
Alexandre Julliard committed
27 28
#include <stdlib.h>
#include <string.h>
29
#include <stdarg.h>
30
#include <stdio.h>
31

32
#define COBJMACROS
33
#define NONAMELESSUNION
34

Alexandre Julliard's avatar
Alexandre Julliard committed
35
#include "winerror.h"
36
#include "windef.h"
37
#include "winbase.h"
38
#include "winreg.h"
39
#include "wingdi.h"
40
#include "winuser.h"
41

42
#include "ole2.h"
43 44
#include "shlguid.h"

Alexandre Julliard's avatar
Alexandre Julliard committed
45
#include "pidl.h"
46
#include "undocshell.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
47
#include "shell32_main.h"
48
#include "shlwapi.h"
49
#include "wine/debug.h"
50
#include "shfldr.h"
51

52
WINE_DEFAULT_DEBUG_CHANNEL (shell);
53

54 55
static const WCHAR wszDotShellClassInfo[] = {
    '.','S','h','e','l','l','C','l','a','s','s','I','n','f','o',0};
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

/***************************************************************************
 *  SHELL32_GetCustomFolderAttribute (internal function)
 *
 * Gets a value from the folder's desktop.ini file, if one exists.
 *
 * PARAMETERS
 *  pidl          [I] Folder containing the desktop.ini file.
 *  pwszHeading   [I] Heading in .ini file.
 *  pwszAttribute [I] Attribute in .ini file.
 *  pwszValue     [O] Buffer to store value into.
 *  cchValue      [I] Size in characters including NULL of buffer pointed to
 *                    by pwszValue.
 *
 *  RETURNS
 *    TRUE if returned non-NULL value.
 *    FALSE otherwise.
 */
74 75
static inline BOOL SHELL32_GetCustomFolderAttributeFromPath(
    LPWSTR pwszFolderPath, LPCWSTR pwszHeading, LPCWSTR pwszAttribute,
76 77
    LPWSTR pwszValue, DWORD cchValue)
{
78 79 80
    static const WCHAR wszDesktopIni[] =
            {'d','e','s','k','t','o','p','.','i','n','i',0};
    static const WCHAR wszDefault[] = {0};
81 82 83 84 85 86 87 88 89 90 91

    PathAddBackslashW(pwszFolderPath);
    PathAppendW(pwszFolderPath, wszDesktopIni);
    return GetPrivateProfileStringW(pwszHeading, pwszAttribute, wszDefault, 
                                    pwszValue, cchValue, pwszFolderPath);
}

BOOL SHELL32_GetCustomFolderAttribute(
    LPCITEMIDLIST pidl, LPCWSTR pwszHeading, LPCWSTR pwszAttribute,
    LPWSTR pwszValue, DWORD cchValue)
{
92
    DWORD dwAttrib = FILE_ATTRIBUTE_SYSTEM;
93
    WCHAR wszFolderPath[MAX_PATH];
94 95 96 97 98

    /* Hack around not having system attribute on non-Windows file systems */
    if (0)
        dwAttrib = _ILGetFileAttributes(pidl, NULL, 0);

99 100
    if (dwAttrib & FILE_ATTRIBUTE_SYSTEM)
    {
101
        if (!SHGetPathFromIDListW(pidl, wszFolderPath))
102
            return FALSE;
103 104 105

        return SHELL32_GetCustomFolderAttributeFromPath(wszFolderPath, pwszHeading, 
                                                pwszAttribute, pwszValue, cchValue);
106 107 108 109
    }
    return FALSE;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
110 111 112
/***************************************************************************
 *  GetNextElement (internal function)
 *
113
 * Gets a part of a string till the first backslash.
Alexandre Julliard's avatar
Alexandre Julliard committed
114 115 116
 *
 * PARAMETERS
 *  pszNext [IN] string to get the element from
117
 *  pszOut  [IN] pointer to buffer which receives string
Alexandre Julliard's avatar
Alexandre Julliard committed
118 119 120 121 122
 *  dwOut   [IN] length of pszOut
 *
 *  RETURNS
 *    LPSTR pointer to first, not yet parsed char
 */
123

124 125 126 127 128
LPCWSTR GetNextElementW (LPCWSTR pszNext, LPWSTR pszOut, DWORD dwOut)
{
    LPCWSTR pszTail = pszNext;
    DWORD dwCopy;

129
    TRACE ("(%s %p 0x%08x)\n", debugstr_w(pszNext), pszOut, dwOut);
Alexandre Julliard's avatar
Alexandre Julliard committed
130

131
    *pszOut = 0;
132

133 134
    if (!pszNext || !*pszNext)
	return NULL;
Alexandre Julliard's avatar
Alexandre Julliard committed
135

136 137
    while (*pszTail && (*pszTail != (WCHAR) '\\'))
	pszTail++;
138

139
    dwCopy = pszTail - pszNext + 1;
140
    lstrcpynW (pszOut, pszNext, (dwOut < dwCopy) ? dwOut : dwCopy);
Alexandre Julliard's avatar
Alexandre Julliard committed
141

142 143 144 145
    if (*pszTail)
	pszTail++;
    else
	pszTail = NULL;
Alexandre Julliard's avatar
Alexandre Julliard committed
146

147
    TRACE ("--(%s %s 0x%08x %p)\n", debugstr_w (pszNext), debugstr_w (pszOut), dwOut, pszTail);
148
    return pszTail;
Alexandre Julliard's avatar
Alexandre Julliard committed
149 150
}

151
HRESULT SHELL32_ParseNextElement (IShellFolder2 * psf, HWND hwndOwner, LPBC pbc,
152
				  LPITEMIDLIST * pidlInOut, LPOLESTR szNext, DWORD * pEaten, DWORD * pdwAttributes)
153
{
154
    LPITEMIDLIST pidlOut = NULL, pidlTemp = NULL;
155
    IShellFolder *psfChild;
156
    HRESULT hr;
157

158
    TRACE ("(%p, %p, %p, %s)\n", psf, pbc, pidlInOut ? *pidlInOut : NULL, debugstr_w (szNext));
159

160
    /* get the shellfolder for the child pidl and let it analyse further */
161
    hr = IShellFolder2_BindToObject (psf, *pidlInOut, pbc, &IID_IShellFolder, (LPVOID *) & psfChild);
162

163
    if (SUCCEEDED(hr)) {
164
	hr = IShellFolder_ParseDisplayName (psfChild, hwndOwner, pbc, szNext, pEaten, &pidlOut, pdwAttributes);
165
	IShellFolder_Release (psfChild);
166

167 168
	if (SUCCEEDED(hr)) {
	    pidlTemp = ILCombine (*pidlInOut, pidlOut);
169

170 171 172
	    if (!pidlTemp)
		hr = E_OUTOFMEMORY;
	}
Martin Fuchs's avatar
Martin Fuchs committed
173

174 175 176
	if (pidlOut)
	    ILFree (pidlOut);
    }
177

178 179
    ILFree (*pidlInOut);
    *pidlInOut = pidlTemp;
180

181
    TRACE ("-- pidl=%p ret=0x%08x\n", pidlInOut ? *pidlInOut : NULL, hr);
182
    return hr;
183 184 185 186 187
}

/***********************************************************************
 *	SHELL32_CoCreateInitSF
 *
188
 * Creates a shell folder and initializes it with a pidl and a root folder
189
 * via IPersistFolder3 or IPersistFolder.
190
 *
191
 * NOTES
192
 *   pathRoot can be NULL for Folders being a drive.
193
 *   In this case the absolute path is built from pidlChild (eg. C:)
194
 */
195
static HRESULT SHELL32_CoCreateInitSF (LPCITEMIDLIST pidlRoot, LPCWSTR pathRoot,
196
                LPCITEMIDLIST pidlChild, REFCLSID clsid, LPVOID * ppvOut)
197
{
198
    HRESULT hr;
199

200
    TRACE ("(%p %s %p %s %p)\n", pidlRoot, debugstr_w(pathRoot), pidlChild, debugstr_guid(clsid), ppvOut);
201

202
    hr = SHCoCreateInstance(NULL, clsid, NULL, &IID_IShellFolder, ppvOut);
203 204
    if (SUCCEEDED (hr))
    {
205 206 207 208
	LPITEMIDLIST pidlAbsolute = ILCombine (pidlRoot, pidlChild);
	IPersistFolder *pPF;
	IPersistFolder3 *ppf;

209 210 211
        if (_ILIsFolder(pidlChild) &&
            SUCCEEDED (IUnknown_QueryInterface ((IUnknown *) * ppvOut, &IID_IPersistFolder3, (LPVOID *) & ppf))) 
        {
212
	    PERSIST_FOLDER_TARGET_INFO ppfti;
213

214
	    ZeroMemory (&ppfti, sizeof (ppfti));
215

216 217 218 219
	    /* fill the PERSIST_FOLDER_TARGET_INFO */
	    ppfti.dwAttributes = -1;
	    ppfti.csidl = -1;

220 221
	    /* build path */
	    if (pathRoot) {
222 223
		lstrcpynW (ppfti.szTargetParsingName, pathRoot, MAX_PATH - 1);
		PathAddBackslashW(ppfti.szTargetParsingName); /* FIXME: why have drives a backslash here ? */
224
	    }
225

Martin Fuchs's avatar
Martin Fuchs committed
226
	    if (pidlChild) {
227
                int len = lstrlenW(ppfti.szTargetParsingName);
Martin Fuchs's avatar
Martin Fuchs committed
228

229 230
		if (!_ILSimpleGetTextW(pidlChild, ppfti.szTargetParsingName + len, MAX_PATH - len))
			hr = E_INVALIDARG;
Martin Fuchs's avatar
Martin Fuchs committed
231
	    }
232

233 234 235
	    IPersistFolder3_InitializeEx (ppf, NULL, pidlAbsolute, &ppfti);
	    IPersistFolder3_Release (ppf);
	}
236 237 238 239 240
	else if (SUCCEEDED ((hr = IUnknown_QueryInterface ((IUnknown *) * ppvOut, &IID_IPersistFolder, (LPVOID *) & pPF)))) {
	    IPersistFolder_Initialize (pPF, pidlAbsolute);
	    IPersistFolder_Release (pPF);
	}
	ILFree (pidlAbsolute);
241
    }
242
    TRACE ("-- (%p) ret=0x%08x\n", *ppvOut, hr);
243
    return hr;
Alexandre Julliard's avatar
Alexandre Julliard committed
244
}
245

246
/***********************************************************************
247
 *	SHELL32_BindToChild [Internal]
248
 *
249
 * Common code for IShellFolder_BindToObject.
250 251 252 253 254 255 256 257 258 259 260 261
 * 
 * PARAMS
 *  pidlRoot     [I] The parent shell folder's absolute pidl.
 *  pathRoot     [I] Absolute dos path of the parent shell folder.
 *  pidlComplete [I] PIDL of the child. Relative to pidlRoot.
 *  riid         [I] GUID of the interface, which ppvOut shall be bound to.
 *  ppvOut       [O] A reference to the child's interface (riid).
 *
 * NOTES
 *  pidlComplete has to contain at least one non empty SHITEMID.
 *  This function makes special assumptions on the shell namespace, which
 *  means you probably can't use it for your IShellFolder implementation.
262
 */
263
HRESULT SHELL32_BindToChild (LPCITEMIDLIST pidlRoot,
264
                             LPCWSTR pathRoot, LPCITEMIDLIST pidlComplete, REFIID riid, LPVOID * ppvOut)
265 266 267 268 269 270
{
    GUID const *clsid;
    IShellFolder *pSF;
    HRESULT hr;
    LPITEMIDLIST pidlChild;

271 272
    TRACE("(%p %s %p %s %p)\n", pidlRoot, debugstr_w(pathRoot), pidlComplete, debugstr_guid(riid), ppvOut);

273
    if (!pidlRoot || !ppvOut || _ILIsEmpty(pidlComplete))
274
        return E_INVALIDARG;
275 276 277 278 279 280

    *ppvOut = NULL;

    pidlChild = ILCloneFirst (pidlComplete);

    if ((clsid = _ILGetGUIDPointer (pidlChild))) {
281
        /* virtual folder */
282
        hr = SHELL32_CoCreateInitSF (pidlRoot, pathRoot, pidlChild, clsid, (LPVOID *)&pSF);
283 284 285
    } else if (_ILIsValue(pidlChild)) {
        /* Don't bind to files */
        hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
286
    } else {
287 288 289
        /* file system folder */
        CLSID clsidFolder = CLSID_ShellFSFolder;
        static const WCHAR wszCLSID[] = {'C','L','S','I','D',0};
290 291
        WCHAR wszCLSIDValue[CHARS_IN_GUID], wszFolderPath[MAX_PATH], *pwszPathTail = wszFolderPath;
       
292
        /* see if folder CLSID should be overridden by desktop.ini file */
293
        if (pathRoot) {
294
            lstrcpynW(wszFolderPath, pathRoot, MAX_PATH);
295 296
            pwszPathTail = PathAddBackslashW(wszFolderPath);
        }
297 298 299

        _ILSimpleGetTextW(pidlChild,pwszPathTail,MAX_PATH - (int)(pwszPathTail - wszFolderPath));

300
        if (SHELL32_GetCustomFolderAttributeFromPath (wszFolderPath,
301 302
            wszDotShellClassInfo, wszCLSID, wszCLSIDValue, CHARS_IN_GUID))
            CLSIDFromString (wszCLSIDValue, &clsidFolder);
303

304 305
        hr = SHELL32_CoCreateInitSF (pidlRoot, pathRoot, pidlChild,
                                     &clsidFolder, (LPVOID *)&pSF);
306 307 308 309
    }
    ILFree (pidlChild);

    if (SUCCEEDED (hr)) {
310 311 312 313 314 315 316 317
        if (_ILIsPidlSimple (pidlComplete)) {
            /* no sub folders */
            hr = IShellFolder_QueryInterface (pSF, riid, ppvOut);
        } else {
            /* go deeper */
            hr = IShellFolder_BindToObject (pSF, ILGetNext (pidlComplete), NULL, riid, ppvOut);
        }
        IShellFolder_Release (pSF);
318
    }
319

320
    TRACE ("-- returning (%p) 0x%08x\n", *ppvOut, hr);
321

322
    return hr;
Alexandre Julliard's avatar
Alexandre Julliard committed
323 324
}

325 326 327
/***********************************************************************
 *	SHELL32_GetDisplayNameOfChild
 *
328
 * Retrieves the display name of a child object of a shellfolder.
329 330 331 332 333 334
 *
 * For a pidl eg. [subpidl1][subpidl2][subpidl3]:
 * - it binds to the child shellfolder [subpidl1]
 * - asks it for the displayname of [subpidl2][subpidl3]
 *
 * Is possible the pidl is a simple pidl. In this case it asks the
335
 * subfolder for the displayname of an empty pidl. The subfolder
336 337 338 339
 * returns the own displayname eg. "::{guid}". This is used for
 * virtual folders with the registry key WantsFORPARSING set.
 */
HRESULT SHELL32_GetDisplayNameOfChild (IShellFolder2 * psf,
340
				       LPCITEMIDLIST pidl, DWORD dwFlags, LPWSTR szOut, DWORD dwOutLen)
341
{
342
    LPITEMIDLIST pidlFirst;
343
    HRESULT hr;
Alexandre Julliard's avatar
Alexandre Julliard committed
344

345
    TRACE ("(%p)->(pidl=%p 0x%08x %p 0x%08x)\n", psf, pidl, dwFlags, szOut, dwOutLen);
346
    pdump (pidl);
347

348 349 350
    pidlFirst = ILCloneFirst (pidl);
    if (pidlFirst) {
	IShellFolder2 *psfChild;
351

352
	hr = IShellFolder2_BindToObject (psf, pidlFirst, NULL, &IID_IShellFolder, (LPVOID *) & psfChild);
353 354 355
	if (SUCCEEDED (hr)) {
	    STRRET strTemp;
	    LPITEMIDLIST pidlNext = ILGetNext (pidl);
Alexandre Julliard's avatar
Alexandre Julliard committed
356

357
	    hr = IShellFolder2_GetDisplayNameOf (psfChild, pidlNext, dwFlags, &strTemp);
358
	    if (SUCCEEDED (hr)) {
359 360
		if(!StrRetToStrNW (szOut, dwOutLen, &strTemp, pidlNext))
                    hr = E_FAIL;
Juergen Schmied's avatar
Juergen Schmied committed
361
	    }
362
	    IShellFolder2_Release (psfChild);
363
	}
364
	ILFree (pidlFirst);
Martin Fuchs's avatar
Martin Fuchs committed
365 366
    } else
	hr = E_OUTOFMEMORY;
367

368
    TRACE ("-- ret=0x%08x %s\n", hr, debugstr_w(szOut));
369

370
    return hr;
371
}
372

373 374 375 376
/***********************************************************************
 *  SHELL32_GetItemAttributes
 *
 * NOTES
377
 * Observed values:
378 379 380 381 382 383
 *  folder:	0xE0000177	FILESYSTEM | HASSUBFOLDER | FOLDER
 *  file:	0x40000177	FILESYSTEM
 *  drive:	0xf0000144	FILESYSTEM | HASSUBFOLDER | FOLDER | FILESYSANCESTOR
 *  mycomputer:	0xb0000154	HASSUBFOLDER | FOLDER | FILESYSANCESTOR
 *  (seems to be default for shell extensions if no registry entry exists)
 *
384 385 386 387 388
 * win2k:
 *  folder:    0xF0400177      FILESYSTEM | HASSUBFOLDER | FOLDER | FILESYSANCESTOR | CANMONIKER
 *  file:      0x40400177      FILESYSTEM | CANMONIKER
 *  drive      0xF0400154      FILESYSTEM | HASSUBFOLDER | FOLDER | FILESYSANCESTOR | CANMONIKER | CANRENAME (LABEL)
 *
389
 * According to the MSDN documentation this function should not set flags. It claims only to reset flags when necessary.
390
 * However it turns out the native shell32.dll _sets_ flags in several cases - so do we.
391
 */
392
HRESULT SHELL32_GetItemAttributes (IShellFolder2 *psf, LPCITEMIDLIST pidl, LPDWORD pdwAttributes)
393
{
394
    DWORD dwAttributes;
395
    BOOL has_guid;
Juan Lang's avatar
Juan Lang committed
396 397
    static const DWORD dwSupportedAttr=
                          SFGAO_CANCOPY |           /*0x00000001 */
398 399
                          SFGAO_CANMOVE |           /*0x00000002 */
                          SFGAO_CANLINK |           /*0x00000004 */
400
                          SFGAO_CANRENAME |         /*0x00000010 */
401
                          SFGAO_CANDELETE |         /*0x00000020 */
402 403
                          SFGAO_HASPROPSHEET |      /*0x00000040 */
                          SFGAO_DROPTARGET |        /*0x00000100 */
Martin Fuchs's avatar
Martin Fuchs committed
404
                          SFGAO_LINK |              /*0x00010000 */
405 406 407 408 409 410 411
                          SFGAO_READONLY |          /*0x00040000 */
                          SFGAO_HIDDEN |            /*0x00080000 */
                          SFGAO_FILESYSANCESTOR |   /*0x10000000 */
                          SFGAO_FOLDER |            /*0x20000000 */
                          SFGAO_FILESYSTEM |        /*0x40000000 */
                          SFGAO_HASSUBFOLDER;       /*0x80000000 */
    
412
    TRACE ("0x%08x\n", *pdwAttributes);
413

414 415
    if (*pdwAttributes & ~dwSupportedAttr)
    {
416
        WARN ("attributes 0x%08x not implemented\n", (*pdwAttributes & ~dwSupportedAttr));
417 418
        *pdwAttributes &= dwSupportedAttr;
    }
419

420 421
    has_guid = _ILGetGUIDPointer(pidl) != NULL;

422 423
    dwAttributes = *pdwAttributes;

424
    if (_ILIsDrive (pidl)) {
425 426
        *pdwAttributes &= SFGAO_HASSUBFOLDER|SFGAO_FILESYSTEM|SFGAO_FOLDER|SFGAO_FILESYSANCESTOR|
	    SFGAO_DROPTARGET|SFGAO_HASPROPSHEET|SFGAO_CANLINK;
427
    } else if (has_guid && HCR_GetFolderAttributes(pidl, &dwAttributes)) {
428
	*pdwAttributes = dwAttributes;
429 430
    } else if (_ILGetDataPointer (pidl)) {
	dwAttributes = _ILGetFileAttributes (pidl, NULL, 0);
431

432 433
        if (!dwAttributes && has_guid) {
	    WCHAR path[MAX_PATH];
434
	    STRRET strret;
435 436

	    /* File attributes are not present in the internal PIDL structure, so get them from the file system. */
437

438
            HRESULT hr = IShellFolder2_GetDisplayNameOf(psf, pidl, SHGDN_FORPARSING, &strret);
439 440 441 442 443 444 445 446
	    if (SUCCEEDED(hr)) {
		hr = StrRetToBufW(&strret, pidl, path, MAX_PATH);

		/* call GetFileAttributes() only for file system paths, not for parsing names like "::{...}" */
		if (SUCCEEDED(hr) && path[0]!=':')
		    dwAttributes = GetFileAttributesW(path);
	    }
	}
447

448 449 450 451 452 453 454 455 456 457 458 459
        /* Set common attributes */
        *pdwAttributes |= SFGAO_FILESYSTEM | SFGAO_DROPTARGET | SFGAO_HASPROPSHEET | SFGAO_CANDELETE | 
                          SFGAO_CANRENAME | SFGAO_CANLINK | SFGAO_CANMOVE | SFGAO_CANCOPY;

	if (dwAttributes & FILE_ATTRIBUTE_DIRECTORY)
	    *pdwAttributes |=  (SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_FILESYSANCESTOR);
	else
	    *pdwAttributes &= ~(SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_FILESYSANCESTOR);

	if (dwAttributes & FILE_ATTRIBUTE_HIDDEN)
	    *pdwAttributes |=  SFGAO_HIDDEN;
	else
460
	    *pdwAttributes &= ~SFGAO_HIDDEN;
461

462 463 464
	if (dwAttributes & FILE_ATTRIBUTE_READONLY)
	    *pdwAttributes |=  SFGAO_READONLY;
	else
465
	    *pdwAttributes &= ~SFGAO_READONLY;
Martin Fuchs's avatar
Martin Fuchs committed
466 467 468 469

	if (SFGAO_LINK & *pdwAttributes) {
	    char ext[MAX_PATH];

470
	    if (!_ILGetExtension(pidl, ext, MAX_PATH) || lstrcmpiA(ext, "lnk"))
Martin Fuchs's avatar
Martin Fuchs committed
471 472
		*pdwAttributes &= ~SFGAO_LINK;
	}
473
    } else {
474
	*pdwAttributes &= SFGAO_HASSUBFOLDER|SFGAO_FOLDER|SFGAO_FILESYSANCESTOR|SFGAO_DROPTARGET|SFGAO_HASPROPSHEET|SFGAO_CANRENAME|SFGAO_CANLINK;
475
    }
476
    TRACE ("-- 0x%08x\n", *pdwAttributes);
477
    return S_OK;
478 479
}

480
/***********************************************************************
481
 *  SHELL32_CompareIDs
482
 */
483 484
HRESULT SHELL32_CompareIDs(IShellFolder2 *sf, LPARAM lParam, LPCITEMIDLIST pidl1,
        LPCITEMIDLIST pidl2)
485
{
486
    int type1, type2;
487 488
    char szTemp1[MAX_PATH];
    char szTemp2[MAX_PATH];
489
    HRESULT nReturn;
490
    LPITEMIDLIST firstpidl, nextpidl1, nextpidl2;
491 492
    IShellFolder *psf;

Gregg Mattinson's avatar
Gregg Mattinson committed
493
    /* test for empty pidls */
494 495 496 497
    BOOL isEmpty1 = _ILIsDesktop (pidl1);
    BOOL isEmpty2 = _ILIsDesktop (pidl2);

    if (isEmpty1 && isEmpty2)
498
        return MAKE_HRESULT( SEVERITY_SUCCESS, 0, 0 );
499
    if (isEmpty1)
500
        return MAKE_HRESULT( SEVERITY_SUCCESS, 0, (WORD)-1 );
501
    if (isEmpty2)
502
        return MAKE_HRESULT( SEVERITY_SUCCESS, 0, 1 );
503

Gregg Mattinson's avatar
Gregg Mattinson committed
504
    /* test for different types. Sort order is the PT_* constant */
505 506
    type1 = _ILGetDataPointer (pidl1)->type;
    type2 = _ILGetDataPointer (pidl2)->type;
507 508 509 510
    if (type1 < type2)
        return MAKE_HRESULT( SEVERITY_SUCCESS, 0, (WORD)-1 );
    else if (type1 > type2)
        return MAKE_HRESULT( SEVERITY_SUCCESS, 0, 1 );
511

Gregg Mattinson's avatar
Gregg Mattinson committed
512
    /* test for name of pidl */
513 514
    _ILSimpleGetText (pidl1, szTemp1, MAX_PATH);
    _ILSimpleGetText (pidl2, szTemp2, MAX_PATH);
515
    nReturn = lstrcmpiA (szTemp1, szTemp2);
516 517 518 519
    if (nReturn < 0)
        return MAKE_HRESULT( SEVERITY_SUCCESS, 0, (WORD)-1 );
    else if (nReturn > 0)
        return MAKE_HRESULT( SEVERITY_SUCCESS, 0, 1 );
520

Gregg Mattinson's avatar
Gregg Mattinson committed
521
    /* test of complex pidls */
522 523 524 525
    firstpidl = ILCloneFirst (pidl1);
    nextpidl1 = ILGetNext (pidl1);
    nextpidl2 = ILGetNext (pidl2);

Gregg Mattinson's avatar
Gregg Mattinson committed
526 527
    /* optimizing: test special cases and bind not deeper */
    /* the deeper shellfolder would do the same */
528 529 530 531
    isEmpty1 = _ILIsDesktop (nextpidl1);
    isEmpty2 = _ILIsDesktop (nextpidl2);

    if (isEmpty1 && isEmpty2) {
532
        nReturn = MAKE_HRESULT( SEVERITY_SUCCESS, 0, 0 );
533
    } else if (isEmpty1) {
534
        nReturn = MAKE_HRESULT( SEVERITY_SUCCESS, 0, (WORD)-1 );
535
    } else if (isEmpty2) {
536
        nReturn = MAKE_HRESULT( SEVERITY_SUCCESS, 0, 1 );
Gregg Mattinson's avatar
Gregg Mattinson committed
537
    /* optimizing end */
538
    } else if (SUCCEEDED(IShellFolder2_BindToObject(sf, firstpidl, NULL, &IID_IShellFolder, (void **)&psf))) {
539 540 541 542 543
	nReturn = IShellFolder_CompareIDs (psf, lParam, nextpidl1, nextpidl2);
	IShellFolder_Release (psf);
    }
    ILFree (firstpidl);
    return nReturn;
544
}
545

546 547 548 549
HRESULT SHELL32_GetColumnDetails(const shvheader *data, int column, SHELLDETAILS *details)
{
    details->fmt = data[column].fmt;
    details->cxChar = data[column].cxChar;
550 551 552 553 554 555 556 557 558 559 560 561 562 563

    if (SHELL_OsIsUnicode())
    {
        details->str.u.pOleStr = CoTaskMemAlloc(MAX_PATH * sizeof(WCHAR));
        if (!details->str.u.pOleStr) return E_OUTOFMEMORY;

        details->str.uType = STRRET_WSTR;
        LoadStringW(shell32_hInstance, data[column].colnameid, details->str.u.pOleStr, MAX_PATH);
    }
    else
    {
        details->str.uType = STRRET_CSTR;
        LoadStringA(shell32_hInstance, data[column].colnameid, details->str.u.cStr, MAX_PATH);
    }
564 565 566 567

    return S_OK;
}

568 569 570 571 572 573 574 575 576 577 578
/***********************************************************************
 *  SHCreateLinks
 *
 *   Undocumented.
 */
HRESULT WINAPI SHCreateLinks( HWND hWnd, LPCSTR lpszDir, LPDATAOBJECT lpDataObject,
                              UINT uFlags, LPITEMIDLIST *lppidlLinks)
{
    FIXME("%p %s %p %08x %p\n",hWnd,lpszDir,lpDataObject,uFlags,lppidlLinks);
    return E_NOTIMPL;
}
579 580 581 582 583 584 585 586 587 588 589 590

/***********************************************************************
 *  SHOpenFolderAndSelectItems
 *
 *   Added in XP.
 */
HRESULT WINAPI SHOpenFolderAndSelectItems( PCIDLIST_ABSOLUTE pidlFolder, UINT cidl,
                              PCUITEMID_CHILD_ARRAY *apidl, DWORD flags )
{
    FIXME("%p %u %p 0x%x: stub\n", pidlFolder, cidl, apidl, flags);
    return E_NOTIMPL;
}
591 592 593 594 595 596 597 598 599 600 601

/***********************************************************************
 *  SHGetSetFolderCustomSettings
 *
 *   Only in XP (up to SP2) and Server 2003
 */
HRESULT WINAPI SHGetSetFolderCustomSettings( LPSHFOLDERCUSTOMSETTINGS fcs, LPCSTR path, DWORD flag )
{
    FIXME("%p %s 0x%x: stub\n", fcs, path, flag);
    return E_NOTIMPL;
}
602 603 604 605 606 607 608 609 610

/***********************************************************************
 * SHLimitInputEdit (SHELL32.747)
 */
HRESULT WINAPI SHLimitInputEdit( HWND textbox, IShellFolder *folder )
{
    FIXME("%p %p: stub\n", textbox, folder);
    return E_NOTIMPL;
}