]> git.saurik.com Git - wxWidgets.git/blobdiff - src/propgrid/props.cpp
adding missing cast
[wxWidgets.git] / src / propgrid / props.cpp
index e01c940bcc7cbfd511a5022938cedfe75511f2ab..2d2890df7302555907df26eacf21ff62dc033291 100644 (file)
@@ -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"
     #include "wx/sizer.h"
     #include "wx/textdlg.h"
     #include "wx/filedlg.h"
-    #include "wx/statusbr.h"
     #include "wx/intl.h"
 #endif
 
-#include <wx/filename.h>
+#include "wx/filename.h"
 
-#include <wx/propgrid/propgrid.h>
+#include "wx/propgrid/propgrid.h"
 
 #define wxPG_CUSTOM_IMAGE_WIDTH     20 // for wxColourProperty etc.
 
@@ -111,7 +112,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;
@@ -148,21 +149,25 @@ 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
 {
-    if ( wxPGIsVariantType(m_value, long) )
+    if ( m_value.GetType() == wxPG_VARIANT_TYPE_LONG )
+    {
         return wxString::Format(wxS("%li"),m_value.GetLong());
+    }
+    else if ( m_value.GetType() == wxLongLong_VariantType )
+    {
+           wxLongLong ll;
+        ll << m_value;
+           return ll.ToString();
+    }
 
-       wxLongLong* ll = &wxLongLongFromVariant(m_value);
-       if ( ll )
-               return ll->ToString();
-
-       return wxEmptyString;
+    return wxEmptyString;
 }
 
 bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int argFlags ) const
@@ -196,7 +201,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;
 
@@ -204,17 +210,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;
@@ -229,7 +245,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;
@@ -265,7 +281,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
@@ -279,7 +297,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
@@ -363,7 +383,7 @@ wxUIntProperty::wxUIntProperty( const wxString& label, const wxString& name,
     const wxULongLong& value ) : wxPGProperty(label,name)
 {
     Init();
-    SetValue(wxULongLongToVariant(value));
+    SetValue(WXVARIANT(value));
 }
 
 wxUIntProperty::~wxUIntProperty() { }
@@ -374,16 +394,21 @@ wxString wxUIntProperty::GetValueAsString( int ) const
     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 ( m_value.GetType() == wxPG_VARIANT_TYPE_LONG )
+    {
+        return wxString::Format(gs_uintTemplates32[index], (unsigned long)m_value.GetLong());
+    }
+
+    wxULongLong ull;
+    ull << m_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 )
     {
@@ -402,17 +427,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;
@@ -425,7 +460,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;
@@ -457,7 +492,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;
             }
         }
@@ -467,7 +504,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;
             }
         }
@@ -601,7 +640,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;
@@ -641,7 +680,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
@@ -656,7 +697,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
@@ -704,16 +747,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;
@@ -738,13 +783,13 @@ 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());
         }
     }
 
