]> git.saurik.com Git - wxWidgets.git/commitdiff
Corrected wxComboBox::GetValue() after a
authorRobert Roebling <robert@roebling.de>
Wed, 8 Dec 2004 22:08:28 +0000 (22:08 +0000)
committerRobert Roebling <robert@roebling.de>
Wed, 8 Dec 2004 22:08:28 +0000 (22:08 +0000)
    selection has changed. Added test for
    that to the "widgets" sample.

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

include/wx/gtk/combobox.h
include/wx/gtk1/combobox.h
samples/widgets/combobox.cpp
src/gtk/combobox.cpp
src/gtk1/combobox.cpp

index c4c7bf3d891bf523729f06389ab778a958419492..0592f6f19364bc8e56493aeaa870e9f7003258b7 100644 (file)
@@ -121,7 +121,7 @@ public:
     void OnSize( wxSizeEvent &event );
     void OnChar( wxKeyEvent &event );
 
-    bool     m_alreadySent;
+    bool     m_ignoreNextUpdate:1;
     wxList   m_clientDataList;
     wxList   m_clientObjectList;
     int      m_prevSelection;
index c4c7bf3d891bf523729f06389ab778a958419492..0592f6f19364bc8e56493aeaa870e9f7003258b7 100644 (file)
@@ -121,7 +121,7 @@ public:
     void OnSize( wxSizeEvent &event );
     void OnChar( wxKeyEvent &event );
 
-    bool     m_alreadySent;
+    bool     m_ignoreNextUpdate:1;
     wxList   m_clientDataList;
     wxList   m_clientObjectList;
     int      m_prevSelection;
index 9bfdc111571af0a9d9fedce8f3963b03f6d655c5..72c4b023f123fbddc8d34dde7610d1ba98f8c063 100644 (file)
@@ -545,6 +545,8 @@ void ComboboxWidgetsPage::OnComboBox(wxCommandEvent& event)
     m_textDelete->SetValue(wxString::Format(_T("%ld"), sel));
 
     wxLogMessage(_T("Combobox item %ld selected"), sel);
+    
+    wxLogMessage(_T("Combobox GetValue(): %s"), m_combobox->GetValue().c_str() );
 }
 
 void ComboboxWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
index 7d42568e62683b26c985ae0dba8f665b3270c524..b72887da0c427a3dca9cccbdb27a49b4ef86a015 100644 (file)
@@ -39,6 +39,35 @@ extern bool g_isIdle;
 
 extern bool   g_blockEventsOnDrag;
 
+//-----------------------------------------------------------------------------
+//  "changed" - typing and list item matches get changed, select-child
+//              if it doesn't match an item then just get a single changed
+//-----------------------------------------------------------------------------
+
+static void
+gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
+{
+    if (g_isIdle) wxapp_install_idle_handler();
+
+    if (combo->m_ignoreNextUpdate)
+    { 
+        combo->m_ignoreNextUpdate = FALSE;
+        return;
+    }
+
+    if (!combo->m_hasVMT) return;
+
+    wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
+    event.SetString( combo->GetValue() );
+    event.SetEventObject( combo );
+    combo->GetEventHandler()->ProcessEvent( event );
+}
+
+static void
+gtk_dummy_callback(GtkEntry *WXUNUSED(entry), GtkCombo *WXUNUSED(combo))
+{
+}
+
 //-----------------------------------------------------------------------------
 // "select-child" - click/cursor get select-child, changed, select-child
 //-----------------------------------------------------------------------------
@@ -61,35 +90,27 @@ gtk_combo_select_child_callback( GtkList *WXUNUSED(list), GtkWidget *WXUNUSED(wi
     
     combo->m_prevSelection = curSelection;
 
+    // Quickly set the value of the combo box
+    // as GTK+ does that only AFTER the event
+    // is sent.
+    gtk_signal_disconnect_by_func( GTK_OBJECT(GTK_COMBO(combo->GetHandle())->entry),
+      GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)combo );
+    combo->SetValue( combo->GetStringSelection() );
+    gtk_signal_connect( GTK_OBJECT(GTK_COMBO(combo->GetHandle())->entry), "changed",
+      GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)combo );
+
     wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
     event.SetInt( curSelection );
     event.SetString( combo->GetStringSelection() );
     event.SetEventObject( combo );
     
     combo->GetEventHandler()->ProcessEvent( event );
