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.

273 lines
6.4 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. CLASSINF.CPP
  5. Abstract:
  6. History:
  7. --*/
  8. #include "classinf.h"
  9. #include "lazy.h"
  10. void CHmmClassInfo::Load(HMM_CLASS_INFO ci)
  11. {
  12. m_wsClassName = ci.m_wszClassName;
  13. m_bIncludeChildren = ci.m_bIncludeChildren;
  14. m_Selected.RemoveAllProperties();
  15. m_Selected.AddProperties(ci.m_lNumSelectedProperties,
  16. ci.m_awszSelected);
  17. }
  18. void CHmmClassInfo::Save(HMM_CLASS_INFO& ci)
  19. {
  20. ci.m_wszClassName = HmmStringCopy((LPCWSTR)m_wsClassName);
  21. ci.m_bIncludeChildren = m_bIncludeChildren;
  22. m_Selected.GetList(0, &ci.m_lNumSelectedProperties,
  23. &ci.m_awszSelected);
  24. }
  25. HRESULT CHmmClassInfo::CheckObjectAgainstMany(
  26. IN long lNumInfos,
  27. IN CHmmClassInfo** apInfos,
  28. IN IHmmPropertySource* pSource,
  29. OUT IHmmPropertyList** ppList,
  30. OUT long* plIndex)
  31. {
  32. if(ppList) *ppList = NULL;
  33. CLazyClassName ClassName(pSource);
  34. // Go through our tokens one by one
  35. // ================================
  36. BOOL bFound = FALSE;
  37. for(int i = 0; !bFound && i < lNumInfos; i++)
  38. {
  39. CHmmClassInfo* pToken = apInfos[i];
  40. if(pToken->m_bIncludeChildren)
  41. {
  42. bFound = (pSource->IsDerivedFrom(pToken->m_wsClassName) ==
  43. HMM_S_NO_ERROR);
  44. }
  45. else
  46. {
  47. bFound = !wcsicmp(ClassName.GetName(), pToken->m_wsClassName);
  48. }
  49. if(bFound && ppList)
  50. {
  51. pToken->GetSelected().QueryInterface(IID_IHmmPropertyList,
  52. (void**)ppList);
  53. }
  54. }
  55. if(bFound)
  56. {
  57. return HMM_S_NO_ERROR;
  58. }
  59. else
  60. {
  61. return HMM_S_FALSE;
  62. }
  63. }
  64. CHmmNode* CHmmClassInfo::GetTree()
  65. {
  66. CSql1Token* pExpr = new CSql1Token;
  67. V_VT(&pExpr->m_vConstValue) = VT_BSTR;
  68. V_BSTR(&pExpr->m_vConstValue) = SysAllocString(m_wsClassName);
  69. if(m_bIncludeChildren)
  70. {
  71. pExpr->m_lOperator = SQL1_OPERATOR_INHERITSFROM;
  72. pExpr->m_wsProperty.Empty();
  73. pExpr->m_lPropertyFunction = pExpr->m_lConstFunction =
  74. SQL1_FUNCTION_NONE;
  75. }
  76. else
  77. {
  78. pExpr->m_lOperator = SQL1_OPERATOR_EQUALS;
  79. pExpr->m_wsProperty = L"__CLASS";
  80. pExpr->m_lPropertyFunction = pExpr->m_lConstFunction =
  81. SQL1_FUNCTION_UPPER;
  82. }
  83. pExpr->AddRef();
  84. return pExpr;
  85. }
  86. CClassInfoFilter::~CClassInfoFilter()
  87. {
  88. if(m_pTree)
  89. m_pTree->Release();
  90. }
  91. void* CClassInfoFilter::GetInterface(REFIID riid)
  92. {
  93. if(riid == IID_IHmmFilter || riid == IID_IHmmClassInfoFilter)
  94. return (IHmmClassInfoFilter*)&m_XFilter;
  95. else if(riid == IID_IConfigureHmmClassInfoFilter)
  96. return (IConfigureHmmClassInfoFilter*)&m_XConfigure;
  97. else
  98. return NULL;
  99. }
  100. STDMETHODIMP CClassInfoFilter::XFilter::
  101. CheckObject(IN IHmmPropertySource* pSource, OUT IHmmPropertyList** ppList,
  102. OUT IUnknown** ppHint)
  103. {
  104. if(ppHint) *ppHint = NULL;
  105. return CHmmClassInfo::CheckObjectAgainstMany(
  106. m_pObject->m_apTokens.GetSize(),
  107. m_pObject->m_apTokens.begin(),
  108. pSource, ppList, NULL);
  109. }
  110. STDMETHODIMP CClassInfoFilter::XFilter::
  111. IsSpecial()
  112. {
  113. if(m_pObject->m_apTokens.GetSize() == 0)
  114. return HMM_S_ACCEPTS_NOTHING;
  115. else
  116. return HMM_S_FALSE;
  117. }
  118. STDMETHODIMP CClassInfoFilter::XFilter::
  119. GetSelectedPropertyList(IN long lFlags, OUT IHmmPropertyList** ppList)
  120. {
  121. // Only implemented if one class info is present
  122. // =============================================
  123. if(m_pObject->m_apTokens.GetSize() == 1)
  124. {
  125. return m_pObject->m_apTokens[0]->GetSelected().
  126. QueryInterface(IID_IHmmPropertyList, (void**)ppList);
  127. }
  128. else
  129. {
  130. // Stubbed out
  131. // ===========
  132. CPropertyList* pList = new CPropertyList(m_pObject->m_pControl, NULL);
  133. pList->QueryInterface(IID_IHmmPropertyList, (void**)ppList);
  134. if(lFlags == HMM_FLAG_NECESSARY)
  135. {
  136. pList->RemoveAllProperties(); // no properties are "necessary"
  137. }
  138. else
  139. {
  140. pList->AddAllProperties();
  141. }
  142. return HMM_S_NO_ERROR;
  143. }
  144. }
  145. STDMETHODIMP CClassInfoFilter::XFilter::
  146. GetType(OUT IID* piid)
  147. {
  148. if(piid == NULL)
  149. return HMM_E_INVALID_PARAMETER;
  150. *piid = IID_IHmmClassInfoFilter;
  151. return HMM_S_NO_ERROR;
  152. }
  153. STDMETHODIMP CClassInfoFilter::XFilter::
  154. GetClassInfos(IN long lFirstIndex,
  155. IN long lNumInfos,
  156. OUT long* plInfosReturned,
  157. OUT HMM_CLASS_INFO* aInfos)
  158. {
  159. if(plInfosReturned == NULL || aInfos == NULL || lFirstIndex < 0 ||
  160. lNumInfos < 0)
  161. {
  162. return HMM_E_INVALID_PARAMETER;
  163. }
  164. long lCurrentSize = m_pObject->m_apTokens.GetSize();
  165. if(lFirstIndex >= lCurrentSize)
  166. return HMM_S_NO_MORE_DATA;
  167. long lEndIndex = lFirstIndex + lNumInfos;
  168. if(lEndIndex > lCurrentSize)
  169. lEndIndex = lCurrentSize;
  170. for(long l = lFirstIndex; l < lEndIndex; l++)
  171. {
  172. m_pObject->m_apTokens[l]->Save(aInfos[l-lFirstIndex]);
  173. }
  174. *plInfosReturned = lEndIndex - lFirstIndex;
  175. return HMM_S_NO_ERROR;
  176. }
  177. STDMETHODIMP CClassInfoFilter::XConfigure::
  178. AddClassInfos(long lNumInfos, IN HMM_CLASS_INFO* aInfos)
  179. {
  180. if(lNumInfos <= 0 || aInfos == NULL)
  181. return HMM_E_INVALID_PARAMETER;
  182. m_pObject->InvalidateTree();
  183. for(long l = 0; l < lNumInfos; l++)
  184. {
  185. // Create a new info object, setting our MemberLife as its life control
  186. // object. This will propagate his AddRef and Release calls to us.
  187. CHmmClassInfo* pNew = new CHmmClassInfo(&m_pObject->m_MemberLife);
  188. pNew->Load(aInfos[l]);
  189. m_pObject->m_apTokens.Add(pNew);
  190. }
  191. return HMM_S_NO_ERROR;
  192. }
  193. STDMETHODIMP CClassInfoFilter::XConfigure::
  194. RemoveAllInfos()
  195. {
  196. m_pObject->InvalidateTree();
  197. m_pObject->m_apTokens.RemoveAll();
  198. return HMM_S_NO_ERROR;
  199. }
  200. CHmmNode* CClassInfoFilter::GetTree()
  201. {
  202. if(m_pTree)
  203. {
  204. m_pTree->AddRef();
  205. return m_pTree;
  206. }
  207. // Build it
  208. // ========
  209. CLogicalNode* pOr = new CLogicalNode;
  210. pOr->m_lTokenType = SQL1_OR;
  211. for(int i = 0; i < m_apTokens.GetSize(); i++)
  212. {
  213. CHmmClassInfo* pInfo = m_apTokens[i];
  214. CHmmNode* pExpr = pInfo->GetTree();
  215. pOr->Add(pExpr);
  216. pExpr->Release();
  217. }
  218. m_pTree = pOr;
  219. m_pTree->AddRef(); // for storage
  220. m_pTree->AddRef(); // for return
  221. return m_pTree;
  222. }