]> git.saurik.com Git - wxWidgets.git/commitdiff
Support float, double and file name values in wxGenericValidator.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 9 Jul 2011 23:37:28 +0000 (23:37 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 9 Jul 2011 23:37:28 +0000 (23:37 +0000)
Currently these values can only be read from/written to wxTextCtrl but support
for other controls (e.g. wxSpinCtrlDouble for float/double) could be added in
the future.

Closes #13304.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68217 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/valgen.h
interface/wx/valgen.h
src/common/valgen.cpp

index 23e7993a223b7c87c2f529788c773af730c175c6..9b7329e2e764e3fea32c960e59b76adef627bf6e 100644 (file)
@@ -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).
index b0adefaf17df0092d2eaab004dd3c78b7964277e..592afe498119b9d1c9753833c05c33b20eb7d86e 100644 (file)
@@ -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)
index 9a4dc6b45b4204285be5ccf8be833eac2c68a68f..2a5f025d7748762b0326bad67f062d7ee5e3ff2c 100644 (file)
@@ -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.
index dbafcaa72164679e0f3f5cd1a8a0deb180508a61..ccbcc7c07fdf634e9611ae18cb82e31415f11c60 100644 (file)
@@ -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