(************************************************************************
*    This File is Part of the AHM Triton Tools                          *
*    for Borland Delphi and C++ Builder.                                *
*************************************************************************
* Copyright © 1995-1999 Alexander H. Mehlhorn (AHM) and Tritontools.com *
* All Rights reserved.                                                  *
*                                                                       *
*    For more Information contact us at                                 *
*    E-Mail : support@tritontools.com                                   *
*    URL : http://www.tritontools.com                                   *
*                                                                       *
*    AHM is copyright by Alexander H. Mehlhorn                          *
*    All Parts of this Collection were developed,                       *
*    designed and implemented by AHM                                    *
*                                                                       *
*    Under no Circumstances may you distribute this file                *
*    in this or any other format. This File is supplied                 *
*    as Evaluation of Source only. No Delphi Components may be developed*
*    using extracts or subsets of this code without expressed permission*
*    by AHM.                                                            *
*                                                                       *
*************************************************************************)
unit AHMTWaveHolderDsgn;
{$I AHM.INC}
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,AHMTSysDsgnWnd,
  DesignIntf,LibIntf,DsgnWnds,ExtCtrls,Buttons,StdCtrls,AHMSystemConst,AHMTWaveHolder,AHMSystemClass
  {$IFDEF AHMINPRISE5},Contnrs{$ENDIF};

type
  TAHMInternalWaveHolderEditor = class(TAHMSysDsgnWnd)
  private
    Listbox: TListbox;
    Panel: TPanel;
    SpeedB:TSpeedButton;
    DelButton : TBitBtn;
    SaveButton : TBitBtn;    
    AddButton : TBitBtn;
    PlayButton : TBitBtn;
    procedure Setup;
    procedure DoFormClose(Sender: TObject; var Action: TCloseAction);
    procedure AddItem(Sender : TObject);
    procedure DeleteItem(Sender : TObject);
    procedure DoEditorClose(Sender : TObject);
    procedure UpdateSelf(Sender : TObject);
    procedure LMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SelfSelect(Sender : TObject);
    Procedure SaveFile(Sender : TObject);    
    Procedure PlayWave(Sender : TObject);
    Procedure ListBoxKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);
  protected
    procedure Activated; override;
  public
    FWaveHolder : TCollection;
    procedure FormModified; override;
    {$IFDEF AHMINPRISE4}
    procedure ComponentDeleted(Component: IPersistent); override;
    {$ELSE}
    procedure ComponentDeleted(Component:TComponent); override;
    {$ENDIF}
    {$IFDEF AHMINPRISE3}
    procedure FormClosed(AForm:TCustomForm); override;
    {$ELSE}
    procedure FormClosed(AForm:TForm); override;
    {$ENDIF}
    destructor Destroy; override;
  published
  end;
  TAHMExternalWaveHolderEditor = class(TAHMSysDsgnWnd)
  private
    Listbox: TListbox;
    Panel: TPanel;
    SpeedB:TSpeedButton;
    DelButton : TBitBtn;
    AddButton : TBitBtn;
    PlayButton : TBitBtn;
    procedure Setup;
    procedure DoFormClose(Sender: TObject; var Action: TCloseAction);
    procedure AddItem(Sender : TObject);
    procedure DeleteItem(Sender : TObject);
    procedure DoEditorClose(Sender : TObject);
    procedure UpdateSelf(Sender : TObject);
    procedure LMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SelfSelect(Sender : TObject);
    Procedure PlayWave(Sender : TObject);
    Procedure ListBoxKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);
  protected
    procedure Activated; override;
  public
    FWaveHolder : TCollection;
    procedure FormModified; override;
    {$IFDEF AHMINPRISE4}
    procedure ComponentDeleted(Component: IPersistent); override;
    {$ELSE}
    procedure ComponentDeleted(Component:TComponent); override;
    {$ENDIF}
    {$IFDEF AHMINPRISE3}
    procedure FormClosed(AForm:TCustomForm); override;
    {$ELSE}
    procedure FormClosed(AForm:TForm); override;
    {$ENDIF}
    destructor Destroy; override;
  published
  end;
