ksskinspinedit.pas

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

PAS
299
字号
{==============================================================================

  SkinEngine's SpinEdit
  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: ksskinspinedit.pas,v 1.1.1.1 2002/08/05 12:12:14 Evgeny Exp $

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

unit KsSkinSpinEdit;

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

interface

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

type

{ TSeSkinSpinEdit class }

  TSeSkinSpinEdit = class(TSeCustomSpinEdit)
  private
    FSkinEngine: TSeSkinEngine;
    FSkinObject: string;
    FSkinEdit: TSeSkinObject;
    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 }
    function CreatePopupMenu(AOwner: TComponent): TSeCustomPopupMenu; override;
    function CreatePopupMenuItem(AOwner: TComponent): TSeCustomItem; override;
    { Edit }
    procedure PaintBorder; override;
    procedure PaintBackground(Rect: TRect; Canvas: TCanvas); override;
    { SpinButton }
    function CreateButton(AOwner: TComponent): TSeInplaceControl; override;
    { VCL protected  }
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Loaded; override;
  published
    { Specifies the appearance and behavior by using specified theme's from TSeSkinEngine .
      See Also:
        TSeSkinEngine
    }
    property SkinEngine: TSeSkinEngine read FSkinEngine write SetSkinEngine;
    { Specifies the SkinObject name, your can change default value to set custom skin object for the control
      For Example:
        For TSeSkinButton the SkinObject property set to 'Button', but your can use you own name - example 'My Button'
    }
    property SkinObject: string read FSkinObject write SetSkinObject;
    property Version: TSeSkinVersion read GetVersion write SetVersion
      stored false;
  end;

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

uses KsSkinMenus, KsSkinItems, KsSkinSpinButtons;

{ TSeSkinSpinEdit }

constructor TSeSkinSpinEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FSkinObject := 'Edit';
end;

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

procedure TSeSkinSpinEdit.Loaded;
begin
  inherited Loaded;
end;

function TSeSkinSpinEdit.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;

{ SpinButton }

function TSeSkinSpinEdit.CreateButton(
  AOwner: TComponent): TSeInplaceControl;
begin
  Result := TSeSkinSpinButton.Create(AOwner);
  (Result as TSeSkinSpinButton).SkinEngine := FSkinEngine;
end;

{ Edits }

function TSeSkinSpinEdit.CreatePopupMenu(AOwner: TComponent): TSeCustomPopupMenu;
begin
  Result := TSeSkinPopupMenu.Create(AOwner);
  (Result as TSeSkinPopupMenu).SkinEngine := FSkinEngine;
end;

function TSeSkinSpinEdit.CreatePopupMenuItem(AOwner: TComponent): TSeCustomItem;
begin
  Result := TSeSkinItem.Create(AOwner);
  (Result as TSeSkinItem).SkinEngine := FSkinEngine;
end;

procedure TSeSkinSpinEdit.PaintBackground(Rect: TRect; Canvas: TCanvas);
var
  SkinObject: TSeSkinObject;
  DrawState: TSeState;
begin
  if UseSkin then
  begin
    if not Enabled then
      DrawState := ssDisabled
    else
      if MouseInControl then
        DrawState := ssHot
      else
        if Focused then
          DrawState := ssFocused
        else
          DrawState := ssNormal;

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

    if SkinObject <> nil then
    begin
      SkinObject.State := DrawState;

      if CompareRect(GetBorderRect, Classes.Rect(0, 0, Width, Height)) then
        with SkinObject do
          SkinObject.BoundsRect := Classes.Rect(-MarginLeft, -MarginTop, FWidth + MarginRight, FHeight + MarginBottom)
      else
        SkinObject.BoundsRect := Classes.Rect(0, 0, FWidth, FHeight);

      SkinObject.Draw(Canvas);
    end;
  end
  else
    inherited ;
end;

procedure TSeSkinSpinEdit.PaintBorder;
var
  SkinObject: TSeSkinObject;
  DrawState: TSeState;
begin
  if UseSkin then
  begin
    if not Enabled then
      DrawState := ssDisabled
    else
      if MouseInControl then
        DrawState := ssHot
      else
        if Focused then
          DrawState := ssFocused
        else
          DrawState := ssNormal;

    SkinObject := FSkinEdit.FindObjectByName('Frame');

    if SkinObject <> nil then
    begin
      SkinObject.State := DrawState;
      SkinObject.BoundsRect := Rect(0, 0, FWidth, FHeight);
      SkinObject.Draw(Canvas);
    end;
  end
  else
    inherited ;
end;

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

procedure TSeSkinSpinEdit.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 TSeSkinSpinEdit.WMInvalidateSkinObject(var Msg: TMessage);
begin
  Invalidate;
end;

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

  SkinEngine := FSkinEngine;
end;

{ Properties }

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

procedure TSeSkinSpinEdit.SetSkinEngine(const Value: TSeSkinEngine);
var
  SkinObject: TSeSkinOBject;
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;

      if FSkinEdit.FindObjectByName('Text') <> nil then
      begin
        SkinObject := FSkinEdit.FindObjectByName('Text');
        Self.Font := SkinObject.Font;
      end
      else
        Self.Font := FSkinEdit.Font;
    end;
  end
  else
  begin
    if FSkinEdit <> nil then FSkinEdit.Free;
    FSkinEdit := nil;
  end;

  if (PopupMenu <> nil) then
    (PopupMenu as TSeSkinPopupMenu).SkinEngine := Value;

  if Button<>nil then
    (Button as TSeSkinSpinButton).SkinEngine := Value;

  Invalidate;
end;

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

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

end.

⌨️ 快捷键说明

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