// UserInfoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "skoko.h"
#include "UserInfoDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CUserInfoDlg dialog


CUserInfoDlg::CUserInfoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CUserInfoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CUserInfoDlg)
	//}}AFX_DATA_INIT
}


void CUserInfoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUserInfoDlg)
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CUserInfoDlg, CDialog)
	//{{AFX_MSG_MAP(CUserInfoDlg)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_RBUTTONDOWN()
	ON_WM_RBUTTONUP()
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUserInfoDlg message handlers

void CUserInfoDlg::ShowInfo( const BGDNet::NDSObject* pObj, CWnd* pParent, CPoint point )
{
  if (!::IsWindow(GetSafeHwnd()))
    Create(IDD, pParent);

  BGDNet::String a;
  m_attrs[0] = pObj->attr("Full Name", &a) ? a : _T("");
  m_attrs[1] = pObj->attr("Surname", &a) ? a : _T("");
  m_attrs[2] = pObj->attr("Title", &a) ? a : _T("");
  m_attrs[3] = pObj->attr("L", &a) ? a : _T("");
  m_attrs[4] = pObj->attr("Telephone Number", &a) ? a : _T("");

  m_curPoint = point;

  ShowWindow(SW_SHOW);
  Invalidate();
}

void CUserInfoDlg::HideInfo()
{
  if (::IsWindow(GetSafeHwnd()))
  {
    ShowWindow(SW_HIDE);
    Invalidate();
  }
}

void CUserInfoDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
  HideInfo();
}

void CUserInfoDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
  HideInfo();
}

void CUserInfoDlg::OnRButtonDown(UINT nFlags, CPoint point) 
{
  HideInfo();
}

void CUserInfoDlg::OnRButtonUp(UINT nFlags, CPoint point) 
{
  HideInfo();
}

void CUserInfoDlg::OnPaint() 
{
  CPaintDC dc(this); // device context for painting

  // TODO: Add your message handler code here

  CString info;
  for (int i = 0; i < sizeof(m_attrs)/sizeof(m_attrs[0]); ++i)
  {
    if (!m_attrs[i].IsEmpty())
    {
      if (!info.IsEmpty())
        info += _T("\r\n");
      info += m_attrs[i];
    }
  }

  CRect infoRect, clientRect;
  infoRect.SetRect(0, 0, 0, 0);
  const UINT fmt = DT_CALCRECT | DT_EXTERNALLEADING | DT_LEFT | DT_NOPREFIX;
  dc.DrawText(info, &infoRect, fmt);
  clientRect = infoRect;
  clientRect.right += 16;
  clientRect.bottom += 16;
  infoRect.OffsetRect(8, 8);
  MoveWindow(
    m_curPoint.x + 15,
    m_curPoint.y + 5,
    clientRect.Width(),
    clientRect.Height());
  COLORREF clr = GetSysColor(COLOR_INFOBK);
  dc.FillSolidRect(&clientRect, clr);
  dc.DrawText(info, &infoRect, fmt & ~DT_CALCRECT);
}
