コード例 #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;
    }
}
コード例 #2
0
int CPropertyGridEditor::ShowModal()
{
    wxLocale locale;
    locale.Init(wxLANGUAGE_CHINESE_SIMPLIFIED);

    BEATS_ASSERT(m_pGridProperty != NULL);
    CListPropertyDescription* pListProperty = (CListPropertyDescription*)m_pGridProperty->GetClientData();
    // When first time show an instance in the list, we have a chance to select a derived instance.
    CPtrPropertyDescription* pTemplateProperty = down_cast<CPtrPropertyDescription*>(pListProperty->GetTemplateProperty());
    if (pListProperty->GetChildrenCount() == 0)
    {
        wxPtrButtonEditor::SelectDerivedInstanceInEditor(pTemplateProperty);
    }
    else
    {
        // If we already got some data in XML to indicate what the instance really is, let the pTemplateProperty to know.
        // So we know what cols should be add in InsertProperty
        CPtrPropertyDescription* pPtrChildProperty = down_cast<CPtrPropertyDescription*>(pListProperty->GetChild(0));
        pTemplateProperty->SetDerivedGuid(pPtrChildProperty->GetDerivedGuid());
    }
    BEATS_ASSERT(pTemplateProperty != NULL);
    InsertProperty(pTemplateProperty, false);

    size_t uChildrenCount = pListProperty->GetChildrenCount();
    m_pGrid->AppendRows(uChildrenCount);
    for (size_t i = 0; i < uChildrenCount; ++i)
    {
        CPropertyDescriptionBase* pProperty = pListProperty->GetChild(i);
        std::vector<CPropertyDescriptionBase*> propertiesToAddInRow;
        BEATS_ASSERT(pProperty != NULL);
        if (pProperty->GetType() == eRPT_Ptr)
        {
            CPtrPropertyDescription* pPtrProperty = down_cast<CPtrPropertyDescription*>(pProperty);
            BEATS_ASSERT(pPtrProperty != NULL && pPtrProperty->GetInstanceComponent() != NULL);
            CComponentProxy* pProxy = pPtrProperty->GetInstanceComponent();
            propertiesToAddInRow = *pProxy->GetPropertyPool();
        }
        else
        {
            propertiesToAddInRow.push_back(pProperty);
        }
        for (size_t j = 0; j < propertiesToAddInRow.size(); ++j)
        {
            char szResult[10240];
            propertiesToAddInRow[j]->GetValueAsChar(eVT_CurrentValue, szResult);
            if (propertiesToAddInRow[j]->GetType() == eRPT_Bool)
            {
                bool bValue = *((bool*)propertiesToAddInRow[j]->GetValue(eVT_CurrentValue));
                szResult[0] = bValue ? '1' : 0;
                szResult[1] = 0;
            }
            else if (propertiesToAddInRow[j]->GetType() == eRPT_Enum)
            {
                CEnumPropertyDescription* pEnumProperty = down_cast<CEnumPropertyDescription*>(propertiesToAddInRow[j]);
                InitEnumCell(i, j, pEnumProperty);
                int nCurValue = *((int*)(pEnumProperty->GetValue(eVT_CurrentValue)));
                strcpy(szResult, pEnumProperty->QueryStringByValue(nCurValue).c_str());
            }
            m_pGrid->SetCellValue(i, j, szResult);
        }
    }
    m_pGrid->AutoSize();
    this->Fit();
    this->Layout();
    return super::ShowModal();
}