Files
Work/m68hc11/ODLSTLED.CPP
2024-08-07 09:16:27 -04:00

130 lines
4.4 KiB
C++

#include <m68hc11/odlstled.hpp>
#include <common/drawitem.hpp>
#include <common/measure.hpp>
#include <common/purebmp.hpp>
OwnerDrawListBinaryLed::OwnerDrawListBinaryLed(GUIWindow &parentWnd,HWND hControlWnd,UINT controlID)
: OwnerDrawList(parentWnd,hControlWnd,controlID), mRGBGray(192,192,192), mGrayBrush(mRGBGray),
mDisabledBrush(RGBColor(128,128,128)), mOneBitmap("ONE"), mZeroBitmap("ZERO"), mBlankBitmap("BLANK"),
mDashBitmap("DASH"), mFont("Courier",14)
{
}
OwnerDrawListBinaryLed::OwnerDrawListBinaryLed(GUIWindow &parentWnd,const Rect &initRect,int controlID,DWORD style)
: OwnerDrawList(parentWnd,initRect,controlID,style), mRGBGray(192,192,192), mGrayBrush(mRGBGray),
mDisabledBrush(RGBColor(128,128,128)), mOneBitmap("ONE"), mZeroBitmap("ZERO"), mBlankBitmap("BLANK"),
mDashBitmap("DASH"), mFont("Courier",14)
{
}
OwnerDrawListBinaryLed::~OwnerDrawListBinaryLed()
{
}
OwnerDrawListBinaryLed &OwnerDrawListBinaryLed::operator=(const OwnerDrawListBinaryLed &/*someOwnerDrawListBinaryLed*/)
{ // private implementation
return *this;
}
// **** virtuals
LPARAM OwnerDrawListBinaryLed::handleControlColor(PureDevice &/*pureDevice*/,Control &/*wndListBox*/)
{
return (LPARAM)(GDIObj)mGrayBrush;
}
WORD OwnerDrawListBinaryLed::handleDraw(const DrawItem &drawItem)
{
if(!isOkay()||-1==drawItem.itemID()||DrawItem::ListBox!=drawItem.controlType())return FALSE;
PureDevice pureDevice(drawItem.deviceContext());
pureDevice.setBkColor(mRGBGray);
switch(drawItem.itemAction())
{
case DrawItem::Select :
case DrawItem::DrawEntire :
case DrawItem::Focus :
drawEntire(drawItem);
break;
}
return TRUE;
}
WORD OwnerDrawListBinaryLed::handleMeasureItem(MeasureItem &measureItem)
{
measureItem.itemHeight(20);
return TRUE;
}
void OwnerDrawListBinaryLed::drawEntire(const DrawItem &drawItem)
{
PureDevice pureDevice(drawItem.deviceContext());
PureDevice memDevice;
String stringData;
String strNumber;
TEXTMETRIC textMetric;
Rect drawRect;
SIZE sizeExtent;
HFONT hPrevFont;
if(!isOkay())return;
stringData.reserve(256);
drawRect=drawItem.rectItem();
hPrevFont=(HFONT)::SelectObject(drawItem.deviceContext(),(GDIObj)mFont);
memDevice.compatibleDevice(pureDevice);
sendMessage(drawItem.hwndItem(),LB_GETTEXT,drawItem.itemID(),(LPARAM)(LPSTR)stringData);
strNumber=stringData.betweenString('\t',0);
if(strNumber.isNull())setBitmap();
else
{
setBitmap(::atoi(strNumber));
stringData=stringData.betweenString(0,'\t');
}
if(stringData.isNull())::MessageBeep(0);
::GetTextMetrics(drawItem.deviceContext(),&textMetric);
::GetTextExtentPoint32(drawItem.deviceContext(),(LPSTR)stringData,stringData.length(),&sizeExtent);
if(drawItem.itemState()&ODS_DISABLED)
{
::GrayString(drawItem.deviceContext(),(HBRUSH)(GDIObj)mDisabledBrush,(GRAYSTRINGPROC)0,(LPARAM)(LPSTR)stringData,stringData.length(),mBlankBitmap.width()+6,(drawRect.bottom()+drawRect.top()-textMetric.tmHeight)/2,0,0);
memDevice.select(mBlankBitmap,TRUE);
Rect stretchRect(drawRect);
stretchRect.right(mBlankBitmap.width());
stretchRect.bottom(sizeExtent.cy);
pureDevice.stretchBlt(stretchRect,memDevice,Rect(0,0,mBlankBitmap.width(),mBlankBitmap.height()),PureDevice::MergeCopy);
memDevice.select(mBlankBitmap,FALSE);
}
else
{
::TextOut(drawItem.deviceContext(),mBlankBitmap.width()+6,(drawRect.bottom()+drawRect.top()-textMetric.tmHeight)/2,(LPSTR)stringData,stringData.length());
memDevice.select(mBlankBitmap,TRUE);
Rect stretchRect(drawRect);
stretchRect.right(mBlankBitmap.width());
stretchRect.bottom(sizeExtent.cy);
pureDevice.stretchBlt(stretchRect,memDevice,Rect(0,0,mBlankBitmap.width(),mBlankBitmap.height()),PureDevice::MergeCopy);
memDevice.select(mBlankBitmap,FALSE);
}
if((((UINT)drawItem.itemState())&ODS_FOCUS))
{
Rect bmpRect(drawRect);
bmpRect.right(bmpRect.left()+mBlankBitmap.width());
bmpRect.bottom(bmpRect.top()+sizeExtent.cy);
::DrawFocusRect(drawItem.deviceContext(),(RECT*)&bmpRect);
}
::SelectObject(drawItem.deviceContext(),hPrevFont);
}
void OwnerDrawListBinaryLed::setBitmap(BYTE value)
{
for(int index=0,mask=0x80;index<8;index++,mask/=2)
mBlankBitmap.setFrom(value&mask?mOneBitmap:mZeroBitmap,getPlacementRect(index));
}
void OwnerDrawListBinaryLed::setBitmap(void)
{
for(int index=0,mask=0x80;index<8;index++,mask/=2)mBlankBitmap.setFrom(mDashBitmap,getPlacementRect(index));
}
Rect OwnerDrawListBinaryLed::getPlacementRect(int position)
{
return Rect(position*CellWidth,0,CellWidth,CellHeight);
}