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.

234 lines
6.5 KiB

  1. /////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2002.
  5. //
  6. // File: SelectCSPDlg.cpp
  7. //
  8. // Contents: Implementation of CSelectCSPDlg
  9. //
  10. //----------------------------------------------------------------------------
  11. //
  12. // SelectCSPDlg.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include "certtmpl.h"
  16. #include "SelectCSPDlg.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CSelectCSPDlg dialog
  24. CSelectCSPDlg::CSelectCSPDlg(
  25. CWnd* pParent,
  26. CCertTemplate& rCertTemplate,
  27. CSP_LIST& rCSPList,
  28. int& rnProvDSSCnt)
  29. : CHelpDialog(CSelectCSPDlg::IDD, pParent),
  30. m_rCertTemplate (rCertTemplate),
  31. m_rCSPList (rCSPList),
  32. m_rnProvDSSCnt (rnProvDSSCnt),
  33. m_nSelected (0),
  34. m_bDirty (false)
  35. {
  36. //{{AFX_DATA_INIT(CSelectCSPDlg)
  37. // NOTE: the ClassWizard will add member initialization here
  38. //}}AFX_DATA_INIT
  39. }
  40. void CSelectCSPDlg::DoDataExchange(CDataExchange* pDX)
  41. {
  42. CHelpDialog::DoDataExchange(pDX);
  43. //{{AFX_DATA_MAP(CSelectCSPDlg)
  44. DDX_Control(pDX, IDC_CSP_LIST, m_CSPListbox);
  45. //}}AFX_DATA_MAP
  46. }
  47. BEGIN_MESSAGE_MAP(CSelectCSPDlg, CHelpDialog)
  48. //{{AFX_MSG_MAP(CSelectCSPDlg)
  49. ON_BN_CLICKED(IDC_USE_ANY_CSP, OnUseAnyCsp)
  50. ON_BN_CLICKED(IDC_USE_SELECTED_CSPS, OnUseSelectedCsps)
  51. //}}AFX_MSG_MAP
  52. ON_CONTROL(CLBN_CHKCHANGE, IDC_CSP_LIST, OnCheckChange)
  53. END_MESSAGE_MAP()
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CSelectCSPDlg message handlers
  56. BOOL CSelectCSPDlg::OnInitDialog()
  57. {
  58. CHelpDialog::OnInitDialog();
  59. CString szCSP;
  60. CString szInvalidCSPs;
  61. for (POSITION nextPos = m_rCSPList.GetHeadPosition (); nextPos; )
  62. {
  63. CT_CSP_DATA* pCSPData = m_rCSPList.GetNext (nextPos);
  64. if ( pCSPData )
  65. {
  66. if ( pCSPData->m_bConforming )
  67. {
  68. int nIndex = m_CSPListbox.AddString (pCSPData->m_szName);
  69. ASSERT (nIndex >= 0);
  70. if ( nIndex >= 0 )
  71. {
  72. if ( pCSPData->m_bSelected )
  73. {
  74. m_CSPListbox.SetCheck (nIndex, BST_CHECKED);
  75. m_nSelected++;
  76. }
  77. VERIFY (LB_ERR != m_CSPListbox.SetItemData (nIndex, (DWORD_PTR) pCSPData));
  78. }
  79. else
  80. {
  81. break;
  82. }
  83. }
  84. }
  85. }
  86. if ( m_nSelected > 0 )
  87. SendDlgItemMessage (IDC_USE_SELECTED_CSPS, BM_SETCHECK, BST_CHECKED);
  88. else
  89. SendDlgItemMessage (IDC_USE_ANY_CSP, BM_SETCHECK, BST_CHECKED);
  90. EnableControls ();
  91. return TRUE; // return TRUE unless you set the focus to a control
  92. // EXCEPTION: OCX Property Pages should return FALSE
  93. }
  94. void CSelectCSPDlg::EnableControls ()
  95. {
  96. if ( m_rCertTemplate.ReadOnly () )
  97. {
  98. GetDlgItem (IDC_LABEL)->EnableWindow (FALSE);
  99. GetDlgItem (IDC_USE_ANY_CSP)->EnableWindow (FALSE);
  100. GetDlgItem (IDC_USE_SELECTED_CSPS)->EnableWindow (FALSE);
  101. GetDlgItem (IDC_CSP_LIST_LABEL)->EnableWindow (FALSE);
  102. int nCnt = m_CSPListbox.GetCount ();
  103. for (int nIndex = 0; nIndex < nCnt; nIndex++)
  104. m_CSPListbox.Enable (nIndex, FALSE);
  105. GetDlgItem (IDOK)->EnableWindow (FALSE);
  106. }
  107. else
  108. {
  109. BOOL bEnable = FALSE;
  110. if ( BST_CHECKED == SendDlgItemMessage (IDC_USE_SELECTED_CSPS, BM_GETCHECK) )
  111. bEnable = TRUE;
  112. GetDlgItem (IDC_CSP_LIST_LABEL)->EnableWindow (bEnable);
  113. int nCnt = m_CSPListbox.GetCount ();
  114. for (int nIndex = 0; nIndex < nCnt; nIndex++)
  115. m_CSPListbox.Enable (nIndex, bEnable);
  116. GetDlgItem (IDOK)->EnableWindow (m_bDirty ? TRUE : FALSE);
  117. }
  118. }
  119. void CSelectCSPDlg::DoContextHelp (HWND hWndControl)
  120. {
  121. _TRACE(1, L"Entering CSelectCSPDlg::DoContextHelp\n");
  122. switch (::GetDlgCtrlID (hWndControl))
  123. {
  124. case IDC_STATIC:
  125. case IDC_CSP_LIST_LABEL:
  126. break;
  127. default:
  128. // Display context help for a control
  129. if ( !::WinHelp (
  130. hWndControl,
  131. GetContextHelpFile (),
  132. HELP_WM_HELP,
  133. (DWORD_PTR) g_aHelpIDs_IDD_CSP_SELECTION) )
  134. {
  135. _TRACE(0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  136. }
  137. break;
  138. }
  139. _TRACE(-1, L"Leaving CSelectCSPDlg::DoContextHelp\n");
  140. }
  141. void CSelectCSPDlg::OnCheckChange()
  142. {
  143. int nSel = m_CSPListbox.GetCurSel ();
  144. if ( nSel >= 0 )
  145. {
  146. if ( BST_CHECKED == m_CSPListbox.GetCheck (nSel) )
  147. {
  148. CT_CSP_DATA* pData = (CT_CSP_DATA*) m_CSPListbox.GetItemData (nSel);
  149. ASSERT (pData);
  150. if ( pData )
  151. {
  152. pData->m_bSelected = true;
  153. if ( PROV_DSS == pData->m_dwProvType || PROV_DSS_DH == pData->m_dwProvType )
  154. m_rnProvDSSCnt++;
  155. }
  156. m_nSelected++;
  157. }
  158. else
  159. {
  160. CT_CSP_DATA* pData = (CT_CSP_DATA*) m_CSPListbox.GetItemData (nSel);
  161. ASSERT (pData);
  162. if ( pData )
  163. {
  164. pData->m_bSelected = false;
  165. if ( PROV_DSS == pData->m_dwProvType || PROV_DSS_DH == pData->m_dwProvType )
  166. m_rnProvDSSCnt--;
  167. }
  168. m_nSelected--;
  169. }
  170. m_bDirty = true;
  171. }
  172. ASSERT (m_nSelected >= 0);
  173. EnableControls ();
  174. }
  175. void CSelectCSPDlg::OnUseAnyCsp()
  176. {
  177. // clear all checks and selection
  178. int nCnt = m_CSPListbox.GetCount ();
  179. for (int nIndex = 0; nIndex < nCnt; nIndex++)
  180. {
  181. m_CSPListbox.SetCheck (nIndex, BST_UNCHECKED);
  182. }
  183. for (POSITION nextPos = m_rCSPList.GetHeadPosition (); nextPos; )
  184. {
  185. CT_CSP_DATA* pCSPData = m_rCSPList.GetNext (nextPos);
  186. if ( pCSPData )
  187. {
  188. if ( pCSPData->m_bSelected )
  189. {
  190. pCSPData->m_bSelected = false;
  191. m_bDirty = true;
  192. }
  193. }
  194. }
  195. EnableControls ();
  196. }
  197. void CSelectCSPDlg::OnUseSelectedCsps()
  198. {
  199. EnableControls ();
  200. }