⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 propform.cpp

📁 Wxpython Implemented on Windows CE, Source code
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        this->Destroy();
    else
        event.Veto();
}

wxPanel *wxPropertyFormFrame::OnCreatePanel(wxFrame *parent, wxPropertyFormView *v)
{
    return new wxPropertyFormPanel(v, parent);
}

bool wxPropertyFormFrame::Initialize(void)
{
    m_propertyPanel = OnCreatePanel(this, m_view);
    if (m_propertyPanel)
    {
        m_view->AssociatePanel(m_propertyPanel);
        m_view->SetManagedWindow(this);
        return true;
    }
    else
        return false;
}

/*
* Property form specific validator
*/

IMPLEMENT_ABSTRACT_CLASS(wxPropertyFormValidator, wxPropertyValidator)


/*
* Default validators
*/

IMPLEMENT_DYNAMIC_CLASS(wxRealFormValidator, wxPropertyFormValidator)

///
/// Real number form validator
///
bool wxRealFormValidator::OnCheckValue( wxProperty *property, wxPropertyFormView *WXUNUSED(view),
                                       wxWindow *parentWindow)
{
    if (m_realMin == 0.0 && m_realMax == 0.0)
        return true;

    // The item used for viewing the real number: should be a text item.
    wxWindow *m_propertyWindow = property->GetWindow();
    if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
        return false;

    wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue());

    float val = 0.0;
    if (!StringToFloat(WXSTRINGCAST value, &val))
    {
        wxChar buf[200];
        wxSprintf(buf, wxT("Value %s is not a valid real number!"), (const wxChar *)value);
        wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow);
        return false;
    }

    if (val < m_realMin || val > m_realMax)
    {
        wxChar buf[200];
        wxSprintf(buf, wxT("Value must be a real number between %.2f and %.2f!"), m_realMin, m_realMax);
        wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow);
        return false;
    }
    return true;
}

bool wxRealFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
                                          wxWindow *WXUNUSED(parentWindow) )
{
    // The item used for viewing the real number: should be a text item.
    wxWindow *m_propertyWindow = property->GetWindow();
    if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
        return false;

    wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue());

    if (value.Length() == 0)
        return false;

    float f = (float)wxAtof((const wxChar *)value);
    property->GetValue() = f;
    return true;
}

bool wxRealFormValidator::OnDisplayValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
                                         wxWindow *WXUNUSED(parentWindow) )
{
    // The item used for viewing the real number: should be a text item.
    wxWindow *m_propertyWindow = property->GetWindow();
    if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
        return false;

    wxTextCtrl *textItem = (wxTextCtrl *)m_propertyWindow;
    textItem->SetValue(FloatToString(property->GetValue().RealValue()));
    return true;
}

///
/// Integer validator
///
IMPLEMENT_DYNAMIC_CLASS(wxIntegerFormValidator, wxPropertyFormValidator)

bool wxIntegerFormValidator::OnCheckValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
                                          wxWindow *parentWindow)
{
    if (m_integerMin == 0.0 && m_integerMax == 0.0)
        return true;

    // The item used for viewing the real number: should be a text item or a slider
    wxWindow *m_propertyWindow = property->GetWindow();
    if (!m_propertyWindow)
        return false;

    long val = 0;

    if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
    {
        wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue());

        if (!StringToLong(WXSTRINGCAST value, &val))
        {
            wxChar buf[200];
            wxSprintf(buf, wxT("Value %s is not a valid integer!"), (const wxChar *)value);
            wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow);
            return false;
        }
    }
    else if (m_propertyWindow->IsKindOf(CLASSINFO(wxSlider)))
    {
        val = (long)((wxSlider *)m_propertyWindow)->GetValue();
    }
    else
        return false;

    if (val < m_integerMin || val > m_integerMax)
    {
        wxChar buf[200];
        wxSprintf(buf, wxT("Value must be an integer between %ld and %ld!"), m_integerMin, m_integerMax);
        wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow);
        return false;
    }
    return true;
}

bool wxIntegerFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
                                             wxWindow *WXUNUSED(parentWindow))
{
    // The item used for viewing the real number: should be a text item or a slider
    wxWindow *m_propertyWindow = property->GetWindow();
    if (!m_propertyWindow)
        return false;

    if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
    {
        wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue());

        if (value.Length() == 0)
            return false;

        long i = wxAtol((const wxChar *)value);
        property->GetValue() = i;
    }
    else if (m_propertyWindow->IsKindOf(CLASSINFO(wxSlider)))
    {
        property->GetValue() = (long)((wxSlider *)m_propertyWindow)->GetValue();
    }
    else
        return false;

    return true;
}

bool wxIntegerFormValidator::OnDisplayValue( wxProperty *property, wxPropertyFormView *WXUNUSED(view),
                                            wxWindow *WXUNUSED(parentWindow))
{
    // The item used for viewing the real number: should be a text item or a slider
    wxWindow *m_propertyWindow = property->GetWindow();
    if (!m_propertyWindow)
        return false;

    if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
    {
        wxTextCtrl *textItem = (wxTextCtrl *)m_propertyWindow;
        textItem->SetValue(LongToString(property->GetValue().IntegerValue()));
    }
    else if (m_propertyWindow->IsKindOf(CLASSINFO(wxSlider)))
    {
        ((wxSlider *)m_propertyWindow)->SetValue((int)property->GetValue().IntegerValue());
    }
    else
        return false;
    return true;
}

///
/// Boolean validator
///
IMPLEMENT_DYNAMIC_CLASS(wxBoolFormValidator, wxPropertyFormValidator)

