{***************************************************************************}
{ TMS IntraWeb Component Pack Pro                                           }
{ for Delphi & C++Builder                                                   }
{                                                                           }
{ written by TMS Software                                                   }
{            copyright © 2002 - 2007                                        }
{            Email : info@tmssoftware.com                                   }
{            Web : http://www.tmssoftware.com                               }
{                                                                           }
{ The source code is given as is. The author is not responsible             }
{ for any possible damage done due to the use of this code.                 }
{ The component can be freely used in any application. The complete         }
{ source code remains property of the author and may not be distributed,    }
{ published, given or sold in any form as such. No parts of the source      }
{ code can be included in any other component or application without        }
{ written authorization of the author.                                      }
{***************************************************************************}

unit IWLBLDE;

interface

uses
  Windows, Classes, StdCtrls, IWPicCntnr, Graphics;

type
  {$I tmsdefs.inc}

  TIWHTMLLabelDE = class(TCustomLabel)
  private
    FHTMLText: string;
    FDesignLive: Boolean;
    function GetBaseDir: string;
    procedure SetBaseDir(const Value: string);
    procedure SetHTMLText(const Value: string);
    procedure SetDesignLive(const Value: Boolean);
  protected
    FAutoSize: Boolean;
    ic: TIWHTMLPictureCache;
    procedure Paint; override;
  public
    function GetDisplText: string; virtual;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Align;
    property BaseDir: string read GetBaseDir write SetBaseDir;
    property DesignLive: Boolean read FDesignLive write SetDesignLive;
    property Font;
    property HTMLText: string read FHTMLText write SetHTMLText;
  end;


implementation

uses
  SysUtils, ImgList, CommCtrl, Controls;

{ TIWHTMLLabelDE }

{$DEFINE REMOVESTRIP}
{$DEFINE REMOVEDRAW}

{$I IWHTMLENG.PAS}

constructor TIWHTMLLabelDE.Create(AOwner: TComponent);
begin
  inherited;
  ic := TIWHTMLPictureCache.Create;
  ic.DesignLive := True;
end;

destructor TIWHTMLLabelDE.Destroy;
begin
  ic.Free;
  inherited;
end;

function TIWHTMLLabelDE.GetBaseDir: string;
begin
  Result := ic.BaseDir;
end;

function TIWHTMLLabelDE.GetDisplText: string;
begin
  Result := FHTMLText;
end;

procedure TIWHTMLLabelDE.Paint;
var
  LWidth: Integer;
  fr: TRect;
  a,s,fa:string;
  xsize,ysize,hl,ml: integer;
  hr:trect;

begin
  with Canvas do
  begin
    Font.Assign(Self.Font);
    Brush.Style := bsSolid;
    Brush.Color := Self.Color;
    if FAutoSize then
    begin
      LWidth := Trunc(TextWidth(GetDisplText) * 1.10);
    end
    else
    begin
      LWidth := Width;
    end;

    Pen.Color := Brush.Color;
    Rectangle(clientrect);

    fr := Rect(0, 0, LWidth, 1000);
    HTMLDrawEx(Canvas, GetDisplText, fr, nil, 0,0,-1,-1,0,false,false,false,false,false,false,True,1.0,
      clBlue,clNone,clNone,clGray,a,s,fa,xsize,ysize,hl,ml,hr,ic,nil);
  end;
end;

procedure TIWHTMLLabelDE.SetBaseDir(const Value: string);
begin
  ic.BaseDir := Value;
end;

procedure TIWHTMLLabelDE.SetDesignLive(const Value: Boolean);
begin
  FDesignLive := Value;
  ic.DesignLive := Value;
end;

procedure TIWHTMLLabelDE.SetHTMLText(const Value: string);
begin
  FHTMLText := Value;
  Invalidate;
end;

end.
 