unit Aidplugin;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  ComObj, ActiveX, ANYQAid_TLB, StdVcl, ANYQCOM_TLB;

type
  TAidPlugin = class(TAutoObject, IANYQPlugin)
  private
    _ANYQ: IANYQController;
    _menu_id: Widestring;
  protected
    function NewIM(const jid: WideString; var Body, Subject: WideString;
      const XTags: WideString): WideString; safecall;
    procedure Configure; safecall;
    procedure MenuClick(const ID: WideString); safecall;
    procedure MsgMenuClick(const ID, jid: WideString; var Body,
      Subject: WideString); safecall;
    procedure NewChat(const jid: WideString; const Chat: IANYQChat);
      safecall;
    procedure NewOutgoingIM(const jid: WideString;
      const InstantMsg: IANYQChat); safecall;
    procedure NewRoom(const jid: WideString; const Room: IANYQChat);
      safecall;
    procedure Process(const xpath, event, xml: WideString); safecall;
    procedure Shutdown; safecall;
    procedure Startup(const ANYQController: IANYQController); safecall;
  end;

implementation

uses ComServ, AidChatplugin, frmAid, uAidData, Forms;

function TAidPlugin.NewIM(const jid: WideString; var Body,
  Subject: WideString; const XTags: WideString): WideString;
begin

end;

type
  TActiveForm = class(TCustomForm);

procedure TAidPlugin.Configure;
var
  f: TAidForm;
  SkinFile: WideString;
  haveSkin: Wordbool;
begin
  SkinFile := '';
//  haveSkin := _ANYQ.GetSkin(SkinFile);
  f := TAidForm.Create(nil);
  f._ANYQ := _ANYQ;
  if haveSkin then
  begin
    if SkinFile <> '' then
    begin
//      f.SkinData1.SkinFile := SkinFile;
//      f.SkinData1.LoadFromFile(SkinFile);
    end;
//    f.SkinData1.Active := haveSkin;
  end;
  f.show;
  TActiveForm(f).activate;
//  f.SkinData1.UpdateMenu(f);
{  with TAidForm.Create(nil) do
  begin
    show;
    activate;
    _ANYQ.skinForm(handle);
  end;{}
end;

procedure TAidPlugin.MenuClick(const ID: WideString);
begin
  if id = _menu_id then
  begin
    Configure;
  end;
end;

procedure TAidPlugin.MsgMenuClick(const ID, jid: WideString; var Body,
  Subject: WideString);
begin

end;

procedure TAidPlugin.NewChat(const jid: WideString;
  const Chat: IANYQChat);
var
  cp: TAidChatPlugin;
  chat_com: IANYQChat;
begin
  // a new chat window is firing up
  chat_com := IUnknown(Chat) as IANYQChat;
  cp := TAidChatPlugin.Create(chat_com);
  cp.ObjAddRef();
  cp.reg_id := chat_com.RegisterPlugin(IANYQChatPlugin(cp));
end;

procedure TAidPlugin.NewOutgoingIM(const jid: WideString;
  const InstantMsg: IANYQChat);
begin

end;

procedure TAidPlugin.NewRoom(const jid: WideString;
  const Room: IANYQChat);
begin

end;

procedure TAidPlugin.Process(const xpath, event, xml: WideString);
begin

end;

procedure TAidPlugin.Shutdown;
begin
  AidData.Free;
  AidData := nil;
end;

procedure TAidPlugin.Startup(const ANYQController: IANYQController);
begin
  AidData := TAidData.Create;
  _ANYQ := ANYQController;
  _menu_id := _ANYQ.addPluginMenu('»úÆ÷ÈËÉèÖÃ');
end;

initialization
  TAutoObjectFactory.Create(ComServer, TAidPlugin, Class_AidPlugin,
    ciMultiInstance, tmApartment);
end.
