Fix regression caused by r76974 (inserting first choice item to wxEnumProperty).

This is a modified way of handling insertion of the first choice item to wxEnumProperty. Previous method based on special value (wxNOT_FOUND) used to indicate empty collection caused regression in wxPGProperty::DeleteChoice(). Currently, the size of the collection is checked directly in wxPGProperty::InsertChoice().

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76977 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Artur Wieczorek 2014-08-02 21:19:41 +00:00
parent 220a8d1ac2
commit 7ef4c2d90b
2 changed files with 12 additions and 13 deletions

View File

@ -1898,20 +1898,19 @@ int wxPGProperty::InsertChoice( const wxString& label, int index, int value )
wxPropertyGrid* pg = GetGrid(); wxPropertyGrid* pg = GetGrid();
const int sel = GetChoiceSelection(); const int sel = GetChoiceSelection();
if ( index == wxNOT_FOUND ) int newSel = sel;
index = m_choices.GetCount();
int newSel; const int numChoices = m_choices.GetCount();
if ( sel == wxNOT_FOUND ) if ( index == wxNOT_FOUND )
newSel = 0; index = numChoices;
else if ( index <= sel )
newSel = sel + 1; if ( numChoices > 0 && index <= sel )
else newSel++;
newSel = sel;
m_choices.Insert(label, index, value); m_choices.Insert(label, index, value);
// Set new selection if it was modified
if ( sel != newSel ) // or if the first element was added.
if ( sel != newSel || numChoices == 0 )
SetChoiceSelection(newSel); SetChoiceSelection(newSel);
if ( pg && this == pg->GetSelection() ) if ( pg && this == pg->GetSelection() )

View File

@ -1102,7 +1102,7 @@ WX_PG_IMPLEMENT_PROPERTY_CLASS(wxEnumProperty, wxPGProperty,
wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, const wxChar* const* labels, wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, const wxChar* const* labels,
const long* values, int value ) : wxPGProperty(label,name) const long* values, int value ) : wxPGProperty(label,name)
{ {
SetIndex(wxNOT_FOUND); SetIndex(0);
if ( labels ) if ( labels )
{ {
@ -1144,7 +1144,7 @@ wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name,
const wxArrayString& labels, const wxArrayInt& values, int value ) const wxArrayString& labels, const wxArrayInt& values, int value )
: wxPGProperty(label,name) : wxPGProperty(label,name)
{ {
SetIndex(wxNOT_FOUND); SetIndex(0);
if ( &labels && labels.size() ) if ( &labels && labels.size() )
{ {