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

#include "StdHeaders.h"

#include "ListBrowserItem.h"

using namespace VectorWorks::VWUI;

VWListBrowserItem::VWListBrowserItem(TControlID dialogID, TControlID controlID, short columnID, short rowID)
{
	fDialogID	= dialogID;
	fControlID	= controlID;
	fColumnID	= columnID;
	fRowID		= rowID;
}

VWListBrowserItem::VWListBrowserItem (const VWListBrowserItem& item)
{
	fDialogID	= item.fDialogID;
	fControlID	= item.fControlID;
	fColumnID	= item.fColumnID;
	fRowID		= item.fRowID;
}

VWListBrowserItem::~VWListBrowserItem()
{
}

VWListBrowserItem& VWListBrowserItem::operator=(const VWListBrowserItem& item)
{
	fDialogID	= item.fDialogID;
	fControlID	= item.fControlID;
	fColumnID	= item.fColumnID;
	fRowID		= item.fRowID;
	return *this;
}

void VWListBrowserItem::SetItemText(const TXString& text)
{
	VERIFYN( kVStanev, ::GS_SetListBrowserItemInfo( gCBP, fDialogID, fControlID, fRowID, fColumnID, text, -1 ) );
}

void VWListBrowserItem::SetItemImage(size_t imageIndex)
{
	TXString		text;
	VERIFYN( kVStanev, ::GS_SetListBrowserItemInfo( gCBP, fDialogID, fControlID, fRowID, fColumnID, text, DemoteTo<short> ( kVStanev, imageIndex ) ) );
}

void VWListBrowserItem::SetItemInfo(const TXString& text, size_t imageIndex)
{
	VERIFYN( kVStanev, ::GS_SetListBrowserItemInfo( gCBP, fDialogID, fControlID, fRowID, fColumnID, text, DemoteTo<short> ( kVStanev, imageIndex ) ) );
}

TXString VWListBrowserItem::GetItemText() const
{
	TXString	result;

	Str255		text;
	short		imageIndex = -1;
	if ( ::GS_GetListBrowserItemInfo( gCBP, fDialogID, fControlID, fRowID, fColumnID, text, imageIndex ) ) {
		result	= text;
	}

	return result;
}

size_t VWListBrowserItem::GetItemImage() const
{
	size_t		result		= (size_t) -1;

	Str255		text;
	short		imageIndex = -1;
	if ( ::GS_GetListBrowserItemInfo( gCBP, fDialogID, fControlID, fRowID, fColumnID, text, imageIndex ) ) {
		result	= imageIndex;
	}

	return result;
}

bool VWListBrowserItem::GetItemInfo(TXString& outText, size_t& outImage) const
{
	Str255 text;
	short  imageIndex = -1;
	if ( ::GS_GetListBrowserItemInfo( gCBP, fDialogID, fControlID, fRowID, fColumnID, text, imageIndex ) ) {
		outText			= text;
		outImage		= imageIndex;
		return true;
	}
	else {
		outText.Clear();
		outImage		= (size_t) -1;
		return false;
	}
}

bool VWListBrowserItem::SetItemData( const long userData )
{
	return GS_SetListBrowserItemData( gCBP, fDialogID, fControlID, fRowID, fColumnID, userData );
}

bool VWListBrowserItem::GetItemData( long &outUserData )
{
	return GS_GetListBrowserItemData( gCBP, fDialogID, fControlID, fRowID, fColumnID, outUserData );
}

bool VWListBrowserItem::IsItemVisible() const
{
	return ::GS_EnsureListBrowserItemIsVisible( gCBP, fDialogID, fControlID, fRowID ) ? true : false;
}

void VWListBrowserItem::EnableItem(bool enable)
{
	::GS_EnableItem( gCBP, fDialogID, fRowID, enable );
}

void VWListBrowserItem::SetItemTextStyle(EItemTextStyle textStyle)
{
	VERIFYN( kVStanev, ::GS_SetListBrowserItemTextStyle( gCBP, fDialogID, fControlID, fRowID, fColumnID, DemoteTo<unsigned char> ( kVStanev, textStyle ) ) );
}

EItemTextStyle VWListBrowserItem::GetItemTextStyle()
{
	unsigned char textStyle;
	bool ok = ::GS_GetListBrowserItemTextStyle( gCBP, fDialogID, fControlID, fRowID, fColumnID, textStyle);
	return ok ? (EItemTextStyle) textStyle : (EItemTextStyle) -1;
}

void VWListBrowserItem::SetItemTextJustification(EItemTextJustification justification)
{
	VERIFYN( kVStanev, ::GS_SetListBrowserItemTextJust( gCBP, fDialogID, fControlID, fRowID, fColumnID, DemoteTo<int> ( kVStanev, justification ) ) );
}

