X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c83576039c3233069eea000078750a03755276da..3508c1432884472f0d24f0f98c0dc75ed35df297:/src/propgrid/props.cpp diff --git a/src/propgrid/props.cpp b/src/propgrid/props.cpp index 69b21d2580..336c55fdc5 100644 --- a/src/propgrid/props.cpp +++ b/src/propgrid/props.cpp @@ -4,7 +4,7 @@ // Author: Jaakko Salli // Modified by: // Created: 2005-05-14 -// RCS-ID: $Id: +// RCS-ID: $Id$ // Copyright: (c) Jaakko Salli // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// @@ -16,6 +16,8 @@ #pragma hdrstop #endif +#if wxUSE_PROPGRID + #ifndef WX_PRECOMP #include "wx/defs.h" #include "wx/object.h" @@ -44,18 +46,15 @@ #include "wx/sizer.h" #include "wx/textdlg.h" #include "wx/filedlg.h" - #include "wx/statusbr.h" #include "wx/intl.h" #endif -#include +#include "wx/filename.h" -#include +#include "wx/propgrid/propgrid.h" #define wxPG_CUSTOM_IMAGE_WIDTH 20 // for wxColourProperty etc. -#include - // ----------------------------------------------------------------------- // wxStringProperty @@ -80,22 +79,30 @@ void wxStringProperty::OnSetValue() if ( HasFlag(wxPG_PROP_COMPOSED_VALUE) ) { wxString s; - GenerateComposedValue(s, 0); + DoGenerateComposedValue(s); m_value = s; } } wxStringProperty::~wxStringProperty() { } -wxString wxStringProperty::GetValueAsString( int argFlags ) const +wxString wxStringProperty::ValueToString( wxVariant& value, + int argFlags ) const { - wxString s = m_value.GetString(); + wxString s = value.GetString(); if ( GetChildCount() && HasFlag(wxPG_PROP_COMPOSED_VALUE) ) { // Value stored in m_value is non-editable, non-full value if ( (argFlags & wxPG_FULL_VALUE) || (argFlags & wxPG_EDITABLE_VALUE) ) - GenerateComposedValue(s, argFlags); + { + // Calling this under incorrect conditions will fail + wxASSERT_MSG( argFlags & wxPG_VALUE_IS_CURRENT, + "Sorry, currently default wxPGProperty::ValueToString() " + "implementation only works if value is m_value." ); + + DoGenerateComposedValue(s, argFlags); + } return s; } @@ -113,7 +120,7 @@ bool wxStringProperty::StringToValue( wxVariant& variant, const wxString& text, if ( GetChildCount() && HasFlag(wxPG_PROP_COMPOSED_VALUE) ) return wxPGProperty::StringToValue(variant, text, argFlags); - if ( m_value.GetString() != text ) + if ( variant != text ) { variant = text; return true; @@ -150,21 +157,26 @@ wxIntProperty::wxIntProperty( const wxString& label, const wxString& name, wxIntProperty::wxIntProperty( const wxString& label, const wxString& name, const wxLongLong& value ) : wxPGProperty(label,name) { - SetValue(wxLongLongToVariant(value)); + SetValue(WXVARIANT(value)); } wxIntProperty::~wxIntProperty() { } -wxString wxIntProperty::GetValueAsString( int ) const +wxString wxIntProperty::ValueToString( wxVariant& value, + int WXUNUSED(argFlags) ) const { - if ( wxPGIsVariantType(m_value, long) ) - return wxString::Format(wxS("%li"),m_value.GetLong()); - - wxLongLong* ll = &wxLongLongFromVariant(m_value); - if ( ll ) - return ll->ToString(); + if ( value.GetType() == wxPG_VARIANT_TYPE_LONG ) + { + return wxString::Format(wxS("%li"),value.GetLong()); + } + else if ( value.GetType() == wxLongLong_VariantType ) + { + wxLongLong ll; + ll << value; + return ll.ToString(); + } - return wxEmptyString; + return wxEmptyString; } bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int argFlags ) const @@ -188,7 +200,7 @@ bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int int firstNonZeroPos = 0; - for ( ; i != iMax; i++ ) + for ( ; i != iMax; ++i ) { wxChar c = *i; if ( c != wxS('0') && c != wxS(' ') ) @@ -198,7 +210,8 @@ bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int wxString useText = text.substr(firstNonZeroPos, text.length() - firstNonZeroPos); - bool isPrevLong = wxPGIsVariantType(variant, long); + wxString variantType = variant.GetType(); + bool isPrevLong = variantType == wxPG_VARIANT_TYPE_LONG; wxLongLong_t value64 = 0; @@ -206,17 +219,27 @@ bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int ( value64 >= INT_MAX || value64 <= INT_MIN ) ) { - wxLongLong* _m_value64 = &wxLongLongFromVariant(m_value); - if ( isPrevLong || !_m_value64 || _m_value64->GetValue() != value64 ) + bool doChangeValue = isPrevLong; + + if ( !isPrevLong && variantType == wxLongLong_VariantType ) + { + wxLongLong oldValue; + oldValue << variant; + if ( oldValue.GetValue() != value64 ) + doChangeValue = true; + } + + if ( doChangeValue ) { - variant = wxLongLongToVariant(value64); + wxLongLong ll(value64); + variant << ll; return true; } } if ( useText.ToLong( &value32, 0 ) ) { - if ( !isPrevLong || m_value.GetLong() != value32 ) + if ( !isPrevLong || variant != value32 ) { variant = value32; return true; @@ -231,7 +254,7 @@ bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int bool wxIntProperty::IntToValue( wxVariant& variant, int value, int WXUNUSED(argFlags) ) const { - if ( !wxPGIsVariantType(variant, long) || variant.GetLong() != value ) + if ( variant.GetType() != wxPG_VARIANT_TYPE_LONG || variant != (long)value ) { variant = (long)value; return true; @@ -267,7 +290,9 @@ bool wxIntProperty::DoValidation( const wxPGProperty* property, wxLongLong_t& va if ( value < min ) { if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ) - pValidationInfo->m_failureMessage = wxString::Format(_("Value must be %lld or higher"),min); + pValidationInfo->SetFailureMessage( + wxString::Format(_("Value must be %lld or higher"),min) + ); else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE ) value = min; else @@ -281,7 +306,9 @@ bool wxIntProperty::DoValidation( const wxPGProperty* property, wxLongLong_t& va if ( value > max ) { if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ) - pValidationInfo->m_failureMessage = wxString::Format(_("Value must be %lld or higher"),min); + pValidationInfo->SetFailureMessage( + wxString::Format(_("Value must be %lld or higher"),min) + ); else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE ) value = max; else @@ -365,27 +392,33 @@ wxUIntProperty::wxUIntProperty( const wxString& label, const wxString& name, const wxULongLong& value ) : wxPGProperty(label,name) { Init(); - SetValue(wxULongLongToVariant(value)); + SetValue(WXVARIANT(value)); } wxUIntProperty::~wxUIntProperty() { } -wxString wxUIntProperty::GetValueAsString( int ) const +wxString wxUIntProperty::ValueToString( wxVariant& value, + int WXUNUSED(argFlags) ) const { size_t index = m_base + m_prefix; if ( index >= wxPG_UINT_TEMPLATE_MAX ) index = wxPG_BASE_DEC; - if ( wxPGIsVariantType(m_value, long) ) - return wxString::Format(gs_uintTemplates32[index],(unsigned long)m_value.GetLong()); - else - return wxString::Format(gs_uintTemplates64[index],wxULongLongFromVariant(m_value).GetValue()); + if ( value.GetType() == wxPG_VARIANT_TYPE_LONG ) + { + return wxString::Format(gs_uintTemplates32[index], (unsigned long)value.GetLong()); + } + + wxULongLong ull; + ull << value; + + return wxString::Format(gs_uintTemplates64[index], ull.GetValue()); } bool wxUIntProperty::StringToValue( wxVariant& variant, const wxString& text, int WXUNUSED(argFlags) ) const { - //long unsigned value32 = 0; - bool isPrevLong = wxPGIsVariantType(variant, long); + wxString variantType = variant.GetType(); + bool isPrevLong = variantType == wxPG_VARIANT_TYPE_LONG; if ( text.length() == 0 ) { @@ -404,17 +437,27 @@ bool wxUIntProperty::StringToValue( wxVariant& variant, const wxString& text, in { if ( value64 >= LONG_MAX ) { - wxULongLong* _m_value64 = &wxULongLongFromVariant(m_value); - if ( isPrevLong || !_m_value64 || _m_value64->GetValue() != value64 ) + bool doChangeValue = isPrevLong; + + if ( !isPrevLong && variantType == wxULongLong_VariantType ) { - variant = wxULongLongToVariant(value64); + wxULongLong oldValue; + oldValue << variant; + if ( oldValue.GetValue() != value64 ) + doChangeValue = true; + } + + if ( doChangeValue ) + { + wxULongLong ull(value64); + variant << ull; return true; } } else { unsigned long value32 = wxLongLong(value64).GetLo(); - if ( !isPrevLong || m_value.GetLong() != (long)value32 ) + if ( !isPrevLong || m_value != (long)value32 ) { variant = (long)value32; return true; @@ -427,7 +470,7 @@ bool wxUIntProperty::StringToValue( wxVariant& variant, const wxString& text, in bool wxUIntProperty::IntToValue( wxVariant& variant, int number, int WXUNUSED(argFlags) ) const { - if ( m_value != (long)number ) + if ( variant != (long)number ) { variant = (long)number; return true; @@ -459,7 +502,9 @@ bool wxUIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& valida wxPGVariantToULongLong(variant, &min); if ( ll < min ) { - validationInfo.m_failureMessage = wxString::Format(_("Value must be %llu or higher"),min); + validationInfo.SetFailureMessage( + wxString::Format(_("Value must be %llu or higher"),min) + ); return false; } } @@ -469,7 +514,9 @@ bool wxUIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& valida wxPGVariantToULongLong(variant, &max); if ( ll > max ) { - validationInfo.m_failureMessage = wxString::Format(_("Value must be %llu or less"),max); + validationInfo.SetFailureMessage( + wxString::Format(_("Value must be %llu or less"),max) + ); return false; } } @@ -559,7 +606,7 @@ void wxPropertyGrid::DoubleToString(wxString& target, wxString::const_iterator i = target.end() - 1; size_t new_len = target.length() - 1; - for ( ; i != target.begin(); i-- ) + for ( ; i != target.begin(); --i ) { if ( *i != wxS('0') ) break; @@ -575,13 +622,14 @@ void wxPropertyGrid::DoubleToString(wxString& target, } } -wxString wxFloatProperty::GetValueAsString( int argFlags ) const +wxString wxFloatProperty::ValueToString( wxVariant& value, + int argFlags ) const { wxString text; - if ( !m_value.IsNull() ) + if ( !value.IsNull() ) { wxPropertyGrid::DoubleToString(text, - m_value, + value, m_precision, !(argFlags & wxPG_FULL_VALUE), (wxString*) NULL); @@ -603,7 +651,7 @@ bool wxFloatProperty::StringToValue( wxVariant& variant, const wxString& text, i bool res = text.ToDouble(&value); if ( res ) { - if ( m_value != value ) + if ( variant != value ) { variant = value; return true; @@ -643,7 +691,9 @@ bool wxFloatProperty::DoValidation( const wxPGProperty* property, double& value, if ( value < min ) { if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ) - pValidationInfo->m_failureMessage = wxString::Format(_("Value must be %f or higher"),min); + pValidationInfo->SetFailureMessage( + wxString::Format(_("Value must be %f or higher"),min) + ); else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE ) value = min; else @@ -658,7 +708,9 @@ bool wxFloatProperty::DoValidation( const wxPGProperty* property, double& value, if ( value > max ) { if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE ) - pValidationInfo->m_failureMessage = wxString::Format(_("Value must be %f or less"),max); + pValidationInfo->SetFailureMessage( + wxString::Format(_("Value must be %f or less"),max) + ); else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE ) value = max; else @@ -706,16 +758,18 @@ const wxPGEditor* wxBoolProperty::DoGetEditorClass() const // Select correct editor control. #if wxPG_INCLUDE_CHECKBOX if ( !(m_flags & wxPG_PROP_USE_CHECKBOX) ) - return wxPG_EDITOR(Choice); - return wxPG_EDITOR(CheckBox); + return wxPGEditor_Choice; + return wxPGEditor_CheckBox; #else - return wxPG_EDITOR(Choice); + return wxPGEditor_Choice; #endif } wxBoolProperty::wxBoolProperty( const wxString& label, const wxString& name, bool value ) : wxPGProperty(label,name) { + m_choices.Assign(wxPGGlobalVars->m_boolChoices); + SetValue(wxPGVariant_Bool(value)); m_flags |= wxPG_PROP_USE_DCC; @@ -723,15 +777,16 @@ wxBoolProperty::wxBoolProperty( const wxString& label, const wxString& name, boo wxBoolProperty::~wxBoolProperty() { } -wxString wxBoolProperty::GetValueAsString( int argFlags ) const +wxString wxBoolProperty::ValueToString( wxVariant& value, + int argFlags ) const { - bool value = m_value.GetBool(); + bool boolValue = value.GetBool(); // As a fragment of composite string value, // make it a little more readable. if ( argFlags & wxPG_COMPOSITE_FRAGMENT ) { - if ( value ) + if ( boolValue ) { return m_label; } @@ -740,46 +795,36 @@ wxString wxBoolProperty::GetValueAsString( int argFlags ) const if ( argFlags & wxPG_UNEDITABLE_COMPOSITE_FRAGMENT ) return wxEmptyString; - const wxChar* notFmt; + wxString notFmt; if ( wxPGGlobalVars->m_autoGetTranslation ) notFmt = _("Not %s"); else - notFmt = wxT("Not %s"); + notFmt = wxS("Not %s"); - return wxString::Format(notFmt,m_label.c_str()); + return wxString::Format(notFmt.c_str(), m_label.c_str()); } } if ( !(argFlags & wxPG_FULL_VALUE) ) { - return wxPGGlobalVars->m_boolChoices[value?1:0].GetText(); + return wxPGGlobalVars->m_boolChoices[boolValue?1:0].GetText(); } wxString text; - if (value) text = wxS("true"); + if ( boolValue ) text = wxS("true"); else text = wxS("false"); return text; } -int wxBoolProperty::GetChoiceInfo( wxPGChoiceInfo* choiceinfo ) -{ - if ( IsValueUnspecified() ) - return -1; - - if ( choiceinfo ) - choiceinfo->m_choices = &wxPGGlobalVars->m_boolChoices; - return m_value.GetBool()?1:0; -} - bool wxBoolProperty::StringToValue( wxVariant& variant, const wxString& text, int WXUNUSED(argFlags) ) const { - int value = 0; + bool boolValue = false; if ( text.CmpNoCase(wxPGGlobalVars->m_boolChoices[1].GetText()) == 0 || text.CmpNoCase(wxS("true")) == 0 || text.CmpNoCase(m_label) == 0 ) - value = 1; + boolValue = true; if ( text.length() == 0 ) { @@ -787,11 +832,9 @@ bool wxBoolProperty::StringToValue( wxVariant& variant, const wxString& text, in return true; } - bool oldValue = m_value.GetBool(); - - if ( (oldValue && !value) || (!oldValue && value) ) + if ( variant != boolValue ) { - variant = wxPGVariant_Bool(value); + variant = wxPGVariant_Bool(boolValue); return true; } return false; @@ -800,9 +843,8 @@ bool wxBoolProperty::StringToValue( wxVariant& variant, const wxString& text, in bool wxBoolProperty::IntToValue( wxVariant& variant, int value, int ) const { bool boolValue = value ? true : false; - bool oldValue = m_value.GetBool(); - if ( oldValue != boolValue ) + if ( variant != boolValue ) { variant = wxPGVariant_Bool(boolValue); return true; @@ -836,33 +878,103 @@ bool wxBoolProperty::DoSetAttribute( const wxString& name, wxVariant& value ) } // ----------------------------------------------------------------------- -// wxBaseEnumProperty +// wxEnumProperty // ----------------------------------------------------------------------- -int wxBaseEnumProperty::ms_nextIndex = -2; +IMPLEMENT_DYNAMIC_CLASS(wxEnumProperty, wxPGProperty) + +WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxEnumProperty,long,Choice) + +wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, const wxChar** labels, + const long* values, int value ) : wxPGProperty(label,name) +{ + SetIndex(0); + + if ( labels ) + { + m_choices.Add(labels,values); + + if ( GetItemCount() ) + SetValue( (long)value ); + } +} + +wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, const wxChar** labels, + const long* values, wxPGChoices* choicesCache, int value ) + : wxPGProperty(label,name) +{ + SetIndex(0); + + wxASSERT( choicesCache ); + + if ( choicesCache->IsOk() ) + { + m_choices.Assign( *choicesCache ); + m_value = wxPGVariant_Zero; + } + else if ( labels ) + { + m_choices.Add(labels,values); + + if ( GetItemCount() ) + SetValue( (long)value ); + } +} + +wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, + const wxArrayString& labels, const wxArrayInt& values, int value ) + : wxPGProperty(label,name) +{ + SetIndex(0); + + if ( &labels && labels.size() ) + { + m_choices.Set(labels, values); -wxBaseEnumProperty::wxBaseEnumProperty( const wxString& label, const wxString& name ) + if ( GetItemCount() ) + SetValue( (long)value ); + } +} + +wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, + wxPGChoices& choices, int value ) : wxPGProperty(label,name) { - m_value = wxPGVariant_Zero; + m_choices.Assign( choices ); + + if ( GetItemCount() ) + SetValue( (long)value ); } -/** If has values array, then returns number at index with value - - otherwise just returns the value. -*/ -int wxBaseEnumProperty::GetIndexForValue( int value ) const +int wxEnumProperty::GetIndexForValue( int value ) const { + if ( !m_choices.IsOk() ) + return -1; + + int intVal = m_choices.Index(value); + if ( intVal >= 0 ) + return intVal; + return value; } -void wxBaseEnumProperty::OnSetValue() +wxEnumProperty::~wxEnumProperty () { - if ( wxPGIsVariantType(m_value, long) ) +} + +int wxEnumProperty::ms_nextIndex = -2; +int wxEnumProperty::ms_prevIndex = -1; + +void wxEnumProperty::OnSetValue() +{ + wxString variantType = m_value.GetType(); + + if ( variantType == wxPG_VARIANT_TYPE_LONG ) ValueFromInt_( m_value, m_value.GetLong(), wxPG_FULL_VALUE ); - else if ( wxPGIsVariantType(m_value, string) ) + else if ( variantType == wxPG_VARIANT_TYPE_STRING ) ValueFromString_( m_value, m_value.GetString(), 0 ); else - wxASSERT( false ); + wxFAIL; if ( ms_nextIndex != -2 ) { @@ -871,64 +983,55 @@ void wxBaseEnumProperty::OnSetValue() } } -bool wxBaseEnumProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& WXUNUSED(validationInfo) ) const +bool wxEnumProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& WXUNUSED(validationInfo) ) const { // Make sure string value is in the list, // unless property has string as preferred value type // To reduce code size, use conversion here as well - if ( wxPGIsVariantType(value, string) && + if ( value.GetType() == wxPG_VARIANT_TYPE_STRING && !this->IsKindOf(CLASSINFO(wxEditEnumProperty)) ) return ValueFromString_( value, value.GetString(), wxPG_PROPERTY_SPECIFIC ); return true; } -wxString wxBaseEnumProperty::GetValueAsString( int ) const +wxString wxEnumProperty::ValueToString( wxVariant& value, + int WXUNUSED(argFlags) ) const { - if ( wxPGIsVariantType(m_value, string) ) - return m_value.GetString(); + if ( value.GetType() == wxPG_VARIANT_TYPE_STRING ) + return value.GetString(); - if ( m_index >= 0 ) - { - int unusedVal; - const wxString* pstr = GetEntry( m_index, &unusedVal ); + int index = m_choices.Index(value.GetLong()); + if ( index < 0 ) + return wxEmptyString; - if ( pstr ) - return *pstr; - } - return wxEmptyString; + return m_choices.GetLabel(index); } -bool wxBaseEnumProperty::StringToValue( wxVariant& variant, const wxString& text, int argFlags ) const +bool wxEnumProperty::StringToValue( wxVariant& variant, const wxString& text, int argFlags ) const { return ValueFromString_( variant, text, argFlags ); } -bool wxBaseEnumProperty::IntToValue( wxVariant& variant, int intVal, int argFlags ) const +bool wxEnumProperty::IntToValue( wxVariant& variant, int intVal, int argFlags ) const { return ValueFromInt_( variant, intVal, argFlags ); } -bool wxBaseEnumProperty::ValueFromString_( wxVariant& value, const wxString& text, int argFlags ) const +bool wxEnumProperty::ValueFromString_( wxVariant& value, const wxString& text, int argFlags ) const { - size_t i = 0; - const wxString* entryLabel; - int entryValue; int useIndex = -1; long useValue = 0; - entryLabel = GetEntry(i, &entryValue); - while ( entryLabel ) + for ( unsigned int i=0; iIsOk() ) - { - m_choices.Assign( *choicesCache ); - m_value = wxPGVariant_Zero; - } - else if ( labels ) - { - m_choices.Add(labels,values); - - if ( GetItemCount() ) - SetValue( (long)value ); - } -} - -wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, - const wxArrayString& labels, const wxArrayInt& values, int value ) : wxBaseEnumProperty(label,name) -{ - SetIndex(0); - - if ( &labels && labels.size() ) - { - m_choices.Set(labels, values); - - if ( GetItemCount() ) - SetValue( (long)value ); - } -} - -wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, - wxPGChoices& choices, int value ) - : wxBaseEnumProperty(label,name) -{ - m_choices.Assign( choices ); - - if ( GetItemCount() ) - SetValue( (long)value ); -} - -int wxEnumProperty::GetIndexForValue( int value ) const -{ - if ( !m_choices.IsOk() ) - return -1; - - if ( m_choices.HasValues() ) - { - int intVal = m_choices.Index(value); - if ( intVal >= 0 ) - return intVal; - } - - return value; -} - -wxEnumProperty::~wxEnumProperty () -{ -} - -const wxString* wxEnumProperty::GetEntry( size_t index, int* pvalue ) const -{ - if ( m_choices.IsOk() && index < m_choices.GetCount() ) - { - int value = (int)index; - if ( m_choices.HasValue(index) ) - value = m_choices.GetValue(index); - - if ( pvalue ) - *pvalue = value; - - return &m_choices.GetLabel(index); - } - return (const wxString*) NULL; -} - -int wxEnumProperty::GetChoiceInfo( wxPGChoiceInfo* choiceinfo ) -{ - if ( choiceinfo ) - choiceinfo->m_choices = &m_choices; - - if ( !m_choices.IsOk() ) - return -1; - - return GetIndex(); -} - // ----------------------------------------------------------------------- // wxEditEnumProperty // ----------------------------------------------------------------------- @@ -1188,8 +1186,7 @@ WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxFlagsProperty,long,TextCtrl) void wxFlagsProperty::Init() { - SetFlag(wxPG_PROP_AGGREGATE); // This is must be done here to support flag props - // with inital zero children. + SetParentalType(wxPG_PROP_AGGREGATE); long value = m_value; @@ -1198,7 +1195,7 @@ void wxFlagsProperty::Init() // unsigned int i; - unsigned int prevChildCount = m_children.GetCount(); + unsigned int prevChildCount = m_children.size(); int oldSel = -1; if ( prevChildCount ) @@ -1214,7 +1211,7 @@ void wxFlagsProperty::Init() if ( selected ) { if ( selected->GetParent() == this ) - oldSel = selected->GetArrIndex(); + oldSel = selected->GetIndexInParent(); else if ( selected == this ) oldSel = -2; } @@ -1224,9 +1221,9 @@ void wxFlagsProperty::Init() // Delete old children for ( i=0; im_autoGetTranslation ) { - boolProp = new wxBoolProperty( ::wxGetTranslation( GetLabel(i) ), wxEmptyString, child_val ); + boolProp = new wxBoolProperty( ::wxGetTranslation(label), label, child_val ); } else #endif { - boolProp = new wxBoolProperty( GetLabel(i), wxEmptyString, child_val ); + boolProp = new wxBoolProperty( label, label, child_val ); } AddChild(boolProp); } @@ -1344,10 +1339,7 @@ void wxFlagsProperty::OnSetValue() const wxPGChoices& choices = m_choices; for ( i = 0; i < GetItemCount(); i++ ) { - if ( choices.HasValue(i) ) - fullFlags |= choices.GetValue(i); - else - fullFlags |= (1<SetFlag( wxPG_PROP_MODIFIED ); @@ -1386,24 +1375,22 @@ void wxFlagsProperty::OnSetValue() } } -wxString wxFlagsProperty::GetValueAsString( int ) const +wxString wxFlagsProperty::ValueToString( wxVariant& value, + int WXUNUSED(argFlags) ) const { wxString text; if ( !m_choices.IsOk() ) return text; - long flags = m_value; + long flags = value; unsigned int i; const wxPGChoices& choices = m_choices; for ( i = 0; i < GetItemCount(); i++ ) { int doAdd; - if ( choices.HasValue(i) ) - doAdd = ( flags & choices.GetValue(i) ); - else - doAdd = ( flags & (1<m_choices = &m_choices; - return -1; -} - // ----------------------------------------------------------------------- // wxDirProperty // ----------------------------------------------------------------------- -WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(wxDirProperty,wxLongStringProperty,const wxString&) +IMPLEMENT_DYNAMIC_CLASS(wxDirProperty, wxLongStringProperty) wxDirProperty::wxDirProperty( const wxString& name, const wxString& label, const wxString& value ) : wxLongStringProperty(name,label,value) { - m_flags |= wxPG_NO_ESCAPE; + m_flags |= wxPG_PROP_NO_ESCAPE; } + wxDirProperty::~wxDirProperty() { } wxValidator* wxDirProperty::DoGetValidator() const @@ -1541,19 +1516,24 @@ wxValidator* wxDirProperty::DoGetValidator() const bool wxDirProperty::OnButtonClick( wxPropertyGrid* propGrid, wxString& value ) { + // Update property value from editor, if necessary wxSize dlg_sz(300,400); + wxString dlgMessage(m_dlgMessage); + if ( dlgMessage.empty() ) + dlgMessage = _("Choose a directory:"); wxDirDialog dlg( propGrid, - m_dlgMessage.length() ? m_dlgMessage : wxString(_("Choose a directory:")), + dlgMessage, value, 0, #if !wxPG_SMALL_SCREEN propGrid->GetGoodEditorDialogPosition(this,dlg_sz), - dlg_sz ); + dlg_sz #else wxDefaultPosition, - wxDefaultSize ); + wxDefaultSize #endif + ); if ( dlg.ShowModal() == wxID_OK ) { @@ -1586,7 +1566,8 @@ bool wxPGFileDialogAdapter::DoShowDialog( wxPropertyGrid* propGrid, wxPGProperty if ( property->IsKindOf(CLASSINFO(wxFileProperty)) ) { fileProp = ((wxFileProperty*)property); - path = fileProp->m_filename.GetPath(); + wxFileName filename = fileProp->GetValue().GetString(); + path = filename.GetPath(); indFilter = fileProp->m_indFilter; if ( !path.length() && fileProp->m_basePath.length() ) @@ -1672,18 +1653,17 @@ void wxFileProperty::OnSetValue() { const wxString& fnstr = m_value.GetString(); - m_filename = fnstr; + wxFileName filename = fnstr; - if ( !m_filename.HasName() ) + if ( !filename.HasName() ) { m_value = wxPGVariant_EmptyString; - m_filename.Clear(); } // Find index for extension. if ( m_indFilter < 0 && fnstr.length() ) { - wxString ext = m_filename.GetExt(); + wxString ext = filename.GetExt(); int curind = 0; size_t pos = 0; size_t len = m_wildcard.length(); @@ -1720,29 +1700,44 @@ void wxFileProperty::OnSetValue() } } -wxString wxFileProperty::GetValueAsString( int argFlags ) const +wxFileName wxFileProperty::GetFileName() const { - // Always return empty string when name component is empty - wxString fullName = m_filename.GetFullName(); + wxFileName filename; + + if ( !m_value.IsNull() ) + filename = m_value.GetString(); + + return filename; +} + +wxString wxFileProperty::ValueToString( wxVariant& value, + int argFlags ) const +{ + wxFileName filename = value.GetString(); + + if ( !filename.HasName() ) + return wxEmptyString; + + wxString fullName = filename.GetFullName(); if ( !fullName.length() ) - return fullName; + return wxEmptyString; if ( argFlags & wxPG_FULL_VALUE ) { - return m_filename.GetFullPath(); + return filename.GetFullPath(); } else if ( m_flags & wxPG_PROP_SHOW_FULL_FILENAME ) { if ( m_basePath.Length() ) { - wxFileName fn2(m_filename); + wxFileName fn2(filename); fn2.MakeRelativeTo(m_basePath); return fn2.GetFullPath(); } - return m_filename.GetFullPath(); + return filename.GetFullPath(); } - return m_filename.GetFullName(); + return filename.GetFullName(); } wxPGEditorDialogAdapter* wxFileProperty::GetEditorDialog() const @@ -1752,9 +1747,11 @@ wxPGEditorDialogAdapter* wxFileProperty::GetEditorDialog() const bool wxFileProperty::StringToValue( wxVariant& variant, const wxString& text, int argFlags ) const { + wxFileName filename = variant.GetString(); + if ( (m_flags & wxPG_PROP_SHOW_FULL_FILENAME) || (argFlags & wxPG_FULL_VALUE) ) { - if ( m_filename != text ) + if ( filename != text ) { variant = text; return true; @@ -1762,9 +1759,9 @@ bool wxFileProperty::StringToValue( wxVariant& variant, const wxString& text, in } else { - if ( m_filename.GetFullName() != text ) + if ( filename.GetFullName() != text ) { - wxFileName fn = m_filename; + wxFileName fn = filename; fn.SetFullName(text); variant = fn.GetFullPath(); return true; @@ -1857,9 +1854,10 @@ wxLongStringProperty::wxLongStringProperty( const wxString& label, const wxStrin wxLongStringProperty::~wxLongStringProperty() {} -wxString wxLongStringProperty::GetValueAsString( int ) const +wxString wxLongStringProperty::ValueToString( wxVariant& value, + int WXUNUSED(argFlags) ) const { - return m_value; + return value; } bool wxLongStringProperty::OnEvent( wxPropertyGrid* propGrid, wxWindow* WXUNUSED(primary), @@ -1868,9 +1866,9 @@ bool wxLongStringProperty::OnEvent( wxPropertyGrid* propGrid, wxWindow* WXUNUSED if ( propGrid->IsMainButtonEvent(event) ) { // Update the value - PrepareValueForDialogEditing(propGrid); + wxVariant useValue = propGrid->GetUncommittedPropertyValue(); - wxString val1 = GetValueAsString(0); + wxString val1 = useValue.GetString(); wxString val_orig = val1; wxString value; @@ -1956,7 +1954,7 @@ bool wxLongStringProperty::DisplayEditorDialog( wxPGProperty* prop, wxPropertyGr bool wxLongStringProperty::StringToValue( wxVariant& variant, const wxString& text, int ) const { - if ( m_value != text ) + if ( variant != text ) { variant = text; return true; @@ -1982,7 +1980,7 @@ END_EVENT_TABLE() IMPLEMENT_ABSTRACT_CLASS(wxArrayEditorDialog, wxDialog) -#include +#include "wx/statline.h" // ----------------------------------------------------------------------- @@ -2066,6 +2064,7 @@ bool wxArrayEditorDialog::Create( wxWindow *parent, // On wxMAC the dialog shows incorrectly if style is not exactly wxCAPTION // FIXME: This should be only a temporary fix. #ifdef __WXMAC__ + wxUnusedVar(style); int useStyle = wxCAPTION; #else int useStyle = style; @@ -2380,9 +2379,23 @@ void wxArrayStringProperty::OnSetValue() GenerateValueAsString(); } -wxString wxArrayStringProperty::GetValueAsString( int WXUNUSED(argFlags) ) const +#define ARRSTRPROP_ARRAY_TO_STRING(STRING,ARRAY) \ + wxPropertyGrid::ArrayStringToString(STRING,ARRAY,wxS('"'),wxS('"'),1) + +wxString wxArrayStringProperty::ValueToString( wxVariant& WXUNUSED(value), + int argFlags ) const { - return m_display; + // + // If this is called from GetValueAsString(), return cached string + if ( argFlags & wxPG_VALUE_IS_CURRENT ) + { + return m_display; + } + + wxArrayString arr = m_value.GetArrayString(); + wxString s; + ARRSTRPROP_ARRAY_TO_STRING(s, arr); + return s; } // Converts wxArrayString to a string separated by delimeters and spaces. @@ -2397,16 +2410,13 @@ void wxPropertyGrid::ArrayStringToString( wxString& dst, const wxArrayString& sr unsigned int i; unsigned int itemCount = src.size(); - wxChar preas[2]; + wxChar preas[2] = { 0, 0 }; dst.Empty(); - if ( !preDelim ) - preas[0] = 0; - else if ( (flags & 1) ) + if ( flags & 1 ) { preas[0] = preDelim; - preas[1] = 0; pdr = wxS("\\"); pdr += preDelim; } @@ -2445,13 +2455,10 @@ void wxPropertyGrid::ArrayStringToString( wxString& dst, const wxArrayString& sr } } -#define ARRSTRPROP_ARRAY_TO_STRING(STRING,ARRAY) \ - wxPropertyGrid::ArrayStringToString(STRING,ARRAY,wxS('"'),wxS('"'),1); - void wxArrayStringProperty::GenerateValueAsString() { wxArrayString arr = m_value.GetArrayString(); - ARRSTRPROP_ARRAY_TO_STRING(m_display, arr) + ARRSTRPROP_ARRAY_TO_STRING(m_display, arr); } // Default implementation doesn't do anything. @@ -2470,7 +2477,7 @@ bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid* propGrid, const wxChar* cbt ) { // Update the value - PrepareValueForDialogEditing(propGrid); + wxVariant useValue = propGrid->GetUncommittedPropertyValue(); if ( !propGrid->EditorValidate() ) return false; @@ -2487,7 +2494,7 @@ bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid* propGrid, if ( strEdDlg ) strEdDlg->SetCustomButton(cbt, this); - dlg->SetDialogValue( wxVariant(m_value) ); + dlg->SetDialogValue( useValue ); dlg->Create(propGrid, wxEmptyString, m_label); #if !wxPG_SMALL_SCREEN @@ -2509,7 +2516,7 @@ bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid* propGrid, { wxArrayString actualValue = value.GetArrayString(); wxString tempStr; - ARRSTRPROP_ARRAY_TO_STRING(tempStr, actualValue) + ARRSTRPROP_ARRAY_TO_STRING(tempStr, actualValue); #if wxUSE_VALIDATORS if ( dialogValidator.DoValidate( propGrid, validator, tempStr ) ) #endif @@ -2602,3 +2609,4 @@ bool wxPGInDialogValidator::DoValidate( wxPropertyGrid* WXUNUSED(propGrid), // ----------------------------------------------------------------------- +#endif // wxUSE_PROPGRID