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.

485 lines
15 KiB

  1. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2. // NOTE: THIS HAS NOT BEEN THROUGHLY TESTED. IT IS A SIMPLE CLASS, AND BUGS SHOULD
  3. // PRESENT THEMSELVES THROUGH USAGE. THE BUGS SHOULD BE SIMPLE TO FIX.
  4. ////////////////////////////////////////////////////////////////////////////////////////////////////
  5. // Include Files
  6. ////////////////////////////////////////////////////////////////////////////////////////////////////
  7. #include "precomp.h"
  8. #include "PropPg.h"
  9. ////////////////////////////////////////////////////////////////////////////////////////////////////
  10. // Construction, Destruction, and Initialization funcs
  11. ////////////////////////////////////////////////////////////////////////////////////////////////////
  12. //--------------------------------------------------------------------------------------------------
  13. // CPropertySheetPage::CPropertySheetPage
  14. CPropertySheetPage::CPropertySheetPage( void ) {
  15. _InitData();
  16. }
  17. //--------------------------------------------------------------------------------------------------
  18. // CPropertySheetPage::CPropertySheetPage
  19. CPropertySheetPage::CPropertySheetPage( const CPropertySheetPage& r ) {
  20. _InitData();
  21. *this = r;
  22. }
  23. //--------------------------------------------------------------------------------------------------
  24. // CPropertySheetPage::CPropertySheetPage
  25. // pszTemplate can specify either the resource identifier of the template
  26. // or the address of a string that specifies the name of the template
  27. CPropertySheetPage::CPropertySheetPage( LPCTSTR pszTemplate, DLGPROC pfnDlgProc,
  28. DWORD dwFlags /* = 0 */, LPARAM lParam /* = 0L */ ) {
  29. _InitData();
  30. this -> dwFlags = dwFlags;
  31. if( ! _Set_hInstance( g_hInstance ) ) { return; }
  32. if( ! _Set_pszTemplate( pszTemplate ) ) { return; }
  33. if( ! _Set_pfnDlgProc( pfnDlgProc ) ) { return; }
  34. if( ! _Set_lParam( lParam ) ) { return; }
  35. if( ! _Validate() ) { return; }
  36. }
  37. //--------------------------------------------------------------------------------------------------
  38. // CPropertySheetPage::CPropertySheetPage
  39. CPropertySheetPage::CPropertySheetPage( LPCDLGTEMPLATE pResource, DLGPROC pfnDlgProc,
  40. DWORD dwFlags /* = 0 */, LPARAM lParam /* = 0L */ ) {
  41. _InitData();
  42. this -> dwFlags = dwFlags;
  43. if( ! _Set_hInstance( g_hInstance ) ) { return; }
  44. if( ! _Set_pResource( pResource ) ) { return; }
  45. if( ! _Set_pfnDlgProc( pfnDlgProc ) ) { return; }
  46. if( ! _Set_lParam( lParam ) ) { return; }
  47. if( ! _Validate() ) { return; }
  48. }
  49. //--------------------------------------------------------------------------------------------------
  50. // CPropertySheetPage::CPropertySheetPage
  51. // pszTemplate can specify either the resource identifier of the template
  52. // or the address of a string that specifies the name of the template
  53. CPropertySheetPage::CPropertySheetPage( LPCTSTR pszTemplate, DLGPROC pfnDlgProc,
  54. HICON hIcon, /* = NULL */ LPCTSTR pszTitle /* = NULL */, DWORD dwFlags, /* = 0 */
  55. LPARAM lParam /* =NULL */, LPFNPSPCALLBACK pfnCallBack, /* =NULL */
  56. UINT FAR * pcRefParent /* =NULL */
  57. ) {
  58. _InitData();
  59. this -> dwFlags = dwFlags;
  60. if( ! _Set_hInstance( g_hInstance ) ) { return; }
  61. if( ! _Set_pszTemplate( pszTemplate ) ) { return; }
  62. if( ! _Set_hIcon( hIcon ) ) { return; }
  63. if( ! _Set_pszTitle( pszTitle ) ) { return; }
  64. if( ! _Set_pfnDlgProc( pfnDlgProc ) ) { return; }
  65. if( ! _Set_lParam( lParam ) ) { return; }
  66. if( ! _Set_pfnCallback( pfnCallBack ) ) { return; }
  67. if( ! _Set_pcRefParent( pcRefParent ) ) { return; }
  68. if( ! _Validate() ) { return; }
  69. }
  70. //--------------------------------------------------------------------------------------------------
  71. // CPropertySheetPage::CPropertySheetPage
  72. CPropertySheetPage::CPropertySheetPage( LPCDLGTEMPLATE pResource, DLGPROC pfnDlgProc,
  73. HICON hIcon, /* = NULL */ LPCTSTR pszTitle /* = NULL */, DWORD dwFlags, /* = 0 */
  74. LPARAM lParam /* =NULL */, LPFNPSPCALLBACK pfnCallBack,/* =NULL */
  75. UINT FAR * pcRefParent /* =NULL */
  76. ) {
  77. _InitData();
  78. this -> dwFlags = dwFlags;
  79. if( ! _Set_hInstance( g_hInstance ) ) { return; }
  80. if( ! _Set_pResource( pResource ) ) { return; }
  81. if( ! _Set_hIcon( hIcon ) ) { return; }
  82. if( ! _Set_pszTitle( pszTitle ) ) { return; }
  83. if( ! _Set_pfnDlgProc( pfnDlgProc ) ) { return; }
  84. if( ! _Set_lParam( lParam ) ) { return; }
  85. if( ! _Set_pfnCallback( pfnCallBack ) ) { return; }
  86. if( ! _Set_pcRefParent( pcRefParent ) ) { return; }
  87. if( ! _Validate() ) { return; }
  88. }
  89. //--------------------------------------------------------------------------------------------------
  90. // CPropertySheetPage::CPropertySheetPage
  91. CPropertySheetPage::CPropertySheetPage( LPCTSTR pszTemplate, DLGPROC pfnDlgProc,
  92. LPCTSTR pszIcon /* =0 */, LPCTSTR pszTitle /* = NULL */, DWORD dwFlags, /* = 0 */
  93. LPARAM lParam /* =NULL */, LPFNPSPCALLBACK pfnCallBack, /* =NULL */
  94. UINT FAR * pcRefParent /* =NULL */
  95. ) {
  96. _InitData();
  97. this -> dwFlags = dwFlags;
  98. if( ! _Set_hInstance( g_hInstance ) ) { return; }
  99. if( ! _Set_pszTemplate( pszTemplate ) ) { return; }
  100. if( ! _Set_pszIcon( pszIcon ) ) { return; }
  101. if( ! _Set_pszTitle( pszTitle ) ) { return; }
  102. if( ! _Set_pfnDlgProc( pfnDlgProc ) ) { return; }
  103. if( ! _Set_lParam( lParam ) ) { return; }
  104. if( ! _Set_pfnCallback( pfnCallBack ) ) { return; }
  105. if( ! _Set_pcRefParent( pcRefParent ) ) { return; }
  106. if( ! _Validate() ) { return; }
  107. }
  108. //--------------------------------------------------------------------------------------------------
  109. // CPropertySheetPage::CPropertySheetPage
  110. CPropertySheetPage::CPropertySheetPage( LPCDLGTEMPLATE pResource, DLGPROC pfnDlgProc,
  111. LPCTSTR pszIcon /* =0 */, LPCTSTR pszTitle /* = NULL */, DWORD dwFlags, /* = 0 */
  112. LPARAM lParam /* =NULL */, LPFNPSPCALLBACK pfnCallBack, /* =NULL */
  113. UINT FAR * pcRefParent /* =NULL */
  114. ) {
  115. _InitData();
  116. this -> dwFlags = dwFlags;
  117. if( ! _Set_hInstance( g_hInstance ) ) { return; }
  118. if( ! _Set_pResource( pResource ) ) { return; }
  119. if( ! _Set_pszIcon( pszIcon ) ) { return; }
  120. if( ! _Set_pszTitle( pszTitle ) ) { return; }
  121. if( ! _Set_pfnDlgProc( pfnDlgProc ) ) { return; }
  122. if( ! _Set_lParam( lParam ) ) { return; }
  123. if( ! _Set_pfnCallback( pfnCallBack ) ) { return; }
  124. if( ! _Set_pcRefParent( pcRefParent ) ) { return; }
  125. if( ! _Validate() ) { return; }
  126. }
  127. //--------------------------------------------------------------------------------------------------
  128. // CPropertySheetPage::CPropertySheetPage
  129. CPropertySheetPage::CPropertySheetPage( LPCPROPSHEETPAGE pPageVector ) {
  130. memcpy( this, pPageVector, sizeof( PROPSHEETPAGE ) );
  131. _Validate();
  132. }
  133. //--------------------------------------------------------------------------------------------------
  134. // CPropertySheetPage::~CPropertySheetPage
  135. CPropertySheetPage::~CPropertySheetPage( void ) {
  136. }
  137. ////////////////////////////////////////////////////////////////////////////////////////////////////
  138. // Public Member Fns
  139. ////////////////////////////////////////////////////////////////////////////////////////////////////
  140. //--------------------------------------------------------------------------------------------------
  141. // operator= assigns *this to another CPropertySheetPage
  142. // Because there are no pointers or references in the PROPSHEETPAGE structure, the contents may
  143. // simply be memory copied
  144. CPropertySheetPage& CPropertySheetPage::operator=( const CPropertySheetPage& r ) {
  145. LPCPROPSHEETPAGE pcSrc = static_cast< LPCPROPSHEETPAGE >( &r );
  146. LPPROPSHEETPAGE pDst = static_cast< LPPROPSHEETPAGE >( this );
  147. memcpy( pDst, pcSrc, sizeof( PROPSHEETPAGE ) );
  148. return *this;
  149. }
  150. ////////////////////////////////////////////////////////////////////////////////////////////////////
  151. // Private Helper Fns
  152. ////////////////////////////////////////////////////////////////////////////////////////////////////
  153. void CPropertySheetPage::_InitData( void ) {
  154. ZeroMemory( this, sizeof( PROPSHEETPAGE ) );
  155. this -> dwSize = sizeof( PROPSHEETPAGE );
  156. this -> dwFlags |= PSP_DEFAULT;
  157. }
  158. //--------------------------------------------------------------------------------------------------
  159. // _IsRightToLeftLocale is called to determine the value of one of the flags in the PROPSHEETPAGE
  160. // datastructure. If this is to be a robust and complete wrapper class, this should be implemented
  161. BOOL CPropertySheetPage::_IsRightToLeftLocale( void ) const {
  162. // BUGBUG
  163. // this is not implemented, and it may not act properly when implemented,
  164. // Look at the the usage as well
  165. return FALSE;
  166. }
  167. ////////////////////////////////////////////////////////////////////////////////////////////////////
  168. // Data Setting and validation funcs
  169. ////////////////////////////////////////////////////////////////////////////////////////////////////
  170. //--------------------------------------------------------------------------------------------------
  171. // _Set_hInstance
  172. BOOL CPropertySheetPage::_Set_hInstance( HINSTANCE hInst ) {
  173. #ifdef CPropertySheetPage_ValidateParameters
  174. if( NULL == hInst ) { assert( 0 ); return FALSE; }
  175. #endif // CPropertySheetPage_ValidateParameters
  176. this -> hInstance = hInst;
  177. return TRUE;
  178. }
  179. //--------------------------------------------------------------------------------------------------
  180. // _Set_pszTemplate
  181. BOOL CPropertySheetPage::_Set_pszTemplate( LPCTSTR pszTemplate ) {
  182. #ifdef CPropertySheetPage_ValidateParameters
  183. if( NULL == pszTemplate ) { assert( 0 ); return FALSE; }
  184. if( this -> dwFlags & PSP_DLGINDIRECT ) { // If the PSP_DLGINDIRECT is set, pszTemplate is ignored
  185. assert( 0 );
  186. return FALSE;
  187. }
  188. #endif // CPropertySheetPage_ValidateParameters
  189. this -> pszTemplate = pszTemplate;
  190. return TRUE;
  191. }
  192. //--------------------------------------------------------------------------------------------------
  193. // _Set_pResource
  194. BOOL CPropertySheetPage::_Set_pResource( LPCDLGTEMPLATE pResource ) {
  195. #ifdef CPropertySheetPage_ValidateParameters
  196. if( NULL == pResource ) { assert( 0 ); return FALSE; }
  197. #endif // CPropertySheetPage_ValidateParameters
  198. this -> pResource = pResource;
  199. this -> dwFlags |= PSP_DLGINDIRECT;
  200. return TRUE;
  201. }
  202. //--------------------------------------------------------------------------------------------------
  203. // _Set_hIcon
  204. BOOL CPropertySheetPage::_Set_hIcon( HICON hIcon ) {
  205. #ifdef CPropertySheetPage_ValidateParameters
  206. if( ( NULL == hIcon ) && ( dwFlags & PSP_USEHICON ) ) { assert( 0 ); return FALSE; }
  207. if ( dwFlags & PSP_USEICONID ) { assert( 0 ); return FALSE; }
  208. #endif // CPropertySheetPage_ValidateParameters
  209. if( NULL != hIcon ) {
  210. this -> dwFlags |= PSP_USEHICON;
  211. this -> hIcon = hIcon;
  212. }
  213. return TRUE;
  214. }
  215. //--------------------------------------------------------------------------------------------------
  216. // _Set_pszIcon
  217. BOOL CPropertySheetPage::_Set_pszIcon( LPCTSTR pszIcon ) {
  218. #ifdef CPropertySheetPage_ValidateParameters
  219. if( ( NULL == pszIcon ) && ( dwFlags & PSP_USEICONID ) ) { // This is a bad parameter
  220. assert( 0 );
  221. return FALSE;
  222. }
  223. if ( dwFlags & PSP_USEHICON ) { // Wrong function signature, use the one that takes LPCTSTR pszIcon /* =0 */
  224. assert( 0 );
  225. return FALSE;
  226. }
  227. #endif // CPropertySheetPage_ValidateParameters
  228. if( NULL != pszIcon ) {
  229. this -> pszIcon = pszIcon;
  230. this -> dwFlags |= PSP_USEICONID;
  231. }
  232. return TRUE;
  233. }
  234. //--------------------------------------------------------------------------------------------------
  235. // _Set_pszTitle
  236. BOOL CPropertySheetPage::_Set_pszTitle( LPCTSTR pszTitle ) {
  237. #ifdef CPropertySheetPage_ValidateParameters
  238. if( ( NULL == pszTitle ) && ( dwFlags & PSP_USETITLE ) ) { // This is a bad parameter
  239. assert( 0 );
  240. return FALSE;
  241. }
  242. #endif // CPropertySheetPage_ValidateParameters
  243. if( NULL != pszTitle ) {
  244. this -> pszTitle = pszTitle;
  245. this -> dwFlags |= PSP_USETITLE;
  246. }
  247. return TRUE;
  248. }
  249. //--------------------------------------------------------------------------------------------------
  250. // _Set_pfnDlgProc
  251. BOOL CPropertySheetPage::_Set_pfnDlgProc( DLGPROC pfnDlgProc ) {
  252. #ifdef CPropertySheetPage_ValidateParameters
  253. if( NULL == pfnDlgProc ) { assert( 0 ); return FALSE; }
  254. #endif // CPropertySheetPage_ValidateParameters
  255. this -> pfnDlgProc = pfnDlgProc;
  256. return TRUE;
  257. }
  258. //--------------------------------------------------------------------------------------------------
  259. // _Set_pfnCallback
  260. BOOL CPropertySheetPage::_Set_pfnCallback( LPFNPSPCALLBACK pfnCallBack ) {
  261. #ifdef CPropertySheetPage_ValidateParameters
  262. if( ( NULL == pfnCallBack ) && ( dwFlags & PSP_USECALLBACK ) ) { // This is a bad parameter
  263. assert( 0 );
  264. return FALSE;
  265. }
  266. #endif // CPropertySheetPage_ValidateParameters
  267. if( NULL != pfnCallback ) {
  268. this -> pfnCallback = pfnCallback;
  269. this -> dwFlags |= PSP_USECALLBACK;
  270. }
  271. return TRUE;
  272. }
  273. //--------------------------------------------------------------------------------------------------
  274. // _Set_pcRefParent
  275. BOOL CPropertySheetPage::_Set_pcRefParent( UINT FAR * pcRefParent ) {
  276. #ifdef CPropertySheetPage_ValidateParameters
  277. if( ( NULL == pcRefParent ) && ( dwFlags & PSP_USEREFPARENT ) ) { // This is a bad parameter
  278. assert( 0 );
  279. return FALSE;
  280. }
  281. #endif // CPropertySheetPage_ValidateParameters
  282. if( NULL != pcRefParent ) {
  283. this -> pcRefParent = pcRefParent;
  284. this -> dwFlags |= PSP_USEREFPARENT;
  285. }
  286. return TRUE;
  287. }
  288. //--------------------------------------------------------------------------------------------------
  289. // _Set_lParam
  290. BOOL CPropertySheetPage::_Set_lParam( LPARAM lParam ) {
  291. #ifdef CPropertySheetPage_ValidateParameters
  292. #endif // CPropertySheetPage_ValidateParameters
  293. this -> lParam = lParam;
  294. return TRUE;
  295. }
  296. //--------------------------------------------------------------------------------------------------
  297. // _Validate
  298. BOOL CPropertySheetPage::_Validate( void ) const {
  299. #ifdef CPropertySheetPage_ValidateParameters
  300. // Make sure there are no mutually exclusize flags set
  301. if( ( this -> dwFlags & PSP_USEICONID ) && ( this -> dwFlags & PSP_USEHICON ) ) {
  302. assert( 0 );
  303. return FALSE;
  304. }
  305. // Make sure that the data is valid ( for set flags )
  306. if( this -> dwFlags & PSP_DLGINDIRECT ) { // We must validate pResource
  307. if( NULL == pResource ) {
  308. assert( 0 );
  309. return FALSE;
  310. }
  311. }
  312. else { // We must validate pszTemplate
  313. if( NULL == this -> pszTemplate ) {
  314. assert( 0 );
  315. return FALSE;
  316. }
  317. }
  318. if( this -> dwFlags & PSP_USECALLBACK ) {
  319. if( NULL == this -> pfnCallback ) {
  320. assert( 0 );
  321. return FALSE;
  322. }
  323. }
  324. if( this -> dwFlags & PSP_USEREFPARENT ) {
  325. if( NULL == this -> pcRefParent ) {
  326. assert( 0 );
  327. return FALSE;
  328. }
  329. }
  330. if( this -> dwFlags & PSP_USETITLE ) {
  331. if( NULL == this -> pszTitle ) {
  332. assert( 0 );
  333. return FALSE;
  334. }
  335. }
  336. #endif // CPropertySheetPage_ValidateParameters
  337. return TRUE;
  338. }