Source code of Windows XP (NT5)
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.

533 lines
14 KiB

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