{***************************************************************************}
{ 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 IWHotSpotEditorDE;
{$I TMSDEFS.INC}
interface
uses
  Classes, IWHotSpotEditor, IWHotSpotImage, Controls,
{$IFDEF DELPHI6_LVL}
  DesignIntf  , DesignEditors
{$ELSE}
  DsgnIntf
{$ENDIF}
  ;


type
  TTIWHotSpotImageEditor = class(TDefaultEditor)
    function GetVerbCount: Integer; override;
    function GetVerb(Index: Integer): String; override;
    procedure ExecuteVerb(Index: Integer); override;
   {$IFNDEF DELPHI6_LVL}
    procedure EditProperty(PropertyEditor: TPropertyEditor;
      var Continue, FreeEditor: Boolean); override;
   {$ELSE}
    procedure EditProperty(const PropertyEditor: IProperty; var Continue: Boolean); override;
   {$ENDIF}
  end;

  TTIWHotSpotEditor = class(TPropertyEditor)
    procedure Edit; override;
    function GetAttributes: TPropertyAttributes; override;
    function GetValue: String; override;

    procedure TransferToHotSpotImage;
    procedure TransferFromHotSpotImage;
  end;


implementation

{ TTIWHotSpotEditor }

//------------------------------------------------------------------------------
procedure TTIWHotSpotEditor.Edit;
var frmEditor: TfrmHSIEditor;
begin
  TransferFromHotSpotImage;

  frmEditor := TfrmHSIEditor.Create(nil);
  try
    if frmEditor.ShowModal = mrOK then
    begin
      TransferToHotSpotImage;
      Modified;
    end;
  finally
    frmEditor.Free;
  end;
end;

//------------------------------------------------------------------------------
function TTIWHotSpotEditor.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog];
end;

//------------------------------------------------------------------------------
function TTIWHotSpotEditor.GetValue: String;
begin
  Result := '(THotSpots)';
end;

{ TTIWHotSpotImageEditor }

//------------------------------------------------------------------------------

{$IFDEF DELPHI6_LVL}
procedure TTIWHotSpotImageEditor.EditProperty(const PropertyEditor: IProperty; var Continue: Boolean);
{$ELSE}
procedure TTIWHotSpotImageEditor.EditProperty(PropertyEditor: TPropertyEditor;
  var Continue, FreeEditor: Boolean);
{$ENDIF}
begin
  if PropertyEditor.GetName = 'HotSpots' then
  begin
    PropertyEditor.Edit;
    Continue := False;
  end
  else inherited;
end;

//------------------------------------------------------------------------------
procedure TTIWHotSpotImageEditor.ExecuteVerb(Index: Integer);
begin
  Edit;
end;

//------------------------------------------------------------------------------
function TTIWHotSpotImageEditor.GetVerb(Index: Integer): String;
begin
  Result := 'Edit hotspots...';
end;

//------------------------------------------------------------------------------
function TTIWHotSpotImageEditor.GetVerbCount: Integer;
begin
  Result := 1;
end;

//------------------------------------------------------------------------------
procedure TTIWHotSpotEditor.TransferFromHotSpotImage;
var
  Comp: TTIWHotSpotImage;
begin
  Comp := TTIWHotSpotImage(GetComponent(0));
  FHotSpots.Assign(Comp.HotSpots);
  if not Comp.Picture.Empty then
    FPicture.Assign(Comp.Picture);
end;

//------------------------------------------------------------------------------
procedure TTIWHotSpotEditor.TransferToHotSpotImage;
var
  Comp: TTIWHotSpotImage;
begin
  Comp := TTIWHotSpotImage(GetComponent(0));
  Comp.HotSpots.Assign(FHotSpots);
  Comp.Picture.Assign(FPicture);
  Comp.RePaint;
end;

end.
