
{*******************************************************}
{                                                       }
{       ScaleRichView                                   }
{       The given component represents TLabel for work  }
{       with ScaleRichView, signatures of such kind are }
{       used on headings of the majority of windows.    }
{                                                       }
{       Copyright (c) Ilya Zelenskiy                    }
{       Ilya.Zelenskiy@gmail.com                        }
{       http://www.trichview.com                        }
{                                                       }
{*******************************************************}

unit SRVLabel;

interface
{$I RV_Defs.inc}
uses
  Windows, Messages, Forms, Graphics, Controls, Classes, SRVControl, RVGrIn;

type
  TSRVLabel = class(TSRVGraphicControl)
  private
  protected
  public
    constructor Create(AOwner: TComponent); override;
    procedure Invalidate; override;
    procedure Resize; override;
    procedure Paint; override;
    procedure PaintTo(DC : THandle; X, Y : Integer); override;
  published
    property SkinManager;
    property SkinSchemeIndex;
    property Anchors;
    property Align;
    property Font;
    property Offset;
    property Height default 14;
    property Width default 47;
    property Alignment;
    property AutoSize;
    property Caption;
    property DrawOnPrint;
    property ForegroundColor;
    property BackgroundColor;
    property Hint;
    property Enabled;
    property PopupMenu;
    property ShowHint;
    property Visible;
    property OnClick;
    {$IFDEF RICHVIEWDEF5}
    property OnContextPopup;
    {$ENDIF}
    property OnDblClick;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
  end;

implementation

constructor TSRVLabel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Height := 14;
  Width := 47;
end;

procedure TSRVLabel.Invalidate;
begin
  if Parent = nil then exit;
//  Realign;

  PaintTo(Canvas.handle, 0, 0);
end;

procedure TSRVLabel.Resize;
begin
  inherited;
  if Parent <> nil then
    PaintTo(Canvas.handle, 0, 0);
end;

procedure TSRVLabel.Paint;
begin
  inherited;
  if Parent <> nil then
    PaintTo(Canvas.handle, 0, 0);
end;

procedure TSRVLabel.PaintTo(DC : THandle; X, Y : Integer);
var
     Canvas, FormatCanvas: TCanvas;
     FullWidth: Integer;
     R : TRect;
begin
  Canvas := TCanvas.Create;

  try
    Canvas.Handle := DC;
    Canvas.Lock;

    R := GetClientRect;
    OffsetRect(R, X, Y);
    DrawBoxBG(Canvas, R, SkinManager, SkinSchemeIndex, True,
      MouseIn, False, Enabled, False, 1, clNone);

    Canvas.Font := Font;
    Canvas.Brush.Style := bsClear;
    FormatCanvas := GetFormatCanvas;
    FullWidth := ClientWidth;
    Canvas.Brush.Style := bsClear;
    if Offset<>0 then begin
      Canvas.Font.Color := BackgroundColor;
  //    Canvas.TextRect(R, X+Offset, Y+Offset, Caption);
      SRVCMultilineTextOut(Canvas, FormatCanvas, X+Offset, Y+Offset, FullWidth,
        Alignment, Caption, FGraphicInterface);
    end;
    Canvas.Font.Color := ForegroundColor;
    //Canvas.TextRect(R, X, Y, Caption);
    SRVCMultilineTextOut(Canvas, FormatCanvas, X, Y, FullWidth,
      Alignment, Caption, FGraphicInterface);
    Canvas.Brush.Style := bsSolid;

    DrawBoxBorder(Canvas, R, SkinManager, SkinSchemeIndex, True,
      MouseIn, False, Enabled, False, 1);
  finally
    Canvas.Unlock;
    Canvas.Handle := 0;
    Canvas.Free;
  end;
end;


end.
