// Author: Jaakko Salli
// Modified by:
// Created: 2005-05-14
-// RCS-ID: $Id:
+// RCS-ID: $Id$
// Copyright: (c) Jaakko Salli
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#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.
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;
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
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;
( 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;
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;
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
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
const wxULongLong& value ) : wxPGProperty(label,name)
{
Init();
- SetValue(wxULongLongToVariant(value));
+ SetValue(WXVARIANT(value));
}
wxUIntProperty::~wxUIntProperty() { }
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 )
{
{
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;
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;
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;
}
}
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;
}
}
bool res = text.ToDouble(&value);
if ( res )
{
- if ( m_value != value )
+ if ( variant != value )
{
variant = value;
return true;
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
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
// 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;
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());
}
}
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 )
{
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;
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;
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 );
// 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 );
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 )
// 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;
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
// -----------------------------------------------------------------------
//
unsigned int i;
- unsigned int prevChildCount = m_children.GetCount();
+ unsigned int prevChildCount = m_children.size();
int oldSel = -1;
if ( prevChildCount )
if ( selected )
{
if ( selected->GetParent() == this )
- oldSel = selected->GetArrIndex();
+ oldSel = selected->GetIndexInParent();
else if ( selected == this )
oldSel = -2;
}
// 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() )
{
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);
}
return false;
long newFlags = 0;
- long oldValue = m_value;
// semicolons are no longer valid delimeters
WX_PG_TOKENIZER1_BEGIN(text,wxS(','))
WX_PG_TOKENIZER1_END()
- variant = newFlags;
-
- if ( newFlags != oldValue )
+ if ( variant != (long)newFlags )
+ {
+ variant = (long)newFlags;
return true;
+ }
return false;
}
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
bool wxDirProperty::OnButtonClick( wxPropertyGrid* propGrid, wxString& value )
{
+ // Update property value from editor, if necessary
wxSize dlg_sz(300,400);
wxDirDialog dlg( propGrid,
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;
bool wxLongStringProperty::StringToValue( wxVariant& variant, const wxString& text, int ) const
{
- if ( m_value != text )
+ if ( variant != text )
{
variant = text;
return true;
IMPLEMENT_ABSTRACT_CLASS(wxArrayEditorDialog, wxDialog)
-#include <wx/statline.h>
+#include "wx/statline.h"
// -----------------------------------------------------------------------
const wxChar* cbt )
{
// Update the value
- PrepareValueForDialogEditing(propGrid);
+ wxVariant useValue = propGrid->GetUncommittedPropertyValue();
if ( !propGrid->EditorValidate() )
return false;
if ( strEdDlg )
strEdDlg->SetCustomButton(cbt, this);
- dlg->SetDialogValue( wxVariant(m_value) );
+ dlg->SetDialogValue( useValue );
dlg->Create(propGrid, wxEmptyString, m_label);
#if !wxPG_SMALL_SCREEN
// -----------------------------------------------------------------------
+#endif // wxUSE_PROPGRID