ksskinspeedbuttons.pas

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

PAS
291
字号
{==============================================================================

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

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

unit KsSkinSpeedButtons;

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

interface

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

type

{ TSeSkinSpeedButton class }

  TSeSkinSpeedButton = class(TSeCustomSpeedButton)
  private
    FSkinEngine: TSeSkinEngine;
    FSkinButton: 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;

    procedure PaintBuffer; override;
    { VCL protected  }
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Loaded; 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 KsSkinSpinButtons;

{ TSeSkinSpeedButton }

constructor TSeSkinSpeedButton.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FSkinObject := 'SpeedButton';
end;

destructor TSeSkinSpeedButton.Destroy;
begin
  if FSkinButton <> nil then FSkinButton.Free;
  inherited;
end;

procedure TSeSkinSpeedButton.Loaded;
begin
  inherited;
  Invalidate;
end;

function TSeSkinSpeedButton.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 TSeSkinSpeedButton.PaintBuffer;
var
  DrawState: TSeState;
  ButtonOffset, ChevronOffset: TPoint;
  SkinObject: TSeSkinObject;
begin
  if not UseSkin then
  begin
    inherited ;
    Exit;
  end;
  SkinObject := nil;

  DrawState := ssNormal;

  if Flat then
  begin
    { Flat }
      
    if State = se_controls.bsDown then
      DrawState := ssPressed
    else
      if MouseInControl then
        DrawState := ssHot;

    if (State = bsExclusive) and not MouseInControl then
      DrawState := ssFocused;

    if FSkinButton.FindObjectByName('FlatFace') <> nil then
      SkinObject := FSkinButton.FindObjectByName('FlatFace')
  end
  else
  begin
    { Normal }

    if State = se_controls.bsDown then
      DrawState := ssPressed;

    if State = bsExclusive then
      DrawState := ssFocused;

    if FSkinButton.FindObjectByName('Face') <> nil then
      SkinObject := FSkinButton.FindObjectByName('Face')
  end;

  if not Enabled then
    DrawState := ssDisabled;

  if SkinObject = nil then
    SkinObject := FSkinButton;

  if Parent is TSeSkinSpinButton then
  begin
    { Spin button }
    if FSkinButton.FindObjectByName('Face') <> nil then
      SkinObject := FSkinButton.FindObjectByName('Face')
    else
      SkinObject := FSkinButton;

    SkinObject.State := DrawState;
    SkinObject.BoundsRect := GetButtonRect;
    SkinObject.Draw(Canvas);
  end
  else
  begin
    { Standard }
    SkinObject.State := DrawState;
    SkinObject.BoundsRect := GetButtonRect;
    SkinObject.Draw(Canvas);

    if ShowChevron then
    begin
      if Flat then
      begin
        if FSkinButton.FindObjectByName('FlatChevron') <> nil then
          SkinObject := FSkinButton.FindObjectByName('FlatChevron');
      end
      else
      begin
        if FSkinButton.FindObjectByName('Chevron') <> nil then
          SkinObject := FSkinButton.FindObjectByName('Chevron');
      end;

      SkinObject.State := DrawState;
      SkinObject.BoundsRect := GetChevronRect;
      SkinObject.Draw(Canvas);
    end;
  end;

  { Draw Glyph }
  ButtonOffset := Point(0, 0);
  ChevronOffset := Point(0, 0);

  if FState in [se_controls.bsDown, bsExclusive] then
    ButtonOffset := Point(1, 1);

  if (FState in [bsChevronDown, bsExclusive]) or Down then
    ChevronOffset := Point(1, 1);

  if ShowGlyph then
    DrawGlyph(ButtonOffset);

  { Draw Text }

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

  if ShowCaption then
    DrawCaption(ButtonOffset);
end;

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

procedure TSeSkinSpeedButton.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 TSeSkinSpeedButton.WMSkinChange(var Msg: TMessage);
begin
  if Pointer(Msg.LParam) = nil then Exit;
  if TSeSkinEngine(Msg.LParam) <> FSkinEngine then Exit;

  SkinEngine := FSkinEngine;
end;

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

{ Properties }

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

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

procedure TSeSkinSpeedButton.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);
  end
  else
  begin
    if FSkinButton <> nil then FSkinButton.Free;
    FSkinButton := nil;
  end;

  Invalidate;
end;

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

end.

⌨️ 快捷键说明

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