#include "StdAfx.h"
#include "SkinnableButton.h"

SkinnableButton::SkinnableButton(void)
{
	type = ButtonType;
	pressable = 1;
	hWndSink = NULL;
}

SkinnableButton::~SkinnableButton(void)
{
}

void SkinnableButton::OnLButtonUp()
{
	if(GetFocus()==hWnd && !MouseOutside){ // there was a left button click!
		if(hWndSink)
			SafeSendMessage(hWndSink,WM_COMMAND,MAKEWPARAM(0,ID_LEFTBUTTON),(LPARAM)hWnd);
		if(hWndParent)
			SafeSendMessage(hWndParent,WM_COMMAND,MAKEWPARAM(0,ID_LEFTBUTTON),(LPARAM)hWnd);
	}
	SkinnableWindow::OnLButtonUp();
}

void SkinnableButton::OnRButtonUp()
{
	if(GetFocus()==hWnd && !MouseOutside){ // there was a right button click!
		if(hWndSink)
			SafeSendMessage(hWndSink,WM_COMMAND,MAKEWPARAM(0,ID_RIGHTBUTTON),(LPARAM)hWnd);
		if(hWndParent)
			SafeSendMessage(hWndParent,WM_COMMAND,MAKEWPARAM(0,ID_RIGHTBUTTON),(LPARAM)hWnd);
	}
	SkinnableWindow::OnRButtonUp();
}

void SkinnableButton::OnLButtonDblClk()
{
	if(hWndSink)
		SafeSendMessage(hWndSink,WM_COMMAND,MAKEWPARAM(0,ID_DOUBLEBUTTON),(LPARAM)hWnd);
	if(hWndParent)
		SafeSendMessage(hWndParent,WM_COMMAND,MAKEWPARAM(0,ID_DOUBLEBUTTON),(LPARAM)hWnd);
	SkinnableWindow::OnLButtonDblClk();
}

void SkinnableButton::SetMessageSink(HWND h)
{
	hWndSink = h;
}

void SkinnableButton::OnCarriageReturn(HWND h)
{
	if(h==hWnd){
		if(GetFocus()==hWnd){ // there was a left button click!
			if(hWndSink)
				SafeSendMessage(hWndSink,WM_COMMAND,MAKEWPARAM(0,ID_LEFTBUTTON),(LPARAM)hWnd);
			if(hWndParent)
				SafeSendMessage(hWndParent,WM_COMMAND,MAKEWPARAM(0,ID_LEFTBUTTON),(LPARAM)hWnd);
		}		
	}
}