/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                          CScroll.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 __CSCROLL_H__
#define __CSCROLL_H__

#include <FL/Fl_Group.h>

#include <sptk3/CScrollBar.h>
#include <sptk3/CLayoutClient.h>
#include <sptk3/CLayoutManager.h>

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

/// Different modes for scrollbars
enum CScrollbarMode { // values for type()
   HORIZONTAL = 1,
   VERTICAL = 2,
   BOTH = 3,
   ALWAYS_ON = 4,
   HORIZONTAL_ALWAYS = 5,
   VERTICAL_ALWAYS = 6,
   BOTH_ALWAYS = 7
};

/// @brief Scroll area widget
///
/// Extended version of FLTK Fl_Group that can be a layout manager and layout client
/// at the same time.
class CScroll : public Fl_Group, public CLayoutClient, public CLayoutManager {

   int m_xposition;        ///< Current x-position of the scrolled area
   int m_yposition;        ///< Current y-position of the scrolled area
   int m_width;            ///< Current width of the scrolled area
   int m_height;           ///< Current height of the scrolled area
   int m_oldx;             ///< Former x-position of the scrolled area
   int m_oldy;             ///< Former y-position of the scrolled area

   /// Horizontal scrollbar callback
   static void hscrollbar_cb(Fl_Widget*, void*);

   /// Vertical scrollbar callback
   static void scrollbar_cb(Fl_Widget*, void*);

   /// Constructor initializer
   void ctor_init();

   /// Insure the scrollbars are the last children:
   void fix_scrollbar_order();

   /// Draw the visible area. This is also the callback for fl_scroll.
   static void draw_clip(void* v,int X, int Y, int W, int H);

   /// Computed area for widgets
   void bbox(int& X, int& Y, int& W, int& H);

public:

   /// Constructor in SPTK style 
   /// @param label const char *, label
   /// @param layoutSize int, widget align in layout
   /// @param layoutAlign CLayoutAlign, widget align in layout
   CScroll(const char * label=0,int layoutSize=10,CLayoutAlign layoutAlign=SP_ALIGN_TOP);

#ifdef __COMPATIBILITY_MODE__    
   /// Constructor in FLTK style 
   /// @param x int, x-position
   /// @param y int, y-position
   /// @param w int, width
   /// @param h int, height
   /// @param label, const char * label
   CScroll(int x,int y,int w,int h,const char *label=0L);
#endif    

   CScrollBar scrollbar;     ///< Vertical scrollbar
   CScrollBar hscrollbar;    ///< Horizontal scrollbar

   /// Resizes the group 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);

   /// Custom draw() method
   virtual void draw();

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

   /// Removes all the child widgets
   void clear();

   /// Sets the position of the scrolled area
   void position(int X, int Y);

   /// Returns the x-position of the scrolled area
   int xposition() const {return m_xposition;}

   /// Returns the y-position of the scrolled area
   int yposition() const {return m_yposition;}

   /// Custom handle method
   int handle(int);
};

/// @}

#endif
