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.

384 lines
7.2 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. Assert( 0 != g_cObjects );
  96. InterlockedDecrement( &g_cObjects );
  97. TraceFuncExit();
  98. }
  99. // ************************************************************************
  100. //
  101. // IUnknown
  102. //
  103. // ************************************************************************
  104. //
  105. //
  106. //
  107. STDMETHODIMP
  108. CLicensePage::QueryInterface(
  109. REFIID riid,
  110. LPVOID *ppv
  111. )
  112. {
  113. TraceQIFunc( riid, ppv );
  114. HRESULT hr = E_NOINTERFACE;
  115. if ( IsEqualIID( riid, __uuidof(IUnknown) ) )
  116. {
  117. *ppv = static_cast< IShellPropSheetExt * >( this );
  118. hr = S_OK;
  119. }
  120. else if ( IsEqualIID( riid, __uuidof(IShellPropSheetExt) ) )
  121. {
  122. *ppv = TraceInterface( __THISCLASS__, IShellPropSheetExt, this, 0 );
  123. hr = S_OK;
  124. }
  125. if ( SUCCEEDED( hr ) )
  126. {
  127. ((IUnknown*) *ppv)->AddRef( );
  128. }
  129. QIRETURN( hr, riid );
  130. }
  131. //
  132. //
  133. //
  134. STDMETHODIMP_(ULONG)
  135. CLicensePage::AddRef( void )
  136. {
  137. TraceFunc( "[IUnknown]" );
  138. _cRef ++; // apartment
  139. RETURN( _cRef );
  140. }
  141. //
  142. //
  143. //
  144. STDMETHODIMP_(ULONG)
  145. CLicensePage::Release( void )
  146. {
  147. TraceFunc( "[IUnknown]" );
  148. _cRef --; // apartment
  149. if ( 0 != _cRef )
  150. RETURN( _cRef );
  151. delete this;
  152. RETURN( 0 );
  153. }
  154. // ************************************************************************
  155. //
  156. // IShellPropSheetExt
  157. //
  158. // ************************************************************************
  159. //
  160. //
  161. //
  162. STDMETHODIMP
  163. CLicensePage::AddPages(
  164. LPFNADDPROPSHEETPAGE lpfnAddPageIn
  165. , LPARAM lParam
  166. )
  167. {
  168. TraceFunc( "" );
  169. HRESULT hr = E_FAIL; // assume failure
  170. HPROPSHEETPAGE hPage;
  171. PROPSHEETPAGE psp = { 0 };
  172. psp.dwSize = sizeof(psp);
  173. psp.dwFlags = PSP_USECALLBACK;
  174. psp.hInstance = g_hInstance;
  175. psp.pszTemplate = MAKEINTRESOURCE(IDD_LICENSEPAGE);
  176. psp.pfnDlgProc = DlgProc;
  177. psp.pfnCallback = PageCallback;
  178. psp.lParam = (LPARAM) this;
  179. hPage = CreatePropertySheetPage( &psp );
  180. if ( NULL != hPage )
  181. {
  182. BOOL b = TBOOL( lpfnAddPageIn( hPage, lParam ) );
  183. if ( b )
  184. {
  185. hr = S_OK;
  186. }
  187. else
  188. {
  189. DestroyPropertySheetPage( hPage );
  190. }
  191. }
  192. HRETURN( hr );
  193. }
  194. //
  195. //
  196. //
  197. STDMETHODIMP
  198. CLicensePage::ReplacePage(
  199. UINT uPageIDIn
  200. , LPFNADDPROPSHEETPAGE lpfnReplacePageIn
  201. , LPARAM lParam
  202. )
  203. {
  204. TraceFunc( "" );
  205. HRESULT hr = THR( E_NOTIMPL );
  206. HRETURN( hr );
  207. }
  208. // ***************************************************************************
  209. //
  210. // Dialog Proc and Property Sheet Callback
  211. //
  212. // ***************************************************************************
  213. //
  214. //
  215. //
  216. INT_PTR CALLBACK
  217. CLicensePage::DlgProc(
  218. HWND hDlgIn
  219. , UINT uMsgIn
  220. , WPARAM wParam
  221. , LPARAM lParam
  222. )
  223. {
  224. // Don't do TraceFunc because every mouse movement will cause this function to spew.
  225. WndMsg( hDlgIn, uMsgIn, wParam, lParam );
  226. LRESULT lr = FALSE;
  227. CLicensePage * pPage = (CLicensePage *) GetWindowLongPtr( hDlgIn, DWLP_USER );
  228. if ( uMsgIn == WM_INITDIALOG )
  229. {
  230. PROPSHEETPAGE * ppage = (PROPSHEETPAGE *) lParam;
  231. SetWindowLongPtr( hDlgIn, DWLP_USER, (LPARAM) ppage->lParam );
  232. pPage = (CLicensePage *) ppage->lParam;
  233. pPage->_hdlg = hDlgIn;
  234. }
  235. if ( pPage != NULL )
  236. {
  237. Assert( hDlgIn == pPage->_hdlg );
  238. switch( uMsgIn )
  239. {
  240. case WM_INITDIALOG:
  241. lr = pPage->OnInitDialog( );
  242. break;
  243. }
  244. }
  245. return lr;
  246. }
  247. //
  248. //
  249. //
  250. UINT CALLBACK
  251. CLicensePage::PageCallback(
  252. HWND hwndIn
  253. , UINT uMsgIn
  254. , LPPROPSHEETPAGE ppspIn
  255. )
  256. {
  257. TraceFunc( "" );
  258. UINT uRet = 0;
  259. CLicensePage * pPage = (CLicensePage *) ppspIn->lParam;
  260. if ( NULL != pPage )
  261. {
  262. switch ( uMsgIn )
  263. {
  264. case PSPCB_CREATE:
  265. uRet = TRUE; // allow the page to be created
  266. break;
  267. case PSPCB_ADDREF:
  268. pPage->AddRef( );
  269. break;
  270. case PSPCB_RELEASE:
  271. pPage->Release( );
  272. break;
  273. }
  274. }
  275. RETURN( uRet );
  276. }
  277. // ***************************************************************************
  278. //
  279. // Private methods
  280. //
  281. // ***************************************************************************
  282. //
  283. // WM_INITDIALOG handler
  284. //
  285. LRESULT
  286. CLicensePage::OnInitDialog( void )
  287. {
  288. TraceFunc( "" );
  289. HRESULT hr;
  290. CPropertyCacheItem * pItem;
  291. LRESULT lr = FALSE;
  292. Assert( NULL != _hdlg ); // this should have been initialized in the DlgProc.
  293. hr = STHR( _pPropertyCache->FindItemEntry( &FMTID_DRM, PIDDRSI_DESCRIPTION, &pItem ) );
  294. if ( S_OK == hr )
  295. {
  296. LPCWSTR pszText;
  297. hr = THR( pItem->GetPropertyStringValue( &pszText ) );
  298. if ( S_OK == hr )
  299. {
  300. TBOOL( SetDlgItemText( _hdlg, IDC_E_LICENSE, pszText ) );
  301. }
  302. }
  303. RETURN( lr );
  304. }