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.

487 lines
13 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation
  4. Module Name:
  5. DlgIASAdd.cpp
  6. Abstract:
  7. Implementation file for the CDlgIASAddAttr class.
  8. We implement the class needed to handle the dialog displayed when the user
  9. hits Add.... from the Advanced tab of the profile sheet.
  10. Revision History:
  11. byao - created
  12. mmaguire 06/01/98 - revamped
  13. --*/
  14. //////////////////////////////////////////////////////////////////////////////
  15. //////////////////////////////////////////////////////////////////////////////
  16. // BEGIN INCLUDES
  17. //
  18. // standard includes:
  19. //
  20. #include "stdafx.h"
  21. #include "resource.h"
  22. //
  23. // where we can find declaration for main class in this file:
  24. //
  25. #include "DlgIASAdd.h"
  26. //
  27. //
  28. // where we can find declarations needed in this file:
  29. //
  30. #include "helper.h"
  31. #include "IASHelper.h"
  32. // help table
  33. #include "helptable.h"
  34. //
  35. // END INCLUDES
  36. //////////////////////////////////////////////////////////////////////////////
  37. #define NOTHING_SELECTED -1
  38. //////////////////////////////////////////////////////////////////////////////
  39. /*++
  40. AttrCompareFunc
  41. comparison function for all attribute list control
  42. --*/
  43. //////////////////////////////////////////////////////////////////////////////
  44. int CALLBACK AttrCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  45. {
  46. HRESULT hr;
  47. std::vector< CComPtr< IIASAttributeInfo > > * parrAllAttr =
  48. ( std::vector< CComPtr< IIASAttributeInfo > > * ) lParamSort;
  49. int iOrder;
  50. // compare vendor ID first
  51. LONG lVendorID1, lVendorID2;
  52. // ISSUE: Shouldn't this be VendorName, not VendorID?
  53. hr = parrAllAttr->at( (int)lParam1 )->get_VendorID( &lVendorID1 );
  54. _ASSERTE( SUCCEEDED( hr ) );
  55. hr = parrAllAttr->at( (int)lParam2 )->get_VendorID( &lVendorID2 );
  56. _ASSERTE( SUCCEEDED( hr ) );
  57. iOrder = lVendorID1 - lVendorID2;
  58. if ( iOrder > 0) iOrder = 1;
  59. else if ( iOrder < 0 ) iOrder = -1;
  60. // For the same vendor, compare attribute name
  61. if ( iOrder == 0 )
  62. {
  63. CComBSTR bstrAttributeName1, bstrAttributeName2;
  64. hr = parrAllAttr->at( (int)lParam1 )->get_AttributeName( &bstrAttributeName1 );
  65. _ASSERTE( SUCCEEDED( hr ) );
  66. hr = parrAllAttr->at( (int)lParam2 )->get_AttributeName( &bstrAttributeName2 );
  67. _ASSERTE( SUCCEEDED( hr ) );
  68. iOrder = _tcscmp( bstrAttributeName1, bstrAttributeName2 );
  69. }
  70. if ( iOrder == 0 )
  71. {
  72. // if everything is the same, we just randomly pick an order
  73. iOrder = -1;
  74. }
  75. return iOrder;
  76. }
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CDlgIASAddAttr dialog
  79. BEGIN_MESSAGE_MAP(CDlgIASAddAttr, CDialog)
  80. //{{AFX_MSG_MAP(CDlgIASAddAttr)
  81. ON_BN_CLICKED(IDC_IAS_BUTTON_ATTRIBUTE_ADD_SELECTED, OnButtonIasAddSelectedAttribute)
  82. ON_NOTIFY(NM_SETFOCUS, IDC_IAS_LIST_ATTRIBUTES_TO_CHOOSE_FROM, OnItemChangedListIasAllAttributes)
  83. ON_WM_CONTEXTMENU()
  84. ON_WM_HELPINFO()
  85. ON_NOTIFY(NM_DBLCLK, IDC_IAS_LIST_ATTRIBUTES_TO_CHOOSE_FROM, OnDblclkListIasAllattrs)
  86. //}}AFX_MSG_MAP
  87. END_MESSAGE_MAP()
  88. /////////////////////////////////////////////////////////////////////////////
  89. /*++
  90. CDlgIASAddAttr::CDlgIASAddAttr
  91. Constructor
  92. --*/
  93. //////////////////////////////////////////////////////////////////////////////
  94. CDlgIASAddAttr::CDlgIASAddAttr(CPgIASAdv* pOwner, LONG lAttrFilter,
  95. std::vector< CComPtr<IIASAttributeInfo> > * pvecAllAttributeInfos
  96. )
  97. : CDialog(CDlgIASAddAttr::IDD, pOwner)
  98. {
  99. //{{AFX_DATA_INIT(CDlgIASAddAttr)
  100. //}}AFX_DATA_INIT
  101. m_lAttrFilter = lAttrFilter;
  102. m_pOwner = pOwner;
  103. m_pvecAllAttributeInfos = pvecAllAttributeInfos;
  104. }
  105. /////////////////////////////////////////////////////////////////////////////
  106. /*++
  107. CDlgIASAddAttr::~CDlgIASAddAttr
  108. Destructor
  109. --*/
  110. //////////////////////////////////////////////////////////////////////////////
  111. CDlgIASAddAttr::~CDlgIASAddAttr()
  112. {
  113. }
  114. /////////////////////////////////////////////////////////////////////////////
  115. /*++
  116. CDlgIASAddAttr::DoDataExchange
  117. --*/
  118. //////////////////////////////////////////////////////////////////////////////
  119. void CDlgIASAddAttr::DoDataExchange(CDataExchange* pDX)
  120. {
  121. CDialog::DoDataExchange(pDX);
  122. //{{AFX_DATA_MAP(CDlgIASAddAttr)
  123. DDX_Control(pDX, IDC_IAS_LIST_ATTRIBUTES_TO_CHOOSE_FROM, m_listAllAttrs);
  124. //}}AFX_DATA_MAP
  125. }
  126. /////////////////////////////////////////////////////////////////////////////
  127. /*++
  128. CDlgIASAddAttr::SetSdo
  129. Set the sdo pointers.
  130. --*/
  131. //////////////////////////////////////////////////////////////////////////////
  132. HRESULT CDlgIASAddAttr::SetSdo(ISdoCollection* pIAttrCollection,
  133. ISdoDictionaryOld* pIDictionary)
  134. {
  135. m_spAttrCollectionSdo = pIAttrCollection;
  136. m_spDictionarySdo = pIDictionary;
  137. return S_OK;
  138. }
  139. /////////////////////////////////////////////////////////////////////////////
  140. /*++
  141. CDlgIASAddAttr::OnInitDialog
  142. Initialize the dialog.
  143. --*/
  144. //////////////////////////////////////////////////////////////////////////////
  145. BOOL CDlgIASAddAttr::OnInitDialog()
  146. {
  147. HRESULT hr = S_OK;
  148. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  149. int iIndex;
  150. //
  151. // call the initialization routine of base class
  152. //
  153. CDialog::OnInitDialog();
  154. //
  155. // first, set the all-attribute list box to 4 columns
  156. //
  157. LVCOLUMN lvc;
  158. int iCol;
  159. CString strColumnHeader;
  160. WCHAR wzColumnHeader[MAX_PATH];
  161. // initialize the LVCOLUMN structure
  162. lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM;
  163. lvc.fmt = LVCFMT_LEFT;
  164. lvc.pszText = wzColumnHeader;
  165. //
  166. // column header for all attribute list box
  167. // These string ID should be in consecutive order
  168. //
  169. strColumnHeader.LoadString(IDS_IAS_ATTRIBUTES_COLUMN_NAME);
  170. wcscpy(wzColumnHeader, strColumnHeader);
  171. m_listAllAttrs.InsertColumn(0, &lvc);
  172. strColumnHeader.LoadString(IDS_IAS_ATTRIBUTES_COLUMN_VENDOR);
  173. wcscpy(wzColumnHeader, strColumnHeader);
  174. m_listAllAttrs.InsertColumn(1, &lvc);
  175. strColumnHeader.LoadString(IDS_IAS_ATTRIBUTES_COLUMN_DESCRIPTION);
  176. wcscpy(wzColumnHeader, strColumnHeader);
  177. m_listAllAttrs.InsertColumn(2, &lvc);
  178. m_listAllAttrs.SetExtendedStyle(
  179. m_listAllAttrs.GetExtendedStyle() | LVS_EX_FULLROWSELECT
  180. );
  181. //
  182. // Populate the list for all available attributes in the dictionary
  183. //
  184. LVITEM lvi;
  185. WCHAR wszItemText[MAX_PATH];
  186. int jRow = 0;
  187. for (iIndex = 0; iIndex < m_pvecAllAttributeInfos->size(); iIndex++)
  188. {
  189. LONG lRestriction;
  190. m_pvecAllAttributeInfos->at(iIndex)->get_AttributeRestriction( &lRestriction );
  191. if ( lRestriction & m_lAttrFilter )
  192. {
  193. //
  194. // update the profattrlist
  195. //
  196. lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
  197. lvi.state = 0;
  198. lvi.stateMask = 0;
  199. lvi.iSubItem = 0;
  200. lvi.iItem = jRow;
  201. // We are saving the iIndex in this lParam for this item so that
  202. // later, when we sort the display of the list, we can still access the
  203. // orginal ordinal of the item in the list of all attributes.
  204. lvi.lParam = iIndex;
  205. CComBSTR bstrName;
  206. hr = m_pvecAllAttributeInfos->at(iIndex)->get_AttributeName( &bstrName );
  207. _ASSERTE( SUCCEEDED(hr) );
  208. lvi.pszText = bstrName;
  209. if (m_listAllAttrs.InsertItem(&lvi) == -1)
  210. {
  211. // return TRUE unless you set the focus to a control
  212. // EXCEPTION: OCX Property Pages should return FALSE
  213. return TRUE;
  214. }
  215. // vendor
  216. CComBSTR bstrVendor;
  217. hr = m_pvecAllAttributeInfos->at(iIndex)->get_VendorName( &bstrVendor );
  218. _ASSERTE( SUCCEEDED(hr) );
  219. m_listAllAttrs.SetItemText(jRow, 1, bstrVendor);
  220. // description
  221. CComBSTR bstrDescription;
  222. hr = m_pvecAllAttributeInfos->at(iIndex)->get_AttributeDescription( &bstrDescription );
  223. _ASSERTE( SUCCEEDED(hr) );
  224. m_listAllAttrs.SetItemText(jRow, 2, bstrDescription);
  225. jRow ++;
  226. } // if
  227. } // for
  228. // Set the sorting algorithm for this list control.
  229. m_listAllAttrs.SortItems( (PFNLVCOMPARE)AttrCompareFunc, (LPARAM)m_pvecAllAttributeInfos);
  230. // Selected the first one.
  231. if ( m_pvecAllAttributeInfos->size() > 0 )
  232. {
  233. // we have at least one element
  234. // m_listAllAttrs.SetItemState(m_dAllAttrCurSel, LVIS_FOCUSED, LVIS_FOCUSED);
  235. m_listAllAttrs.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
  236. }
  237. m_listAllAttrs.SetColumnWidth(0, LVSCW_AUTOSIZE);
  238. m_listAllAttrs.SetColumnWidth(1, LVSCW_AUTOSIZE);
  239. m_listAllAttrs.SetColumnWidth(2, LVSCW_AUTOSIZE);
  240. // button status
  241. UpdateButtonState();
  242. return TRUE; // return TRUE unless you set the focus to a control
  243. // EXCEPTION: OCX Property Pages should return FALSE
  244. }
  245. //+---------------------------------------------------------------------------
  246. //
  247. // Function: OnButtonIasAddSelectedAttribute
  248. //
  249. // Class: CDlgIASAddAttr
  250. //
  251. // Synopsis: The user has clicked the 'Add" button. Add an attribute to the
  252. // profile
  253. //
  254. // Arguments: None
  255. //
  256. // Returns: Nothing
  257. //
  258. // History: Created Header 2/19/98 3:01:14 PM
  259. //
  260. //+---------------------------------------------------------------------------
  261. void CDlgIASAddAttr::OnButtonIasAddSelectedAttribute()
  262. {
  263. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  264. HRESULT hr;
  265. // Get which item is selected in the list.
  266. int iSelected = GetSelectedItemIndex( m_listAllAttrs );
  267. if (NOTHING_SELECTED == iSelected )
  268. {
  269. // do nothing
  270. return;
  271. }
  272. // Retrieve the original (unsorted) ordinal of the item in the list.
  273. // We stored this in lParam before we sorted this list.
  274. LVITEM lvi;
  275. lvi.iItem = iSelected;
  276. lvi.iSubItem = 0;
  277. lvi.mask = LVIF_PARAM;
  278. m_listAllAttrs.GetItem(&lvi);
  279. int iUnsortedSelected = lvi.lParam;
  280. hr = m_pOwner->AddAttributeToProfile( m_hWnd, iUnsortedSelected );
  281. }
  282. //+---------------------------------------------------------------------------
  283. //
  284. // Function: UpdateButtonState
  285. //
  286. // Class: CDlgIASAddAttr
  287. //
  288. // Synopsis: Enable/Disable Add button
  289. //
  290. // Returns: Nothing
  291. //
  292. // History: Created byao 4/7/98 3:32:05 PM
  293. //
  294. //+---------------------------------------------------------------------------
  295. void CDlgIASAddAttr::UpdateButtonState()
  296. {
  297. // Set button states depending on whether anything is selected.
  298. int iSelected = GetSelectedItemIndex( m_listAllAttrs );
  299. if (NOTHING_SELECTED == iSelected )
  300. {
  301. GetDlgItem(IDC_IAS_BUTTON_ATTRIBUTE_ADD_SELECTED)->EnableWindow(FALSE);
  302. }
  303. else
  304. {
  305. // Something is selected.
  306. GetDlgItem(IDC_IAS_BUTTON_ATTRIBUTE_ADD_SELECTED)->EnableWindow(TRUE);
  307. }
  308. }
  309. //+---------------------------------------------------------------------------
  310. //
  311. // Function: OnItemChangedListIasAllAttributes
  312. //
  313. // Class: CDlgIASAddAttr
  314. //
  315. // Synopsis: something has changed in All Attribute list box
  316. // We'll try to get the currently selected one
  317. //
  318. // Arguments: NMHDR* pNMHDR -
  319. // LRESULT* pResult -
  320. //
  321. // Returns: Nothing
  322. //
  323. // History: Created Header 2/19/98 3:32:05 PM
  324. //
  325. //+---------------------------------------------------------------------------
  326. void CDlgIASAddAttr::OnItemChangedListIasAllAttributes(NMHDR* pNMHDR, LRESULT* pResult)
  327. {
  328. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  329. UpdateButtonState();
  330. *pResult = 0;
  331. }
  332. /////////////////////////////////////////////////////////////////////////////
  333. /*++
  334. CDlgIASAddAttr::OnContextMenu
  335. --*/
  336. //////////////////////////////////////////////////////////////////////////////
  337. void CDlgIASAddAttr::OnContextMenu(CWnd* pWnd, CPoint point)
  338. {
  339. ::WinHelp (pWnd->m_hWnd, AfxGetApp()->m_pszHelpFilePath,
  340. HELP_CONTEXTMENU, (DWORD_PTR)(LPVOID)g_aHelpIDs_IDD_IAS_ATTRIBUTE_ADD);
  341. }
  342. /////////////////////////////////////////////////////////////////////////////
  343. /*++
  344. CDlgIASAddAttr::OnHelpInfo
  345. --*/
  346. //////////////////////////////////////////////////////////////////////////////
  347. BOOL CDlgIASAddAttr::OnHelpInfo(HELPINFO* pHelpInfo)
  348. {
  349. ::WinHelp ((HWND)pHelpInfo->hItemHandle,
  350. AfxGetApp()->m_pszHelpFilePath,
  351. HELP_WM_HELP,
  352. (DWORD_PTR)(LPVOID)g_aHelpIDs_IDD_IAS_ATTRIBUTE_ADD);
  353. return CDialog::OnHelpInfo(pHelpInfo);
  354. }
  355. //+---------------------------------------------------------------------------
  356. //
  357. // Function: CDlgIASAddAttr::OnDblclkListIasAllattrs
  358. //
  359. // Synopsis: User has double clicked on the All Attribute list. Just add one.
  360. //
  361. // Arguments: NMHDR* pNMHDR -
  362. // LRESULT* pResult -
  363. //
  364. // Returns: Nothing
  365. //
  366. // History: Created Header byao 2/26/98 2:24:09 PM
  367. //
  368. //+---------------------------------------------------------------------------
  369. void CDlgIASAddAttr::OnDblclkListIasAllattrs(NMHDR* pNMHDR, LRESULT* pResult)
  370. {
  371. OnButtonIasAddSelectedAttribute();
  372. *pResult = 0;
  373. }