// VodWndChn.cpp : implementation file
//

#include "stdafx.h"
#include "VodWndChn.h"
#include "VideoVod.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CVodWndChn

CVodWndChn::CVodWndChn()
{
}

CVodWndChn::~CVodWndChn()
{
}


BEGIN_MESSAGE_MAP(CVodWndChn, CWnd)
	//{{AFX_MSG_MAP(CVodWndChn)
	ON_WM_SIZE()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONDBLCLK()
	ON_WM_PAINT()
	ON_WM_ERASEBKGND()
	ON_WM_CREATE()
	ON_WM_DESTROY()
	ON_WM_RBUTTONUP()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CVodWndChn message handlers

void CVodWndChn::OnSize(UINT nType, int cx, int cy) 
{
	CWnd::OnSize(nType, cx, cy);
	
	if ((cx ==0 && cy == 0) || 
		(cx == m_clientRect.Width() && cy == m_clientRect.Height())) 
	{
		return;
	}
	else
	{
		GetClientRect(&m_clientRect);
		SetWndSize(m_pVodScren->m_bAutoSizeAdj);
	}
}

void CVodWndChn::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_pVodScren->SetActivePage(this);
	CWnd::OnLButtonDown(nFlags, point);
}

void CVodWndChn::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(m_pVodScren->m_nCurViewMode == VIDEO_MODE_1)
	{
		BOOL bFull = !m_pVodScren->GetFullScreen();
		if(bFull && !m_lHandle)
			return;
		m_pVodScren->SetFullScreen(bFull);
	}
	else if(m_pVodScren->m_nCurViewMode > VIDEO_MODE_1 && m_pVodScren->m_nCurViewMode <= VIDEO_MODE_36)
	{
		m_pVodScren->SetMultiScreen(!m_pVodScren->GetMultiScreen());
	}
	CWnd::OnLButtonDblClk(nFlags, point);
}

void CVodWndChn::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	if(m_lHandle && m_nStreamInx >= 0)
		MRPSDK_Chn_RefrenshWnd(m_lHandle, m_nStreamInx);
}

BOOL CVodWndChn::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	CRect rt;
	GetClientRect(&rt);
	CBrush br;
	br.CreateSolidBrush(RGB(0, 0, 0));
	pDC->FillRect(&rt,&br);
	
	return TRUE;
	//return CWnd::OnEraseBkgnd(pDC);
}

int CVodWndChn::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	RECT rc;
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	m_hVideoWnd = new CStatic();
	GetClientRect(&rc);
	m_hVideoWnd->Create("",WS_CHILD|WS_VISIBLE|SS_OWNERDRAW, rc, this, 4600);
	m_hVideoWnd->ShowWindow(SW_SHOW);
	return 0;
}

void CVodWndChn::OnDestroy() 
{
	CWnd::OnDestroy();
	
	if(m_hVideoWnd)
	{
		m_hVideoWnd->DestroyWindow();
		delete m_hVideoWnd;
		m_hVideoWnd = NULL;
	}
}

void CVodWndChn::OnRButtonUp(UINT nFlags, CPoint point) 
{
	if(m_pVodScren->GetFullScreen())
	{
		m_pVodScren->SetFullScreen(FALSE);
	}
	CWnd::OnRButtonUp(nFlags, point);
}
