#include "stdafx.h"
#include "SChartWnd.h"
 
namespace SOUI
{
	SChartWnd::SChartWnd()
	{
		m_bFocusable = TRUE;
	}
 
 
	SChartWnd::~SChartWnd()
	{
	}
 
	void SChartWnd::OnPaint(IRenderTarget *pRT)
	{
		CRect rect;
		GetClientRect(&rect);

		HDC hDC = pRT->GetDC();
		chart.OnDraw(hDC, rect);
		pRT->ReleaseDC(hDC);
	}
	int SChartWnd::OnCreate(LPVOID lpVoid)
	{
		SetFocus();
		chart.SetType(kTypeHeatMap);
		chart.SetHeatDimension(20, 20);
		int i, j;
		for(j=0; j<20; j++)
		{
			for(i=0; i<20; i++)
			{
				chart.SetHeatData((i-10)*(i-10)+5*(j-10), j, i);
			}
		}
		chart.SetTitle(_T("ÈÈÍ¼"));
		chart.SetXRange(-2, 2);
		chart.SetYRange(-2, 2);
		chart.AddAxis(2);//ÓÒÖá
		return 0;
	}

	UINT SChartWnd::OnGetDlgCode()
	{
		return (SC_WANTALLKEYS|SC_WANTSYSKEY);
	}

	void SChartWnd::OnLButtonDown(UINT nFlags,CPoint pt)
	{
		//__super::OnLButtonDown(nFlags, pt);
		//GetContainer()->OnSetSwndFocus(m_swnd);
		SetFocus();

		HWND hWnd = GetContainer()->GetHostHwnd();
		if(hWnd)
		{
			if(chart.OnLButtonDown(hWnd, pt, nFlags))
			{
				Invalidate();
			}
		}
		
	}

	void SChartWnd::OnLButtonUp(UINT nFlags,CPoint pt)
	{
		HWND hWnd = GetContainer()->GetHostHwnd();
		if(hWnd)
		{
			if(chart.OnLButtonUp(hWnd, pt, nFlags))
			{
				Invalidate();
			}
		}
	}
	void SChartWnd::OnLButtonDbClick(UINT nFlags,CPoint pt)
	{
		HWND hWnd = GetContainer()->GetHostHwnd();
		if(hWnd)
		{
			if(chart.OnLButtonDblClk(hWnd, pt, nFlags))
			{
				Invalidate();
			}
		}
	}

	void SChartWnd::OnMouseMove(UINT nFlags,CPoint pt)
	{
		HWND hWnd = GetContainer()->GetHostHwnd();
		if(hWnd)
		{
			if(chart.OnMouseMove(hWnd, pt, nFlags))
			{
				Invalidate();
			}
		}
	}

	void SChartWnd::OnRButtonDown(UINT nFlags,CPoint pt)
	{
		HWND hWnd = GetContainer()->GetHostHwnd();
		if(hWnd)
		{
			::ClientToScreen(hWnd, &pt);
			if(chart.OnContextMenu(NULL, hWnd, pt))
			{
				Invalidate();
			}
		}
	}
	
	void SChartWnd::OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags )
	{
		HWND hWnd = GetContainer()->GetHostHwnd();
		SLOG_INFO("SChartWnd::OnKeyDown");
		if(hWnd)
		{
			if(chart.OnKeyDown(hWnd, nChar))
			{
				Invalidate();
			}
		}
	}
}
