📄 sxskincheckbox.pas
字号:
unit SXSkinCheckBox;
////////////////////////////////////////////////////////////////////////////////
// SXSkinComponents: Skinnable Visual Controls for Delphi and C++Builder //
//----------------------------------------------------------------------------//
// Version: 1.2.1 //
// Author: Alexey Sadovnikov //
// Web Site: http://www.saarixx.info/sxskincomponents/ //
// E-Mail: sxskincomponents@saarixx.info //
//----------------------------------------------------------------------------//
// LICENSE: //
// 1. You may freely distribute this file. //
// 2. You may not make any changes to this file. //
// 3. The only person who may change this file is Alexey Sadovnikov. //
// 4. You may use this file in your freeware projects. //
// 5. If you want to use this file in your shareware or commercial project, //
// you should purchase a project license or a personal license of //
// SXSkinComponents: http://saarixx.info/sxskincomponents/en/purchase.htm //
// 6. You may freely use, distribute and modify skins for SXSkinComponents. //
// 7. You may create skins for SXSkinComponents. //
//----------------------------------------------------------------------------//
// Copyright (C) 2006-2007, Alexey Sadovnikov. All Rights Reserved. //
////////////////////////////////////////////////////////////////////////////////
interface
{$I Compilers.inc}
uses Windows, Classes, SXSkinControl, GR32, StdCtrls, Dialogs, SysUtils,
Messages, Controls, GR32_Blend, SXSkinLibrary, Types, Graphics;
const
VARCB_W = 1;
VARCB_H = 2;
VARCB_GlX = 3;
VARCB_GlY = 4;
VARCB_GlW = 5;
VARCB_GlH = 6;
VARCB_TL = 7;
VARCB_TT = 8;
VARCB_TR = 9;
VARCB_TB = 10;
type
TSXSkinCustomCheckBox=class;
TSXSkinCustomCheckBoxThread=class(TThread)
public
Control:TSXSkinCustomCheckBox;
constructor Create;
procedure Execute; override;
procedure DoEvent;
end;
TSXSkinCheckBoxResetParam=(cbrpText,
cbrpTextOnFontChange,
cbrpTextIfWordWrap,
cbrpGlyph,
cbrpGlyphOnStyleChange,
cbrpGlyphOnSizeChange,
cbrpInvalidateOnStyleChange);
TSXSkinCheckBoxResetParams=set of TSXSkinCheckBoxResetParam;
TSXSkinCheckBoxTransform=(cbtCheckBox,cbtGlyph);
TSXCheckBoxVariableComparer=class(TSXVariableComparer)
private
Control:TSXSkinCustomCheckBox;
function GetValue(VarID:Integer):Integer;
protected
function VarListOnGetVariable(const VarName:String;var Error:Boolean):Single; override;
public
function GetVarValsForVarList(VarList:TList):TList; override;
function Changed(VarList:TList;OldVarVals:TList):Boolean; override;
procedure Update(VarList:TList;VarVals:TList); override;
procedure DestroyVarList(VarList:TList); override;
procedure DestroyVarVals(VarList:TList;VarVals:TList); override;
end;
TSXSkinCustomCheckBox=class(TSXSkinCustomControl)
private
FGlyphPosition:TSXGlyphPosition;
FAllowGrayed:Boolean;
FAutoSizeWidth:Boolean;
FAutoSizeHeight:Boolean;
FAutoAlignFirstLine:Boolean;
FState:TCheckBoxState;
FWordWrap:Boolean;
FTextOffset:Integer;
FAlignment:TAlignment;
FVerticalAlignment:TVerticalAlignment;
FOnChange:TNotifyEvent;
FOnUserModified:TNotifyEvent;
FOnMouseEnter:TNotifyEvent;
FOnMouseLeave:TNotifyEvent;
FMouseOver:Boolean;
FDown:Boolean;
FThread:TSXSkinCustomCheckBoxThread;
//
FLastCheckBoxTransform:TSXTransformEffectData;
FLastGlyphTransform:TSXTransformEffectData;
FDoneSteps:Integer;
FLastGlyph:TBitmap32;
FLastCheckBox:TBitmap32;
//
FGlyphRect:TRect;
FGlyphWidth:Integer;
FGlyphHeight:Integer;
FTextRect:TRect;
FLastFocused:Boolean;
FTextBitmap:TBitmap32;
FLastFontData:TSXFontData;
FLastStyle:String;
FLastOverStyle:String;
FLastGlyphStyle:String;
FLastTextLeftOffset:Integer;
FLastTextTopOffset:Integer;
FLastTextRightOffset:Integer;
FLastTextBottomOffset:Integer;
//
CEID_Back:Integer;
CEID_Glyph:Integer;
VComparer:TSXCheckBoxVariableComparer;
function GetChecked:Boolean;
procedure SetCaption(const Value:TCaption);
procedure SetAutoAlignFirstLine(Value:Boolean);
procedure SetAlignment(Value:TAlignment);
procedure SetVerticalAlignment(Value:TVerticalAlignment);
procedure SetGlyphPosition(Value:TSXGlyphPosition);
procedure SetState(Value:TCheckBoxState);
procedure SetAllowGrayed(Value:Boolean);
procedure SetAutoSizeWidth(Value:Boolean);
procedure SetAutoSizeHeight(Value:Boolean);
procedure SetChecked(Value:Boolean);
procedure SetWordWrap(Value:Boolean);
procedure SetTextOffset(Value:Integer);
function HasUnusualSkinStyle:Boolean;
function OnGetVariable(const VarName:String;var Error:Boolean):Single;
procedure GetCurrentCBState(var CBState:TSXSkinCheckBoxStateParam);
function CreateCurrentGlyph:TBitmap32;
function CreateCurrentBlendedGlyph:TBitmap32;
procedure DoThreadActions;
procedure StartGlyphChanging(T:TSXGlyphChangeAction);
procedure CreateThreadIfNeeded;
procedure ResetCheckBoxParams(Params:TSXSkinCheckBoxResetParams=[]);
procedure CMFontChanged(var Message:TMessage); message CM_FONTCHANGED;
procedure InvalidateGlyph;
procedure GetCurrentTransformEffect(T:TSXSkinCheckBoxTransform;
Action:TSXGlyphChangeAction;var Effect:TSXTransformEffectData);
procedure InternalMouseEnter;
procedure InternalMouseLeave;
protected
function CapturesMouseAt(X,Y:Integer):Boolean; override;
procedure SetEnabled(Value:Boolean); override;
procedure Loaded; override;
procedure InternalSetBounds(ALeft,ATop,AWidth,AHeight:Integer);
function GetCaption:TCaption;
procedure DoClick;
procedure MouseLeave; override;
procedure MouseMove(Shift:TShiftState;X,Y:Integer); override;
procedure MouseDown(Button:TMouseButton;Shift:TShiftState;X,Y:Integer); override;
procedure MouseUp(Button:TMouseButton;Shift:TShiftState;X,Y:Integer); override;
procedure DoKeyDown(var Msg:TMessage); message CN_KEYDOWN;
procedure DoKeyUp(var Msg:TMessage); message CN_KEYUP;
procedure WMSetFocus(var Msg:TWMSetFocus); message WM_SETFOCUS;
procedure WMKillFocus(var Msg:TWMKillFocus); message WM_KILLFOCUS;
procedure PaintCurrentCBStyle(Bitmap:TBitmap32;X,Y:Integer;Rect:TRect;Rgn:HRGN);
procedure PaintCurrentBlendedCBStyle(Bitmap:TBitmap32;X,Y:Integer;Rect:TRect;Rgn:HRGN);
procedure PaintCurrentOverStyleCaptionToBitmap(DestCanvasHandle:HDC;
DestCanvasRect:TRect;Rect:TRect;Rgn:HRGN;Bitmap:TBitmap32;X,Y:Integer);
property Caption:TCaption read GetCaption write SetCaption;
property GlyphPosition:TSXGlyphPosition read FGlyphPosition write SetGlyphPosition default gpLeftTop;
property TextOffset:Integer read FTextOffset write SetTextOffset default 2;
property AllowGrayed:Boolean read FAllowGrayed write SetAllowGrayed default False;
property State:TCheckBoxState read FState write SetState default cbUnchecked;
property Checked:Boolean read GetChecked write SetChecked stored False;
property WordWrap:Boolean read FWordWrap write SetWordWrap default False;
property AutoSizeWidth:Boolean read FAutoSizeWidth write SetAutoSizeWidth default True;
property AutoSizeHeight:Boolean read FAutoSizeHeight write SetAutoSizeHeight default True;
property AutoAlignFirstLine:Boolean read FAutoAlignFirstLine write SetAutoAlignFirstLine default True;
property Alignment:TAlignment read FAlignment write SetAlignment default taLeftJustify;
property VerticalAlignment:TVerticalAlignment read FVerticalAlignment write SetVerticalAlignment default taAlignTop;
property SkinStyle stored HasUnusualSkinStyle;
public
function IsTransparent(X,Y:Integer;Limit:Integer=10):Boolean; override;
procedure PaintRectToBitmap(DestCanvasHandle:HDC;DestCanvasRect:TRect;
Rect:TRect;Rgn:HRGN;Bitmap:TBitmap32;X,Y:Integer;
WithSubItems:Boolean); override;
procedure SetBounds(ALeft,ATop,AWidth,AHeight:Integer); override;
procedure SkinChanged; override;
procedure Click; reintroduce;
constructor Create(AOwner:TComponent); override;
destructor Destroy; override;
published
property TabStop default True;
property OnChange:TNotifyEvent read FOnChange write FOnChange;
property OnUserModified:TNotifyEvent read FOnUserModified write FOnUserModified;
property OnMouseEnter:TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave:TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
end;
TSXSkinCheckBox=class(TSXSkinCustomCheckBox)
published
property Align;
property Alignment;
property AllowGrayed;
property Anchors;
property AutoAlignFirstLine;
property AutoSizeWidth;
property AutoSizeHeight;
property Caption;
property Checked;
property Color;
property Constraints;
property Cursor;
property DragCursor;
property Enabled;
property Font;
property GlyphPosition;
//property HintData;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property SkinLibrary;
property SkinStyle;
property State;
property TabOrder;
property TabStop default True;
property TextOffset;
property VerticalAlignment;
property Visible;
property WordWrap;
property OnCanResize;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnResize;
property OnStartDrag;
property OnUserModified;
end;
implementation
uses Math, SXBitmap32Utils;
{ TSXSkinCustomCheckBoxThread }
constructor TSXSkinCustomCheckBoxThread.Create;
begin
inherited Create(True);
FreeOnTerminate:=False;
end;
procedure TSXSkinCustomCheckBoxThread.Execute;
begin
while not Terminated do
begin
SleepEx(30,True);
if not Suspended then
Synchronize(DoEvent);
end;
end;
procedure TSXSkinCustomCheckBoxThread.DoEvent;
begin
if Assigned(Control) then
Control.DoThreadActions;
end;
{ TSXCheckBoxVariableComparer }
function TSXCheckBoxVariableComparer.VarListOnGetVariable(const VarName:String;var Error:Boolean):Single;
var CurVarVal:Integer;
begin
Result:=1234;
CurVarVal:=-1;
if VarName='W' then
CurVarVal:=VARCB_W else
if VarName='H' then
CurVarVal:=VARCB_H else
if VarName='GlX' then
CurVarVal:=VARCB_GlX else
if VarName='GlY' then
CurVarVal:=VARCB_GlY else
if VarName='GlW' then
CurVarVal:=VARCB_GlW else
if VarName='GlH' then
CurVarVal:=VARCB_GlH else
if VarName='TL' then
CurVarVal:=VARCB_TL else
if VarName='TT' then
CurVarVal:=VARCB_TT else
if VarName='TR' then
CurVarVal:=VARCB_TR else
if VarName='TB' then
CurVarVal:=VARCB_TB;
if CurVarVal>=0 then
begin
if CurValList=nil then
CurValList:=TList.Create;
CurValList.Add(Pointer(CurVarVal));
end;
end;
function TSXCheckBoxVariableComparer.GetValue(VarID:Integer):Integer;
begin
Result:=0;
if Control<>nil then
begin
case VarID of
VARCB_W: Result:=Control.Width;
VARCB_H: Result:=Control.Height;
VARCB_GlX: Result:=Control.FGlyphRect.Left;
VARCB_GlY: Result:=Control.FGlyphRect.Top;
VARCB_GlW: Result:=Control.FGlyphWidth;
VARCB_GlH: Result:=Control.FGlyphHeight;
VARCB_TL: Result:=Control.FTextRect.Left;
VARCB_TT: Result:=Control.FTextRect.Top;
VARCB_TR: Result:=Control.FTextRect.Right;
VARCB_TB: Result:=Control.FTextRect.Bottom;
end;
end;
end;
function TSXCheckBoxVariableComparer.GetVarValsForVarList(VarList:TList):TList;
var A:Integer;
begin
if VarList=nil then
begin
Result:=nil;
exit;
end;
Result:=TList.Create;
for A:=0 to VarList.Count-1 do
Result.Add(Pointer(GetValue(Integer(VarList[A]))));
end;
function TSXCheckBoxVariableComparer.Changed(VarList:TList;OldVarVals:TList):Boolean;
var A:Integer;
begin
Result:=False;
if VarList=nil then exit;
for A:=0 to VarList.Count-1 do
if Integer(OldVarVals[A])<>GetValue(Integer(VarList[A])) then
begin
Result:=True;
exit;
end;
end;
procedure TSXCheckBoxVariableComparer.Update(VarList:TList;VarVals:TList);
var A:Integer;
begin
if VarList=nil then exit;
for A:=0 to VarList.Count-1 do
VarVals[A]:=Pointer(GetValue(Integer(VarList[A])));
end;
procedure TSXCheckBoxVariableComparer.DestroyVarList(VarList:TList);
begin
VarList.Free;
end;
procedure TSXCheckBoxVariableComparer.DestroyVarVals(VarList:TList;VarVals:TList);
begin
VarVals.Free;
end;
{ TSXSkinCustomCheckBox }
function TSXSkinCustomCheckBox.HasUnusualSkinStyle:Boolean;
begin
Result:=SkinStyle<>'_CheckBox';
end;
function TSXSkinCustomCheckBox.GetChecked:Boolean;
begin
Result:=State<>cbUnchecked;
end;
procedure TSXSkinCustomCheckBox.SetEnabled(Value:Boolean);
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -