]> git.saurik.com Git - wxWidgets.git/blobdiff - src/propgrid/props.cpp
simplify Enable()
[wxWidgets.git] / src / propgrid / props.cpp
index f179ca659252b0c9365c9dd8e5997f22f17f74b6..eee0cca8cf32413c34d901647ba235e46025088b 100644 (file)
@@ -134,7 +134,7 @@ bool wxStringProperty::DoSetAttribute( const wxString& name, wxVariant& value )
     if ( name == wxPG_STRING_PASSWORD )
     {
         m_flags &= ~(wxPG_PROP_PASSWORD);
     if ( name == wxPG_STRING_PASSWORD )
     {
         m_flags &= ~(wxPG_PROP_PASSWORD);
-        if ( wxPGVariantToInt(value) ) m_flags |= wxPG_PROP_PASSWORD;
+        if ( value.GetLong() ) m_flags |= wxPG_PROP_PASSWORD;
         RecreateEditor();
         return false;
     }
         RecreateEditor();
         return false;
     }
@@ -169,11 +169,10 @@ wxString wxIntProperty::ValueToString( wxVariant& value,
     {
         return wxString::Format(wxS("%li"),value.GetLong());
     }
     {
         return wxString::Format(wxS("%li"),value.GetLong());
     }
-    else if ( value.GetType() == wxLongLong_VariantType )
+    else if ( value.GetType() == wxPG_VARIANT_TYPE_LONGLONG )
     {
     {
-           wxLongLong ll;
-        ll << value;
-           return ll.ToString();
+        wxLongLong ll = value.GetLongLong();
+        return ll.ToString();
     }
 
     return wxEmptyString;
     }
 
     return wxEmptyString;
@@ -221,10 +220,9 @@ bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int
         {
             bool doChangeValue = isPrevLong;
 
         {
             bool doChangeValue = isPrevLong;
 
-            if ( !isPrevLong && variantType == wxLongLong_VariantType )
+            if ( !isPrevLong && variantType == wxPG_VARIANT_TYPE_LONGLONG )
             {
             {
-                wxLongLong oldValue;
-                oldValue << variant;
+                wxLongLong oldValue = variant.GetLongLong();
                 if ( oldValue.GetValue() != value64 )
                     doChangeValue = true;
             }
                 if ( oldValue.GetValue() != value64 )
                     doChangeValue = true;
             }
@@ -232,7 +230,7 @@ bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int
             if ( doChangeValue )
             {
                 wxLongLong ll(value64);
             if ( doChangeValue )
             {
                 wxLongLong ll(value64);
-                variant << ll;
+                variant = ll;
                 return true;
             }
         }
                 return true;
             }
         }
@@ -274,14 +272,14 @@ bool wxIntProperty::DoValidation( const wxPGProperty* property, wxLongLong_t& va
     variant = property->GetAttribute(wxPGGlobalVars->m_strMin);
     if ( !variant.IsNull() )
     {
     variant = property->GetAttribute(wxPGGlobalVars->m_strMin);
     if ( !variant.IsNull() )
     {
-        wxPGVariantToLongLong(variant, &min);
+        min = variant.GetLongLong().GetValue();
         minOk = true;
     }
 
     variant = property->GetAttribute(wxPGGlobalVars->m_strMax);
     if ( !variant.IsNull() )
     {
         minOk = true;
     }
 
     variant = property->GetAttribute(wxPGGlobalVars->m_strMax);
     if ( !variant.IsNull() )
     {
-        wxPGVariantToLongLong(variant, &max);
+        max = variant.GetLongLong().GetValue();
         maxOk = true;
     }
 
         maxOk = true;
     }
 
@@ -319,12 +317,12 @@ bool wxIntProperty::DoValidation( const wxPGProperty* property, wxLongLong_t& va
     return true;
 }
 
     return true;
 }
 
-bool wxIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const
+bool wxIntProperty::ValidateValue( wxVariant& value,
+                                   wxPGValidationInfo& validationInfo ) const
 {
 {
-    wxLongLong_t ll;
-    if ( wxPGVariantToLongLong(value, &ll) )
-        return DoValidation(this, ll, &validationInfo, wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE);
-    return true;
+    wxLongLong_t ll = value.GetLongLong().GetValue();
+    return DoValidation(this, ll, &validationInfo,
+                        wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE);
 }
 
 wxValidator* wxIntProperty::GetClassValidator()
 }
 
 wxValidator* wxIntProperty::GetClassValidator()
@@ -354,21 +352,21 @@ wxValidator* wxIntProperty::DoGetValidator() const
 
 #define wxPG_UINT_TEMPLATE_MAX 8
 
 
 #define wxPG_UINT_TEMPLATE_MAX 8
 
-static const wxChar* gs_uintTemplates32[wxPG_UINT_TEMPLATE_MAX] = {
+static const wxChar* const gs_uintTemplates32[wxPG_UINT_TEMPLATE_MAX] = {
     wxT("%x"),wxT("0x%x"),wxT("$%x"),
     wxT("%X"),wxT("0x%X"),wxT("$%X"),
     wxT("%u"),wxT("%o")
 };
 
     wxT("%x"),wxT("0x%x"),wxT("$%x"),
     wxT("%X"),wxT("0x%X"),wxT("$%X"),
     wxT("%u"),wxT("%o")
 };
 
-static const wxChar* gs_uintTemplates64[wxPG_UINT_TEMPLATE_MAX] = {
-    wxT("%") wxLongLongFmtSpec wxT("x"),
-    wxT("0x%") wxLongLongFmtSpec wxT("x"),
-    wxT("$%") wxLongLongFmtSpec wxT("x"),
-    wxT("%") wxLongLongFmtSpec wxT("X"),
-    wxT("0x%") wxLongLongFmtSpec wxT("X"),
-    wxT("$%") wxLongLongFmtSpec wxT("X"),
-    wxT("%") wxLongLongFmtSpec wxT("u"),
-    wxT("%") wxLongLongFmtSpec wxT("o")
+static const char* const gs_uintTemplates64[wxPG_UINT_TEMPLATE_MAX] = {
+    "%" wxLongLongFmtSpec "x",
+    "0x%" wxLongLongFmtSpec "x",
+    "$%" wxLongLongFmtSpec "x",
+    "%" wxLongLongFmtSpec "X",
+    "0x%" wxLongLongFmtSpec "X",
+    "$%" wxLongLongFmtSpec "X",
+    "%" wxLongLongFmtSpec "u",
+    "%" wxLongLongFmtSpec "o"
 };
 
 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxUIntProperty,wxPGProperty,
 };
 
 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxUIntProperty,wxPGProperty,
@@ -406,11 +404,11 @@ wxString wxUIntProperty::ValueToString( wxVariant& value,
 
     if ( value.GetType() == wxPG_VARIANT_TYPE_LONG )
     {
 
     if ( value.GetType() == wxPG_VARIANT_TYPE_LONG )
     {
-        return wxString::Format(gs_uintTemplates32[index], (unsigned long)value.GetLong());
+        return wxString::Format(gs_uintTemplates32[index],
+                                (unsigned long)value.GetLong());
     }
 
     }
 
-    wxULongLong ull;
-    ull << value;
+    wxULongLong ull = value.GetULongLong();
 
     return wxString::Format(gs_uintTemplates64[index], ull.GetValue());
 }
 
     return wxString::Format(gs_uintTemplates64[index], ull.GetValue());
 }
@@ -439,18 +437,16 @@ bool wxUIntProperty::StringToValue( wxVariant& variant, const wxString& text, in
         {
             bool doChangeValue = isPrevLong;
 
         {
             bool doChangeValue = isPrevLong;
 
-            if ( !isPrevLong && variantType == wxULongLong_VariantType )
+            if ( !isPrevLong && variantType == wxPG_VARIANT_TYPE_ULONGLONG )
             {
             {
-                wxULongLong oldValue;
-                oldValue << variant;
+                wxULongLong oldValue = variant.GetULongLong();
                 if ( oldValue.GetValue() != value64 )
                     doChangeValue = true;
             }
 
             if ( doChangeValue )
             {
                 if ( oldValue.GetValue() != value64 )
                     doChangeValue = true;
             }
 
             if ( doChangeValue )
             {
-                wxULongLong ull(value64);
-                variant << ull;
+                variant = wxULongLong(value64);
                 return true;
             }
         }
                 return true;
             }
         }
@@ -481,38 +477,37 @@ bool wxUIntProperty::IntToValue( wxVariant& variant, int number, int WXUNUSED(ar
 bool wxUIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const
 {
     // Check for min/max
 bool wxUIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const
 {
     // Check for min/max
-    wxULongLong_t ll;
-    if ( wxPGVariantToULongLong(value, &ll) )
-    {
-        wxULongLong_t min = 0;
-        wxULongLong_t max = wxUINT64_MAX;
-        wxVariant variant;
+    wxULongLong_t ll = value.GetULongLong().GetValue();
 
 
-        variant = GetAttribute(wxPGGlobalVars->m_strMin);
-        if ( !variant.IsNull() )
+    wxULongLong_t min = 0;
+    wxULongLong_t max = wxUINT64_MAX;
+    wxVariant variant;
+
+    variant = GetAttribute(wxPGGlobalVars->m_strMin);
+    if ( !variant.IsNull() )
+    {
+        min = variant.GetULongLong().GetValue();
+        if ( ll < min )
         {
         {
-            wxPGVariantToULongLong(variant, &min);
-            if ( ll < min )
-            {
-                validationInfo.SetFailureMessage(
-                    wxString::Format(_("Value must be %llu or higher"),min)
-                    );
-                return false;
-            }
+            validationInfo.SetFailureMessage(
+                wxString::Format(_("Value must be %llu or higher"),min)
+                );
+            return false;
         }
         }
-        variant = GetAttribute(wxPGGlobalVars->m_strMax);
-        if ( !variant.IsNull() )
+    }
+    variant = GetAttribute(wxPGGlobalVars->m_strMax);
+    if ( !variant.IsNull() )
+    {
+        max = variant.GetULongLong().GetValue();
+        if ( ll > max )
         {
         {
-            wxPGVariantToULongLong(variant, &max);
-            if ( ll > max )
-            {
-                validationInfo.SetFailureMessage(
-                    wxString::Format(_("Value must be %llu or less"),max)
-                    );
-                return false;
-            }
+            validationInfo.SetFailureMessage(
+                wxString::Format(_("Value must be %llu or less"),max)
+                );
+            return false;
         }
     }
         }
     }
+
     return true;
 }
 
     return true;
 }
 
@@ -655,7 +650,10 @@ bool wxFloatProperty::StringToValue( wxVariant& variant, const wxString& text, i
     return false;
 }
 
     return false;
 }
 
-bool wxFloatProperty::DoValidation( const wxPGProperty* property, double& value, wxPGValidationInfo* pValidationInfo, int mode )
+bool wxFloatProperty::DoValidation( const wxPGProperty* property,
+                                    double& value,
+                                    wxPGValidationInfo* pValidationInfo,
+                                    int mode )
 {
     // Check for min/max
     double min = (double)wxINT64_MIN;
 {
     // Check for min/max
     double min = (double)wxINT64_MIN;
@@ -667,14 +665,14 @@ bool wxFloatProperty::DoValidation( const wxPGProperty* property, double& value,
     variant = property->GetAttribute(wxPGGlobalVars->m_strMin);
     if ( !variant.IsNull() )
     {
     variant = property->GetAttribute(wxPGGlobalVars->m_strMin);
     if ( !variant.IsNull() )
     {
-        wxPGVariantToDouble(variant, &min);
+        min = variant.GetDouble();
         minOk = true;
     }
 
     variant = property->GetAttribute(wxPGGlobalVars->m_strMax);
     if ( !variant.IsNull() )
     {
         minOk = true;
     }
 
     variant = property->GetAttribute(wxPGGlobalVars->m_strMax);
     if ( !variant.IsNull() )
     {
-        wxPGVariantToDouble(variant, &max);
+        max = variant.GetDouble();
         maxOk = true;
     }
 
         maxOk = true;
     }
 
@@ -696,7 +694,7 @@ bool wxFloatProperty::DoValidation( const wxPGProperty* property, double& value,
 
     if ( maxOk )
     {
 
     if ( maxOk )
     {
-        wxPGVariantToDouble(variant, &max);
+        max = variant.GetDouble();
         if ( value > max )
         {
             if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
         if ( value > max )
         {
             if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
@@ -713,12 +711,13 @@ bool wxFloatProperty::DoValidation( const wxPGProperty* property, double& value,
     return true;
 }
 
     return true;
 }
 
-bool wxFloatProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const
+bool
+wxFloatProperty::ValidateValue( wxVariant& value,
+                                wxPGValidationInfo& validationInfo ) const
 {
 {
-    double fpv;
-    if ( wxPGVariantToDouble(value, &fpv) )
-        return DoValidation(this, fpv, &validationInfo, wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE);
-    return true;
+    double fpv = value.GetDouble();
+    return DoValidation(this, fpv, &validationInfo,
+                        wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE);
 }
 
 bool wxFloatProperty::DoSetAttribute( const wxString& name, wxVariant& value )
 }
 
 bool wxFloatProperty::DoSetAttribute( const wxString& name, wxVariant& value )
@@ -849,8 +848,7 @@ bool wxBoolProperty::DoSetAttribute( const wxString& name, wxVariant& value )
 #if wxPG_INCLUDE_CHECKBOX
     if ( name == wxPG_BOOL_USE_CHECKBOX )
     {
 #if wxPG_INCLUDE_CHECKBOX
     if ( name == wxPG_BOOL_USE_CHECKBOX )
     {
-        int ival = wxPGVariantToInt(value);
-        if ( ival )
+        if ( value.GetLong() )
             m_flags |= wxPG_PROP_USE_CHECKBOX;
         else
             m_flags &= ~(wxPG_PROP_USE_CHECKBOX);
             m_flags |= wxPG_PROP_USE_CHECKBOX;
         else
             m_flags &= ~(wxPG_PROP_USE_CHECKBOX);
@@ -859,8 +857,7 @@ bool wxBoolProperty::DoSetAttribute( const wxString& name, wxVariant& value )
 #endif
     if ( name == wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING )
     {
 #endif
     if ( name == wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING )
     {
-        int ival = wxPGVariantToInt(value);
-        if ( ival )
+        if ( value.GetLong() )
             m_flags |= wxPG_PROP_USE_DCC;
         else
             m_flags &= ~(wxPG_PROP_USE_DCC);
             m_flags |= wxPG_PROP_USE_DCC;
         else
             m_flags &= ~(wxPG_PROP_USE_DCC);
@@ -877,7 +874,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxEnumProperty, wxPGProperty)
 
 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxEnumProperty,long,Choice)
 
 
 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxEnumProperty,long,Choice)
 
-wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, const wxChar** labels,
+wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, const wxChar* const* labels,
     const long* values, int value ) : wxPGProperty(label,name)
 {
     SetIndex(0);
     const long* values, int value ) : wxPGProperty(label,name)
 {
     SetIndex(0);
@@ -891,7 +888,7 @@ wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, con
     }
 }
 
     }
 }
 
-wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, const wxChar** labels,
+wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, const wxChar* const* labels,
     const long* values, wxPGChoices* choicesCache, int value )
     : wxPGProperty(label,name)
 {
     const long* values, wxPGChoices* choicesCache, int value )
     : wxPGProperty(label,name)
 {
@@ -961,11 +958,17 @@ void wxEnumProperty::OnSetValue()
     wxString variantType = m_value.GetType();
 
     if ( variantType == wxPG_VARIANT_TYPE_LONG )
     wxString variantType = m_value.GetType();
 
     if ( variantType == wxPG_VARIANT_TYPE_LONG )
+    {
         ValueFromInt_( m_value, m_value.GetLong(), wxPG_FULL_VALUE );
         ValueFromInt_( m_value, m_value.GetLong(), wxPG_FULL_VALUE );
+    }
     else if ( variantType == wxPG_VARIANT_TYPE_STRING )
     else if ( variantType == wxPG_VARIANT_TYPE_STRING )
+    {
         ValueFromString_( m_value, m_value.GetString(), 0 );
         ValueFromString_( m_value, m_value.GetString(), 0 );
+    }
     else
     else
+    {
         wxFAIL;
         wxFAIL;
+    }
 
     if ( ms_nextIndex != -2 )
     {
 
     if ( ms_nextIndex != -2 )
     {
@@ -1031,9 +1034,7 @@ bool wxEnumProperty::ValueFromString_( wxVariant& value, const wxString& text, i
 
     // If text not any of the choices, store as text instead
     // (but only if we are wxEditEnumProperty)
 
     // If text not any of the choices, store as text instead
     // (but only if we are wxEditEnumProperty)
-    if ( useIndex == -1 &&
-         (value.GetType() != wxPG_VARIANT_TYPE_STRING || (m_value.GetString() != text)) &&
-         isEdit )
+    if ( useIndex == -1 && isEdit )
     {
         asText = true;
     }
     {
         asText = true;
     }
@@ -1137,14 +1138,14 @@ IMPLEMENT_DYNAMIC_CLASS(wxEditEnumProperty, wxPGProperty)
 
 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxEditEnumProperty,wxString,ComboBox)
 
 
 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxEditEnumProperty,wxString,ComboBox)
 
-wxEditEnumProperty::wxEditEnumProperty( const wxString& label, const wxString& name, const wxChar** labels,
+wxEditEnumProperty::wxEditEnumProperty( const wxString& label, const wxString& name, const wxChar* const* labels,
     const long* values, const wxString& value )
     : wxEnumProperty(label,name,labels,values,0)
 {
     SetValue( value );
 }
 
     const long* values, const wxString& value )
     : wxEnumProperty(label,name,labels,values,0)
 {
     SetValue( value );
 }
 
-wxEditEnumProperty::wxEditEnumProperty( const wxString& label, const wxString& name, const wxChar** labels,
+wxEditEnumProperty::wxEditEnumProperty( const wxString& label, const wxString& name, const wxChar* const* labels,
     const long* values, wxPGChoices* choicesCache, const wxString& value )
     : wxEnumProperty(label,name,labels,values,choicesCache,0)
 {
     const long* values, wxPGChoices* choicesCache, const wxString& value )
     : wxEnumProperty(label,name,labels,values,choicesCache,0)
 {
@@ -1263,7 +1264,7 @@ void wxFlagsProperty::Init()
 }
 
 wxFlagsProperty::wxFlagsProperty( const wxString& label, const wxString& name,
 }
 
 wxFlagsProperty::wxFlagsProperty( const wxString& label, const wxString& name,
-    const wxChar** labels, const long* values, long value ) : wxPGProperty(label,name)
+    const wxChar* const* labels, const long* values, long value ) : wxPGProperty(label,name)
 {
     m_oldChoicesData = NULL;
 
 {
     m_oldChoicesData = NULL;
 
@@ -1641,10 +1642,9 @@ wxFileProperty::wxFileProperty( const wxString& label, const wxString& name,
 
 wxFileProperty::~wxFileProperty() {}
 
 
 wxFileProperty::~wxFileProperty() {}
 
-#if wxUSE_VALIDATORS
-
 wxValidator* wxFileProperty::GetClassValidator()
 {
 wxValidator* wxFileProperty::GetClassValidator()
 {
+#if wxUSE_VALIDATORS
     WX_PG_DOGETVALIDATOR_ENTRY()
 
     // Atleast wxPython 2.6.2.1 required that the string argument is given
     WX_PG_DOGETVALIDATOR_ENTRY()
 
     // Atleast wxPython 2.6.2.1 required that the string argument is given
@@ -1662,6 +1662,9 @@ wxValidator* wxFileProperty::GetClassValidator()
     validator->SetExcludes(exChars);
 
     WX_PG_DOGETVALIDATOR_EXIT(validator)
     validator->SetExcludes(exChars);
 
     WX_PG_DOGETVALIDATOR_EXIT(validator)
+#else
+    return NULL;
+#endif
 }
 
 wxValidator* wxFileProperty::DoGetValidator() const
 }
 
 wxValidator* wxFileProperty::DoGetValidator() const
@@ -1669,8 +1672,6 @@ wxValidator* wxFileProperty::DoGetValidator() const
     return GetClassValidator();
 }
 
     return GetClassValidator();
 }
 
-#endif
-
 void wxFileProperty::OnSetValue()
 {
     const wxString& fnstr = m_value.GetString();
 void wxFileProperty::OnSetValue()
 {
     const wxString& fnstr = m_value.GetString();
@@ -1799,7 +1800,7 @@ bool wxFileProperty::DoSetAttribute( const wxString& name, wxVariant& value )
     // stored in m_attributes.
     if ( name == wxPG_FILE_SHOW_FULL_PATH )
     {
     // stored in m_attributes.
     if ( name == wxPG_FILE_SHOW_FULL_PATH )
     {
-        if ( wxPGVariantToInt(value) )
+        if ( value.GetLong() )
             m_flags |= wxPG_PROP_SHOW_FULL_FILENAME;
         else
             m_flags &= ~(wxPG_PROP_SHOW_FULL_FILENAME);
             m_flags |= wxPG_PROP_SHOW_FULL_FILENAME;
         else
             m_flags &= ~(wxPG_PROP_SHOW_FULL_FILENAME);
@@ -2117,12 +2118,14 @@ bool wxArrayEditorDialog::Create( wxWindow *parent,
     wxBoxSizer* rowsizer = new wxBoxSizer( wxHORIZONTAL );
     m_edValue = new wxTextCtrl(this,21,wxEmptyString,
         wxDefaultPosition,wxDefaultSize,wxTE_PROCESS_ENTER);
     wxBoxSizer* rowsizer = new wxBoxSizer( wxHORIZONTAL );
     m_edValue = new wxTextCtrl(this,21,wxEmptyString,
         wxDefaultPosition,wxDefaultSize,wxTE_PROCESS_ENTER);
+#if wxUSE_VALIDATORS
     wxValidator* validator = GetTextCtrlValidator();
     if ( validator )
     {
         m_edValue->SetValidator( *validator );
         delete validator;
     }
     wxValidator* validator = GetTextCtrlValidator();
     if ( validator )
     {
         m_edValue->SetValidator( *validator );
         delete validator;
     }
+#endif
     rowsizer->Add( m_edValue,
         1, wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL|wxALL, spacing );
 
     rowsizer->Add( m_edValue,
         1, wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL|wxALL, spacing );
 
@@ -2571,7 +2574,7 @@ bool wxArrayStringProperty::StringToValue( wxVariant& variant, const wxString& t
 
         // Need to replace backslashes with empty characters
         // (opposite what is done in GenerateValueString).
 
         // Need to replace backslashes with empty characters
         // (opposite what is done in GenerateValueString).
-        token.Replace ( wxS("\\"), wxEmptyString, true );
+        token.Replace ( wxS("\\\\"), wxS("\\"), true );
 
         arr.Add( token );
 
 
         arr.Add( token );