{ ------------------------------------------------------------- }
{ Purpose : Next Collection 6                                   }
{ By      : Bojan Nikolic                                       }
{ For     : BergSoft                                            }
{ ------------------------------------------------------------- }
{ Copyright (C) BergSoft.net 2013. All Rights Reserved.         }
{ ------------------------------------------------------------- }
{$I '..\..\NxSuite6.inc'}
unit NxCollectionReg6;

interface

uses
  { Standard }
  Classes, Types, Graphics,
  { Controls }
  Forms, Dialogs, ImgList,
  {$IFDEF UI_TYPES}UITypes,{$ENDIF}
  { Standard (Design) }
  DesignIntf, DesignEditors, VCLEditors,
  { Next Standard 6 (Design) }
  NxStandardReg6,
  { Next Collection 6 }
  NxCollection6, NxNotebook6, NxPageControl6, NxBar6;

type
  { TNxCollectionEditor6 }

  TNxCollectionEditor6 = class(TNextSuiteComponentEditor6);

  { TNxFlipPanelEditor6 }

  TNxFlipPanelEditor6 = class(TNxCollectionEditor6)
  public
    function GetVerb(Index: Integer): string; override;
    function GetVerbCount: Integer; override;
    procedure ExecuteVerb(Index: Integer); override;
  end;

  { TNxNotebookEditor6 }

  TNxNotebookEditor6 = class(TNxCollectionEditor6)
  protected
    function AddSheet: TNxNotebookSheet6; virtual;
  public
    constructor Create(AComponent: TComponent; ADesigner: IDesigner); override;
    function GetVerb(Index: Integer): string; override;
    function GetVerbCount: Integer; override;
    procedure Edit; override;
    procedure EditProperty(const Prop: IProperty; var Continue: Boolean); override;
    procedure ExecuteVerb (Index: Integer); override;
  end;

  { TNxBarEditor6 }

  TNxBarEditor6 = class(TNxCollectionEditor6)
  protected
    function AddBarControl(ControlClass: TNxBarControlClass): TNxBarControl6; virtual;
  public
    constructor Create(AComponent: TComponent; ADesigner: IDesigner); override;
    function GetVerb(Index: Integer): string; override;
    function GetVerbCount: Integer; override;
    procedure Edit; override;
    procedure EditProperty(const Prop: IProperty; var Continue: Boolean); override;
    procedure ExecuteVerb (Index: Integer); override;
  end;

  { TNxButtonImageIndexPropertyEditor6 }

  TNxButtonImageIndexPropertyEditor6 = class(TNxImageIndexPropertyEditor6)
  public
    function GetImageListAt(Index: Integer): TCustomImageList; override;
  end;

procedure Register;

implementation

uses
  Math, StrUtils,
  { Next Standard 6 (Design) }
  NxDesignWindow6;

procedure Register;
begin
  { Reg. Controls }
  RegisterComponents('Next Collection 6', [
      TNextBar6,
      TNxButton6,
      TNxTile6,
      TNxGlyph6,
      TNxPanel6,
      TNxFlipPanel6,
      TNxHeaderPanel6,
      TNxLinkLabel6,
      TNxSplitter6,
      TNxHTMLLabel6,
      TNxHint6,
      TNxPathControl6,
      TNxNotebook6,
      TNxPageControl6,
      TNxImage6,
      TNxTrackBar6,
      TNxButtonSlider6
    ]);

  { Reg. Classes }
  RegisterClasses([TNxNotebookSheet6, TNxPageSheet6,
    TNxBarButton6, TNxBarLabel6, TNxBarProgressBar6, TNxBarTrackBar6,
    TNxBarImageListImage6, TNxBarSeparator6]);
  RegisterNoIcon([TNxNotebookSheet6, TNxPageSheet6, TNxBarControl6,
    TNxBarButton6, TNxBarLabel6, TNxBarProgressBar6, TNxBarTrackBar6,
    TNxBarImageListImage6, TNxBarSeparator6]);

  { Property Editors }
  RegisterPropertyEditor(TypeInfo(WideString), TNxHTMLLabel6, 'Caption', TNxMultilinePropertyEditor6);
  RegisterPropertyEditor(TypeInfo(TColor), TNxTile6, 'Color', TNxColorProperty2);
  RegisterPropertyEditor(TypeInfo(TImageIndex), TNxButton6, 'ImageIndex', TNxButtonImageIndexPropertyEditor6);

  { Reg. Editors }
  RegisterComponentEditor(TNxCollectionControl6, TNxCollectionEditor6);
  RegisterComponentEditor(TNxCustomNotebook6, TNxNotebookEditor6);
  RegisterComponentEditor(TNextBar6, TNxBarEditor6);
  RegisterComponentEditor(TNxFlipPanel6, TNxFlipPanelEditor6);
end;

{ TNxFlipPanelEditor6 }

