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

📄 advprops.cpp

📁 这是一个GPS相关的程序
💻 CPP
📖 第 1 页 / 共 4 页
字号:
}

void wxImageFilePropertyClass::OnCustomPaint( wxDC& dc,
                                              const wxRect& rect,
                                              wxPGPaintData& )
{
    if ( m_pBitmap || (m_pImage && m_pImage->Ok() ) )
    {
        // Draw the thumbnail

        // Create the bitmap here because required size is not known in DoSetValue().
        if ( !m_pBitmap )
        {
            m_pImage->Rescale( rect.width, rect.height );
            m_pBitmap = new wxBitmap( *m_pImage );
            delete m_pImage;
            m_pImage = NULL;
        }

        dc.DrawBitmap( *m_pBitmap, rect.x, rect.y, false );
    }
    else
    {
        // No file - just draw a white box
        dc.SetBrush( *wxWHITE_BRUSH );
        dc.DrawRectangle ( rect );
    }
}

#endif // wxUSE_IMAGE

// -----------------------------------------------------------------------
// wxMultiChoiceProperty
// -----------------------------------------------------------------------

#if wxUSE_CHOICEDLG

#include <wx/choicdlg.h>

#ifndef __WXPYTHON__
wxPGProperty* wxPG_CONSTFUNC(wxMultiChoiceProperty)(const wxString& label,
                                                    const wxString& name,
                                                    const wxPGChoices& choices,
                                                    const wxArrayInt& value)
{
    return new wxPG_PROPCLASS(wxMultiChoiceProperty)(label,name,choices,value);
}
#endif

wxPGProperty* wxPG_CONSTFUNC(wxMultiChoiceProperty)(const wxString& label,
                                                    const wxString& name,
                                                    const wxArrayString& strings,
                                                    const wxArrayInt& value)
{
    return new wxPG_PROPCLASS(wxMultiChoiceProperty)(label,name,strings,value);
}

WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty,wxBaseProperty,
                               wxArrayInt,const wxArrayInt&,TextCtrlAndButton)

wxMultiChoicePropertyClass::wxMultiChoicePropertyClass(const wxString& label,
                                                       const wxString& name,
                                                       const wxPGChoices& choices,
                                                       const wxArrayInt& value)
                                                         : wxPGProperty(label,name)
{
    wxPG_INIT_REQUIRED_TYPE(wxArrayInt)

    m_choices.Assign(choices);
    SetValueI(value);
}


wxMultiChoicePropertyClass::wxMultiChoicePropertyClass(const wxString& label,
                                                       const wxString& name,
                                                       const wxArrayString& strings,
                                                       const wxArrayInt& value)
                                                         : wxPGProperty(label,name)
{
    wxPG_INIT_REQUIRED_TYPE(wxArrayInt)

    m_choices.Set(strings);
    SetValueI(value);
}

wxMultiChoicePropertyClass::wxMultiChoicePropertyClass(const wxString& label,
                                                       const wxString& name,
                                                       const wxArrayInt& WXUNUSED(value))
                                                         : wxPGProperty(label,name)
{
}

wxMultiChoicePropertyClass::~wxMultiChoicePropertyClass()
{
}

void wxMultiChoicePropertyClass::SetValueI( const wxArrayInt& arr )
{
    if ( &arr )
    {
        m_value_wxArrayInt = arr;
        GenerateValueAsString();
    }
    else
    {
        m_display = wxEmptyString;
    }
}

void wxMultiChoicePropertyClass::DoSetValue( wxPGVariant value )
{
#if !wxPG_PGVARIANT_IS_VARIANT
    wxArrayInt* pObj = (wxArrayInt*)wxPGVariantToVoidPtr(value);
    SetValueI(*pObj);
#else
    wxArrayInt arr = wxPGVariantToArrayInt(value);
    SetValueI(arr);
#endif
}

wxPGVariant wxMultiChoicePropertyClass::DoGetValue() const
{
    return wxPGVariantCreator(m_value_wxArrayInt);
}

wxString wxMultiChoicePropertyClass::GetValueAsString( int ) const
{
    return m_display;
}

void wxMultiChoicePropertyClass::GenerateValueAsString()
{
    // Allow zero-length strings list
    if ( !m_choices.IsOk() || !m_choices.GetCount() )
    {
        m_display = wxEmptyString;
        return;
    }

    wxString& tempStr = m_display;
    wxArrayInt indices = GetValueAsIndices();
    unsigned int i;
    unsigned int itemCount = indices.GetCount();

    tempStr.Empty();

    if ( itemCount )
        tempStr.append( wxT("\"") );

    for ( i = 0; i < itemCount; i++ )
    {
        int ind = indices.Item(i);
        wxCHECK_RET( ind >= 0 && ind < (int)m_choices.GetCount(),
                     wxT("value out of range") );
        tempStr.append( m_choices.GetLabel(ind) );
        tempStr.append( wxT("\"") );
        if ( i < (itemCount-1) )
            tempStr.append ( wxT(" \"") );
    }
}

