www.pudn.com > DVBPlayer.rar > DlgLnbSet.cpp, change:2004-07-14,size:11614b


// DlgLnbSet.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "app.h" 
#include "DlgLnbSet.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
 
#include "LnbSettingDlg.h" 
 
 
#include "dsm.h" 
 
#include "misc.h" 
 
 
 
void ExpandBranthTree( CTreeCtrl* p_tree, HTREEITEM hr ); 
UINT GetTreeBrotherNthNode(CTreeCtrl* p_tree, HTREEITEM hr ) ;  
 
UINT GetItemHiberarchy(CTreeCtrl* p_tree, HTREEITEM hr)  
{ 
	if ( hr ) 
	{ 
		return GetItemHiberarchy( p_tree, p_tree ->GetParentItem( hr ) ) + 1 ;  
	} 
	else 
		return 0 ;  
} 
 
UINT GetTreeBrotherNthNode ( CTreeCtrl* p_tree, HTREEITEM hr )  
{ 
	if ( hr ) 
	{ 
		HTREEITEM h_parent ;  
		if ( (h_parent = p_tree ->GetParentItem(hr)) ) 
		{ 
			int n = 0 ;  
			HTREEITEM hr_tmp ;  
			hr_tmp  = p_tree ->GetChildItem(h_parent) ;  
			while (hr_tmp)  
			{ 
				if ( hr_tmp == hr ) 
					break;  
				n ++ ;  
				hr_tmp = p_tree ->GetNextSiblingItem(hr_tmp) ;  
			} 
				 
			return n ;  
	 
		} 
	} 
		return 0  ; 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CDlgLnbSet dialog 
 
 
CDlgLnbSet::CDlgLnbSet(CWnd* pParent /*=NULL*/) 
	: CDialog(CDlgLnbSet::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CDlgLnbSet) 
	//}}AFX_DATA_INIT 
 
	CBitmap  bmp ;  
 
	img_list_tree .Create(16, 16, ILC_COLOR8, 0, 1); 
	 
 
	bmp .LoadBitmap(IDB_BITMAP_CARD) ;  
	img_list_tree .Add(&bmp, RGB( 0,0,0 )) ;  
	bmp .DeleteObject() ;  
 
	bmp .LoadBitmap(IDB_BITMAP_SWITCH) ;  
	img_list_tree .Add(&bmp, RGB( 0,0,0 )) ;  
	bmp .DeleteObject() ;  
	 
	bmp .LoadBitmap(IDB_BITMAP_SWITCH_NOSEL) ;  
	img_list_tree .Add(&bmp, RGB( 0,0,0 )) ;  
	bmp .DeleteObject() ;  
	 
	bmp .LoadBitmap(IDB_BITMAP_SWITCH_SEL) ;  
	img_list_tree .Add(&bmp, RGB( 0,0,0 )) ;  
	bmp .DeleteObject() ;  
	 
} 
 
CDlgLnbSet::~CDlgLnbSet( )  
{ 
	img_list_tree .DeleteImageList() ;  
} 
 
void CDlgLnbSet::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CDlgLnbSet) 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CDlgLnbSet, CDialog) 
	//{{AFX_MSG_MAP(CDlgLnbSet) 
	ON_BN_CLICKED(IDC_BTN_OK, OnBtnOk) 
	ON_BN_CLICKED(IDC_BTN_CANCEL, OnBtnCancel) 
	ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_SATSET, OnSelchangedTreeSatset) 
	ON_BN_CLICKED(IDC_BTN_ADDLNB, OnBtnAddlnb) 
	ON_BN_CLICKED(IDC_BTN_PROPERTY, OnBtnProperty) 
	ON_BN_CLICKED(IDC_BTN_DELETE, OnBtnDelete) 
	//}}AFX_MSG_MAP 
	ON_CONTROL_RANGE( BN_CLICKED, IDC_RADIO_SELECT_SWITCH, IDC_RADIO_SELECT_SWITCH+4, OnRadioSelectSwitch ) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CDlgLnbSet message handlers 
 
void CDlgLnbSet::OnBtnOk()  
{ 
	// TODO: Add your control notification handler code here 
	 
	UpdateData(TRUE) ;  
//	DaSetSwitchMode ( i_sel_type ) ;  
	CDialog::OnOK() ;  
} 
 
void CDlgLnbSet::OnBtnCancel()  
{ 
	// TODO: Add your control notification handler code here 
	CDialog ::OnCancel() ;  
} 
 
void CDlgLnbSet::OnRadioSelectSwitch( int nID )  
{ 
	// TODO: Add your control notification handler code here 
	UINT i = nID - IDC_RADIO_SELECT_SWITCH ;  
	ASSERT(i >= 0 && i < 5) ; 
	 
	if (i == i_sel_type) 
		return ;  
 
	i_sel_type = i ;  
 
 
	DaSetSwitchMode (i_sel_type) ;  
 
	UpdateTree ( i ) ;  
	 
} 
 
