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.

383 lines
6.8 KiB

  1. //
  2. // Copyright 2001 - Microsoft Corporation
  3. //
  4. // Created By:
  5. // Geoff Pease (GPease) 27-MAR-2001
  6. //
  7. // Maintained By:
  8. // Geoff Pease (GPease) 27-MAR-2001
  9. //
  10. #include "pch.h"
  11. #include "DocProp.h"
  12. #include "DefProp.h"
  13. #include "PropertyCacheItem.h"
  14. #include "PropertyCache.h"
  15. #include "LicensePage.h"
  16. #pragma hdrstop
  17. DEFINE_THISCLASS( "CLicensePage" )
  18. // ************************************************************************
  19. //
  20. // Constructor / Destructor
  21. //
  22. // ************************************************************************
  23. //
  24. // CreateInstance - used by CFactory
  25. //
  26. HRESULT
  27. CLicensePage::CreateInstance(
  28. IUnknown ** ppunkOut
  29. , CPropertyCache * pPropertyCacheIn
  30. )
  31. {
  32. TraceFunc( "" );
  33. HRESULT hr;
  34. Assert( ppunkOut != NULL );
  35. CLicensePage * pthis = new CLicensePage;
  36. if ( pthis != NULL )
  37. {
  38. hr = THR( pthis->Init( pPropertyCacheIn ) );
  39. if ( SUCCEEDED( hr ) )
  40. {
  41. *ppunkOut = (IShellExtInit *) pthis;
  42. (*ppunkOut)->AddRef( );
  43. }
  44. pthis->Release( );
  45. }
  46. else
  47. {
  48. hr = E_OUTOFMEMORY;
  49. }
  50. HRETURN( hr );
  51. }
  52. //
  53. // Constructor
  54. //
  55. CLicensePage::CLicensePage( void )
  56. : _cRef( 1 )
  57. {
  58. TraceFunc( "" );
  59. InterlockedIncrement( &g_cObjects );
  60. Assert( 1 == _cRef ); // we initialize this above
  61. //
  62. // We assume that we are ZERO_INITed - be paranoid.
  63. //
  64. Assert( NULL == _hdlg );
  65. Assert( NULL == _pPropertyCache );
  66. TraceFuncExit();
  67. }
  68. //
  69. // Description:
  70. // Initializes class. Put calls that can fail in here.
  71. //
  72. HRESULT
  73. CLicensePage::Init(
  74. CPropertyCache * pPropertyCacheIn
  75. )
  76. {
  77. TraceFunc( "" );
  78. HRESULT hr = S_OK;
  79. // IUnknown stuff
  80. Assert( 1 == _cRef );
  81. // IShellPropSheetExt stuff
  82. _pPropertyCache = pPropertyCacheIn;
  83. if ( NULL == _pPropertyCache )
  84. {
  85. hr = THR( E_INVALIDARG );
  86. }
  87. HRETURN( hr );
  88. }
  89. //
  90. // Destructor
  91. //
  92. CLicensePage::~CLicensePage( )
  93. {
  94. TraceFunc( "" );
  95. InterlockedDecrement( &g_cObjects );
  96. TraceFuncExit();
  97. }
  98. // ************************************************************************
  99. //
  100. // IUnknown
  101. //
  102. // ************************************************************************
  103. //
  104. //
  105. //
  106. STDMETHODIMP
  107. CLicensePage::QueryInterface(
  108. REFIID riid,
  109. LPVOID *ppv
  110. )
  111. {
  112. TraceQIFunc( riid, ppv );
  113. HRESULT hr = E_NOINTERFACE;
  114. if ( IsEqualIID( riid, __uuidof(IUnknown) ) )
  115. {
  116. *ppv = static_cast< IShellPropSheetExt * >( this );
  117. hr = S_OK;
  118. }
  119. else if ( IsEqualIID( riid, __uuidof(IShellPropSheetExt) ) )
  120. {
  121. *ppv = TraceInterface( __THISCLASS__, IShellPropSheetExt, this, 0 );
  122. hr = S_OK;
  123. }
  124. if ( SUCCEEDED( hr ) )
  125. {
  126. ((IUnknown*) *ppv)->AddRef( );
  127. }
  128. QIRETURN( hr, riid );
  129. }
  130. //
  131. //
  132. //
  133. STDMETHODIMP_(ULONG)
  134. CLicensePage::AddRef( void )
  135. {
  136. TraceFunc( "[IUnknown]" );
  137. _cRef ++; // apartment
  138. RETURN( _cRef );
  139. }
  140. //
  141. //
  142. //
  143. STDMETHODIMP_(ULONG)
  144. CLicensePage::Release( void )
  145. {
  146. TraceFunc( "[IUnknown]" );
  147. _cRef --; // apartment
  148. if ( 0 != _cRef )
  149. RETURN( _cRef );
  150. delete this;
  151. RETURN( 0 );
  152. }
  153. // ************************************************************************
  154. //
  155. // IShellPropSheetExt
  156. //
  157. // ************************************************************************
  158. //
  159. //
  160. //
  161. STDMETHODIMP
  162. CLicensePage::AddPages(
  163. LPFNADDPROPSHEETPAGE lpfnAddPageIn
  164. , LPARAM lParam
  165. )
  166. {
  167. TraceFunc( "" );
  168. HRESULT hr = E_FAIL; // assume failure
  169. HPROPSHEETPAGE hPage;
  170. PROPSHEETPAGE psp = { 0 };
  171. psp.dwSize = sizeof(psp);
  172. psp.dwFlags = PSP_USECALLBACK;
  173. psp.hInstance = g_hInstance;
  174. psp.pszTemplate = MAKEINTRESOURCE(IDD_LICENSEPAGE);
  175. psp.pfnDlgProc = (DLGPROC) DlgProc;
  176. psp.pfnCallback = PageCallback;
  177. psp.lParam = (LPARAM) this;
  178. hPage = CreatePropertySheetPage( &psp );
  179. if ( NULL != hPage )
  180. {
  181. BOOL b = TBOOL( lpfnAddPageIn( hPage, lParam ) );
  182. if ( b )
  183. {
  184. hr = S_OK;
  185. }
  186. else
  187. {
  188. DestroyPropertySheetPage( hPage );
  189. }
  190. }
  191. HRETURN( hr );
  192. }
  193. //
  194. //
  195. //
  196. STDMETHODIMP
  197. CLicensePage::ReplacePage(
  198. UINT uPageIDIn
  199. , LPFNADDPROPSHEETPAGE lpfnReplacePageIn
  200. , LPARAM lParam
  201. )
  202. {
  203. TraceFunc( "" );
  204. HRESULT hr = THR( E_NOTIMPL );
  205. HRETURN( hr );
  206. }
  207. // ***************************************************************************
  208. //
  209. // Dialog Proc and Property Sheet Callback
  210. //
  211. // ***************************************************************************
  212. //
  213. //
  214. //
  215. INT_PTR CALLBACK
  216. CLicensePage::DlgProc(
  217. HWND hDlgIn
  218. , UINT uMsgIn
  219. , WPARAM wParam
  220. , LPARAM lParam
  221. )
  222. {
  223. // Don't do TraceFunc because every mouse movement will cause this function to spew.
  224. WndMsg( hDlgIn, uMsgIn, wParam, lParam );
  225. LRESULT lr = FALSE;
  226. CLicensePage * pPage = (CLicensePage *) GetWindowLongPtr( hDlgIn, DWLP_USER );
  227. if ( uMsgIn == WM_INITDIALOG )
  228. {
  229. PROPSHEETPAGE * ppage = (PROPSHEETPAGE *) lParam;
  230. SetWindowLongPtr( hDlgIn, DWLP_USER, (LPARAM) ppage->lParam );
  231. pPage = (CLicensePage *) ppage->lParam;
  232. pPage->_hdlg = hDlgIn;
  233. }
  234. if ( pPage != NULL )
  235. {
  236. Assert( hDlgIn == pPage->_hdlg );
  237. switch( uMsgIn )
  238. {
  239. case WM_INITDIALOG:
  240. lr = pPage->OnInitDialog( );
  241. break;
  242. }
  243. }
  244. return lr;
  245. }
  246. //
  247. //
  248. //
  249. UINT CALLBACK
  250. CLicensePage::PageCallback(
  251. HWND hwndIn
  252. , UINT uMsgIn
  253. , LPPROPSHEETPAGE ppspIn
  254. )
  255. {
  256. TraceFunc( "" );
  257. UINT uRet = 0;
  258. CLicensePage * pPage = (CLicensePage *) ppspIn->lParam;
  259. if ( NULL != pPage )
  260. {
  261. switch ( uMsgIn )
  262. {
  263. case PSPCB_CREATE:
  264. uRet = TRUE; // allow the page to be created
  265. break;
  266. case PSPCB_ADDREF:
  267. pPage->AddRef( );
  268. break;
  269. case PSPCB_RELEASE:
  270. pPage->Release( );
  271. break;
  272. }
  273. }
  274. RETURN( uRet );
  275. }
  276. // ***************************************************************************
  277. //
  278. // Private methods
  279. //
  280. // ***************************************************************************
  281. //
  282. // WM_INITDIALOG handler
  283. //
  284. LRESULT
  285. CLicensePage::OnInitDialog( void )
  286. {
  287. TraceFunc( "" );
  288. HRESULT hr;
  289. CPropertyCacheItem * pItem;
  290. LRESULT lr = FALSE;
  291. Assert( NULL != _hdlg ); // this should have been initialized in the DlgProc.
  292. hr = STHR( _pPropertyCache->FindItemEntry( &FMTID_DRM, PIDDRSI_DESCRIPTION, &pItem ) );
  293. if ( S_OK == hr )
  294. {
  295. LPCWSTR pszText;
  296. hr = THR( pItem->GetPropertyStringValue( &pszText ) );
  297. if ( S_OK == hr )
  298. {
  299. TBOOL( SetDlgItemText( _hdlg, IDC_E_LICENSE, pszText ) );
  300. }
  301. }
  302. RETURN( lr );
  303. }