(************************************************************************
*    This File is Part of the AHM Triton Tools                          *
*    for Borland Delphi and C++ Builder.                                *
*************************************************************************
* Copyright © 1995-1999 Alexander H. Mehlhorn (AHM) and Tritontools.com *
* All Rights reserved.                                                  *
*                                                                       *
*    For more Information contact us at                                 *
*    E-Mail : support@tritontools.com                                   *
*    URL : http://www.tritontools.com                                   *
*                                                                       *
*    AHM is copyright by Alexander H. Mehlhorn                          *
*    All Parts of this Collection were developed,                       *
*    designed and implemented by AHM                                    *
*                                                                       *
*    Under no Circumstances may you distribute this file                *
*    in this or any other format. This File is supplied                 *
*    as Evaluation of Source only. No Delphi Components may be developed*
*    using extracts or subsets of this code without expressed permission*
*    by AHM.                                                            *
*                                                                       *
*************************************************************************)
unit AHMTPanel;

interface
{$I AHM.INC}
uses
  SysUtils, Windows, Controls,AHMEnhancedClass,ahmtbackground,
  StdCtrls, Classes, Graphics, Menus,Extctrls;

type
  TAHMPanel = class(TCustomPanel)
  private
    f3d : TAHMFont3D;
    finner,fouter : TAHMFrame;
    FAlignment: TAlignment;
    FAutoSize: Boolean;
    fback : TAHMBackground;
    FAHMAboutStr : TAHMAboutEnhancedStr;
    ffloat : boolean;
    fbspace:Integer;
    procedure Setfloat(value : Boolean);
    procedure SetAlignment(Value: TAlignment);
    Procedure Set3D(value : TAHMFont3D);
    procedure SetbSpace(value : Integer);
    procedure SetAutoSize(Value: Boolean);
    procedure Setback(value : TAHMBackground);
    procedure SetInner(value : TAHMFrame);
    procedure SetOuter(value : TAHMFrame);
  protected
    procedure Paint; override;
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Loaded; override;
    procedure AlignControls(AControl: TControl; var Rect: TRect); override;
  published
    property Align;
    {$IFDEF AHMONLY4}
    property Anchors;
    property BiDiMode;
    property Constraints;
    property DragKind;
    property ParentBiDiMode;
    {$ENDIF}
    property About : TAHMAboutEnhancedStr read FAHMAboutStr write FAHMAboutStr stored False;
    property Alignment: TAlignment read FAlignment write SetAlignment default taCenter;
    property Font3D : TAHMFont3D read f3d write Set3d stored true;
    property AutoSize: Boolean read FAutoSize write SetAutoSize default False;
    property Background : TAHMBackground read fback write Setback;
    property DlgFrame : Boolean read ffloat write Setfloat default False;
    property FrameInner : TAHMFrame read finner write Setinner;
    property FrameOuter : TAHMFrame read fouter write Setouter;
    property Borderwidth : Integer read fbspace write Setbspace default 0;
    property DragCursor;
    property DragMode;
    property Enabled;
    property Caption;
    property Ctl3D;
    property Font;
    property Locked;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Visible;
    property OnClick;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnResize;
    property OnStartDrag;
  end;

implementation

constructor TAHMPanel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ffloat:=false;
  finner:=TAHMFrame.create(self);
  fouter:=TAHMFrame.create(self);
  FFloat:=False;
  FBSpace:=0;
  Alignment:=tacenter;
  f3d:=TAHMFont3D.create(Self);
end;

procedure TAHMPanel.AlignControls(AControl: TControl; var Rect: TRect);
var
  BevelSize: Integer;
begin
  BevelSize := fbspace;
  if Frameouter.framestyle<>framenone then Inc(BevelSize, frameouter.framewidth);
  if FrameInner.framestyle<>framenone then Inc(BevelSize, frameInner.framewidth);
  InflateRect(Rect, -BevelSize, -BevelSize);
  inherited AlignControls(AControl, Rect);
end;

procedure TAHMPanel.Loaded;
begin
  inherited Loaded;
end;

procedure TAHMPanel.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if (Operation = opRemove) and  (AComponent = Background) then Background := nil;
end;


destructor TAHMPanel.Destroy;
begin
  if fback<>nil then fback.OList.remove(self);
  finner.free;
  fouter.free;
  f3d.free;
  inherited Destroy;
end;


procedure TAHMPanel.SetAutoSize(Value: Boolean);
begin
  FAutoSize := Value;
  Invalidate;
end;

procedure TAHMPanel.SetFloat(Value: Boolean);
begin
  Ffloat := Value;
  Invalidate;
end;

procedure TAHMPanel.SetBSpace(Value: Integer);
begin
  if value>0 then Fbspace := Value;
  Invalidate;
end;

procedure TAHMPanel.SetInner(Value: TAHMFrame);
begin
  Finner := Value;
  Invalidate;
end;

procedure TAHMPanel.SetOuter(Value: TAHMFrame);
begin
  Fouter := Value;
  Invalidate;
end;


procedure TAHMPanel.SetAlignment(Value: TAlignment);
begin
  FAlignment := Value;
  invalidate;
end;

procedure TAHMPanel.Set3D(Value: TAHMFont3D);
begin
  F3D := value;
  recreatewnd;
end;

procedure TAHMPanel.SetBack(Value: TAHMBackground);
Begin
  if fback<>nil then fback.OList.remove(self);
  if value<>nil then value.additem(self);
  fback:=Value;
  Invalidate;
end;

procedure TAHMPanel.Paint;
var
  fRect: TRect;
  i : Integer;
const
  Alignments: array[TAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER);
begin
  frect:=clientrect;
  inherited paint;
  if assigned(fback) then fback.draw(Canvas.Handle,width,height,True);
  if ffloat then frame3d(canvas,frect,clbtnhighlight,clblack,1);
  if ffloat then frame3d(canvas,frect,clbtnface,clbtnshadow,1);
  if ffloat then frame3d(canvas,frect,clbtnface,clbtnface,1);
  fouter.draw(Canvas.handle,frect);
  if fbspace>0 then
    For i:=0 to fbspace do InflateRect(fRect, -1, -1);
  finner.draw(canvas.handle,frect);
  Canvas.Font := Self.Font;
  f3d.write(Font,Canvas.handle,fRect,Caption, (DT_EXPANDTABS or  DT_VCENTER or DT_SingleLine) or Alignments[FAlignment],enabled);
end;

end.

