Initial commit
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,241 @@
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#pragma hdrstop
|
||||
|
||||
#include "ComboBoxComponent.h"
|
||||
//---------------------------------------------------------------------------
|
||||
#pragma package(smart_init)
|
||||
|
||||
#include "DropListScrollBar.cpp"
|
||||
#include "DropListView.cpp"
|
||||
#include "CapButton.cpp"
|
||||
|
||||
static inline void ValidCtrCheck(TComboBoxComponent *)
|
||||
{
|
||||
new TComboBoxComponent(NULL);
|
||||
}
|
||||
|
||||
namespace Comboboxcomponent
|
||||
{
|
||||
void __fastcall PACKAGE Register()
|
||||
{
|
||||
TComponentClass classes[1] = {__classid(TComboBoxComponent)};
|
||||
RegisterComponents(L"Samples", classes, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#define MIN(x, y) ((x)<(y)?(x):(y))
|
||||
|
||||
|
||||
__fastcall TComboBoxComponent::TComboBoxComponent(TComponent *Owner)
|
||||
: CBCapButton(Owner)
|
||||
{
|
||||
m_ClickStat = 0;
|
||||
|
||||
m_IsMouseOver = false;
|
||||
|
||||
ItemHeight = 20;
|
||||
ShowItemCount = 5;
|
||||
|
||||
FShowMode = TComboBoxMode(cbShowDown);
|
||||
|
||||
// 初始化下拉列表框
|
||||
m_DropListView = new TDropListView(this);
|
||||
m_DropListView->Parent = (TWinControl *)Owner;
|
||||
m_DropListView->SetDesignVisible(false);
|
||||
m_DropListView->Visible = false;
|
||||
|
||||
m_DropListView->OnHide = DoDropListHide;
|
||||
m_DropListView->OnShow = DoDropListShow;
|
||||
|
||||
OnMouseEnter = DoMouseEnter;
|
||||
OnMouseLeave = DoMouseLeave;
|
||||
}
|
||||
|
||||
__fastcall TComboBoxComponent::~TComboBoxComponent()
|
||||
{
|
||||
}
|
||||
|
||||
void __fastcall TComboBoxComponent::SetParent(TWinControl* AParent)
|
||||
{
|
||||
m_DropListView->Parent = AParent;
|
||||
CBCapButton::Parent = AParent;
|
||||
}
|
||||
|
||||
void __fastcall TComboBoxComponent::SetFontSize( int value )
|
||||
{
|
||||
m_DropListView->SetFontSize(value);
|
||||
CBCapButton::SetFontSize(value);
|
||||
}
|
||||
|
||||
void __fastcall TComboBoxComponent::SetFont( String name, int size )
|
||||
{
|
||||
CBCapButton::SetFont(name, size);
|
||||
m_DropListView->SetFont(name, size);
|
||||
}
|
||||
|
||||
TComboBoxItem * __fastcall TComboBoxComponent::AddItem(String Caption)
|
||||
{
|
||||
TComboBoxItem * pNewItem = new TComboBoxItem(Caption, DoItemClick);
|
||||
m_DropListView->AddItem(pNewItem);
|
||||
|
||||
return pNewItem;
|
||||
}
|
||||
|
||||
TComboBoxItem * __fastcall TComboBoxComponent::GetItem(int Index)
|
||||
{
|
||||
return m_DropListView->GetItem( Index );
|
||||
}
|
||||
|
||||
void __fastcall TComboBoxComponent::Clear()
|
||||
{
|
||||
if(m_DropListView->ItemsCount != 0)
|
||||
{
|
||||
m_DropListView->Clear();
|
||||
}
|
||||
}
|
||||
|
||||
void __fastcall TComboBoxComponent::DoDropListShow(TObject *Sender)
|
||||
{
|
||||
Down = true;
|
||||
m_ClickStat = 1;
|
||||
}
|
||||
|
||||
void __fastcall TComboBoxComponent::DoDropListHide(TObject *Sender)
|
||||
{
|
||||
Down = false;
|
||||
|
||||
if(!m_IsMouseOver)
|
||||
{
|
||||
m_ClickStat = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ClickStat = 3;
|
||||
}
|
||||
}
|
||||
|
||||
void __fastcall TComboBoxComponent::DoItemClick(TComboBoxItem* Sender, int Index)
|
||||
{
|
||||
Caption = Sender->Caption;
|
||||
if(FOnChange) FOnChange(Sender, Index);
|
||||
}
|
||||
|
||||
void __fastcall TComboBoxComponent::DoMouseEnter(TObject *Sender)
|
||||
{
|
||||
m_IsMouseOver = true;
|
||||
}
|
||||
|
||||
void __fastcall TComboBoxComponent::DoMouseLeave(TObject *Sender)
|
||||
{
|
||||
m_IsMouseOver = false;
|
||||
}
|
||||
/*
|
||||
void __fastcall TComboBoxComponent::CMMouseEnter(TMessage &Message)
|
||||
{
|
||||
m_IsMouseOver = true;
|
||||
//TGraphicControl::Dispatch(&Message);
|
||||
CBCapButton::DefaultHandler(&Message);
|
||||
}
|
||||
|
||||
void __fastcall TComboBoxComponent::CMMouseLeave(TMessage &Message)
|
||||
{
|
||||
m_IsMouseOver = false;
|
||||
//TGraphicControl::Dispatch(&Message);
|
||||
}
|
||||
*/
|
||||
void __fastcall TComboBoxComponent::MouseDown(TMouseButton Button, TShiftState Shift, int X, int Y)
|
||||
{
|
||||
TGraphicControl::MouseDown(Button, Shift, X, Y);
|
||||
|
||||
if(Button != 0) return;
|
||||
|
||||
if(m_ClickStat == 3) return;
|
||||
|
||||
m_DropListView->ItemHeight = FItemHeight;
|
||||
m_DropListView->Width = Width;
|
||||
|
||||
TPoint var_Client(0, Height);
|
||||
TPoint var_Screen = ClientToScreen(var_Client);
|
||||
|
||||
m_DropListView->Left = var_Screen.X;
|
||||
|
||||
m_DropListView->ShowItemsCount = FShowItemCount;
|
||||
|
||||
if(ShowMode == TComboBoxMode(cbShowUp))
|
||||
{
|
||||
// 上方显示
|
||||
m_DropListView->Top = var_Screen.Y - Height - m_DropListView->ListHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 下方显示
|
||||
m_DropListView->Top = var_Screen.Y;
|
||||
}
|
||||
|
||||
m_DropListView->Show();
|
||||
}
|
||||
|
||||
void __fastcall TComboBoxComponent::MouseUp(TMouseButton Button, TShiftState Shift, int X, int Y)
|
||||
{
|
||||
TGraphicControl::MouseUp(Button, Shift, X, Y);
|
||||
|
||||
if(Button != 0) return;
|
||||
|
||||
if(m_ClickStat == 3) m_ClickStat = 0;
|
||||
}
|
||||
|
||||
int __fastcall TComboBoxComponent::GetDefaultItem()
|
||||
{
|
||||
return m_DropListView->DefItemIndex;
|
||||
}
|
||||
|
||||
int __fastcall TComboBoxComponent::GetItemsCount()
|
||||
{
|
||||
return m_DropListView->ItemsCount;
|
||||
}
|
||||
|
||||
void __fastcall TComboBoxComponent::RemoveItem(int Index)
|
||||
{
|
||||
int var_Count = m_DropListView->ItemsCount;
|
||||
if(Index < var_Count && Index >= 0)
|
||||
{
|
||||
m_DropListView->RemoveItem(Index);
|
||||
}
|
||||
}
|
||||
|
||||
void __fastcall TComboBoxComponent::SetDefaultItem(int Value)
|
||||
{
|
||||
int var_Count = m_DropListView->ItemsCount;
|
||||
|
||||
if(Value >= var_Count || Value < 0)
|
||||
{
|
||||
Value = -1;
|
||||
Caption = "";
|
||||
}
|
||||
else if(var_Count > 0)
|
||||
{
|
||||
TComboBoxItem *var_Item = m_DropListView->GetItem(Value);
|
||||
if(var_Item != NULL)
|
||||
{
|
||||
Caption = var_Item->Caption;
|
||||
}
|
||||
}
|
||||
|
||||
m_DropListView->DefItemIndex = Value;
|
||||
}
|
||||
|
||||
void __fastcall TComboBoxComponent::SetItemHeight(int Value)
|
||||
{
|
||||
FItemHeight = Value;
|
||||
}
|
||||
|
||||
void __fastcall TComboBoxComponent::SetShowMode(TComboBoxMode Value)
|
||||
{
|
||||
FShowMode = Value;
|
||||
}
|
||||
|
||||
void __fastcall TComboBoxComponent::SetShowItemCount(int Value)
|
||||
{
|
||||
FShowItemCount = Value;
|
||||
}
|
||||
@@ -0,0 +1,427 @@
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#ifndef ComboBoxComponentH
|
||||
#define ComboBoxComponentH
|
||||
|
||||
#include <vcl.h>
|
||||
#include <SysUtils.hpp>
|
||||
#include <Classes.hpp>
|
||||
#include <Vcl.Controls.hpp>
|
||||
#include <Vcl.Imaging.pngimage.hpp>
|
||||
#include <Vcl.Imaging.pnglang.hpp>
|
||||
#include <Vcl.Graphics.hpp>
|
||||
//---------------------------------------------------------------------------
|
||||
class TDropListScrollBar;
|
||||
class TComboBoxItem;
|
||||
class TDropListView;
|
||||
class CBCapButton;
|
||||
//---------------------------------------------------------------------------
|
||||
/* 定义下拉列表项点击事件 */
|
||||
typedef void __fastcall (__closure *TItemClickEvent)(TComboBoxItem* Sender, int Index);
|
||||
|
||||
/* 下拉列表框显示风格 */
|
||||
enum DECLSPEC_DENUM TComboBoxMode : unsigned char {cbShowUp, cbShowDown};
|
||||
//typedef System::Set<ComboBox_Mode, ComboBox_Mode::cbShowUp, ComboBox_Mode::cbShowDown> TComboBoxMode;
|
||||
/* 定义下拉列表框变化事件 */
|
||||
typedef void __fastcall (__closure *TComboBoxChangeEvent)(TComboBoxItem* Sender, int Index);
|
||||
|
||||
/**************************************************************************************************/
|
||||
/**************************************************************************************************/
|
||||
class TDropListScrollBar : public TScrollBar
|
||||
{
|
||||
private:
|
||||
// int m_nTileHeight, //add by tj 2013/11/18
|
||||
int m_nThumbHeight,
|
||||
m_nThumbTop,
|
||||
m_nPreThumbTop,
|
||||
m_nDragPos,
|
||||
m_nDragPoint,
|
||||
m_iClicked,
|
||||
m_iHitPrev,
|
||||
m_nMax,
|
||||
m_nMin,
|
||||
m_nPos,
|
||||
m_nPage,
|
||||
m_nTrackPos;
|
||||
|
||||
bool m_bPause,
|
||||
m_bNotify,
|
||||
m_bDrag,
|
||||
m_bTrace;
|
||||
|
||||
TBitmap *u_pPicLineUp,
|
||||
*u_pPicLineDown;
|
||||
|
||||
TTimer *m_pTimer;
|
||||
TCanvas *m_pCanvas;
|
||||
|
||||
int HitTest( int X, int Y );
|
||||
void CalcThumbHeight();
|
||||
void CalcThumbTop();
|
||||
void DrawArrow( int iDirection, int iState );
|
||||
void DrawThumb( int iState, bool bEraseBk, int iPageUD=-1 );
|
||||
|
||||
void __fastcall TimerProc(TObject* Sender);
|
||||
|
||||
MESSAGE void __fastcall WMPaint(Winapi::Messages::TWMPaint &Message);
|
||||
MESSAGE void __fastcall WMLButtonDown(TWMMouse &Message);
|
||||
MESSAGE void __fastcall WMLButtonUp(TWMMouse &Message);
|
||||
MESSAGE void __fastcall WMLButtonDblClk(TWMMouse &Message);
|
||||
MESSAGE void __fastcall WMRButtonDown(TWMMouse &Message); //add by tj 2013/11/18
|
||||
MESSAGE void __fastcall WMRButtonUp(TWMMouse &Message); //add by tj 2013/11/18
|
||||
MESSAGE void __fastcall WMMouseMove(TWMMouse &Message);
|
||||
// MESSAGE void __fastcall CMMouseLeave(TMessage &Message); //add by tj 2013/11/25 12:35
|
||||
MESSAGE void __fastcall SBMSetScrollInfo(TMessage &Message);
|
||||
MESSAGE void __fastcall SBMGetScrollInfo(TMessage &Message);
|
||||
|
||||
BEGIN_MESSAGE_MAP
|
||||
MESSAGE_HANDLER(WM_PAINT, TWMPaint, WMPaint)
|
||||
MESSAGE_HANDLER(WM_LBUTTONDOWN, TWMLButtonDown, WMLButtonDown)
|
||||
MESSAGE_HANDLER(WM_LBUTTONUP, TWMLButtonUp, WMLButtonUp)
|
||||
MESSAGE_HANDLER(WM_LBUTTONDBLCLK, TWMLButtonDblClk, WMLButtonDblClk)
|
||||
MESSAGE_HANDLER(WM_RBUTTONDOWN, TWMRButtonDown, WMRButtonDown)
|
||||
MESSAGE_HANDLER(WM_RBUTTONUP, TWMRButtonUp, WMRButtonUp) //add by tj 2013/11/18
|
||||
MESSAGE_HANDLER(WM_MOUSEMOVE, TWMMouseMove, WMMouseMove) //add by tj 2013/11/18
|
||||
// MESSAGE_HANDLER(CM_MOUSELEAVE, TMessage, CMMouseLeave) //add by tj 2013/11/25 12:35
|
||||
MESSAGE_HANDLER(SBM_SETSCROLLINFO, TMessage, SBMSetScrollInfo)
|
||||
MESSAGE_HANDLER(SBM_GETSCROLLINFO, TMessage, SBMGetScrollInfo)
|
||||
END_MESSAGE_MAP(TScrollBar)
|
||||
|
||||
protected:
|
||||
virtual void __fastcall PaintWindow(HDC DC);
|
||||
|
||||
public:
|
||||
TWinControl *m_pWndCtrl;
|
||||
bool m_bAction;
|
||||
|
||||
__fastcall virtual TDropListScrollBar(System::Classes::TComponent* AOwner);
|
||||
__fastcall ~TDropListScrollBar();
|
||||
|
||||
void __fastcall CMMouseLeave(TObject *Sender); //add by tj 2013/11/25 12:35
|
||||
|
||||
bool IsDraging(){ return m_bDrag; };
|
||||
void __fastcall SetPosition(int Value, bool bRedraw=true);
|
||||
void __fastcall SetPageSize(int Value, bool bRedraw=true);
|
||||
void __fastcall SetRange(int AMin, int AMax, bool bRedraw=true);
|
||||
void __fastcall GetScrollRange(int* nMin, int* nMax);
|
||||
int __fastcall GetScrollPos();
|
||||
int __fastcall GetPageSize();
|
||||
};
|
||||
/**************************************************************************************************/
|
||||
/**************************************************************************************************/
|
||||
class TComboBoxItem : public TObject
|
||||
{
|
||||
private:
|
||||
int FTag;
|
||||
String FCaption;
|
||||
TItemClickEvent FOnItemClick;
|
||||
|
||||
void __fastcall SetCaption(String Caption);
|
||||
|
||||
public:
|
||||
__fastcall TComboBoxItem(String Caption, TItemClickEvent OnItemClick);
|
||||
|
||||
void __fastcall DrawItem(TCanvas *Canvas, TRect Rect, bool Selected);
|
||||
|
||||
__published:
|
||||
__property String Caption = {read = FCaption, write = FCaption};
|
||||
__property int Tag = {read = FTag, write = FTag};
|
||||
__property TItemClickEvent OnItemClicked = {read = FOnItemClick, write = FOnItemClick};
|
||||
};
|
||||
// ---------------------------------------------------------------------------
|
||||
// TDropListView
|
||||
// ---------------------------------------------------------------------------
|
||||
class TDropListView : public TWinControl
|
||||
{
|
||||
private:
|
||||
TNotifyEvent FOnHide, // 下拉列表隐藏事件
|
||||
FOnShow; // 下拉列表显示事件
|
||||
|
||||
int FItemHeight,
|
||||
FItemWidth,
|
||||
FShowItemsCount,
|
||||
FDefItemIndex;
|
||||
|
||||
TControlCanvas *m_Canvas;
|
||||
TList *m_ItemRectList,
|
||||
*m_ItemList;
|
||||
|
||||
TDropListScrollBar *m_ScrollBar;
|
||||
|
||||
HWND m_pActiveWnd;
|
||||
|
||||
int m_BeginIndex,
|
||||
m_EndIndex,
|
||||
m_CurrentItemIndex,
|
||||
m_RealShowCount,
|
||||
m_MouseX,
|
||||
m_MouseY;
|
||||
|
||||
void __fastcall CreateScrollBar();
|
||||
|
||||
void __fastcall DoItemsCountChange();
|
||||
void __fastcall DoItemClicked(int Index);
|
||||
void __fastcall DoItemSelect(int Index);
|
||||
void __fastcall DoKeyUpDown(int Index);
|
||||
void __fastcall DoShowItemsChange();
|
||||
|
||||
int __fastcall CalcListHeight();
|
||||
int __fastcall GetItemsCount();
|
||||
TRect *__fastcall GetItemRect(int Index);
|
||||
|
||||
void __fastcall SetShowItemsCount(int Value);
|
||||
|
||||
MESSAGE void __fastcall WMEraseBkgnd(TWMEraseBkgnd &Message);
|
||||
MESSAGE void __fastcall WMKeyDown(TWMKeyDown &Message);
|
||||
MESSAGE void __fastcall WMKillFocus(TMessage &Message);
|
||||
MESSAGE void __fastcall WMLButtonDown(TWMLButtonDown &Message);
|
||||
MESSAGE void __fastcall WMMouseWheel(TWMMouseWheel &Message);
|
||||
MESSAGE void __fastcall WMPaint(TWMPaint &Message);
|
||||
MESSAGE void __fastcall WMSetFocus(TMessage &Message);
|
||||
MESSAGE void __fastcall WMVScroll(TWMScroll &Message);
|
||||
|
||||
BEGIN_MESSAGE_MAP
|
||||
MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)
|
||||
MESSAGE_HANDLER(CN_KEYDOWN, TWMKeyDown, WMKeyDown)
|
||||
MESSAGE_HANDLER(WM_KILLFOCUS, TMessage, WMKillFocus)
|
||||
MESSAGE_HANDLER(WM_LBUTTONDOWN, TWMLButtonDown, WMLButtonDown)
|
||||
MESSAGE_HANDLER(WM_MOUSEWHEEL, TWMMouseWheel, WMMouseWheel)
|
||||
MESSAGE_HANDLER(WM_PAINT, TWMPaint, WMPaint)
|
||||
MESSAGE_HANDLER(WM_SETFOCUS, TMessage, WMSetFocus)
|
||||
MESSAGE_HANDLER(WM_VSCROLL, TWMScroll, WMVScroll)
|
||||
END_MESSAGE_MAP(TWinControl)
|
||||
|
||||
protected:
|
||||
virtual void __fastcall CreateParams(TCreateParams &Params);
|
||||
virtual void __fastcall CreateWnd();
|
||||
virtual void __fastcall PaintWindow(HDC DC);
|
||||
|
||||
DYNAMIC void __fastcall MouseDown(TMouseButton Button, TShiftState Shift, int X, int Y);
|
||||
DYNAMIC void __fastcall MouseMove(TShiftState Shift, int X, int Y);
|
||||
DYNAMIC void __fastcall MouseUp(TMouseButton Button, TShiftState Shift, int X, int Y);
|
||||
|
||||
public:
|
||||
__fastcall TDropListView(TComponent *Owner);
|
||||
__fastcall ~TDropListView();
|
||||
void __fastcall AddItem(TComboBoxItem* Item);
|
||||
void __fastcall Clear();
|
||||
TComboBoxItem *__fastcall GetItem(int Index);
|
||||
void __fastcall Hide();
|
||||
void __fastcall RemoveItem(int Index);
|
||||
void __fastcall ScrollPos(int Pos);
|
||||
void __fastcall Show();
|
||||
void __fastcall SetFontSize(int sz);
|
||||
void __fastcall SetFont(String name, int sz);
|
||||
|
||||
__published:
|
||||
__property int ListHeight = {read = CalcListHeight};
|
||||
__property int ItemHeight = {write = FItemHeight, read = FItemHeight, default = 16};
|
||||
|
||||
__property TNotifyEvent OnHide = {write = FOnHide, read = FOnHide};
|
||||
__property TNotifyEvent OnShow = {write = FOnShow, read = FOnShow};
|
||||
|
||||
__property int ShowItemsCount = {write = SetShowItemsCount, read = FShowItemsCount};
|
||||
|
||||
__property int DefItemIndex = {read = FDefItemIndex, write = FDefItemIndex};
|
||||
__property int ItemsCount = {read = GetItemsCount};
|
||||
};
|
||||
/**************************************************************************************************/
|
||||
/**************************************************************************************************/
|
||||
class CBCapButton : public TGraphicControl
|
||||
{
|
||||
public:
|
||||
enum TModalResult{
|
||||
mrNone = System::Int8(0x0),
|
||||
mrOk = System::Int8(0x1),
|
||||
mrCancel = System::Int8(0x2),
|
||||
mrAbort = System::Int8(0x3),
|
||||
mrRetry = System::Int8(0x4),
|
||||
mrIgnore = System::Int8(0x5),
|
||||
mrYes = System::Int8(0x6),
|
||||
mrNo = System::Int8(0x7),
|
||||
mrClose = System::Int8(0x8),
|
||||
mrHelp = System::Int8(0x9),
|
||||
mrTryAgain = System::Int8(0xa),
|
||||
mrContinue = System::Int8(0xb),
|
||||
mrAll = System::Int8(0xc),
|
||||
mrNoToAll = System::Int8(0xd),
|
||||
mrYesToAll = System::Int8(0xe)
|
||||
};
|
||||
|
||||
private:
|
||||
COLORREF
|
||||
clrFrameExNormal,
|
||||
clrFrameExEnter,
|
||||
clrFrameExDisable,
|
||||
clrFrameNormal,
|
||||
clrLineNormal,
|
||||
clrRectNormal,
|
||||
clrRectDisable,
|
||||
clrCapArrowOpenBound[10],
|
||||
clrCapArrowOpenLine[4],
|
||||
clrExFrameBound[4],
|
||||
clrExFrameBoundDisable[4];
|
||||
|
||||
TColor FBorderColor;
|
||||
TColor FInterFrameColor;
|
||||
TColor FInterColor;
|
||||
|
||||
void __fastcall IniColor(int nstate);
|
||||
COLORREF __fastcall TransformColor(COLORREF icolor, int nNum=0, bool bplus=true);
|
||||
void __fastcall SetBorderColor(TColor iBorderColor);
|
||||
void __fastcall SetInterFrameColor(TColor iInterFrameColor);
|
||||
void __fastcall SetInterColor(TColor iInterColor);
|
||||
|
||||
TNotifyEvent FOnMouseEnter;//on mouse enter notify event
|
||||
TNotifyEvent FOnMouseLeave;//on mouse leave notify event
|
||||
|
||||
String FCaption;
|
||||
// System::Uitypes::TModalResult FModalResult;
|
||||
TModalResult FModalResult;
|
||||
|
||||
void __fastcall SetCaption(String Value);
|
||||
|
||||
MESSAGE void __fastcall CMMouseEnter(Winapi::Messages::TMessage &Msg); // to know when mouse is entered
|
||||
MESSAGE void __fastcall CMMouseLeave(Winapi::Messages::TMessage &Msg); // to know when mouse is leaved
|
||||
|
||||
BEGIN_MESSAGE_MAP
|
||||
MESSAGE_HANDLER(CM_MOUSEENTER, TMessage, CMMouseEnter)
|
||||
MESSAGE_HANDLER(CM_MOUSELEAVE, TMessage, CMMouseLeave)
|
||||
END_MESSAGE_MAP(TGraphicControl)
|
||||
|
||||
protected:
|
||||
bool FEnablePNG; //是否加载了png格式图片背景
|
||||
bool FDown; // value to know if we painting mouse down
|
||||
int EtatBtn; // 0=Normal 1=Mouse entered 2=Pressed 3=Disabled
|
||||
int FStateCount;
|
||||
Vcl::Imaging::Pngimage::TPngImage *FPngImg; //our 4 states image
|
||||
|
||||
|
||||
DYNAMIC void __fastcall MouseDown(System::Uitypes::TMouseButton Button, System::Classes::TShiftState Shift, int X, int Y);
|
||||
DYNAMIC void __fastcall MouseUp(System::Uitypes::TMouseButton Button, System::Classes::TShiftState Shift, int X, int Y);
|
||||
virtual void __fastcall SetEnabled(bool Value);
|
||||
|
||||
public:
|
||||
|
||||
__fastcall virtual CBCapButton(System::Classes::TComponent* AOwner);
|
||||
__fastcall virtual ~CBCapButton(void);
|
||||
|
||||
void __fastcall SetStateCount( int count );
|
||||
void __fastcall SetPngImg(Vcl::Imaging::Pngimage::TPngImage *value); // we set the png image
|
||||
void __fastcall SetDown(bool value); // to know if mouse is down or not
|
||||
void __fastcall SetEnablePNG(bool Value);// to know if customer set png img
|
||||
virtual void __fastcall SetFontSize( int value );
|
||||
virtual void __fastcall SetFont( String name, int sz );
|
||||
virtual void __fastcall Paint(void); // override the painting of the component
|
||||
DYNAMIC void __fastcall Click(void);
|
||||
|
||||
__published:
|
||||
|
||||
__property Action;
|
||||
__property Anchors = {default=3};
|
||||
__property bool Down = {read=FDown, write=SetDown, default=False};
|
||||
__property Enabled = {default=1};
|
||||
__property int ImgStates = {read=FStateCount, write=SetStateCount, default=4};
|
||||
// __property System::Uitypes::TModalResult ModalResult = {read=FModalResult, write=FModalResult, default=0};
|
||||
__property TModalResult ModalResult = {read=FModalResult, write=FModalResult, default=0};
|
||||
__property ParentShowHint = {default=1};
|
||||
__property Vcl::Imaging::Pngimage::TPngImage *PngImg = {read=FPngImg, write=SetPngImg};
|
||||
__property PopupMenu;
|
||||
__property ShowHint;
|
||||
__property Visible = {default=1};
|
||||
__property OnClick;
|
||||
__property OnContextPopup;
|
||||
__property OnMouseDown;
|
||||
__property OnMouseMove;
|
||||
__property OnMouseUp;
|
||||
__property System::Classes::TNotifyEvent OnMouseEnter = {read=FOnMouseEnter, write=FOnMouseEnter};
|
||||
__property System::Classes::TNotifyEvent OnMouseLeave = {read=FOnMouseLeave, write=FOnMouseLeave};
|
||||
__property bool EnablePNG = {read=FEnablePNG, write=SetEnablePNG, default=False};
|
||||
__property TColor BorderColor = {read=FBorderColor, write=SetBorderColor, default=TColor(0x83807d)};
|
||||
__property TColor InterFrameColor = {read=FInterFrameColor, write=SetInterFrameColor, default=TColor(0x302e2c)};
|
||||
__property TColor InterColor = {read=FInterColor, write=SetInterColor, default=TColor(0x58504a)};
|
||||
private:
|
||||
Vcl::Imaging::Pngimage::TPngImage *m_pPngButton, *m_pPngFoucusButton;
|
||||
Vcl::Imaging::Pngimage::TPngImage *pTmpDraw, *pTmpFoucusDraw;
|
||||
void __fastcall PaintCustomer(void);
|
||||
void __fastcall PaintCustomerText(void);
|
||||
|
||||
public:
|
||||
TRect rtCaption;
|
||||
|
||||
__published:
|
||||
__property int FontSize = {write=SetFontSize, default=8};
|
||||
__property String Caption = {read=FCaption, write=SetCaption};
|
||||
|
||||
};
|
||||
/**************************************************************************************************/
|
||||
/**************************************************************************************************/
|
||||
class PACKAGE TComboBoxComponent : public CBCapButton
|
||||
{
|
||||
private:
|
||||
TComboBoxChangeEvent FOnChange; // ComboBox变化事件
|
||||
int FItemHeight,
|
||||
FShowItemCount;
|
||||
TComboBoxMode FShowMode;
|
||||
|
||||
TDropListView *m_DropListView; // 定义下拉列表框
|
||||
bool m_IsMouseOver;
|
||||
int m_ClickStat; // .....
|
||||
|
||||
|
||||
void __fastcall DoItemClick(TComboBoxItem *Sender, int Index);
|
||||
|
||||
// 处理下拉列表隐藏、显示事件
|
||||
void __fastcall DoDropListShow(TObject *Sender);
|
||||
void __fastcall DoDropListHide(TObject *Sender);
|
||||
|
||||
int __fastcall GetDefaultItem();
|
||||
int __fastcall GetItemsCount();
|
||||
|
||||
void __fastcall SetDefaultItem(int Value);
|
||||
void __fastcall SetItemHeight(int Value);
|
||||
void __fastcall SetShowItemCount(int Value);
|
||||
void __fastcall SetShowMode(TComboBoxMode Value);
|
||||
|
||||
void __fastcall DoMouseEnter(TObject *Sender);
|
||||
void __fastcall DoMouseLeave(TObject *Sender);
|
||||
|
||||
//MESSAGE void __fastcall CMMouseEnter(TMessage &Message);
|
||||
//MESSAGE void __fastcall CMMouseLeave(TMessage &Message);
|
||||
|
||||
//BEGIN_MESSAGE_MAP
|
||||
// MESSAGE_HANDLER(CM_MOUSEENTER, TMessage, CMMouseEnter)
|
||||
// MESSAGE_HANDLER(CM_MOUSELEAVE, TMessage, CMMouseLeave)
|
||||
//END_MESSAGE_MAP(CBCapButton)
|
||||
|
||||
|
||||
protected:
|
||||
DYNAMIC void __fastcall MouseDown(TMouseButton Button, TShiftState Shift, int X, int Y);
|
||||
DYNAMIC void __fastcall MouseUp(TMouseButton Button, TShiftState Shift, int X, int Y);
|
||||
|
||||
virtual void __fastcall SetParent(TWinControl* AParent);
|
||||
public:
|
||||
__fastcall TComboBoxComponent(TComponent *Owner);
|
||||
__fastcall ~TComboBoxComponent();
|
||||
|
||||
TComboBoxItem * __fastcall AddItem(String Caption);
|
||||
void __fastcall Clear();
|
||||
void __fastcall RemoveItem(int Index);
|
||||
TComboBoxItem * __fastcall GetItem(int Index);
|
||||
virtual void __fastcall SetFontSize( int value );
|
||||
virtual void __fastcall SetFont( String name, int size );
|
||||
__property int DefItemIndex = {read = GetDefaultItem, write = SetDefaultItem};
|
||||
__property int ItemsCount = {read = GetItemsCount};
|
||||
|
||||
__published:
|
||||
__property TComboBoxChangeEvent OnChange = {read = FOnChange, write = FOnChange};
|
||||
|
||||
__property int ItemHeight = {read = FItemHeight, write = SetItemHeight, default = 20};
|
||||
__property int ShowItemCount = {read = FShowItemCount, write = SetShowItemCount, default = 10};
|
||||
__property TComboBoxMode ShowMode = {read = FShowMode, write = SetShowMode, default = cbShowDown};
|
||||
__property TWinControl* Parent = {read=FParent, write=SetParent};
|
||||
};
|
||||
/**************************************************************************************************/
|
||||
/**************************************************************************************************/
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,619 @@
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include "ComboBoxComponent.h"
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
#define CP_ITEM_SLECTED RGB(67, 73, 80)
|
||||
#define CP_ITEM_UNSLECTED RGB(39, 42, 47)
|
||||
//---------------------------------------------------------------------------
|
||||
__fastcall TComboBoxItem::TComboBoxItem(String Caption, TItemClickEvent OnItemClick)
|
||||
{
|
||||
FCaption = Caption;
|
||||
FOnItemClick = OnItemClick;
|
||||
FTag = 0;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TComboBoxItem::DrawItem(TCanvas *Canvas, TRect Rect, bool Selected)
|
||||
{
|
||||
if(Selected)
|
||||
Canvas->Brush->Color = CP_ITEM_SLECTED;
|
||||
else
|
||||
Canvas->Brush->Color = CP_ITEM_UNSLECTED;
|
||||
|
||||
/* 绘制背景 */
|
||||
Canvas->FillRect(Rect);
|
||||
|
||||
/* 绘制文字 */
|
||||
int var_TextRectTop = Rect.Top + (Rect.Height() - Canvas->TextHeight(FCaption)) / 2;
|
||||
|
||||
TRect var_TextRect(4, var_TextRectTop, Rect.Right - 4, Rect.Bottom);
|
||||
|
||||
Canvas->TextRect(var_TextRect, FCaption);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
//---------------------------------------------------------------------------
|
||||
//#define CP_BORDER RGB(29, 31, 35)
|
||||
#define CP_BORDER RGB(106, 111, 117)
|
||||
#define CP_BACKGRND RGB(39, 42, 47)
|
||||
|
||||
#define CP_BORDER_HL RGB(30, 32, 36)
|
||||
#define CP_BACKGRND_HL RGB(67, 73, 80)
|
||||
|
||||
#define CP_TXT_NOR RGB(213, 221, 232)
|
||||
#define CP_TXT_DISABLE RGB(100, 108, 119)
|
||||
#define CP_BREAK RGB(100, 108, 119)
|
||||
#define CP_BOARD_FILL RGB(76, 82, 91)
|
||||
|
||||
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||
#define MAX(x, y) ((x) > (y) ? (x) : (y))
|
||||
//---------------------------------------------------------------------------
|
||||
__fastcall TDropListView::TDropListView(TComponent *Owner) : TWinControl(Owner)
|
||||
{
|
||||
m_Canvas = new TControlCanvas();
|
||||
m_Canvas->Control = this;
|
||||
m_Canvas->Font->Color = RGB(156, 170, 189);
|
||||
|
||||
m_ItemRectList = new TList();
|
||||
m_ItemList = new TList();
|
||||
|
||||
FOnHide = NULL;
|
||||
FOnShow = NULL;
|
||||
|
||||
FItemHeight = 16;
|
||||
FItemWidth = 99;
|
||||
FDefItemIndex = -1;
|
||||
FShowItemsCount = 10;
|
||||
DoShowItemsChange();
|
||||
|
||||
m_CurrentItemIndex = 0;
|
||||
m_RealShowCount = 0;
|
||||
|
||||
m_BeginIndex = 0;
|
||||
|
||||
m_ScrollBar = NULL;
|
||||
|
||||
SetDesignVisible(false);
|
||||
Ctl3D = false;
|
||||
ParentBackground = false;
|
||||
ParentBiDiMode = false;
|
||||
ParentColor = false;
|
||||
ParentCustomHint = false;
|
||||
ParentDoubleBuffered = false;
|
||||
ParentFont = true;
|
||||
ParentShowHint = false;
|
||||
|
||||
CreateScrollBar();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
__fastcall TDropListView::~TDropListView()
|
||||
{
|
||||
if(m_ItemRectList)
|
||||
{
|
||||
delete m_ItemRectList;
|
||||
m_ItemRectList = NULL;
|
||||
}
|
||||
|
||||
if(m_ItemList)
|
||||
{
|
||||
delete m_ItemList;
|
||||
m_ItemList = NULL;
|
||||
}
|
||||
|
||||
if(m_ScrollBar)
|
||||
{
|
||||
delete m_ScrollBar;
|
||||
m_ScrollBar = NULL;
|
||||
}
|
||||
|
||||
if(m_Canvas)
|
||||
{
|
||||
delete m_Canvas;
|
||||
m_Canvas = NULL;
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::AddItem(TComboBoxItem* Item)
|
||||
{
|
||||
m_ItemList->Add(Item);
|
||||
|
||||
DoItemsCountChange();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
int __fastcall TDropListView::CalcListHeight()
|
||||
{
|
||||
if(ItemsCount == 0)
|
||||
return 10;
|
||||
else
|
||||
return FItemHeight * m_RealShowCount;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::Clear()
|
||||
{
|
||||
m_ItemList->Clear();
|
||||
FDefItemIndex = -1;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::CreateParams(TCreateParams &Params)
|
||||
{
|
||||
TWinControl::CreateParams(Params);
|
||||
|
||||
Params.Style = 0;
|
||||
|
||||
Params.Style = WS_POPUP;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::CreateScrollBar()
|
||||
{
|
||||
m_ScrollBar = new TDropListScrollBar(NULL);
|
||||
m_ScrollBar->Parent = this;
|
||||
m_ScrollBar->Visible = false;
|
||||
m_ScrollBar->m_pWndCtrl = this;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::CreateWnd()
|
||||
{
|
||||
TWinControl::CreateWnd();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::SetFontSize(int sz)
|
||||
{
|
||||
m_Canvas->Font->Size = sz;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::SetFont(String name, int sz)
|
||||
{
|
||||
m_Canvas->Font->Name = name;
|
||||
m_Canvas->Font->Size = sz;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::DoItemClicked(int Index)
|
||||
{
|
||||
FDefItemIndex = Index;
|
||||
GetItem(FDefItemIndex)->OnItemClicked(GetItem(FDefItemIndex), FDefItemIndex);
|
||||
Hide();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::DoItemsCountChange()
|
||||
{
|
||||
m_RealShowCount = MIN(FShowItemsCount, ItemsCount);
|
||||
|
||||
m_EndIndex = m_BeginIndex + m_RealShowCount;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::DoItemSelect(int Index)
|
||||
{
|
||||
if(Index != m_CurrentItemIndex)
|
||||
{
|
||||
/* 还原上一次选中项 */
|
||||
if(m_CurrentItemIndex >= m_BeginIndex && m_CurrentItemIndex < m_EndIndex)
|
||||
{
|
||||
GetItem(m_CurrentItemIndex)->DrawItem(m_Canvas,
|
||||
*GetItemRect(m_CurrentItemIndex - m_BeginIndex), false);
|
||||
}
|
||||
/* 更新当前选择项 */
|
||||
m_CurrentItemIndex = Index;
|
||||
/* 重绘选中项 */
|
||||
GetItem(m_CurrentItemIndex)->DrawItem(m_Canvas,
|
||||
*GetItemRect(m_CurrentItemIndex - m_BeginIndex), true);
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::DoKeyUpDown(int Index)
|
||||
{
|
||||
if(Index < m_BeginIndex)
|
||||
{
|
||||
int var_eIndex = Index + 1;
|
||||
|
||||
if(var_eIndex < m_RealShowCount)
|
||||
ScrollPos(0);
|
||||
else
|
||||
ScrollPos(var_eIndex - m_RealShowCount);
|
||||
}
|
||||
|
||||
if(Index >= m_EndIndex)
|
||||
{
|
||||
int var_eIndex = Index + m_RealShowCount;
|
||||
|
||||
if(var_eIndex > ItemsCount)
|
||||
ScrollPos(ItemsCount - m_RealShowCount);
|
||||
else
|
||||
ScrollPos(var_eIndex - m_RealShowCount);
|
||||
}
|
||||
|
||||
DoItemSelect(Index);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::DoShowItemsChange()
|
||||
{
|
||||
m_ItemRectList->Clear();
|
||||
|
||||
for(int i = 0; i < FShowItemsCount; i++)
|
||||
{
|
||||
int var_ItemTop = i * FItemHeight;
|
||||
int var_ItemBottom = var_ItemTop + FItemHeight;
|
||||
|
||||
m_ItemRectList->Add(new TRect(1, var_ItemTop + 1, FItemWidth, var_ItemBottom - 1));
|
||||
}
|
||||
|
||||
DoItemsCountChange();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::Hide()
|
||||
{
|
||||
TWinControl::Hide();
|
||||
|
||||
SetActiveWindow(m_pActiveWnd);
|
||||
|
||||
if(FOnHide) FOnHide(this);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
int __fastcall TDropListView::GetItemsCount()
|
||||
{
|
||||
if(m_ItemList)
|
||||
return m_ItemList->Count;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
TComboBoxItem *__fastcall TDropListView::GetItem(int Index)
|
||||
{
|
||||
if(ItemsCount == 0 || Index < 0 || Index > ItemsCount)
|
||||
return NULL;
|
||||
else
|
||||
return (TComboBoxItem *)m_ItemList->Items[Index];
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
TRect *__fastcall TDropListView::GetItemRect(int Index)
|
||||
{
|
||||
return (TRect *)m_ItemRectList->Items[Index];
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::MouseDown(TMouseButton Button, TShiftState Shift, int X, int Y)
|
||||
{
|
||||
TWinControl::MouseDown(Button, Shift, X, Y);
|
||||
|
||||
TRect cl_Rect = GetClientRect();
|
||||
|
||||
if(X >= 0 && X <= cl_Rect.Right && Y >= 0 && Y <= cl_Rect.Bottom && ItemsCount > 0)
|
||||
{
|
||||
if(Button == 0 && X < FItemWidth)
|
||||
{
|
||||
int var_DefItemIndex = Y / FItemHeight + m_BeginIndex;
|
||||
|
||||
if(m_CurrentItemIndex != var_DefItemIndex)
|
||||
DoItemSelect(var_DefItemIndex);
|
||||
else
|
||||
DoItemClicked(var_DefItemIndex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::MouseMove(TShiftState Shift, int X, int Y)
|
||||
{
|
||||
TWinControl::MouseMove(Shift, X, Y);
|
||||
|
||||
if(m_MouseX == X && m_MouseY == Y) return;
|
||||
|
||||
m_MouseX = X;
|
||||
m_MouseY = Y;
|
||||
|
||||
TRect var_Rect = GetClientRect();
|
||||
|
||||
if(X >= 0 && X < FItemWidth && Y >= 0 && Y < var_Rect.Bottom && ItemsCount > 0)
|
||||
DoItemSelect(Y / FItemHeight + m_BeginIndex);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::MouseUp(TMouseButton Button, TShiftState Shift, int X, int Y)
|
||||
{
|
||||
TWinControl::MouseUp(Button, Shift, X, Y);
|
||||
|
||||
TRect cl_Rect = GetClientRect();
|
||||
|
||||
if(X >= 0 && X <= cl_Rect.Right && Y >= 0 && Y <= cl_Rect.Bottom)
|
||||
{
|
||||
if(Visible && ItemsCount > 0 && Button == 0 && X < FItemWidth)
|
||||
{
|
||||
int var_DefItemIndex = Y / FItemHeight + m_BeginIndex;
|
||||
|
||||
if(m_CurrentItemIndex != var_DefItemIndex)
|
||||
DoItemSelect(var_DefItemIndex);
|
||||
else
|
||||
DoItemClicked(var_DefItemIndex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Visible) Hide();
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::PaintWindow(HDC DC)
|
||||
{
|
||||
if(ItemsCount == 0) return;
|
||||
|
||||
m_Canvas->Lock();
|
||||
for(int Index = m_BeginIndex; Index < m_EndIndex; Index++)
|
||||
{
|
||||
int var_ShowIndex = Index - m_BeginIndex;
|
||||
|
||||
if(Index == m_CurrentItemIndex)
|
||||
GetItem(Index)->DrawItem(m_Canvas, *GetItemRect(var_ShowIndex), true);
|
||||
else
|
||||
GetItem(Index)->DrawItem(m_Canvas, *GetItemRect(var_ShowIndex), false);
|
||||
}
|
||||
m_Canvas->Unlock();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::RemoveItem(int Index)
|
||||
{
|
||||
if(ItemsCount == 0 || Index < 0 || Index > ItemsCount)
|
||||
return;
|
||||
|
||||
if(Index == FDefItemIndex)
|
||||
FDefItemIndex = -1;
|
||||
else if(Index > FDefItemIndex)
|
||||
FDefItemIndex--;
|
||||
|
||||
m_ItemList->Delete(Index);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::ScrollPos(int Pos)
|
||||
{
|
||||
if(Pos >= 0 && Pos < ItemsCount)
|
||||
{
|
||||
int var_bIndex = Pos;
|
||||
int var_eIndex = Pos + m_RealShowCount;
|
||||
|
||||
if(var_eIndex > ItemsCount)
|
||||
{
|
||||
var_eIndex = ItemsCount;
|
||||
var_bIndex = var_eIndex - m_RealShowCount;
|
||||
}
|
||||
|
||||
if(var_bIndex != m_BeginIndex)
|
||||
{
|
||||
m_BeginIndex = var_bIndex;
|
||||
m_EndIndex = var_eIndex;
|
||||
|
||||
PaintWindow(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::SetShowItemsCount(int Value)
|
||||
{
|
||||
if(FShowItemsCount != Value)
|
||||
{
|
||||
FShowItemsCount = Value;
|
||||
|
||||
DoShowItemsChange();
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::Show()
|
||||
{
|
||||
TWinControl::Show();
|
||||
|
||||
m_pActiveWnd = GetActiveWindow();
|
||||
SetActiveWindow(Handle);
|
||||
|
||||
//if(FDefItemIndex == -1)
|
||||
//m_CurrentItemIndex = 0;
|
||||
//else
|
||||
m_CurrentItemIndex = FDefItemIndex;
|
||||
|
||||
if(m_CurrentItemIndex == -1)
|
||||
{
|
||||
m_BeginIndex = 0;
|
||||
m_EndIndex = m_RealShowCount;
|
||||
ScrollPos(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_BeginIndex = m_CurrentItemIndex;
|
||||
m_EndIndex = m_CurrentItemIndex + m_RealShowCount;
|
||||
|
||||
if(m_EndIndex > ItemsCount)
|
||||
{
|
||||
m_EndIndex = ItemsCount;
|
||||
m_BeginIndex = m_EndIndex - m_RealShowCount;
|
||||
}
|
||||
|
||||
if(m_CurrentItemIndex < m_BeginIndex || m_CurrentItemIndex >= m_EndIndex)
|
||||
{
|
||||
int var_eIndex = m_CurrentItemIndex + 1;
|
||||
|
||||
if(var_eIndex < m_RealShowCount)
|
||||
ScrollPos(m_BeginIndex);
|
||||
else
|
||||
ScrollPos(m_EndIndex - m_RealShowCount);
|
||||
}
|
||||
}
|
||||
|
||||
if(ItemsCount == 0)
|
||||
Height = 10;
|
||||
else
|
||||
Height = FItemHeight * m_RealShowCount;
|
||||
|
||||
if(m_ScrollBar)
|
||||
{
|
||||
m_ScrollBar->Height = Height - 2;
|
||||
m_ScrollBar->Left = Width - m_ScrollBar->Width - 1;
|
||||
m_ScrollBar->Top = 1;
|
||||
|
||||
if(m_RealShowCount < ItemsCount)
|
||||
{
|
||||
m_ScrollBar->Visible = true;
|
||||
FItemWidth = m_ScrollBar->Left;
|
||||
m_ScrollBar->SetRange(0, ItemsCount - 1);
|
||||
m_ScrollBar->SetPageSize(m_RealShowCount);
|
||||
m_ScrollBar->SetPosition(m_BeginIndex);
|
||||
DoShowItemsChange();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ScrollBar->Visible = false;
|
||||
FItemWidth = Width - 1;
|
||||
DoShowItemsChange();
|
||||
}
|
||||
}
|
||||
|
||||
if(FOnShow) FOnShow(this);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::WMEraseBkgnd(TWMEraseBkgnd &Message)
|
||||
{
|
||||
TCanvas* var_BKCanvas = new TCanvas();
|
||||
var_BKCanvas->Handle = Message.DC;
|
||||
|
||||
TRect var_Rect = GetClientRect();
|
||||
|
||||
var_BKCanvas->Brush->Color = CP_BACKGRND; // 绘制底色
|
||||
var_BKCanvas->FillRect(var_Rect);
|
||||
|
||||
var_BKCanvas->Brush->Color = CP_BORDER; // 绘制边框
|
||||
var_BKCanvas->FrameRect(var_Rect);
|
||||
|
||||
delete var_BKCanvas;
|
||||
var_BKCanvas = NULL;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::WMKeyDown(TWMKeyDown &Message)
|
||||
{
|
||||
if(ItemsCount == 0) return;
|
||||
|
||||
if(Message.CharCode == VK_UP)
|
||||
{
|
||||
int var_Index = m_CurrentItemIndex - 1;
|
||||
if(var_Index < 0) var_Index = 0;
|
||||
|
||||
DoKeyUpDown(var_Index);
|
||||
}
|
||||
else if(Message.CharCode == VK_DOWN)
|
||||
{
|
||||
int var_Index = m_CurrentItemIndex + 1;
|
||||
if(var_Index >= ItemsCount) var_Index = ItemsCount - 1;
|
||||
|
||||
DoKeyUpDown(var_Index);
|
||||
}
|
||||
else if(Message.CharCode == VK_ESCAPE)
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
else if(Message.CharCode == VK_RETURN)
|
||||
{
|
||||
DoItemClicked(m_CurrentItemIndex);
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::WMKillFocus(TMessage &Message)
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::WMLButtonDown(TWMLButtonDown &Message)
|
||||
{
|
||||
TWinControl::Dispatch(&Message);
|
||||
|
||||
if(m_ScrollBar)
|
||||
{
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::WMMouseWheel(TWMMouseWheel &Message)
|
||||
{
|
||||
UINT nSBCode;
|
||||
|
||||
if(Message.WheelDelta < 0)
|
||||
{
|
||||
nSBCode = SB_LINEDOWN;
|
||||
}
|
||||
else
|
||||
{
|
||||
nSBCode = SB_LINEUP;
|
||||
}
|
||||
|
||||
if(m_ScrollBar->Visible)
|
||||
Perform(WM_VSCROLL, MAKELONG(nSBCode, 0), NULL);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::WMPaint(TWMPaint &Message)
|
||||
{
|
||||
PaintHandler(Message);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::WMSetFocus(TMessage &Message)
|
||||
{
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TDropListView::WMVScroll(TWMScroll &Message)
|
||||
{
|
||||
int minpos, maxpos, page, curpos;
|
||||
|
||||
m_ScrollBar->GetScrollRange(& minpos, & maxpos);
|
||||
|
||||
page = m_ScrollBar->GetPageSize();
|
||||
curpos = m_ScrollBar->GetScrollPos();
|
||||
|
||||
switch(Message.ScrollCode)
|
||||
{
|
||||
case SB_TOP:
|
||||
curpos = minpos;
|
||||
break;
|
||||
|
||||
case SB_BOTTOM:
|
||||
curpos = maxpos - page + 1;
|
||||
break;
|
||||
|
||||
case SB_ENDSCROLL:
|
||||
break;
|
||||
|
||||
case SB_LINEUP:
|
||||
if(curpos > minpos)
|
||||
{
|
||||
curpos--;
|
||||
}
|
||||
break;
|
||||
|
||||
case SB_LINEDOWN:
|
||||
if(curpos < maxpos - page + 1)
|
||||
{
|
||||
curpos++;
|
||||
}
|
||||
break;
|
||||
|
||||
case SB_PAGEUP:
|
||||
if(curpos > minpos)
|
||||
{
|
||||
curpos = MAX(minpos, curpos - page);
|
||||
}
|
||||
break;
|
||||
|
||||
case SB_PAGEDOWN:
|
||||
if(curpos < maxpos)
|
||||
{
|
||||
curpos = MIN(maxpos - page + 1, curpos + page);
|
||||
}
|
||||
break;
|
||||
|
||||
case SB_THUMBPOSITION:
|
||||
curpos = Message.Pos;
|
||||
break;
|
||||
|
||||
case SB_THUMBTRACK:
|
||||
curpos = Message.Pos;
|
||||
break;
|
||||
}
|
||||
|
||||
if(Message.ScrollBar != m_ScrollBar->Handle)
|
||||
{
|
||||
m_ScrollBar->SetPosition(curpos);
|
||||
}
|
||||
|
||||
ScrollPos(curpos);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -0,0 +1,17 @@
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include <System.hpp>
|
||||
#pragma hdrstop
|
||||
#pragma package(smart_init)
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Package source.
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
#pragma argsused
|
||||
extern "C" int _libmain(unsigned long reason)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user