#pragma once
#include <core/Swnd.h>
#include <event/Events.h>

namespace SOUI
{
	#define EVT_SWITCH_CHANGED EVT_EXTERNAL_BEGIN + 800

	SEVENT_BEGIN_EX(EventSwitchChanging, EVT_SWITCH_CHANGED, on_init, )
		BOOL bTurnOn=FALSE;
		BOOL bCacnel = FALSE;
	SEVENT_END()

	class  SSwitch2 : public SWindow, public ITimelineHandler
	{
		SOUI_CLASS_NAME(SSwitch2, L"switch2")
			enum { SwitchSpacing = 4 };
	public:
		SSwitch2();
		~SSwitch2();
	protected://SWindow的虚函数
		virtual CSize GetDesiredSize(int wid, int hei);
		virtual void OnStateChanged(DWORD dwOldState, DWORD dwNewState);
		// 通过 ITimelineHandler 继承
		virtual void OnNextFrame();

	public://属性处理
		BOOL IsOpen();
		void SetOpen(BOOL bOpen);
	protected:
		virtual void GetTextRect(LPRECT pRect);		
		CRect GetSwitchRect();
		void OnPaint(IRenderTarget *pRT);
		void OnLButtonUp(UINT nFlags, CPoint point);
		void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
		HRESULT OnAttrOpen(const SStringW& strValue, BOOL bLoading);
		//SOUI控件消息映射表
		SOUI_MSG_MAP_BEGIN()
			MSG_WM_PAINT_EX(OnPaint)
			MSG_WM_LBUTTONUP(OnLButtonUp)
			MSG_WM_KEYDOWN(OnKeyDown)
		SOUI_MSG_MAP_END()

		ISkinObj *m_pSkin;
		ISkinObj *m_pSkinOn;
		ISkinObj *m_pSkinOff;

		SOUI_ATTRS_BEGIN()
			ATTR_SKIN(L"skin", m_pSkin, TRUE)
			ATTR_SKIN(L"skinon", m_pSkinOn, TRUE)
			ATTR_SKIN(L"skinoff", m_pSkinOff, TRUE)
			ATTR_CUSTOM(L"open", OnAttrOpen)
		SOUI_ATTRS_END()
	private:
		BOOL m_BOpen;
		BOOL m_BChangeing;      //正在改变状态..		
		int  m_FrameNow;		//当前帧
		CAutoRefPtr<ISkinObj> m_disableSkin;
	};

}