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.

316 lines
6.8 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation, 1998 - 1999
  4. Module Name:
  5. IASMultivaluedAttributeEditor.cpp
  6. Abstract:
  7. Implementation file for the CIASMultivaluedAttributeEditor 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 "IASMultivaluedAttributeEditor.h"
  22. //
  23. // where we can find declarations needed in this file:
  24. //
  25. #include "IASMultivaluedEditorPage.h"
  26. //
  27. // END INCLUDES
  28. //////////////////////////////////////////////////////////////////////////////
  29. //////////////////////////////////////////////////////////////////////////////
  30. /*++
  31. CIASMultivaluedAttributeEditor::ShowEditor
  32. IIASAttributeEditor interface implementation
  33. --*/
  34. //////////////////////////////////////////////////////////////////////////////
  35. STDMETHODIMP CIASMultivaluedAttributeEditor::ShowEditor( /*[in, out]*/ BSTR *pReserved )
  36. {
  37. TRACE(_T("CIASMultivaluedAttributeEditor::ShowEditor\n"));
  38. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  39. // Check for preconditions.
  40. if( ! m_spIASAttributeInfo )
  41. {
  42. // We are not initialized properly.
  43. return OLE_E_BLANK;
  44. }
  45. if( ! m_pvarValue )
  46. {
  47. // We are not initialized properly.
  48. return OLE_E_BLANK;
  49. }
  50. HRESULT hr = S_OK;
  51. try
  52. {
  53. // Load page title.
  54. // ::CString strPageTitle;
  55. // strPageTitle.LoadString(IDS_IAS_MULTIVALUED_EDITOR_TITLE);
  56. //
  57. // CPropertySheet propSheet( (LPCTSTR)strPageTitle );
  58. //
  59. // Multivalued Attribute Editor
  60. //
  61. CMultivaluedEditorPage cppPage;
  62. // Initialize the page's data exchange fields with info from IAttributeInfo
  63. CComBSTR bstrName;
  64. CComBSTR bstrSyntax;
  65. ATTRIBUTEID Id = ATTRIBUTE_UNDEFINED;
  66. hr = m_spIASAttributeInfo->get_AttributeName( &bstrName );
  67. if( FAILED(hr) ) throw hr;
  68. hr = m_spIASAttributeInfo->get_SyntaxString( &bstrSyntax );
  69. if( FAILED(hr) ) throw hr;
  70. hr = m_spIASAttributeInfo->get_AttributeID( &Id );
  71. if( FAILED(hr) ) throw hr;
  72. cppPage.m_strAttrName = bstrName;
  73. cppPage.m_strAttrFormat = bstrSyntax;
  74. // Attribute type is actually attribute ID in string format
  75. WCHAR szTempId[MAX_PATH];
  76. wsprintf(szTempId, _T("%ld"), Id);
  77. cppPage.m_strAttrType = szTempId;
  78. // Initialize the page's data exchange fields with info from VARIANT value passed in.
  79. cppPage.SetData( m_spIASAttributeInfo.p, m_pvarValue );
  80. // propSheet.AddPage(&cppPage);
  81. // int iResult = propSheet.DoModal();
  82. int iResult = cppPage.DoModal();
  83. if (IDOK == iResult)
  84. {
  85. // Tell the page to commit the changes made to the m_pvarValue
  86. // pointer it was given. It will take care of
  87. // packaging the array of variants back into a variant safearray.
  88. cppPage.CommitArrayToVariant();
  89. }
  90. else
  91. {
  92. hr = S_FALSE;
  93. }
  94. //
  95. // Remove Page pointer from propSheet
  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. CIASMultivaluedAttributeEditor::SetAttributeValue
  112. IIASAttributeEditor interface implementation
  113. --*/
  114. //////////////////////////////////////////////////////////////////////////////
  115. STDMETHODIMP CIASMultivaluedAttributeEditor::SetAttributeValue(VARIANT * pValue)
  116. {
  117. TRACE(_T("CIASMultivaluedAttributeEditor::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_ARRAY) && V_VT(pValue) != VT_EMPTY )
  125. {
  126. return E_INVALIDARG;
  127. }
  128. m_pvarValue = pValue;
  129. return S_OK;
  130. }
  131. //////////////////////////////////////////////////////////////////////////////
  132. /*++
  133. CIASMultivaluedAttributeEditor::get_ValueAsString
  134. IIASAttributeEditor interface implementation
  135. --*/
  136. //////////////////////////////////////////////////////////////////////////////
  137. STDMETHODIMP CIASMultivaluedAttributeEditor::get_ValueAsString(BSTR * pbstrDisplayText )
  138. {
  139. TRACE(_T("CIASMultivaluedAttributeEditor::get_ValueAsString\n"));
  140. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  141. // Check for preconditions.
  142. if( pbstrDisplayText == NULL )
  143. {
  144. return E_INVALIDARG;
  145. }
  146. if( ! m_spIASAttributeInfo )
  147. {
  148. // We are not initialized properly.
  149. return OLE_E_BLANK;
  150. }
  151. if( ! m_pvarValue )
  152. {
  153. // We are not initialized properly.
  154. return OLE_E_BLANK;
  155. }
  156. if( V_VT( m_pvarValue ) != (VT_VARIANT | VT_ARRAY) && V_VT( m_pvarValue ) != VT_EMPTY )
  157. {
  158. return OLE_E_BLANK;
  159. }
  160. CComBSTR bstrDisplay;
  161. HRESULT hr;
  162. // If the variant we were passed is empty, display and empty string.
  163. if( V_VT( m_pvarValue ) == VT_EMPTY )
  164. {
  165. *pbstrDisplayText = bstrDisplay.Copy();
  166. return S_OK;
  167. }
  168. CComBSTR bstrQuote = "\"";
  169. CComBSTR bstrComma = ", ";
  170. try
  171. {
  172. CComPtr<IIASAttributeEditor> spIASAttributeEditor;
  173. // Get attribute editor.
  174. hr = SetUpAttributeEditor( m_spIASAttributeInfo.p, &spIASAttributeEditor );
  175. if( FAILED( hr ) ) throw hr;
  176. // This creates a new copy of the SAFEARRAY pointed to by m_pvarData
  177. // wrapped by the standard COleSafeArray instance m_osaValueList.
  178. COleSafeArray osaValueList = m_pvarValue;
  179. // Note: GetOneDimSize returns a DWORD, but signed should be OK for few elements here.
  180. long lSize = osaValueList.GetOneDimSize(); // number of multi-valued attrs.
  181. // Lock the safearray. This wrapper class will unlock as soon as it goes out of scope.
  182. CMyOleSafeArrayLock osaLock( osaValueList );
  183. for (long lIndex = 0; lIndex < lSize; lIndex++)
  184. {
  185. VARIANT * pvar;
  186. osaValueList.PtrOfIndex( &lIndex, (void**) &pvar );
  187. // Not sure if I like these.
  188. // bstrDisplay += bstrQuote;
  189. // Get a string to display for the attribute value.
  190. CComBSTR bstrVendor;
  191. CComBSTR bstrValue;
  192. CComBSTR bstrReserved;
  193. hr = spIASAttributeEditor->GetDisplayInfo(m_spIASAttributeInfo.p, pvar, &bstrVendor, &bstrValue, &bstrReserved );
  194. if( SUCCEEDED( hr ) )
  195. {
  196. bstrDisplay += bstrValue;
  197. }
  198. // Not sure if I like these.
  199. // bstrDisplay += bstrQuote;
  200. // Special -- for all but last item, add comma after entry.
  201. if( lIndex < lSize - 1 )
  202. {
  203. bstrDisplay += bstrComma;
  204. }
  205. }
  206. }
  207. catch(...)
  208. {
  209. bstrDisplay = "@Error reading display value";
  210. }
  211. *pbstrDisplayText = bstrDisplay.Copy();
  212. if( *pbstrDisplayText )
  213. {
  214. return S_OK;
  215. }
  216. else
  217. {
  218. return E_FAIL;
  219. }
  220. }