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.

332 lines
6.4 KiB

  1. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  2. //
  3. // infotip.cpp
  4. //
  5. // IQueryInfo for folder items.
  6. //
  7. // History:
  8. //
  9. // 4/21/97 edwardp Created.
  10. //
  11. ////////////////////////////////////////////////////////////////////////////////
  12. //
  13. // Includes
  14. //
  15. #include "stdinc.h"
  16. #include "cdfidl.h"
  17. #include "xmlutil.h"
  18. #include "tooltip.h"
  19. #include "dll.h"
  20. //
  21. // Constructor and destructor.
  22. //
  23. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  24. //
  25. // *** CQueryInfo::CQueryInfo ***
  26. //
  27. // Constructor.
  28. //
  29. ////////////////////////////////////////////////////////////////////////////////
  30. CQueryInfo::CQueryInfo(
  31. PCDFITEMIDLIST pcdfidl,
  32. IXMLElementCollection* pIXMLElementCollection
  33. )
  34. : m_cRef(1)
  35. {
  36. ASSERT(CDFIDL_IsValid(pcdfidl));
  37. ASSERT(ILIsEmpty(_ILNext(pcdfidl)));
  38. ASSERT(XML_IsCdfidlMemberOf(pIXMLElementCollection, pcdfidl));
  39. ASSERT(NULL == m_pIXMLElement);
  40. if (pIXMLElementCollection)
  41. {
  42. XML_GetElementByIndex(pIXMLElementCollection, CDFIDL_GetIndex(pcdfidl),
  43. &m_pIXMLElement);
  44. }
  45. if (m_pIXMLElement)
  46. m_fHasSubItems = XML_IsFolder(m_pIXMLElement);
  47. TraceMsg(TF_OBJECTS, "+ IQueryInfo");
  48. DllAddRef();
  49. return;
  50. }
  51. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  52. //
  53. // *** CQueryInfo::CQueryInfo ***
  54. //
  55. // Constructor.
  56. //
  57. ////////////////////////////////////////////////////////////////////////////////
  58. CQueryInfo::CQueryInfo(
  59. IXMLElement* pIXMLElement,
  60. BOOL fHasSubItems
  61. )
  62. : m_cRef(1)
  63. {
  64. if (pIXMLElement)
  65. {
  66. pIXMLElement->AddRef();
  67. m_pIXMLElement = pIXMLElement;
  68. }
  69. m_fHasSubItems = fHasSubItems;
  70. TraceMsg(TF_OBJECTS, "+ IQueryInfo");
  71. DllAddRef();
  72. return;
  73. }
  74. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  75. //
  76. // *** CQueryInfo::~CQueryInfo ***
  77. //
  78. // Destructor.
  79. //
  80. ////////////////////////////////////////////////////////////////////////////////
  81. CQueryInfo::~CQueryInfo(
  82. void
  83. )
  84. {
  85. ASSERT(0 == m_cRef);
  86. if (m_pIXMLElement)
  87. m_pIXMLElement->Release();
  88. TraceMsg(TF_OBJECTS, "- IQueryInfo");
  89. DllRelease();
  90. return;
  91. }
  92. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  93. //
  94. // *** CQueryInfo::QueryInterface ***
  95. //
  96. // CQueryInfo QI.
  97. //
  98. ////////////////////////////////////////////////////////////////////////////////
  99. STDMETHODIMP
  100. CQueryInfo::QueryInterface (
  101. REFIID riid,
  102. void **ppv
  103. )
  104. {
  105. ASSERT(ppv);
  106. HRESULT hr;
  107. *ppv = NULL;
  108. if (IID_IUnknown == riid || IID_IQueryInfo == riid)
  109. {
  110. AddRef();
  111. *ppv = (IQueryInfo*)this;
  112. hr = S_OK;
  113. }
  114. else
  115. {
  116. hr = E_NOINTERFACE;
  117. }
  118. ASSERT((SUCCEEDED(hr) && *ppv) || (FAILED(hr) && NULL == *ppv));
  119. return hr;
  120. }
  121. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  122. //
  123. // *** CQueryInfo::AddRef ***
  124. //
  125. // CQueryInfo AddRef.
  126. //
  127. ////////////////////////////////////////////////////////////////////////////////
  128. STDMETHODIMP_(ULONG)
  129. CQueryInfo::AddRef (
  130. void
  131. )
  132. {
  133. ASSERT(m_cRef != 0);
  134. ASSERT(m_cRef < (ULONG)-1);
  135. return ++m_cRef;
  136. }
  137. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  138. //
  139. // *** CQueryInfo::Release ***
  140. //
  141. // CQueryInfo Release.
  142. //
  143. ////////////////////////////////////////////////////////////////////////////////
  144. STDMETHODIMP_(ULONG)
  145. CQueryInfo::Release (
  146. void
  147. )
  148. {
  149. ASSERT (m_cRef != 0);
  150. ULONG cRef = --m_cRef;
  151. if (0 == cRef)
  152. delete this;
  153. return cRef;
  154. }
  155. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  156. //
  157. // *** CQueryInfo:: ***
  158. //
  159. //
  160. // Description:
  161. // Returns an info tip for the current pidl.
  162. //
  163. // Parameters:
  164. // [In] dwFlags -
  165. // [Out] ppwszText - A pointer to a text buffer. MAX_PATH length assumed!
  166. //
  167. // Return:
  168. // S_OK if the tip was extracted and returned.
  169. // E_OUTOFMEMORY if not enough memory is available.
  170. // E_FAIL otherwise.
  171. //
  172. // Comments:
  173. //
  174. //
  175. ////////////////////////////////////////////////////////////////////////////////
  176. HRESULT
  177. CQueryInfo::GetInfoTip(
  178. DWORD dwFlags,
  179. WCHAR** ppwszTip
  180. )
  181. {
  182. ASSERT(ppwszTip);
  183. *ppwszTip = NULL;
  184. HRESULT hr;
  185. if (m_pIXMLElement)
  186. {
  187. BSTR bstr;
  188. bstr = XML_GetAttribute(m_pIXMLElement, XML_ABSTRACT);
  189. if (bstr)
  190. {
  191. if (*bstr)
  192. {
  193. //
  194. // REVIEW: SHAlloc correct allocator?
  195. //
  196. int cbSize = SysStringByteLen(bstr) + sizeof(WCHAR);
  197. *ppwszTip = (WCHAR*)SHAlloc(cbSize);
  198. if (*ppwszTip)
  199. {
  200. StrCpyW(*ppwszTip, bstr);
  201. hr = S_OK;
  202. }
  203. else
  204. {
  205. hr = E_OUTOFMEMORY;
  206. }
  207. }
  208. else
  209. {
  210. //
  211. // REVIEW: InfoTip when there is no abstract?
  212. //
  213. hr = E_FAIL;
  214. }
  215. SysFreeString(bstr);
  216. }
  217. else
  218. {
  219. hr = E_OUTOFMEMORY;
  220. }
  221. }
  222. else
  223. {
  224. hr = E_OUTOFMEMORY;
  225. }
  226. ASSERT((SUCCEEDED(hr) && *ppwszTip) || (FAILED(hr) && *ppwszTip == NULL));
  227. return hr;
  228. }
  229. HRESULT
  230. CQueryInfo::GetInfoFlags(
  231. DWORD *pdwFlags
  232. )
  233. {
  234. ASSERT(pdwFlags);
  235. HRESULT hr = S_OK;
  236. if(!pdwFlags)
  237. return E_INVALIDARG;
  238. *pdwFlags = QIF_CACHED; // Assume cached by default
  239. if (!m_fHasSubItems)
  240. *pdwFlags |= QIF_DONTEXPANDFOLDER;
  241. if (m_pIXMLElement)
  242. {
  243. BSTR bstrURL = XML_GetAttribute(m_pIXMLElement, XML_HREF);
  244. if (bstrURL)
  245. {
  246. if (*bstrURL)
  247. {
  248. BOOL fCached;
  249. //
  250. // REVIEW: SHAlloc correct allocator?
  251. //
  252. fCached = CDFIDL_IsCachedURL(bstrURL);
  253. if(!fCached)
  254. *pdwFlags &= ~QIF_CACHED;
  255. }
  256. SysFreeString(bstrURL);
  257. }
  258. else
  259. {
  260. hr = E_OUTOFMEMORY;
  261. }
  262. }
  263. else
  264. {
  265. //
  266. // If m_pIXMLElement is NULL either its a low memory situation, or
  267. // the corresponding cdf is not in the cache.
  268. //
  269. *pdwFlags &= ~QIF_CACHED;
  270. }
  271. return hr;
  272. }