unit PlugInInfoDlg;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, ExtCtrls, CM2GenPlugTypes, CM2VisPlugTypes,
  CM2PlugInTypes, CM2MMRB, Registry, lpl_SysUtils, CM2EditorSupportInterface, COmobj,
  CM2CMLxPlugTypes, ShellApi, CM2VisInterface;

type
  TForm5 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    GroupBox1: TGroupBox;
    ListView1: TListView;
    GroupBox2: TGroupBox;
    ListView2: TListView;
    ComboBox1: TComboBox;
    Button1: TButton;
    Label9: TLabel;
    Label10: TLabel;
    GroupBox4: TGroupBox;
    Label12: TLabel;
    Label11: TLabel;
    ico: TImage;
    Bevel1: TBevel;
    GroupBox3: TPageControl;
    TabSheet1: TTabSheet;
    ListView3: TListView;
    TabSheet2: TTabSheet;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    Label29: TLabel;
    Label30: TLabel;
    Label31: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    Label34: TLabel;
    Label35: TLabel;
    Bevel2: TBevel;
    procedure ComboBox1Change(Sender: TObject);
    procedure ListView2DblClick(Sender: TObject);
    procedure ListView3DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    GenExList: TGenExList;
    Procedure LoadIcon(GUID: TGUID);
    Function Execute(PlugIn: TGenPlugIn): Boolean; overload;
    function Execute(PlugIn: TVisPlugIn): Boolean; overload;
    function Execute(PlugIn: TCMLxPlugIn): Boolean; overload;
    Procedure ShowParamDetail(ListItem: TListItem);
    Procedure SetEventLabels(Str: String);
    Procedure SetNOE(NOE: Int64);
  end;

var
  Form5: TForm5;

implementation

{$R *.dfm}

{ TForm5 }

function TForm5.Execute(PlugIn: TGenPlugIn): Boolean;
Var
 I: Integer;
 ListItem: TListItem;
 Reg: TRegistry;
 S: String;
 EditorSupport: ICM2EditorSupport10;
 SupportsEditor: boolean;
 ShowAt: Byte;
begin
 SupportsEditor := True;
 Try
  EditorSupport := CreateComObject (PlugIn.GUID) as ICM2EditorSupport10;
 except
  SupportsEditor := false;
 end;
 Label5.Caption := PlugIn.Name;
 Label6.Caption := CM2MMRB.WordToStr(PlugIn.Version);
 Label7.Caption := 'General';
 Label8.Caption := CM2MMRB.WordToStr(PlugIn.RequiredCoreVersion);
 S := 'Not Supported';
 Reg := TRegistry.Create;
 If Reg.OpenKey(PathToOk(CertifiedGENPluginsLocation) + GUIDToString(PlugIn.Guid), false) then begin
  If Reg.valueexists('updatefile') then begin
   S := Reg.ReadString('updatefile');
   If S = '' Then S := 'Disabled'
    else S := 'Yes';
  End
 End;
 Reg.Free;
 Label10.Caption := S;
 Listview1.items.clear;
 For I := 0 to PlugIn.InfoList.Count - 1 do begin
  ListItem := Listview1.Items.Add;
  ListItem.Caption := PlugIn.InfoList[I].VarName;
  ListItem.SubItems.Add(PlugIn.InfoList[I].Variable);
 End;
 GroupBox2.Visible := True;
 GroupBox3.Visible := False;
 GroupBox4.Visible := False;
 Combobox1.Clear;
 For I := 0 to PlugIn.SensorList.Count - 1 do begin
  ShowAt := saDesignTime;
  If SupportsEditor then begin
   If EditorSupport.ShowSensor(I, ShowAt) <> S_OK then begin
    ShowAt := saDesignTime;
   end;
  end;
  If ShowAt = saDesignTime then Combobox1.Items.Add(PlugIn.SensorList[I].Name);
 End;
 GenExList := TGenExList.Create(PlugIn.PlugIn);
 If Combobox1.Items.Count > 0 then begin
  Combobox1.Enabled := True;
  Combobox1.itemindex := 0;
  Combobox1Change(self);
 End
  else
 begin
  Combobox1.Enabled := False;
 End;
 LoadIcon(Plugin.GUID);
 Result := Showmodal = mrOk;
 GenExList.Free;
end;

function TForm5.Execute(PlugIn: TVisPlugIn): Boolean;
Var
 I: Integer;
 ListItem: TListItem;
 VisExList: TVisExList;
 Reg: TRegistry;
 S: String;
 C: Cardinal;
