X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9b5bafcf38a1c6b1ad9f8974e4745c73a559a26e..e7d3d27dcef1da559c495481a941dbf34a29efa8:/src/propgrid/advprops.cpp diff --git a/src/propgrid/advprops.cpp b/src/propgrid/advprops.cpp index f50ce38f49..158a45d680 100644 --- a/src/propgrid/advprops.cpp +++ b/src/propgrid/advprops.cpp @@ -80,11 +80,6 @@ // ----------------------------------------------------------------------- -bool operator == (const wxFont&, const wxFont&) -{ - return false; -} - // Implement dynamic class for type value. IMPLEMENT_DYNAMIC_CLASS(wxColourPropertyValue, wxObject) @@ -144,10 +139,10 @@ wxPGWindowList wxPGSpinCtrlEditor::CreateControls( wxPropertyGrid* propgrid, wxP wxWindowID id = wnd2->GetId(); wnd2->Connect( id, wxEVT_SCROLL_LINEUP, - wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent), + wxEventHandler(wxPropertyGrid::OnCustomEditorEvent), NULL, propgrid ); wnd2->Connect( id, wxEVT_SCROLL_LINEDOWN, - wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent), + wxEventHandler(wxPropertyGrid::OnCustomEditorEvent), NULL, propgrid ); // Let's add validator to make sure only numbers can be entered @@ -157,7 +152,7 @@ wxPGWindowList wxPGSpinCtrlEditor::CreateControls( wxPropertyGrid* propgrid, wxP wnd1->SetValidator(validator); wnd1->Connect( wnd1->GetId(), wxEVT_KEY_DOWN, - wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent), + wxEventHandler(wxPropertyGrid::OnCustomEditorEvent), NULL, propgrid ); return wxPGWindowList(wnd1, wnd2); @@ -343,7 +338,7 @@ wxPGWindowList wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid* propgri // (all relevenat wxTextCtrl, wxComboBox and wxButton events are // already connected) ctrl->Connect( wxPG_SUBID1, wxEVT_DATE_CHANGED, - wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent), + wxEventHandler(wxPropertyGrid::OnCustomEditorEvent), NULL, propgrid ); #ifdef __WXMSW__ @@ -477,6 +472,8 @@ wxFontProperty::wxFontProperty( const wxString& label, const wxString& name, wxFont font; font << m_value; + SetParentalType(wxPG_PROP_AGGREGATE); + AddChild( new wxIntProperty( _("Point Size"), wxS("Point Size"),(long)font.GetPointSize() ) ); AddChild( new wxEnumProperty(_("Family"), wxS("PointSize"), @@ -520,9 +517,10 @@ void wxFontProperty::OnSetValue() } } -wxString wxFontProperty::GetValueAsString( int argFlags ) const +wxString wxFontProperty::ValueToString( wxVariant& value, + int argFlags ) const { - return wxPGProperty::GetValueAsString(argFlags); + return wxPGProperty::ValueToString(value, argFlags); } bool wxFontProperty::OnEvent( wxPropertyGrid* propgrid, wxWindow* WXUNUSED(primary), @@ -531,7 +529,7 @@ bool wxFontProperty::OnEvent( wxPropertyGrid* propgrid, wxWindow* WXUNUSED(prima if ( propgrid->IsMainButtonEvent(event) ) { // Update value from last minute changes - wxVariant useValue = propgrid->GetPendingEditedValue(); + wxVariant useValue = propgrid->GetUncommittedPropertyValue(); wxFontData data; wxFont font; @@ -948,10 +946,7 @@ void wxSystemColourProperty::OnSetValue() if ( cpv.m_type < wxPG_COLOUR_WEB_BASE ) { - if ( m_choices.HasValues() ) - ind = GetIndexForValue(cpv.m_type); - else - ind = ColToInd(col); + ind = GetIndexForValue(cpv.m_type); } else { @@ -997,24 +992,30 @@ wxString wxSystemColourProperty::ColourToString( const wxColour& col, int index return m_choices.GetLabel(index); } -wxString wxSystemColourProperty::GetValueAsString( int argFlags ) const +wxString wxSystemColourProperty::ValueToString( wxVariant& value, + int argFlags ) const { - wxColourPropertyValue val = GetVal(); + wxColourPropertyValue val = GetVal(&value); - int ind = GetIndex(); + int index; - // Always show custom colour for textctrl-editor - if ( val.m_type == wxPG_COLOUR_CUSTOM || - ind == GetCustomColourIndex() || - (argFlags & wxPG_PROPERTY_SPECIFIC) ) + if ( argFlags & wxPG_VALUE_IS_CURRENT ) { - return ColourToString(val.m_colour, wxNOT_FOUND); + // GetIndex() only works reliably if wxPG_VALUE_IS_CURRENT flag is set, + // but we should use it whenever possible. + index = GetIndex(); + + // If custom colour was selected, use invalid index, so that + // ColourToString() will return properly formatted colour text. + if ( index == GetCustomColourIndex() ) + index = wxNOT_FOUND; + } + else + { + index = m_choices.Index(val.m_type); } - if ( ind == -1 ) - return wxEmptyString; - - return ColourToString(val.m_colour, ind); + return ColourToString(val.m_colour, index); } @@ -1076,14 +1077,9 @@ bool wxSystemColourProperty::QueryColourFromUser( wxVariant& variant ) const bool wxSystemColourProperty::IntToValue( wxVariant& variant, int number, int WXUNUSED(argFlags) ) const { int index = number; - int type = GetValueForIndex(index); - bool hasValue = m_choices[index].HasValue(); - - if ( ( hasValue && type == wxPG_COLOUR_CUSTOM ) || - ( !hasValue && (index == (int)GetCustomColourIndex() && - !(m_flags & wxPG_PROP_HIDE_CUSTOM_COLOUR)) - ) - ) + int type = m_choices.GetValue(index); + + if ( type == wxPG_COLOUR_CUSTOM ) { QueryColourFromUser(variant); } @@ -1241,7 +1237,7 @@ bool wxSystemColourProperty::StringToValue( wxVariant& value, const wxString& te if ( res && GetIndex() >= 0 ) { val.m_type = GetIndex(); - if ( val.m_type >= 0 && val.m_type < m_choices.GetCount() && m_choices[val.m_type].HasValue() ) + if ( val.m_type >= 0 && val.m_type < m_choices.GetCount() ) val.m_type = m_choices[val.m_type].GetValue(); // Get proper colour for type. @@ -1390,7 +1386,8 @@ void wxColourProperty::Init( wxColour colour ) SetIndex( ind ); } -wxString wxColourProperty::GetValueAsString( int argFlags ) const +wxString wxColourProperty::ValueToString( wxVariant& value, + int argFlags ) const { const wxPGEditor* editor = GetEditorClass(); if ( editor != wxPGEditor_Choice && @@ -1398,16 +1395,11 @@ wxString wxColourProperty::GetValueAsString( int argFlags ) const editor != wxPGEditor_ComboBox ) argFlags |= wxPG_PROPERTY_SPECIFIC; - return wxSystemColourProperty::GetValueAsString(argFlags); + return wxSystemColourProperty::ValueToString(value, argFlags); } wxColour wxColourProperty::GetColour( int index ) const { - if ( !m_choices.HasValue(index) ) - { - wxASSERT( index < (int)GetItemCount() ); - return gs_cp_es_normcolour_colours[index]; - } return gs_cp_es_normcolour_colours[m_choices.GetValue(index)]; } @@ -1649,10 +1641,12 @@ void wxImageFileProperty::OnSetValue() m_pBitmap = NULL; } + wxFileName filename = GetFileName(); + // Create the image thumbnail - if ( m_filename.FileExists() ) + if ( filename.FileExists() ) { - m_pImage = new wxImage( m_filename.GetFullPath() ); + m_pImage = new wxImage( filename.GetFullPath() ); } } @@ -1737,22 +1731,30 @@ wxMultiChoiceProperty::~wxMultiChoiceProperty() void wxMultiChoiceProperty::OnSetValue() { - GenerateValueAsString(); + GenerateValueAsString(m_value, &m_display); } -wxString wxMultiChoiceProperty::GetValueAsString( int ) const +wxString wxMultiChoiceProperty::ValueToString( wxVariant& value, + int argFlags ) const { - return m_display; + // If possible, use cached string + if ( argFlags & wxPG_VALUE_IS_CURRENT ) + return m_display; + + wxString s; + GenerateValueAsString(value, &s); + return s; } -void wxMultiChoiceProperty::GenerateValueAsString() +void wxMultiChoiceProperty::GenerateValueAsString( wxVariant& value, + wxString* target ) const { wxArrayString strings; - if ( m_value.GetType() == wxPG_VARIANT_TYPE_ARRSTRING ) - strings = m_value.GetArrayString(); + if ( value.GetType() == wxPG_VARIANT_TYPE_ARRSTRING ) + strings = value.GetArrayString(); - wxString& tempStr = m_display; + wxString& tempStr = *target; unsigned int i; unsigned int itemCount = strings.size(); @@ -1803,7 +1805,7 @@ bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid* propgrid, if ( propgrid->IsMainButtonEvent(event) ) { // Update the value - wxVariant useValue = propgrid->GetPendingEditedValue(); + wxVariant useValue = propgrid->GetUncommittedPropertyValue(); wxArrayString labels = m_choices.GetLabels(); unsigned int choiceCount; @@ -1949,11 +1951,12 @@ bool wxDateProperty::StringToValue( wxVariant& variant, const wxString& text, return false; } -wxString wxDateProperty::GetValueAsString( int argFlags ) const +wxString wxDateProperty::ValueToString( wxVariant& value, + int argFlags ) const { const wxChar* format = (const wxChar*) NULL; - wxDateTime dateTime = m_value.GetDateTime(); + wxDateTime dateTime = value.GetDateTime(); if ( !dateTime.IsValid() ) return wxT("Invalid");