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.

452 lines
9.4 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1996 - 1998
  3. All rights reserved.
  4. Module Name:
  5. PropMgr.cxx
  6. Abstract:
  7. Property Sheet Manager
  8. Author:
  9. Steve Kiraly (SteveKi) 13-Feb-1996
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. #include "propmgr.hxx"
  15. /********************************************************************
  16. All printer property windows.
  17. ********************************************************************/
  18. TPropertySheetManager::
  19. TPropertySheetManager(
  20. VOID
  21. ) : _bValid( TRUE ),
  22. _hWnd( NULL )
  23. {
  24. DBGMSG( DBG_TRACE, ( "TPropertySheetManager ctor\n") );
  25. ZeroMemory( &_CPSUIInfo, sizeof( _CPSUIInfo ) );
  26. }
  27. TPropertySheetManager::
  28. ~TPropertySheetManager(
  29. VOID
  30. )
  31. {
  32. DBGMSG( DBG_TRACE, ( "TPropertySheetManager dtor\n") );
  33. }
  34. BOOL
  35. TPropertySheetManager::
  36. bValid(
  37. VOID
  38. )
  39. {
  40. return _bValid;
  41. }
  42. //
  43. // This is needed since compstui has a bug
  44. // where it returns either -1 or NULL for an
  45. // invalid handle.
  46. //
  47. BOOL
  48. TPropertySheetManager::
  49. bValidCompstuiHandle(
  50. IN LONG_PTR hHandle
  51. )
  52. {
  53. return hHandle && hHandle != -1;
  54. }
  55. /*++
  56. Routine Name:
  57. bDisplayPages
  58. Routine Description:
  59. Loads the compstui module and displays the pages.
  60. See \nt\public\oak\inc\compstui.h file for details
  61. Arguments:
  62. HWND - Handle to parent window.
  63. pResult - The result returned from COMPSTUI
  64. Return Value:
  65. TRUE success, FALSE error occurred.
  66. --*/
  67. BOOL
  68. TPropertySheetManager::
  69. bDisplayPages(
  70. IN HWND hWnd,
  71. OUT LONG *pResult
  72. )
  73. {
  74. typedef LONG
  75. (APIENTRY *PF_COMPROPSHEETUI)(
  76. HWND hWndOwner,
  77. PFNPROPSHEETUI pfnPropSheetUI,
  78. LPARAM lParam,
  79. LPDWORD pResult
  80. );
  81. DWORD dwResult = CPSUI_CANCEL;
  82. LONG lResult = FALSE;
  83. BOOL bStatus = FALSE;
  84. PF_COMPROPSHEETUI pfn = NULL;
  85. _hWnd = hWnd;
  86. DBGMSG( DBG_TRACE, ( "TPropertySheetManager bDisplayPages\n") );
  87. //
  88. // Load the library and get the entrypoint.
  89. //
  90. TLibrary lib( TEXT( COMMON_UI ) );
  91. //
  92. // Ensure the library was loaded and the
  93. // proc address was fetch with out errors.
  94. //
  95. if( !VALID_OBJ( lib ) ||
  96. !(pfn = (PF_COMPROPSHEETUI)lib.pfnGetProc( COMMON_PROPERTY_SHEETUI ) ) ){
  97. bStatus = FALSE;
  98. } else {
  99. //
  100. // Bring up the actual property sheets.
  101. //
  102. lResult = (*pfn)( _hWnd,
  103. CPSUIFunc,
  104. (LPARAM)this,
  105. &dwResult );
  106. //
  107. // Set return value if the the sheets failed
  108. // it is up to the derived class to capture its error value.
  109. //
  110. if( lResult <= 0 ){
  111. DBGMSG( DBG_ERROR, ( "Display Pages failed %d Result %d GLE %d.\n", lResult, dwResult, GetLastError() ) );
  112. bStatus = FALSE;
  113. } else {
  114. bStatus = TRUE;
  115. if( pResult )
  116. {
  117. // return the actual result from compstui
  118. *pResult = static_cast<LONG>(dwResult);
  119. }
  120. }
  121. }
  122. //
  123. // Return status.
  124. //
  125. return bStatus;
  126. }
  127. /********************************************************************
  128. Private member functions.
  129. ********************************************************************/
  130. LONG
  131. TPropertySheetManager::
  132. lReasonInit(
  133. IN PPROPSHEETUI_INFO pCPSUIInfo,
  134. IN LPARAM lParam
  135. )
  136. {
  137. LONG lResult = FALSE;
  138. pCPSUIInfo->UserData = lParam;
  139. //
  140. // Build the property sheets pages.
  141. //
  142. if( bBuildPages( pCPSUIInfo ) ){
  143. lResult = TRUE;
  144. }
  145. return lResult;
  146. }
  147. LONG
  148. TPropertySheetManager::
  149. lReasonGetInfoHeader(
  150. IN PPROPSHEETUI_INFO pCPSUIInfo,
  151. IN PPROPSHEETUI_INFO_HEADER pPSUInfoHeader
  152. )
  153. {
  154. LONG lResult = FALSE;
  155. //
  156. // Make a copy of the compstui entry point. This is needed for
  157. // future calls to compstui, like freeing pages etc.
  158. //
  159. CopyMemory( &_CPSUIInfo, pCPSUIInfo, sizeof( _CPSUIInfo ) );
  160. //
  161. // Set the property sheet info header.
  162. //
  163. if( bSetHeader( pCPSUIInfo, pPSUInfoHeader ) ){
  164. lResult = TRUE;
  165. }
  166. return lResult;
  167. }
  168. LONG
  169. TPropertySheetManager::
  170. lReasonSetResult(
  171. IN PPROPSHEETUI_INFO pCPSUIInfo,
  172. IN PSETRESULT_INFO pSetResultInfo
  173. )
  174. {
  175. return bSaveResult( pCPSUIInfo, pSetResultInfo );
  176. }
  177. LONG
  178. TPropertySheetManager::
  179. lReasonGetIcon(
  180. IN PPROPSHEETUI_INFO pCPSUIInfo
  181. )
  182. {
  183. return dwGetIcon( pCPSUIInfo );
  184. }
  185. LONG
  186. TPropertySheetManager::
  187. lReasonDestroy(
  188. IN PPROPSHEETUI_INFO pCPSUIInfo
  189. )
  190. {
  191. LONG lResult = FALSE;
  192. //
  193. // Release any sheet specific data.
  194. //
  195. if( bDestroyPages( pCPSUIInfo ) ){
  196. pCPSUIInfo->UserData = NULL;
  197. lResult = TRUE;
  198. }
  199. return lResult;
  200. }
  201. /*++
  202. Routine Name:
  203. CPSUIFunc
  204. Routine Description:
  205. Callback function used by compstui.
  206. Arguments:
  207. See \nt\public\oak\inc\compstui.h file
  208. Return Value:
  209. TRUE success, FALSE error occurred.
  210. --*/
  211. LONG
  212. CALLBACK
  213. TPropertySheetManager::
  214. CPSUIFunc(
  215. PPROPSHEETUI_INFO pCPSUIInfo,
  216. LPARAM lParam
  217. )
  218. {
  219. DBGMSG( DBG_TRACE, ( "TPropertySheetManager CPSUIFunc\n") );
  220. SPLASSERT ( pCPSUIInfo );
  221. LONG lResult = -1;
  222. TPropertySheetManager *pSheets = NULL;
  223. //
  224. // Only valid common ui defined entry requests are acknowledged.
  225. //
  226. if( pCPSUIInfo ){
  227. switch( pCPSUIInfo->Reason ){
  228. case PROPSHEETUI_REASON_INIT:
  229. DBGMSG( DBG_TRACE, ( "TPropertySheetManager PROPSHEETUI_REASON_INIT\n") );
  230. pSheets = (TPropertySheetManager *)lParam;
  231. SPLASSERT( pSheets );
  232. lResult = pSheets->lReasonInit( pCPSUIInfo, lParam );
  233. break;
  234. case PROPSHEETUI_REASON_GET_INFO_HEADER:
  235. DBGMSG( DBG_TRACE, ( "TPropertySheetManager PROPSHEETUI_REASON_GET_INFO_HEADER\n") );
  236. pSheets = (TPropertySheetManager *)pCPSUIInfo->UserData;
  237. SPLASSERT( pSheets );
  238. lResult = pSheets->lReasonGetInfoHeader( pCPSUIInfo, (PPROPSHEETUI_INFO_HEADER)lParam );
  239. break;
  240. case PROPSHEETUI_REASON_SET_RESULT:
  241. DBGMSG( DBG_TRACE, ( "TPropertySheetManager PROPSHEETUI_REASON_SET_RESULT\n") );
  242. pSheets = (TPropertySheetManager *)pCPSUIInfo->UserData;
  243. SPLASSERT( pSheets );
  244. lResult = pSheets->lReasonSetResult( pCPSUIInfo, (PSETRESULT_INFO)lParam );
  245. break;
  246. case PROPSHEETUI_REASON_GET_ICON:
  247. DBGMSG( DBG_TRACE, ( "TPropertySheetManager PROPSHEETUI_REASON_GET_ICON\n") );
  248. pSheets = (TPropertySheetManager *)pCPSUIInfo->UserData;
  249. SPLASSERT( pSheets );
  250. lResult = pSheets->lReasonGetIcon( pCPSUIInfo );
  251. break;
  252. case PROPSHEETUI_REASON_DESTROY:
  253. DBGMSG( DBG_TRACE, ( "TPropertySheetManager PROPSHEETUI_REASON_DESTROY\n") );
  254. pSheets = (TPropertySheetManager *)pCPSUIInfo->UserData;
  255. SPLASSERT( pSheets );
  256. lResult = pSheets->lReasonDestroy( pCPSUIInfo );
  257. break;
  258. default:
  259. DBGMSG( DBG_TRACE, ( "TPropertySheetManager unknown common ui command.\n") );
  260. break;
  261. }
  262. }
  263. return lResult;
  264. }
  265. /********************************************************************
  266. Protected member functions, provided for non pure virtuals.
  267. ********************************************************************/
  268. /*++
  269. Routine Name:
  270. dwGetIcon
  271. Routine Description:
  272. Return the Icon this module is associated with. If no icon is
  273. associated then a NULL can be returned.
  274. Arguments:
  275. pCPSUIInfo - Pointer to commonui property sheet info header,
  276. Return Value:
  277. TRUE success, FALSE error occurred.
  278. --*/
  279. DWORD
  280. TPropertySheetManager::
  281. dwGetIcon(
  282. IN PPROPSHEETUI_INFO pCPSUIInfo
  283. )
  284. {
  285. DBGMSG( DBG_TRACE, ( "TPropertySheetManager dwGetIcon\n") );
  286. UNREFERENCED_PARAMETER( pCPSUIInfo );
  287. return NULL;
  288. }
  289. /*++
  290. Routine Name:
  291. bDestroyPages
  292. Routine Description:
  293. Destroy any compstui specific data information.
  294. Arguments:
  295. pCPSUIInfo - Pointer to commonui property sheet info header,
  296. pSetResultInfo - Pointer to result info header
  297. Return Value:
  298. TRUE success, FALSE error occurred.
  299. --*/
  300. BOOL
  301. TPropertySheetManager::
  302. bDestroyPages(
  303. IN PPROPSHEETUI_INFO pPSUIInfo
  304. )
  305. {
  306. DBGMSG( DBG_TRACE, ( "TPropertySheetManager bDestroyPages\n") );
  307. UNREFERENCED_PARAMETER( pPSUIInfo );
  308. return TRUE;
  309. }
  310. /*++
  311. Routine Name:
  312. bSaveResult
  313. Routine Description:
  314. Save the result from the previous handler to our parent.
  315. Arguments:
  316. pCPSUIInfo - Pointer to commonui property sheet info header,
  317. pSetResultInfo - Pointer to result info header
  318. Return Value:
  319. TRUE success, FALSE error occurred.
  320. --*/
  321. BOOL
  322. TPropertySheetManager::
  323. bSaveResult(
  324. IN PPROPSHEETUI_INFO pCPSUIInfo,
  325. IN PSETRESULT_INFO pSetResultInfo
  326. )
  327. {
  328. DBGMSG( DBG_TRACE, ( "TPropertySheetManager bSaveResult\n") );
  329. pCPSUIInfo->Result = pSetResultInfo->Result;
  330. return TRUE;
  331. }