2011-01-19 10:48:28 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/valnum.h
|
|
|
|
// Purpose: Numeric validator classes.
|
|
|
|
// Author: Vadim Zeitlin based on the submission of Fulvio Senore
|
|
|
|
// Created: 2010-11-06
|
|
|
|
// Copyright: (c) 2010 wxWidgets team
|
|
|
|
// (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_VALNUM_H_
|
|
|
|
#define _WX_VALNUM_H_
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
#if wxUSE_VALIDATORS
|
|
|
|
|
2016-12-09 00:58:14 +00:00
|
|
|
#include "wx/textentry.h"
|
2011-01-19 10:48:28 +00:00
|
|
|
#include "wx/validate.h"
|
|
|
|
|
2017-12-26 03:29:42 +00:00
|
|
|
// This header uses std::numeric_limits<>::min/max, but these symbols are,
|
|
|
|
// unfortunately, often defined as macros and the code here wouldn't compile in
|
|
|
|
// this case, so preventively undefine them to avoid this problem.
|
|
|
|
#undef min
|
|
|
|
#undef max
|
|
|
|
|
2011-01-19 10:48:28 +00:00
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
// Bit masks used for numeric validator styles.
|
|
|
|
enum wxNumValidatorStyle
|
|
|
|
{
|
|
|
|
wxNUM_VAL_DEFAULT = 0x0,
|
|
|
|
wxNUM_VAL_THOUSANDS_SEPARATOR = 0x1,
|
|
|
|
wxNUM_VAL_ZERO_AS_BLANK = 0x2,
|
|
|
|
wxNUM_VAL_NO_TRAILING_ZEROES = 0x4
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Base class for all numeric validators.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_CORE wxNumValidatorBase : public wxValidator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Change the validator style. Usually it's specified during construction.
|
|
|
|
void SetStyle(int style) { m_style = style; }
|
|
|
|
|
|
|
|
|
|
|
|
// Override base class method to not do anything but always return success:
|
|
|
|
// we don't need this as we do our validation on the fly here.
|
2015-09-07 00:20:42 +00:00
|
|
|
virtual bool Validate(wxWindow * WXUNUSED(parent)) wxOVERRIDE { return true; }
|
2011-01-19 10:48:28 +00:00
|
|
|
|
2018-01-07 00:26:53 +00:00
|
|
|
// Override base class method to check that the window is a text control or
|
|
|
|
// combobox.
|
|
|
|
virtual void SetWindow(wxWindow *win) wxOVERRIDE;
|
|
|
|
|
2011-01-19 10:48:28 +00:00
|
|
|
protected:
|
|
|
|
wxNumValidatorBase(int style)
|
|
|
|
{
|
|
|
|
m_style = style;
|
|
|
|
}
|
|
|
|
|
2018-01-04 20:39:57 +00:00
|
|
|
wxNumValidatorBase(const wxNumValidatorBase& other) : wxValidator(other)
|
2011-01-19 10:48:28 +00:00
|
|
|
{
|
|
|
|
m_style = other.m_style;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasFlag(wxNumValidatorStyle style) const
|
|
|
|
{
|
|
|
|
return (m_style & style) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the text entry of the associated control. Normally shouldn't ever
|
|
|
|
// return NULL (and will assert if it does return it) but the caller should
|
|
|
|
// still test the return value for safety.
|
|
|
|
wxTextEntry *GetTextEntry() const;
|
|
|
|
|
|
|
|
// Convert wxNUM_VAL_THOUSANDS_SEPARATOR and wxNUM_VAL_NO_TRAILING_ZEROES
|
|
|
|
// bits of our style to the corresponding wxNumberFormatter::Style values.
|
|
|
|
int GetFormatFlags() const;
|
|
|
|
|
|
|
|
// Return true if pressing a '-' key is acceptable for the current control
|
|
|
|
// contents and insertion point. This is meant to be called from the
|
|
|
|
// derived class IsCharOk() implementation.
|
|
|
|
bool IsMinusOk(const wxString& val, int pos) const;
|
|
|
|
|
|
|
|
// Return the string which would result from inserting the given character
|
|
|
|
// at the specified position.
|
|
|
|
wxString GetValueAfterInsertingChar(wxString val, int pos, wxChar ch) const
|
|
|
|
{
|
|
|
|
val.insert(pos, ch);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Check whether the specified character can be inserted in the control at
|
|
|
|
// the given position in the string representing the current controls
|
|
|
|
// contents.
|
|
|
|
//
|
|
|
|
// Notice that the base class checks for '-' itself so it's never passed to
|
|
|
|
// this function.
|
|
|
|
virtual bool IsCharOk(const wxString& val, int pos, wxChar ch) const = 0;
|
|
|
|
|
|
|
|
// NormalizeString the contents of the string if it's a valid number, return
|
|
|
|
// empty string otherwise.
|
|
|
|
virtual wxString NormalizeString(const wxString& s) const = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// Event handlers.
|
|
|
|
void OnChar(wxKeyEvent& event);
|
|
|
|
void OnKillFocus(wxFocusEvent& event);
|
|
|
|
|
|
|
|
|
|
|
|
// Determine the current insertion point and text in the associated control.
|
|
|
|
void GetCurrentValueAndInsertionPoint(wxString& val, int& pos) const;
|
|
|
|
|
|
|
|
|
|
|
|
// Combination of wxVAL_NUM_XXX values.
|
|
|
|
int m_style;
|
|
|
|
|
|
|
|
|
|
|
|
wxDECLARE_EVENT_TABLE();
|
|
|
|
|
|
|
|
wxDECLARE_NO_ASSIGN_CLASS(wxNumValidatorBase);
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace wxPrivate
|
|
|
|
{
|
|
|
|
|
|
|
|
// This is a helper class used by wxIntegerValidator and wxFloatingPointValidator
|
|
|
|
// below that implements Transfer{To,From}Window() adapted to the type of the
|
|
|
|
// variable.
|
|
|
|
//
|
|
|
|
// The template argument B is the name of the base class which must derive from
|
|
|
|
// wxNumValidatorBase and define LongestValueType type and {To,As}String()
|
|
|
|
// methods i.e. basically be one of wx{Integer,Number}ValidatorBase classes.
|
|
|
|
//
|
|
|
|
// The template argument T is just the type handled by the validator that will
|
|
|
|
// inherit from this one.
|
|
|
|
template <class B, typename T>
|
|
|
|
class wxNumValidator : public B
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef B BaseValidator;
|
|
|
|
typedef T ValueType;
|
|
|
|
|
|
|
|
typedef typename BaseValidator::LongestValueType LongestValueType;
|
|
|
|
|
|
|
|
wxCOMPILE_TIME_ASSERT
|
|
|
|
(
|
|
|
|
sizeof(ValueType) <= sizeof(LongestValueType),
|
|
|
|
UnsupportedType
|
|
|
|
);
|
|
|
|
|
|
|
|
void SetMin(ValueType min)
|
|
|
|
{
|
|
|
|
this->DoSetMin(min);
|
|
|
|
}
|
|
|
|
|
2019-04-10 12:31:46 +00:00
|
|
|
ValueType GetMin() const
|
|
|
|
{
|
|
|
|
return static_cast<ValueType>(this->DoGetMin());
|
|
|
|
}
|
|
|
|
|
2011-01-19 10:48:28 +00:00
|
|
|
void SetMax(ValueType max)
|
|
|
|
{
|
|
|
|
this->DoSetMax(max);
|
|
|
|
}
|
|
|
|
|
2019-04-10 12:31:46 +00:00
|
|
|
ValueType GetMax() const
|
|
|
|
{
|
|
|
|
return static_cast<ValueType>(this->DoGetMax());
|
|
|
|
}
|
|
|
|
|
2011-01-19 10:48:28 +00:00
|
|
|
void SetRange(ValueType min, ValueType max)
|
|
|
|
{
|
|
|
|
SetMin(min);
|
|
|
|
SetMax(max);
|
|
|
|
}
|
|
|
|
|
2019-04-10 12:31:46 +00:00
|
|
|
void GetRange(ValueType& min, ValueType& max) const
|
|
|
|
{
|
|
|
|
min = GetMin();
|
|
|
|
max = GetMax();
|
|
|
|
}
|
|
|
|
|
2016-09-25 20:21:28 +00:00
|
|
|
virtual bool TransferToWindow() wxOVERRIDE
|
2011-01-19 10:48:28 +00:00
|
|
|
{
|
|
|
|
if ( m_value )
|
|
|
|
{
|
|
|
|
wxTextEntry * const control = BaseValidator::GetTextEntry();
|
|
|
|
if ( !control )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
control->SetValue(NormalizeValue(*m_value));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-25 20:21:28 +00:00
|
|
|
virtual bool TransferFromWindow() wxOVERRIDE
|
2011-01-19 10:48:28 +00:00
|
|
|
{
|
|
|
|
if ( m_value )
|
|
|
|
{
|
|
|
|
wxTextEntry * const control = BaseValidator::GetTextEntry();
|
|
|
|
if ( !control )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const wxString s(control->GetValue());
|
|
|
|
LongestValueType value;
|
|
|
|
if ( s.empty() && BaseValidator::HasFlag(wxNUM_VAL_ZERO_AS_BLANK) )
|
|
|
|
value = 0;
|
|
|
|
else if ( !BaseValidator::FromString(s, &value) )
|
|
|
|
return false;
|
|
|
|
|
2011-01-27 11:00:26 +00:00
|
|
|
if ( !this->IsInRange(value) )
|
2011-01-19 10:48:28 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
*m_value = static_cast<ValueType>(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
wxNumValidator(ValueType *value, int style)
|
|
|
|
: BaseValidator(style),
|
|
|
|
m_value(value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implement wxNumValidatorBase virtual method which is the same for
|
|
|
|
// both integer and floating point numbers.
|
2016-09-25 20:21:28 +00:00
|
|
|
virtual wxString NormalizeString(const wxString& s) const wxOVERRIDE
|
2011-01-19 10:48:28 +00:00
|
|
|
{
|
|
|
|
LongestValueType value;
|
|
|
|
return BaseValidator::FromString(s, &value) ? NormalizeValue(value)
|
|
|
|
: wxString();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Just a helper which is a common part of TransferToWindow() and
|
|
|
|
// NormalizeString(): returns string representation of a number honouring
|
|
|
|
// wxNUM_VAL_ZERO_AS_BLANK flag.
|
|
|
|
wxString NormalizeValue(LongestValueType value) const
|
|
|
|
{
|
2018-11-20 13:11:53 +00:00
|
|
|
// We really want to compare with the exact 0 here, so disable gcc
|
|
|
|
// warning about doing this.
|
|
|
|
wxGCC_WARNING_SUPPRESS(float-equal)
|
|
|
|
|
2011-01-19 10:48:28 +00:00
|
|
|
wxString s;
|
|
|
|
if ( value != 0 || !BaseValidator::HasFlag(wxNUM_VAL_ZERO_AS_BLANK) )
|
2011-01-27 11:00:26 +00:00
|
|
|
s = this->ToString(value);
|
2011-01-19 10:48:28 +00:00
|
|
|
|
2018-11-20 13:11:53 +00:00
|
|
|
wxGCC_WARNING_RESTORE(float-equal)
|
|
|
|
|
2011-01-19 10:48:28 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ValueType * const m_value;
|
|
|
|
|
|
|
|
wxDECLARE_NO_ASSIGN_CLASS(wxNumValidator);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace wxPrivate
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Validators for integer numbers.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Base class for integer numbers validator. This class contains all non
|
|
|
|
// type-dependent code of wxIntegerValidator<> and always works with values of
|
|
|
|
// type LongestValueType. It is not meant to be used directly, please use
|
|
|
|
// wxIntegerValidator<> only instead.
|
|
|
|
class WXDLLIMPEXP_CORE wxIntegerValidatorBase : public wxNumValidatorBase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
// Define the type we use here, it should be the maximal-sized integer type
|
|
|
|
// we support to make it possible to base wxIntegerValidator<> for any type
|
|
|
|
// on it.
|
|
|
|
#ifdef wxLongLong_t
|
|
|
|
typedef wxLongLong_t LongestValueType;
|
|
|
|
#else
|
|
|
|
typedef long LongestValueType;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
wxIntegerValidatorBase(int style)
|
|
|
|
: wxNumValidatorBase(style)
|
|
|
|
{
|
|
|
|
wxASSERT_MSG( !(style & wxNUM_VAL_NO_TRAILING_ZEROES),
|
|
|
|
"This style doesn't make sense for integers." );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxIntegerValidatorBase(const wxIntegerValidatorBase& other)
|
|
|
|
: wxNumValidatorBase(other)
|
|
|
|
{
|
|
|
|
m_min = other.m_min;
|
|
|
|
m_max = other.m_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Provide methods for wxNumValidator use.
|
|
|
|
wxString ToString(LongestValueType value) const;
|
|
|
|
static bool FromString(const wxString& s, LongestValueType *value);
|
|
|
|
|
|
|
|
void DoSetMin(LongestValueType min) { m_min = min; }
|
2019-04-10 12:31:46 +00:00
|
|
|
LongestValueType DoGetMin() const { return m_min; }
|
2011-01-19 10:48:28 +00:00
|
|
|
void DoSetMax(LongestValueType max) { m_max = max; }
|
2019-04-10 12:31:46 +00:00
|
|
|
LongestValueType DoGetMax() const { return m_max; }
|
2011-01-19 10:48:28 +00:00
|
|
|
|
|
|
|
bool IsInRange(LongestValueType value) const
|
|
|
|
{
|
|
|
|
return m_min <= value && value <= m_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implement wxNumValidatorBase pure virtual method.
|
2015-09-07 00:20:42 +00:00
|
|
|
virtual bool IsCharOk(const wxString& val, int pos, wxChar ch) const wxOVERRIDE;
|
2011-01-19 10:48:28 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Minimal and maximal values accepted (inclusive).
|
|
|
|
LongestValueType m_min, m_max;
|
|
|
|
|
|
|
|
wxDECLARE_NO_ASSIGN_CLASS(wxIntegerValidatorBase);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Validator for integer numbers. It can actually work with any integer type
|
|
|
|
// (short, int or long and long long if supported) and their unsigned versions
|
|
|
|
// as well.
|
|
|
|
template <typename T>
|
|
|
|
class wxIntegerValidator
|
|
|
|
: public wxPrivate::wxNumValidator<wxIntegerValidatorBase, T>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef T ValueType;
|
|
|
|
|
|
|
|
typedef
|
|
|
|
wxPrivate::wxNumValidator<wxIntegerValidatorBase, T> Base;
|
|
|
|
|
|
|
|
// Ctor for an integer validator.
|
|
|
|
//
|
|
|
|
// Sets the range appropriately for the type, including setting 0 as the
|
|
|
|
// minimal value for the unsigned types.
|
|
|
|
wxIntegerValidator(ValueType *value = NULL, int style = wxNUM_VAL_DEFAULT)
|
|
|
|
: Base(value, style)
|
|
|
|
{
|
2011-01-27 11:00:26 +00:00
|
|
|
this->DoSetMin(std::numeric_limits<ValueType>::min());
|
|
|
|
this->DoSetMax(std::numeric_limits<ValueType>::max());
|
2011-01-19 10:48:28 +00:00
|
|
|
}
|
|
|
|
|
2016-09-25 20:21:28 +00:00
|
|
|
virtual wxObject *Clone() const wxOVERRIDE { return new wxIntegerValidator(*this); }
|
2011-01-19 10:48:28 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
wxDECLARE_NO_ASSIGN_CLASS(wxIntegerValidator);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Helper function for creating integer validators which allows to avoid
|
|
|
|
// explicitly specifying the type as it deduces it from its parameter.
|
|
|
|
template <typename T>
|
|
|
|
inline wxIntegerValidator<T>
|
|
|
|
wxMakeIntegerValidator(T *value, int style = wxNUM_VAL_DEFAULT)
|
|
|
|
{
|
|
|
|
return wxIntegerValidator<T>(value, style);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Validators for floating point numbers.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Similar to wxIntegerValidatorBase, this class is not meant to be used
|
|
|
|
// directly, only wxFloatingPointValidator<> should be used in the user code.
|
|
|
|
class WXDLLIMPEXP_CORE wxFloatingPointValidatorBase : public wxNumValidatorBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Set precision i.e. the number of digits shown (and accepted on input)
|
|
|
|
// after the decimal point. By default this is set to the maximal precision
|
|
|
|
// supported by the type handled by the validator.
|
|
|
|
void SetPrecision(unsigned precision) { m_precision = precision; }
|
|
|
|
|
2018-01-25 18:30:39 +00:00
|
|
|
// Set multiplier applied for displaying the value, e.g. 100 if the value
|
|
|
|
// should be displayed in percents, so that the variable containing 0.5
|
|
|
|
// would be displayed as 50.
|
|
|
|
void SetFactor(double factor) { m_factor = factor; }
|
|
|
|
|
2011-01-19 10:48:28 +00:00
|
|
|
protected:
|
|
|
|
// Notice that we can't use "long double" here because it's not supported
|
|
|
|
// by wxNumberFormatter yet, so restrict ourselves to just double (and
|
|
|
|
// float).
|
|
|
|
typedef double LongestValueType;
|
|
|
|
|
|
|
|
wxFloatingPointValidatorBase(int style)
|
|
|
|
: wxNumValidatorBase(style)
|
|
|
|
{
|
2018-01-25 18:30:39 +00:00
|
|
|
m_factor = 1.0;
|
2011-01-19 10:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxFloatingPointValidatorBase(const wxFloatingPointValidatorBase& other)
|
|
|
|
: wxNumValidatorBase(other)
|
|
|
|
{
|
|
|
|
m_precision = other.m_precision;
|
2018-01-25 18:30:39 +00:00
|
|
|
m_factor = other.m_factor;
|
2011-01-19 10:48:28 +00:00
|
|
|
|
|
|
|
m_min = other.m_min;
|
|
|
|
m_max = other.m_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Provide methods for wxNumValidator use.
|
|
|
|
wxString ToString(LongestValueType value) const;
|
2018-01-25 18:30:39 +00:00
|
|
|
bool FromString(const wxString& s, LongestValueType *value) const;
|
2011-01-19 10:48:28 +00:00
|
|
|
|
|
|
|
void DoSetMin(LongestValueType min) { m_min = min; }
|
2019-04-10 12:31:46 +00:00
|
|
|
LongestValueType DoGetMin() const { return m_min; }
|
2011-01-19 10:48:28 +00:00
|
|
|
void DoSetMax(LongestValueType max) { m_max = max; }
|
2019-04-10 12:31:46 +00:00
|
|
|
LongestValueType DoGetMax() const { return m_max; }
|
2011-01-19 10:48:28 +00:00
|
|
|
|
|
|
|
bool IsInRange(LongestValueType value) const
|
|
|
|
{
|
|
|
|
return m_min <= value && value <= m_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implement wxNumValidatorBase pure virtual method.
|
2015-09-07 00:20:42 +00:00
|
|
|
virtual bool IsCharOk(const wxString& val, int pos, wxChar ch) const wxOVERRIDE;
|
2011-01-19 10:48:28 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Maximum number of decimals digits after the decimal separator.
|
|
|
|
unsigned m_precision;
|
|
|
|
|
2018-01-25 18:30:39 +00:00
|
|
|
// Factor applied for the displayed the value.
|
|
|
|
double m_factor;
|
|
|
|
|
2011-01-19 10:48:28 +00:00
|
|
|
// Minimal and maximal values accepted (inclusive).
|
|
|
|
LongestValueType m_min, m_max;
|
|
|
|
|
|
|
|
wxDECLARE_NO_ASSIGN_CLASS(wxFloatingPointValidatorBase);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Validator for floating point numbers. It can be used with float, double or
|
|
|
|
// long double values.
|
|
|
|
template <typename T>
|
|
|
|
class wxFloatingPointValidator
|
|
|
|
: public wxPrivate::wxNumValidator<wxFloatingPointValidatorBase, T>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef T ValueType;
|
|
|
|
typedef wxPrivate::wxNumValidator<wxFloatingPointValidatorBase, T> Base;
|
|
|
|
|
|
|
|
// Ctor using implicit (maximal) precision for this type.
|
|
|
|
wxFloatingPointValidator(ValueType *value = NULL,
|
|
|
|
int style = wxNUM_VAL_DEFAULT)
|
|
|
|
: Base(value, style)
|
|
|
|
{
|
|
|
|
DoSetMinMax();
|
|
|
|
|
2011-01-27 17:15:40 +00:00
|
|
|
this->SetPrecision(std::numeric_limits<ValueType>::digits10);
|
2011-01-19 10:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ctor specifying an explicit precision.
|
|
|
|
wxFloatingPointValidator(int precision,
|
|
|
|
ValueType *value = NULL,
|
|
|
|
int style = wxNUM_VAL_DEFAULT)
|
|
|
|
: Base(value, style)
|
|
|
|
{
|
|
|
|
DoSetMinMax();
|
|
|
|
|
|
|
|
this->SetPrecision(precision);
|
|
|
|
}
|
|
|
|
|
2016-09-25 20:21:28 +00:00
|
|
|
virtual wxObject *Clone() const wxOVERRIDE
|
2011-01-19 10:48:28 +00:00
|
|
|
{
|
|
|
|
return new wxFloatingPointValidator(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void DoSetMinMax()
|
|
|
|
{
|
|
|
|
// NB: Do not use min(), it's not the smallest representable value for
|
|
|
|
// the floating point types but rather the smallest representable
|
|
|
|
// positive value.
|
2011-01-27 11:00:26 +00:00
|
|
|
this->DoSetMin(-std::numeric_limits<ValueType>::max());
|
|
|
|
this->DoSetMax( std::numeric_limits<ValueType>::max());
|
2011-01-19 10:48:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Helper similar to wxMakeIntValidator().
|
|
|
|
//
|
|
|
|
// NB: Unfortunately we can't just have a wxMakeNumericValidator() which would
|
|
|
|
// return either wxIntegerValidator<> or wxFloatingPointValidator<> so we
|
|
|
|
// do need two different functions.
|
|
|
|
template <typename T>
|
|
|
|
inline wxFloatingPointValidator<T>
|
|
|
|
wxMakeFloatingPointValidator(T *value, int style = wxNUM_VAL_DEFAULT)
|
|
|
|
{
|
|
|
|
return wxFloatingPointValidator<T>(value, style);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline wxFloatingPointValidator<T>
|
|
|
|
wxMakeFloatingPointValidator(int precision, T *value, int style = wxNUM_VAL_DEFAULT)
|
|
|
|
{
|
|
|
|
return wxFloatingPointValidator<T>(precision, value, style);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // wxUSE_VALIDATORS
|
|
|
|
|
|
|
|
#endif // _WX_VALNUM_H_
|