//
//	Copyright © 2006 Nemetschek North America 
//	All Rights Reserved.
//
// Created by Vladislav Stanev

#include "StdHeaders.h"

#include "TreeCtrlItem.h"

#include "Dialog.h"

using namespace VectorWorks::VWUI;

VWTreeCtrlItem::VWTreeCtrlItem()
{
	fDialogID		= -1;
	fControlID		= -1;
	fThisItemID		= -1;
}

VWTreeCtrlItem::VWTreeCtrlItem(TControlID dialogID, TControlID controlID, int itemID)
{
	fDialogID		= dialogID;
	fControlID		= controlID;
	fThisItemID		= itemID;
}

VWTreeCtrlItem::VWTreeCtrlItem(const VWTreeCtrlItem& src)
{
	fDialogID		= src.fDialogID;
	fControlID		= src.fControlID;
	fThisItemID		= src.fThisItemID;
}

VWTreeCtrlItem::~VWTreeCtrlItem()
{
}

VWTreeCtrlItem&	VWTreeCtrlItem::operator=(const VWTreeCtrlItem& src)
{
	fDialogID		= src.fDialogID;
	fControlID		= src.fControlID;
	fThisItemID		= src.fThisItemID;

	return *this;
}

VWTreeCtrlItem VWTreeCtrlItem::AddChildItem(const TXString& text)
{
	if ( ! this->IsValid() )
		return *this;

	int newItemID	= ::GS_InsertTreeControlItem( gCBP, fDialogID, fControlID, text, fThisItemID, -1 );
	return VWTreeCtrlItem( fDialogID, fControlID, newItemID );
}

VWTreeCtrlItem VWTreeCtrlItem::InsertChildItem(const TXString& text, VWTreeCtrlItem	afterItem)
{
	if ( ! this->IsValid() )
		return *this;

	int newItemID	= ::GS_InsertTreeControlItem( gCBP, fDialogID, fControlID, text, fThisItemID, afterItem.fThisItemID );
	return VWTreeCtrlItem( fDialogID, fControlID, newItemID );
}

void VWTreeCtrlItem::DeleteItem()
{
	VERIFYN( kVStanev, this->IsValid() && ::GS_RemoveTreeControlItem( gCBP, fDialogID, fControlID, fThisItemID ) );
}

bool VWTreeCtrlItem::IsValid() const
{
	return (fDialogID != -1 && fControlID != -1);
}

void VWTreeCtrlItem::ExpandItem(bool bExpand)
{
	VERIFYN( kVStanev, this->IsValid() && ::GS_ExpandTreeControlItem( gCBP, fDialogID, fControlID, fThisItemID, bExpand ) );
}

void VWTreeCtrlItem::SelectItem()
{
	VERIFYN( kVStanev, this->IsValid() && ::GS_SelectTreeControlItem( gCBP, fDialogID, fControlID, fThisItemID ) );
}

void VWTreeCtrlItem::SetItemData(long data)
{
	VERIFYN( kVStanev, this->IsValid() && ::GS_SetTreeControlItemData( gCBP, fDialogID, fControlID, fThisItemID, data ) );
}

long VWTreeCtrlItem::GetItemData() const
{
	long	data	= 0;
	VERIFYN( kVStanev, this->IsValid() && ::GS_GetTreeControlItemData( gCBP, fDialogID, fControlID, fThisItemID, data ) );
	return data;
}
