/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                          cinput.h - description
                             -------------------
    begin                : Tue Dec 14 1999
    copyright            : (C) 1999-2005 by Alexey 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 CInput_H
#define CInput_H

#include <FL/Fl_Input.H>

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

#include <string>

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

/// @brief Base input widget
///
/// Extends the standard Fl_Input with the extra
/// input types for the date, time, and phone input masks. It also
/// supports the optional maximum input length.
/// In is used mainly as the internal widget in different CControl-derived
/// widgets.
class SP_EXPORT CInput_ : public Fl_Input, public CLayoutClient {

   int         m_maxLength;      ///< Maximum input length
   std::string m_mask;           ///< Full input mask
   std::string m_inputMask;      ///< Actual input mask
   std::string m_backgroundMask; ///< Background (static) characters in mask

   /// Internal check for the character for matching the mask
   bool checkCharacterAtPos(int pos,char key);

   /// Internal check for the character for matching the mask
   bool checkCharacter(int pos,char& key);

protected:

   /// Conversion of the outside input value into internal masked value 
   /// using mask (if defined)
   void maskValue();

public:

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

   /// CInput_-specific version of FLTK handle() function
   /// @param event int, FLTK event
   /// @returns true if the event was processed
   int     handle(int event);

   /// Returns the font size for the input text
   uchar   textSize() const      { return (uchar)textsize();  }

   /// Sets the font size for the input text
   void    textSize(uchar sz)    { textsize(sz);       }

   /// Returns the font type for the input text
   Fl_Font textFont() const      { return textfont();  }
   /// Sets the font type for the input text
   void    textFont(Fl_Font fnt) { textfont(fnt);      }

   /// Returns the maximum length for the input text
   int     maxLength() const     { return m_maxLength; }

   /// Sets the maximum length for the input text
   void    maxLength(int ml)     { m_maxLength = ml; }

   /// Computes the optimal widgets 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);

   /// Sets the optional mask to the input widget. Passing an empty string as the maskString clears the mask.
   /// @param maskString const char *, the mask string.
   void mask(const char *maskString);
};

/// @}

#endif 
