//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "SkinHintWindow.h"

#define CLR_BORDER 		RGB( 100, 108, 119 )
#define CLR_BKGRND_NOR	RGB( 39, 42, 47 )
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
__fastcall TSkinHintWindow::TSkinHintWindow(TComponent* Owner)
		: THintWindow(Owner)
{
}
//---------------------------------------------------------------------------

__fastcall TSkinHintWindow::~TSkinHintWindow()
{
}
//---------------------------------------------------------------------------

void __fastcall TSkinHintWindow::Paint(void)
{
	TRect rect = ClientRect;
	// 绘制背景
	Canvas->Brush->Color = CLR_BKGRND_NOR;
	Canvas->FillRect(rect);

	// 绘制边框
	Canvas->Pen->Color = CLR_BORDER;
	Canvas->Rectangle(rect);

	// 输出文字
	Canvas->Brush->Style = bsClear;
	rect.left += 5;
	rect.top += 3;

	DrawText( Canvas->Handle, Caption.c_str(), -1, (RECT*)&rect, DT_LEFT|DT_NOPREFIX|DT_WORDBREAK);
}
//---------------------------------------------------------------------------

void __fastcall TSkinHintWindow::NCPaint(HDC hdc)
{
	//Invalidate();
}
//---------------------------------------------------------------------------

void __fastcall TSkinHintWindow::CreateParams(TCreateParams &Params)
{
	THintWindow::CreateParams(Params);
	// 去掉Hint窗口的边框
	Params.Style = Params.Style & ~WS_BORDER;
}
//---------------------------------------------------------------------------

void __fastcall TSkinHintWindow::ActivateHint(const TRect &Rect, const String AHint)
{
	FActivating = true;
	try
	{
		Caption = AHint;
		TRect r = Rect;
		r.Left -= 2;
		r.Right += 2;
		r.Top -= 2;
		r.Bottom += 4;

		// 更新区域
		UpdateBoundsRect(r);
		// Hint窗口处于屏幕边缘时的调整
		if(r.Top + Height > Screen->DesktopHeight)
			r.Top = Screen->DesktopHeight - Height;
		if(r.Left + Width > Screen->DesktopWidth)
			r.Left = Screen->DesktopWidth - Width;
		if(r.Left < Screen->DesktopLeft)
			r.Left = Screen->DesktopLeft;
		if(r.Bottom < Screen->DesktopTop)
			r.Bottom = Screen->DesktopTop;

		// 创建一个矩形
		HRGN hRgn = CreateRectRgn(0, 0, r.Width(), r.Height());
		//HRGN hRgn = CreateRoundRectRgn(0, 0, r.Width(), r.Height(), 4, 4);
		// 设置指定句柄的窗口形状
		SetWindowRgn(Handle, hRgn, true);
		DeleteObject( hRgn );

		// 改变窗口的位置,Z Order,及其他一些属性
		SetWindowPos(Handle, HWND_TOPMOST, r.Left, r.Top, r.Width(),
				r.Height(), SWP_SHOWWINDOW | SWP_NOACTIVATE);
		// 重画窗口
		Invalidate();
	}
	__finally
	{
  //		FActivating = false;
	}
}
//---------------------------------------------------------------------------

void __fastcall TSkinHintWindow::ShowHintWindow( const TPoint &Point, const String Ahint  )
{
	TRect rHint = CalcHintRect( 300, Ahint, NULL );
	OffsetRect( rHint, Point.x, Point.y );
	ActivateHint( rHint, Ahint );
}
//---------------------------------------------------------------------------

