ksskincheckboxs.pas

来自「小区水费管理系统源代码水费收费管理系统 水费收费管理系统」· PAS 代码 · 共 454 行

PAS
454
字号
{==============================================================================

  SkinEngine's CheckBox & RadioButton
  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: KsSkinCheckBoxs.pas,v 1.1.1.1 2002/08/05 12:12:12 Evgeny Exp $

===============================================================================}

unit KsSkinCheckBoxs;

{$I se_define.inc}
{$T-,W-,X+,P+}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Dialogs,
  StdCtrls, Forms, se_controls, KsSkinVersion, KsSkinObjects, KsSkinSource,
  KsSkinEngine;

type

{ TSeSkinCheckBox class }

  TSeSkinCheckBox = class(TSeCustomCheckBox)
  private
    FSkinEngine: TSeSkinEngine;
    FSkinObject: string;
    FSkinCheckBox: TSeSkinObject;
    function GetVersion: TSeSkinVersion;
    procedure SetVersion(const Value: TSeSkinVersion);
    procedure SetSkinEngine(const Value: TSeSkinEngine);
    procedure SetSkinObject(const Value: string);
  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 }
    function GetBoxSize: TPoint; override;
    procedure PaintBox; override;
    { VCL protected  }
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  public
    constructor Create(AOwner: TComponent); override;
    procedure Loaded; override;
    destructor Destroy; override;
  published
    property Caption;
    property Checked;
    property Spacing;
    property State;
    property SkinEngine: TSeSkinEngine read FSkinEngine write SetSkinEngine;
    property SkinObject: string read FSkinObject write SetSkinObject;
    property Version: TSeSkinVersion read GetVersion write SetVersion
      stored false;
  end;

{ TSeSkinRadioButton }

  TSeSkinRadioButton = class(TSeCustomRadioButton)
  private
    FSkinEngine: TSeSkinEngine;
    FSkinObject: string;
    FSkinRadioButton: TSeSkinObject;
    function GetVersion: TSeSkinVersion;
    procedure SetVersion(const Value: TSeSkinVersion);
    procedure SetSkinEngine(const Value: TSeSkinEngine);
    procedure SetSkinObject(const Value: string);
  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 }
    function GetBoxSize: TPoint; override;
    procedure PaintBox; override;
    { VCL protected  }
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  public
    constructor Create(AOwner: TComponent); override;
    procedure Loaded; override;
    destructor Destroy; override;
  published
    property Caption;
    property Checked;
    property GroupIndex;
    property Spacing;
    property SkinEngine: TSeSkinEngine read FSkinEngine write SetSkinEngine;
    property SkinObject: string read FSkinObject write SetSkinObject;
    property Version: TSeSkinVersion read GetVersion write SetVersion
      stored false;
  end;

implementation {===============================================================}

{ TSeSkinCheckBox }

constructor TSeSkinCheckBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FSkinObject := 'CheckBox';
end;

destructor TSeSkinCheckBox.Destroy;
begin
  if FSkinCheckBox <> nil then FSkinCheckBox.Free;
  inherited Destroy;
end;

procedure TSeSkinCheckBox.Loaded;
begin
  inherited;
{  SkinEngine := FSkinEngine; }
end;

function TSeSkinCheckBox.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
       (FSkinCheckBox <> nil)
    then
      Result := true
    else
      Result := false;
end;

function TSeSkinCheckBox.GetBoxSize: TPoint;
begin
  if UseSkin and (FSkinCheckBox.FindObjectByName('Checked') <> nil) then
    Result := Point(FSkinCheckBox.FindObjectByName('Checked').Width,
      FSkinCheckBox.FindObjectByName('Checked').Height)
  else
    Result := inherited GetBoxSize;
end;

procedure TSeSkinCheckBox.PaintBox;
var
  R: TRect;
  DrawState: TSeState;
  SkinObject: TSeSkinObject;
