ksskinstdcontrol.pas

来自「小区水费管理系统源代码水费收费管理系统 水费收费管理系统」· PAS 代码 · 共 892 行 · 第 1/2 页

PAS
892
字号
{==============================================================================

  SkinEngine's Standard Control
  Copyright (C) 2000-2002 by Evgeny Kryukov
  All rights reserved

  All conTeSkinnts 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: ksskinstdcontrol.pas,v 1.2 2002/08/14 19:03:12 Evgeny Exp $

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

unit ksskinstdcontrol;

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

interface

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

type

{ TSeSkinMaskEdit class }

  TSeSkinMaskEdit = class(TSeCustomMaskEdit)
  private
    FSkinEngine: TSeSkinEngine;
    FSkinEdit: TSeSkinObject;
    FSkinObject: string;
    function GetVersion: TSeSkinVersion;
    procedure SetSkinEngine(const Value: TSeSkinEngine);
    procedure SetVersion(const Value: TSeSkinVersion);
    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 }
    procedure PaintBorder(Canvas: TCanvas; ARect: TRect); override;
    procedure PaintBuffer(Canvas: TCanvas; ARect: TRect); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property SkinEngine: TSeSkinEngine read FSkinEngine write SetSkinEngine;
    property SkinObject: string read FSkinObject write SetSkinObject;
    property Version: TSeSkinVersion read GetVersion write SetVersion
      stored false;
  end;

{ TSeSkinScrollBox class }

  TSeSkinScrollBox = class(TSeCustomScrollBox)
  private
    FSkinEngine: TSeSkinEngine;
    FSkinBox: TSeSkinObject;
    FSkinObject: string;
    function GetVersion: TSeSkinVersion;
    procedure SetSkinEngine(const Value: TSeSkinEngine);
    procedure SetVersion(const Value: TSeSkinVersion);
    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 }
    procedure PaintBorder(Canvas: TCanvas; ARect: TRect); override;
    procedure PaintBuffer(Canvas: TCanvas; ARect: TRect); override;
    procedure CreateScrollBar(var AScrollBar: TSeCustomScrollBar; AOwner: TComponent); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property SkinEngine: TSeSkinEngine read FSkinEngine write SetSkinEngine;
    property SkinObject: string read FSkinObject write SetSkinObject;
    property Version: TSeSkinVersion read GetVersion write SetVersion
      stored false;
  end;

{ TSeSkinMemo class }

  TSeSkinMemo = class(TSeCustomMemo)
  private
    FSkinEngine: TSeSkinEngine;
    FSkinEdit: TSeSkinObject;
    FSkinObject: string;
    function GetVersion: TSeSkinVersion;
    procedure SetSkinEngine(const Value: TSeSkinEngine);
    procedure SetVersion(const Value: TSeSkinVersion);
    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 }
    procedure PaintBorder(Canvas: TCanvas; ARect: TRect); override;
    procedure PaintBuffer(Canvas: TCanvas; ARect: TRect); override;
    procedure CreateScrollBar(var AScrollBar: TSeCustomScrollBar; AOwner: TComponent); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property SkinEngine: TSeSkinEngine read FSkinEngine write SetSkinEngine;
    property SkinObject: string read FSkinObject write SetSkinObject;
    property Version: TSeSkinVersion read GetVersion write SetVersion
      stored false;
  end;

{ TSeSkinSTreeView class }

  TSeSkinSTreeView = class(TSeCustomTreeView)
  private
    FSkinEngine: TSeSkinEngine;
    FSkinBox: TSeSkinObject;
    FSkinObject: string;
    function GetVersion: TSeSkinVersion;
    procedure SetSkinEngine(const Value: TSeSkinEngine);
    procedure SetVersion(const Value: TSeSkinVersion);
    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 }
    procedure PaintBorder(Canvas: TCanvas; ARect: TRect); override;
    procedure PaintBuffer(Canvas: TCanvas; ARect: TRect); override;
    procedure CreateScrollBar(var AScrollBar: TSeCustomScrollBar; AOwner: TComponent); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property SkinEngine: TSeSkinEngine read FSkinEngine write SetSkinEngine;
    property SkinObject: string read FSkinObject write SetSkinObject;
    property Version: TSeSkinVersion read GetVersion write SetVersion
      stored false;
  end;

