(************************************************************************
*    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 AHMTLabel;

interface
{$I AHM.INC}
uses
  Windows, Messages, Classes,AHMTBackground, Graphics, Controls,AHMEnhancedClass,StdCtrls;

type
  TAHMLabel = class(TCustomLabel)
  private
    FAHMAboutStr : TAHMAboutEnhancedStr;
    f3D : TAHMFont3D;
    fback : TAHMBackground;
    fback2 : TAHMBackground;
    fframe : TAHMFrame;
    procedure SetBack(value : TAHMBackground);
    procedure SetBack2(value : TAHMBackground);
    procedure Set3D(Value: TAHMFont3D);
    procedure SetFrm(value : TAHMFrame);
  protected
    procedure Paint; override;
    procedure Notification(AComponent: TComponent;Operation: TOperation); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property AutoSize default False;
  published
    property About : TAHMAboutEnhancedStr read FAHMAboutStr write FAHMAboutStr stored False;
    {$IFDEF AHMONLY4}
    property Anchors;
    property BiDiMode;
    property Constraints;
    property DragKind;
    property ParentBiDiMode;
    {$ENDIF}
    property Align;
    property Alignment;
    property Caption;
    property Color;
    property Enabled;
    property FocusControl;
    property FontBackground : TAHMBackground read fback write Setback;
    property Font;
    property Font3D : TAHMFont3D read f3d write Set3D stored true;
    property Frame : TAHMFrame read fframe write Setfrm stored true;
    property Background : TAHMBackground read fback2 write Setback2;
    property Transparent;
    property ShowHint;
    property Visible;
    property WordWrap;
    property OnClick;
    property OnDblClick;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnDragDrop;
    property OnEndDrag;
    property OnStartDrag;
    property OnDragOver;
    property DragCursor;
    property DragMode;
    property ParentColor;
    property ParentFont;
    Property ShowAccelChar;
  end;

implementation

constructor TAHMLabel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  AutoSize:=false;
  f3d:=TAHMFont3d.create(Self);
  ControlStyle := ControlStyle + [csReplicatable];
  fframe:=TAHMFrame.create(Self);
  fframe.framestyle:=framenone;
end;

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

destructor TAHMLabel.Destroy;
begin
  if fback<>nil then fback.OList.remove(self);
  if fback2<>nil then fback2.OList.remove(self);
  F3d.free;
  fframe.free;
  inherited Destroy;
end;

procedure TAHMLabel.Paint;
const
  Alignments: array[TAlignment] of Word =(DT_LEFT, DT_RIGHT, DT_CENTER);
  WordWraps: array[Boolean] of Word = (0, DT_WORDBREAK);
var
  TempRect:TRect;
  flags : Longint;
begin
  TempRect:=Clientrect;
  Temprect.Left:=Temprect.Left+FFrame.TotalWidth;
  Temprect.Bottom:=Temprect.Bottom-FFrame.Totalwidth;
  Temprect.Top:=Temprect.Top+FFrame.Totalwidth;
  Temprect.Right:=Temprect.Right-FFrame.Totalwidth;
  if not(Transparent) then
  begin
    Canvas.Brush.Color := Self.Color;
    Canvas.Brush.Style := bsSolid;
    Canvas.FillRect(ClientRect);
    if assigned(fback2) then fback2.draw(Canvas.Handle,width,height,true);
  end;
  Canvas.Brush.Style := bsClear;
  flags := DT_EXPANDTABS or WordWraps[WordWrap] or Alignments[Alignment];
  Text := GetLabelText;
  if (Flags and DT_CALCRECT <> 0) and ((Text = '') or ShowAccelChar and
     (Text[1] = '&') and (Text[2] = #0)) then Text := Text + ' ';
  TempRect.Top:=TempRect.Top+fframe.Framewidth;
  TempRect.Right:=TempRect.Right-fframe.Totalwidth;
  TempRect.Bottom:=TempRect.Bottom-fframe.Framewidth;
  if assigned(fback) then
     fback.write(f3d,Font,canvas,Temprect,text,flags) else
     f3d.write(Font,canvas.handle,Temprect,text,flags,enabled);
  Temprect:=clientrect;
  fframe.draw(Canvas.handle,Temprect);
end;

procedure TAHMLabel.Set3D(Value: TAHMFont3D);
begin
  if value<>f3d then
  begin
    f3d:=value;
    invalidate;
  end;
end;

procedure TAHMLabel.Setfrm(Value: TAHMFrame);
begin
  if value<>fframe then
  begin
    fframe:=value;
    invalidate;
  end;
end;


procedure TAHMLabel.Setback(Value: TAHMBackground);
begin
  if fback<>nil then fback.OList.remove(self);
  if value<>nil then value.additem(self);
  fback:=value;
  invalidate;
end;

procedure TAHMLabel.Setback2(Value: TAHMBackground);
begin
  if fback2<>nil then fback2.OList.remove(self);
  if value<>nil then value.additem(self);
  fback2:=value;
  invalidate;
end;

end.

