{***************************************************************************}
{ TMS IntraWeb Component Pack Pro                                           }
{ for Delphi & C++Builder                                                   }
{                                                                           }
{ written by TMS Software                                                   }
{            copyright © 2002 - 2009                                        }
{            Email : info@tmssoftware.com                                   }
{            Web : http://www.tmssoftware.com                               }
{                                                                           }
{ The source code is given as is. The author is not responsible             }
{ for any possible damage done due to the use of this code.                 }
{ The component can be freely used in any application. The complete         }
{ source code remains property of the author and may not be distributed,    }
{ published, given or sold in any form as such. No parts of the source      }
{ code can be included in any other component or application without        }
{ written authorization of the author.                                      }
{***************************************************************************}

unit IWHTMLColDE;
{$I TMSDEFS.INC}
interface

uses
  Classes, Forms, Dialogs, Controls, Windows, TypInfo, Graphics, IWHTMLColProp, 
  Sysutils, IWTMSMenus,
{$IFDEF DELPHI6_LVL}
  DesignIntf, DesignEditors
{$ELSE}
  DsgnIntf
{$ENDIF}
  ;

type
  TIWHTMLColDefaultEditor = class(TDefaultEditor)
  protected
  {$IFNDEF DELPHI6_LVL}
    procedure EditProperty(PropertyEditor: TPropertyEditor;
                           var Continue, FreeEditor: Boolean); override;
  {$ELSE}
    procedure EditProperty(const Prop:IProperty; var Continue:Boolean); override;
  {$ENDIF}
  public
    function GetVerb(index:integer):string; override;
    function GetVerbCount:integer; override;
    procedure ExecuteVerb(Index:integer); override;
  end;

  TIWHTMLCollectionProperty = class(TClassProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    procedure Edit; override;
    procedure SetValue(const Value: String); override;
    function GetValue: String; override;
  end;

implementation

function TIWHTMLCollectionProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog];
end;

procedure TIWHTMLCollectionProperty.Edit;
var
  HTMLEditor: THTMLColEditor;
  PropInfo: PPropInfo;
  s: string;
  i: Integer;
  sl: TTIWStaticMenuItems;
  id: TItemData;
begin
  HTMLEditor := THTMLColEditor.Create(Application);

  try
    PropInfo:= typInfo.GetPropInfo(GetComponent(0).ClassInfo,'BaseDir');
    if Assigned(PropInfo) then
      HTMLEditor.HTMLStaticText1.BaseDir := GetStrProp(GetComponent(0),PropInfo);

    HTMLEditor.ToolButton3.Enabled := GetComponent(0).ClassName = 'TTIWStaticMenu';

    sl := TTIWStaticMenuItems(GetOrdValue);

    HTMLEditor.ListBox1.Items.Clear;

    for i := 1 to sl.Count do
    begin
      s := sl.Items[i - 1].Caption;
      id := TItemData.Create;
      id.ClientCode := sl.Items[i - 1].ClientClick;
      id.Fixed := sl.Items[i - 1].Fixed;
      HTMLEditor.ListBox1.Items.AddObject(s,id);
    end;

    HTMLEditor.Memo1.Lines.Clear;

    if sl.Count > 0 then
    begin
      HTMLEditor.Memo1.Lines.Text := sl.Items[0].Caption;
      HTMLEditor.Memo2.Lines.Text := sl.Items[0].ClientClick;
      HTMLEditor.CheckBox1.Checked := sl.Items[0].Fixed;
      HTMLEditor.ListBox1.ItemIndex := 0;
    end;

    if HTMLEditor.Showmodal = mrOK then
    begin
      sl.Clear;
      for i := 1 to HTMLEditor.Listbox1.Items.Count do
      begin
        with sl.Add do
        begin
          Caption := HTMLEditor.Listbox1.Items[i - 1];
          ClientClick := TItemData(HTMLEditor.Listbox1.Items.Objects[i - 1]).ClientCode;
          Fixed := TItemData(HTMLEditor.Listbox1.Items.Objects[i - 1]).Fixed;
        end;




      end;

      {
      sl.Assign(HTMLEditor.Listbox1.Items);

      for i := 1 to sl.Count do
      begin
        if Assigned(sl.Objects[i - 1]) then
        begin
          s := '"#'+IntToStr(Integer(sl.Objects[i - 1]))+'"'+sl.Strings[i - 1];
          sl.Strings[i - 1] := s;
        end;
      end;
      tmplst.Assign(sl);
      }
      Designer.Modified;

    end;

  finally
    //sl.Free;
    HTMLEditor.Free;
  end;

end;

procedure TIWHTMLCollectionProperty.SetValue(const Value: String);
begin
end;

function TIWHTMLCollectionProperty.GetValue: String;
begin
  Result := '(HTMLCollection)';
end;

{ TIWHTMLDefaultEditor }
{$IFDEF DELPHI6_LVL}
procedure TIWHTMLColDefaultEditor.EditProperty(const Prop:IProperty; var Continue:Boolean);
{$ELSE}
procedure TIWHTMLColDefaultEditor.EditProperty(PropertyEditor: TPropertyEditor;
  var Continue, FreeEditor: Boolean);
{$ENDIF}
var
  PropName: string;
begin
 {$IFDEF DELPHI6_LVL}
  PropName := Prop.GetName;
 {$ELSE}
  PropName := PropertyEditor.GetName;
 {$ENDIF}
  if (CompareText(PropName, 'ITEMS') = 0) then
  begin
  {$IFDEF DELPHI6_LVL}
    Prop.Edit;
  {$ELSE}
    PropertyEditor.Edit;
  {$ENDIF}
    Continue := False;
  end;
end;



procedure TIWHTMLColDefaultEditor.ExecuteVerb(Index: integer);
var
  compiler:string;
begin
  case Index of
  0: Edit;
  1: begin
    {$IFDEF VER130}
    {$IFDEF BCB}
    compiler := 'C++Builder 5';
    {$ELSE}
    compiler := 'Delphi 5';
    {$ENDIF}
    {$ENDIF}
    {$IFDEF VER140}
      {$IFDEF BCB}
      compiler := 'C++Builder 6';
      {$ELSE}
      compiler := 'Delphi 6';
      {$ENDIF}
    {$ENDIF}

    {$IFDEF VER150}
      compiler := 'Delphi 7';
    {$ENDIF}

    {$IFDEF VER170}
      compiler := 'Delphi 2005';
    {$ENDIF}

    {$IFDEF VER180}
      compiler := 'Delphi 2006';
    {$ENDIF}

    {$IFDEF VER185}
      compiler := 'Delphi 2007';
    {$ENDIF}

    {$IFDEF VER200}
      compiler := 'Delphi 2009';
    {$ENDIF}

    {$IFDEF LINUX}
    {$IFDEF VER140}
      compiler := 'Kylix 2';
    {$ENDIF}
    {$IFDEF VER150}
      compiler := 'Kylix 3';
    {$ENDIF}
    {$ENDIF}

       MessageDlg(Component.ClassName + ' for ' + Compiler + #13#10#13#10'© 2002 - 2009 by TMS software'#13#10'http://www.tmssoftware.com',
                  mtInformation,[mbok],0);
     end;
  end;
end;



function TIWHTMLColDefaultEditor.GetVerb(index: integer): string;
begin
  Result := '';
  case Index of
  0:Result := 'HTML Collection Editor';
  1:Result := 'About';
  end;
end;

function TIWHTMLColDefaultEditor.GetVerbCount: integer;
begin
  Result := 2;
end;

end.