EItemTextJustification VWListBrowserItem::GetItemTextJustification()
{
	int justification;
	bool ok = ::GS_GetListBrowserItemTextJust( gCBP, fDialogID, fControlID, fRowID, fColumnID, justification);
	return ok ? (EItemTextJustification) justification : (EItemTextJustification) -1;
}

void VWListBrowserItem::SetMultImageIndexes(size_t imageIndex0, size_t imageIndex1, size_t imageIndex2)
{
	VERIFYN( kVStanev, ::GS_SetListBrowserMultImageIndexes( gCBP, fDialogID, fControlID, fRowID, fColumnID, DemoteTo<int> ( kVStanev, imageIndex0 ), DemoteTo<int> ( kVStanev, imageIndex1 ), DemoteTo<int> ( kVStanev, imageIndex2 ) ) );
}

bool VWListBrowserItem::GetMultImageIndexes(size_t& outImageIndex0, size_t& outImageIndex1, size_t& outImageIndex2)
{
	int imageIndex0 = -1;
	int imageIndex1 = -1;
	int imageIndex2 = -1;

	if ( ::GS_GetListBrowserMultImageIndexes( gCBP, fDialogID, fControlID, fRowID, fColumnID, imageIndex0, imageIndex1, imageIndex2 ) ) {
		outImageIndex0		= imageIndex0;
		outImageIndex1		= imageIndex1;
		outImageIndex2		= imageIndex2;
		return true;
	}
	else {
		outImageIndex0		= (size_t) -1;
		outImageIndex1		= (size_t) -1;
		outImageIndex2		= (size_t) -1;
		return false;
	}
}

void VWListBrowserItem::SetOwnerDrawnType(EListBrowserOwnerDrawnType ownerDrawnType)
{
	VERIFYN( kVStanev, ::GS_SetListBrowserColumnOwnerDrawnType( gCBP, fDialogID, fControlID, fRowID, fColumnID, DemoteTo<int> ( kVStanev, ownerDrawnType ) ) );
}

EListBrowserOwnerDrawnType VWListBrowserItem::GetOwnerDrawnType()
{
	int ownerDrawnType;
	bool ok = ::GS_GetListBrowserColumnOwnerDrawnType( gCBP, fDialogID, fControlID, fRowID, fColumnID, ownerDrawnType );
	return ok ? (EListBrowserOwnerDrawnType) ownerDrawnType : kListBrowserNotOwnerDrawn;
}

void VWListBrowserItem::SetItemUsingColumnDataItem(size_t columnDataItemIndex)
{
	VERIFYN( kVStanev, ::GS_SetListBrowserItemUsingColumnDataItem( gCBP, fDialogID, fControlID, fRowID, fColumnID, DemoteTo<short> ( kVStanev, columnDataItemIndex ) ) );
}

bool VWListBrowserItem::GetColumnDataItemInfo()
{
	PStr255	text	= "";
	short imageOn	= -1;
	short imageOff	= -1;
	long  itemData	= -1;

	return ::GS_GetListBrowserColumnDataItemInfo( gCBP, fDialogID, fControlID, fColumnID, fRowID, text, imageOn, imageOff, itemData ) ? true : false;
}

// ----------------------------------------------------------------------------------------------------
// attributes
void VWListBrowserItem::SetItemTextColor(size_t redIndex, size_t greenIndex, size_t blueIndex)
{
	VERIFYN( kVStanev, ::GS_SetListBrowserItemTextColor( gCBP, fDialogID, fControlID, fRowID, fColumnID, DemoteTo<int> ( kVStanev, redIndex ), DemoteTo<int> ( kVStanev, greenIndex ), DemoteTo<int> ( kVStanev, blueIndex ) ) );
}

bool VWListBrowserItem::GetItemTextColor()
{
	int redIndex	= -1;
	int greenIndex	= -1;
	int blueIndex	= -1;

	return ::GS_GetListBrowserItemTextColor( gCBP, fDialogID, fControlID, fRowID, fColumnID, redIndex, greenIndex, blueIndex);
}

void VWListBrowserItem::SetItemDashStyle(size_t styleIndex, size_t lineWeight)
{
	VERIFYN( kVStanev, ::GS_SetListBrowserItemDashStyle( gCBP, fDialogID, fControlID, fRowID, fColumnID, DemoteTo<int> ( kVStanev, styleIndex ), DemoteTo<int> ( kVStanev, lineWeight ) ) );
}

