ksskinscrollbars.pas

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

PAS
403
字号
{==============================================================================

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

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

unit KsSkinScrollBars;

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

interface

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

type

{ TSeSkinScrollBar class }

  TSeSkinScrollBar = class(TSeCustomScrollBar)
  private
    FSkinEngine: TSeSkinEngine;
    FSkinObject: string;
    FSkinScrollBar: 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 }
    procedure PaintBuffer; override;
    { ScrollBar }
    function GetBtnSize: integer; override;
    function GetSliderSize: integer; override;
    procedure DrawLeftTopBtn; override;
    procedure DrawRightBottomBtn; override;
    procedure DrawSlider; override;
    procedure DrawBackground; override;
    procedure DrawBorder; override;
    { VCL protected  }
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Loaded; override;
  published
    property ShowButtons;
    property Kind;
    property LargeChange;
    property Max;
    property Min;
    property PageSize;
    property Position;
    property SmallChange;
    property SkinEngine: TSeSkinEngine read FSkinEngine write SetSkinEngine;
    property SkinObject: string read FSkinObject write SetSkinObject;
    property Version: TSeSkinVersion read GetVersion write SetVersion
      stored false;
    property OnChange;
    property OnScroll;
  end;

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

{ TSeSkinScrollBar }

constructor TSeSkinScrollBar.Create;
begin
  inherited Create(AOwner);
  BorderWidth := 0;
  FSkinObject := 'ScrollBar';
end;

destructor TSeSkinScrollBar.Destroy;
begin
  if FSkinScrollBar <> nil then FSkinScrollBar.Free;
  inherited Destroy;
end;

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

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

function TSeSkinScrollBar.GetBtnSize: integer;
begin
  Result := inherited GetBtnSize;

  if UseSkin then
    if Kind = sbHorizontal then
    begin
      if FSkinScrollBar.FindObjectByName('LeftButton') <> nil then
        Result := FSkinScrollBar.FindObjectByName('LeftButton').Width
    end
    else
    begin
      if FSkinScrollBar.FindObjectByName('TopButton') <> nil then
        Result := FSkinScrollBar.FindObjectByName('TopButton').Height
    end;
end;

function TSeSkinScrollBar.GetSliderSize: integer;
begin
  Result := inherited GetSliderSize;
end;

{ Drawing }

procedure TSeSkinScrollBar.DrawBackground;
var
  SkinObject: TSeSkinObject;
begin
  if not UseSkin then
    inherited
  else
  begin
    if Kind = sbHorizontal then
      SkinObject := FSkinScrollBar.FindObjectByName('HorzFrame')
    else
      SkinObject := FSkinScrollBar.FindObjectByName('VertFrame');

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

    if SkinObject <> nil then
    begin
      SkinObject.BoundsRect := Rect(0, 0, Width, Height);
      SkinObject.Draw(Canvas);
    end;
  end;
end;

procedure TSeSkinScrollBar.DrawBorder;
begin
  if not UseSkin then
    inherited ;
end;

procedure TSeSkinScrollBar.DrawLeftTopBtn;
var
  State: TSeState;
  SkinObject: TSeSkinObject;
begin
  if not UseSkin then
  begin
    inherited ;
    Exit;
  end;

  if not Enabled then
    State := ssDisabled
  else
    if LeftTopBtnPressed then
      State := ssPressed
    else
      if MouseOnLeftTopBtn then
        State := ssHot
      else
        State := ssNormal;

  if Kind = sbHorizontal then
    SkinObject := FSkinScrollBar.FindObjectByName('LeftButton')
  else
    SkinObject := FSkinScrollBar.FindObjectByName('TopButton');

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

procedure TSeSkinScrollBar.DrawRightBottomBtn;
var
  State: TSeState;
  SkinObject: TSeSkinObject;
begin
  if not UseSkin then
  begin
    inherited ;
    Exit;
  end;

  if not Enabled then
    State := ssDisabled
  else
    if RightBottomBtnPressed then
      State := ssPressed
    else
      if MouseOnRightBottomBtn then
        State := ssHot
      else
        State := ssNormal;

  if Kind = sbHorizontal then
    SkinObject := FSkinScrollBar.FindObjectByName('RightButton')
  else
    SkinObject := FSkinScrollBar.FindObjectByName('BottomButton');

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

procedure TSeSkinScrollBar.DrawSlider;
var
  State: TSeState;
  SkinObject: TSeSkinObject;
begin
  if not UseSkin then
  begin
    inherited ;
    Exit;
  end;

  if not Enabled then
    State := ssDisabled
  else
    if SliderPressed then
      State := ssPressed
    else
      if MouseOnSlider then
        State := ssHot
      else
        State := ssNormal;

  if Kind = sbHorizontal then
    SkinObject := FSkinScrollBar.FindObjectByName('HorzSlider')
  else
    SkinObject := FSkinScrollBar.FindObjectByName('VertSlider');

  if SkinOBject = nil then
    SkinObject := FSkinScrollBar.FindObjectByName('Slider');

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

procedure TSeSkinScrollBar.PaintBuffer;
begin
  if not UseSkin then
  begin
    inherited;
    Exit;
  end;

  inherited;

  DrawBorder;
  DrawBackground;

  if ShowButtons then
  begin
    DrawLeftTopBtn;
    DrawRightBottomBtn;
  end;

  if IsSliderVizible then
  begin
    DrawSlider;

    if LeftTopTrackPressed then
      FillRect(Canvas, GetLeftTopTrackRect, clBtnShadow);

    if RightBottomTrackPressed then
      FillRect(Canvas, GetRightBottomTrackRect, clBtnShadow);
  end;
end;

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

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

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

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

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

  SkinEngine := FSkinEngine;
end;

{ Properties }

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

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

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

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

    if FSkinScrollBar <> nil then
    begin
      if Kind = sbHorizontal then
      begin
        if FSkinScrollBar.FindObjectByName('HorzFrame') <> nil then
          Height := FSkinScrollBar.FindObjectByName('HorzFrame').Height
        else
          if FSkinScrollBar.FindObjectByName('Frame') <> nil then
            Height := FSkinScrollBar.FindObjectByName('Frame').Height
      end
      else
      begin
        if FSkinScrollBar.FindObjectByName('VertFrame') <> nil then
          Width := FSkinScrollBar.FindObjectByName('VertFrame').Width
        else
          if FSkinScrollBar.FindObjectByName('Frame') <> nil then
            Width := FSkinScrollBar.FindObjectByName('Frame').Width
      end;
    end;
  end
  else
  begin
    if FSkinScrollBar <> nil then FSkinScrollBar.Free;
    FSkinScrollBar := nil;
  end;

  Invalidate;
end;

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

end.

⌨️ 快捷键说明

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