ksskininplaceedit.pas

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

PAS
294
字号
{==============================================================================

  SkinEngine's InplaceEdit
  Copyright (C) 2000-2002 by Evgeny Kryukov
  Copyright (C) 2002 by DKJ
  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: ksskininplaceedit.pas,v 1.1.1.1 2002/08/05 12:12:13 Evgeny Exp $

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

unit ksskininplaceedit;

{$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

{ TSeSkinEditButton class }

  TSeSkinEditButton = class(TSeCustomEditButton)
  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;
    { Button }
    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
    property SkinEngine: TSeSkinEngine read FSkinEngine write SetSkinEngine;
    property SkinObject: string read FSkinObject write SetSkinObject;
    property Version: TSeSkinVersion read GetVersion write SetVersion
      stored false;
    property Glyph;
    property GlyphKind;
    property NumGlyphs;
  end;

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

uses KsSkinMenus, KsSkinItems, KsSkinButtons;

{ TSeSkinEditButton }

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

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

procedure TSeSkinEditButton.Loaded;
begin
  inherited Loaded;
end;

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

{ Button }

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

{ Edits }

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

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

procedure TSeSkinEditButton.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 TSeSkinEditButton.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 TSeSkinEditButton.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited;
  if (Operation = opRemove) and (AComponent = FSkinEngine) then
    SkinEngine := nil;
end;

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

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

  SkinEngine := FSkinEngine;
end;

{ Properties }

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

procedure TSeSkinEditButton.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 TSeSkinButton).SkinEngine := Value;

  Invalidate;
end;

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

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

end.

⌨️ 快捷键说明

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