diff --git a/docs/changes.txt b/docs/changes.txt index 76070a7260..ce40ad753b 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -192,6 +192,7 @@ wxGTK: - fixed wxDC::Blit() to honour source DC's logical coordinates - implemented wxIdleEvent::RequestMore() for simple background tasks (unlike thread work) +- implemented wxChoice::Delete() wxHTML: diff --git a/docs/latex/wx/choice.tex b/docs/latex/wx/choice.tex index d09ec492a4..7f909cc8ae 100644 --- a/docs/latex/wx/choice.tex +++ b/docs/latex/wx/choice.tex @@ -119,6 +119,16 @@ Clears the strings from the choice item. Creates the choice for two-step construction. See \helpref{wxChoice::wxChoice}{wxchoiceconstr}. +\membersection{wxChoice::Delete}\label{wxchoicedelete} + +\func{void}{Delete}{\param{int }{n}} + +Deletes the item with the given index from the control. + +\wxheading{Parameters} + +\docparam{n}{The item to delete.} + \membersection{wxChoice::FindString}\label{wxchoicefindstring} \constfunc{int}{FindString}{\param{const wxString\& }{string}} diff --git a/src/gtk/choice.cpp b/src/gtk/choice.cpp index 103ebf3901..f62387d9b5 100644 --- a/src/gtk/choice.cpp +++ b/src/gtk/choice.cpp @@ -209,9 +209,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 diff --git a/src/gtk1/choice.cpp b/src/gtk1/choice.cpp index 103ebf3901..f62387d9b5 100644 --- a/src/gtk1/choice.cpp +++ b/src/gtk1/choice.cpp @@ -209,9 +209,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