]> git.saurik.com Git - wxWidgets.git/commitdiff
Disable sending of events by OS X Combobox during programmatic changes.
authorKevin Ollivier <kevino@theolliviers.com>
Fri, 19 Feb 2010 03:00:07 +0000 (03:00 +0000)
committerKevin Ollivier <kevino@theolliviers.com>
Fri, 19 Feb 2010 03:00:07 +0000 (03:00 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63519 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/osx/core/private.h
src/osx/cocoa/combobox.mm
src/osx/window_osx.cpp

index 49b2f13417acdd5a058866b32b0c4dce06d1010f..8844689e36cabfb13c012ad65d8b8037d52457a3 100644 (file)
@@ -276,6 +276,12 @@ public :
     virtual bool        ButtonClickDidStateChange() = 0;
 
     virtual void        InstallEventHandler( WXWidget control = NULL ) = 0;
+    
+    // Mechanism used to keep track of whether a change should send an event
+    // Do SendEvents(false) when starting actions that would trigger programmatic events
+    // and SendEvents(true) at the end of the block.
+    virtual void        SendEvents(bool shouldSendEvents) { m_shouldSendEvents = shouldSendEvents; }
+    virtual bool        ShouldSendEvents() { return m_shouldSendEvents; }
 
     // static methods for associating native controls and their implementations
 
@@ -490,6 +496,7 @@ protected :
     wxWindowMac*        m_wxPeer;
     bool                m_needsFocusRect;
     bool                m_needsFrame;
+    bool                m_shouldSendEvents;
 
     DECLARE_ABSTRACT_CLASS(wxWidgetImpl)
 };
index 3cdb19e247a219aadbc2e6fa666c3649d6b0d929..a6c9e9b7c47883a0898f0ff3f3ba24a18a6b4bc3 100644 (file)
@@ -46,7 +46,7 @@
 {
     wxUnusedVar(aNotification);
     wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
-    if ( impl )
+    if ( impl && impl->ShouldSendEvents() )
     {
         wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
         if ( wxpeer ) {
@@ -62,7 +62,7 @@
 {
     wxUnusedVar(notification);
     wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
-    if ( impl )
+    if ( impl && impl->ShouldSendEvents())
     {
         wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
         if ( wxpeer ) {
@@ -95,7 +95,9 @@ int wxNSComboBoxControl::GetSelectedItem() const
 void wxNSComboBoxControl::SetSelectedItem(int item)
 {
     wxASSERT_MSG(item >= 0 && item < [m_comboBox numberOfItems], "Inavlid item index.");
+    SendEvents(false);
     [m_comboBox selectItemAtIndex: item];
+    SendEvents(true);
 }
 
 int wxNSComboBoxControl::GetNumberOfItems() const
@@ -110,12 +112,16 @@ void wxNSComboBoxControl::InsertItem(int pos, const wxString& item)
 
 void wxNSComboBoxControl::RemoveItem(int pos)
 {
+    SendEvents(false);
     [m_comboBox removeItemAtIndex:pos];
+    SendEvents(true);
 }
 
 void wxNSComboBoxControl::Clear()
 {
+    SendEvents(false);
     [m_comboBox removeAllItems];
+    SendEvents(true);
 }
 
 wxString wxNSComboBoxControl::GetStringAtIndex(int pos) const
index b091cbcab5b459db8f0873d2b0c5d61d7f48e3de..0eeb0df5269edd1347ae9904eaf739c32698c2b7 100644 (file)
@@ -2464,6 +2464,7 @@ wxWidgetImpl::wxWidgetImpl( wxWindowMac* peer , bool isRootControl )
     Init();
     m_isRootControl = isRootControl;
     m_wxPeer = peer;
+    m_shouldSendEvents = true;
 }
 
 wxWidgetImpl::wxWidgetImpl()