begin
 Label5.Caption := PlugIn.Name;
 Label6.Caption := CM2MMRB.WordToStr(PlugIn.Version);
 Label7.Caption := 'Visual';
 Label8.Caption := CM2MMRB.WordToStr(PlugIn.RequiredCoreVersion);
 S := 'Not Supported';
 Reg := TRegistry.Create;
 If Reg.OpenKey(PathToOk(CertifiedVISPluginsLocation) + GUIDToString(PlugIn.Guid), false) then begin
  If Reg.valueexists('updatefile') then begin
   S := Reg.ReadString('updatefile');
   If S = '' Then S := 'Disabled'
    else S := 'Yes';
  End
 End;
 Reg.Free;
 Label10.Caption := S;
 Listview1.items.clear;
 For I := 0 to PlugIn.InfoList.Count - 1 do begin
  ListItem := Listview1.Items.Add;
  ListItem.Caption := PlugIn.InfoList[I].VarName;
  ListItem.SubItems.Add(PlugIn.InfoList[I].Variable);
 End;
 GroupBox2.Visible := False;
 GroupBox3.Visible := True;
 GroupBox4.Visible := False;
 Case PlugIn.InterfaceVersion of
  1: VisExList := TVisExList.Create(PlugIn.PlugIn);
  2: VisExList := TVisExList.Create(PlugIn.PlugIn2);
  3: VisExList := TVisExList.Create(PlugIn.PlugIn3);
  4: VisExList := TVisExList.Create(PlugIn.PlugIn4);
  else begin
   VisExList := Nil;
  end;
 end;
 Listview3.Items.Clear;
 For I := 0 to VisExList.Count - 1 do begin
  ListItem := Listview3.Items.add;
  ListITem.Caption := VisExList[I].Name;
  If VisExList[I].EIT = eitRequired then begin
   ListItem.SubItems.Add('Required');
  End
   else
  Begin
   ListItem.SubItems.Add('Optional');
  End;
  ListItem.SubItems.Add(VisExList[I].Description);
  ListItem.SubItems.Add(VisExList[I].Value);
 End;
 SetEventLabels('No');
 Case PlugIn.InterfaceVersion of
  2: SetEventLabels('V2');
  3: Begin
      If Plugin.PlugIn3.NotifyOnEvent(C) <> E_FAIL then begin
       SetNOE(C);
      end;
     end;
  4: Begin
      If Plugin.PlugIn4.NotifyOnEvent(C) <> E_FAIL then begin
       SetNOE(C);
      end;
     end;
 end;
 LoadIcon(Plugin.GUID);
 Result := Showmodal = mrOk;
 VisExList.Free;
end;

procedure TForm5.ComboBox1Change(Sender: TObject);
Var
 I: Integer;
 ListItem: TListItem;
begin
 Listview2.Items.Clear;
 For I := 0 to GenExList[Combobox1.itemindex].Count - 1 do begin
  ListItem := Listview2.Items.add;
  ListITem.Caption := GenExList[Combobox1.itemindex].ExInfo[I].Name;
  If GenExList[Combobox1.ItemIndex].ExInfo[I].EIT = eitRequired then begin
   ListItem.SubItems.Add('Required');
  End
   else
  Begin
   ListItem.SubItems.Add('Optional');
  End;
  ListItem.SubItems.Add(GenExList[Combobox1.itemindex].ExInfo[I].Description);
  ListItem.SubItems.Add(GenExList[Combobox1.itemindex].ExInfo[I].Value);
 End;
end;

procedure TForm5.ListView2DblClick(Sender: TObject);
begin
 ShowParamDetail(Listview2.Selected);
end;

