Ejemplo n.º 1
0
void CPropertyGridEditor::InsertProperty(CPropertyDescriptionBase* pProperty, bool InPtrProperty)
{
    EReflectPropertyType type = pProperty->GetType();
    switch (type)
    {
    case eRPT_Bool:
        m_pGrid->AppendCols();
        m_pGrid->SetColFormatBool(m_pGrid->GetCols() - 1);
        m_pGrid->SetColLabelValue(m_pGrid->GetCols() - 1, pProperty->GetBasicInfo()->m_displayName.c_str());
        m_cols.push_back(pProperty);
        break;
    case eRPT_Float:
    case eRPT_Double:
        m_pGrid->AppendCols();
        m_pGrid->SetColFormatFloat(m_pGrid->GetCols() - 1);
        m_pGrid->SetColLabelValue(m_pGrid->GetCols() - 1, pProperty->GetBasicInfo()->m_displayName.c_str());
        m_cols.push_back(pProperty);
        break;
    case eRPT_Int:
    case eRPT_UInt:
        m_pGrid->AppendCols();
        m_pGrid->SetColFormatNumber(m_pGrid->GetCols() - 1);
        m_pGrid->SetColLabelValue(m_pGrid->GetCols() - 1, pProperty->GetBasicInfo()->m_displayName.c_str());
        m_cols.push_back(pProperty);
        break;
    case eRPT_Enum:
        m_pGrid->AppendCols();
        m_pGrid->SetColLabelValue(m_pGrid->GetCols() - 1, pProperty->GetBasicInfo()->m_displayName.c_str());
        m_cols.push_back(pProperty);
        break;
    case eRPT_Ptr:
        {
            BEATS_ASSERT(!InPtrProperty, _T("ptr property Can't nested in grid mode!"));
            BEYONDENGINE_UNUSED_PARAM(InPtrProperty);
            CPtrPropertyDescription* pPtrProperty = down_cast<CPtrPropertyDescription*>(pProperty);
            BEATS_ASSERT(pPtrProperty != NULL);
            size_t uGuid = pPtrProperty->GetDerivedGuid() == 0 ? pPtrProperty->GetPtrGuid() : pPtrProperty->GetDerivedGuid();
            CComponentProxy* pProxy = down_cast<CComponentProxy*>(CComponentProxyManager::GetInstance()->GetComponentTemplate(uGuid));
            const std::vector<CPropertyDescriptionBase*>* pPropertyPool = pProxy->GetPropertyPool();
            for (size_t i = 0; i < pPropertyPool->size(); ++i)
            {
                InsertProperty(pPropertyPool->at(i), true);
            }
        }
        break;
    default:
        BEATS_ASSERT(false, _T("Unsupport col format of property type %d in list property grid mode!"), type);
        break;
    }
}
Ejemplo n.º 2
0
bool wxPtrButtonEditor::OnEvent( wxPropertyGrid* propGrid,
                                wxPGProperty* property,
                                wxWindow* ctrl,
                                wxEvent& event ) const
{
    if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED )
    {
        wxPGMultiButton* buttons = (wxPGMultiButton*) propGrid->GetEditorControlSecondary();
        CWxwidgetsPropertyBase* pPropertyDescription = static_cast<CWxwidgetsPropertyBase*>(property->GetClientData());
        CBDTWxFrame* pMainFrame = static_cast<CBDTWxApp*>(wxApp::GetInstance())->GetMainFrame();
        const wxWindow* pButton = NULL;
        for (uint32_t i = 0; i < buttons->GetCount(); ++i)
        {
            if (event.GetId() == buttons->GetButtonId(i))
            {
                pButton = buttons->GetButton(i);
                break;
            }
        }
        if (pButton != NULL)
        {
            if (pPropertyDescription->GetType() == eRPT_Ptr)
            {
                CPtrPropertyDescription* pPtrPropertyDescription = static_cast<CPtrPropertyDescription*>(pPropertyDescription);
                wxString valueStr = property->GetValueAsString();
                bool bValueChanged = false;
                if (pButton->GetLabel().CmpNoCase(_T("+")) == 0)
                {
                    uint32_t ptrGuid = pPtrPropertyDescription->GetPtrGuid();
                    std::vector<uint32_t> instanceClassGuid;
                    CComponentProxyManager::GetInstance()->QueryDerivedClass(ptrGuid, instanceClassGuid, true);
                    bValueChanged = instanceClassGuid.size() == 0;
                    if (!bValueChanged)
                    {
                        instanceClassGuid.insert(instanceClassGuid.begin(), ptrGuid);
                        wxPGChoices choice;
                        for (auto i : instanceClassGuid)
                        {
                            CComponentBase* pBase = CComponentProxyManager::GetInstance()->GetComponentTemplate(i);
                            if (pBase != NULL)//If it is NULL, it must be an abstract class.
                            {
                                choice.Add(pBase->GetClassStr(), pBase->GetGuid());
                            }
                            BEATS_ASSERT(pBase != NULL || 
                                CComponentProxyManager::GetInstance()->GetAbstractComponentNameMap().find(i) != CComponentProxyManager::GetInstance()->GetAbstractComponentNameMap().end(),
                                _T("We can't get a template component with guid %d while it can't be found in abstract class map!"), i);
                        }
                        wxString strSelectItem = ::wxGetSingleChoice(wxT("TypeChoice"), wxT("Caption"), choice.GetLabels(),
                            NULL, wxDefaultCoord, wxDefaultCoord, false, wxCHOICE_WIDTH, wxCHOICE_HEIGHT);
                        if ( !strSelectItem.empty() )
                        {
                            int nSelectIndex = choice.Index(strSelectItem);
                            uint32_t uDerivedGuid = choice.GetValue(nSelectIndex);
                            pPtrPropertyDescription->SetDerivedGuid(uDerivedGuid);
                            bValueChanged = true;
                        }
                    }
                    if (bValueChanged)
                    {
                        bool bCreateInstance = pPtrPropertyDescription->CreateInstance();
                        BEATS_ASSERT(bCreateInstance);
                        CComponentProxy* pCompBase = static_cast<CComponentProxy*>(pPtrPropertyDescription->GetInstanceComponent());
                        BEATS_ASSERT(pCompBase != NULL);
                        BEATS_ASSERT(pMainFrame != NULL);
                        TString* pStrValue = (TString*)pPtrPropertyDescription->GetValue(eVT_CurrentValue);
                        property->SetValueFromString(pStrValue->c_str());
                        pMainFrame->InsertComponentsInPropertyGrid(pCompBase, property);
                        buttons->GetButton(0)->SetLabel(_T("-"));
                        valueStr.insert(0, _T("+"));
                    }
                }
                else if (pButton->GetLabel().CmpNoCase(_T("-")) == 0)
                {
                    property->DeleteChildren();
                    bool bDeleteInstance = pPtrPropertyDescription->DestroyInstance(true);
                    // Destroy instance may cause the value changed, so we fetch it again.
                    char szTmp[MAX_PATH];
                    pPtrPropertyDescription->GetValueAsChar(eVT_CurrentValue, szTmp);
                    valueStr = szTmp;
                    pPtrPropertyDescription->GetChildren().clear();
                    BEATS_ASSERT(bDeleteInstance);
                    buttons->GetButton(0)->SetLabel(_T("+"));
                    bValueChanged = true;
                }
                if (bValueChanged)
                {
                    wxVariant newValue(valueStr);
                    pPtrPropertyDescription->SetValue(newValue, false);
                    property->SetValue(newValue);
                    propGrid->Refresh();
                }
            }
            if (pPropertyDescription->IsContainerProperty())
            {
                if (pButton->GetLabel().CmpNoCase(_T("+")) == 0)
                {
                    CPropertyDescriptionBase* pNewChild = pPropertyDescription->AddChild(NULL);
                    if (pNewChild != NULL)
                    {
                        std::vector<CPropertyDescriptionBase*> value;
                        value.push_back(pNewChild);
                        pMainFrame->InsertInPropertyGrid(value, property);
                    }
                }
                else if (pButton->GetLabel().CmpNoCase(_T("-")) == 0)
                {
                    pPropertyDescription->DeleteAllChild();
                    property->DeleteChildren();
                }
                char valueStr[256];
                pPropertyDescription->GetValueAsChar(eVT_CurrentValue, valueStr);
                property->SetValue(valueStr);
                property->SetModifiedStatus(pPropertyDescription->GetChildrenCount() > 0);
                property->RecreateEditor();
            }

            if (pButton->GetLabel().CmpNoCase(_T("x")) == 0)
            {
                BEATS_ASSERT(pPropertyDescription->GetParent() != NULL);
                CPropertyDescriptionBase* pParent = pPropertyDescription->GetParent();
                pParent->DeleteChild(pPropertyDescription);
                // NOTICE: We have deleted this already!
                pPropertyDescription = NULL;

                property->SetClientData(NULL);
                char valueStr[256];
                pParent->GetValueAsChar(eVT_CurrentValue, valueStr);
                property->GetParent()->SetValue(valueStr);
                //TODO: I can't refresh property here, because we are trying to delete property of which callback we are in.
                pMainFrame->RequestToUpdatePropertyGrid();
            }
            return true;
        }
    }
    return wxPGTextCtrlEditor::OnEvent(propGrid, property, ctrl, event);
}