/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                          CWindow.h  -  description
                             -------------------
    begin                : Sun May 22 2003
    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 __CWINDOW_H__
#define __CWINDOW_H__

#include <FL/Fl_Double_Window.H>
#include <sptk3/CLayoutManager.h>
#include <sptk3/CStrings.h>
#include <sptk3/CGroupXml.h>

namespace sptk {

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

   /// @brief Window widget
   ///
   /// Extended version of FLTK's standard Fl_Double_Window, with added
   /// CLayoutManager capabilities
	class CWindow : public Fl_Double_Window, public CLayoutManager, public CGroupXml {

      /// @brief Constructor initializer
		void ctor_init(const char *label);

	public:

      /// @brief Constructor
      /// @param w int, window width
      /// @param h int, window height
      /// @param label int, window label
		CWindow(int w,int h,const char * label=0L)
		: Fl_Double_Window(w,h), CLayoutManager(), CGroupXml(this) { ctor_init(label); }

      /// @brief Constructor
      /// @param x int, window x-position
      /// @param y int, window y-position
      /// @param w int, window width
      /// @param h int, window height
      /// @param label int, window label
		CWindow(int x,int y,int w,int h,const char *label=0L)
		: Fl_Double_Window(x,y,w,h), CLayoutManager(), CGroupXml(this) { ctor_init(label); } 

      /// @brief Draws a window, including an optional background image
		virtual void draw();    

      /// @brief Relayouts window's widgets that have CLayoutClient interface
		virtual void relayout() { resize(x(),y(),w(),h()); }

      /// @brief Resizes the window and inside widgets. 
      /// @param x int, x-position
      /// @param y int, y-position
      /// @param w int, width
      /// @param h int, height
		virtual void resize(int x,int y,int w,int h);

      /// @brief Computes the optimal window size
      /// @param w int&, input - width offered by the program, output - width required by the window
      /// @param h int&, input - height offered by the program, output - height required by the window
		virtual void preferredSize(int& w,int& h);

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

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

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

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

	   /// @brief Loads the window position from XML node
      ///
      /// @param node const CXmlNode&, node to load position from
		void loadPosition(const CXmlNode& node);

	   /// @brief Saves the window position into XML node
      ///
      /// @param node CXmlNode&, node to save position into
		void savePosition(CXmlNode& node) const;

      /// @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) { CGroupXml::label(lbl); }

      /// Sets label for the group, makes an internal copy of the string
      /// @param lbl const string&, new label
		void label(const std::string& lbl) { CGroupXml::label(lbl); }
	};	
   /// @}
}
#endif
