Filter Library Camera Interface Physics

ControlIntegerEdit.h

00001 /*
00002  * ControlIntegerEdit.h - an integer entry field.
00003  *
00004  * This file is part of the Camera Filter Library.
00005  * Computer Aided Measurement Environment for Realtime Atomic imaging (Camera)
00006  *
00007  * Copyright (C) 2004, Leiden Probe Microscopy.
00008  * Copyright (C) 2004, Universiteit Leiden.
00009  *
00010  * Authors: Martin J. Moene (original)
00011  *
00012  * $Id: ControlIntegerEdit.h 202 2005-05-12 11:00:48Z moene $
00013  */
00014 
00015 #ifndef CFL_CONTROLINTEGEREDIT_H
00016 #define CFL_CONTROLINTEGEREDIT_H
00017 
00018 #if _MSC_VER > 1000
00019 #pragma once
00020 #endif // _MSC_VER > 1000
00021 
00022 #include <cfl/ControlFilterEdit.h>      // for base class CFilterEdit
00023 
00024 /**
00025  * \addtogroup cfl_controlnumedit Numeric Edit Control
00026  * \brief numeric edit control.
00027  *
00028  * @{
00029  */
00030 
00031 DECLARE_CLASS( CIntegerEdit );          // declare various types for class
00032 
00033 /**
00034  * Class CIntegerEdit is a text edit field for integer number entry and validation.
00035  *
00036  * Class CIntegerEdit provides the following facilities:
00037  * - accept signed or unsigned numbers (also settable in the constructor), SetSigned()
00038  * - accept base 10 numbers or determine the base from the leading zero (octal),
00039  *   determine it from the leading 0x (hexadecimal), or use base 10 in the absence
00040  *   of both (decimal), SetUseBase()
00041  * - obtain the current value, GetValue(), operator integer()
00042  * - specify a new value, SetValue(), operator=()
00043  * - specify the format to display the number in, SetFormat()
00044  */
00045 
00046 class CIntegerEdit : public CFilterEdit
00047 {
00048    DECLARE_DYNAMIC (CIntegerEdit)
00049 
00050    typedef CIntegerEdit self;           ///< this type
00051 
00052 public:
00053    typedef int integer;                 ///< the integer type
00054 
00055    ///
00056    /// \name Construction
00057    /// @{
00058 
00059    virtual ~CIntegerEdit();
00060    CIntegerEdit ( bool bSigned = true, bool bUseBase = false );
00061 
00062    /// @}
00063    /// \name Operators
00064    /// @{
00065 
00066    operator integer() const;
00067 
00068    self& operator= ( integer value );
00069 
00070    /// @}
00071    /// \name Predicates
00072    /// @{
00073 
00074    /// @}
00075    /// \name Accessors
00076    /// @{
00077 
00078    integer GetValue() const;
00079 
00080    /// @}
00081    /// \name Mutators
00082    /// @{
00083 
00084    void    SetValue  ( integer value );
00085 
00086    void    SetSigned ( bool bSigned  = true );
00087    void    SetUseBase( bool bUseBase = true );
00088    void    SetFormat ( const char* format = _T("%d") );
00089 
00090    /// @} 
00091 
00092 protected:
00093    virtual bool Check( const CString &csText ) ;
00094    virtual bool Match( const CString &csText ) ;
00095 
00096 private:
00097    bool    m_bSigned;                   ///< accept signed numbers
00098    bool    m_bUseBase;                  ///< determina base from leading 0[x]
00099    CString m_csFormat;                  ///< display format
00100 };
00101 
00102 /// @} cfl_controlnumedit
00103 
00104 /**
00105  * destructor.
00106  */
00107 
00108 inline CIntegerEdit::~CIntegerEdit()
00109 {
00110    ; // do nothing
00111 }
00112 
00113 /**
00114  * (default) constructor.
00115  */
00116 
00117 inline CIntegerEdit::CIntegerEdit( bool bSigned /* = true */, bool bUseBase /* = false */ ) :
00118    CFilterEdit(), m_bSigned( bSigned ),m_bUseBase( bUseBase ), m_csFormat( "%d" )
00119 {
00120    ; // do nothing
00121 }
00122 
00123 /**
00124  * convert to integer.
00125  */
00126 
00127 inline CIntegerEdit::operator CIntegerEdit::integer() const
00128 {
00129    return GetValue();
00130 }
00131 
00132 /**
00133  * assign integer value.
00134  */
00135 
00136 inline CIntegerEdit::self& CIntegerEdit::operator= ( integer value )
00137 {
00138    SetValue( value );
00139    return *this;
00140 }
00141 
00142 /**
00143  * get value.
00144  */
00145 
00146 inline CIntegerEdit::integer CIntegerEdit::GetValue() const
00147 {
00148    return _tcstol( c_str_ptr( *this ), NULL, m_bUseBase ? 0 : 10 );
00149 }
00150 
00151 /**
00152  * set integer value.
00153  */
00154 
00155 inline void CIntegerEdit::SetValue( integer value )
00156 {
00157    CString txt;
00158    txt.Format( m_csFormat, value );
00159    SetWindowText ( txt );
00160 }
00161 
00162 /**
00163  * set number to unsigned, signed (default).
00164  */
00165 
00166 inline void CIntegerEdit::SetSigned ( bool bSigned /* = true */ )
00167 {
00168    m_bSigned = bSigned;
00169 }
00170 
00171 /**
00172  * set number to use base (0, 0x) for conversion.
00173  */
00174 
00175 inline void CIntegerEdit::SetUseBase( bool bUseBase /* = true */  )
00176 {
00177    m_bUseBase = bUseBase;
00178 }
00179 
00180 
00181 /**
00182  * set the presentation format [\%d].
00183  */
00184 
00185 inline void CIntegerEdit::SetFormat( const char* format /* = "%d" */ )
00186 {
00187    m_csFormat = format;
00188 }
00189 
00190 #endif // CFL_CONTROLINTEGEREDIT_H
00191 
00192 /*
00193  * end of file
00194  */

Camera Filter Library documentation © 2004-2007 by Leiden Probe Microscopy