Type
  TAHMExternalWaveHolderProperty = class(TClassProperty)
  public
    procedure Edit; override;
    function GetAttributes: TPropertyAttributes; override;
  end;
  TAHMInternalWaveHolderProperty = class(TClassProperty)
  public
    procedure Edit; override;
    function GetAttributes: TPropertyAttributes; override;
  end;
  TAHMWaveHolderComponentEditor=class(TDefaultEditor)
  public
    procedure ExecuteVerb(Index : Integer); override;
    function GetVerb(Index : Integer): string; override;
    function GetVerbCount : Integer; override;
    procedure Edit; override;
  end;

implementation

{$R AHMTIWaveHolderDsgn.res}
{$R AHMTEWaveHolderDsgn.res}

{ TAHMExternalWaveHolderEditor }

Var
  AHMExternalWaveHolderEditor : TAHMExternalWaveHolderEditor=nil;
  FIWaveHolderOwner: TAHMWaveHolder=nil;
  FEWaveHolderOwner: TAHMWaveHolder=nil;

Procedure EditExternalCollection(Items : TCollection;CComponent : TAHMWaveHolder;FormDsgn:{$IFDEF AHMINPRISE4}IFormDesigner{$ELSE}TFormDesigner{$ENDIF});
Var I : Integer;
begin
  if AHMExternalWaveHolderEditor<>nil then AHMExternalWaveHolderEditor.Bringtofront else
  begin
    {$WARNINGS OFF}AHMExternalWaveHolderEditor:=TAHMExternalWaveHolderEditor.Create(Application);{$WARNINGS ON}
    AHMExternalWaveHolderEditor.Setup;
  end;
  with AHMExternalWaveHolderEditor do
  begin
    AHMExternalWaveHolderEditor.Designer:=FormDsgn;
    FWaveHolder:=Items;
    FEWaveHolderOwner:=CComponent;
    AHMExternalWaveHolderEditor.Caption:=ahmsccolledit+FEWaveHolderOwner.Name;
    try
      AHMExternalWaveHolderEditor.SpeedB.Glyph.LoadFromResourceName(HInstance,FEWaveHolderOwner.ClassName);
    except
    end;
    Listbox.Clear;
    if FWaveHolder.Count>0 then
    begin
      For I:=0 to FWaveHolder.Count-1 do
      AHMExternalWaveHolderEditor.Listbox.Items.AddObject(Inttostr(I)+' - '+FWaveHolder.Items[I].DisplayName,FWaveHolder.Items[I]);
      if Listbox.Items.count>0 then Listbox.ItemIndex:=0;
    end;
    Show;
    UpdateSelf(nil);
  end;
end;

procedure TAHMExternalWaveHolderEditor.Setup;
begin
  Height:= 240;
  Width:= 320;
  BorderStyle:= bsToolWindow;
  Position:=poScreenCenter;
  KeyPreview:=True;
  Panel:=TPanel.Create(self);
  OnClose:=DoFormClose;
  with Panel do
  begin
    Width:=111;
    Height:=216;
    Align:= alRight;
    BevelOuter:= bvNone;
    Parent:=self;
    AddButton:=TBitBtn.Create(self);
    with AddButton do
    begin
      Left:= 8;
      Top:= 8;
      Width:= 97;
      Height:= 25;
      Parent:=Panel;
      Caption:=ahmsccolladd;
      TabOrder:=0;
      OnClick:=AddItem;
      Default:= True;
      Glyph.LoadFromResourceName(HInstance,'AHMEWHOLDADD');
      Numglyphs:=2;
    end;
    DelButton:=TBitBtn.Create(self);
    with DelButton do
    begin
      Left:=8;
      Top:=36;
      Width:=97;
      Height:=25;
      Parent:=Panel;
      Caption:=ahmsccolldel;
      TabOrder:=1;
      OnClick:=DeleteItem;
      Glyph.LoadFromResourceName(HInstance,'AHMEWHOLDDEL');
      Numglyphs:=2;
    end;
    PlayButton:=TBitBtn.Create(self);
    with PlayButton do
    begin
      Left:=8;
      Top:=64;
      Width:=97;
      Height:=25;
      Parent:=Panel;
      Caption:='Test Wave...';
      TabOrder:=3;
      OnClick:=PlayWave;
      Glyph.LoadFromResourceName(HInstance,'AHMEWHOLDPLAY');
      Numglyphs:=2;
    end;
    SpeedB:=TSpeedButton.Create(self);
    with SpeedB do
    begin
      Top:=140;
      Left:=41;
      Width:=28;
      Height:=28;
      Flat:=True;
      Parent:=Panel;
      OnCLick:=SelfSelect;
    end;
    with TBitBtn.Create(self) do
    begin
      Left:=8;
      Top:=184;
      Width:=97;
      Height:=25;
      Parent:=Panel;
      Caption:=ahmsccollclose;
      TabOrder:=4;
      OnClick:=DoEditorClose;
    end;
  end;
  ListBox:=TListBox.Create(Self);
  with Listbox do
  begin
    Parent:=self;
    Align:= alClient;
    OnMouseDown:=LMouseDown;
    OnKeyDown:=ListBoxKeyDown;
  end;
