mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-16 08:34:10 +02:00
Fix a conflict between the backported number validator and formatter
When building for wx3 on Linux, the backported number validators and formatter conflicts with the wx3 version because I never renamed them. Crashes during termination would occur because the wx3 version and our version had different vtables. I was thinking that we would just be able to delete the backported version when upgrading to wx3, but since we've made Audacity specific changes to them we can't simply start using the real wx3 versions anymore. Therefore, I needed to rename then to prevent the crashes.
This commit is contained in:
parent
22d3719db5
commit
4e8b794452
@ -786,7 +786,7 @@ void VSTEffectOptionsDialog::PopulateOrExchange(ShuttleGui & S)
|
|||||||
{
|
{
|
||||||
S.StartStatic(_("Buffer Size"));
|
S.StartStatic(_("Buffer Size"));
|
||||||
{
|
{
|
||||||
wxIntegerValidator<int> vld(&mBufferSize);
|
IntegerValidator<int> vld(&mBufferSize);
|
||||||
vld.SetRange(8, 1048576 * 1);
|
vld.SetRange(8, 1048576 * 1);
|
||||||
|
|
||||||
S.AddVariableText(wxString() +
|
S.AddVariableText(wxString() +
|
||||||
|
@ -1279,7 +1279,7 @@ bool LadspaEffect::PopulateUI(wxWindow *parent)
|
|||||||
{
|
{
|
||||||
fieldText.Printf(wxT("%d"), (int)(mInputControls[p] + 0.5));
|
fieldText.Printf(wxT("%d"), (int)(mInputControls[p] + 0.5));
|
||||||
|
|
||||||
wxIntegerValidator<float> vld(&mInputControls[p]);
|
IntegerValidator<float> vld(&mInputControls[p]);
|
||||||
vld.SetRange(haslo ? lower : INT_MIN,
|
vld.SetRange(haslo ? lower : INT_MIN,
|
||||||
hashi ? upper : INT_MAX);
|
hashi ? upper : INT_MAX);
|
||||||
mFields[p]->SetValidator(vld);
|
mFields[p]->SetValidator(vld);
|
||||||
@ -1289,21 +1289,21 @@ bool LadspaEffect::PopulateUI(wxWindow *parent)
|
|||||||
fieldText = Internat::ToDisplayString(mInputControls[p]);
|
fieldText = Internat::ToDisplayString(mInputControls[p]);
|
||||||
|
|
||||||
// > 12 decimal places can cause rounding errors in display.
|
// > 12 decimal places can cause rounding errors in display.
|
||||||
wxFloatingPointValidator<float> vld(6, &mInputControls[p]);
|
FloatingPointValidator<float> vld(6, &mInputControls[p]);
|
||||||
vld.SetRange(lower, upper);
|
vld.SetRange(lower, upper);
|
||||||
|
|
||||||
// Set number of decimal places
|
// Set number of decimal places
|
||||||
if (upper - lower < 10.0)
|
if (upper - lower < 10.0)
|
||||||
{
|
{
|
||||||
vld.SetStyle(wxNUM_VAL_THREE_TRAILING_ZEROES);
|
vld.SetStyle(NUM_VAL_THREE_TRAILING_ZEROES);
|
||||||
}
|
}
|
||||||
else if (upper - lower < 100.0)
|
else if (upper - lower < 100.0)
|
||||||
{
|
{
|
||||||
vld.SetStyle(wxNUM_VAL_TWO_TRAILING_ZEROES);
|
vld.SetStyle(NUM_VAL_TWO_TRAILING_ZEROES);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vld.SetStyle(wxNUM_VAL_ONE_TRAILING_ZERO);
|
vld.SetStyle(NUM_VAL_ONE_TRAILING_ZERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
mFields[p]->SetValidator(vld);
|
mFields[p]->SetValidator(vld);
|
||||||
|
@ -1749,20 +1749,20 @@ NyquistDialog::NyquistDialog(wxWindow * parent, wxWindowID id,
|
|||||||
item->SetName(ctrl->name);
|
item->SetName(ctrl->name);
|
||||||
if (ctrl->type == NYQ_CTRL_REAL) {
|
if (ctrl->type == NYQ_CTRL_REAL) {
|
||||||
// > 12 decimal places can cause rounding errors in display.
|
// > 12 decimal places can cause rounding errors in display.
|
||||||
wxFloatingPointValidator<double> vld(12, &ctrl->val);
|
FloatingPointValidator<double> vld(12, &ctrl->val);
|
||||||
vld.SetRange(-FLT_MAX, FLT_MAX);
|
vld.SetRange(-FLT_MAX, FLT_MAX);
|
||||||
// Set number of decimal places
|
// Set number of decimal places
|
||||||
if (ctrl->high - ctrl->low < 10) {
|
if (ctrl->high - ctrl->low < 10) {
|
||||||
vld.SetStyle(wxNUM_VAL_THREE_TRAILING_ZEROES);
|
vld.SetStyle(NUM_VAL_THREE_TRAILING_ZEROES);
|
||||||
} else if (ctrl->high - ctrl->low < 100) {
|
} else if (ctrl->high - ctrl->low < 100) {
|
||||||
vld.SetStyle(wxNUM_VAL_TWO_TRAILING_ZEROES);
|
vld.SetStyle(NUM_VAL_TWO_TRAILING_ZEROES);
|
||||||
} else {
|
} else {
|
||||||
vld.SetStyle(wxNUM_VAL_ONE_TRAILING_ZERO);
|
vld.SetStyle(NUM_VAL_ONE_TRAILING_ZERO);
|
||||||
}
|
}
|
||||||
item->SetValidator(vld);
|
item->SetValidator(vld);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
wxIntegerValidator<double> vld(&ctrl->val);
|
IntegerValidator<double> vld(&ctrl->val);
|
||||||
vld.SetRange(INT_MIN, INT_MAX);
|
vld.SetRange(INT_MIN, INT_MAX);
|
||||||
item->SetValidator(vld);
|
item->SetValidator(vld);
|
||||||
}
|
}
|
||||||
|
@ -1914,7 +1914,7 @@ void Meter::OnPreferences(wxCommandEvent & WXUNUSED(event))
|
|||||||
wxString::Format(wxT("%d"), meterRefreshRate),
|
wxString::Format(wxT("%d"), meterRefreshRate),
|
||||||
10);
|
10);
|
||||||
rate->SetName(_("Meter refresh rate per second [1-100]"));
|
rate->SetName(_("Meter refresh rate per second [1-100]"));
|
||||||
wxIntegerValidator<long> vld(&mMeterRefreshRate);
|
IntegerValidator<long> vld(&mMeterRefreshRate);
|
||||||
vld.SetRange(0, 100);
|
vld.SetRange(0, 100);
|
||||||
rate->SetValidator(vld);
|
rate->SetValidator(vld);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
//
|
//
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: src/common/numformatter.cpp
|
// Name: src/common/numformatter.cpp
|
||||||
// Purpose: wxNumberFormatter
|
// Purpose: NumberFormatter
|
||||||
// Author: Fulvio Senore, Vadim Zeitlin
|
// Author: Fulvio Senore, Vadim Zeitlin
|
||||||
// Created: 2010-11-06
|
// Created: 2010-11-06
|
||||||
// Copyright: (c) 2010 wxWidgets team
|
// Copyright: (c) 2010 wxWidgets team
|
||||||
@ -16,20 +16,20 @@
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
// For compilers that support precompilation, includes "wx.h".
|
// For compilers that support precompilation, includes "wx.h".
|
||||||
#include "wx/wxprec.h"
|
#include <wx/wxprec.h>
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
#pragma hdrstop
|
#pragma hdrstop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __WIN32__
|
#ifdef __WIN32__
|
||||||
#include "wx/msw/private.h"
|
#include <wx/msw/private.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "numformatter.h"
|
#include "numformatter.h"
|
||||||
#include "wx/intl.h"
|
#include <wx/intl.h>
|
||||||
|
|
||||||
#include <locale.h> // for setlocale and LC_ALL
|
#include <locale.h> // for setlocale and LC_ALL
|
||||||
#include <wx/log.h>
|
#include <wx/log.h>
|
||||||
@ -110,14 +110,14 @@ private:
|
|||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// wxNumberFormatter implementation
|
// NumberFormatter implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Locale information accessors
|
// Locale information accessors
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxChar wxNumberFormatter::GetDecimalSeparator()
|
wxChar NumberFormatter::GetDecimalSeparator()
|
||||||
{
|
{
|
||||||
#if wxUSE_INTL
|
#if wxUSE_INTL
|
||||||
// Notice that while using static variable here is not MT-safe, the worst
|
// Notice that while using static variable here is not MT-safe, the worst
|
||||||
@ -155,7 +155,7 @@ wxChar wxNumberFormatter::GetDecimalSeparator()
|
|||||||
#endif // wxUSE_INTL/!wxUSE_INTL
|
#endif // wxUSE_INTL/!wxUSE_INTL
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxNumberFormatter::GetThousandsSeparatorIfUsed(wxChar *sep)
|
bool NumberFormatter::GetThousandsSeparatorIfUsed(wxChar *sep)
|
||||||
{
|
{
|
||||||
#if wxUSE_INTL
|
#if wxUSE_INTL
|
||||||
static wxChar s_thousandsSeparator = 0;
|
static wxChar s_thousandsSeparator = 0;
|
||||||
@ -216,7 +216,7 @@ bool wxNumberFormatter::GetThousandsSeparatorIfUsed(wxChar *sep)
|
|||||||
// Conversion to string and helpers
|
// Conversion to string and helpers
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxString wxNumberFormatter::PostProcessIntString(wxString s, int style)
|
wxString NumberFormatter::PostProcessIntString(wxString s, int style)
|
||||||
{
|
{
|
||||||
if ( style & Style_WithThousandsSep )
|
if ( style & Style_WithThousandsSep )
|
||||||
AddThousandsSeparators(s);
|
AddThousandsSeparators(s);
|
||||||
@ -233,14 +233,14 @@ wxString wxNumberFormatter::PostProcessIntString(wxString s, int style)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxNumberFormatter::ToString(long val, int style)
|
wxString NumberFormatter::ToString(long val, int style)
|
||||||
{
|
{
|
||||||
return PostProcessIntString(wxString::Format(wxT("%ld"), val), style);
|
return PostProcessIntString(wxString::Format(wxT("%ld"), val), style);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
#ifdef HAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
||||||
|
|
||||||
wxString wxNumberFormatter::ToString(wxLongLong_t val, int style)
|
wxString NumberFormatter::ToString(wxLongLong_t val, int style)
|
||||||
{
|
{
|
||||||
#if wxCHECK_VERSION(3,0,0)
|
#if wxCHECK_VERSION(3,0,0)
|
||||||
return PostProcessIntString(wxString::Format("%" wxLongLongFmtSpec "d", val),
|
return PostProcessIntString(wxString::Format("%" wxLongLongFmtSpec "d", val),
|
||||||
@ -251,9 +251,9 @@ wxString wxNumberFormatter::ToString(wxLongLong_t val, int style)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
#endif // HAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
||||||
|
|
||||||
wxString wxNumberFormatter::ToString(double val, int precision, int style)
|
wxString NumberFormatter::ToString(double val, int precision, int style)
|
||||||
{
|
{
|
||||||
wxString format;
|
wxString format;
|
||||||
if ( precision == -1 )
|
if ( precision == -1 )
|
||||||
@ -287,7 +287,7 @@ wxString wxNumberFormatter::ToString(double val, int precision, int style)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNumberFormatter::AddThousandsSeparators(wxString& s)
|
void NumberFormatter::AddThousandsSeparators(wxString& s)
|
||||||
{
|
{
|
||||||
wxChar thousandsSep;
|
wxChar thousandsSep;
|
||||||
if ( !GetThousandsSeparatorIfUsed(&thousandsSep) )
|
if ( !GetThousandsSeparatorIfUsed(&thousandsSep) )
|
||||||
@ -318,7 +318,7 @@ void wxNumberFormatter::AddThousandsSeparators(wxString& s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNumberFormatter::RemoveTrailingZeroes(wxString& s, size_t retain /* = 0 */)
|
void NumberFormatter::RemoveTrailingZeroes(wxString& s, size_t retain /* = 0 */)
|
||||||
{
|
{
|
||||||
const size_t posDecSep = s.find(GetDecimalSeparator());
|
const size_t posDecSep = s.find(GetDecimalSeparator());
|
||||||
wxCHECK_RET( posDecSep != wxString::npos,
|
wxCHECK_RET( posDecSep != wxString::npos,
|
||||||
@ -342,7 +342,7 @@ void wxNumberFormatter::RemoveTrailingZeroes(wxString& s, size_t retain /* = 0 *
|
|||||||
// Conversion from strings
|
// Conversion from strings
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxNumberFormatter::RemoveThousandsSeparators(wxString& s)
|
void NumberFormatter::RemoveThousandsSeparators(wxString& s)
|
||||||
{
|
{
|
||||||
wxChar thousandsSep;
|
wxChar thousandsSep;
|
||||||
if ( !GetThousandsSeparatorIfUsed(&thousandsSep) )
|
if ( !GetThousandsSeparatorIfUsed(&thousandsSep) )
|
||||||
@ -351,23 +351,23 @@ void wxNumberFormatter::RemoveThousandsSeparators(wxString& s)
|
|||||||
s.Replace(wxString(thousandsSep), wxString());
|
s.Replace(wxString(thousandsSep), wxString());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxNumberFormatter::FromString(wxString s, long *val)
|
bool NumberFormatter::FromString(wxString s, long *val)
|
||||||
{
|
{
|
||||||
RemoveThousandsSeparators(s);
|
RemoveThousandsSeparators(s);
|
||||||
return s.ToLong(val);
|
return s.ToLong(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
#ifdef HAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
||||||
|
|
||||||
bool wxNumberFormatter::FromString(wxString s, wxLongLong_t *val)
|
bool NumberFormatter::FromString(wxString s, wxLongLong_t *val)
|
||||||
{
|
{
|
||||||
RemoveThousandsSeparators(s);
|
RemoveThousandsSeparators(s);
|
||||||
return s.ToLongLong(val);
|
return s.ToLongLong(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
#endif // HAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
||||||
|
|
||||||
bool wxNumberFormatter::FromString(wxString s, double *val)
|
bool NumberFormatter::FromString(wxString s, double *val)
|
||||||
{
|
{
|
||||||
RemoveThousandsSeparators(s);
|
RemoveThousandsSeparators(s);
|
||||||
return s.ToDouble(val);
|
return s.ToDouble(val);
|
||||||
|
@ -4,23 +4,23 @@
|
|||||||
//
|
//
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: wx/numformatter.h
|
// Name: wx/numformatter.h
|
||||||
// Purpose: wxNumberFormatter class
|
// Purpose: NumberFormatter class
|
||||||
// Author: Fulvio Senore, Vadim Zeitlin
|
// Author: Fulvio Senore, Vadim Zeitlin
|
||||||
// Created: 2010-11-06
|
// Created: 2010-11-06
|
||||||
// Copyright: (c) 2010 wxWidgets team
|
// Copyright: (c) 2010 wxWidgets team
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef _WX_NUMFORMATTER_H_
|
#ifndef _WIDGETS_NUMFORMATTER_H_
|
||||||
#define _WX_NUMFORMATTER_H_
|
#define _WIDGETS_NUMFORMATTER_H_
|
||||||
|
|
||||||
#include "wx/string.h"
|
#include <wx/string.h>
|
||||||
|
|
||||||
#define wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
#define HAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
||||||
|
|
||||||
// Helper class for formatting numbers with thousands separators which also
|
// Helper class for formatting numbers with thousands separators which also
|
||||||
// supports parsing the numbers formatted by it.
|
// supports parsing the numbers formatted by it.
|
||||||
class wxNumberFormatter
|
class NumberFormatter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Bit masks for ToString()
|
// Bit masks for ToString()
|
||||||
@ -39,10 +39,10 @@ public:
|
|||||||
// precision can also be specified.
|
// precision can also be specified.
|
||||||
static wxString ToString(long val,
|
static wxString ToString(long val,
|
||||||
int style = Style_WithThousandsSep);
|
int style = Style_WithThousandsSep);
|
||||||
#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
#ifdef HAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
||||||
static wxString ToString(wxLongLong_t val,
|
static wxString ToString(wxLongLong_t val,
|
||||||
int style = Style_WithThousandsSep);
|
int style = Style_WithThousandsSep);
|
||||||
#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
#endif // HAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
||||||
static wxString ToString(double val,
|
static wxString ToString(double val,
|
||||||
int precision,
|
int precision,
|
||||||
int style = Style_WithThousandsSep);
|
int style = Style_WithThousandsSep);
|
||||||
@ -52,9 +52,9 @@ public:
|
|||||||
// Return true on success and stores the result in the provided location
|
// Return true on success and stores the result in the provided location
|
||||||
// which must be a valid non-NULL pointer.
|
// which must be a valid non-NULL pointer.
|
||||||
static bool FromString(wxString s, long *val);
|
static bool FromString(wxString s, long *val);
|
||||||
#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
#ifdef HAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
||||||
static bool FromString(wxString s, wxLongLong_t *val);
|
static bool FromString(wxString s, wxLongLong_t *val);
|
||||||
#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
#endif // HAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
||||||
static bool FromString(wxString s, double *val);
|
static bool FromString(wxString s, double *val);
|
||||||
|
|
||||||
|
|
||||||
@ -84,4 +84,4 @@ private:
|
|||||||
static void RemoveThousandsSeparators(wxString& s);
|
static void RemoveThousandsSeparators(wxString& s);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _WX_NUMFORMATTER_H_
|
#endif // _WIDGETS_NUMFORMATTER_H_
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
// For compilers that support precompilation, includes "wx.h".
|
// For compilers that support precompilation, includes "wx.h".
|
||||||
#include "wx/wxprec.h"
|
#include <wx/wxprec.h>
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
#pragma hdrstop
|
#pragma hdrstop
|
||||||
@ -29,40 +29,40 @@
|
|||||||
#if wxUSE_VALIDATORS && wxUSE_TEXTCTRL
|
#if wxUSE_VALIDATORS && wxUSE_TEXTCTRL
|
||||||
|
|
||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
#include "wx/msgdlg.h"
|
#include <wx/msgdlg.h>
|
||||||
#include "wx/textctrl.h"
|
#include <wx/textctrl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "valnum.h"
|
#include "valnum.h"
|
||||||
#include "numformatter.h"
|
#include "numformatter.h"
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// wxNumValidatorBase implementation
|
// NumValidatorBase implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(wxNumValidatorBase, wxValidator)
|
BEGIN_EVENT_TABLE(NumValidatorBase, wxValidator)
|
||||||
EVT_CHAR(wxNumValidatorBase::OnChar)
|
EVT_CHAR(NumValidatorBase::OnChar)
|
||||||
EVT_KILL_FOCUS(wxNumValidatorBase::OnKillFocus)
|
EVT_KILL_FOCUS(NumValidatorBase::OnKillFocus)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
int wxNumValidatorBase::GetFormatFlags() const
|
int NumValidatorBase::GetFormatFlags() const
|
||||||
{
|
{
|
||||||
int flags = wxNumberFormatter::Style_None;
|
int flags = NumberFormatter::Style_None;
|
||||||
if ( m_style & wxNUM_VAL_THOUSANDS_SEPARATOR )
|
if ( m_style & NUM_VAL_THOUSANDS_SEPARATOR )
|
||||||
flags |= wxNumberFormatter::Style_WithThousandsSep;
|
flags |= NumberFormatter::Style_WithThousandsSep;
|
||||||
if ( m_style & wxNUM_VAL_NO_TRAILING_ZEROES )
|
if ( m_style & NUM_VAL_NO_TRAILING_ZEROES )
|
||||||
flags |= wxNumberFormatter::Style_NoTrailingZeroes;
|
flags |= NumberFormatter::Style_NoTrailingZeroes;
|
||||||
if ( m_style & wxNUM_VAL_ONE_TRAILING_ZERO )
|
if ( m_style & NUM_VAL_ONE_TRAILING_ZERO )
|
||||||
flags |= wxNumberFormatter::Style_OneTrailingZero;
|
flags |= NumberFormatter::Style_OneTrailingZero;
|
||||||
if ( m_style & wxNUM_VAL_TWO_TRAILING_ZEROES )
|
if ( m_style & NUM_VAL_TWO_TRAILING_ZEROES )
|
||||||
flags |= wxNumberFormatter::Style_TwoTrailingZeroes;
|
flags |= NumberFormatter::Style_TwoTrailingZeroes;
|
||||||
if ( m_style & wxNUM_VAL_THREE_TRAILING_ZEROES )
|
if ( m_style & NUM_VAL_THREE_TRAILING_ZEROES )
|
||||||
flags |= wxNumberFormatter::Style_ThreeTrailingZeroes;
|
flags |= NumberFormatter::Style_ThreeTrailingZeroes;
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxTextEntry *wxNumValidatorBase::GetTextEntry() const
|
wxTextEntry *NumValidatorBase::GetTextEntry() const
|
||||||
{
|
{
|
||||||
#if wxUSE_TEXTCTRL
|
#if wxUSE_TEXTCTRL
|
||||||
if ( wxTextCtrl *text = wxDynamicCast(m_validatorWindow, wxTextCtrl) )
|
if ( wxTextCtrl *text = wxDynamicCast(m_validatorWindow, wxTextCtrl) )
|
||||||
@ -74,7 +74,7 @@ wxTextEntry *wxNumValidatorBase::GetTextEntry() const
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxNumValidatorBase::Validate(wxWindow *parent)
|
bool NumValidatorBase::Validate(wxWindow *parent)
|
||||||
{
|
{
|
||||||
// If window is disabled, simply return
|
// If window is disabled, simply return
|
||||||
if ( !m_validatorWindow->IsEnabled() )
|
if ( !m_validatorWindow->IsEnabled() )
|
||||||
@ -95,7 +95,7 @@ bool wxNumValidatorBase::Validate(wxWindow *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wxNumValidatorBase::GetCurrentValueAndInsertionPoint(wxString& val,
|
NumValidatorBase::GetCurrentValueAndInsertionPoint(wxString& val,
|
||||||
int& pos) const
|
int& pos) const
|
||||||
{
|
{
|
||||||
wxTextEntry * const control = GetTextEntry();
|
wxTextEntry * const control = GetTextEntry();
|
||||||
@ -126,7 +126,7 @@ wxNumValidatorBase::GetCurrentValueAndInsertionPoint(wxString& val,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxNumValidatorBase::IsMinusOk(const wxString& val, int pos) const
|
bool NumValidatorBase::IsMinusOk(const wxString& val, int pos) const
|
||||||
{
|
{
|
||||||
// Minus is only ever accepted in the beginning of the string.
|
// Minus is only ever accepted in the beginning of the string.
|
||||||
if ( pos != 0 )
|
if ( pos != 0 )
|
||||||
@ -139,7 +139,7 @@ bool wxNumValidatorBase::IsMinusOk(const wxString& val, int pos) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNumValidatorBase::OnChar(wxKeyEvent& event)
|
void NumValidatorBase::OnChar(wxKeyEvent& event)
|
||||||
{
|
{
|
||||||
// By default we just validate this key so don't prevent the normal
|
// By default we just validate this key so don't prevent the normal
|
||||||
// handling from taking place.
|
// handling from taking place.
|
||||||
@ -190,7 +190,7 @@ void wxNumValidatorBase::OnChar(wxKeyEvent& event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNumValidatorBase::OnKillFocus(wxFocusEvent& event)
|
void NumValidatorBase::OnKillFocus(wxFocusEvent& event)
|
||||||
{
|
{
|
||||||
wxTextEntry * const control = GetTextEntry();
|
wxTextEntry * const control = GetTextEntry();
|
||||||
if ( !control )
|
if ( !control )
|
||||||
@ -216,22 +216,22 @@ void wxNumValidatorBase::OnKillFocus(wxFocusEvent& event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// wxIntegerValidatorBase implementation
|
// IntegerValidatorBase implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
wxString wxIntegerValidatorBase::ToString(LongestValueType value) const
|
wxString IntegerValidatorBase::ToString(LongestValueType value) const
|
||||||
{
|
{
|
||||||
return wxNumberFormatter::ToString(value, GetFormatFlags());
|
return NumberFormatter::ToString(value, GetFormatFlags());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
wxIntegerValidatorBase::FromString(const wxString& s, LongestValueType *value)
|
IntegerValidatorBase::FromString(const wxString& s, LongestValueType *value)
|
||||||
{
|
{
|
||||||
return wxNumberFormatter::FromString(s, value);
|
return NumberFormatter::FromString(s, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
wxIntegerValidatorBase::IsCharOk(const wxString& val, int pos, wxChar ch) const
|
IntegerValidatorBase::IsCharOk(const wxString& val, int pos, wxChar ch) const
|
||||||
{
|
{
|
||||||
// We may accept minus sign if we can represent negative numbers at all.
|
// We may accept minus sign if we can represent negative numbers at all.
|
||||||
if ( ch == '-' )
|
if ( ch == '-' )
|
||||||
@ -252,7 +252,7 @@ wxIntegerValidatorBase::IsCharOk(const wxString& val, int pos, wxChar ch) const
|
|||||||
if ( ch < '0' || ch > '9' )
|
if ( ch < '0' || ch > '9' )
|
||||||
{
|
{
|
||||||
wxChar thousands;
|
wxChar thousands;
|
||||||
if ( wxNumberFormatter::GetThousandsSeparatorIfUsed(&thousands) )
|
if ( NumberFormatter::GetThousandsSeparatorIfUsed(&thousands) )
|
||||||
{
|
{
|
||||||
if (ch != thousands)
|
if (ch != thousands)
|
||||||
return false;
|
return false;
|
||||||
@ -266,7 +266,7 @@ wxIntegerValidatorBase::IsCharOk(const wxString& val, int pos, wxChar ch) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxIntegerValidatorBase::DoValidateNumber(wxString * errMsg) const
|
bool IntegerValidatorBase::DoValidateNumber(wxString * errMsg) const
|
||||||
{
|
{
|
||||||
wxTextEntry * const control = GetTextEntry();
|
wxTextEntry * const control = GetTextEntry();
|
||||||
if ( !control )
|
if ( !control )
|
||||||
@ -274,13 +274,13 @@ bool wxIntegerValidatorBase::DoValidateNumber(wxString * errMsg) const
|
|||||||
|
|
||||||
wxString s(control->GetValue());
|
wxString s(control->GetValue());
|
||||||
wxChar thousandsSep;
|
wxChar thousandsSep;
|
||||||
if ( wxNumberFormatter::GetThousandsSeparatorIfUsed(&thousandsSep) )
|
if ( NumberFormatter::GetThousandsSeparatorIfUsed(&thousandsSep) )
|
||||||
s.Replace(wxString(thousandsSep), wxString());
|
s.Replace(wxString(thousandsSep), wxString());
|
||||||
|
|
||||||
if ( s.empty() )
|
if ( s.empty() )
|
||||||
{
|
{
|
||||||
// Is blank, but allowed. Stop here
|
// Is blank, but allowed. Stop here
|
||||||
if ( HasFlag(wxNUM_VAL_ZERO_AS_BLANK) )
|
if ( HasFlag(NUM_VAL_ZERO_AS_BLANK) )
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -308,23 +308,23 @@ bool wxIntegerValidatorBase::DoValidateNumber(wxString * errMsg) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// wxFloatingPointValidatorBase implementation
|
// FloatingPointValidatorBase implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
wxString wxFloatingPointValidatorBase::ToString(LongestValueType value) const
|
wxString FloatingPointValidatorBase::ToString(LongestValueType value) const
|
||||||
{
|
{
|
||||||
return wxNumberFormatter::ToString(value, m_precision, GetFormatFlags());
|
return NumberFormatter::ToString(value, m_precision, GetFormatFlags());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
wxFloatingPointValidatorBase::FromString(const wxString& s,
|
FloatingPointValidatorBase::FromString(const wxString& s,
|
||||||
LongestValueType *value)
|
LongestValueType *value)
|
||||||
{
|
{
|
||||||
return wxNumberFormatter::FromString(s, value);
|
return NumberFormatter::FromString(s, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
wxFloatingPointValidatorBase::IsCharOk(const wxString& val,
|
FloatingPointValidatorBase::IsCharOk(const wxString& val,
|
||||||
int pos,
|
int pos,
|
||||||
wxChar ch) const
|
wxChar ch) const
|
||||||
{
|
{
|
||||||
@ -349,7 +349,7 @@ wxFloatingPointValidatorBase::IsCharOk(const wxString& val,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wxChar separator = wxNumberFormatter::GetDecimalSeparator();
|
const wxChar separator = NumberFormatter::GetDecimalSeparator();
|
||||||
if ( ch == separator )
|
if ( ch == separator )
|
||||||
{
|
{
|
||||||
if ( val.find(separator) != wxString::npos )
|
if ( val.find(separator) != wxString::npos )
|
||||||
@ -374,7 +374,7 @@ wxFloatingPointValidatorBase::IsCharOk(const wxString& val,
|
|||||||
if( ( ch < '0' || ch > '9' ) && ch != 'E' && ch != 'e' )
|
if( ( ch < '0' || ch > '9' ) && ch != 'E' && ch != 'e' )
|
||||||
{
|
{
|
||||||
wxChar thousands;
|
wxChar thousands;
|
||||||
if ( wxNumberFormatter::GetThousandsSeparatorIfUsed(&thousands) )
|
if ( NumberFormatter::GetThousandsSeparatorIfUsed(&thousands) )
|
||||||
{
|
{
|
||||||
if (ch != thousands)
|
if (ch != thousands)
|
||||||
return false;
|
return false;
|
||||||
@ -391,7 +391,7 @@ wxFloatingPointValidatorBase::IsCharOk(const wxString& val,
|
|||||||
return ValidatePrecision(str);
|
return ValidatePrecision(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFloatingPointValidatorBase::DoValidateNumber(wxString * errMsg) const
|
bool FloatingPointValidatorBase::DoValidateNumber(wxString * errMsg) const
|
||||||
{
|
{
|
||||||
wxTextEntry * const control = GetTextEntry();
|
wxTextEntry * const control = GetTextEntry();
|
||||||
if ( !control )
|
if ( !control )
|
||||||
@ -399,12 +399,12 @@ bool wxFloatingPointValidatorBase::DoValidateNumber(wxString * errMsg) const
|
|||||||
|
|
||||||
wxString s(control->GetValue());
|
wxString s(control->GetValue());
|
||||||
wxChar thousandsSep;
|
wxChar thousandsSep;
|
||||||
if ( wxNumberFormatter::GetThousandsSeparatorIfUsed(&thousandsSep) )
|
if ( NumberFormatter::GetThousandsSeparatorIfUsed(&thousandsSep) )
|
||||||
s.Replace(wxString(thousandsSep), wxString());
|
s.Replace(wxString(thousandsSep), wxString());
|
||||||
|
|
||||||
if ( s.empty() )
|
if ( s.empty() )
|
||||||
{
|
{
|
||||||
if ( HasFlag(wxNUM_VAL_ZERO_AS_BLANK) )
|
if ( HasFlag(NUM_VAL_ZERO_AS_BLANK) )
|
||||||
return true; //Is blank, but allowed. Stop here
|
return true; //Is blank, but allowed. Stop here
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -433,9 +433,9 @@ bool wxFloatingPointValidatorBase::DoValidateNumber(wxString * errMsg) const
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFloatingPointValidatorBase::ValidatePrecision(const wxString& s) const
|
bool FloatingPointValidatorBase::ValidatePrecision(const wxString& s) const
|
||||||
{
|
{
|
||||||
size_t posSep = s.find(wxNumberFormatter::GetDecimalSeparator());
|
size_t posSep = s.find(NumberFormatter::GetDecimalSeparator());
|
||||||
if ( posSep == wxString::npos )
|
if ( posSep == wxString::npos )
|
||||||
posSep = s.length();
|
posSep = s.length();
|
||||||
|
|
||||||
|
@ -8,36 +8,36 @@
|
|||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef _WX_VALNUM_H_
|
#ifndef _WIDGETS_VALNUM_H_
|
||||||
#define _WX_VALNUM_H_
|
#define _WIDGETS_VALNUM_H_
|
||||||
|
|
||||||
#include "wx/defs.h"
|
#include <wx/defs.h>
|
||||||
|
|
||||||
#if wxUSE_VALIDATORS
|
#if wxUSE_VALIDATORS
|
||||||
|
|
||||||
#include "wx/validate.h"
|
#include <wx/validate.h>
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
#define wxTextEntry wxTextCtrl
|
#define wxTextEntry wxTextCtrl
|
||||||
|
|
||||||
// Bit masks used for numeric validator styles.
|
// Bit masks used for numeric validator styles.
|
||||||
enum wxNumValidatorStyle
|
enum NumValidatorStyle
|
||||||
{
|
{
|
||||||
wxNUM_VAL_DEFAULT = 0x0,
|
NUM_VAL_DEFAULT = 0x0,
|
||||||
wxNUM_VAL_THOUSANDS_SEPARATOR = 0x1,
|
NUM_VAL_THOUSANDS_SEPARATOR = 0x1,
|
||||||
wxNUM_VAL_ZERO_AS_BLANK = 0x2,
|
NUM_VAL_ZERO_AS_BLANK = 0x2,
|
||||||
wxNUM_VAL_NO_TRAILING_ZEROES = 0x4,
|
NUM_VAL_NO_TRAILING_ZEROES = 0x4,
|
||||||
wxNUM_VAL_ONE_TRAILING_ZERO = 0x8,
|
NUM_VAL_ONE_TRAILING_ZERO = 0x8,
|
||||||
wxNUM_VAL_TWO_TRAILING_ZEROES = 0x10,
|
NUM_VAL_TWO_TRAILING_ZEROES = 0x10,
|
||||||
wxNUM_VAL_THREE_TRAILING_ZEROES = 0x20
|
NUM_VAL_THREE_TRAILING_ZEROES = 0x20
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Base class for all numeric validators.
|
// Base class for all numeric validators.
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxNumValidatorBase : public wxValidator
|
class NumValidatorBase : public wxValidator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Change the validator style. Usually it's specified during construction.
|
// Change the validator style. Usually it's specified during construction.
|
||||||
@ -48,17 +48,17 @@ public:
|
|||||||
virtual bool Validate(wxWindow * parent);
|
virtual bool Validate(wxWindow * parent);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxNumValidatorBase(int style)
|
NumValidatorBase(int style)
|
||||||
{
|
{
|
||||||
m_style = style;
|
m_style = style;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxNumValidatorBase(const wxNumValidatorBase& other) : wxValidator()
|
NumValidatorBase(const NumValidatorBase& other) : wxValidator()
|
||||||
{
|
{
|
||||||
m_style = other.m_style;
|
m_style = other.m_style;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HasFlag(wxNumValidatorStyle style) const
|
bool HasFlag(NumValidatorStyle style) const
|
||||||
{
|
{
|
||||||
return (m_style & style) != 0;
|
return (m_style & style) != 0;
|
||||||
}
|
}
|
||||||
@ -68,8 +68,8 @@ protected:
|
|||||||
// still test the return value for safety.
|
// still test the return value for safety.
|
||||||
wxTextEntry *GetTextEntry() const;
|
wxTextEntry *GetTextEntry() const;
|
||||||
|
|
||||||
// Convert wxNUM_VAL_THOUSANDS_SEPARATOR and wxNUM_VAL_NO_TRAILING_ZEROES
|
// Convert NUM_VAL_THOUSANDS_SEPARATOR and NUM_VAL_NO_TRAILING_ZEROES
|
||||||
// bits of our style to the corresponding wxNumberFormatter::Style values.
|
// bits of our style to the corresponding NumberFormatter::Style values.
|
||||||
int GetFormatFlags() const;
|
int GetFormatFlags() const;
|
||||||
|
|
||||||
// Return true if pressing a '-' key is acceptable for the current control
|
// Return true if pressing a '-' key is acceptable for the current control
|
||||||
@ -118,24 +118,24 @@ private:
|
|||||||
|
|
||||||
DECLARE_EVENT_TABLE();
|
DECLARE_EVENT_TABLE();
|
||||||
|
|
||||||
DECLARE_NO_ASSIGN_CLASS(wxNumValidatorBase);
|
DECLARE_NO_ASSIGN_CLASS(NumValidatorBase);
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace wxPrivate
|
namespace Private
|
||||||
{
|
{
|
||||||
|
|
||||||
// This is a helper class used by wxIntegerValidator and wxFloatingPointValidator
|
// This is a helper class used by IntegerValidator and FloatingPointValidator
|
||||||
// below that implements Transfer{To,From}Window() adapted to the type of the
|
// below that implements Transfer{To,From}Window() adapted to the type of the
|
||||||
// variable.
|
// variable.
|
||||||
//
|
//
|
||||||
// The template argument B is the name of the base class which must derive from
|
// The template argument B is the name of the base class which must derive from
|
||||||
// wxNumValidatorBase and define LongestValueType type and {To,As}String()
|
// wxNumValidatorBase and define LongestValueType type and {To,As}String()
|
||||||
// methods i.e. basically be one of wx{Integer,Number}ValidatorBase classes.
|
// methods i.e. basically be one of {Integer,Number}ValidatorBase classes.
|
||||||
//
|
//
|
||||||
// The template argument T is just the type handled by the validator that will
|
// The template argument T is just the type handled by the validator that will
|
||||||
// inherit from this one.
|
// inherit from this one.
|
||||||
template <class B, typename T>
|
template <class B, typename T>
|
||||||
class wxNumValidator : public B
|
class NumValidator : public B
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef B BaseValidator;
|
typedef B BaseValidator;
|
||||||
@ -145,7 +145,7 @@ public:
|
|||||||
|
|
||||||
// FIXME-VC6: This compiler fails to compile the assert below with a
|
// FIXME-VC6: This compiler fails to compile the assert below with a
|
||||||
// nonsensical error C2248: "'LongestValueType' : cannot access protected
|
// nonsensical error C2248: "'LongestValueType' : cannot access protected
|
||||||
// typedef declared in class 'wxIntegerValidatorBase'" so just disable the
|
// typedef declared in class 'IntegerValidatorBase'" so just disable the
|
||||||
// check for it.
|
// check for it.
|
||||||
#ifndef __VISUALC6__
|
#ifndef __VISUALC6__
|
||||||
wxCOMPILE_TIME_ASSERT
|
wxCOMPILE_TIME_ASSERT
|
||||||
@ -195,7 +195,7 @@ public:
|
|||||||
|
|
||||||
const wxString s(control->GetValue());
|
const wxString s(control->GetValue());
|
||||||
LongestValueType value;
|
LongestValueType value;
|
||||||
if ( s.empty() && BaseValidator::HasFlag(wxNUM_VAL_ZERO_AS_BLANK) )
|
if ( s.empty() && BaseValidator::HasFlag(NUM_VAL_ZERO_AS_BLANK) )
|
||||||
value = 0;
|
value = 0;
|
||||||
else if ( !BaseValidator::FromString(s, &value) )
|
else if ( !BaseValidator::FromString(s, &value) )
|
||||||
return false;
|
return false;
|
||||||
@ -210,13 +210,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxNumValidator(ValueType *value, int style)
|
NumValidator(ValueType *value, int style)
|
||||||
: BaseValidator(style),
|
: BaseValidator(style),
|
||||||
m_value(value)
|
m_value(value)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement wxNumValidatorBase virtual method which is the same for
|
// Implement NumValidatorBase virtual method which is the same for
|
||||||
// both integer and floating point numbers.
|
// both integer and floating point numbers.
|
||||||
virtual wxString NormalizeString(const wxString& s) const
|
virtual wxString NormalizeString(const wxString& s) const
|
||||||
{
|
{
|
||||||
@ -228,11 +228,11 @@ protected:
|
|||||||
private:
|
private:
|
||||||
// Just a helper which is a common part of TransferToWindow() and
|
// Just a helper which is a common part of TransferToWindow() and
|
||||||
// NormalizeString(): returns string representation of a number honouring
|
// NormalizeString(): returns string representation of a number honouring
|
||||||
// wxNUM_VAL_ZERO_AS_BLANK flag.
|
// NUM_VAL_ZERO_AS_BLANK flag.
|
||||||
wxString NormalizeValue(LongestValueType value) const
|
wxString NormalizeValue(LongestValueType value) const
|
||||||
{
|
{
|
||||||
wxString s;
|
wxString s;
|
||||||
if ( value != 0 || !BaseValidator::HasFlag(wxNUM_VAL_ZERO_AS_BLANK) )
|
if ( value != 0 || !BaseValidator::HasFlag(NUM_VAL_ZERO_AS_BLANK) )
|
||||||
s = this->ToString(value);
|
s = this->ToString(value);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
@ -241,10 +241,10 @@ private:
|
|||||||
|
|
||||||
ValueType * const m_value;
|
ValueType * const m_value;
|
||||||
|
|
||||||
DECLARE_NO_ASSIGN_CLASS(wxNumValidator);
|
DECLARE_NO_ASSIGN_CLASS(NumValidator);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace wxPrivate
|
} // namespace Private
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Validators for integer numbers.
|
// Validators for integer numbers.
|
||||||
@ -253,12 +253,12 @@ private:
|
|||||||
// Base class for integer numbers validator. This class contains all non
|
// Base class for integer numbers validator. This class contains all non
|
||||||
// type-dependent code of wxIntegerValidator<> and always works with values of
|
// type-dependent code of wxIntegerValidator<> and always works with values of
|
||||||
// type LongestValueType. It is not meant to be used directly, please use
|
// type LongestValueType. It is not meant to be used directly, please use
|
||||||
// wxIntegerValidator<> only instead.
|
// IntegerValidator<> only instead.
|
||||||
class wxIntegerValidatorBase : public wxNumValidatorBase
|
class IntegerValidatorBase : public NumValidatorBase
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
// Define the type we use here, it should be the maximal-sized integer type
|
// 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
|
// we support to make it possible to base IntegerValidator<> for any type
|
||||||
// on it.
|
// on it.
|
||||||
#ifdef wxLongLong_t
|
#ifdef wxLongLong_t
|
||||||
typedef wxLongLong_t LongestValueType;
|
typedef wxLongLong_t LongestValueType;
|
||||||
@ -266,27 +266,27 @@ protected:
|
|||||||
typedef long LongestValueType;
|
typedef long LongestValueType;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxIntegerValidatorBase(int style)
|
IntegerValidatorBase(int style)
|
||||||
: wxNumValidatorBase(style)
|
: NumValidatorBase(style)
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( !(style & wxNUM_VAL_NO_TRAILING_ZEROES),
|
wxASSERT_MSG( !(style & NUM_VAL_NO_TRAILING_ZEROES),
|
||||||
wxT("This style doesn't make sense for integers.") );
|
wxT("This style doesn't make sense for integers.") );
|
||||||
wxASSERT_MSG( !(style & wxNUM_VAL_ONE_TRAILING_ZERO),
|
wxASSERT_MSG( !(style & NUM_VAL_ONE_TRAILING_ZERO),
|
||||||
wxT("This style doesn't make sense for integers.") );
|
wxT("This style doesn't make sense for integers.") );
|
||||||
wxASSERT_MSG( !(style & wxNUM_VAL_TWO_TRAILING_ZEROES),
|
wxASSERT_MSG( !(style & NUM_VAL_TWO_TRAILING_ZEROES),
|
||||||
wxT("This style doesn't make sense for integers.") );
|
wxT("This style doesn't make sense for integers.") );
|
||||||
wxASSERT_MSG( !(style & wxNUM_VAL_THREE_TRAILING_ZEROES),
|
wxASSERT_MSG( !(style & NUM_VAL_THREE_TRAILING_ZEROES),
|
||||||
wxT("This style doesn't make sense for integers.") );
|
wxT("This style doesn't make sense for integers.") );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxIntegerValidatorBase(const wxIntegerValidatorBase& other)
|
IntegerValidatorBase(const IntegerValidatorBase& other)
|
||||||
: wxNumValidatorBase(other)
|
: NumValidatorBase(other)
|
||||||
{
|
{
|
||||||
m_min = other.m_min;
|
m_min = other.m_min;
|
||||||
m_max = other.m_max;
|
m_max = other.m_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provide methods for wxNumValidator use.
|
// Provide methods for NumValidator use.
|
||||||
wxString ToString(LongestValueType value) const;
|
wxString ToString(LongestValueType value) const;
|
||||||
static bool FromString(const wxString& s, LongestValueType *value);
|
static bool FromString(const wxString& s, LongestValueType *value);
|
||||||
|
|
||||||
@ -298,7 +298,7 @@ protected:
|
|||||||
return m_min <= value && value <= m_max;
|
return m_min <= value && value <= m_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement wxNumValidatorBase pure virtual method.
|
// Implement NumValidatorBase pure virtual method.
|
||||||
virtual bool IsCharOk(const wxString& val, int pos, wxChar ch) const;
|
virtual bool IsCharOk(const wxString& val, int pos, wxChar ch) const;
|
||||||
virtual bool DoValidateNumber(wxString * errMsg) const;
|
virtual bool DoValidateNumber(wxString * errMsg) const;
|
||||||
|
|
||||||
@ -306,55 +306,55 @@ private:
|
|||||||
// Minimal and maximal values accepted (inclusive).
|
// Minimal and maximal values accepted (inclusive).
|
||||||
LongestValueType m_min, m_max;
|
LongestValueType m_min, m_max;
|
||||||
|
|
||||||
DECLARE_NO_ASSIGN_CLASS(wxIntegerValidatorBase);
|
DECLARE_NO_ASSIGN_CLASS(IntegerValidatorBase);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Validator for integer numbers. It can actually work with any integer type
|
// 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
|
// (short, int or long and long long if supported) and their unsigned versions
|
||||||
// as well.
|
// as well.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class wxIntegerValidator
|
class IntegerValidator
|
||||||
: public wxPrivate::wxNumValidator<wxIntegerValidatorBase, T>
|
: public Private::NumValidator<IntegerValidatorBase, T>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef T ValueType;
|
typedef T ValueType;
|
||||||
|
|
||||||
typedef
|
typedef
|
||||||
wxPrivate::wxNumValidator<wxIntegerValidatorBase, T> Base;
|
Private::NumValidator<IntegerValidatorBase, T> Base;
|
||||||
|
|
||||||
// Ctor for an integer validator.
|
// Ctor for an integer validator.
|
||||||
//
|
//
|
||||||
// Sets the range appropriately for the type, including setting 0 as the
|
// Sets the range appropriately for the type, including setting 0 as the
|
||||||
// minimal value for the unsigned types.
|
// minimal value for the unsigned types.
|
||||||
wxIntegerValidator(ValueType *value = NULL, int style = wxNUM_VAL_DEFAULT)
|
IntegerValidator(ValueType *value = NULL, int style = NUM_VAL_DEFAULT)
|
||||||
: Base(value, style)
|
: Base(value, style)
|
||||||
{
|
{
|
||||||
this->DoSetMin(std::numeric_limits<ValueType>::min());
|
this->DoSetMin(std::numeric_limits<ValueType>::min());
|
||||||
this->DoSetMax(std::numeric_limits<ValueType>::max());
|
this->DoSetMax(std::numeric_limits<ValueType>::max());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual wxObject *Clone() const { return new wxIntegerValidator(*this); }
|
virtual wxObject *Clone() const { return new IntegerValidator(*this); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_NO_ASSIGN_CLASS(wxIntegerValidator);
|
DECLARE_NO_ASSIGN_CLASS(IntegerValidator);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper function for creating integer validators which allows to avoid
|
// Helper function for creating integer validators which allows to avoid
|
||||||
// explicitly specifying the type as it deduces it from its parameter.
|
// explicitly specifying the type as it deduces it from its parameter.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline wxIntegerValidator<T>
|
inline IntegerValidator<T>
|
||||||
wxMakeIntegerValidator(T *value, int style = wxNUM_VAL_DEFAULT)
|
MakeIntegerValidator(T *value, int style = NUM_VAL_DEFAULT)
|
||||||
{
|
{
|
||||||
return wxIntegerValidator<T>(value, style);
|
return IntegerValidator<T>(value, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Validators for floating point numbers.
|
// Validators for floating point numbers.
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
// Similar to wxIntegerValidatorBase, this class is not meant to be used
|
// Similar to IntegerValidatorBase, this class is not meant to be used
|
||||||
// directly, only wxFloatingPointValidator<> should be used in the user code.
|
// directly, only FloatingPointValidator<> should be used in the user code.
|
||||||
class wxFloatingPointValidatorBase : public wxNumValidatorBase
|
class FloatingPointValidatorBase : public NumValidatorBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Set precision i.e. the number of digits shown (and accepted on input)
|
// Set precision i.e. the number of digits shown (and accepted on input)
|
||||||
@ -364,17 +364,17 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Notice that we can't use "long double" here because it's not supported
|
// Notice that we can't use "long double" here because it's not supported
|
||||||
// by wxNumberFormatter yet, so restrict ourselves to just double (and
|
// by NumberFormatter yet, so restrict ourselves to just double (and
|
||||||
// float).
|
// float).
|
||||||
typedef double LongestValueType;
|
typedef double LongestValueType;
|
||||||
|
|
||||||
wxFloatingPointValidatorBase(int style)
|
FloatingPointValidatorBase(int style)
|
||||||
: wxNumValidatorBase(style)
|
: NumValidatorBase(style)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFloatingPointValidatorBase(const wxFloatingPointValidatorBase& other)
|
FloatingPointValidatorBase(const FloatingPointValidatorBase& other)
|
||||||
: wxNumValidatorBase(other)
|
: NumValidatorBase(other)
|
||||||
{
|
{
|
||||||
m_precision = other.m_precision;
|
m_precision = other.m_precision;
|
||||||
|
|
||||||
@ -382,7 +382,7 @@ protected:
|
|||||||
m_max = other.m_max;
|
m_max = other.m_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provide methods for wxNumValidator use.
|
// Provide methods for NumValidator use.
|
||||||
wxString ToString(LongestValueType value) const;
|
wxString ToString(LongestValueType value) const;
|
||||||
static bool FromString(const wxString& s, LongestValueType *value);
|
static bool FromString(const wxString& s, LongestValueType *value);
|
||||||
|
|
||||||
@ -394,7 +394,7 @@ protected:
|
|||||||
return m_min <= value && value <= m_max;
|
return m_min <= value && value <= m_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement wxNumValidatorBase pure virtual method.
|
// Implement NumValidatorBase pure virtual method.
|
||||||
virtual bool IsCharOk(const wxString& val, int pos, wxChar ch) const;
|
virtual bool IsCharOk(const wxString& val, int pos, wxChar ch) const;
|
||||||
virtual bool DoValidateNumber(wxString * errMsg) const;
|
virtual bool DoValidateNumber(wxString * errMsg) const;
|
||||||
|
|
||||||
@ -408,22 +408,22 @@ private:
|
|||||||
// Minimal and maximal values accepted (inclusive).
|
// Minimal and maximal values accepted (inclusive).
|
||||||
LongestValueType m_min, m_max;
|
LongestValueType m_min, m_max;
|
||||||
|
|
||||||
DECLARE_NO_ASSIGN_CLASS(wxFloatingPointValidatorBase);
|
DECLARE_NO_ASSIGN_CLASS(FloatingPointValidatorBase);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Validator for floating point numbers. It can be used with float, double or
|
// Validator for floating point numbers. It can be used with float, double or
|
||||||
// long double values.
|
// long double values.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class wxFloatingPointValidator
|
class FloatingPointValidator
|
||||||
: public wxPrivate::wxNumValidator<wxFloatingPointValidatorBase, T>
|
: public Private::NumValidator<FloatingPointValidatorBase, T>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef T ValueType;
|
typedef T ValueType;
|
||||||
typedef wxPrivate::wxNumValidator<wxFloatingPointValidatorBase, T> Base;
|
typedef Private::NumValidator<FloatingPointValidatorBase, T> Base;
|
||||||
|
|
||||||
// Ctor using implicit (maximal) precision for this type.
|
// Ctor using implicit (maximal) precision for this type.
|
||||||
wxFloatingPointValidator(ValueType *value = NULL,
|
FloatingPointValidator(ValueType *value = NULL,
|
||||||
int style = wxNUM_VAL_DEFAULT)
|
int style = NUM_VAL_DEFAULT)
|
||||||
: Base(value, style)
|
: Base(value, style)
|
||||||
{
|
{
|
||||||
DoSetMinMax();
|
DoSetMinMax();
|
||||||
@ -432,9 +432,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ctor specifying an explicit precision.
|
// Ctor specifying an explicit precision.
|
||||||
wxFloatingPointValidator(int precision,
|
FloatingPointValidator(int precision,
|
||||||
ValueType *value = NULL,
|
ValueType *value = NULL,
|
||||||
int style = wxNUM_VAL_DEFAULT)
|
int style = NUM_VAL_DEFAULT)
|
||||||
: Base(value, style)
|
: Base(value, style)
|
||||||
{
|
{
|
||||||
DoSetMinMax();
|
DoSetMinMax();
|
||||||
@ -444,7 +444,7 @@ public:
|
|||||||
|
|
||||||
virtual wxObject *Clone() const
|
virtual wxObject *Clone() const
|
||||||
{
|
{
|
||||||
return new wxFloatingPointValidator(*this);
|
return new FloatingPointValidator(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -458,25 +458,25 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper similar to wxMakeIntValidator().
|
// Helper similar to MakeIntValidator().
|
||||||
//
|
//
|
||||||
// NB: Unfortunately we can't just have a wxMakeNumericValidator() which would
|
// NB: Unfortunately we can't just have a MakeNumericValidator() which would
|
||||||
// return either wxIntegerValidator<> or wxFloatingPointValidator<> so we
|
// return either IntegerValidator<> or FloatingPointValidator<> so we
|
||||||
// do need two different functions.
|
// do need two different functions.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline wxFloatingPointValidator<T>
|
inline FloatingPointValidator<T>
|
||||||
wxMakeFloatingPointValidator(T *value, int style = wxNUM_VAL_DEFAULT)
|
MakeFloatingPointValidator(T *value, int style = NUM_VAL_DEFAULT)
|
||||||
{
|
{
|
||||||
return wxFloatingPointValidator<T>(value, style);
|
return FloatingPointValidator<T>(value, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline wxFloatingPointValidator<T>
|
inline FloatingPointValidator<T>
|
||||||
wxMakeFloatingPointValidator(int precision, T *value, int style = wxNUM_VAL_DEFAULT)
|
MakeFloatingPointValidator(int precision, T *value, int style = NUM_VAL_DEFAULT)
|
||||||
{
|
{
|
||||||
return wxFloatingPointValidator<T>(precision, value, style);
|
return FloatingPointValidator<T>(precision, value, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_VALIDATORS
|
#endif // wxUSE_VALIDATORS
|
||||||
|
|
||||||
#endif // _WX_VALNUM_H_
|
#endif // _WIDGETS_VALNUM_H_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user