begin
  if UseSkin then
  begin
    R := Rect(0, 0, GetBoxSize.X, GetBoxSize.Y);
    if Alignment = ktaLeftJustify then
      RectVCenter(R, Rect(0, 0, FWidth, FHeight))
    else
      RectVCenter(R, Rect(FWidth-GetBoxSize.X, 0, FWidth, FHeight));

    if not Enabled then
      DrawState := ssDisabled
    else
      if MouseInControl then
        DrawState := ssHot
      else
        if Focused then
          DrawState := ssFocused
        else
          DrawState := ssNormal;

    case State of
      cbChecked: SkinObject := FSkinCheckBox.FindObjectByName('Checked');
      cbGrayed: SkinObject := FSkinCheckBox.FindObjectByName('Mixed');
    else
      SkinObject := FSkinCheckBox.FindObjectByName('Unchecked');
    end;

    if SkinObject <> nil then
    begin
      SkinObject.State := DrawState;
      SkinObject.BoundsRect := R;
      SkinObject.Draw(Canvas);
    end;

    if FSkinCheckBox.FindObjectByName('Text') <> nil then
    begin
      SkinObject := FSkinCheckBox.FindObjectByName('Text');
      SkinObject.State := DrawState;
      ControlFont.Assign(SkinObject.Font);
    end
    else
      ControlFont.Assign(SkinObject.Font);
  end
  else
    inherited;
end;

procedure TSeSkinCheckBox.WMInvalidateSkinObject(var Msg: TMessage);
begin
  Invalidate;
end;

procedure TSeSkinCheckBox.WMBeforeChange(var Msg: TMessage);
begin
  if Pointer(Msg.LParam) = nil then Exit;
  if TSeSkinEngine(Msg.LParam) <> FSkinEngine then Exit;

  if FSkinCheckBox <> nil then FSkinCheckBox.Free;
  FSkinCheckBox := nil;
end;

procedure TSeSkinCheckBox.WMSkinChange(var Msg: TMessage);
begin
  if Pointer(Msg.LParam) = nil then Exit;
  if TSeSkinEngine(Msg.LParam) <> FSkinEngine then Exit;

  SkinEngine := FSkinEngine;
end;

{ VCL }

procedure TSeSkinCheckBox.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited;
  if (Operation = opRemove) and (AComponent = FSkinEngine) then
    SkinEngine := nil;
end;

{ Properties }

procedure TSeSkinCheckBox.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 FSkinCheckBox <> nil then FSkinCheckBox.Free;
    FSkinCheckBox := nil;

    if FSkinEngine.SkinSource.GetObjectByName(FSkinObject) <> nil then
    begin
      FSkinCheckBox := FSkinEngine.SkinSource.GetObjectByName(FSkinObject).CreateCopy(nil);

      if FSkinCheckBox.FindObjectByName('Text') <> nil then
        Font.Assign(FSkinCheckBox.FindObjectByName('Text').Font)
      else
        Font.Assign(FSkinCheckBox.Font);
    end;

    if FSkinCheckBox <> nil then
      FSkinCheckBox.ParentControl := Self;
  end
  else
  begin
    if FSkinCheckBox <> nil then FSkinCheckBox.Free;
    FSkinCheckBox := nil;
  end;

  Invalidate;
end;

function TSeSkinCheckBox.GetVersion: TSeSkinVersion;
begin
  Result := sSeSkinVersion;
end;

procedure TSeSkinCheckBox.SetVersion(const Value: TSeSkinVersion);
begin
end;

{ TSeSkinRadioButton =========================================================}

constructor TSeSkinRadioButton.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FSkinObject := 'RadioButton';
end;

destructor TSeSkinRadioButton.Destroy;
begin
  if FSkinRadioButton <> nil then FSkinRadioButton.Free;
  inherited Destroy;
end;

procedure TSeSkinRadioButton.Loaded;
begin
  inherited;
  SkinEngine := FSkinEngine;
end;

function TSeSkinRadioButton.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
       (FSkinRadioButton <> nil)
    then
      Result := true
    else
      Result := false;
