/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                          CWindow.h  -  description
                             -------------------
    begin                : Sun May 22 2003
    copyright            : (C) 2000-2005 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>

/// @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 {
   /// Window caption storage
   std::string m_label;

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

public:

   /// 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() { ctor_init(label); }

   /// 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() { ctor_init(label); } 

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

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

   /// 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);

   /// 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);

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

   /// Sets the new window caption
   /// @param lbl CString, new window caption
   void label(std::string lbl) { m_label = lbl; Fl_Double_Window::label(m_label.c_str()); }
};

/// @}

#endif
