]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/combobox.cpp
Oh well, I'll just stuff in the rest of the Unicode changes I have made
[wxWidgets.git] / src / gtk / combobox.cpp
index 9550e296d3bfad476a2c491e4f14de61a7a3bcf0..98b3ba7b826e13921455ae5c9d733c47566ccae6 100644 (file)
@@ -11,7 +11,6 @@
 #pragma implementation "combobox.h"
 #endif
 
-
 #include "wx/combobox.h"
 
 #include <wx/intl.h>
@@ -48,11 +47,9 @@ gtk_combo_clicked_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
 
     wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
     event.SetInt( combo->GetSelection() );
-    event.SetString( copystring(combo->GetStringSelection()) );
+    event.SetString( combo->GetStringSelection() );
     event.SetEventObject( combo );
     combo->GetEventHandler()->ProcessEvent( event );
-
-    delete [] event.GetString();
 }
 
 //-----------------------------------------------------------------------------
@@ -63,11 +60,9 @@ static void
 gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
 {
     wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
-    event.SetString( copystring(combo->GetValue()) );
+    event.SetString( combo->GetValue() );
     event.SetEventObject( combo );
     combo->GetEventHandler()->ProcessEvent( event );
-
-    delete [] event.GetString();
 }
 
 //-----------------------------------------------------------------------------
@@ -314,14 +309,13 @@ int wxComboBox::FindString( const wxString &item )
     {
         GtkBin *bin = GTK_BIN( child->data );
         GtkLabel *label = GTK_LABEL( bin->child );
-        if (item == label->label) return count;
+        if (item == label->label)
+            return count;
         count++;
         child = child->next;
     }
 
-    wxFAIL_MSG( "wxComboBox: string not found" );
-
-    return -1;
+    return wxNOT_FOUND;
 }
 
 int wxComboBox::GetSelection() const
@@ -354,17 +348,20 @@ wxString wxComboBox::GetString( int n ) const
 
     GtkWidget *list = GTK_COMBO(m_widget)->list;
 
+    wxString str;
     GList *child = g_list_nth( GTK_LIST(list)->children, n );
     if (child)
     {
         GtkBin *bin = GTK_BIN( child->data );
         GtkLabel *label = GTK_LABEL( bin->child );
-        return label->label;
+        str = label->label;
+    }
+    else
+    {
+        wxFAIL_MSG( "wxComboBox: wrong index" );
     }
 
-    wxFAIL_MSG( "wxComboBox: wrong index" );
-
-    return "";
+    return str;
 }
 
 wxString wxComboBox::GetStringSelection() const
@@ -437,7 +434,7 @@ void wxComboBox::Copy()
     wxCHECK_RET( m_widget != NULL, "invalid combobox" );
 
     GtkWidget *entry = GTK_COMBO(m_widget)->entry;
-#if (GTK_MINOR_VERSION == 1)
+#if (GTK_MINOR_VERSION > 0)
     gtk_editable_copy_clipboard( GTK_EDITABLE(entry) );
 #else
     gtk_editable_copy_clipboard( GTK_EDITABLE(entry), 0 );
@@ -449,7 +446,7 @@ void wxComboBox::Cut()
     wxCHECK_RET( m_widget != NULL, "invalid combobox" );
 
     GtkWidget *entry = GTK_COMBO(m_widget)->entry;
-#if (GTK_MINOR_VERSION == 1)
+#if (GTK_MINOR_VERSION > 0)
     gtk_editable_cut_clipboard( GTK_EDITABLE(entry) );
 #else
     gtk_editable_cut_clipboard( GTK_EDITABLE(entry), 0 );
@@ -461,7 +458,7 @@ void wxComboBox::Paste()
     wxCHECK_RET( m_widget != NULL, "invalid combobox" );
 
     GtkWidget *entry = GTK_COMBO(m_widget)->entry;
-#if (GTK_MINOR_VERSION == 1)
+#if (GTK_MINOR_VERSION > 0)
     gtk_editable_paste_clipboard( GTK_EDITABLE(entry) );
 #else
     gtk_editable_paste_clipboard( GTK_EDITABLE(entry), 0 );
@@ -529,18 +526,40 @@ void wxComboBox::SetEditable( bool editable )
 
 void wxComboBox::OnChar( wxKeyEvent &event )
 {
-    // make Enter generate "selected" event if there is only one item in the
-    // combobox - without it, it's impossible to select it at all!
-    if ( (event.KeyCode() == WXK_RETURN) && (Number() == 0) )
+    if ( event.KeyCode() == WXK_RETURN )
     {
-        wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() );
-        event.SetInt( 0 );
-        event.SetString( copystring(GetValue()) );
-        event.SetEventObject( this );
-        GetEventHandler()->ProcessEvent( event );
+        wxString value = GetValue();
 
-        delete [] event.GetString();
+        if ( Number() == 0 )
+        {
+            // make Enter generate "selected" event if there is only one item
+            // in the combobox - without it, it's impossible to select it at
+            // all!
+            wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() );
+            event.SetInt( 0 );
+            event.SetString( value );
+            event.SetEventObject( this );
+            GetEventHandler()->ProcessEvent( event );
+        }
+        else
+        {
+            // add the item to the list if it's not there yet
+            if ( FindString(value) == wxNOT_FOUND )
+            {
+                Append(value);
+
+                // and generate the selected event for it
+                wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() );
+                event.SetInt( Number() - 1 );
+                event.SetString( value );
+                event.SetEventObject( this );
+                GetEventHandler()->ProcessEvent( event );
+            }
+            //else: do nothing, this will open the listbox
+        }
     }
+
+    event.Skip();
 }
 
 void wxComboBox::OnSize( wxSizeEvent &event )