bool wxBoolFormValidator::OnCheckValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
                                       wxWindow *WXUNUSED(parentWindow))
{
    // The item used for viewing the boolean: should be a checkbox
    wxWindow *m_propertyWindow = property->GetWindow();
    if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxCheckBox)))
        return false;

    return true;
}

bool wxBoolFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
                                          wxWindow *WXUNUSED(parentWindow) )
{
    // The item used for viewing the boolean: should be a checkbox.
    wxWindow *m_propertyWindow = property->GetWindow();
    if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxCheckBox)))
        return false;

    wxCheckBox *checkBox = (wxCheckBox *)m_propertyWindow;

    property->GetValue() = (bool)checkBox->GetValue();
    return true;
}

bool wxBoolFormValidator::OnDisplayValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
                                         wxWindow *WXUNUSED(parentWindow))
{
    // The item used for viewing the boolean: should be a checkbox.
    wxWindow *m_propertyWindow = property->GetWindow();
    if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxCheckBox)))
        return false;

    wxCheckBox *checkBox = (wxCheckBox *)m_propertyWindow;
    checkBox->SetValue((bool)property->GetValue().BoolValue());
    return true;
}

///
/// String validator
///
IMPLEMENT_DYNAMIC_CLASS(wxStringFormValidator, wxPropertyFormValidator)

wxStringFormValidator::wxStringFormValidator(wxStringList *list, long flags):
wxPropertyFormValidator(flags)
{
    m_strings = list;
}

bool wxStringFormValidator::OnCheckValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
                                         wxWindow *parentWindow )
{
    if (!m_strings)
        return true;

    // The item used for viewing the string: should be a text item, choice item or listbox.
    wxWindow *m_propertyWindow = property->GetWindow();
    if (!m_propertyWindow)
        return false;
    if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
    {
        wxTextCtrl *text = (wxTextCtrl *)m_propertyWindow;
        if (!m_strings->Member(text->GetValue()))
        {
            wxString str( wxT("Value ") );
            str += text->GetValue();
            str += wxT(" is not valid.");
            wxMessageBox(str, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow);
            return false;
        }
    }
    else
    {
        // Any other item constrains the string value,
        // so we don't have to check it.
    }
    return true;
}

bool wxStringFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
                                            wxWindow *WXUNUSED(parentWindow) )
{
    // The item used for viewing the string: should be a text item, choice item or listbox.
    wxWindow *m_propertyWindow = property->GetWindow();
    if (!m_propertyWindow)
        return false;
    if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
    {
        wxTextCtrl *text = (wxTextCtrl *)m_propertyWindow;
        property->GetValue() = text->GetValue();
    }
    else if (m_propertyWindow->IsKindOf(CLASSINFO(wxListBox)))
    {
        wxListBox *lbox = (wxListBox *)m_propertyWindow;
        if (lbox->GetSelection() != wxNOT_FOUND)
            property->GetValue() = lbox->GetStringSelection();
    }
    /*
    else if (m_propertyWindow->IsKindOf(CLASSINFO(wxRadioBox)))
    {
    wxRadioBox *rbox = (wxRadioBox *)m_propertyWindow;
    int n = 0;
    if ((n = rbox->GetSelection()) != wxNOT_FOUND)
    property->GetValue() = rbox->GetString(n);
    }
    */
    else if (m_propertyWindow->IsKindOf(CLASSINFO(wxChoice)))
    {
        wxChoice *choice = (wxChoice *)m_propertyWindow;
        if (choice->GetSelection() != wxNOT_FOUND)
            property->GetValue() = choice->GetStringSelection();
    }
    else
        return false;
    return true;
}

bool wxStringFormValidator::OnDisplayValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view),
                                           wxWindow *WXUNUSED(parentWindow) )
{
    // The item used for viewing the string: should be a text item, choice item or listbox.
    wxWindow *m_propertyWindow = property->GetWindow();
    if (!m_propertyWindow)
        return false;
    if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl)))
    {
        wxTextCtrl *text = (wxTextCtrl *)m_propertyWindow;
        text->SetValue(property->GetValue().StringValue());
    }
    else if (m_propertyWindow->IsKindOf(CLASSINFO(wxListBox)))
    {
        wxListBox *lbox = (wxListBox *)m_propertyWindow;
        if (lbox->GetCount() == 0 && m_strings)
        {
            // Try to initialize the listbox from 'strings'
            wxStringList::Node  *node = m_strings->GetFirst();
            while (node)
            {
                wxChar *s = node->GetData();
                lbox->Append(s);
                node = node->GetNext();
            }
        }
        lbox->SetStringSelection(property->GetValue().StringValue());
    }
    /*
    else if (m_propertyWindow->IsKindOf(CLASSINFO(wxRadioBox)))
    {
    wxRadioBox *rbox = (wxRadioBox *)m_propertyWindow;
    rbox->SetStringSelection(property->GetValue().StringValue());
    }
    */
    else if (m_propertyWindow->IsKindOf(CLASSINFO(wxChoice)))
    {
        wxChoice *choice = (wxChoice *)m_propertyWindow;
        if (choice->GetCount() == 0 && m_strings)
        {
            // Try to initialize the choice item from 'strings'
            // XView doesn't allow this kind of thing.
            wxStringList::Node  *node = m_strings->GetFirst();
            while (node)
            {
                wxChar *s = node->GetData();
                choice->Append(s);
                node = node->GetNext();
            }
        }
        choice->SetStringSelection(property->GetValue().StringValue());
    }
    else
        return false;
    return true;
}

#endif // wxUSE_PROPSHEET

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -