unit Dpi.ExtCtrls;

interface

uses
  Classes, SysUtils, Controls, ExtCtrls, Dpi.Controls, Dpi.Graphics;

type
  TTimer = ExtCtrls.TTimer;

  { TDpiPanel }

  TDpiPanel = class(TWinControl)
  private
    NativePanel: TPanel;
  public
    function GetNativePanel: TPanel;
    constructor Create(TheOwner: TComponent); override;
    destructor Destroy; override;
  end;

  { TDpiPaintBox }

  TDpiPaintBox = class(TGraphicControl)
  public
    NativePaintBox: TPaintBox;
    function GetNativeGraphicControl: Controls.TGraphicControl; override;
    constructor Create(TheOwner: TComponent); override;
    destructor Destroy; override;
  published
    property OnPaint;
    property Visible;
  end;

  { TDpiImage }

  TDpiImage = class(TControl)
  private
    FDpiPicture: TPicture;
    FStretch: Boolean;
    procedure SetPicture(AValue: TPicture);
    procedure SetStretch(AValue: Boolean);
  protected
  public
    NativeImage: TImage;
    function GetNativeControl: Controls.TControl; override;
    destructor Destroy; override;
  published
    property Stretch: Boolean read FStretch write SetStretch;
    property Picture: TPicture read FDpiPicture write SetPicture;
    property Visible;
  end;


procedure Register;


implementation

uses
  Dpi.Common;

procedure Register;
begin
  RegisterComponents(DpiControlsComponentPaletteName, [TDpiPaintBox, TDpiImage]);
end;

{ TDpiPanel }

function TDpiPanel.GetNativePanel: TPanel;
begin
  if not Assigned(NativePanel) then NativePanel := TPanel.Create(nil);
    Result := NativePanel;
end;

constructor TDpiPanel.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
end;

destructor TDpiPanel.Destroy;
begin
  FreeAndNil(NativePanel);
  inherited;
end;

{ TDpiPaintBox }

function TDpiPaintBox.GetNativeGraphicControl: Controls.TGraphicControl;
begin
  if not Assigned(NativePaintBox) then NativePaintBox := TPaintBox.Create(nil);
  Result := NativePaintBox;
end;

constructor TDpiPaintBox.Create(TheOwner: TComponent);
begin
  inherited;
  Canvas := TCanvas.Create;
  Canvas.NativeCanvas := NativePaintBox.Canvas;
  UpdateNativeControl;
  ScreenChanged;
end;

destructor TDpiPaintBox.Destroy;
begin
  FreeAndNil(NativePaintBox);
  inherited;
end;

{ TDpiImage }

procedure TDpiImage.SetStretch(AValue: Boolean);
begin
  if FStretch = AValue then Exit;
  FStretch := AValue;
  NativeImage.Stretch := AValue;
end;

procedure TDpiImage.SetPicture(AValue: TPicture);
begin
  if FDpiPicture = AValue then Exit;
  FDpiPicture := AValue;
end;

function TDpiImage.GetNativeControl: Controls.TControl;
begin
  if not Assigned(NativeImage) then NativeImage := TImage.Create(nil);
  Result := NativeImage;
end;

destructor TDpiImage.Destroy;
begin
  FreeAndNil(NativeImage);
  inherited Destroy;
end;

initialization

RegisterClasses([TDpiImage]);

end.

