/****************************************************************************************************

		IMFHierarchicalListPart.h
		Copyright: (c) 2007 Daz Productions Inc. All rights reserved.

		Author:	Mathieu
		Date:	6/29/2007

****************************************************************************************************/



#ifndef __IMFHierarchicalListPart__
#define __IMFHierarchicalListPart__

#if CP_PRAGMA_ONCE
#pragma once
#endif


struct IMFHierarchyItem;
class THierarchicalListDropArea;
class TMFDropCandidate;
class THierarchicalListItem;
class TMFHierarchicalListPart;
class TMFDropArea;


typedef const TMCClassArray<TMCString255>			ItemStrings;
typedef TMCArray<uint32>							ListSelection;


//Interface for elements that are displayed by a TMFHierarchicalListPart
struct IMFHierarchyItem : public IMCUnknown
{
	//returns true if the item has children (might not be loaded yet)
	virtual boolean	HasChildren		() const = 0;

	//Notifies the item that is was selected
	virtual void	Selected		() = 0;

	//Notifies the item that is was unselected
	virtual void	Unselected		() = 0;

	//notifies the item that it has been opened (so it can load its content for example)
	virtual void	OpenItem		(	THierarchicalListItem*	item, 
										TMFHierarchicalListPart* inListPart) = 0;

	virtual void	CloseItem		() = 0;

	//Used to temporarily store some info (eg the open/close status) on the item
	virtual void	SetWasOpen			(boolean inWasOpen) = 0;

	virtual boolean	GetWasOpen			() = 0;
};


//****** Globally Unique Ids *************************************************
MCDEFINE_GUID_H(IID_IMFHierarchicalListPart);


/// \addtogroup MCF

/// This is the interface to access a hierarchical part. The corresponding type in MCSketch is:
/// TMFHierarchicalListPart
///

class IMFHierarchicalListPart: public IMCUnknown
{
public:

	virtual void   MCCOMAPI			RecalcPartSize(void) = 0;
	virtual uint32 MCCOMAPI			GetNextSelectedItem(uint32 inCurrentItem = kUnusedIndex) = 0;
	virtual const ListSelection&    MCCOMAPI GetSelection(void) const = 0;
	virtual void   MCCOMAPI			ClearSelection(void) = 0;
	virtual void   MCCOMAPI			SelectItemByIndex	(uint32 inIndex) = 0;
	virtual void   MCCOMAPI			SelectItemByKey		(IMFHierarchyItem* inItem) = 0;
	virtual void   MCCOMAPI			ToggleItemSelection	(uint32 inIndex) = 0;

	virtual void   MCCOMAPI			SaveOpenCloseStatus	() = 0;
	virtual IMFHierarchyItem*	    MCCOMAPI GetItem(uint32 inIndex) = 0;

	virtual uint32 MCCOMAPI			InsertItemAfter(IMFHierarchyItem*	inItem,
											ItemStrings&		inDisplayStrings,
											boolean				canHaveChildren,
											boolean				asChild = false,
											uint32				afterIndex = kUnusedIndex) = 0;

	virtual uint32 MCCOMAPI		    AddItemToEnd(	IMFHierarchyItem*	inItem,
											ItemStrings&		inDisplayStrings,
											boolean				canHaveChildren,
											boolean				asChild = false) = 0;

	virtual uint32 MCCOMAPI			AddItem(IMFHierarchyItem*	inItem,
											ItemStrings&		inDisplayStrings,
											boolean				canHaveChildren,
											uint32				inParent) = 0;	// uses kUnusedIndex for top group

	virtual uint32 MCCOMAPI			GetItemsCount() const = 0;

	virtual void   MCCOMAPI			RemoveItem(uint32 inItemIndex) = 0;
	virtual void   MCCOMAPI			InvalItem(uint32 inItemIndex) = 0;

	virtual void   MCCOMAPI			GetOpenIndicies(TMCArray<uint32>& outOpenIndicies) = 0;
	virtual void   MCCOMAPI		 	SetOpenStatusIndicies(const TMCArray<uint32>& inOpenIndicies, bool itemOpen) = 0;

	virtual void   MCCOMAPI			DroppedItemsInArea(const ListSelection& inItems,
												THierarchicalListDropArea& inDropArea) = 0;
	virtual void   MCCOMAPI			CopyItemsFromList(	TMFDropCandidate& inFrom,
												THierarchicalListDropArea& inDropArea) = 0;

	virtual inline IDType  MCCOMAPI			        GetDragFlavor(void) const = 0;
	virtual inline boolean MCCOMAPI			        GetDrawColumnLines(void) const = 0;
	virtual inline const TMCArray<uint32>& MCCOMAPI	GetColumnStarts(void) const = 0;

	virtual void   MCCOMAPI			SetDragFlavor(IDType inFlavor) = 0;
	virtual void   MCCOMAPI			SetDrawColumnLines(boolean inDrawLines) = 0;
	virtual void   MCCOMAPI			SetColumnStarts(const TMCArray<uint32>& inWidths) = 0;

	virtual boolean	MCCOMAPI		GetDrawRoot() = 0;
	virtual void    MCCOMAPI		SetDrawRoot(boolean drawRoot) = 0;

	virtual boolean	MCCOMAPI		GetAllowMultipleSelection() = 0;
	virtual void	MCCOMAPI		SetAllowMultipleSelection(boolean allow) = 0;
	virtual void    MCCOMAPI		GetDisplayData(TMCClassArray<TMCString255>& data, int32 inIndex) = 0;
};


///Simple wrapper around some data (can be a pointer)
template <class T> class TSimpleHierarchyItem : public IMFHierarchyItem, public TMCCountedObject
{
public:
	static const MCGUID sClassId;
	static void Create(const T& inData, TSimpleHierarchyItem** outItem)
	{
		TMCCountedCreateHelper<TSimpleHierarchyItem> result(outItem);
		result= new TSimpleHierarchyItem(inData);
	}

	inline T&		GetData		()						{ return fData; }
	inline void		SetData		(const T& inData)		{ fData= inData; }

	//IMCUnknown
	virtual uint32	MCCOMAPI AddRef			()							{ return TMCCountedObject::AddRef(); }
	virtual uint32	MCCOMAPI Release		()							{ return TMCCountedObject::Release(); }
	virtual MCErr	MCCOMAPI QueryInterface	(const MCIID& riid, void** ppvObj)
	{
		if(MCIsEqualGUID(riid, sClassId))
		{
			TMCCountedGetHelper<TSimpleHierarchyItem> result(ppvObj);
			result = this;
			return MC_S_OK;
		}
		else		
			return TMCCountedObject::QueryInterface(riid, ppvObj);
	}

	//IMFHierarchyItem
	virtual boolean	HasChildren		() const				{ return false; }
	virtual void	Selected		()						{}
	virtual void	Unselected		()						{}
	virtual void	CloseItem		() {}
	virtual void	OpenItem		(	THierarchicalListItem*	item, 
										TMFHierarchicalListPart* inListPart) {}
	virtual void	SetWasOpen		(	boolean inWasOpen)	{ }
	virtual boolean	GetWasOpen		()						{ return true; }
	
protected:
	TSimpleHierarchyItem	(const T& inData)				{ fData= inData; }
	~TSimpleHierarchyItem	()	{}
protected:
	T	fData;
};





#endif
