ksskinbuttons.pas
来自「小区水费管理系统源代码水费收费管理系统 水费收费管理系统」· PAS 代码 · 共 298 行
PAS
298 行
{==============================================================================
SkinEngine's Buttons
Copyright (C) 2000-2002 by Evgeny Kryukov
All rights reserved
All conTeThements of this file and all other files included in this archive
are Copyright (C) 2002 Evgeny Kryukov. Use and/or distribution of
them requires acceptance of the License Agreement.
See License.txt for licence information
$Id: KsSkinButtons.pas,v 1.2 2002/10/29 02:41:19 Evgeny Exp $
===============================================================================}
unit KsSkinButtons;
{$I se_define.inc}
{$T-,W-,X+,P+}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Buttons,
se_controls, KsSkinVersion, KsSkinObjects, KsSkinSource, KsSkinEngine;
type
{ TSeSkinButton class }
TSeSkinButton = class(TSeCustomButton)
private
FSkinEngine: TSeSkinEngine;
FSkinObject: string;
FSkinButton: TSeSkinObject;
FShowGlyph: boolean;
FShowCaption: boolean;
function GetVersion: TSeSkinVersion;
procedure SetVersion(const Value: TSeSkinVersion);
procedure SetSkinEngine(const Value: TSeSkinEngine);
procedure SetSkinObject(const Value: string);
procedure SetShowGlyph(const Value: boolean);
procedure SetShowCaption(const Value: boolean);
protected
procedure WMInvalidateSkinObject(var Msg: TMessage); message WM_INVALIDATESKINOBJECT;
procedure WMBeforeChange(var Msg: TMessage); message WM_BEFORECHANGE;
procedure WMSkinChange(var Msg: TMessage); message WM_SKINCHANGE;
function UseSkin: boolean;
{ overrides }
procedure PaintFace; override;
procedure PaintGlyph; override;
procedure PaintText; override;
{ VCL protected }
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
constructor Create(AOwner: TComponent); override;
procedure Loaded; override;
destructor Destroy; override;
published
property Align;
property Caption;
property Default;
property Enabled;
property Glyph;
property Kind;
property ShowCaption: boolean read FShowCaption write SetShowCaption;
property ShowGlyph: boolean read FShowGlyph write SetShowGlyph;
property SkinEngine: TSeSkinEngine read FSkinEngine write SetSkinEngine;
property SkinObject: string read FSkinObject write SetSkinObject;
property Transparent;
property Version: TSeSkinVersion read GetVersion write SetVersion
stored false;
property OnClick;
end;
implementation {===============================================================}
{ TSeSkinButton }
constructor TSeSkinButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FSkinObject := 'Button';
FShowGlyph := true;
FShowCaption := true;
end;
destructor TSeSkinButton.Destroy;
begin
if FSkinButton <> nil then FSkinButton.Free;
inherited Destroy;
end;
procedure TSeSkinButton.Loaded;
begin
inherited;
Invalidate;
end;
function TSeSkinButton.UseSkin: boolean;
begin
if (csDestroying in ComponentState) or (csLoading in ComponentState) then
Result := false
else
if (FSkinEngine <> nil) and (FSkinEngine.SkinSource <> nil) and
(not FSkinEngine.SkinSource.IsChanging) and
(FSkinEngine.SkinSource.Count > 0) and
(FSkinEngine.SkinSource.GetObjectByName(FSkinObject) <> nil) and
(FSkinButton <> nil)
then
Result := true
else
Result := false;
end;
procedure TSeSkinButton.PaintFace;
var
DrawState: TSeState;
FFace: TSeSkinObject;
begin
if UseSkin then
begin
if not Enabled then
DrawState := ssDisabled
else
if State = kbsPressed then
DrawState := ssPressed
else
if MouseInControl then
DrawState := ssHot
else
if Focused or ActiveDefault then
DrawState := ssFocused
else
DrawState := ssNormal;
if FSkinButton.FindObjectByName('Face') <> nil then
FFace := FSkinButton.FindObjectByName('Face')
else
FFace := FSkinButton;
FFace.State := DrawState;
FFace.BoundsRect := Rect(0, 0, FWidth, FHeight);
FFace.Draw(Canvas);
end
else
inherited ;
end;
procedure TSeSkinButton.PaintGlyph;
begin
if not UseSkin or FShowGlyph then
inherited PaintGlyph;
end;
procedure TSeSkinButton.PaintText;
var
R: TRect;
DrawState: TSeState;
FText: TSeSkinObject;
begin
if UseSkin and ShowCaption then
begin
if not Enabled then
DrawState := ssDisabled
else
if State = kbsPressed then
DrawState := ssPressed
else
if MouseInControl then
DrawState := ssHot
else
if Focused or ActiveDefault then
DrawState := ssFocused
else
DrawState := ssNormal;
if FSkinButton.FindObjectByName('Text') <> nil then
begin
FText := FSkinButton.FindObjectByName('Text');
FText.State := DrawState;
Canvas.Font := FText.Font;
end
else
Canvas.Font := FSkinButton.Font;
if WordWrap then
R := Rect(0, 0, RectWidth(GetCaptionRect), Canvas.TextHeight(Caption))
else
R := Rect(0, 0, Canvas.TextWidth(Caption), Canvas.TextHeight(Caption));
DrawText(Canvas, Caption, R, DrawTextBiDiModeFlags(DT_CALCRECT or WordWraps[WordWrap]));
OffsetRect(R, (RectWidth(GetCaptionRect) - R.Right) div 2, (RectHeight(GetCaptionRect) - R.Bottom) div 2);
OffsetRect(R, GetCaptionRect.Left, GetCaptionRect.Top);
{ Draw Text }
DrawText(Canvas, Caption, R, DrawTextBiDiModeFlags(DT_CENTER or WordWraps[WordWrap]));
end
else
inherited PaintText;
end;
procedure TSeSkinButton.WMInvalidateSkinObject(var Msg: TMessage);
begin
Invalidate;
end;
procedure TSeSkinButton.WMBeforeChange(var Msg: TMessage);
begin
if Pointer(Msg.LParam) = nil then Exit;
if TSeSkinEngine(Msg.LParam) <> FSkinEngine then Exit;
if FSkinButton <> nil then FSkinButton.Free;
FSkinButton := nil;
end;
procedure TSeSkinButton.WMSkinChange(var Msg: TMessage);
begin
if Pointer(Msg.LParam) = nil then Exit;
if TSeSkinEngine(Msg.LParam) <> FSkinEngine then Exit;
SkinEngine := FSkinEngine;
end;
{ VCL Protected }
procedure TSeSkinButton.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if (Operation = opRemove) and (AComponent = FSkinEngine) then
SkinEngine := nil;
end;
{ Properties }
function TSeSkinButton.GetVersion: TSeSkinVersion;
begin
Result := sSeSkinVersion;
end;
procedure TSeSkinButton.SetVersion(const Value: TSeSkinVersion);
begin
end;
procedure TSeSkinButton.SetSkinEngine(const Value: TSeSkinEngine);
begin
FSkinEngine := Value;
if (FSkinEngine <> nil) and (FSkinEngine.SkinSource <> nil) and
(not FSkinEngine.SkinSource.IsChanging) and
(FSkinEngine.SkinSource.Count > 0) then
begin
if FSkinButton <> nil then FSkinButton.Free;
FSkinButton := nil;
if FSkinEngine.SkinSource.GetObjectByName(FSkinObject) <> nil then
FSkinButton := FSkinEngine.SkinSource.GetObjectByName(FSkinObject).CreateCopy(nil);
if FSkinButton <> nil then
begin
FSkinButton.ParentControl := Self;
{ Change transparent }
if FSkinButton.FindObjectByName('Face') <> nil then
if FSkinButton.FindObjectByName('Face') is TSeBitmapObject then
with TSeBitmapObject(FSkinButton.FindObjectByName('Face')) do
Transparent := Masked or MaskedBorder or MaskedAngles;
end;
end
else
begin
if FSkinButton <> nil then FSkinButton.Free;
FSkinButton := nil;
end;
Invalidate;
end;
procedure TSeSkinButton.SetSkinObject(const Value: string);
begin
FSkinObject := Value;
end;
procedure TSeSkinButton.SetShowGlyph(const Value: boolean);
begin
FShowGlyph := Value;
end;
procedure TSeSkinButton.SetShowCaption(const Value: boolean);
begin
FShowCaption := Value;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?