29 #define YUILogComponent "ncurses"
30 #include <yui/YUILog.h>
32 #include "NCTimeField.h"
33 #include "NCInputTextBase.h"
38 const unsigned NCTimeField::fieldLength = 8;
40 NCTimeField::NCTimeField ( YWidget * parent,
41 const std::string & nlabel )
42 : YTimeField ( parent, nlabel )
45 yuiDebug() << std::endl;
49 setValue (
"00:00:00" );
54 NCTimeField::~NCTimeField()
56 yuiDebug() << std::endl;
61 int NCTimeField::preferredWidth()
63 return NCInputTextBase::preferredWidth();
68 int NCTimeField::preferredHeight()
70 return NCInputTextBase::preferredHeight();
75 void NCTimeField::setSize (
int newwidth,
int newheight )
77 NCInputTextBase::setSize ( newwidth, newheight );
84 YWidget::setEnabled ( do_bv );
87 void NCTimeField::setLabel (
const std::string & nlabel )
91 YTimeField::setLabel ( nlabel );
97 bool NCTimeField::validTime(
const std::string& input_time)
100 std::stringstream ss;
104 if (!(ss >> tm1.tm_hour))
108 if (!(ss >> tm1.tm_min))
112 if (!(ss >> tm1.tm_sec))
115 return (tm1.tm_hour<=23 && tm1.tm_min <= 59 && tm1.tm_sec <= 59);
119 void NCTimeField::setValue (
const std::string & ntext )
121 if (validTime(ntext))
125 if ( buffer.length() > maxFldLength )
127 buffer = buffer.erase ( maxFldLength );
138 std::string NCTimeField::value( )
158 buffer.erase ( curpos, 1 );
159 buffer.insert ( std::wstring::size_type ( curpos ), 1,
'0' );
160 if ( curpos == 3 || curpos == 6 )
170 if ( curpos < buffer.length() )
172 buffer.erase ( curpos, 1 );
173 buffer.insert ( std::wstring::size_type ( curpos ), 1,
'0' );
199 if ( curpos < maxCursor() )
201 curpos = maxCursor();
213 if ( curpos == 3 || curpos == 6 )
230 if ( curpos == 1 || curpos == 4 )
233 if ( curpos < maxCursor() )
248 if ( notify() || returnOnReturn_b )
249 ret = NCursesEvent::Activated;
259 bool is_special =
false;
267 if ( ( !is_special && KEY_MIN < key && KEY_MAX > key )
290 std::string buf =
NCstring(buffer).Str();
291 buffer.erase ( curpos, 1 );
292 buffer.insert ( std::wstring::size_type ( curpos ), 1, key );
294 if (validTime(
NCstring(buffer).Str()))
296 if ( curpos == 1 || curpos == 4 )
298 else if ( curpos < maxCursor() )
327 ret = NCursesEvent::ValueChanged;