
#include "linkindicator.h"
#include "lrsconnectionstatus.h"


CLinkIndicator::CLinkIndicator(UINT id, LrsConnectionStatus *pClient, CWnd *parent,
							   UINT ledOffBitmap, UINT ledOnBitmap, UINT ledClrBitmap) {
	_id = id;
	_pClient = pClient;
	_toggle = 0;

	_ledOff.LoadBitmap(ledOffBitmap);
	_ledOn.LoadBitmap(ledOnBitmap);
	_ledClr.LoadBitmap(ledClrBitmap);
	_parent = parent;
}


CLinkIndicator::~CLinkIndicator()
{
}


void CLinkIndicator::update() {

	if(_pClient->isConnected()){
		repaint((_toggle? &_ledOn:&_ledClr));
		_toggle = (_toggle == 0? 1: 0);
	}else
		repaint(&_ledOff);
}

void CLinkIndicator::repaint(CBitmap *bitmap) 
{

	CWnd *canvas = _parent->GetDlgItem(_id);
	if(canvas != NULL)
	{
		CDC *pDC = canvas->GetDC();
		CDC dC;
		dC.CreateCompatibleDC(pDC);
		dC.SelectObject(bitmap);
		BITMAP bmp;	
		bitmap->GetBitmap(&bmp);
		pDC->BitBlt(0, 0, bmp.bmWidth, bmp.bmHeight, &dC, 0, 0, SRCCOPY);
		_parent->ReleaseDC(pDC);		
	}
}