end;

procedure TAHMExternalWaveHolderEditor.AddItem(Sender: TObject);
begin
  FWaveHolder.Add;
  Listbox.Items.AddObject(Inttostr(FWaveHolder.Count-1)+' - '+FWaveHolder.Items[FWaveHolder.Count-1].DisplayName,FWaveHolder.Items[FWaveHolder.Count-1]);
  Listbox.Itemindex:=Listbox.Items.Count-1;
  UpdateSelf(Self);
end;

procedure TAHMExternalWaveHolderEditor.Activated;
begin
//  SpeedButton1Click(self);
//  inherited;
end;


procedure TAHMExternalWaveHolderEditor.DeleteItem(Sender: TObject);
Var I : Integer;
    SInd : String;
begin
  if (Listbox.ItemIndex>-1) and (Listbox.Items.count>0) then
  begin
    FWaveHolder.Items[Listbox.ItemIndex].Free;
    Listbox.Items.Delete(Listbox.ItemIndex);
    For I:=0 to Listbox.Items.Count-1 do
    begin
      SInd:=Listbox.Items[I];
      Delete(SInd,1,Pos(' - ',SInd)-1);
      SInd:=InttoStr(I)+SInd;
      ListBox.Items[I]:=SInd;
    end;
    if Listbox.Items.Count>0 then
    Listbox.Itemindex:=Listbox.Items.Count-1;
  end;
  UpdateSelf(Self);
end;


{$IFDEF AHMINPRISE3}
procedure TAHMExternalWaveHolderEditor.FormClosed(AForm: TCustomForm);
begin
  FEWaveHolderOwner:=nil;
  FWaveHolder:=nil;
  ListBox.Clear;
  Release;
  inherited;
end;

{$ELSE}
procedure TAHMExternalWaveHolderEditor.FormClosed(AForm: TForm);
begin
  FEWaveHolderOwner:=nil;
  FWaveHolder:=nil;
  ListBox.Clear;
  Release;
  inherited;
end;
{$ENDIF}

{$IFDEF AHMINPRISE4}
procedure TAHMExternalWaveHolderEditor.ComponentDeleted(Component: IPersistent);
begin
  if ExtractPersistent(Component)=(FEWaveHolderOwner as TPersistent) then
  begin
    FEWaveHolderOwner:=nil;
    FWaveHolder:=nil;
    ListBox.Clear;
    Release;
  end;
  inherited;
end;
{$ELSE}
procedure TAHMExternalWaveHolderEditor.ComponentDeleted(Component: TComponent);
begin
  if Component=FEWaveHolderOwner then
  begin
    FEWaveHolderOwner:=nil;
    FWaveHolder:=nil;
    ListBox.Clear;
    Release;
  end;
  inherited;
end;
{$ENDIF}

destructor TAHMExternalWaveHolderEditor.Destroy;
begin
  inherited Destroy;
  AHMExternalWaveHolderEditor:=nil;
end;

procedure TAHMExternalWaveHolderEditor.DoEditorClose(Sender: TObject);
begin
  Close;
end;

procedure TAHMExternalWaveHolderEditor.DoFormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  SelfSelect(nil);
  AHMExternalWaveHolderEditor:=nil;
  FEWaveHolderOwner:=nil;
  Action:=caFree;
end;

