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.

326 lines
7.9 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 00
  5. *
  6. * File: mtnode.inl
  7. *
  8. * Contents:
  9. *
  10. * History: 8-Mar-2000 jeffro Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #pragma once
  14. //_____________________________________________________________________________
  15. //
  16. // Inlines for class: CMTNode
  17. //_____________________________________________________________________________
  18. //
  19. inline USHORT CMTNode::AddRef()
  20. {
  21. return (++m_cRef);
  22. }
  23. inline USHORT CMTNode::Release()
  24. {
  25. // Note: The return value from this is important
  26. // as a return value of zero is interpreted as
  27. // object destroyed.
  28. ASSERT(m_cRef > 0);
  29. --m_cRef;
  30. if (m_cRef == 0)
  31. {
  32. delete this;
  33. return 0;
  34. }
  35. return m_cRef;
  36. }
  37. inline PMTNODE CMTNode::GetChild()
  38. {
  39. if (!WasExpandedAtLeastOnce())
  40. Expand();
  41. return Child();
  42. }
  43. inline CMTSnapInNode* CMTNode::GetStaticParent(void)
  44. {
  45. CMTNode* p = this;
  46. while (!p->IsStaticNode())
  47. p = p->Parent();
  48. ASSERT(p != NULL);
  49. CMTSnapInNode* pMTSnapInNode = dynamic_cast<CMTSnapInNode*>(p);
  50. ASSERT (pMTSnapInNode != NULL);
  51. return pMTSnapInNode;
  52. }
  53. inline void CMTNode::CreatePathList(CHMTNODEList& path)
  54. {
  55. CMTNode* pMTNode = this;
  56. for (; pMTNode != NULL; pMTNode = pMTNode->Parent())
  57. path.AddHead(ToHandle(pMTNode));
  58. }
  59. inline CMTNode* CMTNode::Find(MTNODEID id)
  60. {
  61. CMTNode* pStartNode = this; // this is to avoid traversing the tree above the initial node passed
  62. CMTNode* pNode = this;
  63. while ( pNode->GetID() != id )
  64. {
  65. if ( NULL != pNode->Child() )
  66. {
  67. // dive down to the lowest child
  68. pNode = pNode->Child();
  69. }
  70. else
  71. {
  72. // get to the next sub-branch
  73. // ( but first - climb up till you get to the junction )
  74. while ( NULL == pNode->Next() )
  75. {
  76. pNode = pNode->Parent();
  77. // if there are no more nodes - we are done ( search failed )
  78. // ... or if we looked thru all children and siblings [ this
  79. // mostly for compatibility - CMTNode::Find is never used else than
  80. // from topmost node].
  81. if ( (NULL == pNode) || (pNode == pStartNode->Parent()) )
  82. return NULL;
  83. }
  84. pNode = pNode->Next();
  85. }
  86. }
  87. return pNode;
  88. }
  89. inline CMTNode* CMTNode::GetLastChild()
  90. {
  91. CMTNode* pMTNode = Child();
  92. if (pMTNode == NULL)
  93. return NULL;
  94. while (pMTNode->Next() != NULL)
  95. {
  96. pMTNode = pMTNode->Next();
  97. }
  98. return pMTNode;
  99. }
  100. inline wchar_t* CMTNode::GetViewStorageName(wchar_t* name, int idView)
  101. {
  102. ASSERT(name != NULL);
  103. _ltow(idView, name, 36);
  104. return name;
  105. }
  106. /***************************************************************************\
  107. *
  108. * METHOD: CMTNode::GetViewIdFromStorageName
  109. *
  110. * PURPOSE: function reconstructs view id from the component storage name
  111. * in structured storage based console. This is opposit to what
  112. * GetViewStorageName [above] does.
  113. *
  114. * PARAMETERS:
  115. * const wchar_t* name [in] name of storage element
  116. *
  117. * RETURNS:
  118. * int - view id
  119. *
  120. \***************************************************************************/
  121. inline int CMTNode::GetViewIdFromStorageName(const wchar_t* name)
  122. {
  123. ASSERT(name != NULL);
  124. if (name == NULL)
  125. return 0;
  126. wchar_t *stop = NULL;
  127. return wcstol( name, &stop, 36/*base*/ );
  128. }
  129. inline wchar_t* CMTNode::GetComponentStreamName(wchar_t* name, const CLSID& clsid)
  130. {
  131. ASSERT(name != NULL);
  132. ASSERT(&clsid != NULL);
  133. wchar_t* pName = name;
  134. const long* pl = reinterpret_cast<const long*>(&clsid);
  135. for (int i = 0; i < 4; i++)
  136. {
  137. _ltow(*pl++, pName, 36);
  138. pName += wcslen(pName);
  139. }
  140. return name;
  141. }
  142. inline wchar_t* CMTNode::GetComponentStorageName(wchar_t* name, const CLSID& clsid)
  143. {
  144. return GetComponentStreamName(name, clsid);
  145. }
  146. inline void CMTNode::_SetFlag(ENUM_FLAGS flag, BOOL bSet)
  147. {
  148. ASSERT((flag & (flag-1)) == 0);
  149. if (bSet == TRUE)
  150. m_usFlags |= flag;
  151. else
  152. m_usFlags &= ~flag;
  153. }
  154. inline const CLSID& CMTNode::GetPrimarySnapInCLSID(void)
  155. {
  156. if (m_pPrimaryComponentData == NULL)
  157. return (GUID_NULL);
  158. CSnapIn* const pSnapIn = m_pPrimaryComponentData->GetSnapIn();
  159. if (pSnapIn == NULL)
  160. return (GUID_NULL);
  161. return pSnapIn->GetSnapInCLSID();
  162. }
  163. inline HRESULT CMTNode::GetNodeType(GUID* pGuid)
  164. {
  165. HRESULT hr = m_pPrimaryComponentData->GetNodeType(GetUserParam(), pGuid);
  166. CHECK_HRESULT(hr);
  167. return hr;
  168. }
  169. inline HRESULT CMTNode::OnRename(long fRename, LPOLESTR pszNewName)
  170. {
  171. IDataObjectPtr spDataObject;
  172. HRESULT hr = QueryDataObject(CCT_SCOPE, &spDataObject);
  173. if (FAILED(hr))
  174. return hr;
  175. hr = m_pPrimaryComponentData->Notify(spDataObject,
  176. MMCN_RENAME, fRename, reinterpret_cast<LPARAM>(pszNewName));
  177. CHECK_HRESULT(hr);
  178. return hr;
  179. }
  180. inline HRESULT CMTNode::QueryDataObject(DATA_OBJECT_TYPES type,
  181. LPDATAOBJECT* ppdtobj)
  182. {
  183. if (ppdtobj == NULL)
  184. return (E_INVALIDARG);
  185. *ppdtobj = NULL; // init
  186. CMTSnapInNode* pMTSINode = GetStaticParent();
  187. CComponentData* pCCD = pMTSINode->GetComponentData(GetPrimarySnapInCLSID());
  188. if (pCCD == NULL)
  189. return E_FAIL;
  190. HRESULT hr = pCCD->QueryDataObject(GetUserParam(),
  191. type, ppdtobj);
  192. CHECK_HRESULT(hr);
  193. return hr;
  194. }
  195. inline COMPONENTID CMTNode::GetPrimaryComponentID()
  196. {
  197. return m_pPrimaryComponentData->GetComponentID();
  198. }
  199. inline int CMTNode::GetDynExtCLSID ( LPCLSID *ppCLSID )
  200. {
  201. ASSERT(ppCLSID != NULL);
  202. *ppCLSID = m_arrayDynExtCLSID.GetData();
  203. return m_arrayDynExtCLSID.GetSize();
  204. }
  205. inline void CMTNode::SetNoPrimaryChildren(BOOL bState)
  206. {
  207. if (bState)
  208. m_usExpandFlags |= FLAG_NO_CHILDREN_FROM_PRIMARY;
  209. else
  210. m_usExpandFlags &= ~FLAG_NO_CHILDREN_FROM_PRIMARY;
  211. }
  212. //____________________________________________________________________________
  213. //
  214. // Class: CComponentData Inlines
  215. //____________________________________________________________________________
  216. //
  217. inline HRESULT CComponentData::QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject)
  218. {
  219. DECLARE_SC (sc, _T("CComponentData::QueryDataObject"));
  220. sc = ScCheckPointers (m_spIComponentData, E_FAIL);
  221. if (sc)
  222. return (sc.ToHr());
  223. ASSERT(type != CCT_RESULT);
  224. return ((sc = m_spIComponentData->QueryDataObject(cookie, type, ppDataObject)).ToHr());
  225. }
  226. inline HRESULT CComponentData::GetDisplayInfo(SCOPEDATAITEM* pScopeDataItem)
  227. {
  228. DECLARE_SC (sc, _T("CComponentData::GetDisplayInfo"));
  229. sc = ScCheckPointers (m_spIComponentData, E_FAIL);
  230. if (sc)
  231. return (sc.ToHr());
  232. return ((sc = m_spIComponentData->GetDisplayInfo(pScopeDataItem)).ToHr());
  233. }
  234. inline HRESULT CComponentData::GetNodeType(MMC_COOKIE cookie, GUID* pGuid)
  235. {
  236. IDataObjectPtr spdtobj;
  237. HRESULT hr = QueryDataObject(cookie, CCT_SCOPE, &spdtobj);
  238. if (SUCCEEDED(hr))
  239. hr = ExtractObjectTypeGUID(spdtobj, pGuid);
  240. return hr;
  241. }
  242. //____________________________________________________________________________
  243. //
  244. // Class: CMTSnapInNode Inlines
  245. //____________________________________________________________________________
  246. //
  247. inline CComponentData* CMTSnapInNode::GetComponentData(const CLSID& clsid)
  248. {
  249. for (int i=0; i < m_ComponentDataArray.size(); i++)
  250. {
  251. if (m_ComponentDataArray[i] != NULL &&
  252. IsEqualCLSID(clsid, m_ComponentDataArray[i]->GetCLSID()) == TRUE)
  253. return m_ComponentDataArray[i];
  254. }
  255. return NULL;
  256. }
  257. inline CComponentData* CMTSnapInNode::GetComponentData(COMPONENTID nID)
  258. {
  259. if (nID < m_ComponentDataArray.size())
  260. return m_ComponentDataArray[nID];
  261. return NULL;
  262. }
  263. inline COMPONENTID CMTSnapInNode::AddComponentDataToArray(CComponentData* pCCD)
  264. {
  265. m_ComponentDataArray.push_back(pCCD);
  266. int nID = m_ComponentDataArray.size() -1;
  267. pCCD->SetComponentID(nID);
  268. return nID;
  269. }