/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                          CColumn.h  -  description
                             -------------------
    begin                : Thu Apr 27 2000
    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 __CCOLUMNS_H__
#define __CCOLUMNS_H__

#include <string>
#include <sptk3/CStrings.h>
#include <sptk3/CVariant.h>
#include <sptk3/cxml>

namespace sptk {

   /// @addtogroup gui GUI Classes
   /// @{

   /// @brief Class CColumn represents a column descriptor for CListView
	class SP_EXPORT CColumn {
	protected:
		std::string  m_name;			///< Column name
		unsigned     m_width;		///< Column width in pixels
		CVariantType m_type;			///< Column data type
		bool         m_visible;		///< Column visibility
		bool         m_autoWidth;	///< Column auto width flag
	public:

      /// @brief Constructor
      /// @param cname std::string, column name
      /// @param type CVariantType, column data type
      /// @param cwidth short, column width
      /// @param cvisible bool, column visibility
		CColumn(std::string cname="",CVariantType type=VAR_STRING,short cwidth=100,bool cvisible=true);

      /// @brief Copy constructor
      /// @param col const CColumn&, source column object
		CColumn(const CColumn& col);

      /// @brief Returns column name
		std::string name()        const { return m_name; }

      /// @brief Returns column width in pixels
		short   width()           const { return m_width; }

      /// @brief Sets column width in pixels
		void    width(short w)          { m_width = w; }

      /// @brief Returns column visibility
		bool    visible()         const { return m_visible; }

      /// @brief Sets column visibility
		void    visible(bool v)         { m_visible = v; }

      /// @brief Returns Column auto width flag
		bool    autoWidth()       const { return m_autoWidth; }

      /// @brief Sets column auto width flag
		void    autoWidth(bool v)       { m_autoWidth = v; }

      /// @brief Returns column data type
		CVariantType type()       const { return m_type; }

      /// @brief Loads column information
      ///
      /// Loads information about column
      /// from the registry.
      /// @param node const CXmlNode&, an XML node to load column information from
		void load(const CXmlNode& node);

      /// @brief Loads column information
      ///
      /// Loads information about column
      /// from the registry.
      /// @param node const CXmlNode*, an XML node to load column information from
		void load(const CXmlNode* node) { load(*node); }

      /// @brief Saves column information
      ///
      /// Saves information about column
      /// from the registry.
      /// @param node CXmlNode&, an XML node to unload column information to
		void save(CXmlNode& node) const;

      /// @brief Saves column information
      ///
      /// Saves information about column
      /// from the registry.
      /// @param node CXmlNode*, an XML node to unload column information to
		void save(CXmlNode* node) const { save(*node); }
	};

   /// Class CColumnList is a list of columns used in CListView
	class SP_EXPORT CColumnList : public std::vector<CColumn> {
	public:

      /// @brief Default constructor
		CColumnList() {}

      /// @brief Finds the column index by column name 
      /// @param columnName const char *, column name
		int  indexOf(const char *columnName) const;

      /// @brief Loads columns information
      ///
      /// Loads information about columns 
      /// from the registry.
      /// @param node const CXmlNode&, an XML node to load columns information from
		void load(const CXmlNode& node);

      /// @brief Loads columns information
      ///
      /// Loads information about columns 
      /// from the registry.
      /// @param node const CXmlNode*, an XML node to load columns information from
		void load(const CXmlNode* node) { load(*node); }

      /// @brief Saves columns information
      ///
      /// Saves information about columns
      /// from the registry.
      /// @param node CXmlNode&, an XML node to unload columns information to
		void save(CXmlNode& node) const;

      /// @brief Saves columns information
      ///
      /// Saves information about columns
      /// from the registry.
      /// @param node CXmlNode*, an XML node to unload columns information to
		void save(CXmlNode* node) const { save(*node); }
	};
   /// @}
}
#endif
