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.

276 lines
6.6 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) Microsoft Corporation
  4. //
  5. // Module Name:
  6. //
  7. // IASBooleanAttributeEditor.cpp
  8. //
  9. // Abstract:
  10. //
  11. // Implementation file for the CIASBooleanAttributeEditor class.
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. #include "Precompiled.h"
  15. #include "IASBooleanAttributeEditor.h"
  16. #include "IASBooleanEditorPage.h"
  17. #include "iashelper.h"
  18. //////////////////////////////////////////////////////////////////////////////
  19. // CIASBooleanAttributeEditor::CIASBooleanAttributeEditor
  20. //////////////////////////////////////////////////////////////////////////////
  21. CIASBooleanAttributeEditor::CIASBooleanAttributeEditor()
  22. {
  23. int nLoadStringResult = LoadString(
  24. _Module.GetResourceInstance(),
  25. IDS_BOOLEAN_TRUE,
  26. szTrue,
  27. IAS_MAX_STRING);
  28. _ASSERT( nLoadStringResult > 0 );
  29. nLoadStringResult = LoadString(
  30. _Module.GetResourceInstance(),
  31. IDS_BOOLEAN_FALSE,
  32. szFalse,
  33. IAS_MAX_STRING);
  34. _ASSERT( nLoadStringResult > 0 );
  35. }
  36. //////////////////////////////////////////////////////////////////////////////
  37. // CIASBooleanAttributeEditor::ShowEditor
  38. //////////////////////////////////////////////////////////////////////////////
  39. STDMETHODIMP CIASBooleanAttributeEditor::ShowEditor(
  40. /*[in, out]*/ BSTR *pReserved
  41. )
  42. {
  43. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  44. HRESULT hr = S_OK;
  45. try
  46. {
  47. //
  48. // Boolean Editor
  49. //
  50. CIASBooleanEditorPage cBoolPage;
  51. // Initialize the page's data exchange fields with info
  52. // from IAttributeInfo
  53. CComBSTR bstrName;
  54. CComBSTR bstrSyntax;
  55. ATTRIBUTESYNTAX asSyntax = IAS_SYNTAX_BOOLEAN;
  56. ATTRIBUTEID Id = ATTRIBUTE_UNDEFINED;
  57. if( m_spIASAttributeInfo )
  58. {
  59. hr = m_spIASAttributeInfo->get_AttributeName( &bstrName );
  60. if( FAILED(hr) ) throw hr;
  61. hr = m_spIASAttributeInfo->get_SyntaxString( &bstrSyntax );
  62. if( FAILED(hr) ) throw hr;
  63. hr = m_spIASAttributeInfo->get_AttributeSyntax( &asSyntax );
  64. if( FAILED(hr) ) throw hr;
  65. hr = m_spIASAttributeInfo->get_AttributeID( &Id );
  66. if( FAILED(hr) ) throw hr;
  67. }
  68. cBoolPage.m_strAttrName = bstrName;
  69. cBoolPage.m_strAttrFormat = bstrSyntax;
  70. // Attribute type is actually attribute ID in string format
  71. WCHAR szTempId[MAX_PATH];
  72. wsprintf(szTempId, _T("%ld"), Id);
  73. cBoolPage.m_strAttrType = szTempId;
  74. // Initialize the page's data exchange fields with info
  75. // from VARIANT value passed in.
  76. if ( V_VT(m_pvarValue) == VT_EMPTY )
  77. {
  78. V_VT(m_pvarValue) = VT_BOOL;
  79. V_BOOL(m_pvarValue) = VARIANT_FALSE;
  80. }
  81. cBoolPage.m_bValue = (V_BOOL(m_pvarValue) == VARIANT_TRUE);
  82. int iResult = cBoolPage.DoModal();
  83. if (IDOK == iResult)
  84. {
  85. CComVariant varTemp;
  86. varTemp = cBoolPage.m_bValue;
  87. put_ValueAsVariant(varTemp);
  88. }
  89. else
  90. {
  91. hr = S_FALSE;
  92. }
  93. }
  94. catch( HRESULT & hr )
  95. {
  96. return hr;
  97. }
  98. catch(...)
  99. {
  100. return hr = E_FAIL;
  101. }
  102. return hr;
  103. }
  104. //////////////////////////////////////////////////////////////////////////////
  105. /*++
  106. CIASBooleanAttributeEditor::SetAttributeValue
  107. --*/
  108. //////////////////////////////////////////////////////////////////////////////
  109. STDMETHODIMP CIASBooleanAttributeEditor::SetAttributeValue(VARIANT * pValue)
  110. {
  111. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  112. // Check for preconditions.
  113. if( ! pValue )
  114. {
  115. return E_INVALIDARG;
  116. }
  117. m_pvarValue = pValue;
  118. return S_OK;
  119. }
  120. //////////////////////////////////////////////////////////////////////////////
  121. // CIASBooleanAttributeEditor::get_ValueAsString
  122. //////////////////////////////////////////////////////////////////////////////
  123. STDMETHODIMP CIASBooleanAttributeEditor::get_ValueAsString(
  124. BSTR * pbstrDisplayText)
  125. {
  126. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  127. // Check for preconditions.
  128. if( ! pbstrDisplayText )
  129. {
  130. return E_INVALIDARG;
  131. }
  132. if( ! m_spIASAttributeInfo || ! m_pvarValue )
  133. {
  134. // We are not initialized properly.
  135. return OLE_E_BLANK;
  136. }
  137. HRESULT hr = S_OK;
  138. try
  139. {
  140. CComBSTR bstrDisplay;
  141. VARTYPE vType = V_VT(m_pvarValue);
  142. switch( vType )
  143. {
  144. case VT_BOOL:
  145. {
  146. if( V_BOOL(m_pvarValue) )
  147. {
  148. bstrDisplay = szTrue; //L"TRUE";
  149. }
  150. else
  151. {
  152. bstrDisplay = szFalse; //L"FALSE";
  153. }
  154. break;
  155. }
  156. case VT_EMPTY:
  157. // do nothing -- we will fall through and return a blank string.
  158. break;
  159. default:
  160. // need to check what is happening here,
  161. ASSERT(0);
  162. break;
  163. }
  164. *pbstrDisplayText = bstrDisplay.Copy();
  165. }
  166. catch( HRESULT &hr )
  167. {
  168. return hr;
  169. }
  170. catch(...)
  171. {
  172. return E_FAIL;
  173. }
  174. return hr;
  175. }
  176. //////////////////////////////////////////////////////////////////////////////
  177. // CIASBooleanAttributeEditor::put_ValueAsVariant
  178. //////////////////////////////////////////////////////////////////////////////
  179. STDMETHODIMP CIASBooleanAttributeEditor::put_ValueAsVariant(
  180. const CComVariant& newVal)
  181. {
  182. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  183. if( ! m_pvarValue )
  184. {
  185. // We are not initialized properly.
  186. return OLE_E_BLANK;
  187. }
  188. if( m_spIASAttributeInfo == NULL )
  189. {
  190. // We are not initialized properly.
  191. return OLE_E_BLANK;
  192. }
  193. if( V_VT(&newVal) != VT_BOOL)
  194. {
  195. ASSERT(true);
  196. }
  197. V_VT(m_pvarValue) = VT_BOOL;
  198. V_BOOL(m_pvarValue) = V_BOOL(&newVal);
  199. return S_OK;
  200. }
  201. //////////////////////////////////////////////////////////////////////////////
  202. // CIASBooleanAttributeEditor::put_ValueAsString
  203. //////////////////////////////////////////////////////////////////////////////
  204. STDMETHODIMP CIASBooleanAttributeEditor::put_ValueAsString(BSTR newVal)
  205. {
  206. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  207. if( ! m_pvarValue )
  208. {
  209. // We are not initialized properly.
  210. return OLE_E_BLANK;
  211. }
  212. if( m_spIASAttributeInfo == NULL )
  213. {
  214. // We are not initialized properly.
  215. return OLE_E_BLANK;
  216. }
  217. CComBSTR bstrTemp(newVal);
  218. V_VT(m_pvarValue) = VT_BOOL;
  219. if( wcsncmp(newVal, szTrue, wcslen(szTrue) ) == 0 )
  220. {
  221. V_BOOL(m_pvarValue) = VARIANT_TRUE;
  222. }
  223. else
  224. {
  225. V_BOOL(m_pvarValue) = VARIANT_FALSE;
  226. }
  227. return S_OK;
  228. }