unit pluginPalette;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ImgList, ExtCtrls;

type
  ToePlugin = class(TForm)
    TrackBar1: TTrackBar;
    PageControl1: TPageControl;
    tabVis: TTabSheet;
    tabGen: TTabSheet;
    tabEx: TTabSheet;
    listEx: TListView;
    listGen: TListView;
    listVis: TListView;
    iconListSmall: TImageList;
    iconListLarge: TImageList;
    TabSheet1: TTabSheet;
    listEvent: TListView;
    IconEvents: TImageList;
    procedure TrackBar1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormHide(Sender: TObject);
    procedure listVisMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure listGenMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormActivate(Sender: TObject);
    procedure FormDeactivate(Sender: TObject);
  private
    IsExtended: boolean;
    procedure UnloadTabs;
    procedure CreatePluginIcons(piName, piGUIDasStr: string; piType: integer);
    procedure WMNCLButtondblclk(var Msg: TWMNCLButtondblclk); message WM_NCLBUTTONDBLCLK;
  public
    oldHeight: integer;
    procedure SetRoll(Extended: Boolean);
    procedure LoadTabs;
    procedure ToggleRoll;
    procedure WM(Var msg: TWMWindowPosChanging); message WM_WINDOWPOSCHANGING;
  end;

var
  oePlugin: ToePlugin;

implementation

uses
  Registry, ShellApi, Main, SnapTo;

{$R *.dfm}

procedure ToePlugin.LoadTabs;
//var
//  i: integer;
begin
  UnloadTabs;
end;

procedure ToePlugin.UnloadTabs;
begin
{
  listVis.Clear;
  listGen.Clear;
  listEx.Clear;
  iconListLarge.Clear;
  iconListSmall.Clear;
}
end;

procedure ToePlugin.CreatePluginIcons(piName, piGUIDasStr: string; piType: integer);
var
  reg: TRegistry;
  lItem: TListItem;
  count: integer;
  fName: string;
  largeIcon, smallIcon: HICON;
  sIcon, lIcon: TIcon;
begin
  lItem := nil;
  reg := TRegistry.Create;
  try
    reg.RootKey := HKEY_CLASSES_ROOT;
    case piType of
      0: lItem := listVis.Items.Add;
      1: lItem := listGen.Items.Add;
      2: lItem := listEx.Items.Add;
    end;
    lItem.Caption := piName;
    lItem.SubItems.Add(piGUIDasStr);
    if reg.OpenKey('\CLSID\' + piGUIDasStr + '\InProcServer32', false) then
      begin
        fName := Reg.ReadString('');
        reg.CloseKey;
        if FileExists(fName) then
          begin
            Count := ExtractIconEx(PChar(fName), -1, largeIcon, smallIcon, 1);
            if Count > 0 then
              begin
                ExtractIconEx(PChar(fName), 0, largeIcon, smallIcon, 1);
                sIcon := TIcon.Create;
                sIcon.Handle := smallIcon;
                iconListSmall.AddIcon(sIcon);
                FreeAndNil(sIcon);
                DestroyIcon(smallIcon);
                lIcon := TIcon.Create;
                lIcon.Handle := largeIcon;
                lItem.ImageIndex := iconListLarge.AddIcon(lIcon);
                FreeAndNil(lIcon);
                DestroyIcon(largeIcon);
              end;
          end;
      end;
  finally
    FreeAndNil(reg);
  end;
end;

procedure ToePlugin.TrackBar1Change(Sender: TObject);
begin
  AlphaBlendValue := TrackBar1.Position;
end;

procedure ToePlugin.ToggleRoll;
begin
  if ClientHeight = TrackBar1.Height then ClientHeight := oldHeight
    else ClientHeight := TrackBar1.Height;
end;

procedure ToePlugin.FormCreate(Sender: TObject);
Var
 I: Integer;
begin
  IsExtended := true;
  left := 50;
  top := 50;
  DoubleBuffered := true;
  oldHeight := ClientHeight;
  PageControl1.ActivePageIndex := 0;
  with oemain do
    begin
      if vpl.Count > 0 then
        for i := 0 to vpl.Count - 1 do
          CreatePluginIcons(vpl.VISPlugIn[i].Name, GUIDToString(vpl[i].GUID), cVIS);
      if gpl.Count > 0 then
        for i := 0 to gpl.Count - 1 do
          CreatePluginIcons(gpl.GenPlugIn[i].Name, GUIDToString(gpl[i].GUID), cGEN);
      if xpl.Count > 0 then
        for i := 0 to xpl.Count - 1 do
          CreatePluginIcons(xpl.CMLXPlugIn[i].Name, GUIDToString(xpl[i].GUID), cEX);
    end;
end;

procedure ToePlugin.FormDestroy(Sender: TObject);
begin
  UnloadTabs;
end;

procedure ToePlugin.FormShow(Sender: TObject);
begin
//  LoadTabs;
  oeMain.actionPluginPalette.Checked := True;
end;

procedure ToePlugin.FormHide(Sender: TObject);
begin
  UnloadTabs;
  oeMain.actionPluginPalette.Checked := False;
end;

procedure ToePlugin.listVisMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbLeft then Listvis.BeginDrag(false, 5);
end;

procedure ToePlugin.listGenMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbLeft then ListGen.BeginDrag(false, 5);
end;

procedure ToePlugin.WM(var msg: TWMWindowPosChanging);
begin
 SnapTo.WMWindowPosChanging(MSG, self);
end;


procedure ToePlugin.SetRoll(Extended: Boolean);
begin
 If not extended then begin
  If not IsExtended then exit;
  oldHeight := ClientHeight;
  ClientHeight := TrackBar1.Height;
  IsExtended := false;
 end
  else
 begin
  If IsExtended then exit;
  ClientHeight := oldHeight;
  IsExtended := true;
 end;
end;

procedure ToePlugin.WMNCLButtondblclk(var Msg: TWMNCLButtondblclk);
begin
 If ((msg.HitTest = HTCAPTION) and (not(Options.ToolWindows.AutoRollUp and (not Options.ToolWindows.ARUExcept.Palette)))) then begin
  SetRoll(not IsExtended);
 end;
end;

procedure ToePlugin.FormActivate(Sender: TObject);
begin
 oeMain.SetHotKeyStates(self);
 If (Options.ToolWindows.AutoRollUp and (not Options.ToolWindows.ARUExcept.Palette)) then begin
  SetRoll(true);
 end;
end;

procedure ToePlugin.FormDeactivate(Sender: TObject);
begin
 If (Options.ToolWindows.AutoRollUp and (not Options.ToolWindows.ARUExcept.Palette)) then begin
  SetRoll(false);
 end;
end;

end.
