//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "NxInspector"
#pragma link "NxScrollControl"
#pragma link "NxStdCtrls"
#pragma link "NxPropertyItemClasses"
#pragma link "NxPropertyItems"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
        //
        // 1. Create top-level item
        //

        // Create new item
        TNxTextItem *ATopItem = new TNxTextItem(this);

        // Set properties for item
        ATopItem->Caption = "Root Item";
        ATopItem->ReadOnly = true;

        // Add Item into Items array as Top-level item (first parameter NULL)
        NextInspector1->Items->AddItem(NULL, ATopItem);

        //
        // 2. Create items inside first item
        //

        // Create new item
        TNxSpinItem *AItem = new TNxSpinItem(this);

        // Set properties for item
        AItem->Caption = "Spin Item";

        // Add Item into Items array, to be a child of ATopItem
        NextInspector1->Items->AddItem(ATopItem, AItem);

        // Set some property additionally
        AItem->Value = "10.2";

        // Add one another item with different method
        // __classid(TNxDateItem) indicate item type, may be:
        //      __classid(TNxTextItem),
        //      __classid(TNxSpinItem),
        //      __classid(TNxProgressItem)...
        NextInspector1->Items->AddChild(ATopItem, __classid(TNxDateItem), "Date Item");

        //
        // 3. Add new item with using typecasting
        //
        TNxToolbarItem *AToolbarItem = (TNxToolbarItem*)NextInspector1->Items->AddChild(ATopItem, __classid(TNxToolbarItem), "Button Item");
        AToolbarItem->AllowAllUp = true;
        AToolbarItem->Buttons->Add();
        AToolbarItem->Buttons->Add(); // <-- Made this button as divider
        AToolbarItem->Buttons->Add();

        TNxToolbarItemButton *AButton = (TNxToolbarItemButton*)AToolbarItem->Buttons->Items[1];
        AButton->Divider = true;

        TNxCheckBoxItem *ACeckBoxItem = (TNxCheckBoxItem*)NextInspector1->Items->AddChild(ATopItem, __classid(TNxCheckBoxItem), "Checkbox Item");

        // Add few items into newly added item
        NextInspector1->Items->AddChild(ACeckBoxItem, __classid(TNxTextItem), "Sub-item 1");
        NextInspector1->Items->AddChild(ACeckBoxItem, __classid(TNxTextItem), "Sub-item 2");

        // Add child at first position, and we have set one property
        NextInspector1->Items->AddChildFirst(ACeckBoxItem, __classid(TNxTextItem), "Sub-item 0")->Color = clMoneyGreen;

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
        NextInspector1->Items->Clear();        
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button2Click(TObject *Sender)
{
        if(NextInspector1->SelectedItem != NULL)
        {
                NextInspector1->SelectedItem->Delete();
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::NextInspector1SelectItem(TObject *Sender,
      TNxPropertyItem *Item)
{
        if(NextInspector1->SelectedItem != NULL)
        {
                edtValue->Text = NextInspector1->SelectedItem->Value;
                Caption = "AbsoluteIndex: " + IntToStr(NextInspector1->SelectedItem->AbsoluteIndex) +
                        ", Index: " + IntToStr(NextInspector1->SelectedItem->Index);
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button4Click(TObject *Sender)
{
        if(NextInspector1->SelectedItem != NULL)
        {
                ShowMessage(NextInspector1->SelectedItem->Count);
        }
}
//---------------------------------------------------------------------------

