Add wxDataViewRendererBase::PrepareForItem() helper.
For calling SetValue() and SetAttr() consistently, instead of having the same code duplicated all over the place. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65950 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -118,6 +118,10 @@ public:
|
|||||||
|
|
||||||
wxString GetVariantType() const { return m_variantType; }
|
wxString GetVariantType() const { return m_variantType; }
|
||||||
|
|
||||||
|
// helper that calls SetValue and SetAttr:
|
||||||
|
void PrepareForItem(const wxDataViewModel *model,
|
||||||
|
const wxDataViewItem& item, unsigned column);
|
||||||
|
|
||||||
// renderer properties:
|
// renderer properties:
|
||||||
virtual void SetMode( wxDataViewCellMode mode ) = 0;
|
virtual void SetMode( wxDataViewCellMode mode ) = 0;
|
||||||
virtual wxDataViewCellMode GetMode() const = 0;
|
virtual wxDataViewCellMode GetMode() const = 0;
|
||||||
|
@@ -779,6 +779,20 @@ bool wxDataViewRendererBase::FinishEditing()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxDataViewRendererBase::PrepareForItem(const wxDataViewModel *model,
|
||||||
|
const wxDataViewItem& item,
|
||||||
|
unsigned column)
|
||||||
|
{
|
||||||
|
wxVariant value;
|
||||||
|
model->GetValue(value, item, column);
|
||||||
|
SetValue(value);
|
||||||
|
|
||||||
|
wxDataViewItemAttr attr;
|
||||||
|
model->GetAttr(item, column, attr);
|
||||||
|
SetAttr(attr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxDataViewCustomRendererBase
|
// wxDataViewCustomRendererBase
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -1553,14 +1553,8 @@ wxBitmap wxDataViewMainWindow::CreateItemBitmap( unsigned int row, int &indent )
|
|||||||
if (column == expander)
|
if (column == expander)
|
||||||
width -= indent;
|
width -= indent;
|
||||||
|
|
||||||
wxVariant value;
|
|
||||||
wxDataViewItem item = GetItemByRow( row );
|
wxDataViewItem item = GetItemByRow( row );
|
||||||
model->GetValue( value, item, column->GetModelColumn());
|
cell->PrepareForItem(model, item, column->GetModelColumn());
|
||||||
cell->SetValue( value );
|
|
||||||
|
|
||||||
wxDataViewItemAttr attr;
|
|
||||||
model->GetAttr(item, column->GetModelColumn(), attr);
|
|
||||||
cell->SetAttr(attr);
|
|
||||||
|
|
||||||
wxRect item_rect(x, 0, width, height);
|
wxRect item_rect(x, 0, width, height);
|
||||||
item_rect.Deflate(PADDING_RIGHTLEFT, 0);
|
item_rect.Deflate(PADDING_RIGHTLEFT, 0);
|
||||||
@@ -1742,7 +1736,6 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
|||||||
for (unsigned int item = item_start; item < item_last; item++)
|
for (unsigned int item = item_start; item < item_last; item++)
|
||||||
{
|
{
|
||||||
// get the cell value and set it into the renderer
|
// get the cell value and set it into the renderer
|
||||||
wxVariant value;
|
|
||||||
wxDataViewTreeNode *node = NULL;
|
wxDataViewTreeNode *node = NULL;
|
||||||
wxDataViewItem dataitem;
|
wxDataViewItem dataitem;
|
||||||
|
|
||||||
@@ -1763,12 +1756,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
|||||||
dataitem = wxDataViewItem( wxUIntToPtr(item+1) );
|
dataitem = wxDataViewItem( wxUIntToPtr(item+1) );
|
||||||
}
|
}
|
||||||
|
|
||||||
model->GetValue( value, dataitem, col->GetModelColumn());
|
cell->PrepareForItem(model, dataitem, col->GetModelColumn());
|
||||||
cell->SetValue( value );
|
|
||||||
|
|
||||||
wxDataViewItemAttr attr;
|
|
||||||
model->GetAttr(dataitem, col->GetModelColumn(), attr);
|
|
||||||
cell->SetAttr(attr);
|
|
||||||
|
|
||||||
// update cell_rect
|
// update cell_rect
|
||||||
cell_rect.y = GetLineStart( item );
|
cell_rect.y = GetLineStart( item );
|
||||||
@@ -2520,14 +2508,7 @@ int wxDataViewMainWindow::GetLineStart( unsigned int row ) const
|
|||||||
|
|
||||||
wxDataViewRenderer *renderer =
|
wxDataViewRenderer *renderer =
|
||||||
const_cast<wxDataViewRenderer*>(column->GetRenderer());
|
const_cast<wxDataViewRenderer*>(column->GetRenderer());
|
||||||
|
renderer->PrepareForItem(model, item, column->GetModelColumn());
|
||||||
wxVariant value;
|
|
||||||
model->GetValue( value, item, column->GetModelColumn() );
|
|
||||||
renderer->SetValue( value );
|
|
||||||
|
|
||||||
wxDataViewItemAttr attr;
|
|
||||||
model->GetAttr(item, column->GetModelColumn(), attr);
|
|
||||||
renderer->SetAttr(attr);
|
|
||||||
|
|
||||||
height = wxMax( height, renderer->GetSize().y );
|
height = wxMax( height, renderer->GetSize().y );
|
||||||
}
|
}
|
||||||
@@ -2588,14 +2569,7 @@ int wxDataViewMainWindow::GetLineAt( unsigned int y ) const
|
|||||||
|
|
||||||
wxDataViewRenderer *renderer =
|
wxDataViewRenderer *renderer =
|
||||||
const_cast<wxDataViewRenderer*>(column->GetRenderer());
|
const_cast<wxDataViewRenderer*>(column->GetRenderer());
|
||||||
|
renderer->PrepareForItem(model, item, column->GetModelColumn());
|
||||||
wxVariant value;
|
|
||||||
model->GetValue( value, item, column->GetModelColumn() );
|
|
||||||
renderer->SetValue( value );
|
|
||||||
|
|
||||||
wxDataViewItemAttr attr;
|
|
||||||
model->GetAttr(item, column->GetModelColumn(), attr);
|
|
||||||
renderer->SetAttr(attr);
|
|
||||||
|
|
||||||
height = wxMax( height, renderer->GetSize().y );
|
height = wxMax( height, renderer->GetSize().y );
|
||||||
}
|
}
|
||||||
@@ -2646,14 +2620,7 @@ int wxDataViewMainWindow::GetLineHeight( unsigned int row ) const
|
|||||||
|
|
||||||
wxDataViewRenderer *renderer =
|
wxDataViewRenderer *renderer =
|
||||||
const_cast<wxDataViewRenderer*>(column->GetRenderer());
|
const_cast<wxDataViewRenderer*>(column->GetRenderer());
|
||||||
|
renderer->PrepareForItem(model, item, column->GetModelColumn());
|
||||||
wxVariant value;
|
|
||||||
model->GetValue( value, item, column->GetModelColumn() );
|
|
||||||
renderer->SetValue( value );
|
|
||||||
|
|
||||||
wxDataViewItemAttr attr;
|
|
||||||
model->GetAttr(item, column->GetModelColumn(), attr);
|
|
||||||
renderer->SetAttr(attr);
|
|
||||||
|
|
||||||
height = wxMax( height, renderer->GetSize().y );
|
height = wxMax( height, renderer->GetSize().y );
|
||||||
}
|
}
|
||||||
@@ -3820,13 +3787,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
|
|||||||
if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() )
|
if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() )
|
||||||
{
|
{
|
||||||
// notify cell about click
|
// notify cell about click
|
||||||
wxVariant value;
|
custom->PrepareForItem(model, item, col->GetModelColumn());
|
||||||
model->GetValue( value, item, col->GetModelColumn() );
|
|
||||||
custom->SetValue( value );
|
|
||||||
|
|
||||||
wxDataViewItemAttr attr;
|
|
||||||
model->GetAttr(item, col->GetModelColumn(), attr);
|
|
||||||
custom->SetAttr(attr);
|
|
||||||
|
|
||||||
wxRect cell_rect( xpos, GetLineStart( current ),
|
wxRect cell_rect( xpos, GetLineStart( current ),
|
||||||
col->GetWidth(), GetLineHeight( current ) );
|
col->GetWidth(), GetLineHeight( current ) );
|
||||||
@@ -4179,13 +4140,7 @@ unsigned int wxDataViewCtrl::GetBestColumnWidth(int idx) const
|
|||||||
{
|
{
|
||||||
wxDataViewItem item = m_clientArea->GetItemByRow(row);
|
wxDataViewItem item = m_clientArea->GetItemByRow(row);
|
||||||
|
|
||||||
wxVariant value;
|
renderer->PrepareForItem(GetModel(), item, column->GetModelColumn());
|
||||||
GetModel()->GetValue(value, item, column->GetModelColumn());
|
|
||||||
renderer->SetValue(value);
|
|
||||||
|
|
||||||
wxDataViewItemAttr attr;
|
|
||||||
GetModel()->GetAttr(item, column->GetModelColumn(), attr);
|
|
||||||
renderer->SetAttr(attr);
|
|
||||||
|
|
||||||
max_width = (unsigned)wxMax((int)max_width, renderer->GetSize().x);
|
max_width = (unsigned)wxMax((int)max_width, renderer->GetSize().x);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user