BOOL CDlgLnbSet::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
	 
	CButton* p_btn = (CButton*) GetDlgItem ( IDC_RADIO_SELECT_SWITCH ) ;  
//	p_btn ->SetCheck(1) ;  
 
	CTreeCtrl* p_tc = ( CTreeCtrl* ) GetDlgItem(IDC_TREE_SATSET) ;  
 
	p_tc ->SetImageList(&img_list_tree, TVSIL_NORMAL ) ;  
	 
	i_sel_type = DaGetSwitchMode ()  ;  
//	DaSetSwitchMode(i_sel_type) ;  
 
	UINT id = IDC_RADIO_SELECT_SWITCH + i_sel_type ; 
	((CButton* ) GetDlgItem(id) )  ->SetCheck(1) ;  
	UpdateTree(i_sel_type) ;  
	 
	 
 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CDlgLnbSet::UpdateTree(int n) 
{ 
 
 
	CTreeCtrl* p_tc = ( CTreeCtrl* ) GetDlgItem(IDC_TREE_SATSET) ;  
 
	p_tc ->DeleteAllItems() ;  
 
 
	HTREEITEM hr = p_tc ->InsertItem( "DVB Card", BMP_ID_CARD, BMP_ID_CARD ) ;  
 
	HTREEITEM hr_switch ;  
	HTREEITEM hr_sel ;  
	 
 
	switch(n) 
	{ 
	case SWITCH_NONE: 
		hr_sel = hr_switch = p_tc ->InsertItem( "", BMP_ID_SWITCH_NO_SEL, BMP_ID_SWITCH_NO_SEL, hr ) ;  
		UpdateNode(hr_sel) ;  
		break; 
 
	case SWITCH_DISQEC10: 
		hr_switch = p_tc ->InsertItem( "DisQec1.0", BMP_ID_SWITCH, BMP_ID_SWITCH, hr ) ;  
		hr_sel = p_tc ->InsertItem("not connected", BMP_ID_SWITCH_NO_SEL, BMP_ID_SWITCH_NO_SEL, hr_switch) ; 
		UpdateNode(hr_sel) ;  
		hr_sel = p_tc ->InsertItem("not connected", BMP_ID_SWITCH_NO_SEL, BMP_ID_SWITCH_NO_SEL, hr_switch) ;  
		UpdateNode(hr_sel) ;  
		hr_sel = p_tc ->InsertItem("not connected", BMP_ID_SWITCH_NO_SEL, BMP_ID_SWITCH_NO_SEL, hr_switch) ;  
		UpdateNode(hr_sel) ;  
		hr_sel = p_tc ->InsertItem("not connected", BMP_ID_SWITCH_NO_SEL, BMP_ID_SWITCH_NO_SEL, hr_switch) ;  
		UpdateNode(hr_sel) ;  
		break; 
 
	case SWITCH_DISQEC12: 
		hr_switch = p_tc ->InsertItem( "DisQec1.2", BMP_ID_SWITCH, BMP_ID_SWITCH, hr ) ;  
		hr_sel = p_tc ->InsertItem("not connected", BMP_ID_SWITCH_NO_SEL, BMP_ID_SWITCH_NO_SEL, hr_switch) ;  
		UpdateNode(hr_sel) ;  
		hr_sel = p_tc ->InsertItem("not connected", BMP_ID_SWITCH_NO_SEL, BMP_ID_SWITCH_NO_SEL, hr_switch) ;  
		UpdateNode(hr_sel) ;  
		hr_sel = p_tc ->InsertItem("not connected", BMP_ID_SWITCH_NO_SEL, BMP_ID_SWITCH_NO_SEL, hr_switch) ;  
		UpdateNode(hr_sel) ;  
		hr_sel = p_tc ->InsertItem("not connected", BMP_ID_SWITCH_NO_SEL, BMP_ID_SWITCH_NO_SEL, hr_switch) ;  
		UpdateNode(hr_sel) ;  
		break; 			 
 
	case SWITCH_22k: 
		hr_switch = p_tc ->InsertItem( "22k", BMP_ID_SWITCH, BMP_ID_SWITCH, hr ) ;  
		hr_sel = p_tc ->InsertItem("on", BMP_ID_SWITCH_NO_SEL, BMP_ID_SWITCH_NO_SEL, hr_switch) ;  
		UpdateNode(hr_sel) ;  
		hr_sel = p_tc ->InsertItem("off", BMP_ID_SWITCH_NO_SEL, BMP_ID_SWITCH_NO_SEL, hr_switch) ;  
		UpdateNode(hr_sel) ;  
		break;  
 
	case SWITCH_TONEBURST: 
		hr_switch = p_tc ->InsertItem( "ToneBurst", BMP_ID_SWITCH, BMP_ID_SWITCH, hr ) ;  
		hr_sel = p_tc ->InsertItem("on", BMP_ID_SWITCH_NO_SEL, BMP_ID_SWITCH_NO_SEL, hr_switch) ;  
		UpdateNode(hr_sel) ;  
		hr_sel = p_tc ->InsertItem("off", BMP_ID_SWITCH_NO_SEL, BMP_ID_SWITCH_NO_SEL, hr_switch) ;  
		UpdateNode(hr_sel) ;  
		break ; 				 
			 
	default: 
		ASSERT( FALSE) ;  
	} 
 
 
	ExpandBranthTree(p_tc, p_tc ->GetRootItem ()) ;  
 
	p_tc ->SelectItem(hr_sel) ;  
 
#if 1 
	UpdateButtons ( i_sel_type, GetItemHiberarchy( p_tc, hr_sel), GetTreeBrotherNthNode(p_tc, hr_sel) ) ;  
#else 
	GetDlgItem (IDC_BTN_ADDLNB) ->EnableWindow(TRUE)  ;  
	GetDlgItem (IDC_BTN_PROPERTY) ->EnableWindow( FALSE ) ;  
	GetDlgItem (IDC_BTN_DELETE) ->EnableWindow( FALSE ) ;  
				 
#endif 
} 
 