procedure TNxFlipPanelEditor6.ExecuteVerb(Index: Integer);
begin
  inherited;
  with GetComponent as TNxFlipPanel6 do
    case Index of
      0: Expanded := not Expanded;
      1: if FlipChangeArea = faHeader then FlipChangeArea := faButton else FlipChangeArea := faHeader;
    end;
end;

function TNxFlipPanelEditor6.GetVerb(Index: Integer): string;
begin
  with GetComponent as TNxFlipPanel6 do
    case Index of
      0: Result := IfThen(Expanded, 'Collapse Panel', 'Expand Panel');
      1: Result := IfThen(FlipChangeArea <> faHeader, 'Header Click', 'Button Click') + ' can Toggle' ;
    end;
  Result := inherited GetVerb(Index);
end;

function TNxFlipPanelEditor6.GetVerbCount: Integer;
begin
  Result := inherited GetVerbCount + 2;
end;

{ TNxNotebookEditor6 }

function TNxNotebookEditor6.AddSheet: TNxNotebookSheet6;
var
  Notebook: TNxCustomNotebook6;
begin
  Notebook := TNxCustomNotebook6(GetComponent);

  Result := Notebook.GetTabSheetClass.Create(Notebook.Owner);

//  Result := TNxNotebookSheet6(Designer.CreateComponent(TNxNotebookSheet6, Notebook, 0, 0, 100, 100));

  with Notebook do
  begin
    Add(Result, True);

    Result.Name := Designer.UniqueName(Result.ClassName);
  end;

  { Update }
  Designer.Modified;

end;

constructor TNxNotebookEditor6.Create(AComponent: TComponent;
  ADesigner: IDesigner);
begin
  inherited;

end;

procedure TNxNotebookEditor6.Edit;
begin
  inherited;

end;

procedure TNxNotebookEditor6.EditProperty(const Prop: IProperty;
  var Continue: Boolean);
begin
  inherited;

end;

procedure TNxNotebookEditor6.ExecuteVerb(Index: Integer);
begin
  inherited;

  case Index of
    0: AddSheet;
  end;
end;

function TNxNotebookEditor6.GetVerb(Index: Integer): string;
begin
  with GetComponent as TNxCustomNotebook6 do
    case Index of
      0: Result := '&New Page';
      1: Result := '&Delete Page';
      2: Result := '-';
      3: Result := 'N&ext Page';
      4: Result := '&Previous Page';
      5: Result := '&Select Active Page';
    end;

  { TNextSuiteComponentEditor6 }
  Result := inherited GetVerb(Index);
end;

function TNxNotebookEditor6.GetVerbCount: Integer;
begin
  Result := inherited GetVerbCount + 6;
end;

{ TNxBarComponentEditor6 }

function TNxBarEditor6.AddBarControl(ControlClass: TNxBarControlClass)
  : TNxBarControl6;
var
  Bar: TNextBar6;
begin
  Bar := TNextBar6(GetComponent);

  Result := ControlClass.Create(Bar.Owner);

  with Bar do
  begin
    { Add as child & align }
    Bar.AddControl(Result);

    Result.Name := Designer.UniqueName(Result.ClassName);
  end;

  { Update }
  Designer.Modified;

end;

constructor TNxBarEditor6.Create(AComponent: TComponent;
  ADesigner: IDesigner);
begin
  inherited;

end;

procedure TNxBarEditor6.Edit;
begin
  inherited;

end;

procedure TNxBarEditor6.EditProperty(const Prop: IProperty;
  var Continue: Boolean);
begin
  inherited;
end;

procedure TNxBarEditor6.ExecuteVerb(Index: Integer);
begin
  inherited;
  case Index of
    0: AddBarControl(TNxBarButton6);
    1: AddBarControl(TNxBarLabel6);
    2: AddBarControl(TNxBarTrackBar6);
    3: AddBarControl(TNxBarProgressBar6);
    4: AddBarControl(TNxBarImageListImage6);
    5: AddBarControl(TNxBarSeparator6);
  end;
end;

function TNxBarEditor6.GetVerb(Index: Integer): string;
begin
  with GetComponent as TNextBar6 do
    case Index of
      0: Result := 'New &Button';
      1: Result := 'New &Label';
      2: Result := 'New &Track Bar';
      3: Result := 'New &Progress Bar';
      4: Result := 'New &Image';
      5: Result := 'New &Separator';
    end;

  { TNextSuiteComponentEditor6 }
  Result := inherited GetVerb(Index);
end;

function TNxBarEditor6.GetVerbCount: Integer;
begin
  Result := inherited GetVerbCount + 6;
end;

{ TNxButtonImageIndexPropertyEditor6 }

function TNxButtonImageIndexPropertyEditor6.GetImageListAt(Index: Integer): TCustomImageList;
var
  Ctrl: TPersistent;
begin
  Result := nil;
  Ctrl := GetComponent(Index);
  if Ctrl is TNxButton6 then Result := TNxButton6(Ctrl).Images;
end;

end.
