X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/071a2d78147df569d57b1ef138ab126a586b594d..7b1279006496ba3251a755bcef91301ad107bb78:/src/gtk/choice.cpp diff --git a/src/gtk/choice.cpp b/src/gtk/choice.cpp index 97ea9be8b9..103ebf3901 100644 --- a/src/gtk/choice.cpp +++ b/src/gtk/choice.cpp @@ -12,12 +12,13 @@ #pragma implementation "choice.h" #endif -#include "wx/choice.h" +#include "wx/defs.h" #if wxUSE_CHOICE -#include -#include +#include "wx/choice.h" + +#include "wx/gtk/private.h" //----------------------------------------------------------------------------- // idle system @@ -90,8 +91,6 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id, m_widget = gtk_option_menu_new(); - SetSizeOrDefault( size ); - if ( style & wxCB_SORT ) { // if our m_strings != NULL, DoAppend() will check for it and insert @@ -112,9 +111,12 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id, PostCreation(); + SetFont( parent->GetFont() ); + + SetBestSize(size); + SetBackgroundColour( parent->GetBackgroundColour() ); SetForegroundColour( parent->GetForegroundColour() ); - SetFont( parent->GetFont() ); Show( TRUE ); @@ -226,16 +228,18 @@ int wxChoice::FindString( const wxString &string ) const { GtkBin *bin = GTK_BIN( child->data ); GtkLabel *label = (GtkLabel *) NULL; - if (bin->child) label = GTK_LABEL(bin->child); - if (!label) label = GTK_LABEL( GTK_BUTTON(m_widget)->child ); + if (bin->child) + label = GTK_LABEL(bin->child); + if (!label) + label = GTK_LABEL( BUTTON_CHILD(m_widget) ); wxASSERT_MSG( label != NULL , wxT("wxChoice: invalid label") ); - if (string == wxString(label->label,*wxConvCurrent)) - return count; + if (string == wxString(label->label,*wxConvCurrent)) + return count; - child = child->next; - count++; + child = child->next; + count++; } return -1; @@ -279,8 +283,10 @@ wxString wxChoice::GetString( int n ) const if (count == n) { GtkLabel *label = (GtkLabel *) NULL; - if (bin->child) label = GTK_LABEL(bin->child); - if (!label) label = GTK_LABEL( GTK_BUTTON(m_widget)->child ); + if (bin->child) + label = GTK_LABEL(bin->child); + if (!label) + label = GTK_LABEL( BUTTON_CHILD(m_widget) ); wxASSERT_MSG( label != NULL , wxT("wxChoice: invalid label") ); @@ -334,8 +340,10 @@ void wxChoice::ApplyWidgetStyle() GtkBin *bin = GTK_BIN( child->data ); GtkWidget *label = (GtkWidget *) NULL; - if (bin->child) label = bin->child; - if (!label) label = GTK_BUTTON(m_widget)->child; + if (bin->child) + label = bin->child; + if (!label) + label = BUTTON_CHILD(m_widget); gtk_widget_set_style( label, m_widgetStyle ); @@ -396,7 +404,45 @@ size_t wxChoice::GtkAppendHelper(GtkWidget *menu, const wxString& item) wxSize wxChoice::DoGetBestSize() const { - return wxSize(80, 26); + wxSize ret( wxControl::DoGetBestSize() ); + + // we know better our horizontal extent: it depends on the longest string + // we have + ret.x = 0; + if ( m_widget ) + { + GdkFont *font = m_font.GetInternalFont(); + + wxCoord width; + size_t count = GetCount(); + 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; + } + + // add extra for the choice "=" button + + // VZ: I don't know how to get the right value, it seems to be in + // GtkOptionMenuProps struct from gtkoptionmenu.c but we can't get + // to it - maybe we can use gtk_option_menu_size_request() for this + // somehow? + // + // This default value works only for the default GTK+ theme (i.e. + // no theme at all) (FIXME) + static const int widthChoiceIndicator = 35; + ret.x += widthChoiceIndicator; + } + + // but not less than the minimal width + if ( ret.x < 80 ) + ret.x = 80; + + ret.y = 16 + gdk_char_height(GET_STYLE_FONT( m_widget->style ), 'H'); + + return ret; } -#endif +#endif // wxUSE_CHOICE +