@@ -761,23 +806,13 @@ wxString wxBoolProperty::GetValueAsString( int argFlags ) const
     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 )
     {
@@ -785,11 +820,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;
@@ -798,9 +831,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;
@@ -855,9 +887,11 @@ int wxBaseEnumProperty::GetIndexForValue( int value ) const
 
 void wxBaseEnumProperty::OnSetValue()
 {
-    if ( wxPGIsVariantType(m_value, long) )
+    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 );
@@ -874,7 +908,7 @@ bool wxBaseEnumProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& WX
     // 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 );
 
@@ -883,7 +917,7 @@ bool wxBaseEnumProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& WX
 
 wxString wxBaseEnumProperty::GetValueAsString( int ) const
 {
-    if ( wxPGIsVariantType(m_value, string) )
+    if ( m_value.GetType() == wxPG_VARIANT_TYPE_STRING )
         return m_value.GetString();
 
     if ( m_index >= 0 )
@@ -936,7 +970,7 @@ bool wxBaseEnumProperty::ValueFromString_( wxVariant& value, const wxString& tex
     // If text not any of the choices, store as text instead
     // (but only if we are wxEditEnumProperty)
     if ( useIndex == -1 &&
-         (!wxPGIsVariantType(m_value, string) || (m_value.GetString() != text)) &&
+         (value.GetType() != wxPG_VARIANT_TYPE_STRING || (m_value.GetString() != text)) &&
          isEdit )
     {
         asText = true;
@@ -1125,17 +1159,6 @@ const wxString* wxEnumProperty::GetEntry( size_t index, int* pvalue ) const
     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
 // -----------------------------------------------------------------------
@@ -1196,7 +1219,7 @@ void wxFlagsProperty::Init()
     //
     unsigned int i;
 
-    unsigned int prevChildCount = m_children.GetCount();
+    unsigned int prevChildCount = m_children.size();
 
     int oldSel = -1;
     if ( prevChildCount )
@@ -1212,7 +1235,7 @@ void wxFlagsProperty::Init()
             if ( selected )
             {
                 if ( selected->GetParent() == this )
-                    oldSel = selected->GetArrIndex();
+                    oldSel = selected->GetIndexInParent();
                 else if ( selected == this )
                     oldSel = -2;
             }
@@ -1222,9 +1245,9 @@ void wxFlagsProperty::Init()
 
     // Delete old children
     for ( i=0; i<prevChildCount; i++ )
-        delete ( (wxPGProperty*) m_children[i] );
+        delete m_children[i];
 
-    m_children.Empty();
+    m_children.clear();
 
     if ( m_choices.IsOk() )
     {
@@ -1239,16 +1262,17 @@ void wxFlagsProperty::Init()
                 child_val = ( value & (1<<i) )?true:false;
 
             wxPGProperty* boolProp;
+            wxString label = GetLabel(i);
 
         #if wxUSE_INTL
             if ( wxPGGlobalVars->m_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);
         }
@@ -1424,7 +1448,6 @@ bool wxFlagsProperty::StringToValue( wxVariant& variant, const wxString& text, i
         return false;
 
     long newFlags = 0;
-    long oldValue = m_value;
 
     // semicolons are no longer valid delimeters
     WX_PG_TOKENIZER1_BEGIN(text,wxS(','))
@@ -1447,10 +1470,11 @@ bool wxFlagsProperty::StringToValue( wxVariant& variant, const wxString& text, i
 
     WX_PG_TOKENIZER1_END()
 
-    variant = newFlags;
-
-    if ( newFlags != oldValue )
+    if ( variant != (long)newFlags )
+    {
+        variant = (long)newFlags;
         return true;
+    }
 
     return false;
 }
@@ -1512,24 +1536,18 @@ void wxFlagsProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVari
         thisValue = (long)(oldValue & ~(vi));
 }
 
-int wxFlagsProperty::GetChoiceInfo( wxPGChoiceInfo* choiceinfo )
-{
-    if ( choiceinfo )
-        choiceinfo->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
@@ -1539,6 +1557,7 @@ wxValidator* wxDirProperty::DoGetValidator() const
 
 bool wxDirProperty::OnButtonClick( wxPropertyGrid* propGrid, wxString& value )
 {
+    // Update property value from editor, if necessary
     wxSize dlg_sz(300,400);
 
     wxDirDialog dlg( propGrid,
@@ -1866,9 +1885,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;
@@ -1954,7 +1973,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;
@@ -1980,7 +1999,7 @@ END_EVENT_TABLE()
 
 IMPLEMENT_ABSTRACT_CLASS(wxArrayEditorDialog, wxDialog)
 
-#include <wx/statline.h>
+#include "wx/statline.h"
 
 // -----------------------------------------------------------------------
 
@@ -2468,7 +2487,7 @@ bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid* propGrid,
                                            const wxChar* cbt )
 {
     // Update the value
-    PrepareValueForDialogEditing(propGrid);
+    wxVariant useValue = propGrid->GetUncommittedPropertyValue();
 
     if ( !propGrid->EditorValidate() )
         return false;
@@ -2485,7 +2504,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
@@ -2600,3 +2619,4 @@ bool wxPGInDialogValidator::DoValidate( wxPropertyGrid* WXUNUSED(propGrid),
 
 // -----------------------------------------------------------------------
 
+#endif  // wxUSE_PROPGRID