void ExpandBranthTree( CTreeCtrl* ptree, HTREEITEM hr ) 
{ 
	ptree ->Expand(hr, TVE_EXPAND ) ;  
	if ( !ptree ->ItemHasChildren(hr) ) return ;  
	HTREEITEM h = ptree ->GetChildItem( hr ) ;  
	while (h)  
	{ 
		ExpandBranthTree(ptree, h)	 ;  
		h = ptree ->GetNextSiblingItem( hr ) ;  
	}  
} 
 
void CDlgLnbSet::UpdateButtons(UINT u_sel_type, UINT u_Hiberarchy, UINT u_brother_nth ) 
{ 
	ASSERT(u_sel_type >= 0 && u_sel_type < 5) ;  
	BOOL b_sel_nod = FALSE ;  
 
	switch(u_sel_type)  
	{ 
	case SWITCH_NONE: 
		ASSERT(u_Hiberarchy>=HIBER_DVB_CARD && u_Hiberarchy <= HIBER_NONE_NODE) ;  
		if ( u_Hiberarchy == HIBER_NONE_NODE ) 
			b_sel_nod = TRUE ;  
		break; 
 
	case SWITCH_DISQEC10: 
	case SWITCH_DISQEC12: 
	case SWITCH_22k: 
	case SWITCH_TONEBURST: 
		ASSERT(u_Hiberarchy>=HIBER_DVB_CARD && u_Hiberarchy <= HIBER_DVB_NODE) ;  
		if ( u_Hiberarchy == HIBER_DVB_NODE ) 
			b_sel_nod = TRUE ;  
		break; 
		 
	default: 
		ASSERT(FALSE) ;  
	} 
 
 
	if ( b_sel_nod ) 
	{ 
		 
			BYTE num ;  
			DaGetSwitchNum ( &num ) ; 
			ASSERT( u_brother_nth < num ) ;  
			WORD sat_id ;  
			DaGetSwitchSatelID (  u_brother_nth, &sat_id ) ;  
			BOOL b = (sat_id != NO_CONNECT_ID) ;  
			GetDlgItem (IDC_BTN_ADDLNB) ->EnableWindow(!b)  ;  
			GetDlgItem (IDC_BTN_PROPERTY) ->EnableWindow( b ) ;  
			GetDlgItem (IDC_BTN_DELETE) ->EnableWindow( b ) ;  
 
			return ;  
	 
	 
 
	} 
		GetDlgItem (IDC_BTN_ADDLNB) ->EnableWindow(FALSE)  ;  
		GetDlgItem (IDC_BTN_PROPERTY) ->EnableWindow( FALSE ) ;  
		GetDlgItem (IDC_BTN_DELETE) ->EnableWindow( FALSE ) ;  
	 
	 
} 
 
void CDlgLnbSet::OnSelchangedTreeSatset(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; 
	// TODO: Add your control notification handler code here 
 
	CTreeCtrl* p_tc = ( CTreeCtrl* ) GetDlgItem(IDC_TREE_SATSET) ;  
	 
	UpdateButtons ( i_sel_type, GetItemHiberarchy( p_tc, p_tc ->GetSelectedItem()), GetTreeBrotherNthNode(p_tc, p_tc ->GetSelectedItem()) ) ;  
	 
	*pResult = 0; 
} 
 