-}
-
-//-----------------------------------------------------------------------------
-//  "changed" - typing and list item matches get changed, select-child
-//              if it doesn't match an item then just get a single changed
-//-----------------------------------------------------------------------------
-
-static void
-gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
-{
-    if (g_isIdle) wxapp_install_idle_handler();
-
-    if (!combo->m_hasVMT) return;
-
-    wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
-    event.SetString( combo->GetValue() );
-    event.SetEventObject( combo );
-    combo->GetEventHandler()->ProcessEvent( event );
-}
 
-static void
-gtk_dummy_callback(GtkEntry *WXUNUSED(entry), GtkCombo *WXUNUSED(combo))
-{
+    // Now send the event ourselves    
+    wxCommandEvent event2( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
+    event2.SetString( combo->GetValue() );
+    event2.SetEventObject( combo );
+    combo->GetEventHandler()->ProcessEvent( event2 );
 }
 
 //-----------------------------------------------------------------------------
@@ -122,7 +143,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
                          long style, const wxValidator& validator,
                          const wxString& name )
 {
-    m_alreadySent = FALSE;
+    m_ignoreNextUpdate = FALSE;
     m_needParent = TRUE;
     m_acceptsFocus = TRUE;
     m_prevSelection = 0;
index 7d42568e62683b26c985ae0dba8f665b3270c524..b72887da0c427a3dca9cccbdb27a49b4ef86a015 100644 (file)
@@ -39,6 +39,35 @@ extern bool g_isIdle;
 
 extern bool   g_blockEventsOnDrag;
 
+//-----------------------------------------------------------------------------
+//  "changed" - typing and list item matches get changed, select-child
+//              if it doesn't match an item then just get a single changed
+//-----------------------------------------------------------------------------
+
+static void
+gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
+{
+    if (g_isIdle) wxapp_install_idle_handler();
+
+    if (combo->m_ignoreNextUpdate)
+    { 
+        combo->m_ignoreNextUpdate = FALSE;
+        return;
+    }
+
+    if (!combo->m_hasVMT) return;
+
+    wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
+    event.SetString( combo->GetValue() );
+    event.SetEventObject( combo );
+    combo->GetEventHandler()->ProcessEvent( event );
+}
+
+static void
+gtk_dummy_callback(GtkEntry *WXUNUSED(entry), GtkCombo *WXUNUSED(combo))
+{
+}
+
 //-----------------------------------------------------------------------------
 // "select-child" - click/cursor get select-child, changed, select-child
 //-----------------------------------------------------------------------------
@@ -61,35 +90,27 @@ gtk_combo_select_child_callback( GtkList *WXUNUSED(list), GtkWidget *WXUNUSED(wi
     
     combo->m_prevSelection = curSelection;
 
+    // Quickly set the value of the combo box
+    // as GTK+ does that only AFTER the event
+    // is sent.
+    gtk_signal_disconnect_by_func( GTK_OBJECT(GTK_COMBO(combo->GetHandle())->entry),
+      GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)combo );
+    combo->SetValue( combo->GetStringSelection() );
+    gtk_signal_connect( GTK_OBJECT(GTK_COMBO(combo->GetHandle())->entry), "changed",
+      GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)combo );
+
     wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
     event.SetInt( curSelection );
     event.SetString( combo->GetStringSelection() );
     event.SetEventObject( combo );
     
     combo->GetEventHandler()->ProcessEvent( event );
-}
-
-//-----------------------------------------------------------------------------
-//  "changed" - typing and list item matches get changed, select-child
-//              if it doesn't match an item then just get a single changed
-//-----------------------------------------------------------------------------
-
-static void
-gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
-{
-    if (g_isIdle) wxapp_install_idle_handler();
-
-    if (!combo->m_hasVMT) return;
-
-    wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
-    event.SetString( combo->GetValue() );
-    event.SetEventObject( combo );
-    combo->GetEventHandler()->ProcessEvent( event );
-}
 
-static void
-gtk_dummy_callback(GtkEntry *WXUNUSED(entry), GtkCombo *WXUNUSED(combo))
-{
+    // Now send the event ourselves    
+    wxCommandEvent event2( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
+    event2.SetString( combo->GetValue() );
+    event2.SetEventObject( combo );
+    combo->GetEventHandler()->ProcessEvent( event2 );
 }
 
 //-----------------------------------------------------------------------------
@@ -122,7 +143,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
                          long style, const wxValidator& validator,
                          const wxString& name )
 {
-    m_alreadySent = FALSE;
+    m_ignoreNextUpdate = FALSE;
     m_needParent = TRUE;
     m_acceptsFocus = TRUE;
     m_prevSelection = 0;