wxArrayInt wxMultiChoicePropertyClass::GetValueAsIndices() const
{
    const wxArrayInt& choiceValues = m_choices.GetValues();
    if ( choiceValues.GetCount() )
    {
        // Translate values to string indices.
        wxArrayInt selections;

        unsigned int i;
        for ( i=0; i<m_value_wxArrayInt.GetCount(); i++ )
        {
            int sIndex = choiceValues.Index(m_value_wxArrayInt[i]);
            if ( sIndex >= 0 )
                selections.Add(sIndex);
        }

        return selections;
    }

    return m_value_wxArrayInt;
}

bool wxMultiChoicePropertyClass::OnEvent( wxPropertyGrid* propgrid,
                                          wxWindow* primary,
                                          wxEvent& event )
{
    if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED )
    {
        // Update the value
        PrepareValueForDialogEditing(propgrid);

        // launch editor dialog
        wxMultiChoiceDialog dlg( propgrid,
                                 _("Make a selection:"),
                                 m_label,
                                 m_choices.GetCount(),
                                 &m_choices.GetLabels()[0],
                                 wxCHOICEDLG_STYLE );

        dlg.Move( propgrid->GetGoodEditorDialogPosition(this,dlg.GetSize()) );

        dlg.SetSelections(GetValueAsIndices());

        if ( dlg.ShowModal() == wxID_OK )
        {
            wxArrayInt arrInt = dlg.GetSelections();

            const wxArrayInt& choiceValues = m_choices.GetValues();
            if ( choiceValues.GetCount() )
            {
                // Translate string indices to values.
                wxArrayInt values;

                unsigned int i;
                for ( i=0; i<arrInt.GetCount(); i++ )
                    values.Add(choiceValues.Item(arrInt.Item(i)));

                SetValueI( values );
            }
            else
            {
                SetValueI( arrInt );
            }
            UpdateControl( primary );

            return true;
        }
    }
    return false;
}

int wxMultiChoicePropertyClass::GetChoiceInfo( wxPGChoiceInfo* choiceinfo )
{
    if ( choiceinfo )
    {
        if ( m_choices.IsOk() )
            choiceinfo->m_itemCount = m_choices.GetCount();

        choiceinfo->m_choices = &m_choices;
    }
    return -1;
}

bool wxMultiChoicePropertyClass::SetValueFromString( const wxString& text, int )
{
    m_value_wxArrayInt.Empty();
    const wxArrayString& strings = m_choices.GetLabels();
    const wxArrayInt& values = m_choices.GetValues();

    WX_PG_TOKENIZER2_BEGIN(text,wxT('"'))
        int ind = strings.Index( token );
        if ( ind != wxNOT_FOUND )
        {
            if ( values.GetCount() )
                ind = values.Item(ind);

            m_value_wxArrayInt.Add(ind);
        }
    WX_PG_TOKENIZER2_END()

    GenerateValueAsString();

    return true;
}

#endif // wxUSE_CHOICEDLG


// -----------------------------------------------------------------------
// wxDateProperty
// -----------------------------------------------------------------------

#if wxUSE_DATETIME


#if wxUSE_DATEPICKCTRL
    #define dtCtrl      DatePickerCtrl
#else
    #define dtCtrl      TextCtrl
#endif

WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty,
                               wxBaseProperty,
                               wxDateTime,
                               const wxDateTime&,
                               dtCtrl)


wxString wxDatePropertyClass::ms_defaultDateFormat;


wxDatePropertyClass::wxDatePropertyClass( const wxString& label,
                                                  const wxString& name,
                                                  const wxDateTime& value )
    : wxPGProperty(label,name)
{
    wxPGRegisterDefaultValueType(wxDateTime)

#if wxUSE_DATEPICKCTRL
    wxPGRegisterEditorClass(DatePickerCtrl);

    m_dpStyle = wxDP_DEFAULT | wxDP_SHOWCENTURY;
#else
    m_dpStyle = 0;
#endif

    DoSetValue( value );
}

wxDatePropertyClass::~wxDatePropertyClass()
{
}

