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.

463 lines
10 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation, 1998 - 1999
  4. Module Name:
  5. IASEnumerableAttributeEditor.cpp
  6. Abstract:
  7. Implementation file for the CIASEnumerableAttributeEditor class.
  8. Revision History:
  9. mmaguire 06/25/98 - created
  10. --*/
  11. //////////////////////////////////////////////////////////////////////////////
  12. //////////////////////////////////////////////////////////////////////////////
  13. // BEGIN INCLUDES
  14. //
  15. // standard includes:
  16. //
  17. #include "Precompiled.h"
  18. //
  19. // where we can find declaration for main class in this file:
  20. //
  21. #include "IASEnumerableAttributeEditor.h"
  22. //
  23. // where we can find declarations needed in this file:
  24. //
  25. #include "IASEnumerableEditorPage.h"
  26. //
  27. // END INCLUDES
  28. //////////////////////////////////////////////////////////////////////////////
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CIASEnumerableAttributeEditor
  31. //////////////////////////////////////////////////////////////////////////////
  32. /*++
  33. CIASEnumerableAttributeEditor::ShowEditor
  34. IIASAttributeEditor interface implementation
  35. --*/
  36. //////////////////////////////////////////////////////////////////////////////
  37. STDMETHODIMP CIASEnumerableAttributeEditor::ShowEditor( /*[in, out]*/ BSTR *pReserved )
  38. {
  39. TRACE(_T("CIASEnumerableAttributeEditor::ShowEditor\n"));
  40. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  41. // Check for preconditions.
  42. if( m_spIASAttributeInfo == NULL )
  43. {
  44. // We are not initialized properly.
  45. return OLE_E_BLANK;
  46. }
  47. HRESULT hr = S_OK;
  48. try
  49. {
  50. // Load page title.
  51. // ::CString strPageTitle;
  52. // strPageTitle.LoadString(IDS_IAS_IP_EDITOR_TITLE);
  53. //
  54. // CPropertySheet propSheet( (LPCTSTR)strPageTitle );
  55. //
  56. // IP Address Editor
  57. //
  58. CIASPgEnumAttr cppPage;
  59. // Initialize the page's data exchange fields with info from IAttributeInfo
  60. CComBSTR bstrName;
  61. CComBSTR bstrSyntax;
  62. ATTRIBUTEID Id = ATTRIBUTE_UNDEFINED;
  63. hr = m_spIASAttributeInfo->get_AttributeName( &bstrName );
  64. if( FAILED(hr) ) throw hr;
  65. hr = m_spIASAttributeInfo->get_SyntaxString( &bstrSyntax );
  66. if( FAILED(hr) ) throw hr;
  67. hr = m_spIASAttributeInfo->get_AttributeID( &Id );
  68. if( FAILED(hr) ) throw hr;
  69. cppPage.m_strAttrName = bstrName;
  70. cppPage.m_strAttrFormat = bstrSyntax;
  71. // Attribute type is actually attribute ID in string format
  72. WCHAR szTempId[MAX_PATH];
  73. wsprintf(szTempId, _T("%ld"), Id);
  74. cppPage.m_strAttrType = szTempId;
  75. // Initialize the page's data exchange fields with info from VARIANT value passed in.
  76. CComBSTR bstrTemp;
  77. hr = get_ValueAsString( &bstrTemp );
  78. if( FAILED( hr ) ) throw hr;
  79. cppPage.m_strAttrValue = bstrTemp;
  80. cppPage.SetData( m_spIASAttributeInfo.p );
  81. // propSheet.AddPage(&cppPage);
  82. // int iResult = propSheet.DoModal();
  83. int iResult = cppPage.DoModal();
  84. if (IDOK == iResult)
  85. {
  86. CComBSTR bstrTemp = cppPage.m_strAttrValue;
  87. hr = put_ValueAsString( bstrTemp );
  88. if( FAILED( hr ) ) throw hr;
  89. }
  90. else
  91. {
  92. hr = S_FALSE;
  93. }
  94. //
  95. // delete the property page pointer
  96. //
  97. // propSheet.RemovePage(&cppPage);
  98. }
  99. catch( HRESULT & hr )
  100. {
  101. return hr;
  102. }
  103. catch(...)
  104. {
  105. return hr = E_FAIL;
  106. }
  107. return hr;
  108. }
  109. //////////////////////////////////////////////////////////////////////////////
  110. /*++
  111. CIASEnumerableAttributeEditor::SetAttributeValue
  112. IIASAttributeEditor interface implementation
  113. --*/
  114. //////////////////////////////////////////////////////////////////////////////
  115. STDMETHODIMP CIASEnumerableAttributeEditor::SetAttributeValue(VARIANT * pValue)
  116. {
  117. TRACE(_T("CIASEnumerableAttributeEditor::SetAttributeValue\n"));
  118. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  119. // Check for preconditions.
  120. if( pValue == NULL )
  121. {
  122. return E_INVALIDARG;
  123. }
  124. if( V_VT(pValue) != VT_I4 && V_VT(pValue) != VT_EMPTY )
  125. {
  126. return E_INVALIDARG;
  127. }
  128. m_pvarValue = pValue;
  129. return S_OK;
  130. }
  131. //////////////////////////////////////////////////////////////////////////////
  132. /*++
  133. CIASEnumerableAttributeEditor::get_ValueAsString
  134. IIASAttributeEditor interface implementation
  135. --*/
  136. //////////////////////////////////////////////////////////////////////////////
  137. STDMETHODIMP CIASEnumerableAttributeEditor::get_ValueAsString(BSTR * pbstrDisplayText )
  138. {
  139. TRACE(_T("CIASEnumerableAttributeEditor::get_ValueAsString\n"));
  140. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  141. // Check for preconditions.
  142. if( ! pbstrDisplayText )
  143. {
  144. return E_INVALIDARG;
  145. }
  146. if( m_spIASAttributeInfo == NULL || m_spIASEnumerableAttributeInfo == NULL )
  147. {
  148. // We are not initialized properly.
  149. return OLE_E_BLANK;
  150. }
  151. if( m_pvarValue == NULL )
  152. {
  153. // We are not initialized properly.
  154. return OLE_E_BLANK;
  155. }
  156. HRESULT hr = S_OK;
  157. try
  158. {
  159. CComBSTR bstrDisplay;
  160. if( V_VT(m_pvarValue) == VT_I4 )
  161. {
  162. long lCurrentSelection = 0;
  163. long lCurrentEnumerateID = V_I4(m_pvarValue);
  164. // Figure out the position of this ID in the list of possible ID's.
  165. lCurrentSelection = ConvertEnumerateIDToOrdinal( lCurrentEnumerateID );
  166. // Get the description string for the specified ID.
  167. hr = m_spIASEnumerableAttributeInfo->get_EnumerateDescription( lCurrentSelection, &bstrDisplay );
  168. if( FAILED( hr ) ) throw hr;
  169. }
  170. *pbstrDisplayText = bstrDisplay.Copy();
  171. }
  172. catch(...)
  173. {
  174. return E_FAIL;
  175. }
  176. return hr;
  177. }
  178. //////////////////////////////////////////////////////////////////////////////
  179. /*++
  180. CIASEnumerableAttributeEditor::put_ValueAsString
  181. IIASAttributeEditor interface implementation
  182. --*/
  183. //////////////////////////////////////////////////////////////////////////////
  184. STDMETHODIMP CIASEnumerableAttributeEditor::put_ValueAsString(BSTR newVal)
  185. {
  186. TRACE(_T("CIASEnumerableAttributeEditor::put_ValueAsString\n"));
  187. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  188. // Check for preconditions.
  189. if( ! m_spIASAttributeInfo || ! m_spIASEnumerableAttributeInfo )
  190. {
  191. // We are not initialized properly.
  192. return OLE_E_BLANK;
  193. }
  194. if( ! m_pvarValue )
  195. {
  196. // We are not initialized properly.
  197. return OLE_E_BLANK;
  198. }
  199. HRESULT hr = S_OK;
  200. try
  201. {
  202. // Initialize the variant that was passed in.
  203. VariantClear(m_pvarValue);
  204. // Figure out the position in the enumeration of the user's choice.
  205. long lCurrentEnumerateID = 0;
  206. CComBSTR bstrTemp = newVal;
  207. long lCurrentSelection = ConvertEnumerateDescriptionToOrdinal( bstrTemp );
  208. // Convert the position to an ID.
  209. m_spIASEnumerableAttributeInfo->get_EnumerateID( lCurrentSelection, &lCurrentEnumerateID );
  210. // Save the ID that the user chose to the variant.
  211. V_VT(m_pvarValue) = VT_I4;
  212. V_I4(m_pvarValue) = lCurrentEnumerateID;
  213. }
  214. catch(...)
  215. {
  216. return E_FAIL;
  217. }
  218. return hr;
  219. }
  220. //////////////////////////////////////////////////////////////////////////////
  221. /*++
  222. CIASEnumerableAttributeEditor::SetAttributeSchema
  223. IIASAttributeEditor interface implementation
  224. --*/
  225. //////////////////////////////////////////////////////////////////////////////
  226. STDMETHODIMP CIASEnumerableAttributeEditor::SetAttributeSchema(IIASAttributeInfo * pIASAttributeInfo)
  227. {
  228. TRACE(_T("CIASEnumerableAttributeEditor::SetAttributeSchema\n"));
  229. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  230. HRESULT hr = S_OK;
  231. hr = CIASAttributeEditor::SetAttributeSchema( pIASAttributeInfo );
  232. if( FAILED( hr ) ) return hr;
  233. // This particular type of attribute editor requires that the AttributeInfo it was passed
  234. // implement a specific type of interface. We query for this interface now.
  235. CComQIPtr< IIASEnumerableAttributeInfo, &IID_IIASEnumerableAttributeInfo> spIASEnumerableAttributeInfo( m_spIASAttributeInfo );
  236. if( spIASEnumerableAttributeInfo == NULL )
  237. {
  238. return E_NOINTERFACE;
  239. }
  240. // Save away the interface.
  241. m_spIASEnumerableAttributeInfo = spIASEnumerableAttributeInfo;
  242. return S_OK;
  243. }
  244. /////////////////////////////////////////////////////////////////////////////
  245. /*++
  246. CIASEnumerableAttributeEditor::ConvertEnumerateIDToOrdinal
  247. Figure out the position in the enumeration of the specified ID.
  248. --*/
  249. //////////////////////////////////////////////////////////////////////////////
  250. long CIASEnumerableAttributeEditor::ConvertEnumerateIDToOrdinal( long ID )
  251. {
  252. TRACE(_T("CIASEnumerableAttributeEditor::ConvertEnumerateIDToOrdinal\n"));
  253. // Check for preconditions:
  254. _ASSERTE( m_spIASEnumerableAttributeInfo != NULL );
  255. HRESULT hr;
  256. long lCountEnumeration;
  257. hr = m_spIASEnumerableAttributeInfo->get_CountEnumerateID( & lCountEnumeration );
  258. if( FAILED( hr ) ) throw hr;
  259. for (long lIndex=0; lIndex < lCountEnumeration; lIndex++)
  260. {
  261. long lTemp;
  262. hr = m_spIASEnumerableAttributeInfo->get_EnumerateID( lIndex, &lTemp );
  263. if( FAILED( hr ) ) throw hr;
  264. if ( ID == lTemp )
  265. {
  266. return( lIndex );
  267. }
  268. }
  269. // If we got here, we couldn't find it.
  270. throw E_FAIL;
  271. return 0;
  272. }
  273. /////////////////////////////////////////////////////////////////////////////
  274. /*++
  275. CIASEnumerableAttributeEditor::ConvertEnumerateIDToOrdinal
  276. Figure out the position in the enumeration of the specified description string.
  277. --*/
  278. //////////////////////////////////////////////////////////////////////////////
  279. long CIASEnumerableAttributeEditor::ConvertEnumerateDescriptionToOrdinal( BSTR bstrDescription )
  280. {
  281. TRACE(_T("CIASEnumerableAttributeEditor::ConvertEnumerateDescriptionToOrdinal\n"));
  282. // Check for preconditions:
  283. _ASSERTE( m_spIASEnumerableAttributeInfo != NULL );
  284. long lCountEnumeration;
  285. HRESULT hr = S_OK;
  286. hr = m_spIASEnumerableAttributeInfo->get_CountEnumerateDescription( & lCountEnumeration );
  287. if( FAILED( hr ) ) throw hr;
  288. for (long lIndex=0; lIndex < lCountEnumeration; lIndex++)
  289. {
  290. CComBSTR bstrTemp;
  291. hr = m_spIASEnumerableAttributeInfo->get_EnumerateDescription( lIndex, &bstrTemp );
  292. if( FAILED( hr ) ) throw hr;
  293. if ( wcscmp( bstrTemp , bstrDescription ) == 0 )
  294. {
  295. return( lIndex );
  296. }
  297. }
  298. // If we got here, we couldn't find it.
  299. throw E_FAIL;
  300. return 0;
  301. }