]> git.saurik.com Git - wxWidgets.git/commitdiff
Merged wxBaseEnumPropertyClass (intermediate property class with obsolete purpose...
authorJaakko Salli <jaakko.salli@dnainternet.net>
Wed, 22 Oct 2008 15:23:07 +0000 (15:23 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Wed, 22 Oct 2008 15:23:07 +0000 (15:23 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56486 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/propgrid/props.h
src/propgrid/advprops.cpp
src/propgrid/props.cpp

index 965de7dc7a963c11ddde4ef5f8c8cd09af2c96bb..b096bb24e106da0f22db4a2e316bfe5620ae389a 100644 (file)
@@ -343,9 +343,14 @@ public:
 
 // -----------------------------------------------------------------------
 
-/** @class wxBaseEnumProperty
+// If set, then selection of choices is static and should not be
+// changed (i.e. returns NULL in GetPropertyChoices).
+#define wxPG_PROP_STATIC_CHOICES    wxPG_PROP_CLASS_SPECIFIC_1
+
+/** @class wxEnumProperty
     @ingroup classes
-    Derive dynamic custom properties with choices from this class.
+    You can derive custom properties with choices from this class. See
+    wxBaseEnumProperty for remarks.
 
     @remarks
     - Updating private index is important. You can do this either by calling
@@ -353,11 +358,46 @@ public:
     be called (by not implementing it, or by calling super class function in
     it) -OR- you can just call SetIndex in OnSetValue.
 */
-class WXDLLIMPEXP_PROPGRID wxBaseEnumProperty : public wxPGProperty
+class WXDLLIMPEXP_PROPGRID wxEnumProperty : public wxPGProperty
 {
+    WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty)
 public:
-    wxBaseEnumProperty( const wxString& label = wxPG_LABEL,
-                        const wxString& name = wxPG_LABEL );
+
+#ifndef SWIG
+    wxEnumProperty( const wxString& label = wxPG_LABEL,
+                    const wxString& name = wxPG_LABEL,
+                    const wxChar** labels = NULL,
+                    const long* values = NULL,
+                    int value = 0 );
+    wxEnumProperty( const wxString& label,
+                    const wxString& name,
+                    wxPGChoices& choices,
+                    int value = 0 );
+
+    // Special constructor for caching choices (used by derived class)
+    wxEnumProperty( const wxString& label,
+                    const wxString& name,
+                    const wxChar** labels,
+                    const long* values,
+                    wxPGChoices* choicesCache,
+                    int value = 0 );
+
+    wxEnumProperty( const wxString& label,
+                    const wxString& name,
+                    const wxArrayString& labels,
+                    const wxArrayInt& values = wxArrayInt(),
+                    int value = 0 );
+#else
+    wxEnumProperty( const wxString& label = wxPG_LABEL,
+                    const wxString& name = wxPG_LABEL,
+                    const wxArrayString& labels = wxArrayString(),
+                    const wxArrayInt& values = wxArrayInt(),
+                    int value = 0 );
+#endif
+
+    virtual ~wxEnumProperty();
+
+    size_t GetItemCount() const { return m_choices.GetCount(); }
 
     virtual void OnSetValue();
     virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
@@ -379,23 +419,11 @@ public:
     // This must be overridden to have non-index based value
     virtual int GetIndexForValue( int value ) const;
 
-    // This returns string and value for index
-    // Returns NULL if beyond last item
-    // pvalue is never NULL - always set it.
-    virtual const wxString* GetEntry( size_t index, int* pvalue ) const = 0;
-
     // GetChoiceSelection needs to overridden since m_index is
     // the true index, and various property classes derived from
     // this take advantage of it.
     virtual int GetChoiceSelection() const { return m_index; }
 
-    int GetValueForIndex( size_t index ) const
-    {
-        int v;
-        GetEntry( index, &v );
-        return v;
-    }
-
 protected:
 
     int GetIndex() const;
@@ -419,63 +447,6 @@ private:
 
 // -----------------------------------------------------------------------
 
-// If set, then selection of choices is static and should not be
-// changed (i.e. returns NULL in GetPropertyChoices).
-#define wxPG_PROP_STATIC_CHOICES    wxPG_PROP_CLASS_SPECIFIC_1
-
-/** @class wxEnumProperty
-    @ingroup classes
-    You can derive custom properties with choices from this class. See
-    wxBaseEnumProperty for remarks.
-*/
-class WXDLLIMPEXP_PROPGRID wxEnumProperty : public wxBaseEnumProperty
-{
-    WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty)
-public:
-
-#ifndef SWIG
-    wxEnumProperty( const wxString& label = wxPG_LABEL,
-                    const wxString& name = wxPG_LABEL,
-                    const wxChar** labels = NULL,
-                    const long* values = NULL,
-                    int value = 0 );
-    wxEnumProperty( const wxString& label,
-                    const wxString& name,
-                    wxPGChoices& choices,
-                    int value = 0 );
-
-    // Special constructor for caching choices (used by derived class)
-    wxEnumProperty( const wxString& label,
-                    const wxString& name,
-                    const wxChar** labels,
-                    const long* values,
-                    wxPGChoices* choicesCache,
-                    int value = 0 );
-
-    wxEnumProperty( const wxString& label,
-                    const wxString& name,
-                    const wxArrayString& labels,
-                    const wxArrayInt& values = wxArrayInt(),
-                    int value = 0 );
-#else
-    wxEnumProperty( const wxString& label = wxPG_LABEL,
-                    const wxString& name = wxPG_LABEL,
-                    const wxArrayString& labels = wxArrayString(),
-                    const wxArrayInt& values = wxArrayInt(),
-                    int value = 0 );
-#endif
-
-    virtual ~wxEnumProperty();
-
-    virtual int GetIndexForValue( int value ) const;
-    virtual const wxString* GetEntry( size_t index, int* pvalue ) const;
-
-    size_t GetItemCount() const { return m_choices.GetCount(); }
-    const wxPGChoices& GetChoices() const { return m_choices; }
-};
-
-// -----------------------------------------------------------------------
-
 /** @class wxEditEnumProperty
     @ingroup classes
     wxEnumProperty with wxString value and writable combo box editor.
index 60fda14f1b2fb70676da8bbb29841a062b5d927a..0b578f687437042ecf8d491db0cba9888277a423 100644 (file)
@@ -1082,7 +1082,7 @@ bool wxSystemColourProperty::QueryColourFromUser( wxVariant& variant ) const
 bool wxSystemColourProperty::IntToValue( wxVariant& variant, int number, int WXUNUSED(argFlags) ) const
 {
     int index = number;
-    int type = GetValueForIndex(index);
+    int type = m_choices.GetValue(index);
 
     if ( type == wxPG_COLOUR_CUSTOM )
     {
index 1b61ba15df3a5e84f00bf96cfc23b4cecf264c96..566572ff877c6abf7a94de864d591a67fc486893 100644 (file)
@@ -878,26 +878,93 @@ 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);
+
+        if ( GetItemCount() )
+            SetValue( (long)value );
+    }
+}
 
-wxBaseEnumProperty::wxBaseEnumProperty( const wxString& label, const wxString& name )
+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 ()
+{
+}
+
+int wxEnumProperty::ms_nextIndex = -2;
+
+void wxEnumProperty::OnSetValue()
 {
     wxString variantType = m_value.GetType();
 
@@ -915,7 +982,7 @@ 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
@@ -927,7 +994,7 @@ bool wxBaseEnumProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& WX
     return true;
 }
 
-wxString wxBaseEnumProperty::ValueToString( wxVariant& value,
+wxString wxEnumProperty::ValueToString( wxVariant& value,
                                             int WXUNUSED(argFlags) ) const
 {
     if ( value.GetType() == wxPG_VARIANT_TYPE_STRING )
@@ -940,36 +1007,30 @@ wxString wxBaseEnumProperty::ValueToString( wxVariant& value,
     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; i<m_choices.GetCount(); i++ )
     {
-        if ( text.CmpNoCase(*entryLabel) == 0 )
+        const wxString& entryLabel = m_choices.GetLabel(i);
+        if ( text.CmpNoCase(entryLabel) == 0 )
         {
             useIndex = (int)i;
-            useValue = (long)entryValue;
+            useValue = m_choices.GetValue(i);
             break;
         }
-
-        i++;
-        entryLabel = GetEntry(i, &entryValue);
     }
 
     bool asText = false;
@@ -1021,7 +1082,7 @@ bool wxBaseEnumProperty::ValueFromString_( wxVariant& value, const wxString& tex
     return false;
 }
 
-bool wxBaseEnumProperty::ValueFromInt_( wxVariant& variant, int intVal, int argFlags ) const
+bool wxEnumProperty::ValueFromInt_( wxVariant& variant, int intVal, int argFlags ) const
 {
     // If wxPG_FULL_VALUE is *not* in argFlags, then intVal is index from combo box.
     //
@@ -1042,7 +1103,7 @@ bool wxBaseEnumProperty::ValueFromInt_( wxVariant& variant, int intVal, int argF
     if ( ms_nextIndex != -2 )
     {
         if ( !(argFlags & wxPG_FULL_VALUE) )
-            GetEntry(intVal, &intVal);
+            intVal = m_choices.GetValue(intVal);
 
         variant = (long)intVal;
 
@@ -1052,117 +1113,19 @@ bool wxBaseEnumProperty::ValueFromInt_( wxVariant& variant, int intVal, int argF
     return false;
 }
 
-void wxBaseEnumProperty::SetIndex( int index )
+void wxEnumProperty::SetIndex( int index )
 {
     ms_nextIndex = -2;
     m_index = index;
 }
 
-int wxBaseEnumProperty::GetIndex() const
+int wxEnumProperty::GetIndex() const
 {
     if ( ms_nextIndex != -2 )
         return ms_nextIndex;
     return m_index;
 }
 
-// -----------------------------------------------------------------------
-// wxEnumProperty
-// -----------------------------------------------------------------------
-
-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 ) : wxBaseEnumProperty(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 )
-    : wxBaseEnumProperty(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 ) : 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;
-
-    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 = m_choices.GetValue(index);
-
-        if ( pvalue )
-            *pvalue = value;
-
-        return &m_choices.GetLabel(index);
-    }
-    return (const wxString*) NULL;
-}
-
 // -----------------------------------------------------------------------
 // wxEditEnumProperty
 // -----------------------------------------------------------------------