📄 props.cpp
字号:
return true;
}
bool res = text.ToDouble(&value);
if ( res )
{
if ( m_value != value )
{
m_value = value;
return true;
}
}
else if ( argFlags & wxPG_REPORT_ERROR )
{
ShowError(wxString::Format( _("\"%s\" is not a floating-point number"), text.c_str() ));
}
return false;
}
void wxFloatPropertyClass::SetAttribute( int id, wxVariant& value )
{
if ( id == wxPG_FLOAT_PRECISION )
{
m_precision = value.GetLong();
}
}
#if wxUSE_VALIDATORS
wxValidator* wxFloatPropertyClass::DoGetValidator() const
{
return wxIntPropertyClass::GetClassValidator();
}
#endif
// -----------------------------------------------------------------------
// wxBoolProperty
// -----------------------------------------------------------------------
wxPG_BEGIN_PROPERTY_CLASS_BODY2(wxBoolPropertyClass,wxPGProperty,bool,long,bool,class)
WX_PG_DECLARE_BASIC_TYPE_METHODS()
WX_PG_DECLARE_CHOICE_METHODS()
WX_PG_DECLARE_ATTRIBUTE_METHODS()
wxPG_END_PROPERTY_CLASS_BODY()
// We cannot use standard WX_PG_IMPLEMENT_PROPERTY_CLASS macro, since
// there is a custom GetEditorClass.
WX_PG_IMPLEMENT_CONSTFUNC(wxBoolProperty,bool)
WX_PG_IMPLEMENT_CLASSINFO(wxBoolProperty,wxBasePropertyClass)
wxPG_GETCLASSNAME_IMPLEMENTATION(wxBoolProperty)
wxPG_VALUETYPE_MSGVAL wxBoolPropertyClass::GetValueType() const { return wxPG_VALUETYPE(bool); }
const wxChar* wxPG_ClassName_wxBoolProperty = wxBoolProperty_ClassName;
const wxPGEditor* wxBoolPropertyClass::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);
#else
return wxPG_EDITOR(Choice);
#endif
}
wxBoolPropertyClass::wxBoolPropertyClass( const wxString& label, const wxString& name, bool value ) :
wxPGProperty(label,name)
{
int useVal;
if ( value ) useVal = 1;
else useVal = 0;
DoSetValue((long)useVal);
m_flags |= wxPG_PROP_USE_DCC;
}
wxBoolPropertyClass::~wxBoolPropertyClass() { }
void wxBoolPropertyClass::DoSetValue( wxPGVariant value )
{
long v = wxPGVariantToLong(value);
if ( v == 2 )
SetValueToUnspecified();
else if ( v != 0 )
m_value = 1;
else
m_value = 0;
}
wxPGVariant wxBoolPropertyClass::DoGetValue() const
{
return wxPGVariant(m_value);
}
wxString wxBoolPropertyClass::GetValueAsString( int argFlags ) const
{
if ( !(argFlags & wxPG_FULL_VALUE) )
{
return wxPGGlobalVars->m_boolChoices[m_value];
}
wxString text;
if (m_value) text = wxT("true");
else text = wxT("false");
return text;
}
int wxBoolPropertyClass::GetChoiceInfo( wxPGChoiceInfo* choiceinfo )
{
if ( choiceinfo )
{
// 3 choice mode (ie. true, false, unspecified) does not work well (yet).
//choiceinfo->m_itemCount = wxPGGlobalVars->m_numBoolChoices;
choiceinfo->m_itemCount = 2;
choiceinfo->m_arrWxString = wxPGGlobalVars->m_boolChoices;
}
return m_value;
}
bool wxBoolPropertyClass::SetValueFromString( const wxString& text, int /*argFlags*/ )
{
int value = 0;
if ( text.CmpNoCase(wxPGGlobalVars->m_boolChoices[1]) == 0 || text.CmpNoCase(wxT("true")) == 0 )
value = 1;
if ( text.length() == 0 )
{
SetValueToUnspecified();
return true;
}
if ( (m_value && !value) || (!m_value && value) )
{
DoSetValue( (long) value );
return true;
}
/*
else if ( argFlags & wxPG_REPORT_ERROR )
{
wxLogError ( wxT("Property %s: \"%s\" is not a boolean value (True and False are valid)."), m_label.c_str(), text.c_str() );
}
*/
return false;
}
bool wxBoolPropertyClass::SetValueFromInt( long value, int )
{
if ( value != 0 ) value = 1;
if ( (m_value && !value) || (!m_value && value) )
{
// (wxPG_BOOLPROP_VAL_INTERNAL_LONG)
m_value = value;
return true;
}
return false;
}
void wxBoolPropertyClass::SetAttribute( int id, wxVariant& value )
{
int ival = value.GetLong();
#if wxPG_INCLUDE_CHECKBOX
if ( id == wxPG_BOOL_USE_CHECKBOX )
{
if ( ival )
m_flags |= wxPG_PROP_USE_CHECKBOX;
else
m_flags &= ~(wxPG_PROP_USE_CHECKBOX);
}
//else
#endif
if ( id == wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING )
{
if ( ival )
m_flags |= wxPG_PROP_USE_DCC;
else
m_flags &= ~(wxPG_PROP_USE_DCC);
}
}
// -----------------------------------------------------------------------
// wxBaseEnumPropertyClass
// -----------------------------------------------------------------------
// Class body is in propdev.h.
wxBaseEnumPropertyClass::wxBaseEnumPropertyClass( const wxString& label, const wxString& name )
: wxPGProperty(label,name)
{
}
/** If has values array, then returns number at index with value -
otherwise just returns the value.
*/
int wxBaseEnumPropertyClass::GetIndexForValue( int value ) const
{
return value;
}
void wxBaseEnumPropertyClass::DoSetValue( wxPGVariant value )
{
int intval = (int) value.GetLong();
m_index = GetIndexForValue(intval);
}
wxPGVariant wxBaseEnumPropertyClass::DoGetValue() const
{
if ( m_index < 0 )
return wxPGVariant((long)-1);
int val;
GetEntry(m_index,&val);
return wxPGVariantCreator(val);
}
wxString wxBaseEnumPropertyClass::GetValueAsString( int ) const
{
if ( m_index >= 0 )
{
int unused_val;
const wxString* pstr = GetEntry( m_index, &unused_val );
if ( pstr )
return *pstr;
}
return wxEmptyString;
}
bool wxBaseEnumPropertyClass::SetValueFromString ( const wxString& text, int WXUNUSED(argFlags) )
{
size_t i = 0;
const wxString* entry_label;
int entry_value;
int use_index = -1;
long use_value = 0;
entry_label = GetEntry(i,&entry_value);
while ( entry_label )
{
if ( text.CmpNoCase(*entry_label) == 0 )
{
use_index = (int)i;
use_value = (long)entry_value;
break;
}
i++;
entry_label = GetEntry(i,&entry_value);
}
if ( m_index != use_index )
{
if ( use_index != -1 )
// FIXME: Why can't this be virtual call?
wxBaseEnumPropertyClass::DoSetValue ( use_value );
else
m_index = -1;
return true;
}
/*}
else if ( argFlags & wxPG_REPORT_ERROR )
{
wxString s;
s.Printf ( wxT("\"%s\" was not among valid choices."), text.c_str() );
ShowError(s);
}*/
return false;
}
bool wxBaseEnumPropertyClass::SetValueFromInt ( long value, int argFlags )
{
if ( argFlags & wxPG_FULL_VALUE )
{
DoSetValue(value);
return true;
}
else
{
if ( m_index != value )
{
m_index = value;
return true;
}
}
return false;
}
// -----------------------------------------------------------------------
// wxEnumProperty
// -----------------------------------------------------------------------
// Class body is in propdev.h.
wxPGProperty* wxEnumProperty( const wxString& label, const wxString& name, const wxChar** labels,
const long* values, int value )
{
return new wxEnumPropertyClass (label,name,labels,values,value);
}
wxPGProperty* wxEnumProperty( const wxString& label, const wxString& name,
const wxArrayString& labels, const wxArrayInt& values, int value )
{
return new wxEnumPropertyClass(label,name,labels,values,value);
}
wxPGProperty* wxEnumProperty( const wxString& label, const wxString& name,
const wxArrayString& labels, int value )
{
return new wxEnumPropertyClass (label,name,labels,*((const wxArrayInt*)NULL),value);
}
wxPGProperty* wxEnumProperty( const wxString& label, const wxString& name,
wxPGChoices& choices, int value )
{
return new wxEnumPropertyClass (label,name,choices,value);
}
WX_PG_IMPLEMENT_CLASSINFO(wxEnumProperty,wxBasePropertyClass)
WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxEnumProperty,long,Choice)
wxEnumPropertyClass::wxEnumPropertyClass ( const wxString& label, const wxString& name, const wxChar** labels,
const long* values, int value ) : wxBaseEnumPropertyClass(label,name)
{
m_index = 0;
if ( labels )
{
m_choices.Add(labels,values);
if ( GetItemCount() )
wxEnumPropertyClass::DoSetValue( (long)value );
}
}
wxEnumPropertyClass::wxEnumPropertyClass ( const wxString& label, const wxString& name, const wxChar** labels,
const long* values, wxPGChoices* choicesCache, int value )
: wxBaseEnumPropertyClass(label,name)
{
m_index = 0;
wxASSERT( choicesCache );
if ( choicesCache->IsOk() )
{
m_choices.Assign( *choicesCache );
}
else if ( labels )
{
m_choices.Add(labels,values);
if ( GetItemCount() )
wxEnumPropertyClass::DoSetValue( (long)value );
}
}
wxEnumPropertyClass::wxEnumPropertyClass ( const wxString& label, const wxString& name,
const wxArrayString& labels, const wxArrayInt& values, int value ) : wxBaseEnumPropertyClass(label,name)
{
m_index = 0;
if ( &labels )
{
wxPGChoices choices(labels,values);
m_choices = choices.ExtractData();
if ( GetItemCount() )
wxEnumPropertyClass::DoSetValue( (long)value );
}
}
wxEnumPropertyClass::wxEnumPropertyClass ( const wxString& label, const wxString& name,
wxPGChoices& choices, int value )
: wxBaseEnumPropertyClass(label,name)
{
m_choices.Assign( choices );
if ( GetItemCount() )
wxEnumPropertyClass::DoSetValue( (long)value );
}
int wxEnumPropertyClass::GetIndexForValue( int value ) const
{
if ( !m_choices.IsOk() )
return -1;
const wxArrayInt& arrValues = m_choices.GetValues();
if ( arrValues.GetCount() )
{
int intval = arrValues.Index(value);
// TODO: Use real default instead of 0.
if ( intval < 0 )
intval = 0;
return intval;
}
return value;
}
wxEnumPropertyClass::~wxEnumPropertyClass ()
{
}
const wxString* wxEnumPropertyClass::GetEntry( size_t index, int* pvalue ) const
{
if ( m_choices.IsOk() && index < m_choices.GetCount() )
{
const wxArrayInt& arrValues = m_choices.GetValues();
int value = (int)index;
if ( arrValues.GetCount() )
value = arrValues[index];
*pvalue = value;
return &m_choices.GetLabel(index);
}
return (const wxString*) NULL;
}
int wxEnumPropertyClass::GetChoiceInfo( wxPGChoiceInfo* choiceinfo )
{
if ( choiceinfo )
{
if ( !(m_flags & wxPG_PROP_STATIC_CHOICES) )
choiceinfo->m_choices = &m_choices;
if ( !m_choices.IsOk() )
return -1;
choiceinfo->m_itemCount = m_choices.GetCount();
if ( m_choices.GetCount() )
choiceinfo->m_arrWxString = (wxString*)&m_choices.GetLabel(0);
}
if ( !m_choices.IsOk() )
return -1;
return m_index;
}
// -----------------------------------------------------------------------
// wxEditEnumProperty
// -----------------------------------------------------------------------
class wxEditEnumPropertyClass : public wxEnumPropertyClass
{
WX_PG_DECLARE_PROPERTY_CLASS()
public:
wxEditEnumPropertyClass( const wxString& label, const wxString& name, const wxChar** labels,
const long* values, const wxString& value );
wxEditEnumPropertyClass( const wxString& label, const wxString& name,
const wxArrayString& labels, const wxArrayInt& values, const wxString& value );
wxEditEnumPropertyClass( const wxString& label, const wxString& name,
wxPGChoices& choices, const wxString& value );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -