// intentionally returns NULL for all the other renderer classes as the
// user should _not_ be able to override Activate/LeftClick() when deriving
// from them for consistency with the other ports and while we can't
- // prevent this from working at compile-time because all renderer are
+ // prevent this from working at compile-time because all renderers are
// custom renderers in the generic implementation, we at least make sure
// that it doesn't work at run-time because Activate/LeftClick() would
// never be called
virtual wxDataViewCustomRenderer *WXGetAsCustom() { return NULL; }
+ // The generic implementation of some standard renderers reacts to item
+ // activation, so provide this internal function which is called by
+ // wxDataViewCtrl for them. It is called with the old value of the cell and
+ // is passed the model and cell coordinates to be able to change the model
+ // value for this cell.
+ virtual void WXOnActivate(wxDataViewModel * WXUNUSED(model),
+ const wxVariant& WXUNUSED(valueOld),
+ const wxDataViewItem& WXUNUSED(item),
+ unsigned int WXUNUSED(col))
+ {
+ }
+
private:
int m_align;
wxDataViewCellMode m_mode;
bool GetValue( wxVariant &value ) const;
bool Render( wxRect cell, wxDC *dc, int state );
- bool Activate( wxRect cell, wxDataViewModel *model, const wxDataViewItem & item,
- unsigned int col );
wxSize GetSize() const;
+ // Implementation only, don't use nor override
+ virtual void WXOnActivate(wxDataViewModel *model,
+ const wxVariant& valueOld,
+ const wxDataViewItem& item,
+ unsigned int col);
private:
bool m_toggle;
virtual bool Render( wxRect cell, wxDC *dc, int state );
virtual wxSize GetSize() const;
- virtual bool Activate( wxRect cell,
- wxDataViewModel *model,
- const wxDataViewItem& item,
- unsigned int col );
+
+ // Implementation only, don't use nor override
+ virtual void WXOnActivate(wxDataViewModel *model,
+ const wxVariant& valueOld,
+ const wxDataViewItem& item,
+ unsigned int col);
private:
wxDateTime m_date;
return true;
}
-bool wxDataViewToggleRenderer::Activate( wxRect WXUNUSED(cell),
- wxDataViewModel *model,
- const wxDataViewItem & item, unsigned int col)
+void wxDataViewToggleRenderer::WXOnActivate(wxDataViewModel *model,
+ const wxVariant& valueOld,
+ const wxDataViewItem & item,
+ unsigned int col)
{
- model->ChangeValue(!m_toggle, item, col);
- return true;
+ model->ChangeValue(!valueOld.GetBool(), item, col);
}
wxSize wxDataViewToggleRenderer::GetSize() const
return wxSize(x,y+d);
}
-bool wxDataViewDateRenderer::Activate( wxRect WXUNUSED(cell), wxDataViewModel *model,
- const wxDataViewItem & item, unsigned int col )
+void wxDataViewDateRenderer::WXOnActivate(wxDataViewModel *model,
+ const wxVariant& valueOld,
+ const wxDataViewItem & item,
+ unsigned int col )
{
- wxVariant variant;
- model->GetValue( variant, item, col );
- wxDateTime value = variant.GetDateTime();
+ wxDateTime dtOld = valueOld.GetDateTime();
#if wxUSE_DATE_RENDERER_POPUP
wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient(
- GetOwner()->GetOwner()->GetParent(), &value, model, item, col);
+ GetOwner()->GetOwner()->GetParent(), &dtOld, model, item, col);
wxPoint pos = wxGetMousePosition();
popup->Move( pos );
popup->Layout();
popup->Popup( popup->m_cal );
#else // !wxUSE_DATE_RENDERER_POPUP
- wxMessageBox(value.Format());
+ wxMessageBox(dtOld.Format());
#endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
- return true;
}
// ---------------------------------------------------------
{
if ((!ignore_other_columns) && (cell->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE))
{
+ const unsigned colIdx = col->GetModelColumn();
+
+ wxVariant value;
+ model->GetValue( value, item, colIdx );
+
+ cell->WXOnActivate(model, value, item, colIdx);
+
if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() )
{
- wxVariant value;
- model->GetValue( value, item, col->GetModelColumn() );
- custom->SetValue( value );
+ cell->SetValue( value );
+
wxRect cell_rect( xpos, GetLineStart( current ),
col->GetWidth(), GetLineHeight( current ) );
- custom->Activate( cell_rect, model, item, col->GetModelColumn() );
+ custom->Activate( cell_rect, model, item, colIdx );
}
}
else