ReactOS  0.4.15-dev-994-ga9f6032
fprop.cpp
Go to the documentation of this file.
1 /*
2  * Shell Library Functions
3  *
4  * Copyright 2005 Johannes Anderwald
5  * Copyright 2012 Rafal Harabien
6  * Copyright 2017-2018 Katayama Hirofumi MZ
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "precomp.h"
24 
26 
27 EXTERN_C HPSXA WINAPI SHCreatePropSheetExtArrayEx(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface, IDataObject *pDataObj);
28 
29 static UINT
30 LoadPropSheetHandlers(LPCWSTR pwszPath, PROPSHEETHEADERW *pHeader, UINT cMaxPages, HPSXA *phpsxa, IDataObject *pDataObj)
31 {
32  WCHAR wszBuf[MAX_PATH];
33  UINT cPages = 0, i = 0;
34 
35  LPWSTR pwszFilename = PathFindFileNameW(pwszPath);
36  BOOL bDir = PathIsDirectoryW(pwszPath);
37 
38  if (bDir)
39  {
40  phpsxa[i] = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, L"Folder", cMaxPages - cPages, pDataObj);
41  cPages += SHAddFromPropSheetExtArray(phpsxa[i++], AddPropSheetPageCallback, (LPARAM)pHeader);
42 
43  phpsxa[i] = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, L"Directory", cMaxPages - cPages, pDataObj);
44  cPages += SHAddFromPropSheetExtArray(phpsxa[i++], AddPropSheetPageCallback, (LPARAM)pHeader);
45  }
46  else
47  {
48  /* Load property sheet handlers from ext key */
49  LPWSTR pwszExt = PathFindExtensionW(pwszFilename);
50  phpsxa[i] = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, pwszExt, cMaxPages - cPages, pDataObj);
51  cPages += SHAddFromPropSheetExtArray(phpsxa[i++], AddPropSheetPageCallback, (LPARAM)pHeader);
52 
53  /* Load property sheet handlers from prog id key */
54  DWORD cbBuf = sizeof(wszBuf);
55  if (RegGetValueW(HKEY_CLASSES_ROOT, pwszExt, L"", RRF_RT_REG_SZ, NULL, wszBuf, &cbBuf) == ERROR_SUCCESS)
56  {
57  TRACE("EnumPropSheetExt wszBuf %s, pwszExt %s\n", debugstr_w(wszBuf), debugstr_w(pwszExt));
58  phpsxa[i] = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, wszBuf, cMaxPages - cPages, pDataObj);
59  cPages += SHAddFromPropSheetExtArray(phpsxa[i++], AddPropSheetPageCallback, (LPARAM)pHeader);
60  }
61 
62  /* Add property sheet handlers from "*" key */
63  phpsxa[i] = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, L"*", cMaxPages - cPages, pDataObj);
64  cPages += SHAddFromPropSheetExtArray(phpsxa[i++], AddPropSheetPageCallback, (LPARAM)pHeader);
65  }
66 
67  return cPages;
68 }
69 
70 /*************************************************************************
71  *
72  * SH_ShowPropertiesDialog
73  *
74  * called from ShellExecuteExW32
75  *
76  * pwszPath contains path of folder/file
77  *
78  * TODO: provide button change application type if file has registered type
79  * make filename field editable and apply changes to filename on close
80  */
81 
82 BOOL
84 {
85  HPSXA hpsxa[3] = {NULL, NULL, NULL};
86  CComObject<CFileDefExt> *pFileDefExt = NULL;
87 
88  TRACE("SH_ShowPropertiesDialog entered filename %s\n", debugstr_w(pwszPath));
89 
90  if (pwszPath == NULL || !wcslen(pwszPath))
91  return FALSE;
92 
94  memset(hppages, 0x0, sizeof(HPROPSHEETPAGE) * MAX_PROPERTY_SHEET_PAGE);
95 
96  /* Make a copy of path */
97  WCHAR wszPath[MAX_PATH];
98  StringCbCopyW(wszPath, sizeof(wszPath), pwszPath);
99 
100  /* remove trailing \\ at the end of path */
101  PathRemoveBackslashW(wszPath);
102 
103  /* Handle drives */
104  if (PathIsRootW(wszPath))
105  return SUCCEEDED(SH_ShowDriveProperties(wszPath, pidlFolder, apidl));
106 
110  if (!stub.Create(NULL, NULL, NULL, style, exstyle))
111  {
112  ERR("StubWindow32 creation failed\n");
113  return FALSE;
114  }
115 
116  /* Handle files and folders */
118  memset(&Header, 0x0, sizeof(PROPSHEETHEADERW));
119  Header.dwSize = sizeof(PROPSHEETHEADERW);
120  Header.hwndParent = stub;
121  Header.dwFlags = PSH_NOCONTEXTHELP | PSH_PROPTITLE;
122  Header.phpage = hppages;
123  Header.pszCaption = PathFindFileNameW(wszPath);
124 
125  CComPtr<IDataObject> pDataObj;
126  HRESULT hr = SHCreateDataObject(pidlFolder, 1, apidl, NULL, IID_PPV_ARG(IDataObject, &pDataObj));
127 
128  if (SUCCEEDED(hr))
129  {
130  hr = CComObject<CFileDefExt>::CreateInstance(&pFileDefExt);
131  if (SUCCEEDED(hr))
132  {
133  pFileDefExt->AddRef(); // CreateInstance returns object with 0 ref count
134  hr = pFileDefExt->Initialize(pidlFolder, pDataObj, NULL);
135  if (SUCCEEDED(hr))
136  {
137  hr = pFileDefExt->AddPages(AddPropSheetPageCallback, (LPARAM)&Header);
138  if (FAILED(hr))
139  ERR("AddPages failed\n");
140  } else
141  ERR("Initialize failed\n");
142  }
143 
144  LoadPropSheetHandlers(wszPath, &Header, MAX_PROPERTY_SHEET_PAGE - 1, hpsxa, pDataObj);
145  }
146 
148 
149  for (UINT i = 0; i < 3; ++i)
150  if (hpsxa[i])
152  if (pFileDefExt)
153  pFileDefExt->Release();
154 
155  stub.DestroyWindow();
156 
157  return (Result != -1);
158 }
159 
160 /*EOF */
LSTATUS WINAPI RegGetValueW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData)
Definition: reg.c:1965
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
void WINAPI SHDestroyPropSheetExtArray(HPSXA hpsxa)
Definition: shellord.c:2162
#define WS_DISABLED
Definition: pedump.c:621
BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
Definition: path.c:1702
#define WS_EX_WINDOWEDGE
Definition: winuser.h:407
WINE_DEFAULT_DEBUG_CHANNEL(shell)
BOOL CALLBACK AddPropSheetPageCallback(HPROPSHEETPAGE hPage, LPARAM lParam)
Definition: precomp.h:128
#define ERROR_SUCCESS
Definition: deptool.c:10
HRESULT hr
Definition: shlfolder.c:183
GLint x0
Definition: linetemp.h:95
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
HRESULT WINAPI SHCreateDataObject(PCIDLIST_ABSOLUTE pidlFolder, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, IDataObject *pdtInner, REFIID riid, void **ppv)
static UINT LoadPropSheetHandlers(LPCWSTR pwszPath, PROPSHEETHEADERW *pHeader, UINT cMaxPages, HPSXA *phpsxa, IDataObject *pDataObj)
Definition: fprop.cpp:30
UINT WINAPI SHAddFromPropSheetExtArray(HPSXA hpsxa, LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
Definition: shellord.c:1984
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
Definition: stubgen.c:11
#define RRF_RT_REG_SZ
Definition: driver.c:575
struct _PROPSHEETHEADERW PROPSHEETHEADERW
int32_t INT_PTR
Definition: typedefs.h:64
#define IID_PPV_ARG(Itype, ppType)
struct _stub stub
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FALSE
Definition: types.h:117
const PCUITEMID_CHILD * PCUITEMID_CHILD_ARRAY
Definition: shtypes.idl:71
Definition: Header.h:8
unsigned int BOOL
Definition: ntddk_ex.h:94
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
#define debugstr_w
Definition: kernel32.h:32
EXTERN_C HPSXA WINAPI SHCreatePropSheetExtArrayEx(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface, IDataObject *pDataObj)
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:389
LONG_PTR LPARAM
Definition: windef.h:208
INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
Definition: propsheet.c:2905
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:442
#define WS_CAPTION
Definition: pedump.c:624
BOOL WINAPI PathIsRootW(LPCWSTR lpszPath)
Definition: path.c:1621
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define PSH_PROPTITLE
Definition: prsht.h:40
LONG HRESULT
Definition: typedefs.h:79
#define MAX_PATH
Definition: compat.h:34
#define WINAPI
Definition: msvc.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL SH_ShowPropertiesDialog(LPCWSTR pwszPath, LPCITEMIDLIST pidlFolder, PCUITEMID_CHILD_ARRAY apidl)
Definition: fprop.cpp:83
static const WCHAR L[]
Definition: oid.c:1250
LPWSTR WINAPI PathRemoveBackslashW(LPWSTR lpszPath)
Definition: path.c:862
#define ERR(fmt,...)
Definition: debug.h:110
HRESULT SH_ShowDriveProperties(WCHAR *pwszDrive, LPCITEMIDLIST pidlFolder, PCUITEMID_CHILD_ARRAY apidl)
Definition: drive.cpp:120
void shell(int argc, const char *argv[])
Definition: cmds.c:1231
unsigned int UINT
Definition: ndis.h:50
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define WS_EX_APPWINDOW
Definition: winuser.h:383
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define EXTERN_C
Definition: basetyps.h:12
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
Arabic default style
Definition: afstyles.h:93
#define memset(x, y, z)
Definition: compat.h:39
#define MAX_PROPERTY_SHEET_PAGE
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define SUCCEEDED(hr)
Definition: intsafe.h:57