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.

591 lines
15 KiB

  1. /****************************************************************************************
  2. * NAME: EnumCondEdit.cpp
  3. *
  4. * CLASS: CEnumConditionEditor
  5. *
  6. * OVERVIEW
  7. *
  8. * Internet Authentication Server:
  9. * This dialog box is used to edit enum-typed editor
  10. *
  11. * e.x. attr = <value1>\|<value2>
  12. *
  13. *
  14. * Copyright (C) Microsoft Corporation, 1998 - 1999 . All Rights Reserved.
  15. *
  16. * History:
  17. * 1/27/98 Created by Byao (using ATL wizard)
  18. *
  19. *****************************************************************************************/
  20. #include "precompiled.h"
  21. #include "EnumCondEdit.h"
  22. //+---------------------------------------------------------------------------
  23. //
  24. // Function: CEnumConditionEditor
  25. //
  26. // Class: CEnumConditionEditor
  27. //
  28. // Synopsis: constructor for CEnumConditionEditor.
  29. //
  30. // Arguments: LPTSTR pszAttrName - The attribute that needs to be edited
  31. //
  32. // Returns: Nothing
  33. //
  34. // History: Created byao 1/30/98 6:14:32 PM
  35. //
  36. //+---------------------------------------------------------------------------
  37. CEnumConditionEditor::CEnumConditionEditor()
  38. {
  39. }
  40. //+---------------------------------------------------------------------------
  41. //
  42. // Function: OnInitDialog
  43. //
  44. // Class: CEnumConditionEditor
  45. //
  46. // Synopsis: initialize the dialog box
  47. //
  48. // Arguments: UINT uMsg -
  49. // WPARAM wParam -
  50. // LPARAM lParam -
  51. // BOOL& bHandled -
  52. //
  53. // Returns: LRESULT -
  54. //
  55. // History: Created Header 1/30/98 6:15:41 PM
  56. //
  57. //+---------------------------------------------------------------------------
  58. LRESULT CEnumConditionEditor::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  59. {
  60. TRACE_FUNCTION("CEnumConditionEditor::OnInitDialog");
  61. LVCOLUMN lvCol;
  62. lvCol.mask = LVCF_FMT | LVCF_WIDTH ;
  63. lvCol.fmt = LVCFMT_LEFT;
  64. lvCol.cx = 200; // will readjust with later in the program
  65. SendDlgItemMessage(IDC_LIST_ENUMCOND_CHOICE,
  66. LVM_INSERTCOLUMN,
  67. 1,
  68. (LPARAM) &lvCol
  69. );
  70. SendDlgItemMessage(IDC_LIST_ENUMCOND_SELECTION,
  71. LVM_INSERTCOLUMN,
  72. 1,
  73. (LPARAM) &lvCol
  74. );
  75. //
  76. // populate the possible multiple selections
  77. //
  78. PopulateSelections();
  79. // change the title to the name of the attribute
  80. SetWindowText(m_strAttrName);
  81. return 1; // Let the system set the focus
  82. }
  83. LRESULT CEnumConditionEditor::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  84. {
  85. TRACE_FUNCTION("CEnumConditionEditor::OnOK");
  86. m_pSelectedList->clear();
  87. TCHAR buffer[MAX_PATH * 2];
  88. //
  89. // get the current selection index in the source list box
  90. //
  91. // LVM_GETSELECTIONMARK
  92. int iTotal = SendDlgItemMessage(IDC_LIST_ENUMCOND_SELECTION,
  93. LVM_GETITEMCOUNT,
  94. 0,
  95. 0);
  96. // put the text into the list
  97. for( int i = 0; i < iTotal; i++)
  98. {
  99. LVITEM lvItem;
  100. lvItem.mask = 0;
  101. lvItem.iSubItem = 0;
  102. lvItem.iItem = i;
  103. lvItem.pszText = buffer;
  104. lvItem.cchTextMax = MAX_PATH * 2;
  105. if (SendDlgItemMessage(IDC_LIST_ENUMCOND_SELECTION,
  106. LVM_GETITEMTEXT,
  107. i,
  108. (LPARAM)&lvItem
  109. ) > 0)
  110. {
  111. try
  112. {
  113. CComBSTR bstrValue = buffer;
  114. m_pSelectedList->push_back( bstrValue );
  115. }
  116. catch (...)
  117. {
  118. throw;
  119. }
  120. }
  121. }
  122. EndDialog(wID);
  123. return 0;
  124. }
  125. LRESULT CEnumConditionEditor::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  126. {
  127. TRACE_FUNCTION("CEnumConditionEditor::OnCancel");
  128. EndDialog(wID);
  129. return 0;
  130. }
  131. //+---------------------------------------------------------------------------
  132. //
  133. // Function: OnAdd
  134. //
  135. // Class: CEnumConditionEditor
  136. //
  137. // Synopsis: Add a selected value from the "Choices" list to "Selection" list
  138. //
  139. // Arguments: WORD wNotifyCode - notify code for this WM_COMMAND msg
  140. // WORD wID - ID of the control
  141. // HWND hWndCtl - Window Handle for this msg
  142. // BOOL& bHandled - whether it's handled or not
  143. //
  144. // Returns: LRESULT -
  145. // S_FALSE: failure
  146. // 0: succeed
  147. //
  148. // History: Created byao 1/30/98 3:47:33 PM
  149. //
  150. //+---------------------------------------------------------------------------
  151. LRESULT CEnumConditionEditor::OnAdd(WORD wNotifyCode,
  152. WORD wID,
  153. HWND hWndCtl,
  154. BOOL& bHandled)
  155. {
  156. TRACE_FUNCTION("CEnumConditionEditor::OnAdd");
  157. //
  158. // see if the current focus is in "Selection" listbox
  159. //
  160. return SwapSelection(IDC_LIST_ENUMCOND_CHOICE,
  161. IDC_LIST_ENUMCOND_SELECTION);
  162. }
  163. //+---------------------------------------------------------------------------
  164. //
  165. // Function: OnDelete
  166. //
  167. // Class: CEnumConditionEditor
  168. //
  169. // Synopsis: Delete a selected value from the "Selection" list
  170. // and move it back to "Choices" list
  171. //
  172. // Arguments: WORD wNotifyCode - notify code for this WM_COMMAND msg
  173. // WORD wID - ID of the control
  174. // HWND hWndCtl - Window Handle for this msg
  175. // BOOL& bHandled - whether it's handled or not
  176. //
  177. // Returns: LRESULT -
  178. // S_FALSE: failure
  179. // 0: succeed
  180. //
  181. // History: Created byao 1/30/98 3:47:33 PM
  182. //+---------------------------------------------------------------------------
  183. LRESULT CEnumConditionEditor::OnDelete(WORD wNotifyCode,
  184. WORD wID,
  185. HWND hWndCtl,
  186. BOOL& bHandled)
  187. {
  188. TRACE_FUNCTION("CEnumConditionEditor::OnDelete");
  189. return SwapSelection(IDC_LIST_ENUMCOND_SELECTION,
  190. IDC_LIST_ENUMCOND_CHOICE);
  191. }
  192. //+---------------------------------------------------------------------------
  193. //
  194. // Function: OnChoiceDblclk
  195. //
  196. // Class: CEnumConditionEditor
  197. //
  198. // Synopsis: Double click on the "Choice" list --> move it to selection list
  199. //
  200. // Arguments: WORD wNotifyCode - notify code for this WM_COMMAND msg
  201. // WORD wID - ID of the control
  202. // HWND hWndCtl - Window Handle for this msg
  203. // BOOL& bHandled - whether it's handled or not
  204. //
  205. // Returns: LRESULT -
  206. // S_FALSE: failure
  207. // 0: succeed
  208. //
  209. // History: Created byao 4/7/98 3:47:33 PM
  210. //+---------------------------------------------------------------------------
  211. LRESULT CEnumConditionEditor::OnChoiceDblclk(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  212. {
  213. TRACE_FUNCTION("CEnumConditionEditor::OnChoiceDblclk");
  214. return SwapSelection(IDC_LIST_ENUMCOND_CHOICE,
  215. IDC_LIST_ENUMCOND_SELECTION);
  216. }
  217. //+---------------------------------------------------------------------------
  218. //
  219. // Function: OnSelectionDblclk
  220. //
  221. // Class: CEnumConditionEditor
  222. //
  223. // Synopsis: Double click on the "Selection" list --> move it back to choice list
  224. //
  225. // Arguments: WORD wNotifyCode - notify code for this WM_COMMAND msg
  226. // WORD wID - ID of the control
  227. // HWND hWndCtl - Window Handle for this msg
  228. // BOOL& bHandled - whether it's handled or not
  229. //
  230. // Returns: LRESULT -
  231. // S_FALSE: failure
  232. // 0: succeed
  233. //
  234. // History: Created byao 4/7/98 3:47:33 PM
  235. //+---------------------------------------------------------------------------
  236. LRESULT CEnumConditionEditor::OnSelectionDblclk(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  237. {
  238. TRACE_FUNCTION("CEnumConditionEditor::OnSelectionDblclk");
  239. return SwapSelection(IDC_LIST_ENUMCOND_SELECTION,
  240. IDC_LIST_ENUMCOND_CHOICE);
  241. }
  242. //+---------------------------------------------------------------------------
  243. //
  244. // Function: PopulateSelections
  245. //
  246. // Class: CEnumConditionEditor
  247. //
  248. // Synopsis: Populate the multiple selection list
  249. //
  250. // Arguments: None
  251. //
  252. // Returns: BOOL -
  253. //
  254. // History: Created byao 1/30/98 3:24:22 PM
  255. //
  256. //+---------------------------------------------------------------------------
  257. BOOL CEnumConditionEditor::PopulateSelections()
  258. {
  259. TRACE_FUNCTION("CEnumConditionEditor::PopulateSelections");
  260. LONG lIndex;
  261. HRESULT hr;
  262. LONG lMaxWidth = 0;
  263. LONG tempSize;
  264. LVITEM lvItem;
  265. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  266. CComQIPtr< IIASEnumerableAttributeInfo, &IID_IIASEnumerableAttributeInfo > spEnumerableAttributeInfo( m_spAttributeInfo );
  267. _ASSERTE( spEnumerableAttributeInfo );
  268. LONG lSize;
  269. LONG lTotalChoices;
  270. hr = spEnumerableAttributeInfo->get_CountEnumerateDescription( &lSize );
  271. lTotalChoices = lSize;
  272. _ASSERTE( SUCCEEDED( hr ) );
  273. // set item count
  274. // LVM_SETITEMCOUNT
  275. SendDlgItemMessage(IDC_LIST_ENUMCOND_CHOICE,
  276. LVM_SETITEMCOUNT,
  277. lSize + 1,
  278. (LPARAM) 0
  279. );
  280. SendDlgItemMessage(IDC_LIST_ENUMCOND_SELECTION,
  281. LVM_SETITEMCOUNT,
  282. lSize + 1,
  283. (LPARAM) 0
  284. );
  285. for (lIndex=0; lIndex < lSize; lIndex++)
  286. {
  287. CComBSTR bstrDescription;
  288. hr = spEnumerableAttributeInfo->get_EnumerateDescription( lIndex, &bstrDescription );
  289. _ASSERTE( SUCCEEDED( hr ) );
  290. lvItem.mask = LVIF_PARAM;
  291. lvItem.pszText = bstrDescription;
  292. lvItem.lParam = lIndex;
  293. lvItem.iItem = lIndex;
  294. lvItem.iSubItem = 0;
  295. int lvItemIndex = SendDlgItemMessage(IDC_LIST_ENUMCOND_CHOICE,
  296. LVM_INSERTITEM,
  297. 0,
  298. (LPARAM) &lvItem
  299. );
  300. lvItem.mask = LVIF_TEXT;
  301. lvItem.iItem = lvItemIndex;
  302. lvItem.iSubItem = 0;
  303. SendDlgItemMessage(IDC_LIST_ENUMCOND_CHOICE,
  304. LVM_SETITEMTEXT,
  305. lvItemIndex,
  306. (LPARAM) &lvItem
  307. );
  308. tempSize = SendDlgItemMessage(IDC_LIST_ENUMCOND_CHOICE,
  309. LVM_GETSTRINGWIDTH,
  310. 0,
  311. (LPARAM) (BSTR)bstrDescription
  312. );
  313. if(tempSize> lMaxWidth)
  314. lMaxWidth = tempSize;
  315. }
  316. lMaxWidth += 20;
  317. // set the width
  318. SendDlgItemMessage(IDC_LIST_ENUMCOND_CHOICE,
  319. LVM_SETCOLUMNWIDTH,
  320. 0,
  321. MAKELPARAM(lMaxWidth, 0)
  322. );
  323. SendDlgItemMessage(IDC_LIST_ENUMCOND_SELECTION,
  324. LVM_SETCOLUMNWIDTH,
  325. 0,
  326. MAKELPARAM(lMaxWidth, 0)
  327. );
  328. // now populate the pre-selected values;
  329. LVFINDINFO lvFindInfo;
  330. lvFindInfo.flags = LVFI_STRING;
  331. lvFindInfo.psz = NULL;
  332. for (lIndex=0; lIndex < m_pSelectedList->size(); lIndex++)
  333. {
  334. CComBSTR bstrTemp = m_pSelectedList->at(lIndex);
  335. lvItem.mask = LVIF_PARAM;
  336. lvItem.pszText = bstrTemp;
  337. lvItem.lParam = lIndex;
  338. lvItem.iItem = lIndex;
  339. lvItem.iSubItem = 0;
  340. int lvItemIndex = SendDlgItemMessage(IDC_LIST_ENUMCOND_SELECTION,
  341. LVM_INSERTITEM,
  342. 0,
  343. (LPARAM) &lvItem
  344. );
  345. lvItem.mask = LVIF_TEXT;
  346. lvItem.iItem = lvItemIndex;
  347. lvItem.iSubItem = 0;
  348. SendDlgItemMessage(IDC_LIST_ENUMCOND_SELECTION,
  349. LVM_SETITEMTEXT,
  350. lvItemIndex,
  351. (LPARAM) &lvItem
  352. );
  353. // remove the item from choice
  354. // find it and remove it
  355. lvFindInfo.psz = bstrTemp;
  356. int iDelIndex = SendDlgItemMessage(IDC_LIST_ENUMCOND_CHOICE,
  357. LVM_FINDITEM,
  358. -1,
  359. (LPARAM) &lvFindInfo
  360. );
  361. if(iDelIndex != -1)
  362. SendDlgItemMessage(IDC_LIST_ENUMCOND_CHOICE,
  363. LVM_DELETEITEM,
  364. iDelIndex,
  365. (LPARAM) 0
  366. );
  367. } // for
  368. if(m_pSelectedList->size() > 0) // set default selection -- first one
  369. ListView_SetItemState(GetDlgItem(IDC_LIST_ENUMCOND_SELECTION), 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
  370. if(lTotalChoices > m_pSelectedList->size()) // still some in availableset default selection -- first one
  371. ListView_SetItemState(GetDlgItem(IDC_LIST_ENUMCOND_CHOICE), 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
  372. return TRUE;
  373. }
  374. //+---------------------------------------------------------------------------
  375. //
  376. // Function: SwapSelection
  377. //
  378. // Class: CEnumConditionEditor
  379. //
  380. // Synopsis: move a selected item from one list box to another list box
  381. // and move it back to "Choices" list
  382. //
  383. // Arguments: int iSource - source list box
  384. // int iDest - destination list box
  385. //
  386. // Returns: LRESULT -
  387. // S_FALSE: failure
  388. // S_OK: succeed
  389. //
  390. // History: Created byao 1/30/98 3:47:33 PM
  391. //+---------------------------------------------------------------------------
  392. LRESULT CEnumConditionEditor::SwapSelection(int iSource, int iDest)
  393. {
  394. TRACE_FUNCTION("CEnumConditionEditor::SwapSelection");
  395. LRESULT lErrCode;
  396. TCHAR buffer[MAX_PATH * 2];
  397. //
  398. // get the current selection index in the source list box
  399. //
  400. // LVM_GETSELECTIONMARK
  401. int iTotalSel = SendDlgItemMessage(iSource,
  402. LVM_GETSELECTEDCOUNT,
  403. 0,
  404. 0
  405. );
  406. int iCurSel = SendDlgItemMessage(iSource,
  407. LVM_GETSELECTIONMARK,
  408. 0,
  409. 0
  410. );
  411. // no selection
  412. if(iCurSel == -1 || iTotalSel < 1)
  413. return S_OK;
  414. LVITEM lvItem;
  415. lvItem.mask = 0;
  416. lvItem.iSubItem = 0;
  417. lvItem.iItem = iCurSel;
  418. lvItem.pszText = buffer;
  419. lvItem.cchTextMax = MAX_PATH * 2;
  420. // since we only allow single selection
  421. if (SendDlgItemMessage(iSource,
  422. LVM_GETITEMTEXT,
  423. iCurSel,
  424. (LPARAM)&lvItem
  425. ) > 0)
  426. {
  427. // remove the item from source
  428. SendDlgItemMessage(iSource,
  429. LVM_DELETEITEM,
  430. iCurSel,
  431. (LPARAM)&lvItem
  432. );
  433. // add the new item in the dest list
  434. lvItem.mask = 0;
  435. lvItem.iItem = 0;
  436. lvItem.iSubItem = 0;
  437. int lvItemIndex = SendDlgItemMessage(iDest,
  438. LVM_INSERTITEM,
  439. 0,
  440. (LPARAM) &lvItem
  441. );
  442. lvItem.mask = LVIF_TEXT;
  443. lvItem.iItem = lvItemIndex;
  444. lvItem.iSubItem = 0;
  445. SendDlgItemMessage(iDest,
  446. LVM_SETITEMTEXT,
  447. lvItemIndex,
  448. (LPARAM) &lvItem
  449. );
  450. // total number of items
  451. int i = SendDlgItemMessage(iSource,
  452. LVM_GETITEMCOUNT,
  453. 0,
  454. 0);
  455. // select the new added on in dest
  456. ListView_SetItemState(GetDlgItem(iDest), lvItemIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
  457. // select next item -- source
  458. if ( i > iCurSel)
  459. {
  460. ListView_SetItemState(GetDlgItem(iSource), iCurSel, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
  461. }
  462. else if ( i > 0)
  463. {
  464. ListView_SetItemState(GetDlgItem(iSource), i - 1, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
  465. }
  466. }
  467. return S_OK; // succeed
  468. }
  469. /////////////////////////////////////////////////////////////////////////////
  470. /*++
  471. CEnumConditionEditor::GetHelpPath
  472. Remarks:
  473. This method is called to get the help file path within
  474. an compressed HTML document when the user presses on the Help
  475. button of a property sheet.
  476. It is an override of CIASDialog::OnGetHelpPath.
  477. --*/
  478. //////////////////////////////////////////////////////////////////////////////
  479. HRESULT CEnumConditionEditor::GetHelpPath( LPTSTR szHelpPath )
  480. {
  481. TRACE_FUNCTION("CEnumCondEditor::GetHelpPath");
  482. #if 0
  483. // ISSUE: We seemed to have a problem with passing WCHAR's to the hhctrl.ocx
  484. // installed on this machine -- it appears to be non-unicode.
  485. lstrcpy( szHelpPath, _T("html/idh_proc_cond.htm") );
  486. #else
  487. strcpy( (CHAR *) szHelpPath, "html/idh_proc_cond.htm" );
  488. #endif
  489. return S_OK;
  490. }