procedure TAHMExternalWaveHolderEditor.UpdateSelf(Sender: TObject);
begin
  if Listbox.Items.Count>0 then
  begin
    DelButton.Enabled:=True;
    PlayButton.Enabled:=True;
  end else
  begin
    DelButton.Enabled:=False;
    PlayButton.Enabled:=False;
  end;
  LMouseDown(self,mbLeft,[ssLeft],0,0);
end;

procedure TAHMExternalWaveHolderEditor.LMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
{$IFDEF AHMINPRISE5}
var FSelectList: TDesignerSelectionList;
{$ELSE}
var FSelectList: TComponentList;
{$ENDIF}

begin
  if (Button=mbRight) or (Listbox.Items.Count=0) then exit;
  if (ListBox.itemindex<>-1) then
  begin
    {$IFDEF AHMINPRISE5}
    FSelectList:=TDesignerSelectionList.Create;
    if (FWaveHolder.Items[Listbox.ItemIndex] as TCollectionItem)<>nil then
    FSelectList.Add(FWaveHolder.Items[Listbox.ItemIndex] as TCollectionItem)
    else FSelectList.Add(FWaveHolder);
    {$ELSE}
    FSelectList:=TComponentList.Create;
    if (FWaveHolder.Items[Listbox.ItemIndex] as TCollectionItem)<>nil then
    FSelectList.Add(FWaveHolder.Items[Listbox.ItemIndex] as TCollectionItem)
    else FSelectList.Add(FWaveHolder);
    {$ENDIF}
    {$IFDEF AHMINPRISE4}IFormDesigner{$ELSE}TFormDesigner{$ENDIF}(Designer).SetSelections(FSelectList);
  end else SelfSelect(self);
end;

procedure TAHMExternalWaveHolderEditor.SelfSelect(sender : TObject);
{$IFDEF AHMINPRISE5}
var FSelectList: TDesignerSelectionList;
{$ELSE}
var FSelectList: TComponentList;
{$ENDIF}
begin
  {$IFDEF AHMINPRISE5}
  FSelectList:=TDesignerSelectionList.Create;
  {$ELSE}
  FSelectList:=TComponentList.Create;
  {$ENDIF}
  FSelectList.Add(FEWaveHolderOwner);
  {$IFDEF AHMINPRISE4}IFormDesigner{$ELSE}TFormDesigner{$ENDIF}(Designer).SetSelections(FSelectList);
end;

Procedure TAHMExternalWaveHolderEditor.ListBoxKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);
begin
  if Key=VK_Delete then DeleteItem(self);
end;

procedure TAHMExternalWaveHolderEditor.FormModified;
Var i: Integer;
begin
  For I:=0 to FWaveHolder.Count-1 do
    Listbox.Items[I]:=(Inttostr(I)+' - '+FWaveHolder.Items[I].DisplayName);
end;

procedure TAHMExternalWaveHolderEditor.PlayWave(Sender: TObject);
begin
  if (ListBox.itemindex<>-1) then
  begin
    if (FWaveHolder.Items[Listbox.ItemIndex] as TCollectionItem)<>nil then
      TAHMExternalWave(FWaveHolder.Items[Listbox.ItemIndex]).Play;
  end;
end;

{ TAHMExternalWaveHolderProperty }

procedure TAHMExternalWaveHolderProperty.Edit;
begin
  EditExternalCollection(TCollection(GetOrdValue),TAHMWaveHolder(GetComponent(0)),Self.Designer);
end;

function TAHMExternalWaveHolderProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog,paReadOnly];
end;

Var
  AHMInternalWaveHolderEditor : TAHMInternalWaveHolderEditor=nil;

{ TAHMInternalWaveHolderEditor }

