Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

375 lines
8.4 KiB

  1. /*
  2. * ftps.cpp - File Types property sheet implementation for MIME types.
  3. */
  4. /* Headers
  5. **********/
  6. #include "project.hpp"
  7. #pragma hdrstop
  8. #include <mluisupp.h>
  9. #include <ispriv.h>
  10. #include "clsfact.h"
  11. extern "C"
  12. {
  13. #include "filetype.h"
  14. }
  15. #include "ftps.hpp"
  16. #include "resource.h"
  17. #include "urlshell.h"
  18. #ifdef WINNT
  19. #include <shlguidp.h>
  20. #else
  21. #include <shlguid.h>
  22. #endif
  23. /****************************** Public Functions *****************************/
  24. #ifdef DEBUG
  25. PUBLIC_CODE BOOL IsValidPCMIMEHook(PCMIMEHook pcmimehk)
  26. {
  27. return(IS_VALID_READ_PTR(pcmimehk, CMIMEHook) &&
  28. IS_VALID_STRUCT_PTR((PCRefCount)pcmimehk, CRefCount) &&
  29. IS_VALID_INTERFACE_PTR((PCIShellExtInit)pcmimehk, IShellExtInit) &&
  30. IS_VALID_INTERFACE_PTR((PCIShellPropSheetExt)pcmimehk, IShellPropSheetExt));
  31. }
  32. #endif
  33. #pragma warning(disable:4100) /* "unreferenced formal parameter" warning */
  34. PRIVATE_CODE UINT CALLBACK MIMEFileTypesPSCallback(HWND hwnd, UINT uMsg,
  35. LPPROPSHEETPAGE ppsp)
  36. {
  37. UINT uResult = TRUE;
  38. // uMsg may be any value.
  39. ASSERT(! hwnd ||
  40. IS_VALID_HANDLE(hwnd, WND));
  41. ASSERT(IS_VALID_STRUCT_PTR(ppsp, CPROPSHEETPAGE));
  42. switch (uMsg)
  43. {
  44. case PSPCB_CREATE:
  45. TRACE_OUT(("MIMEFileTypesPSCallback(): Received PSPCB_CREATE."));
  46. break;
  47. case PSPCB_RELEASE:
  48. TRACE_OUT(("MIMEFileTypesPSCallback(): Received PSPCB_RELEASE."));
  49. delete (PFILETYPESDIALOGINFO)(ppsp->lParam);
  50. ppsp->lParam = NULL;
  51. break;
  52. default:
  53. TRACE_OUT(("MIMEFileTypesPSCallback(): Unhandled message %u.",
  54. uMsg));
  55. break;
  56. }
  57. return(uResult);
  58. }
  59. #pragma warning(default:4100) /* "unreferenced formal parameter" warning */
  60. /********************************** Methods **********************************/
  61. MIMEHook::MIMEHook(void)
  62. {
  63. DebugEntry(MIMEHook::MIMEHook);
  64. // Don't validate this until after construction.
  65. ASSERT(IS_VALID_STRUCT_PTR(this, CMIMEHook));
  66. DebugExitVOID(MIMEHook::MIMEHook);
  67. return;
  68. }
  69. MIMEHook::~MIMEHook(void)
  70. {
  71. DebugEntry(MIMEHook::~MIMEHook);
  72. ASSERT(IS_VALID_STRUCT_PTR(this, CMIMEHook));
  73. DebugExitVOID(MIMEHook::~MIMEHook);
  74. return;
  75. }
  76. ULONG STDMETHODCALLTYPE MIMEHook::AddRef(void)
  77. {
  78. ULONG ulcRef;
  79. DebugEntry(MIMEHook::AddRef);
  80. ASSERT(IS_VALID_STRUCT_PTR(this, CMIMEHook));
  81. ulcRef = RefCount::AddRef();
  82. ASSERT(IS_VALID_STRUCT_PTR(this, CMIMEHook));
  83. DebugExitULONG(MIMEHook::AddRef, ulcRef);
  84. return(ulcRef);
  85. }
  86. ULONG STDMETHODCALLTYPE MIMEHook::Release(void)
  87. {
  88. ULONG ulcRef;
  89. DebugEntry(MIMEHook::Release);
  90. ASSERT(IS_VALID_STRUCT_PTR(this, CMIMEHook));
  91. ulcRef = RefCount::Release();
  92. DebugExitULONG(MIMEHook::Release, ulcRef);
  93. return(ulcRef);
  94. }
  95. HRESULT STDMETHODCALLTYPE MIMEHook::QueryInterface(REFIID riid,
  96. PVOID *ppvObject)
  97. {
  98. HRESULT hr = S_OK;
  99. DebugEntry(MIMEHook::QueryInterface);
  100. ASSERT(IS_VALID_STRUCT_PTR(this, CMIMEHook));
  101. ASSERT(IsValidREFIID(riid));
  102. ASSERT(IS_VALID_WRITE_PTR(ppvObject, PVOID));
  103. if (riid == IID_IShellPropSheetExt)
  104. {
  105. *ppvObject = (PIShellPropSheetExt)this;
  106. TRACE_OUT(("MIMEHook::QueryInterface(): Returning IShellPropSheetExt."));
  107. }
  108. else if (riid == IID_IShellExtInit)
  109. {
  110. *ppvObject = (PIShellExtInit)this;
  111. TRACE_OUT(("MIMEHook::QueryInterface(): Returning IShellExtInit."));
  112. }
  113. else if (riid == IID_IUnknown)
  114. {
  115. *ppvObject = (PIUnknown)(PIShellPropSheetExt)this;
  116. TRACE_OUT(("MIMEHook::QueryInterface(): Returning IUnknown."));
  117. }
  118. else
  119. {
  120. TRACE_OUT(("MIMEHook::QueryInterface(): Called on unknown interface."));
  121. *ppvObject = NULL;
  122. hr = E_NOINTERFACE;
  123. }
  124. if (hr == S_OK)
  125. AddRef();
  126. ASSERT(IS_VALID_STRUCT_PTR(this, CMIMEHook));
  127. DebugExitHRESULT(MIMEHook::QueryInterface, hr);
  128. return(hr);
  129. }
  130. #pragma warning(disable:4100) /* "unreferenced formal parameter" warning */
  131. HRESULT STDMETHODCALLTYPE MIMEHook::Initialize(LPCITEMIDLIST pidlFolder,
  132. IDataObject *pdtobj,
  133. HKEY hkeyProgID)
  134. {
  135. HRESULT hr;
  136. DebugEntry(MIMEHook::Initialize);
  137. ASSERT(IS_VALID_STRUCT_PTR(this, CMIMEHook));
  138. hr = S_OK;
  139. ASSERT(IS_VALID_STRUCT_PTR(this, CMIMEHook));
  140. DebugExitHRESULT(MIMEHook::Initialize, hr);
  141. return(hr);
  142. }
  143. #pragma warning(disable:4100) /* "unreferenced formal parameter" warning */
  144. HRESULT STDMETHODCALLTYPE MIMEHook::AddPages(LPFNADDPROPSHEETPAGE pfnAddPage,
  145. LPARAM lparam)
  146. {
  147. HRESULT hr;
  148. DebugEntry(MIMEHook::AddPages);
  149. // lparam may be any value.
  150. ASSERT(IS_VALID_STRUCT_PTR(this, CMIMEHook));
  151. ASSERT(IS_VALID_CODE_PTR(pfnAddPage, LPFNADDPROPSHEETPAGE));
  152. hr = E_FAIL;
  153. ASSERT(IS_VALID_STRUCT_PTR(this, CMIMEHook));
  154. DebugExitHRESULT(MIMEHook::AddPages, hr);
  155. return(hr);
  156. }
  157. #pragma warning(default:4100) /* "unreferenced formal parameter" warning */
  158. HRESULT STDMETHODCALLTYPE MIMEHook::ReplacePage(
  159. UINT uPageID,
  160. LPFNADDPROPSHEETPAGE pfnReplaceWith,
  161. LPARAM lparam)
  162. {
  163. HRESULT hr;
  164. DebugEntry(MIMEHook::ReplacePage);
  165. // lparam may be any value.
  166. // uPageID is checked below.
  167. ASSERT(IS_VALID_STRUCT_PTR(this, CMIMEHook));
  168. ASSERT(IS_VALID_CODE_PTR(pfnReplaceWith, LPFNADDPROPSHEETPAGE));
  169. if (EVAL(uPageID == EXPPS_FILETYPES))
  170. {
  171. TRACE_OUT(("MIMEHook::ReplacePage(): Replacing File Types property sheet."));
  172. hr = AddMIMEFileTypesPS(pfnReplaceWith, lparam);
  173. }
  174. else
  175. {
  176. TRACE_OUT(("MIMEHook::ReplacePage(): Not replacing unknown property sheet %u.",
  177. uPageID));
  178. hr = E_FAIL;
  179. }
  180. ASSERT(IS_VALID_STRUCT_PTR(this, CMIMEHook));
  181. DebugExitHRESULT(MIMEHook::ReplacePage, hr);
  182. return(hr);
  183. }
  184. /***************************** Exported Functions ****************************/
  185. INTSHCUTPRIVAPI HRESULT WINAPI AddMIMEFileTypesPS(LPFNADDPROPSHEETPAGE pfnAddPage,
  186. LPARAM lparam)
  187. {
  188. HRESULT hr = E_OUTOFMEMORY;
  189. PFILETYPESDIALOGINFO pFTDInfo;
  190. IShellPropSheetExt* pspse;
  191. // Try to bind to shell32 to gain the file types box, if this works then we
  192. // don't need to give them our ANSI implementation.
  193. hr = SHCoCreateInstance(NULL, &CLSID_FileTypes, NULL, IID_IShellPropSheetExt, (LPVOID*)&pspse);
  194. if (SUCCEEDED(hr))
  195. {
  196. hr = pspse->AddPages(pfnAddPage, lparam);
  197. pspse->Release();
  198. }
  199. else
  200. {
  201. // lparam may be any value.
  202. ASSERT(IS_VALID_CODE_PTR(pfnAddPage, LPFNADDPROPSHEETPAGE));
  203. pFTDInfo = new(FILETYPESDIALOGINFO);
  204. if (pFTDInfo)
  205. {
  206. PROPSHEETPAGE psp;
  207. HPROPSHEETPAGE hpsp;
  208. ZeroMemory(pFTDInfo, sizeof(*pFTDInfo));
  209. psp.dwSize = sizeof(psp);
  210. psp.dwFlags = (PSP_DEFAULT | PSP_USECALLBACK | PSP_USEREFPARENT);
  211. psp.hInstance = MLGetHinst();
  212. psp.pszTemplate = MAKEINTRESOURCE(DLG_FILETYPEOPTIONS);
  213. psp.hIcon = NULL;
  214. psp.pszTitle = NULL;
  215. psp.pfnDlgProc = &FT_DlgProc;
  216. psp.lParam = (LPARAM)pFTDInfo;
  217. psp.pfnCallback = &MIMEFileTypesPSCallback;
  218. psp.pcRefParent = (PUINT)GetDLLRefCountPtr();
  219. ASSERT(IS_VALID_STRUCT_PTR(&psp, CPROPSHEETPAGE));
  220. hpsp = CreatePropertySheetPage(&psp);
  221. if (hpsp)
  222. {
  223. if ((*pfnAddPage)(hpsp, lparam))
  224. {
  225. hr = S_OK;
  226. TRACE_OUT(("AddMIMEFileTypesPS(): Added MIME File Types property sheet."));
  227. }
  228. else
  229. {
  230. DestroyPropertySheetPage(hpsp);
  231. hr = E_FAIL;
  232. WARNING_OUT(("AddMIMEFileTypesPS(): Callback to add property sheet failed."));
  233. }
  234. }
  235. if (hr != S_OK)
  236. {
  237. LocalFree(pFTDInfo);
  238. pFTDInfo = NULL;
  239. }
  240. }
  241. }
  242. return(hr);
  243. }
  244. extern "C"
  245. STDAPI CreateInstance_MIMEHook(IUnknown *punkOuter, REFIID riid, void **ppvOut)
  246. {
  247. HRESULT hres;
  248. *ppvOut = NULL;
  249. if (punkOuter)
  250. return CLASS_E_NOAGGREGATION;
  251. MIMEHook *phook = new(MIMEHook);
  252. if (phook)
  253. {
  254. hres = phook->QueryInterface(riid, ppvOut);
  255. phook->Release();
  256. }
  257. else
  258. hres = E_OUTOFMEMORY;
  259. return hres;
  260. }