end;

function TSeSkinRadioButton.GetBoxSize: TPoint;
begin
  if UseSkin and (FSkinRadioButton.FindObjectByName('Checked') <> nil) then
    Result := Point(FSkinRadioButton.FindObjectByName('Checked').Width,
      FSkinRadioButton.FindObjectByName('Checked').Height)
  else
    Result := inherited GetBoxSize;
end;

procedure TSeSkinRadioButton.PaintBox;
var
  R: TRect;
  DrawState: TSeState;
  SkinObject: TSeSkinObject;
begin
  if UseSkin then
  begin
    R := Rect(0, 0, GetBoxSize.X, GetBoxSize.Y);
    if Alignment = ktaLeftJustify then
      RectVCenter(R, Rect(0, 0, FWidth, FHeight))
    else
      RectVCenter(R, Rect(FWidth-GetBoxSize.X, 0, FWidth, FHeight));

    if not Enabled then
      DrawState := ssDisabled
    else
      if MouseInControl then
        DrawState := ssHot
      else
        if Focused then
          DrawState := ssFocused
        else
          DrawState := ssNormal;

    if Checked then
      SkinObject := FSkinRadioButton.FindObjectByName('Checked')
    else
      SkinObject := FSkinRadioButton.FindObjectByName('Unchecked');

    if SkinObject <> nil then
    begin
      SkinObject.State := DrawState;
      SkinObject.BoundsRect := R;
      SkinObject.Draw(Canvas);
    end;

    { Set Font }
    if FSkinRadioButton.FindObjectByName('Text') <> nil then
    begin
      SkinObject := FSkinRadioButton.FindObjectByName('Text');
      SkinObject.State := DrawState;
      ControlFont := SkinObject.Font;
    end
    else
      ControlFont := FSkinRadioButton.Font;
  end
  else
    inherited;
end;

procedure TSeSkinRadioButton.WMInvalidateSkinObject(var Msg: TMessage);
begin
  Invalidate;
end;

procedure TSeSkinRadioButton.WMBeforeChange(var Msg: TMessage);
begin
  if Pointer(Msg.LParam) = nil then Exit;
  if TSeSkinEngine(Msg.LParam) <> FSkinEngine then Exit;

  if FSkinRadioButton <> nil then FSkinRadioButton.Free;
  FSkinRadioButton := nil;
end;

procedure TSeSkinRadioButton.WMSkinChange(var Msg: TMessage);
begin
  if Pointer(Msg.LParam) = nil then Exit;
  if TSeSkinEngine(Msg.LParam) <> FSkinEngine then Exit;

  SkinEngine := FSkinEngine;
end;

procedure TSeSkinRadioButton.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited;
  if (Operation = opRemove) and (AComponent = FSkinEngine) then
    SkinEngine := nil;
end;

{ Properties }

function TSeSkinRadioButton.GetVersion: TSeSkinVersion;
begin
  Result := sSeSkinVersion;
end;

procedure TSeSkinRadioButton.SetVersion(const Value: TSeSkinVersion);
begin
end;

procedure TSeSkinRadioButton.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 FSkinRadioButton <> nil then FSkinRadioButton.Free;
    FSkinRadioButton := nil;

    if FSkinEngine.SkinSource.GetObjectByName(FSkinObject) <> nil then
      FSkinRadioButton := FSkinEngine.SkinSource.GetObjectByName(FSkinObject).CreateCopy(nil);

    if FSkinRadioButton <> nil then
      FSkinRadioButton.ParentControl := Self;
  end
  else
  begin
    if FSkinRadioButton <> nil then FSkinRadioButton.Free;
    FSkinRadioButton := nil;
  end;

  Invalidate;
end;

procedure TSeSkinCheckBox.SetSkinObject(const Value: string);
begin
  FSkinObject := Value;
end;

procedure TSeSkinRadioButton.SetSkinObject(const Value: string);
begin
  FSkinObject := Value;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?