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.

1189 lines
33 KiB

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