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

  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 EpIIGroupBoxs;

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

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  KsUtils, KsBitmap, KsControls, KsGroupBoxs, EpIIStyles, EpIIVersion;

type

{ TEpGroupBoxII class }

  TEpGroupBoxII = class(TKsCustomGroupBox)
  private
    FBackground: TEpBackground;
    FBorder: TepBorder;
    FCaptionBackground: TEpBackground;
    FCaptionBorder: TepBorder;
    procedure DoChange(Sender: TObject);

    function GetVersion: TEpVersion;
    procedure SetVersion(const Value: TEpVersion);
    procedure SetBackground(const Value: TEpBackground);
    procedure SetBorder(const Value: TepBorder);
    procedure SetCaptionBackground(const Value: TEpBackground);
    procedure SetCaptionBorder(const Value: TepBorder);
  protected
    procedure PaintBackground; 
    procedure PaintBuffer; override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Loaded; override;
  published
    property Anchors;
    property Align;
    { It's possible to draw the background for control. Based on TEpBackground class.
      See Also:
        TEpBackground
    }
    property Background: TEpBackground read FBackground write SetBackground;
    { It's possible to draw the border for control. Based on TEpBorder class.
      See Also:
        TEpBorder
    }
    property Border: TepBorder read FBorder write SetBorder;
    property Blend;
    property BlendValue;
    property Caption;
    property CaptionMargin;
    { It's possible to draw the caption background for control. Based on TEpBackground class.
      See Also:
        TEpBackground
    }
    property CaptionBackground: TEpBackground read FCaptionBackground
      write SetCaptionBackground;
    { It's possible to draw the caption border for control. Based on TEpBorder class.
      See Also:
        TEpBorder
    }
    property CaptionBorder: TepBorder read FCaptionBorder
      write SetCaptionBorder;
    property Font;
    property Transparent;
    property Version: TEpVersion read GetVersion write SetVersion
      stored False;
  end;

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

{ TEpGroupBoxII }

constructor TEpGroupBoxII.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Transparent := true;
  
  FBackground := TEpBackground.Create;
  FBackground.OnChange := DoChange;
  FBorder := TEpBorder.Create;
  FBorder.OnChange := DoChange;

  FCaptionBackground := TEpBackground.Create;
  FCaptionBackground.OnChange := DoChange;
  FCaptionBorder := TEpBorder.Create;
  FCaptionBorder.OnChange := DoChange;
end;

destructor TEpGroupBoxII.Destroy;
begin
  FCaptionBackground.Free;
  FCaptionBorder.Free;
  FBackground.Free;
  FBorder.Free;
  inherited Destroy;
end;

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

procedure TEpGroupBoxII.DoChange(Sender: TObject);
begin
  Invalidate;
end;

{ Drawing }

procedure TEpGroupBoxII.PaintBackground;
var
  R, CaptionRect: TRect;
begin
  if FBorder = nil then Exit;

  Buffer.Font.Assign(Self.Font);

  R := GetBoxRect;
  CaptionRect := Rect(CaptionMargin, 0, CaptionMargin + Buffer.TextWidth(Caption),
    Buffer.TextHeight(Caption));
  InflateRect(CaptionRect, 3, 0);

  { Draw Frame }
  FBackGround.Draw(Buffer, R);
  FBorder.Draw(Buffer, R, 0);

  { Draw Caption }
  FCaptionBackGround.Draw(Buffer, CaptionRect);
  FCaptionBorder.Draw(Buffer, CaptionRect, 0);
  Buffer.DrawText(Caption, CaptionRect, DT_CENTER or DT_VCENTER or DT_SINGLELINE);
end;

procedure TEpGroupBoxII.PaintBuffer;
begin
  inherited PaintBuffer;
end;

{ Properties }

function TEpGroupBoxII.GetVersion: TEpVersion;
begin
  Result := EpVersion;
end;

procedure TEpGroupBoxII.SetVersion(const Value: TEpVersion);
begin
end;

procedure TEpGroupBoxII.SetBackground(const Value: TEpBackground);
begin
  FBackground.Assign(Value);
end;

procedure TEpGroupBoxII.SetBorder(const Value: TepBorder);
begin
  FBorder.Assign(Value);
end;

procedure TEpGroupBoxII.SetCaptionBackground(const Value: TEpBackground);
begin
  FCaptionBackground.Assign(Value);
end;

procedure TEpGroupBoxII.SetCaptionBorder(const Value: TepBorder);
begin
  FCaptionBorder.Assign(Value);
end;

end.
