// LayerListCtrl.cpp : インプリメンテーション ファイル
//

#include "stdafx.h"
#include "shitarabianLayer.h"
#include "LayerListCtrl.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLayerListCtrl

CLayerListCtrl::CLayerListCtrl()
{

}

CLayerListCtrl::~CLayerListCtrl()
{
}


BEGIN_MESSAGE_MAP(CLayerListCtrl, CListCtrl)
	//{{AFX_MSG_MAP(CLayerListCtrl)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLayerListCtrl メッセージ ハンドラ

void CLayerListCtrl::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);

	COLORREF	colBack = RGB(255,255,255);
	COLORREF	colFore = RGB(0,0,0);
	if( lpDrawItemStruct->itemState & ODS_SELECTED )
	{
		colBack = RGB(64,128,128);
		colFore = RGB(255,255,255);
	}

	pDC->FillSolidRect(
		&(lpDrawItemStruct->rcItem),
		colBack
	);

	int	iLeft = lpDrawItemStruct->rcItem.left;

	// チェックボックス
	{
		CBitmap	bmClose;
		CBitmap	bmOpen;
		bmClose.LoadBitmap( IDB_CLOSEEYE );
		bmOpen.LoadBitmap( IDB_OPENEYE );

		CDC	dc;
		dc.CreateCompatibleDC( pDC );
		CBitmap*	pbmOld = dc.SelectObject( &bmClose );
	/*
		pDC->FillSolidRect(
			iLeft,
			lpDrawItemStruct->rcItem.top,
			GetColumnWidth(0),
			lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top,
			RGB(255,255,0)
		);
	*/
		BITMAP	tBitmap;
		bmClose.GetBitmap( &tBitmap );

		pDC->BitBlt(
			iLeft + (GetColumnWidth(0)-tBitmap.bmWidth)/2,
			lpDrawItemStruct->rcItem.top
				+ (lpDrawItemStruct->rcItem.bottom-lpDrawItemStruct->rcItem.top-tBitmap.bmHeight)/2,
			tBitmap.bmWidth,
			tBitmap.bmHeight,
			&dc,
			0,0,
//			tBitmap.bmWidth,
//			tBitmap.bmHeight,
			SRCCOPY
		);
		dc.SelectObject( pbmOld );
	}
	iLeft += GetColumnWidth(0);

	// 表示色
	pDC->FillSolidRect(
		iLeft+1,
		lpDrawItemStruct->rcItem.top,
		GetColumnWidth(1)-2,
		lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top-1,
		RGB(0,0,0)
	);
	iLeft += GetColumnWidth(1);

	// 名称
	pDC->SetTextColor( colFore );
	pDC->TextOut(
		iLeft+2,
		lpDrawItemStruct->rcItem.top,
		"あいう"
	);
	iLeft += GetColumnWidth(2);

	CPen	pen;
	pen.CreatePen( PS_SOLID, 1, RGB(200,200,200 ) );
	CPen*	ppenOld = (CPen*)pDC->SelectObject( &pen );
	pDC->MoveTo( lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.bottom-1 );
	pDC->LineTo( iLeft-1, lpDrawItemStruct->rcItem.bottom-1 );
	pDC->LineTo( iLeft-1, lpDrawItemStruct->rcItem.top );
	pDC->SelectObject( ppenOld );
}