Procedure EditInternalCollection(Items : TCollection;CComponent : TAHMWaveHolder);
Var I : Integer;
begin
  if AHMInternalWaveHolderEditor<>nil then AHMInternalWaveHolderEditor.Bringtofront else
  begin
    {$WARNINGS OFF}AHMInternalWaveHolderEditor:=TAHMInternalWaveHolderEditor.Create(Application);{$WARNINGS ON}
    AHMInternalWaveHolderEditor.Setup;
  end;
  with AHMInternalWaveHolderEditor do
  begin
    AHMInternalWaveHolderEditor.Designer:={$IFDEF AHMINPRISE4}IFormDesigner{$ELSE}TFormDesigner{$ENDIF}(TCustomForm(CComponent.Owner).Designer);
    FWaveHolder:=Items;
    FIWaveHolderOwner:=CComponent;
    AHMInternalWaveHolderEditor.Caption:=ahmsccolledit+FIWaveHolderOwner.Name;
    try
      AHMInternalWaveHolderEditor.SpeedB.Glyph.LoadFromResourceName(HInstance,FIWaveHolderOwner.ClassName);
    except
    end;
    Listbox.Clear;
    if FWaveHolder.Count>0 then
    begin
      For I:=0 to FWaveHolder.Count-1 do
      AHMInternalWaveHolderEditor.Listbox.Items.AddObject(Inttostr(I)+' - '+FWaveHolder.Items[I].DisplayName,FWaveHolder.Items[I]);
      Listbox.ItemIndex:=0;
    end;
    Show;
    UpdateSelf(nil);
  end;
end;

procedure TAHMInternalWaveHolderEditor.Setup;
begin
  Height:= 240;
  Width:= 320;
  BorderStyle:= bsToolWindow;
  Position:=poScreenCenter;
  KeyPreview:=True;
  Panel:=TPanel.Create(self);
  OnClose:=DoFormClose;
  with Panel do
  begin
    Width:=111;
    Height:=216;
    Align:= alRight;
    BevelOuter:= bvNone;
    Parent:=self;
    AddButton:=TBitBtn.Create(self);
    with AddButton do
    begin
      Left:= 8;
      Top:= 8;
      Width:= 97;
      Height:= 25;
      Parent:=Panel;
      Caption:=ahmsccolladd;
      TabOrder:=0;
      OnClick:=AddItem;
      Default:= True;
      Glyph.LoadFromResourceName(HInstance,'AHMIWHOLDADD');
      Numglyphs:=2;
    end;
    DelButton:=TBitBtn.Create(self);
    with DelButton do
    begin
      Left:=8;
      Top:=36;
      Width:=97;
      Height:=25;
      Parent:=Panel;
      Caption:=ahmsccolldel;
      TabOrder:=1;
      OnClick:=DeleteItem;
      Glyph.LoadFromResourceName(HInstance,'AHMIWHOLDDEL');
      Numglyphs:=2;
    end;
    PlayButton:=TBitBtn.Create(self);
    with PlayButton do
    begin
      Left:=8;
      Top:=64;
      Width:=97;
      Height:=25;
      Parent:=Panel;
      Caption:='Test Wave...';
      TabOrder:=3;
      OnClick:=PlayWave;
      Glyph.LoadFromResourceName(HInstance,'AHMIWHOLDPLAY');
      Numglyphs:=2;
    end;
    SaveButton:=TBitBtn.Create(self);
    with SaveButton do
    begin
      Left:=8;
      Top:=92;
      Width:=97;
      Height:=25;
      Parent:=Panel;
      Caption:='Save File...';
      TabOrder:=3;
      OnClick:=SaveFile;
      Glyph.LoadFromResourceName(HInstance,'AHMIWHOLDSAVE');
      Numglyphs:=2;
    end;
    SpeedB:=TSpeedButton.Create(self);
    with SpeedB do
    begin
      Top:=140;
      Left:=41;
      Width:=28;
      Height:=28;
      Flat:=True;
      Parent:=Panel;
      OnCLick:=SelfSelect;
    end;
    with TBitBtn.Create(self) do
    begin
      Left:=8;
      Top:=184;
      Width:=97;
      Height:=25;
      Parent:=Panel;
      Caption:=ahmsccollclose;
      TabOrder:=4;
      OnClick:=DoEditorClose;
    end;
  end;
  ListBox:=TListBox.Create(Self);
  with Listbox do
  begin
    Parent:=self;
    Align:= alClient;
    OnMouseDown:=LMouseDown;
    OnKeyDown:=ListBoxKeyDown;
  end;
end;

