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

#pragma once

#include "Control.h"

namespace VectorWorks
{
	namespace VWUI
	{
		// -----------------------------------------------------------------------------
		enum EStandardImageID {
			kStandardImageID_None,
			kStandardImageID_Blank,
			kStandardImageID_DiamondBlack,
			kStandardImageID_DiamondHollow,
			kStandardImageID_DiamondGray,
			kStandardImageID_RedCrossedCircle,
			kStandardImageID_CheckMark,
			kStandardImageID_CheckMarkWhite,
			kStandardImageID_LeftBlackArrow,
			kStandardImageID_RightBlackArrow,
			kStandardImageID_LeftHollowArrow,
			kStandardImageID_RightHollowArraw,
			kStandardImageID_LeftThinArrow,
			kStandardImageID_RightThinkArrow,
			kStandardImageID_BallBlack,
			kStandardImageID_BallHollow,
			kStandardImageID_Slash,
			kStandardImageID_XMark,
		};

		// -----------------------------------------------------------------------------
		class VWListBrowserColumn;
		class VWListBrowserItem;

		// -----------------------------------------------------------------------------
		class VWDialog;
		class VWListBrowserCtrl : public VWControl
		{
		public:
									VWListBrowserCtrl(TControlID id);
			virtual					~VWListBrowserCtrl();

			virtual bool			CreateControl(VWDialog* pDlg, short widthInCharacters, short heightInLines);

		public:
			void					EnableControl(bool enable);
			void					EnableClickAllDataChange(bool enable);
			void					EnableDragAndDrop(bool enable);

			void					EnableSorting(bool enable);
			bool					IsSortingEnabled() const;

			void					EnableSingleLineSelection(bool enable);
			void					EnableUpdates(bool enable);
			void					EnableDropOnIndices(size_t startIndex, size_t endIndex, bool enable);

			void					SetFocusOnControl();

			void					RefreshControl();

			void					SetColumnWidth(size_t fromColumn, size_t toColumn, size_t width);
			void					GetColumnWidth(size_t column, short &width);

			size_t					GetSelectedItemsCount();

		// image list managment
		public:
			size_t					AddImage(size_t resourceID, size_t resourceIDSelected = 0);
			size_t					AddImageStandard(EStandardImageID image, EStandardImageID selImage = kStandardImageID_None);

		// columns
		public:
			VWListBrowserColumn		AddColumn(const TXString& text, size_t width);
			VWListBrowserColumn		InsertColumn(size_t columnIndex, const TXString& text, size_t width);
			void					DeleteColumn(size_t columnIndex);

			size_t					GetColumnsCount() const;
			VWListBrowserColumn		GetColumn(size_t columnIndex);

			void					EnableColumnLines(bool enable);
			bool					AreColumnLinesEnabled() const;

		// rows
		public:
			size_t					AddRow(const TXString& text, long marker = 0);
			size_t					InsertRow(size_t rowIndex, const TXString& text, long marker = 0);
			void					DeleteRow(size_t rowIndex);
			void					DeleteAllRows();

			size_t					GetRowsCount() const;

			bool					IsRowSelected(size_t rowIndex) const;
			void					SelectRow(size_t rowIndex, bool select) const;
			void					SelectRow(size_t firstRowIndex, size_t lastRowIndex, bool select) const;
			void					DeselectAll() const;

			long					GetRowMarker(size_t itemIndex) const;
			void					SetRowMarker(size_t itemIndex, long marker);
			size_t					GetRowWithMarker(long marker);

			// returns (size_t)-1 if nothing is selected
			size_t					GetFirstSelected() const;
			bool					GetNextSelected(size_t& row) const;

			// changes 'row' to next the selected row, starting from 'row' value
			// if 'row' is selected, nothing changes
			bool					GetNextRowSelected(size_t& row) const;

		// items
		public:
			VWListBrowserItem		GetItem(size_t rowIndex, size_t columnIndex);

		private:
			typedef std::vector<long>		TMarkersArray;

			TMarkersArray		farrIndexToMarker;
		};
	}
}