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.

347 lines
9.3 KiB

  1. /****************************************************************************************
  2. * NAME: SelCondAttr.h
  3. *
  4. * CLASS: CSelCondAttrDlg
  5. *
  6. * OVERVIEW
  7. *
  8. * Internet Authentication Server: NAP Rule Editing Dialog
  9. * This dialog box is used to display all condition types that users
  10. * can choose from when adding a rule
  11. *
  12. * Copyright (C) Microsoft Corporation, 1998 - 2001 . All Rights Reserved.
  13. *
  14. * History:
  15. * 1/28/98 Created by Byao (using ATL wizard)
  16. *
  17. *****************************************************************************************/
  18. #include "precompiled.h"
  19. #include "TimeOfDay.h"
  20. #include "selcondattr.h"
  21. #include "iasdebug.h"
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CSelCondAttrDlg
  24. CSelCondAttrDlg::CSelCondAttrDlg(CIASAttrList* pAttrList, LONG attrFilter)
  25. :m_pAttrList(pAttrList), m_filter(attrFilter)
  26. {
  27. TRACE_FUNCTION("CSelCondAttrDlg::CSelCondAttrDlg");
  28. //
  29. // index of the condition attribute that has been selected
  30. // This value is initialized to -1 == INVALID_VALUE
  31. //
  32. // The caller of this dialog box will need to know this index
  33. // in order to get the correct condition attribute object
  34. // in pCondAttrList
  35. //
  36. m_nSelectedCondAttr = -1;
  37. }
  38. CSelCondAttrDlg::~CSelCondAttrDlg()
  39. {
  40. }
  41. //+---------------------------------------------------------------------------
  42. //
  43. // Function: OnInitDialog
  44. //
  45. // Class: CSelCondAttrDlg
  46. //
  47. // Synopsis: init the dialog
  48. //
  49. // Arguments: UINT uMsg -
  50. // WPARAM wParam -
  51. // LPARAM lParam -
  52. // BOOL& bHandled -
  53. //
  54. // Returns: LRESULT -
  55. //
  56. // History: Created Header 2/16/98 8:44:35 PM
  57. //
  58. //+---------------------------------------------------------------------------
  59. LRESULT CSelCondAttrDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  60. {
  61. TRACE_FUNCTION("CSelCondAttrDlg::OnInitDialog");
  62. m_hWndAttrList = GetDlgItem(IDC_LIST_COND_SELATTR);
  63. //
  64. // first, set the list box to 2 columns
  65. //
  66. LVCOLUMN lvc;
  67. int iCol;
  68. WCHAR achColumnHeader[256];
  69. HINSTANCE hInst;
  70. // initialize the LVCOLUMN structure
  71. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  72. lvc.fmt = LVCFMT_LEFT;
  73. lvc.cx = 120;
  74. lvc.pszText = achColumnHeader;
  75. // first column header: name
  76. hInst = _Module.GetModuleInstance();
  77. ::LoadStringW(hInst, IDS_RULE_SELATTR_FIRSTCOLUMN, achColumnHeader, sizeof(achColumnHeader)/sizeof(achColumnHeader[0]));
  78. lvc.iSubItem = 0;
  79. ListView_InsertColumn(m_hWndAttrList, 0, &lvc);
  80. lvc.cx = 400;
  81. lvc.pszText = achColumnHeader;
  82. // second columns: description
  83. ::LoadStringW(hInst, IDS_RULE_SELATTR_SECONDCOLUMN, achColumnHeader, sizeof(achColumnHeader)/sizeof(achColumnHeader[0]));
  84. lvc.iSubItem = 1;
  85. ListView_InsertColumn(m_hWndAttrList, 1, &lvc);
  86. //
  87. // populate the list control with bogus data
  88. //
  89. if (!PopulateCondAttrs())
  90. {
  91. ErrorTrace(ERROR_NAPMMC_SELATTRDLG, "PopulateRuleAttrs() failed");
  92. return 0;
  93. }
  94. // Make sure the Add button is not enabled initially.
  95. // We will enable it when the user selects something.
  96. ::EnableWindow(GetDlgItem(IDC_BUTTON_ADD_CONDITION), FALSE);
  97. return 1; // Let the system set the focus
  98. }
  99. //+---------------------------------------------------------------------------
  100. //
  101. // Function: OnListViewDbclk
  102. //
  103. // Class: CSelCondAttrDlg
  104. //
  105. // Synopsis: handle the case where the user has changed a selection
  106. // enable/disable OK, CANCEL button accordingly
  107. //
  108. // Arguments: int idCtrl - ID of the list control
  109. // LPNMHDR pnmh - notification message
  110. // BOOL& bHandled - handled or not?
  111. //
  112. // Returns: LRESULT -
  113. //
  114. // History: Created Header byao 2/19/98 11:15:30 PM
  115. //
  116. //+---------------------------------------------------------------------------
  117. LRESULT CSelCondAttrDlg::OnListViewDbclk(int idCtrl,
  118. LPNMHDR pnmh,
  119. BOOL& bHandled)
  120. {
  121. TRACE_FUNCTION("CSelCondAttrDlg::OnListViewDbclk");
  122. return OnOK((WORD)idCtrl, IDC_BUTTON_ADD_CONDITION, m_hWndAttrList, bHandled); // the same as ok;
  123. }
  124. //+---------------------------------------------------------------------------
  125. //
  126. // Function: OnOK
  127. //
  128. // Class: CSelCondAttrDlg
  129. //
  130. // Synopsis: The user has clicked OK; We will decide whether we need to
  131. // put up another dialogbox depending on whether he has actually
  132. // selected a condition type
  133. //
  134. // Arguments: WORD wNotifyCode -
  135. // WORD wID -
  136. // HWND hWndCtl -
  137. // BOOL& bHandled -
  138. //
  139. // Returns: LRESULT -
  140. // S_FALSE: failed
  141. // S_OK: succeeded
  142. //
  143. // History: Created byao 1/30/98 5:54:55 PM
  144. //
  145. //+---------------------------------------------------------------------------
  146. LRESULT CSelCondAttrDlg::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  147. {
  148. TRACE_FUNCTION("CSelCondAttrDlg::OnOK");
  149. //
  150. // Has the user chosen any condition type yet?
  151. //
  152. LVITEM lvi;
  153. // Find out what's selected.
  154. // MAM: This is not what we want here: int iIndex = ListView_GetSelectionMark(m_hWndAttrList);
  155. int iIndex = ListView_GetNextItem(m_hWndAttrList, -1, LVNI_SELECTED);
  156. DebugTrace(DEBUG_NAPMMC_SELATTRDLG, "Selected item: %d", iIndex);
  157. if (iIndex != -1)
  158. {
  159. // The index inside the attribute list is stored as the lParam of this item.
  160. lvi.iItem = iIndex;
  161. lvi.iSubItem = 0;
  162. lvi.mask = LVIF_PARAM;
  163. ListView_GetItem(m_hWndAttrList, &lvi);
  164. DebugTrace(DEBUG_NAPMMC_SELATTRDLG, "The actual index in the list is %ld", lvi.lParam);
  165. m_nSelectedCondAttr = lvi.lParam;
  166. //
  167. // Close the condition selection dialog box -- only if something was selected.
  168. //
  169. // TRUE will be the return value of the DoModal call on this dialog.
  170. EndDialog(TRUE);
  171. }
  172. // ISSUE: This function wants an LRESULT, not and HRESULT
  173. // -- not sure of importance of return code here.
  174. return S_OK;
  175. }
  176. LRESULT CSelCondAttrDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  177. {
  178. TRACE_FUNCTION("+NAPMMC+:# CSelCondAttrDlg::OnCancel\n");
  179. // FALSE will be the return value of the DoModal call on this dialog.
  180. EndDialog(FALSE);
  181. return 0;
  182. }
  183. //+---------------------------------------------------------------------------
  184. //
  185. // Function: PopulateCondAttrs
  186. //
  187. // Class: CSelCondAttrDlg
  188. //
  189. // Synopsis: populate the condition types in the list control
  190. //
  191. // Arguments: None
  192. //
  193. // Returns: BOOL -
  194. // TRUE: if succeed
  195. // FALSE: otherwise
  196. //
  197. // History: Created byao 1/30/98 3:10:35 PM
  198. //
  199. //+---------------------------------------------------------------------------
  200. BOOL CSelCondAttrDlg::PopulateCondAttrs()
  201. {
  202. TRACE_FUNCTION("CSelCondAttrDlg::PopulateCondAttrs");
  203. _ASSERTE( m_pAttrList != NULL );
  204. int iIndex;
  205. WCHAR wzText[MAX_PATH];
  206. LVITEM lvi;
  207. lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
  208. lvi.state = 0;
  209. lvi.stateMask = 0;
  210. lvi.iSubItem = 0;
  211. //
  212. // insert the item
  213. //
  214. int jRow = 0;
  215. for (iIndex=0; iIndex < (int) m_pAttrList->size(); iIndex++)
  216. {
  217. lvi.iItem = jRow;
  218. CComPtr<IIASAttributeInfo> spAttributeInfo = m_pAttrList->GetAt(iIndex);
  219. _ASSERTE( spAttributeInfo );
  220. LONG lRestriction;
  221. spAttributeInfo->get_AttributeRestriction( &lRestriction );
  222. if ( lRestriction & m_filter )
  223. {
  224. // DebugTrace(DEBUG_NAPMMC_SELATTRDLG, "Inserting %ws", (LPCTSTR)m_pAttrList->GetAt(iIndex)->m_pszName);
  225. // set the item data to the index of this attribute
  226. // Since only a subset of the attribute can be used in the condition
  227. // we store the actual index to the attribute list as the item data
  228. lvi.lParam = iIndex;
  229. // name
  230. CComBSTR bstrName;
  231. spAttributeInfo->get_AttributeName( &bstrName );
  232. lvi.pszText = bstrName;
  233. int iRowIndex = ListView_InsertItem(m_hWndAttrList, &lvi);
  234. if(iRowIndex != -1)
  235. {
  236. // description
  237. CComBSTR bstrDescription;
  238. spAttributeInfo->get_AttributeDescription( &bstrDescription );
  239. ListView_SetItemText(m_hWndAttrList, iRowIndex, 1, bstrDescription);
  240. }
  241. jRow++; // go to the next Row
  242. }
  243. }
  244. return TRUE;
  245. }
  246. //+---------------------------------------------------------------------------
  247. //
  248. // Function: OnListViewItemChanged
  249. //
  250. // Class: CSelCondAttrDlg
  251. //
  252. // Synopsis: handle the case where the user has changed a selection
  253. // enable/disable OK, CANCEL button accordingly
  254. //
  255. // Arguments: int idCtrl - ID of the list control
  256. // LPNMHDR pnmh - notification message
  257. // BOOL& bHandled - handled or not?
  258. //
  259. // Returns: LRESULT -
  260. //
  261. // History: Created Header byao 2/19/98 11:15:30 PM
  262. //
  263. //+---------------------------------------------------------------------------
  264. LRESULT CSelCondAttrDlg::OnListViewItemChanged(int idCtrl,
  265. LPNMHDR pnmh,
  266. BOOL& bHandled)
  267. {
  268. TRACE_FUNCTION("CSelCondAttrDlg::OnListViewItemChanged");
  269. // Find out what's selected.
  270. // MAM: This is not what we want here: int iCurSel = ListView_GetSelectionMark(m_hWndAttrList);
  271. int iCurSel = ListView_GetNextItem(m_hWndAttrList, -1, LVNI_SELECTED);
  272. if (-1 == iCurSel)
  273. {
  274. // The user selected nothing, let's disable the ok button.
  275. ::EnableWindow(GetDlgItem(IDC_BUTTON_ADD_CONDITION), FALSE);
  276. }
  277. else
  278. {
  279. // Yes, enable the ok button.
  280. ::EnableWindow(GetDlgItem(IDC_BUTTON_ADD_CONDITION), TRUE);
  281. }
  282. bHandled = FALSE;
  283. return 0;
  284. }