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.

1288 lines
30 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation, 1997 - 1998
  4. Module Name:
  5. PgIASAdv.cpp
  6. Abstract:
  7. Implementation file for the CPgIASAdv class.
  8. We implement the class needed to handle the Advanced tab
  9. of the profile sheet.
  10. Revision History:
  11. byao - created
  12. mmaguire 06/01/98 - extensively 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 "PgIASAdv.h"
  26. //
  27. //
  28. // where we can find declarations needed in this file:
  29. //
  30. #include "IASHelper.h"
  31. #include "IASProfA.h"
  32. #include "DlgIASAdd.h"
  33. #include "vendors.h"
  34. #include "napmmc.h"
  35. // help table
  36. #include "hlptable.h"
  37. //
  38. // END INCLUDES
  39. //////////////////////////////////////////////////////////////////////////////
  40. #define NOTHING_SELECTED -1
  41. IMPLEMENT_DYNCREATE(CPgIASAdv, CManagedPage)
  42. BEGIN_MESSAGE_MAP(CPgIASAdv, CPropertyPage)
  43. //{{AFX_MSG_MAP(CPgIASAdv)
  44. ON_BN_CLICKED(IDC_IAS_BUTTON_ATTRIBUTE_ADD, OnButtonIasAttributeAdd)
  45. ON_BN_CLICKED(IDC_IAS_BUTTON_ATTRIBUTE_REMOVE, OnButtonIasAttributeRemove)
  46. ON_BN_CLICKED(IDC_IAS_BUTTON_ATTRIBUTE_EDIT, OnButtonIasAttributeEdit)
  47. ON_WM_HELPINFO()
  48. ON_WM_CONTEXTMENU()
  49. ON_NOTIFY(NM_DBLCLK, IDC_IAS_LIST_ATTRIBUTES_IN_PROFILE, OnDblclkListIasProfattrs)
  50. ON_NOTIFY(LVN_ITEMCHANGED, IDC_IAS_LIST_ATTRIBUTES_IN_PROFILE, OnItemChangedListIasProfileAttributes)
  51. ON_NOTIFY(LVN_KEYDOWN, IDC_IAS_LIST_ATTRIBUTES_IN_PROFILE, OnKeydownIasListAttributesInProfile)
  52. //}}AFX_MSG_MAP
  53. END_MESSAGE_MAP()
  54. //////////////////////////////////////////////////////////////////////////////
  55. /*++
  56. CPgIASAdv::CPgIASAdv
  57. Constructor
  58. --*/
  59. //////////////////////////////////////////////////////////////////////////////
  60. CPgIASAdv::CPgIASAdv(ISdo* pIProfile, ISdoDictionaryOld* pIDictionary) :
  61. CManagedPage(CPgIASAdv::IDD)
  62. {
  63. TRACE(_T("CPgIASAdv::CPgIASAdv\n"));
  64. m_spProfileSdo = pIProfile;
  65. m_spDictionarySdo = pIDictionary;
  66. m_fAllAttrInitialized = FALSE;
  67. SetHelpTable(g_aHelpIDs_IDD_IAS_ADVANCED_TAB);
  68. m_bModified = FALSE;
  69. m_lAttrFilter = 0;
  70. }
  71. //////////////////////////////////////////////////////////////////////////////
  72. /*++
  73. CPgIASAdv::CPgIASAdv
  74. Destructor
  75. --*/
  76. //////////////////////////////////////////////////////////////////////////////
  77. CPgIASAdv::~CPgIASAdv()
  78. {
  79. TRACE(_T("CPgIASAdv::~CPgIASAdv\n"));
  80. int iIndex;
  81. // delete all the profiel attribute node
  82. TRACE(_T("Deleting arrProfileAttr list...\n"));
  83. for (iIndex=0; iIndex<m_vecProfileAttributes.size(); iIndex++)
  84. {
  85. delete m_vecProfileAttributes[iIndex];
  86. }
  87. // release all the SDO pointers
  88. for (iIndex=0; iIndex<m_vecProfileSdos.size(); iIndex++)
  89. {
  90. if ( m_vecProfileSdos[iIndex] )
  91. {
  92. m_vecProfileSdos[iIndex]->Release();
  93. m_vecProfileSdos[iIndex] = NULL;
  94. }
  95. }
  96. }
  97. //////////////////////////////////////////////////////////////////////////////
  98. /*++
  99. CPgIASAdv::DoDataExchange
  100. --*/
  101. //////////////////////////////////////////////////////////////////////////////
  102. void CPgIASAdv::DoDataExchange(CDataExchange* pDX)
  103. {
  104. TRACE(_T("CPgIASAdv::DoDataExchange\n"));
  105. CPropertyPage::DoDataExchange(pDX);
  106. //{{AFX_DATA_MAP(CPgIASAdv)
  107. DDX_Control(pDX, IDC_IAS_LIST_ATTRIBUTES_IN_PROFILE, m_listProfileAttributes);
  108. //}}AFX_DATA_MAP
  109. }
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CPgIASAdv message handlers
  112. //////////////////////////////////////////////////////////////////////////////
  113. /*++
  114. CPgIASAdv::OnInitDialog
  115. --*/
  116. //////////////////////////////////////////////////////////////////////////////
  117. BOOL CPgIASAdv::OnInitDialog()
  118. {
  119. TRACE(_T("CPgIASAdv::OnInitDialog\n"));
  120. HRESULT hr = S_OK;
  121. CPropertyPage::OnInitDialog();
  122. //
  123. // first, set the list box to 3 columns
  124. //
  125. LVCOLUMN lvc;
  126. int iCol;
  127. CString strColumnHeader;
  128. WCHAR wzColumnHeader[MAX_PATH];
  129. // initialize the LVCOLUMN structure
  130. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  131. lvc.fmt = LVCFMT_LEFT;
  132. lvc.cx = 120;
  133. lvc.pszText = wzColumnHeader;
  134. lvc.cx = ATTRIBUTE_NAME_COLUMN_WIDTH;
  135. strColumnHeader.LoadString(IDS_IAS_ATTRIBUTES_COLUMN_NAME);
  136. wcscpy(wzColumnHeader, strColumnHeader);
  137. m_listProfileAttributes.InsertColumn(0, &lvc);
  138. lvc.cx = ATTRIBUTE_VENDOR_COLUMN_WIDTH;
  139. strColumnHeader.LoadString(IDS_IAS_ATTRIBUTES_COLUMN_VENDOR);
  140. wcscpy(wzColumnHeader, strColumnHeader);
  141. m_listProfileAttributes.InsertColumn(1, &lvc);
  142. lvc.cx = ATTRIBUTE_VALUE_COLUMN_WIDTH;
  143. strColumnHeader.LoadString(IDS_IAS_ATTRIBUTES_COLUMN_VALUE);
  144. wcscpy(wzColumnHeader, strColumnHeader);
  145. m_listProfileAttributes.InsertColumn(2, &lvc);
  146. if ( !m_pvecAllAttributeInfos )
  147. {
  148. TRACE(_T("Empty attribute list!\n"));
  149. ShowErrorDialog(m_hWnd, IDS_IAS_ERR_ADVANCED_EMPTY_ATTRLIST, _T(""), hr);
  150. return TRUE;
  151. }
  152. //
  153. // get the attribute collection of this profile
  154. //
  155. hr = IASGetSdoInterfaceProperty(m_spProfileSdo,
  156. (LONG)PROPERTY_PROFILE_ATTRIBUTES_COLLECTION,
  157. IID_ISdoCollection,
  158. (void **) &m_spProfileAttributeCollectionSdo
  159. );
  160. TRACE(_T("IASGetSdoInterfaceProperty() returned %x\n"), hr);
  161. if (SUCCEEDED(hr))
  162. {
  163. TRACE(_T("Initializing profAttr list...\n"));
  164. hr = InitProfAttrList();
  165. }
  166. if (FAILED(hr))
  167. {
  168. ShowErrorDialog(m_hWnd, IDS_IAS_ERR_ADVANCED_PROFATTRLIST, _T(""), hr);
  169. }
  170. UpdateButtonState();
  171. return TRUE; // return TRUE unless you set the focus to a control
  172. // EXCEPTION: OCX Property Pages should return FALSE
  173. }
  174. //+---------------------------------------------------------------------------
  175. //
  176. // Function: CPgIASAdv::InitProfAttrList
  177. //
  178. // Synopsis: initialize the attribute list for this profile
  179. //
  180. // Arguments: None
  181. //
  182. // Returns: HRESULT -
  183. //
  184. // History: Created Header byao 2/22/98 4:40:17 AM
  185. //
  186. //+---------------------------------------------------------------------------
  187. HRESULT CPgIASAdv::InitProfAttrList()
  188. {
  189. TRACE(_T("CPgIASAdv::InitProfAttrList\n"));
  190. HRESULT hr = S_OK;
  191. int iIndex;
  192. CComPtr<IUnknown> spUnknown;
  193. CComPtr<IEnumVARIANT> spEnumVariant;
  194. CComVariant varAttributeSdo;
  195. long ulCount;
  196. ULONG ulCountReceived;
  197. ATTRIBUTEID AttrId;
  198. //
  199. // initialize the variant
  200. //
  201. _ASSERTE(m_spProfileAttributeCollectionSdo);
  202. // We check the count of items in our collection and don't bother getting the
  203. // enumerator if the count is zero.
  204. // This saves time and also helps us to a void a bug in the the enumerator which
  205. // causes it to fail if we call next when it is empty.
  206. m_spProfileAttributeCollectionSdo->get_Count( & ulCount );
  207. TRACE(_T("Number of attribute in the profile: %ld\n"), ulCount);
  208. if( ulCount <= 0 )
  209. {
  210. TRACE(_T("No profile attributes, now updating the UI list\n"));
  211. hr = UpdateProfAttrListCtrl();
  212. return hr;
  213. }
  214. // Get the enumerator for the attribute collection.
  215. hr = m_spProfileAttributeCollectionSdo->get__NewEnum( (IUnknown **) & spUnknown );
  216. _ASSERTE( SUCCEEDED( hr ) );
  217. hr = spUnknown->QueryInterface( IID_IEnumVARIANT, (void **) &spEnumVariant );
  218. spUnknown.Release();
  219. _ASSERTE( spEnumVariant != NULL );
  220. // Get the first item.
  221. hr = spEnumVariant->Next( 1, &varAttributeSdo, &ulCountReceived );
  222. TRACE(_T("Next() returned %x\n"), hr);
  223. while( SUCCEEDED( hr ) && ulCountReceived == 1 )
  224. {
  225. // Get an sdo pointer from the variant we received.
  226. _ASSERTE( V_VT(&varAttributeSdo) == VT_DISPATCH );
  227. _ASSERTE( V_DISPATCH(&varAttributeSdo) != NULL );
  228. CComPtr<ISdo> spSdo;
  229. hr = V_DISPATCH(&varAttributeSdo)->QueryInterface( IID_ISdo, (void **) &spSdo );
  230. if ( !SUCCEEDED(hr))
  231. {
  232. ShowErrorDialog(m_hWnd, IDS_IAS_ERR_SDOERROR_QUERYINTERFACE, _T(""), hr);
  233. continue;
  234. }
  235. //
  236. // get attribute ID
  237. //
  238. CComVariant varAttributeID;
  239. hr = spSdo->GetProperty(PROPERTY_ATTRIBUTE_ID, &varAttributeID);
  240. if ( !SUCCEEDED(hr) )
  241. {
  242. TRACE(_T("GetProperty(attributeId) failed, err = %x\n"), hr);
  243. ShowErrorDialog(m_hWnd, IDS_IAS_ERR_SDOERROR_GETPROPERTY, _T(""), hr);
  244. continue;
  245. }
  246. _ASSERTE( V_VT(&varAttributeID) == VT_I4 );
  247. AttrId = (ATTRIBUTEID) V_I4(&varAttributeID);
  248. TRACE(_T("Attribute ID = %ld\n"), AttrId);
  249. // search the attribute in the system attribute list
  250. for (iIndex=0; iIndex<m_pvecAllAttributeInfos->size(); iIndex++)
  251. {
  252. // search for this attribute in the profile attribute list
  253. ATTRIBUTEID id;
  254. m_pvecAllAttributeInfos->at(iIndex)->get_AttributeID( &id );
  255. if( AttrId == id ) break;
  256. }
  257. if ( iIndex < m_pvecAllAttributeInfos->size() )
  258. {
  259. LONG lRestriction;
  260. hr = m_pvecAllAttributeInfos->at(iIndex)->get_AttributeRestriction( &lRestriction );
  261. _ASSERTE( SUCCEEDED(hr) );
  262. if( lRestriction & m_lAttrFilter )
  263. {
  264. // attribute found in the global list, that means this is a valid ADVANCED IAS
  265. // attribute
  266. // -- add this SDO pointer to the profile SDO list
  267. spSdo->AddRef();
  268. m_vecProfileSdos.push_back(spSdo);
  269. // -- get attribute value
  270. TRACE(_T("Getting attribute value...\n"));
  271. CComVariant varValue;
  272. hr = spSdo->GetProperty(PROPERTY_ATTRIBUTE_VALUE, &varValue);
  273. if ( !SUCCEEDED(hr))
  274. {
  275. ShowErrorDialog(m_hWnd,
  276. IDS_IAS_ERR_SDOERROR_GETPROPERTY,
  277. _T(""),
  278. hr
  279. );
  280. continue;
  281. }
  282. TRACE(_T("Valid attribute ID! Creating a new attribute node...\n"));
  283. IIASAttributeInfo *pAttributeInfo = m_pvecAllAttributeInfos->at(iIndex);
  284. _ASSERTE(pAttributeInfo);
  285. CIASProfileAttribute *pProfileAttribute = new CIASProfileAttribute( pAttributeInfo, varValue );
  286. if( ! pProfileAttribute )
  287. {
  288. hr = HRESULT_FROM_WIN32(GetLastError());
  289. ShowErrorDialog(m_hWnd, IDS_IAS_ERR_ADD_ATTR, _T(""), hr);
  290. continue;
  291. }
  292. // Add the newly created node to the list of attributes.
  293. try
  294. {
  295. m_vecProfileAttributes.push_back(pProfileAttribute);
  296. }
  297. catch(...)
  298. {
  299. hr = HRESULT_FROM_WIN32(GetLastError());
  300. TRACE(_T("Can't add this attribuet node to profile attribute list, err = %x\n"), hr);
  301. ShowErrorDialog(m_hWnd, IDS_IAS_ERR_ADD_ATTR, _T(""), hr);
  302. delete pProfileAttribute;
  303. continue;
  304. };
  305. } // if
  306. } // if
  307. // ISSUE: Find out why Wei is compiling with atl10 only: varAttributeSdo.Clear();
  308. VariantClear( &varAttributeSdo );
  309. // Get the next item.
  310. hr = spEnumVariant->Next( 1, &varAttributeSdo, &ulCountReceived );
  311. TRACE(_T("Next() returned %x\n"), hr);
  312. if ( !SUCCEEDED(hr))
  313. {
  314. ShowErrorDialog(m_hWnd, IDS_IAS_ERR_SDOERROR_COLLECTION, _T(""), hr);
  315. return hr;
  316. }
  317. } // while
  318. //
  319. // fill in the prof attribute list
  320. //
  321. TRACE(_T("We've got all the profile attributes, now updating the UI list\n"));
  322. hr = UpdateProfAttrListCtrl();
  323. return hr;
  324. }
  325. //+---------------------------------------------------------------------------
  326. //
  327. // Function: CPgIASAdv::UpdateProfAttrListCtrl
  328. //
  329. // Synopsis: update the profile attribute list control
  330. //
  331. // Arguments: None
  332. //
  333. // Returns: HRESULT -
  334. //
  335. // History: Created Header byao 2/23/98 12:19:11 AM
  336. //
  337. //+---------------------------------------------------------------------------
  338. HRESULT CPgIASAdv::UpdateProfAttrListCtrl()
  339. {
  340. TRACE(_T("CPgIASAdv::UpdateProfAttrListCtrl\n"));
  341. LVITEM lvi;
  342. int iItem;
  343. //
  344. // clear up the whole list first
  345. //
  346. m_listProfileAttributes.DeleteAllItems();
  347. // re populate the list again
  348. for (int iIndex = 0; iIndex < m_vecProfileAttributes.size(); iIndex++)
  349. {
  350. CComBSTR bstrName;
  351. CComBSTR bstrVendor;
  352. CComBSTR bstrDisplayValue;
  353. // Set the attribute name (the leftmost column).
  354. m_vecProfileAttributes[iIndex]->get_AttributeName( &bstrName );
  355. m_listProfileAttributes.InsertItem(iIndex, bstrName );
  356. // Set the subitems (the other columns).
  357. // Vendor and value of variant as a displayable string.
  358. m_vecProfileAttributes[iIndex]->GetDisplayInfo( &bstrVendor, &bstrDisplayValue );
  359. m_listProfileAttributes.SetItemText(iIndex, 1, bstrVendor );
  360. m_listProfileAttributes.SetItemText(iIndex, 2, bstrDisplayValue );
  361. }
  362. return S_OK;
  363. }
  364. //+---------------------------------------------------------------------------
  365. //
  366. // Function: OnButtonIasAttributeAdd
  367. //
  368. // Class: CPgIASAdv
  369. //
  370. // Synopsis: User has clicked Add button -- pop up the attribute list
  371. //
  372. // Arguments: None
  373. //
  374. // Returns: Nothing
  375. //
  376. // History: Created Header 2/19/98 5:46:17 PM
  377. //
  378. //+---------------------------------------------------------------------------
  379. void CPgIASAdv::OnButtonIasAttributeAdd()
  380. {
  381. TRACE(_T("CPgIASAdv::OnButtonIasAttributeAdd()\n"));
  382. HRESULT hr = S_OK;
  383. CDlgIASAddAttr *pDlgAddAttr = new CDlgIASAddAttr( this, m_lAttrFilter, m_pvecAllAttributeInfos );
  384. if (!pDlgAddAttr)
  385. {
  386. hr = HRESULT_FROM_WIN32(GetLastError());
  387. ShowErrorDialog(m_hWnd, IDS_IAS_ERR_ADVANCED, _T(""), hr);
  388. return;
  389. }
  390. pDlgAddAttr->SetSdo(m_spProfileAttributeCollectionSdo,
  391. m_spDictionarySdo);
  392. if( pDlgAddAttr->DoModal() )
  393. {
  394. TRACE(_T("User selected something to add from the Add Attribute dialog\n"));
  395. CPropertyPage::SetModified();
  396. m_bModified = TRUE;
  397. }
  398. }
  399. /////////////////////////////////////////////////////////////////////////////
  400. /*++
  401. CPgIASAdv::EditProfileItemInList
  402. --*/
  403. //////////////////////////////////////////////////////////////////////////////
  404. STDMETHODIMP CPgIASAdv::EditProfileItemInList( int iIndex )
  405. {
  406. TRACE(_T("CPgIASAdv::EditProfileItemInList\n"));
  407. HRESULT hr = S_OK;
  408. // Get the specified node.
  409. CIASProfileAttribute* pProfAttr = m_vecProfileAttributes.at( iIndex );
  410. if( ! pProfAttr )
  411. {
  412. return E_FAIL;
  413. }
  414. // edit it!
  415. hr = pProfAttr->Edit();
  416. if( S_OK == hr )
  417. {
  418. // Update the UI.
  419. UpdateProfAttrListItem( iIndex );
  420. CPropertyPage::SetModified();
  421. m_bModified = TRUE;
  422. }
  423. return hr;
  424. }
  425. //+---------------------------------------------------------------------------
  426. //
  427. // Function: CPgIASAdv::OnApply
  428. //
  429. // Synopsis: User chose Apply or OK -- commit all changes
  430. //
  431. // Arguments: None
  432. //
  433. // Returns: BOOL - succeed or not
  434. //
  435. // History: Created Header byao 2/23/98 11:09:05 PM
  436. //
  437. //+---------------------------------------------------------------------------
  438. BOOL CPgIASAdv::OnApply()
  439. {
  440. TRACE(_T("CPgIASAdv::OnApply\n"));
  441. HRESULT hr = S_OK;
  442. int iIndex;
  443. if( ! m_bModified )
  444. {
  445. TRACE(_T("User changed nothing here, do nothing!\n"));
  446. return TRUE;
  447. }
  448. // remove all Advanced attributes SDOs - to repopulate them.
  449. for (iIndex =0; iIndex<m_vecProfileSdos.size(); iIndex++)
  450. {
  451. if ( m_vecProfileSdos[iIndex] != NULL )
  452. {
  453. CComPtr<IDispatch> spDispatch;
  454. hr = m_vecProfileSdos[iIndex]->QueryInterface( IID_IDispatch, (void **) & spDispatch );
  455. _ASSERTE( SUCCEEDED( hr ) );
  456. hr = m_spProfileAttributeCollectionSdo->Remove(spDispatch);
  457. if ( !SUCCEEDED(hr) )
  458. {
  459. TRACE(_T("Remove() failed, err = %x\n"), hr);
  460. ShowErrorDialog(m_hWnd, IDS_IAS_ERR_SDOERROR_COLLECTION, _T(""),hr);
  461. }
  462. m_vecProfileSdos[iIndex]->Release();
  463. m_vecProfileSdos[iIndex] = NULL;
  464. }
  465. }
  466. m_vecProfileSdos.clear();
  467. // repopulate the prof-attribute list
  468. for (iIndex=0; iIndex<m_vecProfileAttributes.size(); iIndex++)
  469. {
  470. // create the SDO for this attribute
  471. CComPtr<IDispatch> spDispatch;
  472. spDispatch.p = NULL;
  473. ATTRIBUTEID ID;
  474. hr = m_vecProfileAttributes[iIndex]->get_AttributeID( &ID );
  475. if( FAILED(hr) )
  476. {
  477. TRACE(_T("get_AttributeID() failed, err = %x\n"), hr);
  478. ShowErrorDialog(m_hWnd, IDS_IAS_ERR_SDOERROR_CREATEATTR,_T(""), hr);
  479. continue;
  480. }
  481. hr = m_spDictionarySdo->CreateAttribute( ID,
  482. (IDispatch**)&spDispatch.p);
  483. if ( !SUCCEEDED(hr) )
  484. {
  485. TRACE(_T("CreateAttrbute() failed, err = %x\n"), hr);
  486. ShowErrorDialog(m_hWnd, IDS_IAS_ERR_SDOERROR_CREATEATTR,_T(""), hr);
  487. continue; // go to the next attribute
  488. }
  489. _ASSERTE( spDispatch.p != NULL );
  490. // add this node to profile attribute collection
  491. hr = m_spProfileAttributeCollectionSdo->Add(NULL, (IDispatch**)&spDispatch.p);
  492. if ( !SUCCEEDED(hr) )
  493. {
  494. TRACE(_T("Add() failed, err = %x\n"), hr);
  495. ShowErrorDialog(m_hWnd, IDS_IAS_ERR_SDOERROR_CREATEATTR, _T("Add"),hr);
  496. continue; // go to the next attribute
  497. }
  498. //
  499. // get the ISdo pointer
  500. //
  501. CComPtr<ISdo> spAttrSdo;
  502. hr = spDispatch->QueryInterface( IID_ISdo, (void **) &spAttrSdo);
  503. if ( !SUCCEEDED(hr) )
  504. {
  505. TRACE(_T("QueryInterface() failed, err = %x\n"), hr);
  506. ShowErrorDialog(m_hWnd,IDS_IAS_ERR_SDOERROR_QUERYINTERFACE,_T(""),hr);
  507. continue; // go on to the next attribute
  508. }
  509. _ASSERTE( spAttrSdo != NULL );
  510. TRACE(_T("Created an attribute successfully! Now setting the properties...\n"));
  511. // set sdo property for this attribute
  512. CComVariant varValue;
  513. m_vecProfileAttributes[iIndex]->get_VarValue( &varValue );
  514. // set value
  515. TRACE(_T("Set value\n"));
  516. hr = spAttrSdo->PutProperty(PROPERTY_ATTRIBUTE_VALUE, &varValue );
  517. if ( !SUCCEEDED(hr) )
  518. {
  519. TRACE(_T("PutProperty(value) failed, err = %x\n"), hr);
  520. CComBSTR bstrTemp;
  521. m_vecProfileAttributes[iIndex]->get_AttributeName( &bstrTemp );
  522. ShowErrorDialog(m_hWnd, IDS_IAS_ERR_SDOERROR_PUTPROPERTY_ATTRIBUTE_VALUE, bstrTemp, hr );
  523. continue; // go on to the next attribute
  524. }
  525. // commit
  526. hr = spAttrSdo->Apply();
  527. if ( !SUCCEEDED(hr) )
  528. {
  529. TRACE(_T("Apply() failed, err = %x\n"), hr);
  530. ShowErrorDialog(m_hWnd, IDS_IAS_ERR_SDOERROR_APPLY, _T(""),hr);
  531. continue; // go on to the next attribute
  532. }
  533. // -- add this SDO pointer to the profile SDO list
  534. // we must AddRef() first for this SDO pointer because we are to copy it to
  535. // the array. We don't want the SDO object be released with spAttrSdo;
  536. spAttrSdo->AddRef();
  537. m_vecProfileSdos.push_back(spAttrSdo);
  538. } // for
  539. TRACE(_T("Done with this profile !\n"));
  540. return CPropertyPage::OnApply();
  541. }
  542. //////////////////////////////////////////////////////////////////////////////
  543. /*++
  544. CPgIASAdv::OnHelpInfo
  545. --*/
  546. //////////////////////////////////////////////////////////////////////////////
  547. BOOL CPgIASAdv::OnHelpInfo(HELPINFO* pHelpInfo)
  548. {
  549. TRACE(_T("CPgIASAdv::OnHelpInfo\n"));
  550. return CManagedPage::OnHelpInfo(pHelpInfo);
  551. }
  552. //////////////////////////////////////////////////////////////////////////////
  553. /*++
  554. CPgIASAdv::OnContextMenu
  555. --*/
  556. //////////////////////////////////////////////////////////////////////////////
  557. void CPgIASAdv::OnContextMenu(CWnd* pWnd, CPoint point)
  558. {
  559. TRACE(_T("CPgIASAdv::OnContextMenu\n"));
  560. CManagedPage::OnContextMenu(pWnd, point);
  561. }
  562. //+---------------------------------------------------------------------------
  563. //
  564. // Function: CPgIASAdv::OnButtonIasAttributeEdit
  565. //
  566. // Synopsis: edit the currectly selected attribute
  567. //
  568. // Arguments: None
  569. //
  570. // Returns: Nothing
  571. //
  572. // History: Created Header byao 2/25/98 8:03:38 PM
  573. //
  574. //+---------------------------------------------------------------------------
  575. void CPgIASAdv::OnButtonIasAttributeEdit()
  576. {
  577. TRACE(_T("CPgIASAdv::OnButtonIasAttributeEdit\n"));
  578. HRESULT hr = S_OK;
  579. //
  580. // see if there is an item already selected in ProfAttr list
  581. //
  582. int iSelected = GetSelectedItemIndex( m_listProfileAttributes );
  583. if (NOTHING_SELECTED == iSelected )
  584. {
  585. // do nothing
  586. return;
  587. }
  588. EditProfileItemInList( iSelected );
  589. }
  590. //+---------------------------------------------------------------------------
  591. //
  592. // Function: OnButtonIasAttributeRemove
  593. //
  594. // Class: CPgIASAdv
  595. //
  596. // Synopsis: The user has clicked the "Remove" button. Remove an attribute from
  597. // the profile
  598. //
  599. // Arguments: None
  600. //
  601. // Returns: Nothing
  602. //
  603. // History: Created Header 2/19/98 3:01:14 PM
  604. //
  605. //+---------------------------------------------------------------------------
  606. void CPgIASAdv::OnButtonIasAttributeRemove()
  607. {
  608. TRACE(_T("CPgIASAdv::OnButtonIasAttributeRemove()"));
  609. HRESULT hr;
  610. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  611. //
  612. // see if there is an item already selected in ProfAttr list
  613. //
  614. int iSelected = GetSelectedItemIndex( m_listProfileAttributes );
  615. if (NOTHING_SELECTED == iSelected )
  616. {
  617. // do nothing
  618. return;
  619. }
  620. //
  621. // get the current node
  622. //
  623. CIASProfileAttribute* pProfAttr = m_vecProfileAttributes.at(iSelected);
  624. _ASSERTE( pProfAttr != NULL );
  625. // delete the attribute node
  626. m_vecProfileAttributes.erase( m_vecProfileAttributes.begin() + iSelected );
  627. delete pProfAttr;
  628. CPropertyPage::SetModified();
  629. m_bModified = TRUE;
  630. // Update the UI.
  631. // for some reason, the focus is lost within the following, so save it, and restore it later
  632. HWND hWnd = ::GetFocus();
  633. m_listProfileAttributes.DeleteItem(iSelected);
  634. // Make sure the selection stays on the same position in the list.
  635. if( ! m_listProfileAttributes.SetItemState( iSelected, LVIS_SELECTED, LVIS_SELECTED) )
  636. {
  637. // We failed, probably because the item that was deleted was the last
  638. // in the list, so try to select the one before the deleted item.
  639. if (iSelected > 0)
  640. m_listProfileAttributes.SetItemState( iSelected -1, LVIS_SELECTED, LVIS_SELECTED);
  641. }
  642. // restore the focus
  643. ::SetFocus(hWnd);
  644. UpdateButtonState();
  645. }
  646. //+---------------------------------------------------------------------------
  647. //
  648. // Function: UpdateButtonState
  649. //
  650. // Class: CPgIASAdv
  651. //
  652. // Synopsis: Enable/Disable Edit/Remove/Up/Down/Add buttons
  653. //
  654. // Returns: Nothing
  655. //
  656. // History: Created byao 4/7/98 3:32:05 PM
  657. //
  658. //+---------------------------------------------------------------------------
  659. void CPgIASAdv::UpdateButtonState()
  660. {
  661. TRACE(_T("CPgIASAdv::UpdateButtonState\n"));
  662. // According to whether we have anything in this list box, enable or disable
  663. // remove and edit button
  664. // if ( m_listProfileAttributes.GetItemCount() > 0 )
  665. // {
  666. // }
  667. // else
  668. // {
  669. // }
  670. // Set button states depending on whether anything is selected.
  671. int iSelected = GetSelectedItemIndex( m_listProfileAttributes );
  672. if (NOTHING_SELECTED == iSelected )
  673. {
  674. HWND hFocus = ::GetFocus();
  675. // move focus
  676. if(hFocus == GetDlgItem(IDC_IAS_BUTTON_ATTRIBUTE_REMOVE)->m_hWnd)
  677. ::SetFocus(GetDlgItem(IDC_IAS_BUTTON_ATTRIBUTE_ADD)->m_hWnd);
  678. GetDlgItem(IDC_IAS_BUTTON_ATTRIBUTE_REMOVE)->EnableWindow(FALSE);
  679. GetDlgItem(IDC_IAS_BUTTON_ATTRIBUTE_EDIT)->EnableWindow(FALSE);
  680. }
  681. else
  682. {
  683. // Something is selected.
  684. GetDlgItem(IDC_IAS_BUTTON_ATTRIBUTE_REMOVE)->EnableWindow(TRUE);
  685. GetDlgItem(IDC_IAS_BUTTON_ATTRIBUTE_EDIT)->EnableWindow(TRUE);
  686. }
  687. }
  688. //+---------------------------------------------------------------------------
  689. //
  690. // Function: OnItemChangedListIasProfileAttributes
  691. //
  692. // Class: CPgIASAdv
  693. //
  694. // Synopsis: something has changed in Profile Attribute list box
  695. // We'll try to get the currently selected one
  696. //
  697. // Arguments: NMHDR* pNMHDR -
  698. // LRESULT* pResult -
  699. //
  700. // Returns: Nothing
  701. //
  702. // History: Created Header 2/19/98 3:32:05 PM
  703. //
  704. //+---------------------------------------------------------------------------
  705. void CPgIASAdv::OnItemChangedListIasProfileAttributes(NMHDR* pNMHDR, LRESULT* pResult)
  706. {
  707. TRACE(_T("CPgIASAdv::OnItemChangedListIasProfileAttributes\n"));
  708. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  709. // NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  710. // if (pNMListView->uNewState & LVIS_SELECTED)
  711. // {
  712. // m_dProfAttrCurSel = pNMListView->iItem;
  713. // }
  714. UpdateButtonState();
  715. *pResult = 0;
  716. }
  717. //+---------------------------------------------------------------------------
  718. //
  719. // Function: CPgIASAdv::UpdateProfAttrListItem
  720. //
  721. // Synopsis: update the No.nItem of the profile attribute list ctrl
  722. //
  723. // Arguments: int nItem - index of the item to update
  724. //
  725. // Returns: HRESULT -
  726. //
  727. // History: Created Header byao 2/23/98 2:46:21 PM
  728. //
  729. //+---------------------------------------------------------------------------
  730. HRESULT CPgIASAdv::UpdateProfAttrListItem(int nItem)
  731. {
  732. TRACE(_T("CPgIASAdv::UpdateProfAttrListItem\n"));
  733. //
  734. // update the profattrlist
  735. //
  736. LVITEM lvi;
  737. WCHAR wszItemText[MAX_PATH];
  738. lvi.mask = LVIF_TEXT | LVIF_STATE;
  739. lvi.state = 0;
  740. lvi.stateMask = 0;
  741. lvi.iSubItem = 0;
  742. lvi.iItem = nItem;
  743. CComBSTR bstrName;
  744. CComBSTR bstrVendor;
  745. CComBSTR bstrDisplayValue;
  746. // Attribute name.
  747. m_vecProfileAttributes.at(nItem)->get_AttributeName( &bstrName );
  748. lvi.pszText = bstrName;
  749. if (m_listProfileAttributes.SetItem(&lvi) == -1)
  750. {
  751. return E_FAIL;
  752. }
  753. // Vendor and value of variant as a displayable string.
  754. m_vecProfileAttributes.at(nItem)->GetDisplayInfo( &bstrVendor, &bstrDisplayValue );
  755. m_listProfileAttributes.SetItemText(nItem,1, bstrVendor );
  756. m_listProfileAttributes.SetItemText(nItem,2, bstrDisplayValue );
  757. return S_OK;
  758. }
  759. //+---------------------------------------------------------------------------
  760. //
  761. // Function: CPgIASAdv::InsertProfileAttributeListItem
  762. //
  763. // Synopsis: insert the No.nItem of the profile attribute to the list ctrl
  764. //
  765. // Arguments: int nItem - index of the item to update
  766. //
  767. // Returns: HRESULT -
  768. //
  769. // History: Created Header byao 2/23/98 2:46:21 PM
  770. //
  771. //+---------------------------------------------------------------------------
  772. HRESULT CPgIASAdv::InsertProfileAttributeListItem(int nItem)
  773. {
  774. TRACE(_T("CPgIASAdv::InsertProfileAttributeListItem\n"));
  775. //
  776. // update the profattrlist
  777. //
  778. LVITEM lvi;
  779. lvi.mask = LVIF_TEXT | LVIF_STATE;
  780. lvi.state = 0;
  781. lvi.stateMask = 0;
  782. lvi.iSubItem = 0;
  783. lvi.iItem = nItem;
  784. CComBSTR bstrName;
  785. CComBSTR bstrVendor;
  786. CComBSTR bstrDisplayValue;
  787. m_vecProfileAttributes.at(nItem)->get_AttributeName( &bstrName );
  788. lvi.pszText = bstrName;
  789. if (m_listProfileAttributes.InsertItem(&lvi) == -1)
  790. {
  791. return E_FAIL;
  792. }
  793. // Vendor and value of variant as a displayable string.
  794. m_vecProfileAttributes.at(nItem)->GetDisplayInfo( &bstrVendor, &bstrDisplayValue );
  795. m_listProfileAttributes.SetItemText(nItem,1, bstrVendor );
  796. m_listProfileAttributes.SetItemText(nItem,2, bstrDisplayValue );
  797. return S_OK;
  798. }
  799. //+---------------------------------------------------------------------------
  800. //
  801. // Function: CPgIASAdv::OnDblclkListIasProfattrs
  802. //
  803. // Synopsis: user has double clicked on the profile attribute list
  804. // We need to edit the attribute value using corresponding UI
  805. //
  806. // Arguments: NMHDR* pNMHDR -
  807. // LRESULT* pResult -
  808. //
  809. // Returns: Nothing
  810. //
  811. // History: Created Header byao 2/23/98 5:56:36 PM
  812. //
  813. //+---------------------------------------------------------------------------
  814. void CPgIASAdv::OnDblclkListIasProfattrs(NMHDR* pNMHDR, LRESULT* pResult)
  815. {
  816. TRACE(_T("CPgIASAdv::OnDblclkListIasProfattrs\n"));
  817. HRESULT hr = S_OK;
  818. //
  819. // see if there is an item already selected in ProfAttr list
  820. //
  821. int iSelected = GetSelectedItemIndex( m_listProfileAttributes );
  822. if (NOTHING_SELECTED == iSelected)
  823. {
  824. // do nothing
  825. return;
  826. }
  827. EditProfileItemInList( iSelected );
  828. *pResult = 0;
  829. }
  830. //////////////////////////////////////////////////////////////////////////////
  831. /*++
  832. CPgIASAdv::AddAttributeToProfile
  833. iItem is the ordinal in m_vecAllAttributeInfos of the attribute to add
  834. to m_vecProfileAttributes.
  835. Called by external customers of this class, checks to see whether an
  836. attribute at position iItem in m_vecAllAttributeInfos is already in
  837. the profile. If it is, gives the option to edit it. If it isn't,
  838. then calls InternalAddAttributeToProfile, which adds it.
  839. --*/
  840. //////////////////////////////////////////////////////////////////////////////
  841. STDMETHODIMP CPgIASAdv::AddAttributeToProfile( int iItem )
  842. {
  843. TRACE(_T("CPgIASAdv::AddAttributeToProfile\n"));
  844. HRESULT hr;
  845. ATTRIBUTEID ID1;
  846. hr = m_pvecAllAttributeInfos->at( iItem )->get_AttributeID( &ID1 );
  847. _ASSERTE( SUCCEEDED( hr ) );
  848. // Check if this attribute already in the profile.
  849. for( int iIndex=0; iIndex< m_vecProfileAttributes.size(); iIndex++ )
  850. {
  851. ATTRIBUTEID ID2;
  852. hr = m_vecProfileAttributes.at(iIndex)->get_AttributeID( &ID2 );
  853. _ASSERTE( SUCCEEDED( hr ) );
  854. if ( ID1 == ID2 )
  855. {
  856. // The selected attribute is already in the profile.
  857. // Ask the user if they want to edit it.
  858. CString strMessage;
  859. strMessage.LoadString(IDS_IAS_ATTRIBUTE_ALREADY_IN_PROFILE);
  860. CString strTitle;
  861. strTitle.LoadString(IDS_IAS_TITLE_ATTRIBUTE_ALREADY_IN_PROFILE);
  862. int iResult = MessageBox(strMessage, strTitle, MB_YESNO);
  863. if( iResult == IDYES )
  864. {
  865. // Edit the existing profile
  866. EditProfileItemInList( iIndex );
  867. }
  868. // In any case, don't continue with this function.
  869. return S_FALSE;
  870. }
  871. }
  872. // Now we create this attribute, and add it to profile.
  873. hr = InternalAddAttributeToProfile( iItem );
  874. if ( FAILED(hr) )
  875. {
  876. ShowErrorDialog(m_hWnd, IDS_IAS_ERR_ADD_ATTR, _T(""), hr);
  877. return hr;
  878. }
  879. // The use may have cancelled out, so don't need to update.
  880. if( S_OK == hr )
  881. {
  882. UpdateButtonState();
  883. UpdateProfAttrListCtrl();
  884. }
  885. return hr;
  886. }
  887. //////////////////////////////////////////////////////////////////////////////
  888. /*++
  889. CPgIASAdv::InternalAddAttributeToProfile
  890. iItem is the ordinal in m_vecAllAttributeInfos of the attribute to add
  891. to m_vecProfileAttributes.
  892. Private to this class. Used to add a new attribute to a profile
  893. and edit it.
  894. --*/
  895. //////////////////////////////////////////////////////////////////////////////
  896. STDMETHODIMP CPgIASAdv::InternalAddAttributeToProfile(int nIndex)
  897. {
  898. TRACE(_T("CPgIASAdv::InternalAddAttributeToProfile\n"));
  899. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  900. _ASSERTE( 0<=nIndex && nIndex < m_pvecAllAttributeInfos->size() );
  901. _ASSERTE( m_pvecAllAttributeInfos->at(nIndex) != NULL );
  902. HRESULT hr = S_OK;
  903. // Get the "schema" of the new attributevendor to create.
  904. IIASAttributeInfo *pAttributeInfo = m_pvecAllAttributeInfos->at(nIndex);
  905. // Create a new attribute, initialized with an empty variant.
  906. CComVariant varValue;
  907. CIASProfileAttribute *pProfileAttribute = new CIASProfileAttribute( pAttributeInfo, varValue );
  908. if( ! pProfileAttribute )
  909. {
  910. hr = E_OUTOFMEMORY;
  911. ReportError(hr, IDS_OUTOFMEMORY, NULL);
  912. return hr;
  913. }
  914. // Edit the value of this profile attribute node.
  915. hr = pProfileAttribute->Edit();
  916. if ( hr != S_OK )
  917. {
  918. // The user hit cancel or there was an error -- don't add.
  919. return hr;
  920. }
  921. //
  922. // add this prof attribute node to the list
  923. //
  924. try
  925. {
  926. m_vecProfileAttributes.push_back(pProfileAttribute);
  927. }
  928. catch(CMemoryException&)
  929. {
  930. hr = E_OUTOFMEMORY;
  931. ReportError(hr, IDS_OUTOFMEMORY, NULL);
  932. return hr;
  933. }
  934. // Update the UI.
  935. HRESULT InsertProfileAttributeListItem( m_listProfileAttributes.GetItemCount() );
  936. return S_OK;
  937. }
  938. void CPgIASAdv::OnKeydownIasListAttributesInProfile(NMHDR* pNMHDR, LRESULT* pResult)
  939. {
  940. LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
  941. // TODO: Add your control notification handler code here
  942. if (pLVKeyDow->wVKey == VK_DELETE)
  943. {
  944. // delete the item
  945. OnButtonIasAttributeRemove();
  946. }
  947. *pResult = 0;
  948. }