#include "wx/settings.h"
#include "wx/intl.h"
-#include "gdk/gdk.h"
-#include "gtk/gtk.h"
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
//-----------------------------------------------------------------------------
// idle system
!CreateBase( parent, id, pos, size, style, validator, name ))
{
wxFAIL_MSG( wxT("wxComboBox creation failed") );
- return FALSE;
+ return FALSE;
}
m_widget = gtk_combo_new();
// make it more useable
gtk_combo_set_use_arrows_always(GTK_COMBO(m_widget), TRUE);
- wxSize newSize = size;
- if (newSize.x == -1)
- newSize.x = 100;
- if (newSize.y == -1)
- newSize.y = 26;
- SetSize( newSize.x, newSize.y );
-
GtkWidget *list = GTK_COMBO(m_widget)->list;
for (int i = 0; i < n; i++)
{
/* don't send first event, which GTK sends aways when
- inserting the first item */
+ inserting the first item */
m_alreadySent = TRUE;
GtkWidget *list_item = gtk_list_item_new_with_label( choices[i].mbc_str() );
gtk_signal_connect( GTK_OBJECT(GTK_COMBO(m_widget)->entry), "changed",
GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
+ wxSize size_best( DoGetBestSize() );
+ wxSize new_size( size );
+ if (new_size.x == -1)
+ new_size.x = size_best.x;
+ if (new_size.y == -1)
+ new_size.y = size_best.y;
+ if (new_size.y > size_best.y)
+ new_size.y = size_best.y;
+ if ((new_size.x != size.x) || (new_size.y != size.y))
+ SetSize( new_size.x, new_size.y );
+
SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOW ) );
SetForegroundColour( parent->GetForegroundColour() );
- SetFont( parent->GetFont() );
Show( TRUE );
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
-#if (GTK_MINOR_VERSION > 0)
+#if defined(__WXGTK13__) || (GTK_MINOR_VERSION > 0)
gtk_editable_copy_clipboard( GTK_EDITABLE(entry) );
#else
gtk_editable_copy_clipboard( GTK_EDITABLE(entry), 0 );
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
-#if (GTK_MINOR_VERSION > 0)
+#if defined(__WXGTK13__) || (GTK_MINOR_VERSION > 0)
gtk_editable_cut_clipboard( GTK_EDITABLE(entry) );
#else
gtk_editable_cut_clipboard( GTK_EDITABLE(entry), 0 );
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
-#if (GTK_MINOR_VERSION > 0)
+#if defined(__WXGTK13__) || (GTK_MINOR_VERSION > 0)
gtk_editable_paste_clipboard( GTK_EDITABLE(entry) );
#else
gtk_editable_paste_clipboard( GTK_EDITABLE(entry), 0 );
if ( FindString(value) == wxNOT_FOUND )
{
Append(value);
+ SetStringSelection(value);
// and generate the selected event for it
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() );
(window == GTK_COMBO(m_widget)->button->window ) );
}
+wxSize wxComboBox::DoGetBestSize() const
+{
+ wxSize ret( wxControl::DoGetBestSize() );
+
+ // we know better our horizontal extent: it depends on the longest string
+ // in the combobox
+ ret.x = 0;
+ if ( m_widget )
+ {
+ GdkFont *font = m_font.GetInternalFont();
+
+ wxCoord width;
+ size_t count = Number();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ width = (wxCoord)gdk_string_width(font, GetString(n).mbc_str());
+ if ( width > ret.x )
+ ret.x = width;
+ }
+ }
+
+ // empty combobox should have some reasonable default size too
+ if ( ret.x < 100 )
+ ret.x = 100;
+ return ret;
+}
+
#endif