shell32: Use shared code to return column details from IShellFolder2::GetDetailsOf().

This commit is contained in:
Nikolay Sivov 2010-04-18 18:04:25 +04:00 committed by Alexandre Julliard
parent 506264becd
commit e51fe8e070
7 changed files with 104 additions and 112 deletions

View File

@ -1,4 +1,3 @@
/*
* Virtual Folder
* common definitions
@ -30,6 +29,8 @@ typedef struct {
int cxChar;
} shvheader;
HRESULT SHELL32_GetColumnDetails(const shvheader *data, int column, SHELLDETAILS *details);
#define GET_SHGDN_FOR(dwFlags) ((DWORD)dwFlags & (DWORD)0x0000FF00)
#define GET_SHGDN_RELATION(dwFlags) ((DWORD)dwFlags & (DWORD)0x000000FF)

View File

@ -81,7 +81,7 @@ static inline IDesktopFolderImpl *impl_from_IPersist( IPersist *iface )
return (IDesktopFolderImpl *)((char*)iface - FIELD_OFFSET(IDesktopFolderImpl, lpVtblIPersist));
}
static const shvheader DesktopSFHeader[] = {
static const shvheader desktop_header[] = {
{IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
{IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
{IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
@ -89,7 +89,7 @@ static const shvheader DesktopSFHeader[] = {
{IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
};
#define DESKTOPSHELLVIEWCOLUMNS 5
#define DESKTOPSHELLVIEWCOLUMNS sizeof(desktop_header)/sizeof(shvheader)
/**************************************************************************
* ISF_Desktop_fnQueryInterface
@ -775,7 +775,7 @@ static HRESULT WINAPI ISF_Desktop_fnGetDefaultColumnState (
if (!pcsFlags || iColumn >= DESKTOPSHELLVIEWCOLUMNS)
return E_INVALIDARG;
*pcsFlags = DesktopSFHeader[iColumn].pcsFlags;
*pcsFlags = desktop_header[iColumn].pcsFlags;
return S_OK;
}
@ -801,14 +801,7 @@ static HRESULT WINAPI ISF_Desktop_fnGetDetailsOf (IShellFolder2 * iface,
return E_INVALIDARG;
if (!pidl)
{
psd->fmt = DesktopSFHeader[iColumn].fmt;
psd->cxChar = DesktopSFHeader[iColumn].cxChar;
psd->str.uType = STRRET_CSTR;
LoadStringA (shell32_hInstance, DesktopSFHeader[iColumn].colnameid,
psd->str.u.cStr, MAX_PATH);
return S_OK;
}
return SHELL32_GetColumnDetails(desktop_header, iColumn, psd);
/* the data from the pidl */
psd->str.uType = STRRET_CSTR;

View File

