Leaked source code of windows server 2003
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.

423 lines
7.6 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. Assert( 0 != g_cObjects );
  90. InterlockedDecrement( &g_cObjects );
  91. TraceFuncExit();
  92. }
  93. //
  94. //
  95. //
  96. HRESULT
  97. CDocPropShExt::RegisterShellExtensions(
  98. BOOL fRegisterIn
  99. )
  100. {
  101. TraceFunc( "" );
  102. HRESULT hr;
  103. LONG lr;
  104. LPTSTR psz;
  105. DWORD cbSize;
  106. HKEY hkeyHandlers = NULL;
  107. HKEY hkeySummary = NULL;
  108. LPOLESTR pszCLSID = NULL;
  109. const TCHAR szSummaryPropertyPageExtName[] = TEXT("Summary Properties Page");
  110. //
  111. // Convert the CLSID to a string
  112. //
  113. hr = THR( StringFromCLSID( CLSID_DocPropShellExtension, &pszCLSID ) );
  114. if ( FAILED( hr ) )
  115. goto Cleanup;
  116. #ifdef UNICODE
  117. psz = pszCLSID;
  118. #else // ASCII
  119. CHAR szCLSID[ 40 ];
  120. wcstombs( szCLSID, pszCLSID, StrLenW( pszCLSID ) + 1 );
  121. psz = szCLSID;
  122. #endif // UNICODE
  123. //
  124. // Open the "*\shellex\PropertySheetHandlers" under HKCR
  125. //
  126. lr = TW32( RegOpenKeyEx( HKEY_CLASSES_ROOT, TEXT("*\\shellex\\PropertySheetHandlers"), 0, KEY_CREATE_SUB_KEY, &hkeyHandlers ) );
  127. if ( ERROR_SUCCESS != lr )
  128. goto Win32Error;
  129. //
  130. // Create the CLSID key
  131. //
  132. lr = TW32( RegCreateKeyEx( hkeyHandlers, psz, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkeySummary, NULL ) );
  133. if ( ERROR_SUCCESS != lr )
  134. goto Win32Error;
  135. //
  136. // Give the default property a non-localizable name
  137. //
  138. cbSize = sizeof(szSummaryPropertyPageExtName);
  139. lr = TW32( RegSetValueEx( hkeySummary, NULL, 0, REG_SZ, (LPBYTE) szSummaryPropertyPageExtName, cbSize ) );
  140. if ( ERROR_SUCCESS != lr )
  141. goto Win32Error;
  142. Cleanup:
  143. if ( NULL != pszCLSID )
  144. {
  145. CoTaskMemFree( pszCLSID );
  146. }
  147. if ( NULL != hkeyHandlers )
  148. {
  149. RegCloseKey( hkeyHandlers );
  150. }
  151. if ( NULL != hkeySummary )
  152. {
  153. RegCloseKey( hkeySummary );
  154. }
  155. HRETURN( hr );
  156. Win32Error:
  157. hr = HRESULT_FROM_WIN32( lr );
  158. goto Cleanup;
  159. }
  160. // ************************************************************************
  161. //
  162. // IUnknown
  163. //
  164. // ************************************************************************
  165. //
  166. //
  167. //
  168. STDMETHODIMP
  169. CDocPropShExt::QueryInterface(
  170. REFIID riid,
  171. LPVOID *ppv
  172. )
  173. {
  174. TraceQIFunc( riid, ppv );
  175. HRESULT hr = E_NOINTERFACE;
  176. if ( IsEqualIID( riid, __uuidof(IUnknown) ) )
  177. {
  178. *ppv = static_cast< IShellExtInit * >( this );
  179. hr = S_OK;
  180. }
  181. else if ( IsEqualIID( riid, __uuidof(IShellExtInit) ) )
  182. {
  183. *ppv = TraceInterface( __THISCLASS__, IShellExtInit, this, 0 );
  184. hr = S_OK;
  185. }
  186. else if ( IsEqualIID( riid, __uuidof(IShellPropSheetExt) ) )
  187. {
  188. *ppv = TraceInterface( __THISCLASS__, IShellPropSheetExt, this, 0 );
  189. hr = S_OK;
  190. }
  191. if ( SUCCEEDED( hr ) )
  192. {
  193. ((IUnknown*) *ppv)->AddRef( );
  194. }
  195. QIRETURN( hr, riid );
  196. }
  197. //
  198. //
  199. //
  200. STDMETHODIMP_(ULONG)
  201. CDocPropShExt::AddRef( void )
  202. {
  203. TraceFunc( "[IUnknown]" );
  204. _cRef ++; // apartment
  205. RETURN( _cRef );
  206. }
  207. //
  208. //
  209. //
  210. STDMETHODIMP_(ULONG)
  211. CDocPropShExt::Release( void )
  212. {
  213. TraceFunc( "[IUnknown]" );
  214. _cRef --; // apartment
  215. if ( 0 != _cRef )
  216. RETURN( _cRef );
  217. delete this;
  218. RETURN( 0 );
  219. }
  220. // ************************************************************************
  221. //
  222. // IShellExtInit
  223. //
  224. // ************************************************************************
  225. //
  226. //
  227. //
  228. STDMETHODIMP
  229. CDocPropShExt::Initialize(
  230. LPCITEMIDLIST pidlFolderIn
  231. , LPDATAOBJECT lpdobjIn
  232. , HKEY hkeyProgIDIn
  233. )
  234. {
  235. TraceFunc( "" );
  236. HRESULT hr;
  237. HRESULT hrResult = E_FAIL; // returned to caller - assume failure
  238. hr = THR( CSummaryPage::CreateInstance( &_punkSummary ) );
  239. if ( S_OK == hr )
  240. {
  241. IShellExtInit * psei;
  242. hr = THR( _punkSummary->TYPESAFEQI( psei ) );
  243. if ( S_OK == hr )
  244. {
  245. hr = THR( psei->Initialize( pidlFolderIn, lpdobjIn, hkeyProgIDIn ) );
  246. if ( S_OK == hr )
  247. {
  248. hrResult = S_OK;
  249. }
  250. psei->Release( );
  251. }
  252. }
  253. //
  254. // TODO: gpease 23-JAN-2001
  255. // Add additional pages here.
  256. //
  257. HRETURN( hrResult );
  258. }
  259. // ************************************************************************
  260. //
  261. // IShellPropSheetExt
  262. //
  263. // ************************************************************************
  264. //
  265. //
  266. //
  267. STDMETHODIMP
  268. CDocPropShExt::AddPages(
  269. LPFNADDPROPSHEETPAGE lpfnAddPageIn
  270. , LPARAM lParam
  271. )
  272. {
  273. TraceFunc( "" );
  274. HRESULT hr;
  275. IShellPropSheetExt * pspse = NULL;
  276. //
  277. // Check state
  278. //
  279. if ( NULL == _punkSummary )
  280. goto InvalidState;
  281. //
  282. // Add the Summary Page
  283. //
  284. hr = THR( _punkSummary->TYPESAFEQI( pspse ) );
  285. if ( S_OK != hr )
  286. goto Cleanup;
  287. hr = THR( pspse->AddPages( lpfnAddPageIn, lParam ) );
  288. if ( FAILED( hr ) )
  289. goto Cleanup;
  290. // release to reuse
  291. pspse->Release( );
  292. pspse = NULL;
  293. //
  294. // TODO: gpease 23-JAN-2001
  295. // Add additional pages here.
  296. //
  297. Cleanup:
  298. if ( NULL != pspse )
  299. {
  300. pspse->Release( );
  301. }
  302. HRETURN( hr );
  303. InvalidState:
  304. hr = THR( E_UNEXPECTED ); // REVIEW: gpease 23-JAN-2001 * Is there a better error code?
  305. goto Cleanup;
  306. }
  307. //
  308. //
  309. //
  310. STDMETHODIMP
  311. CDocPropShExt::ReplacePage(
  312. UINT uPageIDIn
  313. , LPFNADDPROPSHEETPAGE lpfnReplacePageIn
  314. , LPARAM lParam
  315. )
  316. {
  317. TraceFunc( "" );
  318. HRESULT hr = THR( E_NOTIMPL );
  319. HRETURN( hr );
  320. }
  321. // ***************************************************************************
  322. //
  323. // Private methods
  324. //
  325. // ***************************************************************************