diff --git a/docs/changes.txt b/docs/changes.txt index 23e7993a22..9b7329e2e7 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -437,6 +437,10 @@ Major new features in this release 2.9.3: ------ +All (GUI): + +- Support float, double and file name values in wxGenericValidator (troelsk). + GTK: - Generate events for two auxiliary mouse buttons in wxGTK (Marcin Wojdyr). diff --git a/include/wx/valgen.h b/include/wx/valgen.h index b0adefaf17..592afe4981 100644 --- a/include/wx/valgen.h +++ b/include/wx/valgen.h @@ -16,6 +16,7 @@ #if wxUSE_VALIDATORS class WXDLLIMPEXP_FWD_BASE wxDateTime; +class WXDLLIMPEXP_FWD_BASE wxFileName; // ---------------------------------------------------------------------------- // wxGenericValidator performs data transfer between many standard controls and @@ -42,6 +43,13 @@ public: // wxDatePickerCtrl wxGenericValidator(wxDateTime* val); #endif // wxUSE_DATETIME + // wxTextCtrl + wxGenericValidator(wxFileName* val); + // wxTextCtrl + wxGenericValidator(float* val); + // wxTextCtrl + wxGenericValidator(double* val); + wxGenericValidator(const wxGenericValidator& copyFrom); virtual ~wxGenericValidator(){} @@ -73,6 +81,9 @@ protected: #if wxUSE_DATETIME wxDateTime* m_pDateTime; #endif // wxUSE_DATETIME + wxFileName* m_pFileName; + float* m_pFloat; + double* m_pDouble; private: DECLARE_CLASS(wxGenericValidator) diff --git a/interface/wx/valgen.h b/interface/wx/valgen.h index 9a4dc6b45b..2a5f025d77 100644 --- a/interface/wx/valgen.h +++ b/interface/wx/valgen.h @@ -96,6 +96,42 @@ public: window). */ wxGenericValidator(wxDateTime* valPtr); + /** + Constructor taking a wxFileName pointer. This will be used for + wxTextCtrl. + + @param valPtr + A pointer to a variable that contains the value. This variable + should have a lifetime equal to or longer than the validator + lifetime (which is usually determined by the lifetime of the + window). + @since 2.9.3 + */ + wxGenericValidator(wxFileName* valPtr); + /** + Constructor taking a float pointer. This will be used for + wxTextCtrl. + + @param valPtr + A pointer to a variable that contains the value. This variable + should have a lifetime equal to or longer than the validator + lifetime (which is usually determined by the lifetime of the + window). + @since 2.9.3 + */ + wxGenericValidator(float* valPtr); + /** + Constructor taking a double pointer. This will be used for + wxTextCtrl. + + @param valPtr + A pointer to a variable that contains the value. This variable + should have a lifetime equal to or longer than the validator + lifetime (which is usually determined by the lifetime of the + window). + @since 2.9.3 + */ + wxGenericValidator(double* valPtr); /** Destructor. diff --git a/src/common/valgen.cpp b/src/common/valgen.cpp index dbafcaa721..ccbcc7c07f 100644 --- a/src/common/valgen.cpp +++ b/src/common/valgen.cpp @@ -46,6 +46,7 @@ #if wxUSE_TOGGLEBTN #include "wx/tglbtn.h" #endif +#include "wx/filename.h" #include "wx/valgen.h" @@ -83,6 +84,24 @@ wxGenericValidator::wxGenericValidator(wxDateTime *val) m_pDateTime = val; } +wxGenericValidator::wxGenericValidator(wxFileName *val) +{ + Initialize(); + m_pFileName = val; +} + +wxGenericValidator::wxGenericValidator(float *val) +{ + Initialize(); + m_pFloat = val; +} + +wxGenericValidator::wxGenericValidator(double *val) +{ + Initialize(); + m_pDouble = val; +} + #endif // wxUSE_DATETIME wxGenericValidator::wxGenericValidator(const wxGenericValidator& val) @@ -321,6 +340,21 @@ bool wxGenericValidator::TransferToWindow(void) pControl->SetValue(str); return true; } + else if (m_pFileName) + { + pControl->SetValue(m_pFileName->GetFullPath()); + return true; + } + else if (m_pFloat) + { + pControl->SetValue(wxString::Format(wxT("%g"), *m_pFloat)); + return true; + } + else if (m_pDouble) + { + pControl->SetValue(wxString::Format(wxT("%g"), *m_pDouble)); + return true; + } } else #endif @@ -582,6 +616,21 @@ bool wxGenericValidator::TransferFromWindow(void) *m_pInt = wxAtoi(pControl->GetValue()); return true; } + else if (m_pFileName) + { + m_pFileName->Assign(pControl->GetValue()); + return true; + } + else if (m_pFloat) + { + *m_pFloat = (float)wxAtof(pControl->GetValue()); + return true; + } + else if (m_pDouble) + { + *m_pDouble = wxAtof(pControl->GetValue()); + return true; + } } else #endif @@ -652,6 +701,9 @@ void wxGenericValidator::Initialize() #if wxUSE_DATETIME m_pDateTime = NULL; #endif // wxUSE_DATETIME + m_pFileName = NULL; + m_pFloat = NULL; + m_pDouble = NULL; } #endif // wxUSE_VALIDATORS