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.

808 lines
25 KiB

  1. // DVBSTuningSpaces.h : Declaration of the CDVBSTuningSpaces
  2. #ifndef __DVBSTUNINGSPACES_H_
  3. #define __DVBSTUNINGSPACES_H_
  4. #include "resource.h" // main symbols
  5. #include "misccell.h"
  6. #include <list>
  7. EXTERN_C const CLSID CLSID_DVBSTuningSpaces;
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CDVBSTuningSpaces
  10. class ATL_NO_VTABLE CDVBSTuningSpaces :
  11. public CComObjectRootEx<CComMultiThreadModel>,
  12. public CComCoClass<CDVBSTuningSpaces, &CLSID_DVBSTuningSpaces>,
  13. public IPropertyPageImpl<CDVBSTuningSpaces>,
  14. public CDialogImpl<CDVBSTuningSpaces>
  15. {
  16. public:
  17. CDVBSTuningSpaces()
  18. {
  19. m_dwTitleID = IDS_TITLEDVBSTuningSpaces;
  20. m_dwHelpFileID = IDS_HELPFILEDVBSTuningSpaces;
  21. m_dwDocStringID = IDS_DOCSTRINGDVBSTuningSpaces;
  22. m_bstrNetworkType = L"{FA4B375A-45B4-4d45-8440-263957B11623}";//DVBS Network Type
  23. }
  24. ~CDVBSTuningSpaces()
  25. {
  26. ReleaseTuningSpaces ();
  27. }
  28. enum {IDD = IDD_DVBSTUNINGSPACES};
  29. DECLARE_REGISTRY_RESOURCEID(IDR_DVBSTUNINGSPACES)
  30. DECLARE_PROTECT_FINAL_CONSTRUCT()
  31. BEGIN_COM_MAP(CDVBSTuningSpaces)
  32. COM_INTERFACE_ENTRY(IPropertyPage)
  33. END_COM_MAP()
  34. BEGIN_MSG_MAP(CDVBSTuningSpaces)
  35. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  36. CHAIN_MSG_MAP(IPropertyPageImpl<CDVBSTuningSpaces>)
  37. COMMAND_HANDLER(IDC_BUTTON_NEW_TUNING_SPACE, BN_CLICKED, OnClickedButton_new_tuning_space)
  38. COMMAND_HANDLER(IDC_BUTTON_SUBMIT_TUNING_SPACE, BN_CLICKED, OnClickedButton_submit_tuning_space)
  39. COMMAND_HANDLER(IDC_LIST_TUNING_SPACES, LBN_SELCHANGE, OnSelchangeList_tuning_spaces)
  40. COMMAND_HANDLER(IDC_CHECK_WEST_POSITION, BN_CLICKED, OnClickedCheck_west_position)
  41. COMMAND_HANDLER(IDC_COMBO_FEC_RATE, CBN_SELCHANGE, OnSelchangeCombo_fec_rate)
  42. COMMAND_HANDLER(IDC_COMBO_INNER_FEC, CBN_SELCHANGE, OnSelchangeCombo_inner_fec)
  43. COMMAND_HANDLER(IDC_COMBO_MODULATION, CBN_SELCHANGE, OnSelchangeCombo_modulation)
  44. COMMAND_HANDLER(IDC_COMBO_OUTER_FEC, CBN_SELCHANGE, OnSelchangeCombo_outer_fec)
  45. COMMAND_HANDLER(IDC_COMBO_OUTER_FEC_RATE, CBN_SELCHANGE, OnSelchangeCombo_outer_fec_rate)
  46. COMMAND_HANDLER(IDC_COMBO_OUTER_SIGNAL_POLARISATION, CBN_SELCHANGE, OnSelchangeCombo_outer_signal_polarisation)
  47. COMMAND_HANDLER(IDC_COMBO_SPECTRAL_INVERSION, CBN_SELCHANGE, OnSelchangeCombo_spectral_inversion)
  48. COMMAND_HANDLER(IDC_EDIT_AZIMUTH, EN_CHANGE, OnChangeEdit_azimuth)
  49. COMMAND_HANDLER(IDC_EDIT_CARRIER_FREQUENCY, EN_CHANGE, OnChangeEdit_carrier_frequency)
  50. COMMAND_HANDLER(IDC_EDIT_ELEVATION, EN_CHANGE, OnChangeEdit_elevation)
  51. COMMAND_HANDLER(IDC_EDIT_FREQUENCY_MAPPING, EN_CHANGE, OnChangeEdit_frequency_mapping)
  52. COMMAND_HANDLER(IDC_EDIT_FRIENDLY_NAME, EN_CHANGE, OnChangeEdit_friendly_name)
  53. COMMAND_HANDLER(IDC_EDIT_HIGH_OSCILLATOR, EN_CHANGE, OnChangeEdit_high_oscillator)
  54. COMMAND_HANDLER(IDC_EDIT_INPUT_RANGE, EN_CHANGE, OnChangeEdit_input_range)
  55. COMMAND_HANDLER(IDC_EDIT_LNBSwitch, EN_CHANGE, OnChangeEdit_lnbswitch)
  56. COMMAND_HANDLER(IDC_EDIT_LOW_OSCILATOR, EN_CHANGE, OnChangeEdit_low_oscilator)
  57. COMMAND_HANDLER(IDC_EDIT_NETWORKID, EN_CHANGE, OnChangeEdit_networkid)
  58. COMMAND_HANDLER(IDC_EDIT_ORBITAL_POSITION, EN_CHANGE, OnChangeEdit_orbital_position)
  59. COMMAND_HANDLER(IDC_EDIT_SYMBOL_RATE, EN_CHANGE, OnChangeEdit_symbol_rate)
  60. COMMAND_HANDLER(IDC_EDIT_UNIQUE_NAME, EN_CHANGE, OnChangeEdit_unique_name)
  61. MESSAGE_HANDLER(WM_VKEYTOITEM, OnListKeyItem)
  62. END_MSG_MAP()
  63. // Handler prototypes:
  64. // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  65. // LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  66. // LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  67. typedef IPropertyPageImpl<CDVBSTuningSpaces> PPGBaseClass;
  68. void
  69. ReleaseTuningSpaces ()
  70. {
  71. TUNING_SPACES::iterator it;
  72. for (it = m_tunigSpaceList.begin (); it != m_tunigSpaceList.end ();)
  73. {
  74. (*it)->Release ();
  75. m_tunigSpaceList.erase (it);
  76. it = m_tunigSpaceList.begin ();
  77. }
  78. }
  79. STDMETHOD(SetObjects)(ULONG nObjects, IUnknown** ppUnk)
  80. {
  81. // Use SetObjects to perform basic sanity checks on the objects whose properties will be set
  82. // This page can only handle a single object
  83. // and that object must support the IBDA_NetworkProvider interface.
  84. // We return E_INVALIDARG in any other situation
  85. HRESULT hr = E_INVALIDARG;
  86. if (nObjects == 1) // Single object
  87. {
  88. CComQIPtr<IBDA_NetworkProvider> pNP(ppUnk[0]); // Must support IBDA_NetworkProvider
  89. if (pNP)
  90. hr = PPGBaseClass::SetObjects(nObjects, ppUnk);
  91. }
  92. return hr;
  93. }
  94. STDMETHOD(Activate)(HWND hWndParent, LPCRECT prc, BOOL bModal)
  95. {
  96. // If we don't have any objects, this method should not be called
  97. // Note that OleCreatePropertyFrame will call Activate even if a call to SetObjects fails, so this check is required
  98. if (!m_ppUnk)
  99. return E_UNEXPECTED;
  100. // Use Activate to update the property page's UI with information
  101. // obtained from the objects in the m_ppUnk array
  102. // We update the page to display the Name and ReadOnly properties of the document
  103. // Call the base class
  104. HRESULT hr = S_OK;
  105. if (!this->m_hWnd)
  106. hr = PPGBaseClass::Activate(hWndParent, prc, bModal);
  107. //if already been through this skip it
  108. if (m_pTuner)
  109. return S_OK;
  110. if (!m_ppUnk[0])
  111. return E_UNEXPECTED;
  112. m_pTuner = m_ppUnk[0];
  113. if (!m_pTuner)
  114. return E_FAIL;
  115. //clear the tuning spaces both from the list and memory
  116. ReleaseTuningSpaces ();
  117. HWND hwndListBox = GetDlgItem (IDC_LIST_TUNING_SPACES);
  118. ::SendMessage (hwndListBox, LB_RESETCONTENT, NULL, NULL);
  119. //get the tunning spaces
  120. CComPtr <IEnumTuningSpaces> pTuneSpaces;
  121. hr = m_pTuner->EnumTuningSpaces (&pTuneSpaces);
  122. IDVBSTuningSpace* pDVBSTuningSpace = NULL;
  123. if (SUCCEEDED (hr) && (pTuneSpaces))
  124. {
  125. ITuningSpace* pTuneSpace = NULL;
  126. while (pTuneSpaces->Next (1, &pTuneSpace, 0) == S_OK)
  127. {
  128. hr = pTuneSpace->QueryInterface(__uuidof (IDVBSTuningSpace), reinterpret_cast <void**> (&pDVBSTuningSpace));
  129. if (FAILED (hr) || (!pDVBSTuningSpace))
  130. {
  131. ASSERT (FALSE);
  132. continue;
  133. }
  134. CComBSTR uniqueName;
  135. hr = pDVBSTuningSpace->get_UniqueName (&uniqueName.m_str);
  136. if (FAILED (hr))
  137. continue;
  138. //don't bother to release the DVBSTuningSpace pointers
  139. //they will be added to a list that will be released later
  140. AddItemToListBox (uniqueName, pDVBSTuningSpace);//we will identify the items from the name
  141. }
  142. }
  143. if (pDVBSTuningSpace)
  144. {
  145. //if there is any existing tuning space available,
  146. //select the last one
  147. //select the last tuning space
  148. int nCount = ::SendMessage (hwndListBox, LB_GETCOUNT , NULL, NULL);
  149. ::SendMessage (hwndListBox, LB_SETCURSEL, nCount-1, NULL);
  150. //fill with the last tuning space we got
  151. FillControlsFromTuningSpace (pDVBSTuningSpace);
  152. }
  153. else
  154. {
  155. //fill with default values
  156. FillDefaultControls ();
  157. }
  158. SetModifiedFlag (false);
  159. return S_OK;
  160. }
  161. STDMETHOD(Apply)(void)
  162. {
  163. //ATLTRACE(_T("CNP_CommonPage::Apply\n"));
  164. for (UINT i = 0; i < m_nObjects; i++)
  165. {
  166. // Do something interesting here
  167. }
  168. m_bDirty = FALSE;
  169. return S_OK;
  170. }
  171. LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  172. {
  173. USES_CONVERSION;
  174. //set the spins
  175. HWND hwndSpin = GetDlgItem (IDC_SPIN_NETWORKID);
  176. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  177. hwndSpin = GetDlgItem (IDC_SPIN_MINMINOR_CHANNEL);
  178. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  179. hwndSpin = GetDlgItem (IDC_SPIN_HIGH_OSCILLATOR);
  180. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  181. hwndSpin = GetDlgItem (IDC_SPIN_LNBSwitch);
  182. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  183. hwndSpin = GetDlgItem (IDC_SPIN_LOW_OSCILATOR);
  184. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  185. hwndSpin = GetDlgItem (IDC_SPIN_CARRIER);
  186. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  187. hwndSpin = GetDlgItem (IDC_SPIN_SYMBOL_RATE);
  188. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  189. hwndSpin = GetDlgItem (IDC_SPIN_TSID);
  190. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  191. hwndSpin = GetDlgItem (IDC_SPIN_AZIMUTH);
  192. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  193. hwndSpin = GetDlgItem (IDC_SPIN_ELEVATION);
  194. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  195. hwndSpin = GetDlgItem (IDC_SPIN_ORBITAL_POSITION);
  196. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  197. //fill the combos
  198. HWND hwndCombo = GetDlgItem (IDC_COMBO_INNER_FEC);
  199. int nIndex = 0;
  200. MAP_FECMethod::iterator it;
  201. for (it = m_misc.m_FECMethodMap.begin ();it != m_misc.m_FECMethodMap.end ();it++)
  202. {
  203. nIndex = ::SendMessage (
  204. hwndCombo,
  205. CB_INSERTSTRING,
  206. nIndex,
  207. reinterpret_cast <LPARAM> (A2T(const_cast <char*>((*it).first.c_str())))
  208. );
  209. //set the associated data
  210. ::SendMessage (
  211. hwndCombo,
  212. CB_SETITEMDATA,
  213. nIndex,
  214. (*it).second
  215. );
  216. ++nIndex;
  217. }
  218. hwndCombo = GetDlgItem (IDC_COMBO_FEC_RATE);
  219. nIndex = 0;
  220. MAP_BinaryConvolutionCodeRate::iterator it2;
  221. for (it2 = m_misc.m_BinaryConvolutionCodeRateMap.begin ();it2 != m_misc.m_BinaryConvolutionCodeRateMap.end ();it2++)
  222. {
  223. nIndex = ::SendMessage (
  224. hwndCombo,
  225. CB_INSERTSTRING,
  226. nIndex,
  227. reinterpret_cast <LPARAM> (A2T(const_cast <char*>((*it2).first.c_str())))
  228. );
  229. //set the associated data
  230. ::SendMessage (
  231. hwndCombo,
  232. CB_SETITEMDATA,
  233. nIndex,
  234. (*it2).second
  235. );
  236. ++nIndex;
  237. }
  238. hwndCombo = GetDlgItem (IDC_COMBO_MODULATION);
  239. nIndex = 0;
  240. MAP_ModulationType::iterator it3;
  241. for (it3 = m_misc.m_ModulationTypeMap.begin ();it3 != m_misc.m_ModulationTypeMap.end ();it3++)
  242. {
  243. nIndex = ::SendMessage (
  244. hwndCombo,
  245. CB_INSERTSTRING,
  246. nIndex,
  247. reinterpret_cast <LPARAM> (A2T(const_cast <char*>((*it3).first.c_str())))
  248. );
  249. //set the associated data
  250. ::SendMessage (
  251. hwndCombo,
  252. CB_SETITEMDATA,
  253. nIndex,
  254. (*it3).second
  255. );
  256. ++nIndex;
  257. }
  258. hwndCombo = GetDlgItem (IDC_COMBO_OUTER_FEC);
  259. nIndex = 0;
  260. MAP_FECMethod::iterator it4;
  261. for (it4 = m_misc.m_FECMethodMap.begin ();it4 != m_misc.m_FECMethodMap.end ();it4++)
  262. {
  263. nIndex = ::SendMessage (
  264. hwndCombo,
  265. CB_INSERTSTRING,
  266. nIndex,
  267. reinterpret_cast <LPARAM> (A2T(const_cast <char*>((*it4).first.c_str())))
  268. );
  269. //set the associated data
  270. ::SendMessage (
  271. hwndCombo,
  272. CB_SETITEMDATA,
  273. nIndex,
  274. (*it4).second
  275. );
  276. ++nIndex;
  277. }
  278. hwndCombo = GetDlgItem (IDC_COMBO_OUTER_FEC_RATE);
  279. nIndex = 0;
  280. MAP_BinaryConvolutionCodeRate::iterator it5;
  281. for (it5 = m_misc.m_BinaryConvolutionCodeRateMap.begin ();it5 != m_misc.m_BinaryConvolutionCodeRateMap.end ();it5++)
  282. {
  283. nIndex = ::SendMessage (
  284. hwndCombo,
  285. CB_INSERTSTRING,
  286. nIndex,
  287. reinterpret_cast <LPARAM> (A2T(const_cast <char*>((*it5).first.c_str())))
  288. );
  289. //set the associated data
  290. ::SendMessage (
  291. hwndCombo,
  292. CB_SETITEMDATA,
  293. nIndex,
  294. (*it5).second
  295. );
  296. ++nIndex;
  297. }
  298. hwndCombo = GetDlgItem (IDC_COMBO_OUTER_SIGNAL_POLARISATION);
  299. nIndex = 0;
  300. MAP_Polarisation::iterator it6;
  301. for (it6 = m_misc.m_PolarisationMap.begin ();it6 != m_misc.m_PolarisationMap.end ();it6++)
  302. {
  303. nIndex = ::SendMessage (
  304. hwndCombo,
  305. CB_INSERTSTRING,
  306. nIndex,
  307. reinterpret_cast <LPARAM> (A2T(const_cast <char*>((*it6).first.c_str())))
  308. );
  309. //set the associated data
  310. ::SendMessage (
  311. hwndCombo,
  312. CB_SETITEMDATA,
  313. nIndex,
  314. (*it6).second
  315. );
  316. ++nIndex;
  317. }
  318. hwndCombo = GetDlgItem (IDC_COMBO_SPECTRAL_INVERSION);
  319. nIndex = 0;
  320. MAP_SpectralInversion::iterator it7;
  321. for (it7 = m_misc.m_SpectralInversionMap.begin ();it7 != m_misc.m_SpectralInversionMap.end ();it7++)
  322. {
  323. nIndex = ::SendMessage (
  324. hwndCombo,
  325. CB_INSERTSTRING,
  326. nIndex,
  327. reinterpret_cast <LPARAM> (A2T(const_cast <char*>((*it7).first.c_str())))
  328. );
  329. //set the associated data
  330. ::SendMessage (
  331. hwndCombo,
  332. CB_SETITEMDATA,
  333. nIndex,
  334. (*it7).second
  335. );
  336. ++nIndex;
  337. }
  338. SetModifiedFlag (false);
  339. return 0;
  340. }
  341. STDMETHOD(Deactivate)( )
  342. {
  343. //overwrite the default behavior that was destroying the window
  344. //all the time
  345. return S_OK;
  346. }
  347. private:
  348. CComQIPtr <IScanningTuner> m_pTuner;
  349. CComQIPtr <IMediaEventEx> m_pEventInterface;
  350. CBDAMiscellaneous m_misc;
  351. bool m_fFirstTime;
  352. typedef std::list <IDVBSTuningSpace*> TUNING_SPACES;
  353. TUNING_SPACES m_tunigSpaceList;//mantaing a list of available tuning spaces
  354. //so we can access them easier
  355. CComBSTR m_bstrNetworkType;
  356. static UINT m_NotifyMessage;
  357. void
  358. FillDefaultControls ();
  359. int
  360. AddItemToListBox (
  361. CComBSTR strItem,
  362. IDVBSTuningSpace* const dwData
  363. );
  364. void
  365. SelectComboBoxFromString (
  366. UINT nID,
  367. CComBSTR strToFind
  368. );
  369. CComBSTR
  370. GetComboText (
  371. UINT nID
  372. );
  373. HRESULT
  374. FillControlsFromTuningSpace (IDVBSTuningSpace* pTuningSpace);
  375. HRESULT
  376. FillControlFromLocator (IDVBSLocator* pLocator);
  377. HRESULT
  378. FillLocatorFromControls (IDVBSLocator* pLocator);
  379. HRESULT
  380. FillTuningSpaceFromControls (IDVBSTuningSpace* pTuningSpace);
  381. void
  382. SetModifiedFlag (bool fValue)
  383. {
  384. //this will also set the m_bDirty flag
  385. SetDirty (fValue);
  386. HWND hwndSubmit = GetDlgItem (IDC_BUTTON_SUBMIT_TUNING_SPACE);
  387. ::EnableWindow (hwndSubmit, fValue);
  388. }
  389. LRESULT OnClickedButton_new_tuning_space(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  390. {
  391. //let's clear all fields
  392. HWND hwndListBox = GetDlgItem (IDC_LIST_TUNING_SPACES);
  393. int nSelIndex = ::SendMessage (hwndListBox, LB_GETCURSEL , NULL, NULL);
  394. if (nSelIndex >= 0)
  395. {//we already have a selection, so try a clone
  396. SetDlgItemText (IDC_EDIT_UNIQUE_NAME, _T(""));
  397. }
  398. else
  399. {
  400. FillDefaultControls ();
  401. }
  402. //clear the current selection so the user will not be confused
  403. int nVal = ::SendMessage (hwndListBox, LB_SETCURSEL , -1, NULL);
  404. SetModifiedFlag (true);
  405. return 0;
  406. }
  407. LRESULT OnClickedButton_submit_tuning_space(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  408. {
  409. HRESULT hr = S_OK;
  410. bool bIsNew = false;
  411. CComPtr <IDVBSTuningSpace> pTuningSpace;
  412. CComQIPtr <IDVBSLocator> pDVBSLocator;
  413. //try to get a tuning space, either from the list, either creating a new one
  414. HWND hwndListBox = GetDlgItem (IDC_LIST_TUNING_SPACES);
  415. int nTunIndex = ::SendMessage (hwndListBox, LB_GETCURSEL, NULL, NULL);
  416. if (nTunIndex == LB_ERR)
  417. bIsNew = true;
  418. //just create a tuning space so we can check if it's unique or not
  419. hr = CoCreateInstance (
  420. CLSID_DVBSTuningSpace,
  421. NULL,
  422. CLSCTX_INPROC_SERVER,
  423. __uuidof (IDVBSTuningSpace),
  424. reinterpret_cast <PVOID*> (&pTuningSpace)
  425. );
  426. if (FAILED (hr) || (!pTuningSpace))
  427. {
  428. MESSAGEBOX (this, IDS_CANNOT_INSTANTIATE_DVBSTUNE);
  429. return 0;
  430. }
  431. hr = CoCreateInstance (
  432. CLSID_DVBSLocator,
  433. NULL,
  434. CLSCTX_INPROC_SERVER,
  435. __uuidof (IDVBSLocator),
  436. reinterpret_cast <PVOID*> (&pDVBSLocator)
  437. );
  438. if (!pDVBSLocator)
  439. {
  440. MESSAGEBOX (this, IDS_CANNOT_GET_IDVBSLOCATOR);
  441. return 0;
  442. }
  443. if (FAILED (FillLocatorFromControls (pDVBSLocator)))
  444. return 0;
  445. pTuningSpace->put_DefaultLocator (pDVBSLocator);
  446. //fill the tuningSpace
  447. hr = FillTuningSpaceFromControls (pTuningSpace);
  448. if (FAILED (hr))
  449. return 0;
  450. hr = pTuningSpace->put_SystemType (DVB_Satellite);
  451. //create the tuning space container so we can find the tuning space
  452. CComPtr <ITuningSpaceContainer> pTuningSpaceContainer;
  453. hr = CoCreateInstance (
  454. CLSID_SystemTuningSpaces,
  455. NULL,
  456. CLSCTX_INPROC_SERVER,
  457. __uuidof (ITuningSpaceContainer),
  458. reinterpret_cast <PVOID*> (&pTuningSpaceContainer)
  459. );
  460. if (FAILED (hr) || (!pTuningSpaceContainer))
  461. {
  462. MESSAGEBOX (this, IDS_CANNOT_INSTANTIATE_TUNECONTAINER);
  463. return 0;
  464. }
  465. LONG lID;
  466. hr = pTuningSpaceContainer->FindID (pTuningSpace, &lID);
  467. if (FAILED (hr))
  468. {
  469. //looks like a new item
  470. int nIndex = 0;
  471. CComVariant varIndex (nIndex);
  472. hr = pTuningSpaceContainer->Add (pTuningSpace, &varIndex);
  473. if (SUCCEEDED (hr))
  474. {
  475. CComBSTR genericName;
  476. hr = pTuningSpace->get_UniqueName (&genericName.m_str);
  477. if (SUCCEEDED (hr))
  478. {
  479. int nTunIndex = AddItemToListBox (genericName, pTuningSpace);
  480. HWND hwndListBox = GetDlgItem (IDC_LIST_TUNING_SPACES);
  481. ::SendMessage (hwndListBox, LB_SETCURSEL, nTunIndex, NULL);
  482. (*pTuningSpace).AddRef ();//need to addref since is a smart pointer
  483. }
  484. }
  485. }
  486. else
  487. {
  488. if (bIsNew)
  489. {
  490. MESSAGEBOX (this, IDS_ENTER_UNIQUE_NAME);
  491. return 0;
  492. }
  493. else
  494. {
  495. //looks like we can sumbmit this EXISTING item
  496. //release the old tuning space
  497. pTuningSpace.Release ();
  498. pTuningSpace = NULL;
  499. pTuningSpace = reinterpret_cast <IDVBSTuningSpace*> (
  500. ::SendMessage (hwndListBox, LB_GETITEMDATA, nTunIndex, NULL));
  501. ASSERT (pTuningSpace);
  502. if (!pTuningSpace)
  503. return NULL;
  504. CComPtr <ILocator> pLocator;
  505. pTuningSpace->get_DefaultLocator (&pLocator);
  506. pDVBSLocator = pLocator;
  507. if (!pDVBSLocator)
  508. {
  509. ASSERT (FALSE);
  510. return NULL;
  511. }
  512. CComBSTR uniqueName;
  513. hr = pTuningSpace->get_UniqueName (&uniqueName.m_str);
  514. if (FAILED(hr))
  515. {
  516. MESSAGEBOX (this, IDS_CANNOT_RETRIEVE_UNIQUENAME);
  517. return 0;
  518. }
  519. if (FAILED (FillLocatorFromControls (pDVBSLocator)))
  520. return 0;
  521. pTuningSpace->put_DefaultLocator (pDVBSLocator);
  522. //fill the tuningSpace
  523. hr = FillTuningSpaceFromControls (pTuningSpace);
  524. if (FAILED (hr))
  525. return 0;
  526. //replace with old name
  527. hr = pTuningSpace->put_UniqueName (uniqueName);
  528. if (FAILED(hr))
  529. {
  530. MESSAGEBOX (this, IDS_CANNOT_SET_UNIQUE);
  531. return 0;
  532. }
  533. CComVariant varIndex (lID);
  534. hr = pTuningSpaceContainer->put_Item (varIndex, pTuningSpace);
  535. if (FAILED (hr))
  536. {
  537. MESSAGEBOX (this, IDS_CANNOT_SUBMIT_TUNE);
  538. return 0;
  539. }
  540. }
  541. }
  542. //disable the submit button
  543. ::EnableWindow (GetDlgItem (IDC_BUTTON_SUBMIT_TUNING_SPACE), FALSE);
  544. RefreshAll ();
  545. return 0;
  546. }
  547. void RefreshAll ()
  548. {
  549. HWND hwndListBox = GetDlgItem (IDC_LIST_TUNING_SPACES);
  550. int nIndex = ::SendMessage (hwndListBox, LB_GETCURSEL, NULL, NULL);
  551. if (nIndex == LB_ERR)
  552. {
  553. ASSERT (FALSE);
  554. return;
  555. }
  556. LRESULT dwData = ::SendMessage (hwndListBox, LB_GETITEMDATA, nIndex, NULL);
  557. if (dwData == LB_ERR)
  558. {
  559. ASSERT (FALSE);
  560. return;
  561. }
  562. IDVBSTuningSpace* pTuningSpace = reinterpret_cast <IDVBSTuningSpace*> (dwData);
  563. ASSERT (pTuningSpace);
  564. FillControlsFromTuningSpace (pTuningSpace);
  565. }
  566. LRESULT OnSelchangeList_tuning_spaces(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  567. {
  568. RefreshAll ();
  569. //disable the submit button
  570. ::EnableWindow (GetDlgItem (IDC_BUTTON_SUBMIT_TUNING_SPACE), FALSE);
  571. return 0;
  572. }
  573. //standard 'dirty' messages
  574. LRESULT OnClickedCheck_west_position(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  575. {
  576. SetModifiedFlag (true);
  577. return 0;
  578. }
  579. LRESULT OnSelchangeCombo_fec_rate(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  580. {
  581. SetModifiedFlag (true);
  582. return 0;
  583. }
  584. LRESULT OnSelchangeCombo_inner_fec(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  585. {
  586. SetModifiedFlag (true);
  587. return 0;
  588. }
  589. LRESULT OnSelchangeCombo_modulation(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  590. {
  591. SetModifiedFlag (true);
  592. return 0;
  593. }
  594. LRESULT OnSelchangeCombo_outer_fec(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  595. {
  596. SetModifiedFlag (true);
  597. return 0;
  598. }
  599. LRESULT OnSelchangeCombo_outer_fec_rate(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  600. {
  601. SetModifiedFlag (true);
  602. return 0;
  603. }
  604. LRESULT OnSelchangeCombo_outer_signal_polarisation(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  605. {
  606. SetModifiedFlag (true);
  607. return 0;
  608. }
  609. LRESULT OnSelchangeCombo_spectral_inversion(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  610. {
  611. SetModifiedFlag (true);
  612. return 0;
  613. }
  614. LRESULT OnChangeEdit_azimuth(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  615. {
  616. SetModifiedFlag (true);
  617. return 0;
  618. }
  619. LRESULT OnChangeEdit_carrier_frequency(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  620. {
  621. SetModifiedFlag (true);
  622. return 0;
  623. }
  624. LRESULT OnChangeEdit_elevation(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  625. {
  626. SetModifiedFlag (true);
  627. return 0;
  628. }
  629. LRESULT OnChangeEdit_frequency_mapping(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  630. {
  631. SetModifiedFlag (true);
  632. return 0;
  633. }
  634. LRESULT OnChangeEdit_friendly_name(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  635. {
  636. SetModifiedFlag (true);
  637. return 0;
  638. }
  639. LRESULT OnChangeEdit_high_oscillator(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  640. {
  641. SetModifiedFlag (true);
  642. return 0;
  643. }
  644. LRESULT OnChangeEdit_input_range(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  645. {
  646. SetModifiedFlag (true);
  647. return 0;
  648. }
  649. LRESULT OnChangeEdit_lnbswitch(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  650. {
  651. SetModifiedFlag (true);
  652. return 0;
  653. }
  654. LRESULT OnChangeEdit_low_oscilator(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  655. {
  656. SetModifiedFlag (true);
  657. return 0;
  658. }
  659. LRESULT OnChangeEdit_networkid(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  660. {
  661. SetModifiedFlag (true);
  662. return 0;
  663. }
  664. LRESULT OnChangeEdit_orbital_position(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  665. {
  666. SetModifiedFlag (true);
  667. return 0;
  668. }
  669. LRESULT OnChangeEdit_symbol_rate(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  670. {
  671. SetModifiedFlag (true);
  672. return 0;
  673. }
  674. LRESULT OnChangeEdit_unique_name(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  675. {
  676. SetModifiedFlag (true);
  677. return 0;
  678. }
  679. LRESULT OnListKeyItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  680. {
  681. if (LOWORD(wParam) == VK_DELETE)
  682. {
  683. HWND hwndListBox = GetDlgItem (IDC_LIST_TUNING_SPACES);
  684. int nIndex = ::SendMessage (hwndListBox, LB_GETCURSEL, NULL, NULL);
  685. if (nIndex != LB_ERR)
  686. {
  687. DWORD_PTR dwData = ::SendMessage (hwndListBox, LB_GETITEMDATA, nIndex, NULL);
  688. IDVBSTuningSpace* pTunSpace = reinterpret_cast <IDVBSTuningSpace*> (dwData);
  689. TUNING_SPACES::iterator it;
  690. for (it = m_tunigSpaceList.begin (); it != m_tunigSpaceList.end ();it++)
  691. {
  692. if (pTunSpace == *it)
  693. {
  694. CComPtr <ITuningSpaceContainer> pTuningSpaceContainer;
  695. HRESULT hr = CoCreateInstance (
  696. CLSID_SystemTuningSpaces,
  697. NULL,
  698. CLSCTX_INPROC_SERVER,
  699. __uuidof (ITuningSpaceContainer),
  700. reinterpret_cast <PVOID*> (&pTuningSpaceContainer)
  701. );
  702. if (FAILED (hr) || (!pTuningSpaceContainer))
  703. {
  704. MESSAGEBOX (this, IDS_CANNOT_INSTANTIATE_TUNECONTAINER);
  705. return 0;
  706. }
  707. LONG lID;
  708. hr = pTuningSpaceContainer->FindID (pTunSpace, &lID);
  709. if (FAILED (hr))
  710. {
  711. MESSAGEBOX (this, IDS_CANNOT_FIND_TUNE_IN_CONTAINER);
  712. return 0;
  713. }
  714. CComVariant varIndex (lID);
  715. hr = pTuningSpaceContainer->Remove (varIndex);
  716. if (FAILED (hr))
  717. {
  718. MESSAGEBOX (this, IDS_CANNOT_REMOVE_TUNINGSPACE);
  719. return 0;
  720. }
  721. (*it)->Release ();
  722. m_tunigSpaceList.erase (it);
  723. ::SendMessage (hwndListBox, LB_DELETESTRING, nIndex, NULL);
  724. //looks like the list is empty//try to select the first item from the list
  725. if (::SendMessage (hwndListBox, LB_SETCURSEL, 0, NULL) == LB_ERR)
  726. {
  727. //looks like the list is empty
  728. FillDefaultControls ();
  729. //set the unique name to an empty string so the user will enter it's own
  730. SetDlgItemText (IDC_EDIT_UNIQUE_NAME, _T(""));
  731. }
  732. break;
  733. }
  734. }
  735. }
  736. }
  737. return 0;
  738. }
  739. };
  740. #endif //__DVBSTUNINGSPACES_H_