]> git.saurik.com Git - wxWidgets.git/commitdiff
suppress events resulting from our own SetValue() calls
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 17 May 2005 23:19:46 +0000 (23:19 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 17 May 2005 23:19:46 +0000 (23:19 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34117 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/generic/datectlg.cpp

index a8f65fe98164167b96a9fab02ab271064f92ac64..b08865412933e0ac7297fe7fc5ee0a8e00351840 100644 (file)
@@ -88,6 +88,18 @@ enum
     #define TXTPOSY           0
 #endif
 
+// ----------------------------------------------------------------------------
+// global variables
+// ----------------------------------------------------------------------------
+
+// this should have been a flag in wxDatePickerCtrlGeneric itself but adding it
+// there now would break backwards compatibility, so put it here as a global:
+// this shouldn't be a big problem as only one (GUI) thread normally can call
+// wxDatePickerCtrlGeneric::SetValue() and so it can be only ever used for one
+// control at a time
+//
+// if the value is not NULL, it points to the control which is inside SetValue()
+static wxDatePickerCtrlGeneric *gs_inSetValue = NULL;
 
 // ----------------------------------------------------------------------------
 // local classes
@@ -694,20 +706,29 @@ wxDateTime wxDatePickerCtrlGeneric::GetValue() const
 
 void wxDatePickerCtrlGeneric::SetValue(const wxDateTime& date)
 {
-    if (m_cal)
-    {
-        if (date.IsValid())
-            m_txt->SetValue(date.Format(m_format));
-        else
-        {
-            wxASSERT_MSG( HasFlag(wxDP_ALLOWNONE),
-                            _T("this control must have a valid date") );
+    if ( !m_cal ) 
+        return;
 
-            m_txt->SetValue(wxEmptyString);
-        }
+    // we need to suppress the event sent from wxTextCtrl as calling our
+    // SetValue() should not result in an event being sent (wxTextCtrl is
+    // an exception to this rule)
+    gs_inSetValue = this;
+
+    if ( date.IsValid() )
+    {
+        m_txt->SetValue(date.Format(m_format));
+    }
+    else // invalid date
+    {
+        wxASSERT_MSG( HasFlag(wxDP_ALLOWNONE),
+                        _T("this control must have a valid date") );
 
-        m_currentDate = date;
+        m_txt->SetValue(wxEmptyString);
     }
+
+    gs_inSetValue = NULL;
+
+    m_currentDate = date;
 }
 
 
@@ -879,6 +900,12 @@ void wxDatePickerCtrlGeneric::OnSelChange(wxCalendarEvent &ev)
 
 void wxDatePickerCtrlGeneric::OnText(wxCommandEvent &ev)
 {
+    if ( gs_inSetValue )
+    {
+        // artificial event resulting from our own SetValue() call, ignore it
+        return;
+    }
+
     ev.SetEventObject(this);
     ev.SetId(GetId());
     GetParent()->ProcessEvent(ev);