commit libyui-ncurses for openSUSE:Factory
Hello community, here is the log from the commit of package libyui-ncurses for openSUSE:Factory checked in at 2015-02-20 12:00:21 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/libyui-ncurses (Old) and /work/SRC/openSUSE:Factory/.libyui-ncurses.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "libyui-ncurses" Changes: -------- --- /work/SRC/openSUSE:Factory/libyui-ncurses/libyui-ncurses.changes 2015-01-21 21:52:11.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.libyui-ncurses.new/libyui-ncurses.changes 2015-02-20 12:00:34.000000000 +0100 @@ -1,0 +2,17 @@ +Tue Feb 17 15:40:07 UTC 2015 - anaselli@linux.it + +- NCTimeField input validity check +- NCDateField input validity check +- Implementation of optional widget YTimeField +- Implementation of optional widget YDateField +- new class NCInputText to share code between NCTimeField, NCDateField + and NCInputField +- 2.46.10 + +------------------------------------------------------------------- +Tue Feb 3 13:57:26 CET 2015 - gs@suse.de + +- don't use internal ncurses (_nc_) functions (bnc #915945) +- 2.46.9 + +------------------------------------------------------------------- Old: ---- libyui-ncurses-2.46.8.tar.bz2 New: ---- libyui-ncurses-2.46.10.tar.bz2 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ libyui-ncurses-doc.spec ++++++ --- /var/tmp/diff_new_pack.1MxvH6/_old 2015-02-20 12:00:35.000000000 +0100 +++ /var/tmp/diff_new_pack.1MxvH6/_new 2015-02-20 12:00:35.000000000 +0100 @@ -17,7 +17,7 @@ Name: libyui-ncurses-doc -Version: 2.46.8 +Version: 2.46.10 Release: 0 Source: libyui-ncurses-%{version}.tar.bz2 ++++++ libyui-ncurses.spec ++++++ --- /var/tmp/diff_new_pack.1MxvH6/_old 2015-02-20 12:00:35.000000000 +0100 +++ /var/tmp/diff_new_pack.1MxvH6/_new 2015-02-20 12:00:35.000000000 +0100 @@ -17,7 +17,7 @@ Name: libyui-ncurses -Version: 2.46.8 +Version: 2.46.10 Release: 0 Source: libyui-ncurses-%{version}.tar.bz2 ++++++ libyui-ncurses-2.46.8.tar.bz2 -> libyui-ncurses-2.46.10.tar.bz2 ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-ncurses-2.46.8/ChangeLog new/libyui-ncurses-2.46.10/ChangeLog --- old/libyui-ncurses-2.46.8/ChangeLog 2015-01-20 17:15:11.000000000 +0100 +++ new/libyui-ncurses-2.46.10/ChangeLog 2015-02-18 14:50:10.000000000 +0100 @@ -1,4 +1,21 @@ ------------------------------------------------------------------- +Tue Feb 17 15:40:07 UTC 2015 - anaselli@linux.it + +- NCTimeField input validity check +- NCDateField input validity check +- Implementation of optional widget YTimeField +- Implementation of optional widget YDateField +- new class NCInputText to share code between NCTimeField, NCDateField + and NCInputField +- 2.46.10 + +------------------------------------------------------------------- +Tue Feb 3 13:57:26 CET 2015 - gs@suse.de + +- don't use internal ncurses (_nc_) functions (bnc #915945) +- 2.46.9 + +------------------------------------------------------------------- Tue Jan 20 16:09:58 UTC 2015 - mvidner@suse.com - Fixed building with cmake 3.1 (PREFIX in spec, boo#911875). diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-ncurses-2.46.8/SOURCECONF.cmake new/libyui-ncurses-2.46.10/SOURCECONF.cmake --- old/libyui-ncurses-2.46.8/SOURCECONF.cmake 2014-02-21 11:37:26.000000000 +0100 +++ new/libyui-ncurses-2.46.10/SOURCECONF.cmake 2015-02-18 14:50:10.000000000 +0100 @@ -44,7 +44,10 @@ NCPushButton.cc NCDumbTab.cc NCRadioButton.cc + NCInputTextBase.cc NCInputField.cc + NCDateField.cc + NCTimeField.cc NCIntField.cc NCComboBox.cc NCPadWidget.cc @@ -115,7 +118,10 @@ NCPushButton.h NCDumbTab.h NCRadioButton.h + NCInputTextBase.h NCInputField.h + NCTimeField.h + NCDateField.h NCIntField.h NCComboBox.h NCPadWidget.h diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-ncurses-2.46.8/VERSION.cmake new/libyui-ncurses-2.46.10/VERSION.cmake --- old/libyui-ncurses-2.46.8/VERSION.cmake 2015-01-20 17:15:11.000000000 +0100 +++ new/libyui-ncurses-2.46.10/VERSION.cmake 2015-02-18 14:50:10.000000000 +0100 @@ -1,6 +1,6 @@ SET( VERSION_MAJOR "2" ) SET( VERSION_MINOR "46" ) -SET( VERSION_PATCH "8" ) +SET( VERSION_PATCH "10" ) SET( VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}${GIT_SHA1_VERSION}" ) ##### This is need for the libyui core, ONLY. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-ncurses-2.46.8/src/NCDateField.cc new/libyui-ncurses-2.46.10/src/NCDateField.cc --- old/libyui-ncurses-2.46.8/src/NCDateField.cc 1970-01-01 01:00:00.000000000 +0100 +++ new/libyui-ncurses-2.46.10/src/NCDateField.cc 2015-02-18 14:50:10.000000000 +0100 @@ -0,0 +1,323 @@ +/* + Copyright (C) 2014 Angelo Naselli + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) version 3.0 of the License. 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 Lesser General Public + License for more details. You should have received a copy of the GNU + Lesser General Public License along with this library; if not, write + to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + Floor, Boston, MA 02110-1301 USA +*/ + + +/*-/ + + File: NCDateField.cc + + Author: Angelo Naselli <anaselli@linux.it> + +/-*/ +#include <climits> +#include <boost/date_time/posix_time/posix_time.hpp> +#include <iostream> +#include <sstream> + + +#define YUILogComponent "ncurses" +#include <yui/YUILog.h> +#include "NCurses.h" +#include "NCDateField.h" +#include "NCInputTextBase.h" + +using namespace boost::gregorian; + +const unsigned NCDateField::fieldLength = 10; + +NCDateField::NCDateField ( YWidget * parent, + const std::string & nlabel ) + : YDateField ( parent, nlabel ) + , NCInputTextBase ( parent, false, fieldLength, fieldLength ) +{ + yuiDebug() << std::endl; + + setLabel ( nlabel ); + + // Same value as QT default + setValue ( "2000-01-01" ); +} + + +NCDateField::~NCDateField() +{ + yuiDebug() << std::endl; +} + +int NCDateField::preferredHeight() +{ + return NCInputTextBase::preferredHeight(); +} + +int NCDateField::preferredWidth() +{ + return NCInputTextBase::preferredWidth(); +} + +void NCDateField::setSize ( int newWidth, int newHeight ) +{ + NCInputTextBase::setSize ( newWidth, newHeight ); +} + + +void NCDateField::setEnabled ( bool do_bv ) +{ + NCInputTextBase::setEnabled ( do_bv ); + YWidget::setEnabled ( do_bv ); +} + +void NCDateField::setLabel ( const std::string & nlabel ) +{ + _label = NCstring ( nlabel ); + _label.stripHotkey(); + YDateField::setLabel ( nlabel ); + setDefsze(); + Redraw(); +} + +bool NCDateField::validDate(const std::string& input_date) +{ + std::wstringstream ss; + wdate_input_facet * fac = new wdate_input_facet(L"%Y-%m-%d"); + ss.imbue(std::locale(std::locale::classic(), fac)); + + date d; + ss << input_date.c_str(); + ss >> d; + + return d != date(); +} + + +void NCDateField::setValue ( const std::string & ntext ) +{ + if ( validDate(ntext) ) + { + buffer = NCstring ( ntext ).str(); + + if ( buffer.length() > maxFldLength ) + { + buffer = buffer.erase ( maxFldLength ); + } + + fldstart = 0; + + curpos = buffer.length(); + tUpdate(); + } +} + + +std::string NCDateField::value( ) +{ + NCstring text ( buffer ); + + return text.Str(); +} + + +NCursesEvent NCDateField::wHandleInput ( wint_t key ) +{ + NCursesEvent ret = NCursesEvent::none; + bool beep = false; + bool update = true; + + switch ( key ) + { + case '\b': //ctrl-h + case 0x7f: //del + case KEY_BACKSPACE: + + buffer.erase ( curpos, 1 ); + buffer.insert ( std::wstring::size_type ( curpos ), 1, '0' ); + if ( curpos == 5 || curpos == 8 ) + curpos -= 2; + else + if ( curpos ) + curpos--; + + break; + + case KEY_DC: + + if ( curpos < buffer.length() ) + { + buffer.erase ( curpos, 1 ); + buffer.insert ( std::wstring::size_type ( curpos ), 1, '0' ); + } + else + { + update = false; + beep = true; + } + + break; + + case KEY_HOME: + + if ( curpos ) + { + curpos = 0; + } + else + { + update = false; + beep = true; + } + + break; + + case KEY_END: + + if ( curpos < maxCursor() ) + { + curpos = maxCursor(); + } + else + { + update = false; + beep = true; + } + + break; + + case KEY_LEFT: + + if ( curpos == 5 || curpos == 8 ) + curpos -= 2; + else + if ( curpos ) + { + --curpos; + } + else + { + update = false; + beep = true; + } + + break; + + case KEY_RIGHT: + + if ( curpos == 3 || curpos == 6 ) + curpos += 2; + else + if ( curpos < maxCursor() ) + { + ++curpos; + } + else + { + update = false; + beep = true; + } + + break; + + case KEY_RETURN: + update = false; + + if ( notify() || returnOnReturn_b ) + ret = NCursesEvent::Activated; + + break; + + case KEY_HOTKEY: + update = false; + + break; + + default: + bool is_special = false; + + if ( key > 0xFFFF ) + { + is_special = true; + key -= 0xFFFF; + } + + if ( ( !is_special && KEY_MIN < key && KEY_MAX > key ) + || + !iswprint ( key ) ) + { + update = false; + beep = true; + } + else + { + { + switch ( key ) + { + case L'0': + case L'1': + case L'2': + case L'3': + case L'4': + case L'5': + case L'6': + case L'7': + case L'8': + case L'9': + { + std::string buf = NCstring(buffer).Str(); + buffer.erase ( curpos, 1 ); + buffer.insert ( std::wstring::size_type ( curpos ), 1, key ); + if (validDate(NCstring(buffer).Str())) + { + if ( curpos == 3 || curpos == 6 ) + curpos += 2; + else + if ( curpos < maxCursor() ) + ++curpos; + } + else + { + update = false; + setValue(buf); + beep = true; + } + } + break; + + default: + update = false; + beep = true; + break; + } + } + + } + + break; + } + + if ( update ) + { + tUpdate(); + + if ( notify() ) + ret = NCursesEvent::ValueChanged; + } + + if ( beep ) + ::beep(); + + return ret; + +} + + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-ncurses-2.46.8/src/NCDateField.h new/libyui-ncurses-2.46.10/src/NCDateField.h --- old/libyui-ncurses-2.46.8/src/NCDateField.h 1970-01-01 01:00:00.000000000 +0100 +++ new/libyui-ncurses-2.46.10/src/NCDateField.h 2015-02-18 14:50:10.000000000 +0100 @@ -0,0 +1,87 @@ +/* + Copyright (C) 2014 Angelo Naselli + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) version 3.0 of the License. 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 Lesser General Public + License for more details. You should have received a copy of the GNU + Lesser General Public License along with this library; if not, write + to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + Floor, Boston, MA 02110-1301 USA +*/ + + +/*-/ + + File: NCDateField.h + + Author: Angelo Naselli <anaselli@linux.it> + +/-*/ + +#ifndef NCDateField_h +#define NCDateField_h + +#include <iosfwd> + +#include <yui/YDateField.h> +#include "NCWidget.h" +#include "NCInputTextBase.h" + +class NCDateField : public YDateField, public NCInputTextBase +{ + + friend std::ostream & operator<< ( std::ostream & STREAM, const NCDateField & OBJ ); + + NCDateField & operator= ( const NCDateField & ); + NCDateField ( const NCDateField & ); + +private: + static const unsigned fieldLength; + + bool validDate(const std::string& input_date); + +protected: + + virtual const char * location() const + { + return "NCDateField"; + } + +public: + + NCDateField ( YWidget * parent, + const std::string & label + ); + virtual ~NCDateField(); + + virtual int preferredWidth(); + virtual int preferredHeight(); + + virtual void setSize ( int newWidth, int newHeight ); + + virtual void setLabel ( const std::string & nlabel ); + + virtual void setValue ( const std::string & ntext ); + virtual std::string value(); + + virtual void setEnabled ( bool do_bv ); + + virtual NCursesEvent wHandleInput ( wint_t key ); + + virtual bool setKeyboardFocus() + { + if ( !grabFocus() ) + return YWidget::setKeyboardFocus(); + + return true; + } + +}; + + +#endif // NCDateField_h diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-ncurses-2.46.8/src/NCInputTextBase.cc new/libyui-ncurses-2.46.10/src/NCInputTextBase.cc --- old/libyui-ncurses-2.46.8/src/NCInputTextBase.cc 1970-01-01 01:00:00.000000000 +0100 +++ new/libyui-ncurses-2.46.10/src/NCInputTextBase.cc 2015-02-18 14:50:10.000000000 +0100 @@ -0,0 +1,296 @@ +/* + Copyright (C) 2014 Angelo Naselli + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) version 3.0 of the License. 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 Lesser General Public + License for more details. You should have received a copy of the GNU + Lesser General Public License along with this library; if not, write + to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + Floor, Boston, MA 02110-1301 USA +*/ + + +/*-/ + + File: NCInputText.cc + + Author: Angelo Naselli <anaselli@linux.it> + +/-*/ +#include <climits> + + +#define YUILogComponent "ncurses" +#include <yui/YUILog.h> +#include "NCurses.h" +#include "NCInputTextBase.h" + +#include <wctype.h> // iswalnum() + + +NCInputTextBase::NCInputTextBase ( YWidget * parent, + bool passwordMode, + unsigned maxInput, + unsigned maxFld ) + : NCWidget ( parent ) + , passwd ( passwordMode ) + , lwin ( 0 ) + , twin ( 0 ) + , maxFldLength ( maxFld ) + , maxInputLength ( maxInput ) + , fldstart ( 0 ) + , fldlength ( 0 ) + , curpos ( 0 ) + , returnOnReturn_b ( false ) +{ + yuiDebug() << std::endl; + + if ( maxInputLength && + ( !maxFldLength || maxFldLength > maxInputLength ) ) + { + maxFldLength = maxInputLength; + } + + hotlabel = &_label; +} + + + +NCInputTextBase::~NCInputTextBase() +{ + delete lwin; + delete twin; + yuiDebug() << std::endl; +} + + + +int NCInputTextBase::preferredWidth() +{ + return wGetDefsze().W; +} + + + +int NCInputTextBase::preferredHeight() +{ + return wGetDefsze().H; +} + + + +void NCInputTextBase::setEnabled ( bool do_bv ) +{ + NCWidget::setEnabled ( do_bv ); +} + + + +void NCInputTextBase::setSize ( int newwidth, int newheight ) +{ + wRelocate ( wpos ( 0 ), wsze ( newheight, newwidth ) ); +} + + + +void NCInputTextBase::setDefsze() +{ + unsigned defwidth = maxFldLength ? maxFldLength : 5; + + if ( _label.width() > defwidth ) + defwidth = _label.width(); + + defsze = wsze ( _label.height() + 1, defwidth ); +} + + + +void NCInputTextBase::wCreate ( const wrect & newrect ) +{ + NCWidget::wCreate ( newrect ); + + if ( !win ) + return; + + wrect lrect ( 0, wsze::min ( newrect.Sze, + wsze ( _label.height(), newrect.Sze.W ) ) ); + + if ( lrect.Sze.H == newrect.Sze.H ) + lrect.Sze.H -= 1; + + wrect trect ( 0, wsze ( 1, newrect.Sze.W ) ); + + trect.Pos.L = lrect.Sze.H > 0 ? lrect.Sze.H : 0; + + lwin = new NCursesWindow ( *win, + lrect.Sze.H, lrect.Sze.W, + lrect.Pos.L, lrect.Pos.C, + 'r' ); + + twin = new NCursesWindow ( *win, + trect.Sze.H, trect.Sze.W, + trect.Pos.L, trect.Pos.C, + 'r' ); + + if ( maxFldLength && maxFldLength < ( unsigned ) newrect.Sze.W ) + trect.Sze.W = maxFldLength; + + fldlength = trect.Sze.W; +} + + + +void NCInputTextBase::wDelete() +{ + delete lwin; + delete twin; + lwin = 0; + twin = 0; + NCWidget::wDelete(); +} + + +void NCInputTextBase::wRedraw() +{ + if ( !win ) + return; + + // label + const NCstyle::StWidget & style ( widgetStyle ( true ) ); + + lwin->bkgd ( style.plain ); + + lwin->clear(); + + _label.drawAt ( *lwin, style ); + + tUpdate(); +} + + + +bool NCInputTextBase::bufferFull() const +{ + return ( maxInputLength && buffer.length() == maxInputLength ); +} + + + +unsigned NCInputTextBase::maxCursor() const +{ + return ( bufferFull() ? buffer.length() - 1 : buffer.length() ); +} + + + +void NCInputTextBase::tUpdate() +{ + if ( !win ) + return; + + unsigned maxc = maxCursor(); + + // adjust cursor + if ( curpos > maxc ) + { + curpos = maxc; + } + + // adjust fldstart that cursor is visible + if ( maxc < fldlength ) + { + fldstart = 0; + } + else + { + if ( curpos <= fldstart ) + { + fldstart = curpos ? curpos - 1 : 0; + } + + if ( curpos >= fldstart + fldlength - 1 ) + { + fldstart = curpos + ( curpos == maxc ? 1 : 2 ) - fldlength; + } + } + + const NCstyle::StWidget & style ( widgetStyle() ); + + twin->bkgd ( widgetStyle ( true ).plain ); + + twin->move ( 0, 0 ); + + unsigned i = 0; + + unsigned end = fldlength; + + const wchar_t * cp = buffer.data() + fldstart; + + // draw left scrollhint if + if ( *cp && fldstart ) + { + twin->bkgdset ( style.scrl ); + twin->addch ( ACS_LARROW ); + ++i; + ++cp; + } + + // check for right scrollhint + if ( fldstart + fldlength <= maxc ) + { + --end; + } + + // draw field + twin->bkgdset ( style.data ); + + for ( /*adjusted i*/; *cp && i < end; ++i ) + { + if ( passwd ) + { + twin->addwstr ( L"*" ); + } + else + { + twin->addwstr ( cp, 1 ); + } + + ++cp; + } + + twin->bkgdset ( style.plain ); + + for ( /*adjusted i*/; i < end; ++i ) + { + twin->addch ( ACS_CKBOARD ); + } + + // draw right scrollhint if + if ( end < fldlength ) + { + twin->bkgdset ( style.scrl ); + twin->addch ( ACS_RARROW ); + } + + // reverse curpos + if ( GetState() == NC::WSactive ) + { + twin->move ( 0, curpos - fldstart ); + twin->bkgdset ( wStyle().cursor ); + + if ( curpos < buffer.length() ) + twin->add_attr_char( ); + else + twin->addch ( ACS_CKBOARD ); + } + + Update(); +} + + + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-ncurses-2.46.8/src/NCInputTextBase.h new/libyui-ncurses-2.46.10/src/NCInputTextBase.h --- old/libyui-ncurses-2.46.8/src/NCInputTextBase.h 1970-01-01 01:00:00.000000000 +0100 +++ new/libyui-ncurses-2.46.10/src/NCInputTextBase.h 2015-02-18 14:50:10.000000000 +0100 @@ -0,0 +1,105 @@ +/* + Copyright (C) 2014 Angelo Naselli + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) version 3.0 of the License. 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 Lesser General Public + License for more details. You should have received a copy of the GNU + Lesser General Public License along with this library; if not, write + to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + Floor, Boston, MA 02110-1301 USA +*/ + + +/*-/ + + File: NCInputText.h + + Author: Angelo Naselli <anaselli@linux.it> + +/-*/ +#ifndef NCInputText_h +#define NCInputText_h + +#include <iosfwd> + +#include "NCWidget.h" + + +class NCInputTextBase : public NCWidget +{ + + friend std::ostream & operator<< ( std::ostream & STREAM, const NCInputTextBase & OBJ ); + + NCInputTextBase & operator= ( const NCInputTextBase & ); + NCInputTextBase ( const NCInputTextBase & ); + +protected: + + bool passwd; + NClabel _label; + std::wstring buffer; + + NCursesWindow * lwin; + NCursesWindow * twin; + + unsigned maxFldLength; + unsigned maxInputLength; + + unsigned fldstart; + unsigned fldlength; + unsigned curpos; + + bool returnOnReturn_b; + + virtual void setDefsze(); + virtual void tUpdate(); + + virtual bool bufferFull() const; + virtual unsigned maxCursor() const; + + virtual const char * location() const + { + return "NCInputTextBase"; + } + + virtual void wCreate ( const wrect & newrect ); + virtual void wDelete(); + + virtual void wRedraw(); + + + NCInputTextBase ( YWidget * parent, + bool passwordMode = false, + unsigned maxInput = 0, + unsigned maxFld = 0 + ); + virtual ~NCInputTextBase(); + +public: + + void setReturnOnReturn ( bool on_br ) + { + returnOnReturn_b = on_br; + } + + virtual int preferredWidth(); + virtual int preferredHeight(); + + virtual void setSize ( int newWidth, int newHeight ); + + virtual void setEnabled ( bool do_bv ); + + virtual void setCurPos ( unsigned pos ) + { + curpos = pos; + } + +}; + + +#endif // NCInputText_h diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-ncurses-2.46.8/src/NCOptionalWidgetFactory.cc new/libyui-ncurses-2.46.10/src/NCOptionalWidgetFactory.cc --- old/libyui-ncurses-2.46.8/src/NCOptionalWidgetFactory.cc 2014-02-21 11:37:26.000000000 +0100 +++ new/libyui-ncurses-2.46.10/src/NCOptionalWidgetFactory.cc 2015-02-18 14:50:10.000000000 +0100 @@ -24,6 +24,8 @@ #include "NCOptionalWidgetFactory.h" #include <yui/YUIException.h> +#include <NCTimeField.h> +#include <NCDateField.h> #define THROW_UNSUPPORTED( WIDGET_TYPE ) \ @@ -57,5 +59,30 @@ return dumbTab; } +bool NCOptionalWidgetFactory::hasTimeField() +{ + return true; +} + +YTimeField* NCOptionalWidgetFactory::createTimeField( YWidget * parent, const std::string & label ) +{ + NCTimeField * timeField = new NCTimeField( parent, label ); + YUI_CHECK_NEW( timeField ); + + return timeField; +} + +bool NCOptionalWidgetFactory::hasDateField() +{ + return true; +} + +YDateField* NCOptionalWidgetFactory::createDateField( YWidget * parent, const std::string & label ) +{ + NCDateField * dateField = new NCDateField( parent, label ); + YUI_CHECK_NEW( dateField ); + + return dateField; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-ncurses-2.46.8/src/NCOptionalWidgetFactory.h new/libyui-ncurses-2.46.10/src/NCOptionalWidgetFactory.h --- old/libyui-ncurses-2.46.8/src/NCOptionalWidgetFactory.h 2014-02-21 11:37:26.000000000 +0100 +++ new/libyui-ncurses-2.46.10/src/NCOptionalWidgetFactory.h 2015-02-18 14:50:10.000000000 +0100 @@ -29,6 +29,8 @@ #include <yui/YOptionalWidgetFactory.h> #include "NCDumbTab.h" +class YTimeField; +class YDateField; /** * Widget factory for optional ("special") widgets. @@ -68,6 +70,12 @@ NCDumbTab *createDumbTab( YWidget * parent ); + bool hasTimeField(); + YTimeField* createTimeField( YWidget * parent, const std::string & label ); + + bool hasDateField(); + YDateField* createDateField( YWidget * parent, const std::string & label ); + }; // class NCOptionalWidgetFactory diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-ncurses-2.46.8/src/NCTimeField.cc new/libyui-ncurses-2.46.10/src/NCTimeField.cc --- old/libyui-ncurses-2.46.8/src/NCTimeField.cc 1970-01-01 01:00:00.000000000 +0100 +++ new/libyui-ncurses-2.46.10/src/NCTimeField.cc 2015-02-18 14:50:10.000000000 +0100 @@ -0,0 +1,337 @@ +/* + Copyright (C) 2014 Angelo Naselli + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) version 3.0 of the License. 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 Lesser General Public + License for more details. You should have received a copy of the GNU + Lesser General Public License along with this library; if not, write + to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + Floor, Boston, MA 02110-1301 USA +*/ + + +/*-/ + + File: NCTimeField.cc + + Author: Angelo Naselli <anaselli@linux.it> + +/-*/ +#include <climits> +#include <iostream> +#include <sstream> + +#define YUILogComponent "ncurses" +#include <yui/YUILog.h> +#include "NCurses.h" +#include "NCTimeField.h" +#include "NCInputTextBase.h" + +#include <wctype.h> // iswalnum() + + +const unsigned NCTimeField::fieldLength = 8; + +NCTimeField::NCTimeField ( YWidget * parent, + const std::string & nlabel ) + : YTimeField ( parent, nlabel ) + , NCInputTextBase ( parent, false, fieldLength, fieldLength ) +{ + yuiDebug() << std::endl; + + setLabel ( nlabel ); + + setValue ( "00:00:00" ); +} + + + +NCTimeField::~NCTimeField() +{ + yuiDebug() << std::endl; +} + + + +int NCTimeField::preferredWidth() +{ + return NCInputTextBase::preferredWidth(); +} + + + +int NCTimeField::preferredHeight() +{ + return NCInputTextBase::preferredHeight(); +} + + + +void NCTimeField::setSize ( int newwidth, int newheight ) +{ + NCInputTextBase::setSize ( newwidth, newheight ); +} + + +void NCTimeField::setEnabled ( bool do_bv ) +{ + NCWidget::setEnabled ( do_bv ); + YWidget::setEnabled ( do_bv ); +} + +void NCTimeField::setLabel ( const std::string & nlabel ) +{ + _label = NCstring ( nlabel ); + _label.stripHotkey(); + YTimeField::setLabel ( nlabel ); + setDefsze(); + Redraw(); +} + + +bool NCTimeField::validTime(const std::string& input_time) +{ + tm tm1; + std::stringstream ss; + ss << input_time; + char c; + + if (!(ss >> tm1.tm_hour)) + return false; + ss >> c; + + if (!(ss >> tm1.tm_min)) + return false; + ss >> c; + + if (!(ss >> tm1.tm_sec)) + return false; + + return (tm1.tm_hour<=23 && tm1.tm_min <= 59 && tm1.tm_sec <= 59); +} + + +void NCTimeField::setValue ( const std::string & ntext ) +{ + if (validTime(ntext)) + { + buffer = NCstring ( ntext ).str(); + + if ( buffer.length() > maxFldLength ) + { + buffer = buffer.erase ( maxFldLength ); + } + + fldstart = 0; + + tUpdate(); + } +} + + + +std::string NCTimeField::value( ) +{ + NCstring text ( buffer ); + + return text.Str(); +} + + +NCursesEvent NCTimeField::wHandleInput ( wint_t key ) +{ + NCursesEvent ret = NCursesEvent::none; + bool beep = false; + bool update = true; + + switch ( key ) + { + case '\b': //ctrl-h + case 0x7f: //del + case KEY_BACKSPACE: + + buffer.erase ( curpos, 1 ); + buffer.insert ( std::wstring::size_type ( curpos ), 1, '0' ); + if ( curpos == 3 || curpos == 6 ) + curpos -= 2; + else + if ( curpos ) + curpos--; + + break; + + case KEY_DC: + + if ( curpos < buffer.length() ) + { + buffer.erase ( curpos, 1 ); + buffer.insert ( std::wstring::size_type ( curpos ), 1, '0' ); + } + else + { + update = false; + beep = true; + } + + break; + + case KEY_HOME: + + if ( curpos ) + { + curpos = 0; + } + else + { + update = false; + beep = true; + } + + break; + + case KEY_END: + + if ( curpos < maxCursor() ) + { + curpos = maxCursor(); + } + else + { + update = false; + beep = true; + } + + break; + + case KEY_LEFT: + + if ( curpos == 3 || curpos == 6 ) + curpos -= 2; + else + if ( curpos ) + { + --curpos; + } + else + { + update = false; + beep = true; + } + + break; + + case KEY_RIGHT: + + if ( curpos == 1 || curpos == 4 ) + curpos += 2; + else + if ( curpos < maxCursor() ) + { + ++curpos; + } + else + { + update = false; + beep = true; + } + + break; + + case KEY_RETURN: + update = false; + + if ( notify() || returnOnReturn_b ) + ret = NCursesEvent::Activated; + + break; + + case KEY_HOTKEY: + update = false; + + break; + + default: + bool is_special = false; + + if ( key > 0xFFFF ) + { + is_special = true; + key -= 0xFFFF; + } + + if ( ( !is_special && KEY_MIN < key && KEY_MAX > key ) + || + !iswprint ( key ) ) + { + update = false; + beep = true; + } + else + { + { + switch ( key ) + { + case L'0': + case L'1': + case L'2': + case L'3': + case L'4': + case L'5': + case L'6': + case L'7': + case L'8': + case L'9': + { + std::string buf = NCstring(buffer).Str(); + buffer.erase ( curpos, 1 ); + buffer.insert ( std::wstring::size_type ( curpos ), 1, key ); + + if (validTime(NCstring(buffer).Str())) + { + if ( curpos == 1 || curpos == 4 ) + curpos += 2; + else if ( curpos < maxCursor() ) + ++curpos; + } + else + { + update = false; + setValue(buf); + beep = true; + } + } + break; + + default: + update = false; + beep = true; + break; + } + } + + } + + break; + } + + if ( update ) + { + tUpdate(); + + if ( notify() ) + ret = NCursesEvent::ValueChanged; + } + + if ( beep ) + ::beep(); + + return ret; + +} + + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-ncurses-2.46.8/src/NCTimeField.h new/libyui-ncurses-2.46.10/src/NCTimeField.h --- old/libyui-ncurses-2.46.8/src/NCTimeField.h 1970-01-01 01:00:00.000000000 +0100 +++ new/libyui-ncurses-2.46.10/src/NCTimeField.h 2015-02-18 14:50:10.000000000 +0100 @@ -0,0 +1,88 @@ +/* + Copyright (C) Angelo Naselli + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) version 3.0 of the License. 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 Lesser General Public + License for more details. You should have received a copy of the GNU + Lesser General Public License along with this library; if not, write + to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + Floor, Boston, MA 02110-1301 USA +*/ + + +/*-/ + + File: NCTimeField.h + + Author: Angelo Naselli <anaselli@linux.it> + +/-*/ + +#ifndef NCTimeField_h +#define NCTimeField_h + +#include <iosfwd> + +#include <yui/YTimeField.h> +#include "NCWidget.h" +#include "NCInputTextBase.h" + + +class NCTimeField : public YTimeField, public NCInputTextBase +{ + + friend std::ostream & operator<< ( std::ostream & STREAM, const NCTimeField & OBJ ); + + NCTimeField & operator= ( const NCTimeField & ); + NCTimeField ( const NCTimeField & ); + +private: + static const unsigned fieldLength; + + bool validTime(const std::string& input_time); + +protected: + + virtual const char * location() const + { + return "NCTimeField"; + } + +public: + + NCTimeField ( YWidget * parent, + const std::string & label + ); + virtual ~NCTimeField(); + + virtual int preferredWidth(); + virtual int preferredHeight(); + + virtual void setSize ( int newWidth, int newHeight ); + + virtual void setLabel ( const std::string & nlabel ); + + virtual void setValue ( const std::string & ntext ); + virtual std::string value(); + + virtual void setEnabled ( bool do_bv ); + + virtual NCursesEvent wHandleInput ( wint_t key ); + + virtual bool setKeyboardFocus() + { + if ( !grabFocus() ) + return YWidget::setKeyboardFocus(); + + return true; + } + +}; + + +#endif // NCTimeField_h diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-ncurses-2.46.8/src/ncursesw.cc new/libyui-ncurses-2.46.10/src/ncursesw.cc --- old/libyui-ncurses-2.46.8/src/ncursesw.cc 2014-02-21 11:37:26.000000000 +0100 +++ new/libyui-ncurses-2.46.10/src/ncursesw.cc 2015-02-04 11:15:13.000000000 +0100 @@ -377,7 +377,6 @@ static int r_init_idx = 0; static RIPOFFINIT* prip = R_INIT; -extern "C" int _nc_ripoffline( int, int ( *init )( WINDOW*, int ) ); NCursesWindow::NCursesWindow( WINDOW *win, int cols ) { @@ -405,7 +404,7 @@ int NCursesWindow::ripoffline( int ripoff_lines, int ( *init )( NCursesWindow& win ) ) { - int code = ::_nc_ripoffline( ripoff_lines, ripoff_init ); + int code = ::ripoffline( ripoff_lines, ripoff_init ); if ( code == OK && init && ripoff_lines ) { @@ -579,7 +578,6 @@ return OK; } - int NCursesWindow::setcolor( short pair ) { @@ -596,11 +594,9 @@ return OK; } -extern "C" int _nc_has_mouse( void ); - bool NCursesWindow::has_mouse() const { - return (( ::has_key( KEY_MOUSE ) || ::_nc_has_mouse() ) + return (( ::has_key( KEY_MOUSE ) || ::has_mouse() ) ? TRUE : FALSE ); } -- To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-commit+help@opensuse.org
participants (1)
-
root@hilbert.suse.de