X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/df336b7f251b1df65c27d761beb9fff7cdf34e9a..739e366ac91d526da389d01bb230cb628b16450a:/src/gtk1/choice.cpp diff --git a/src/gtk1/choice.cpp b/src/gtk1/choice.cpp index 5d129bb5af..4edcdc8b94 100644 --- a/src/gtk1/choice.cpp +++ b/src/gtk1/choice.cpp @@ -18,8 +18,7 @@ #include "wx/choice.h" -#include -#include +#include "wx/gtk/private.h" //----------------------------------------------------------------------------- // idle system @@ -144,7 +143,7 @@ void wxChoice::DoSetItemClientData( int n, void* clientData ) { wxCHECK_RET( m_widget != NULL, wxT("invalid choice control") ); - wxNode *node = m_clientList.Nth( n ); + wxNode *node = m_clientList.Item( n ); wxCHECK_RET( node, wxT("invalid index in wxChoice::DoSetItemClientData") ); node->SetData( (wxObject*) clientData ); @@ -154,21 +153,20 @@ void* wxChoice::DoGetItemClientData( int n ) const { wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid choice control") ); - wxNode *node = m_clientList.Nth( n ); + wxNode *node = m_clientList.Item( n ); wxCHECK_MSG( node, NULL, wxT("invalid index in wxChoice::DoGetItemClientData") ); - return node->Data(); + return node->GetData(); } void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData ) { wxCHECK_RET( m_widget != NULL, wxT("invalid choice control") ); - wxNode *node = m_clientList.Nth( n ); + wxNode *node = m_clientList.Item( n ); wxCHECK_RET( node, wxT("invalid index in wxChoice::DoSetItemClientObject") ); - wxClientData *cd = (wxClientData*) node->Data(); - delete cd; + // wxItemContainer already deletes data for us node->SetData( (wxObject*) clientData ); } @@ -177,11 +175,11 @@ wxClientData* wxChoice::DoGetItemClientObject( int n ) const { wxCHECK_MSG( m_widget != NULL, (wxClientData*) NULL, wxT("invalid choice control") ); - wxNode *node = m_clientList.Nth( n ); + wxNode *node = m_clientList.Item( n ); wxCHECK_MSG( node, (wxClientData *)NULL, wxT("invalid index in wxChoice::DoGetItemClientObject") ); - return (wxClientData*) node->Data(); + return (wxClientData*) node->GetData(); } void wxChoice::Clear() @@ -197,11 +195,11 @@ void wxChoice::Clear() // destroy the data (due to Robert's idea of using wxList // and not wxList we can't just say // m_clientList.DeleteContents(TRUE) - this would crash! - wxNode *node = m_clientList.First(); + wxNode *node = m_clientList.GetFirst(); while ( node ) { - delete (wxClientData *)node->Data(); - node = node->Next(); + delete (wxClientData *)node->GetData(); + node = node->GetNext(); } } m_clientList.Clear(); @@ -210,9 +208,31 @@ void wxChoice::Clear() m_strings->Clear(); } -void wxChoice::Delete( int WXUNUSED(n) ) +void wxChoice::Delete( int n ) { - wxFAIL_MSG( wxT("wxChoice:Delete not implemented") ); + wxCHECK_RET( m_widget != NULL, wxT("invalid choice") ); + + // VZ: apparently GTK+ doesn't have a built-in function to do it (not even + // in 2.0), hence this dump implementation - still better than nothing + int i, + count = GetCount(); + + wxCHECK_RET( n >= 0 && n < count, _T("invalid index in wxChoice::Delete") ); + + wxArrayString items; + items.Alloc(count); + for ( i = 0; i < count; i++ ) + { + if ( i != n ) + items.Add(GetString(i)); + } + + Clear(); + + for ( i = 0; i < count - 1; i++ ) + { + Append(items[i]); + } } int wxChoice::FindString( const wxString &string ) const @@ -229,16 +249,23 @@ 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") ); + +#ifdef __WXGTK20__ + wxString tmp( wxGTK_CONV_BACK( gtk_label_get_text( label) ) ); +#else + wxString tmp( label->label ); +#endif + if (string == tmp) + return count; - if (string == wxString(label->label,*wxConvCurrent)) - return count; - - child = child->next; - count++; + child = child->next; + count++; } return -1; @@ -247,9 +274,15 @@ int wxChoice::FindString( const wxString &string ) const int wxChoice::GetSelection() const { wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid choice") ); + +#ifdef __WXGTK20__ + return gtk_option_menu_get_history( GTK_OPTION_MENU(m_widget) ); + +#else GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) ); int count = 0; + GList *child = menu_shell->children; while (child) { @@ -260,6 +293,7 @@ int wxChoice::GetSelection() const } return -1; +#endif } void wxChoice::SetString( int WXUNUSED(n), const wxString& WXUNUSED(string) ) @@ -282,12 +316,18 @@ 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") ); - return wxString(label->label,*wxConvCurrent); +#ifdef __WXGTK20__ + return wxString( wxGTK_CONV_BACK( gtk_label_get_text( label) ) ); +#else + return wxString( label->label ); +#endif } child = child->next; count++; @@ -337,8 +377,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 ); @@ -348,7 +390,7 @@ void wxChoice::ApplyWidgetStyle() size_t wxChoice::GtkAppendHelper(GtkWidget *menu, const wxString& item) { - GtkWidget *menu_item = gtk_menu_item_new_with_label( item.mbc_str() ); + GtkWidget *menu_item = gtk_menu_item_new_with_label( wxGTK_CONV( item ) ); size_t index; if ( m_strings ) @@ -406,13 +448,11 @@ wxSize wxChoice::DoGetBestSize() const ret.x = 0; if ( m_widget ) { - GdkFont *font = m_font.GetInternalFont(); - - wxCoord width; + int width; size_t count = GetCount(); for ( size_t n = 0; n < count; n++ ) { - width = (wxCoord)gdk_string_width(font, GetString(n).mbc_str()); + GetTextExtent( GetString(n), &width, NULL, NULL, NULL, &m_font ); if ( width > ret.x ) ret.x = width; } @@ -434,7 +474,8 @@ wxSize wxChoice::DoGetBestSize() const if ( ret.x < 80 ) ret.x = 80; - ret.y = 16 + gdk_char_height( m_widget->style->font, 'H' ); + ret.y = 16 + GetCharHeight(); + return ret; }