コード例 #1
0
ファイル: wxPtrButtonEditor.cpp プロジェクト: beyondlwm/Beats
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;
}
コード例 #2
0
bool CMenuEditor::OnEvent(wxPropertyGrid* propGrid,
    wxPGProperty* property,
    wxWindow* /*ctrl*/,
    wxEvent& event) const
{
    CPropertyDescriptionBase* pPropertyDescription = (CPropertyDescriptionBase*)(property->GetClientData());
    if (event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED)
    {
        if (pPropertyDescription->GetType() == eRPT_RandomColor)
        {
            CRandomColorPropertyDescription* pRandomColorProperty = down_cast<CRandomColorPropertyDescription*>(pPropertyDescription);
            wxArrayString displayString;
            int nInitSelection = (int)pRandomColorProperty->GetColorType();
            if (!pRandomColorProperty->IsOnlyGradient())
            {
                displayString.Add("color");
                displayString.Add("random color");
            }
            if (!pRandomColorProperty->IsOnlyColor())
            {
                displayString.Add("spline");
                displayString.Add("random spline");
            }
            if (nInitSelection > (int)displayString.size())
            {
                nInitSelection = 0;
            }
            int nSelection = wxGetSingleChoiceIndex("选取类型", "选取类型", displayString, nInitSelection);
            if (nSelection != 0xFFFFFFFF)
            {
                wxPGProperty* pMinProperty = nullptr;
                pRandomColorProperty->SetColorType(ERandomColorType(nSelection));
                ERandomColorType realColorType = pRandomColorProperty->GetColorType();// may not be the same to nSelection.
                wxPGProperty* pMaxProperty = pRandomColorProperty->CreateRandomColorProperty(realColorType, pMinProperty);
                property->DeleteChildren();
                if (pMinProperty)
                {
                    property->InsertChild(-1, pMinProperty);
                }
                property->InsertChild(-1, pMaxProperty);
                propGrid->RefreshProperty(property);
                wxVariant tmp((int)realColorType);
                pRandomColorProperty->SetValue(tmp);
            }
        }
    }
    return true;
}
コード例 #3
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();
}