コード例 #1
0
//! fills the property with children - must be called after the array has been inserted to the property list
void wxArrayProperty::Fill(ArrayProperty* pProperty)
{
	s32 numProperties = pProperty->GetProperties().size();
	for(s32 i=0; i<numProperties; ++i)
	{
		IProperty* pSubProperty = pProperty->GetProperties()[i];

		std::stringstream ss;
		ss << "[" << i << "]";
		pSubProperty->SetName(ss.str());

		wxPGProperty* pWxProperty = PropertyList::GetWxProperty(pSubProperty, m_pParent);
		InsertChild(-1, pWxProperty);
		bool bParentDisabled = !GetGrid()->IsPropertyEnabled(this);
		if(bParentDisabled)
		{
			GetGrid()->DisableProperty(pWxProperty);
		}
	}

	UpdateValue();
}
コード例 #2
0
bool wxArrayPropertyEditor::OnEvent( wxPropertyGrid* propGrid,
                                     wxPGProperty* property,
                                     wxWindow* ctrl,
                                     wxEvent& event ) const
{
    if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED )
    {
        wxPGMultiButton* buttons = (wxPGMultiButton*) propGrid->GetEditorControlSecondary();
		wxArrayProperty* pArrayProperty = static_cast<wxArrayProperty*>(property);

		if(event.GetId() == buttons->GetButtonId(0)) // + - add element
		{
			if(pArrayProperty->GetMaxElems() < 0
			|| pArrayProperty->GetChildCount() < u32(pArrayProperty->GetMaxElems()))
			{
				// determine new property name
				IProperty* pNewProperty = pArrayProperty->GetSubPropertyTemplate();
				std::stringstream ss;
				ss << "[" << property->GetChildCount() << "]";
				pNewProperty->SetName(ss.str());

				// create a new wxPGProperty out of it and insert it
				wxPGProperty* pWxProperty = PropertyList::GetWxProperty(pNewProperty, pArrayProperty->GetParent());
				property->InsertChild(-1, pWxProperty);

				if(pNewProperty->GetType() == PT_Reference)
				{
					pArrayProperty->GetParent()->FillArrayProperties(pNewProperty, pWxProperty);	
				}

				pArrayProperty->UpdateValue();
				propGrid->RefreshProperty(property);			

				// update the corresponding property in the property stream
				wxPropertyGridEvent PGEvent;
				PGEvent.SetProperty(property);
				pArrayProperty->SetEventType(wxArrayProperty::E_PropertyAdded);
				pArrayProperty->GetParent()->OnPropertyGridChange(PGEvent);
			}			
		}	
		else if(event.GetId() == buttons->GetButtonId(1)) // - remove element
		{
			int childCount = property->GetChildCount();
			if(childCount > 0)
			{
				// remove the wx property
				wxPGProperty* pChild = property->Item(childCount-1);
				propGrid->DeleteProperty(pChild);	
				pArrayProperty->UpdateValue();
				propGrid->RefreshProperty(property);

				// update the corresponding property in the property stream
				wxPropertyGridEvent PGEvent;
				PGEvent.SetProperty(property);
				pArrayProperty->SetEventType(wxArrayProperty::E_PropertyRemoved);
				pArrayProperty->GetParent()->OnPropertyGridChange(PGEvent);
			}
		}

		return true;
    }
	else
	{
		return wxPGTextCtrlEditor::OnEvent(propGrid, property, ctrl, event);
	}    
}