// flnuminput.cpp -- a subclass of Fl_Input // // Written by Frederic Bouvier, started March 2002. // // Copyright (C) 2002 Frederic Bouvier - fredb@users.sourceforge.net // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of the // License, or (at your option) any later version. // // This program 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 // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // // $Id: flnuminput.cpp,v 1.3 2004/02/14 14:17:38 fredb2 Exp $ #include #include #include "flnuminput.hpp" FGSD_NumInput::FGSD_NumInput(int x, int y, int w, int h, const char* l) : Fl_Input(x,y,w,h,l) , _type( _INT ) { } FGSD_NumInput::~FGSD_NumInput() { } bool FGSD_NumInput::replace(int b, int e, const char* text, int ilen) { bool ok = true; for ( int i = 0; ok && i < ilen; i++ ) { if ( !isdigit( text[ i ] ) && ( i != 0 || b != 0 || _type != _INT || text[ i ] != '-' ) ) ok = false; } if ( ok ) ok = Fl_Input::replace( b, e, text, ilen ); return ok; } void FGSD_NumInput::int_value( int v ) { _type = _INT; std::ostringstream str; str << v; value( str.str().c_str() ); } int FGSD_NumInput::int_value() const { int ret = 0; if ( _type == _INT ) { std::istringstream str( value() ); str >> ret; } return ret; } void FGSD_NumInput::uint_value( unsigned int v ) { _type = _UINT; std::ostringstream str; str << v; value( str.str().c_str() ); } unsigned int FGSD_NumInput::uint_value() const { unsigned int ret = 0; if ( _type == _UINT ) { std::istringstream str( value() ); str >> ret; } return ret; }