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.

233 lines
7.9 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 1999
  5. *
  6. * File: siprop.h
  7. *
  8. * Contents: Interface file for CSnapinProperties, et al
  9. *
  10. * History: 04-Nov-99 jeffro Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #ifndef SIPROP_H
  14. #define SIPROP_H
  15. #pragma once
  16. #include "refcount.h"
  17. #include "variant.h"
  18. class CSnapinProperties;
  19. /*+-------------------------------------------------------------------------*
  20. * CMMCPropertyAction
  21. *
  22. * This class is intended to be identical to the MMC_SNAPIN_PROPERTY
  23. * structure that's sent to ISnapinProperties::PropertiesChanged.
  24. *
  25. * It exists to give us intelligent initialization and VARIANT handling
  26. * through CComVariant. This makes it much easier to build an array of
  27. * these things and recover from errors.
  28. *--------------------------------------------------------------------------*/
  29. class CSmartProperty
  30. {
  31. public:
  32. CSmartProperty() : pszPropName(NULL), eAction(MMC_PROPACT_INITIALIZED)
  33. {
  34. /*
  35. * CSmartProperty must have an identical memory layout to
  36. * MMC_SNAPIN_PROPERTY. If any of these asserts fail, that's
  37. * not the case.
  38. */
  39. COMPILETIME_ASSERT (sizeof (CSmartProperty) == sizeof (MMC_SNAPIN_PROPERTY));
  40. COMPILETIME_ASSERT (sizeof (CComVariant) == sizeof (VARIANT));
  41. COMPILETIME_ASSERT (offsetof (CSmartProperty, pszPropName) == offsetof (MMC_SNAPIN_PROPERTY, pszPropName));
  42. COMPILETIME_ASSERT (offsetof (CSmartProperty, varValue) == offsetof (MMC_SNAPIN_PROPERTY, varValue));
  43. COMPILETIME_ASSERT (offsetof (CSmartProperty, eAction) == offsetof (MMC_SNAPIN_PROPERTY, eAction));
  44. }
  45. CSmartProperty (
  46. LPCOLESTR pszPropName_,
  47. const VARIANT& varValue_,
  48. MMC_PROPERTY_ACTION eAction_)
  49. : pszPropName (pszPropName_),
  50. varValue (varValue_),
  51. eAction (eAction_)
  52. {}
  53. public:
  54. LPCOLESTR pszPropName; // name of property
  55. CComVariant varValue; // value of the property
  56. MMC_PROPERTY_ACTION eAction; // what happened to this property
  57. };
  58. /*+-------------------------------------------------------------------------*
  59. * CSnapinProperty
  60. *
  61. * Implements a single property in a properties collection.
  62. *--------------------------------------------------------------------------*/
  63. class CSnapinProperty : public CTiedObject, public CXMLObject
  64. {
  65. public:
  66. enum
  67. {
  68. MMC_PROP_REGISTEREDBYSNAPIN = 0x80000000,
  69. PrivateFlags = MMC_PROP_REGISTEREDBYSNAPIN,
  70. PublicFlags = MMC_PROP_CHANGEAFFECTSUI |
  71. MMC_PROP_MODIFIABLE |
  72. MMC_PROP_REMOVABLE |
  73. MMC_PROP_PERSIST,
  74. };
  75. public:
  76. CSnapinProperty (DWORD dwFlags = 0) : m_dwFlags (dwFlags), m_fInitialized (dwFlags != 0)
  77. {
  78. /*
  79. * public and private flags shouldn't overlap
  80. */
  81. COMPILETIME_ASSERT ((PublicFlags & PrivateFlags) == 0);
  82. }
  83. // default destruction, copy construction and assignment are suitable
  84. const VARIANT& GetValue () const
  85. { return (m_varValue); }
  86. SC ScSetValue (const VARIANT& varValue)
  87. {
  88. /*
  89. * use CComVariant::Copy instead of assignment so we'll have access
  90. * to a return code
  91. */
  92. return (m_varValue.Copy (&varValue));
  93. }
  94. DWORD GetFlags () const
  95. { return (m_dwFlags); }
  96. void InitializeFlags (DWORD dwFlags)
  97. {
  98. // only init once
  99. if (!IsInitialized())
  100. {
  101. m_dwFlags = (dwFlags & PublicFlags) | MMC_PROP_REGISTEREDBYSNAPIN;
  102. m_fInitialized = true;
  103. }
  104. }
  105. bool IsRegisteredBySnapin () const
  106. { return (m_dwFlags & MMC_PROP_REGISTEREDBYSNAPIN); }
  107. bool IsInitialized () const
  108. { return (m_fInitialized); }
  109. void SetRegisteredBySnapin()
  110. { m_dwFlags |= MMC_PROP_REGISTEREDBYSNAPIN; }
  111. // CXMLObject methods
  112. DEFINE_XML_TYPE(XML_TAG_SNAPIN_PROPERTY);
  113. virtual void Persist(CPersistor &persistor);
  114. private:
  115. CXMLVariant m_varValue; // value of the property
  116. DWORD m_dwFlags; // flags for the property
  117. bool m_fInitialized; // initialized yet?
  118. };
  119. /*+-------------------------------------------------------------------------*
  120. * CSnapinProperties
  121. *
  122. * Implementation class for properties collections. It implements Properties
  123. * and ISnapinPropertiesCallback, as well as the methods required to support
  124. * enumeration through CMMCEnumerator.
  125. *
  126. * Note that there is not a tied COM object to support Properties; that is
  127. * implemented here. This class can, however, be tied to tied COM objects
  128. * implementing the collection enumerator.
  129. *--------------------------------------------------------------------------*/
  130. class CSnapinProperties :
  131. public ISnapinPropertiesCallback,
  132. public CMMCIDispatchImpl<Properties>, // the Properties interface
  133. public CTiedObject,
  134. public XMLListCollectionBase
  135. {
  136. BEGIN_MMC_COM_MAP(CSnapinProperties)
  137. COM_INTERFACE_ENTRY(ISnapinPropertiesCallback)
  138. END_MMC_COM_MAP()
  139. public:
  140. CSnapinProperties() : m_pMTSnapInNode(NULL) {}
  141. typedef std::map<std::wstring, CSnapinProperty> CPropertyMap;
  142. /*
  143. * When used for enumeration, an key represents the most recent item
  144. * returned. When a new enumerator is created, the key will be empty,
  145. * signifiying that nothing has been returned yet. After returning Item1,
  146. * the key will point to Item1, and the next call to return an item will
  147. * find the next item in the collection after Item1. This will allow us
  148. * to correctly enumerate if Item1 is removed from the collection between
  149. * calls to retrieve Item1 and Item2.
  150. *
  151. * When used to identify a property, the key is the name of the property.
  152. */
  153. typedef CPropertyMap::key_type CPropertyKey;
  154. private:
  155. typedef CPropertyMap::iterator CPropertyIterator;
  156. typedef CPropertyMap::const_iterator CConstPropertyIterator;
  157. public:
  158. ::SC ScInitialize (ISnapinProperties* psip, Properties* pInitialProps, CMTSnapInNode* pMTSnapInNode);
  159. ::SC ScSetSnapInNode (CMTSnapInNode* pMTSnapInNode);
  160. static CSnapinProperties* FromInterface (IUnknown* pUnk);
  161. public:
  162. // ISnapinPropertiesCallback interface
  163. STDMETHOD(AddPropertyName) (LPCOLESTR pszPropName, DWORD dwFlags);
  164. // Properties interface
  165. STDMETHOD(Item) (BSTR bstrName, PPPROPERTY ppProperty);
  166. STDMETHOD(get_Count) (PLONG pCount);
  167. STDMETHOD(Remove) (BSTR bstrName);
  168. STDMETHOD(get__NewEnum) (IUnknown** ppUnk);
  169. // for support of get__NewEnum and IEnumVARIANT via CMMCNewEnumImpl
  170. ::SC ScEnumNext (CPropertyKey &key, PDISPATCH & pDispatch);
  171. ::SC ScEnumSkip (unsigned long celt, unsigned long& celtSkipped, CPropertyKey &key);
  172. ::SC ScEnumReset (CPropertyKey &key);
  173. // Property interface
  174. ::SC Scget_Value (VARIANT* pvarValue, const CPropertyKey& key);
  175. ::SC Scput_Value (VARIANT varValue, const CPropertyKey& key);
  176. // CXMLObject methods
  177. DEFINE_XML_TYPE(XML_TAG_SNAPIN_PROPERTIES);
  178. virtual void OnNewElement(CPersistor& persistor);
  179. virtual void Persist (CPersistor &persistor);
  180. private:
  181. ::SC ScGetPropertyComObject (const CPropertyKey& key, Property*& rpProperty);
  182. ::SC ScMergeProperties (const CSnapinProperties& other);
  183. ::SC ScNotifyPropertyChange (CPropertyIterator itProp, const VARIANT& varNewValue, MMC_PROPERTY_ACTION eAction);
  184. ::SC ScNotifyPropertyChange (CSmartProperty* pProps, ULONG cProps);
  185. CPropertyIterator IteratorFromKey (const CPropertyKey& key, bool fExactMatch);
  186. void PersistWorker (CPersistor &persistor, CPropertyIterator it);
  187. protected:
  188. CPropertyMap m_PropMap;
  189. CMTSnapInNode* m_pMTSnapInNode;
  190. ISnapinPropertiesPtr m_spSnapinProps;
  191. };
  192. #endif /* SIPROP_H */