{ TSeSkinSListView class }

  TSeSkinSListView = class(TSeCustomListView)
  private
    FSkinEngine: TSeSkinEngine;
    FSkinBox: TSeSkinObject;
    FSkinObject: string;
    function GetVersion: TSeSkinVersion;
    procedure SetSkinEngine(const Value: TSeSkinEngine);
    procedure SetVersion(const Value: TSeSkinVersion);
    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 }
    procedure PaintBorder(Canvas: TCanvas; ARect: TRect); override;
    procedure PaintBuffer(Canvas: TCanvas; ARect: TRect); override;
    procedure CreateScrollBar(var AScrollBar: TSeCustomScrollBar; AOwner: TComponent); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    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 {===============================================================}

uses KsSkinScrollbars;

{ TSeSkinMaskEdit ===============================================================}

constructor TSeSkinMaskEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  SkinObject := 'Edit';
end;

destructor TSeSkinMaskEdit.Destroy;
begin
  if FSkinEdit <> nil then FSkinEdit.Free;
  inherited Destroy;
end;

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

procedure TSeSkinMaskEdit.PaintBorder(Canvas: TCanvas; ARect: TRect);
var
  SkinObject: TSeSkinObject;
  DrawState: TSeState;
begin
  if UseSkin then
  begin
    if not Enabled then
      DrawState := ssDisabled
    else
      DrawState := ssNormal;

    SkinObject := FSkinEdit.FindObjectByName('Frame');
    if SkinObject = nil then
      SkinObject := FSkinEdit;

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

procedure TSeSkinMaskEdit.PaintBuffer(Canvas: TCanvas; ARect: TRect);
begin
  inherited ;
end;

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

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

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

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

  SkinEngine := FSkinEngine;
end;

{ Properties }

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

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

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

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

  Invalidate;
end;

procedure TSeSkinMaskEdit.SetVersion(const Value: TSeSkinVersion);
begin

end;


{ TSeSkinScrollBox ===============================================================}


constructor TSeSkinScrollBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  SkinObject := 'ScrollBox';
end;

destructor TSeSkinScrollBox.Destroy;
begin
  if FSkinBox <> nil then FSkinBox.Free;
  inherited Destroy;
end;

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

procedure TSeSkinScrollBox.CreateScrollBar(var AScrollBar: TSeCustomScrollBar; AOwner: TComponent);
begin
  AScrollBar := TSeSkinScrollBar.Create(AOwner);
end;

procedure TSeSkinScrollBox.PaintBorder(Canvas: TCanvas; ARect: TRect);
var
  SkinObject: TSeSkinObject;
  DrawState: TSeState;
begin
  if UseSkin then
  begin
    if not Enabled then
      DrawState := ssDisabled
    else
      DrawState := ssNormal;

    SkinObject := FSkinBox.FindObjectByName('Frame');
    if SkinObject = nil then
      SkinObject := FSkinBox;

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

procedure TSeSkinScrollBox.PaintBuffer(Canvas: TCanvas; ARect: TRect);
begin
  inherited ;
end;

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

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

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

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

  SkinEngine := FSkinEngine;
end;

{ Properties }

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

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

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

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

  if SubScrollBars <> nil then
  begin
    TSeSkinScrollBar(SubScrollBars.HScrollBar.ScrollBar).SkinEngine := Value;
    TSeSkinScrollBar(SubScrollBars.VScrollBar.ScrollBar).SkinEngine := Value;
  end;

  Invalidate;
end;

procedure TSeSkinScrollBox.SetVersion(const Value: TSeSkinVersion);

⌨️ 快捷键说明

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