////////////////////////////////////////////////////////////////////////////////
// CM2API.pas
// ----------
// This unit contains the API system for CoolMon 2.
//
// Last Edit: July 5th, 2006
// Certified: NA
//
// This unit is coded in : Delphi 7
//
// Unit is copyright (c) 2005 - 2006, The CoolMon Project
////////////////////////////////////////////////////////////////////////////////
unit CM2API;

interface

Uses CM2PlugInTypes, CM2VisPlugTypes, SysUtils, Filter; //, Unit1; //, bogusapiform;

Type
 TAPICallBackProc = Procedure(Owner: PVisObject; APIStr: PChar; Var CallBackStr: String) of Object;
 TAPI = Class(TObject)
 private
    FOnAPI: TAPICallBackProc;
    procedure SetOnAPI(const Value: TAPICallBackProc);

 public
  Property OnAPI: TAPICallBackProc read FOnAPI write SetOnAPI;
  Procedure ProcessAPI(Owner: PVisObject; APIStr: Pchar; Var CallBackStr: String);
 end;

Var
 APIObj: TAPI;

Function API(Owner: PVisObject; APIStr: PChar; Var CallBackStr: String): boolean;

implementation

Function API(Owner: PVisObject; APIStr: PChar; Var CallBackStr: String): boolean;
Begin
{ If uppercase(Copy(APIStr, 1, length('SET_TOOLTIP:'))) = 'SET_TOOLTIP:' then begin
  CM2MainForm.tray.Hint := Copy(APIStr, length('SET_TOOLTIP:') + 1, length(APIStr));
 end;
 if uppercase(Copy(APIStr, 1, length('SHOW_FORM:'))) = 'SHOW_FORM:' then begin
  CM2MainForm.SetFormVisible(Copy(APIStr, length('SHOW_FORM:') + 1, length(APIStr)), true);
 end;
 if uppercase(Copy(APIStr, 1, length('HIDE_FORM:'))) = 'HIDE_FORM:' then begin
  CM2MainForm.SetFormVisible(Copy(APIStr, length('HIDE_FORM:') + 1, length(APIStr)), false);
 end;
 if uppercase(Copy(APIStr, 1, length('TOGGLE_FORM:'))) = 'TOGGLE_FORM:' then begin
  CM2MainForm.SetFormVisible(Copy(APIStr, length('TOGGLE_FORM:') + 1, length(APIStr)), false, true);
 end;
}
 Result := True;
 APIObj.ProcessAPI(Owner, APIStr, CallBackStr);
end;

{ TAPI }

procedure TAPI.ProcessAPI(Owner: PVisObject; APIStr: Pchar;
  var CallBackStr: String);
Var
 I: Integer;
 Handled: Boolean;
 S: String;
begin
 For I := 1 to CountFilt(APIStr, ';') do begin
  S := GetFilt(APIStr, I, ';');
  Handled := false;
  CallBackStr := '';
  If uppercase(S) = 'REPAINT' then begin
   // Cause Form to repaint Visual Object
   Owner^.Parent.fParent.Repaint;
   Handled := true;
  end;
  If uppercase(Copy(S, 1, length('SENDBACK:'))) = 'SENDBACK:' then Begin
   CallBackStr := Copy(S, 10, length(S));
   Handled := true;
  end;
  If (assigned(fOnAPI)) and (Not handled) then begin
   fOnAPI(Owner, Pchar(S), CallBackStr);
  end;
 end;
end;

procedure TAPI.SetOnAPI(const Value: TAPICallBackProc);
begin
  FOnAPI := Value;
end;

initialization
Begin
 APIObj := TAPI.Create;
end;

Finalization
begin
 APIObj.Free;
end;

end.