void wxDatePropertyClass::DoSetValue( wxPGVariant value )
{
    m_valueDateTime = wxPGVariantToDateTime(value);
}

wxPGVariant wxDatePropertyClass::DoGetValue() const
{
    return wxPGVariantCreator(m_valueDateTime);
}

bool wxDatePropertyClass::SetValueFromString( const wxString& text,
                                                  int WXUNUSED(argFlags) )
{
    const wxChar* c = m_valueDateTime.ParseFormat(text.c_str(),wxDefaultDateTimeFormat);

    return c ? true : false;
}

wxString wxDatePropertyClass::GetValueAsString( int argFlags ) const
{
    const wxChar* format = (const wxChar*) NULL;

    if ( !m_valueDateTime.IsValid() )
        return wxT("Invalid");

    if ( !ms_defaultDateFormat.length() )
    {
#if wxUSE_DATEPICKCTRL
        bool showCentury = m_dpStyle & wxDP_SHOWCENTURY ? true : false;
#else
        bool showCentury = true;
#endif
        ms_defaultDateFormat = DetermineDefaultDateFormat( showCentury );
    }

    if ( m_format.length() &&
         !(argFlags & wxPG_FULL_VALUE) )
            format = m_format.c_str();

    // Determine default from locale
    // NB: This is really simple stuff, but can't figure anything
    //     better without proper support in wxLocale
    if ( !format )
        format = ms_defaultDateFormat.c_str();

    return m_valueDateTime.Format(format);
}

wxString wxDatePropertyClass::DetermineDefaultDateFormat( bool showCentury )
{
    // This code is basicly copied from datectlg.cpp's SetFormat
    //
    wxString format;

    wxDateTime dt;
    dt.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
    wxString str(dt.Format(wxT("%x")));

    const wxChar *p = str.c_str();
    while ( *p )
    {
        int n=wxAtoi(p);
        if (n == dt.GetDay())
        {
            format.Append(wxT("%d"));
            p += 2;
        }
        else if (n == (int)dt.GetMonth()+1)
        {
            format.Append(wxT("%m"));
            p += 2;
        }
        else if (n == dt.GetYear())
        {
            format.Append(wxT("%Y"));
            p += 4;
        }
        else if (n == (dt.GetYear() % 100))
        {
            if (showCentury)
                format.Append(wxT("%Y"));
            else
                format.Append(wxT("%y"));
            p += 2;
        }
        else
            format.Append(*p++);
    }

    return format;
}

void wxDatePropertyClass::SetAttribute( int id, wxVariant& value )
{
    if ( id == wxPG_DATE_FORMAT )
    {
        m_format = value.GetString();
    }
    else if ( id == wxPG_DATE_PICKER_STYLE )
    {
        m_dpStyle = value.GetLong();
        ms_defaultDateFormat.clear();  // This may need recalculation
    }
}

#endif  // wxUSE_DATETIME


// -----------------------------------------------------------------------
// wxPropertyContainerMethods
// -----------------------------------------------------------------------

void wxPropertyContainerMethods::InitAllTypeHandlers()
{
    wxPG_INIT_REQUIRED_TYPE(wxColour)
    wxPG_INIT_REQUIRED_TYPE(wxFont)
    wxPG_INIT_REQUIRED_TYPE(wxArrayInt)
    wxPG_INIT_REQUIRED_TYPE(wxColourPropertyValue)
#if wxUSE_DATETIME
    wxPGRegisterDefaultValueType(wxDateTime)
#endif
}

// -----------------------------------------------------------------------

void wxPropertyContainerMethods::RegisterAdditionalEditors()
{
#if wxUSE_SPINBTN
    wxPGRegisterEditorClass(SpinCtrl);
#endif
#if wxUSE_DATEPICKCTRL
    wxPGRegisterEditorClass(DatePickerCtrl);
#endif
}

// -----------------------------------------------------------------------

void wxPropertyContainerMethods::RegisterAdvancedPropertyClasses()
{
    wxPGRegisterPropertyClass(wxMultiChoiceProperty);
    wxPGRegisterPropertyClass(wxImageFileProperty);
    wxPGRegisterPropertyClass(wxColourProperty);
    wxPGRegisterPropertyClass(wxFontProperty);
    wxPGRegisterPropertyClass(wxSystemColourProperty);
    wxPGRegisterPropertyClass(wxCursorProperty);
#if wxUSE_DATETIME
    wxPGRegisterPropertyClass(wxDateProperty);
#endif
}

// -----------------------------------------------------------------------

#endif // wxPG_INCLUDE_ADVPROPS

⌨️ 快捷键说明

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