@ -86,14 +86,14 @@ static inline IMyComputerFolderImpl *impl_from_IPersistFolder2( IPersistFolder2
* IShellFolder [MyComputer] implementation
*/
static const shvheader MyComputerSFHeader[] = {
static const shvheader mycomputer_header[] = {
{IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
{IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
{IDS_SHV_COLUMN6, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
{IDS_SHV_COLUMN7, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
};
#define MYCOMPUTERSHELLVIEWCOLUMNS 4
#define MYCOMPUTERSHELLVIEWCOLUMNS sizeof(mycomputer_header)/sizeof(shvheader)
/**************************************************************************
* ISF_MyComputer_Constructor
@ -809,11 +809,13 @@ static HRESULT WINAPI ISF_MyComputer_fnGetDefaultColumnState (
{
IMyComputerFolderImpl *This = (IMyComputerFolderImpl *)iface;
TRACE ("(%p)\n", This);
TRACE ("(%p)->(%d %p)\n", This, iColumn, pcsFlags);
if (!pcsFlags || iColumn >= MYCOMPUTERSHELLVIEWCOLUMNS)
return E_INVALIDARG;
*pcsFlags = MyComputerSFHeader[iColumn].pcsFlags;
*pcsFlags = mycomputer_header[iColumn].pcsFlags;
return S_OK;
}
@ -826,11 +828,13 @@ static HRESULT WINAPI ISF_MyComputer_fnGetDetailsEx (IShellFolder2 * iface,
}
/* FIXME: drive size >4GB is rolling over */
static HRESULT WINAPI ISF_MyComputer_fnGetDetailsOf (IShellFolder2 * iface,
LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
static HRESULT WINAPI ISF_MyComputer_fnGetDetailsOf (IShellFolder2 *iface,
LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd)
{
IMyComputerFolderImpl *This = (IMyComputerFolderImpl *)iface;
HRESULT hr;
char szPath[MAX_PATH];
ULARGE_INTEGER ulBytes;
HRESULT hr = S_OK;
TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
@ -838,23 +842,13 @@ static HRESULT WINAPI ISF_MyComputer_fnGetDetailsOf (IShellFolder2 * iface,
return E_INVALIDARG;
if (!pidl)
{
psd->fmt = MyComputerSFHeader[iColumn].fmt;
psd->cxChar = MyComputerSFHeader[iColumn].cxChar;
psd->str.uType = STRRET_CSTR;
LoadStringA (shell32_hInstance, MyComputerSFHeader[iColumn].colnameid,
psd->str.u.cStr, MAX_PATH);
return S_OK;
}
else
{
char szPath[MAX_PATH];
ULARGE_INTEGER ulBytes;
return SHELL32_GetColumnDetails(mycomputer_header, iColumn, psd);
psd->str.u.cStr[0] = 0x00;
psd->str.uType = STRRET_CSTR;
switch (iColumn)
{
psd->str.u.cStr[0] = 0;
psd->str.uType = STRRET_CSTR;
switch (iColumn)
{
case 0: /* name */
hr = IShellFolder_GetDisplayNameOf (iface, pidl,
SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
@ -878,8 +872,6 @@ static HRESULT WINAPI ISF_MyComputer_fnGetDetailsOf (IShellFolder2 * iface,
StrFormatByteSizeA (ulBytes.u.LowPart, psd->str.u.cStr, MAX_PATH);
}
break;
}
hr = S_OK;
}
return hr;

View File

@ -65,20 +65,21 @@ typedef struct {
static const IShellFolder2Vtbl vt_ShellFolder2;
static const IPersistFolder2Vtbl vt_NP_PersistFolder2;
#define _ICOM_THIS_From_IPersistFolder2(class, name) class* This = \
(class*)(((char*)name) - FIELD_OFFSET(IGenericSFImpl, lpVtblPersistFolder2))
static inline IGenericSFImpl *impl_from_IPersistFolder2(IPersistFolder2 *iface)
{
return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpVtblPersistFolder2));
}
#define _IUnknown_(This) ((IUnknown*)&(This)->lpVtbl)
#define _IShellFolder_(This) ((IShellFolder*)&(This)->lpVtbl)
#define _IPersistFolder2_(This) (&(This)->lpVtblPersistFolder2)
static const shvheader NetworkPlacesSFHeader[] = {
static const shvheader networkplaces_header[] = {
{IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
{IDS_SHV_COLUMN9, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10}
};
#define NETWORKPLACESSHELLVIEWCOLUMNS 2
#define NETWORKPLACESSHELLVIEWCOLUMNS sizeof(networkplaces_header)/sizeof(shvheader)
/**************************************************************************
* ISF_NetworkPlaces_Constructor
@ -534,11 +535,13 @@ static HRESULT WINAPI ISF_NetworkPlaces_fnGetDefaultColumnState (
{
IGenericSFImpl *This = (IGenericSFImpl *)iface;
TRACE ("(%p)\n", This);
TRACE ("(%p)->(%d %p)\n", This, iColumn, pcsFlags);
if (!pcsFlags || iColumn >= NETWORKPLACESSHELLVIEWCOLUMNS)
return E_INVALIDARG;
*pcsFlags = NetworkPlacesSFHeader[iColumn].pcsFlags;
*pcsFlags = networkplaces_header[iColumn].pcsFlags;
return S_OK;
}
@ -600,7 +603,7 @@ static const IShellFolder2Vtbl vt_ShellFolder2 = {
static HRESULT WINAPI INPFldr_PersistFolder2_QueryInterface (IPersistFolder2 * iface,
REFIID iid, LPVOID * ppvObj)
{
_ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
TRACE ("(%p)\n", This);
@ -612,7 +615,7 @@ static HRESULT WINAPI INPFldr_PersistFolder2_QueryInterface (IPersistFolder2 * i
*/
static ULONG WINAPI INPFldr_PersistFolder2_AddRef (IPersistFolder2 * iface)
{
_ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
TRACE ("(%p)->(count=%u)\n", This, This->ref);
@ -624,7 +627,7 @@ static ULONG WINAPI INPFldr_PersistFolder2_AddRef (IPersistFolder2 * iface)
*/
static ULONG WINAPI INPFldr_PersistFolder2_Release (IPersistFolder2 * iface)
{
_ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
TRACE ("(%p)->(count=%u)\n", This, This->ref);
@ -637,7 +640,7 @@ static ULONG WINAPI INPFldr_PersistFolder2_Release (IPersistFolder2 * iface)
static HRESULT WINAPI INPFldr_PersistFolder2_GetClassID (
IPersistFolder2 * iface, CLSID * lpClassId)
{
_ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
TRACE ("(%p)\n", This);
@ -657,7 +660,7 @@ static HRESULT WINAPI INPFldr_PersistFolder2_GetClassID (
static HRESULT WINAPI INPFldr_PersistFolder2_Initialize (
IPersistFolder2 * iface, LPCITEMIDLIST pidl)
{
_ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
TRACE ("(%p)->(%p)\n", This, pidl);
@ -670,7 +673,7 @@ static HRESULT WINAPI INPFldr_PersistFolder2_Initialize (
static HRESULT WINAPI INPFldr_PersistFolder2_GetCurFolder (
IPersistFolder2 * iface, LPITEMIDLIST * pidl)
{
_ICOM_THIS_From_IPersistFolder2 (IGenericSFImpl, iface);
IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
TRACE ("(%p)->(%p)\n", This, pidl);

View File

@ -303,14 +303,7 @@ static HRESULT WINAPI IShellFolder_Printers_fnGetDetailsOf (IShellFolder2 *iface
return E_NOTIMPL;
if (!pidl)
{
psd->fmt = printers_header[iColumn].fmt;
psd->cxChar = printers_header[iColumn].cxChar;
psd->str.uType = STRRET_CSTR;
LoadStringA (shell32_hInstance, printers_header[iColumn].colnameid,
psd->str.u.cStr, MAX_PATH);
return S_OK;
}
return SHELL32_GetColumnDetails(printers_header, iColumn, psd);
FIXME("unimplemented for supplied pidl\n");

View File

@ -1315,7 +1315,9 @@ static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2* iface
HRESULT hr = E_FAIL;
struct passwd *pPasswd;
struct group *pGroup;
static const shvheader SFHeader[SHELLVIEWCOLUMNS] = {
struct stat statItem;
static const shvheader unixfs_header[SHELLVIEWCOLUMNS] = {
{IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
{IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
{IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
@ -1330,59 +1332,55 @@ static HRESULT WINAPI UnixFolder_IShellFolder2_GetDetailsOf(IShellFolder2* iface
if (!psd || iColumn >= SHELLVIEWCOLUMNS)
return E_INVALIDARG;
if (!pidl) {
psd->fmt = SFHeader[iColumn].fmt;
psd->cxChar = SFHeader[iColumn].cxChar;
psd->str.uType = STRRET_CSTR;
LoadStringA(shell32_hInstance, SFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
return S_OK;
} else {
struct stat statItem;
if (iColumn == 4 || iColumn == 5 || iColumn == 6) {
char szPath[FILENAME_MAX];
strcpy(szPath, This->m_pszPath);
if (!UNIXFS_filename_from_shitemid(pidl, szPath + strlen(szPath)))
return E_INVALIDARG;
if (stat(szPath, &statItem))
return E_INVALIDARG;
}
psd->str.u.cStr[0] = '\0';
psd->str.uType = STRRET_CSTR;
switch (iColumn) {
case 0:
hr = IShellFolder2_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL|SHGDN_INFOLDER, &psd->str);
break;
case 1:
_ILGetFileSize(pidl, psd->str.u.cStr, MAX_PATH);
break;
case 2:
_ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
break;
case 3:
_ILGetFileDate(pidl, psd->str.u.cStr, MAX_PATH);
break;
case 4:
psd->str.u.cStr[0] = S_ISDIR(statItem.st_mode) ? 'd' : '-';
psd->str.u.cStr[1] = (statItem.st_mode & S_IRUSR) ? 'r' : '-';
psd->str.u.cStr[2] = (statItem.st_mode & S_IWUSR) ? 'w' : '-';
psd->str.u.cStr[3] = (statItem.st_mode & S_IXUSR) ? 'x' : '-';
psd->str.u.cStr[4] = (statItem.st_mode & S_IRGRP) ? 'r' : '-';
psd->str.u.cStr[5] = (statItem.st_mode & S_IWGRP) ? 'w' : '-';
psd->str.u.cStr[6] = (statItem.st_mode & S_IXGRP) ? 'x' : '-';
psd->str.u.cStr[7] = (statItem.st_mode & S_IROTH) ? 'r' : '-';
psd->str.u.cStr[8] = (statItem.st_mode & S_IWOTH) ? 'w' : '-';
psd->str.u.cStr[9] = (statItem.st_mode & S_IXOTH) ? 'x' : '-';
psd->str.u.cStr[10] = '\0';
break;
case 5:
pPasswd = getpwuid(statItem.st_uid);
if (pPasswd) strcpy(psd->str.u.cStr, pPasswd->pw_name);
break;
case 6:
pGroup = getgrgid(statItem.st_gid);
if (pGroup) strcpy(psd->str.u.cStr, pGroup->gr_name);
break;
}
if (!pidl)
return SHELL32_GetColumnDetails(unixfs_header, iColumn, psd);
if (iColumn == 4 || iColumn == 5 || iColumn == 6) {
char szPath[FILENAME_MAX];
strcpy(szPath, This->m_pszPath);
if (!UNIXFS_filename_from_shitemid(pidl, szPath + strlen(szPath)))
return E_INVALIDARG;
if (stat(szPath, &statItem))
return E_INVALIDARG;
}
psd->str.u.cStr[0] = '\0';
psd->str.uType = STRRET_CSTR;
switch (iColumn) {
case 0:
hr = IShellFolder2_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL|SHGDN_INFOLDER, &psd->str);
break;
case 1:
_ILGetFileSize(pidl, psd->str.u.cStr, MAX_PATH);
break;
case 2:
_ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
break;
case 3:
_ILGetFileDate(pidl, psd->str.u.cStr, MAX_PATH);
break;
case 4:
psd->str.u.cStr[0] = S_ISDIR(statItem.st_mode) ? 'd' : '-';
psd->str.u.cStr[1] = (statItem.st_mode & S_IRUSR) ? 'r' : '-';
psd->str.u.cStr[2] = (statItem.st_mode & S_IWUSR) ? 'w' : '-';
psd->str.u.cStr[3] = (statItem.st_mode & S_IXUSR) ? 'x' : '-';
psd->str.u.cStr[4] = (statItem.st_mode & S_IRGRP) ? 'r' : '-';
psd->str.u.cStr[5] = (statItem.st_mode & S_IWGRP) ? 'w' : '-';
psd->str.u.cStr[6] = (statItem.st_mode & S_IXGRP) ? 'x' : '-';
psd->str.u.cStr[7] = (statItem.st_mode & S_IROTH) ? 'r' : '-';
psd->str.u.cStr[8] = (statItem.st_mode & S_IWOTH) ? 'w' : '-';
psd->str.u.cStr[9] = (statItem.st_mode & S_IXOTH) ? 'x' : '-';
psd->str.u.cStr[10] = '\0';
break;
case 5:
pPasswd = getpwuid(statItem.st_uid);
if (pPasswd) strcpy(psd->str.u.cStr, pPasswd->pw_name);
break;
case 6:
pGroup = getgrgid(statItem.st_gid);
if (pGroup) strcpy(psd->str.u.cStr, pGroup->gr_name);
break;
}
return hr;

View File

@ -30,6 +30,8 @@
#include <stdio.h>
#define COBJMACROS
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include "winerror.h"
#include "windef.h"
@ -542,6 +544,16 @@ HRESULT SHELL32_CompareIDs (IShellFolder * iface, LPARAM lParam, LPCITEMIDLIST p
return nReturn;
}
HRESULT SHELL32_GetColumnDetails(const shvheader *data, int column, SHELLDETAILS *details)
{
details->fmt = data[column].fmt;
details->cxChar = data[column].cxChar;
details->str.uType = STRRET_CSTR;
LoadStringA (shell32_hInstance, data[column].colnameid, details->str.u.cStr, MAX_PATH);
return S_OK;
}
/***********************************************************************
* SHCreateLinks
*