/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                          CGroupXml.h  -  description
                             -------------------
    begin                : Wed June 28 2006
    copyright            : (C) 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 __CGROUPXML_H__
#define __CGROUPXML_H__

#include <FL/Fl_Group.H>
#include <string>

namespace sptk {

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

	class CXmlNode;

   /// @brief Loads/saves the SPTK group/window from/to XML node.
   ///
   /// Designed to be used as a base class for CGroup and CWindow
	class CGroupXml {
		::Fl_Group*    m_widget; ///< Controlled group widget
		bool          m_noXml;  ///< If true - do not read or produce any XML

	protected:
		std::string   m_label;  ///< Window caption storage

	public:
	   /// @brief Constructor
      ///
	   /// @param widget Fl_Group*, a widget to control
		CGroupXml(::Fl_Group* widget) : m_widget(widget) {
			m_noXml = false;
			if (widget && widget->label()) {
				m_label = m_widget->label();
				m_widget->label(m_label.c_str());
			}
		}

	   /// @brief Destructor
		virtual ~CGroupXml() {}

	   /// @brief Loads group controls data from XML node
	   ///
	   /// @param node const CXmlNode&, node to load data from
		virtual void load(const CXmlNode& node);

	   /// @brief Loads group controls data from XML node
	   ///
	   /// @param node const CXmlNode*, node to load data from
		virtual void load(const CXmlNode* node) { load(*node); }

	   /// @brief Saves group controls data into XML node
	   ///
	   /// @param node const CXmlNode&, node to save data into
		virtual void save(CXmlNode& node) const;

	   /// @brief Saves group controls data into XML node
	   ///
	   /// @param node const CXmlNode*, node to save data into
		virtual void save(CXmlNode* node) const { save(*node); }

      /// @brief Returns the current label
		std::string label() const { return m_label; }

      /// @brief Sets the new label
      ///
      /// @param lbl const char*, new label
		void label(const char* lbl) { m_label = lbl; m_widget->label(m_label.c_str()); }

      /// @brief Sets label for the group, makes an internal copy of the string
      /// @param l const string&, new label
		void label(const std::string& l) { m_label = l; m_widget->label(m_label.c_str()); }

      /// @brief Returns flag of blocking XML processing
      ///
      /// If this flag is set then no XML is loaded or saved
		bool noXml() const { return m_noXml; }


      /// @brief Sets flag of blocking XML processing
      ///
      /// If this flag is set then no XML is loaded or saved
		void noXml(bool noXml) { m_noXml = noXml; }
	};
	/// @}
}
#endif
