/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                          CExcelPalette.h  -  description
                             -------------------
    begin                : Wed May 12 2004
    copyright            : (C) 2000-2006 by Alexey S.Parshin
    email                : alexeyp@gmail.com
 ***************************************************************************/

/***************************************************************************
   This library is free software; you can redistribute it and/or modify it 
   under the terms of the GNU Library General Public License as published by
   the Free Software Foundation; either version 2 of the License, or (at 
   your option) any later version.

   This library is distributed in the hope that it will be useful, but 
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
   General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; if not, write to the Free Software Foundation, 
   Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

   Please report all bugs and problems to "alexeyp@gmail.com"
 ***************************************************************************/

#ifndef __CEXCELPALETTE_H__
#define __CEXCELPALETTE_H__

#include <sptk3/excel/CExcelRecord.h>
#include <sptk3/excel/CExcelRecordsBuffer.h>

#include <map>

namespace sptk {

#define EPC_BLACK   0
#define EPC_WHITE   1
#define EPC_RED     2
#define EPC_GREEN   3
#define EPC_BLUE    4
#define EPC_YELLOW  5
#define EPC_MAGENTA 6
#define EPC_CYAN    7

#define EPC_SYSBORDER       0x40
#define EPC_SYSBACKGROUND   0x41
#define EPC_SYSTEXT         0x7FFF

   /// @addtogroup excel Excel Classes
   /// @{

   /// @brief Excel palette record.
   ///
   /// Represents the colours available for this Excel file. 
   /// First eight colours are standard and should not be redefined.
	class CExcelPalette : public CExcelRecord {
      /// The standard colors palette
		static const unsigned  standardPalette[8];

	protected:
		std::map<unsigned,unsigned>	m_colorMap;        ///< The map of defined colors
		unsigned           				m_colors[64];      ///< The list of defined colors

	public:

      /// Default constructor
		CExcelPalette() : CExcelRecord(PALETTE,258,new char[258],true) { clear(); }

      /// Initializes the default colours int the palette
		void clear();

      /// Returns the palette index for the RGB color. 
      /// If the color isn't part of the palette yet it's added to palette.
      /// The maximum number of colors in the palette is 56
      /// @param rgbColor unsigned, the RGB color value
      /// @returns the index of color in the palette
		unsigned colorIndex(unsigned rgbColor);

      /// Returns the palette RGB color for the index.
      /// Index may be in 8..63
		unsigned colorForIndex(unsigned colorIndex) const;

      /// Saves PALETTE record into the external Excel format.
      /// @param records CExcelRecordsBuffer&, the output buffer of Excel records
		void saveRecords(CExcelRecordsBuffer& records);
	};
   /// @}
}
#endif