bool VWListBrowserItem::GetItemDashStyle()
{
	int styleIndex = -1;
	int lineWeight = -1;

	return ::GS_GetListBrowserItemDashStyle( gCBP, fDialogID, fControlID, fRowID, fColumnID, styleIndex, lineWeight ) ? true : false;
}

void VWListBrowserItem::SetItemFillForeColor(size_t redIndex, size_t greenIndex, size_t blueIndex)
{
	VERIFYN( kVStanev, ::GS_SetListBrowserItemFillForeColor( gCBP, fDialogID, fControlID, fRowID, fColumnID, DemoteTo<int> ( kVStanev, redIndex ), DemoteTo<int> ( kVStanev, greenIndex ), DemoteTo<int> ( kVStanev, blueIndex ) ) );
}

void VWListBrowserItem::SetItemNoFillForeColor()
{
	VERIFYN( kVStanev, ::GS_SetListBrowserItemFillForeColor( gCBP, fDialogID, fControlID, fRowID, fColumnID, -1, -1, -1 ) );
}

bool VWListBrowserItem::GetItemFillForeColor( size_t &outRedIndex, size_t &outGreenIndex, size_t &outBlueIndex )
{
	int		redIndex	= -1;
	int		greenIndex	= -1;
	int		blueIndex	= -1;
	bool	success = ::GS_GetListBrowserItemFillForeColor( gCBP, fDialogID, fControlID, fRowID, fColumnID, redIndex, greenIndex, blueIndex );
	
	outRedIndex = redIndex;
	outGreenIndex = greenIndex;
	outBlueIndex = blueIndex;
	
	return  success;
}

void VWListBrowserItem::SetItemFillBackColor(size_t redIndex, size_t greenIndex, size_t blueIndex)
{
	VERIFYN( kVStanev, ::GS_SetListBrowserItemFillBackColor( gCBP, fDialogID, fControlID, fRowID, fColumnID, DemoteTo<int> ( kVStanev, redIndex ), DemoteTo<int> ( kVStanev, greenIndex ), DemoteTo<int> ( kVStanev, blueIndex ) ) );
}

bool VWListBrowserItem::GetItemFillBackColor()
{
	int redIndex	= -1;
	int greenIndex	= -1;
	int blueIndex	= -1;

	return ::GS_GetListBrowserItemFillBackColor( gCBP, fDialogID, fControlID, fRowID, fColumnID, redIndex, greenIndex, blueIndex);
}

void VWListBrowserItem::SetItemGradientOrImageRefNumber(size_t refNumber)
{
	VERIFYN( kVStanev, ::GS_SetListBrowserItemGradientOrImageRefNumber( gCBP, fDialogID, fControlID, fRowID, fColumnID,  DemoteTo<long> ( kVStanev, refNumber ) ) );
}

size_t VWListBrowserItem::GetItemGradientOrImageRefNumber()
{
	long refNumber;
	bool ok = GS_GetListBrowserItemGradientOrImageRefNumber( gCBP, fDialogID, fControlID, fRowID, fColumnID, refNumber );
	return ok ? (size_t) refNumber : (size_t) -1;;
}

void VWListBrowserItem::SetItemPenForeColor(size_t redIndex, size_t greenIndex, size_t blueIndex)
{
	VERIFYN( kVStanev, ::GS_SetListBrowserItemPenForeColor( gCBP, fDialogID, fControlID, fRowID, fColumnID, DemoteTo<int> ( kVStanev, redIndex ), DemoteTo<int> ( kVStanev, greenIndex ), DemoteTo<int> ( kVStanev, blueIndex ) ) );
}

bool VWListBrowserItem::GetItemPenForeColor()
{
	int redIndex	= -1;
	int greenIndex	= -1;
	int blueIndex	= -1;

	return ::GS_GetListBrowserItemPenForeColor( gCBP, fDialogID, fControlID, fRowID, fColumnID, redIndex, greenIndex, blueIndex);
}

void VWListBrowserItem::SetItemPenBackColor(size_t redIndex, size_t greenIndex, size_t blueIndex)
{
	VERIFYN( kVStanev, ::GS_SetListBrowserItemPenBackColor( gCBP, fDialogID, fControlID, fRowID, fColumnID, DemoteTo<int> ( kVStanev, redIndex ), DemoteTo<int> ( kVStanev, greenIndex ), DemoteTo<int> ( kVStanev, blueIndex ) ) );
}

bool VWListBrowserItem::GetItemPenBackColor()
{
	int redIndex	= -1;
	int greenIndex	= -1;
	int blueIndex	= -1;

	return ::GS_GetListBrowserItemPenBackColor( gCBP, fDialogID, fControlID, fRowID, fColumnID, redIndex, greenIndex, blueIndex);
}







		