procedure TAHMInternalWaveHolderEditor.AddItem(Sender: TObject);
begin
  with TOpenDialog.Create(self) do
  try
    Filter:='Wave Files|*.wav';
    DefaultExt:='*.wav';
    Title:='Please select a Wave File';
    if Execute then
    begin
        TAHMInternalWave(FWaveHolder.Add).LoadFromFile(FileName);
        Listbox.Items.AddObject(Inttostr(FWaveHolder.Count-1)+' - '+FWaveHolder.Items[FWaveHolder.Count-1].DisplayName,FWaveHolder.Items[FWaveHolder.Count-1]);
        Listbox.Itemindex:=Listbox.Items.Count-1;
        UpdateSelf(Self);
        Designer.Modified;
    end;
  finally
    free;
  end;
end;

procedure TAHMInternalWaveHolderEditor.Activated;
begin
//  SpeedButton1Click(self);
//  inherited;
end;


procedure TAHMInternalWaveHolderEditor.DeleteItem(Sender: TObject);
Var I : Integer;
    SInd : String;
begin
  if (Listbox.ItemIndex>-1) and (Listbox.Items.count>0) then
  begin
    FWaveHolder.Items[Listbox.ItemIndex].Free;
    Listbox.Items.Delete(Listbox.ItemIndex);
    For I:=0 to Listbox.Items.Count-1 do
    begin
      SInd:=Listbox.Items[I];
      Delete(SInd,1,Pos(' - ',SInd)-1);
      SInd:=InttoStr(I)+SInd;
      ListBox.Items[I]:=SInd;
    end;
    if Listbox.Items.Count>0 then
    Listbox.Itemindex:=Listbox.Items.Count-1;
  end;
  UpdateSelf(Self);
end;


{$IFDEF AHMINPRISE3}
procedure TAHMInternalWaveHolderEditor.FormClosed(AForm: TCustomForm);
begin
  FIWaveHolderOwner:=nil;
  FWaveHolder:=nil;
  ListBox.Clear;
  Release;
  inherited;
end;
{$ELSE}
procedure TAHMInternalWaveHolderEditor.FormClosed(AForm: TForm);
begin
  FEWaveHolderOwner:=nil;
  FWaveHolder:=nil;
  ListBox.Clear;
  Release;
  inherited;
end;
{$ENDIF}

{$IFDEF AHMINPRISE4}
procedure TAHMInternalWaveHolderEditor.ComponentDeleted(Component: IPersistent);
begin
  if ExtractPersistent(Component)=(FIWaveHolderOwner as TPersistent) then
  begin
    FIWaveHolderOwner:=nil;
    FWaveHolder:=nil;
    ListBox.Clear;
    Release;
  end;
  inherited;
end;
{$ELSE}
procedure TAHMInternalWaveHolderEditor.ComponentDeleted(Component: TComponent);
begin
  if Component=FIWaveHolderOwner then
  begin
    FIWaveHolderOwner:=nil;
    FWaveHolder:=nil;
    ListBox.Clear;
    Release;
  end;
  inherited;
end;
{$ENDIF}

destructor TAHMInternalWaveHolderEditor.Destroy;
begin
  inherited Destroy;
  AHMInternalWaveHolderEditor:=nil;
end;

procedure TAHMInternalWaveHolderEditor.DoEditorClose(Sender: TObject);
begin
  Close;
end;

procedure TAHMInternalWaveHolderEditor.DoFormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  SelfSelect(nil);
  AHMInternalWaveHolderEditor:=nil;
  FIWaveHolderOwner:=nil;
  Action:=caFree;
end;

procedure TAHMInternalWaveHolderEditor.UpdateSelf(Sender: TObject);
begin
  if Listbox.Items.Count>0 then
  begin
    DelButton.Enabled:=True;
    PlayButton.Enabled:=True;
    SaveButton.Enabled:=True;
  end else
  begin
    DelButton.Enabled:=False;
    PlayButton.Enabled:=False;
    SaveButton.Enabled:=False;
  end;
  LMouseDown(self,mbLeft,[ssLeft],0,0);
end;

