// Author: Jaakko Salli
// Modified by:
// Created: 2008-08-23
-// 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/panel.h"
#include "wx/dc.h"
#include "wx/dcmemory.h"
- #include "wx/button.h"
#include "wx/pen.h"
#include "wx/brush.h"
- #include "wx/cursor.h"
- #include "wx/dialog.h"
#include "wx/settings.h"
- #include "wx/msgdlg.h"
- #include "wx/choice.h"
- #include "wx/stattext.h"
- #include "wx/scrolwin.h"
- #include "wx/dirdlg.h"
- #include "wx/layout.h"
- #include "wx/sizer.h"
- #include "wx/textdlg.h"
- #include "wx/filedlg.h"
- #include "wx/statusbr.h"
#include "wx/intl.h"
- #include "wx/frame.h"
#endif
-#include <wx/propgrid/propgrid.h>
-
-#include <typeinfo>
+#include "wx/propgrid/propgrid.h"
#define PWC_CHILD_SUMMARY_LIMIT 16 // Maximum number of children summarized in a parent property's
#define PWC_CHILD_SUMMARY_CHAR_LIMIT 64 // Character limit of summary field when not editing
+#if wxPG_COMPATIBILITY_1_4
+
+// Used to establish backwards compatiblity
+const char* g_invalidStringContent = "@__TOTALLY_INVALID_STRING__@";
+
+#endif
// -----------------------------------------------------------------------
// Use choice cell?
if ( column == 1 && (flags & Control) )
{
- const wxPGCell* ccell = property->GetCurrentChoice();
- if ( ccell &&
- ( ccell->GetBitmap().IsOk() || ccell->GetFgCol().IsOk() || ccell->GetBgCol().IsOk() )
- )
- cell = ccell;
+ int selectedIndex = property->GetChoiceSelection();
+ if ( selectedIndex != wxNOT_FOUND )
+ {
+ const wxPGChoices& choices = property->GetChoices();
+ const wxPGCell* ccell = &choices[selectedIndex];
+ if ( ccell &&
+ ( ccell->GetBitmap().IsOk() || ccell->GetFgCol().IsOk() || ccell->GetBgCol().IsOk() )
+ )
+ cell = ccell;
+ }
}
if ( cell )
if ( column == 0 )
text = property->GetLabel();
else if ( column == 1 )
- text = property->GetValueString();
+ text = property->GetValueAsString();
else
text = wxEmptyString;
}
imageOffset = paintdata.m_drawnWidth;
}
- text = property->GetValueString();
+ text = property->GetValueAsString();
// Add units string?
if ( propertyGrid->GetColumnCount() <= 2 )
Init();
}
+void wxPGProperty::InitAfterAdded( wxPropertyGridPageState* pageState,
+ wxPropertyGrid* propgrid )
+{
+ //
+ // Called after property has been added to grid or page
+ // (so propgrid can be NULL, too).
+
+ wxPGProperty* parent = m_parent;
+ bool parentIsRoot = parent->IsKindOf(CLASSINFO(wxPGRootProperty));
+
+ m_parentState = pageState;
+
+#if wxPG_COMPATIBILITY_1_4
+ // Make sure deprecated virtual functions are not implemented
+ wxString s = GetValueAsString( 0xFFFF );
+ wxASSERT_MSG( s == g_invalidStringContent,
+ "Implement ValueToString() instead of GetValueAsString()" );
+#endif
+
+ if ( !parentIsRoot )
+ {
+ m_bgColIndex = parent->m_bgColIndex;
+ m_fgColIndex = parent->m_fgColIndex;
+ }
+
+ // If in hideable adding mode, or if assigned parent is hideable, then
+ // make this one hideable.
+ if (
+ ( !parentIsRoot && parent->HasFlag(wxPG_PROP_HIDDEN) ) ||
+ ( propgrid && (propgrid->HasInternalFlag(wxPG_FL_ADDING_HIDEABLES)) )
+ )
+ SetFlag( wxPG_PROP_HIDDEN );
+
+ // Set custom image flag.
+ int custImgHeight = OnMeasureImage().y;
+ if ( custImgHeight < 0 )
+ {
+ SetFlag(wxPG_PROP_CUSTOMIMAGE);
+ }
+
+ if ( propgrid && (propgrid->HasFlag(wxPG_LIMITED_EDITING)) )
+ SetFlag(wxPG_PROP_NOEDITOR);
+
+ // Make sure parent has some parental flags
+ if ( !parent->HasFlag(wxPG_PROP_PARENTAL_FLAGS) )
+ parent->SetParentalType(wxPG_PROP_MISC_PARENT);
+
+ if ( !IsCategory() )
+ {
+ // This is not a category.
+
+ // Depth.
+ //
+ unsigned char depth = 1;
+ if ( !parentIsRoot )
+ {
+ depth = parent->m_depth;
+ if ( !parent->IsCategory() )
+ depth++;
+ }
+ m_depth = depth;
+ unsigned char greyDepth = depth;
+
+ if ( !parentIsRoot )
+ {
+ wxPropertyCategory* pc;
+
+ if ( parent->IsCategory() )
+ pc = (wxPropertyCategory* ) parent;
+ else
+ // This conditional compile is necessary to
+ // bypass some compiler bug.
+ pc = pageState->GetPropertyCategory(parent);
+
+ if ( pc )
+ greyDepth = pc->GetDepth();
+ else
+ greyDepth = parent->m_depthBgCol;
+ }
+
+ m_depthBgCol = greyDepth;
+ }
+ else
+ {
+ // This is a category.
+
+ // depth
+ unsigned char depth = 1;
+ if ( !parentIsRoot )
+ {
+ depth = parent->m_depth + 1;
+ }
+ m_depth = depth;
+ m_depthBgCol = depth;
+ }
+
+ //
+ // Has initial children
+ if ( GetChildCount() )
+ {
+ FlagType parentalFlags = m_flags & wxPG_PROP_PARENTAL_FLAGS;
+
+ // Check parental flags
+ wxASSERT_MSG( parentalFlags,
+ "Call SetFlag(wxPG_PROP_MISC_PARENT) or"
+ "SetFlag(wxPG_PROP_AGGREGATE) before calling"
+ "wxPGProperty::AddChild()." );
+
+ if ( HasFlag(wxPG_PROP_AGGREGATE) )
+ {
+ // Properties with private children are not expanded by default.
+ SetExpanded(false);
+ }
+ else if ( propgrid && propgrid->HasFlag(wxPG_HIDE_MARGIN) )
+ {
+ // ...unless it cannot be expanded by user and therefore must
+ // remain visible at all times
+ SetExpanded(true);
+ }
+
+ //
+ // Prepare children recursively
+ for ( unsigned int i=0; i<GetChildCount(); i++ )
+ {
+ wxPGProperty* child = Item(i);
+ child->InitAfterAdded(pageState, pageState->GetGrid());
+ }
+
+ if ( propgrid && (propgrid->GetExtraStyle() & wxPG_EX_AUTO_UNSPECIFIED_VALUES) )
+ SetFlagRecursively(wxPG_PROP_AUTO_UNSPECIFIED, true);
+ }
+}
+
wxPGProperty::wxPGProperty()
: wxObject()
{
return m_parentState->GetGrid();
}
+int wxPGProperty::Index( const wxPGProperty* p ) const
+{
+ for ( unsigned int i = 0; i<m_children.size(); i++ )
+ {
+ if ( p == m_children[i] )
+ return i;
+ }
+ return wxNOT_FOUND;
+}
void wxPGProperty::UpdateControl( wxWindow* primary )
{
return wxEmptyString;
}
-void wxPGProperty::GenerateComposedValue( wxString& text, int argFlags ) const
+void wxPGProperty::DoGenerateComposedValue( wxString& text,
+ int argFlags,
+ const wxVariantList* valueOverrides,
+ wxPGHashMapS2S* childResults ) const
{
int i;
- int iMax = m_children.GetCount();
+ int iMax = m_children.size();
text.clear();
if ( iMax == 0 )
if ( !IsTextEditable() )
argFlags |= wxPG_UNEDITABLE_COMPOSITE_FRAGMENT;
- wxPGProperty* curChild = (wxPGProperty*) m_children.Item(0);
+ wxPGProperty* curChild = m_children[0];
+
+ bool overridesLeft = false;
+ wxVariant overrideValue;
+ wxVariantList::const_iterator node;
+
+ if ( valueOverrides )
+ {
+ node = valueOverrides->begin();
+ if ( node != valueOverrides->end() )
+ {
+ overrideValue = *node;
+ overridesLeft = true;
+ }
+ }
for ( i = 0; i < iMax; i++ )
{
+ wxVariant childValue;
+
+ wxString childLabel = curChild->GetLabel();
+
+ // Check for value override
+ if ( overridesLeft && overrideValue.GetName() == childLabel )
+ {
+ if ( !overrideValue.IsNull() )
+ childValue = overrideValue;
+ else
+ childValue = curChild->GetValue();
+ node++;
+ if ( node != valueOverrides->end() )
+ overrideValue = *node;
+ else
+ overridesLeft = false;
+ }
+ else
+ {
+ childValue = curChild->GetValue();
+ }
+
wxString s;
- if ( !curChild->IsValueUnspecified() )
- s = curChild->GetValueString(argFlags|wxPG_COMPOSITE_FRAGMENT);
+ if ( !childValue.IsNull() )
+ {
+ if ( overridesLeft &&
+ curChild->HasFlag(wxPG_PROP_COMPOSED_VALUE) &&
+ childValue.GetType() == wxPG_VARIANT_TYPE_LIST )
+ {
+ wxVariantList& childList = childValue.GetList();
+ DoGenerateComposedValue(s, argFlags|wxPG_COMPOSITE_FRAGMENT,
+ &childList, childResults);
+ }
+ else
+ {
+ s = curChild->ValueToString(childValue,
+ argFlags|wxPG_COMPOSITE_FRAGMENT);
+ }
+ }
+
+ if ( childResults && curChild->GetChildCount() )
+ (*childResults)[curChild->GetName()] = s;
bool skip = false;
if ( (argFlags & wxPG_UNEDITABLE_COMPOSITE_FRAGMENT) && !s.length() )
text += wxS(" ");
}
- curChild = (wxPGProperty*) m_children.Item(i+1);
+ curChild = m_children[i+1];
}
}
if ( text.EndsWith(wxS("; "), &rest) )
text = rest;
- if ( (unsigned int)i < m_children.GetCount() )
+ if ( (unsigned int)i < m_children.size() )
text += wxS("; ...");
}
-wxString wxPGProperty::GetValueAsString( int argFlags ) const
+wxString wxPGProperty::ValueToString( wxVariant& WXUNUSED(value),
+ int argFlags ) const
{
wxCHECK_MSG( GetChildCount() > 0,
wxString(),
- wxT("If user property does not have any children, it must override GetValueAsString") );
+ "If user property does not have any children, it must "
+ "override GetValueAsString" );
+
+ // FIXME: Currently code below only works if value is actually m_value
+ wxASSERT_MSG( argFlags & wxPG_VALUE_IS_CURRENT,
+ "Sorry, currently default wxPGProperty::ValueToString() "
+ "implementation only works if value is m_value." );
wxString text;
- GenerateComposedValue(text, argFlags);
+ DoGenerateComposedValue(text, argFlags);
return text;
}
-wxString wxPGProperty::GetValueString( int argFlags ) const
+wxString wxPGProperty::GetValueAsString( int argFlags ) const
{
+#if wxPG_COMPATIBILITY_1_4
+ // This is backwards compatibility test
+ // That is, to make sure this function is not overridden
+ // (instead, ValueToString() should be).
+ if ( argFlags == 0xFFFF )
+ {
+ // Do not override! (for backwards compliancy)
+ return g_invalidStringContent;
+ }
+#endif
+
if ( IsValueUnspecified() )
return wxEmptyString;
if ( m_commonValue == -1 )
- return GetValueAsString(argFlags);
+ {
+ wxVariant value(GetValue());
+ return ValueToString(value, argFlags|wxPG_VALUE_IS_CURRENT);
+ }
//
// Return common value's string representation
}
}
+wxString wxPGProperty::GetValueString( int argFlags ) const
+{
+ return GetValueAsString(argFlags);
+}
+
bool wxPGProperty::IntToValue( wxVariant& variant, int number, int WXUNUSED(argFlags) ) const
{
variant = (long)number;
unsigned int curChild = 0;
- unsigned int iMax = m_children.GetCount();
+ unsigned int iMax = m_children.size();
if ( iMax > PWC_CHILD_SUMMARY_LIMIT &&
!(argFlags & wxPG_FULL_VALUE) )
wxVariantList temp_list;
wxVariant list(temp_list);
- int propagatedFlags = argFlags & wxPG_REPORT_ERROR;
+ int propagatedFlags = argFlags & (wxPG_REPORT_ERROR|wxPG_PROGRAMMATIC_VALUE);
#ifdef __WXDEBUG__
bool debug_print = false;
if ( !addOnlyIfNotEmpty || len > 0 )
{
const wxPGProperty* child = Item(curChild);
+ wxVariant variant(child->GetValue());
+ variant.SetName(child->GetBaseName());
+
#ifdef __WXDEBUG__
if ( debug_print )
wxLogDebug(wxT("token = '%s', child = %s"),token.c_str(),child->GetLabel().c_str());
#endif
- if ( len > 0 )
+ // Add only if editable or setting programmatically
+ if ( (argFlags & wxPG_PROGRAMMATIC_VALUE) ||
+ !child->HasFlag(wxPG_PROP_DISABLED|wxPG_PROP_READONLY) )
{
- bool wasUnspecified = child->IsValueUnspecified();
-
- wxVariant variant(child->GetValueRef());
- if ( child->StringToValue(variant, token, propagatedFlags|wxPG_COMPOSITE_FRAGMENT) )
+ if ( len > 0 )
{
- variant.SetName(child->GetBaseName());
+ bool wasUnspecified = child->IsValueUnspecified();
- // Clear unspecified flag only if OnSetValue() didn't
- // affect it.
- if ( child->IsValueUnspecified() &&
- (wasUnspecified || !UsesAutoUnspecified()) )
+ if ( child->StringToValue(variant, token, propagatedFlags|wxPG_COMPOSITE_FRAGMENT) )
{
- variant = child->GetDefaultValue();
- }
+ // Clear unspecified flag only if OnSetValue() didn't
+ // affect it.
+ if ( child->IsValueUnspecified() &&
+ (wasUnspecified || !UsesAutoUnspecified()) )
+ {
+ variant = child->GetDefaultValue();
+ }
- list.Append(variant);
+ list.Append(variant);
+ changed = true;
+ }
+ }
+ else
+ {
+ // Empty, becomes unspecified
+ variant.MakeNull();
+ list.Append(variant);
changed = true;
}
}
- else
- {
- // Empty, becomes unspecified
- wxVariant variant2;
- variant2.SetName(child->GetBaseName());
- list.Append(variant2);
- changed = true;
- }
curChild++;
if ( curChild >= iMax )
const wxPGProperty* child = Item(curChild);
- wxVariant variant(child->GetValueRef());
- if ( child->StringToValue( variant, token, propagatedFlags ) )
- {
- variant.SetName(child->GetBaseName());
- list.Append(variant);
- changed = true;
- }
- else
+ wxVariant oldChildValue = child->GetValue();
+ wxVariant variant(oldChildValue);
+
+ if ( (argFlags & wxPG_PROGRAMMATIC_VALUE) ||
+ !child->HasFlag(wxPG_PROP_DISABLED|wxPG_PROP_READONLY) )
{
- // Failed, becomes unspecified
- wxVariant variant2;
- variant2.SetName(child->GetBaseName());
- list.Append(variant2);
- changed = true;
+ bool stvRes = child->StringToValue( variant, token, propagatedFlags );
+ if ( stvRes || (variant != oldChildValue) )
+ {
+ if ( stvRes )
+ changed = true;
+ }
+ else
+ {
+ // Failed, becomes unspecified
+ variant.MakeNull();
+ changed = true;
+ }
}
+ variant.SetName(child->GetBaseName());
+ list.Append(variant);
+
curChild++;
if ( curChild >= iMax )
break;
const wxPGEditor* wxPGProperty::DoGetEditorClass() const
{
- return wxPG_EDITOR(TextCtrl);
+ return wxPGEditor_TextCtrl;
}
// Default extra property event handling - that is, none at all.
void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
{
+ // If auto unspecified values are not wanted (via window or property style),
+ // then get default value instead of wxNullVariant.
+ if ( value.IsNull() && (flags & wxPG_SETVAL_BY_USER) &&
+ !UsesAutoUnspecified() )
+ {
+ value = GetDefaultValue();
+ }
+
if ( !value.IsNull() )
{
wxVariant tempListVariant;
// List variants are reserved a special purpose
// as intermediate containers for child values
// of properties with children.
- if ( wxPGIsVariantType(value, list) )
+ if ( value.GetType() == wxPG_VARIANT_TYPE_LIST )
{
//
// However, situation is different for composed string properties
if ( pList && !pList->IsNull() )
{
- wxASSERT( wxPGIsVariantType(*pList, list) );
+ wxASSERT( pList->GetType() == wxPG_VARIANT_TYPE_LIST );
wxASSERT( GetChildCount() );
wxASSERT( !IsCategory() );
if ( child )
{
//wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
- if ( wxPGIsVariantType(childValue, list) )
+ if ( childValue.GetType() == wxPG_VARIANT_TYPE_LIST )
{
if ( child->HasFlag(wxPG_PROP_AGGREGATE) && !(flags & wxPG_SETVAL_AGGREGATED) )
{
child->SetValue(oldVal, &childValue, flags|wxPG_SETVAL_FROM_PARENT);
}
}
- else if ( !wxPG_VARIANT_EQ(child->GetValue(), childValue) )
+ else if ( child->GetValue() != childValue )
{
// For aggregate properties, we will trust RefreshChildren()
// to update child values.
if ( !value.IsNull() )
{
- wxPGVariantAssign(m_value, value);
+ m_value = value;
OnSetValue();
if ( !(flags & wxPG_SETVAL_FROM_PARENT) )
if ( !value.IsNull() )
{
- wxPGVariantDataClassInfo classInfo = wxPGVariantDataGetClassInfo(value.GetData());
- if ( wxPGIsVariantClassInfo(classInfo, long) )
+ wxString valueType(value.GetType());
+
+ if ( valueType == wxPG_VARIANT_TYPE_LONG )
return wxPGVariant_Zero;
- if ( wxPGIsVariantClassInfo(classInfo, string) )
+ if ( valueType == wxPG_VARIANT_TYPE_STRING )
return wxPGVariant_EmptyString;
- if ( wxPGIsVariantClassInfo(classInfo, bool) )
+ if ( valueType == wxPG_VARIANT_TYPE_BOOL )
return wxPGVariant_False;
- if ( wxPGIsVariantClassInfo(classInfo, double) )
+ if ( valueType == wxPG_VARIANT_TYPE_DOUBLE )
return wxVariant(0.0);
-
- wxPGVariantData* pgvdata = wxDynamicCastVariantData(m_value.GetData(), wxPGVariantData);
- if ( pgvdata )
- return pgvdata->GetDefaultValue();
-
- if ( wxPGIsVariantClassInfo(classInfo, arrstring) )
+ if ( valueType == wxPG_VARIANT_TYPE_ARRSTRING )
return wxVariant(wxArrayString());
- if ( wxPGIsVariantClassInfo(classInfo, wxColour) )
- return WXVARIANT(*wxRED);
+ if ( valueType == wxS("wxLongLong") )
+ return WXVARIANT(wxLongLong(0));
+ if ( valueType == wxS("wxULongLong") )
+ return WXVARIANT(wxULongLong(0));
+ if ( valueType == wxS("wxColour") )
+ return WXVARIANT(*wxBLACK);
#if wxUSE_DATETIME
- if ( wxPGIsVariantClassInfo(classInfo, datetime) )
+ if ( valueType == wxPG_VARIANT_TYPE_DATETIME )
return wxVariant(wxDateTime::Now());
#endif
-
- wxFAIL_MSG(
- wxString::Format(wxT("Inorder for value to have default value, it must be added to")
- wxT("wxPGProperty::GetDefaultValue or it's variantdata must inherit")
- wxT("from wxPGVariantData (unrecognized type was '%s')"),m_value.GetType().c_str())
- );
+ if ( valueType == wxS("wxFont") )
+ return WXVARIANT(*wxNORMAL_FONT);
+ if ( valueType == wxS("wxPoint") )
+ return WXVARIANT(wxPoint(0, 0));
+ if ( valueType == wxS("wxSize") )
+ return WXVARIANT(wxSize(0, 0));
}
return wxVariant();
m_cells[column] = cellObj;
}
-void wxPGProperty::SetChoiceSelection( int newValue, const wxPGChoiceInfo& choiceInfo )
-{
- // Changes value of a property with choices, but only
- // works if the value type is long or string.
- wxString ts = GetValue().GetType();
-
- wxCHECK_RET( choiceInfo.m_choices, wxT("invalid choiceinfo") );
-
- if ( ts == wxS("long") )
- {
- SetValue( (long) newValue );
- }
- else if ( ts == wxS("string") )
- {
- SetValue( choiceInfo.m_choices->GetLabel(newValue) );
- }
-}
-
-
-wxString wxPGProperty::GetChoiceString( unsigned int index )
-{
- wxPGChoiceInfo ci;
- GetChoiceInfo(&ci);
- wxASSERT(ci.m_choices);
- return ci.m_choices->GetLabel(index);
-}
-
-int wxPGProperty::InsertChoice( const wxString& label, int index, int value )
-{
- wxPropertyGrid* pg = GetGrid();
-
- wxPGChoiceInfo ci;
- ci.m_choices = (wxPGChoices*) NULL;
- int sel = GetChoiceInfo(&ci);
-
- if ( ci.m_choices )
- {
- int newSel = sel;
-
- if ( index < 0 )
- index = ci.m_choices->GetCount();
-
- if ( index <= sel )
- newSel++;
-
- ci.m_choices->Insert(label, index, value);
-
- if ( sel != newSel )
- SetChoiceSelection(newSel, ci);
-
- if ( this == pg->GetSelection() )
- GetEditorClass()->InsertItem(pg->GetEditorControl(),label,index);
-
- return index;
- }
-
- return -1;
-}
-
-
-void wxPGProperty::DeleteChoice( int index )
-{
- wxPropertyGrid* pg = GetGrid();
-
- wxPGChoiceInfo ci;
- ci.m_choices = (wxPGChoices*) NULL;
- int sel = GetChoiceInfo(&ci);
-
- if ( ci.m_choices )
- {
- int newSel = sel;
-
- // Adjust current value
- if ( sel == index )
- {
- SetValueToUnspecified();
- newSel = 0;
- }
- else if ( index < sel )
- {
- newSel--;
- }
-
- ci.m_choices->RemoveAt(index);
-
- if ( sel != newSel )
- SetChoiceSelection(newSel, ci);
-
- if ( this == pg->GetSelection() )
- GetEditorClass()->DeleteItem(pg->GetEditorControl(), index);
- }
-}
-
-int wxPGProperty::GetChoiceInfo( wxPGChoiceInfo* WXUNUSED(info) )
-{
- return -1;
-}
-
wxPGEditorDialogAdapter* wxPGProperty::GetEditorDialog() const
{
return NULL;
return (wxValidator*) NULL;
}
-wxPGChoices& wxPGProperty::GetChoices()
+int wxPGProperty::InsertChoice( const wxString& label, int index, int value )
{
- wxPGChoiceInfo choiceInfo;
- choiceInfo.m_choices = NULL;
- GetChoiceInfo(&choiceInfo);
- return *choiceInfo.m_choices;
+ wxPropertyGrid* pg = GetGrid();
+ int sel = GetChoiceSelection();
+
+ int newSel = sel;
+
+ if ( index == wxNOT_FOUND )
+ index = m_choices.GetCount();
+
+ if ( index <= sel )
+ newSel++;
+
+ m_choices.Insert(label, index, value);
+
+ if ( sel != newSel )
+ SetChoiceSelection(newSel);
+
+ if ( this == pg->GetSelection() )
+ GetEditorClass()->InsertItem(pg->GetEditorControl(),label,index);
+
+ return index;
}
-const wxPGChoices& wxPGProperty::GetChoices() const
+
+void wxPGProperty::DeleteChoice( int index )
{
- return (const wxPGChoices&) ((wxPGProperty*)this)->GetChoices();
+ wxPropertyGrid* pg = GetGrid();
+
+ int sel = GetChoiceSelection();
+ int newSel = sel;
+
+ // Adjust current value
+ if ( sel == index )
+ {
+ SetValueToUnspecified();
+ newSel = 0;
+ }
+ else if ( index < sel )
+ {
+ newSel--;
+ }
+
+ m_choices.RemoveAt(index);
+
+ if ( sel != newSel )
+ SetChoiceSelection(newSel);
+
+ if ( this == pg->GetSelection() )
+ GetEditorClass()->DeleteItem(pg->GetEditorControl(), index);
}
-unsigned int wxPGProperty::GetChoiceCount() const
+int wxPGProperty::GetChoiceSelection() const
{
- const wxPGChoices& choices = GetChoices();
- if ( &choices && choices.IsOk() )
- return choices.GetCount();
- return 0;
+ wxVariant value = GetValue();
+ wxString valueType = value.GetType();
+ int index = wxNOT_FOUND;
+
+ if ( IsValueUnspecified() || !m_choices.GetCount() )
+ return wxNOT_FOUND;
+
+ if ( valueType == wxPG_VARIANT_TYPE_LONG )
+ {
+ index = value.GetLong();
+ }
+ else if ( valueType == wxPG_VARIANT_TYPE_STRING )
+ {
+ index = m_choices.Index(value.GetString());
+ }
+ else if ( valueType == wxPG_VARIANT_TYPE_BOOL )
+ {
+ index = value.GetBool()? 1 : 0;
+ }
+
+ return index;
}
-const wxPGChoiceEntry* wxPGProperty::GetCurrentChoice() const
+void wxPGProperty::SetChoiceSelection( int newValue )
{
- wxPGChoiceInfo ci;
- ci.m_choices = (wxPGChoices*) NULL;
- int index = ((wxPGProperty*)this)->GetChoiceInfo(&ci);
- if ( index == -1 || !ci.m_choices || index >= (int)ci.m_choices->GetCount() )
- return NULL;
+ // Changes value of a property with choices, but only
+ // works if the value type is long or string.
+ wxString valueType = GetValue().GetType();
+
+ wxCHECK_RET( m_choices.IsOk(), wxT("invalid choiceinfo") );
- return &(*ci.m_choices)[index];
+ if ( valueType == wxPG_VARIANT_TYPE_STRING )
+ {
+ SetValue( m_choices.GetLabel(newValue) );
+ }
+ else // if ( valueType == wxPG_VARIANT_TYPE_LONG )
+ {
+ SetValue( (long) newValue );
+ }
}
bool wxPGProperty::SetChoices( wxPGChoices& choices )
{
- wxPGChoiceInfo ci;
- ci.m_choices = (wxPGChoices*) NULL;
+ m_choices.Assign(choices);
- // Unref existing
- GetChoiceInfo(&ci);
- if ( ci.m_choices )
{
- ci.m_choices->Assign(choices);
-
- //if ( m_parent )
- {
- // This may be needed to trigger some initialization
- // (but don't do it if property is somewhat uninitialized)
- wxVariant defVal = GetDefaultValue();
- if ( defVal.IsNull() )
- return false;
-
- SetValue(defVal);
+ // This may be needed to trigger some initialization
+ // (but don't do it if property is somewhat uninitialized)
+ wxVariant defVal = GetDefaultValue();
+ if ( defVal.IsNull() )
+ return false;
- return true;
- }
+ SetValue(defVal);
}
- return false;
+
+ return true;
}
{
// TextCtrlAndButton -> ComboBoxAndButton
if ( editor->IsKindOf(CLASSINFO(wxPGTextCtrlAndButtonEditor)) )
- editor = wxPG_EDITOR(ChoiceAndButton);
+ editor = wxPGEditor_ChoiceAndButton;
// TextCtrl -> ComboBox
else if ( editor->IsKindOf(CLASSINFO(wxPGTextCtrlEditor)) )
- editor = wxPG_EDITOR(ComboBox);
+ editor = wxPGEditor_ComboBox;
}
return editor;
}
-
-// Privatizes set of choices
-void wxPGProperty::SetChoicesExclusive()
-{
- wxPGChoiceInfo ci;
- ci.m_choices = (wxPGChoices*) NULL;
-
- GetChoiceInfo(&ci);
- if ( ci.m_choices )
- ci.m_choices->SetExclusive();
-}
-
bool wxPGProperty::HasVisibleChildren() const
{
unsigned int i;
return false;
}
-bool wxPGProperty::PrepareValueForDialogEditing( wxPropertyGrid* propGrid )
-{
- return propGrid->EditorValidate();
-}
-
-
bool wxPGProperty::RecreateEditor()
{
wxPropertyGrid* pg = GetGrid();
return GetY2(GetGrid()->GetRowHeight());
}
-
-wxPGProperty* wxPGPropArgCls::GetPtr( wxPropertyGridInterface* methods ) const
-{
- if ( !m_isName )
- {
- wxASSERT_MSG( m_ptr.property, wxT("invalid property ptr") );
- return m_ptr.property;
- }
- else if ( m_isName == 1 )
- return methods->GetPropertyByNameA(*m_ptr.name);
- else if ( m_isName == 2 )
- return methods->GetPropertyByNameA(m_ptr.rawname);
- // 3 is like 1, but ptr is freed in dtor - only needed by wxPython bindings.
- else if ( m_isName == 3 )
- return methods->GetPropertyByNameA(*m_ptr.name);
-
- wxASSERT( m_isName <= 3 );
- return NULL;
-}
-
// This is used by Insert etc.
void wxPGProperty::AddChild2( wxPGProperty* prop, int index, bool correct_mode )
{
- if ( index < 0 || (size_t)index >= m_children.GetCount() )
+ if ( index < 0 || (size_t)index >= m_children.size() )
{
- if ( correct_mode ) prop->m_arrIndex = m_children.GetCount();
- m_children.Add( prop );
+ if ( correct_mode ) prop->m_arrIndex = m_children.size();
+ m_children.push_back( prop );
}
else
{
- m_children.Insert( prop, index );
- if ( correct_mode ) FixIndexesOfChildren( index );
+ m_children.insert( m_children.begin()+index, prop);
+ if ( correct_mode ) FixIndicesOfChildren( index );
}
prop->m_parent = this;
wxASSERT_MSG( prop->GetBaseName().length(),
"Property's children must have unique, non-empty names within their scope" );
- prop->m_arrIndex = m_children.GetCount();
- m_children.Add( prop );
+ prop->m_arrIndex = m_children.size();
+ m_children.push_back( prop );
int custImgHeight = prop->OnMeasureImage().y;
if ( custImgHeight < 0 /*|| custImgHeight > 1*/ )
prop->m_parent = this;
}
+void wxPGProperty::RemoveChild( wxPGProperty* p )
+{
+ wxArrayPGProperty::iterator it;
+ wxArrayPGProperty& children = m_children;
+
+ for ( it=children.begin(); it != children.end(); it++ )
+ {
+ if ( *it == p )
+ {
+ m_children.erase(it);
+ break;
+ }
+ }
+}
void wxPGProperty::AdaptListToValue( wxVariant& list, wxVariant* value ) const
{
{
//wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
- if ( wxPGIsVariantType(childValue, list) )
+ if ( childValue.GetType() == wxPG_VARIANT_TYPE_LIST )
{
wxVariant cv2(child->GetValue());
child->AdaptListToValue(childValue, &cv2);
}
-void wxPGProperty::FixIndexesOfChildren( size_t starthere )
+void wxPGProperty::FixIndicesOfChildren( unsigned int starthere )
{
size_t i;
for ( i=starthere;i<GetChildCount();i++)
{
for ( i=0; i<GetChildCount(); i++ )
{
- wxPGProperty* p = (wxPGProperty*) Item(i);
- delete p;
+ delete m_children[i];
}
}
- m_children.Empty();
+ m_children.clear();
}
void wxPGProperty::ChildChanged( wxVariant& WXUNUSED(thisValue),
{
const wxVariant* childList = NULL;
- if ( listValue && wxPGIsVariantType(*listValue, list) )
+ if ( listValue && listValue->GetType() == wxPG_VARIANT_TYPE_LIST )
childList = listValue;
if ( !child->AreAllChildrenSpecified((wxVariant*)childList) )
!parent->IsCategory() && !parent->IsRoot() )
{
wxString s;
- parent->GenerateComposedValue(s, 0);
+ parent->DoGenerateComposedValue(s);
parent->m_value = s;
return parent->UpdateParentValues();
}
return true;
}
-// Call for after sub-properties added with AddChild
-void wxPGProperty::PrepareSubProperties()
-{
- wxPropertyGridPageState* state = GetParentState();
-
- wxASSERT(state);
-
- if ( !GetChildCount() )
- return;
-
- wxByte depth = m_depth + 1;
- wxByte depthBgCol = m_depthBgCol;
-
- FlagType inheritFlags = m_flags & wxPG_INHERITED_PROPFLAGS;
-
- wxByte bgColIndex = m_bgColIndex;
- wxByte fgColIndex = m_fgColIndex;
-
- //
- // Set some values to the children
- //
- size_t i = 0;
- wxPGProperty* nparent = this;
-
- while ( i < nparent->GetChildCount() )
- {
- wxPGProperty* np = nparent->Item(i);
-
- np->m_parentState = state;
- np->m_flags |= inheritFlags; // Hideable also if parent.
- np->m_depth = depth;
- np->m_depthBgCol = depthBgCol;
- np->m_bgColIndex = bgColIndex;
- np->m_fgColIndex = fgColIndex;
-
- // Also handle children of children
- if ( np->GetChildCount() > 0 )
- {
- nparent = np;
- i = 0;
-
- // Init
- nparent->SetParentalType(wxPG_PROP_AGGREGATE);
- nparent->SetExpanded(false);
- depth++;
- }
- else
- {
- // Next sibling
- i++;
- }
-
- // After reaching last sibling, go back to processing
- // siblings of the parent
- while ( i >= nparent->GetChildCount() )
- {
- // Exit the loop when top parent hit
- if ( nparent == this )
- break;
-
- depth--;
-
- i = nparent->GetArrIndex() + 1;
- nparent = nparent->GetParent();
- }
- }
-}
-
// Call after fixed sub-properties added/removed after creation.
// if oldSelInd >= 0 and < new max items, then selection is
// moved to it. Note: oldSelInd -2 indicates that this property
wxPropertyGridPageState* state = GetParentState();
wxPropertyGrid* grid = state->GetGrid();
- PrepareSubProperties();
+ //
+ // Re-repare children (recursively)
+ for ( unsigned int i=0; i<GetChildCount(); i++ )
+ {
+ wxPGProperty* child = Item(i);
+ child->InitAfterAdded(state, grid);
+ }
wxPGProperty* sel = (wxPGProperty*) NULL;
- if ( oldSelInd >= (int)m_children.GetCount() )
- oldSelInd = (int)m_children.GetCount() - 1;
+ if ( oldSelInd >= (int)m_children.size() )
+ oldSelInd = (int)m_children.size() - 1;
if ( oldSelInd >= 0 )
- sel = (wxPGProperty*) m_children[oldSelInd];
+ sel = m_children[oldSelInd];
else if ( oldSelInd == -2 )
sel = this;
}
-wxString wxPropertyCategory::GetValueAsString( int ) const
+wxString wxPropertyCategory::ValueToString( wxVariant& WXUNUSED(value),
+ int WXUNUSED(argFlags) ) const
{
return wxEmptyString;
}
// Free old, if any
wxPGHashMapS2P::iterator it = m_map.find(name);
if ( it != m_map.end() )
+ {
((wxVariantData*)it->second)->DecRef();
+ if ( !data )
+ {
+ // If Null variant, just remove from set
+ m_map.erase(it);
+ return;
+ }
+ }
+
if ( data )
+ {
data->IncRef();
- m_map[name] = data;
+ m_map[name] = data;
+ }
}
+#endif // wxUSE_PROPGRID