Merged wxBaseEnumPropertyClass (intermediate property class with obsolete purpose) to wxEnumPropertyClass

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56486 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli 2008-10-22 15:23:07 +00:00
parent 788432e343
commit 78f2d746a0
3 changed files with 143 additions and 209 deletions

View File

@ -343,82 +343,6 @@ public:
// -----------------------------------------------------------------------
/** @class wxBaseEnumProperty
@ingroup classes
Derive dynamic custom properties with choices from this class.
@remarks
- Updating private index is important. You can do this either by calling
SetIndex() in IntToValue, and then letting wxBaseEnumProperty::OnSetValue
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
{
public:
wxBaseEnumProperty( const wxString& label = wxPG_LABEL,
const wxString& name = wxPG_LABEL );
virtual void OnSetValue();
virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
virtual bool StringToValue( wxVariant& variant,
const wxString& text,
int argFlags = 0 ) const;
virtual bool ValidateValue( wxVariant& value,
wxPGValidationInfo& validationInfo ) const;
// If wxPG_FULL_VALUE is not set in flags, then the value is interpreted
// as index to choices list. Otherwise, it is actual value.
virtual bool IntToValue( wxVariant& variant,
int number,
int argFlags = 0 ) const;
//
// Additional virtuals
// 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;
void SetIndex( int index );
bool ValueFromString_( wxVariant& value,
const wxString& text,
int argFlags ) const;
bool ValueFromInt_( wxVariant& value, int intVal, int argFlags ) const;
static void ResetNextIndex() { ms_nextIndex = -2; }
private:
// This is private so that classes are guaranteed to use GetIndex
// for up-to-date index value.
int m_index;
// Relies on ValidateValue being called always before OnSetValue
static int ms_nextIndex;
};
// -----------------------------------------------------------------------
// 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
@ -427,8 +351,14 @@ private:
@ingroup classes
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
SetIndex() in IntToValue, and then letting wxBaseEnumProperty::OnSetValue
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 wxEnumProperty : public wxBaseEnumProperty
class WXDLLIMPEXP_PROPGRID wxEnumProperty : public wxPGProperty
{
WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty)
public:
@ -467,11 +397,52 @@ public:
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; }
virtual void OnSetValue();
virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
virtual bool StringToValue( wxVariant& variant,
const wxString& text,
int argFlags = 0 ) const;
virtual bool ValidateValue( wxVariant& value,
wxPGValidationInfo& validationInfo ) const;
// If wxPG_FULL_VALUE is not set in flags, then the value is interpreted
// as index to choices list. Otherwise, it is actual value.
virtual bool IntToValue( wxVariant& variant,
int number,
int argFlags = 0 ) const;
//
// Additional virtuals
// This must be overridden to have non-index based value
virtual int GetIndexForValue( int value ) const;
// 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; }
protected:
int GetIndex() const;
void SetIndex( int index );
bool ValueFromString_( wxVariant& value,
const wxString& text,
int argFlags ) const;
bool ValueFromInt_( wxVariant& value, int intVal, int argFlags ) const;
static void ResetNextIndex() { ms_nextIndex = -2; }
private:
// This is private so that classes are guaranteed to use GetIndex
// for up-to-date index value.
int m_index;
// Relies on ValidateValue being called always before OnSetValue
static int ms_nextIndex;
};
// -----------------------------------------------------------------------

View 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 )
{

View 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)
wxBaseEnumProperty::wxBaseEnumProperty( const wxString& label, const wxString& name )
: wxPGProperty(label,name)
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)
{
m_value = wxPGVariant_Zero;
SetIndex(0);
if ( labels )
{
m_choices.Add(labels,values);
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
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 );
}
}
wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name,
wxPGChoices& choices, int value )
: wxPGProperty(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;
}
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
// -----------------------------------------------------------------------