ksskinpanels.pas

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

PAS
293
字号
{==============================================================================

  SkinEngine's Panels
  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: KsSkinPanels.pas,v 1.4 2002/10/29 02:41:20 Evgeny Exp $

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

unit KsSkinPanels;

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

interface

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

type

{ TSeSkinPanel class }

  TSeSkinPanel = class(TSeCustomPanel)
  private
    FSkinEngine: TSeSkinEngine;
    FSkinObject: string;
    FSkinPanel: TSeSkinObject;
    FOldCaptionHeight: integer;
    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;
    { Inherited }
    procedure DrawCaption; override;
    procedure DrawFace; override;
    { VCL protected  }
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Loaded; override;
  published
    property Align;
    property SkinEngine: TSeSkinEngine read FSkinEngine write SetSkinEngine;
    property SkinObject: string read FSkinObject write SetSkinObject;
    property Transparent;
    property Version: TSeSkinVersion read GetVersion write SetVersion
      stored False;
  end;

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

type
  THackControl = class(TControl);

{ TSeSkinPanel }

constructor TSeSkinPanel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FSkinObject := 'Panel';
end;

destructor TSeSkinPanel.Destroy;
begin
  if FSkinPanel <> nil then FSkinPanel.Free;
  inherited Destroy;
end;

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

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

procedure TSeSkinPanel.DrawCaption;
var
  R: TRect;
  SkinObject: TSeSkinObject;
  State: TSeState;
  ButtonObject: string;
begin
  if not UseSkin then
    inherited
  else
  begin
    if not ShowCaption then Exit;

    R := GetCaptionRect;
    if not Transparent then
      FillRect(Canvas, R, THackControl(Parent).Color);

    SkinObject := nil;
    if FSkinPanel.FindObjectByName('Caption') <> nil then
    begin
      SkinObject := FSkinPanel.FindObjectByName('Caption');
      if FSkinPanel.FindObjectByName('Title') <> nil then
        SkinObject := FSkinPanel.FindObjectByName('Title');

      SkinObject.Text := Caption;  
      SkinObject.BoundsRect := R;
      SkinObject.Draw(Canvas);

      Canvas.Font.Assign(SkinObject.Font);
    end;

    { Draw Text }
    if SkinObject = nil then
    begin
      InflateRect(R, -5, 0);
      DrawText(Canvas, Caption, R, DrawTextBiDiModeFlags(DT_LEFT or DT_SINGLELINE or DT_VCENTER));
    end;

    { Draw Button }
    if not ShowButton then Exit;

    R := GetButtonRect;

    if ButtonPressed then
      State := ssPressed
    else
      if MouseOnButton then
        State := ssHot
      else
        State := ssNormal;

    if ButtonKind = pbkRoll then
      if Rolled then
        ButtonObject := 'ButtonRolldown'
      else
        ButtonObject := 'ButtonRollup'
    else
      ButtonObject := 'ButtonHide';

    SkinObject := FSkinPanel.FindObjectByName(ButtonObject);

    if SkinObject = nil then
      SkinObject := FSkinPanel.FindObjectByName('Button');

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

procedure TSeSkinPanel.DrawFace;
var
  R: TRect;
  SkinObject: TSeSkinObject;
begin
  if not UseSkin then
    inherited
  else
  begin
    R := Rect(0, 0, FWidth, FHeight);

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

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

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

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

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

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

  SkinEngine := FSkinEngine;
end;

{ VCL Routines }

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

{ Properties }

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

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

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

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

    if FSkinPanel <> nil then
    begin
      FSkinPanel.ParentControl := Self;

      if FSkinPanel.FindObjectByName('Caption') <> nil then
        CaptionHeight := FSkinPanel.FindObjectByName('Caption').Height;

      { Change transparent }
      if FSkinPanel.FindObjectByName('Frame') <> nil then
        if FSkinPanel.FindObjectByName('Frame') is TSeBitmapObject then
        with TSeBitmapObject(FSkinPanel.FindObjectByName('Frame')) do
          Transparent := Masked or MaskedBorder or MaskedAngles;
    end
    else
      if FOldCaptionHeight <> 0 then
        CaptionHeight := FOldCaptionHeight;
  end
  else
  begin
    if FOldCaptionHeight = 0 then
      FOldCaptionHeight := CaptionHeight;
    if FSkinPanel <> nil then FSkinPanel.Free;
    FSkinPanel := nil;
    CaptionHeight := FOldCaptionHeight;
  end;

  Invalidate;
end;

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

end.

⌨️ 快捷键说明

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