Changeset 4032 for trunk/src/shell32/shlfolder.cpp
- Timestamp:
- Aug 18, 2000, 4:01:27 AM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/shell32/shlfolder.cpp
r3646 r4032 1 /* $Id: shlfolder.cpp,v 1.1 4 2000-06-01 14:01:10 sandervlExp $ */1 /* $Id: shlfolder.cpp,v 1.15 2000-08-18 02:01:23 phaller Exp $ */ 2 2 /* 3 3 * Shell Folder stuff … … 32 32 #include "shresdef.h" 33 33 #include "shlwapi.h" 34 35 #include "initguid.h" 36 #include "shellfolder.h" 34 37 35 38 #include <heapstring.h> … … 286 289 287 290 ICOM_VTABLE(IShellFolder2)* lpvtblShellFolder; 288 ICOM_VTABLE(IPersistFolder )* lpvtblPersistFolder;291 ICOM_VTABLE(IPersistFolder2)* lpvtblPersistFolder2; 289 292 ICOM_VTABLE(IDropTarget)* lpvtblDropTarget; 293 ICOM_VTABLE(ISFHelper)* lpvtblSFHelper; 290 294 291 295 IUnknown *pUnkOuter; /* used for aggregation */ … … 302 306 extern struct ICOM_VTABLE(IUnknown) unkvt; 303 307 extern struct ICOM_VTABLE(IShellFolder2) sfvt; 304 extern struct ICOM_VTABLE(IPersistFolder ) psfvt;308 extern struct ICOM_VTABLE(IPersistFolder2) psfvt; 305 309 extern struct ICOM_VTABLE(IDropTarget) dtvt; 310 extern struct ICOM_VTABLE(ISFHelper) shvt; 306 311 307 312 static IShellFolder * ISF_MyComputer_Constructor(void); … … 310 315 #define _ICOM_THIS_From_IShellFolder2(class, name) class* This = (class*)(((char*)name)-_IShellFolder2_Offset); 311 316 312 #define _IPersistFolder_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblPersistFolder )))313 #define _ICOM_THIS_From_IPersistFolder (class, name) class* This = (class*)(((char*)name)-_IPersistFolder_Offset);317 #define _IPersistFolder_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblPersistFolder2))) 318 #define _ICOM_THIS_From_IPersistFolder2(class, name) class* This = (class*)(((char*)name)-_IPersistFolder_Offset); 314 319 315 320 #define _IDropTarget_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblDropTarget))) 316 321 #define _ICOM_THIS_From_IDropTarget(class, name) class* This = (class*)(((char*)name)-_IDropTarget_Offset); 317 322 323 #define _ISFHelper_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblSFHelper))) 324 #define _ICOM_THIS_From_ISFHelper(class, name) class* This = (class*)(((char*)name)-_ISFHelper_Offset); 318 325 /* 319 326 converts This to a interface pointer … … 322 329 #define _IShellFolder_(This) (IShellFolder*)&(This->lpvtblShellFolder) 323 330 #define _IShellFolder2_(This) (IShellFolder2*)&(This->lpvtblShellFolder) 324 #define _IPersist_(This) (IPersist*)&(This->lpvtblPersistFolder) 325 #define _IPersistFolder_(This) (IPersistFolder*)&(This->lpvtblPersistFolder) 331 #define _IPersist_(This) (IPersist*)&(This->lpvtblPersistFolder2) 332 #define _IPersistFolder_(This) (IPersistFolder*)&(This->lpvtblPersistFolder2) 333 #define _IPersistFolder2_(This) (IPersistFolder2*)&(This->lpvtblPersistFolder2) 326 334 #define _IDropTarget_(This) (IDropTarget*)&(This->lpvtblDropTarget) 335 #define _ISFHelper_(This) (ISFHelper*)&(This->lpvtblSFHelper) 327 336 328 337 /************************************************************************** … … 363 372 else if(IsEqualIID(riid, &IID_IPersist)) *ppvObj = _IPersist_(This); 364 373 else if(IsEqualIID(riid, &IID_IPersistFolder)) *ppvObj = _IPersistFolder_(This); 374 else if(IsEqualIID(riid, &IID_IPersistFolder2)) *ppvObj = _IPersistFolder2_(This); 375 else if(IsEqualIID(riid, &IID_ISFHelper)) *ppvObj = _ISFHelper_(This); 365 376 else if(IsEqualIID(riid, &IID_IDropTarget)) 366 377 { … … 467 478 ICOM_VTBL(sf)=&unkvt; 468 479 sf->lpvtblShellFolder=&sfvt; 469 sf->lpvtblPersistFolder =&psfvt;480 sf->lpvtblPersistFolder2=&psfvt; 470 481 sf->lpvtblDropTarget=&dtvt; 471 482 sf->pclsid = (CLSID*)&CLSID_SFFile; … … 504 515 ICOM_VTBL(sf)=&unkvt; 505 516 sf->lpvtblShellFolder=&sfvt; 506 sf->lpvtblPersistFolder =&psfvt;517 sf->lpvtblPersistFolder2=&psfvt; 507 518 sf->lpvtblDropTarget=&dtvt; 508 519 sf->pclsid = (CLSID*)&CLSID_SFFile; … … 539 550 540 551 len = strlen(sf->sMyPath); 541 _ILSimpleGetText(pidl, sf->sMyPath + len, dwSize - len + 1);552 _ILSimpleGetText(pidl, sf->sMyPath + len, dwSize - len + 2); 542 553 } 543 554 … … 668 679 else 669 680 { 670 hr = S_OK; 681 hr = S_OK; 682 683 if (pdwAttributes && *pdwAttributes) 684 { 685 SHELL32_GetItemAttributes(_IShellFolder_(This), pidlTemp, pdwAttributes); 686 } 671 687 } 672 688 } … … 761 777 } 762 778 } 763 else 779 else if(_ILIsFolder(pidl)) 764 780 { 765 781 LPITEMIDLIST pidltemp = ILCloneFirst(pidl); 766 782 pShellFolder = IShellFolder_Constructor(iface, pidltemp); 767 783 ILFree(pidltemp); 784 } 785 else 786 { 787 ERR("can't bind to a file\n"); 788 return E_FAIL; 768 789 } 769 790 … … 1053 1074 if(IsEqualIID(riid, &IID_IContextMenu) && (cidl >= 1)) 1054 1075 { 1055 pObj = (LPUNKNOWN)I ContextMenu_Constructor((IShellFolder *)iface, This->absPidl, apidl, cidl);1076 pObj = (LPUNKNOWN)ISvItemCm_Constructor((IShellFolder *)iface, This->absPidl, apidl, cidl); 1056 1077 hr = S_OK; 1057 1078 } … … 1171 1192 LPCITEMIDLIST pidl, /*simple pidl*/ 1172 1193 LPCOLESTR lpName, 1173 DWORD dw ,1194 DWORD dwFlags, 1174 1195 LPITEMIDLIST *pPidlOut) 1175 1196 { 1176 1197 _ICOM_THIS_From_IShellFolder2(IGenericSFImpl, iface) 1177 1178 FIXME("(%p)->(%u,pidl=%p,%s,%lu,%p),stub!\n", 1179 This,hwndOwner,pidl,debugstr_w(lpName),dw,pPidlOut); 1180 1181 return E_NOTIMPL; 1198 1199 char szSrc[MAX_PATH], szDest[MAX_PATH]; 1200 int len; 1201 BOOL bIsFolder = _ILIsFolder(ILFindLastID(pidl)); 1202 1203 TRACE("(%p)->(%u,pidl=%p,%s,%lu,%p)\n", 1204 This,hwndOwner,pidl,debugstr_w(lpName),dwFlags,pPidlOut); 1205 1206 /* build source path */ 1207 if (dwFlags & SHGDN_INFOLDER) 1208 { 1209 strcpy(szSrc, This->sMyPath); 1210 PathAddBackslashA(szSrc); 1211 len = strlen (szSrc); 1212 _ILSimpleGetText(pidl, szSrc+len, MAX_PATH-len); 1213 } 1214 else 1215 { 1216 SHGetPathFromIDListA(pidl, szSrc); 1217 } 1218 1219 /* build destination path */ 1220 strcpy(szDest, This->sMyPath); 1221 PathAddBackslashA(szDest); 1222 len = strlen (szDest); 1223 lstrcpynWtoA(szDest+len, lpName, MAX_PATH-len); 1224 1225 TRACE("src=%s dest=%s\n", szSrc, szDest); 1226 if ( MoveFileA(szSrc, szDest) ) 1227 { 1228 if (pPidlOut) *pPidlOut = SHSimpleIDListFromPathA(szDest); 1229 SHChangeNotifyA( bIsFolder?SHCNE_RENAMEFOLDER:SHCNE_RENAMEITEM, SHCNF_PATHA, szSrc, szDest); 1230 return S_OK; 1231 } 1232 return E_FAIL; 1182 1233 } 1183 1234 … … 1347 1398 }; 1348 1399 1400 1401 /**************************************************************************** 1402 * ISFHelper for IShellFolder implementation 1403 */ 1404 1405 static HRESULT WINAPI ISFHelper_fnQueryInterface( 1406 ISFHelper *iface, 1407 REFIID riid, 1408 LPVOID *ppvObj) 1409 { 1410 _ICOM_THIS_From_ISFHelper(IGenericSFImpl,iface); 1411 1412 TRACE("(%p)\n", This); 1413 1414 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObj); 1415 } 1416 1417 static ULONG WINAPI ISFHelper_fnAddRef( 1418 ISFHelper *iface) 1419 { 1420 _ICOM_THIS_From_ISFHelper(IGenericSFImpl,iface); 1421 1422 TRACE("(%p)\n", This); 1423 1424 return IUnknown_AddRef(This->pUnkOuter); 1425 } 1426 1427 static ULONG WINAPI ISFHelper_fnRelease( 1428 ISFHelper *iface) 1429 { 1430 _ICOM_THIS_From_ISFHelper(IGenericSFImpl,iface); 1431 1432 TRACE("(%p)\n", This); 1433 1434 return IUnknown_Release(This->pUnkOuter); 1435 } 1436 1437 1438 /**************************************************************************** 1439 * ISFHelper_fnAddFolder 1440 * 1441 * creates a unique folder name 1442 */ 1443 1444 static HRESULT WINAPI ISFHelper_fnGetUniqueName( 1445 ISFHelper *iface, 1446 LPSTR lpName, 1447 UINT uLen) 1448 { 1449 _ICOM_THIS_From_ISFHelper(IGenericSFImpl,iface) 1450 IEnumIDList * penum; 1451 HRESULT hr; 1452 char szText[MAX_PATH]; 1453 char * szNewFolder = "New Folder"; 1454 1455 TRACE("(%p)(%s %u)\n", This, lpName, uLen); 1456 1457 if (uLen < strlen(szNewFolder) + 4) return E_POINTER; 1458 1459 strcpy(lpName, szNewFolder); 1460 1461 hr = IShellFolder_fnEnumObjects(_IShellFolder2_(This), 0, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &penum); 1462 if (penum) 1463 { 1464 LPITEMIDLIST pidl; 1465 DWORD dwFetched; 1466 int i=1; 1467 1468 next: IEnumIDList_Reset(penum); 1469 while(S_OK == IEnumIDList_Next(penum, 1, &pidl, &dwFetched) && dwFetched) 1470 { 1471 _ILSimpleGetText(pidl, szText, MAX_PATH); 1472 if (0 == strcmp(szText, lpName)) 1473 { 1474 sprintf(lpName, "%s %d", szNewFolder, i++); 1475 if (i > 99) 1476 { 1477 hr = E_FAIL; 1478 break; 1479 } 1480 goto next; 1481 } 1482 } 1483 1484 IEnumIDList_Release(penum); 1485 } 1486 return hr; 1487 } 1488 1489 /**************************************************************************** 1490 * ISFHelper_fnAddFolder 1491 * 1492 * adds a new folder. 1493 */ 1494 1495 static HRESULT WINAPI ISFHelper_fnAddFolder( 1496 ISFHelper *iface, 1497 HWND hwnd, 1498 LPCSTR lpName, 1499 LPITEMIDLIST* ppidlOut) 1500 { 1501 _ICOM_THIS_From_ISFHelper(IGenericSFImpl,iface) 1502 char lpstrNewDir[MAX_PATH]; 1503 DWORD bRes; 1504 HRESULT hres = E_FAIL; 1505 1506 TRACE("(%p)(%s %p)\n", This, lpName, ppidlOut); 1507 1508 strcpy(lpstrNewDir, This->sMyPath); 1509 PathAddBackslashA(lpstrNewDir); 1510 strcat(lpstrNewDir, lpName); 1511 1512 bRes = CreateDirectoryA(lpstrNewDir, NULL); 1513 1514 if (bRes) 1515 { 1516 LPITEMIDLIST pidl, pidlitem; 1517 1518 pidlitem = SHSimpleIDListFromPathA(lpstrNewDir); 1519 1520 pidl = ILCombine(This->absPidl, pidlitem); 1521 SHChangeNotifyA(SHCNE_MKDIR, SHCNF_IDLIST, pidl, NULL); 1522 SHFree(pidl); 1523 1524 if (ppidlOut) *ppidlOut = pidlitem; 1525 hres = S_OK; 1526 } 1527 else 1528 { 1529 char lpstrText[128+MAX_PATH]; 1530 char lpstrTempText[128]; 1531 char lpstrCaption[256]; 1532 1533 /* Cannot Create folder because of permissions */ 1534 LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_DENIED, lpstrTempText, sizeof(lpstrTempText)); 1535 LoadStringA(shell32_hInstance, IDS_CREATEFOLDER_CAPTION, lpstrCaption, sizeof(lpstrCaption)); 1536 sprintf(lpstrText,lpstrTempText, lpstrNewDir); 1537 MessageBoxA(hwnd,lpstrText, lpstrCaption, MB_OK | MB_ICONEXCLAMATION); 1538 } 1539 1540 return hres; 1541 } 1542 1543 /**************************************************************************** 1544 * ISFHelper_fnDeleteItems 1545 * 1546 * deletes items in folder 1547 */ 1548 static HRESULT WINAPI ISFHelper_fnDeleteItems( 1549 ISFHelper *iface, 1550 UINT cidl, 1551 LPCITEMIDLIST* apidl) 1552 { 1553 _ICOM_THIS_From_ISFHelper(IGenericSFImpl,iface) 1554 int i; 1555 char szPath[MAX_PATH]; 1556 1557 TRACE("(%p)(%u %p)\n", This, cidl, apidl); 1558 1559 for(i=0; i< cidl; i++) 1560 { 1561 strcpy(szPath, This->sMyPath); 1562 PathAddBackslashA(szPath); 1563 _ILSimpleGetText(apidl[i], szPath+strlen(szPath), MAX_PATH); 1564 1565 if (_ILIsFolder(apidl[i])) 1566 { 1567 LPITEMIDLIST pidl; 1568 1569 MESSAGE("delete %s\n", szPath); 1570 if (! SHELL_DeleteDirectoryA(szPath, TRUE)) return E_FAIL; 1571 pidl = ILCombine(This->absPidl, apidl[i]); 1572 SHChangeNotifyA(SHCNE_RMDIR, SHCNF_IDLIST, pidl, NULL); 1573 SHFree(pidl); 1574 } 1575 else if (_ILIsValue(apidl[i])) 1576 { 1577 LPITEMIDLIST pidl; 1578 1579 MESSAGE("delete %s\n", szPath); 1580 if (! DeleteFileA(szPath)) return E_FAIL; 1581 pidl = ILCombine(This->absPidl, apidl[i]); 1582 SHChangeNotifyA(SHCNE_DELETE, SHCNF_IDLIST, pidl, NULL); 1583 SHFree(pidl); 1584 } 1585 1586 } 1587 return S_OK; 1588 } 1589 1590 /**************************************************************************** 1591 * ISFHelper_fnCopyItems 1592 * 1593 * copys items to this folder 1594 */ 1595 static HRESULT WINAPI ISFHelper_fnCopyItems( 1596 ISFHelper *iface, 1597 IShellFolder* pSFFrom, 1598 UINT cidl, 1599 LPCITEMIDLIST *apidl) 1600 { 1601 int i; 1602 IPersistFolder2 * ppf2=NULL; 1603 char szSrcPath[MAX_PATH], szDstPath[MAX_PATH]; 1604 _ICOM_THIS_From_ISFHelper(IGenericSFImpl,iface); 1605 1606 TRACE("(%p)->(%p,%u,%p)\n", This, pSFFrom, cidl, apidl); 1607 1608 IShellFolder_QueryInterface(pSFFrom, &IID_IPersistFolder2, (LPVOID*)&ppf2); 1609 if (ppf2) 1610 { 1611 LPITEMIDLIST pidl; 1612 if (SUCCEEDED(IPersistFolder2_GetCurFolder(ppf2, &pidl))) 1613 { 1614 for (i=0; i<cidl; i++) 1615 { 1616 SHGetPathFromIDListA(pidl, szSrcPath); 1617 PathAddBackslashA(szSrcPath); 1618 _ILSimpleGetText(apidl[i], szSrcPath+strlen(szSrcPath), MAX_PATH); 1619 1620 strcpy(szDstPath, This->sMyPath); 1621 PathAddBackslashA(szDstPath); 1622 _ILSimpleGetText(apidl[i], szDstPath+strlen(szDstPath), MAX_PATH); 1623 MESSAGE("would copy %s to %s\n", szSrcPath, szDstPath); 1624 } 1625 SHFree(pidl); 1626 } 1627 IPersistFolder2_Release(ppf2); 1628 } 1629 return S_OK; 1630 } 1631 1632 ICOM_VTABLE(ISFHelper) shvt = 1633 { 1634 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE 1635 ISFHelper_fnQueryInterface, 1636 ISFHelper_fnAddRef, 1637 ISFHelper_fnRelease, 1638 ISFHelper_fnGetUniqueName, 1639 ISFHelper_fnAddFolder, 1640 ISFHelper_fnDeleteItems, 1641 ISFHelper_fnCopyItems, 1642 }; 1643 1349 1644 /*********************************************************************** 1350 1645 * [Desktopfolder] IShellFolder implementation … … 1464 1759 { 1465 1760 hr = S_OK; 1761 1762 if (pdwAttributes && *pdwAttributes) 1763 { 1764 SHELL32_GetItemAttributes(_IShellFolder_(This), pidlTemp, pdwAttributes); 1765 } 1466 1766 } 1467 1767 … … 1883 2183 ICOM_VTBL(sf)=&unkvt; 1884 2184 sf->lpvtblShellFolder=&sfmcvt; 1885 sf->lpvtblPersistFolder = &psfvt;2185 sf->lpvtblPersistFolder2 = &psfvt; 1886 2186 sf->pclsid = (CLSID*)&CLSID_SFMyComp; 1887 2187 sf->absPidl=_ILCreateMyComputer(); /* my qualified pidl */ … … 2367 2667 * 2368 2668 */ 2369 static HRESULT WINAPI ISFPersistFolder _QueryInterface(2370 IPersistFolder * iface,2669 static HRESULT WINAPI ISFPersistFolder2_QueryInterface( 2670 IPersistFolder2 * iface, 2371 2671 REFIID iid, 2372 2672 LPVOID* ppvObj) 2373 2673 { 2374 _ICOM_THIS_From_IPersistFolder (IGenericSFImpl, iface);2674 _ICOM_THIS_From_IPersistFolder2(IGenericSFImpl, iface); 2375 2675 2376 2676 TRACE("(%p)\n", This); … … 2383 2683 * 2384 2684 */ 2385 static ULONG WINAPI ISFPersistFolder _AddRef(2386 IPersistFolder * iface)2387 { 2388 _ICOM_THIS_From_IPersistFolder (IGenericSFImpl, iface);2685 static ULONG WINAPI ISFPersistFolder2_AddRef( 2686 IPersistFolder2 * iface) 2687 { 2688 _ICOM_THIS_From_IPersistFolder2(IGenericSFImpl, iface); 2389 2689 2390 2690 TRACE("(%p)\n", This); … … 2397 2697 * 2398 2698 */ 2399 static ULONG WINAPI ISFPersistFolder _Release(2400 IPersistFolder * iface)2401 { 2402 _ICOM_THIS_From_IPersistFolder (IGenericSFImpl, iface);2699 static ULONG WINAPI ISFPersistFolder2_Release( 2700 IPersistFolder2 * iface) 2701 { 2702 _ICOM_THIS_From_IPersistFolder2(IGenericSFImpl, iface); 2403 2703 2404 2704 TRACE("(%p)\n", This); … … 2410 2710 * ISFPersistFolder_GetClassID (IPersist) 2411 2711 */ 2412 static HRESULT WINAPI ISFPersistFolder _GetClassID(2413 IPersistFolder * iface,2712 static HRESULT WINAPI ISFPersistFolder2_GetClassID( 2713 IPersistFolder2 * iface, 2414 2714 CLSID * lpClassId) 2415 2715 { 2416 _ICOM_THIS_From_IPersistFolder (IGenericSFImpl, iface);2716 _ICOM_THIS_From_IPersistFolder2(IGenericSFImpl, iface); 2417 2717 2418 2718 TRACE("(%p)\n", This); … … 2430 2730 * sMyPath is not set. Don't know how to handle in a non rooted environment. 2431 2731 */ 2432 static HRESULT WINAPI ISFPersistFolder _Initialize(2433 IPersistFolder *iface,2732 static HRESULT WINAPI ISFPersistFolder2_Initialize( 2733 IPersistFolder2 * iface, 2434 2734 LPCITEMIDLIST pidl) 2435 2735 { 2436 2736 char sTemp[MAX_PATH]; 2437 _ICOM_THIS_From_IPersistFolder (IGenericSFImpl, iface);2737 _ICOM_THIS_From_IPersistFolder2(IGenericSFImpl, iface); 2438 2738 2439 2739 TRACE("(%p)->(%p)\n", This, pidl); … … 2466 2766 } 2467 2767 2468 ICOM_VTABLE(IPersistFolder) psfvt = 2768 /************************************************************************** 2769 * IPersistFolder2_fnGetCurFolder 2770 */ 2771 static HRESULT WINAPI ISFPersistFolder2_fnGetCurFolder( 2772 IPersistFolder2 * iface, 2773 LPITEMIDLIST * pidl) 2774 { 2775 _ICOM_THIS_From_IPersistFolder2(IGenericSFImpl, iface); 2776 2777 TRACE("(%p)->(%p)\n",This, pidl); 2778 2779 if (!pidl) return E_POINTER; 2780 2781 *pidl = ILClone(This->absPidl); 2782 2783 return S_OK; 2784 } 2785 2786 ICOM_VTABLE(IPersistFolder2) psfvt = 2469 2787 { 2470 2788 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE 2471 ISFPersistFolder_QueryInterface, 2472 ISFPersistFolder_AddRef, 2473 ISFPersistFolder_Release, 2474 ISFPersistFolder_GetClassID, 2475 ISFPersistFolder_Initialize 2789 ISFPersistFolder2_QueryInterface, 2790 ISFPersistFolder2_AddRef, 2791 ISFPersistFolder2_Release, 2792 ISFPersistFolder2_GetClassID, 2793 ISFPersistFolder2_Initialize, 2794 ISFPersistFolder2_fnGetCurFolder 2476 2795 }; 2477 2796 … … 2609 2928 ISFDropTarget_Drop 2610 2929 }; 2611
Note:
See TracChangeset
for help on using the changeset viewer.