unit frmHyperLink;

interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, 
  Buttons, ExtCtrls, uCommon;

type
  TFormHyperLink = class(TForm)
    OKBtn: TButton;
    CancelBtn: TButton;
    Label1: TLabel;
    CBTarget: TComboBox;
    Label2: TLabel;
    EdtHyperLink: TEdit;
  private
    { Private declarations }
    FText: string;
  public
    { Public declarations }
    procedure SetText(AValue: string);
    function GetHTML: string;
  end;

  function GetPlugInHTML(AHandle: THandle;ASelectedText: PChar;
                   AResultHTHML: TResultHTML): Boolean;stdcall;
  procedure GetPlugInName(AValue: PChar);stdcall;
  procedure GetPlugInDescription(AValue: PChar);stdcall;

var
  FormHyperLink: TFormHyperLink;

implementation

{$R *.dfm}

{ TFormHyperLink }

function TFormHyperLink.GetHTML: string;
begin
  result := Format('<a href="%s" target="%s">%s</a>',
    [EdtHyperLink.Text, CBTarget.Text, FText]);
end;

procedure TFormHyperLink.SetText(AValue: string);
begin
  FText := AValue;
end;


function GetPlugInHTML(AHandle: THandle;ASelectedText: PChar;
                   AResultHTHML: TResultHTML): Boolean;stdcall;
var
  Dlg: TFormHyperLink;
  t: string;
begin
  result := false;
  AResultHTHML.ReplaceHTML[0] := #0;
  AResultHTHML.BodyHTML[0] := #0;
  AResultHTHML.BodyTagHTML[0] := #0;
  AResultHTHML.HeadHTML[0] := #0;
  if ASelectedText = nil then
    Exit;
  Dlg := TFormHyperLink.Create(nil);
  Dlg.ParentWindow := AHandle;
  Dlg.SetText(PChar(ASelectedText));
  if Dlg.ShowModal = mrOK then
  begin
    result := true;
    t := Dlg.GetHTML;
    FillMemory(AResultHTHML.ReplaceHTML, MAXHTMLSIZE, 0);
    StrLCopy(AResultHTHML.ReplaceHTML, PChar(t), MAXHTMLSIZE);
  end;
end;

procedure GetPlugInName(AValue: PChar);stdcall;
begin
  FillMemory(AValue, MAXNAMEDESCSIZE, 0);
  StrLCopy(AValue, PChar('添加超链接'), MAXNAMEDESCSIZE);
end;

procedure GetPlugInDescription(AValue: PChar);stdcall;
begin
  FillMemory(AValue, MAXNAMEDESCSIZE, 0);
  StrLCopy(AValue, PChar('本插件将为您选择的文字添加超链接'),MAXNAMEDESCSIZE);
end;

end.
