if ( HasFlag(wxPG_PROP_COMPOSED_VALUE) )
{
wxString s;
- GenerateComposedValue(s, 0);
+ DoGenerateComposedValue(s);
m_value = s;
}
}
wxStringProperty::~wxStringProperty() { }
-wxString wxStringProperty::GetValueAsString( int argFlags ) const
+wxString wxStringProperty::ValueToString( wxVariant& value,
+ int argFlags ) const
{
- wxString s = m_value.GetString();
+ wxString s = value.GetString();
if ( GetChildCount() && HasFlag(wxPG_PROP_COMPOSED_VALUE) )
{
// Value stored in m_value is non-editable, non-full value
if ( (argFlags & wxPG_FULL_VALUE) || (argFlags & wxPG_EDITABLE_VALUE) )
- GenerateComposedValue(s, argFlags);
+ {
+ // Calling this under incorrect conditions will fail
+ wxASSERT_MSG( argFlags & wxPG_VALUE_IS_CURRENT,
+ "Sorry, currently default wxPGProperty::ValueToString() "
+ "implementation only works if value is m_value." );
+
+ DoGenerateComposedValue(s, argFlags);
+ }
return s;
}
wxIntProperty::~wxIntProperty() { }
-wxString wxIntProperty::GetValueAsString( int ) const
+wxString wxIntProperty::ValueToString( wxVariant& value,
+ int WXUNUSED(argFlags) ) const
{
- if ( m_value.GetType() == wxPG_VARIANT_TYPE_LONG )
+ if ( value.GetType() == wxPG_VARIANT_TYPE_LONG )
{
- return wxString::Format(wxS("%li"),m_value.GetLong());
+ return wxString::Format(wxS("%li"),value.GetLong());
}
- else if ( m_value.GetType() == wxLongLong_VariantType )
+ else if ( value.GetType() == wxLongLong_VariantType )
{
wxLongLong ll;
- ll << m_value;
+ ll << value;
return ll.ToString();
}
wxUIntProperty::~wxUIntProperty() { }
-wxString wxUIntProperty::GetValueAsString( int ) const
+wxString wxUIntProperty::ValueToString( wxVariant& value,
+ int WXUNUSED(argFlags) ) const
{
size_t index = m_base + m_prefix;
if ( index >= wxPG_UINT_TEMPLATE_MAX )
index = wxPG_BASE_DEC;
- if ( m_value.GetType() == wxPG_VARIANT_TYPE_LONG )
+ if ( value.GetType() == wxPG_VARIANT_TYPE_LONG )
{
- return wxString::Format(gs_uintTemplates32[index], (unsigned long)m_value.GetLong());
+ return wxString::Format(gs_uintTemplates32[index], (unsigned long)value.GetLong());
}
wxULongLong ull;
- ull << m_value;
+ ull << value;
return wxString::Format(gs_uintTemplates64[index], ull.GetValue());
}
}
}
-wxString wxFloatProperty::GetValueAsString( int argFlags ) const
+wxString wxFloatProperty::ValueToString( wxVariant& value,
+ int argFlags ) const
{
wxString text;
- if ( !m_value.IsNull() )
+ if ( !value.IsNull() )
{
wxPropertyGrid::DoubleToString(text,
- m_value,
+ value,
m_precision,
!(argFlags & wxPG_FULL_VALUE),
(wxString*) NULL);
wxBoolProperty::~wxBoolProperty() { }
-wxString wxBoolProperty::GetValueAsString( int argFlags ) const
+wxString wxBoolProperty::ValueToString( wxVariant& value,
+ int argFlags ) const
{
- bool value = m_value.GetBool();
+ bool boolValue = value.GetBool();
// As a fragment of composite string value,
// make it a little more readable.
if ( argFlags & wxPG_COMPOSITE_FRAGMENT )
{
- if ( value )
+ if ( boolValue )
{
return m_label;
}
if ( !(argFlags & wxPG_FULL_VALUE) )
{
- return wxPGGlobalVars->m_boolChoices[value?1:0].GetText();
+ return wxPGGlobalVars->m_boolChoices[boolValue?1:0].GetText();
}
wxString text;
- if (value) text = wxS("true");
+ if ( boolValue ) text = wxS("true");
else text = wxS("false");
return text;
}
// -----------------------------------------------------------------------
-// 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();
}
}
-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
return true;
}
-wxString wxBaseEnumProperty::GetValueAsString( int ) const
+wxString wxEnumProperty::ValueToString( wxVariant& value,
+ int WXUNUSED(argFlags) ) const
{
- if ( m_value.GetType() == wxPG_VARIANT_TYPE_STRING )
- return m_value.GetString();
+ if ( value.GetType() == wxPG_VARIANT_TYPE_STRING )
+ return value.GetString();
- if ( m_index >= 0 )
- {
- int unusedVal;
- const wxString* pstr = GetEntry( m_index, &unusedVal );
+ int index = m_choices.Index(value.GetLong());
+ if ( index < 0 )
+ return wxEmptyString;
- if ( pstr )
- return *pstr;
- }
- return wxEmptyString;
+ 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;
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.
//
if ( ms_nextIndex != -2 )
{
if ( !(argFlags & wxPG_FULL_VALUE) )
- GetEntry(intVal, &intVal);
+ intVal = m_choices.GetValue(intVal);
variant = (long)intVal;
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;
-
- if ( m_choices.HasValues() )
- {
- 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 = (int)index;
- if ( m_choices.HasValue(index) )
- value = m_choices.GetValue(index);
-
- if ( pvalue )
- *pvalue = value;
-
- return &m_choices.GetLabel(index);
- }
- return (const wxString*) NULL;
-}
-
// -----------------------------------------------------------------------
// wxEditEnumProperty
// -----------------------------------------------------------------------
for ( i=0; i<GetItemCount(); i++ )
{
bool child_val;
- if ( choices.HasValue(i) )
- child_val = ( value & choices.GetValue(i) )?true:false;
- else
- child_val = ( value & (1<<i) )?true:false;
+ child_val = ( value & choices.GetValue(i) )?true:false;
wxPGProperty* boolProp;
wxString label = GetLabel(i);
const wxPGChoices& choices = m_choices;
for ( i = 0; i < GetItemCount(); i++ )
{
- if ( choices.HasValue(i) )
- fullFlags |= choices.GetValue(i);
- else
- fullFlags |= (1<<i);
+ fullFlags |= choices.GetValue(i);
}
val &= fullFlags;
{
int flag;
- if ( choices.HasValue(i) )
- flag = choices.GetValue(i);
- else
- flag = (1<<i);
+ flag = choices.GetValue(i);
if ( (newFlags & flag) != (m_oldValue & flag) )
Item(i)->SetFlag( wxPG_PROP_MODIFIED );
}
}
-wxString wxFlagsProperty::GetValueAsString( int ) const
+wxString wxFlagsProperty::ValueToString( wxVariant& value,
+ int WXUNUSED(argFlags) ) const
{
wxString text;
if ( !m_choices.IsOk() )
return text;
- long flags = m_value;
+ long flags = value;
unsigned int i;
const wxPGChoices& choices = m_choices;
for ( i = 0; i < GetItemCount(); i++ )
{
int doAdd;
- if ( choices.HasValue(i) )
- doAdd = ( flags & choices.GetValue(i) );
- else
- doAdd = ( flags & (1<<i) );
+ doAdd = ( flags & choices.GetValue(i) );
if ( doAdd )
{
{
if ( id == GetLabel(i) )
{
- if ( m_choices.HasValue(i) )
- return m_choices.GetValue(i);
- return (1<<i);
+ return m_choices.GetValue(i);
}
}
return -1;
{
long flag;
- if ( choices.HasValue(i) )
- flag = choices.GetValue(i);
- else
- flag = (1<<i);
+ flag = choices.GetValue(i);
long subVal = flags & flag;
wxPGProperty* p = Item(i);
{
long oldValue = thisValue.GetLong();
long val = childValue.GetLong();
- unsigned long vi = (1<<childIndex);
- if ( m_choices.HasValue(childIndex) ) vi = m_choices.GetValue(childIndex);
+ unsigned long vi = m_choices.GetValue(childIndex);
if ( val )
thisValue = (long)(oldValue | vi);
else
// Update property value from editor, if necessary
wxSize dlg_sz(300,400);
+ wxString dlgMessage(m_dlgMessage);
+ if ( dlgMessage.empty() )
+ dlgMessage = _("Choose a directory:");
wxDirDialog dlg( propGrid,
- m_dlgMessage.length() ? m_dlgMessage : wxString(_("Choose a directory:")),
+ dlgMessage,
value,
0,
#if !wxPG_SMALL_SCREEN
propGrid->GetGoodEditorDialogPosition(this,dlg_sz),
- dlg_sz );
+ dlg_sz
#else
wxDefaultPosition,
- wxDefaultSize );
+ wxDefaultSize
#endif
+ );
if ( dlg.ShowModal() == wxID_OK )
{
if ( property->IsKindOf(CLASSINFO(wxFileProperty)) )
{
fileProp = ((wxFileProperty*)property);
- path = fileProp->m_filename.GetPath();
+ wxFileName filename = fileProp->GetValue().GetString();
+ path = filename.GetPath();
indFilter = fileProp->m_indFilter;
if ( !path.length() && fileProp->m_basePath.length() )
{
const wxString& fnstr = m_value.GetString();
- m_filename = fnstr;
+ wxFileName filename = fnstr;
- if ( !m_filename.HasName() )
+ if ( !filename.HasName() )
{
m_value = wxPGVariant_EmptyString;
- m_filename.Clear();
}
// Find index for extension.
if ( m_indFilter < 0 && fnstr.length() )
{
- wxString ext = m_filename.GetExt();
+ wxString ext = filename.GetExt();
int curind = 0;
size_t pos = 0;
size_t len = m_wildcard.length();
}
}
-wxString wxFileProperty::GetValueAsString( int argFlags ) const
+wxFileName wxFileProperty::GetFileName() const
+{
+ wxFileName filename;
+
+ if ( !m_value.IsNull() )
+ filename = m_value.GetString();
+
+ return filename;
+}
+
+wxString wxFileProperty::ValueToString( wxVariant& value,
+ int argFlags ) const
{
- // Always return empty string when name component is empty
- wxString fullName = m_filename.GetFullName();
+ wxFileName filename = value.GetString();
+
+ if ( !filename.HasName() )
+ return wxEmptyString;
+
+ wxString fullName = filename.GetFullName();
if ( !fullName.length() )
- return fullName;
+ return wxEmptyString;
if ( argFlags & wxPG_FULL_VALUE )
{
- return m_filename.GetFullPath();
+ return filename.GetFullPath();
}
else if ( m_flags & wxPG_PROP_SHOW_FULL_FILENAME )
{
if ( m_basePath.Length() )
{
- wxFileName fn2(m_filename);
+ wxFileName fn2(filename);
fn2.MakeRelativeTo(m_basePath);
return fn2.GetFullPath();
}
- return m_filename.GetFullPath();
+ return filename.GetFullPath();
}
- return m_filename.GetFullName();
+ return filename.GetFullName();
}
wxPGEditorDialogAdapter* wxFileProperty::GetEditorDialog() const
bool wxFileProperty::StringToValue( wxVariant& variant, const wxString& text, int argFlags ) const
{
+ wxFileName filename = variant.GetString();
+
if ( (m_flags & wxPG_PROP_SHOW_FULL_FILENAME) || (argFlags & wxPG_FULL_VALUE) )
{
- if ( m_filename != text )
+ if ( filename != text )
{
variant = text;
return true;
}
else
{
- if ( m_filename.GetFullName() != text )
+ if ( filename.GetFullName() != text )
{
- wxFileName fn = m_filename;
+ wxFileName fn = filename;
fn.SetFullName(text);
variant = fn.GetFullPath();
return true;
wxLongStringProperty::~wxLongStringProperty() {}
-wxString wxLongStringProperty::GetValueAsString( int ) const
+wxString wxLongStringProperty::ValueToString( wxVariant& value,
+ int WXUNUSED(argFlags) ) const
{
- return m_value;
+ return value;
}
bool wxLongStringProperty::OnEvent( wxPropertyGrid* propGrid, wxWindow* WXUNUSED(primary),
// On wxMAC the dialog shows incorrectly if style is not exactly wxCAPTION
// FIXME: This should be only a temporary fix.
#ifdef __WXMAC__
+ wxUnusedVar(style);
int useStyle = wxCAPTION;
#else
int useStyle = style;
GenerateValueAsString();
}
-wxString wxArrayStringProperty::GetValueAsString( int WXUNUSED(argFlags) ) const
+#define ARRSTRPROP_ARRAY_TO_STRING(STRING,ARRAY) \
+ wxPropertyGrid::ArrayStringToString(STRING,ARRAY,wxS('"'),wxS('"'),1)
+
+wxString wxArrayStringProperty::ValueToString( wxVariant& WXUNUSED(value),
+ int argFlags ) const
{
- return m_display;
+ //
+ // If this is called from GetValueAsString(), return cached string
+ if ( argFlags & wxPG_VALUE_IS_CURRENT )
+ {
+ return m_display;
+ }
+
+ wxArrayString arr = m_value.GetArrayString();
+ wxString s;
+ ARRSTRPROP_ARRAY_TO_STRING(s, arr);
+ return s;
}
// Converts wxArrayString to a string separated by delimeters and spaces.
}
}
-#define ARRSTRPROP_ARRAY_TO_STRING(STRING,ARRAY) \
- wxPropertyGrid::ArrayStringToString(STRING,ARRAY,wxS('"'),wxS('"'),1);
-
void wxArrayStringProperty::GenerateValueAsString()
{
wxArrayString arr = m_value.GetArrayString();
- ARRSTRPROP_ARRAY_TO_STRING(m_display, arr)
+ ARRSTRPROP_ARRAY_TO_STRING(m_display, arr);
}
// Default implementation doesn't do anything.
{
wxArrayString actualValue = value.GetArrayString();
wxString tempStr;
- ARRSTRPROP_ARRAY_TO_STRING(tempStr, actualValue)
+ ARRSTRPROP_ARRAY_TO_STRING(tempStr, actualValue);
#if wxUSE_VALIDATORS
if ( dialogValidator.DoValidate( propGrid, validator, tempStr ) )
#endif