libyui-ncurses  2.44.1
/usr/src/RPM/BUILD/libyui-ncurses-2.44.1/src/NCInputField.h
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019    File:       NCInputField.h
00020 
00021    Author:     Michael Andres <ma@suse.de>
00022 
00023 /-*/
00024 
00025 #ifndef NCInputField_h
00026 #define NCInputField_h
00027 
00028 #include <iosfwd>
00029 
00030 #include <yui/YInputField.h>
00031 #include "NCWidget.h"
00032 
00033 
00034 class NCInputField : public YInputField, public NCWidget
00035 {
00036 
00037     friend std::ostream & operator<<( std::ostream & STREAM, const NCInputField & OBJ );
00038 
00039     NCInputField & operator=( const NCInputField & );
00040     NCInputField( const NCInputField & );
00041 
00042 public:
00043 
00044     enum FTYPE
00045     {
00046         PLAIN,
00047         NUMBER
00048     };
00049 
00050 private:
00051 
00052     bool     passwd;
00053     NClabel  label;
00054     std::wstring   buffer;
00055 
00056     NCursesWindow * lwin;
00057     NCursesWindow * twin;
00058 
00059     unsigned maxFldLength;
00060     unsigned maxInputLength;
00061 
00062     unsigned fldstart;
00063     unsigned fldlength;
00064     unsigned curpos;
00065 
00066     FTYPE    fldtype;
00067     NCstring validChars;
00068 
00069     bool     returnOnReturn_b;
00070 
00071     void setDefsze();
00072     void tUpdate();
00073 
00074     bool     bufferFull() const;
00075     unsigned maxCursor() const;
00076 
00077     // specifies how much characters can be inserted. -1 for unlimited input
00078     int InputMaxLength;
00079 
00080 protected:
00081 
00082     virtual const char * location() const { return "NCInputField"; }
00083 
00084     virtual void wCreate( const wrect & newrect );
00085     virtual void wDelete();
00086 
00087     virtual void wRedraw();
00088 
00089     bool validKey( wint_t key ) const;
00090 
00091 public:
00092 
00093     NCInputField( YWidget * parent,
00094                   const std::string & label,
00095                   bool passwordMode = false,
00096                   unsigned maxInput = 0,
00097                   unsigned maxFld   = 0
00098                 );
00099     virtual ~NCInputField();
00100 
00101     void setFldtype( FTYPE t )           { fldtype = t; }
00102 
00103     void setReturnOnReturn( bool on_br ) { returnOnReturn_b = on_br; }
00104 
00105     virtual int preferredWidth();
00106     virtual int preferredHeight();
00107 
00108     virtual void setSize( int newWidth, int newHeight );
00109 
00110     virtual void setLabel( const std::string & nlabel );
00111 
00112     virtual void setValue( const std::string & ntext );
00113     virtual std::string value();
00114 
00115     virtual void setValidChars( const std::string & validchars );
00116 
00117     virtual NCursesEvent wHandleInput( wint_t key );
00118 
00119     virtual void setEnabled( bool do_bv );
00120 
00121     virtual bool setKeyboardFocus()
00122     {
00123         if ( !grabFocus() )
00124             return YWidget::setKeyboardFocus();
00125 
00126         return true;
00127     }
00128 
00129     // limits  the input to numberOfChars characters and truncates the text
00130     // if appropriate
00131     void setInputMaxLength( int numberOfChars );
00132 
00133     void setCurPos( unsigned pos ) { curpos = pos; }
00134 };
00135 
00136 
00137 #endif // NCInputField_h
 All Classes Functions Variables