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.

385 lines
11 KiB

  1. /////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000-2001.
  5. //
  6. // File: ViewOIDDlg.cpp
  7. //
  8. // Contents: Implementation of CViewOIDDlg
  9. //
  10. //----------------------------------------------------------------------------
  11. // ViewOIDDlg.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "certtmpl.h"
  15. #include "ViewOIDDlg.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. extern POLICY_OID_LIST g_policyOIDList;
  22. extern PCWSTR pcszNEWLINE;
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CViewOIDDlg dialog
  25. CViewOIDDlg::CViewOIDDlg(CWnd* pParent /*=NULL*/)
  26. : CHelpDialog(CViewOIDDlg::IDD, pParent)
  27. {
  28. //{{AFX_DATA_INIT(CViewOIDDlg)
  29. // NOTE: the ClassWizard will add member initialization here
  30. //}}AFX_DATA_INIT
  31. }
  32. void CViewOIDDlg::DoDataExchange(CDataExchange* pDX)
  33. {
  34. CHelpDialog::DoDataExchange(pDX);
  35. //{{AFX_DATA_MAP(CViewOIDDlg)
  36. DDX_Control(pDX, IDC_OID_LIST, m_oidList);
  37. //}}AFX_DATA_MAP
  38. }
  39. BEGIN_MESSAGE_MAP(CViewOIDDlg, CHelpDialog)
  40. //{{AFX_MSG_MAP(CViewOIDDlg)
  41. ON_NOTIFY(LVN_ITEMCHANGED, IDC_OID_LIST, OnItemchangedOidList)
  42. ON_BN_CLICKED(IDC_COPY_OID, OnCopyOid)
  43. ON_NOTIFY(LVN_COLUMNCLICK, IDC_OID_LIST, OnColumnclickOidList)
  44. //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CViewOIDDlg message handlers
  48. BOOL CViewOIDDlg::OnInitDialog()
  49. {
  50. CHelpDialog::OnInitDialog();
  51. GetDlgItem (IDC_COPY_OID)->EnableWindow (FALSE);
  52. // Set up list control
  53. int colWidths[NUM_COLS] = {200, 150, 100, 100};
  54. // Set to full-row select
  55. DWORD dwExstyle = m_oidList.GetExtendedStyle ();
  56. m_oidList.SetExtendedStyle (dwExstyle | LVS_EX_FULLROWSELECT);
  57. // Add "Policy Name" column
  58. CString szText;
  59. VERIFY (szText.LoadString (IDS_POLICY_NAME));
  60. VERIFY (m_oidList.InsertColumn (COL_POLICY_NAME, (LPCWSTR) szText,
  61. LVCFMT_LEFT, colWidths[COL_POLICY_NAME], COL_POLICY_NAME) != -1);
  62. VERIFY (szText.LoadString (IDS_OID));
  63. VERIFY (m_oidList.InsertColumn (COL_OID, (LPCWSTR) szText,
  64. LVCFMT_LEFT, colWidths[COL_OID], COL_OID) != -1);
  65. VERIFY (szText.LoadString (IDS_POLICY_TYPE));
  66. VERIFY (m_oidList.InsertColumn (COL_POLICY_TYPE, (LPCWSTR) szText,
  67. LVCFMT_LEFT, colWidths[COL_POLICY_TYPE], COL_POLICY_TYPE) != -1);
  68. VERIFY (szText.LoadString (IDS_CPS_LOCATION));
  69. VERIFY (m_oidList.InsertColumn (COL_CPS_LOCATION, (LPCWSTR) szText,
  70. LVCFMT_LEFT, colWidths[COL_CPS_LOCATION], COL_CPS_LOCATION) != -1);
  71. m_oidList.SetColumnWidth (COL_CPS_LOCATION, LVSCW_AUTOSIZE_USEHEADER);
  72. // Fill list
  73. for (POSITION nextPos = g_policyOIDList.GetHeadPosition (); nextPos; )
  74. {
  75. CPolicyOID* pPolicyOID = g_policyOIDList.GetNext (nextPos);
  76. if ( pPolicyOID )
  77. {
  78. if ( FAILED (InsertItemInList (pPolicyOID)) )
  79. break;
  80. }
  81. }
  82. return TRUE; // return TRUE unless you set the focus to a control
  83. // EXCEPTION: OCX Property Pages should return FALSE
  84. }
  85. HRESULT CViewOIDDlg::InsertItemInList (CPolicyOID* pPolicyOID)
  86. {
  87. ASSERT (pPolicyOID);
  88. if ( !pPolicyOID )
  89. return E_POINTER;
  90. if ( !pPolicyOID->IsApplicationOID () && !pPolicyOID->IsIssuanceOID () )
  91. return S_OK; // not a failure, but don't add
  92. HRESULT hr = S_OK;
  93. LV_ITEM lvItem;
  94. int iItem = m_oidList.GetItemCount ();
  95. int iResult = 0;
  96. ::ZeroMemory (&lvItem, sizeof (lvItem));
  97. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  98. lvItem.iItem = iItem;
  99. lvItem.iSubItem = COL_POLICY_NAME;
  100. lvItem.pszText = (PWSTR)(PCWSTR) pPolicyOID->GetDisplayName ();
  101. lvItem.lParam = (LPARAM) pPolicyOID;
  102. iItem = m_oidList.InsertItem (&lvItem);
  103. ASSERT (-1 != iItem);
  104. if ( -1 == iItem )
  105. hr = E_FAIL;
  106. if ( SUCCEEDED (hr) )
  107. {
  108. ::ZeroMemory (&lvItem, sizeof (lvItem));
  109. lvItem.mask = LVIF_TEXT;
  110. lvItem.iItem = iItem;
  111. lvItem.iSubItem = COL_OID;
  112. lvItem.pszText = (PWSTR)(PCWSTR) pPolicyOID->GetOIDW ();
  113. iResult = m_oidList.SetItem (&lvItem);
  114. ASSERT (-1 != iResult);
  115. if ( -1 == iResult )
  116. hr = E_FAIL;
  117. }
  118. if ( SUCCEEDED (hr) )
  119. {
  120. lvItem.iSubItem = COL_POLICY_TYPE;
  121. CString text;
  122. if ( pPolicyOID->IsApplicationOID () )
  123. VERIFY (text.LoadString (IDS_APPLICATION));
  124. else // Is issuance OID
  125. VERIFY (text.LoadString (IDS_ISSUANCE));
  126. lvItem.pszText = (PWSTR)(PCWSTR) text;
  127. iResult = m_oidList.SetItem (&lvItem);
  128. ASSERT (-1 != iResult);
  129. if ( -1 == iResult )
  130. hr = E_FAIL;
  131. }
  132. if ( SUCCEEDED (hr) && pPolicyOID->IsIssuanceOID () )
  133. {
  134. lvItem.iSubItem = COL_CPS_LOCATION;
  135. PWSTR pszCPS = 0;
  136. hr = CAOIDGetProperty(
  137. pPolicyOID->GetOIDW (),
  138. CERT_OID_PROPERTY_CPS,
  139. &pszCPS);
  140. if ( SUCCEEDED (hr) )
  141. {
  142. lvItem.pszText = pszCPS;
  143. iResult = m_oidList.SetItem (&lvItem);
  144. ASSERT (-1 != iResult);
  145. if ( -1 == iResult )
  146. hr = E_FAIL;
  147. CAOIDFreeProperty (pszCPS);
  148. }
  149. else if ( HRESULT_FROM_WIN32 (ERROR_FILE_NOT_FOUND) == hr ||
  150. HRESULT_FROM_WIN32 (ERROR_DS_OBJ_NOT_FOUND) == hr )
  151. {
  152. hr = S_OK;
  153. }
  154. else
  155. {
  156. _TRACE (0, L"CAOIDGetProperty (%s, CERT_OID_PROPERTY_CPS) failed: 0x%x\n",
  157. (PCWSTR) pPolicyOID->GetOIDW (), hr);
  158. hr = S_OK;
  159. }
  160. }
  161. return hr;
  162. }
  163. void CViewOIDDlg::OnItemchangedOidList(NMHDR* /*pNMHDR*/, LRESULT* pResult)
  164. {
  165. // NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  166. GetDlgItem (IDC_COPY_OID)->EnableWindow (m_oidList.GetSelectedCount () > 0);
  167. *pResult = 0;
  168. }
  169. void CViewOIDDlg::OnCopyOid()
  170. {
  171. CString szText;
  172. int nCnt = m_oidList.GetItemCount ();
  173. if ( nCnt > 0 && m_oidList.GetSelectedCount () > 0 )
  174. {
  175. for (int nItem = 0; nItem < nCnt; nItem++)
  176. {
  177. if ( LVIS_SELECTED == m_oidList.GetItemState (nItem, LVIS_SELECTED) )
  178. {
  179. if ( !szText.IsEmpty () )
  180. szText += pcszNEWLINE;
  181. szText += m_oidList.GetItemText (nItem, COL_OID);
  182. }
  183. }
  184. }
  185. if ( !szText.IsEmpty () )
  186. {
  187. if ( OpenClipboard () )
  188. {
  189. if ( EmptyClipboard () )
  190. {
  191. size_t nLen = wcslen (szText);
  192. HGLOBAL hglbCopy = GlobalAlloc (GMEM_MOVEABLE,
  193. (nLen + 1) * sizeof (WCHAR));
  194. if ( hglbCopy )
  195. {
  196. PWSTR pszCopy = (PWSTR) GlobalLock (hglbCopy);
  197. if ( pszCopy )
  198. {
  199. wcscpy (pszCopy, szText);
  200. GlobalUnlock(hglbCopy);
  201. // Place the handle on the clipboard.
  202. if ( !SetClipboardData (CF_UNICODETEXT, hglbCopy) )
  203. {
  204. ASSERT (0);
  205. _TRACE (0, L"SetClipboardData () failed: %d\n", GetLastError ());
  206. GlobalFree (hglbCopy);
  207. }
  208. }
  209. else
  210. GlobalFree (hglbCopy);
  211. }
  212. if ( !CloseClipboard () )
  213. {
  214. ASSERT (0);
  215. _TRACE (0, L"CloseClipboard () failed: %d\n", GetLastError ());
  216. }
  217. }
  218. else
  219. {
  220. ASSERT (0);
  221. _TRACE (0, L"EmptyClipboard () failed: %d\n", GetLastError ());
  222. }
  223. }
  224. else
  225. {
  226. ASSERT (0);
  227. _TRACE (0, L"OpenClipboard () failed: %d\n", GetLastError ());
  228. }
  229. }
  230. }
  231. int CALLBACK CViewOIDDlg::fnCompareOIDItems (LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  232. {
  233. int iVal = 0;
  234. if ( lParam1 && lParam2 )
  235. {
  236. CPolicyOID* pPolicyOID1 = (CPolicyOID*) lParam1;
  237. CPolicyOID* pPolicyOID2 = (CPolicyOID*) lParam2;
  238. switch (lParamSort)
  239. {
  240. case COL_POLICY_NAME:
  241. iVal = LocaleStrCmp (pPolicyOID1->GetDisplayName (),
  242. pPolicyOID2->GetDisplayName ());
  243. break;
  244. case COL_OID:
  245. iVal = LocaleStrCmp (pPolicyOID1->GetOIDW (),
  246. pPolicyOID2->GetOIDW ());
  247. break;
  248. case COL_POLICY_TYPE:
  249. {
  250. CString szApplication;
  251. CString szIssuance;
  252. VERIFY (szApplication.LoadString (IDS_APPLICATION));
  253. VERIFY (szIssuance.LoadString (IDS_ISSUANCE));
  254. iVal = LocaleStrCmp (pPolicyOID1->IsApplicationOID () ? szApplication : szIssuance,
  255. pPolicyOID2->IsApplicationOID () ? szApplication : szIssuance);
  256. }
  257. break;
  258. case COL_CPS_LOCATION:
  259. {
  260. CString strItem1;
  261. CString strItem2;
  262. if ( pPolicyOID1->IsIssuanceOID () )
  263. {
  264. PWSTR pszCPS = 0;
  265. if ( SUCCEEDED (CAOIDGetProperty(
  266. pPolicyOID1->GetOIDW (),
  267. CERT_OID_PROPERTY_CPS,
  268. &pszCPS)) )
  269. {
  270. strItem1 = pszCPS;
  271. }
  272. }
  273. if ( pPolicyOID2->IsIssuanceOID () )
  274. {
  275. PWSTR pszCPS = 0;
  276. if ( SUCCEEDED (CAOIDGetProperty(
  277. pPolicyOID2->GetOIDW (),
  278. CERT_OID_PROPERTY_CPS,
  279. &pszCPS)) )
  280. {
  281. strItem2 = pszCPS;
  282. }
  283. }
  284. iVal = LocaleStrCmp (strItem1, strItem2);
  285. }
  286. break;
  287. default:
  288. ASSERT (0);
  289. break;
  290. }
  291. }
  292. return iVal;
  293. }
  294. void CViewOIDDlg::OnColumnclickOidList(NMHDR* pNMHDR, LRESULT* pResult)
  295. {
  296. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  297. if ( pNMListView )
  298. {
  299. m_oidList.SortItems ((PFNLVCOMPARE) fnCompareOIDItems,
  300. (LPARAM) pNMListView->iSubItem);
  301. }
  302. *pResult = 0;
  303. }
  304. void CViewOIDDlg::DoContextHelp (HWND hWndControl)
  305. {
  306. _TRACE(1, L"Entering CViewOIDDlg::DoContextHelp\n");
  307. switch (::GetDlgCtrlID (hWndControl))
  308. {
  309. case IDC_STATIC:
  310. break;
  311. default:
  312. // Display context help for a control
  313. if ( !::WinHelp (
  314. hWndControl,
  315. GetContextHelpFile (),
  316. HELP_WM_HELP,
  317. (DWORD_PTR) g_aHelpIDs_IDD_VIEW_OIDS) )
  318. {
  319. _TRACE (0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  320. }
  321. break;
  322. }
  323. _TRACE(-1, L"Leaving CViewOIDDlg::DoContextHelp\n");
  324. }