Add strike-through support to wxDataViewItem attributes
Implement support for this attribute only in the generic version so far, it will hopefully be implemented for the natives ones in the future. Also add a new toggle column to the dataview sample to check how it works: checking the items in this column enables using this attribute for some other ones. Closes #18180.
This commit is contained in:
parent
e1a7f56040
commit
09124932eb
@ -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 <div> in wxHTML.
|
||||
- Add strike-through support to wxDataViewItem attributes (approach).
|
||||
|
||||
wxGTK:
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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,
|
||||
|
@ -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())
|
||||
|
@ -9,6 +9,7 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "wx/hashmap.h"
|
||||
#include <wx/vector.h>
|
||||
|
||||
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<bool> m_toggleColValues;
|
||||
wxArrayString m_textColValues;
|
||||
wxArrayString m_iconColValues;
|
||||
IntToStringMap m_customColValues;
|
||||
|
@ -87,6 +87,8 @@ wxFont wxDataViewItemAttr::GetEffectiveFont(const wxFont& font) const
|
||||
f.MakeBold();
|
||||
if ( GetItalic() )
|
||||
f.MakeItalic();
|
||||
if ( GetStrikethrough() )
|
||||
f.MakeStrikethrough();
|
||||
return f;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user