X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e90c1d2a19361551eb07778280f22be3e759cf64..f22e0c3c3f90510f1a92ab148f20b2453e338626:/src/gtk/combobox.cpp diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index 74ca53348b..b8ed05b45f 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -18,8 +18,8 @@ #include "wx/settings.h" #include "wx/intl.h" -#include "gdk/gdk.h" -#include "gtk/gtk.h" +#include +#include //----------------------------------------------------------------------------- // idle system @@ -101,11 +101,21 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, m_needParent = TRUE; m_acceptsFocus = TRUE; - if (!PreCreation( parent, pos, size ) || + wxSize newSize = size, + bestSize = DoGetBestSize(); + + if (newSize.x == -1) + newSize.x = bestSize.x; + if (newSize.y == -1) + newSize.y = bestSize.y; + if (newSize.y > 30) + newSize.y = 30; + + if (!PreCreation( parent, pos, newSize ) || !CreateBase( parent, id, pos, size, style, validator, name )) { - wxFAIL_MSG( T("wxComboBox creation failed") ); - return FALSE; + wxFAIL_MSG( wxT("wxComboBox creation failed") ); + return FALSE; } m_widget = gtk_combo_new(); @@ -113,19 +123,12 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, // 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() ); @@ -180,7 +183,7 @@ wxComboBox::~wxComboBox() void wxComboBox::AppendCommon( const wxString &item ) { - wxCHECK_RET( m_widget != NULL, T("invalid combobox") ); + wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); GtkWidget *list = GTK_COMBO(m_widget)->list; @@ -228,7 +231,7 @@ void wxComboBox::Append( const wxString &item, wxClientData *clientData ) void wxComboBox::SetClientData( int n, void* clientData ) { - wxCHECK_RET( m_widget != NULL, T("invalid combobox") ); + wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); wxNode *node = m_clientDataList.Nth( n ); if (!node) return; @@ -238,7 +241,7 @@ void wxComboBox::SetClientData( int n, void* clientData ) void* wxComboBox::GetClientData( int n ) { - wxCHECK_MSG( m_widget != NULL, NULL, T("invalid combobox") ); + wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid combobox") ); wxNode *node = m_clientDataList.Nth( n ); if (!node) return NULL; @@ -248,7 +251,7 @@ void* wxComboBox::GetClientData( int n ) void wxComboBox::SetClientObject( int n, wxClientData* clientData ) { - wxCHECK_RET( m_widget != NULL, T("invalid combobox") ); + wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); wxNode *node = m_clientObjectList.Nth( n ); if (!node) return; @@ -261,7 +264,7 @@ void wxComboBox::SetClientObject( int n, wxClientData* clientData ) wxClientData* wxComboBox::GetClientObject( int n ) { - wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, T("invalid combobox") ); + wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, wxT("invalid combobox") ); wxNode *node = m_clientDataList.Nth( n ); if (!node) return (wxClientData*) NULL; @@ -271,7 +274,7 @@ wxClientData* wxComboBox::GetClientObject( int n ) void wxComboBox::Clear() { - wxCHECK_RET( m_widget != NULL, T("invalid combobox") ); + wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); GtkWidget *list = GTK_COMBO(m_widget)->list; gtk_list_clear_items( GTK_LIST(list), 0, Number() ); @@ -290,7 +293,7 @@ void wxComboBox::Clear() void wxComboBox::Delete( int n ) { - wxCHECK_RET( m_widget != NULL, T("invalid combobox") ); + wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); GtkList *listbox = GTK_LIST( GTK_COMBO(m_widget)->list ); @@ -298,7 +301,7 @@ void wxComboBox::Delete( int n ) if (!child) { - wxFAIL_MSG(T("wrong index")); + wxFAIL_MSG(wxT("wrong index")); return; } @@ -323,7 +326,7 @@ void wxComboBox::Delete( int n ) int wxComboBox::FindString( const wxString &item ) { - wxCHECK_MSG( m_widget != NULL, -1, T("invalid combobox") ); + wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") ); GtkWidget *list = GTK_COMBO(m_widget)->list; @@ -344,7 +347,7 @@ int wxComboBox::FindString( const wxString &item ) int wxComboBox::GetSelection() const { - wxCHECK_MSG( m_widget != NULL, -1, T("invalid combobox") ); + wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") ); GtkWidget *list = GTK_COMBO(m_widget)->list; @@ -366,7 +369,7 @@ int wxComboBox::GetSelection() const wxString wxComboBox::GetString( int n ) const { - wxCHECK_MSG( m_widget != NULL, T(""), T("invalid combobox") ); + wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid combobox") ); GtkWidget *list = GTK_COMBO(m_widget)->list; @@ -380,7 +383,7 @@ wxString wxComboBox::GetString( int n ) const } else { - wxFAIL_MSG( T("wxComboBox: wrong index") ); + wxFAIL_MSG( wxT("wxComboBox: wrong index") ); } return str; @@ -388,7 +391,7 @@ wxString wxComboBox::GetString( int n ) const wxString wxComboBox::GetStringSelection() const { - wxCHECK_MSG( m_widget != NULL, T(""), T("invalid combobox") ); + wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid combobox") ); GtkWidget *list = GTK_COMBO(m_widget)->list; @@ -400,14 +403,14 @@ wxString wxComboBox::GetStringSelection() const return tmp; } - wxFAIL_MSG( T("wxComboBox: no selection") ); + wxFAIL_MSG( wxT("wxComboBox: no selection") ); - return T(""); + return wxT(""); } int wxComboBox::Number() const { - wxCHECK_MSG( m_widget != NULL, 0, T("invalid combobox") ); + wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid combobox") ); GtkWidget *list = GTK_COMBO(m_widget)->list; @@ -419,7 +422,7 @@ int wxComboBox::Number() const void wxComboBox::SetSelection( int n ) { - wxCHECK_RET( m_widget != NULL, T("invalid combobox") ); + wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); DisableEvents(); @@ -431,7 +434,7 @@ void wxComboBox::SetSelection( int n ) void wxComboBox::SetStringSelection( const wxString &string ) { - wxCHECK_RET( m_widget != NULL, T("invalid combobox") ); + wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); int res = FindString( string ); if (res == -1) return; @@ -447,20 +450,20 @@ wxString wxComboBox::GetValue() const void wxComboBox::SetValue( const wxString& value ) { - wxCHECK_RET( m_widget != NULL, T("invalid combobox") ); + wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); GtkWidget *entry = GTK_COMBO(m_widget)->entry; - wxString tmp = T(""); + wxString tmp = wxT(""); if (!value.IsNull()) tmp = value; gtk_entry_set_text( GTK_ENTRY(entry), tmp.mbc_str() ); } void wxComboBox::Copy() { - wxCHECK_RET( m_widget != NULL, T("invalid combobox") ); + 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 ); @@ -469,10 +472,10 @@ void wxComboBox::Copy() void wxComboBox::Cut() { - wxCHECK_RET( m_widget != NULL, T("invalid combobox") ); + 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 ); @@ -481,10 +484,10 @@ void wxComboBox::Cut() void wxComboBox::Paste() { - wxCHECK_RET( m_widget != NULL, T("invalid combobox") ); + 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 ); @@ -493,7 +496,7 @@ void wxComboBox::Paste() void wxComboBox::SetInsertionPoint( long pos ) { - wxCHECK_RET( m_widget != NULL, T("invalid combobox") ); + wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); GtkWidget *entry = GTK_COMBO(m_widget)->entry; gtk_entry_set_position( GTK_ENTRY(entry), (int)pos ); @@ -501,7 +504,7 @@ void wxComboBox::SetInsertionPoint( long pos ) void wxComboBox::SetInsertionPointEnd() { - wxCHECK_RET( m_widget != NULL, T("invalid combobox") ); + wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); SetInsertionPoint( -1 ); } @@ -521,7 +524,7 @@ long wxComboBox::GetLastPosition() const void wxComboBox::Replace( long from, long to, const wxString& value ) { - wxCHECK_RET( m_widget != NULL, T("invalid combobox") ); + wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); // FIXME: not quite sure how to do this method right in multibyte mode GtkWidget *entry = GTK_COMBO(m_widget)->entry; @@ -533,7 +536,7 @@ void wxComboBox::Replace( long from, long to, const wxString& value ) void wxComboBox::Remove(long from, long to) { - wxCHECK_RET( m_widget != NULL, T("invalid combobox") ); + wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); GtkWidget *entry = GTK_COMBO(m_widget)->entry; gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to ); @@ -619,13 +622,13 @@ void wxComboBox::OnSize( wxSizeEvent &event ) { event.Skip(); - return; - +#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 } void wxComboBox::ApplyWidgetStyle() @@ -660,4 +663,10 @@ bool wxComboBox::IsOwnGtkWindow( GdkWindow *window ) (window == GTK_COMBO(m_widget)->button->window ) ); } +wxSize wxComboBox::DoGetBestSize() const +{ + // totally bogus - should measure the strings in the combo! + return wxSize(100, 26); +} + #endif