Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pgpropertyfield_integer.h

Go to the documentation of this file.
00001 /*
00002     ParaGUI - crossplatform widgetset
00003     Copyright (C) 2000,2001,2002  Alexander Pipelka
00004  
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009  
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014  
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  
00019     Alexander Pipelka
00020     pipelka@teleweb.at
00021  
00022     Last Update:      $Author: mbickel $
00023     Update Date:      $Date: 2007-04-13 16:15:57 $
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/include/pgpropertyfield_integer.h,v $
00025     CVS/RCS Revision: $Revision: 1.2 $
00026     Status:           $State: Exp $
00027 */
00028 
00029 #ifndef PG_PROPERTYFIELD_INTEGER_H
00030 #define PG_PROPERTYFIELD_INTEGER_H
00031 
00032 #include <sstream>
00033 #include <limits>
00034 
00035 #include "pgpropertyeditor_linefield.h"
00036 
00037 
00043 template <class IntegerType=int>
00044 class PG_PropertyField_Integer : public PG_PropertyEditor_LineField {
00045         IntegerType* myProperty;
00046         IntegerType minValue;
00047         IntegerType maxValue;
00048 protected:
00049         bool convert( IntegerType& i ) {
00050                 std::istringstream s( lineEdit->GetText() );
00051                 if ( !( s >> i ))
00052                         return false;
00053 
00054                 return s.eof();
00055         };
00056 
00057         void set
00058                 ( IntegerType i ) {
00059                 std::ostringstream s;
00060                 s << i;
00061                 lineEdit->SetText( s.str() );
00062         }
00063 
00064         bool EditEnd() {
00065                 IntegerType i ;
00066                 if ( convert(i)) {
00067                         sigValueChanged(this,i);
00068                         return true;
00069                 } else
00070                         return false;
00071         }
00072 
00073 public:
00074 
00075         typedef PG_Signal2<PG_PropertyField_Integer*, IntegerType> IntegerPropertySignal;
00076         IntegerPropertySignal sigValueChanged;
00077         IntegerPropertySignal sigValueApplied;
00078 
00084         PG_PropertyField_Integer( PG_PropertyEditor* propertyEditor, const std::string& name, IntegerType* myInteger ) : PG_PropertyEditor_LineField( propertyEditor, name ), myProperty( myInteger ) {
00085                 minValue = std::numeric_limits<IntegerType>::min();
00086                 maxValue = std::numeric_limits<IntegerType>::max();
00087                 Reload();
00088         };
00089 
00095         PG_PropertyField_Integer( PG_PropertyEditor* propertyEditor, const std::string& name, IntegerType myInteger ) : PG_PropertyEditor_LineField( propertyEditor, name ), myProperty( NULL ) {
00096                 minValue = std::numeric_limits<IntegerType>::min();
00097                 maxValue = std::numeric_limits<IntegerType>::max();
00098                 set
00099                         ( myInteger );
00100         };
00101 
00102         void SetRange( IntegerType min, IntegerType max ) {
00103                 if ( min <= max ) {
00104                         minValue = min;
00105                         maxValue = max;
00106                 }
00107         }
00108 
00109         virtual bool CheckValue( IntegerType value ) {
00110                 return value >= minValue && value <= maxValue;
00111         }
00112 
00113         bool Valid() {
00114                 IntegerType i;
00115                 if ( !convert(i) )
00116                         return false;
00117 
00118                 if ( !CheckValue( i ))
00119                         return false;
00120 
00121                 return true;
00122         };
00123 
00124         bool Apply() {
00125                 IntegerType i;
00126                 if ( !convert(i) )
00127                         return false;
00128 
00129                 if ( !CheckValue( i ))
00130                         return false;
00131 
00132                 sigValueApplied( this, i );
00133 
00134                 if ( myProperty )
00135                         *myProperty = i;
00136 
00137                 return true;
00138         };
00139 
00140         void Reload() {
00141                 if ( myProperty )
00142                         set
00143                                 ( *myProperty );
00144         };
00145 
00146 };
00147 
00148 #endif

Generated on Tue Jun 24 01:27:49 2008 for Advanced Strategic Command by  doxygen 1.4.2