Files
2026-06-13 00:05:19 +08:00

140 lines
5.3 KiB
C++

//---------------------------------------------------------------------------
#ifndef CapButtonH
#define CapButtonH
//---------------------------------------------------------------------------
#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 PACKAGE TCapButton : 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);
private:
String FCaption;
TNotifyEvent FOnMouseEnter;//on mouse enter notify event
TNotifyEvent FOnMouseLeave;//on mouse leave notify event
// System::Uitypes::TModalResult FModalResult;
TModalResult FModalResult;
int __fastcall GetFontSize();
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 TCapButton(System::Classes::TComponent* AOwner);
__fastcall virtual ~TCapButton(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
void __fastcall SetCaption(String Value);
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;
void __fastcall SetFontSize( int value );
void __fastcall SetFont(String name, int size );
__published:
__property String Caption = {read=FCaption, write=FCaption};
__property int FontSize = {read=GetFontSize, write=SetFontSize, default=8};
};
//---------------------------------------------------------------------------
#endif