//--------------------------------------------------------------------------- #include #pragma hdrstop #include "CommonListBoxUnit.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #define COLOR_BORDER RGB(150,118,80) #define UM_HIDEPOPCONTROL WM_USER + 0x1121 //--------------------------------------------------------------------------- __fastcall CommonListBoxUnit::TListBox::TListBox(System::Classes::TComponent* AOwner) : TSkinListBox(AOwner) { m_pNormal = new TBitmap; m_pNormal->LoadFromResourceName(int(HInstance), "LBNormal"); m_pHover = new TBitmap; m_pHover->LoadFromResourceName(int(HInstance), "LBHover"); ApplicationEvents = NULL; } //--------------------------------------------------------------------------- __fastcall CommonListBoxUnit::TListBox::~TListBox() { if( m_pNormal ){ delete m_pNormal; m_pNormal = NULL; } if( m_pHover ){ delete m_pHover; m_pHover = NULL; } if( ApplicationEvents!=NULL ){ delete ApplicationEvents; ApplicationEvents = NULL; } } //--------------------------------------------------------------------------- void __fastcall CommonListBoxUnit::TListBox::DoHandleMessage(MSG &Msg, bool &Handled) { if( Visible && (Msg.message == WM_NCLBUTTONDOWN || Msg.message == WM_NCRBUTTONDOWN || (Msg.message == WM_LBUTTONDOWN || Msg.message == WM_RBUTTONDOWN) && Msg.hwnd != Handle && Msg.hwnd != GetSBHandle() )){ PostMessage( Parent->Handle, UM_HIDEPOPCONTROL, 0, (LPARAM)this ); } } //--------------------------------------------------------------------------- void __fastcall CommonListBoxUnit::TListBox::DrawItem(int Index, const System::Types::TRect &Rect, Winapi::Windows::TOwnerDrawState State) { TRect rcDraw, rcOrig = Rect; if( rcOrig.Width()Pen->Color = COLOR_BORDER; if( Index==TopIndex ){ //绘制上边框 Canvas->MoveTo(Rect.left, Rect.top); Canvas->LineTo(Rect.right, Rect.top); rcDraw.top++; } int iBottomIndex = TopIndex + Height/ItemHeight-1; if( Index==iBottomIndex ){ //绘制下边框 Canvas->MoveTo(Rect.left, Rect.bottom-1); Canvas->LineTo(Rect.right, Rect.bottom-1); rcDraw.bottom--; } if( State.Contains(odSelected) ){// || State.Contains(odFocused) ){ //绘制选中项 Canvas->Font->Color = RGB(232,212,191); Canvas->StretchDraw( rcDraw, m_pHover ); } else{ Canvas->Font->Color = RGB(60,43,23); Canvas->StretchDraw( rcDraw, m_pNormal ); //绘制左边框 Canvas->MoveTo( rcDraw.left, rcDraw.top ); Canvas->LineTo( rcDraw.left, rcDraw.bottom ); //绘制右边框 Canvas->MoveTo( rcDraw.right-1, rcDraw.top ); Canvas->LineTo( rcDraw.right-1, rcDraw.bottom ); } String strText = Items->Strings[Index]; Canvas->Brush->Style = bsClear; Canvas->TextOut( Rect.left+5, Rect.top, strText ); } //--------------------------------------------------------------------------- void __fastcall CommonListBoxUnit::TListBox::Show(void) { TSkinListBox::Show(); if( ApplicationEvents==NULL ){ ApplicationEvents = new TApplicationEvents(Application->MainForm); ApplicationEvents->OnMessage = DoHandleMessage; } } //--------------------------------------------------------------------------- void __fastcall CommonListBoxUnit::TListBox::Hide(void) { TSkinListBox::Hide(); if( ApplicationEvents!=NULL ){ delete ApplicationEvents; ApplicationEvents = NULL; } } //---------------------------------------------------------------------------