X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0372d42ea50de251b381c22855b372a967bc04d9..e6ba38871f6cc5c02391c04e37e481d0428cef3f:/src/propgrid/property.cpp diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index fa7702ddbb..c083039124 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -16,6 +16,8 @@ #pragma hdrstop #endif +#if wxUSE_PROPGRID + #ifndef WX_PRECOMP #include "wx/defs.h" #include "wx/object.h" @@ -27,30 +29,14 @@ #include "wx/panel.h" #include "wx/dc.h" #include "wx/dcmemory.h" - #include "wx/button.h" #include "wx/pen.h" #include "wx/brush.h" - #include "wx/cursor.h" - #include "wx/dialog.h" #include "wx/settings.h" - #include "wx/msgdlg.h" - #include "wx/choice.h" - #include "wx/stattext.h" - #include "wx/scrolwin.h" - #include "wx/dirdlg.h" - #include "wx/layout.h" - #include "wx/sizer.h" - #include "wx/textdlg.h" - #include "wx/filedlg.h" - #include "wx/statusbr.h" #include "wx/intl.h" - #include "wx/frame.h" #endif #include -#include - #define PWC_CHILD_SUMMARY_LIMIT 16 // Maximum number of children summarized in a parent property's // value field. @@ -208,11 +194,16 @@ void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect, // Use choice cell? if ( column == 1 && (flags & Control) ) { - const wxPGCell* ccell = property->GetCurrentChoice(); - if ( ccell && - ( ccell->GetBitmap().IsOk() || ccell->GetFgCol().IsOk() || ccell->GetBgCol().IsOk() ) - ) - cell = ccell; + int selectedIndex = property->GetChoiceSelection(); + if ( selectedIndex != wxNOT_FOUND ) + { + const wxPGChoices& choices = property->GetChoices(); + const wxPGCell* ccell = &choices[selectedIndex]; + if ( ccell && + ( ccell->GetBitmap().IsOk() || ccell->GetFgCol().IsOk() || ccell->GetBgCol().IsOk() ) + ) + cell = ccell; + } } if ( cell ) @@ -774,22 +765,24 @@ bool wxPGProperty::StringToValue( wxVariant& variant, const wxString& text, int const wxPGProperty* child = Item(curChild); - wxVariant variant(child->GetValueRef()); - if ( child->StringToValue( variant, token, propagatedFlags ) ) + wxVariant oldChildValue = child->GetValue(); + wxVariant variant(oldChildValue); + bool stvRes = child->StringToValue( variant, token, propagatedFlags ); + if ( stvRes || (variant != oldChildValue) ) { - variant.SetName(child->GetBaseName()); - list.Append(variant); - changed = true; + if ( stvRes ) + changed = true; } else { // Failed, becomes unspecified - wxVariant variant2; - variant2.SetName(child->GetBaseName()); - list.Append(variant2); + variant.MakeNull(); changed = true; } + variant.SetName(child->GetBaseName()); + list.Append(variant); + curChild++; if ( curChild >= iMax ) break; @@ -1095,104 +1088,6 @@ void wxPGProperty::SetCell( int column, wxPGCell* cellObj ) m_cells[column] = cellObj; } -void wxPGProperty::SetChoiceSelection( int newValue, const wxPGChoiceInfo& choiceInfo ) -{ - // Changes value of a property with choices, but only - // works if the value type is long or string. - wxString ts = GetValue().GetType(); - - wxCHECK_RET( choiceInfo.m_choices, wxT("invalid choiceinfo") ); - - if ( ts == wxS("long") ) - { - SetValue( (long) newValue ); - } - else if ( ts == wxS("string") ) - { - SetValue( choiceInfo.m_choices->GetLabel(newValue) ); - } -} - - -wxString wxPGProperty::GetChoiceString( unsigned int index ) -{ - wxPGChoiceInfo ci; - GetChoiceInfo(&ci); - wxASSERT(ci.m_choices); - return ci.m_choices->GetLabel(index); -} - -int wxPGProperty::InsertChoice( const wxString& label, int index, int value ) -{ - wxPropertyGrid* pg = GetGrid(); - - wxPGChoiceInfo ci; - ci.m_choices = (wxPGChoices*) NULL; - int sel = GetChoiceInfo(&ci); - - if ( ci.m_choices ) - { - int newSel = sel; - - if ( index < 0 ) - index = ci.m_choices->GetCount(); - - if ( index <= sel ) - newSel++; - - ci.m_choices->Insert(label, index, value); - - if ( sel != newSel ) - SetChoiceSelection(newSel, ci); - - if ( this == pg->GetSelection() ) - GetEditorClass()->InsertItem(pg->GetEditorControl(),label,index); - - return index; - } - - return -1; -} - - -void wxPGProperty::DeleteChoice( int index ) -{ - wxPropertyGrid* pg = GetGrid(); - - wxPGChoiceInfo ci; - ci.m_choices = (wxPGChoices*) NULL; - int sel = GetChoiceInfo(&ci); - - if ( ci.m_choices ) - { - int newSel = sel; - - // Adjust current value - if ( sel == index ) - { - SetValueToUnspecified(); - newSel = 0; - } - else if ( index < sel ) - { - newSel--; - } - - ci.m_choices->RemoveAt(index); - - if ( sel != newSel ) - SetChoiceSelection(newSel, ci); - - if ( this == pg->GetSelection() ) - GetEditorClass()->DeleteItem(pg->GetEditorControl(), index); - } -} - -int wxPGProperty::GetChoiceInfo( wxPGChoiceInfo* WXUNUSED(info) ) -{ - return -1; -} - wxPGEditorDialogAdapter* wxPGProperty::GetEditorDialog() const { return NULL; @@ -1345,63 +1240,116 @@ wxValidator* wxPGProperty::DoGetValidator() const return (wxValidator*) NULL; } -wxPGChoices& wxPGProperty::GetChoices() +int wxPGProperty::InsertChoice( const wxString& label, int index, int value ) { - wxPGChoiceInfo choiceInfo; - choiceInfo.m_choices = NULL; - GetChoiceInfo(&choiceInfo); - return *choiceInfo.m_choices; + wxPropertyGrid* pg = GetGrid(); + int sel = GetChoiceSelection(); + + int newSel = sel; + + if ( index == wxNOT_FOUND ) + index = m_choices.GetCount(); + + if ( index <= sel ) + newSel++; + + m_choices.Insert(label, index, value); + + if ( sel != newSel ) + SetChoiceSelection(newSel); + + if ( this == pg->GetSelection() ) + GetEditorClass()->InsertItem(pg->GetEditorControl(),label,index); + + return index; } -const wxPGChoices& wxPGProperty::GetChoices() const + +void wxPGProperty::DeleteChoice( int index ) { - return (const wxPGChoices&) ((wxPGProperty*)this)->GetChoices(); + wxPropertyGrid* pg = GetGrid(); + + int sel = GetChoiceSelection(); + int newSel = sel; + + // Adjust current value + if ( sel == index ) + { + SetValueToUnspecified(); + newSel = 0; + } + else if ( index < sel ) + { + newSel--; + } + + m_choices.RemoveAt(index); + + if ( sel != newSel ) + SetChoiceSelection(newSel); + + if ( this == pg->GetSelection() ) + GetEditorClass()->DeleteItem(pg->GetEditorControl(), index); } -unsigned int wxPGProperty::GetChoiceCount() const +int wxPGProperty::GetChoiceSelection() const { - const wxPGChoices& choices = GetChoices(); - if ( &choices && choices.IsOk() ) - return choices.GetCount(); - return 0; + wxVariant value = GetValue(); + wxString valueType = value.GetType(); + int index = wxNOT_FOUND; + + if ( IsValueUnspecified() || !m_choices.GetCount() ) + return wxNOT_FOUND; + + if ( valueType == wxPG_VARIANT_TYPE_LONG ) + { + index = value.GetLong(); + } + else if ( valueType == wxPG_VARIANT_TYPE_STRING ) + { + index = m_choices.Index(value.GetString()); + } + else if ( valueType == wxPG_VARIANT_TYPE_BOOL ) + { + index = value.GetBool()? 1 : 0; + } + + return index; } -const wxPGChoiceEntry* wxPGProperty::GetCurrentChoice() const +void wxPGProperty::SetChoiceSelection( int newValue ) { - wxPGChoiceInfo ci; - ci.m_choices = (wxPGChoices*) NULL; - int index = ((wxPGProperty*)this)->GetChoiceInfo(&ci); - if ( index == -1 || !ci.m_choices || index >= (int)ci.m_choices->GetCount() ) - return NULL; + // Changes value of a property with choices, but only + // works if the value type is long or string. + wxString valueType = GetValue().GetType(); - return &(*ci.m_choices)[index]; + wxCHECK_RET( m_choices.IsOk(), wxT("invalid choiceinfo") ); + + if ( valueType == wxPG_VARIANT_TYPE_STRING ) + { + SetValue( m_choices.GetLabel(newValue) ); + } + else // if ( valueType == wxPG_VARIANT_TYPE_LONG ) + { + SetValue( (long) newValue ); + } } bool wxPGProperty::SetChoices( wxPGChoices& choices ) { - wxPGChoiceInfo ci; - ci.m_choices = (wxPGChoices*) NULL; + m_choices.Assign(choices); - // Unref existing - GetChoiceInfo(&ci); - if ( ci.m_choices ) { - ci.m_choices->Assign(choices); - - //if ( m_parent ) - { - // This may be needed to trigger some initialization - // (but don't do it if property is somewhat uninitialized) - wxVariant defVal = GetDefaultValue(); - if ( defVal.IsNull() ) - return false; - - SetValue(defVal); + // This may be needed to trigger some initialization + // (but don't do it if property is somewhat uninitialized) + wxVariant defVal = GetDefaultValue(); + if ( defVal.IsNull() ) + return false; - return true; - } + SetValue(defVal); } - return false; + + return true; } @@ -1432,18 +1380,6 @@ const wxPGEditor* wxPGProperty::GetEditorClass() const return editor; } - -// Privatizes set of choices -void wxPGProperty::SetChoicesExclusive() -{ - wxPGChoiceInfo ci; - ci.m_choices = (wxPGChoices*) NULL; - - GetChoiceInfo(&ci); - if ( ci.m_choices ) - ci.m_choices->SetExclusive(); -} - bool wxPGProperty::HasVisibleChildren() const { unsigned int i; @@ -2165,3 +2101,4 @@ void wxPGAttributeStorage::Set( const wxString& name, const wxVariant& value ) m_map[name] = data; } +#endif // wxUSE_PROPGRID