void CDlgLnbSet::OnBtnAddlnb()  
{ 
	// TODO: Add your control notification handler code here 
 
	CTreeCtrl* p_tc = ( CTreeCtrl* ) GetDlgItem(IDC_TREE_SATSET) ;  
 
 
	int n_disqec_type = GetItemHiberarchy( p_tc, p_tc ->GetSelectedItem()) ; 
	int n_disqec_id =  GetTreeBrotherNthNode(p_tc, p_tc ->GetSelectedItem())  ;  
 
	 
	CLnbSettingDlg dlg ; 
	DaGetDefaultSatelAttr ( &dlg .m_sel_param ) ;  
 
	dlg .DoModal() ;  
 
	DaSetSatelAttr ( n_disqec_id, dlg .m_sel_sat, &dlg .m_sel_param ) ;  
 
 
	//刷新节点 
	UpdateNode ( p_tc ->GetSelectedItem() ) ;  
 
	UpdateButtons ( i_sel_type, GetItemHiberarchy( p_tc, p_tc ->GetSelectedItem()), GetTreeBrotherNthNode(p_tc, p_tc ->GetSelectedItem()) ) ;  
	 
 
} 
 
void CDlgLnbSet::UpdateNode(HTREEITEM hr ) 
{	 
	CTreeCtrl* p_tc = ( CTreeCtrl* ) GetDlgItem(IDC_TREE_SATSET) ;  
 
	int n_disqec_id =  GetTreeBrotherNthNode(p_tc, hr) ;  
 
	WORD sat_id  ;  
	DaGetSwitchSatelID (  n_disqec_id, &sat_id ) ; 
 
 
	if ( sat_id ==   NO_CONNECT_ID ) 
	{ 
	 
		p_tc ->SetItemImage( hr, BMP_ID_SWITCH_NO_SEL, BMP_ID_SWITCH_NO_SEL ) ; 
		p_tc ->SetItemText(hr, "not connected") ;  
	} 
	else 
	{ 
		p_tc ->SetItemImage(hr, BMP_ID_SWITCH_SEL, BMP_ID_SWITCH_SEL) ;  
		char sat_name [MAX_PARAM_LENGTH] ;  
		DaGetSatelName ( sat_id, (unsigned char*)sat_name ) ;  
		p_tc ->SetItemText(hr, sat_name) ;  
	} 
	 
 
 
	 
} 
 
void CDlgLnbSet::OnBtnProperty()  
{ 
	// TODO: Add your control notification handler code here 
	CTreeCtrl* p_tc = ( CTreeCtrl* ) GetDlgItem(IDC_TREE_SATSET) ;  
	 
	 
	int n_disqec_type = GetItemHiberarchy( p_tc, p_tc ->GetSelectedItem()) ; 
	int n_disqec_id =  GetTreeBrotherNthNode(p_tc, p_tc ->GetSelectedItem())  ;  
	 
	 
	CLnbSettingDlg dlg ; 
	DaGetSatelAttr (n_disqec_id, &dlg .m_sel_param) ;  
	WORD id; 
	DaGetSwitchSatelID( n_disqec_id, &id  ) ; 
	dlg .m_sel_sat = id ;  
	dlg .DoModal() ;  
	 
	DaSetSatelAttr ( n_disqec_id, dlg .m_sel_sat, &dlg .m_sel_param ) ;  
	 
	 
	//刷新节点 
	UpdateNode ( p_tc ->GetSelectedItem() ) ;  
	 
	UpdateButtons ( i_sel_type, GetItemHiberarchy( p_tc, p_tc ->GetSelectedItem()), GetTreeBrotherNthNode(p_tc, p_tc ->GetSelectedItem()) ) ;  
	 
} 
 
void CDlgLnbSet::OnBtnDelete()  
{ 
	// TODO: Add your control notification handler code here 
	CTreeCtrl* p_tc = ( CTreeCtrl* ) GetDlgItem(IDC_TREE_SATSET) ;  
	 
	 
	int n_disqec_type = GetItemHiberarchy( p_tc, p_tc ->GetSelectedItem()) ; 
	int n_disqec_id =  GetTreeBrotherNthNode(p_tc, p_tc ->GetSelectedItem())  ;  
	 
	 
	 
	DaSetSatelAttr ( n_disqec_id, (WORD)NO_CONNECT_ID, NULL ) ;  
	 
	 
	//刷新节点 
	UpdateNode ( p_tc ->GetSelectedItem() ) ;  
	 
	UpdateButtons ( i_sel_type, GetItemHiberarchy( p_tc, p_tc ->GetSelectedItem()), GetTreeBrotherNthNode(p_tc, p_tc ->GetSelectedItem()) ) ;  
	 
}