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.

217 lines
6.0 KiB

  1. /////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000-2001.
  5. //
  6. // File: AddApprovalDlg.cpp
  7. //
  8. // Contents: Implementation of CAddApprovalDlg
  9. //
  10. //----------------------------------------------------------------------------
  11. // AddApprovalDlg.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "certtmpl.h"
  15. #include "AddApprovalDlg.h"
  16. #include "PolicyOID.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. extern POLICY_OID_LIST g_policyOIDList;
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CAddApprovalDlg dialog
  25. CAddApprovalDlg::CAddApprovalDlg(CWnd* pParent, const PSTR* paszUsedApprovals)
  26. : CHelpDialog(CAddApprovalDlg::IDD, pParent),
  27. m_paszReturnedApprovals (0),
  28. m_paszUsedApprovals (paszUsedApprovals)
  29. {
  30. //{{AFX_DATA_INIT(CAddApprovalDlg)
  31. //}}AFX_DATA_INIT
  32. }
  33. CAddApprovalDlg::~CAddApprovalDlg()
  34. {
  35. if ( m_paszReturnedApprovals )
  36. {
  37. for (int nIndex = 0; m_paszReturnedApprovals[nIndex]; nIndex++)
  38. delete [] m_paszReturnedApprovals[nIndex];
  39. delete [] m_paszReturnedApprovals;
  40. }
  41. }
  42. void CAddApprovalDlg::DoDataExchange(CDataExchange* pDX)
  43. {
  44. CHelpDialog::DoDataExchange(pDX);
  45. //{{AFX_DATA_MAP(CAddApprovalDlg)
  46. DDX_Control(pDX, IDC_APPROVAL_LIST, m_issuanceList);
  47. //}}AFX_DATA_MAP
  48. }
  49. BEGIN_MESSAGE_MAP(CAddApprovalDlg, CHelpDialog)
  50. //{{AFX_MSG_MAP(CAddApprovalDlg)
  51. ON_LBN_SELCHANGE(IDC_APPROVAL_LIST, OnSelchangeApprovalList)
  52. ON_LBN_DBLCLK(IDC_APPROVAL_LIST, OnDblclkApprovalList)
  53. //}}AFX_MSG_MAP
  54. END_MESSAGE_MAP()
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CAddApprovalDlg message handlers
  57. BOOL CAddApprovalDlg::OnInitDialog()
  58. {
  59. CHelpDialog::OnInitDialog();
  60. for (POSITION nextPos = g_policyOIDList.GetHeadPosition (); nextPos; )
  61. {
  62. CPolicyOID* pPolicyOID = g_policyOIDList.GetNext (nextPos);
  63. if ( pPolicyOID )
  64. {
  65. // If this is the Application OID dialog, show only application
  66. // OIDS, otherwise if this is the Issuance OID dialog, show only
  67. // issuance OIDs
  68. if ( pPolicyOID->IsIssuanceOID () )
  69. {
  70. bool bFound = false;
  71. // Don't display an approval that's already been used
  72. if ( m_paszUsedApprovals )
  73. {
  74. for (int nIndex = 0; m_paszUsedApprovals[nIndex]; nIndex++)
  75. {
  76. if ( !strcmp (pPolicyOID->GetOIDA (), m_paszUsedApprovals[nIndex]) )
  77. {
  78. bFound = true;
  79. break;
  80. }
  81. }
  82. }
  83. if ( !bFound )
  84. {
  85. int nIndex = m_issuanceList.AddString (pPolicyOID->GetDisplayName ());
  86. if ( nIndex >= 0 )
  87. {
  88. LPSTR pszOID = new CHAR[strlen (pPolicyOID->GetOIDA ())+1];
  89. if ( pszOID )
  90. {
  91. strcpy (pszOID, pPolicyOID->GetOIDA ());
  92. m_issuanceList.SetItemDataPtr (nIndex, pszOID);
  93. }
  94. }
  95. }
  96. }
  97. }
  98. }
  99. return TRUE; // return TRUE unless you set the focus to a control
  100. // EXCEPTION: OCX Property Pages should return FALSE
  101. }
  102. void CAddApprovalDlg::EnableControls()
  103. {
  104. GetDlgItem (IDOK)->EnableWindow (m_issuanceList.GetSelCount () > 0);
  105. }
  106. void CAddApprovalDlg::OnOK()
  107. {
  108. int nSelectedCnt = m_issuanceList.GetSelCount ();
  109. // allocate an array of PSTR pointers and set each item to an approval.
  110. // Set the last to NULL
  111. if ( nSelectedCnt )
  112. {
  113. int* pnSelItems = new int[nSelectedCnt];
  114. if ( pnSelItems )
  115. {
  116. if ( LB_ERR != m_issuanceList.GetSelItems (nSelectedCnt, pnSelItems) )
  117. {
  118. m_paszReturnedApprovals = new PSTR[nSelectedCnt+1];
  119. if ( m_paszReturnedApprovals )
  120. {
  121. ::ZeroMemory (m_paszReturnedApprovals, sizeof (PSTR) * (nSelectedCnt+1));
  122. for (int nIndex = 0; nIndex < nSelectedCnt; nIndex++)
  123. {
  124. PSTR pszPolicyOID = (PSTR) m_issuanceList.GetItemData (pnSelItems[nIndex]);
  125. if ( pszPolicyOID )
  126. {
  127. PSTR pNewStr = new CHAR[strlen (pszPolicyOID) + 1];
  128. if ( pNewStr )
  129. {
  130. strcpy (pNewStr, pszPolicyOID);
  131. m_paszReturnedApprovals[nIndex] = pNewStr;
  132. }
  133. else
  134. break;
  135. }
  136. }
  137. }
  138. }
  139. delete [] pnSelItems;
  140. }
  141. }
  142. CHelpDialog::OnOK();
  143. }
  144. bool CAddApprovalDlg::ApprovalAlreadyUsed(PCSTR pszOID) const
  145. {
  146. bool bResult = false;
  147. if ( m_paszUsedApprovals )
  148. {
  149. for (int nIndex = 0; m_paszUsedApprovals[nIndex]; nIndex++)
  150. {
  151. if ( !strcmp (m_paszUsedApprovals[nIndex], pszOID) )
  152. {
  153. bResult = true;
  154. break;
  155. }
  156. }
  157. }
  158. return bResult;
  159. }
  160. void CAddApprovalDlg::DoContextHelp (HWND hWndControl)
  161. {
  162. _TRACE(1, L"Entering CAddApprovalDlg::DoContextHelp\n");
  163. switch (::GetDlgCtrlID (hWndControl))
  164. {
  165. case IDC_STATIC:
  166. break;
  167. default:
  168. // Display context help for a control
  169. if ( !::WinHelp (
  170. hWndControl,
  171. GetContextHelpFile (),
  172. HELP_WM_HELP,
  173. (DWORD_PTR) g_aHelpIDs_IDD_ADD_APPROVAL) )
  174. {
  175. _TRACE(0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  176. }
  177. break;
  178. }
  179. _TRACE(-1, L"Leaving CAddApprovalDlg::DoContextHelp\n");
  180. }
  181. void CAddApprovalDlg::OnSelchangeApprovalList()
  182. {
  183. EnableControls ();
  184. }
  185. void CAddApprovalDlg::OnDblclkApprovalList()
  186. {
  187. OnOK ();
  188. }