/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                          CTabs.h  -  description
                             -------------------
    begin                : Tue Feb 26 2002
    copyright            : (C) 2002-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 __CTABS_H__
#define __CTABS_H__

#include <sptk3/sptk.h>
#include <sptk3/CGroup.h>

class CTabsMatrix;
class CTabInfo;

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

/// Tabs position
enum CTabsMode { 
   CTM_TOP,    ///< Tabs are on the top
   CTM_RIGHT   ///< Tabs are on the right
};

/// @brief Tabs widget
///
/// It can show the tabs in several rows if they are too wide to fit.
class SP_EXPORT CTabs : public CGroup {
   Fl_Widget        *value_;            ///< Currently active tab
   Fl_Widget        *push_;             ///< Currently pushed tab
   CTabsMatrix      *m_tabsMatrix;      ///< The internal matrix of tabs
   int               m_autoColorIndex;  ///< The internal index inside tabs auto-color table

   /// The tab mode, defines the positions of the tabs
   /// @see CTabsMode
   CTabsMode         m_tabsMode;        

   /// Constructor initializer
   void ctor_init();

   /// Internal check for mouse events
   bool mouseEventOnTabs();

protected:

   /// Show tabs flag
   bool              m_showTabs;
   /// Tabs width when tabs are on the right
   int               m_tabsWidth;
   /// Tabs height when tabs are on the top
   int               m_tabsHeight;
protected:

   /// Draws tab
   /// @param tab CTabInfo *, internal tab information
   /// @param selected int, true if tab is currently selected
   virtual void draw_tab(CTabInfo *tab,int selected=0);

   /// Draws the whole widget
   void draw();

   /// Returns the last tab created. Internal.
   Fl_Group* lastTab();

   /// Resizes tabs during widget resize
   virtual void resizeTabs();

   /// Extends tabs during widget resize to fill the available width
   virtual void extendTabs();

   /// Which tab was pushed?
   Fl_Widget *push() const {return push_;}

   /// Push a tab. Internal
   int push(Fl_Widget *);

   /// Which tab is clicked?
   Fl_Widget *which(int event_x, int event_y);

public:
   /// auto-color table
   static const Fl_Color AutoColorTable[16];

   /// Constructor in SPTK style 
   /// @param label const char *, label
   /// @param layoutSize int, widget align in layout
   /// @param layoutAlign CLayoutAlign, widget align in layout
   CTabs(const char * label=0L,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
   CTabs(int x,int y,int w,int h,const char *label = 0);
#endif    

   /// Destructor
   virtual ~CTabs();

   /// Creates a new CGroup page
   /// @param label const char *, tab and page label
   /// @param autoColor bool, auto-color assignment on/off
   virtual Fl_Group* newPage(const char *label,bool autoColor=false);

   /// Creates a new CScroll page
   /// @param label const char *, tab and page label
   /// @param autoColor bool, auto-color assignment on/off
   virtual Fl_Group* newScroll(const char *label,bool autoColor=false);

   /// Special handle() function
   int handle(int);

   /// Returns currently selected tab 
   Fl_Widget *value();

   /// Sets selected tab 
   int value(Fl_Widget *page);

   /// Returns selected page number
   int pageNumber() const;

   /// Sets selected page by number
   void pageNumber(unsigned pageNumber);

   /// Tabs count
   unsigned tabsCount() const;

   /// Sets show tabs flag on/off
   void      showTabs(bool st);

   /// Returns show tabs flag on/off
   bool      showTabs() { return m_showTabs; }

   /// Sets tabs mode left/top
   void      tabsMode(CTabsMode tm);

   /// Returns tabs mode left/top
   CTabsMode tabsMode() { return m_tabsMode; }

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

/// @}

#endif
