#include <common/odlstalt.hpp>
#include <common/rect.hpp>
#include <common/brush.hpp>
#include <common/drawitem.hpp>
#include <common/purehdc.hpp>

OwnerDrawListAltColor::OwnerDrawListAltColor(GUIWindow &parentWnd,HWND hControlWnd,UINT controlID,const RGBColor &primColor,const RGBColor &altColor,const RGBColor &bkGndSelColor)
: OwnerDrawList(parentWnd,hControlWnd,controlID), myIndent(0), mPrimColor(primColor), mAltColor(altColor), 
  mBkGndSelColor(bkGndSelColor), mBkGndSelBrush(mBkGndSelColor), mPrimBrush(mPrimColor), mAltBrush(mAltColor)
{
}

OwnerDrawListAltColor::OwnerDrawListAltColor(GUIWindow &parentWnd,const Rect &initRect,int controlID,const RGBColor &primColor,const RGBColor &altColor,const RGBColor &bkGndSelColor)
: OwnerDrawList(parentWnd,initRect,controlID), mPrimColor(primColor), mAltColor(altColor), mBkGndSelColor(bkGndSelColor), mBkGndSelBrush(mBkGndSelColor), 
  mPrimBrush(mPrimColor), mAltBrush(mAltColor)
{
  yIndent(parentWnd.width()-initRect.right());
}

OwnerDrawListAltColor::~OwnerDrawListAltColor()
{
}

OwnerDrawListAltColor &OwnerDrawListAltColor::operator=(const OwnerDrawListAltColor &someOwnerDrawListAltColor)
{ // private implementation
  return *this;
}

// virtual overloads

void OwnerDrawListAltColor::handleResize(WORD /*width*/,WORD /*height*/)
{
}

WORD OwnerDrawListAltColor::handleDraw(const DrawItem &drawItem)
{
  switch(drawItem.itemAction())
	{
		case DrawItem::Select :
		case DrawItem::DrawEntire :
		case DrawItem::Focus :
			drawEntire(drawItem);
			break;
	}
  return TRUE;
}

WORD OwnerDrawListAltColor::handleMeasureItem(MeasureItem &measureItem)
{
  return TRUE;
}

LPARAM OwnerDrawListAltColor::handleControlColor(PureDevice &pureDevice,Control &wndListBox)
{
  return FALSE;
}

void OwnerDrawListAltColor::drawEntire(const DrawItem &drawItem)
{
	String stringData;

	if(!isOkay())return;
	sendMessage(drawItem.hwndItem(),LB_GETTEXT,drawItem.itemID(),(LPARAM)(LPSTR)stringData);
	PureDevice controlDevice(drawItem.deviceContext());
  if((((UINT)drawItem.itemState())&ODS_SELECTED))
	{
	  controlDevice.setBkColor(mBkGndSelColor);
		controlDevice.fillRect(drawItem.rectItem(),mBkGndSelBrush);
	}
	else 
	{
	  if(drawItem.itemID()%2)
		{
		  controlDevice.setBkColor(mAltColor);
			controlDevice.fillRect(drawItem.rectItem(),mAltBrush);
		}
		else 
		{
		  controlDevice.setBkColor(mPrimColor);
			controlDevice.fillRect(drawItem.rectItem(),mPrimBrush);
		}
	}
	textOut(drawItem,stringData);
  return;
}
