{==============================================================================

  Copyright (C) 2000-2001 by Evgeny Kryukov
  All rights reserved

  All contents of this file and all other files included in this archive
  are Copyright (C) 2001 Evgeny Kryukov. Use and/or distribution of
  them requires acceptance of the License Agreement.

  See License.txt for licence information

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

unit KsSkinSpinButtons;

{$I KsSkinVer.Inc}
{$T-,W-,X+,P+}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, Menus, Buttons, KsUtils, KsBitmap, KsControls, KsSpeedButtons,
  KsSpinButtons, KsSkinSpeedButtons, KsSkinVersion, KsSkinObjects,
  KsSkinSource, KsSkinEngine;

type

{ TSeSkinSpinButton }

  TSeSkinSpinButton = class (TKsCustomSpinButton)
  private
    FSkinEngine: TSeSkinEngine;
    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 CreateButton: TKsCustomSpeedButton; override;
    { VCL protected  }
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  public
    constructor Create(AOwner: TComponent); 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 {===============================================================}

{ TSeSkinSpinButton }

constructor TSeSkinSpinButton.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FSkinObject := 'SpinButton';
end;

procedure TSeSkinSpinButton.Loaded;
begin
  inherited;
  SkinEngine := FSkinEngine;
end;

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

  if UpButton <> nil then
  begin
    UpButton.Perform(Msg.Msg, Msg.wParam, Msg.lParam);
    DownButton.Perform(Msg.Msg, Msg.wParam, Msg.lParam);
  end;
end;

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

  if UpButton <> nil then
  begin
    UpButton.Perform(Msg.Msg, Msg.wParam, Msg.lParam);
    DownButton.Perform(Msg.Msg, Msg.wParam, Msg.lParam);
  end;
end;

procedure TSeSkinSpinButton.WMInvalidateSkinObject(var Msg: TMessage);
begin
  Invalidate;
  if UpButton <> nil then
  begin
    (UpButton as TSeSkinSpeedButton).SkinEngine := FSkinEngine;
    (DownButton as TSeSkinSpeedButton).SkinEngine := FSkinEngine;
  end;
end;

function TSeSkinSpinButton.CreateButton: TKsCustomSpeedButton;
begin
  Result := TSeSkinSpeedButton.Create(Self);
  (Result as TSeSkinSpeedButton).SkinObject := 'SpinButton';
  (Result as TSeSkinSpeedButton).Flat := true;
end;

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

{ Properties }

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

procedure TSeSkinSpinButton.SetSkinEngine(const Value: TSeSkinEngine);
begin
  FSkinEngine := Value;
  if UpButton <> nil then
  begin
    (UpButton as TSeSkinSpeedButton).SkinEngine := Value;
    (DownButton as TSeSkinSpeedButton).SkinEngine := Value;
  end;
  Invalidate;
end;

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

procedure TSeSkinSpinButton.SetSkinObject(const Value: string);
begin
  FSkinObject := Value;
  if UpButton <> nil then
  begin
    (UpButton as TSeSkinSpeedButton).SkinObject := Value;
    (DownButton as TSeSkinSpeedButton).SkinObject := Value;
    (UpButton as TSeSkinSpeedButton).SkinEngine := FSkinEngine; 
    (DownButton as TSeSkinSpeedButton).SkinEngine := FSkinEngine; 
    SkinEngine := FSkinEngine;
  end;
end;

end.