procedure TForm5.ShowParamDetail(ListItem: TListItem);
begin
 If ListItem = nil then exit;
 MessageDlg('Name:'+#13+#10+ListItem.Caption+#13+#10+''+#13+#10+'Description:'+#13+#10+ListItem.SubItems[1]+#13+#10+''+#13+#10+'Default Value:' + #13#10 + ListItem.SubItems[2], mtInformation, [mbOK], 0);
end;

procedure TForm5.ListView3DblClick(Sender: TObject);
begin
 ShowParamDetail(Listview3.Selected);
end;

function TForm5.Execute(PlugIn: TCMLxPlugIn): Boolean;
Var
 I: Integer;
 ListItem: TListItem;
 Reg: TRegistry;
 S: String;
begin
 Label5.Caption := PlugIn.Name;
 Label6.Caption := CM2MMRB.WordToStr(PlugIn.Version);
 Label7.Caption := 'cmlX';
 Label8.Caption := CM2MMRB.WordToStr(PlugIn.RequiredCoreVersion);
 S := 'Not Supported';
 Reg := TRegistry.Create;
 If Reg.OpenKey(PathToOk(CertifiedCMLxPluginsLocation) + GUIDToString(PlugIn.Guid), false) then begin
  If Reg.valueexists('updatefile') then begin
   S := Reg.ReadString('updatefile');
   If S = '' Then S := 'Disabled'
    else S := 'Yes';
  End
 End;
 Reg.Free;
 Label10.Caption := S;
 Listview1.items.clear;
 For I := 0 to PlugIn.InfoList.Count - 1 do begin
  ListItem := Listview1.Items.Add;
  ListItem.Caption := PlugIn.InfoList[I].VarName;
  ListItem.SubItems.Add(PlugIn.InfoList[I].Variable);
 End;
 GroupBox4.Visible := True;
 GroupBox3.Visible := False;
 GroupBox2.Visible := False;
 Label11.Caption := Plugin.TagName;
 LoadIcon(Plugin.GUID);
 Result := Showmodal = mrOk;
 GenExList.Free;
End;

procedure TForm5.LoadIcon(GUID: TGUID);
Var
  LargeIcon, SmallIcon: HIcon;
  Icon: TIcon;
  Reg: TRegistry;
  FNAme: String;
begin
 Reg := TRegistry.Create;
 Reg.RootKey := HKEY_CLASSES_ROOT;
 if not Reg.OpenKey('CLSID\' + GUIDToString(GUID) + '\InProcServer32', false) then exit;
 FName := Reg.ReadString('');
 If not fileexists(Fname) then exit;
 ExtractIconEx(PChar(FName), 0, LargeIcon, SmallIcon, 1);
 Icon := TIcon.Create;
 self.Icon.Handle := SmallIcon;
 ico.Picture.Icon.Handle := LargeIcon;
 FreeAndNil(Icon);
end;

procedure TForm5.SetEventLabels(Str: String);
Var
 I: Integer;
begin
 For I := 0 to ComponentCount - 1 do begin
  If (Components[I] is TLabel) then begin
   If (Components[I].Tag = 999) then begin
    (Components[I] as TLabel).Caption := Str;
   end;
  end;
 end;
end;

procedure TForm5.SetNOE(NOE: Int64);
begin
  If NOE - noeMouseMove >= 0 Then begin
   Label31.Caption := 'Yes';
   Dec(Noe, noeMouseMove);
  end;
  If NOE - noeMouseWheelDown >= 0 Then begin
   Label33.Caption := 'Yes';
   Dec(Noe, noeMouseWheelDown);
  end;
  If NOE - noeMouseWheelUp >= 0 Then begin
   Label34.Caption := 'Yes';
   Dec(Noe, noeMouseWheelUp);
  end;
  If NOE - noeMouseWheelAny >= 0 Then begin
   Label32.Caption := 'Yes';
   Dec(Noe, noeMouseWheelAny);
  end;
  If NOE - noeMouseUpMiddle >= 0 Then Begin
   Label23.Caption := 'Yes';
   Dec(Noe, noeMouseUpMiddle);
  end;
  If NOE - noeMouseUpRight >= 0 Then Begin
   Label25.Caption := 'Yes';
   Dec(Noe, noeMouseUpRight);
  end;
  If NOE - noeMouseUpLeft >= 0 Then Begin
   Label21.Caption := 'Yes';
   Dec(Noe, noeMouseUpleft);
  end;
  If NOE - noeMouseDownMiddle >= 0 Then Begin
   Label24.Caption := 'Yes';
   Dec(Noe, noeMouseDownMiddle);
  end;
  If NOE - noeMouseDownRight >= 0 Then begin
   Label35.Caption := 'Yes';
   Dec(Noe, noeMouseDownRight);
  end;
  If NOE - noeMouseDownLeft >= 0 Then begin
   Label22.Caption := 'Yes';
   Dec(Noe, noeMouseDownLeft);
  end;
  If NOE - noeDblClick >= 0 Then Begin
   Label20.Caption := 'Yes';
  End;
end;

end.
