Leaked source code of windows server 2003
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.

418 lines
10 KiB

  1. // TreeWindow.cpp: implementation of the CTreeWindow class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "TreeWin.h"
  6. #include "NP_CommonPage.h"
  7. #include "misccell.h"
  8. //////////////////////////////////////////////////////////////////////
  9. // Construction/Destruction
  10. //////////////////////////////////////////////////////////////////////
  11. CTreeWin::CTreeWin(
  12. CNP_CommonPage* pParent
  13. )
  14. {
  15. m_pCommonPage = pParent;
  16. }
  17. CTreeWin::~CTreeWin()
  18. {
  19. CleanMapList ();
  20. }
  21. void
  22. CTreeWin::CleanMapList ()
  23. {
  24. //first make sure we free the existing list
  25. TREE_MAP::iterator treeIt = m_treeMap.begin ();
  26. while (treeIt != m_treeMap.end ())
  27. {
  28. if ((*treeIt).first)
  29. (*treeIt).first->Release ();
  30. if ((*treeIt).second)
  31. (*treeIt).second->Release ();
  32. m_treeMap.erase (treeIt);
  33. treeIt = m_treeMap.begin ();
  34. }
  35. }
  36. HRESULT
  37. CTreeWin::RefreshTree (
  38. IScanningTuner* pTuner
  39. )
  40. {
  41. HRESULT hr = S_OK;
  42. USES_CONVERSION;
  43. if (!m_hWnd)
  44. return NULL;
  45. //first make sure we free the existing list
  46. CleanMapList ();
  47. //delete all previous items
  48. TreeView_DeleteAllItems (m_hWnd);
  49. //insert the default TuningSpace
  50. ITuningSpace* pTunningSpace;
  51. CComPtr <ITuneRequest> pTuneRequest;
  52. hr = pTuner->get_TuneRequest (&pTuneRequest);
  53. if (pTuneRequest)
  54. {
  55. pTuneRequest->get_TuningSpace (&pTunningSpace);
  56. HTREEITEM hLocatorParent = InsertTuningSpace (
  57. pTunningSpace,
  58. _T ("Current TuneRequest")
  59. );
  60. TreeView_SelectItem (m_hWnd, hLocatorParent);
  61. if (hLocatorParent == NULL)
  62. {
  63. pTunningSpace->Release ();
  64. pTunningSpace = NULL;
  65. }
  66. //now let's fill with the ILocator info
  67. //add to the list
  68. ILocator* pLocator = NULL;
  69. hr = pTuneRequest->get_Locator (&pLocator);
  70. InsertLocator (hLocatorParent, pLocator);
  71. //add to the maplist
  72. m_treeMap.insert (TREE_MAP::value_type (pTunningSpace, pLocator));
  73. }
  74. //fill the tree with all TunningSpaces this NP knows about them
  75. CComPtr <IEnumTuningSpaces> pEnumTunningSpaces;
  76. hr = pTuner->EnumTuningSpaces (&pEnumTunningSpaces);
  77. if (FAILED (hr) || (!pEnumTunningSpaces))
  78. return hr;
  79. while (pEnumTunningSpaces->Next (1, &pTunningSpace, 0) == S_OK)
  80. {
  81. HTREEITEM hLocatorParent = InsertTuningSpace (pTunningSpace);
  82. if (hLocatorParent == NULL)
  83. {
  84. pTunningSpace->Release ();
  85. pTunningSpace = NULL;
  86. continue;
  87. }
  88. //now let's fill with the ILocator info
  89. //add to the list
  90. ILocator* pLocator = NULL;
  91. hr = pTunningSpace->get_DefaultLocator (&pLocator);
  92. if (FAILED (hr) || (!pLocator))
  93. {
  94. pTunningSpace->Release ();
  95. pTunningSpace = NULL;
  96. continue;
  97. }
  98. InsertLocator (hLocatorParent, pLocator);
  99. //add to the maplist
  100. m_treeMap.insert (TREE_MAP::value_type (pTunningSpace, pLocator));
  101. }
  102. return hr;
  103. }
  104. HTREEITEM
  105. CTreeWin::InsertTuningSpace (
  106. ITuningSpace* pTunSpace,
  107. TCHAR* szCaption
  108. )
  109. {
  110. HRESULT hr = S_OK;
  111. USES_CONVERSION;
  112. TCHAR szText[MAX_PATH];
  113. CComBSTR friendlyName;
  114. hr = pTunSpace->get_FriendlyName (&friendlyName);
  115. if (FAILED (hr))
  116. {
  117. m_pCommonPage->SendError (_T("Calling ITuningSpace::get_FriendlyName"), hr);
  118. return NULL;
  119. }
  120. bool bBold = false;
  121. //make sure we write the caption if there is one
  122. if (_tcslen (szCaption) > 0)
  123. {
  124. wsprintf (szText, _T("%s-%s"), szCaption, W2T (friendlyName));
  125. bBold = true;
  126. }
  127. else
  128. {
  129. _tcscpy (szText, W2T (friendlyName));
  130. }
  131. HTREEITEM hParentItem = InsertTreeItem (
  132. NULL,
  133. reinterpret_cast <DWORD_PTR> (pTunSpace),
  134. szText,
  135. bBold
  136. );
  137. //for all the outers add the TreeParams params
  138. //uniqueName
  139. CComBSTR uniqueName;
  140. hr = pTunSpace->get_UniqueName (&uniqueName);
  141. if (FAILED (hr))
  142. {
  143. m_pCommonPage->SendError (_T("Calling ITuningSpace::get_UniqueName"), hr);
  144. return NULL;
  145. }
  146. wsprintf (szText, _T("Unique Name - %s"), W2T(uniqueName));
  147. HTREEITEM hItem = InsertTreeItem (
  148. hParentItem,
  149. UniqueName,
  150. szText
  151. );
  152. //frequencyMapping
  153. CComBSTR frequencyMapping;
  154. hr = pTunSpace->get_FrequencyMapping (&frequencyMapping);
  155. if (FAILED (hr))
  156. {
  157. m_pCommonPage->SendError (_T("Calling ITuningSpace::get_FrequencyMapping"), hr);
  158. return NULL;
  159. }
  160. wsprintf (szText, _T("Frequency Mapping - %s"), W2T(frequencyMapping));
  161. hItem = InsertTreeItem (
  162. hParentItem,
  163. FrequencyMapping,
  164. szText
  165. );
  166. //TunCLSID
  167. CComBSTR TunCLSID;
  168. hr = pTunSpace->get_CLSID (&TunCLSID);
  169. if (FAILED (hr))
  170. {
  171. m_pCommonPage->SendError (_T("Calling ITuningSpace::get_CLSID"), hr);
  172. return NULL;
  173. }
  174. wsprintf (szText, _T("CLSID - %s"), W2T(TunCLSID));
  175. hItem = InsertTreeItem (
  176. hParentItem,
  177. TunSpace_CLSID,
  178. szText
  179. );
  180. //finally insert the locator parent
  181. ILocator* pLocator = NULL;
  182. hr = pTunSpace->get_DefaultLocator (&pLocator);
  183. if (FAILED (hr) || (!pLocator))
  184. {
  185. //first delete the tunning space item
  186. TreeView_DeleteItem (m_hWnd, hParentItem);
  187. m_pCommonPage->SendError (_T("Calling ITuningSpace::get_DefaultLocator"), hr);
  188. return NULL;
  189. }
  190. hItem = InsertTreeItem (
  191. hParentItem,
  192. reinterpret_cast <DWORD_PTR> (pLocator),
  193. _T("Locator")
  194. );
  195. return hItem;
  196. }
  197. //==================================================================
  198. // Will insert in the tree all information for the passed ILocator
  199. //
  200. //
  201. //==================================================================
  202. HTREEITEM
  203. CTreeWin::InsertLocator (
  204. HTREEITEM hParentItem,
  205. ILocator* pLocator
  206. )
  207. {
  208. USES_CONVERSION;
  209. HRESULT hr = S_OK;
  210. TCHAR szText[MAX_PATH];
  211. LONG lFrequency;
  212. hr = pLocator->get_CarrierFrequency (&lFrequency);
  213. if (FAILED (hr))
  214. {
  215. m_pCommonPage->SendError (_T("Calling ILocator::get_CarrierFrequency"), hr);
  216. return NULL;
  217. }
  218. wsprintf (szText, _T("Frequency - %ld"), lFrequency);
  219. HTREEITEM hItem = InsertTreeItem (
  220. hParentItem,
  221. CarrierFrequency,
  222. szText
  223. );
  224. FECMethod fecMethod;
  225. hr = pLocator->get_InnerFEC (&fecMethod);
  226. if (FAILED (hr))
  227. {
  228. m_pCommonPage->SendError (_T("Calling ILocator::get_InnerFEC"), hr);
  229. return NULL;
  230. }
  231. CComBSTR bstrTemp = m_misc.ConvertFECMethodToString (fecMethod);
  232. wsprintf (szText, _T("InnerFEC - %s"), W2T (bstrTemp));
  233. hItem = InsertTreeItem (
  234. hParentItem,
  235. InnerFEC,
  236. szText
  237. );
  238. BinaryConvolutionCodeRate binaryConvolutionCodeRate;
  239. hr = pLocator->get_InnerFECRate (&binaryConvolutionCodeRate);
  240. if (FAILED (hr))
  241. {
  242. m_pCommonPage->SendError (_T("Calling ILocator::get_InnerFECRate"), hr);
  243. return NULL;
  244. }
  245. bstrTemp = m_misc.ConvertInnerFECRateToString (binaryConvolutionCodeRate);
  246. wsprintf (szText, _T("InnerFECRate - %s"), W2T (bstrTemp));
  247. hItem = InsertTreeItem (
  248. hParentItem,
  249. InnerFECRate,
  250. szText
  251. );
  252. ModulationType modulationType;
  253. hr = pLocator->get_Modulation (&modulationType);
  254. if (FAILED (hr))
  255. {
  256. m_pCommonPage->SendError (_T("Calling ILocator::get_Modulation"), hr);
  257. return NULL;
  258. }
  259. bstrTemp = m_misc.ConvertModulationToString (modulationType);
  260. wsprintf (szText, _T("Modulation - %s"), W2T (bstrTemp));
  261. hItem = InsertTreeItem (
  262. hParentItem,
  263. Modulation,
  264. szText
  265. );
  266. hr = pLocator->get_OuterFEC (&fecMethod);
  267. if (FAILED (hr))
  268. {
  269. m_pCommonPage->SendError (_T("Calling ILocator::get_OuterFEC"), hr);
  270. return NULL;
  271. }
  272. bstrTemp = m_misc.ConvertFECMethodToString (fecMethod);
  273. wsprintf (szText, _T("OuterFEC - %s"), W2T (bstrTemp));
  274. hItem = InsertTreeItem (
  275. hParentItem,
  276. OuterFEC,
  277. szText
  278. );
  279. hr = pLocator->get_OuterFECRate (&binaryConvolutionCodeRate);
  280. if (FAILED (hr))
  281. {
  282. m_pCommonPage->SendError (_T("Calling ILocator::get_OuterFECRate"), hr);
  283. return NULL;
  284. }
  285. bstrTemp = m_misc.ConvertInnerFECRateToString (binaryConvolutionCodeRate);
  286. wsprintf (szText, _T("OuterFECRate - %s"), W2T (bstrTemp));
  287. hItem = InsertTreeItem (
  288. hParentItem,
  289. OuterFECRate,
  290. szText
  291. );
  292. LONG lRate;
  293. hr = pLocator->get_SymbolRate (&lRate);
  294. if (FAILED (hr))
  295. {
  296. m_pCommonPage->SendError (_T("Calling ILocator::get_SymbolRate"), hr);
  297. return NULL;
  298. }
  299. wsprintf (szText, _T("SymbolRate - %ld"), lRate);
  300. hItem = InsertTreeItem (
  301. hParentItem,
  302. SymbolRate,
  303. szText
  304. );
  305. return hItem;
  306. }
  307. //================================================
  308. // Helper method to the tree helper macro...
  309. // This will just insert an item in the tree
  310. //================================================
  311. HTREEITEM
  312. CTreeWin::InsertTreeItem (
  313. HTREEITEM hParentItem ,
  314. LONG lParam,
  315. TCHAR* pszText,
  316. bool bBold /*= false*/
  317. )
  318. {
  319. if (!m_hWnd)
  320. return NULL;
  321. HTREEITEM hItem = NULL;
  322. TVINSERTSTRUCT tviInsert;
  323. tviInsert.hParent = hParentItem;
  324. tviInsert.hInsertAfter = TVI_LAST;
  325. TVITEM tvItem;
  326. tvItem.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT;
  327. if (bBold)
  328. {
  329. tvItem.mask |= TVIF_STATE;
  330. tvItem.state = TVIS_BOLD | TVIS_EXPANDED;
  331. tvItem.stateMask = TVIS_BOLD;
  332. }
  333. tvItem.hItem = NULL;
  334. tvItem.lParam = lParam;
  335. tvItem.pszText = pszText;
  336. tvItem.cchTextMax = _tcslen (pszText);
  337. tviInsert.item = tvItem;
  338. hItem = TreeView_InsertItem (m_hWnd, &tviInsert);
  339. return hItem;
  340. }
  341. HRESULT
  342. CTreeWin::SubmitCurrentLocator ()
  343. {
  344. ASSERT (m_hWnd);
  345. HTREEITEM hItem = TreeView_GetSelection (m_hWnd);
  346. ASSERT (hItem);
  347. HRESULT hr = S_OK;
  348. //this state is merely impossible
  349. if (hItem == NULL)
  350. return E_FAIL;
  351. HTREEITEM hRoot = hItem;
  352. HTREEITEM hParent = hRoot;
  353. TVITEM tvItem;
  354. tvItem.mask = TVIF_PARAM;
  355. tvItem.lParam = NULL;
  356. //just get the parent
  357. while ( (hRoot = TreeView_GetParent (m_hWnd, hRoot)) != NULL)
  358. {
  359. //keep the last parent alive so we can query later
  360. hParent = hRoot;
  361. }
  362. tvItem.hItem = hParent;
  363. if (!TreeView_GetItem (m_hWnd, &tvItem))
  364. {
  365. ASSERT (FALSE);
  366. return E_FAIL;
  367. }
  368. //normally this cast should not be done between different apartments
  369. //It's ok with DShow apartment model
  370. ITuningSpace* pTuneSpace = reinterpret_cast <ITuningSpace*> (tvItem.lParam);
  371. ASSERT (pTuneSpace);
  372. //TREE_MAP::iterator it = m_treeMap.find (pTuneSpace);
  373. //ILocator* pLocator = (*it).second;
  374. if (FAILED (hr = m_pCommonPage->PutTuningSpace (pTuneSpace)))
  375. {
  376. m_pCommonPage->SendError (_T("Calling IScaningTuner::put_TuningSpace"), hr);
  377. return hr;
  378. }
  379. return S_OK;
  380. }