library tasktray;

(*
needs for compile
  http://okapony.hp.infoseek.co.jp/
  [old] http://homepage1.nifty.com/~okapon/
*)

uses Classes, Rubies, uDefUtils, Pythia, Taskbar;

{$E so}

var
  cTrayIcon: Tvalue;

function ap_cTrayIcon: Tvalue;
begin
  result := cTrayIcon;
end;

procedure TrayIcon_setup(obj: Tvalue; real: TTrayIcon);
begin
  ap_set_child_attr_module(obj);
end;

function TrayIcon_event_handle(This, name: Tvalue): Tvalue; cdecl;
begin
  EventHandle(This, name, [PhiGetHandle]);
  result := Qnil;
end;

function TrayIcon_alloc(This: Tvalue; real: TTrayIcon): Tvalue;
begin
  result := ChildAlloc(This, real);
  TrayIcon_setup(result, real);
end;

function ap_iTrayIcon(real: TTrayIcon; owner: Tvalue): Tvalue;
begin
  result := TrayIcon_alloc(cTrayIcon, real);
  ap_owner(result, owner);
end;

function ap_iTrayIcon_v(var AControl; owner: Tvalue): Tvalue;
begin
  result := ap_iTrayIcon(TTrayIcon(AControl), owner);
end;

function TrayIcon_new(argc: integer; argv: Pointer; This: Tvalue): Tvalue; cdecl;
var
  real: TTrayIcon;
begin
  real := TTrayIcon.Create(nil);
  result := CompoAlloc(This, real);
  TrayIcon_setup(result, real);
  ap_obj_call_init(result, argc, argv);
end;

procedure Init_tasktray;
begin
  PhiStart;

  cTrayIcon := DefinePersistentClass(ap_mPhi, TTrayIcon, ap_cComponent, ap_iTrayIcon_v);

  rb_define_method(cTrayIcon, 'event_handle', @TrayIcon_event_handle, 1);
  DefineSingletonMethod(cTrayIcon, 'new', TrayIcon_new);
end;

exports
  ap_cTrayIcon,
  ap_iTrayIcon,
  Init_tasktray;

end.
