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.

480 lines
13 KiB

  1. // DVBSTuningSpaces.cpp : Implementation of CDVBSTuningSpaces
  2. #include "stdafx.h"
  3. #include "NPPropPage.h"
  4. #include "DVBSTuningSpaces.h"
  5. #include <comdef.h>
  6. /////////////////////////////////////////////////////////////////////////////
  7. // CDVBSTuningSpaces
  8. HRESULT
  9. CDVBSTuningSpaces::FillControlsFromTuningSpace (
  10. IDVBSTuningSpace* pTuningSpace
  11. )
  12. {
  13. HRESULT hr = S_OK;
  14. USES_CONVERSION;
  15. CComBSTR genericName;
  16. hr = pTuningSpace->get_UniqueName (&genericName);
  17. if (FAILED (hr))
  18. {
  19. MESSAGEBOX (this, IDS_CANNOT_GET_UNIQUENAME);
  20. return E_FAIL;
  21. }
  22. SetDlgItemText (IDC_EDIT_UNIQUE_NAME , W2T (genericName));
  23. CComBSTR FriendlyName;
  24. hr = pTuningSpace->get_FriendlyName (&FriendlyName);
  25. if (FAILED (hr))
  26. {
  27. MESSAGEBOX (this, IDS_CANNOT_GET_FRIENDLYNAME);
  28. return E_FAIL;
  29. }
  30. SetDlgItemText (IDC_EDIT_FRIENDLY_NAME, W2T (FriendlyName));
  31. CComBSTR FrequencyMapping;
  32. hr = pTuningSpace->get_FrequencyMapping (&FrequencyMapping);
  33. if (FAILED (hr))
  34. {
  35. MESSAGEBOX (this, IDS_CANNOT_GET_FREQUENCYMAPPING);
  36. return E_FAIL;
  37. }
  38. SetDlgItemText (IDC_EDIT_FREQUENCY_MAPPING, W2T (FrequencyMapping));
  39. LONG lGeneric;
  40. hr = pTuningSpace->get_NetworkID (&lGeneric);
  41. if (FAILED (hr))
  42. {
  43. MESSAGEBOX (this, IDS_CANNOT_GET_NETWORKID);
  44. return E_FAIL;
  45. }
  46. SetDlgItemInt (IDC_EDIT_NETWORKID, lGeneric);
  47. hr = pTuningSpace->get_HighOscillator (&lGeneric);
  48. if (FAILED (hr))
  49. {
  50. MESSAGEBOX (this, IDS_CANNOT_GET_HIGHOSCILATOR);
  51. return E_FAIL;
  52. }
  53. SetDlgItemInt (IDC_EDIT_HIGH_OSCILLATOR, lGeneric);
  54. hr = pTuningSpace->get_LNBSwitch (&lGeneric);
  55. if (FAILED (hr))
  56. {
  57. MESSAGEBOX (this, IDS_CANNOT_GET_LNBSWITCH);
  58. return E_FAIL;
  59. }
  60. SetDlgItemInt (IDC_EDIT_LNBSwitch, lGeneric);
  61. CComBSTR inputRange;
  62. hr = pTuningSpace->get_InputRange (&inputRange);
  63. if (FAILED (hr))
  64. {
  65. MESSAGEBOX (this, IDS_CANNOT_GET_INPUTRANGE);
  66. return E_FAIL;
  67. }
  68. SetDlgItemText (IDC_EDIT_INPUT_RANGE, W2T(inputRange));
  69. hr = pTuningSpace->get_LowOscillator (&lGeneric);
  70. if (FAILED (hr))
  71. {
  72. MESSAGEBOX (this, IDS_CANNOT_GET_LOWOSCILLATOR);
  73. return E_FAIL;
  74. }
  75. SetDlgItemInt (IDC_EDIT_LOW_OSCILATOR, lGeneric);
  76. SpectralInversion spectralInv;
  77. hr = pTuningSpace->get_SpectralInversion (&spectralInv);
  78. if (FAILED (hr))
  79. {
  80. MESSAGEBOX (this, IDS_CANNOT_GET_SPECTRALINVERSION);
  81. return E_FAIL;
  82. }
  83. SelectComboBoxFromString (IDC_COMBO_SPECTRAL_INVERSION, m_misc.ConvertSpectralInversionToString (spectralInv));
  84. CComQIPtr <ILocator> pLocator;
  85. CComQIPtr <IDVBSLocator> pDVBSLocator;
  86. hr = pTuningSpace->get_DefaultLocator (&pLocator);
  87. if (FAILED (hr) || !pLocator)
  88. {
  89. MESSAGEBOX (this, IDS_CANNOT_GET_ILOCATOR);
  90. return E_FAIL;
  91. }
  92. pDVBSLocator = pLocator;
  93. if (!pDVBSLocator)
  94. {
  95. MESSAGEBOX (this, IDS_CANNOT_GET_DVBSLOCATOR);
  96. return E_FAIL;
  97. }
  98. FillControlFromLocator (pDVBSLocator);
  99. return hr;
  100. }
  101. HRESULT
  102. CDVBSTuningSpaces::FillControlFromLocator (IDVBSLocator* pLocator)
  103. {
  104. //fill the combos
  105. FECMethod method;
  106. HRESULT hr = pLocator->get_InnerFEC (&method);
  107. if (SUCCEEDED (hr))
  108. SelectComboBoxFromString (IDC_COMBO_INNER_FEC, m_misc.ConvertFECMethodToString (method));
  109. hr = pLocator->get_InnerFEC (&method);
  110. BinaryConvolutionCodeRate binaryConv;
  111. hr = pLocator->get_InnerFECRate (&binaryConv);
  112. if (SUCCEEDED (hr))
  113. SelectComboBoxFromString (IDC_COMBO_FEC_RATE, m_misc.ConvertInnerFECRateToString (binaryConv));
  114. ModulationType modulation;
  115. hr = pLocator->get_Modulation (&modulation);
  116. if (SUCCEEDED (hr))
  117. SelectComboBoxFromString (IDC_COMBO_MODULATION, m_misc.ConvertModulationToString(modulation));
  118. hr = pLocator->get_OuterFEC (&method);
  119. if (SUCCEEDED (hr))
  120. SelectComboBoxFromString (IDC_COMBO_OUTER_FEC, m_misc.ConvertFECMethodToString (method));
  121. hr = pLocator->get_OuterFECRate (&binaryConv);
  122. if (SUCCEEDED (hr))
  123. SelectComboBoxFromString (IDC_COMBO_OUTER_FEC_RATE, m_misc.ConvertInnerFECRateToString (binaryConv));
  124. Polarisation polarisation;
  125. hr = pLocator->get_SignalPolarisation (&polarisation);
  126. if (SUCCEEDED (hr))
  127. SelectComboBoxFromString (IDC_COMBO_OUTER_SIGNAL_POLARISATION, m_misc.ConvertPolarisationToString(polarisation));
  128. //fill the edit boxes
  129. LONG lGeneric;
  130. hr = pLocator->get_CarrierFrequency (&lGeneric);
  131. if (SUCCEEDED (hr))
  132. SetDlgItemInt (IDC_EDIT_CARRIER_FREQUENCY, lGeneric);
  133. hr = pLocator->get_SymbolRate (&lGeneric);
  134. if (SUCCEEDED (hr))
  135. SetDlgItemInt (IDC_EDIT_SYMBOL_RATE, lGeneric);
  136. hr = pLocator->get_Azimuth (&lGeneric);
  137. if (SUCCEEDED (hr))
  138. SetDlgItemInt (IDC_EDIT_AZIMUTH, lGeneric);
  139. hr = pLocator->get_Elevation (&lGeneric);
  140. if (SUCCEEDED (hr))
  141. SetDlgItemInt (IDC_EDIT_ELEVATION, lGeneric);
  142. hr = pLocator->get_OrbitalPosition (&lGeneric);
  143. if (SUCCEEDED (hr))
  144. SetDlgItemInt (IDC_EDIT_ORBITAL_POSITION, lGeneric);
  145. //and finally the west position
  146. _variant_t var;
  147. var.vt = VT_BOOL;
  148. hr = pLocator->get_WestPosition (&var.boolVal);
  149. if (var.vt == VT_BOOL)
  150. {
  151. //weird - seems that -1 == TRUE
  152. CheckDlgButton (IDC_CHECK_WEST_POSITION, (var.boolVal == -1)?BST_CHECKED:BST_UNCHECKED);
  153. }
  154. return hr;
  155. }
  156. int
  157. CDVBSTuningSpaces::AddItemToListBox (
  158. CComBSTR strItem,
  159. IDVBSTuningSpace* const dwData
  160. )
  161. {
  162. USES_CONVERSION;
  163. HWND hwndListBox = GetDlgItem (IDC_LIST_TUNING_SPACES);
  164. int nIndex = ::SendMessage(
  165. hwndListBox,
  166. LB_ADDSTRING,
  167. 0,
  168. reinterpret_cast <LPARAM> (W2T(strItem))
  169. );
  170. ::SendMessage(
  171. hwndListBox,
  172. LB_SETITEMDATA,
  173. nIndex,
  174. reinterpret_cast <LPARAM> (dwData)
  175. );
  176. //if we succeesfully inserted in the list
  177. if (nIndex != LB_ERR)
  178. {
  179. m_tunigSpaceList.push_back (dwData);
  180. }
  181. else
  182. {
  183. //seems that smtg went wrong
  184. ASSERT (FALSE);
  185. dwData->Release ();
  186. }
  187. return nIndex;
  188. }
  189. void
  190. CDVBSTuningSpaces::SelectComboBoxFromString (
  191. UINT nID,
  192. CComBSTR strToFind
  193. )
  194. {
  195. USES_CONVERSION;
  196. HWND hwndControl = GetDlgItem (nID);
  197. int nIndex = ::SendMessage (
  198. hwndControl,
  199. CB_FINDSTRING,
  200. -1,
  201. reinterpret_cast <LPARAM> (W2T(strToFind))
  202. );
  203. ::SendMessage (
  204. hwndControl,
  205. CB_SETCURSEL,
  206. nIndex,
  207. 0
  208. );
  209. }
  210. CComBSTR
  211. CDVBSTuningSpaces::GetComboText (
  212. UINT nID
  213. )
  214. {
  215. HWND hwndControl = GetDlgItem (nID);
  216. int nIndex = ::SendMessage (
  217. hwndControl,
  218. CB_GETCURSEL,
  219. 0,
  220. 0
  221. );
  222. TCHAR szText[MAX_PATH];
  223. ::SendMessage (
  224. hwndControl,
  225. CB_GETLBTEXT,
  226. nIndex,
  227. reinterpret_cast <LPARAM> (szText)
  228. );
  229. return CComBSTR (szText);
  230. }
  231. HRESULT
  232. CDVBSTuningSpaces::FillLocatorFromControls (
  233. IDVBSLocator* pLocator
  234. )
  235. {
  236. USES_CONVERSION;
  237. //fill the combos
  238. CComBSTR genericString;
  239. genericString = GetComboText (IDC_COMBO_INNER_FEC);
  240. HRESULT hr = pLocator->put_InnerFEC (m_misc.ConvertStringToFECMethod (W2A(genericString.m_str)));
  241. if (FAILED (hr))
  242. {
  243. MESSAGEBOX (this, IDS_CANNOT_SET_INNERFEC);
  244. return E_FAIL;
  245. }
  246. genericString = GetComboText (IDC_COMBO_FEC_RATE);
  247. hr = pLocator->put_InnerFECRate (m_misc.ConvertStringToBinConvol (W2A(genericString.m_str)));
  248. if (FAILED (hr))
  249. {
  250. MESSAGEBOX (this, IDS_CANNOT_SET_INNERFECRATE);
  251. return E_FAIL;
  252. }
  253. genericString = GetComboText (IDC_COMBO_MODULATION);
  254. hr = pLocator->put_Modulation (m_misc.ConvertStringToModulation (W2A(genericString.m_str)));
  255. if (FAILED (hr))
  256. {
  257. MESSAGEBOX (this, IDS_CANNOT_SET_MODULATION);
  258. return E_FAIL;
  259. }
  260. genericString = GetComboText (IDC_COMBO_OUTER_FEC);
  261. hr = pLocator->put_OuterFEC (m_misc.ConvertStringToFECMethod (W2A(genericString.m_str)));
  262. if (FAILED (hr))
  263. {
  264. MESSAGEBOX (this, IDS_CANNOT_SET_OUTERFEC);
  265. return E_FAIL;
  266. }
  267. genericString = GetComboText (IDC_COMBO_OUTER_FEC_RATE);
  268. hr = pLocator->put_OuterFECRate (m_misc.ConvertStringToBinConvol (W2A(genericString.m_str)));
  269. if (FAILED (hr))
  270. {
  271. MESSAGEBOX (this, IDS_CANNOT_SET_OUTERFECRATE);
  272. return E_FAIL;
  273. }
  274. genericString = GetComboText (IDC_COMBO_OUTER_SIGNAL_POLARISATION);
  275. hr = pLocator->put_SignalPolarisation (m_misc.ConvertStringToPolarisation (W2A(genericString.m_str)));
  276. if (FAILED (hr))
  277. {
  278. MESSAGEBOX (this, IDS_CANNOT_SET_SIGNALPOLARISATION);
  279. return E_FAIL;
  280. }
  281. //edit boxes
  282. //cannot use C++ casts here
  283. BOOL bTrans;
  284. LONG lValue = (LONG)((int)(GetDlgItemInt (IDC_EDIT_CARRIER_FREQUENCY, &bTrans)));
  285. if (!bTrans)
  286. lValue = -1;
  287. hr = pLocator->put_CarrierFrequency (lValue);
  288. if (FAILED (hr))
  289. {
  290. MESSAGEBOX (this, IDS_CANNOT_SET_CARRIERFREQUENCY);
  291. return E_FAIL;
  292. }
  293. lValue = (LONG)((int)(GetDlgItemInt (IDC_EDIT_SYMBOL_RATE, &bTrans)));
  294. if (!bTrans)
  295. lValue = -1;
  296. hr = pLocator->put_SymbolRate (lValue);
  297. if (FAILED (hr))
  298. {
  299. MESSAGEBOX (this, IDS_CANNOT_SET_SYMBOLRATE);
  300. return E_FAIL;
  301. }
  302. lValue = (LONG)((int)(GetDlgItemInt (IDC_EDIT_AZIMUTH, &bTrans)));
  303. if (!bTrans)
  304. lValue = -1;
  305. hr = pLocator->put_Azimuth (lValue);
  306. if (FAILED (hr))
  307. {
  308. MESSAGEBOX (this, IDS_CANNOT_SET_AZIMUTH);
  309. return E_FAIL;
  310. }
  311. lValue = (LONG)((int)(GetDlgItemInt (IDC_EDIT_ELEVATION, &bTrans)));
  312. if (!bTrans)
  313. lValue = -1;
  314. hr = pLocator->put_Elevation (lValue);
  315. if (FAILED (hr))
  316. {
  317. MESSAGEBOX (this, IDS_CANNOT_SET_ELEVATION);
  318. return E_FAIL;
  319. }
  320. lValue = (LONG)((int)(GetDlgItemInt (IDC_EDIT_ORBITAL_POSITION, &bTrans)));
  321. if (!bTrans)
  322. lValue = -1;
  323. hr = pLocator->put_OrbitalPosition (lValue);
  324. if (FAILED (hr))
  325. {
  326. MESSAGEBOX (this, IDS_CANNOT_SET_ORBITALPOSITION);
  327. return E_FAIL;
  328. }
  329. int nCheckState = IsDlgButtonChecked (IDC_CHECK_WEST_POSITION);
  330. _variant_t var;
  331. var.vt = VT_BOOL;
  332. var.boolVal = (nCheckState == BST_CHECKED)?-1:0;
  333. hr = pLocator->put_WestPosition (var.boolVal);
  334. if (FAILED (hr))
  335. {
  336. MESSAGEBOX (this, IDS_CANNOT_SET_WESTPOSITION);
  337. return E_FAIL;
  338. }
  339. return hr;
  340. }
  341. HRESULT
  342. CDVBSTuningSpaces::FillTuningSpaceFromControls (
  343. IDVBSTuningSpace* pTuningSpace
  344. )
  345. {
  346. HRESULT hr = S_OK;
  347. USES_CONVERSION;
  348. CComBSTR genericName;
  349. GetDlgItemText (IDC_EDIT_UNIQUE_NAME , genericName.m_str);
  350. hr = pTuningSpace->put_UniqueName (genericName);
  351. if (FAILED (hr))
  352. {
  353. MESSAGEBOX (this, IDS_CANNOT_SET_UNIQUENAME);
  354. return E_FAIL;
  355. }
  356. GetDlgItemText (IDC_EDIT_FRIENDLY_NAME, genericName.m_str);
  357. hr = pTuningSpace->put_FriendlyName (genericName);
  358. if (FAILED (hr))
  359. {
  360. MESSAGEBOX (this, IDS_CANNOT_SET_FRIENDLYNAME);
  361. return E_FAIL;
  362. }
  363. GetDlgItemText (IDC_EDIT_FREQUENCY_MAPPING, genericName.m_str);
  364. if (genericName.Length () == 0)
  365. genericName = L"-1";
  366. hr = pTuningSpace->put_FrequencyMapping (genericName);
  367. if (FAILED (hr))
  368. {
  369. MESSAGEBOX (this, IDS_CANNOT_SET_FREQUENCYMAPPING);
  370. return E_FAIL;
  371. }
  372. LONG lGeneric;
  373. BOOL bTrans;
  374. lGeneric = GetDlgItemInt (IDC_EDIT_NETWORKID, &bTrans);
  375. if (!bTrans)
  376. lGeneric = -1;
  377. hr = pTuningSpace->put_NetworkID (lGeneric);
  378. if (FAILED (hr))
  379. {
  380. MESSAGEBOX (this, IDS_CANNOT_SET_NETWORKID);
  381. return E_FAIL;
  382. }
  383. lGeneric = GetDlgItemInt (IDC_EDIT_HIGH_OSCILLATOR, &bTrans);
  384. if (!bTrans)
  385. lGeneric = -1;
  386. hr = pTuningSpace->put_HighOscillator (lGeneric);
  387. if (FAILED (hr))
  388. {
  389. MESSAGEBOX (this, IDS_CANNOT_SET_HIGHOSCILATOR);
  390. return E_FAIL;
  391. }
  392. lGeneric = GetDlgItemInt (IDC_EDIT_LNBSwitch, &bTrans);
  393. if (!bTrans)
  394. lGeneric = -1;
  395. hr = pTuningSpace->put_LNBSwitch (lGeneric);
  396. if (FAILED (hr))
  397. {
  398. MESSAGEBOX (this, IDS_CANNOT_SET_LNBSWITCH);
  399. return E_FAIL;
  400. }
  401. GetDlgItemText (IDC_EDIT_INPUT_RANGE, genericName.m_str);
  402. if (genericName.Length () == 0)
  403. genericName = L"-1";
  404. hr = pTuningSpace->put_InputRange (genericName);
  405. if (FAILED (hr))
  406. {
  407. MESSAGEBOX (this, IDS_CANNOT_SET_INPUTRANGE);
  408. return E_FAIL;
  409. }
  410. lGeneric = GetDlgItemInt (IDC_EDIT_LOW_OSCILATOR, &bTrans);
  411. if (!bTrans)
  412. lGeneric = -1;
  413. hr = pTuningSpace->put_LowOscillator (lGeneric);
  414. if (FAILED (hr))
  415. {
  416. MESSAGEBOX (this, IDS_CANNOT_SET_LOWOSCILLATOR);
  417. return E_FAIL;
  418. }
  419. genericName = GetComboText (IDC_COMBO_SPECTRAL_INVERSION);
  420. hr = pTuningSpace->put_SpectralInversion (m_misc.ConvertStringToSpectralInversion (W2A(genericName)));
  421. if (FAILED (hr))
  422. {
  423. MESSAGEBOX (this, IDS_CANNOT_SET_SPECTRALINVERSION);
  424. return E_FAIL;
  425. }
  426. hr = pTuningSpace->put_NetworkType (m_bstrNetworkType);
  427. if (FAILED (hr))
  428. {
  429. MESSAGEBOX (this, IDS_CANNOT_SET_NETWORKTYPE);
  430. return E_FAIL;
  431. }
  432. return hr;
  433. }
  434. void
  435. CDVBSTuningSpaces::FillDefaultControls ()
  436. {
  437. //locator first
  438. SelectComboBoxFromString (IDC_COMBO_INNER_FEC, m_misc.ConvertFECMethodToString (BDA_FEC_METHOD_NOT_SET));
  439. SelectComboBoxFromString (IDC_COMBO_FEC_RATE, m_misc.ConvertInnerFECRateToString (BDA_BCC_RATE_NOT_SET));
  440. SelectComboBoxFromString (IDC_COMBO_MODULATION, m_misc.ConvertModulationToString(BDA_MOD_NOT_SET));
  441. SelectComboBoxFromString (IDC_COMBO_OUTER_FEC, m_misc.ConvertFECMethodToString (BDA_FEC_METHOD_NOT_SET));
  442. SelectComboBoxFromString (IDC_COMBO_OUTER_FEC_RATE, m_misc.ConvertInnerFECRateToString (BDA_BCC_RATE_NOT_SET));
  443. SelectComboBoxFromString (IDC_COMBO_OUTER_SIGNAL_POLARISATION, m_misc.ConvertPolarisationToString(BDA_POLARISATION_NOT_SET));
  444. //fill the edit boxes
  445. SetDlgItemInt (IDC_EDIT_CARRIER_FREQUENCY, -1);
  446. SetDlgItemInt (IDC_EDIT_SYMBOL_RATE, -1);
  447. SetDlgItemInt (IDC_EDIT_AZIMUTH, -1);
  448. SetDlgItemInt (IDC_EDIT_ELEVATION, -1);
  449. SetDlgItemInt (IDC_EDIT_ORBITAL_POSITION, -1);
  450. //fill the tuning space now...
  451. SetDlgItemInt (IDC_EDIT_NETWORKID, -1);
  452. SetDlgItemInt (IDC_EDIT_HIGH_OSCILLATOR, -1);
  453. SetDlgItemInt (IDC_EDIT_LNBSwitch, -1);
  454. SetDlgItemInt (IDC_EDIT_LOW_OSCILATOR, -1);
  455. SelectComboBoxFromString (IDC_COMBO_SPECTRAL_INVERSION, m_misc.ConvertSpectralInversionToString (BDA_SPECTRAL_INVERSION_NOT_SET));
  456. }