procedure TAHMInternalWaveHolderEditor.LMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
{$IFDEF AHMINPRISE5}
var FSelectList: TDesignerSelectionList;
{$ELSE}
var FSelectList: TComponentList;
{$ENDIF}
begin
  if (Button=mbRight) or (Listbox.Items.Count=0) then exit;
  if (ListBox.itemindex<>-1) then
  begin
    {$IFDEF AHMINPRISE5}
    FSelectList:=TDesignerSelectionList.Create;
    {$ELSE}
    FSelectList:=TComponentList.Create;
    {$ENDIF}
    if (FWaveHolder.Items[Listbox.ItemIndex] as TCollectionItem)<>nil then
    FSelectList.Add(FWaveHolder.Items[Listbox.ItemIndex] as TCollectionItem)
    else FSelectList.Add(FWaveHolder);
    {$IFDEF AHMINPRISE4}IFormDesigner{$ELSE}TFormDesigner{$ENDIF}(Designer).SetSelections(FSelectList);
  end else SelfSelect(self);
end;

procedure TAHMInternalWaveHolderEditor.SelfSelect(sender : TObject);
{$IFDEF AHMINPRISE5}
var FSelectList: TDesignerSelectionList;
{$ELSE}
var FSelectList: TComponentList;
{$ENDIF}
begin
  {$IFDEF AHMINPRISE5}
  FSelectList:=TDesignerSelectionList.Create;
  {$ELSE}
  FSelectList:=TComponentList.Create;
  {$ENDIF}
  FSelectList.Add(FIWaveHolderOwner);
  {$IFDEF AHMINPRISE4}IFormDesigner{$ELSE}TFormDesigner{$ENDIF}(Designer).SetSelections(FSelectList);
end;

Procedure TAHMInternalWaveHolderEditor.ListBoxKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);
begin
  if Key=VK_Delete then DeleteItem(self);
end;

procedure TAHMInternalWaveHolderEditor.FormModified;
Var i: Integer;
begin
  For I:=0 to FWaveHolder.Count-1 do
    Listbox.Items[I]:=(Inttostr(I)+' - '+FWaveHolder.Items[I].DisplayName);
end;

procedure TAHMInternalWaveHolderEditor.PlayWave(Sender: TObject);
begin
  if (ListBox.itemindex<>-1) then
  begin
    if (FWaveHolder.Items[Listbox.ItemIndex] as TCollectionItem)<>nil then
      TAHMInternalWave(FWaveHolder.Items[Listbox.ItemIndex]).Play;
  end;
end;

procedure TAHMInternalWaveHolderEditor.SaveFile(Sender: TObject);
begin
  with TSaveDialog.Create(self) do
  try
    Filter:='All Files|*.*';
    DefaultExt:='*.*';
    Title:='Saving...';
    FileName:=TAHMInternalWave(FWaveHolder.Items[Listbox.ItemIndex]).Wave;
    if Execute then TAHMInternalWave(FWaveHolder.Items[Listbox.ItemIndex]).SaveToFile(FileName);
    Designer.Modified;
  finally
    free;
  end;
end;

{ TAHMInternalWaveHolderProperty }

procedure TAHMInternalWaveHolderProperty.Edit;
begin
  EditInternalCollection(TCollection(GetOrdValue),TAHMWaveHolder(GetComponent(0)));
end;

function TAHMInternalWaveHolderProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog,paReadOnly];
end;

{ TAHMWaveHolderComponentEditor }

procedure TAHMWaveHolderComponentEditor.Edit;
begin
  EditInternalCollection(TCollection(TAHMWaveHolder(Component).Internals),TAHMWaveHolder(Component));
end;

procedure TAHMWaveHolderComponentEditor.ExecuteVerb(Index: Integer);
begin
  if (Index< 0) and (Index>3) then Exit;
  if index=0 then Edit;
  if index=1 then EditExternalCollection(TCollection(TAHMWaveHolder(Component).Externals),TAHMWaveHolder(Component),Self.Designer);
  if index=2 then ShowSysAbout;
end;

function TAHMWaveHolderComponentEditor.GetVerb(Index: Integer): string;
begin
  if index=0 then  Result := ahmscWaveHolder1;
  if index=1 then  Result := ahmscWaveHolder2;
  if index=2 then  Result := '© 1995-1999 AHM';
end;

function TAHMWaveHolderComponentEditor.GetVerbCount: Integer;
begin
  result:=3;
end;


end.

