26 #include <boost/date_time/posix_time/posix_time.hpp>
31 #define YUILogComponent "ncurses"
32 #include <yui/YUILog.h>
34 #include "NCDateField.h"
35 #include "NCInputTextBase.h"
39 const unsigned NCDateField::fieldLength = 10;
41 NCDateField::NCDateField ( YWidget * parent,
42 const std::string & nlabel )
43 : YDateField ( parent, nlabel )
46 yuiDebug() << std::endl;
51 setValue (
"2000-01-01" );
55 NCDateField::~NCDateField()
57 yuiDebug() << std::endl;
60 int NCDateField::preferredHeight()
62 return NCInputTextBase::preferredHeight();
65 int NCDateField::preferredWidth()
67 return NCInputTextBase::preferredWidth();
70 void NCDateField::setSize (
int newWidth,
int newHeight )
72 NCInputTextBase::setSize ( newWidth, newHeight );
79 YWidget::setEnabled ( do_bv );
82 void NCDateField::setLabel (
const std::string & nlabel )
86 YDateField::setLabel ( nlabel );
91 bool NCDateField::validDate(
const std::string& input_date)
93 std::wstringstream ss;
94 wdate_input_facet * fac =
new wdate_input_facet(L
"%Y-%m-%d");
95 ss.imbue(std::locale(std::locale::classic(), fac));
98 ss << input_date.c_str();
105 void NCDateField::setValue (
const std::string & ntext )
107 if ( validDate(ntext) )
111 if ( buffer.length() > maxFldLength )
113 buffer = buffer.erase ( maxFldLength );
118 curpos = buffer.length();
124 std::string NCDateField::value( )
144 buffer.erase ( curpos, 1 );
145 buffer.insert ( std::wstring::size_type ( curpos ), 1,
'0' );
146 if ( curpos == 5 || curpos == 8 )
156 if ( curpos < buffer.length() )
158 buffer.erase ( curpos, 1 );
159 buffer.insert ( std::wstring::size_type ( curpos ), 1,
'0' );
185 if ( curpos < maxCursor() )
187 curpos = maxCursor();
199 if ( curpos == 5 || curpos == 8 )
216 if ( curpos == 3 || curpos == 6 )
219 if ( curpos < maxCursor() )
234 if ( notify() || returnOnReturn_b )
235 ret = NCursesEvent::Activated;
245 bool is_special =
false;
253 if ( ( !is_special && KEY_MIN < key && KEY_MAX > key )
276 std::string buf =
NCstring(buffer).Str();
277 buffer.erase ( curpos, 1 );
278 buffer.insert ( std::wstring::size_type ( curpos ), 1, key );
279 if (validDate(
NCstring(buffer).Str()))
281 if ( curpos == 3 || curpos == 6 )
284 if ( curpos < maxCursor() )
313 ret = NCursesEvent::ValueChanged;
virtual void setEnabled(bool do_bv)
Pure virtual to make sure every widget implements it.
virtual void setEnabled(bool do_bv)
Pure virtual to make sure every widget implements it.