]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/combobox.cpp
Applied patch for PNG8 alpha mask.
[wxWidgets.git] / src / gtk / combobox.cpp
index ab4f7bead8dac46ed627e8b2146d85f7ba9f19a6..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;
@@ -262,6 +283,8 @@ int wxComboBox::DoAppend( const wxString &item )
 
     EnableEvents();
 
+    InvalidateBestSize();
+
     return count - 1;
 }
 
@@ -306,6 +329,8 @@ int wxComboBox::DoInsert( const wxString &item, int pos )
     m_clientObjectList.Insert( pos, (wxObject*) NULL );
 
     EnableEvents();
+    
+    InvalidateBestSize();
 
     return pos;
 }
@@ -371,6 +396,8 @@ void wxComboBox::Clear()
     m_clientDataList.Clear();
 
     EnableEvents();
+
+    InvalidateBestSize();
 }
 
 void wxComboBox::Delete( int n )
@@ -406,6 +433,8 @@ void wxComboBox::Delete( int n )
         m_clientDataList.Erase( node );
     
     EnableEvents();
+    
+    InvalidateBestSize();
 }
 
 void wxComboBox::SetString(int n, const wxString &text)
@@ -425,6 +454,8 @@ void wxComboBox::SetString(int n, const wxString &text)
     {
         wxFAIL_MSG( wxT("wxComboBox: wrong index") );
     }
+    
+    InvalidateBestSize();
 }
 
 int wxComboBox::FindString( const wxString &item ) const
@@ -587,6 +618,8 @@ void wxComboBox::SetValue( const wxString& value )
     wxString tmp = wxT("");
     if (!value.IsNull()) tmp = value;
     gtk_entry_set_text( GTK_ENTRY(entry), wxGTK_CONV( tmp ) );
+    
+    InvalidateBestSize();
 }
 
 void wxComboBox::Copy()
@@ -719,15 +752,16 @@ void wxComboBox::EnableEvents()
 
 void wxComboBox::OnSize( wxSizeEvent &event )
 {
-    event.Skip();
+    // NB: In some situations (e.g. on non-first page of a wizard, if the
+    //     size used is default size), GtkCombo widget is resized correctly,
+    //     but it's look is not updated, it's rendered as if it was much wider.
+    //     No other widgets are affected, so it looks like a bug in GTK+.
+    //     Manually requesting resize calculation (as gtk_pizza_set_size does)
+    //     fixes it.
+    if (GTK_WIDGET_VISIBLE(m_widget))
+        gtk_widget_queue_resize(m_widget);
 
-#if 0
-    int w = 21;
-    gtk_widget_set_usize( GTK_COMBO(m_widget)->entry, m_width-w-1, m_height );
-
-    gtk_widget_set_uposition( GTK_COMBO(m_widget)->button, m_x+m_width-w, m_y );
-    gtk_widget_set_usize( GTK_COMBO(m_widget)->button, w, m_height );
-#endif // 0
+    event.Skip();
 }
 
 void wxComboBox::DoApplyWidgetStyle(GtkRcStyle *style)
@@ -767,7 +801,6 @@ wxSize wxComboBox::DoGetBestSize() const
 
     // we know better our horizontal extent: it depends on the longest string
     // in the combobox
-    ret.x = 0;
     if ( m_widget )
     {
         int width;