libyui-ncurses  2.44.1
 All Classes Functions Variables
NCInputField.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: NCInputField.h
20 
21  Author: Michael Andres <ma@suse.de>
22 
23 /-*/
24 
25 #ifndef NCInputField_h
26 #define NCInputField_h
27 
28 #include <iosfwd>
29 
30 #include <yui/YInputField.h>
31 #include "NCWidget.h"
32 
33 
34 class NCInputField : public YInputField, public NCWidget
35 {
36 
37  friend std::ostream & operator<<( std::ostream & STREAM, const NCInputField & OBJ );
38 
39  NCInputField & operator=( const NCInputField & );
40  NCInputField( const NCInputField & );
41 
42 public:
43 
44  enum FTYPE
45  {
46  PLAIN,
47  NUMBER
48  };
49 
50 private:
51 
52  bool passwd;
53  NClabel label;
54  std::wstring buffer;
55 
56  NCursesWindow * lwin;
57  NCursesWindow * twin;
58 
59  unsigned maxFldLength;
60  unsigned maxInputLength;
61 
62  unsigned fldstart;
63  unsigned fldlength;
64  unsigned curpos;
65 
66  FTYPE fldtype;
67  NCstring validChars;
68 
69  bool returnOnReturn_b;
70 
71  void setDefsze();
72  void tUpdate();
73 
74  bool bufferFull() const;
75  unsigned maxCursor() const;
76 
77  // specifies how much characters can be inserted. -1 for unlimited input
78  int InputMaxLength;
79 
80 protected:
81 
82  virtual const char * location() const { return "NCInputField"; }
83 
84  virtual void wCreate( const wrect & newrect );
85  virtual void wDelete();
86 
87  virtual void wRedraw();
88 
89  bool validKey( wint_t key ) const;
90 
91 public:
92 
93  NCInputField( YWidget * parent,
94  const std::string & label,
95  bool passwordMode = false,
96  unsigned maxInput = 0,
97  unsigned maxFld = 0
98  );
99  virtual ~NCInputField();
100 
101  void setFldtype( FTYPE t ) { fldtype = t; }
102 
103  void setReturnOnReturn( bool on_br ) { returnOnReturn_b = on_br; }
104 
105  virtual int preferredWidth();
106  virtual int preferredHeight();
107 
108  virtual void setSize( int newWidth, int newHeight );
109 
110  virtual void setLabel( const std::string & nlabel );
111 
112  virtual void setValue( const std::string & ntext );
113  virtual std::string value();
114 
115  virtual void setValidChars( const std::string & validchars );
116 
117  virtual NCursesEvent wHandleInput( wint_t key );
118 
119  virtual void setEnabled( bool do_bv );
120 
121  virtual bool setKeyboardFocus()
122  {
123  if ( !grabFocus() )
124  return YWidget::setKeyboardFocus();
125 
126  return true;
127  }
128 
129  // limits the input to numberOfChars characters and truncates the text
130  // if appropriate
131  void setInputMaxLength( int numberOfChars );
132 
133  void setCurPos( unsigned pos ) { curpos = pos; }
134 };
135 
136 
137 #endif // NCInputField_h
C++ class for windows.
Definition: ncursesw.h:904
virtual void setEnabled(bool do_bv)
Definition: NCInputField.cc:94
Definition: NCtext.h:81