diff --git a/docs/changes.txt b/docs/changes.txt index 684d8617a9..d48e03e78f 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -108,6 +108,7 @@ All (GUI): - Fix possible infinite loop in wxHtmlWindow layout (trivia21). - Add "hint" property support to XRC for wxComboBox and wxSearchCtrl. - Add support for style="page-break-inside:avoid" to
in wxHTML. +- Add strike-through support to wxDataViewItem attributes (approach). wxGTK: diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 573caf5227..c41ac8298c 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -144,21 +144,24 @@ public: { m_bold = false; m_italic = false; + m_strikethrough = false; } // setters void SetColour(const wxColour& colour) { m_colour = colour; } void SetBold( bool set ) { m_bold = set; } void SetItalic( bool set ) { m_italic = set; } + void SetStrikethrough( bool set ) { m_strikethrough = set; } void SetBackgroundColour(const wxColour& colour) { m_bgColour = colour; } // accessors bool HasColour() const { return m_colour.IsOk(); } const wxColour& GetColour() const { return m_colour; } - bool HasFont() const { return m_bold || m_italic; } + bool HasFont() const { return m_bold || m_italic || m_strikethrough; } bool GetBold() const { return m_bold; } bool GetItalic() const { return m_italic; } + bool GetStrikethrough() const { return m_strikethrough; } bool HasBackgroundColour() const { return m_bgColour.IsOk(); } const wxColour& GetBackgroundColour() const { return m_bgColour; } @@ -172,6 +175,7 @@ private: wxColour m_colour; bool m_bold; bool m_italic; + bool m_strikethrough; wxColour m_bgColour; }; diff --git a/interface/wx/dataview.h b/interface/wx/dataview.h index c673939758..6958ee7386 100644 --- a/interface/wx/dataview.h +++ b/interface/wx/dataview.h @@ -703,6 +703,17 @@ public: */ void SetItalic(bool set); + /** + Call this to indicate that the item shall be displayed in strikethrough + text. + + Currently this attribute is only supported in the generic version of + wxDataViewCtrl and ignored by the native GTK+ and OS X implementations. + + @since 3.1.2 + */ + void SetStrikethrough( bool set ); + /** Returns true if the colour property has been set. diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index 9615cc2c88..8f20dee696 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -725,6 +725,11 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l m_list_model = new MyListModel; m_ctrl[1]->AssociateModel( m_list_model.get() ); + m_ctrl[1]->AppendToggleColumn(L"\u2714", + MyListModel::Col_Toggle, + wxDATAVIEW_CELL_ACTIVATABLE, + wxCOL_WIDTH_AUTOSIZE); + // the various columns m_ctrl[1]->AppendTextColumn("editable string", MyListModel::Col_EditableText, diff --git a/samples/dataview/mymodels.cpp b/samples/dataview/mymodels.cpp index c7953bfcdc..ae40acb021 100644 --- a/samples/dataview/mymodels.cpp +++ b/samples/dataview/mymodels.cpp @@ -336,10 +336,13 @@ MyListModel::MyListModel() : // all the others are synthesized on request static const unsigned NUMBER_REAL_ITEMS = 100; + m_toggleColValues.reserve(NUMBER_REAL_ITEMS); m_textColValues.reserve(NUMBER_REAL_ITEMS); + m_toggleColValues.push_back(false); m_textColValues.push_back("first row with long label to test ellipsization"); for (unsigned int i = 1; i < NUMBER_REAL_ITEMS; i++) { + m_toggleColValues.push_back(false); m_textColValues.push_back(wxString::Format("real row %d", i)); } @@ -351,6 +354,7 @@ MyListModel::MyListModel() : void MyListModel::Prepend( const wxString &text ) { + m_toggleColValues.insert( m_toggleColValues.begin(), 0 ); m_textColValues.Insert( text, 0 ); RowPrepended(); } @@ -359,6 +363,11 @@ void MyListModel::DeleteItem( const wxDataViewItem &item ) { unsigned int row = GetRow( item ); + if (row >= m_toggleColValues.size()) + return; + + m_toggleColValues.erase( m_toggleColValues.begin()+row ); + if (row >= m_textColValues.GetCount()) return; @@ -374,7 +383,10 @@ void MyListModel::DeleteItems( const wxDataViewItemArray &items ) { unsigned int row = GetRow( items[i] ); if (row < m_textColValues.GetCount()) + { + wxASSERT(row < m_toggleColValues.size()); rows.Add( row ); + } } if (rows.GetCount() == 0) @@ -390,7 +402,10 @@ void MyListModel::DeleteItems( const wxDataViewItemArray &items ) // remaining indeces would all be wrong. rows.Sort( my_sort_reverse ); for (i = 0; i < rows.GetCount(); i++) + { + m_toggleColValues.erase( m_toggleColValues.begin()+rows[i] ); m_textColValues.RemoveAt( rows[i] ); + } // This is just to test if wxDataViewCtrl can // cope with removing rows not sorted in @@ -409,6 +424,13 @@ void MyListModel::GetValueByRow( wxVariant &variant, { switch ( col ) { + case Col_Toggle: + if (row >= m_toggleColValues.size()) + variant = false; + else + variant = m_toggleColValues[row]; + break; + case Col_EditableText: if (row >= m_textColValues.GetCount()) variant = wxString::Format( "virtual row %d", row ); @@ -470,8 +492,20 @@ bool MyListModel::GetAttrByRow( unsigned int row, unsigned int col, { switch ( col ) { + case Col_Toggle: + return false; + case Col_EditableText: case Col_Date: + if (row < m_toggleColValues.size()) + { + if (m_toggleColValues[row]) + { + attr.SetColour( wxColour( *wxLIGHT_GREY ) ); + attr.SetStrikethrough( true ); + return true; + } + } return false; case Col_IconText: @@ -482,6 +516,16 @@ bool MyListModel::GetAttrByRow( unsigned int row, unsigned int col, break; case Col_TextWithAttr: + if (row < m_toggleColValues.size()) + { + if (m_toggleColValues[row]) + { + attr.SetColour( wxColour( *wxLIGHT_GREY ) ); + attr.SetStrikethrough( true ); + return true; + } + } + case Col_Custom: // do what the labels defined in GetValueByRow() hint at switch ( row % 5 ) @@ -520,6 +564,13 @@ bool MyListModel::SetValueByRow( const wxVariant &variant, { switch ( col ) { + case Col_Toggle: + if (row >= m_toggleColValues.size()) + return false; + + m_toggleColValues[row] = variant.GetBool(); + return true; + case Col_EditableText: case Col_IconText: if (row >= m_textColValues.GetCount()) diff --git a/samples/dataview/mymodels.h b/samples/dataview/mymodels.h index 4c7d1a3a10..d812a31c8c 100644 --- a/samples/dataview/mymodels.h +++ b/samples/dataview/mymodels.h @@ -9,6 +9,7 @@ ///////////////////////////////////////////////////////////////////////////// #include "wx/hashmap.h" +#include WX_DECLARE_HASH_MAP(unsigned, wxString, wxIntegerHash, wxIntegerEqual, IntToStringMap); @@ -196,6 +197,7 @@ class MyListModel: public wxDataViewVirtualListModel public: enum { + Col_Toggle, Col_EditableText, Col_IconText, Col_Date, @@ -223,6 +225,9 @@ public: virtual wxString GetColumnType( unsigned int col ) const wxOVERRIDE { + if (col == Col_Toggle) + return wxT( "bool" ); + if (col == Col_IconText) return wxT("wxDataViewIconText"); @@ -237,6 +242,7 @@ public: unsigned int row, unsigned int col ) wxOVERRIDE; private: + wxVector m_toggleColValues; wxArrayString m_textColValues; wxArrayString m_iconColValues; IntToStringMap m_customColValues; diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index fd68880243..05a1021742 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -87,6 +87,8 @@ wxFont wxDataViewItemAttr::GetEffectiveFont(const wxFont& font) const f.MakeBold(); if ( GetItalic() ) f.MakeItalic(); + if ( GetStrikethrough() ) + f.MakeStrikethrough(); return f; }