]> git.saurik.com Git - wxWidgets.git/commitdiff
Add "GTK" prefix to wxChoice::{Dis,En}ableEvents() methods in wxGTK.
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 15 Oct 2010 23:46:32 +0000 (23:46 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 15 Oct 2010 23:46:32 +0000 (23:46 +0000)
This is more than a cosmetic change: adding "GTK" prefix in wxComboBox and not
doing it in wxChoice in r64436 broke the event generation for wxComboBox as it
didn't override wxChoice methods any longer but defined its own (useless) ones.

Using the same name for the methods in both classes notably fixes unexpected
event generation from wxComboBox::SetSelection().

Closes #12568.

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

include/wx/gtk/choice.h
src/gtk/choice.cpp
tests/controls/itemcontainertest.cpp
tests/controls/itemcontainertest.h

index e5da9b413d305cc3d79231af78105bcc78892801..70e93fd534231e47c14071fa2c7a55ab8b14a95d 100644 (file)
@@ -77,8 +77,8 @@ public:
     virtual void SetColumns(int n=1);
     virtual int GetColumns() const;
 
-    virtual void DisableEvents();
-    virtual void EnableEvents();
+    virtual void GTKDisableEvents();
+    virtual void GTKEnableEvents();
 
     static wxVisualAttributes
     GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
index 3932eed9121bde6917895f001f67ea4a6c2bfca0..462d9266ef65fa5edf943d13e0bc533299f8ece1 100644 (file)
@@ -168,7 +168,7 @@ void wxChoice::DoClear()
 {
     wxCHECK_RET( m_widget != NULL, wxT("invalid control") );
 
-    DisableEvents();
+    GTKDisableEvents();
 
     GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
     GtkTreeModel* model = gtk_combo_box_get_model( combobox );
@@ -179,7 +179,7 @@ void wxChoice::DoClear()
     if (m_strings)
         m_strings->Clear();
 
-    EnableEvents();
+    GTKEnableEvents();
 
     InvalidateBestSize();
 }
@@ -299,12 +299,12 @@ void wxChoice::SetSelection( int n )
 {
     wxCHECK_RET( m_widget != NULL, wxT("invalid control") );
 
-    DisableEvents();
+    GTKDisableEvents();
 
     GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
     gtk_combo_box_set_active( combobox, n );
 
-    EnableEvents();
+    GTKEnableEvents();
 }
 
 void wxChoice::SetColumns(int n)
@@ -321,13 +321,13 @@ int wxChoice::GetColumns() const
 }
 
 
-void wxChoice::DisableEvents()
+void wxChoice::GTKDisableEvents()
 {
     g_signal_handlers_block_by_func(m_widget,
                                 (gpointer) gtk_choice_changed_callback, this);
 }
 
-void wxChoice::EnableEvents()
+void wxChoice::GTKEnableEvents()
 {
     g_signal_handlers_unblock_by_func(m_widget,
                                 (gpointer) gtk_choice_changed_callback, this);
index b405e64a69ebde6ac6dcbc5fac893c99fa47420d..d5894c83d52b58f2e2d177f71637d036e48ab3a1 100644 (file)
@@ -14,6 +14,8 @@
     #include "wx/ctrlsub.h"
 #endif // WX_PRECOMP
 
+#include "wx/scopeguard.h"
+
 #include "itemcontainertest.h"
 
 void ItemContainerTestCase::Append()
@@ -243,3 +245,38 @@ void ItemContainerTestCase::SetString()
     CPPUNIT_ASSERT_EQUAL("", container->GetString(2));
 #endif
 }
+
+void ItemContainerTestCase::SetSelection()
+{
+    wxItemContainer * const container = GetContainer();
+
+    container->Append("first");
+    container->Append("second");
+
+    // This class is used to check that SetSelection() doesn't generate any
+    // events, as documented.
+    class CommandEventHandler : public wxEvtHandler
+    {
+    public:
+        virtual bool ProcessEvent(wxEvent& event)
+        {
+            CPPUNIT_ASSERT_MESSAGE
+            (
+                "unexpected command event from SetSelection",
+                !event.IsCommandEvent()
+            );
+
+            return wxEvtHandler::ProcessEvent(event);
+        }
+    } h;
+
+    wxWindow * const win = GetContainerWindow();
+    win->PushEventHandler(&h);
+    wxON_BLOCK_EXIT_OBJ1( *win, wxWindow::PopEventHandler, false );
+
+    container->SetSelection(0);
+    CPPUNIT_ASSERT_EQUAL( 0, container->GetSelection() );
+
+    container->SetSelection(1);
+    CPPUNIT_ASSERT_EQUAL( 1, container->GetSelection() );
+}
index 86d0801a5d1840899bd006966614989972793e31..3b152304d572d365936058c2af23b0f881c13b17 100644 (file)
@@ -39,6 +39,7 @@ protected:
         CPPUNIT_TEST( ClientData ); \
         CPPUNIT_TEST( VoidData ); \
         CPPUNIT_TEST( Set ); \
+        CPPUNIT_TEST( SetSelection ); \
         CPPUNIT_TEST( SetString )
 
     void Append();
@@ -49,6 +50,7 @@ protected:
     void ClientData();
     void VoidData();
     void Set();
+    void SetSelection();
     void SetString();
 
 private: