
{******************************************}
{                                          }
{             FastReport v3.0              }
{             New item dialog              }
{                                          }
{         Copyright (c) 1998-2006          }
{         by Alexander Tzyganenko,         }
{            Fast Reports Inc.             }
{                                          }
{******************************************}

unit frxNewItem;

interface

{$I frx.inc}

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

type
  TfrxNewItemForm = class(TForm)
    Pages: TPageControl;
    ItemsTab: TTabSheet;
    TemplatesTab: TTabSheet;
    OkB: TButton;
    CancelB: TButton;
    TemplatesLV: TListView;
    ItemsLB: TListBox;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ItemsLBDblClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure ItemsLBDrawItem(Control: TWinControl; Index: Integer;
      ARect: TRect; State: TOwnerDrawState);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


implementation

{$R *.DFM}

uses frxClass, frxDsgnIntf, frxUtils, frxRes;


procedure TfrxNewItemForm.FormCreate(Sender: TObject);
begin
  Caption := frxGet(5300);
  ItemsTab.Caption := frxGet(5301);
  TemplatesTab.Caption := frxGet(5302);
  OkB.Caption := frxGet(1);
  CancelB.Caption := frxGet(2);
end;

procedure TfrxNewItemForm.FormShow(Sender: TObject);
var
  i: Integer;
  Item: TfrxWizardItem;
begin
  for i := 0 to frxWizards.Count - 1 do
  begin
    Item := frxWizards[i];
    ItemsLB.Items.AddObject(Item.ClassRef.GetDescription, Item);
  end;
end;

procedure TfrxNewItemForm.ItemsLBDblClick(Sender: TObject);
begin
  ModalResult := mrOk;
end;

procedure TfrxNewItemForm.FormDestroy(Sender: TObject);
var
  w: TfrxCustomWizard;
begin
  if ModalResult = mrOk then
  begin
    if (Pages.ActivePage = ItemsTab) and (ItemsLB.ItemIndex <> -1) then
    begin
      w := TfrxCustomWizard(TfrxWizardItem(ItemsLB.Items.Objects[ItemsLB.ItemIndex]).ClassRef.NewInstance);
      w.Create(Owner);
      if w.Execute then
        w.Designer.Modified := True;
      w.Free;
    end
    else if (Pages.ActivePage = TemplatesTab) and (TemplatesLV.Selected <> nil) then
    begin
    end;
  end;
end;

procedure TfrxNewItemForm.ItemsLBDrawItem(Control: TWinControl;
  Index: Integer; ARect: TRect; State: TOwnerDrawState);
begin
  with ItemsLB.Canvas do
  begin
    FillRect(ARect);
    frxDrawTransparent(ItemsLB.Canvas, ARect.Left + 8, ARect.Top + 3,
      TfrxWizardItem(ItemsLB.Items.Objects[Index]).ButtonBmp);
    TextOut(ARect.Left + 32, ARect.Top + 8, ItemsLB.Items[Index]);
  end;
end;

procedure TfrxNewItemForm.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_F1 then
    frxResources.Help(Self);
end;

end.


//<censored>