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.

422 lines
7.1 KiB

  1. //
  2. // Copyright 2001 - Microsoft Corporation
  3. //
  4. //
  5. // Created By:
  6. // Geoff Pease (GPease) 23-JAN-2001
  7. //
  8. // Maintained By:
  9. // Geoff Pease (GPease) 23-JAN-2001
  10. //
  11. #include "pch.h"
  12. #include "DocProp.h"
  13. #include "DefProp.h"
  14. #include "IEditVariantsInPlace.h"
  15. #include "PropertyCacheItem.h"
  16. #include "PropertyCache.h"
  17. #include "AdvancedDlg.h"
  18. #include "SimpleDlg.h"
  19. #include "SummaryPage.h"
  20. #pragma hdrstop
  21. DEFINE_THISCLASS( "CDocPropShExt" )
  22. // ************************************************************************
  23. //
  24. // Constructor / Destructor
  25. //
  26. // ************************************************************************
  27. //
  28. //
  29. //
  30. HRESULT
  31. CDocPropShExt::CreateInstance(
  32. IUnknown ** ppunkOut
  33. )
  34. {
  35. TraceFunc( "" );
  36. HRESULT hr;
  37. Assert( ppunkOut != NULL );
  38. CDocPropShExt * pthis = new CDocPropShExt;
  39. if ( pthis != NULL )
  40. {
  41. hr = THR( pthis->Init( ) );
  42. if ( SUCCEEDED( hr ) )
  43. {
  44. *ppunkOut = (IShellExtInit *) pthis;
  45. (*ppunkOut)->AddRef( );
  46. }
  47. pthis->Release( );
  48. }
  49. else
  50. {
  51. hr = E_OUTOFMEMORY;
  52. }
  53. HRETURN( hr );
  54. }
  55. //
  56. //
  57. //
  58. CDocPropShExt::CDocPropShExt( void )
  59. : _cRef( 1 )
  60. {
  61. TraceFunc( "" );
  62. InterlockedIncrement( &g_cObjects );
  63. TraceFuncExit();
  64. }
  65. //
  66. //
  67. //
  68. HRESULT
  69. CDocPropShExt::Init( void )
  70. {
  71. TraceFunc( "" );
  72. HRESULT hr = S_OK;
  73. // IUnknown stuff
  74. Assert( _cRef == 1 );
  75. // IShellExtInit stuff
  76. // IShellPropSheetExt stuff
  77. HRETURN( hr );
  78. }
  79. //
  80. //
  81. //
  82. CDocPropShExt::~CDocPropShExt( )
  83. {
  84. TraceFunc( "" );
  85. if ( NULL != _punkSummary )
  86. {
  87. _punkSummary->Release( );
  88. }
  89. InterlockedDecrement( &g_cObjects );
  90. TraceFuncExit();
  91. }
  92. //
  93. //
  94. //
  95. HRESULT
  96. CDocPropShExt::RegisterShellExtensions(
  97. BOOL fRegisterIn
  98. )
  99. {
  100. TraceFunc( "" );
  101. HRESULT hr;
  102. LONG lr;
  103. LPTSTR psz;
  104. DWORD cbSize;
  105. HKEY hkeyHandlers = NULL;
  106. HKEY hkeySummary = NULL;
  107. LPOLESTR pszCLSID = NULL;
  108. const TCHAR szSummaryPropertyPageExtName[] = TEXT("Summary Properties Page");
  109. //
  110. // Convert the CLSID to a string
  111. //
  112. hr = THR( StringFromCLSID( CLSID_DocPropShellExtension, &pszCLSID ) );
  113. if ( FAILED( hr ) )
  114. goto Cleanup;
  115. #ifdef UNICODE
  116. psz = pszCLSID;
  117. #else // ASCII
  118. CHAR szCLSID[ 40 ];
  119. wcstombs( szCLSID, pszCLSID, StrLenW( pszCLSID ) + 1 );
  120. psz = szCLSID;
  121. #endif // UNICODE
  122. //
  123. // Open the "*\shellex\PropertySheetHandlers" under HKCR
  124. //
  125. lr = TW32( RegOpenKey( HKEY_CLASSES_ROOT, TEXT("*\\shellex\\PropertySheetHandlers"), &hkeyHandlers ) );
  126. if ( ERROR_SUCCESS != lr )
  127. goto Win32Error;
  128. //
  129. // Create the CLSID key
  130. //
  131. lr = TW32( RegCreateKey( hkeyHandlers, psz, &hkeySummary ) );
  132. if ( ERROR_SUCCESS != lr )
  133. goto Win32Error;
  134. //
  135. // Give the default property a non-localizable name
  136. //
  137. cbSize = sizeof(szSummaryPropertyPageExtName);
  138. lr = TW32( RegSetValueEx( hkeySummary, NULL, 0, REG_SZ, (LPBYTE) szSummaryPropertyPageExtName, cbSize ) );
  139. if ( ERROR_SUCCESS != lr )
  140. goto Win32Error;
  141. Cleanup:
  142. if ( NULL != pszCLSID )
  143. {
  144. CoTaskMemFree( pszCLSID );
  145. }
  146. if ( NULL != hkeyHandlers )
  147. {
  148. RegCloseKey( hkeyHandlers );
  149. }
  150. if ( NULL != hkeySummary )
  151. {
  152. RegCloseKey( hkeySummary );
  153. }
  154. HRETURN( hr );
  155. Win32Error:
  156. hr = HRESULT_FROM_WIN32( lr );
  157. goto Cleanup;
  158. }
  159. // ************************************************************************
  160. //
  161. // IUnknown
  162. //
  163. // ************************************************************************
  164. //
  165. //
  166. //
  167. STDMETHODIMP
  168. CDocPropShExt::QueryInterface(
  169. REFIID riid,
  170. LPVOID *ppv
  171. )
  172. {
  173. TraceQIFunc( riid, ppv );
  174. HRESULT hr = E_NOINTERFACE;
  175. if ( IsEqualIID( riid, __uuidof(IUnknown) ) )
  176. {
  177. *ppv = static_cast< IShellExtInit * >( this );
  178. hr = S_OK;
  179. }
  180. else if ( IsEqualIID( riid, __uuidof(IShellExtInit) ) )
  181. {
  182. *ppv = TraceInterface( __THISCLASS__, IShellExtInit, this, 0 );
  183. hr = S_OK;
  184. }
  185. else if ( IsEqualIID( riid, __uuidof(IShellPropSheetExt) ) )
  186. {
  187. *ppv = TraceInterface( __THISCLASS__, IShellPropSheetExt, this, 0 );
  188. hr = S_OK;
  189. }
  190. if ( SUCCEEDED( hr ) )
  191. {
  192. ((IUnknown*) *ppv)->AddRef( );
  193. }
  194. QIRETURN( hr, riid );
  195. }
  196. //
  197. //
  198. //
  199. STDMETHODIMP_(ULONG)
  200. CDocPropShExt::AddRef( void )
  201. {
  202. TraceFunc( "[IUnknown]" );
  203. _cRef ++; // apartment
  204. RETURN( _cRef );
  205. }
  206. //
  207. //
  208. //
  209. STDMETHODIMP_(ULONG)
  210. CDocPropShExt::Release( void )
  211. {
  212. TraceFunc( "[IUnknown]" );
  213. _cRef --; // apartment
  214. if ( 0 != _cRef )
  215. RETURN( _cRef );
  216. delete this;
  217. RETURN( 0 );
  218. }
  219. // ************************************************************************
  220. //
  221. // IShellExtInit
  222. //
  223. // ************************************************************************
  224. //
  225. //
  226. //
  227. STDMETHODIMP
  228. CDocPropShExt::Initialize(
  229. LPCITEMIDLIST pidlFolderIn
  230. , LPDATAOBJECT lpdobjIn
  231. , HKEY hkeyProgIDIn
  232. )
  233. {
  234. TraceFunc( "" );
  235. HRESULT hr;
  236. HRESULT hrResult = E_FAIL; // returned to caller - assume failure
  237. hr = THR( CSummaryPage::CreateInstance( &_punkSummary ) );
  238. if ( S_OK == hr )
  239. {
  240. IShellExtInit * psei;
  241. hr = THR( _punkSummary->TYPESAFEQI( psei ) );
  242. if ( S_OK == hr )
  243. {
  244. hr = THR( psei->Initialize( pidlFolderIn, lpdobjIn, hkeyProgIDIn ) );
  245. if ( S_OK == hr )
  246. {
  247. hrResult = S_OK;
  248. }
  249. psei->Release( );
  250. }
  251. }
  252. //
  253. // TODO: gpease 23-JAN-2001
  254. // Add additional pages here.
  255. //
  256. HRETURN( hrResult );
  257. }
  258. // ************************************************************************
  259. //
  260. // IShellPropSheetExt
  261. //
  262. // ************************************************************************
  263. //
  264. //
  265. //
  266. STDMETHODIMP
  267. CDocPropShExt::AddPages(
  268. LPFNADDPROPSHEETPAGE lpfnAddPageIn
  269. , LPARAM lParam
  270. )
  271. {
  272. TraceFunc( "" );
  273. HRESULT hr;
  274. IShellPropSheetExt * pspse = NULL;
  275. //
  276. // Check state
  277. //
  278. if ( NULL == _punkSummary )
  279. goto InvalidState;
  280. //
  281. // Add the Summary Page
  282. //
  283. hr = THR( _punkSummary->TYPESAFEQI( pspse ) );
  284. if ( S_OK != hr )
  285. goto Cleanup;
  286. hr = THR( pspse->AddPages( lpfnAddPageIn, lParam ) );
  287. if ( FAILED( hr ) )
  288. goto Cleanup;
  289. // release to reuse
  290. pspse->Release( );
  291. pspse = NULL;
  292. //
  293. // TODO: gpease 23-JAN-2001
  294. // Add additional pages here.
  295. //
  296. Cleanup:
  297. if ( NULL != pspse )
  298. {
  299. pspse->Release( );
  300. }
  301. HRETURN( hr );
  302. InvalidState:
  303. hr = THR( E_UNEXPECTED ); // REVIEW: gpease 23-JAN-2001 * Is there a better error code?
  304. goto Cleanup;
  305. }
  306. //
  307. //
  308. //
  309. STDMETHODIMP
  310. CDocPropShExt::ReplacePage(
  311. UINT uPageIDIn
  312. , LPFNADDPROPSHEETPAGE lpfnReplacePageIn
  313. , LPARAM lParam
  314. )
  315. {
  316. TraceFunc( "" );
  317. HRESULT hr = THR( E_NOTIMPL );
  318. HRETURN( hr );
  319. }
  320. // ***************************************************************************
  321. //
  322. // Private methods
  323. //
  324. // ***************************************************************************