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.

438 lines
11 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: ScInsBar.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // ScInsBar.cpp : implementation file
  11. //
  12. #include "stdafx.h"
  13. #include "scdlg.h"
  14. #include "scinsdlg.h"
  15. #include "ScInsBar.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CScEdit special edit boxes (CardName, CardStatus)
  23. BEGIN_MESSAGE_MAP(CScEdit, CEdit)
  24. //{{AFX_MSG_MAP(CScEdit)
  25. ON_WM_CONTEXTMENU()
  26. //}}AFX_MSG_MAP
  27. END_MESSAGE_MAP()
  28. void CScEdit::OnContextMenu(CWnd* pWnd, CPoint pt)
  29. {
  30. ::WinHelp(m_hWnd, _T("SCardDlg.hlp"), HELP_CONTEXTMENU, (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_SCARDDLG_BAR);
  31. }
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CScInsertBar dialog
  34. CScInsertBar::CScInsertBar(CWnd* pParent /*=NULL*/)
  35. : CDialog(CScInsertBar::IDD, pParent)
  36. {
  37. m_paReaderState = NULL;
  38. //{{AFX_DATA_INIT(CScInsertBar)
  39. // NOTE: the ClassWizard will add member initialization here
  40. //}}AFX_DATA_INIT
  41. }
  42. void CScInsertBar::DoDataExchange(CDataExchange* pDX)
  43. {
  44. CDialog::DoDataExchange(pDX);
  45. //{{AFX_DATA_MAP(CScInsertBar)
  46. DDX_Control(pDX, IDC_NAME, m_ediName);
  47. DDX_Control(pDX, IDC_STATUS, m_ediStatus);
  48. DDX_Control(pDX, IDC_READERS, m_lstReaders);
  49. //}}AFX_DATA_MAP
  50. }
  51. void CScInsertBar::OnCancel()
  52. {
  53. CScInsertDlg* pParent = (CScInsertDlg*)GetParent();
  54. _ASSERTE(NULL != pParent);
  55. if (NULL != pParent)
  56. {
  57. pParent->PostMessage(IDCANCEL);
  58. }
  59. }
  60. BEGIN_MESSAGE_MAP(CScInsertBar, CDialog)
  61. //{{AFX_MSG_MAP(CScInsertBar)
  62. ON_WM_DESTROY()
  63. ON_NOTIFY(LVN_ITEMCHANGED, IDC_READERS, OnReaderItemChanged)
  64. ON_WM_HELPINFO()
  65. ON_WM_CONTEXTMENU()
  66. //}}AFX_MSG_MAP
  67. END_MESSAGE_MAP()
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CScInsertBar UI & smart card methods
  70. /*++
  71. InitializeReaderList:
  72. Initialize the list control w/ large images, and set up the
  73. CStringArray of image (reader/card status) descriptions...
  74. Arguments:
  75. None.
  76. Return Value:
  77. None.
  78. Author:
  79. Amanda Matlosz 07/14/1998
  80. --*/
  81. void CScInsertBar::InitializeReaderList(void)
  82. {
  83. HICON hicon;
  84. CImageList imageList;
  85. CString str;
  86. // Create the image list & give it to the list control
  87. imageList.Create (
  88. IMAGE_WIDTH,
  89. IMAGE_HEIGHT,
  90. TRUE, // list does include masks
  91. NUMBER_IMAGES,
  92. 0); // list won't grow
  93. // Build the image list
  94. for (int i = 0; i < NUMBER_IMAGES; i++ )
  95. {
  96. // Load icon and add it to image list
  97. hicon = NULL;
  98. hicon = ::LoadIcon ( AfxGetInstanceHandle(),
  99. MAKEINTRESOURCE(IMAGE_LIST_IDS[i]) );
  100. if (NULL==hicon) {
  101. break; // what can we do?
  102. }
  103. imageList.Add (hicon);
  104. }
  105. // Be sure that all the small icons were added.
  106. _ASSERTE(imageList.GetImageCount() == NUMBER_IMAGES);
  107. m_lstReaders.SetImageList(&imageList, (int) LVSIL_NORMAL);
  108. imageList.Detach();
  109. }
  110. /*++
  111. UpdateStatusList:
  112. This routine resets the list box display
  113. Arguments:
  114. None.
  115. Return Value:
  116. A LONG value indicating the status of the requested action. Please
  117. see the Smartcard header files for additional information.
  118. Author:
  119. Amanda Matlosz 06/15/1998
  120. Notes:
  121. Strings need to be converted from type stored in the smartcard
  122. thread help classes to this dialog's build type (i.e. UNICODE/ANSI)!!!!
  123. --*/
  124. void CScInsertBar::UpdateStatusList(CSCardReaderStateArray* paReaderState)
  125. {
  126. CString strCardStatus, strCardName;
  127. CSCardReaderState* pReader = NULL;
  128. CSCardReaderState* pSelectedRdr = NULL;
  129. LV_ITEM lv_item;
  130. //
  131. // Update the reader information
  132. //
  133. m_paReaderState = paReaderState;
  134. // reset previous knowledge re: reader/card status
  135. m_ediName.SetWindowText(_T(""));
  136. m_ediStatus.SetWindowText(_T(""));
  137. m_lstReaders.DeleteAllItems();
  138. if (NULL != m_paReaderState)
  139. {
  140. // Insert (new) items
  141. lv_item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  142. lv_item.cchTextMax = MAX_ITEMLEN;
  143. int nNumReaders = (int)m_paReaderState->GetSize();
  144. for(int nIndex = 0; nIndex < nNumReaders; nIndex++)
  145. {
  146. // Setup struct for system reader list
  147. pReader = m_paReaderState->GetAt(nIndex);
  148. _ASSERTE(NULL != pReader);
  149. lv_item.iItem = nIndex;
  150. lv_item.stateMask = 0;
  151. lv_item.state = 0;
  152. lv_item.iSubItem = 0;
  153. lv_item.iImage = (int)READEREMPTY;
  154. lv_item.pszText = NULL;
  155. // set lparam to the reader ptr so we can fetch the readerinfo later
  156. lv_item.lParam = (LPARAM)pReader;
  157. //
  158. // Get the card status: image, and select OK card
  159. //
  160. if (NULL != pReader)
  161. {
  162. lv_item.pszText = (LPTSTR)(LPCTSTR)(pReader->strReader);
  163. DWORD dwState = pReader->dwState;
  164. if (dwState == SC_STATUS_NO_CARD)
  165. {
  166. lv_item.iImage = (int)READEREMPTY;
  167. }
  168. else if (dwState == SC_STATUS_ERROR)
  169. {
  170. lv_item.iImage = (int)READERERROR;
  171. }
  172. else
  173. {
  174. if (pReader->fOK)
  175. {
  176. lv_item.iImage = (int)READERLOADED;
  177. }
  178. else
  179. {
  180. lv_item.iImage = (int)WRONGCARD;
  181. }
  182. }
  183. // Select if this is a search card
  184. if (pReader->fOK && (NULL==pSelectedRdr))
  185. {
  186. lv_item.state = LVIS_SELECTED | LVIS_FOCUSED;
  187. // Set that a selection has occurred
  188. pSelectedRdr = pReader;
  189. }
  190. }
  191. // Add Item
  192. m_lstReaders.InsertItem(&lv_item);
  193. }
  194. // indicate that the reader selection has changed
  195. if (NULL != pSelectedRdr)
  196. {
  197. OnReaderSelChange(pSelectedRdr);
  198. }
  199. else
  200. {
  201. // select the first item in the list
  202. m_lstReaders.SetItemState(0, LVIS_SELECTED | LVIS_FOCUSED, 0);
  203. OnReaderSelChange(m_paReaderState->GetAt(0));
  204. }
  205. m_lstReaders.SetFocus(); // TODO: ?? Remove this? ??
  206. }
  207. }
  208. /////////////////////////////////////////////////////////////////////////////
  209. // CScInsertBar message handlers
  210. /*++
  211. void ShowHelp:
  212. Helper function for OnHelpInfo and OnContextMenu.
  213. BOOL OnHelpInfo:
  214. Called by the MFC framework when the user hits F1.
  215. void OnContextMenu
  216. Called by the MFC framework when the user right-clicks.
  217. Author:
  218. Amanda Matlosz 03/04/1999
  219. Note:
  220. These three functions work together to provide context-sensitive
  221. help for the insertdlg.
  222. --*/
  223. void CScInsertBar::ShowHelp(HWND hWnd, UINT nCommand)
  224. {
  225. ::WinHelp(hWnd, _T("SCardDlg.hlp"), nCommand, (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_SCARDDLG_BAR);
  226. }
  227. afx_msg BOOL CScInsertBar::OnHelpInfo(LPHELPINFO lpHelpInfo)
  228. {
  229. _ASSERTE(NULL != lpHelpInfo);
  230. ShowHelp((HWND)lpHelpInfo->hItemHandle, HELP_WM_HELP);
  231. return TRUE;
  232. }
  233. afx_msg void CScInsertBar::OnContextMenu(CWnd* pWnd, CPoint pt)
  234. {
  235. _ASSERTE(NULL != pWnd);
  236. ShowHelp(pWnd->m_hWnd, HELP_CONTEXTMENU);
  237. }
  238. void CScInsertBar::OnDestroy()
  239. {
  240. // clean up image list
  241. m_SCardImages.DeleteImageList();
  242. CDialog::OnDestroy();
  243. }
  244. BOOL CScInsertBar::OnInitDialog()
  245. {
  246. CDialog::OnInitDialog();
  247. //
  248. // prepare list control
  249. //
  250. InitializeReaderList();
  251. //
  252. // TODO: try SubclassWindow() trick. What's up with MFC?
  253. //
  254. CWnd* pEdit = NULL;
  255. pEdit = GetDlgItem(IDC_NAME);
  256. if (NULL != pEdit) m_ediName.SubclassWindow(pEdit->m_hWnd);
  257. pEdit = NULL;
  258. pEdit = GetDlgItem(IDC_STATUS);
  259. if (NULL != pEdit) m_ediStatus.SubclassWindow(pEdit->m_hWnd);
  260. return TRUE; // return TRUE unless you set the focus to a control
  261. // EXCEPTION: OCX Property Pages should return FALSE
  262. }
  263. /*++
  264. OnReaderItemChanged:
  265. Routine processes a selection change in the list control --
  266. if a card name is selected, it is displayed in a separate control
  267. Arguments:
  268. pNMHDR - pointer to notification structure
  269. pResult - pointer to LRESULT
  270. Return Value:
  271. Returns TRUE on success; FALSE otherwise.
  272. Author:
  273. Amanda Matlosz 09/26/1998
  274. Revision History:
  275. --*/
  276. void CScInsertBar::OnReaderItemChanged(NMHDR* pNMHDR, LRESULT* pResult)
  277. {
  278. int nItem = m_lstReaders.GetNextItem(-1, LVNI_SELECTED);
  279. if (nItem != -1)
  280. {
  281. CSCardReaderState* pRdrSt = (CSCardReaderState*)m_lstReaders.GetItemData(nItem);
  282. OnReaderSelChange(pRdrSt);
  283. }
  284. *pResult = 0;
  285. }
  286. void CScInsertBar::OnReaderSelChange(CSCardReaderState* pSelectedRdr)
  287. {
  288. _ASSERTE(pSelectedRdr);
  289. if (NULL != pSelectedRdr)
  290. {
  291. //
  292. // Change UI to show selection details
  293. //
  294. CString strStatus, strName;
  295. DWORD dwState = pSelectedRdr->dwState;
  296. strStatus.LoadString(IDS_SC_STATUS_NO_CARD + dwState - SC_STATUS_NO_CARD);
  297. if (dwState != SC_STATUS_NO_CARD)
  298. {
  299. strName = pSelectedRdr->strCard;
  300. strName.TrimLeft();
  301. if (strName.IsEmpty() || dwState == SC_STATUS_UNKNOWN)
  302. {
  303. strName.LoadString(IDS_SC_NAME_UNKNOWN);
  304. }
  305. if (!pSelectedRdr->fOK && (dwState >= SC_SATATUS_AVAILABLE && dwState <= SC_STATUS_EXCLUSIVE))
  306. {
  307. CString strAdd;
  308. strAdd.LoadString(IDS_SC_CANT_USE);
  309. strStatus += " ";
  310. strStatus += strAdd;
  311. }
  312. }
  313. m_ediName.SetWindowText(strName);
  314. m_ediStatus.SetWindowText(strStatus);
  315. }
  316. //
  317. // Inform parent of change in selection, even if that sel is "NULL"
  318. //
  319. CScInsertDlg* pParent = (CScInsertDlg*)GetParent();
  320. _ASSERTE(NULL != pParent);
  321. if (NULL != pParent)
  322. {
  323. pParent->SetSelection(pSelectedRdr);
  324. }
  325. }
  326.