// CPACTTip.cpp : implementation file
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"

#include "EDACTTip.hpp"

#include "EDACCnst.hpp"

CBrush g_cbToolTipBackgroudBrush(RGB(32, 32,224));
COLORREF g_colrefTextColor = RGB(192, 192, 192);


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// EdActors_SpecialToolTip
BEGIN_MESSAGE_MAP(EdActors_SpecialToolTip, CWnd)
	//{{AFX_MSG_MAP(EdActors_SpecialToolTip)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

//***************************************************************************
EdActors_SpecialToolTip::EdActors_SpecialToolTip(CString csText,
											 CFont *pclFont)
{
	m_csToolTipText = csText;
	m_pclFont = pclFont;
}

//***************************************************************************
EdActors_SpecialToolTip::~EdActors_SpecialToolTip()
{
}

/////////////////////////////////////////////////////////////////////////////
// EdActors_SpecialToolTip message handlers

//***************************************************************************
BOOL EdActors_SpecialToolTip::m_fn_bCreate(CWnd *pclParentWnd) 
{
	return CWnd::Create(NULL,
						"",
						WS_BORDER,
						CRect(0,0,0,0),
						/*GetDesktopWindow()*/pclParentWnd,
						0,
						NULL);
}

//***************************************************************************
void EdActors_SpecialToolTip::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	CRect crClientRect;
	GetClientRect(crClientRect);
	dc.FillRect(crClientRect, &g_cbToolTipBackgroudBrush);

	dc.SelectObject(m_pclFont);
	dc.SetTextColor(g_colrefTextColor);
	dc.SetBkMode(TRANSPARENT);
	dc.TextOut(0, 0, m_csToolTipText);

	// Do not call CWnd::OnPaint() for painting messages
}

//***************************************************************************
void EdActors_SpecialToolTip::m_fn_vMove(CPoint point)
{
	CRect crNewRect;
	CClientDC dc(this);
	dc.SelectObject(m_pclFont);
	CSize csTextSize = dc.GetTextExtent(m_csToolTipText);
	
	crNewRect = CRect(	point.x,
						point.y,
						point.x	+ csTextSize.cx + C_TTIPS_SPACING,
						point.y	+ csTextSize.cy + C_TTIPS_SPACING);

	//Looks if whole tooltip would be visible
	CRect crPCRect;
	GetParent()->GetClientRect(crPCRect);
	if ( crNewRect.right > crPCRect.right )
		crNewRect.OffsetRect(crPCRect.right-crNewRect.right, 0);

	ShowWindow(SW_SHOW);
	MoveWindow(crNewRect);
}

