📄 lbctrls.pas
字号:
unit LBCtrls;
interface
uses
SysUtils, Windows, Classes, Controls, StdCtrls, Messages,
Forms, Graphics, LBUtils, Buttons, ExtCtrls, ImgList,
CommCtrl, Themes, ActnList;
type
TButStyle=(cbsXp, cbsLine);
TLBEdit = class(TCustomEdit)
private
FParentColor: Boolean;
FBorderColor: TColor;
MouseInControl: Boolean;
FEnterTab : Boolean;
procedure SetColors (Index: Integer; Value: TColor);
procedure SetEnterTab(Value: Boolean);
procedure SetParentColor (Value: Boolean);
procedure RedrawBorder (const Clip: HRGN);
procedure NewAdjustHeight;
procedure CMEnabledChanged (var Message: TMessage); message CM_ENABLEDCHANGED;
procedure CMFontChanged (var Message: TMessage); message CM_FONTCHANGED;
procedure CMMouseEnter (var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave (var Message: TMessage); message CM_MOUSELEAVE;
procedure WMSetFocus (var Message: TWMSetFocus); message WM_SETFOCUS;
procedure WMKillFocus (var Message: TWMKillFocus); message WM_KILLFOCUS;
procedure WMNCCalcSize (var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
procedure WMNCPaint (var Message: TMessage); message WM_NCPAINT;
procedure CMSysColorChange (var Message: TMessage); message CM_SYSCOLORCHANGE;
procedure CMParentColorChanged (var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
protected
procedure Loaded; override;
public
constructor Create (AOwner: TComponent); override;
published
property ColorBorder: TColor index 1 read FBorderColor write SetColors default clBackground;
property ParentColor: Boolean read FParentColor write SetParentColor default false;
property EnterTob: Boolean read FEnterTab write SetEnterTab default True;
property Align;
property CharCase;
property Color;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property MaxLength;
property OEMConvert;
property ParentFont;
property ParentShowHint;
property PasswordChar;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Text;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
end;
TLBNumberEdit=class(TLBEdit)
private
FDecimalPlaces: Integer;
FDisplayFormat: string;
FMaxValue: Double;
FMinValue: Double;
function GetValue: Double;
function IsDisplayFormatStored: Boolean;
function IsMaxValueStored: Boolean;
function IsMinValueStored: Boolean;
function IsValueStored: Boolean;
procedure SetDisplayFormat(const Value: string);
procedure SetMaxValue(Value: Double);
procedure SetMinValue(Value: Double);
procedure SetValue(Value: Double);
procedure WMPaste(var Message: TWMPaste); message WM_PASTE;
procedure CMWinIniChange(var Message: TWMWinIniChange); message CM_WININICHANGE;
protected
procedure KeyPress(var Key: Char); override;
function IsValidChar(Key: Char): Boolean; virtual;
procedure SetEditDisplayFormat(const Value: string); virtual;
procedure SetEditMaxValue(Value: Double); virtual;
procedure SetEditMinValue(Value: Double); virtual;
procedure SetEditMinMaxValues(AMinValue, AMaxValue: Double); virtual;
class function StrToFloatEx(const S: string; var Value: Double): Boolean;
property DecimalPlaces: Integer read FDecimalPlaces write FDecimalPlaces default 2;
property DisplayFormat: string read FDisplayFormat write SetDisplayFormat stored IsDisplayFormatStored;
public
constructor Create(AOwner: TComponent); override;
function DefaultDisplayFormat: string; virtual;
function DefaultMaxValue: Double; virtual;
function DefaultMinValue: Double; virtual;
procedure SetMinMaxValues(AMinValue, AMaxValue: Double);
published
property MaxValue: Double read FMaxValue write SetMaxValue stored IsMaxValueStored;
property MinValue: Double read FMinValue write SetMinValue stored IsMinValueStored;
property Value: Double read GetValue write SetValue stored IsValueStored;
end;
TLBComboBox = class(TCustomComboBox)
private
FArrowColor: TColor;
FBorderColor: TColor;
FButtonColor: TColor;
FButtonWidth: Integer;
FChildHandle: HWND;
FDefListProc: Pointer;
FListHandle: HWND;
FListInstance: Pointer;
FSysBtnWidth: Integer;
FSolidBorder: Boolean;
FButStyle: TButStyle;
procedure SetColors (Index: Integer; Value: TColor);
function GetButtonRect: TRect;
procedure PaintButton;
procedure PaintBorder;
procedure RedrawBorders;
procedure InvalidateSelection;
function GetSolidBorder: Boolean;
procedure SetSolidBorder;
procedure ListWndProc (var Message: TMessage);
procedure WMSetFocus (var Message: TMessage); message WM_SETFOCUS;
procedure WMKillFocus (var Message: TMessage); message WM_KILLFOCUS;
procedure WMKeyDown (var Message: TMessage); message WM_KEYDOWN;
procedure WMPaint (var Message: TWMPaint); message WM_PAINT;
procedure WMNCPaint (var Message: TMessage); message WM_NCPAINT;
procedure CMEnabledChanged (var Msg: TMessage); message CM_ENABLEDCHANGED;
procedure CNCommand (var Message: TWMCommand); message CN_COMMAND;
procedure CMFontChanged (var Message: TMessage); message CM_FONTCHANGED;
procedure CMSysColorChange (var Message: TMessage); message CM_SYSCOLORCHANGE;
procedure CMParentColorChanged (var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
protected
procedure WndProc (var Message: TMessage); override;
procedure ComboWndProc (var Message: TMessage; ComboWnd: HWnd; ComboProc: Pointer); override;
property SolidBorder: Boolean read FSolidBorder;
public
constructor Create (AOwner: TComponent); override;
destructor Destroy; override;
published
property Style;
property Color;
property ArrowColor: TColor read FArrowColor write FArrowColor;
property ColorBorder: TColor index 2 read FBorderColor write SetColors default clBackground;
property ButtonColor: TColor read FButtonColor write FButtonColor;
property ButStyle: TButStyle read FButStyle write FButStyle;
property DragMode;
property DragCursor;
property DropDownCount;
property Enabled;
property Font;
property ItemHeight;
property Items;
property MaxLength;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Sorted;
property TabOrder;
property TabStop;
property Text;
property Visible;
property ItemIndex;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDrawItem;
property OnDropDown;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMeasureItem;
property OnStartDrag;
end;
TLBButton = class(TCustomControl)
private
FGroupIndex: Integer;
FModalResult: TModalResult;
TextBounds: TRect;
FDown: Boolean;
FDragging: Boolean;
FAllowAllUp: Boolean;
FLayout: TButtonLayout;
FSpacing: Integer;
FMargin: Integer;
FMouseInControl: Boolean;
procedure SetDown (Value: Boolean);
procedure SetAllowAllUp (Value: Boolean);
procedure SetLayout (Value: TButtonLayout);
procedure SetGroupIndex (Value: Integer);
procedure SetSpacing (Value: Integer);
procedure SetMargin (Value: Integer);
procedure UpdateTracking;
procedure WMLButtonDblClk (var Message: TWMLButtonDown); message WM_LBUTTONDBLCLK;
procedure CMEnabledChanged (var Message: TMessage); message CM_ENABLEDCHANGED;
procedure CMDialogChar (var Message: TCMDialogChar); message CM_DIALOGCHAR;
procedure CMFontChanged (var Message: TMessage); message CM_FONTCHANGED;
procedure CMTextChanged (var Message: TMessage); message CM_TEXTCHANGED;
procedure RemoveMouseTimer;
procedure MouseTimerHandler (Sender: TObject);
protected
FState: TButtonState;
procedure Loaded; override;
procedure MouseDown (Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove (Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp (Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure Paint; override;
public
constructor Create (AOwner: TComponent); override;
destructor Destroy; override;
procedure Click; override;
procedure MouseEnter;
procedure MouseLeave;
published
property AllowAllUp: Boolean read FAllowAllUp write SetAllowAllUp default False;
property Down: Boolean read FDown write SetDown default False;
property Caption;
property Enabled;
property Font;
property Layout: TButtonLayout read FLayout write SetLayout default blGlyphTop;
property Margin: Integer read FMargin write SetMargin default -1;
property GroupIndex: Integer read FGroupIndex write SetGroupIndex default 0;
property ParentFont;
property ParentColor;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Spacing: Integer read FSpacing write SetSpacing default 4;
property ModalResult: TModalResult read FModalResult write FModalResult default 0;
property TabStop;
property TabOrder;
property Visible;
property OnClick;
property OnDblClick;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
end;
TLBLabel = class(TLabel)
private
FMouseInControl: Boolean;
FMouseInColor : TColor;
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
procedure SetMouseInColor (value :TColor);
function GetMouseInColor : TColor;
protected
procedure DoDrawText(var Rect: TRect; Flags: Longint); override;
public
constructor Create(AOwner: TComponent); override;
procedure Paint; override;
published
property MouseInColor : TColor read GetMouseInColor write SetMouseInColor;
property Action;
end;
TGlyphList = class(TImageList)
private
Used: TBits;
FCount: Integer;
function AllocateIndex: Integer;
public
constructor CreateSize(AWidth, AHeight: Integer);
destructor Destroy; override;
function AddMasked(Image: TBitmap; MaskColor: TColor): Integer;
procedure Delete(Index: Integer);
property Count: Integer read FCount;
end;
TGlyphCache = class
private
GlyphLists: TList;
public
constructor Create;
destructor Destroy; override;
function GetList(AWidth, AHeight: Integer): TGlyphList;
procedure ReturnList(List: TGlyphList);
function Empty: Boolean;
end;
TButtonGlyph = class
private
FOriginal: TBitmap;
FGlyphList: TGlyphList;
FIndexs: array[TButtonState] of Integer;
FTransparentColor: TColor;
FNumGlyphs: TNumGlyphs;
FOnChange: TNotifyEvent;
procedure GlyphChanged(Sender: TObject);
procedure SetGlyph(Value: TBitmap);
procedure SetNumGlyphs(Value: TNumGlyphs);
procedure Invalidate;
function CreateButtonGlyph(State: TButtonState): Integer;
procedure DrawButtonGlyph(Canvas: TCanvas; const GlyphPos: TPoint;
State: TButtonState; Transparent: Boolean);
procedure DrawButtonText(Canvas: TCanvas; const Caption: string;
TextBounds: TRect; State: TButtonState; BiDiFlags: Longint);
procedure CalcButtonLayout(Canvas: TCanvas; const Client: TRect;
const Offset: TPoint; const Caption: string; Layout: TButtonLayout;
Margin, Spacing: Integer; var GlyphPos: TPoint; var TextBounds: TRect;
BiDiFlags: Longint);
public
constructor Create;
destructor Destroy; override;
{ return the text rectangle }
function Draw(Canvas: TCanvas; const Client: TRect; const Offset: TPoint;
const Caption: string; Layout: TButtonLayout; Margin, Spacing: Integer;
State: TButtonState; Transparent: Boolean; BiDiFlags: Longint): TRect;
property Glyph: TBitmap read FOriginal write SetGlyph;
property NumGlyphs: TNumGlyphs read FNumGlyphs write SetNumGlyphs;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
end;
TLBBarButtonStyle = (tbsButton, tbsCheck, tbsDropDown, tbsSeparator, tbsDivider);
TLBSpeecButton = class(TGraphicControl)
private
FGroupIndex: Integer;
FGlyph: Pointer;
FDown: Boolean;
FDragging: Boolean;
FAllowAllUp: Boolean;
FLayout: TButtonLayout;
FSpacing: Integer;
FTransparent: Boolean;
FMargin: Integer;
FFlat: Boolean;
FMouseInControl: Boolean;
FStyle: TLBBarButtonStyle;
procedure GlyphChanged(Sender: TObject);
procedure UpdateExclusive;
function GetGlyph: TBitmap;
procedure SetGlyph(Value: TBitmap);
function GetNumGlyphs: TNumGlyphs;
procedure SetNumGlyphs(Value: TNumGlyphs);
procedure SetDown(Value: Boolean);
procedure SetFlat(Value: Boolean);
procedure SetAllowAllUp(Value: Boolean);
procedure SetGroupIndex(Value: Integer);
procedure SetLayout(Value: TButtonLayout);
procedure SetSpacing(Value: Integer);
procedure SetTransparent(Value: Boolean);
procedure SetMargin(Value: Integer);
procedure UpdateTracking;
procedure WMLButtonDblClk(var Message: TWMLButtonDown); message WM_LBUTTONDBLCLK;
procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
procedure CMButtonPressed(var Message: TMessage); message CM_BUTTONPRESSED;
procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
protected
FState: TButtonState;
procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
function GetActionLinkClass: TControlActionLinkClass; override;
function GetPalette: HPALETTE; override;
procedure Loaded; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure Paint; override;
property MouseInControl: Boolean read FMouseInControl;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Click; override;
published
property Action;
property AllowAllUp: Boolean read FAllowAllUp write SetAllowAllUp default False;
property Anchors;
property BiDiMode;
property Constraints;
property GroupIndex: Integer read FGroupIndex write SetGroupIndex default 0;
property Down: Boolean read FDown write SetDown default False;
property Caption;
property Enabled;
property Flat: Boolean read FFlat write SetFlat default False;
property Font;
property Glyph: TBitmap read GetGlyph write SetGlyph;
property Layout: TButtonLayout read FLayout write SetLayout default blGlyphLeft;
property Margin: Integer read FMargin write SetMargin default -1;
property NumGlyphs: TNumGlyphs read GetNumGlyphs write SetNumGlyphs default 1;
property ParentFont;
property ParentShowHint;
property ParentBiDiMode;
property PopupMenu;
property ShowHint;
property Spacing: Integer read FSpacing write SetSpacing default 4;
property Style: TLBBarButtonStyle read FStyle write FStyle;
property Transparent: Boolean read FTransparent write SetTransparent default True;
property Visible;
property OnClick;
property OnDblClick;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
end;
TLBCheckBox = class(TCustomControl)
private
FMouseInControl: Boolean;
Focused: Boolean;
FChecked: Boolean;
procedure SetChecked (Value: Boolean);
procedure CMMouseEnter (var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave (var Message: TMessage); message CM_MOUSELEAVE;
procedure CMEnabledChanged (var Message: TMessage); message CM_ENABLEDCHANGED;
procedure CMTextChanged (var Message: TWmNoParams); message CM_TEXTCHANGED;
procedure CMDialogChar (var Message: TCMDialogChar); message CM_DIALOGCHAR;
procedure CNCommand (var Message: TWMCommand); message CN_COMMAND;
procedure WMSetFocus (var Message: TWMSetFocus); message WM_SETFOCUS;
procedure WMKillFocus (var Message: TWMKillFocus); message WM_KILLFOCUS;
procedure CMSysColorChange (var Message: TMessage); message CM_SYSCOLORCHANGE;
procedure CMParentColorChanged (var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
protected
procedure DoEnter; override;
procedure DoExit; override;
procedure MouseDown (Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp (Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove (Shift: TShiftState; X, Y: Integer); override;
procedure CreateWnd; override;
procedure DrawCheckRect;virtual;
procedure DrawCheckText;
procedure Paint; override;
public
constructor Create (AOwner: TComponent); override;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -