Exemplo n.º 1
0
wxPGWindowList wxPtrButtonEditor::CreateControls( wxPropertyGrid* propGrid,
                                                 wxPGProperty* property,
                                                 const wxPoint& pos,
                                                 const wxSize& sz ) const
{
    wxPGMultiButton* buttons = new wxPGMultiButton( propGrid, sz );
    void* pClientData = property->GetClientData();
    BEATS_ASSERT(pClientData != NULL);
    CPropertyDescriptionBase* pPropertyDescription = static_cast<CPropertyDescriptionBase*>(pClientData);
    if (pPropertyDescription->GetType() == eRPT_Ptr)
    {
        CPtrPropertyDescription* pPtrProperty = static_cast<CPtrPropertyDescription*>(pPropertyDescription);
        buttons->Add( pPtrProperty->GetInstanceComponent() == NULL ? _T("+") : _T("-"));
    }
    else if (pPropertyDescription->IsContainerProperty())
    {
        buttons->Add(_T("+"));
        if (property->GetChildCount() > 0)
        {
            buttons->Add(_T("-"));
        }
    }
    CPropertyDescriptionBase* pParent = pPropertyDescription->GetParent();
    // it is a list element.
    if (pParent && pParent->IsContainerProperty())
    {
        buttons->Add(_T("x"));
    }
    wxPGWindowList wndList = wxPGTextCtrlEditor::CreateControls( propGrid, property, pos, buttons->GetPrimarySize() );

    buttons->Finalize(propGrid, pos);

    wndList.SetSecondary( buttons );
    return wndList;
}
Exemplo n.º 2
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;
    }
}
Exemplo n.º 3
0
void CPropertyGridEditor::OnConfirmBtnClicked(wxCommandEvent& /*event*/)
{
    CListPropertyDescription* pListProperty = (CListPropertyDescription*)m_pGridProperty->GetClientData();
    pListProperty->DeleteAllChild();
    size_t uGridRows = m_pGrid->GetRows();
    for (size_t i = 0; i < uGridRows; ++i)
    {
        CWxwidgetsPropertyBase* pNewProperty = down_cast<CWxwidgetsPropertyBase*>(pListProperty->AddChild(NULL));
        pNewProperty->Initialize();
        BEATS_ASSERT(m_cols.size() > 0 && pNewProperty != NULL);
        if (pNewProperty->GetType() == eRPT_Ptr)
        {
            CPtrPropertyDescription* pPtrProperty = down_cast<CPtrPropertyDescription*>(pNewProperty);
            BEATS_ASSERT(pPtrProperty != NULL && pPtrProperty->GetInstanceComponent() == NULL);
            pPtrProperty->CreateInstance();
            const std::vector<CPropertyDescriptionBase*>* pProperties = pPtrProperty->GetInstanceComponent()->GetPropertyPool();
            BEATS_ASSERT(pProperties->size() == m_cols.size());
            for (size_t j = 0; j < pProperties->size(); ++j)
            {
                CPropertyDescriptionBase* pProperty = pProperties->at(j);
                ApplyCellValueToProperty(pProperty, i, j);
            }
        }
        else
        {
            BEATS_ASSERT(m_cols.size() == 1);
            ApplyCellValueToProperty(pNewProperty, i, 0);
        }
    }
    char valueStr[256];
    pListProperty->GetValueAsChar(eVT_CurrentValue, valueStr);
    m_pGridProperty->SetValue(valueStr);
    m_pGridProperty->SetModifiedStatus(pListProperty->GetChildrenCount() > 0);
    m_pGridProperty->RecreateEditor();
    CloseDialog();
}
Exemplo n.º 4
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();
}
Exemplo n.º 5
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);
}