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.

545 lines
17 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: ccertbmp.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "global.hxx"
  11. #include <dbgdef.h>
  12. #define SELPALMODE TRUE
  13. //////////////////////////////////////////////////////////////////////////////////////
  14. //
  15. //////////////////////////////////////////////////////////////////////////////////////
  16. CCertificateBmp::CCertificateBmp()
  17. {
  18. m_fInitialized = FALSE;
  19. m_hpal = NULL;
  20. m_hbmpMiniCertOK = NULL;
  21. m_hbmpMiniCertNotOK = NULL;
  22. m_hbmbMiniCertExclamation = NULL;
  23. m_hbmbPKey = NULL;
  24. m_hWnd = NULL;
  25. m_hInst = NULL;
  26. m_pCertContext = NULL;
  27. m_dwChainError = 0;
  28. m_hWindowTextColorBrush = NULL;
  29. m_hWindowColorBrush = NULL;
  30. m_h3DLight = NULL;
  31. m_h3DHighLight = NULL;
  32. m_h3DLightShadow = NULL;
  33. m_h3DDarkShadow = NULL;
  34. m_fNoUsages = FALSE;
  35. }
  36. //////////////////////////////////////////////////////////////////////////////////////
  37. //
  38. //////////////////////////////////////////////////////////////////////////////////////
  39. CCertificateBmp::~CCertificateBmp()
  40. {
  41. if (m_hpal != NULL)
  42. {
  43. ::DeleteObject(m_hpal);
  44. }
  45. if (m_hbmpMiniCertOK != NULL)
  46. {
  47. ::DeleteObject(m_hbmpMiniCertOK);
  48. }
  49. if (m_hbmpMiniCertNotOK != NULL)
  50. {
  51. ::DeleteObject(m_hbmpMiniCertNotOK);
  52. }
  53. if (m_hbmbMiniCertExclamation != NULL)
  54. {
  55. ::DeleteObject(m_hbmbMiniCertExclamation);
  56. }
  57. if (m_hbmbPKey != NULL)
  58. {
  59. ::DeleteObject(m_hbmbPKey);
  60. }
  61. }
  62. //////////////////////////////////////////////////////////////////////////////////////
  63. //
  64. //////////////////////////////////////////////////////////////////////////////////////
  65. /*BOOL CCertificateBmp::IsTrueErrorString(DWORD dwError)
  66. {
  67. BOOL fRet;
  68. switch (dwError)
  69. {
  70. case CERT_E_CHAINING:
  71. case TRUST_E_BASIC_CONSTRAINTS:
  72. case CERT_E_PURPOSE:
  73. case CERT_E_WRONG_USAGE:
  74. fRet = FALSE;
  75. break;
  76. default:
  77. fRet = TRUE;
  78. break;
  79. }
  80. return fRet;
  81. }*/
  82. //////////////////////////////////////////////////////////////////////////////////////
  83. //
  84. //////////////////////////////////////////////////////////////////////////////////////
  85. void CCertificateBmp::SetChainError(DWORD dwError, BOOL fTrueError, BOOL fNoUsages)
  86. {
  87. m_dwChainError = dwError;
  88. m_fTrueError = fTrueError; //IsTrueErrorString(dwError);
  89. m_fNoUsages = fNoUsages;
  90. }
  91. //////////////////////////////////////////////////////////////////////////////////////
  92. //
  93. //////////////////////////////////////////////////////////////////////////////////////
  94. void CCertificateBmp::SetHinst(HINSTANCE hInst)
  95. {
  96. m_hInst = hInst;
  97. }
  98. //////////////////////////////////////////////////////////////////////////////////////
  99. //
  100. //////////////////////////////////////////////////////////////////////////////////////
  101. HINSTANCE CCertificateBmp::Hinst()
  102. {
  103. return m_hInst;
  104. }
  105. //////////////////////////////////////////////////////////////////////////////////////
  106. //
  107. //////////////////////////////////////////////////////////////////////////////////////
  108. void CCertificateBmp::SetWindow(HWND hWnd)
  109. {
  110. m_hWnd = hWnd;
  111. }
  112. //////////////////////////////////////////////////////////////////////////////////////
  113. //
  114. //////////////////////////////////////////////////////////////////////////////////////
  115. HWND CCertificateBmp::GetMyWindow()
  116. {
  117. return m_hWnd;
  118. }
  119. //////////////////////////////////////////////////////////////////////////////////////
  120. //
  121. //////////////////////////////////////////////////////////////////////////////////////
  122. LRESULT APIENTRY CCertificateBmpProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  123. {
  124. CCertificateBmp* This = (CCertificateBmp*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  125. switch (uMsg)
  126. {
  127. case WM_PAINT:
  128. CallWindowProc((WNDPROC)(This->m_prevProc), hwnd, uMsg, wParam, lParam);
  129. This->OnPaint();
  130. break;
  131. default:
  132. return CallWindowProc((WNDPROC)(This->m_prevProc), hwnd, uMsg, wParam, lParam);
  133. }
  134. return 0;
  135. }
  136. //////////////////////////////////////////////////////////////////////////////////////
  137. //
  138. //////////////////////////////////////////////////////////////////////////////////////
  139. void CCertificateBmp::DoSubclass()
  140. {
  141. SetWindowLongPtr(GetMyWindow(), GWLP_USERDATA, (LONG_PTR)this);
  142. //
  143. // hook the window proc so we can get first stab at the messages
  144. //
  145. m_prevProc = (WNDPROC)SetWindowLongPtr(GetMyWindow(), GWLP_WNDPROC, (LONG_PTR)CCertificateBmpProc);
  146. //
  147. // Set 'no class cursor' so that SetCursor will work.
  148. //
  149. m_hPrevCursor = (HCURSOR)SetClassLongPtr(GetMyWindow(), GCLP_HCURSOR, NULL);
  150. }
  151. //////////////////////////////////////////////////////////////////////////////////////
  152. //
  153. //////////////////////////////////////////////////////////////////////////////////////
  154. void CCertificateBmp::DoUnSubclass()
  155. {
  156. if (m_prevProc)
  157. {
  158. SetWindowLongPtr(GetMyWindow(), GWLP_WNDPROC, (LONG_PTR)m_prevProc);
  159. SetWindowLongPtr(GetMyWindow(), GCLP_HCURSOR, (LONG_PTR)m_hPrevCursor);
  160. m_prevProc = NULL;
  161. }
  162. }
  163. //////////////////////////////////////////////////////////////////////////////////////
  164. //
  165. //////////////////////////////////////////////////////////////////////////////////////
  166. void CCertificateBmp::SetRevoked(BOOL fRevoked)
  167. {
  168. m_fRevoked = fRevoked;
  169. }
  170. //////////////////////////////////////////////////////////////////////////////////////
  171. //
  172. //////////////////////////////////////////////////////////////////////////////////////
  173. BOOL CCertificateBmp::GetRevoked()
  174. {
  175. return m_fRevoked;
  176. }
  177. //////////////////////////////////////////////////////////////////////////////////////
  178. //
  179. //////////////////////////////////////////////////////////////////////////////////////
  180. void CCertificateBmp::SetCertContext(PCCERT_CONTEXT pCertContext, BOOL fHasPrivateKey)
  181. {
  182. m_pCertContext = pCertContext;
  183. m_fHasPrivateKey = fHasPrivateKey;
  184. }
  185. //////////////////////////////////////////////////////////////////////////////////////
  186. //
  187. //////////////////////////////////////////////////////////////////////////////////////
  188. PCCERT_CONTEXT CCertificateBmp::GetCertContext()
  189. {
  190. return m_pCertContext;
  191. }
  192. //////////////////////////////////////////////////////////////////////////////////////
  193. //
  194. //////////////////////////////////////////////////////////////////////////////////////
  195. void CCertificateBmp::InitializeBmp()
  196. {
  197. m_hbmpMiniCertNotOK = LoadResourceBitmap(Hinst(), MAKEINTRESOURCE(IDB_REVOKED_MINICERT), NULL);
  198. m_hbmpMiniCertOK = LoadResourceBitmap(Hinst(), MAKEINTRESOURCE(IDB_MINICERT), NULL);
  199. m_hbmbMiniCertExclamation = LoadResourceBitmap(Hinst(), MAKEINTRESOURCE(IDB_EXCLAMATION_MINICERT), NULL);
  200. m_hbmbPKey = LoadResourceBitmap(Hinst(), MAKEINTRESOURCE(IDB_PRIVATEKEY), NULL);
  201. }
  202. //////////////////////////////////////////////////////////////////////////////////////
  203. //
  204. //////////////////////////////////////////////////////////////////////////////////////
  205. void CCertificateBmp::Initialize()
  206. {
  207. if (!m_fInitialized)
  208. {
  209. WCHAR szDisplayText[CRYPTUI_MAX_STRING_SIZE];
  210. WCHAR szURLText[CRYPTUI_MAX_STRING_SIZE];
  211. InitCommonControls();
  212. InitializeBmp();
  213. m_fInitialized = TRUE;
  214. m_hWindowTextColorBrush = GetSysColorBrush(COLOR_WINDOWTEXT);
  215. m_hWindowColorBrush = GetSysColorBrush(COLOR_WINDOW);
  216. m_h3DLight= GetSysColorBrush(COLOR_3DLIGHT);
  217. m_h3DHighLight = GetSysColorBrush(COLOR_3DHILIGHT);
  218. m_h3DLightShadow = GetSysColorBrush(COLOR_3DSHADOW);
  219. m_h3DDarkShadow = GetSysColorBrush(COLOR_3DDKSHADOW);
  220. }
  221. }
  222. //////////////////////////////////////////////////////////////////////////////////////
  223. //
  224. //////////////////////////////////////////////////////////////////////////////////////
  225. /*
  226. int CCertificateBmp::OnQueryNewPalette()
  227. {
  228. HDC hDC = GetDC(GetMyWindow());
  229. HPALETTE hOldPal = SelectPalette(hDC, m_hpal, SELPALMODE);
  230. int iTemp = RealizePalette(hDC); // Realize drawing palette.
  231. SelectPalette(hDC, hOldPal, TRUE);
  232. RealizePalette(hDC);
  233. ReleaseDC(GetMyWindow(), hDC);
  234. //
  235. // Did the realization change?
  236. //
  237. if (iTemp)
  238. {
  239. InvalidateRect(GetMyWindow(), NULL, FALSE);
  240. }
  241. return(iTemp);
  242. }
  243. */
  244. //////////////////////////////////////////////////////////////////////////////////////
  245. //
  246. //////////////////////////////////////////////////////////////////////////////////////
  247. void CCertificateBmp::OnPaint()
  248. {
  249. Initialize();
  250. BITMAP bmMiniCert;
  251. BITMAP bmPKey;
  252. LONG miniCertXY;
  253. RECT rect;
  254. RECT disclaimerButtonRect;
  255. RECT frameRect;
  256. RECT mainWindowRect;
  257. RECT borderRect;
  258. RECT goodForRect;
  259. LONG borderSpacing;
  260. //PAINTSTRUCT ps;
  261. HDC hdc = GetDC(GetMyWindow());//BeginPaint(GetMyWindow(), &ps);
  262. if (hdc == NULL)
  263. {
  264. return;
  265. }
  266. //
  267. // get the mini bitmap first thing so it can be used to do sizing
  268. //
  269. memset(&bmMiniCert, 0, sizeof(bmMiniCert));
  270. if ((m_dwChainError != 0) && m_fTrueError)
  271. {
  272. ::GetObject(m_hbmpMiniCertNotOK, sizeof(BITMAP), (LPSTR)&bmMiniCert);
  273. }
  274. else if ((m_dwChainError != 0) || m_fNoUsages)
  275. {
  276. ::GetObject(m_hbmbMiniCertExclamation, sizeof(BITMAP), (LPSTR)&bmMiniCert);
  277. }
  278. else
  279. {
  280. ::GetObject(m_hbmpMiniCertOK, sizeof(BITMAP), (LPSTR)&bmMiniCert);
  281. }
  282. //
  283. // calculate where the minicert bmp should be and where the lines should
  284. // be based on where other controls are
  285. //
  286. GetWindowRect(GetDlgItem(m_hWnd, IDC_CERT_GENERAL_HEADER), &rect);
  287. MapWindowPoints(HWND_DESKTOP, m_hWnd, (LPPOINT) &rect, 2);
  288. miniCertXY = rect.bottom - bmMiniCert.bmHeight;
  289. GetWindowRect(m_hWnd, &mainWindowRect);
  290. MapWindowPoints(HWND_DESKTOP, m_hWnd, (LPPOINT) &mainWindowRect, 2);
  291. GetWindowRect(GetDlgItem(m_hWnd, IDC_DISCLAIMER_BUTTON), &disclaimerButtonRect);
  292. MapWindowPoints(HWND_DESKTOP, m_hWnd, (LPPOINT) &disclaimerButtonRect, 2);
  293. //borderSpacing = mainWindowRect.right - disclaimerButtonRect.right;
  294. if ((mainWindowRect.right - disclaimerButtonRect.right) < (miniCertXY - 7))
  295. {
  296. borderSpacing = mainWindowRect.right - disclaimerButtonRect.right;
  297. }
  298. else
  299. {
  300. borderSpacing = miniCertXY - 7;
  301. }
  302. //
  303. // draw the background by drawing four rectangels. these rectangels
  304. // border the "what this cert is good for" edit control or the error edit
  305. // control if there is an error.
  306. // we have to do this due to a bug in richedit where if you
  307. // invalidate the entire rect of the control sometimes the scroll
  308. // bars do not get redrawn.
  309. //
  310. if ((m_dwChainError != 0) || m_fNoUsages)
  311. {
  312. GetWindowRect(GetDlgItem(m_hWnd, IDC_CERT_GENERAL_ERROR_EDIT), &goodForRect);
  313. }
  314. else
  315. {
  316. GetWindowRect(GetDlgItem(m_hWnd, IDC_GOODFOR_EDIT), &goodForRect);
  317. }
  318. MapWindowPoints(HWND_DESKTOP, m_hWnd, (LPPOINT) &goodForRect, 2);
  319. rect.left = mainWindowRect.left + borderSpacing;
  320. rect.right = mainWindowRect.right - borderSpacing;
  321. rect.bottom = goodForRect.top;
  322. rect.top = mainWindowRect.top + borderSpacing;
  323. ::FillRect(hdc, &rect, m_hWindowColorBrush);
  324. rect.bottom = disclaimerButtonRect.top - borderSpacing;
  325. rect.top = goodForRect.bottom;
  326. ::FillRect(hdc, &rect, m_hWindowColorBrush);
  327. rect.top = goodForRect.top;
  328. rect.bottom = goodForRect.bottom;
  329. rect.left = mainWindowRect.left + borderSpacing;
  330. rect.right = goodForRect.left;
  331. ::FillRect(hdc, &rect, m_hWindowColorBrush);
  332. rect.left = goodForRect.right;
  333. rect.right = mainWindowRect.right - borderSpacing;
  334. ::FillRect(hdc, &rect, m_hWindowColorBrush);
  335. //
  336. // draw the frame
  337. //
  338. frameRect.left = mainWindowRect.left + borderSpacing;
  339. frameRect.right = mainWindowRect.right - borderSpacing;
  340. frameRect.bottom = disclaimerButtonRect.top - borderSpacing;
  341. frameRect.top = mainWindowRect.top + borderSpacing;
  342. borderRect.left = frameRect.left;
  343. borderRect.right = frameRect.right - 1;
  344. borderRect.top = frameRect.top;
  345. borderRect.bottom = frameRect.top + 1;
  346. ::FillRect(hdc, &borderRect, m_h3DLightShadow);
  347. borderRect.left = frameRect.left;
  348. borderRect.right = frameRect.left + 1;
  349. borderRect.top = frameRect.top;
  350. borderRect.bottom = frameRect.bottom - 1;
  351. ::FillRect(hdc, &borderRect, m_h3DLightShadow);
  352. borderRect.left = frameRect.left + 1;
  353. borderRect.right = frameRect.right - 2;
  354. borderRect.top = frameRect.top + 1;
  355. borderRect.bottom = frameRect.top + 2;
  356. ::FillRect(hdc, &borderRect, m_h3DDarkShadow);
  357. borderRect.left = frameRect.left + 1;
  358. borderRect.right = frameRect.left + 2;
  359. borderRect.top = frameRect.top + 1;
  360. borderRect.bottom = frameRect.bottom - 2;
  361. ::FillRect(hdc, &borderRect, m_h3DDarkShadow);
  362. borderRect.left = frameRect.left;
  363. borderRect.right = frameRect.right;
  364. borderRect.top = frameRect.bottom - 1;
  365. borderRect.bottom = frameRect.bottom;
  366. ::FillRect(hdc, &borderRect, m_h3DHighLight);
  367. borderRect.left = frameRect.right - 1;
  368. borderRect.right = frameRect.right;
  369. borderRect.top = frameRect.top;
  370. borderRect.bottom = frameRect.bottom;
  371. ::FillRect(hdc, &borderRect, m_h3DHighLight);
  372. borderRect.left = frameRect.left + 1;
  373. borderRect.right = frameRect.right - 1;
  374. borderRect.top = frameRect.bottom - 2;
  375. borderRect.bottom = frameRect.bottom - 1;
  376. ::FillRect(hdc, &borderRect, m_h3DLight);
  377. borderRect.left = frameRect.right - 2;
  378. borderRect.right = frameRect.right - 1;
  379. borderRect.top = frameRect.top + 1;
  380. borderRect.bottom = frameRect.bottom - 1;
  381. ::FillRect(hdc, &borderRect, m_h3DLight);
  382. //
  383. // draw the lines with the proper foreground color
  384. //
  385. GetWindowRect(GetDlgItem(m_hWnd, IDC_CERT_GENERAL_HEADER), &rect);
  386. MapWindowPoints(HWND_DESKTOP, m_hWnd, (LPPOINT) &rect, 2);
  387. rect.left = mainWindowRect.left + miniCertXY;
  388. rect.right = mainWindowRect.right - miniCertXY;
  389. rect.top = rect.bottom + 6;
  390. rect.bottom = rect.top + 1;
  391. ::FillRect(hdc, &rect, m_hWindowTextColorBrush);
  392. GetWindowRect(GetDlgItem(m_hWnd, IDC_SUBJECT_EDIT), &rect);
  393. MapWindowPoints(HWND_DESKTOP, m_hWnd, (LPPOINT) &rect, 2);
  394. rect.left = mainWindowRect.left + miniCertXY;
  395. rect.right = mainWindowRect.right - miniCertXY;
  396. rect.top -= 10;
  397. rect.bottom = rect.top + 1;
  398. ::FillRect(hdc, &rect, m_hWindowTextColorBrush);
  399. //
  400. // Draw the mini cert bitmap
  401. //
  402. if ((m_dwChainError != 0) && m_fTrueError)
  403. {
  404. MaskBlt(m_hbmpMiniCertNotOK,
  405. m_hpal,
  406. hdc,
  407. miniCertXY,
  408. miniCertXY,
  409. bmMiniCert.bmWidth,
  410. bmMiniCert.bmHeight);
  411. }
  412. else if ((m_dwChainError != 0) || m_fNoUsages)
  413. {
  414. MaskBlt(m_hbmbMiniCertExclamation,
  415. m_hpal,
  416. hdc,
  417. miniCertXY,
  418. miniCertXY,
  419. bmMiniCert.bmWidth,
  420. bmMiniCert.bmHeight);
  421. }
  422. else
  423. {
  424. MaskBlt(m_hbmpMiniCertOK,
  425. m_hpal,
  426. hdc,
  427. miniCertXY,
  428. miniCertXY,
  429. bmMiniCert.bmWidth,
  430. bmMiniCert.bmHeight);
  431. }
  432. //
  433. // if there is a private key then draw the bitmap
  434. //
  435. if (m_fHasPrivateKey)
  436. {
  437. GetWindowRect(GetDlgItem(m_hWnd, IDC_CERT_PRIVATE_KEY_EDIT), &rect);
  438. MapWindowPoints(HWND_DESKTOP, m_hWnd, (LPPOINT) &rect, 2);
  439. memset(&bmPKey, 0, sizeof(bmPKey));
  440. ::GetObject(m_hbmbPKey, sizeof(BITMAP), (LPSTR)&bmPKey);
  441. MaskBlt(m_hbmbPKey,
  442. m_hpal,
  443. hdc,
  444. rect.left - bmPKey.bmWidth - 4,
  445. rect.top - 2,
  446. bmPKey.bmWidth,
  447. bmPKey.bmHeight);
  448. }
  449. ReleaseDC(GetMyWindow(), hdc);//::EndPaint(GetMyWindow(), &ps);
  450. InvalidateRect(GetDlgItem(m_hWnd, IDC_SUBJECT_EDIT), NULL, TRUE);
  451. InvalidateRect(GetDlgItem(m_hWnd, IDC_ISSUER_EDIT), NULL, TRUE);
  452. InvalidateRect(GetDlgItem(m_hWnd, IDC_CERT_GENERAL_HEADER), NULL, TRUE);
  453. InvalidateRect(GetDlgItem(m_hWnd, IDC_CERT_GENERAL_GOODFOR_HEADER), NULL, TRUE);
  454. InvalidateRect(GetDlgItem(m_hWnd, IDC_CERT_GENERAL_ISSUEDTO_HEADER), NULL, TRUE);
  455. InvalidateRect(GetDlgItem(m_hWnd, IDC_CERT_GENERAL_ISSUEDBY_HEADER), NULL, TRUE);
  456. InvalidateRect(GetDlgItem(m_hWnd, IDC_CERT_GENERAL_VALID_EDIT), NULL, TRUE);
  457. InvalidateRect(GetDlgItem(m_hWnd, IDC_CERT_GENERAL_ERROR_EDIT), NULL, TRUE);
  458. InvalidateRect(GetDlgItem(m_hWnd, IDC_CERT_ISSUER_WARNING_EDIT), NULL, TRUE);
  459. InvalidateRect(GetDlgItem(m_hWnd, IDC_CERT_PRIVATE_KEY_EDIT), NULL, TRUE);
  460. }